473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1951
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: bofh | last post by:
I'm working on a project where I need to store a CGI query in a database field. The query contains variables which will be substitued at runtime (e.g., today's date, key to select upon, etc), and...
1
by: Jacob Grydholt Jensen | last post by:
I am trying to learn iSQL*Plus for the 1Z0-007 exam. I am having a bit of problems with the substitution variables. My understanding was that they behave as in SQL*Plus, but my experiments beg to...
22
by: bmgz | last post by:
sorry for the stupid question, bu6 I haven't been able to find the answer anywhere.. consider this useless function which assigns an object to a var.. function(myParam){ var select1 =...
3
by: bearophileHUGS | last post by:
The current version of ShedSkin (http://shedskin.sourceforge.net/ experimental Python to C++ compiler) is rather alpha, and the development work is focused on debugging and implementing some more...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
1
by: KERLOG | last post by:
Hello, I found that in "glibc" there is a function to perform variable substitution. It start with $. By digging inside the code of "glibc" I can't find how it's done. Has someone already...
5
by: Steve Richter | last post by:
I have a public variable ( "mZipServiceUrl" ) in my code behind class that I am able to substitute into the HTML of the .aspx file: <span onclick="WindowOpen('<%=mZipServiceUrl%>')"...
1
by: Brian Newman | last post by:
I have a form with five rows of text boxes, displaying data. For certain reasons, I can't bind these directly to data records, so I'm using code to load the data into an object, then manually get...
3
by: Skip | last post by:
OK, I'm a novice in JS but have lots of coding experience. I am trying to accomplish something that would seem somewhat simple - BUT IT'S NOT. I have a basic window that calls another window...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.