need help regarding creating a .py file and executing it using the shell(GUI).

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • suhas bose
    New Member
    • Mar 2011
    • 2

    need help regarding creating a .py file and executing it using the shell(GUI).

    hi, I've read through a couple threads related to my question but i guess i haven't been able to find the right one. so here's my question again..
    need the right format to create a .py file( actually i did create a .py file! :P but the thing is i'm not sure if it's executable). My file has a function defined in it and that is all. am i supposed to add extra commands into it before saving the file? because when i type .py file name in the shell it gives something like this..
    >>> spelling.py

    Traceback (most recent call last):
    File "<pyshell#4 >", line 1, in <module>
    spelling.py
    NameError: name 'spelling' is not defined

    i'm doing this on python2.7.1(IDL E) in windows. it's the same even with the command line..
    also, i want to know how i can input the argument after executing the file.

    the contents of the file:(it's for a spell check)

    Code:
    def spell(arg):
    	b=arg
    	a=arg
    	s=[]
    	for i in range(len(b)):
    		i=arg[i]
    		arg=arg.replace(i,'')
    		s.append(arg)
    		arg=a
    	alph=list('abcdefghijklmnopqrstuvwxyz')
    	for i in range(len(arg)):
    		i=arg[i]
    		for j in range(26):
    			j=alph[j]
    			arg=arg.replace(i,j)
    			s.append(arg)
    			arg=a
    	for i in range(len(arg)):
    		for j in range(26):
    			arg=arg[:i]+alph[j]+arg[i:]
    			s.append(arg)
    			arg=a
    		for j in range(26):
    			arg=arg+alph[j]
    			s.append(arg)
    			arg=a	
    	y=open('text.txt')
    	x=y.read()
    	x=x.split()
    	for i in s:
    		z=x.count(i)
    		if z!=0:
    			print i
    	y.close()
    Last edited by Niheel; Mar 21 '11, 08:06 PM.
  • Bishop Manu
    New Member
    • Mar 2011
    • 5

    #2
    try to import spelling.py,
    then you can call the function from the shell! :)

    Comment

    • suhas bose
      New Member
      • Mar 2011
      • 2

      #3
      thanks, but i couldn't call it that way. had to put in the lines
      if__name__=="__ main__":
      spell(raw_input (""))

      at the end.found this in someone's program :P. now it works just the way i wanted.
      this thread is answered.

      Comment

      Working...