- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to execute a Python file in Python shell?
To execute a Python file in the python shell, you could use either the execfile method or the exec method.
For example, you want to run a script called my_script.py that only contains the line:
print("Greetings from my_script")
from the python shell, you could simply enter:
>>> execfile('my_script.py') Greetings from my_script
Or you could use the exec method as follows:
>>> exec(open("my_script.py").read()) Greetings from my_script
- How to clear Python shell?
- Python Interface to Shell Pipelines
- Python Program to Implement Shell Sort
- How to edit a file after I shell to a Docker container?
- How to know/change current directory in Python shell?
- How do I execute a string containing Python code in Python?
- How to execute a python cgi-script under Linux?
- How to Count Word Occurrences in a Text File using Shell Script?
- Execute a String of Code in Python
- How can I source a Python file from another Python file?
- How to rename a file using Python?
- How to delete a file using Python?
- How to find a file using Python?