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