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

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

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

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