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
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
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/
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
[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
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
"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
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:
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
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
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
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
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__
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
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
[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
[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
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
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
And I just realized that Jython doesn't support the __builtins__
variable... :(
--
http://mail.python.org/mailman/listinfo/python-list
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
[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
[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
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
56 matches
Mail list logo