[Tutor] ASP And Python - Calling Python Scripts from within the web page

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Aug 4 21:49:56 CEST 2005

> 	sys.argv = [ 'junk', '-u jgooch.admin' ]

Hi John,

The code highlighted above looks unusual.  Can you explain why the code
assigns to sys.argv?

Ah, ok, I assume that you're trying to pass state with the 'chgpwd_enq'

> 	transid = chgpwd_enq.main()

If so, you may want to do this more directly, by modifying
chgpwd_enq.main() to take in arguments.  For example, something like this:

    chgpwd_enq.main('junk', user='jgooch.admin')

Using sys.argv to pass state between the two Python programs is slightly
weird because there are easier mechanisms such as direct parameter passing
between functions.

> Transaction ID is None. If I run the "chgpwd_enq.py" script in a command
> window, it works fine. But it is not doing anything when run as from the
> ASP page.
> I am guessing that the sys.argv is not working as intended, but it is
> hard to tell as I am not getting any response from the called Python
> script.

The bug here is that sys.argv should contain three arguments:

    sys.argv = [ 'junk', '-u', 'jgooch.admin' ]

But even so, the whole mechanism of passing state between the ASP page and
the chgpwd_enq program with sys.argv sounds weird: it may be more direct
to call chgpwd_enq.main() with those arguments instead.

Good luck!

More information about the Tutor mailing list