argparse如何不扩展路径

2024-05-17 04:34:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我添加了一个参数,将path作为str来表示远程主机上的路径

    parser_upload.add_argument(
      'destination',
      help="Remote destination directory, Note'~' should be quoted",
      type=str
    )

我用Git Bash测试了我的程序

$ python skeleton.py upload ../../tests/auth_pub.py /home/wsx/test/upload -v
  File "skeleton.py", line 140
    type=str
[2019-10-03 13:25:34] INFO:__main__:Starting loon...
[2019-10-03 13:25:34] INFO:__main__:Upload command is detected.
['../../tests/auth_pub.py']
C:/Tools/Git/home/wsx/test/upload
Starting upload...
['wsx', '10.19.24.165', 22]
Uploading ../../tests/auth_pub.py to C
os.stat_result(st_mode=33206, st_ino=1407374883788705, st_dev=2013704423, st_nlink=1, st_uid=0, st_gid=0, st_size=1690, st_atime=1570071985, st_mtime=1570071985, st_ctime=1569955352)
C/auth_pub.py
1570071985.659461
Traceback (most recent call last):
  File "skeleton.py", line 221, in <module>
    run()
  File "skeleton.py", line 217, in run
    main(sys.argv[1:])
  File "skeleton.py", line 209, in main
    host.upload(args.source, args.destination)
  File "C:\GitHub\loon\src\loon\classes.py", line 181, in upload
    info.st_atime
  File "ssh2\session.pyx", line 553, in ssh2.session.Session.scp_send64
  File "ssh2\utils.pyx", line 151, in ssh2.utils.handle_error_codes
ssh2.exceptions.SCPProtocolError

我发现/home/wsx/test/upload变成了C:/Tools/Git/home/wsx/test/upload

引用它也不起作用:

$ python skeleton.py upload ../../tests/auth_pub.py '/home/wsx/test/upload' -v
[2019-10-03 13:28:17] INFO:__main__:Starting loon...
[2019-10-03 13:28:17] INFO:__main__:Upload command is detected.
['../../tests/auth_pub.py']
C:/Tools/Git/home/wsx/test/upload

我该如何解决这个问题

谢谢

更新

这是由gitbash引起的问题,而不是argparse

顺便问一下,我应该如何结束这个问题


Tags: inpytestauthssh2homemainline