2012-04-03 2 views
1

web.py를 사용하여 몇 가지 큰 라이브러리에 대한 http 인터페이스를 작성하고 옵션 매개 변수를 사용하는 명령 행 스크립트를 제공하고 싶습니다.맞춤 cmd 옵션을 사용하여 web.py 앱 실행

optparse와 함께 간단한 web.py 튜토리얼 예제를 만들었을 때 web.py가 항상 원하는 첫 번째 cmd 인수를 포트로 사용한다는 문제가 있습니다. web-py가 명령 행 인자를 검사하지 않도록 지시 할 수있는 방법이 있는가?

나는대로 실행하려는
#!/usr/bin/env python 
# encoding: utf-8 
""" 
web_interface.py: A simple Web interface 

""" 

import optparse 
import web 

urls = ("/.*", "hello") 
app = web.application(urls, globals()) 

class hello: 
    def GET(self): 
     return 'Hello, world!\n' 

if __name__ == "__main__": 
    p = optparse.OptionParser() 
    p.add_option('--test', '-t', help="the number of seed resources") 
    options, arguments = p.parse_args() 
    print options.test 
    app.run() 

...은 다음과 같습니다 :

python web_interface.py -t 10 

답변

0

그것은 해킹의 비트,하지만 난 당신이 할 수있는 것 같아요 :

import sys 
... 

if __name__ == "__main__": 
    p = optparse.OptionParser() 
    p.add_option('--test', '-t', help="the number of seed resources") 
    options, arguments = p.parse_args() 
    print options.test 

    # set sys.argv to the remaining arguments after 
    # everything consumed by optparse 
    sys.argv = arguments 

    app.run() 
다음은 그 예이다