PythonAnywhere (www.pythonanywhere.com) is a free online service that gives you a way to develop and run Python programs inside a browser. This is a full-featured Linux environment with a browser-based text editor with syntax highlighting. To use Pythonanywhere for this class - all you need to write and run Python code is a web browser. There is nothing to install at all.
This means that you can do this course on a "locked-down" environment on systems like Apple's iPad, iPhone, Android, ChromeBooks, or Windows 10 Home S. You can also use PythonAnywhere if you are using a work or school computer that does not allow any software into be installed.
You will need to sign up for an account to use PythonAnywhere. They have a free level that will cover all of your needs for this course through Chapter 15.
PythonAnywhere is committed to letting you have a free account forever as long as you keep logging in and extending it. They have low cost paid plans if you want more disk space or compute power for your own projects or more flexibility or features. But rest assured that their free plan is sufficient for this course.
Once you can log in to PythonAnywhere, go into the files tab and create a new file called hello.py in your home folder (should be something like /home/drchuck. Put the following line in the file:
print('Hello world')Save the file and press Run and you should see:
Hello world >>>Then change the text to 'Hello PY4E world', press Save and press Run and it should run your modified program.
While the Run button works for programs that are a few lines, once you start working on more complex programs you will need to use a Linux shell (command line). It might feel a little strange at the beginning but learning a little bit of Linux is a great idea as it is the dominant system that is used for servers.
This works best if you can have two tabs open at the same time in the browser. One tab should be navigated to the Files screen and another should be nagivated to the Consoles screen. If you already have a bash console running you can go back to it - otherwise start a new Bash console. After it starts up, you should see something like:
14:12 ~ $This is the Linux command prompt. Lets run your 'hello.py' program from the command line:
14:12 ~ $ cd 14:14 ~ $ pwd /home/drchuck 14:15 ~ $ ls -l -rw-rw-r-- 1 drchuck registered_users 27 Mar 29 14:15 hello.py 14:16 ~ $ python3 hello.py Hello PY4E world 14:16 ~ $Here is what the commands are doing:
You can scroll back through previous commands by pressing the up and down arrows and re-execute commands using the enter key. This can save a lot of typing. If you like keeping your screen uncluttered, you can clear the scroll back buffer by pressing the Command key and the K key at the same time.
There are three ways to edit files in your PythonAnywhere environment, ranging from the easiest to the coolest. You only have to edit the file one of these ways.
cd ~ nano hello.pySave the File by pressing CTRL-X, Y, and Enter.
cd ~ vi hello.pyOnce you have opened vi, cursor down where you want to make a change, and press the i key to go into 'INSERT' mode, then type your new text and press the esc key when you are done. To save the file, you type :wq followed by enter. If you get lost press esc :q! enter to get out of the file without saving.
Copyright Creative Commons Attribution 3.0 - Charles R. Severance