Re: Python class and variable issue(newby question!)

2013-03-29 Thread Dave Angel
On 03/29/2013 06:17 PM, Sam Berry wrote: Thanks for the responses! My issue was sorted with Benjamins post, just printing s worked. Cheers for the info though Chris, if i have any further issues il post them with some working code. In that case, you probably should add a line like: s = Non

Re: Python class and variable issue(newby question!)

2013-03-29 Thread Chris Angelico
On Sat, Mar 30, 2013 at 9:51 AM, Steven D'Aprano wrote: > On Sat, 30 Mar 2013 08:24:00 +1100, Chris Angelico wrote: > >> On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry >> wrote: >>> class test() >>> s = 1 >>> >>> def test1() >>> global s >>> s = 2 > >> That's not a global, tha

Re: Python class and variable issue(newby question!)

2013-03-29 Thread Steven D'Aprano
On Sat, 30 Mar 2013 08:24:00 +1100, Chris Angelico wrote: > On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry > wrote: >> class test() >> s = 1 >> >> def test1() >> global s >> s = 2 > That's not a global, that's a class variable. /me thwacks Chris with a halibut. Not only i

Re: Python class and variable issue(newby question!)

2013-03-29 Thread Chris Angelico
On Sat, Mar 30, 2013 at 9:17 AM, Sam Berry wrote: > Thanks for the responses! My issue was sorted with Benjamins post, just > printing s worked. > > Cheers for the info though Chris, if i have any further issues il post them > with some working code. Awesome! Always happy to help out. ChrisA -

Re: Python class and variable issue(newby question!)

2013-03-29 Thread Sam Berry
Thanks for the responses! My issue was sorted with Benjamins post, just printing s worked. Cheers for the info though Chris, if i have any further issues il post them with some working code. Sam -- http://mail.python.org/mailman/listinfo/python-list

Re: Python class and variable issue(newby question!)

2013-03-29 Thread Benjamin Kaplan
On Fri, Mar 29, 2013 at 2:12 PM, Sam Berry wrote: > Hey, > > Im new to object orientated programming and have an issue with using classes. > Im using the kivy module, a GUI creator , so posting the actual code may > confuse. But an example of what im trying to achieve is below > > class test() >

Re: Python class and variable issue(newby question!)

2013-03-29 Thread Chris Angelico
On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry wrote: > class test() > s = 1 > > def test1() > global s > s = 2 > > def test2() > global s > s = 3 > > def test3() > global s > s = 4 That's not a global, that's a class variable. But to gi

Re: Python Class

2013-02-01 Thread Rodrick Brown
On Friday, February 1, 2013, Charles Hoskinson wrote: > I'm developing an online course for beginning python programmers starting > from basic syntax through object oriented design and GUI. I'd like to > include some helpful community resources like Code Academy in the appendix > and I was wonderi

Re: Python Class

2013-02-01 Thread Steven D'Aprano
Charles Hoskinson wrote: > I'm developing an online course for beginning python programmers starting > from basic syntax through object oriented design and GUI. I'd like to > include some helpful community resources like Code Academy in the appendix > and I was wondering if this community has some

Re: Python class gotcha with scope?

2009-06-20 Thread billy
great, thanks for the quick responses :) On Jun 21, 2:41 am, Carl Banks wrote: > On Jun 20, 11:32 pm, billy wrote: > > > I don't quite understand why this happens. Why doesn't b have its own > > version of r? If r was just an int instead of a dict, then it would. > > > >>> class foo: > > > ...

Re: Python class gotcha with scope?

2009-06-20 Thread Carl Banks
On Jun 20, 11:32 pm, billy wrote: > I don't quite understand why this happens. Why doesn't b have its own > version of r? If r was just an int instead of a dict, then it would. > > >>> class foo: > > ...     r = {} > ...     def setn(self, n): > ...             self.r["f"] = n > ...>>> a = foo() >

Re: Python class gotcha with scope?

