There’s two different areas where it can work.Ġ4:55 The first one is it can tell you what’s available from a module that you’ve imported. This can be doubly useful, as you’ll see here. And if I’ve been maybe a little foolish with my naming, this helps point out the fact that this is a different variable, even though it may share the same name as something in the global scope.Ġ4:44 Thonny can perform what’s called code completion, filling in the code which is the rest of your line. That means that local variables are highlighted in italics, which I’ve found useful and helps remind me that these are local variables and not global variables. Now, occasionally it can get maybe a little bit confused because highlighting the one on line 9 highlights all of them, but if you highlight where it’s actually defined, it will generally do a good job of ensuring they’re separate from each other, as you can see here.Ġ4:06 Something I find useful, also in Preferences, is highlighting local variables. And now highlighting a name such as my_calculator by double-clicking it shows that this is only in one place in that scope.Ġ3:44 It doesn’t highlight that one there, but if I highlight that one, you can see that it doesn’t highlight the one inside the function. On Ubuntu, it’s the same as Windows, so Tools > Options, then you go to the Editor tab and click Highlight matching names.Ġ3:29 Back on the Mac, we’ve ticked Highlight matching names and hit OK. Thonny can highlight the names of variables, and because it knows about variable scope, it knows the difference between a local and a global variable.Ġ2:59 This isn’t turned on by default, so on a Mac, you would need to go up to the Thonny menu and then Preferences, and then go to the Editor tab and tick Highlight matching names.Ġ3:12 In Windows, it’s under Tools > Options, but then Editor and Highlight matching names is the same. Then we can run the program and we can get the predictably large output from factorial(100).Ġ2:48 Variable Highlighting. So you can see here, we have the same error message as Python has given us-the same as that one there- but it does give us some extra, so Unbalanced parentheses, brackets or braces, so it says that ‘(‘ at line 8 is not closed by the end of the program.Ġ2:34 That’s helpful. There’s that Synta圎rror in the shell.Ġ2:11 And it’s also giving us that same Synta圎rror in the Assistant. And as we can see, running it has given us a Synta圎rror. Here we can see that it’s blank at the moment because the Assistant view doesn’t work until you try to run the program.Ġ1:58 So because the program has been saved previously, we can click Run, which will save it and then run it. But if you think you’ve finished typing a line and it’s still highlighted, then there’s definitely something you need to look at.Ġ1:43 You can see what’s really going on with this by going to View > Assistant. And while you can put that in as you add an extra code inside there, such as a function call, until you put in the correct closing bracket it will be highlighted as wrong.Ġ1:33 Until you’ve finished typing a line, probably best to ignore it. As soon as we put that in place, the highlighting disappears because we’ve got good syntax.Ġ1:09 Thonny will always be looking over your shoulder to make sure your code has good syntax, although you will notice as you create the code, it’s initially highlighted as being incorrect because we haven’t got a closing bracket. It still looks wrong because Python knows that this is wrong and we’re looking for another bracket. So, here, in a print statement, by leaving out the last of two brackets, we can see that that line is highlighted.Ġ0:44 If I move to another line and try typing, you can see I’ve got an indent, which seems a little bit odd, and that should probably highlight to you that something’s wrong.Ġ0:53 If I start another print statement, it doesn’t help. So as you’re typing the code, it’s checking for syntax errors and it will highlight them, in this case, by leaving a highlighted line. This is done as you’re creating the code. 00:05 Thonny has a number of other great features which will help you write more accurate code more quickly, the first of which is finding syntax errors.Ġ0:19 Thonny can find a syntax error in your code and highlight it to you.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |