简体   繁体   中英

command line python script run on a file in different directory

I have a script.py in /Users/admin/Desktop and I want to run this script on a file that is in /Users/admin//Desktop/folder/file.txt, without changing the present dir.

Question: what is the most efficient way to do that on command-line ? I am using the following commands and results are not as expected.

$ python script.py --script; /Users/admin/Desktop/file.txt

     raise StopIteration('because of missing file (file.txt)')

 StopIteration: because of missing file (file.txt)
  1. Remove the semicolon because that will prematurely terminate the command.
  2. Pass the correct path to the file to your program. You say it is /Users/admin/Desktop/folder/file.txt , however, your command is using /Users/admin/Desktop/file.txt (it's missing folder )

So the command should (probably) be:

$ python script.py --script /Users/admin/Desktop/folder/file.txt

If that doesn't work you will need to edit your question to show your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM