I've got a couple of pdf's on python, but im having trouble grasping how to build classes. Was trying to do it for a poker program and i think im in over my head with that idea. (its a bit big just doing it with functions). So id like an exercise that can get me into them and understand them more.
ryan461 0 Junior Poster
Recommended Answers
Jump to PostWhy don't you make like a text-based shopping checkout program? You can have a main class filled with all the main functions, like a welcome, ouput priter etc.
Then you can have an object class. It can have variables like name, price, quantity, etc. Then you can make new objects …
Jump to PostYou might look here:
http://wiki.python.org/moin/BeginnersGuide
http://pytut.infogami.com/node11-baseline.htmlMy own basic take on classes: A class is a description of a data holder along with the things you might want to do to …
Jump to Postwoops. My bad. This is why we need constructors... I was just typing, not actually trying. I should learn. This code works (but :hasattr isn't a good introduction to classes)
class SimpleMessageClass: def setMessage(self, message): self.message = message def printMessage(self): if hasattr(self,'message'): print(self.message) else: print("Sorry, I have no …
Jump to PostHmm...
Change all theshopping.????(self)
toself.????()
And from what I see, your program is impossibly recursive...shopping(Make(shopping( #make instance, then shopping again, etc
How are you running it?EDIT:
Also you are missing some colons and there're some syntax errors.
Just copy and paste the code that you …
Jump to PostYes i did re write it. im doing it on a box with no internet. so i looked at the screen and typed it on this one.
I see.
This is a big challenge to help you with, because we don't have the entire code.Are you sure there …
All 29 Replies
jon.kiparsky 326 Posting Virtuoso
SgtMe 46 Veteran Poster Featured Poster
ryan461 0 Junior Poster
griswolf 304 Veteran Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
ryan461 0 Junior Poster
ryan461 0 Junior Poster
griswolf 304 Veteran Poster
ryan461 0 Junior Poster
jcao219 18 Posting Pro in Training
ryan461 0 Junior Poster
jcao219 18 Posting Pro in Training
ryan461 0 Junior Poster
jcao219 18 Posting Pro in Training
jcao219 18 Posting Pro in Training
ryan461 0 Junior Poster
ryan461 0 Junior Poster
jcao219 18 Posting Pro in Training
ryan461 0 Junior Poster
jcao219 18 Posting Pro in Training
ryan461 0 Junior Poster
griswolf 304 Veteran Poster
ultimatebuster 14 Posting Whiz in Training
ryan461 0 Junior Poster
ryan461 0 Junior Poster
jcao219 18 Posting Pro in Training
ryan461 0 Junior Poster
jcao219 18 Posting Pro in Training
ryan461 0 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.