|
|
|
28:27 |
|
|
transcript
|
6:20 |
Hello and welcome to my course Python Jumpstart By Building Ten Applications. Whether you are entirely new to Python, or you have had some experience with it, but you would like to understand the language better, I think you'll have a lot of fun building these ten applications with me and learning the core language concepts along the way. I've carefully chosen these ten applications to make them small enough that you can focus on the essential language constructs while you are building the application, and there won't be too much extra stuff to distract you, but hopefully they are big enough and complex enough that they are interesting to you, and you'll see we start out quite simple, but as we build up they get more and more complex, more and more realistic, I would say. Welcome to the course, we are going to have a lot of fun! Let's talk about what we are going to build. We are going to start at "Hello World", and this in not just to test that you can write "print('Hello world!')", that would be kind of silly, we actually do just a little more than that, but we are also going to make the focus of this app to make sure that your setup is right, that you've got Python installed, that you are using the right version, it's in your path, all the various things you need to make sure your environment is working, your editor configured correctly, all those kind of things. Then, we are going to get to our first what you might think of as real app. Guess that number game, and the computer is going to randomly choose a number and it's going to ask the user, "hey, what number do you think I guessed" and it will sort of say, "too high/ too low," you may know this game. So that will let us work with things like user input, converting strings to numbers, conditional statements, booleans, all those foundational language constructs. Then, the next one we are going to focus on is a birthday countdown application, and this will let us really explore dates, time, differences between dates, the various things like that. Once you have finished with this app you will be very comfortable working with dates in the Python language, and the idea here is the user is going to enter their birthday, we'll then use that information to figure out how many days their birthday is in the future of that year, or how many days it's already been since it's gone by. The fourth app we are going to build is a personal journal or diary. This app is fairly complex, we are going to look at a lot of really useful and central features to the language. We are going to focus mostly on file I/O, but also partitioning our app into many different files and reusing those files to build up a more complex application. We are going to dig into functions, and a lot more. So, these first four apps will just run on our computer, and that's great, but we live in a connected world, so this fifth application is going to be a weather client. We are going to actually go out to the Internet and get the weather wherever you happen to be located. You will enter your zip code and out will pop a weather report, a real, live weather report that is up to date to the minute. Now we are going to use a lot of cool language features and packages to build this one, so we are going to focus specifically on how you go to the Python package index often referred to as PyPI, and grab these packages, install them locally and use them to construct something that will let us get our weather report. We are going to do some HTTP request, we are going to do some screen scraping, HTML parsing, things like that. At this point, we are going to need a little laugh. We've built these five apps and we've worked with the Internet, but we've only gotten text back, so this LOL Cat Factory is going to let us dig into the concept of binary files, so we'll combine the fact that we are going to go to the Internet, grab some binary data, in this case very important LOL Cat pictures, save those to binary files on the disk, and then explore them with Python. Have you ever played DnD or some of these types of games? Well, it's time for a wizard battle, so we are going to make a game where we have things like wizards, and dragons and so on, and this is kind of a text roll playing game, we'll create a wizard and the wizard will be part of this ecosystem where he battles different creatures and so on. Now, for this, we are going to really dig into the concept of classes, object oriented programming, inheritance, duck typing, all of the OO type building blocks that really make Python a powerful language. Number eight, we are going to build this file searcher so you can enter some text, and it will go through your system, your hard drive, look at all the different files, pull out the various pieces of text and give you little report on it. Number nine, we are going to build a real estate investor application. We are going to start with CSV file full of real estate transactions data, historical data for particular location, and then we are going to write an application that will let you answer questions about it, what is the average price of a house that has two bedrooms sold in this location, what is the most valuable house ever sold that had one bathroom and one bedroom. Those types of things. So we are going to work with this file format CSV which most of you should be very familiar with, but the idea will be easily translatable to other formats as well of course, and we are going to really focus on two Pythonic concepts here, two language features in the Python language that are fairly unique to Python, that is generator expressions and list comprehensions. Either way is to do almost database like query work in your procedural code, so it's super powerful, super interesting for answering the types of questions this app might ask. Last but not least, we are going to have a movie lookup app. So, in this application, it's going to go out to the Internet again, and give you information about movies, but the thing we are actually going to focus on is not so much the Internet part, we did that in five and six already, we are going to focus on errors, exceptions, error handling, things like that. What if you can't get to the Internet, what if the site is down, what if it returns data you don't expect, how do you write an application that fails gracefully or maybe it doesn't fail at all? So, that's what we are going to focus on, these are our ten applications. If you are brand new to Python I recommend you go in order. If you kind of know what you are doing, if you look at the second one and go, "I know all these things," feel free to skip around. But, I would encourage you to go and look through the list of the core concepts, each chapter, each application has a set of core concepts that are list out, and if you don't know those, be sure to go back and look at that first, because they kind of build on each other, even though they are somewhat independent.
|
|
|
transcript
|
3:22 |
What fun would it be to build these applications if you don't build them yourself? So, it's really important that you guys try to build these apps yourself. There are two ways you can do it, you can either, go to each chapter and see the description of the app, and then try to build it, then watch the lesson, that is maybe an advanced scenario, more likely you watch me do it, we talk about it and then, you put the video aside, you go and you start working on yourself. Either way, you are going to need to get hold of the source code. So the source code is in a public Git repository, it's github.com/mikeckennedy/Python-jumpstart-course-demos. So let's go over there and have a look. Here is the repository, you can just simply download it as a zip, or if you are into Git like me, feel free to clone it, you can install GitHub desktop and clone it that way, you can clone it from the command line copying this here. So the most important part you'll find are the apps. So if you go into the apps you will see there is 0, 1, 2, 3 and in the setup one, we just have some links, stuff to help you get setup, those will be in the next video, but for each of the other ones, let's say... let's jump down here to journal. You can see for each particular app, there is a... you_try and a final. The final is exactly what I created in the video, so in the video, I actually created these three files and here is the exact code that I wrote for this particular application, ok? Not surprisingly, when it's time for you to try to build the app, you go to you_try. Now, for almost all the apps there is nothing to really get started with, you can just create a file, a new Python file, and get started, it doesn't matter where you put it, but I put the instructions in here for a few of the apps there will be resources you need to get started, for example that real estate app, the data files you need are going to be there to get started with. But, most of the time, I have something like this, and it will give you a picture of what we are going to build, so here is our birthday app... we are going to write an app that has this output, and you can see it asks three questions to construct the date, what year, day and month were you born, and then it does its work and it answers the question... well it looks like you were born on this day, and it looks like your birthday is in so many days from now. Hope you are looking forward to it. Down below, you can see that there is always the key concepts that you need to know, so for example, in this one, we talk about functions, so here is kind of the basics of functions, and we talk about "datetimes", so it shows you the various pieces of "datetimes" that you might need to use. If we look at another one, like, let's look at number 2... you can see this one talked about string formatting, conditionals, loops, importing modules, and there is just a little example here, this is not instructions that you follow, but these are sort of the key concepts that you need to know, so if you want to try it before we talk about it, you have at least a chance, right?, but for the most part I expect you to have watched the video and then you try it yourself. So that's the story the source code, the apps, the instructions, how you follow along. So, LET GET STARTED!!!!! It doesn't matter what you want to build, I am sure you are going to build something amazing with Python, and the time to get stated on it, and learning, and building, is right now. Let's move on to the next set of videos where you will learn about setting up your environment and then it will be on to the applications. Once again, welcome to the class, have a great time.
|
|
|
transcript
|
5:09 |
Before we get to the actual apps that we are going to build, let's talk a little bit about the tools we are going to use, how you use them up, and even just a little bit of history. The first question that you get a lot of times when you start talking about Python, Python apps, Python course, is... what version of Python is it going to run on? It turns out this is kind of a big question, so let's talk about that first. To appreciate this, let's look at the history of Python. In the beginning, it came into existence as a concept in 1989, it was released in 1991, had a couple of major releases, version 2 came out in 2003, today it's 2016. So, development started, version 1 was released, version 2 was released, and then version 3 actually was a major breaking change to the Python code. The developers look back over the 17 years of experience and said, what was good about Python and what things kind of gave people trouble, what would be a nice way to clean up the language, so that it's solid going forward, and they made these breaking changes to Python 3 and expected people to move along pretty quickly. Well, it's today, sometime in 2016 when this was recorded, and there is still a debate, should people be using Python 2 or should they be using Python 3, there is a lot of large code bases still running on Python 2, the majority of large commercial applications are probably using Python 2, even though it's been 8 years Python 3 has been out. However, there is something on horizon coming in 2020, they are going to make this a much simpler choice between the two languages. First of all, the changes between Python 3 and Python 2 are not that major, if you write code in Python 3 chances are, unless it's one of the advanced features "asyncio" or something like this, chances are it's going to work fine in Python 2, but there are older ways in Python 2 that are not forward compatible, and I think that's actually the bigger problem. So, if you learn Python 3 I feel like you have more well rounded ability to jump into either type of project, but that said, in 2020, just 4 short years from now, Python 2 is going to be end of life. No more bug fixes, not sure about security fixes, but definitely no more support, and to drive that point home, at PyCon, Guido Van Rossum, the guy who invented Python, started out his keynote with this saying... "there will not be an extension to this policy", this is it, only 4 years away before this being an absolutely clear choice, Python 3 is the future, and that's why this course is designed with Python 3 in mind. So, in order to do this course, you are going to need to install Python 3. And, we are going to talk about how to do that for each of the various operating systems. One question, is maybe you already have Python 3, maybe there is nothing to do, so just knowing where Python is available, that's kind of good background knowledge. Before we get into details to set it up each on these operating systems, let's answer the question- If I have Windows, do I have Python? No, you have no version of Python, Windows does not ship with Python. Unfortunately, it just doesn't. So, if you have Windows, you have users who are using Windows, you need to get them Python somehow, right? On Linux, chances are at least on Ubuntu, you have both versions of Python, that's pretty awesome, maybe it's not the absolute latest, maybe it's 3.4 and 3.5, but still, pretty darn good. OS X is somewhere in the middle, typically you have Python 2, but you don't have Python 3. A little like the choice between Python 2 and Python 3 is somewhat contentious in the Python community, so as the editor you choose. On one end of the spectrum you have people that use VI and Vim and Emacs, and these very light weight sort of shell friendly, ssh friendly editors, and that's actually a very large percentage of the professional programmer's population for Python devs, and on the other end, you have IDEs rich, full featured, large applications that bring all of your development tools together. Sort of the premiere one of those, is the one I have here, and the one I am recommending for the course is PyCharm, but we'll see a few other options as well. So, in editors like PyCharm you can edit of course and run your code, you can run unit tests, code coverage, look, you have a graphical visualizations of your git history and commit changes, there is all sorts of stuff you can do here. So I recommend to use PyCharm, when we get to the particular operating systems we'll talk more about that. But if for some reason you don't want to use PyCharm, there are other options. PyCharm has a free option for the community edition, but if you are on Windows, you can also use Visual Studio and then plug in the Python tools for Visual Studio, that's a nice free option, Microsoft has the community edition of Visual Studio and then the Python tools are open source and free, so that's a really good choice actually, just a bare notch under PyCharm, but really good, if you are into the IDEs, if you are not into the IDEs, choose something like Sublime text or Atom by GitHub.
|
|
|
transcript
|
4:18 |
All right, let's talk about how to install the various tools in Python on your operating system. Now, there are going to be three of these videos, there is going to be one for OS X, one for Windows and one for Linux. You probably only need to look at one. Just choose the operating system that you are currently working on, and watch that video, you don't need to watch the Linux one if you are on Windows for example, unless you just want to sort of see what the experiences are like across the different platforms. So, with that said, here is the OS X one, and the others will follow. So, there is only two tools, two resources you need to take this class outside the source code on the GitHub repository, one is you are going to need Python 3, remember, Python 3 does not come on OS X, Python 2.7 does, but Python 3 does not so you've got to install that. As well as PyCharm. So let's go look at these. I pulled up the websites that we are going to be working with, Python.org, this is where we get Python 3, PyCharm over here on jetbrains.com, we are going to download PyCharm here and I also pulled up the other three options, Sublime Text if you are interested in that, Atom, you've got to watch this video it's very funny, a great little light weight editor. We'll come over here, download this, quick, just it defaults you the latest of both Python 2 and Python 3 for your operating system, so you pick this, download, save, I've already done that. So let's go over here and see, if I type Python you will get something, but you'll see that Python 2.7.10 comes up, if I type Python 3, there is no Python 3, so let's install Python 3 and make sure everything setup good there. So, this is what I got of Python.org, just click through, agree to, whatever it's going to make you agree to... ok, so Python is installed. Let's just try a little trick again, we can even do a --version on the end, excellent, so we have Python 3 installed and it's the latest version. So, that's a good start. Next, PyCharm... when you just click download, it gives us a choice between what version do you want, the professional or the community edition, this is up to you, I love this tool, I paid money for it, I am getting the professional, the community is free, if you are wondering what the differences are, just come back here to the main PyCharm page and you can see, it will show you that actually the Python features themselves, there is not too much of a difference, but the web development, and Python web frameworks, and data base stuff, that is only in the professional edition. But, lucky for you, none of that is actually happening in this class so you can pick either of these that you wish. Once you have it downloaded, you will have "dmg"... disk image here, I love their little installer, here is the app, just drag it over here, wait a moment, and you should have PyCharm installed. Now, that's finished installing, let's check that, and we can just run PyCharm. First time it will warn you this came of the Internet, beware, yeah, we did that on purpose. Make sure you get it from right place. And, here is PyCharm, I've already run it before, but the first time you run it, it'll ask you for the settings, I like mine in this dark theme, so everywhere it ask you about colors, there is two places, you can say Dracula if you want the same theme as me, or pick another one. The other two editors are just Atom, here is Atom, nice and clean, and Sublime text, again, super small, super clean. Let me show you a technique that will be helpful for opening these projects in basically working with Python projects, in general. So, here I have Request Masters, I got this off of GitHub, this is the Request package and this is actually the source code, so here you can see, here is all the Python files, just like the project base, if I want to open this in PyCharm, I just drop it on here, this is OS X only feature, but if I drop it like this it will open the whole project, and see here is all the code that we need. You do a similar thing for Sublime text and you can do a similar thing for Atom. So, here is all the packages, same thing. So, that's a really helpful tip, if you are jumping from project to project and you want to just open up this project, open up that after project, open up before project, and so on, I am sure you will find that useful throughout the class. All right, that's it, this OS X system is ready to roll, ready to work on this class. Hope you are ready to go build app number 1.
|
|
|
transcript
|
4:11 |
Hello my Windows friends! Let's get you all setup and ready to work on this class and build those ten applications. And I have good news for you, until very recently, using Python on Windows has been actually fairly painful to get it setup and everything configured right, but with Python 3.5 the installer and the setup process is way better. So let's get to it. To get started you are going to need two resources on Windows, you are going to need to install Python 3, which you can get at Python.org, and you are going to need to install PyCharm at jetbrains.com/pycharm. Let's go over to Windows 10. Here is a brand new, completely fresh install of Windows 10 I just got form Microsoft, and I've opened up the various web pages we are going to be working with. First thing we have to do is install Python, and as I told you, there is no Python on Windows, if I open this up and I type Python, there is no Python. So, we have to download Python, and we want 3.5 1 or whatever the latest version of 3 is and I've already actually downloaded it so I won't click here, but you just click that, that's super easy. The other thing we need to download is PyCharm, so here is PyCharm, it actually comes in two editions, the professional edition, or the community edition. You can pick either for this class, the community edition is totally fine, the things you'll be missing are... you'll basically be missing on web development and database management features from the professional edition, and the community for straight pure Python has the same features as professional. If for some reason you don't want to use PyCharm, you want something more light weight, you can use Atom, at atom.io, Atom is from GitHub it's pretty cool, I really like this editor, you can see there is a little video here, I recommend you watch it, it's pretty hilarious. Sublime Text is also a super popular light weight editor, and I told you about Visual Studio, so you can get Visual Studio community edition this is now a free, full-fledged version of Visual Studio, and you can get Python tools for Visual Studio, plug this together, and you are doing pretty good. But, we are going to be using PyCharm in the class so that's what I will setup here. Let's start by installing Python. So I've got it downloaded, and I'm going to run it, now it has a couple of options in the installer, let's say if you are going to try to just type Python from the command line or other tools like "pip" for installing packages, you will probably want to add this to your path. And let's customize installation just to see what we get, we get documentation, "pip" which manages packages, we'll talk about that in our apps, and we have the test suite and "py launcher" is really nice and we don't need to install it for all the users. Let's go ahead and precompile standard library this will give us a little better perf, I really don't like this big long folder here so this app data folder is hidden in Windows so it's kind of hard to discover where these are so I am just going to put a Python folder directly in my user profile and then, in case you want to have 64 bit or 32 bit version of Python or maybe different types 2.7, 3.5 you probably want to leave this specifier here. That seems like a good setup, let's go. All right, Python was set up successfully, let's close this and let's just find out, if I type python --version which we should see 3.5 1 and... SURVERY SAYS? SUCCESS!!! Ok, Python is working, last thing to set up is just PyCharm. So the installer is just a standard Windows installer, just sort of yes your way through, it's up to you whether you associate py files with it, typically, I don't do that, but it's your call. Ok, it looks like we successfully installed PyCharm, that was easy, let's go and run it. Brand new, nothing to import, now, normally I would log in with my JetBrains account, but for this purpose I'll just evaluate it, say ok, that's great. The first time you launch PyCharm it will ask you what theme and keyboard scheme you want to use, I'll say Visual Studio keyboard theme, and I like my code dark, I have the editors dark and the code text to be light, so I am going to pick the Dracula theme, pick which ever you like, and there you have it, PyCharm is up and ready to roll! this brand new version of Windows 10 is ready to build our 10 apps So without further ado... let's move on!
|
|
|
transcript
|
5:07 |
Hello my Linux friends! Let's talk about what you've got to setup on your machine to do this class, in the same way that I am, at least, you will see that you actually already have Python and Python 3 installed on Linux if you are using something like Ubuntu, so that's pretty awesome. I'll show you where to go to get it if you don't happen to have it and I'll show you how to install PyCharm. It works wonderfully on Linux but it's a little bit of a pain to set it up so I'll walk you through that. So, here we are over in Ubuntu 15, brand new fresh version I literally just downloaded, and we are on the PyCharm page. So we can go and download PyCharm, you will see there is actually two versions, there is a professional version and a community edition, we are going to download the professional edition, you can get a 30 day free trial and if you pay for it like I do, then obviously, you can have it forever. The main difference between the community and the professional edition, the community edition is always free, is... the community edition does a whole bunch of cool Python stuff but it doesn't do web or database work, the professional edition does, in addition to standard Python things, web frameworks, type script, database designer type things. So, for this course, you can totally go by with community but for a professional work, well, maybe professional is the thing to go with. Some of the other editors you might choose if for some reason you don't want to use PyCharm, is you could use Atom, it is a really great editor from GitHub, I really like it and the video is hilarious so check out the video, just for a laugh. Sublime text is very popular, and of course, you can use Emacs or Vim that a lot of people are using. As I said, Ubuntu comes with Python 2 and 3 but for some reason if you need to download it, just come over here, Python.org, grab the latest version it'll automatically find the right thing for your operating system, you could also install it with aptitude, you can do things like apt-get install Python3 -dev, there is a couple of packages that you can install. So first, let's verify that I actually do have Python installed, Python 3 so I can say Python3 --version, and we have 3.4.3+, which makes it even better than 3.4.3, awesome, and then we have PyCharm, we are going to go download it, it's kind of big, so I actually already downloaded it, go over to my downloads folder, and we have the tarball (tar.gz) right here. So we need to decompress this and copy it somewhere, so I come over here, right click and say extract here, and it will extract it out. Now it has the version name here, let's find, let's make it new location, let's put it in my home, I like to create a folder called bin in my home and then here I'll make a folder called PyCharm and within PyCharm I'll put PyCharm-5.0.4. Now if you open it up you'll see there is nothing to run right away but there is a bin folder within there and what we want to do is we want to run this script, so I could double click it, and it will just open in gedit, not the best, so I am going to come over here and just drop it into my terminal and run it. Now, it turns out, there is a problem, PyCharm is built on the IntelliJ platform, IDE platform, and that platform is Java based, so we need to install Java, before we can carry on. So on Ubuntu, we'll just use apt-get so we'll say sudo apt-get install openjdk-8-jdk. And I'll put in my password, I'll wait for a moment, and says are you sure you want to do this, it might take a moment 171 MG's, it's fine, go Excellent, well, that took a minute, but now we have Java installed, let's try to run that again, PyCharm shell, now it's running, you can see it says do you want to import previous versions? well no, it's a brand new machine so no, not really; normally I would just log in with my JetBrains account but for now, I'll just evaluate it for free, which you guys should be able to do for this class. When PyCharm first opens, it asks us what keyboard map and visual theme we would like, I am going to leave the keyboard map alone but I like my code my IDEs and windows and stuff to be dark, not bright, so dark background light code, so I am going to pick the Dracula theme for both the code colors as well as IDE theme, and I will say ok, and it can't make the change unless you restart, so yeah, let's let it restart. Excellent, my PyCharm is running, it's nice and dark with its Dracula theme. Now the one other thing I'd like to do is notice it's over here, and I kind of like to not be running this shell script anymore straight from the terminal, so let's run it one more time, notice it's gone from the launcher. Now it's up and running, I can lock it to the launcher, and now this way, when it's gone, I want to launch it again, I can just come over here and launch it straight out of launcher. Congratulations, you have PyCharm working on Ubuntu, it's time to head on over and build your first app and have a great time doing it!
|
|
|
|
13:38 |
|
|
transcript
|
1:14 |
Hello and welcome to the first app you are going to build. It's a Hello World app. And we are naming it Hello (You Pythonic) World. So, what exactly are we going to build? Well, it's going to look like this. We are going to have a little Hello World app and it's going to have a header that says "Hello App" and it's going to ask a question "What is your name?" And then, the user will enter something like "Michael". And you can see here, this is a convention we use throughout the course that the yellow indicates user input and the white indicates application output. So the user enters "Michael", and the app will echo back, "Nice to meet you, Michael" Now, you may not think that there is a whole lot to learn from such a simple application, but in fact, there is really quite a bit going on here. We are going to use the Hello World app not just to show the minimum number of characters you have to enter into an editor to get Python to generate an application, but in fact, to verify our Python environment, and to get started with our editors, as well as we are extending it to do a little bit more than standard Hello World which is maybe console out, but we are talking about basic syntax, strings, accepting input from the users, variables, that kind of stuff. So you can actually learn quite a bit, even from this very simple Hello World application.
|
|
|
transcript
|
4:39 |
So let's switch over to my Mac and get started. So to use PyCharm, it's pretty simple, you open it up, and you just say create a new project. You can see there is a lot of different kinds of projects we can create, we are just going to do a pure Python app for our beginning one, but you could create a Django, Flask, or Pyramid web app, even a Google App Engine app, and there is also a lot of HTML, Javascript options because PyCharm is a full featured Javascript, CSS, HTML editor, in addition to being a great Python editor. So I actually already have a project I created just by basically saying ok, on the next screen. And when you create a new Python app, a pure Python app, you end up with basically a blank folder. So, we are going to come over here and add a new Python file, so right click and say new Python file, and throughout this class, the main program that you'll run, that indicates sort of the entry point into this set of scripts, or Python files that we are building, is going to be named program.py, so I am going to create something called program.py, I am using Git to store all the files and demos that I create for you during this class which I will make publicly available for you to look at and see how they have evolved over time and you can see that PyCharm is actually suggesting that we add this to our Git repository I was going to tell it to please don't ask again. Now, remember, the first thing that our little sample app had was it had a little header with some dashes and it said "Hello App", and it sort of was bracketed by kind of a dashed line above and below. So let's go back creating that. So we are going to use something called the print function. And this is typically the way that you output things to the console. We can say print, and then here we can pass a string. And in Python, you can create string with double quotes, like this " " or you can create strings with single quotes, like that ' ' and I actually prefer the single quotes, it's just a little less typing, you'll see there is some times you might want to use double quotes, you might want to use single quotes, we'll talk about that later. So, we are going to come over here and we are just going to have our dashes like so, and then we also want to output that little "Hello App" part, so we are going to come here and say print, go over and say hello app, I think pretty much like that and we are going to say print, I am just going to do this one more time. Let's go and run this and make sure there is some reasonable output, first thing to do is save this. Now I could go to the console, to the terminal and just run that, I can easily do that by saying copy path, we go down here and I can type Python 3 and I can just give it a path, add hit go, and then out comes our output, hello app, perfect. But, PyCharm let us run this, and debug it, and do all sorts of cool runtime analyses of our app, right from within PyCharm. And you see there is a little debug icon here and a little play icon here, but they are both grayed out, and that's because there is no run configuration setup. So instead of going over here, we are just going to right click and say run the program and it will create a run configuration and save that for us going forward. So just like before in the terminal, we have hello app, very very nice. We also maybe want a little space between here, we can actually just call print with no arguments, and I will just do a new line. Now, the next thing that we did in our app was we actually asked the user what their name was. So we could actually get down to the system input output streams and directly work with those, but in Python there is a simpler way. We can just say input, now this also takes a string, and we can say something like "what is your name?" put a space and then, in the console the cursor is just going to stop right there and wait for the user to put some inputs, so let's just going to run that, I can click this, or this or I can say control r "^R", in Windows, I believe that's F5, and on the Mac it's control R "^R", and down here you can see it's asking what my name is, I'll say my name is Michael. Then, it waits and when I hit enter, it accepts the input and moves on. Now, that's not super helpful because we are not actually getting the name, we are just asking the question. So, let's take a moment and look at a couple of core concepts that we are working with here.
|
|
|
transcript
|
1:56 |
The first concept is around this idea of calling functions, print is a function, input is a function these are reusable pieces of functionality in our application. Here we are calling a function called main, and you can see that you call it with the parenthesis on the end some languages have semicolons to indicate the end of a line, thankfully, Python does not have that, and this takes no arguments and it returns no value so you just call like this. Now, the input on the other hand, we can call it and we pass it a string, kind of like print, but then it returns whatever the user inputted. So we are to create a variable called saying, we are storing the return value from the input function which is what the user typed in the saying variable we can work with that later. So that brings us to variables. And variables in Python are very very simple, they are sort of no-nonsense, so you just say the name, or the word you want to use for the variable and then you assign to it and... SHAZAM!! the variable exists. Some languages you have to specify types and initialization and so on, Python is sort of as simple as it can be around variables. So here we have a variable called name, and we are assigning the value of Michael, we have a variable called age and we are assigning 42, and we can even increment this value of the age, we are doing a "+=" operations, so we are taking the age, adding 1 to it, now the age is 43, so happy birthday to me. We have more complex variables of course, here we are creating what is called the list and we are populating the list with 3 strings, so biking, motocross and programming, and then we are storing that list holding those objects in the hobbies. So, all of these are directly created upon assignment, we can also create variables and store return values from functions, so here we have home address and we call in a function and we are storing the result of that function into home address. So let's go back and use these ideas to finish up our "Hello World" app.
|
|
|
transcript
|
2:14 |
So back in PyCharm we need to grab hold of that value that is returned from input. Let's be really explicit and call this user_text or something like this... ok. So in Python, when you have complex words or variables and functions made up of multiple words, if you will, you typically separate them with underscores. Other programming languages might write "userText" like this, where they use camel-casing, in Python it's all about the underscore. So, we are going to call it this, so that gives us the user text and we could actually just print this out just to see what they entered, so let's run this really quick say "I entered this", if I hit enter it just says "I entered this", excellent. So we have got that value and print it back out. That's not exactly what we want to do though. We want to actually store some kind of saying that we want to say and I believe it was "Nice to meet you", whatever they entered for their name. So we'll say greeting = "Nice to meet you " and we want to sort of somehow incorporate this string here so in Python, they make it really easy to combine strings just using the "+" sign. So we'll say, nice to meet you "+" user text and we can just print out that greeting, give a little space so it's easier to read, so let's just run that, and see what we get. So down here, we can enter our name which will be Michael, hit enter, and it says "Nice to meet you Michael". Perfect!!. So now, we've completed our first app, you can see we've worked with the print function, we're calling it with parenthesis, passing a string literal, it's what you call it when you create them just in place like this, passing these string literals as arguments, sometimes were not, calling the input function, again passing strings, catching the response, the input into a variable called user text, we are concatenating to another string, a literal string plus a variable, storing the greeting and we are printing it out. All right, pretty simple this application but it really gets us off to a good start to start building more interesting complex applications that build on things like file i/o and web services and all sorts of cool stuff like that.
|
|
|
transcript
|
3:35 |
Now, before we move on to our next application let's take a quick tour of PyCharm. So, PyCharm has so many features, it's very hard to just sit down and show them to you. But let's just take a moment and hit the highlights. So on the left over here we have our project, folder, and this can be quite complex, in real apps you might find many subdirectories, multiple files, all sorts of stuff, we'll get to that later. But here we just have our directory and our program.py, and it actually shows the external libraries that are set up into the particular Python environment that we are working with. So you can see that we have things like Pygments, and Chameleon which is a web templating framework and mailchimp for managing subscribers, things like that. Not super important for us now, but this sort of lets you get at your active Python environment. We can also go over to the structure, and the structure for this app is frankly boring, because it just has a few variables and that's it, but if we had functions which were using classes and these classes were defined with more functions and fields and attributes and properties, all this kinds of things, you would see this would actually be quite interesting, you can use all these little pieces up here to slice and dice them. Down at the bottom, we have our run configuration, or a place where we would run our app you can see there is actually two of them running, that's kind of a problem, we'll talk about how to fix that. So we can come over here, we can run it, we can stop the running one, you can see this one as a green dot because it's running, so we can stop this... it's all good. We can also have TODO's so we could come over and put a comment; comments in Python start with "#" hash so I could say, # TODO "this needs cleaned up", something like that and I could say something like TODO. All right, so now if you look down here you can see it actually shows us our TODO's PyCharm highlights them very nicely up here. Take those back out but that's what this section is for. Here is just a Python console you can... as if you typed Python in the terminal or the command prompt, here is literally a terminal, and here is the version control that we talked about. There is support for all different kinds of version control, you can see we are actually working on the master branch in GitHub. Over here, on the right we have a database section, some really excellent database management and design and querying tools built in the PyCharm. We don't have a database that we are working with right now, but if we did, we would connect it here and like it do all sorts of cool stuff. Finally we have sort of run, debug and manage version control shortcuts up here. We come up here, we can look at the configuration you can see we can actually pass parameters like if I want to just hard code a name and pass it like this, this would be passed to our program when it runs, we are not going to do that but we could you could pick which version of Python you want to run pass additional options to the |