I'm using python's argparse module to process command line arguments. I am having a problem on decoding actual unicode file names/file paths. Here's my code:
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-f", dest="file", default="", help="file to be processed")
options = parser.parse_args()
main(options)
def main(options):
detail = options.file.decode(sys.stderr.encoding)
print os.path.exists(detail)
print detail
Now, when I run the script via Windows command line:
sample.py -f "c:\temp\2-¡¢£¤¥¦§¨©ª«¬®¯°±²³´μ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
I am getting this as the result:
c:\temp\2-íóúñѪº¿⌐¬½¼?«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■
False
As you can see, the decoded file name is different, resulting to a "False" in file existence checking.
Any ideas on solving this? Thanks in advance!