Re: Create a variable on the fly

2005-07-28 Thread Paul D.Smith
Bruno, FYI, notes in-line... Cheers, Paul DS a look instantiate Python variables of the appropriate type. What do you mean of the appropriate type ? You want to typecast (eg. from string to numeric) ? Then you need to know what env var must be casted to what type ? Then you don't need to

Re: Create a variable on the fly

2005-07-28 Thread Sybren Stuvel
Paul D.Smith enlightened us with: The background is that I've inherited some historical Python scripts that need to be configured from a bash shell script [...] instead of the existing Pything config script. [...] The problem is that this config file is almost certainly not complete [...] and

Re: Create a variable on the fly

2005-07-28 Thread Steven Bethard
Paul D.Smith wrote: 2. A simple Python config which searches for all shell environment variables named MY_... and instantiates then as Python variables. my_vars = dict((k, v) for k, v in os.environ.iteritems() if k.startswith('MY_')) globals().update(my_vars) If

Re: Create a variable on the fly

2005-07-28 Thread Scott David Daniels
Paul D.Smith wrote: ... What I'm left with is the following... 1. A shell script which I maintain. 2. A simple Python config which searches for all shell environment variables named MY_... and instantiates then as Python variables. 3. Historical scripts that run without me needing to spend

Create a variable on the fly

2005-07-27 Thread Paul D.Smith
Can Python create a variable on-the-fly. For example I would like something like... make_variable('OSCAR', 'the grouch'); print OSCAR; ...to output... the grouch Anything like this in Python? And in case anyone is interested, I want to instantiate a set of variables based on environment

Re: Create a variable on the fly

2005-07-27 Thread Paolino
Paul D.Smith wrote: Can Python create a variable on-the-fly. For example I would like something like... make_variable('OSCAR', 'the grouch'); print OSCAR; ...to output... Python has only 'on the fly' variables and ';' is not used for one expression in one line. Probably the tutorial

Re: Create a variable on the fly

2005-07-27 Thread Dan
make_variable('OSCAR', 'the grouch'); print OSCAR; Try using setattr. (It's in __builtins__; you don't have to import anything.) print setattr.__doc__ setattr(object, name, value) Set a named attribute on an object; setattr(x, 'y', v) is equivalent to ``x.y = v''. -- If builders built

Re: Create a variable on the fly

2005-07-27 Thread Paolino
Paul D.Smith wrote: Can Python create a variable on-the-fly. For example I would like something like... make_variable('OSCAR', 'the grouch'); print OSCAR; ...to output... Python has only 'on the fly' variables and ';' is not used for one expression in one line. Probably the tutorial

Re: Create a variable on the fly

2005-07-27 Thread Steve M
PythonWin 2.3.5 (#62, Feb 9 2005, 16:17:08) [MSC v.1200 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) - see 'Help/About PythonWin' for further copyright information. locals()['OSCAR'] = 'the grouch' OSCAR 'the grouch' --

Re: Create a variable on the fly

2005-07-27 Thread bruno modulix
Paul D.Smith wrote: Can Python create a variable on-the-fly. For example I would like something like... make_variable('OSCAR', 'the grouch'); print OSCAR; ...to output... the grouch Anything like this in Python? The bad news is that yes, there is something like this in Python

Re: Create a variable on the fly

2005-07-27 Thread Willem Broekema
Steve M: locals()['OSCAR'] = 'the grouch' OSCAR 'the grouch' Use globals, not locals: globals()['OSCAR'] = 'the grouch' because http://www.python.org/doc/current/lib/built-in-funcs.html states: locals() Update and return a dictionary representing the current local symbol table.

Re: Create a variable on the fly

2005-07-27 Thread Do Re Mi chel La Si Do
Hi ! Try : OSCAR='the grouch' print OSCAR useless to thank me Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list