On Jan 29, 2010, at 2:30 AM, Steven D'Aprano wrote:
On Thu, 28 Jan 2010 17:01:38 +0100, Roald de Vries wrote:
Question out of general interest in the language: If I would want to
generate such functions in a for-loop, what would I have to do? This
doesn't work:
class Move(object):
def
On Jan 22, 2010, at 11:56 AM, Roald de Vries wrote:
Hi Martin,
On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If
On Thu, 28 Jan 2010 17:01:38 +0100, Roald de Vries wrote:
Question out of general interest in the language: If I would want to
generate such functions in a for-loop, what would I have to do? This
doesn't work:
class Move(object):
def __call__(self, direction):
return
En Fri, 22 Jan 2010 10:16:50 -0300, Alf P. Steinbach al...@start.no
escribió:
I get the impression that there's some message traffic that I don't see,
perhaps on the mailing list, since (a) I haven't seen that about
'locals' pointed out by anyone else in this thread, and I think I've
* Gabriel Genellina:
En Fri, 22 Jan 2010 10:16:50 -0300, Alf P. Steinbach al...@start.no
escribió:
I get the impression that there's some message traffic that I don't
see, perhaps on the mailing list, since (a) I haven't seen that about
'locals' pointed out by anyone else in this thread, and
On Jan 22, 8:39 pm, Martin Drautzburg martin.drautzb...@web.de
wrote:
Martin Drautzburg wrote:
with scope():
# ...
# use up, down, left, right here
# up, down, left, right no longer defined after the with block exits.
Just looked it up again. It's a cool thing. Too bad my
Just top-posting for clarity. :-)
code file=directions.py
up = UP
left= LEFT
down= DOWN
right = RIGHT
/code
code file=locals.py
# This code is not guaranteed to work by the language specification.
# But it is one way to do the solution I presented earlier in the thread.
import
On Sun, 24 Jan 2010 10:11:07 -0800, George Sakkis wrote:
Both in your example and by using a context manager, you can get away
with not passing locals() explicitly by introspecting the stack frame.
You say that as if it were less of an ugly hack than the locals() trick.
But sys._getframe is a
On Jan 25, 1:05 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
On Sun, 24 Jan 2010 10:11:07 -0800, George Sakkis wrote:
Both in your example and by using a context manager, you can get away
with not passing locals() explicitly by introspecting the stack frame.
You say that
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 20:24:
Do you understand how bad that makes you look?
I think the right thing to say at this point is don't feed the troll.
I find it amazing that you continue this kind of ad hominem attack. You leave it
open who you regard as trolling, but
Steven D'Aprano wrote:
I think this really is the correct solution for your problem. In
Python, the standard place to have such public constants is at the
module level, not the function or class. I think you're worrying
unnecessarily about namespace pollution -- the module namespace is
Carl Banks wrote:
I see. Well, Python is a poor choice for defining an internal DSL
(i.e., DSL using the general language's syntax), because it's
(deliberately) rigid in both grammar and semantics.
I had this impression too.
Paul McGuire should be by to recommend PyParsing shortly.
I
* Martin Drautzburg:
Here is a complete expample using a decorator, still a bit noisy
def move(aDirection):
print moving + aDirection
#Here comes the decorator
def scope(aDict):
def save(locals):
Set symbols in locals and remember their original state
setSymbols={}
On Jan 21, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
wrote:
Paul McGuire should be by to recommend PyParsing shortly.
I looked it up and it seems to be about parsing strings. This is not
what I am looking for as it would create a separate world outside of
python. But I haven't
Hi Martin,
On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down, left or right, you can
Steven D'Aprano wrote:
(3) Then somone suggested to tie the constants to the function itself,
as in
def move(direction):
print moving %s % direction
move.UP = 'up'
move.DOWN = 'down'
This is quite nice.
I would call it a horrible, horrible, horrible code smell. A stench in
fact.
21-01-2010, 22:51:34 Martin Drautzburg martin.drautzb...@web.de wrote:
Thanks for all the answers. Let me summarize
(1) [...]
(2) Using enum's was suggested. That is good to know, but again it is
just a way to define constants in the caller's namespace. [...]
(3) Then somone suggested to tie
s/sollution/solution
s/event implemented/even implemented
Sorry
*j
--
http://mail.python.org/mailman/listinfo/python-list
Jean-Michel Pichavant jeanmic...@sequans.com writes:
Steven D'Aprano wrote:
I would call it a horrible, horrible, horrible code smell. A stench
in fact.
[…]
As soon as it is properly documented, as a public interface should be,
it becomes an acceptable design, IMO.
[…]
So your position
Roald de Vries wrote:
div class=moz-text-flowed style=font-family: -moz-fixedHi Martin,
On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move
On 22 Jan., 11:56, Roald de Vries r...@roalddevries.nl wrote:
Hi Martin,
On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
On Jan 22, 2010, at 1:06 PM, Martin Drautzburg wrote:
On 22 Jan., 11:56, Roald de Vries r...@roalddevries.nl wrote:
Hi Martin,
On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume
On Jan 21, 10:57 pm, Martin Drautzburg martin.drautzb...@web.de
wrote:
Here is a complete expample using a decorator, still a bit noisy
def move(aDirection):
print moving + aDirection
#Here comes the decorator
def scope(aDict):
def save(locals):
[...]
Have you considered making
On Fri, 22 Jan 2010 09:12:46 +0100, Martin Drautzburg wrote:
Defining those symbols at the module level is absolutely fine with me.
The namespace pollution is indeed my biggest worry. You see, I want to
be able to type in lots of lines with little effort. Preferably I would
want to type
Ben Finney wrote:
Jean-Michel Pichavant jeanmic...@sequans.com writes:
Steven D'Aprano wrote:
I would call it a horrible, horrible, horrible code smell. A stench
in fact.
[…]
As soon as it is properly documented, as a public interface should be,
it becomes an acceptable
On Fri, 22 Jan 2010 09:29:18 +0100, Alf P. Steinbach wrote:
But have you tested this within a function or class, which is what the
use of locals implies?
The reason that I ask is that in the documentation of locals() it says
this:
Note
The contents of this dictionary should not be
* Steven D'Aprano - Alf P. Steinbach:
No, you got it spot on. Not to discourage you, but you're at least the
third person who pointed this out in this thread.
I get the impression that there's some message traffic that I don't see, perhaps
on the mailing list, since (a) I haven't seen that
On Friday 22 January 2010, Alf P. Steinbach wrote:
I get the impression that there's some message traffic that I don't
see
For example, the recent thread Covert number into string started
with a reply in my newreader, using EternalSeptember's NNTP host.
It also starts with a reply in
* Steven D'Aprano:
One implementation-specific trick is that modifying locals does actually
work inside a class definition (at least in Python 2.5):
class Foo(object):
... x = 1
... print locals()
... locals()['x'] = 2
...
{'x': 1, '__module__': '__main__'}
Foo.x
2
But it
* Wolfgang Rohdewald:
On Friday 22 January 2010, Alf P. Steinbach wrote:
I get the impression that there's some message traffic that I don't
see
For example, the recent thread Covert number into string started
with a reply in my newreader, using EternalSeptember's NNTP host.
It also starts
Mark Dickinson wrote:
On Jan 21, 10:57 pm, Martin Drautzburg martin.drautzb...@web.de
wrote:
Here is a complete expample using a decorator, still a bit noisy
def move(aDirection):
print moving + aDirection
#Here comes the decorator
def scope(aDict):
def save(locals):
[...]
Have you
Martin Drautzburg wrote:
with scope():
# ...
# use up, down, left, right here
# up, down, left, right no longer defined after the with block exits.
Just looked it up again. It's a cool thing. Too bad my locals() hack
would still be required. The result would be less noisy (and
On Thu, Jan 21, 2010 at 8:43 AM, Martin Drautzburg
martin.drautzb...@web.de wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down,
* Martin Drautzburg:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down, left or right, you can solve
this by passing strings, but this is
Hello,
I'd say that isn't totally incorrect to use strings instead of
symbols. Please note that in other programming languages symbols,
atoms and the like are in fact immutable strings, which is what python
provides by default.
Best regards,
Javier
2010/1/21 Alf P. Steinbach al...@start.no:
Martin Drautzburg martin.drautzb...@web.de writes:
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values
You might like to try the ‘enum’ library for this
URL:http://pypi.python.org/pypi/enum.
--
\ “You could augment an earwig to the
Martin Drautzburg, having symbols spread in the namespace is bad. And
too much magic is even worse. You seem to need something like an enum
that must be used with its qualified name, as:
move(direction.up)
That works well unless the symbols name are keywords.
Creating a small class like this
On Jan 21, 7:43 am, Martin Drautzburg martin.drautzb...@web.de
wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down, left or
Huh? I guess you meant to reply to the OP, not me.
Cheers,
- Alf
* Javier Collado:
Hello,
I'd say that isn't totally incorrect to use strings instead of
symbols. Please note that in other programming languages symbols,
atoms and the like are in fact immutable strings, which is what python
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down, left or
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able to call move(up)
- having the up symbol only in the context of the function call
Short answer is, you can't do it.
On the contrary,
Martin Drautzburg wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down, left or right, you can solve
this by passing strings, but
Alf P. Steinbach, 21.01.2010 09:30:
* Martin Drautzburg:
- to be able to call move(up)
- having the up symbol only in the context of the function call
So it should look something like this
... magic, magic ...
move(up)
... unmagic, unmagic ...
print up
Looks like a
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able to call move(up)
- having the up symbol only in the context of the function
call
Short answer is,
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 09:30:
* Martin Drautzburg:
- to be able to call move(up)
- having the up symbol only in the context of the function call
So it should look something like this
... magic, magic ...
move(up)
... unmagic, unmagic ...
print up
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able to call move(up)
- having the up symbol only in the context of the function
call
Martin Drautzburg wrote:
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down, left or right, you can solve
this by passing strings, but
On Jan 21, 2:38 am, Alf P. Steinbach al...@start.no wrote:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able to call move(up)
- having the up symbol only in the context of the
Am 21.01.10 12:58, schrieb Alf P. Steinbach:
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able to call move(up)
- having the up symbol only in the
* Carl Banks:
On Jan 21, 2:38 am, Alf P. Steinbach al...@start.no wrote:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able to call move(up)
- having the up symbol only in the context of
* Diez B. Roggisch:
Am 21.01.10 12:58, schrieb Alf P. Steinbach:
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able to call move(up)
- having the up
Am 21.01.10 19:48, schrieb Alf P. Steinbach:
* Diez B. Roggisch:
Am 21.01.10 12:58, schrieb Alf P. Steinbach:
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
-
* Diez B. Roggisch:
Am 21.01.10 19:48, schrieb Alf P. Steinbach:
* Diez B. Roggisch:
Am 21.01.10 12:58, schrieb Alf P. Steinbach:
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really
Am 21.01.10 20:01, schrieb Alf P. Steinbach:
* Diez B. Roggisch:
Am 21.01.10 19:48, schrieb Alf P. Steinbach:
* Diez B. Roggisch:
Am 21.01.10 12:58, schrieb Alf P. Steinbach:
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg
* Diez B. Roggisch:
Am 21.01.10 20:01, schrieb Alf P. Steinbach:
* Diez B. Roggisch:
Am 21.01.10 19:48, schrieb Alf P. Steinbach:
* Diez B. Roggisch:
Am 21.01.10 12:58, schrieb Alf P. Steinbach:
* Stefan Behnel:
Alf P. Steinbach, 21.01.2010 11:38:
* Carl Banks:
On Jan 20, 11:43 pm,
On Jan 21, 10:46 am, Alf P. Steinbach al...@start.no wrote:
* Carl Banks:
On Jan 21, 2:38 am, Alf P. Steinbach al...@start.no wrote:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able
* Carl Banks:
On Jan 21, 10:46 am, Alf P. Steinbach al...@start.no wrote:
* Carl Banks:
On Jan 21, 2:38 am, Alf P. Steinbach al...@start.no wrote:
* Carl Banks:
On Jan 20, 11:43 pm, Martin Drautzburg martin.drautzb...@web.de
[snip]
What I am really looking for is a way
- to be able
Thanks for all the answers. Let me summarize
(1) I fail to see the relevance of
def move( direction ):
... print( move + str( direction ) )
...
move( up )
move up
not only in the context of my question. And I don't see an abuse of the
language either. Maybe this could pass as a Zen
* Martin Drautzburg:
Thanks for all the answers. Let me summarize
(1) I fail to see the relevance of
def move( direction ):
... print( move + str( direction ) )
...
move( up )
move up
not only in the context of my question. And I don't see an abuse of the
language either. Maybe this
Am 21.01.10 22:51, schrieb Martin Drautzburg:
Thanks for all the answers. Let me summarize
(1) I fail to see the relevance of
def move( direction ):
... print( move + str( direction ) )
...
move( up )
move up
not only in the context of my question. And I don't see an abuse of the
On Jan 21, 1:51 pm, Martin Drautzburg martin.drautzb...@web.de
wrote:
Thanks for all the answers. Let me summarize
[snip]
(2) Using enum's was suggested. That is good to know, but again it is
just a way to define constants in the caller's namespace.
It'll at least corral the symbols you want.
Carl Banks pavlovevide...@gmail.com writes:
On Jan 21, 1:51 pm, Martin Drautzburg martin.drautzb...@web.de
wrote:
(2) Using enum's was suggested. That is good to know, but again it
is just a way to define constants in the caller's namespace.
It'll at least corral the symbols you want.
It
On Thu, 21 Jan 2010 22:51:34 +0100, Martin Drautzburg wrote:
Thanks for all the answers. Let me summarize
(1) I fail to see the relevance of
def move( direction ):
... print( move + str( direction ) ) ...
move( up )
move up
I'm glad it's not just me then.
not only in the
Steven D'Aprano wrote:
[snip]
An example from the standard library: the re module defines constants I,
L, M, etc. representing flags that are passed to the re.compile. They are
implemented as integers so they can easily be combined with , but
another implementation might use symbols. You will
On Fri, 22 Jan 2010 02:42:55 +, MRAB wrote:
Steven D'Aprano wrote:
[snip]
An example from the standard library: the re module defines constants
I, L, M, etc. representing flags that are passed to the re.compile.
They are implemented as integers so they can easily be combined with ,
but
Here is a complete expample using a decorator, still a bit noisy
def move(aDirection):
print moving + aDirection
#Here comes the decorator
def scope(aDict):
def save(locals):
Set symbols in locals and remember their original state
setSymbols={}
unsetSymbols=[]
Alf P. Steinbach, 21.01.2010 20:24:
Do you understand how bad that makes you look?
I think the right thing to say at this point is don't feed the troll.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Hello all,
When passing parameters to a function, you sometimes need a paramter
which can only assume certain values, e.g.
def move (direction):
...
If direction can only be up, down, left or right, you can solve
this by passing strings, but this is not quite to the
68 matches
Mail list logo