python - Handle spaces in argparse input -
using python , argparse, user input file name -d flag.
parser.add_argument("-d", "--dmp", default=none) however, failed when path included spaces. e.g.
-d c:\smthng\name spaces\more\file.csv note: spaces cause error (flag takes in 'c:smthng\name' input).
error: unrecognized arguments: spaces\more\file.csv took me longer should have find solution problem... (did not find q&a i'm making own post)
for can't parse arguments , still "error: unrecognized arguments:" found workaround:
parser.add_argument('-d', '--dmp', nargs='+', ...) opts = parser.parse_args() and when want use
' '.join(opts.dmp)
Comments
Post a Comment