Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > using names before they're defined

Reply
Thread Tools

using names before they're defined

 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      07-24-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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 package a breeze.

> 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.

 
Reply With Quote
 
 
 
 
davehowey@f2s.com
Guest
Posts: n/a
 
      07-26-2006
> >
> > 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 alternative config parsing
program:
http://www.voidspace.org.uk/python/configobj.html

seems to offer a bit more than configparser

Dave

 
Reply With Quote
 
 
 
 
David Isaac
Guest
Posts: n/a
 
      07-26-2006
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 by the 'main()' function
in mod1.

Whichever is imported will be imported as, say, 'use_mod',
and code in mod1 will refer to use_mod.

Problem:
classes in mod1 that refer to 'use_mod' of course
raise a NameError, since the import does not take
place until 'main()' is run.

So, what is the right way to implement my desire?

Thanks,
Alan Isaac


 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      07-27-2006
(E-Mail Removed) 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 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 dicts, lists, etc !-)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
davehowey@f2s.com
Guest
Posts: n/a
 
      07-27-2006

> > 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 dicts, lists, etc !-)
>
>


What do you mean? I don't really understand. I had a blast with
configobj and seems to be ok - quite straightfoward for the type of ini
file I'm using. configparser prob the same... it's kind of 'much over
muchness' as they say

Dave

 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      07-28-2006
(E-Mail Removed) 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 Python file with dicts, lists, etc !-)
>>
>>

>
>
> What do you mean? I don't really understand.


It's not a criticism of configobj - which is a quite nice package -,
it's just a matter of personal tastes (I don't like configobj's
[[[some-nested-sub-sub-section]]] syntax) and specific needs.

Most of the time, I don't need nothing more than a plain ini file - and
in this case, I prefer to use configparser because it's in the standard
lib (so I avoid a dependency on a 3rd part package).

When an ini file won't do, it's usually because what the app need is
really complex and specific enough to justify a "domain specific language".

And sometimes, this DSL can be expressed with Python's syntax, like for
example:

schema = {'turbine1': {'class': 'Turbine',
'upstream' : ('frobnicator2',),
'downstream' : () # nothing,
},
'frobnicator2' : {'class' : 'Frobnicator',
'upstream' : (),
'downstream' : ('frobnicator2',),
},
}

FWIW, the package's end user is not even supposed to know this is in
fact Python code !-)

FWIW, JSON can be a good candidate for this kind of stuff too.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using identifiers before they are defined Julio Sergio Python 0 06-12-2012 05:53 PM
Using parenthesis with defined (#if defined(...)) Angel Tsankov C++ 1 04-05-2006 10:00 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
WSDL- Mapping Application Defined Names to XML Names Craig XML 0 02-09-2004 04:14 PM
XSL rules applying to XSD (XML schema) defined type names (as opposed to node names) Lewis G. Pringle, Jr. XML 0 09-30-2003 10:34 PM



Advertisments