Professional Python Web Development Using Flask | Jorge Escobar | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Professional Python Web Development Using Flask

teacher avatar Jorge Escobar, Technologist, entrepreneur and open source fanatic

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

81 Lessons (12h 9m)
    • 1. Introduction

    • 2. What is Backend Development?

    • 3. Why Python?

    • 4. The FromZero Approach

    • 5. Introduction to Cloud9

    • 6. Closer Look IDE

    • 7. Shell Commands

    • 8. Python Shell

    • 9. Arithmetic Functions

    • 10. Variables

    • 11. Checking Types

    • 12. Variable Format

    • 13. Strings

    • 14. Lists, Tuples and Dictionaries

    • 15. Date and time

    • 16. Conditionals Control Flow

    • 17. Loops

    • 18. Functions

    • 19. Classes and Objects

    • 20. Modules

    • 21. Parameters

    • 22. New Workspace Virtualenv

    • 23. Pip Install Flask

    • 24. C9 Python Path

    • 25. Minimal App

    • 26. Starting with Git

    • 27. Debugging

    • 28. Routing with Vars

    • 29. Url_for

    • 30. Get Method

    • 31. Post Method

    • 32. Introduction to Templates

    • 33. Login Template

    • 34. Login Function

    • 35. Redirect After Post

    • 36. Flash Messages

    • 37. Better HTML

    • 38. Block Super

    • 39. Template Inheritance

    • 40. Cookies

    • 41. Static Folder

    • 42. Sessions

    • 43. Loggers

    • 44. User Table

    • 45. Intro Mysql

    • 46. Requirements

    • 47. Let's begin with our Blog

    • 48. The Basic Structure

    • 49. The Author Model

    • 50. Setting Up the ORM

    • 51. Interacting with the ORM

    • 52. The Base Template and Bootstrap

    • 53. Introduction to WTForms

    • 54. Form Errors

    • 55. Macros

    • 56. Blog Model and Form

    • 57. Blog Admin and Setup Templates

    • 58. Blog Creation Database

    • 59. Author Login

    • 60. Login Required Decorator

    • 61. Introduction to Migrations

    • 62. More Secure Password

    • 63. Checking is_author

    • 64. The Post and Category Model

    • 65. Post Migration and Testing

    • 66. Introduction to Markdown

    • 67. Post Form

    • 68. Saving the Post to Database

    • 69. The Article View

    • 70. List Articles

    • 71. Logout Links Footer

    • 72. Pagination

    • 73. Installing Flask Uploads

    • 74. Adding Image Blog Post

    • 75. View Image Index Article

    • 76. Deleting Article

    • 77. Editing Articles

    • 78. Introduction to Unit Testing

    • 79. Create Blog Test

    • 80. User Tests

    • 81. Final Project

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


Learn from scratch how to build backend web applications using Python Flask, Cloud9, MySQL and Docker Containers

This course will teach you, assuming no prior coding knowledge, how to develop back end web applications the way professional coders do in the top internet startups. How do I know this? Because I've been leading tech teams in both large enterprise as well as startup companies in New York City for the past 15 years.

I have seen a lot of courses and free tutorials and I can tell you 90% of them just teach bad habits while promising to turn you into a real “web developer". But let me tell you a reality: There's no such thing as a web developer these days. You're either a back end web applications developer, a front end application developer or the so-called (and rare) full stack web developer which includes the other two. However there are so many technologies to master in both the backend and frontend areas that full-stacks (or “web developers") are a rarity in professional environments -- You're either a back end or a front end web developer.

This course doesn't promise to turn you into a professional back end developer after you complete it -- it takes much more than the 11 hours of of this course (and probably hundreds of hours of self-practicing) to do that, but it will give you a good foundation from where to start and continue your training, knowing the right path to become a real professional backend web applications developer using Python. My goal is to make a second course, which would introduce more advanced back end concepts and then start the front end courses (basic and advanced) soon after that.

The course goes through a step by step process of developing web applications, teaching you the Python basics for web development, introducing Flask and using Cloud9 as your development environment. It then moves to explore SQL databases, using MySQL and finally showing you how to develop a blogging application using all these learnings.

Best of all, you don't need to install anything as we will use a revolutionary online web development environment that essentially gives you your own Linux web server with database capabilities! All you need to have is a browser and internet connection and it's completely free to you.

The course is divided in 8 sections and 2 bonus sections:

  • Introduction
  • Setting up our environment
  • Python basics
  • Installing Flask
  • Introduction to Flask
  • An introduction to databases
  • Our first Flask application: A personal blog powered by MySQL
  • Final Project
  • Bonus: Running Our Flask Application with Docker
  • Bonus: Deploying our Application to a Cloud Server

The course has more than 12 hours of video tutorials as well as the source code at the end of each of the Flask application lessons, so that you can see exactly what the whole project looks like in each stage.

The course can take anywhere from 10 days to a month to complete based on how much material the student completes daily.

Additionally we're constantly updating the course, adding content thanks to the feedback of our students.

We will also have office hours where you can ask the instructor any question you might have about the course or about Python Backend Web Application Development in general.

So If you are interested in learning how to code from zero and without prior knowledge, but do it using best industry practices towards becoming a professional backend web developer, this is the course for you.

So stop looking around and start the right path to becoming a professional Python backend web developer with this course!

What are the requirements?

  • A computer with internet access and administrative access to install packages
  • A basic understanding of how to use the internet and text editors

What am I going to get from this course?

  • You will learn the basics of the Python programming language
  • You will learn what databases are and how to use them effectively
  • You will learn how to interact with the database using the MySQL CLI
  • You will learn how to effectively develop a Flask application
  • You will learn about Software Patterns like MVC and decorators
  • You will learn how to process data from HTML Forms into a web application
  • You will learn how to run Flask applications using Docker
  • You will learn how to deploy an application to a cloud server

What is the target audience?

  • Programmers
  • Software Developers
  • Project Managers
  • Computer students
  • Entrepreneurs
  • Software development aficionados

Meet Your Teacher

Teacher Profile Image

Jorge Escobar

Technologist, entrepreneur and open source fanatic


From Zero is an educational project created by Jorge Escobar, a technologist, entrepreneur and open source fanatic with more than 15 years of experience in the development of web applications in New York City.

Jorge has worked in well established companies like Yahoo!, Univision and MongoDB and has also been the technical founding member of various successful tech startups that have received multiple rounds of venture capital.

The biggest problem Jorge has experienced during his career is finding well rounded developers and he interviewed hundreds of them for positions in the teams he was leading. A constant pattern (no matter if candidates came from a good university or had a few years of experience) was the lack of practical, real world knowledge.

That's why Jorge... See full profile

Class Ratings

