Python Forum

Full Version: Problem: touch file.py
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 ?
touch is not a python command.
use subprocess
import subprocess

subprocess(['touch', 'file.py'])
(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'])
In recent versions of python there is a cross platform command
import pathlib
pathlib.Path('file.py').touch()