2009-06-20 Thread Vincent
On Jun 21, 2:38 pm, Vincent wrote: > On Jun 21, 2:32 pm, billy wrote: > > > > > I don't quite understand why this happens. Why doesn't b have its own > > version of r? If r was just an int instead of a dict, then it would. > > > >>> class foo: > > > ...     r = {} > > ...     def setn(self, n): >

Re: Python class gotcha with scope?

2009-06-20 Thread Vincent
On Jun 21, 2:32 pm, billy wrote: > I don't quite understand why this happens. Why doesn't b have its own > version of r? If r was just an int instead of a dict, then it would. > > >>> class foo: > > ...     r = {} > ...     def setn(self, n): > ...             self.r["f"] = n > ...>>> a = foo() >

Re: Python Class Best Practice

2007-12-12 Thread MarkE
On 4 Dec, 23:18, Rod Person <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > I've been doing python programming for about 2 years as a hobby and now > I'm finally able to use it at work in an enterprise environment. Since > I will be creating the base classes and lib

Re: Python Class Best Practice

2007-12-07 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Dec 5, 12:18 am, Rod Person <[EMAIL PROTECTED]> wrote: >> -BEGIN PGP SIGNED MESSAGE- >> Hash: SHA1 >> >> I've been doing python programming for about 2 years as a hobby and now >> I'm finally able to use it at work in an enterprise environment. Since >> I wi

Re: Python Class Best Practice

2007-12-05 Thread cptnwillard
On Dec 5, 12:18 am, Rod Person <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > I've been doing python programming for about 2 years as a hobby and now > I'm finally able to use it at work in an enterprise environment. Since > I will be creating the base classes and

Re: Python Class Best Practice

2007-12-04 Thread Pavan Mishra
On Dec 5, 4:18 am, Rod Person <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > I've been doing python programming for about 2 years as a hobby and now > I'm finally able to use it at work in an enterprise environment. Since > I will be creating the base classes and l

Re: Python Class Best Practice

2007-12-04 Thread Rod Person
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tue, 04 Dec 2007 15:51:18 -0800 Gary Herron <[EMAIL PROTECTED]> wrote: > Rod Person wrote: > > > > 1: > > class Foo(object): > > member1='' > > member2=0 > > > > def __init__(self,member1='',member2=0): > > self.member1 = member1 > >

Re: Python Class Best Practice

2007-12-04 Thread Gary Herron
Rod Person wrote: > I've been doing python programming for about 2 years as a hobby and now > I'm finally able to use it at work in an enterprise environment. Since > I will be creating the base classes and libraries I wondering which why > is consider best when creating python classes: > > 1: > cl

Re: python class methods identity?

2007-11-23 Thread Bruno Desthuilliers
Chris Mellon a écrit : > On Nov 23, 2007 1:29 AM, Roc Zhou <[EMAIL PROTECTED]> wrote: (snip) >>Since both "var" and "func" are the variable of the class object, and > > "members", not variables. > "attributes", not members !-) -- http://mail.python.org/mailman/listinfo/python-list

Re: python class methods identity?

2007-11-23 Thread Chris Mellon
On Nov 23, 2007 1:29 AM, Roc Zhou <[EMAIL PROTECTED]> wrote: > Hello, > > I'm now being confused by this segment of code: > >>> class Test: > ... var = 1 > ... def func(self): pass > ... > >>> x = Test() > >>> y = Test() > >>> x.var is y.var > True > >>> x.func is y.func > False > >>> id(x.

Re: python class methods identity?

2007-11-23 Thread limodou
On Nov 23, 2007 4:06 PM, Roc Zhou <[EMAIL PROTECTED]> wrote: > This is the result comes from the Linux. > > And the result from Windows is: > > >>> class Test: > var = 1 > def func(self): pass > >>> x = Test() > >>> y = Test() > >>> x.var is y.var > True > >>> x.func is y.func > False > >>>

Re: python class methods identity?

2007-11-23 Thread Roc Zhou
This is the result comes from the Linux. And the result from Windows is: >>> class Test: var = 1 def func(self): pass >>> x = Test() >>> y = Test() >>> x.var is y.var True >>> x.func is y.func False >>> id(x.var) 11228488 >>> id(y.var) 11228488 >>> id(x.func) 14430976 >>> id(y.func) 144336