Expectations Met?
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: Hi. Welcome to professional back in Web development with Pichon Flask, where you learn how to build where applications Using the amazing Python language. My name is Jorge Escobar, and I've been lucky to work in the leading tech companies for the past 15 years, and now we'll show you from scratch how to become a professional Web developer. You can find a lot of online courses that promise you how to become a Web developer. The truth is that in the professional tech industry, there's no such thing as Web developer positions. You're either a back and developer or front end developer on the skills required for each are completely. This course will show you step by step, the best practices to begin your career to become unemployable back in Web applications. Developer I will show you step by step and through the power of video on introduction toe the Python language. How to install Flask, a first look at sequel databases and then we'll build a blogging application using best development practice. At the end of the course, you will challenge to expand the application by developing a commenting system for Blawg. You will also be able to get the full court base as it looks each step of the way so you can develop your knowledge looking at how the system grows bit by bit. The course is the sign for people with little or no previous coding knowledge but are eager to learn how to build Web applications. All you need is a computer and the willingness to put your full attention toe the Metis. Listen. There are other courses that go the easy route and teach using graphical tools. I can tell you, those students would not survive a real life interview in a professional by my course now, and I will start your path to becoming a professional python backend weapon. 2. What is Backend Development?: Okay, let's take a look at what is front and back in development. Um, for that we're going to check what a Internet process looks like on a very high level. Um, let's a diagram and and understand what the steps look like when you request a page. So the first thing you need to know is that there's always a browser and a client. The browser is basically the program that you used to access the Web, the Firefox grown Internet Explorer, whatever you use, and then the server is basically a service that's out there in the Internet. Basically, um, it's a group off servers or computers that are, um, located in a specific you're out. So when you type of euro, what happens is the, um, your Internet provider will hook you up, will direct you to the appropriate server, and then that server will has a process that's a looping process that is always checking. Is there any requests there any requests? And when it received your request for a specific page, it ah basically renders or or comes up with the with the code to build the page that you're requesting, and for that it can access a database where where all this content is is located. Once that Carlton is located, it packages all that up into a webpage on B, returns it back to the browser where the browser will render it as, ah, so appropriate. So what is back end development in front of it? Development? Um, so the idea is that back in development is the processes or the software, Um, the code and the, um the different routines and algorithms that live in the server, um, and interact with the with the database, um, versus the browser code, which is the front. And development so far in development entails working with HTML, CSS and Js, which are ah, the basic, you know, languages for the basic systems that allow the browser to render the content of the server is giving back. So you can think of it as front and being, um, everything that has to do with what declines sees and then back in is all the data behind. Ah, what that page looks like. So in this course, we're gonna we're gonna focus on that on that piece, we're gonna be talking about how to code um, and Ah, and how to develop applications that are inherently listening for requests from a browser and return back ah content code, if you will, that will allow the browser to render that data that information that is stored in the Indus Server. 3. Why Python?: Okay, So one question you may ask it's y Python, where we're learning Typhon or back in development and not something else. And there's a lot of other languages that are that are suitable and have good Ah, you know, good reviews or or their talked about very well on the Internet. And I think it's a personal decision. My personal experience has been that Python has been a very, um, easy to learn, like the learning curve is not too steep. Um, but it's also a language that that it's a joy to read, um, a lot off coding when you're when you have a coating. Careers is about reading other people's code, and Tyson makes it really easy to understand. What, what the thinking waas off another quarter? Um, just by reading it without even looking at the comments, um, or documentation. I think, um, you know, Python ease is Ah, it's fast. Um, again, there are people that say that other things are are faster, but I think once you get into the, um, the real mawf Web, um, Web serving and serving times and all that I think there are many other Viable is to consider um, aside from how fast the languages. But having said that Python is Reese is pretty fast. Um, I like that. It's, ah, object oriented from the beginning. I think that we're gonna talk about a little bit. Why that that's important. But, um, s a first introduction toe. What that concept is it has to do with laying out your code in a way that's reusable and that you can leverage other people's work without having you to reinvent the wheel. Um, that's kind of like what object oriented for me is, ah, what the benefit is. It also, um, you know, building on top of that python is very extensively has a lot off, um, third party libraries that can do what I mean, there's, like, thousands off things that you can do with it from, you know, like math, um, calculations from hooking up to the most popular that air bases from, um, you know, interacting with social platforms like Facebook, Twitter and ah, you know, Ah, a lot off very, very exciting projects that, um that are across that believe across fields off different, different things, like from gaming to, like, scientific to business. So it has a lot off libraries, and the community around Python is very, um, very strong. They're very passionate about by phone, and you will hear about a little bit of the rivalries, especially with the folks that that, like Ruby on rails, which is kind of like a ah, big, um, it's a counterpart or or competition for Python. Then you know, you have to know jazz community also popping up. But it's a it's a friendly competition. I think that, um, you know, each language has he has its own strengths and its deficiencies. But I just like Python. I felt very much at home. Um, I came from, ah coding in peril and then pee. It's B and, ah, now python. I kind of like I look back and it will be very hard for me to go back to another language 4. The FromZero Approach: Hi. I wanted to talk to you a little bit about why is from zero different or better than other courses? Well, first of all, I have experience with complex projects. I've been working with both big companies and start ups, and I've completed a lot off high traffic and fast response, very complex projects that have, um, dozens off developers committing and contributing. So I know the best way to, um, approach a project and make it efficient, scalable. So I'm gonna teach you all those things that I that I know. Um and, um, one thing that I I I'm always striving to doing these courses is to guide you through the basics. Ah, or start with the basics. And then we want to advance topics in the most efficient way. I e I'm not gonna go into small details or maybe go through all the, um, all the chapters of a for example, Baekeland book. But I'm gonna go through the most efficient way so that you can get yourselves up and running and ready for development. Um, I'm also gonna be teaching this us hands on course in all the courses. That means that you're always gonna learn by doing and not just getting a lot of information off the projects or the courses or the languages before actually doing stuff. So it's gonna be very hands on, and I'm not gonna sugarcoat it. Um, it'll be I'm gonna teach you the hard way. Which means I'm not gonna teach you, for example, how to use my sequel or a database using a coolie like PHP. My admin. That's another way that professional developers do it. So I'm not gonna go ahead and just teach you something That's E. C. Because it's just easy for you to use it. You're gonna actually learn the tools the way that professional developers do it in in the leading tech startups. So I hope that you join me and that you enjoy this course on bond. I'll be there to assist to in every step of the way. Um, that's why let all the other students, But I can promise you that you're gonna learn, even though it's gonna be hard sometime, Um, you're gonna learn the proper way, and you're gonna be a professional Web developer in no time 5. Introduction to Cloud9: So now we're going to talk about what is the development environment that we're going to use. And I did some searching and I decided to finally go for Cloud nine. So Cloud nine is basically, ah, Web development environment. Think about it. I say your your server in the cloud. You can add it coding, and you can start databases and it works based on a technology every like, which is Doctor Um so I think it's It's ah, it's a great way for us to learn coding without, um, having to install things, installing python. And if you've if you've seen some of the courses I have, I always go into, like how toe set up. You know, the different environments and the databases and and all that. But I found that students, because they were just like starting to learn it, was kind of like an additional hassle for them to learn how to set up, you know, Windows, Paice, owner or Mac by phone, and then the data basis and all that. So I've decided to start using Cloud nine as the development environment for all my courses , and it's gonna be good because we're gonna be able to basically install and be able to code and work on this platform without having to install anything on our computers. And it doesn't matter what operating system you have for if it's Windows or Mac, you basically will have a lean it's machine running on, um, on the cloud, and you can edit and work on your application wherever you are. Um, the good thing is that they're they're pricing model. They have a free tier here, as you can see. And, you know, you can basically sign up, just enter your user name and password, and he has some pretty cool features like, um, collaborative coding. So, for example, you can, you know, called with another friend of yours or another student on you can we can install data basis and set of frameworks without any problems. So I think it's gonna be a good a good thing for us to use. And we're gonna go over it, um, a little bit us. We start doing the scores 6. Closer Look IDE: Okay, so let's get a little bit acquainted with different areas off cloud nine. So first you head over to see nine dot io, and you can basically just click on tried now to register, um, your new account. Um, once you click there, you can sign up with. If you have a gate, have account or a big bucket account, you can sign up with that. All the ones you can choose a user name and email and a password, and select here so that you can get, like, a capture and then create your frequent account. Like I said, they have ah free account here. They also have, like, some paid paid account ears. But for the purposes of this course, you don't need to really get into a a paying course. I mean, account. So I'm gonna log in with get hub. And when you when you sign in or you register, you get basically this area, which is the dashboard, and you have what they call workspaces and workspaces. Think of them as basically different projects and they're actually basically certain, like separate servers that you're creating with applications in it. Um, so initially you get this test workspace, and then you can create a new one, which is what we're gonna do when we start our first flask application. But let's see what happens when you when you select that existing workspace. But before we get there, if you click here on the name off the workspace, you basically have the capacity off. Like doing some editing you can have. Ah, you'll see a read me. You'll have the files that are in there. Um, so you can take, like, a quick look on. Leigh, Read me. Um is here in this in this test project, and here's a very interesting one. You have members and in members you can basically invite. If you have invited people, you can see them in there, um, to invite people, you need to be inside of the off the actual project. But you also you'll also see how much CPU using how many, how much of the ram and how much of the storage you're using. And they have. For the free tier, you can have up to one CPU 512 megs of ram and one gigabyte hard drive, which is more than then generous I find, um, but now that we know more or less, what's that about? Like I said, you click on the name itself. You'll see those those those statistics. But in order for us to actually start doing stuff, you click on this green open button. So once we click open here, well, we're gonna be taken toe the what's called the I. D or the integrated development environment. And basically, this is kind of like a code editor also has, like, a terminal here for the server. And you have a basically a file navigator, as you can like, you recognize from from similar type of applications, like coordinators Or, you know, even like, you know, work or editors. But, ah, here you can basically navigate what's in the folder. Right now, we only have this file read me MD on the side. Here we have basically, you can edit. Um, you know anything and you have an undo function as well, if you want. Um, it shares like a lot of the things that normal coordinators have, so it's It's very, very well built, Has a lot off capacity. You're not giving away a lot off, um, off power because you were using this disintegrated Ah, development environment. And here the bottom. We have the terminal, and this is something that I always kind off force students to kind of get very acquainted with because it's basically the the way that you interact more with with with systems we don't want to get used to using, like, graphical things. We want to be very comfortable with the with the terminal. If you click on this little kind of like a window function here, we will get a, uh, a standalone editor. And you can minimize again by clicking on that, um on that is likened. And 11 important one that you want to remember is control escape, which basically shows and hides that that terminal back and forth. Um, you can also, like, add tops here, for example. You can add a new like and I think when you when you've opened it for the first time, you'll see this in needed JavaScript editor. I usually close it because it's not something that we're gonna be using, uh, for this course, so you can go ahead and close it, but you can have another terminal window. Let's say from Ah, with another folder open or things that you want to do a swell. But in any case, um, it's it's ah, it's a very nicely integrated environment and what we're gonna look at next is some basic terminal function so that you guys get better acquainted with with terminal commands and how to copy and navigate directories and things like that. 7. Shell Commands: So the star playing a little bit with the terminal? Um, I have modified the callers as we can see here, Um, I going to Ah, you go here to Preferences, and then you go to, uh, terminal here. And then I put the background colder by clicking here to black so you can basically put any any combination of colors. I also increase the phone size to 18 so you guys can can see a little a little bit better. Um, and I close that and then let me put that in full screen and start, um, doing some basic a man so you can get acquainted with how, basically our linen, um, file management and and commence work. So the first thing we're gonna look is we want to know where we're at at a given time. And for that we use a chemical PWD, which is present working directory. And here it's It says that we're at home boom to work space. You see, guys understand. Home is basically usually the folder where the the accounts the user accounts are placed in . So if you had another user cold, you know Jorge, it would be slash home slash Jorge, and that's called the Home Directory for that user. And this still the basically represents that. So if you're in any that say we moved to any other folder, um, we can quickly go back by doing CD, which is change directory and putting that till they're there. It'll take us back to the to the home directory. Um, so and in cloud nine, there's a There's a workspace folder, which basically is where the projects are stored. I don't have a problem with that. I usually when I work on Lenox, I have, um, actually worked with the O. P. T directory. But workspace works finest well, so again to let us know where we're at PWD. So we're in the home Bhutto, which is the user that that Chlo nine assigns you automatically when you when you select the the bone to environment and then work space, which is a directory where, where we're at. So let's see at how we can see what the contents of the directory are. And that's basically the command ls So ls will show us what What files are in that current directory. And so, as you can see, we have read me dot MD, which is that Read me file that we saw on the editor earlier. Um, now, let's say let's say we want to create a new directory within the home. A boom to work space. The command for that It's make directory M k the I r. And let's say we create a direct trickle test. Um, Now, if we do ls you'll see that we have read me. And then we have a directory called Test. So in order for us to change the directory, get inside of that directory we used CD and then test. One trick that you guys want to know about is that you can put the first, like letters off, basically commands and directories and all that. And then if you press the tab, you'll see that it auto completes to whatever, um, the best matches on if you continue clicking tab, you continue seeing through those things. So if I If I do see the r and then click tab, you'll see that, um, it should get me toe. Since I'm not in the Marine, the workspace. So what? Basically, you will get the read me empty, but I'm going to go to the so if I do ls you'll see that? Read me there, um, on gonna change to the test directory here. So right now there's nothing in there. Um, the next thing we're gonna do is we're gonna use a common cold touch and touch is useful to create empty directories. Like, if you want to just create a quick, um, file that has nothing in it. So we can do, Let's say, test test, not txt. Um, if you do a less now, you'll see that, um, there's a test txt now in there. So that's a useful command we're gonna use it to. There's a, um there's a file name called Any P Y that we use for initializing directories as modules for python ball will get will get toe that quickly. If you want to clear the screen on, go back to the top. We used a clear command, and that puts us with a clear with a clear screen. Um, some other useful things. Let's say we have Ah, the test directory. Here. Let's create another directory called test. Um, in Let's say test in. Okay, so now we have tastic City and then another folder. We think that, um, cold test in. So let's say I want to move that folder. I mean, that filed spoon that's dot txt two. Their test in I use the M V command, which is move, and basically I'm gonna move test the txt to, ah, test in directory. So I do that. So I move. I'm saying move test txt to within the directory test in effect press enter there. Now, if I do a last, you'll see that we don't have test txt anymore, and it's in test in. But how do I checked up without having to go again? Like doing seedy testing You can actually do l s and then type the name off a directory. And if you press enter, you'll see the contents off that directory within, um, that that that folder that you have selected so you don't have to go inside of it. So that's the move, Command. Um, there's also, um, a very useful command called Cat. Let's go back to the to the home folder and then workspace. So see how I did that? Um, um, I'm now in the homeroom toe workspace, so there's a chemical cat and cat basically allows you to see the contents of a file quickly without having to, um, open theater or anything. You just want to, like, take a quick lands. So there you go. So if I do can't read me, I see the contents of the file without having to go to the to the editor. Um, if we have a long file, we can also use a command clear the screen called more. So if I do mawr and then read me, um, it basically will Pagine eight because this this file can be seen within only one page. There's not a whole a whole lot off use for it. But if you if you type more and there was more than one page, you can basically see the contents of the file in a paginated manner. Um, one more useful one is called man and man. It's like the manual so you can see the options that you have for any in UNIX or Linux commands. So let's say if I type man CP, I can see the Aled the options that I have for the for the copy command and you can press down arrow or up arrow to see them. The file. Or you can also press the space key and then paginated by page. When you want to exit, you just press the queue, the queue letter and it'll go back out. So, um and that's what basically, it's using the more command, which I was telling you earlier. Um, the last thing I want to talk about is the wild card. So if that they have, let's go to the test folder and let's say, let me create quickly, that's two dot txt and then test three dot txt. And there's something called Wild Car, which is the asterisk. Um, and it's a wanted to move quickly a bunch of files that started with test. If I do move, Test star or ASA is the T Eckstine and I want them in the test in folder, that ass teres is going to say, OK, anything that has that begins with test, no matter what, uh, letters or numbers come afterwards and then after that, a dot and txt are gonna be moved. So if I press enter there, you'll see that, um, I don't have the test. Um, you know files anymore, and they're all in the test in folder. So that's a quick look at terminal commands, and there's many, many more. And there's, like different flags that we can put, which are like parameters for those commands. But you're you learn them ass you as you use them Azaz. We go through the 30 course, but for now, that's Ah, that's a very quick introduction to the terminal commands. 8. Python Shell: So let's start playing a little bit with Python and we're gonna use the terminal again. Time will maximize this here. Um, with cloud nine, we have an option to use sports by Thorn to and buy from three by phone to is still very much in use because there's some libraries that still haven't been ported to buy from three . But I would say these days, most off the off, the useful or most common libraries and frameworks have been updated. So I'm definitely start. And I would start using python three from from this point on, Um and you know, it's it's ah, It's a good thing that we start using by from three projects to, um kind of like move our community or python community towards that, that newer version. So the way we access, if we use only python like this, we're gonna use we're gonna be basically using Python 2.7, which is the the last two version you can do dash V to see to check the version of it. So as you can see by phone, 2.6, 2.7 point six I mean, is what you get from python But we can also use Python three by just typing by from three, and then you'll see that we have 3.4, which is the latest by phone version. So that's that's good. So, um, there's there's a way to play with my iPhone and that's through the python shell. And the way you do that is you just use your state by phone or by from three and then press enter and you'll enter this Ah ah, basically, uh, terminal, where you can play with and do, like, small kind of functions and get to know by son better. So let's start doing some commands and start playing with it. 9. Arithmetic Functions: Okay, the first thing we're gonna do is, um, use by phone as a calculator. Yes. So you get an idea of what things we can do. Um, if I type through plus three, I get five. So, you know, that's that's, ah, basic stuff in there, but, yes, you get a feel for it. So three minus one is to for multiplication. Used to star three times eight for division used to slash 10 divided by two. Ah, One thing you'll notice is that in this operation we got a what's called a floating number . So it wasn't five integer body was five point. Oh, that's because my family is basically kind of like, uh, advancing or forecasting that you might get not, um, integer number. So if we do then divided by three, you'll get 3.3333 which is, you know, the floating number. Um, we can also do, um, exponential by doing two asterisks. So to the power of three is eight. Um, and you can also get the module is which is the reminder of a division. So 10 modules, three iss one because you know, 10 divided by three is three and then you get one more as the, um, seem arduous. Um, the last thing here's like we can, um, group terms together because usually divisions and modifications come before substructure in and addition, for example, if we do two plus three, uh, times five. What will see here is that the multiplication comes first, so it's 15 and then it'll add to two, which is 17. But if we wanted to do the two plus three first you put a parenthesis there and then in that in that case will get two. Plus three is five times five is 25 so that's kind of like basic arithmetic functions. 10. Variables: one key concept in by phone and in other languages is the concept of variables and viable czar basically boxes where you can store, um, some value in it. And then we can reference that value from from that boxes name, so to speak. So let's say if I have, say, a viable called X, you assign it a viable using the equal command, and then you do three. So from now on, X is equal to three. To see the value off a viable, you can use the prin command. So you do print Were you spying this season? Python three used to be print with apprentices X on python to So now we get the value of it . Um, because it's a viable we can change the value whenever we want. So now if I do X equals four and do the print of it, I'll get the do the new value. So as you can see, you can change um, the values off off a viable religiously Um, you can also a sign say we have another viable call. Why? And we can also then now a sine x equals why? And that all that will assign the value off X toe the current value of why, And we'll see why I say that. So if I do print exe now you see that I get seven. But if I change, why toe 10? What do you think? The value of excess the value of X is still the old value. Because this was passed as a value and notice of reference toe the value. So a for for me to change the value of X, I need to, like, reassign x equal. Why X equals y. And then if I do X now, get the updated value. Um, and of course I can. Some those variables, um, explosive y equals 20 um, and you know, do multiplication is and all that. Um another interesting thing is that I can also a sign, uh, strings to viable. So if I do that, say, now Z equals hello. Um, if I pray and see here Ah, you'll see that I have Hello there. And, um, if I have another one, it's a Z Z equals world. If I type c plus zzz, what happens? There is a concatenation. It's not gonna add the values of it, but it's gonna just contaminate the strings. However, notice that we have no spaces in between, which is you know what? We're basically telling it to the self. Refer us to put a space. We would have to do something I z plus quotes plus c z. And then we get the proper hello world. Um, one thing that you cannot do, it's at a a string to a number. We get a an error there because we need to, um, basically convert that one of, you know, the Z toe. Ah ah number which is not possible. But for example, if Z was one right and C c watts equals to two, if I do C plus easy, I get that era. Right? But if I do end of Z, that's basically convert see into an integer and then I do plus easy, Then I don't get the proper result. Um, so that's more or less an introduction to Virals. We're gonna use them a lot, so we're gonna get pretty acquainted with them as we move on to the course 11. Checking Types: a way to check the type off, the viable or the or the number, not the number about the, um the the term that you're you have is through the Taiko man. So, for example, if I do type off one, it says, it's ah, it's a type off integer. So basically it's, ah, it's an integer number. If I don't type 1.0, then type tells me that's a floating them. That means it has, you know, decimals in it. Um, if I do X equals five and then I do type off X, it's as it's it's an integer because it's it's assigning it to, um to an integer number. So that means the viable is inherits the type off, the off the value on If I change that to a string. Um and then I do type X again. I get, you know, the nuclear new classes. It's a string. Um, one thing that do you have noticed maybe is that I can press the type the arrow top and bottom to kind of like go through history so I don't have to, like, retired things again. Um, and once again, you know, if I do type. Hello? Which is a string I'm going to get type off strength. So that's a useful thing. Toe Know and learn. Um, when you want to, like know what? What? The type off a viable that you don't know exactly what what it is? Um, um, kind of like it's Andi. Schools celebrate as just as you see. Very. It says class, we're going to get into classes in later in this section. 12. Variable Format: one thing that you want to get used to, um or know about is something called Pep eight. So if you go to Google and just search for eight, um, and foot Python just in case you'll see this pit eight, um, guideline. And there's basically the style guy for the whole, like by phone coding. And that includes, like, you know how to use code using taps or spaces. What's the maximum lying length? And it basically goes through all the conventions for, um for those, um, you know, functions. Oh, are things that we normally do when I daily basis. So when you have a chance and you have, like, you know, you're having a long lunch and you want to get used to or get acquainted with all the recommendations for for how you know we type code in python, then you should definitely read this. Um, but in any case, um, going back to variables for valuables, we use basically numbers letters and underscores, um, so basically, you know a good noma Good. Ah, viable name is, um you know my var Sony's I use a an underscore whenever I have spaces in there, so I don't do this. My bar, um or do my capital case bar, which is something that jealous refuses. Um, so on the other thing is like try to make viable names as explained, explicit as possible. Like make them meaningful. Don't don't do like, you know, X X. Like I was doing zzz before That was, that was, that's not a good practice. If you're like writing a riel project, it's better to put, you know, you know, database, um, index value versus just like DB I, you know, try to use explicit names, things that you can. People reading the code. I can't understand what's what's going on. Um, there's also like a uh, it's not. None of this is really enforced, but it's it's again what Bebe dictates. We have a constant, which means it's a number that's never gonna change. We use all caps. So, for example, um, data bays ah, name, for example, equals test. So that's that's kind of like it's a good practice to have caps, because that means whenever the person or the developer reading the code looks at that, he knows. Oh, this is something that doesn't change throughout the code base it's it's Ah, it's a cat, it's Ah, it's capital capital life. So that means it's not gonna change, Um, but there's there's all the things that you should definitely look at and take a look at pervade when you have a chance because it's, ah, it's useful for you to get acquainted with it. 13. Strings: Let's take a look at some strength functions. And, um, and helpers. Um, strings can be expressed as quotes like X equals hello or as singles xolo. One thing to know is that strings are basically a raise, and we're going to see a raise, which in pie thunder cold lists in a little bit more detail afterwards. Spot basically think of Honore as a collection off individual characters. So what that means is that if I do, let's say X off zero. That means that I'm going to get the first character off the string. If I do X off one, I get the second. So as you can see, it's basically a collection or array off the strings. H e l l O. And that's something to remember when you you can kind of, like, get the, um, you know, sub strings off off a string by putting a range off characters. For example, if I do zero calling three, I will get the 1st 3 characters off that string, Um, the same way. If I do three through five, I get the last two characters. Um, the thing is, um, as we were seeing earlier, we can con card innate to string. So if I to why equals? Um hey, then we can do explosives. Why? And e get Hello, Paul. Um, if we want to do, like, the the space between the tool I just insert that space in there. Um, we can convert, um, a string that I mean a number toe a stream by using the str function. So, for example, if I have, it's a c equals three. Remember how we said that we cannot come cut in eight? Um, the integer and a number if you wanted to say hello, Uh, three. We would do X plus str off three off z. So str will convert the number three, which is an integer to us strength and their their works. If you wanted to the opposite, remember? Like if we wanted to have a a string that was, um, basically a number we want to get the value of it. Then we do I nt There's also some methods that we can use that are already built in on the strings. For example, if I wanted to have the hello all in uppercase, I would do x dot offer and, um off That doesn't make a lot of sense, I guess. Um, let's say why don't offer and we'll see Paul all in caps and I want to get them all to lower than we do X off lower. So there are more methods like that. But you get an idea off off some things you want to, uh you know, there there are certain my foot. So you can that you can use and one less one that you'll use often is Len, which is what's the length off a specific string. So, Len off. Why is four which is Paul? Um, so, you know, take a look at string operations. When you have a time, there's lots of them, but these are kind of like the ones that are used most after. 14. Lists, Tuples and Dictionaries: So let's take a look at three. Um, very useful types off variables when it's called lists. Um, list is basically a ah, a list of values that can be numbers or strings or both. So let's say X is one common to come on three. Um, and you close them with brackets, and that means that that's a list. So every print exe you get the whole list even to get type X, You get the type class is list, um so least are very useful if you have, ah, basically an ordered or in order kind of like least off values that are, um you need to get access to. And a lot of times, things that come from like the database are are returned as us lift. So you want, like, be able to look through them and get their their viable their their values. One thing you can you're able to do is loop through a list. Um, but that's something that we're gonna we're gonna look at a little bit later. Um, another type, um, or another, uh, yeah, kind of like different storage. Um, Function or or or class is Stupples and Topolsky is basically used with parts. So you can do you know, X equals one comma too. And that's a Topol. So if you do type off X, you get a Topol. So one thing that separates the list on the two poles is that you cannot once a to police, they find you cannot update the values. So it think of a Topol as a constant of, ah constant list or a static list that you cannot change afterwards. Um, to get both a triple and a list value at a specific position. You do basically, um, x off. Let's say the index so actually X off zero, which is this Topol? It's one x of one is is to So it's ah, it's always you always starts the next at zero something that sometimes we forget, Um and what? Basically, you can get any any of the off the values off that off that list or or to pull using that notation. So let's say that, um, we want toe. I want to show you how the we can change the value off off lease, but not of a Topol. So does the find that ex again as 123 If I do X off, one equals four now if I If I print exe, see that I just replaced That won the second value 24 But if I did this Tupelo 1 to 3 and you'll notice that I put a comma after worst, that's kind of like the the way that you work with topples, you have to kind of like ended with with the coma, even though you're not putting a value there. So if I do why off one equals four, I'll get in there because there's no item assignment on totals. Um, the last type that we're going to see is called dictionaries and dictionaries are basically key value, Um, objects. So basically, if I do, let's say, uh, first it first is Jorge and then last ISS Escobar. And then I used Carly brackets for those, so they say is a dictionary and the way you reference it instead of doing X off zero, which you would do in a list, you do X off first, and that will return Jorge. A lot of times these are called objects. Dictionaries are called objects because it's kind of like the first on the last are properties of that object. And, um, and their values are the ones that you put afterwards. Um, the last thing that that we want to see is, um, you can do a list off dictionaries, which is something that you'll see a lot when you're interacting again with with databases . So, for example, let's say we have, you know, users equals and then we have, um let's say, ah, let's to find another another user. Us, uh, why equals first Paul. Ah, and then last name is, uh, Gram. So now I can do users equals ex calmer. Why? So that's a list off users. If I print uh users. I see that I have all these objects there, and something you'll notice is that I eat set to the dictionary first equals pole and Lasses gram. But now it's printing. Last first and 1st 2nd That's something that you can not control on dictionaries. Is three ordering off the off the key? Um, off the keys. Um, and it's store basically randomly in python. Basically, there's no guarantee off that off off. Ordering off the off those keys. Um, but there are things that you can do to kind of like manage that Bought something for for you to like always. Remember 15. Date and time: Python has great control functions for dates in time. Um, again, there's a lot of information, but we'll see some, like, really simple things that you can do. So the first thing you want to do is import daytime, which is a collection off date and time, um, functions and and utilities, By the way, we haven't seen this before, so import basically means, you know, loading toe memory, this specific module. And this is a lot of how Python works. It's, um, basically, you import or you kind off ad any off the libraries or utilities that you have in your in your false system. But you don't need to, like, have them all loaded at once. So that's how you, you know, pick and choose what utilities you're gonna be using in a specific file. Um, and we'll see a lot off that asses. We get into the to the course, but now, after I presenter, I have all these daytime functions available to me. But when we're going to see is like, um, it's this called daytime, uh, daytime now, and what that means is that it's if I print that I get a the state, which is, you know, today, state and the the hour. Um, right now, off, off, off the computer. Um, so basically, since CLOUD9 operates in the cloud, I believe this is said already to, um two UTC, which is basically the the, you know, universal time or green each time as a So you have may have heard. Um and this is have very good practice. You never ever used the local time toe store as your time stamps because, um, you're gonna be basically, users are gonna be in different time zones, and you don't want to be doing conversions. Um, after the data husband stores. So remember, this is a golden rule. Always store time or dates in the database as UTC. But we'll see what? What? How we do that for now. Let's say this is the local time. So if I do now, um, it's a type off. Now you'll see that it's our off type daytime datum. Um, but now I can just things like Why don't year? Um oh, sorry. Now the year and you'll see that I get the year for that date. And I can say now that our I will tell me the hour. So, you know, I can basically, um, be able tow bars. Different difference. Different parts of that off that data. Um, you know, in order for us to start the the UTC properly, we need to import this specific, um, class or function ical daytime from daytime import datum. And now what we can do now is, um it's a time you to see, and we assign that to daytime UTC now. And that will give us, um, the UTC, uh, for for this exact moment. And as you can see, it's the same, basically the same hours as Cloud nine gave us as the local time, which is smart. I mean, they're using UTC. Yes, there as their as their time. So you don't have to do the you know, you don't have to deal with that conversion. Um, manually, but I still kind of expecting and and store things using this function You to see now versus this now function, Um, something for you to always remember 16. Conditionals Control Flow: So let's take a look at, um at two very important parts of the iPhone called conditional is and control flow. So conditional is basically you want to compare one value with another. And, um so basically, if we have X equals three and why equals four, um, a condition would be is X lower than four. And all those conditions give us a either true or false. They're basically billions. Um, billions are, like, you know, logical, true, false, kind off virals. So, um, if I do X is greater than four, then I get a false because threes is not greater than than four. Um, I can also do, um, is X greater than why? And that gives us a false a swell. Um, one thing that we can also do is X is not equal to why, and that will give us basically is eggs. And then than the value of X is not equal to the value of why um, we can also to, um X is minor or equal to its a three. That's true because even though it's not less than three, it is equal to three on the same thing. Why is greater than or equal to four. It will give us true as well. Um, so those are the basic ones? Um Then control flows is basically you can control the where the program goes by doing, if conditions. Right. So if I to If X is lower than four, then you would have a semi colon there and you press enter. You see how we have three dots there? That means that by phone is expecting you to put a kind of like the the inner peace off that conditional. So you can press one space normal you have to do for I mean, the editor, you'll see four. But in the terminal, you can do just one, and that's fine. So if if xx minor before then, then print exe is lower, then four. Okay, so then if I press enter and then print, print, enter again, then it'll execute that because X, which is three. He's lower than four. So that that does execute. But it's safe. We wanted to do if why is greater than five, which is false, right? So we can do, uh, print. Why is greater done for? What will happen here is that nothing will get printed. Why? Because you know why. It's not great and five so it escape and continue on. But there was nothing else to do there. So one thing that we could do is do an else statement. So if you do if Why, uh, these were than five, then I bring this and they put Els and also semi calling there and then put print. Why ISS say not greater than four. So if I press enter again here, you'll see that it'll it'll execute the second line. See? So that's if else, um, there's there's like you basically build all your your programs, using a lot of this like building blocks. So it's very important for you to to know them. I will get to know, um, more off them us. We continue with the course. 17. Loops: Let's look at loops. Loops are basically like the word something that cycles until something happens. And then usually they exit. Although we can have, ah, limited loop. And then, um, you can go on for ah for a long time until you basically stop the program. But let's see what that looks like. So let's say we have this list, Um, and five x 12345 We can look through all those values by using something called a four look . So what, What Four doses that basically you assign value. Let's would call that vow in X, and you put a semi colon and then you'll do something if, for every single item, it will execute that and it'll have vow as thieve value for that for that love. So let's just go ahead and praying Val in there. So if I pressed Enter, you'll see that he went through each one and they printed that that value. So that's called a for loop. You use that all the time. That's coming, kind of like one of those, you know, very useful functions. Another one we can we can use is, um, a while loop and for that. Let's try something else that say that X equals zero on the local here will be while X is lower than six. Let's say then we do print exe and then we'll do another one, since we need to, like, change the value of X because that'll be checked every time that loop ends, we need to say that X is equal to explosive one. That means now the first time it'll be zero. When he gets here, it will be at it. What? And now it's gonna be one. Any checks again. So now X, which is one is lower than sex. It's still prints that goes one of off. So X now is two checks that and so on until he gets to five. Right? And when the springs here we bring it will bring five. It'll add 1256 And when he tries to run that again because because six is not no lower than six, it'll exit and continue with whatever comments you have afterwards. So they see that inaction. And, as you can see, it'll be executed from 0 to 5. Um, the moment that it became six, um, it didn't execute anymore. Um, so these are some of the most used look bloops, but there's there some other variations, some of the things that that you'll discover as as we go alone. 18. Functions: okay, We'll take a look at functions now so we can define our own functions by using the keyword death, which is, like, define So they're fine. That's a, um, plus one. And then basically, you pass. You can have nothing here, or you can have parameters which are basically virals that are set whenever this function is called. So in this case, we're gonna pass. Ah, next. Viable. Um, so once that is is set, we can do stuff with that. Viable. So, for example, we can say, um, X equals X plus one, which that's why the function is called plus one. Um And then we can then print. Exe. Okay, now we have that that function. And if if you type pl us and then press tab, you'll see that Python order completes that because it already has that in memory. So for us to be able to see what what happens there we can past five. And when we enter that it'll return six. So what happened there? It called the function it past five us. The X basically X equals five. A merry did X equals equals X plus one, and it printed that value So if we did hear 15 we get 16. So you get the idea. That's kind of like what functions are And, um, we can we can we basically use functions all the time as well? It's very important that we understand how they work. Um, but play around a little bit with functions and see what we what you can get out of them. One important thing that I want to, um, two guys know and remember, Um, because it's a fundamental thing. There's something called scoping, and basically the variables that are defined within functions are not exposed outside. So in this case, if I print exe here, um, you'll see that I don't get anything because it's not define, even though it's their within the plus one. But that viable is called. It's called a local viable toe. That function, and that's the way that python kind off like protects the data from from the outside to within the function, Um, by using that separation. So remember that sometimes you know, students forget this, and they're like, Why? Why can't I get X if it's seen within the function? Remember that that viable is on Lee seen, and it's only apparent or usable by that function, but not outside 19. Classes and Objects: So, um, something that you may have heard is that Python is an object oriented language and, you know, object oriented programming is something that has bean, you know, being used for a long time. And there are languages are object oriented, like java by phone. But some others are not properly object oriented, like JavaScript, um, and ah ph B. Which they kind of like have bean getting towards object orientation. Um, and the main benefit off object oriented programming. And using that concept is, um is you know how to better manage data and make things were usable, um, and basically allow you to to separate, you know, logic in a in A. In a better way. It's a concept that you'll not grasp immediately. It's something that you'll kind off strong a little bit on, and you'll get to it by by practicing a lot. But think off objects as, um off, Let's say a basically a a physical object that's represented digitally with basically two things. One is properties on the other s methods. Properties are, for example, if you have a car, property could be the number of wheels right, which is, you know, for a normal like to say sedan. It's four. But if it's a truck, it's like 16 or whatever the case might be, that's a property. And a method would be, you know, start the engine. Something that its's kind of like a function off for that object and the class we call classes basically as a blueprint or the, you know, the schematics for you to produce an instance or a clone off that off that object. So let's do an example again. If you don't understand completely, there's a lot off things that you can read or even by using by phone and flash. You'll get a better understanding of what classes and objects are. But let's let's do an example. So one thing you you'll want to remember is that classes are they find with, um, basically a a Oprah case for each one of the words and no on this course within them. That's kind of like the the pep eight off them. So let's say, um, we're gonna define a class gold car, right? So the car I'm going to just have a, um, basically a property cold brand, so I'm going to define a method called. Um, you know, said Brand, and you always put self as the first parameter for these functions that are within the the class. And it's basically a way of saying this can only be called from an instance off that car and we'll put something here called Brand. So then I'm going to say the the brand of the car is whatever you passed as that brand on that function and let's let's leave it at that. So basically, now I can I can the fine copies off that class or objects or instances, basically instances of car that are basically clones of each other, and I can set a brand for each one of them. So, for example, if I say X is on instance off of a car and I put far into this year, if I put type off X, you'll see that it says it's It's a It's a type of car, right? Um, but now you know, if I print exe, um, I I won't get anything. It's just that a car object. Um, but now if I want to set the brand, I'll call that that function by doing x dot Set brand and they will put to your Okay, So now if I If I get the brand of the car, I does x that brand and I'll get Toyota. Um, so then I can do another car, which is why. And then I'll do Ah, why? Said brand. Ah, Ford. And then if I if I tried to get X to the Y brand again forward. So basically ex. And why are instances off the off the off the car class? They're basically cars, and I can set Mawr functions. Tow them, which are called methods. In this case, said Brian, it's a method. And, uh, you know, manipulator defined properties like Brand is a property, so we'll see up a bit more of that asses we go along. But that's basically very brief introduction of what glasses and objects are. A couple of things I wanted to add to our class lecture is one of them is called Ah, magic methods. Oh, are their kind of built in methods, and we're going to see one that's really important. It's called the innate function, um, which basically instructs how we initialize an instance of the class. Ah, by requiring some some Bibles to be to be passed. And the other one is, um, the notion off, um, subclass ing, um, which is basically you can take a class and then, uh, extended. And ah, that's gold in inheritance. You can hurt the older methods and all the characteristics of that class bypassing the class us the s a first parameter. But let's check out how how that works. Because we would not enter the Python interpreter again by from three. And we're gonna define a ah, again the class car and without any parameters in there. So I'm gonna define a, um, a new method, a magic method which is present in many classes. It's very often that we use this and it's called in it. So we need. What it says is that whenever you create a new instance of the car, you need Toby, you need to pass this viable that. I'm gonna be listening here. So I'm gonna do that by saying I need to be, ah, provided the brand when I create the new and the new car. Instance someone and then here again. And what that innit method does is it's gonna set the sell brand toe. Whatever you passed in, Brand here. Now I'm gonna create another one. Another method. This one is not a magic method, which is called Get brand. And what that does is it's gonna just, um, print the brand. Okay, so now, um, if we ah, execute this. So let's say we're gonna have our first car, and it's gonna be, um Let's say it's Ah, it's my car. It's called it my car, and it's gonna be a type off car. Right? Well, remember now we need to instead of putting to parents is like we did before. We need to pass this magic method in it and they need by the wedding. I don't know if I said it's too underscores in it. And then to underscores all magic methods. Have that that, um um, that protocol you need to pass to under underscores. So ah, here. We're gonna pass Toyota as the other brand. So what happened? Basically, I create a new instance off off a car class called my car, and when I initialized that I need to a needed to pass this this brand. So this this Toyota string is gonna be assigned toe that um viable that were a defining on the in it. And then it's past here to the self brand, which is the the local or the local viable brand that that car has. So now if I do my car dot get brand, it brings Toyota. So that was said properly right? It is the same thing That's just accessing the brand directly here, which is Toyota. But as you noticing that in the top one, the top example, it's not. It's not returned with quotes because it's just printing out on the screen versus this is actually the viable Toyota. So that's, Ah, magic method. There's many more one that we're gonna be using on our owner examples on the database. Um, it's ah, when called ar e pr or reproduce, I guess it's ah, it stands for and that basically will print Ah, the representation off that record off the database record on the terminal whenever you you pull it and there's their soldiers that we're gonna be looking at as well. Okay, so now let's look at our inheritance so inherent and is basically I want to create a new I knew collapse, but I don't want to like, let's say, do this all the definitions and all the things that that class already has, so I want to build on top of it. This is very common when you like. It's a working on an open source project, and some other person wrote all these Great. Um, you know, functionalities around. That's a communicating with a ah, with an Arduino um, on your, um, that you can connect your laptop, Um, and you want toe build from our toe on top off those libraries. Then you can inherit those libraries or those classes that that library defines without having to repeat all the work that that older developer did. So this is a very powerful thing that object oriented programming allows us to do in Python . So let's say that, and I want to create a new vehicle type of class called truck, But this time around, instead of leaving it empty, I'm gonna pass car asked the, um, as the parent class on there's like a it kind of like a parent, um, child, um, kind of like relationship. And there So this class truck, when I do that class truck car, it's inheriting the innit? Method and the get brand method, so I can basically it's basically the same thing. But then I'm gonna, like, defined a new kind of, like method on top, which could be, let's say, Ah so car or base or rather, this tocar so I would have a tocar method. And I'm going to say when? When? When I call that, um, it's gonna print out towing car, right? So that's it. It's a very, very simple classical truck. So now I'm gonna my I'm gonna define an instance of that. It's my truck and I'm gonna pass truck as the class. But notice that I need to pass the the brand because it's it's basically that is required when when I defined, Ah, the truck class as a subclass, um, off the of the car class. So let's say this is a four truck, right? So see that it didn't give any air or anything. It's it's It's fine if I get in my truck, um, that get brand, you'll see that even though I didn't they find that method in here, I still have it available, and it says Ford C. But my truck has a very specific thing that it can only do not. The CART cannot do that, which is a tow car. So if I do talk, are here, it's a stolen car. What do you think happens if I try to tow a car with my Toyota, which is my car? Any guesses? Well, we basically get in there because it says that that car object has no attribute. Tocar and it's it's saying, attribute. It's basically like a method, but that method it's not available. So that's that's what happens to that original class. It's not modify at all by this new, um, new method that truck is defining. 20. Modules: Okay, So, um, now we're going to see how to do this kind of operations without using the, um, the python terminal. Um, and basically, we're gonna do start creating some files. So to do that, I'm going to create a new directory. Um, so we're here in work spaces. Eso We're gonna make a directory called module tests, and, as you can see, there it created model tests. Um, and there's no files in their asses off now. So what we're gonna do is we're gonna create, um, within that. So I just control, click or out Click. And we're creating a new file here, and it's gonna be cold car, not B Y. Uh, usually you name the the files as the class they contain, but it's again. It's not a hard roll. It's not required. Bought? Um ah, we're gonna do that here. So now remember how well we're attack of before we were doing, you know, glass car. Um and then we're gonna say in it self brand, and then we're gonna do Ah, self brand equals brand, whichever you you're passing there. Um and they were gonna do another a method called get brand. I mean there were gonna print. Ah, self brand. Um, so now we save it. But when this little gray little ball there, that means that we have unsafe changes in the file. So make sure that you always you always see that little X instead of the little great ball . I don't know if you noticed. When I pressed the safe, it went from, like, yellow to green really quickly. Ah, yellow means that it's like the request is going out. And then green make make means that the server, the Cloud nine server. Actually, I was able to save the file to list right now to interact with that with that class. And so before you do anything, uh, we're not on that directory model 10. So make sure that you're going inside and you'll see why, Um, a little bit later. So another were with same module test. I'm gonna call the interpreter. Um, the terminal and we're gonna now be ableto work with that with that class. So the former for that is you usually put from file name without the P y from car import car. So I'm telling python from the car p y file import the car class so that I can do stuff with it. So as you can see here, a new directory popped up here called Pie Cash on the score, on the score, by cash on the score, the score, and within it you'll see that he has some, like strange file with That ends in P Y. C. And it's basically this is the compiled version off this file of carp. Ey off all this, and it basically allows Python to execute this files faster. So that's why by Chinese are very good language in terms off speed, because it will use this compiled versions of your foul instead off having to run the file from scratch every time. So now whenever I execute anything from Carpi, why it's gonna look first if it has a recent compile version of it, and then it'll it'll little done instead. And if he opened that foul, you'll see that it's all giver it. So it's all like machine code, so something to look for. Also, make sure that if you just get to ignore underscoring the score pie cash on the score in the score directories because there's no use for you to put this within your repository. So now I should have the car class a, um, available to me in memory. So I'm going to do the same thing I said it before. I'm gonna do an instance off the car class with the brand Toyota. Um, and now if I do my car, get brand and you'll notice here that I completely with with other, complete with tap. So say this. If a president the top here, it already knows what what methods it has available. So that's pretty musical. So if you do this, I'm going to get to Europe. So remember how I told you to going inside that directory before. So let's exit. You can do control the or type exit like this, and let's go back to the previous folder directory workspace and let's stop by from three. Right? And I'm gonna do the same thing from from car import car. I get an error. It says No module name car. So this car file it's not being able to Toby loaded on the, um on the directory from that directory mean So what's happening here? So, basically, if if where you run python from makes its a lot off. It's very important. And you're going to see no module name. Block a lot in your careers is just, you know, try to do some common sense and ask yourself, where am I running python from? Are the directories that I need? Um, for those, um, available to me. So the way that you fix this error is basically, you need to check that you have a very magic another magic, Um ah, thing here. But it's but this time it So it's a file, and it's called in it b y just like they in it on the class. Now we're gonna need to create an image file within model tests. But before I do that, let me delete this. And one thing that you'll want to always, um, do in your in your work is to be organized well organized. So when I delete the by cash file and I'm going to create, I'm gonna see the toe module test. And I want to create a director called vehicles because when I want to do is I want to put all the, um, the classes that have to do with vehicles within this folder. So I'm gonna move Car B. Why? Within vehicles? OK, so now vehicles has that and for all, still be ableto call vehicles A module. Okay. I want to create a file called in it B y. So new file. I'm just going to score in it that Ah, and it I'm just going to score p y. So it's on this going to score in it on this Going to score dot people with this file, you don't have to put anything in it, although you can. Technically, um, gonna say yes to this. No, don't. Don't keep it. That's the old carpet. Why? Okay, let me open it. Here. Here, you can put also code. And whenever you import from that module, that court is going to run. But for this this time, we're not gonna do that. Okay, so now notice that I have, um, that vehicles holding their if I see what's inside vehicles, I have to any people on the carpet wife. And I'm gonna run by fun from the top folder module tests. OK, now you're going to notice how the foreman is going to change a little bit. I'm going to say from vehicles dot car import car. So what's what's Python saying? There is that from the vehicles module And what defines that as a module? Because it has an NDP. Why fire within that folder? So it treats it fits vehicles as almost as if it was a P Y file itself. You see what? That how interesting that is. And then you're importing the car file. Ah, um, on inside that vehicles module, and then you're going to import car the car class. So now I can do the same thing. My car equals car Toyota, and then my car get brand. See, everything works perfectly fine. So I'm running by thumb from here from module tests. Um, what I importing from vehicles? Carpi? Why the car class? Okay, so that's something that it's really important for you to, um, manage and to be able to master on something that even, you know, it's us. And experience developer, this model not found. Thing is you're gonna have You're gonna have it. And you just have to, like, stop for a moment and think of yourself. Where are you going? Running python from those are called a path. So you can. You can also like the fine paths that that can be searched. So so to speak. We're going to see that through other course, but But remember to have that in it b y file on your module, so you can you can do stuff with it. Okay, One last thing that we're going to see here in this. Ah, this lecture is Let's say that I want to do by found three and then import the dual that I want to like Run is correct. That does all that for me. How should I do that? So we're gonna create a new file at the level of model tests, and it's gonna be cold. We're gonna call it wrong people. I okay. And what's wrong? P i b we're going to do You're gonna be able to basically do what we said or we did on the Python interpreter, but problematically So we're going to do the same thing that we did before from vehicles car import car. Um, and so now we're gonna do, um let's say my car equals car Toyota, and then we're gonna do my car. No, my car. Get Brent. This is something really interesting. You see how Cloud Nine's editor is Is kind of loading the models or the methods? Um, it even is gonna, you know, tells me, like, what? What parameters do I need to pass and all that? So this is pretty useful. It's kind of like already giving me hints off what methods are available. So that's that. We're going to save that. And now instead, off loading the Python terminal, we just do python three Run B Y. And there you go. You get Toyota. That's what it just ran all that. All those commands and it printed out to yoga. 21. Parameters: Okay, The last thing I want to cover here with with our fight. But python introduction is function arguments or in this case, classmethod arguments. And you'll see this a lot in working on a daily basis. So there are two types off functional arguments, um, or function arguments rather. And they're either keywords, um types or positional times. And what that means is that when you have, ah, method like get brand in this case, we don't have any arguments were no, we don't require any arguments to be passed. However, there might be an instance where you want to have, um, another function. And it's a that's great one that's called open door for our car class. And in this case, I'm gonna say, Ah, door number is a is a parameter or ah, one argument for that for that method. So what that means is that you need to pass in this case a an open door function, toe that class toe or rather that car instance, and define what door number you want to to open. So let's say it's one for the driver and two for the to the side of the driver's side and then three and four for the two in the back of the car. And, you know, I'm assuming that it's a four door car. So in this case, I'm going to just say, um, let's do a print statement and and will say Opening door and then, um will just tack on the door number and let's make this is us three str because it's ah, it's a number. And that's the way that we should be able to to go incarnate those two strings, right? So we saved that eso here. What I'm defining is that the door number is actually a positional argument because it's the 1st 1 Okay, and we'll see. We'll see a better example when I do another one, but let's some let's play with this. I'm just gonna run the terminal and, um, let's say from car from vehicles, the car import car Oh, I think I'm not in the right directory, So let's go to model tests and try that again. So there we go. So now we have you know, that's a my car, vehicles and instance of car, and I believe now we need to pass a sparkler in it. The the brand, right? So it's a Toyota. So if I do my car get brand, um, we'll get that, but notice. So I'm gonna I'm gonna try to open a door, right. So let's say what happened? The driver's door. So I say, open door. And if I don't best anything, I'll get in there because it's saying it's requiring one position argument door number. But that means is that it knows that the function requires that the first does the positional moniker here. The first argument needs to be some sort of off value that that the function needs. So I'm gonna try that again. I'm gonna say my, uh, my car, Open door one. So now I get opening door one. If I passed too, I get opening doors so you can see that that viable has been assigned here. When, when I call that function and then it's it's printing it out here, and it's kind of like available for that for that function from that from that point on. Okay, so now let's destroy another. Another method we're gonna add, which is gonna be, um, we're gonna have a ah function or a method for these class that allows me to turn on or off the, um, the blinking lights. OK, so let's say deaf, um ah, blinker control. And what we're gonna pass here is gonna be left. Ah, blinker and right blinker. So I'm gonna have to say it's either on or are off. Okay? And here I want to keep, like, the status off the blinkers in the kind of like in the class itself. So I'm going to say self left blinker equals left blinker self right. Blinker equals right blinker. And I'm going to just say, um print, uh, I want to say left. And then the status off that linker and then right, str so right to blink, Okay. And, um, close that. So what I'm gonna do is I'm gonna actually check with an if so that I can turn on and off. So if left blinker, um actually, no, that won't work. And I will tell you why in a second, So we need to pass both both of those functions. Okay, so once again, I'll do the python here, and I'm gonna import and put an instance off the car. So now I'm gonna do my car dot blinker control. But I need to pass left Linker equals, say own and right blinker equals off. So now it's saying that the left blinker is on in the right Blinker yourself, but you know, in when you're driving the car, you don't really tuggle or or passed both of those things. You either passed one or you pass the other. I either little kind of lever, right? When you put the lever toe the, you know, upright position, you're turning right. And then if we put it on down position and it's it's you're going left, so I wouldn't make the function kind of like behave a little bit like that. But the problem is that I need to pass both. So what happens if I just pass? Um, the right wing or the left blinker? Only I get another. It says missing one required positional argument, Right blinker. So you see here is like saying I need to pass the ah, the 2nd 1 And so that's kind of like annoying. Right? Um, So what do we do there? So we have the option to do something here, which is we convert this instead of being a um, a positional argument we're gonna do This s A S. Ah, it's ah, keyword argument. The way you do that is you can put you can put an equal signing here, okay? And then you can pre ah, load the the value off those off those arguments. And, um, and from that point on, it's ah, it's gonna be an optional or or or basically you can either pass it on or off. But, um, let's just start with this one with the right blinker. So you see this how this works. So I'm going to say the default value of right blinker is going to be off. Okay, so if you don't pass that it's fine. It's gonna be wife is going to say All right, wing was impasse. So that's fine. I'm just gonna Preed defaulted toe be off. So you see that in action? So we'll do this, um, important this and then I'm gonna say my car is car Toyota and now I'm going to just pass the 1st 1 which gave us a never before. So let's see what happens. See, now I can pass only the 1st 1 I mean, the left blinker one and everyone and I didn't need to pass. So that is from that point, it's It's called a, um, a keyword argument because the keyword is right blinker, and it already knows that that might be or might not be passed to the function. One golden rule that you need to know is that you always put past the positional or required parameters to the left, and then they once are optional. Um, or key were arguments to the, um so the right oh are basically trailing. So so always list the ones that required first and then the the ones that are optional. Or have a pre set value toe the toe, the trailing side. So now I can really do what I wanted to do at the beginning, which waas basically have this kind of on a total basis. So if I put both by the fault are off, I can say if left blinker equals on, then set the self lit linker to to on and then put the right blinker to off and the same thing. Um, if right linker, then that's like else. If else if right blinker is on, then you want to um, basically put the right blinker toe that value and turn off the left Linker if he was on already and take this out. So now the function is gonna be If I passed the 1st 1 us on, then the right blinker is going to be turned off. And if I passed the right blinker on, then the left thinkers gonna be off. So let's see if that works. Um running stunned, she ate the car. Perfect. So I'm gonna do my car. Ah, blinker control. And then I'm gonna plus left blinker equals on. So what? What happens here is in passing this on. So even though the, um, the right blinker value can be be on, it'll be turned off. So let's see that Words. Okay, Perfect. So now I have the left lingers on and the right one is off. So what happens if I instead buys the past the right blinker? I'm gonna turn right, Right. So now they see the life. The left one was set off, and, uh, the right one was turned up. So I know there, uh, quick thing that I want to mention is that if you can, you can also pass or make this parameters be none. And what that means is that there might not even be be passed, and they're gonna be initialized with with a non value. So that's that's the way that you do like you. No parameters that you want to be able to pass or not pass. It doesn't really matter. And you can, um and you can make, you know, check if they're sad or whatever they can be. They can be passed the last thing. And again, this is this isn't for you to remind this. Like, if this is a required one, always put it at the beginning, and then the ones that are not required to the to the end. So that's it. I think we're ready to start building our Fleiss application and, you know, play a little bit with this and and have, um, you know, make up some some fun, more features toe our car class. Um, and you know, if you have any questions, let me know 22. New Workspace Virtualenv: perfect. So we're going to start our flask, Um, adventure here, and we're gonna start by creating a new workspace and, um, basically start our first flask app. So create a new workspace. You're gonna have to define a ah project name. Uh, and we're going to call this the, uh hello? Up. Um, you can put out Trump description there. Uh, there's no need for that. You can also, um, make this private or public for for paying customers you can do. Um, I think more than one. If you're like a free customer, you can only the one private Berber account. And you can also clone from existing get, um, repository, but for us, we're going to start from scratch. Um, so there's also these templates here. You can do, you know, custom. This is Theo Bone to basically logo. A custom open to installation. You can do which they may have five. No Js. All these things were gonna just use custom here and then create war space. So now it's basically creating a new server for us. Um, and, um, it takes a little while while it's creating that container, which I, as I mentioned before it's using docker containers. So here we go. We have are our container there One thing that I will tell you right off the bat this. Hello Up here on, it's something that I'm gonna probably contact See Cloud nine to see if they can change that. It's a little bit misleading because it appears as if you were in a hello up folder. But if you see PWD, you're actually on home a boon to work space. So, um, this is referring basically to leave toe the workspace folder and not the, um the hello up There's no hello up folder there. That's something that tripped me off a little bit and it tripped. Also some, um, some of my some of my students there's also, like, navigate and commands here, but I always keep it on workspace there. So, um, let's create on actual folder for our our ah first project. So we're gonna do make the air, and we're gonna call it flask. Um, underscore in it. Always used, underscores for folders on you can use Stashes as well. The foul system will let you. But if you're doing python work on, you're gonna up half modules that, um, that you're gonna have to import it center. It's very to use on the score. So, in one in basically a golden rule that you wanna have from now is that always always have folder names with on this course and not not dashes. So that's why I recommended you put a dash in here. So you remember this is not a folder. So but hello up or, you know, whatever the words temporary by dashes until you remember. Okay, so now we're in the flask. We're gonna go in the flask, innit? Folder? And that's how are basically our home folder there. And the first thing we're gonna do is, um, we're gonna have, um we're going to create basically something called a virtual environment. What's a virtual environment? Virtual environment is, um a It separates each projects where you have you can have multiple projects. Were simply can have a flask in it. Project that you can have another like, the flats block problem that we're gonna do afterwards. Is it gonna be another folder? And then each folder it's gonna have its own set off libraries, um, version off python, and you gonna be able to run all this in the same server. So that's a pretty big deal. It's It's a great thing. And it allows you to track which which libraries? You installing that folder by using something called A requirements file. But don't worry about all that. We're going to see that through other course. For now, Um, just make sure that you created your folder, and now we're gonna create this virtual environment. So how do we create a virtual environment? It's very easy. You use virtual and which is this command that, um that is, um allows us to create this this this separated environment. And then you're gonna dio basically you put a folder here where that well, where those files, those libraries, those python versions we're gonna live in. But because we're using Python three and boom to or at least cloud nine, you can check the version here. But if you do python, that's fate. You'll see that it's by from 2.7. So we want to do a veto environment that uses by from three. So for that you do virtual and then you pass Dash B, which is python version, and you put by phone three. That's basically the execute herbal that we're going to use on. Then the name of the folders gonna be ve envy. Um, you can put any name you want in there. However, it's easier if you use it always the same the same name, because you know it's gonna be second nature for you, too, to always activate this virtual environment, and you're gonna see that in a bit. So virtual em dash be Faison, three VND. So what happens there is that it creates a new virtual em with with python three within the flask. Innit? Folder. So now, um, if we see here, see, you'll see that it has a new folder called Virtual Environment. If you're looking there, you're going to see Ben, which is the basically some commands that retirement needs to execute another. See Lib Labour's world. The virus will live and if you click here, there's python 3.4 and then side package is going to be another important one because that's where the older packages or the libraries and when stole, are going to be installed at. So, um for now, just know that we have that V and V p um folder in there. So now what? What What is it that you do? You basically need to activate this virtual environment. Activate means that from now on, all the commence for installing things and for running things are gonna be done as if it a CIF This environment was your whole server. So the way to do that issue have to memorize days, but you're you'll remember That's you Do it over and over again. You do Source V E N V. Which is the folder with it before been activated. Okay, I want you to look at him. This here. You see how now he has a parenthesis at the beginning? I ve envy. That means that the virtual environment is activated. Do not And I repeat this in like red front Bold letters. Do not do anything with your project unless this V envy thing is on the on the beginning off the of the foul, um, structure or or the prompt, because otherwise bad things will happen if you, you know, install packages and that V and there's no turn on. He's not gonna install them here on B and B. It's gonna install them side wide or server wide and a lot off things will happen. So remember, um, always have that V and be there. So let's how does the act How do you deactivate? Well, once you're activated, you just type deactivate, and you'll get out. See, now there's no being and be there. Um, but remember your you know your had your coffee, your open up your cloud nine. To start working, you go to your directory flask in it or whatever your product is working and without, don't even open the editor. Don't do anything do source than being active and press those types. You just have to play like, type like two letters your spreads tab, and it'll order complete and make sure that you have that ve and be at the beginning. 23. Pip Install Flask: Okay, so now let's install flask. So flashes a basically a collection off libraries. And, um, remember that we have the ve envy in there. That means that we're good. Okay. Do not do this with without that. Also, just to make sure that you're on the underwrite, the bright version of the iPhone, and that the virtual environment installed the right version. Just a python Dutch, be if you don't see 34 You see, you know, two point something and you don't see three point something that your you know, your put your very own environment. It's not defined, um, or activated. Or you didn't pass the dash p flag properly and he didn't find a python. Three. Execute herbal there. So hopefully that's not the case. You should have python three 0.4 or something similar in there. Okay, so we have that. So how do install packages? We use something called Pip on. That's the bike by phone package installer that allows us to easily just, you know, do pip install X, and it'll go in the, you know, the internet. Look for that package, and then if it finds it, then installs it locally and it's gonna install it again in this ve and be labor python. Three side packages. So I'm gonna leave that open, see if we can check out when flask is installed. So, like I said, you do pay ping stall, and then we just have to pass flask. And as we press enter, um, let me put this a little higher here. Um, you'll see all the packages being installed in there. Yes, so you can see here. There's now flask. Ah ah, Flex folder. There's ah ah Jean job, too. There's a markup safe on. If if you read through the funds that were being stole the same thing you you see that, um, there was a flask voreqe soy ginger to its dangerous markup safe. So those are old libraries that flashed requires for a two to work properly. But, you know, you should see something that's a successful installed flask and all these other files if you got any errors, you know, try to check if you're missing something. If you mistyped it. Ah, etcetera. You should You should be fine. Um, And that means that now flask is is available. Um, so that's it. We're gonna now in the next section, start building our application or our first flats application rather step by step and let's ah, let's go there. 24. C9 Python Path: So I wanted to do this clarification because there's something that cloud nine recently changed in terms off there. Um, linking on. Lending is kind of like a a program software that is constantly checking if you have any kind of, like mistakes or errors on the on the code that you're writing. And they recently they're being kind of like improving their by phone support for, you know, things like, uh, maybe I and, um better, better kind of like linking and support. And one thing that introduced that it's not, um, doesn't help. Uh, kind of like our The way that we've been writing the code is that, um they now you need to like, um, specifically, uh, tell them or tell the editor the path where your virtual environment libraries work, and I'm gonna show you an example. And so you have on idea of what I'm talking about. So I have this, like, test import, um, workspace, and I'm going to do a new file here, And, um, so I'm gonna tow um, actually, let me let me save it. Then we create the file from here, and you file and I'm called going. Dad. Hello? p y. So I have a visual in for Eddie that have that has flask imported, I mean, installed in it. And as you can see here, if I go to side packages, you'll see that I have. I have flask in there, right? However, um, there's a little problem now that, um if I if I go ahead and start doing my code and remember that you need to like, um um source, uh, virtual environment. Activate here. But that's even before that. Um, if you do from ah ah flask import flask. Right. And you try to, like, continue working in your code base. Um, you'll see that you eventually get, like, a little like red. Uh, sign here saying, like meaning that the court editors not finding flask. Um, sometimes it takes a little bit to appear, but, um, it's if I can open another c opened. Read me here. I'm looking at Harris This here and see. I get this, like, unable to import flask. And let's forget for about this for a moment. So what's happening here is that it's, um the editor is not able is not finding the where the what That flask libraries, and it's currently looking just at the at the current path, uh, where the python path that they have pre installed, which is the one on the, uh, on the main server. So what we need to do to have that disappear and you'll see right access for other things that are imports from your virtual environment packages. I spoke to Toe Cloud nine and they actually, like were very helpful. And try to, um, kind of like work with me this this issue But what you need to do to get the red the red Xs go away is you need to like it's explicitly tell the editor where the side packages off your virtual environment are, and the way you do that is the following you go to the re envy go lib. So open your live here and then goto bison 34 right, And then go to Sai packages and they're right clicking there and use Put something that says open terminal here. If you see that, um, it will take you to the toe, the toe, that path and then you just dopey wt which is, you know, person working directory on you get this this this this path, this is the path from the beginning. I mean, from the root off the server to your side packages off your virtual environment. So just make sure to copy their, um um command, see or control. See? And then you go to the gears here and where it says, um hints, and I mean language support. You see, there's a bison path now in there and you see this there's there's two patsy there. Those are the ones from the from the server. Make sure you go to the end of the line in there, put a semi colon and then paste the path of you. Copy it. So you see, here it's the sack package, A spice on 34 the envy live, etcetera. And, as you can see here, it has the same. My column would be before there, the one that was already there. So you press enter. You don't need to do like, say, for anything. It automatically saves that and then close and close this one as well, and you see that this is going to go away in a in a minute. Um, because now it's finding the path were for flask, so you can continue working here. Um, and it eventually goes away. See? So that's the thing. It's a little bit of, ah hassle, because before, at least from when I was working with it, they didn't have that that problem. But now you need toe do that. You need to set your python path. And at the, um, at that library, um, that side packages path on if you see any, any any little right access with any of the packages trying to import, kind of like look at where they're stored And if you don't have that kind of liking here, but it's installed somewhere else in the spice and 34 um, kind of like directories. Just go ahead and put another semi colon and at the path where the containing path or folder where that libraries. So that's the update. Hopefully, that will solve any problems. And if you have any issues, just just think me 25. Minimal App: Okay, so let's start our ah flask. Um, journey here. Um, you should have the handle app workspace ing there. Um, we're gonna go ahead and open it. Um, perfect. So now we have we have our virtual environment, uh, within the flask. Innit? Folder? So remember, Hello? Dash up. It's not a folder. It's just the name off the, um um off the server of their workspace and a flask in it is the actual folder that we've created. And then virtual environment is the virtual environment. So before we do anything, remember what we need to do here before you start coding or doing any any kind of operation . That's right. We need to activate our virtual environment. So you do sores Vande being activated. And remember, you have to be there on the flask. Innit? Folder. So if you by any chance it's ah, Control. See that, um, it's a your in your workspace here or in home. You do see the workspace flask in it, and then in their you do the source. Um, sorry. Sores. Um, van being active. Okay, Now that we have RV and be there, that means that we're good to go it's clear the screen and the Stipe start typing our first flats application. Okay, so let's create the file where we're going to start the the application. Let me close this. Read me because we don't need that. And the late the file, um, the leap. Great. And I'm gonna briefly disappear the dis terminal by doing control escape. So let's grand your file here, and it's gonna be called Hello, P, y make sure that it's on the flask innit? Folder, and it's on the same level as they ve MB. Now, let's double click there to open it. And so the first thing we're gonna do is, um we're gonna type from flask import flask as you remember this from the modules lesson that we just saw on the previous section. This is just saying from the flask file import flask. Now, if there's no flask director here, how's it finding that? Well, so the thing is that we've seen a spot of the V envy activation, um, python eyes said to look for files within this side packages a swell of other directories. So that flask, um um, file or folder? That's being, um ah, reference. There is actually this this flask here. So that's how it's ableto find it. But let's continue from flask import flask. Um, usually there's the first thing that you need to do on the flash application is to define an instance off flask class by doing this line up equals flask and then a magic meant method called name on this Going to score name on this Going to score this name or the department or that's being passed here is just to make sure that you have on unique application, um, name, um for the for the flask instance. And on this kind of score name just contains a string that, depending on where you call this file, is gonna be either underscore underscore main underscoring the score if it's called from the terminal, or it's gonna be called hello if it's called from the from the python terminal. So basically just side that is usually what you do, um, to make sure that you have a unique instance off that off that flask app. Um, the next thing is, we're gonna define ah route and around it basically, the your l that you're gonna be hitting, and then we just put it in here. So you see, um, this little funny at sign of the beginning off this, um, off this method off the app instance is called a decorator, and a decorator usually means modify the next line or the next thing that happens after this, Um, with some sort off behavior and what we decorate is these function called Hello world. Okay, now, don't don't don't worry. If there's a lot off new things happening here, you'll get the hang of it as we continue to play with this. But we're basically they're finding a function within this file called Hello World, and we're gonna return. Um, hello, world. I don't believe we've seen return, but return basically tells a function when it's completed. Um, Or when he gets to that point, just throw that whatever viable or string or, um, uh, expression you have after the return back to whoever called it. Um, and we're gonna see how that works in a second. So now we're gonna say if name, which is the same magic thing that we have here. The magic method. If name equals main, then that means that were being called from the from the from the terminal from the from the command line and not from the python. Um, terminal. Um, so then we're gonna do app that run, and we're gonna basically leave that I say us this is to print it. So what run does It's basically create a server. That's all the time waiting until somebody hits a on address off that application. And, um, and just, like, routed throughly through this routes to whatever function it matches in terms of the folder . Um, however, since we're working with with cloud nine, there's a couple of things that we need to add in here. One is, um Before I do the import there, you need to refine a host. So we're gonna do this by saying host equals, um os that get environment viable. I p comma 0000 And this is basically saying the host for that For this, for this application is gonna be either the i p that's passed by Cloud nine just like a preset environment viable. That contains the servers I P. And we also need to define a port where this is going to run. And in in this case, we're gonna have, um, convert toe into Jer the, uh, environment viable cold port or past 5000. Okay. And then we close this, okay? And now we have we passed this as host equals host, comma port, equal sport. Okay, so you see how I'm getting, um this this errors here? Um, basically, I need I need to have always available, so I'm going to tow import. Oh, as and we should be fine. Oh, this air here saying on the fine, viable name. Yeah, I'm missing another score, so see how cloud nine centers? It's telling me all the time, Like if I have errors, that's very, very useful on the heirs. Are you city? Very expressive. So, um, that is ah, pretty Brickell thing. So let's save that, um, control s or command s if you're on the Mac and we should be good there. So whats happening again? Um, we're importing the flask class and extension eating an app or application using the underscore. Underscore name. Then we're saying if anybody hits the slash, which is like the top domain then executed this function and the function is called hello world and it returns to string. Hello, world back to the person that that hit that euro. And then this is like the main kind of like a runner part of the script, which is, if name is Maine, which means that it's being run from the terminal. Then we're going to define a host, which is the Cloud nine host and the Cloud nine port, which is Ah, the I p viable if it's set. And if not, it's 0.0 point 0.0. We just an I P. That's, ah, you know, basically explosives, the application to the world and then port Is the integer off the port m environment viable or 5000? Which is the flasks? Default. If you were running this on a kind of like a Lennox machine or or Windows or Mac locally, you don't need these two things and flash, but basically run by the fault on the 5004th. But that's, um, that's all you need to have for our first application. So let's see how it runs. So do control escape again, eh? So we can bring up the terminal and remember, ve envy has to be there. It's activated, and you need to be on the flask, innit? Directory, and you need to have your hello p. Why they're your B m v. Um, so basically, we're gonna do Python. Hello p. Why OK and hit Enter Perfect. So it says now that it's running on HDP zero points Europe, once you're aboard 08 80 which which is basically like it's running for every anybody that hits the port 80 80 which is the Cloud nine's development environment. But it's not really, um, you know, it's not really the, um ah, that port on the outside, it's it's bright running, really on the port 80 which is the normal, you know, kind of like your URL for extra P services. So how do we see this like, there's no how do I kind of like, look at the running application. There's this. Previ and run bottoms do not work with those. Preview just allows you to like preview a file, annexed email or static content and run executes the file, but unfortunately it uses the python 2.7. That's not our virtual environment, and there's a way to run it, using the kind of like you can modify what python execute herbal and you could potentially define despite unexcusable here and vent. But I haven't found the time to do that yet. Maybe a student that has a little bit more time Can ah, figure that out and put a example there in the in the forms. But for now, the way we see where it's running, where you go to the share here on the top and you see that you have on enter application and preview editor is to share your your code. Um, and application is the the actual were all there we want to look at, Which is these this string? So it's basically you are work. Um um, your ah, your projects Name dash, your user name dot c nine dot io. So if I clicking there and I click open, you'll get another tap. And there you go. We have Ah, hello world, Which is Ah, basically our first flax obligation running. Congratulations. 26. Starting with Git: okay, There's our beautiful flats application running. And as you know, um, um, I'm a big, um I recommend, like, really strongly that you they learn and, ah, use Get as your version control. If you haven't heard about get or you don't know about get a lot, um, there's definitely of course I want to recommend to you, which is the are owns essential get course, which is also here in you, Timmy and basically essential get course teaches you like the basics without going into, like, you know, cause Skip gates are very complicated tool that you can do a lot off things with here. In this course, I'll teach you basically the very essential things that you need to to have as a developer to work on a daily basis like there's some other, more specialized things that you could potentially do. And you can learn after you do the course. But a taste for basics stuff and to get your your day to day operations for forget, basically recommend that you do this or, you know if you want. You can also look at other get courses in una me or on the Internet, but I went out like that. You are quickly how we would do that here. So whenever I started project, I initially, you know, from the beginning, I just start getting my my get set up. So, you know, for those for us to do that, um, you have to be on the root folder, and you do get in it. That basically creates a get, um, I get in. Ah, folder. Um And, um, we want to have a did ignore file so that we don't have, for example, those python, um, compiled directories or things that we we we usually do. So I have a, um a starter gettinit file that we can use, which is the following. So being a new top here and just go to a guest. Doug, you have that come slash from serie D you and you'll see a get ignore fouling there. This is the getting nor so you should start with this one. Um, you can put raw here, and then just copy and paste that. And so we're gonna create at the same at the ruled level. Um, new file dot Get ignored. No, I did that file and put this which is a good starting point for funds that we usually don't need to check into a repository. Perfect. So now I'm gonna do get status to see what? What? What's new have to get Get ignoring him. Hello, P. Why I at those files in there, and I'm gonna commit this with first coming perfect. And now I can basically push this to get hub again. If you don't know any of this, that's fine. And you can continue the course without it. I strongly recommend, though, that you get yourself started would get. And, um, you know, let me know if you, um you know, if if you have any questions on how to get the course with with a discount, um, but definitely will recommend you to get get a spy off your professional developer tool set . 27. Debugging: Okay, so we have our application here. Um, with the hello world Askew can see everything looks pretty much the same. If I see here, I see Hello, world. That's perfect. So I'm gonna do control escape and put the make the application run again. Um, and there's the other world. One thing that you're gonna be finding yourself doing a lot is editing code and then checking the of this. Ah, if this change looks good and nothing is breaking So let's say we want toe change world to Hello, everyone. Um, I saved the file and then go and reload the page here, but I still see Hello world. So what's happening? Well, what happens is when this page is already, um, let's say this application is already running. Um, this, ah, this code basis not being updated because remember what I told you about having the application being cashed, which means that it's it's kind of like on a static mode, and it's just retrieving the the most recent version of the code base. But it's not really, um, reflecting the changes in there. So that's that's the pain, because that means that I have to like control. See here and then put python Hello, p y again. And now if I reload the page, then I'll see my change. But I don't want to be doing that every time. Right? So again, let's save if I change this through Hello world, save it And then we know the page Nothing is there. So one way that we can go around That is, um, by passing another flag and that flag, it's called debug. So the way we do that is by doing the following, we just have to add a We referenced the app, the app instance. Which is this happing since here. And, uh, let me clear that and then you put the bug equals true. Now you don't want to do this on a on a production environment because app debug actually is lower. And you will also are us weaken. We're going to see later. It will display the errors on the page. Um, I say as they occur, and we don't want to do that for, like our public facing application. We just want to, like, display Ah, a generic, You know, 500 error or application there with some like you know, nice image instead of like, spitting out, You know, the by phone error, stock trays. So let's see how that works. So I've did active articles. True. Let me bring up the, um, the server again, and I'm gonna run this again. Python had Opie. Why? So if I refresh here, it says hello world. But notice here on the bottom as I changed this to Hello, everyone. And then save as you can see, it says detective change in this directory reloading, Restarting with that so I don't have to stop and restart the server. The changes are reflected just by pressing refree Load on the on the browser. So that's a big help. And that, um that also helps you, you know, continue working on your core base without having to like, doing control. See? And then we started again. Another cool thing that we can do here is, um, when you have Abdi particles true. Well, let me show you before without the Abdi particle structure, let me save this, um, any control, see, just in case. And so what I'm gonna do here without the active illegals? True. I'm gonna introduce in there. So one thing I'm gonna do is like, let's say I'm gonna put I equals three, and then I'm gonna put, um, you visited. I need to put dollar courts because I need to put a You have visited something I'm gonna put, um, I times. Now, if you remember, um, from the, um, viable strings section, we cannot put a plus I here because this is an integer and this is string, so that should return in error. So what happens when you don't have to? Barnicle's true, and I'm gonna reload the page. I get on internal server error, which is this like how it would look on normal size and that's preferred instead of like, showing toe the public users What happened there's, like a more, um, like, nicer communication toe. The the user saying something happened and, you know, there was something unexpected. But when we're developing, we want to probably see what's what what went wrong. So, um, again, we are gonna put the barnacles true here, and we're going to run the application again and see what what happens. So see, this is a much different error message. Now it's actually telling us where the air is, and this is called the stack Trace. As I mentioned, it basically says, you know, from from the very in in ward or internal peace, What what happened on do usually just go back and kind of like escape until you get to like the actual application. Although after you've been doing this for a while, this this, some of these things might make it might make sense, but, um so here's the air that we really are interested in. It says type air can convert int object to string implicitly. So that means that I need to put a conversion of that I toe string before I can add it to those two strings. So that helps a lot. And this is something that, um, that we can we can definitely use while we're developing, but not not for the actual like public users. So the way to fix that as you like no, is I put stir, stir I around that save, and we started automatically. And then if we reload, we see you visited three times, so that's working perfectly fine. Another cool trick that I want to show you guys is, um, something called the by Sunday bugger. And, um, I want to just do something here, E I equals I close one. And, um, just putting some extra lines of code visited equals I and then put visited here. So I'm just like, starting that with with equals three. And then I equals I plus one, which would be four. And then I just like a sign visited toe I This is all a little bit off, like nonsense, but I I just want to show you something called Dirty bugger. So on cloud nine, if you just type PDB and you see that snippet in there, you just press enter. And this is something they're gonna use a lot askew, kindof like, are trying to home for for bugs. What? What this does is it steps O. R stops the execution off the script at that point. And then after that, you can kind of, like, go forward, back forward, step by step and see what's going on. So usually you use this when you have an error and you see the line number. You put this statement maybe five lines before, or something like that, so that you can see what what what's going on Step by step on the on the application as the acid runs. So when I saved that, it already recorded this. The the change. So now when I when I load here, you're going to see something, which is the pages not loading. It says, You know, it's kind of like in, ah, in waiting for a lap to resolve. And if you see here, you'll see that now we have something strange here it says, um greater than Homo belong to. Hello, p. Y. Nine. That means that it stopped at Line a Line nine on the Hello World function and you see, there's a little arrow that's a cursor, and that's where the execution the next command is gonna happen.