I have created a .py
file and saved it in my "Python" folder located on my desktop.
Now, I want to execute that particular file named "use.py
".
How can I execute the file using LXTerminal?
I have created a .py
file and saved it in my "Python" folder located on my desktop.
Now, I want to execute that particular file named "use.py
".
How can I execute the file using LXTerminal?
You've got several options here (choose the one you like best):
Make the file itself executable.
On the first line of the file, make sure the "shebang" is there:
#!/usr/bin/env python
This is needed for the shell so that it knows how to run the file.
Mark the file executable on the filesystem:
chmod +x thefile.py
Run it like any other executable:
./thefile.py
or
/full/path/to/thefile.py
Run the file directly in the Python interpreter:
python thefile.py
The disadvantage of this is that everyone who would like to run the file should know how to call it. With the first option you have this inside the file itself and you can run the file without knowledge of that.