Re: using names before they're defined

2006-07-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hiya, you might be interested in this alternative config parsing program: http://www.voidspace.org.uk/python/configobj.html Yes, I know it. But I don't like it. Either a simple ini file do the trick, or I need a full blown app-specific DSL - which can be as simple as a

Re: using names before they're defined

2006-07-27 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: do you mean 'configparser'? Yes. Does it generate objects from the config file automatically? It generates a representation of the config file as a Python object composed of sections and options. The documentation should get you started. Hiya, you might be

Re: using names before they're defined

2006-07-27 Thread davehowey
Hiya, you might be interested in this alternative config parsing program: http://www.voidspace.org.uk/python/configobj.html Yes, I know it. But I don't like it. Either a simple ini file do the trick, or I need a full blown app-specific DSL - which can be as simple as a Python file with

Re: using names before they're defined

2006-07-26 Thread davehowey
do you mean 'configparser'? Yes. Does it generate objects from the config file automatically? It generates a representation of the config file as a Python object composed of sections and options. The documentation should get you started. Hiya, you might be interested in this

Re: using names before they're defined

2006-07-26 Thread David Isaac
Suppose I have inherited the structure PackageFolder/ __init__.py mod1.py SubPackageFolder/ __init__.py mod2.py mod3.py When mod1 is run as a script, I desire to import either mod2 or mod3 but not both conditional on an option detected

Re: using names before they're defined

2006-07-24 Thread Bruno Desthuilliers
Nick Vatamaniuc wrote: Dave, Sometimes generating classes from .ini or XML files is not the best way. You are just translating one language into another and are making bigger headaches for your self. It is certainly cool and bragable to say that my classes get generated on the fly from XML

Re: using names before they're defined

2006-07-24 Thread davehowey
First case is a little shorter but then you have to use a parser for it There's one builtin. do you mean 'configparser'? I'm just trying to figure out how this works. Does it generate objects from the config file automatically? Dave -- http://mail.python.org/mailman/listinfo/python-list

Re: using names before they're defined

2006-07-24 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : First case is a little shorter but then you have to use a parser for it There's one builtin. do you mean 'configparser'? Yes. I'm just trying to figure out how this works. One nice thing with Python is the interactive python shell. It makes exploring a

Re: using names before they're defined

2006-07-22 Thread Nick Vatamaniuc
Dave, Sometimes generating classes from .ini or XML files is not the best way. You are just translating one language into another and are making bigger headaches for your self. It is certainly cool and bragable to say that my classes get generated on the fly from XML but Python is terse and

Re: using names before they're defined

