SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Lounges / Members Lounge / Anyone know Python? Technical question.
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 26-02-2010, 07:26 PM   #1
elephantinc
Level 32 pachyderm
 
elephantinc's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 1,859
Thanks: 12
Thanked 43 Times in 37 Posts
Default Anyone know Python? Technical question.

Does anyone know how to call a function thats defined with in a class? I've tried myclass.myfunction() but that doesn't seem to work.

Any help will be greatly appreciated.
ElephantInc
elephantinc is offline   Reply With Quote
Old 26-02-2010, 08:58 PM   #2
stwert
EduSciVis-er
 
Join Date: Dec 2005
Location: Toronto
Posts: 3,373
Thanks: 74
Thanked 710 Times in 642 Posts
Default

That should be about right. Are there any parameters you need to specify, such as myclass.myfunction(var1)? What error message are you getting?

Oh yeah, and have you imported the class in your script?
stwert is offline   Reply With Quote
Old 26-02-2010, 09:46 PM   #3
elephantinc
Level 32 pachyderm
 
elephantinc's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 1,859
Thanks: 12
Thanked 43 Times in 37 Posts
Default

error:
File "/Users/Elephant_Inc/Desktop/PhAT/main.py", line 270, in <module>
commText.update(timer)
TypeError: unbound method update() must be called with commText instance as first argument (got int instance instead)

My class is commText and the function is update (that needs the timer variable)
this is the line I'm using to call it: commText.update(timer)
elephantinc is offline   Reply With Quote
Old 26-02-2010, 10:40 PM   #4
ctbram
Moderator
 
ctbram's Avatar
 
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,996
Thanks: 42
Thanked 582 Times in 532 Posts
Default

looks like you have not instantiated the commText class unless it is a static class you must instantiate it.

I have used python bit the syntax would be something like...

...
x = commText()
x.update(timer)
...
__________________
"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675

Last edited by ctbram : 06-03-2010 at 05:50 AM.
ctbram is offline   Reply With Quote
Old 26-02-2010, 11:00 PM   #5
elephantinc
Level 32 pachyderm
 
elephantinc's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 1,859
Thanks: 12
Thanked 43 Times in 37 Posts
Default

Thanks that worked
I thought just doing

commText()
commText.update(timer)

would work.

elephantinc is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.