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
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
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
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
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
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
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
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
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
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
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
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
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
>
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
"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)
>>
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
[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 =
> "[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
[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
>
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
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
"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
22 matches
Mail list logo