namespace question

2006-04-19 Thread Nugent, Pete (P.)
Title: namespace question






Hi all,


I'm confused by namespaces in python, specifically using the global keyword.  I'm able to access and modify a global variable from a function if the function is defined in the same module but not if the function is defined in a different module:

//File t2.py

def sn():

    global test_var 

    test_var = 2


//File t1.py

test_var = 1

print test_var

from t2 import sn

sn()

print test_var

def so():

    global test_var 

    test_var = 3

so()

print test_var



The output from running t1 is:

1

1

3


Can anyone tell me how I can modify the test_var variable form another module?


Pete



-- 
http://mail.python.org/mailman/listinfo/python-list

namespace question

2006-12-11 Thread [EMAIL PROTECTED]
Hi ,

class Test:
   a = 1
   b = 2
   c = 1+2

Now, all a,b and c would be directly visible to the user from the
instance of Test. I am looking for a way to make only c directly
visible from the instance.


--
Suresh

-- 
http://mail.python.org/mailman/listinfo/python-list


namespace question

2007-05-18 Thread T. Crane
Hi,

If I define a class like so:

class myClass:
import numpy
a = 1
b = 2
c = 3

def myFun(self):
print a,b,c
return numpy.sin(a)


I get the error that the global names a,b,c,numpy are not defined.  Fairly 
straightforward.  But if I am going to be writing several methods that keep 
calling the same variables or using the same functions/classes from numpy, 
for example, do I have to declare and import those things in each method 
definition?  Is there a better way of doing this?

thanks,
trevis 


-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie namespace question

2004-12-22 Thread [EMAIL PROTECTED]
I have a variable that I want to make global across all modules, i.e. I
want it added to the builtin namespace.  Is there a way to do this?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2006-04-19 Thread Fredrik Lundh
"Nugent, Pete (P.)" wrote:

> I'm confused by namespaces in python, specifically
> using the global keyword.  I'm able to access and
> modify a global variable from a function if the function
> is defined in the same module but not if the function
> s defined in a different module:

"global" means "not local", not "application-wide global".

> Can anyone tell me how I can modify the test_var variable
> form another module?

import t2
t2.test_variable = some value

also see:

http://pyfaq.infogami.com/how-do-i-share-global-variables-across-modules

http://pyfaq.infogami.com/what-are-the-rules-for-local-and-global-variables-in-python





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2006-12-11 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> class Test:
>a = 1
>b = 2
>c = 1+2
> 
> Now, all a,b and c would be directly visible to the user from the
> instance of Test. I am looking for a way to make only c directly
> visible from the instance.

Simplest way:

class Test:
c = 3

:-)

You know that `a`, `b` and `c` are class variables and not instance
variables!?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2006-12-11 Thread [EMAIL PROTECTED]

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] wrote:
>
> > class Test:
> >a = 1
> >b = 2
> >c = 1+2
> >
> > Now, all a,b and c would be directly visible to the user from the
> > instance of Test. I am looking for a way to make only c directly
> > visible from the instance.
>
> Simplest way:
>
> class Test:
> c = 3
>
> :-)


>
> You know that `a`, `b` and `c` are class variables and not instance
> variables!?
Yes. I want to have only one class variable called c and a and b are
required as temporary variables to calculate the value for c.

I just found one way:
class Test:
a = 1
b = 2
c = a + b
del a,b

This one works. But I suppose there must be a way to artificially
create a new block of code, some thing like this,

class Test:
   c = None
   <>:
   # Objects created here are local to this scope
   a = 1
   b = 2
   global c
   c = a + b

> 
> Ciao,
>   Marc 'BlackJack' Rintsch

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2006-12-11 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> This one works. But I suppose there must be a way to artificially
> create a new block of code, some thing like this,
> 
> class Test:
>c = None
><>:
># Objects created here are local to this scope
>a = 1
>b = 2
>global c
>c = a + b

if you want a local scope, use a function:

 class Test:
 c = do_calculation(1, 2)



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2006-12-13 Thread Piet van Oostrum
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> (jssgc) wrote:
>jssgc> This one works. But I suppose there must be a way to artificially
>jssgc> create a new block of code, some thing like this,

>jssgc> class Test:
>jssgc>c = None
>jssgc><>:
>jssgc># Objects created here are local to this scope
>jssgc>a = 1
>jssgc>b = 2
>jssgc>global c
>jssgc>c = a + b

