Passing meta-characters to Python as arguments from command line

前端 未结 4 772
一生所求
一生所求 2020-12-11 03:37

I\'m making a Python program that will parse the fields in some input lines. I\'d like to let the user enter the field separator as an option from the command line. I\'m usi

4条回答
  •  醉梦人生
    2020-12-11 03:37

    solving it from within your script:

    options.delimiter = re.sub("\\\\t","\t",options.delimiter)
    

    you can adapt the re about to match more escaped chars (\n, \r, etc)

    another way to solve the problem outside python:

    when you call your script from shell, do it like this:

    parseme.py -f input.txt -d '^V'
    

    ^V means "press Ctrl+V"

    then press the normal tab key

    this will properly pass the tab character to your python script;

提交回复
热议问题