[Tutor] Proper uses of classes

frank ernest doark at mail.com
Thu Apr 4 19:01:45 CEST 2013


Sorry about the indentation guys my mail service atomatically removed it when I pasted the text (I tried to fix it by hand but it was hard to tell if I was sucessful.)
I was tring to create a list object (self) and change it using the list methods and some additional ones I will define in my class.
I wanted to create some varibles which I pass to most if not all of my methods. Two of my variables are to be passed to the class apon creation of the object and then they in turn are to be passed to all or most of the methods I create (a, b in this case.) If I make a, b nonlocal I get the message that they are already nonlocal.
I will need for debuging purposes to print my object in random places in my class.
If I did this:
> self.a = aWhat would that create (I'm thinking local variable?)?

class alist(): def __init__(self, b, a): self.mylist = list() self.mylist.append(b) self.a = a + b def appendit(self): #I need to get a in hear without passing  #it in; it must come from the init method. self.mylist.append(self.a) #(I hope I've updated the code well, I can't test it from this computer.)PS: This is not the real code that I'm Emailing: I thought I'd be better off with some simpler code that produces the same errors.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130404/da96592b/attachment.html>


More information about the Tutor mailing list