By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,293 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,293 IT Pros & Developers. It's quick & easy.

Assignments and Variable Substitution

P: n/a
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
Share this Question
Share on Google+
6 Replies

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.