Skip to content

Commit 7a6a7f1

Browse files
committed
add partially done stuff
1 parent 2c8892f commit 7a6a7f1

8 files changed

+253
-75
lines changed

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,39 @@ asked to create a GitHub account if you don't already have one.
8383

8484
### How can I read this tutorial without an Internet connection?
8585

86+
Currently (Feb. 2017) this tutorial is updated often, so it's best to
87+
read this tutorial on GitHub to make sure you are reading the latest
88+
version. But you can also download this tutorial and read it without
89+
Internet if you need to, like this:
90+
8691
1. Go [here](https://github.com/Akuli/python-tutorial) if you aren't
8792
here already.
8893
2. Click the big green "Clone or download" button in the top right of
8994
the page, then click "Download ZIP".
9095

91-
![Download ZIP](images/download-me.png)
96+
![The Download ZIP button.](images/download-me.png)
97+
98+
3. Open the ZIP, then drag and drop `python-tutorial-master` to your
99+
desktop.
100+
4. [Install Python and open a command prompt or
101+
terminal](basics/installing-python-md). If you are using Windows,
102+
run these commands:
103+
104+
```
105+
cd Desktop
106+
python-tutorial-master
107+
py make-html.py
108+
```
92109
93-
3. Extract the ZIP and open it. Unfortunately I don't have any more
94-
specific instructions because how exactly this is done depends on
95-
which operating system you run.
96-
4. Run `make-html.py` and follow the instructions.
110+
Use these commands instead on Linux and Mac OSX:
111+
112+
```
113+
cd Desktop
114+
cd python-tutorial-master
115+
python3 make-html.py
116+
```
117+
118+
5. Follow the instructions you see on the terminal or command prompt.
97119
98120
If you have git and you know how to use it, you can also clone the
99121
repository instead of downloading a zip and extracting it. An advantage
@@ -109,6 +131,8 @@ have helped me with it:
109131
error fixes.
110132
- [theelous3](https://github.com/theelous3): Small improvements and fixes.
111133
134+
**TODO:** add the names of all beginners who have told me what they struggled with.
135+
112136
***
113137
114138
If you have trouble with this tutorial please [tell me about

basics/cheatsheet.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Cheat sheet of the basics
2+
3+
The basics section contains a lot of stuff, and the most important
4+
things are summarized here. You can keep this page open while writing
5+
code, or if you see something you don't understand you can check if it's
6+
here.
7+

basics/editor-setup-2.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Setting up an editor for programming
2+
3+
An editor is a program that lets us write longer programs than we can on
4+
the `>>>` prompt. Then we can save the programs to files and run them.
5+
You may have noticed that Python comes with an editor called IDLE, but
6+
it's not really good enough for programming and I don't know any
7+
experienced programmers who would actually use it.
8+
9+
In this chapter we'll download, install, set up and learn to use an
10+
alternative editor. This does not mean something like Microsoft Word or
11+
LibreOffice/OpenOffice Writer. These programs are for writing text, not
12+
for programming.
13+
14+
This tutorial uses an editor called Geany because it's easy to use and
15+
it works great on Windows, Mac OSX and Linux. You can use any editor you
16+
want, but I don't recommend learning any of these editors now. There are
17+
many editors to choose from and the choice of editor is a very personal
18+
thing.
19+
20+
Different programmers have different favorite editors, and they often
21+
recommend their own favorite editor to everyone. These editors are not
22+
good for beginners. **If someone recommends one of these to you when you
23+
are getting started with Python, say no:**
24+
25+
- Spyder
26+
- PyCharm
27+
- Emacs
28+
- Vim
29+
- NetBeans
30+
- Spyder
31+
32+
These editors are missing some important features, so **don't use
33+
these** either:
34+
35+
- Wingware
36+
- Windows Notepad
37+
- Gedit
38+
- Pluma
39+
40+
Editor setup sections in all Python tutorials I have seen are usually
41+
like "click here, then here". In this tutorial I'll show you what
42+
different settings do and why you need them.
43+
44+
## Downloading Geany
45+
46+
47+
48+
## Automatic tab expanding
49+
50+
51+
52+
This is important. Never use tabs in Python. Nobody else is using tabs,
53+
and the official style guide tells you to never use tabs.
54+
55+
However, **you don't need to press the spacebar four times every time
56+
you want to indent**. Your editor should give you four spaces when you
57+
hit the tab key. Some editors also remove four spaces when you hit
58+
backspace and there are four spaces before the cursor.
59+
60+
### Geany
61+
62+
1. Go to *Edit* at the top and select Preferences.
63+
2. Go to *Editor* at left.
64+
2. Go to *Indenting* at top.
65+
4. Select *Spaces* instead of *Tabs*.
66+
67+
### gedit and pluma
68+
69+
1. Go to Edit at the top and select Preferences.
70+
2. Go to Editor at top.
71+
3. Change the indent width to 4 and select *Add spaces instead of tabs*.
72+
73+
### GNU Emacs
74+
75+
Emacs uses spaces with Python files by default.
76+
77+
### GNU Nano
78+
79+
Open your `~/.nanorc`.
80+
81+
$ nano ~/.nanorc
82+
83+
Add these lines to it:
84+
85+
set tabsize 4
86+
set tabstospaces
87+
88+
### Mousepad
89+
90+
1. Go to *Document* at the top, then *Tab Size*.
91+
2. Select 4.
92+
3. Also select *Insert Spaces*.
93+
94+
## Syntax highlighting
95+
96+
If you type a keyword, like `if`, it should show up with a different
97+
color than the rest of your text. `"Strings"`, `# comments` and
98+
everything else should also have their own colors. This makes it much
99+
easier to write code.
100+
101+
Most of the editors below have syntax highlighting turned on by
102+
default, but you can also change the colors.
103+
104+
### Geany
105+
106+
Install more [color schemes](https://www.geany.org/Download/Extras#colors),
107+
then go to *View*, *Change Color Scheme*.
108+
109+
### gedit and pluma
110+
111+
Click *Fonts & Colors* in the preferences and select another color
112+
theme.
113+
114+
### GNU Emacs
115+
116+
Type M-x, type `load-theme`, press Tab twice to see a list of theme
117+
names, then enter a theme name and press Enter. If you want to
118+
automatically set the theme when Emacs starts, add
119+
`(load-theme 'your-theme-name)` to your `~/.emacs`.
120+
121+
### Mousepad
122+
123+
Click *View*, go to *Color Scheme* and select whatever you want.
124+
125+
## Is your editor using Python 3?
126+
127+
Some editors allow you to run your programs with a single keystroke,
128+
usually by pressing F5. This tutorial is written for Python 3 or newer,
129+
so your editor also needs to run the programs in Python 3 or newer.
130+
131+
If you are unsure which Python your editor runs, create a test file
132+
with the following contents:
133+
134+
```python
135+
import sys
136+
print(sys.version)
137+
```
138+
139+
If the version starts with 2, it's too old.
140+
141+
### Geany
142+
143+
1. Go to *Build*, then *Set Build Commands*.
144+
2. Replace `python` or `python2` with `python3` everywhere. Or if you
145+
are using Windows, run `python` on a terminal and enter these
146+
commands:
147+
148+
```python
149+
>>> import sys
150+
>>> print(sys.executable)
151+
```
152+
153+
You'll get a path to your python.exe. Replace `python` in the build
154+
commands with this path. Most importantly, your *Execute* command
155+
should be `"C:\your\path" "%f"`.
156+
157+
### gedit, pluma and Mousepad
158+
159+
These editors don't support running programs with F5.
160+
161+
### GNU Emacs
162+
163+
Usually I write something in Emacs, then I press Ctrl+Z to suspend
164+
Emacs, run the program myself and then I run `fg` to get back to Emacs.
165+
If you know how to run Python programs in Emacs and you'd like to write
166+
about it here, [tell me](contact-me.md).
167+
168+
***
169+
170+
If you have trouble with this tutorial please [tell me about
171+
it](./contact-me.md) and I'll make this tutorial better. If you
172+
like this tutorial, please [give it a
173+
star](./README.md#how-can-i-thank-you-for-writing-and-sharing-this-tutorial).
174+
175+
You may use this tutorial freely at your own risk. See
176+
[LICENSE](./LICENSE).
177+
178+
[List of contents](./README.md#list-of-contents)

basics/installing-python.md

Lines changed: 37 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ need to try out the code examples. You can use a website like
66
installing Python. That way you don't need to open a web browser just
77
to write code, and you can work without an Internet connection.
88

9+
It doesn't matter which operating system you use because Python runs
10+
great on Windows, Mac OSX, Linux and many other operating systems.
11+
However, installing and launching Python are done differently on
12+
different operating systems, so just follow your operating system's
13+
instructions.
14+
915
Let's get started!
1016

1117
## Downloading and installing Python
@@ -16,92 +22,54 @@ Use the official Python installer, it will install Python and IDLE for
1622
you.
1723

1824
1. Go to [the official Python website](https://www.python.org/).
19-
2. Move your mouse over the blue Downloads button, but don't click it,
20-
Then click the button that downloads the latest version of Python.
25+
2. Move your mouse over the blue Downloads button, but don't click it.
26+
Then click the button that downloads the latest version of Python.
2127
3. Run the installer.
22-
4. Install Python like any other program. Make sure the py.exe
23-
launcher gets installed.
28+
4. Make sure that the launcher gets installed and click Install Now.
29+
![The py.exe launcher.](../images/py-exe.png)
2430

2531
### Mac OSX
2632

27-
I don't have an up-to-date copy of Mac OSX. If you would like to write
28-
instructions for OSX, [tell me](../contact-me.md).
29-
30-
### GNU/Linux
33+
At the time of writing this, Macs don't come with a Python 3 and you
34+
need to install it yourself. It should be like installing any other
35+
program, but unfortunately I don't have better instructions because I
36+
don't have an up-to-date Mac and I have never installed Python on a Mac.
37+
If you would like to write better instructions, [tell
38+
me](../contact-me.md).
3139

32-
You already have Python, there's no need to download anything.
40+
### Linux
3341

34-
If you want to use IDLE (see below), install it. The name of the
35-
package is `idle3` on Debian-based distributions, like Ubuntu and Linux
36-
Mint, and you can install it with a software manager like any other
37-
program. On other distributions you can just search for idle using the
38-
distribution's package manager.
42+
You already have Python 3, there's no need to install anything. You may
43+
also have Python 2, but don't try to remove it. Some of your programs
44+
are probably written in Python 2, so removing the Python 2 would break
45+
them.
3946

4047
## Running Python
4148

42-
Now you have Python installed. There are several ways to run Python:
43-
44-
1. Directly from PowerShell, command prompt or terminal.
45-
2. Using IDLE.
46-
3. Using something else.
47-
48-
I'm not going to focus on the third option in this tutorial, but if you
49-
know how to use Python with something else than PowerShell, command
50-
prompt, a terminal or IDLE it's fine. Do whatever you want.
51-
52-
### If you are not an advanced user and you have no idea what PowerShell, command prompt and terminal are
53-
54-
Use IDLE. Experienced Python users will say that IDLE is garbage, but
55-
don't listen to them. These people want you to use "better"
56-
alternatives with more features, but that's exactly what you don't want
57-
as a beginner. You should spend as little time as possible learning
58-
your tools, and as much time as possible learning Python. Advanced
59-
programming tools are not going to help you with this at all.
49+
Next we'll learn to run Python on a command prompt or terminal. There
50+
are several other ways to run Python, but if you learn this way now it's
51+
going to make things easier later.
6052

61-
Launch Python's IDLE like any other program. You should see something
62-
like this:
63-
64-
![IDLE](../images/idle.png)
65-
66-
From now on, I'll instead show everything like this, so I don't have to
67-
take more screenshots:
68-
69-
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
70-
[GCC 4.8.4] on linux
71-
Type "copyright", "credits" or "license()" for more information.
72-
>>>
73-
74-
The exact content of your Python's welcome message is probably different
75-
than mine, it's ok.
53+
### Windows
7654

77-
### If you like working with PowerShell, command prompt or terminal
55+
1. Open a PowerShell from your start menu or start screen.
56+
2. Type `py` and press Enter. You should see something like this:
7857

79-
On Windows. you should be able to run Python from a PowerShell window,
80-
or a command prompt window if you don't have PowerShell. Open one of
81-
these programs from the start menu or start screen, type there `py` and
82-
press Enter. You should see something like this in it:
58+
![Python running in a PowerShell window.](../images/powershell.png)
8359

84-
C:\Users\You> py
85-
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18)
86-
[MSC v.1600 32 bit (Intel)] on win32
87-
Type "help", "copyright", "credits" or "license" for more information.
88-
>>>
60+
### Other operating systems
8961

90-
On GNU/Linux or Mac OSX, you should have a terminal application installed
91-
already. Run it and type `python3`:
62+
1. Open a terminal. How exactly this is done depends on your operating
63+
system, but most operating systems have some way to search for
64+
programs. Search for a program called terminal and launch it.
65+
2. Type `python3` and press Enter. You should see something like this:
9266

93-
you@YourComputer:~$ python3
94-
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
95-
[GCC 4.8.4] on linux
96-
Type "help", "copyright", "credits" or "license" for more information.
97-
>>>
67+
![Running Python on my terminal.](../images/terminal.png)
9868

99-
Now you can type `exit()` and press Enter to get out of Python.
69+
Your terminal probably looks different than mine, it's OK.
10070

101-
You may also have an older version of Python installed, but don't remove
102-
it. Your system may need it, so if you replace it with your own Python
103-
some things might stop working. See
104-
[this](https://docs.python.org/3/faq/installed.html) for more info.
71+
Now you can type `exit()` and press Enter to get out of Python. Or you
72+
can just close the PowerShell or Terminal window.
10573

10674
## Summary
10775

images/powershell.png

32.3 KB
Loading

images/py-exe.png

97.1 KB
Loading

images/terminal.png

761 KB
Loading

update-ends.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
If you have trouble with this tutorial please [tell me about
3939
it]({toplevel}/contact-me.md) and I'll make this tutorial better. If you
4040
like this tutorial, please [give it a
41-
star]({toplevel}/README.md#how-can-i-thank-you-for-writing-and-sharing-this-tutorial).
41+
star]({toplevel}/README.md#how-can-i-thank-you-for-writing-and-sharing-\
42+
this-tutorial).
4243
4344
You may use this tutorial freely at your own risk. See
4445
[LICENSE]({toplevel}/LICENSE).

0 commit comments

Comments
 (0)