Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Seems like my Python syntax is a bit off when copying a python program

I’m trying to create a self-replicating Python program. Currently, the code I have looks something like this:

from sys import argv
import os
script = argv
name = str(script[0])
try:
    os.mkdir('testFolder')
except:
    pass
os.system(r'copy ' + name + ' testFolder')

This returns the following error:

The syntax of the command is incorrect.

What’s the cause of this, and what would be correct syntax?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are not passing the correct arguments to copy – namely Windows paths are \ separated – e.g. C:\Users\xxxx\Desktop\script.py while Python’s sys.argv[0] will give you / separated path – c:/Users/xxxx/Desktop/script.py

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading