LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-20-2004, 07:40 PM   #1
rmanocha
Member
 
Registered: Oct 2003
Location: Austin,TX
Distribution: Debian SID-->fully content-->Love APT,kernel 2.6.4
Posts: 327

Rep: Reputation: 30
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
 
Old 11-21-2004, 12:00 AM   #2
doublefailure
Member
 
Registered: Mar 2002
Location: ma
Distribution: slackware
Posts: 747

Rep: Reputation: 30
i think you only supply 'self' argument in class functions.

hope it helps
 
Old 11-21-2004, 12:04 AM   #3
rmanocha
Member
 
Registered: Oct 2003
Location: Austin,TX
Distribution: Debian SID-->fully content-->Love APT,kernel 2.6.4
Posts: 327

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python gui file dialog question mulciber Programming 0 07-26-2005 07:37 AM
Python Question - moving file across filesystems drj000 Programming 3 01-26-2005 11:36 AM
What function does linux call to save a file ? lostboy Programming 2 06-04-2004 03:03 PM
simple python function question Tyir Programming 2 03-28-2004 10:53 PM
newbie python question: doing more than one thing in a for loop SerfurJ Programming 1 03-18-2004 10:14 AM


All times are GMT -5. The time now is 03:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration