Introduction to Computing

Python Coding in a Text Editor

Although possible, it is useful as a temporary practice to use the terminal for writing and executing source code. Writing more complex and larger source codes requires the use of python source code files that can be stored in a hard drive and redistributed (hopefully sold) to other parties.


Python source code can simply be written in a text file, and executed from the terminal without the need of writing the entire source every time the application is expected to be executed.


Let's write the previous source code into a file named MyFirstCode.py and store it to our computer, remembering the location of the file.

print("Welcome to Cmpe 150 – Introduction to Computing")

In the command prompt or terminal, you can simply type the following command to execute the source code any time you need to run your program:

python real_path_to_MyFirstCode.py

real_path_to_MyFirstCode.py may be C:\Users\userXYZ\Documents\MyFirstCode.py, or /Users/userXYZ/Documents/MyFirstCode.py etc depending on your operating system and location you stored your file.

Note: Depending on the text editor you are using, you may encounter an error regarding "SyntaxError: Non-ASCII character". If so, you should add "# coding: utf-8" line at the top of the text file and save it once again. That line informs the python interpreter on the type of character set used in that text file.

# coding: utf-8
print("Welcome to Cmpe 150 – Introduction to Computing")