How do I make a static function in an Class that can be called by another object?

Thanks in advance.

Recommended Answers

All 5 Replies

Have a look at staticmethod and classmethod built ins in the python documentation.

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

This is my predicament

class Object1:

	@staticmethod
	def printDamnIT():
		print 'PRINT DAMN IT!' # You can see I'm getting very frustrated

Within another file

import sys
sys.path.append('C:\')
import Object1

Object1.printDamnIT()

Error that I am getting :-

ATTRIBUTEERROR: 'module' object has no attribute 'printDamnIT'

The way you are importing to need to use
Object1.Object1.printDamnIT()
to give the namespace too.

Thank you very very much bumsfeld!!!!!!

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.