How to call script in interative status
Fu Chen
novalet at yahoo.com.cn
Thu Feb 27 22:21:01 EST 2003
yes, i write the script like below
#######################################################
def main():
import getopt
try:
opts, args = getopt.getopt(sys.argv[1:], "slc:d:e:")
except getopt.error, why:
print why
print usage % (os.path.basename(sys.argv[0],))
return
bCallback = 0
if args or not opts:
print usage % (os.path.basename(sys.argv[0],))
return
for opt, val in opts:
if opt=="-s":
bCallback = 1
if opt=="-l":
ShowConnections()
if opt=="-c":
hras, rc = Connect(val, bCallback)
if hras != None:
print "hras: 0x%8lx, rc: 0x%04x" % ( hras, rc )
if opt=="-d":
Disconnect(val)
if opt=="-e":
EditEntry(val)
if __name__=='__main__':
main()
######################################################
then in the command line >>>, how can i run it with args?
import script
script.main()
but where is the args to input?
I know i can press ctrl-R in pythonwin to invoke a dialog to enter the
args, but i hate it if i have to run it several times.
Steven Taschuk <staschuk at telusplanet.net> wrote in message news:<mailman.1046368237.24643.python-list at python.org>...
> Quoth Fu Chen:
> > Hi!
> >
> > I use python under windows2k.
> > Uptonow i only call script by
> > python script.py arg1 arg2
> >
> > My question is can we call a script under the interative status ( >>>
> > ) and how to do ? it seems possible to import a script and call its
> > function like script.func, but how to run the segment marked by name
> > == '__MAIN__' ?
>
> Usually the best thing is to write the script like this:
>
> def do_something():
> ...
> if __name__ == '__main__':
> do_something()
>
> Then it can be run programmatically by importing it and calling
> do_something.
>
> Alternatively, there's all the process management functions in the
> os module.
More information about the Python-list
mailing list