开发者

How to call main() of a python script with arguments from mod_python.publisher?

I use a mod_python publisher function which calls the main() function of another python script with a custom built argv list. When I execute the publisher script from shell command line it works. But when I tried it through apache2 with mod_python, I get the error (shown below) that main takes no arguments.


File "/var/www/wabaServ/waba.py", line 15, in index
    aba.main([ "aba.py","-i", "-b"])

TypeError: main() takes no arguments (1 given)

main() in aba.py is defined as:

def main(argv=None):
 --code--

Note: if the list argument is not passed, aba.main() gets executed from mod_python.

The mod_python publisher function looks like:

import sys
sys.path.append("/u/scripts")
import aba
from cStringIO import StringIO

def index():

    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()
    aba.main([ "aba.py","-i", "-开发者_如何学编程b"])
    sys.stdout = old_stdout
    return(mystdout.getvalue())


The first logging statement says:

aba.main([ "aba.py","-i", "-b"])

And you say main is defined as:

def main(argv=None):

Therefore aba is passed in as the first argument into main() which takes up the argv argument and then there's no arguments left to pass that list in.

I don't think this has anything to do with mod_python.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