How can I open my .py file in the python terminal (noob asking)?

I've been trying to open a graphical user interface through the command line in Python 3.7. I was just wondering how I would do this? How do I access the file it's located in? Do I copy and paste the file (C:\Users...) and run python ui.py through it?

Thank-you.

8

2 Answers

You could use the command line rather than the python terminal

cd into the directory of the project and then run python ui.py.

Copying the file to another directory may break the program as it could rely on other files in its project directory.

If you really want to stay in the python terminal you could

> import os > os.chdir(PATH_TO_FILE) 

then run the file as normal

hope this helps

2

If you are trying to view python file from command line, open command line and use cd

for me I have my python scripts in a folder on my Dekstop so I would put:

C:\Users\YourName>cd Desktop C:\Users\YourName\Desktop>cd Python C:\Users\YourName\Desktop\Python>"Your Python Code Name Goes Here.py" 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like