Re: Python class method as an argument of a function in a C extension

2007-09-26 Thread mauro
On 26 Set, 19:00, Matimus <[EMAIL PROTECTED]> wrote: > > Can anybody give me an hint (or some link) on how to define > > 'aCFunction' and how to call 'self.myMethod' in the C source code? > > A python function defined in C accepts a pointer to self and a tuple > of arguments, each of which is also

Re: Python class method as an argument of a function in a C extension

2007-09-26 Thread Matimus
> Can anybody give me an hint (or some link) on how to define > 'aCFunction' and how to call 'self.myMethod' in the C source code? A python function defined in C accepts a pointer to self and a tuple of arguments, each of which is also a PyObject. If you pass a function or method, it will be inclu

Re: python class instantiation

2006-10-23 Thread Paul McGuire
"Éric Daigneault" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > It is humbling to see how simple yet powerfull python`s view on things > is +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: python class instantiation

2006-10-23 Thread Gabriel Genellina
At Monday 23/10/2006 17:56, Éric Daigneault lists wrote: >When creating a class with data members but no __init__ method. Python >deals differently with data members that are muatable and immutables. See specially items 4 and 5. And

Re: python class instantiation

2006-10-23 Thread Chetan
Éric Daigneault wrote: >Got a question for you all... > >I noticed a behaviour in python class creation that is strange, to say the >least. > >When creating a class with data members but no __init__ method. Python deals >differently with data members that are muatable and immutables. > >Ex: >class

Re: python class instantiation

2006-10-23 Thread Éric Daigneault
Fredrik Lundh wrote: > Éric Daigneault lists wrote: > > >> When creating a class with data members but no __init__ method. Python >> deals differently with data members that are muatable and immutables. >> > > no, it doesn't. it's your code that deals with them in different ways, > not

Re: python class instantiation

2006-10-23 Thread Fredrik Lundh
Éric Daigneault lists wrote: > When creating a class with data members but no __init__ method. Python > deals differently with data members that are muatable and immutables. no, it doesn't. it's your code that deals with them in different ways, not Python. > Ex: > class A(object): > stri

Re: Python Class for Apache log analysis

2006-06-09 Thread Steve Holden
And80 wrote: > Hi all, > I am looking for a python package that I could employ to analyze > Apache's log files in real time. Of course I already have found some > scripts, but most of them are outdated (python1.5), while others are > simply impossible to use for a custom application. I was looking

Re: Python Class use

2006-02-08 Thread bruno at modulix
S Borg wrote: > Hello, > > I am running Python on Mac OS X. The interpreter has been great for > learning the basics, but I would now like to be able to reuse code. > How do I write reusable code? I have done it "The Java way": write > the class, and save it to my home directory, then call it fr

Re: Python Class use

2006-02-07 Thread Magnus Lycka
Roel Schroeven wrote: > import MyModule > > x = MyModule.MyClass() > x.f() > > Or you could directly import MyClass into the global namespace like this: > > from MyModule import MyClass > > x = MyClass() > x.f() > > But that's not recommended since it clutters the global namespace and > makes

Re: Python Class use

2006-02-07 Thread Roel Schroeven
S Borg schreef: > Hello, > > I am running Python on Mac OS X. The interpreter has been great for > learning the basics, but I would now like to be able to reuse code. > How do I write reusable code? I have done it "The Java way": write > the class, and save it to my home directory, then call it

Re: Python Class use

2006-02-07 Thread Fabiano Sidler
Huh? You definitely must import that module. Then, is your homedir listed in sys.path? Greetings, F. Sidler -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Class use

2006-02-07 Thread Roy Smith
S Borg <[EMAIL PROTECTED]> wrote: > I am running Python on Mac OS X. The interpreter has been great for > learning the basics, but I would now like to be able to reuse code. Excellent. Code reuse is what it's all about! > How do I write reusable code? I have done it "The Java way": write > the c