Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc:
i = anyclass()
a.shutdown()
b.update()
Any Ideas?
Many Thanks, m 10 1613
Tanteauguri wrote: Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc: i = anyclass()
a.shutdown() b.update()
Use a dictionary:
stuff = {}
pc = ['a', 'b', 'c']
for i in pc:
stuff[i] = anyclass()
stuff['a'].shutdown()
stuff['b'].update()
On Sat, 19 Mar 2005 04:35:47 -0500, Leif K-Brooks <eu*****@ecritt ers.biz> wrote: Tanteauguri wrote: Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc: i = anyclass()
a.shutdown() b.update() Use a dictionary:
stuff = {} pc = ['a', 'b', 'c']
I think what he wants to do is basically hold object names in a tuple
list, and then call the methods on those objects (while iterating or
whatever). for i in pc: stuff[i] = anyclass()
stuff['a'].shutdown() stuff['b'].update() -- http://mail.python.org/mailman/listinfo/python-list
--
Premshree Pillai http://www.livejournal.com/users/premshree/
Tanteauguri wrote: Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc: i = anyclass()
a.shutdown() b.update()
Any Ideas?
def seq(n,cls,*args ,**kw):
"create a sequence of n objects of type cls."
return [cls(*args,**kw) for i in range(n)] a,b,c = seq(3,anyclass) a.shutdown() b.update()
Regards Kay
In article <11************ **********@g14g 2000cwa.googleg roups.com>,
Kay Schluehr <ka**********@g mx.net> wrote: Tanteauguri wrote: Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc: i = anyclass()
a.shutdown() b.update()
Any Ideas?
def seq(n,cls,*args ,**kw): "create a sequence of n objects of type cls." return [cls(*args,**kw) for i in range(n)]
a,b,c = seq(3,anyclass) a.shutdown() b.update()
Regards Kay
I'm going to make this explicit: the PHP idiom is a defect.
Yes, I know that's good style among top PHP practitioners,
but, from all I know, it's simply a bad habit. The advice to
use a dictionary is on target.
Tanteauguri a écrit : Hi List, is there in python a variable variable like in PHP ($$var)?
Hopefully, no.
See other answers in that thread for pythonic idioms.
> I'm going to make this explicit: the PHP idiom is a defect. Yes, I know that's good style among top PHP practitioners, but, from all I know, it's simply a bad habit. The advice to use a dictionary is on target.
I tried to like it the whole last hour ;-)
I reconstructed the formal structure of $$var from a PHP Web-tutorial
though i do not have any experience with the language.
This is what i got:
$ =
<Name> ---> <Var> --------------> <Var>x<String >
| |
$ | # | $ o q' o proj2
| |
V V
<Var> ----- f ------> <Var>
| |
| # | =
| V
+-----------------> <Var>x<String >
=
In the diagram $ is an operator that creates a var from a name, = is an
operator that binds a string to a var and q' drops quotations from a
string to get an name. The function f is an implied isomorphism. It
represents the equivalence of $$a and $b, where $a = "b".
Personally I could live with that, but the diagram is a bit special
because of the restriction of the = operation. I do not know if PHP
supports this operational view by enabling iterations: $a, $$a, $$$a
.... ?
After all I can also live without that in Python...
Regards Kay
> Personally I could live with that, but the diagram is a bit special because of the restriction of the = operation. I do not know if PHP supports this operational view by enabling iterations: $a, $$a, $$$a ... ?
It does.
--
Regards,
Diez B. Roggisch
Premshree Pillai wrote: On Sat, 19 Mar 2005 04:35:47 -0500, Leif K-Brooks <eu*****@ecritt ers.biz> wrote:
Tanteauguri wrote:
Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc: i = anyclass()
a.shutdown () b.update()
Use a dictionary:
stuff = {} pc = ['a', 'b', 'c']
I think what he wants to do is basically hold object names in a tuple list, and then call the methods on those objects (while iterating or whatever).
for i in pc: stuff[i] = anyclass()
stuff['a'].shutdown() stuff['b'].update() -- http://mail.python.org/mailman/listinfo/python-list
Try this:
pc=["a","b","c"]
for i in pc:
vars()[i] = anyclass()
a.shutdown()
b.update()
MikeG
Premshree Pillai wrote: On Sat, 19 Mar 2005 04:35:47 -0500, Leif K-Brooks <eu*****@ecritt ers.biz> wrote:
Tanteauguri wrote:
Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc: i = anyclass()
a.shutdown () b.update()
Use a dictionary:
stuff = {} pc = ['a', 'b', 'c']
I think what he wants to do is basically hold object names in a tuple list, and then call the methods on those objects (while iterating or whatever).
for i in pc: stuff[i] = anyclass()
stuff['a'].shutdown() stuff['b'].update() -- http://mail.python.org/mailman/listinfo/python-list
Try this:
pc=["a","b","c"]
for i in pc:
vars()[i] = anyclass()
a.shutdown()
b.update()
MikeG This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scott |
last post by:
I have an XML Document in a format like:
<Variable name="Bob">ABCDEFG</Variable>
<Variable name="Steve">QWERTYUI</Variable>
<Variable name="John">POIUYTR</Variable>
<Variable name="Tim">ZXCVBNM</Variable>
<Function id="1">
<Parameter type="String">Bob</Parameter>
<Parameter type="String">Steve</Parameter>
|
by: Frederik Sørensen |
last post by:
I include a xslt stylesheet with variables for all the error messages in
my system.
<xsl:variable name="Banner_error_1">
errormessage 1 for banner
</xsl:variable>
<xsl:variable name="Banner_error_2">
errormessage 2 for banner
</xsl:variable>
|
by: James A. Donald |
last post by:
I am contemplating getting into Python, which is used by engineers I
admire - google and Bram Cohen, but was horrified to read
"no variable or argument declarations are necessary."
Surely that means that if I misspell a variable name, my program will
mysteriously fail to work with no error message.
If you don't declare variables, you can inadvertently re-use an
variable used in an enclosing context when you don't intend to, or
|
by: Blaxer |
last post by:
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be...
function Calculate_Something(ByVal multiplyer as integer, ByVal variable as ___?)
variable = 5 * multiplyer
end function
What I would like this function to do is take the name of the incoming variable and assign a calculated value to it.
Any help would be greatly appreciated, TIA!!
|
by: Russ Chinoy |
last post by:
Hi,
This may be a totally newbie question, but I'm stumped.
If I have a function such as:
function DoSomething(strVarName) {
.....
}
| |
by: rls03 |
last post by:
I have the following which creates a variable containing a relative
path where <xsl:value-of select="."/returns a portion of the
filename:
<xsl:variable name="fileName">../../data/models/<xsl:value-of
select="."/>.xml</xsl:variable>
I want to use this variable as an argument of the document function:
<xsl:apply-templates mode="coordinates" select="document( REFERENCE
|
by: pbmods |
last post by:
VARIABLE SCOPE IN JAVASCRIPT
LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN )
PREREQS: VARIABLES
First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
|
by: Florian Loitsch |
last post by:
hi,
What should be the output of the following code-snippet?
===
var x = "global";
function f() {
var x = 0;
eval("function x() { return false; }");
delete x;
alert(x);
}
|
by: minkoo.seo |
last post by:
Hi.
I've got a question on the differences and how to define static and
class variables. AFAIK, class methods are the ones which receives the
class itself as an argument, while static methods are the one which
runs statically with the defining class.
Hence, my understanding is that static variables must be bound to the
class defining the variables and shared by children of parent class
where the variable is defined. But, please have a...
|
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions that may print some messages.
foo(...)
{
if (!silent)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |