| 38 | +many features that they would confuse you or they aren't free. You can |
| 39 | +use these editors if you like them, but **I dont recommend these editors |
| 40 | +for getting started with programming**: |
44 | 41 |
|
| 42 | +- Emacs |
45 | 43 | - Gedit
|
46 | 44 | - IDLE
|
47 | 45 | - Nano
|
| 46 | +- NetBeans |
48 | 47 | - Notepad
|
49 | 48 | - Pluma
|
50 |
| -- Wingware |
51 |
| - |
52 |
| -On the other hand, some editors have too many features for getting |
53 |
| -started with programming. They are not bad, but they are not meant for |
54 |
| -beginners. So **I don't recommend using these editors yet**: |
55 |
| - |
56 |
| -- Emacs |
57 |
| -- NetBeans |
58 | 49 | - PyCharm
|
59 | 50 | - Spyder
|
60 | 51 | - Vim
|
| 52 | +- Wingware |
61 | 53 |
|
62 |
| -These lists don't contain all bad editors, but these are editors that |
| 54 | +This list doesn't contain all bad editors, but these are editors that |
63 | 55 | people often try to use. If you know a bad editor and you think I should
|
64 | 56 | mention it here, please [let me know](../contact-me.md).
|
65 | 57 |
|
66 |
| -## Installing your new editor |
67 |
| - |
68 |
| -Installing Geany is easy. If you are using Windows or Mac OSX, go to |
69 |
| -[the official Geany download |
70 |
| -page](http://www.geany.org/Download/Releases) and click the correct |
71 |
| -download link. If you are using Linux, just install Geany from the |
72 |
| -package manager like any other program. For example, on Debian-based |
73 |
| -distributions (e.g. Ubuntu) you can type `sudo apt install geany` on a |
74 |
| -terminal. |
75 |
| - |
76 |
| -When you have Geany installed, you can launch it like any other program. |
77 |
| -By default, it has a big sidebar and bottom area, but we don't need them |
78 |
| -so you can start by dragging them away. Geany should look roughly like |
79 |
| -this after that: |
80 |
| - |
81 |
| - |
82 |
| - |
83 |
| -## Dark background |
84 |
| - |
85 |
| -Geany has a white background by default, but we'll tell Geany to use a |
86 |
| -black background instead. Your eyes will thank you for doing this when |
87 |
| -you have been programming for a few hours. |
88 |
| - |
89 |
| -1. Click *Edit* at top and click *Preferences*. |
90 |
| -2. Click *Editor* at left. |
91 |
| -3. Click *Display* at top right. |
92 |
| -4. Check *Invert syntax highlighting colors*. |
93 |
| -5. Click *OK*. |
94 |
| - |
95 |
| -If you don't like the colors, you can install more [color |
96 |
| -schemes](https://github.com/geany/geany-themes/) and then go to *View* |
97 |
| -at top and click *Change Color Scheme*. |
98 |
| - |
99 |
| -## Opening and saving files |
100 |
| - |
101 |
| -Now it's time to create our first file. Geany creates a new file when |
102 |
| -you open it for the first time, but it doesn't know that it's going to |
103 |
| -be a Python file. We need to tell that to Geany by saving the file |
104 |
| -first. You can use the *File* menu at top or the buttons below the |
105 |
| -menus, just like in most other programs. |
| 58 | +## Editor or `>>>` prompt? |
106 | 59 |
|
107 |
| -Save the empty file on your desktop as `test.py`. The `.py` at the end |
108 |
| -of the name is important, it tells Geany and other programs that it's a |
109 |
| -Python file. |
| 60 | +So far we have used the `>>>` prompt for everything. But now we also |
| 61 | +have an editor that lets us write longer programs. So why not just |
| 62 | +always use the editor? |
110 | 63 |
|
111 |
| -## Automatic tab expanding |
| 64 | +The `>>>` prompt is meant to be used for experimenting with things. For |
| 65 | +example, if you want to know what `"hello" + 123` does, just open the |
| 66 | +prompt and run it. |
112 | 67 |
|
113 |
| -Open a Python file in your editor. Then press the tab key, and the |
114 |
| -cursor should move right. Now press the left arrow key. See how the |
115 |
| -cursor jumps over the empty space? The empty space is actually a tab |
116 |
| -character, but Python's style guide recommends using four spaces instead |
117 |
| -of tab characters so we'll need to change Geany's settings. |
| 68 | +If you want to write something once and then run it many times, write |
| 69 | +the code to a file. For example, if you want to make a program that asks |
| 70 | +the user to enter a word and then echoes it back, write a program that |
| 71 | +does that in a file and run it as many times as you want to. |
118 | 72 |
|
119 |
| -1. Click *Edit* at top, then click Preferences. |
120 |
| -2. Click *Editor* at left. |
121 |
| -3. Click *Indentation* at top. |
122 |
| -4. Select *Spaces* instead of *Tabs*. |
123 |
| -5. Click *OK*. |
124 |
| -6. Click *Project* at top and click *Apply Default Indentation*. |
125 |
| - |
126 |
| -Delete the whitespace, then press tab and press the arrow left again. |
127 |
| -Now the cursor should move one space at a time. |
128 |
| - |
129 |
| -**TODO:** animated gifs that show what's going on. |
130 |
| - |
131 |
| -## Stripping spaces when pressing Enter |
132 |
| - |
133 |
| -Press Tab and then press Enter, and Geany should add spaces to the new |
134 |
| -line automatically for you. If you are not using Geany, make sure that |
135 |
| -your editor does this too. |
136 |
| - |
137 |
| -Now press the arrow up and then move left and right. You'll notice that |
138 |
| -the previous line has spaces left over on it. Leaving useless spaces to |
139 |
| -ends of lines like this is usually considered bad style, but it's easy |
140 |
| -to tell Geany to get rid of them: |
141 |
| - |
142 |
| -1. Click *Edit* at top and click *Preferences* |
143 |
| -2. Click *Editor* at left. |
144 |
| -3. Click *Features* at top. |
145 |
| -4. Check *Newline strips trailing spaces*. |
146 |
| -5. Click *OK*. |
147 |
| - |
148 |
| -Press tab and Enter again. If you go back to the previous line now there |
149 |
| -is no whitespace on it. |
150 |
| - |
151 |
| -**TODO:** again, animated gifs |
152 |
| - |
153 |
| -## Maximum line length |
154 |
| - |
155 |
| -You have probably noticed that Geany displays a thin, green-ish line at |
156 |
| -right from where you type. The idea is that you should avoid writing |
157 |
| -anything longer than where this line is. Your programs will work if they |
158 |
| -contain lines that go past this marker, but it's not recommended because |
159 |
| -shorter lines are nicer to work with in general. People with small |
160 |
| -screens can work with your code, and people with large screens can have |
161 |
| -multiple files opened at the same time. |
162 |
| - |
163 |
| -By default, there's room for 72 characters before the marker. Staying in |
164 |
| -72 characters is not always easy, and that's why Python's style guide |
165 |
| -recommends 79 instead of 72. Let's move Geany's marker to 79 characters: |
166 |
| - |
167 |
| -1. Click *Edit* at top and click *Preferences* |
168 |
| -2. Click *Editor* at left. |
169 |
| -3. Click *Display* at top. |
170 |
| -4. Change 72 to 79. |
171 |
| -5. Click *OK*. |
172 |
| - |
173 |
| -## Running things from the editor |
174 |
| - |
175 |
| -This setting up stuff is boring! Let's write some code. |
176 |
| - |
177 |
| -We'll use this program to check if our editor is set up correctly. |
178 |
| -Create a new file and type this into it: |
179 |
| - |
180 |
| -```python |
181 |
| -import sys |
182 |
| -print(sys.version) |
183 |
| -``` |
184 |
| - |
185 |
| -You don't need to understand this program yet, you'll learn what it does |
186 |
| -later in this tutorial. You can type this program on the `>>>` prompt to |
187 |
| -see what it does if you want to. |
188 |
| - |
189 |
| -Now save the program somewhere as `test.py`. It doesn't matter what the |
190 |
| -name of the file is, but it needs to end with `.py`. This way Geany |
191 |
| -knows that it's a Python file. |
192 |
| - |
193 |
| -Next we'll need to change Geany's settings so that it runs the program |
194 |
| -correctly. You need to have a Python file opened to change these |
195 |
| -settings. |
196 |
| - |
197 |
| -1. Click *Build* at top, then click *Set Build Commands*. |
198 |
| -2. The *Execute* command is probably `python "%f"`. Change it to |
199 |
| - `py "%f"` if you are using Windows and `python3 "%f"` if you are |
200 |
| - using Linux or Mac OSX. |
201 |
| -3. Click *OK*. |
202 |
| - |
203 |
| -Note that the first part of our *Execute* is the same thing [we type on |
204 |
| -a PowerShell or terminal](installing-python.md#running-python). Actually |
205 |
| -the whole command means "run this file using my Python". |
206 |
| - |
207 |
| -Now press the F5 key at the top of your keyboard to run the file we |
208 |
| -wrote. It should open up in a terminal or command prompt and print the |
209 |
| -same Python version as the `>>>` prompt prints when we open it. If the |
210 |
| -version starts with 2 it's too old, and you can [ask |
211 |
| -me](../contact-me.md) or some other experienced programmer for help. |
212 |
| - |
213 |
| -## Important notes |
214 |
| - |
215 |
| -Now your editor is ready to go. There are a couple important things that |
216 |
| -you need to keep in mind when reading the rest of this tutorial: |
217 |
| - |
218 |
| -- When a code example starts with `>>>`, type it to the `>>>` prompt. If |
219 |
| - it doesn't, create or open a `.py` file with your editor, type the |
220 |
| - code into it and run the file. |
221 |
| -- When we type some code to the `>>>` prompt it [echoes back the |
222 |
| - result](getting-started.md) [when it's not None](variables.md#none), |
223 |
| - but code in a file does nothing to the result. For example, typing |
224 |
| - `1 + 2` to the `>>>` prompt makes it echo `3`, but we need to do |
225 |
| - `print(1 + 2)` if we want to do the same thing in a file. |
226 |
| -- The editor doesn't replace the `>>>` prompt. The prompt is good for |
227 |
| - trying things out quickly, and the editor is better when we want to |
228 |
| - write longer programs. |
229 |
| - |
230 |
| -## You're done! |
231 |
| - |
232 |
| -This probably felt like a lot of work, but don't worry, there will be no |
233 |
| -more things like this in the future. Now we have installed and set up |
234 |
| -all the tools we need and we can continue learning Python. |
| 73 | +Note that if you write something like `'hello'` to the `>>>` prompt it |
| 74 | +echoes it back, but if you make a file that contains nothing but a |
| 75 | +`'hello'` it won't do anything when you run it. You need to use |
| 76 | +`print('hello')` instead when your code is in a file. |
235 | 77 |
|
236 | 78 | ***
|
237 | 79 |
|
|
0 commit comments