2006-07-22 Thread Patrick Maupin
[EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply()

Re: using names before they're defined

2006-07-21 Thread davehowey
Hi Also, I gave the example using Python code as 'config' format, but any structured enough text format could do, ie JSON, XML, or even ini-like: # schema.ini objects = turbine1, frobnicator2 [turbine1] class=Turbine upstream=frobnicator2 downstream= yes, I like the idea of using .ini

Re: using names before they're defined

2006-07-21 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: Hi (snip) def get_class_by_name(name): return globals()[name] QD way to retrieve the class object (Python's classes are themselves objects) known by it's name (as a string). ok, so it actually returns the class object itself. One thing that confuses me is

Re: using names before they're defined

2006-07-20 Thread Nick Vatamaniuc
Dave, Python properties allow you to get rid of methods like c.getAttr(), c.setAttr(v), c.delAttr() and replace them with simple constructs like c.attr, c.attr=v and del c.attr. If you have been using Java or C++ you know that as soon as you code your class you have to start filling in the get()

Re: using names before they're defined

2006-07-20 Thread Steve Holden
[EMAIL PROTECTED] wrote: Steve Holden wrote: [EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and

Re: using names before they're defined

2006-07-20 Thread Iain King
[EMAIL PROTECTED] wrote: Iain, thanks - very helpful. Really I'm trying to write a simulation program that goes through a number of objects that are linked to one another and does calculations at each object. The calculations might be backwards or fowards (i.e. starting at the supply or

Re: using names before they're defined

2006-07-20 Thread davehowey
Paddy, thanks for your mail. In Digital electronics we have what are called netlists, (and also component lists) yes, years back I did a 3rd year project on a 'logic simulator' which used the kind of thing you are talking about. I think spice does as well. Fortunately my problem is a little

Re: using names before they're defined

2006-07-20 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: (snip) brings me onto another question that has been bugging me, which is, if I want to create components (as object instances) at run time (rather than through a python code imported in), how do I do this? i.e. if I hardcoded something like turbine1 = turbine(...)

Re: using names before they're defined

2006-07-20 Thread davehowey
Hiya Could you just talk me through this... is it: schema = {'turbine1': {'class': 'Turbine', 'upstream' : ('frobnicator2',), 'downstream' : () # nothing, }, 'frobnicator2' : {'class' : 'Frobnicator',

Re: using names before they're defined

2006-07-20 Thread Larry Bates
I don't know if you saw my earlier post but something like this has worked for me. What about something like: supply = supply() compressor = compressor(supply) combuster1= combuster(compressor) combuster2= combuster(compressor) compressor.append(combuster1) compressor.append(combuster2) or

Re: using names before they're defined

2006-07-20 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hiya Could you just talk me through this... is it: schema = {'turbine1': {'class': 'Turbine', 'upstream' : ('frobnicator2',), 'downstream' : () # nothing, }, 'frobnicator2' : {'class'

using names before they're defined

2006-07-19 Thread davehowey
I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply() compressor =

Re: using names before they're defined

2006-07-19 Thread Iain King
[EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply()

Re: using names before they're defined

2006-07-19 Thread Steve Holden
[EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply()

Re: using names before they're defined

2006-07-19 Thread Larry Bates
What about something like: supply = supply() compressor = compressor(supply) combuster = combuster(compressor) compressor.append(combuster) turbine = turbine(combuster) combuster.append(turbine) -Larry Bates [EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a

Re: using names before they're defined

2006-07-19 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply()

Re: using names before they're defined

2006-07-19 Thread davehowey
Iain, thanks - very helpful. Really I'm trying to write a simulation program that goes through a number of objects that are linked to one another and does calculations at each object. The calculations might be backwards or fowards (i.e. starting at the supply or demand ends of the system and then

Re: using names before they're defined

2006-07-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply() NB :

Re: using names before they're defined

2006-07-19 Thread Nick Vatamaniuc
Your can of course initialize the components first: compr=Compressor(...), comb=Combuster(...), sup=Supply(...) , tur=Turbine(...). Then do: compr.up, compr.down =sup, comb comb.up, comb.down =compr, tur Even if you need to do something during attachment of components it is more Pythonic to

Re: using names before they're defined

2006-07-19 Thread davehowey
Bruno, Thanks. An issue is that I need to be able to link multiple objects to a single object etc. Say for example using the previous wording, I might have compressor - multiple combustors - turbine this complicates things slightly. my current thought is to do a two stage initialisation 1.

Re: using names before they're defined

2006-07-19 Thread davehowey
Even if you need to do something during attachment of components it is more Pythonic to use properties. So you will write a method in your class name something like _set_up(self,upstream_obj) an _get_up(self). And then at the end of your class put up=property(_get_up, _set_up). You can

Re: using names before they're defined

2006-07-19 Thread Rob Williscroft
Iain King wrote in news:1153323649.171612.74510 @s13g2000cwa.googlegroups.com in comp.lang.python: [EMAIL PROTECTED] wrote: [...] I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply() compressor =

Re: using names before they're defined

2006-07-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Even if you need to do something during attachment of components it is more Pythonic to use properties. So you will write a method in your class name something like _set_up(self,upstream_obj) an _get_up(self). And then at the end of your class put up=property(_get_up,

Re: using names before they're defined

2006-07-19 Thread Paddy
[EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e. supply = supply()

Re: using names before they're defined

2006-07-19 Thread jordan . nick
Steve Holden wrote: [EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the objects upstream and downstream of it, i.e.

Re: using names before they're defined

2006-07-19 Thread Paul McGuire
[EMAIL PROTECTED] wrote: I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. Have you looked at SimPy? This may simplify much of your data structure anguish (probably only need forward refs, without the back refs), plus it will do