Re: [Tutor] class functions/staticmethod?

2019-08-13 Thread Cameron Simpson
On 14Aug2019 11:15, Steven D'Aprano wrote: On Wed, Aug 14, 2019 at 09:58:35AM +1000, Cameron Simpson wrote: On 11Aug2019 22:58, James Hartley wrote: >I am lacking in understanding of the @staticmethod property. >Explanation(s)/links might be helpful. I have not found the descriptions >found i

Re: [Tutor] class functions/staticmethod?

2019-08-13 Thread Steven D'Aprano
On Wed, Aug 14, 2019 at 09:58:35AM +1000, Cameron Simpson wrote: > On 11Aug2019 22:58, James Hartley wrote: > >I am lacking in understanding of the @staticmethod property. > >Explanation(s)/links might be helpful. I have not found the descriptions > >found in the Internet wild to be particularly

Re: [Tutor] class functions/staticmethod?

2019-08-13 Thread Cameron Simpson
On 11Aug2019 22:58, James Hartley wrote: I am lacking in understanding of the @staticmethod property. Explanation(s)/links might be helpful. I have not found the descriptions found in the Internet wild to be particularly instructive. You have received some answers; to me they seem detailed en

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Steven D'Aprano
Part 3. On Sun, Aug 11, 2019 at 10:58:37PM -0500, James Hartley wrote: > from collections import namedtuple > > class Foo(): > Dimensions = namedtuple('Dimensions', ['height', 'width']) > _dimensions = Dimensions(3, 4) > > def dimensions(): > print('id = {}'.format(id(Foo.

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Steven D'Aprano
Part Two. On Sun, Aug 11, 2019 at 10:58:37PM -0500, James Hartley wrote: > from collections import namedtuple > > class Foo(): > Dimensions = namedtuple('Dimensions', ['height', 'width']) > _dimensions = Dimensions(3, 4) > > def dimensions(): > print('id = {}'.format(id(Foo

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Steven D'Aprano
On Sun, Aug 11, 2019 at 10:58:37PM -0500, James Hartley wrote: > I am lacking in understanding of the @staticmethod property. > Explanation(s)/links might be helpful. I have not found the descriptions > found in the Internet wild to be particularly instructive. Given the code > below: [...] > The

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Peter Otten
James Hartley wrote: > I am lacking in understanding of the @staticmethod property. > Explanation(s)/links might be helpful. I have not found the descriptions > found in the Internet wild to be particularly instructive. Given the code > below: > =8<-- > from collections impor

[Tutor] class functions/staticmethod?

2019-08-11 Thread James Hartley
I am lacking in understanding of the @staticmethod property. Explanation(s)/links might be helpful. I have not found the descriptions found in the Internet wild to be particularly instructive. Given the code below: =8<-- from collections import namedtuple class Foo(): Dim

Re: [Tutor] class newbie

2017-07-23 Thread Michael C
thanks! On Sun, Jul 23, 2017 at 5:35 PM, Danny Yoo wrote: > On Sun, Jul 23, 2017 at 1:24 PM, Michael C > wrote: > > class mahschool: > > def print(): > > print('Say something') > > > By the way, you've chosen a name for your method that's spelled the > same as the name of the built-

Re: [Tutor] class newbie

2017-07-23 Thread Mats Wichmann
On 07/23/2017 02:42 PM, Michael C wrote: > never mind, I forgot to put 'self' in the method definition! class mahschool: def print(self): print('Say something') a = mahschool() a.print() Indeed. The error message was clear on this - but not in a way that's always instructive until

Re: [Tutor] class newbie

2017-07-23 Thread Danny Yoo
On Sun, Jul 23, 2017 at 1:24 PM, Michael C wrote: > class mahschool: > def print(): > print('Say something') By the way, you've chosen a name for your method that's spelled the same as the name of the built-in "print" function. I'd recommend you choose a different name than "print"

Re: [Tutor] class newbie

2017-07-23 Thread Michael C
never mind, I forgot to put 'self' in the method definition! class mahschool: def print(self): print('Say something') a = mahschool() a.print() On Sun, Jul 23, 2017 at 1:24 PM, Michael C wrote: > class mahschool: > def print(): > print('Say something') > > > a = mahs

[Tutor] class newbie

2017-07-23 Thread Michael C
class mahschool: def print(): print('Say something') a = mahschool() a.print() With this, I get this error: Traceback (most recent call last): File "test.py", line 8, in a.print() TypeError: print() takes 0 positional arguments but 1 was given What did I do wrong? Thank

Re: [Tutor] Class

2017-06-21 Thread Alan Gauld via Tutor
On 20/06/17 23:39, Rex Florian via Tutor wrote: > Can someone explain how Python achieves the vector addition of more than 2 > vectors > without some kind of looping? > > class Vector: >def __init__(self, a, b): >def __str__(): >def __add__(self,other): > return Vector(self.a +

[Tutor] Class

2017-06-21 Thread Rex Florian via Tutor
Hello, Below is a class I am using to comprehend how class works. The code came from tutorialspoint.com and executes correctly but I do not understand why it works. The original example defined just v1 and v2. I decided to experiment and instantiated v3. The executed the print statement yiel

Re: [Tutor] Class Inheritance

2017-02-21 Thread Peter Otten
Rafael Knuth wrote: > Hey there, > > I am trying to wrap my head around Class Inheritance in Python, and I > wrote a little program which is supposed to calculate revenues from > customers who don't get a discount (parent class) and those who get a > 30% discount (child class): > > class FullPri

Re: [Tutor] Class Inheritance

2017-02-21 Thread Alan Gauld via Tutor
On 21/02/17 09:49, Rafael Knuth wrote: > class DiscountCustomer(FullPriceCustomer): > discount = 0.7 > def calculate_discount(self, rate, hours): > print ("Your customer %s made you %s USD at a 30% discount > rate this year." % (self.customer, self.rate * rate * discount)) I meant

Re: [Tutor] Class Inheritance

2017-02-21 Thread Alan Gauld via Tutor
On 21/02/17 09:49, Rafael Knuth wrote: > class FullPriceCustomer(object): > def __init__(self, customer, rate, hours): > > > class DiscountCustomer(FullPriceCustomer): > discount = 0.7 > def calculate_discount(self, rate, hours): > > customer_one = DiscountCustomer("Customer A", 75,

[Tutor] Class Inheritance

2017-02-21 Thread Rafael Knuth
Hey there, I am trying to wrap my head around Class Inheritance in Python, and I wrote a little program which is supposed to calculate revenues from customers who don't get a discount (parent class) and those who get a 30% discount (child class): class FullPriceCustomer(object): def __init__(

Re: [Tutor] Class learning

2015-01-23 Thread Alan Gauld
On 23/01/15 01:44, jarod...@libero.it wrote: How can gave the attributes __name__ to a function? You don't Python does it for you. class Foo(object): def __init__(self): steps = {} tmp = open("rnaseq.base.ini","rb") config.readfp(tmp) readsets = pa

Re: [Tutor] Class learning

2015-01-23 Thread Danny Yoo
You are trying to use advanced features of Python, and they are not the right tool for what you're trying to do. Specifically, you're trying two things at the same time: 1. Properties, which allows method calls to look like simple variable access. 2. The __name__ special attribute on methods (

Re: [Tutor] Class learning

2015-01-23 Thread Danny Yoo
On Fri, Jan 23, 2015 at 12:37 AM, jarod...@libero.it wrote: > Thanks for the help and patience! > It is a function on the class so I suppose for read that function list I > need self.steps Where I'm wrong? > @property > def steps(self): > return [ > >

Re: [Tutor] Class learning

2015-01-23 Thread Danny Yoo
> #@property > def show(self): > ftp="\n".join([str(idx + 1) + "- " + step.__name__ for idx, step in enumerate(self.steps)]) > Questions you should be asking yourself: What is self.steps? What type is it? In the case where this breaks with an error, what is self.steps t

Re: [Tutor] Class errors

2015-01-23 Thread Patrick Thunstrom
If the code I'm seeing is correct, the problem is the class is Jobs, and you instantiated a Job, which doesn't exit. Replace one with the other in either case should fix it. On Thu, Jan 22, 2015 at 11:11 AM, jarod...@libero.it wrote: > Dear All, > > I created a class that invoke from another fi

[Tutor] Class learning

2015-01-22 Thread jarod...@libero.it
Dear All How can gave the attributes __name__ to a function? class Foo(object): def __init__(self): steps = {} tmp = open("rnaseq.base.ini","rb") config.readfp(tmp) readsets = parse_illumina_readset_file("/home/mauro/Desktop/readset.csv") @prop

Re: [Tutor] Class errors

2015-01-22 Thread Cameron Simpson
On 22Jan2015 17:11, jarod...@libero.it wrote: I created a class that invoke from another file another class I get an error that I do not understand: gobal name Job is not defined However If I see the class imported I found the class Job. Any suggestion or example on class invoke another class

Re: [Tutor] Class errors

2015-01-22 Thread Danny Yoo
On Thu, Jan 22, 2015 at 8:11 AM, jarod...@libero.it wrote: > Dear All, > > I created a class that invoke from another file another class > I get an error that I do not understand: gobal name Job is not defined Please use copy-and-paste. You just typed out the error message by hand: we can tell

[Tutor] Class errors

2015-01-22 Thread jarod...@libero.it
Dear All, I created a class that invoke from another file another class I get an error that I do not understand: gobal name Job is not defined However If I see the class imported I found the class Job. Any suggestion or example on class invoke another class #job,py class Jobs: . #trial

Re: [Tutor] class to function

2014-05-25 Thread Danny Yoo
> i am trying to understand this code: > http://nbviewer.ipython.org/gist/BenLangmead/6665861 I'm slightly familiar with the purpose of the code. It's constructing a Suffix Tree, though not in linear time. Reading the code... ah. I see. This is enumerating through all suffixes, and building it

Re: [Tutor] class to function

2014-05-25 Thread Alan Gauld
On 25/05/14 16:39, rahmad akbar wrote: Hi guys i am trying to understand this code: http://nbviewer.ipython.org/gist/BenLangmead/6665861 i understand functions quite alright . but i have no idea about classes yet. Do you understand modules? Modules contain functions and data that you can reus

Re: [Tutor] class to function

2014-05-25 Thread Alex Kleider
On 2014-05-25 09:20, R. Alan Monroe wrote: can you guys help explain. super thanks A class is like a blueprint. An instance of that class is like a house built from that blueprint. Think about it. An infinite number of houses could be constructed using those blueprints. But the architect only

Re: [Tutor] class to function

2014-05-25 Thread R. Alan Monroe
> can you > guys help explain. super thanks A class is like a blueprint. An instance of that class is like a house built from that blueprint. Think about it. An infinite number of houses could be constructed using those blueprints. But the architect only had to draw them once. __init__() is like

[Tutor] class to function

2014-05-25 Thread rahmad akbar
Hi guys i am trying to understand this code: http://nbviewer.ipython.org/gist/BenLangmead/6665861 i understand functions quite alright . but i have no idea about classes yet. the code is written using class and i could not make much sense out of it. all this init and self thingy drive me crazy. c

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread Sangeeth Saravanaraj
Peter, Spir - thanks for your time and effort! I am posting this query to few more Python mailers. Thank you, Sangeeth On Tue, Feb 25, 2014 at 5:22 AM, spir wrote: > On 02/24/2014 08:19 PM, Sangeeth Saravanaraj wrote: > >> Sorry, I should have described what I was trying! >> >> I want to cre

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread spir
On 02/24/2014 08:19 PM, Sangeeth Saravanaraj wrote: Sorry, I should have described what I was trying! I want to create a decorator which should do the following things: - When an object of the decorated class is created, the objects name (say the value of the incoming "id" argument) sho

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread Peter Otten
Sangeeth Saravanaraj wrote: > On Mon, Feb 24, 2014 at 10:53 PM, Peter Otten <__pete...@web.de> wrote: > >> Sangeeth Saravanaraj wrote: >> >> > I am trying to capture an object initiation and deletion events using >> > the __call__() and __del__() methods with the following approach. >> >> Note th

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread Sangeeth Saravanaraj
On Mon, Feb 24, 2014 at 10:53 PM, Peter Otten <__pete...@web.de> wrote: > Sangeeth Saravanaraj wrote: > > > I am trying to capture an object initiation and deletion events using the > > __call__() and __del__() methods with the following approach. > > Note that there is no guarantee that __dell__

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread Peter Otten
Sangeeth Saravanaraj wrote: > I am trying to capture an object initiation and deletion events using the > __call__() and __del__() methods with the following approach. Note that there is no guarantee that __dell__ will ever be called. Usually it is better to introduce a weakref with callback. >

[Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread Sangeeth Saravanaraj
I am trying to capture an object initiation and deletion events using the __call__() and __del__() methods with the following approach. class A(object): def __init__(self, klass): print "A::__init__()" self._klass = klass def __call__(self): print "A::__call__()"

Re: [Tutor] class variables

2013-12-21 Thread eryksun
On Sat, Dec 21, 2013 at 12:40 PM, Steven D'Aprano wrote: > On Sat, Dec 21, 2013 at 08:41:17AM -0500, eryksun wrote: >> >> >>> vars(type)['__base__'] >> > > Oooh, nice! I always forget about vars(), and end up messing about with > __dict__. It's a bit more efficient to use the __dict__ at

Re: [Tutor] class variables

2013-12-21 Thread Steven D'Aprano
On Sat, Dec 21, 2013 at 08:41:17AM -0500, eryksun wrote: > On Sat, Dec 21, 2013 at 2:14 AM, Steven D'Aprano wrote: > > > > (Sometimes, people will call them "members", especially if they are used > > to C#. The meaning here is member as in an arm or leg, as in > > "dismember", not member in the se

Re: [Tutor] class variables [was Tutor Digest, Vol 118, Issue 99]

2013-12-21 Thread Steven D'Aprano
(I fixed the subject line for you.) On Sat, Dec 21, 2013 at 02:53:28AM -0500, Keith Winston wrote: > On Sat, Dec 21, 2013 at 2:14 AM, wrote: > > > I don't like the terms "class variable" and "instance variable". In the > > Python community, these are usually called class and instance attributes

Re: [Tutor] class variables

2013-12-21 Thread eryksun
On Sat, Dec 21, 2013 at 2:14 AM, Steven D'Aprano wrote: > > (Sometimes, people will call them "members", especially if they are used > to C#. The meaning here is member as in an arm or leg, as in > "dismember", not member in the sense of belonging to a group.) A Python object isn't just a fixed-s

Re: [Tutor] class variables

2013-12-20 Thread Steven D'Aprano
On Fri, Dec 20, 2013 at 02:04:49AM -0500, Keith Winston wrote: > I am a little confused about class variables: I feel like I've repeatedly > seen statements like this: I don't like the terms "class variable" and "instance variable". In the Python community, these are usually called class and inst

Re: [Tutor] class variables

2013-12-20 Thread eryksun
On Fri, Dec 20, 2013 at 5:20 AM, Alan Gauld wrote: > > Similarly if you have a name defined within the instance it will use that if > not it will look in the class. An instance can generally shadow class attributes, except properties and other data descriptors defined by the class are given prece

Re: [Tutor] class variables

2013-12-20 Thread Alan Gauld
On 20/12/13 07:04, Keith Winston wrote: Class.pi == 3.14 # defined/set in the class def instance.pi == 3.14 # initially instance.pi = 4 # oops, changed it Class.pi == 3.14 # still Class.pi = "rhubarb" # oops, there I go again instance.pi == 4 # still Sorry if I'm beating this to a pulp, I

Re: [Tutor] class variables

2013-12-20 Thread Dominik George
Hi, > I am a little confused about class variables: I feel like I've repeatedly > seen statements like this: please take a look at the archives - this topic has been discussed on this list recently. -nik -- * mirabilos is handling my post-1990 smartphone * Aaah, it vibrates! Wherefore art tho

[Tutor] class variables

2013-12-20 Thread Keith Winston
I am a little confused about class variables: I feel like I've repeatedly seen statements like this: There is only one copy of the class variable and when any one object makes a change to a class variable, that change will be seen by all the other instances. Object variables are owned by each indi

Re: [Tutor] Class attribute error

2013-11-17 Thread Reuben
Hi, Thanks for correcting me. The solutions mentioned by Dominik and Alan have simplified the concept to me now. Regards, Reuben On Sun, Nov 17, 2013 at 5:25 AM, Dominik George wrote: > On Sat, Nov 16, 2013 at 09:13:13AM -0800, reutest wrote: > > class myclass(): > > > > def test(

Re: [Tutor] Class attribute error

2013-11-16 Thread Alan Gauld
On 16/11/13 17:13, reutest wrote: class myclass(): def test(self): print "print this line" if __name__ == '__main__': myclass.run() If you have a question it helps if you ask it rather than have us guess. In this case I'm guessin

Re: [Tutor] Class attribute error

2013-11-16 Thread Dominik George
On Sat, Nov 16, 2013 at 09:13:13AM -0800, reutest wrote: > class myclass(): > > def test(self): > print "print this line" > > > if __name__ == '__main__': > myclass.run() Is that a question? If I were to guess, I'd say you sho

[Tutor] Class attribute error

2013-11-16 Thread reutest
class myclass(): def test(self): print "print this line" if __name__ == '__main__': myclass.run() -- View this message in context: http://python.6.x6.nabble.com/Class-attribute-error-tp5039199.html Sent from the Pyth

Re: [Tutor] class decorator question

2013-10-06 Thread Albert-Jan Roskam
- Original Message - > From: Steven D'Aprano > To: tutor@python.org > Cc: > Sent: Sunday, October 6, 2013 4:52 AM > Subject: Re: [Tutor] class decorator question > > On Sat, Oct 05, 2013 at 12:26:14PM -0700, Albert-Jan Roskam wrote: > >> >

Re: [Tutor] class decorator question

2013-10-06 Thread Mark Lawrence
On 06/10/2013 03:58, Steven D'Aprano wrote: On Sun, Oct 06, 2013 at 01:06:18AM +0100, Alan Gauld wrote: On 05/10/13 20:26, Albert-Jan Roskam wrote: General question: I am using pastebin now. Is that okay, For code as short as this it's probably best kept with the message. But once you get to

Re: [Tutor] class decorator question

2013-10-05 Thread Steven D'Aprano
On Sun, Oct 06, 2013 at 01:06:18AM +0100, Alan Gauld wrote: > On 05/10/13 20:26, Albert-Jan Roskam wrote: > > >General question: I am using pastebin now. Is that okay, > > For code as short as this it's probably best kept with the message. > But once you get to 100+ lines its more debatable and i

Re: [Tutor] class decorator question

2013-10-05 Thread Steven D'Aprano
On Sat, Oct 05, 2013 at 12:26:14PM -0700, Albert-Jan Roskam wrote: > >> On http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/ I saw > >> a very cool and useful example of a class decorator. It (re)implements > >> __str__ and __unicode__ in case Python 2 is used. For Python 3, the > >>

Re: [Tutor] class decorator question

2013-10-05 Thread Alan Gauld
On 05/10/13 20:26, Albert-Jan Roskam wrote: General question: I am using pastebin now. Is that okay, For code as short as this it's probably best kept with the message. But once you get to 100+ lines its more debatable and if you get to 200+ lines I'd definitely say a pastebin is better. fro

Re: [Tutor] class decorator question

2013-10-05 Thread Albert-Jan Roskam
___ > From: Steven D'Aprano >To: tutor@python.org >Sent: Saturday, October 5, 2013 3:14 PM >Subject: Re: [Tutor] class decorator question > >On Sat, Oct 05, 2013 at 05:33:46AM -0700, Albert-Jan Roskam wrote: >> Hi, >> >> On

Re: [Tutor] class decorator question

2013-10-05 Thread Steven D'Aprano
On Sat, Oct 05, 2013 at 05:33:46AM -0700, Albert-Jan Roskam wrote: > Hi, > > On http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/ I saw > a very cool and useful example of a class decorator. It (re)implements > __str__ and __unicode__ in case Python 2 is used. For Python 3, the > dec

[Tutor] class decorator question

2013-10-05 Thread Albert-Jan Roskam
Hi, On http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/ I saw a very cool and useful example of a class decorator. It (re)implements __str__ and __unicode__ in case Python 2 is used. For Python 3, the decorator does nothing. I wanted to generalize this decorator so the __str__ metho

Re: [Tutor] class data member and objects of class in python

2013-09-12 Thread Dave Angel
On 12/9/2013 05:10, zubair alam wrote: > class PizzaShop():    pizza_stock = > 10    def get_pizza(self):        while > PizzaShop.pizza_stock:            PizzaShop.pizza_stock -= > 1            yield "take yours pizza order, total pizzas left > {}".format(PizzaShop.pizza_stock) > mypizza_sho

Re: [Tutor] class data member and objects of class in python

2013-09-12 Thread Alan Gauld
On 12/09/13 10:10, zubair alam wrote: class PizzaShop(): pizza_stock = 10 def get_pizza(self): while PizzaShop.pizza_stock: PizzaShop.pizza_stock -= 1 yield "take yours pizza order, total pizzas left {}".format(PizzaShop.pizza_stock) mypizza_shop = Pi

Re: [Tutor] class data member and objects of class in python

2013-09-12 Thread zubair alam
class PizzaShop(): pizza_stock = 10 def get_pizza(self): while PizzaShop.pizza_stock: PizzaShop.pizza_stock -= 1 yield "take yours pizza order, total pizzas left {}".format(PizzaShop.pizza_stock) mypizza_shop = PizzaShop() pizza_order = mypizza_shop.get_pizz

Re: [Tutor] class data member and objects of class in python

2013-09-12 Thread Felix Dietrich
> i am learning how a __class__ data member behaves in python as > compared to static data member in java [...] The error is not related to class variables. Also could you elaborate on what you intended to find out with this snippet? > class PizzaShop(): > pizza_stock = 10 > > def get_pi

Re: [Tutor] class data member and objects of class in python

2013-09-11 Thread Marc Tompkins
On Wed, Sep 11, 2013 at 5:40 AM, zubair alam wrote: > i am learning how a __class__ data member behaves in python as compared to > static data member in java, but following code is throwing error > > > class PizzaShop(): > pizza_stock = 10 > def get_pizza(self): > while not PizzaSh

[Tutor] class data member and objects of class in python

2013-09-11 Thread zubair alam
i am learning how a __class__ data member behaves in python as compared to static data member in java, but following code is throwing error class PizzaShop(): pizza_stock = 10 def get_pizza(self): while not PizzaShop.pizza_stock: PizzaShop.pizza_stock -= 1

Re: [Tutor] Class-based generator

2013-02-18 Thread Peter Otten
Michael O'Leary wrote: > I wrote some code to create tasks to be run in a queue based system last > week. It consisted of a big monolithic function that consisted of two > parts: 1) read data from a file and create dictionaries and lists to > iterate through > 2) iterate through the lists creating

Re: [Tutor] Class-based generator

2013-02-18 Thread Oscar Benjamin
On 18 February 2013 07:36, Michael O'Leary wrote: > I wrote some code to create tasks to be run in a queue based system last > week. It consisted of a big monolithic function that consisted of two parts: > 1) read data from a file and create dictionaries and lists to iterate > through > 2) iterate

[Tutor] Class-based generator

2013-02-17 Thread Michael O'Leary
I wrote some code to create tasks to be run in a queue based system last week. It consisted of a big monolithic function that consisted of two parts: 1) read data from a file and create dictionaries and lists to iterate through 2) iterate through the lists creating a job data file and a task for th

Re: [Tutor] 'class' for someone with no object oriented programming experience

2012-09-11 Thread Brannon, Terrence
From: Tutor [mailto:tutor-bounces+terrence.brannon=bankofamerica@python.org] On Behalf Of Art Scheel Sent: Tuesday, September 11, 2012 3:34 PM To: tutor@python.org Subject: [Tutor] 'class' for someone with no object oriented programming experience Are there any better res

Re: [Tutor] Class definition confusion

2012-02-15 Thread Mark Lawrence
On 15/02/2012 18:35, Hugo Arts wrote: [snip] An __init__ might seem like it's special in some way, declaring attributes. But it's not, really, it's just another method that gets passed the object it is called on (that would be "self"). It's only special because it gets called when an object is c

Re: [Tutor] Class definition confusion

2012-02-15 Thread Mark Lawrence
On 15/02/2012 18:14, Sivaram Neelakantan wrote: I was under the impression that you have to define the attributes of the class before using it in an instance. Following the book 'thinking in Python', class Point: ... """pts in 2d space""" ... print Point __main__.Point b = Point() b.x

Re: [Tutor] Class definition confusion

2012-02-15 Thread Sivaram Neelakantan
On Thu, Feb 16 2012,Alan Gauld wrote: [snipped 19 lines] > Python allows instance attributes to be added at runtime. > In general this is a bad idea IMHO, a dictionary would probably > be more appropriate, but there can, very occasionally, be valid > uses for it. Thanks for that, I kept thinkin

Re: [Tutor] Class definition confusion

2012-02-15 Thread Hugo Arts
On Wed, Feb 15, 2012 at 7:14 PM, Sivaram Neelakantan wrote: > > I was under the impression that you have to define the attributes of > the class before using it in an instance.  Following the book > 'thinking in Python', > class Point: > ...     """pts in 2d space""" > ... print Point >

Re: [Tutor] Class definition confusion

2012-02-15 Thread Alan Gauld
On 15/02/12 18:14, Sivaram Neelakantan wrote: I was under the impression that you have to define the attributes of the class before using it in an instance. Only in some languages. Python is not one of those. class Point: ... """pts in 2d space""" ... b = Point() b.x =3 b.y =4 print b.

[Tutor] Class definition confusion

2012-02-15 Thread Sivaram Neelakantan
I was under the impression that you have to define the attributes of the class before using it in an instance. Following the book 'thinking in Python', >>> class Point: ... """pts in 2d space""" ... >>> print Point __main__.Point >>> b = Point() >>> b.x =3 >>> b.y =4 >>> print b.y 4 >>> Why

Re: [Tutor] Class Nesting

2012-02-06 Thread Steven D'Aprano
On Mon, Feb 06, 2012 at 08:17:05PM -0500, Greg Nielsen wrote: [...] > So here is the problem, to create an object, you need to assign it to > a variable, and you need to know what that variable is to call upon it > later, so to have a object build a second object, it would need to somehow > cr

Re: [Tutor] Class Nesting

2012-02-06 Thread Dave Angel
On 02/06/2012 08:17 PM, Greg Nielsen wrote: Hello List, My name is Greg, and while working on a project I've come across a rather interesting problem. I'm trying to create a rough model of a star cluster and all of the stars and planets contained within. Kind of a cool project; hopefully i

[Tutor] Class Nesting

2012-02-06 Thread Greg Nielsen
Hello List, My name is Greg, and while working on a project I've come across a rather interesting problem. I'm trying to create a rough model of a star cluster and all of the stars and planets contained within. Kind of a cool project; hopefully it should work a little like this. I create a St

Re: [Tutor] Class vs. instance

2012-01-18 Thread Alan Gauld
On 18/01/12 02:13, Stayvoid wrote: class A: def __init__(self, data): self.data = data print self.data I'm trying to understand this function-like syntax: A('foo').__init__(42) You would not normally call any method with a double underscore pre/poist f

Re: [Tutor] Class vs. instance

2012-01-17 Thread Dave Angel
On 01/17/2012 09:13 PM, Stayvoid wrote: Hello! Here is another one. class A: def __init__(self, data): self.data = data print self.data I'm trying to understand this function-like syntax: A('foo').__init__(42) A(12).data What are we actually calling thi

Re: [Tutor] Class vs. instance

2012-01-17 Thread Stayvoid
Hello! Here is another one. class A: def __init__(self, data): self.data = data print self.data I'm trying to understand this function-like syntax: A('foo').__init__(42) A(12).data What are we actually calling this way? Are there any other ways to get the

Re: [Tutor] Class vs. instance

2012-01-01 Thread Stayvoid
Thanks. I totally get it now. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Class vs. instance

2012-01-01 Thread Hugo Arts
On Sun, Jan 1, 2012 at 8:40 PM, Stayvoid wrote: > Hi there! > class Sample:     def method(self): pass > Sample().method() > > What's the difference between class __main__.Sample and > __main__.Sample instance? > Why should I write "Sample().method" instead of "Sample.method"? > Th

[Tutor] Class vs. instance

2012-01-01 Thread Stayvoid
Hi there! >>> class Sample: >>> def method(self): pass >>> Sample().method() What's the difference between class __main__.Sample and __main__.Sample instance? Why should I write "Sample().method" instead of "Sample.method"? Cheers! ___ Tutor mail

Re: [Tutor] Class methods

2011-06-27 Thread Alan Gauld
"David Merrick" wrote Is it possible too have crit1 = Critter("Dave") crit2 = Critter("Sweetie") farm = [crit1,crit2] #List# and then be able to use Critters methods on farm? No, Marc has already answered that. class Critter(object): """A virtual pet""" def __init__(self, name, hu

Re: [Tutor] Class methods

2011-06-26 Thread Marc Tompkins
On Sun, Jun 26, 2011 at 7:12 PM, David Merrick wrote: > Is it possible too have > > crit1 = Critter("Dave") > crit2 = Critter("Sweetie") > farm = [crit1,crit2] #List# > > and then be able to use Critters methods on farm? > > No. farm is a list, and lists don't inherit the methods of the objects

[Tutor] Class methods

2011-06-26 Thread David Merrick
Is it possible too have crit1 = Critter("Dave") crit2 = Critter("Sweetie") farm = [crit1,crit2] #List# and then be able to use Critters methods on farm? # Critter Caretaker # A virtual pet to care for class Critter(object): """A virtual pet""" def __init__(self, name, hunger = 0, bore

Re: [Tutor] Class methods

2011-06-22 Thread Alan Gauld
"David Merrick" wrote Can someone show me how to code this correctly please? We've been doing that but you are still making some very basic mistakes which reflect a deep misunderastanding of what you are doing. You really should take several steps back and review the use of variables and fun

Re: [Tutor] Class methods

2011-06-22 Thread Alan Gauld
"michael scott" wrote you are using python 3 by your print statements, so I don't think you need the int() around your input, Yes he does because in Python 3 input is the same as raw_input in Python 2 even in python.2x input() was safe for numbers I believe (the whole list will rip my

Re: [Tutor] Class methods

2011-06-22 Thread michael scott
yer know which one he is feeding / talking to / playing with in your farmlet? Anyways best of luck in your program, sounds pretty cool...   What is it about you... that intrigues me so? From: Alexandre Conrad To: David Merrick Cc: tutor@python.org Sen

Re: [Tutor] Class methods

2011-06-22 Thread Alexandre Conrad
David, 2011/6/22 David Merrick : >     # listen to your critter >     elif choice == "1": >     for critter in farmlet: >     farmlet.talk() You want to call .talk() on your "critter" instance which has the .talk() method, not on farmlet (which is a list as the error m

[Tutor] Class methods

2011-06-22 Thread David Merrick
Can someone show me how to code this correctly please? # Critter Caretaker # A virtual pet to care for class Critter(object): """A virtual pet""" def __init__(self, name, hunger = 0, boredom = 0): self.name = name self.hunger = hunger self.boredom = boredom #

Re: [Tutor] Class methods

2011-06-22 Thread Alan Gauld
"David Merrick" wrote class Critter(object): def __init__(self, name, hunger = 0, boredom = 0): def __pass_time(self): def __str__(self): @property def mood(self): def talk(self): def eat(self): def play(self): class Farm(Critter): I still don't think a Farm is a typ

[Tutor] Class methods

2011-06-21 Thread David Merrick
# Critter Caretaker # A virtual pet to care for class Critter(object): """A virtual pet""" def __init__(self, name, hunger = 0, boredom = 0): self.name = name self.hunger = hunger self.boredom = boredom # __ denotes private method def __pass_time(self):

Re: [Tutor] class question

2011-01-26 Thread ALAN GAULD
> >>I'm not sure I follow that bit. > > Say you have a master part, # 3245671, this is sort of a "primary machined >number". > > On the blueprint for this part, there will be certain features that don't > have >any dimensional > > information, but instead have a callout of some kind, i

Re: [Tutor] class question

2011-01-26 Thread Steven D'Aprano
Elwin Estle wrote: --- On Wed, 1/26/11, Alan Gauld wrote: From: Alan Gauld Subject: Re: [Tutor] class question To: tutor@python.org Date: Wednesday, January 26, 2011, 1:10 PM Is this really a series of different types of casting or a single Workpiece going through a sequence of Actions each

Re: [Tutor] Class Docs - how much is too much?

2011-01-26 Thread Tim Johnson
* Emile van Sebille [110126 12:30]: > On 1/26/2011 11:03 AM Tim Johnson said... >> >> I've developed a module which necessitates a very large amount of >> documentation. At this point all of the documentation is in the >> class docstring. I'm thinking that perhaps I should pare down the >> docstri

Re: [Tutor] Class Docs - how much is too much?

2011-01-26 Thread Emile van Sebille
On 1/26/2011 11:03 AM Tim Johnson said... FYI: I'm currently using version 2.6.5 I've developed a module which necessitates a very large amount of documentation. At this point all of the documentation is in the class docstring. I'm thinking that perhaps I should pare down the docstring and deliv

Re: [Tutor] class question

2011-01-26 Thread Elwin Estle
--- On Wed, 1/26/11, Alan Gauld wrote: From: Alan Gauld Subject: Re: [Tutor] class question To: tutor@python.org Date: Wednesday, January 26, 2011, 1:10 PM >>Is this really a series of different types of casting or a single Workpiece >>going through a sequence of Actions >>

  1   2   3   4   5   >