开发者

How can I use a positional argument with a space in it in Pythonbrew?

I have been using the argparse module for accepting input into a program, with much success. I have defined about six optional argum开发者_高级运维ents (arguments that need to be prepended with a -- can be placed anywhere in the list) and one positional argument (required arguments that use the order placed to determine the argument), so my usage chart looks like this (with extra optional arguments removed for brevity):

usage: Main.py [-h] [--site SITE] [--username USERNAME] [--password PASSWORD]
           [--verbose]
           filepath

In order to run a Python 2.7 script on Debian (which ships with Python 2.6), I have had success using pythonbrew, which allows multiple Python installations to co-exist on the same server. A nice side effect of using it means that I can turn off executable permissions on my script, which makes user management much easier for me.

All was well, until I tried to store to a filepath (my lone positional argument) that had a space in it, and I found that I could not!

pythonbrew py Main.py --verbose /media/rackspace/db1/clients/My\ Client/
pythonbrew py Main.py --verbose '/media/rackspace/db1/clients/My\ Client/'
pythonbrew py Main.py --verbose "/media/rackspace/db1/clients/My\ Client/"
pythonbrew py Main.py --verbose [/media/rackspace/db1/clients/My\ Client/]

pythonbrew py Main.py --verbose /media/rackspace/db1/clients/My Client/
pythonbrew py Main.py --verbose '/media/rackspace/db1/clients/My Client/'
pythonbrew py Main.py --verbose "/media/rackspace/db1/clients/My Client/"
pythonbrew py Main.py --verbose [/media/rackspace/db1/clients/My Client/]

all return the same error message

Main.py: error: unrecognized arguments: Client

Can anyone confirm this error? The fact that no one has mentioned it yet in the Python groups makes me believe that this is a Pythonbrew bug, but I am hoping to keep Pythonbrew and find an alternate way to run this script. For now, I am simply storing the files to a folder without a space, but I am hoping that someone can help with this error.


The problem is in pythonbrew/commands/py.py. Each call to subprocess.Popen() needs to be modified so that it uses a list for the command instead of a string.


I can not post a comment since I am too new, but have you tried to escape the space, by placing a \ in front of it? Maybe something like :

pythonbrew py Main.py --verbose /media/rackspace/db1/clients/My\ Client/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