LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python call function in same file(very newbie question) (https://www.linuxquestions.org/questions/programming-9/python-call-function-in-same-file-very-newbie-question-257407/)

rmanocha 11-20-2004 07:40 PM

python call function in same file(very newbie question)
 
hey guys,
I have just started writing some code in python and have hit a wall on a very basic question.
I basically want to call a function I have written. My code is something like this:
Code:

if __name__ = "__main__"
      try:
                username = sys.argv[1]
        except IndexError:
                print "%d" % self.mySyntax()
                sys.exit(2)

mySyntax() is a function i have written in the same file and it goes like this:
Code:

        def mySyntax(self):
              result = blah...blah...blah
              return result

When i run this, i get:
Code:

Traceback (most recent call last):
  File "./mdirgmail.py", line 37, in ?
    print "%d" % self.mySyntax()
NameError: name 'self' is not defined

Can someone please suggest a fix for this.
Thanks

doublefailure 11-21-2004 12:00 AM

i think you only supply 'self' argument in class functions.

hope it helps

rmanocha 11-21-2004 12:04 AM

i have tried it without self too:
Code:

if __name__ = "__main__"
      try:
                username = sys.argv[1]
        except IndexError:
                print "%d" % mySyntax()
                sys.exit(2)

I have tried to define mySyntax inside the if statement as well as outside and neither work.
Being a Java developer, my first instince was using self(like this in Java). I have tried all other options though and still cant seem to get past this small problem.
If someone wants to have a look, you can check out the file at: http://cvs.sourceforge.net/viewcvs.p...v=1.1&view=log

I would really appreciate some help in getting past this problem. Thanks


All times are GMT -5. The time now is 02:52 PM.