Drag and drop onto Python script in Windows Explorer

前端 未结 6 989
予麋鹿
予麋鹿 2020-11-29 17:39

I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a co

6条回答
  •  一向
    一向 (楼主)
    2020-11-29 17:57

    With an installed python - at least 2.6.1 - you can just drag and drop any file on a python script.

    import sys
    droppedFile = sys.argv[1]
    print droppedFile
    

    sys.argv[0] is the script itself. sys.argv[n+1] are the files you have dropped.

提交回复
热议问题