As you want c to be an *instance* variable, the normal idiom would be:

class Test:
  def __init__(self):
  a = 1
  b = 2
  self.c = a+b

x = Test()
print x.c
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2006-12-13 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Yes. I want to have only one class variable called c and a and b are
> required as temporary variables to calculate the value for c.
>
> I just found one way:
> class Test:
> a = 1
> b = 2
> c = a + b
> del a,b

Or even...

a = 1
b = 2
class Test:
c = a + b

Or even the apparently nonsensical...

a = 1
b = 2
c = a + b
class Test:
c = c

Insert del statements to remove module globals where appropriate.

Paul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2007-05-18 Thread Robert Kern
T. Crane wrote:
> Hi,
> 
> If I define a class like so:
> 
> class myClass:
> import numpy
> a = 1
> b = 2
> c = 3
> 
> def myFun(self):
> print a,b,c
> return numpy.sin(a)
> 
> 
> I get the error that the global names a,b,c,numpy are not defined.  Fairly 
> straightforward.  But if I am going to be writing several methods that keep 
> calling the same variables or using the same functions/classes from numpy, 
> for example, do I have to declare and import those things in each method 
> definition?  Is there a better way of doing this?

Put your imports at the module level. I'm not sure what you intended with a, b,
c so let's also put them at the top level.

import numpy
a = 1
b = 2
c = 4

class myClass:
def myFun(self):
print a, b, c
return numpy.sin(a)


OTOH, if a, b, c were supposed to be attached to the class so they could be
overridden in subclasses, or be default values for instances, you can leave them
in the class definition, but access them through "self" or "myClass" directly.


import numpy

class myClass:
a = 1
b = 2
c = 4

def myFun(self):
print self.a, self.b, myClass.c
return numpy.sin(self.a)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2007-05-18 Thread T. Crane
"Robert Kern" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> T. Crane wrote:
>> Hi,
>>
>> If I define a class like so:
>>
>> class myClass:
>> import numpy
>> a = 1
>> b = 2
>> c = 3
>>
>> def myFun(self):
>> print a,b,c
>> return numpy.sin(a)
>>
>>
>> I get the error that the global names a,b,c,numpy are not defined. 
>> Fairly
>> straightforward.  But if I am going to be writing several methods that 
>> keep
>> calling the same variables or using the same functions/classes from 
>> numpy,
>> for example, do I have to declare and import those things in each method
>> definition?  Is there a better way of doing this?
>
> Put your imports at the module level. I'm not sure what you intended with 
> a, b,
> c so let's also put them at the top level.

If you put them at the top level, and suppose you saved it all in a file 
called test.py, then when you type

ln [1]: from test import myClass

does it still load a,b,c and numpy into the namespace?

>
> import numpy
> a = 1
> b = 2
> c = 4
>
> class myClass:
>def myFun(self):
>print a, b, c
>return numpy.sin(a)
>
>
> OTOH, if a, b, c were supposed to be attached to the class so they could 
> be
> overridden in subclasses, or be default values for instances, you can 
> leave them
> in the class definition, but access them through "self" or "myClass" 
> directly.

Yeah, they don't need to be accessed anywhere other than within the class 
itself and I won't need to overwrite them, so I'll try just putting them in 
the top level.

thanks,
trevis


>
>
> import numpy
>
> class myClass:
>a = 1
>b = 2
>c = 4
>
>def myFun(self):
>print self.a, self.b, myClass.c
>return numpy.sin(self.a)
>
> -- 
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless 
> enigma
> that is made terrible by our own mad attempt to interpret it as though it 
> had
> an underlying truth."
>  -- Umberto Eco
> 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2007-05-18 Thread 7stud
On May 18, 12:29 pm, "T. Crane" <[EMAIL PROTECTED]> wrote:
> If you put them at the top level, and suppose you saved it all in a file
> called test.py, then when you type
>
> ln [1]: from test import myClass
>
> does it still load a,b,c and numpy into the namespace?
>

Yep.  Easy to test:

toBeImported.py
-
1) Create a global variable: x = "red"
2) Create a function or a class with a method that prints out the
value of x.


yourProgram.py
--
1) Create a global variable with the same name, but with a different
value: x = 100
2) Use from...import to import your class or function
3) Call the method or function that displays x.  Which value for x was
displayed?


When things defined in a module travel around, they carry a snapshot
of home with them.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2007-05-18 Thread Steve Holden
T. Crane wrote:
> "Robert Kern" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> T. Crane wrote:
>>> Hi,
>>>
>>> If I define a class like so:
>>>
>>> class myClass:
>>> import numpy
>>> a = 1
>>> b = 2
>>> c = 3
>>>
>>> def myFun(self):
>>> print a,b,c
>>> return numpy.sin(a)
>>>
>>>
>>> I get the error that the global names a,b,c,numpy are not defined. 
>>> Fairly
>>> straightforward.  But if I am going to be writing several methods that 
>>> keep
>>> calling the same variables or using the same functions/classes from 
>>> numpy,
>>> for example, do I have to declare and import those things in each method
>>> definition?  Is there a better way of doing this?
>> Put your imports at the module level. I'm not sure what you intended with 
>> a, b,
>> c so let's also put them at the top level.
> 
> If you put them at the top level, and suppose you saved it all in a file 
> called test.py, then when you type
> 
> ln [1]: from test import myClass
> 
> does it still load a,b,c and numpy into the namespace?
> 
Why does it need to? The functions in module "test" will access that 
module's namespace, not that of the calling module.

>> import numpy
>> a = 1
>> b = 2
>> c = 4
>>
>> class myClass:
>>def myFun(self):
>>print a, b, c
>>return numpy.sin(a)
>>
>>
>> OTOH, if a, b, c were supposed to be attached to the class so they could 
>> be
>> overridden in subclasses, or be default values for instances, you can 
>> leave them
>> in the class definition, but access them through "self" or "myClass" 
>> directly.
> 
> Yeah, they don't need to be accessed anywhere other than within the class 
> itself and I won't need to overwrite them, so I'll try just putting them in 
> the top level.
> 
That should work

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 your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace question

2007-05-18 Thread Jordan Greenberg
T. Crane wrote:
> Hi,
> 
> If I define a class like so:
> 
> class myClass:
> import numpy
> a = 1
> b = 2
> c = 3
> 
> def myFun(self):
> print a,b,c
> return numpy.sin(a)
> 
> 
> I get the error that the global names a,b,c,numpy are not defined.  Fairly 
> straightforward.  But if I am going to be writing several methods that keep 
> calling the same variables or using the same functions/classes from numpy, 
> for example, do I have to declare and import those things in each method 
> definition?  Is there a better way of doing this?
> 
> thanks,
> trevis 
> 
> 

Put the import at the top level, and you forgot self when accessing
attributes.

import numpy

class myClass:
a=1
b=2
c=3

def myFun(self):
print self.a, self.b, self.c
return numpy.sin(a)


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread deelan
[EMAIL PROTECTED] wrote:
I have a variable that I want to make global across all modules, i.e. I
want it added to the builtin namespace.  Is there a way to do this?
i would not pollute built-ins namespace.
how about:
### a.py
FOO = "I'm a global foo!"
### b.py
import a
print a.FOO
HTH,
deelan
--
@prefix foaf:  .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog  .
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Steve Holden
[EMAIL PROTECTED] wrote:
I have a variable that I want to make global across all modules, i.e. I
want it added to the builtin namespace.  Is there a way to do this?
Of course: you can do *anything* in Python. I'm not sure this is to be 
recommended, but since you ask ... if you have

# mymod.py
print myname
then in some other module (and here specifically in the interactive 
interpreter) you can bind a value to "myname" in __builtins__ and it 
will be seen by mymod.py when it's imported:

 >>> __builtins__.myname = "MyValue"
 >>> myname
'MyValue'
 >>> import mymod
MyValue
 >>>
Having said all that, you have to be careful, since it's necessary to 
explicity assign to __builtins__.myname to change the value - if you 
just assign to myname then you create a new myname in the module's 
global namespace that will make the name in __builtins__ inaccessible.

So, what with that plus the way the names automagically appear it's 
probably something to relegate to the "definitely not best practice" 
category.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread [EMAIL PROTECTED]
Here's my situation, I've created some scripts to configure WebSphere
and the WAS scripting engine assigns the variable AdminConfig to a Java
object.  I have created classes that wrap the AdminConfig settings,
simplifying the interface for those who want to script their server
installs.

At the command line, I pass the main script in and AdminConfig is
automatically assigned and placed in the global namespace and control
is passed to the main script.

Therefore...

#configure_server_foo.py
from jdbc import DataSource

print globals()["AdminConfig"]  # Will print com.ibm.yada.yada.yada

# Create a couple of data sources
ds = DataSource("ServerName")
ds.create("dsname1", "connectionInfo", "etc")
ds.create("dsname2", "connectionInfo", "etc")

Now, in jdbc.py I have

#jdbc.py
class DataSource:
def __init__(self, servername):
self.servername = servername

def create(name, connectionInfo, etc):
#Call the IBM supplied WebSphere config object
AdminConfig.create('DataSource')

Run it and get a name error, which, makes sense.
If I try to use the standard import solution as deelan suggests I have
a circular reference on the imports and I get an error that it can't
import class DataSource (presumbably because it hasn't gotten far
enough through jdbc.py to realize that there's a DataSource class
defined.

Any insight would be greatly appreciated, and thanks to both deelan and
Steve for your help.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Brandon
And I just realized that Jython doesn't support the __builtins__
variable...  :(

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Peter Hansen
Steve Holden wrote:
then in some other module (and here specifically in the interactive 
interpreter) you can bind a value to "myname" in __builtins__ and it 
will be seen by mymod.py when it's imported:

 >>> __builtins__.myname = "MyValue"
Steve's basic premise is correct, but he's chosen the wrong
name to use.  As Fredrik Lundh has written here 
http://mail.python.org/pipermail/python-list/2002-June/109090.html
the name above is an implementation detail and one should
always do this instead:

import __builtin__
__builtin__.myname = "MyValue"
And doing so reinforces the idea that this is Almost Always
a Bad Idea.  :-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Brandon
Thanks, that worked to get me past the "problem".  Did you see my post
regarding my issue?  I just know that there's a "Python way" to resolve
my issue, so if anyone has a better way, I'm really interested.
Not only does it feel like a hack, it looks like one too!  Even worse!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread deelan
[EMAIL PROTECTED] wrote:
(...)
Run it and get a name error, which, makes sense.
If I try to use the standard import solution as deelan suggests I have
a circular reference on the imports and I get an error that it can't
import class DataSource (presumbably because it hasn't gotten far
enough through jdbc.py to realize that there's a DataSource class
defined.
oh, i see. so the scenario is more complex.
Any insight would be greatly appreciated, and thanks to both deelan and
Steve for your help.
i believe that to avoid circular refs errors remember you can 
lazy-import,  for example here i'm importing the email package:

m = __import__('email')
m

check help(__import__) for futher details.
bye.
--
@prefix foaf:  .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog  .
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Jeff Shannon
[EMAIL PROTECTED] wrote:
Now, in jdbc.py I have
#jdbc.py
class DataSource:
def __init__(self, servername):
self.servername = servername
def create(name, connectionInfo, etc):
#Call the IBM supplied WebSphere config object
AdminConfig.create('DataSource')
Run it and get a name error, which, makes sense.
If I try to use the standard import solution as deelan suggests I have
a circular reference on the imports and I get an error that it can't
import class DataSource (presumbably because it hasn't gotten far
enough through jdbc.py to realize that there's a DataSource class
defined.
 

How about you try this?
def create(name, connectionInfo, ...):
   from configure_server_foo import AdminConfig
   AdminConfig.create('DataSource')
This way, jdbc.py won't try to import configure_server.foo until 
create() is called.  By deferring that import, you should be able to 
avoid the circular import problem...

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Peter Hansen
deelan wrote:
i believe that to avoid circular refs errors remember you can 
lazy-import,  for example here i'm importing the email package:

m = __import__('email')
m

check help(__import__) for futher details.
I'm not sure what you think that does, but I don't
think it does it.
The code you show above is no more "lazy" than a simple
"import email as m" would have been, I believe.
All statements are executed as they are encountered
during import, so any that are no inside a function
or class definition, or protected by a conditional
control structure in some way, will be executed right
away, rather than lazily.
I may have misinterpreted what you were trying to say...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Peter Hansen
Brandon wrote:
Thanks, that worked to get me past the "problem".  Did you see my post
regarding my issue?  I just know that there's a "Python way" to resolve
my issue, so if anyone has a better way, I'm really interested.
Not only does it feel like a hack, it looks like one too!  Even worse!
If you mean the one you describe in your post with the Jython
code, I can't help, mainly because I can't parse it.  For
one thing I think you are using TABs instead of spaces, and
many newsreaders will eliminate leading tabs so it makes the
code pretty hard to decipher.  I could probably figure it out
anyway, except that I think you have a bug as well:
#jdbc.py
class DataSource:
def __init__(self, servername):
self.servername = servername
def create(name, connectionInfo, etc):
#Call the IBM supplied WebSphere config object
AdminConfig.create('DataSource')
This is how it looked to me.  The presumed bug is in the "create"
method definition, where you are not supplying a "self" parameter.
At least, I assume that is a method of DataSource and not
a module-level function, because in the previous code you were
trying to call ds.create() where ds was a DataSource object.
I'd probably have some ideas if you reposted with leading
spaces and explained or fixed the supposed bug.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Brandon
Peter,

You're correct about the bug.  I did need a 'self' parm...  I was just
winging the example because the actual code is pretty large.  I'm using
google groups for my posting and it didn't carry spaces through (I did
use spaces and not tabs).

The "fix" or workaround was to import __builtin__ and add the
AdminConfig reference there in configure_server_foo.py as follows:

import __builtin__
__builtin__.AdminConfig = AdminConfig

As for the indentations, substitute ~ with a space.

Hopefully, a bug free and "indented" version.  :)

#jdbc.py
class DataSource:
~~~def __init__(self, servername):
~~self.servername = servername

~~~def create(self, name, connectionInfo, etc):
~~#Call the IBM supplied WebSphere config object
~~AdminConfig.create('DataSource')

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-22 Thread Nick Coghlan
Brandon wrote:
Peter,
You're correct about the bug.  I did need a 'self' parm...  I was just
winging the example because the actual code is pretty large.  I'm using
google groups for my posting and it didn't carry spaces through (I did
use spaces and not tabs).
The "fix" or workaround was to import __builtin__ and add the
AdminConfig reference there in configure_server_foo.py as follows:
import __builtin__
__builtin__.AdminConfig = AdminConfig
As for the indentations, substitute ~ with a space.
Hopefully, a bug free and "indented" version.  :)
#jdbc.py
class DataSource:
~~~def __init__(self, servername):
~~self.servername = servername
~~~def create(self, name, connectionInfo, etc):
~~#Call the IBM supplied WebSphere config object
~~AdminConfig.create('DataSource')
Is there any particular reason DataSource can't be modified to accept a 
reference to the AdminConfig as a constructor argument? Or as a class attribute?

