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 PostHave you used any other object-oriented languages? In other words, are you looking for help on classes as a concept or on how to do OO in python?
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 PostI would read and think deeply article like this and would really do a use case first, maybe a basic. Isolate objects and attributes/methods and code those. __init__ is just to put initial data to attributes, maybe any automatic method call to take care of calculated initializations.
Do some …
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 …
All 29 Replies
jon.kiparsky
326
Posting Virtuoso
SgtMe
46
Veteran Poster
Featured Poster
ryan461
0
Junior Poster
griswolf
304
Veteran Poster
TrustyTony
888
pyMod
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.