| Author |
Message |
Steve "TZOTZIOY" *nix forums beginner
Joined: 04 Feb 2005
Posts: 1
|
Posted: Fri Feb 04, 2005 11:07 pm Post subject:
Re: [OT] PEP 8j, pythonista naming style
|
|
|
On Fri, 04 Feb 2005 23:56:44 +1000, rumours say that Steve Coghlan
<scoghlan@iinet.net.au> might have written:
| Quote: | A Steve wrote:
A Steve wrote:
A Steve wrote:
There we go, much clearer
|
Indeed. I recall some Dan Perl who was advised to change his name to a more
pythonic one, but now I see he misinterpreted the advice.
Am I assimilated or what?
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually... |
|
| Back to top |
|
 |
Nick Coghlan *nix forums Guru Wannabe
Joined: 20 Feb 2005
Posts: 131
|
Posted: Fri Feb 04, 2005 12:56 pm Post subject:
Re: global variables
|
|
|
A Steve wrote:
| Quote: | A Steve wrote:
A Steve wrote:
|
There we go, much clearer ;)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net |
|
| Back to top |
|
 |
Steve Holden *nix forums Guru
Joined: 22 Feb 2005
Posts: 1255
|
Posted: Thu Feb 03, 2005 5:12 pm Post subject:
Re: global variables
|
|
|
Steven Bethard wrote:
| Quote: | Steve Holden wrote:
M.E.Farmer wrote:
Ok it has been a long day,
In my reply to Steven Bethard , Steve should read Steven ;)
M.E.Farmer
Well, since he signs himself "Steve" too I guess we'll just have to
put up with the ambiguities. Or perhaps, given my (lack of) typing
skill, I should just start signing myself "Stvev"?
regards
Steve
Or I can stop correcting it every time I type STeve[1]. ;)
STeve
[1] But of course, you probably do the same thing too.
|
Indeed. I defy anyone to be a crappier typist then me.
Stevbe - see?
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/ |
|
| Back to top |
|
 |
Steven Bethard *nix forums Guru
Joined: 20 Feb 2005
Posts: 773
|
Posted: Thu Feb 03, 2005 4:41 pm Post subject:
Re: global variables
|
|
|
Steve Holden wrote:
| Quote: | M.E.Farmer wrote:
Ok it has been a long day,
In my reply to Steven Bethard , Steve should read Steven ;)
M.E.Farmer
Well, since he signs himself "Steve" too I guess we'll just have to put
up with the ambiguities. Or perhaps, given my (lack of) typing skill, I
should just start signing myself "Stvev"?
regards
Steve
|
Or I can stop correcting it every time I type STeve[1]. ;)
STeve
[1] But of course, you probably do the same thing too.  |
|
| Back to top |
|
 |
Michael *nix forums Guru
Joined: 28 Mar 2003
Posts: 352
|
Posted: Thu Feb 03, 2005 4:35 pm Post subject:
Re: global variables
|
|
|
| Quote: | Probably naming it something other than 'globals' would be a good idea
-- otherwise you'll hide the builtin globals() function.
But I agree that the attributes of a class instance (as you suggest)
or the attributes of a module (as Steve Holden suggests) is probably
the right way to go.
|
I like to use 'runtime' or 'runtime_options' to store the results of
command-line options. I wasn't sure about this way of getting Python to
handle global variables when I first tried it but after a little
experience with it I think it works out pretty well. One thing I did
learn though is that it's best to keep these modules simple. Don't make
them import or define classes or functions if you can avoid it. It's
easy to get into a mess of recursive imports if you start doing that.
Just a good newbie tip.
***
if runtime.verbose: print 'Something happened.'
***
--
Michael <mogmios@mlug.missouri.edu>
http://kavlon.org |
|
| Back to top |
|
 |
Mark Jackson *nix forums beginner
Joined: 11 Jul 2005
Posts: 10
|
Posted: Thu Feb 03, 2005 12:36 pm Post subject:
Re: global variables
|
|
|
Steve Holden <steve@holdenweb.com> writes:
| Quote: | M.E.Farmer wrote:
Ok it has been a long day,
In my reply to Steven Bethard , Steve should read Steven ;)
M.E.Farmer
Well, since he signs himself "Steve" too I guess we'll just have to put
up with the ambiguities. Or perhaps, given my (lack of) typing skill, I
should just start signing myself "Stvev"?
|
What's this doing *here*? I thought the discussion of the pitfalls of
name rebinding was taking place in the "variable declaration" thread.
--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
People who write obscurely are either unskilled in writing
or up to mischief. - Sir Peter Medawar |
|
| Back to top |
|
 |
Steve Holden *nix forums Guru
Joined: 22 Feb 2005
Posts: 1255
|
Posted: Thu Feb 03, 2005 12:06 pm Post subject:
Re: global variables
|
|
|
M.E.Farmer wrote:
| Quote: | Ok it has been a long day,
In my reply to Steven Bethard , Steve should read Steven ;)
M.E.Farmer
Well, since he signs himself "Steve" too I guess we'll just have to put |
up with the ambiguities. Or perhaps, given my (lack of) typing skill, I
should just start signing myself "Stvev"?
regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/ |
|
| Back to top |
|
 |
M.E.Farmer *nix forums Guru Wannabe
Joined: 20 Feb 2005
Posts: 105
|
Posted: Thu Feb 03, 2005 12:04 am Post subject:
Re: global variables
|
|
|
Ok it has been a long day,
In my reply to Steven Bethard , Steve should read Steven ;)
M.E.Farmer |
|
| Back to top |
|
 |
M.E.Farmer *nix forums Guru Wannabe
Joined: 20 Feb 2005
Posts: 105
|
Posted: Wed Feb 02, 2005 11:42 pm Post subject:
Re: global variables
|
|
|
Steve,
Yes I agree Never use builtin names.
I know better but missed it somehow.
I apologize for any confusion I may have caused.
Thank you Steve for the correction.
M.E.Farmer
Steven Bethard wrote:
| Quote: | M.E.Farmer wrote:
alex wrote:
is it possible to create 'global' variables that can be seen in
all
other classes?
What about using a class?
Py> class globalVar:
... pass
Py> globals = globalVar()
Probably naming it something other than 'globals' would be a good
idea
-- otherwise you'll hide the builtin globals() function.
But I agree that the attributes of a class instance (as you suggest)
or
the attributes of a module (as Steve Holden suggests) is probably the
right way to go.
Steve |
|
|
| Back to top |
|
 |
Larry Bates *nix forums Guru
Joined: 21 Feb 2005
Posts: 422
|
Posted: Wed Feb 02, 2005 11:26 pm Post subject:
Re: global variables
|
|
|
One way to to this is by using keyword args:
class a:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.arg1=arg1
self.arg2=arg2
self.__dict__.update(kwargs)
return
class b:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.__dict__.update(kwargs)
self.a=a(arg1, arg2, **kwargs)
return
class c:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.__dict__.update(kwargs)
self.b=b(arg1, arg2, **kwargs)
return
globals={'global1':1, 'global2':2, 'global3':3, 'global4':4}
C=c(1, 2, **globals)
you will have global1, global2, global3, and global4 attributs
in all classes. If you don't want the attributes, just access
to the values, delete the self.__dict__.update(kwargs) lines.
Larry Bates
alex wrote:
| Quote: | Hi,
is it possible to create 'global' variables that can be seen in all
other classes?
Alex
|
|
|
| Back to top |
|
 |
Steven Bethard *nix forums Guru
Joined: 20 Feb 2005
Posts: 773
|
Posted: Wed Feb 02, 2005 11:23 pm Post subject:
Re: global variables
|
|
|
M.E.Farmer wrote:
| Quote: | alex wrote:
is it possible to create 'global' variables that can be seen in all
other classes?
What about using a class?
Py> class globalVar:
... pass
Py> globals = globalVar()
|
Probably naming it something other than 'globals' would be a good idea
-- otherwise you'll hide the builtin globals() function.
But I agree that the attributes of a class instance (as you suggest) or
the attributes of a module (as Steve Holden suggests) is probably the
right way to go.
Steve |
|
| Back to top |
|
 |
M.E.Farmer *nix forums Guru Wannabe
Joined: 20 Feb 2005
Posts: 105
|
Posted: Wed Feb 02, 2005 11:01 pm Post subject:
Re: global variables
|
|
|
alex wrote:
| Quote: | Hi,
is it possible to create 'global' variables that can be seen in all
other classes?
Alex
Hello, |
What about using a class?
Py> class globalVar:
.... pass
Py> globals = globalVar()
Now you can assign 'variables' to it.
And use it anywhere you need it.
Py> globals.image_height = (255,777)
Py> globals.image_mode = 'RGB'
Py> globals.image_names = ['this.jpg', that.jpg']
etc...
hth,
M.E.Farmer |
|
| Back to top |
|
 |
Steve Holden *nix forums Guru
Joined: 22 Feb 2005
Posts: 1255
|
Posted: Wed Feb 02, 2005 10:26 pm Post subject:
Re: global variables
|
|
|
alex wrote:
| Quote: | Hi,
is it possible to create 'global' variables that can be seen in all
other classes?
Alex
Not sensibly, though you can mess around with the __builtin__ namespace |
to make values accessible without qualification.
The usual solution is to maintain a config module that establishes
default settings for configuration variables. Other modules that import
config can access (and change) those values using
config.name = value
and so on. Hope this help.
regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/ |
|
| Back to top |
|
 |
alex *nix forums beginner
Joined: 02 Feb 2005
Posts: 1
|
Posted: Wed Feb 02, 2005 10:04 pm Post subject:
global variables
|
|
|
Hi,
is it possible to create 'global' variables that can be seen in all
other classes?
Alex |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|