1

I am trying to call a function defined in a class from main..how can I do that?

class file_process:
    def findb(self, id):
    ....  

def main():
  id = sys.argv[2]
 file_process.findb(id)//how to call findb function from main,this is giving an error
user1795998
  • 4,937
  • 7
  • 23
  • 23
  • You need to study up on classes and python first. You are calling a *method*, and methods want to be called on class instances. – Martijn Pieters Dec 12 '12 at 23:07
  • After you've learned a little more OOP, you might decide you want to make that function a static method: http://stackoverflow.com/questions/735975/static-methods-in-python – Chris Zeh Dec 13 '12 at 00:04

2 Answers2

3

Since finddb is a method, you need to call it on an instance of file_process:

file_process().finddb(id)

I strongly urge you to study up on Python and classes, I can recommend the Python tutorial, before you continue.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Getting the error...TypeError: __init__() takes exactly 2 arguments (1 given) ,should it be file_process().finddb(self,id) – user1795998 Dec 12 '12 at 23:15
  • @user1795998: look for a `__init__` function and see what it expects. You need to pass *something* to the `file_process()` class but we can not possibly guess what without more detail. – Martijn Pieters Dec 12 '12 at 23:48
1

You need to create an instance of your class first:

process = file_process()
process.findb(id)
Blender
  • 289,723
  • 53
  • 439
  • 496