Static functions in 2.5

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2008
Posts: 11
Reputation: darkMatter2008 is an unknown quantity at this point 
Solved Threads: 0
darkMatter2008 darkMatter2008 is offline Offline
Newbie Poster

Static functions in 2.5

 
0
  #1
Jun 11th, 2008
How do I make a static function in an Class that can be called by another object?

Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 122
Reputation: slate is an unknown quantity at this point 
Solved Threads: 30
slate slate is offline Offline
Junior Poster

Re: Static functions in 2.5

 
0
  #2
Jun 11th, 2008
Have a look at staticmethod and classmethod built ins in the python documentation.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: darkMatter2008 is an unknown quantity at this point 
Solved Threads: 0
darkMatter2008 darkMatter2008 is offline Offline
Newbie Poster

Re: Static functions in 2.5

 
0
  #3
Jun 11th, 2008
Could somebody give me a snippet of code, where two classes that exist in different files, with one is calling a user defined static method of the other.

All I can find on the internet is examples where they only work with the static method being called with in the class file. I cannot call that method from another class.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: darkMatter2008 is an unknown quantity at this point 
Solved Threads: 0
darkMatter2008 darkMatter2008 is offline Offline
Newbie Poster

Re: Static functions in 2.5

 
0
  #4
Jun 11th, 2008
This is my predicament

  1. class Object1:
  2.  
  3. @staticmethod
  4. def printDamnIT():
  5. print 'PRINT DAMN IT!' # You can see I'm getting very frustrated

Within another file

  1. import sys
  2. sys.path.append('C:\')
  3. import Object1
  4.  
  5. Object1.printDamnIT()
  6.  

Error that I am getting :-

ATTRIBUTEERROR: 'module' object has no attribute 'printDamnIT'
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Static functions in 2.5

 
0
  #5
Jun 11th, 2008
The way you are importing to need to use
Object1.Object1.printDamnIT()
to give the namespace too.
Should you find Irony, you can keep her!
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: darkMatter2008 is an unknown quantity at this point 
Solved Threads: 0
darkMatter2008 darkMatter2008 is offline Offline
Newbie Poster

Re: Static functions in 2.5

 
0
  #6
Jun 11th, 2008
Thank you very very much bumsfeld!!!!!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC