Python Forum
Problem: touch file.py - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Problem: touch file.py (/thread-21545.html)



Problem: touch file.py - JohnnyCoffee - Oct-04-2019

From the command line I can create a file using the syntax touch file.py without problems. Now when I try to run a script.py with just the syntax touch file.py to create the file by script I simply get the message -> SyntaxError: invalid syntax ?


RE: Problem: touch file.py - Larz60+ - Oct-04-2019

touch is not a python command.
use subprocess
import subprocess

subprocess(['touch', 'file.py'])



RE: Problem: touch file.py - JohnnyCoffee - Oct-04-2019

(Oct-04-2019, 03:54 AM)Larz60+ Wrote: touch is not a python command. use subprocess
 import subprocess subprocess(['touch', 'file.py']) 

Thanks for the help, was missing calling the method or function (run or call) tested both and worked just do not know what is the difference of both? Here's the example of how it looked:

import subprocess

subprocess.run(['touch','file.py'])



RE: Problem: touch file.py - Gribouillis - Oct-06-2019

In recent versions of python there is a cross platform command
import pathlib
pathlib.Path('file.py').touch()