Alternatively, here's another trick to 'nicely' set a module global from outside 
a module:

#jdbc.py
def setAdminConfig(adm_cfg):
  global AdminConfig
  AdminConfig = adm_cfg
However, if you would prefer not to alter jdbc.py, consider trying:
import jdbc
jdbc.AdminConfig = AdminConfig
Global variables are bad karma to start with, and monkeying with __builtin__ is 
even worse :)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-23 Thread Brandon
I did the constructor thing and just didn't like it, it didn't feel
clean (I know, I know and monkeying with __builtin__ is?)

As for global, that will just make it modlue-level global (I think?)
and I have this reference in multiple modules.  I think I tried it
already, but I can't remember for sure...  Anyway, all of this got me
brainstorming and I think I've got a solution that I think is clean and
will be effective, I'll bust it out and post it here for comments.
Thanks for your input!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-23 Thread Nick Coghlan
Brandon wrote:
I did the constructor thing and just didn't like it, it didn't feel
clean (I know, I know and monkeying with __builtin__ is?)
As for global, that will just make it modlue-level global (I think?)
and I have this reference in multiple modules.  I think I tried it
already, but I can't remember for sure...  Anyway, all of this got me
brainstorming and I think I've got a solution that I think is clean and
will be effective, I'll bust it out and post it here for comments.
Thanks for your input!
Another option for you to consider:
#__main__ ( I forget the script's name)
import app_config
app_config.setConfiguration(AdminConfig)
from jdbc import DataStore
 . . .etc
#jdbc.py
from app_config import AdminConfig
. . .etc
#app_config.py
def setConfiguration(adm_cfg):
  global AdminConfig
  AdminConfig = adm_cfg
The reason the import solution was breaking for you earlier was that you were 
setting up circular imports by using your main script as the holder for the 
global configuration.

By creating a special 'configuration data' module, you can use that to store the 
data, and every module that needs it can import it without worrying about 
circular imports.

Any extra global configuration properties can be added by updating the 
'setConfiguration' function.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie namespace question

2004-12-24 Thread Alex Martelli
Peter Hansen <[EMAIL PROTECTED]> wrote:

> I'm not sure what you think that does, but I don't
> think it does it.

QOTW +1 !!!


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list