Re: Chapter 9 Tutorial for Classes Not Working
- From: "tac-tics" <tactics40@xxxxxxxxx>
- Date: 30 Jun 2006 08:33:55 -0700
x = MyClass
xf = x.f
while True:
print xf()
Python has some VERY nasty gotchas concerning parenthesis (or lack
there of).
In the first line here, you assign x = MyClass. That means x becomes an
alias for the class MyClass..... not an object like you intended. Look
back at the tutorial. You simply left of the parenthesis.
Another time this may cause you headaches is with functions:
#!/usr/bin/python
def fun():
print "Hello world!"
if __name__ == "__main__":
fun
Run this script, and you will get no output at all. Forgetting the ()
on the end of "fun" on the last line makes the difference between
executing the function and returning a reference to it.
.
- Follow-Ups:
- Re: Chapter 9 Tutorial for Classes Not Working
- From: John Salerno
- Re: Chapter 9 Tutorial for Classes Not Working
- References:
- Chapter 9 Tutorial for Classes Not Working
- From: Tom Grove
- Chapter 9 Tutorial for Classes Not Working
- Prev by Date: Re: Way for see if dict has a key
- Next by Date: VPW: early registration deadline today!
- Previous by thread: Re: Chapter 9 Tutorial for Classes Not Working
- Next by thread: Re: Chapter 9 Tutorial for Classes Not Working
- Index(es):
Relevant Pages
|