Modern Python Projects Transcripts
Chapter: Your code editor
Lecture: Running Python code

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's say, you wrote some code in VSCode and now you want to run it. How can you do this?
0:06 Well, let's go back to our example with just a simple hello world run this code
0:10 in terminal you can just press this green arrow in the right upper corner. And if you don't like using your mouse,
0:18 you can run Python run Python file in terminal command, from the command palette. So let's say we have two lines and we only want to run the second one
0:28 You can select the code that you want to run and run command called Run Selection in Python Terminal. As you can see,
0:37 this starts Python terminal and runs this line. You can also use Shift + enter for the same effect.
0:45 So, that's how you would run a simple Python script. Things get a bit more complicated if you want to run, for example, a Web application.
0:53 Of course, you can always run it from this building terminal, but maybe you don't like to switch between the code editor and the terminal all the
1:01 time. So here I have a very simple flask Web application, just a single file, and when you go to the main page, it's gonna display you. A,
1:10 hello from flask text. Don't worry. If you don't know flask. This is just for the illustration purpose.
1:17 As I said, we could go to a terminal and run Python -m flask run Command. But that's not very convenient because,
1:25 well, what's the point in switching to a terminal? If there are so many buttons in VSCode,
1:30 so for sure, one of them can be used to run flask server for us And indeed, we can go to the Debug panel and start our server
1:39 from there. So, first, let's kill this server. Let's open the debug panel. So first we have to create a debug configuration.
1:47 It sounds complicated, but actually, VSCode has some default configuration that we can use. And as you can see, we even have one for flask,
1:55 which is awesome. So, let's select flask from this list. Next, let's select the name of the file. That is the main flask file.
2:04 In our case, we only have So, that's easy. We press enter and that's it.
2:12 You can see a lot off thing has changed but that's because we started the debug session. So, if we had some break points in our code,
2:20 we would be able to actually stop there and investigate our code. So at the top, you can see we have a debug panel that lets
2:28 you stop the code execution step in, step out, completely Stop the debugger, or restart it, and we can see that our bottom panel has changed.
2:39 Color to orange. This is an indicator that we have a debugging session launched If we stop at some break points and now we go to the debug console
2:47 we would actually be able to see more things here. So to verify that our server is actually running.
2:53 Let's open this URL all in the browser and we have our hello from flask message. Right? So, in the next lesson,
3:03 I will show you how we can use this debug panel more.

Talk Python's Mastodon Michael Kennedy's Mastodon