473,804 Members | 4,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1967
On Aug 13, 1:00 pm, brad <byte8b...@gmai l.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*******@gmai l.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.co m>
Aug 13 '07 #3
Evan Klitzke wrote:
On 8/13/07, brad <by*******@gmai l.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...@holdenwe b.comwrote:
Evan Klitzke wrote:
On 8/13/07, brad <byte8b...@gmai l.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...@holdenwe b.comwrote:
>Evan Klitzke wrote:
>>On 8/13/07, brad <byte8b...@gmai l.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*******@gmai l.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
2214
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 may be pointed to different URLs depending upon the table key. The variable substitution works fine when hardcoding into the script, e.g.: $var1='data1';
1
5159
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 differ. I log on to the sample schema 'hr' and enter the following statements: -- statements begin set verify on define name = K%
22
1616
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 = document.myForm.mySelectName; } I simply want this line to subsitute "mySelectName" with a var string
3
2116
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 basic Python functionality. But hopefully in future versions more work will be spent to make the resulting C++ programs as fast as possible. One of the many possible details that may be improved, is the compiling to C++ of the Python "parallel"...
166
8694
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
438
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 written such function ? For an old BC3.1 it will be fine.
5
2895
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%>')" style="text-decoration:underline;cursor:hand;color:red;"> <%=mZipServiceUrl%> </span> but in the same page, I cant substitute the same variable into a user control:
1
3508
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 each field value and assign it to each text box. The text boxes are named like this: txtSPctTrees1 txtSPctShrubs1 txt(etc)1 ... txtSPctTrees2 txtSPctShrubs2 txt(etc)2 ... txtSPctTrees3 ... ....
3
5617
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 with window.open and passes in 1 value using a querystring i.e., www.myhome.com/mypage?video=BAK-Extension Now when the window opens, I can capture the passed value in a JS function. But if I want to use that in the body of the HTML in a
0
10575
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.