-1

I have made a piece of code to automate making a new project. I ahve mangaged to create the file in a location I like, create the file and create a test python file. How would I open that file in vs code?

import subprocess,os,time

projectName = input("What is the name of the project?\n")
filename = "test"
fileEx = '.py'

os.chdir('../')
os.chdir('../')
os.chdir('../')
os.chdir('.\Documents\ ')
os.chdir('.\programs\ ')
project = subprocess.Popen(["powershell","md",projectName])
file = filename + fileEx
fileLoctaion = os.getcwd() + file
d = os.getcwd() + f'\{projectName}\ '
time.sleep(1)
os.chdir(d)
with open(file, 'w') as fp:
    pass
Josh
  • 15
  • 4
  • 1
    Duplicate of [How to execute a program or call a system command?](https://stackoverflow.com/questions/89228/how-to-execute-a-program-or-call-a-system-command) – esqew Oct 19 '21 at 14:17

1 Answers1

1

You could try the following:

import os
os.system("code NAMEOFFILE.py") ## the "code" command is the command used to open a file with vsc in a command line interface.

You can do the same thing with subprocess:

import subprocess
subprocess.getoutput("code NAMEOFFILE.py")
Tom
  • 440
  • 3
  • 10