Re: namespace question

2012-02-28 Thread Steven D'Aprano
On Tue, 28 Feb 2012 22:36:56 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Sun, 26 Feb 2012 19:47:49 +1100, Ben Finney wrote: >> >> >> An integer variable is a variable holding an integer. A string >> >> variable is a variable holding a string. A list variable is a >> >> variable ho

Re: namespace question

2012-02-28 Thread Ben Finney
Steven D'Aprano writes: > On Sun, 26 Feb 2012 19:47:49 +1100, Ben Finney wrote: > > >> An integer variable is a variable holding an integer. A string variable > >> is a variable holding a string. A list variable is a variable holding a > >> list. > > > > And Python has none of those. Its referen

Re: namespace question

2012-02-26 Thread Steven D'Aprano
On Sun, 26 Feb 2012 19:47:49 +1100, Ben Finney wrote: >> An integer variable is a variable holding an integer. A string variable >> is a variable holding a string. A list variable is a variable holding a >> list. > > And Python has none of those. Its references don't “hold” anything. Ah, but the

Re: namespace question

2012-02-26 Thread Ben Finney
Steven D'Aprano writes: > The preferred terms in Python circles are class and instance > *attributes*, not variables. Yes, full ACK. > An integer variable is a variable holding an integer. > A string variable is a variable holding a string. > A list variable is a variable holding a list. And P

Re: namespace question

2012-02-24 Thread Steven D'Aprano
On Sat, 25 Feb 2012 00:39:39 +, Mark Lawrence wrote: > On 24/02/2012 22:25, Steven D'Aprano wrote: >> On Fri, 24 Feb 2012 10:08:43 -0800, David wrote: >> >>> Your code updated to show the difference between a variable, a class >>> variable, and an instance variable. >> >> The preferred terms i

Re: namespace question

2012-02-24 Thread Mark Lawrence
On 24/02/2012 22:25, Steven D'Aprano wrote: On Fri, 24 Feb 2012 10:08:43 -0800, David wrote: Your code updated to show the difference between a variable, a class variable, and an instance variable. The preferred terms in Python circles are class and instance *attributes*, not variables. An i

Re: namespace question

2012-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2012 10:08:43 -0800, David wrote: > Your code updated to show the difference between a variable, a class > variable, and an instance variable. The preferred terms in Python circles are class and instance *attributes*, not variables. An integer variable is a variable holding an in

Re: namespace question

2012-02-24 Thread David
Your code updated to show the difference between a variable, a class variable, and an instance variable. c = [1, 2, 3, 4, 5] class TEST(): c = [5, 2, 3, 4, 5] ## class variable (TEST.c) def __init__(self): self.c = [1, 2, 3, 4, 5] ## instance variable (a.c) def add(self, c

Re: namespace question

2012-02-24 Thread Jean-Michel Pichavant
xixiliguo wrote: c = [1, 2, 3, 4, 5] class TEST(): c = [5, 2, 3, 4, 5] def add( self ): c[0] = 15 a = TEST() a.add() print( c, a.c, TEST.c ) result : [15, 2, 3, 4, 5] [5, 2, 3, 4, 5] [5, 2, 3, 4, 5] why a.add() do not update c in Class TEST? but update c in main file A

Re: namespace question

