472,118 Members | 1,101 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,118 software developers and data experts.

Assignments and Variable Substitution

I'd like to do something like this:

var = '123'
%s = [], %var

So that, in the end, var is '123' and an empty list is named '123' as
well. The list assignments are created during a loop.

Thanks,
Brad
Aug 13 '07 #1
6 1904
On Aug 13, 1:00 pm, brad <byte8b...@gmail.comwrote:
I'd like to do something like this:

var = '123'
%s = [], %var

So that, in the end, var is '123' and an empty list is named '123' as
well. The list assignments are created during a loop.

Thanks,
Brad
You probably want to use a dictionary to store your lists... code
like:

variableDict = {}
variableDict[var] = ['value1', 'value2', 'value3']

Aug 13 '07 #2
On 8/13/07, brad <by*******@gmail.comwrote:
I'd like to do something like this:

var = '123'
%s = [], %var

So that, in the end, var is '123' and an empty list is named '123' as
well. The list assignments are created during a loop.
You can't assign a variable whose name is 123, but you can do this
sort of thing with setattr.

--
Evan Klitzke <ev**@yelp.com>
Aug 13 '07 #3
Evan Klitzke wrote:
On 8/13/07, brad <by*******@gmail.comwrote:
>I'd like to do something like this:

var = '123'
%s = [], %var

So that, in the end, var is '123' and an empty list is named '123' as
well. The list assignments are created during a loop.

You can't assign a variable whose name is 123, but you can do this
sort of thing with setattr.
And why would you want a variable whose name is '123'?

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 14 '07 #4
Ali
On Aug 14, 12:45 am, Steve Holden <st...@holdenweb.comwrote:
Evan Klitzke wrote:
On 8/13/07, brad <byte8b...@gmail.comwrote:
I'd like to do something like this:
var = '123'
%s = [], %var
And why would you want a variable whose name is '123'?
.... and thus continues the search for private variables in Python.
Aug 14 '07 #5
Ali a écrit :
On Aug 14, 12:45 am, Steve Holden <st...@holdenweb.comwrote:
>Evan Klitzke wrote:
>>On 8/13/07, brad <byte8b...@gmail.comwrote:
I'd like to do something like this:
var = '123'
%s = [], %var
>And why would you want a variable whose name is '123'?

... and thus continues the search for private variables in Python.
I must be tired, but I don't see what this has to do with "private"
variables.

But if you want private variables, it's quite easy: prefix their names
with a single underscore.

Aug 14 '07 #6
Steve Holden wrote:
Evan Klitzke wrote:
>On 8/13/07, brad <by*******@gmail.comwrote:
>>I'd like to do something like this:

var = '123'
%s = [], %var

So that, in the end, var is '123' and an empty list is named '123' as
well. The list assignments are created during a loop.

You can't assign a variable whose name is 123, but you can do this
sort of thing with setattr.
And why would you want a variable whose name is '123'?
Just an example.
Aug 14 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jacob Grydholt Jensen | last post: by
22 posts views Thread by bmgz | last post: by
3 posts views Thread by bearophileHUGS | last post: by
166 posts views Thread by Graham | last post: by
1 post views Thread by KERLOG | last post: by
5 posts views Thread by Steve Richter | last post: by
1 post views Thread by Brian Newman | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.