Re: "once" assigment in Python

2007-09-17 Thread Steve Holden
Lorenzo Di Gregorio wrote: > On 17 Sep., 16:54, Larry Bates <[EMAIL PROTECTED]> wrote: >> IMHO variables like what you describe are really data not program variables. >> You might consider putting variables like these in a dictionary and then >> check >> to see if the keys exist before assignment:

Re: "once" assigment in Python

2007-09-17 Thread Lorenzo Di Gregorio
On 17 Sep., 16:54, Larry Bates <[EMAIL PROTECTED]> wrote: > > IMHO variables like what you describe are really data not program variables. > You might consider putting variables like these in a dictionary and then check > to see if the keys exist before assignment: > > var_dict={} > > # > # See if

Re: "once" assigment in Python

2007-09-17 Thread Larry Bates
Lorenzo Di Gregorio wrote: > Hello, > > I've been using Python for some DES simulations because we don't need > full C speed and it's so much faster for writing models. During > coding I find it handy to assign a variable *unless it has been > already assigned*: I've found that this is often refe

Re: "once" assigment in Python

2007-09-14 Thread Alex Martelli
Lorenzo Di Gregorio <[EMAIL PROTECTED]> wrote: > When employing Python it's pretty straightforward to translate the > instance to an object. > > instance = Component(input=wire1,output=wire2) > > Then you don't use "instance" *almost* anymore: it's an object which > gets registered with the simu

Re: "once" assigment in Python

2007-09-14 Thread Lorenzo Di Gregorio
Thank you very much for your suggestions! I'll try in the next days to elaborate a bit on the last two ones. By the way, the "once" assignment is not that evil if you use it for hardware modeling. Most hardware models look like: wire1 = function() instance component(input=wire1,output=wire2) resu

Re: "once" assigment in Python

2007-09-14 Thread Carl Banks
On Fri, 14 Sep 2007 06:16:56 +, Lorenzo Di Gregorio wrote: > Hello, > > I've been using Python for some DES simulations because we don't need > full C speed and it's so much faster for writing models. During coding > I find it handy to assign a variable *unless it has been already > assigned

Re: "once" assigment in Python

2007-09-14 Thread DouhetSukd
Agree that what you are looking for may not be a good idea. So make sure you don't shoot yourself in the foot with it. You should probably look into your problem some more. >>> def once(obj,attrname,value): ... if hasattr(obj,attrname): ... return ... else: ... se

Re: "once" assigment in Python

2007-09-14 Thread Peter Otten
Lorenzo Di Gregorio wrote: > I've been using Python for some DES simulations because we don't need > full C speed and it's so much faster for writing models. During > coding I find it handy to assign a variable *unless it has been > already assigned*: I've found that this is often referred to as

Re: "once" assigment in Python

2007-09-14 Thread Steve Holden
Lorenzo Di Gregorio wrote: > Hello, > > I've been using Python for some DES simulations because we don't need > full C speed and it's so much faster for writing models. During > coding I find it handy to assign a variable *unless it has been > already assigned*: I've found that this is often refe

Re: "once" assigment in Python

2007-09-13 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Lorenzo Di Gregorio wrote: > During coding I find it handy to assign a variable *unless it has been > already assigned*: I've found that this is often referred to as "once" > assigment. Why not just assign to it once at the beginning and be done with it? -- http:/

Re: "once" assigment in Python

2007-09-13 Thread Calvin Spealman
This is one of the things that I often see people trying to do in Python, where the best solution is simply to understand how Python works and craft the code to work with the language. The problem, in my view, is not that you don't have a good way to do this "once assignment" operation, but that yo