2012-02-23 Thread Chris Rebert
On Thu, Feb 23, 2012 at 9:55 PM, xixiliguo wrote: > c = [1, 2, 3, 4, 5] > class TEST(): >    c = [5, 2, 3, 4, 5] That line creates a class (i.e. "static") variable, which is unlikely to be what you want. Instance variables are normally created in the body of an __init__() method. >    def add( s

namespace question

2012-02-23 Thread xixiliguo
c = [1, 2, 3, 4, 5] class TEST(): c = [5, 2, 3, 4, 5] def add( self ): c[0] = 15 a = TEST() a.add() print( c, a.c, TEST.c ) result : [15, 2, 3, 4, 5] [5, 2, 3, 4, 5] [5, 2, 3, 4, 5] why a.add() do not update c in Class TEST? but update c in main file -- http://mail.python.or

Re: python namespace question

2010-07-13 Thread alex23
chad wrote: > I could care less about the extra blank line. I guess I was just more > concerned about the namespace question. Which is why Steven spent far more time answering that question than commenting on newline handling. Now say 'thank you'. -- http://mail.python.org/

Re: python namespace question

2010-07-13 Thread Steven D'Aprano
On Tue, 13 Jul 2010 20:52:31 -0700, Chris Rebert wrote: > The built-ins is the > namespace of last resort; it's the last one to be consulted when trying > to resolve a name in Python. You can inspect it via __builtins__ Avoid __builtins__ as it is an implementation detail. The difference between

Re: python namespace question

2010-07-13 Thread Chris Rebert
On Tue, Jul 13, 2010 at 8:03 PM, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: >    def printme(self): >        print "hello\n" > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the > printme() one? Neither. It exis

Re: python namespace question

2010-07-13 Thread chad
ce. > > BTW, print (both versions) automatically prints a newline at the end of > the output, so printing "hello\n" will end up with an extra blank line. > Is that what you wanted? > I could care less about the extra blank line. I guess I was just more concerned about the namespace question. -- http://mail.python.org/mailman/listinfo/python-list

Re: python namespace question

2010-07-13 Thread Steven D'Aprano
On Tue, 13 Jul 2010 20:03:14 -0700, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: > def printme(self): > print "hello\n" > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the printme() > one? What

Re: python namespace question

2010-07-13 Thread Shashwat Anand
On Wed, Jul 14, 2010 at 8:33 AM, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: >def printme(self): >print "hello\n" > No need to do print "hello\n", python is not C, print "hello" prints hello with a newline. Try it on interpretor. > > x = cgraph

python namespace question

2010-07-13 Thread chad
Given the following code... #!/usr/bin/python class cgraph: def printme(self): print "hello\n" x = cgraph() x.printme() Does the function print() exist in the cgraph namespace or the printme() one? -- http://mail.python.org/mailman/listinfo/python-list

Re: function local namespace question

2009-07-09 Thread Diez B. Roggisch
Dave Angel wrote: > Paul LaFollette wrote: >> Kind people, >> >> Using Python 3.1 under FreeBSD and WinXP. >> >> I've been tearing my hair out trying to solve this myself, but I need >> to ask for help. I want (for obscure reasons) to be able to log >> transactions in the namespace(s) of a scrip

Re: function local namespace question

2009-07-09 Thread Dave Angel
Paul LaFollette wrote: Kind people, Using Python 3.1 under FreeBSD and WinXP. I've been tearing my hair out trying to solve this myself, but I need to ask for help. I want (for obscure reasons) to be able to log transactions in the namespace(s) of a script. Specifically I would like to log c

Re: function local namespace question

2009-07-08 Thread Miles Kaufmann
On Jul 8, 2009, at 1:35 PM, Paul LaFollette wrote: I cannot figure out any way to get a hook into the local namespace of a user defined function. I have tried making a wrapper class that grabs the function call and then uses exec to invoke myfunction.__code__ with my own dictionaries. This run

function local namespace question

2009-07-08 Thread Paul LaFollette
Kind people, Using Python 3.1 under FreeBSD and WinXP. I've been tearing my hair out trying to solve this myself, but I need to ask for help. I want (for obscure reasons) to be able to log transactions in the namespace(s) of a script. Specifically I would like to log creation of identifiers, c

Re: Namespace question

2007-10-31 Thread Chris M
On Oct 31, 10:06 am, Frank Aune <[EMAIL PROTECTED]> wrote: > Hello, > > Is it possible writing custom modules named the same as modules in the > standard library, which in turn use the same module from the standard > library? > > Say I want my application to have a random.py module, which in turn m

Re: Fwd: Namespace question

2007-10-31 Thread Frank Aune
On Wednesday 31 October 2007 15:19:25 Andrii V. Mishkovskyi wrote: > You mean something like this: > >>>import random > >>>def foo(): > > ...print '42' > > >>>random.randit = foo > >>>random.randit() > > 42 > > am I right? > -- I was thinking more of the line: random.py: (my custom random.py

Fwd: Namespace question

2007-10-31 Thread Andrii V. Mishkovskyi
2007/10/31, Frank Aune <[EMAIL PROTECTED]>: > Hello, > > Is it possible writing custom modules named the same as modules in the > standard library, which in turn use the same module from the standard > library? > > Say I want my application to have a random.py module, which in turn must > import th

Namespace question

2007-10-31 Thread Frank Aune
Hello, Is it possible writing custom modules named the same as modules in the standard library, which in turn use the same module from the standard library? Say I want my application to have a random.py module, which in turn must import the standard library random.py module also, to get hold o

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

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 >

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: toBeImpo

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

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

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 seve

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 =

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

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 >

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

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

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

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

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:

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

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 r

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 su

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

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__

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

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

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 se

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 throug

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

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 wro

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 [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 com

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 pri

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 -- @p

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