By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

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

P: 2
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..

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

i'm doing this on python2.7.1(IDLE) 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)

Expand|Select|Wrap|Line Numbers
  1. def spell(arg):
  2.     b=arg
  3.     a=arg
  4.     s=[]
  5.     for i in range(len(b)):
  6.         i=arg[i]
  7.         arg=arg.replace(i,'')
  8.         s.append(arg)
  9.         arg=a
  10.     alph=list('abcdefghijklmnopqrstuvwxyz')
  11.     for i in range(len(arg)):
  12.         i=arg[i]
  13.         for j in range(26):
  14.             j=alph[j]
  15.             arg=arg.replace(i,j)
  16.             s.append(arg)
  17.             arg=a
  18.     for i in range(len(arg)):
  19.         for j in range(26):
  20.             arg=arg[:i]+alph[j]+arg[i:]
  21.             s.append(arg)
  22.             arg=a
  23.         for j in range(26):
  24.             arg=arg+alph[j]
  25.             s.append(arg)
  26.             arg=a    
  27.     y=open('text.txt')
  29.     x=x.split()
  30.     for i in s:
  31.         z=x.count(i)
  32.         if z!=0:
  33.             print i
  34.     y.close()
Mar 21 '11 #1
Share this Question
Share on Google+
2 Replies

P: 5
try to import,
then you can call the function from the shell! :)
Mar 21 '11 #2

P: 2
thanks, but i couldn't call it that way. had to put in the lines

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

Post your reply

Sign in to post your reply or Sign up for a free account.