Re: [Tutor] How do I create the equivalent of a Java class in Python?
> Erm. Shouldn't that be the following? > > class Msg: > def __init__(self,s): > self.s = s > def say(self): > if *not *self.s: print "No message" > else: print self.s Yep, its my week for making mistakes. Although this one was just a typo... My only excuse is that I'm really busy with my project at work just now so not really checking the tutor code... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I create the equivalent of a Java class in Python?
Alan Gauld wrote: > > How do I create the equivalent of a Java class in Python? I've been > looking > > at the reference, and it's been confusing to me at least. > > Adapted from my book: > > Java code: > > class Msg{ >private String txt; >public Msg(String s){ > this.txt = s; >} >public void say(){ > if (this.txt == "") > System.out.println("No message"); > else > System.out.println(this.txt); >} > } > > Python code: > > class Msg: >def __init__(self,s): > self.s = s >def say(self): > if self.s: print "No message" > else: print self.s > > Does that help? > There is more on writing classes in the OOP topic of my tutor. > > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > Erm. Shouldn't that be the following? class Msg: def __init__(self,s): self.s = s def say(self): if *not *self.s: print "No message" else: print self.s -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I create the equivalent of a Java class in Python?
> How do I create the equivalent of a Java class in Python? I've been looking> at the reference, and it's been confusing to me at least. Adapted from my book: Java code: class Msg{ private String txt; public Msg(String s){ this.txt = s; } public void say(){ if (this.txt == "") System.out.println("No message"); else System.out.println(this.txt); } } Python code: class Msg: def __init__(self,s): self.s = s def say(self): if self.s: print "No message" else: print self.s Does that help? There is more on writing classes in the OOP topic of my tutor. Alan GauldAuthor of the Learn to Program web sitehttp://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I create the equivalent of a Java class in Python?
> How do I create the equivalent of a Java class in Python? I've been > looking at the reference, and it's been confusing to me at least. You may want to look at a tutorial on classes, like: http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm Does this help? Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I create the equivalent of a Java class in Python?
> How do I create the equivalent of a Java class in Python? I've been looking > at the reference, and it's been confusing to me at least. can you clarify what you are looking for? do you want to create a class using Python, create the equivalent of a Java class using Python via Jython, accessing a preexisting Java class from Python, or what? you cannot simply write Java code in Python, but Python classes do get turned into Java classes under the covers. also, what is confusing you in the documentation? can you send a pointer to it? thanks, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How do I create the equivalent of a Java class in Python?
Hey all, How do I create the equivalent of a Java class in Python? I've been looking at the reference, and it's been confusing to me at least. Thanks, Nathan Pinno ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor