Transcripts

Coding 101 11 (Transcript)

Shannon Morse: Today on Coding 101 we start our newest module, Python with Dale Chase. And we say goodbye to our first code warrior, Lou MM. We’ll miss you.

Netcasts you love, from people you trust, this is Twit!

Bandwidth for Coding 101 is provided by Cachefly. At C-A-C-H-E-F-L-Y dot com.

Fr. Robert Ballecer: This episode of Coding 101 is brought to you by Lynda.com. Learn what you want, when you want with access to over 2,000 high quality online courses and training videos all for one low monthly price. To try it free for seven days visit lynda.com/c101. That’s l-y-n-d-a dot com slash c 101.

Fr. Robert: Welcome to Coding 101. It’s the Twit show where we show you how to live in the wonderful world of a computer programmer. I'm father Robert Ballecer.

Shannon: And I'm Shannon Morse and today for thirty minutes we are going to get you all coded up on everything you need to know to be a code monkey.

Fr. Robert: Absolutely, but you know what Shannon, this is a sad occasion because—

Shannon: It is.

Fr. Robert: …we lose one of our own. Sad but we've gone for ten episodes—

Shannon: I'm an ugly cryer, I should not do this.

Fr. Robert: …I know yeah, totally yeah. It messes up the IFB. But we had Lou for eight episodes, in fact we really had him for ten episodes because he was with us with the two beta.

Shannon: Yes.

Fr. Robert: And we had to say goodbye. We miss you Lou and so this is for you.

Shannon: It’s so beautiful.

Fr. Robert: You will be fondly remembered Lou but we need to move on. You see, we’re done with C# right?

Shannon: Yes we are, well for now.

Fr. Robert: For now, we may come back. But I mean we got a lot of language to go through so we figured we want to give you a little something, something. Something that’s a bit more of what you were asking for while we were doing C#. There were a lot of people saying “Wait a minute, this platform is so Windows centric. What about something that works cross platform, on the OS 10, on Windows, on Linux.” And so, Shannon what language did we choose?

Shannon: We chose P-P-P-Python because guess what? I was playing with it right before the show and it’s actually kind of easy to get it started.

Fr. Robert: It’s really easy. It’s a crazy easy language to learn and—

Shannon: Surprise.

Fr. Robert: …if you hated any of the formatting, that kind of held you back in C# and if you wanted something that was bare bones, we had a lot of people saying “Wait a minute—

Shannon: This one is totally bare bones.

Fr. Robert: Yeah, totally bare bones, something you can do in notepad, something you can do in your nano editor—

Shannon: Yeah.

Fr. Robert: …and then drop it into the compiler, that’s what Python is.

Shannon: It’s so, so very pretty. So I wanted to go ahead and first off first nubs compile, get you guys started on downloading the program and how to get Python onto your computer. It’s a really, really simple process. If we check out my computer, I’ll show you exactly how it works. You simply go over to a website called python.org, surprise, surprise, surprise.

Fr. Robert: That’s so counter intuitive, wow.

Shannon: I know right. So you got to the website and there’s this big whole thing that says download, surprise, surprise. Now you’ll notice down here, it says latest and there's two latests. There’s Python 3 and there's Python 2.

Fr. Robert: Right.

Shannon: Interesting.

Fr. Robert: And that’s because they forked it. So there's actually two forks of Python right now. There's the 2X and the 3X. We’re going to be using 2X Shannon right?

Shannon: That’s right. So if you click on to Python 2.7.6, this is the newest version of Python 2X, and you go to whichever one you need to use. For myself, I just use the x86 MSI installer, it’s super easy and then I download the program database.

Fr. Robert: Right, now we should probably mention that if you have a Mac, Python’s actually installed. When you boot up Mac OS 10 10.6, Python’s already in there but go ahead—

Shannon: You're so lucky.

Fr. Robert: You are kind of lucky. Go ahead and get the most recent version, it’ll help you head off any issues that we may run into while coding.

Shannon: Now I did want to mention as well while we’re on this topic, if you also go under the download form on the front page, it says “Not sure which version to use”, you can click here. Now there’s a really nice, very descriptive Wikipedia page all about the differences about Python 3 and Python 2. I really recommend checking this out because it’ll give you a lot of updated information on what modules will work with Python 2 and why they forked it in the first place. Definitely a good read for anybody who’s new to the language.

Fr. Robert: Yeah, now we should also mention that if you are learning Python 2X with us, it doesn’t mean that you’re closed off from Python 3. You can actually take the lessons, they're perfectly the same. There are a few syntax changes, like for example print moves from a statement in Python 2X to a function in Python 3. And there are other sort of under the hood—

Shannon: Really?

Fr. Robert: Yeah we’ll show that a little bit later on.

Shannon: Oooh.

Fr. Robert: But the lessons of Python will still be there. The reason why we’re staying with 2X, is because there are so many ready-made modules that will work into 2x that aren’t quite ready for 3.

Shannon: Yes, it’s still widely used in lots of different companies and lots of softwares. So it’s definitely a good one to start on and it’s very, very easy to learn so I can’t wait to get started in it. We will be bringing back viewer submissions and viewer questions in our next module. Since this is the first episode of course we don’t have any review to go over with Python so we’ll be starting that on the next episode.

Fr. Robert: But do remember that because one of the fun parts about the show has been looking at programs that our viewers make. So make sure, make sure to go to our Google Plus page, we’ll tell you about it in the end, so that you can submit your programs. You can let Snubs take a look at it and she likes it, she’ll show it off in the show.

Shannon: Yay.

Fr. Robert: Yatah.

Shannon: You know, I heard there’s another place where you can learn lots of Python.

Fr. Robert: Yeah, I heard about this. One of the things that we run into a lot is there are gaps in what we can teach right?

Shannon: That’s true.

Fr. Robert: Because we only have thirty minutes a week, maybe forty-five if we push it.

Shannon: If we’re lucky.

Fr. Robert: If we’re lucky, yeah. If we started on time.

Shannon: If we started early.

Fr. Robert: But there are always those little things that user wish they could learn and things that we would love to teach, we just don’t have the time. What we try to do is we give them the highlights, right? We give you, as Shannon always says, we give you enough to kind of poke around and break things because we like when you break things.

Shannon: Go break it.

Fr. Robert: Go break it but people want more, which is why we’re so happy to have lynda.com as a supporter of Coding 101.

Shannon: I love them.

Fr. Robert: Now what is lynda.com you may ask. Lynda.com is the online repository for knowledge. They're an online learning company that can help anyone learn creative, software and business skills to achieve both personal and professional goals. With a lynda.com subscription, members receive unlimited access to a vast of current and engaging video tutorials across a wide variety of subjects. Everything from creative and software skills to business, negotiation and programming. At lynda.com you’ll learn how to code, create and build applications from the foundations of object oriented programming in C and C++ to desktop and mobile apps for today’s popular operating systems. You’ll explore the fundamentals of programming build web applications with .Net, PHP and MySQL. Manage data with SQL databases and connect to cloud services and oh so much more. Now the reason we like Lynda is because they have Python modules, yatah!

Shannon: Yay.

Fr. Robert: Yeah yippie, yippie. You can learn about Python at Lynda. All those things that we can’t show you because we’re time limited, the minutiae of the language which actually is fascinating, you can get from lynda.com. If you’re new to Python or programming, Lynda offers a guided tour through the syntax flow and best practices of solid Python code including how to use Python’s date of object module to write concise powerful code. Ready for a deep dive into the inner workings of Python or to learn Python as an additional language in your developer tool belt, while you can take and expansive look at Python’s flexible object oriented languages syntax and usage and step forward into advanced Python features and lynda.com. One of my favorite modules and lynda.com right now was Python for the raspberry pie. Remember we had ISS above on the show. If you wanted to learn how to do that, how to develop an app for that wonderful little platform, well you got to start with Lynda. Lynda.com offers 2,000 courses with more added weekly. All lynda.com courses are produced at the highest quality not like a lot of those home-made videos on Youtube, which we love, I mean both of us have made those but there’s something about professional videos with good lighting, good cameras, with good audio that make you want to finish the lesson. At lynda.com the instructors are accomplished professionals at the top of their fields and passionate about their teaching. These are people who know but can’t teach, or who can teach but don’t know, they’ve actually done this in the field. So they teach you from experience. That’s one of the things I love about lynda.com. They have courses for all experience levels, from beginner, intermediate and advanced, and they let you watch form your computer, your tablet or your mobile device. Whether you have fifteen minutes or fifteen hours, each course is structured so that you can learn from start to finish. And you can search the transcripts to find quick answers or read along with video. Lynda.com also offers  certificates of completion when you finish a course so you can put them on your LinkedIn profile, which is great if you're a professional in the field and you want people to know “Hey, I know Python.” So here’s what we want you to do, if you watch Coding 101, if you're serious about becoming a code monkey or a code warrior, then try lynda.com. It’s only $20 a month for access to the entire lynda.com course library. Or for $37.50 a month you can subscribe to the premium plan, which includes exercise files that let you follow along with the instructor’s projects in real time using the exact same project assets that they do. And you can try lynda.com right now with the free 7 day trial. Visit lynda.com/coding101 to access the entire library, that’s over 2,000 courses free for 7 days. That’s L-Y-N-D-A dot com slash C one zero one. And we thank Lynda for their support of Coding 101.

Shannon: I'm ready.

Fr. Robert: Shall we do it.

Shannon: I'm totally ready, let’s do this. I'm so excited.

Fr. Robert: Let’s do this, okay so if we’re going to do it we’re going to have to do a little bit of ivory tower. Now this is going to be a little ivory tower that’s – it’s a bit more expansive than we’re used to. Normally ivory tower’s one or two concepts.

Shannon: Yes.

Fr. Robert: We’re going to do a few concepts here.

Shannon: Okay, let’s do it.

Fr. Robert: But hopefully, I'm not going to bull people’s minds.

Shannon: If you do, I’ll just let you know.

Fr. Robert: Just back me up, just back me up.

Shannon: Back it up a bit padre.

Fr. Robert: Slap me in the forehead and we’ll be all good.

Shannon: Can I slap you in the forehead.

Fr. Robert: If you do, you’ll get feedback.

Shannon: That’s okay.

Fr. Robert: So let’s talk really quickly about a compiled language versus an interpreted language.

Shannon: Yes because C# is compiled and Python is interpreted correct?

Fr. Robert: Precisely, exactly or they also call it scripted, same idea. So when we have a complied language like C#, you take all that code that you wrote and the IDE, the compiler actually turns it into machine readable code and then it makes an executable file, a binary.

Shannon: Right.

Fr. Robert: Have you ever seen like and EXE file on a Windows box, that’s a complied piece of code—

Shannon: Oh yeah.

Fr. Robert: …that’s an executable, that’s a binary. Well, you can’t read that code right?

Shannon: Right.

Fr. Robert: Because it’s already been compiled for that language. Now compiled languages tend to be faster because if you compile it down into the machine level, it’s ready to execute, it’s ready to run. An interpreted language on the other hand does not compile down into machine language until you need it. We also call it just in time programming. So in other words, when I complete my Python program, I'm not going to get a little executable. I'm not going to get a binary, I'm not going to get a file that you can’t read. It’s going to look exactly like the code I just wrote but maybe in a different, you know a saved file extension.

Shannon: Okay.

Fr. Robert: It will actually turn it into machine code on the fly.

Shannon: So it’s that going to end up using more of your RAM.

Fr. Robert: Yeah, yeah it actually uses up more of your computer resources, this was one of the big things when interpreted code first came around. Remember with Java, and all those scripting languages.

Shannon: Yeah.

Fr. Robert: You took a big hit, because if you're essentially compiling it as you're running it, you're using up some of that power that you could otherwise use for the program just to compile the code right?

Shannon: Right, okay.

Fr. Robert: But as computers got more powerful and as we got more RAM and more CPU cycles to spare, most of the performance disparity has gone away. I mean unless it’s a really high performance application, you're not going to notice it. Furthermore, scripted languages, interpreted languages are incredibly popular on the internet. And why might they be popular? Because another huge advantage of an interpreted language over a compiled language is the cross platform ability. In a compiled language, even if I have a piece of code that can be used on many different computers, I still have to compile it for that computer. So I have to compile it for Mac, I have to compile it for Windows.

Shannon: Right.

Fr. Robert: Maybe I have to compile it for different versions of Mac OS 10 and Windows. Maybe I have to also compile a version for Linux and etcetera, etcetera, etcetera. Whereas with interpreted, since I am compiling it in real time, it compiles automatically for whatever platform I’m using.

Shannon: So it would be good for using it on websites and things like that?

Fr. Robert: It’s great for websites.

Shannon: Okay.

Fr. Robert: Right, and that’s why you see a lot of requests for scripting language developers.

Shannon: Right.

Fr. Robert: It’s one of the things that drive the internet today, that makes content so rich and that’s why we’re learning about an interpreted language.

Shannon: Yeah so we are starting with Python 2X not 3X.

Fr. Robert: Yes, yes, yes. Now, okay Python 2X and 3X, what happened with the fork is that the developers of Python came back and for the longest time they’ve been saying a few things like “Oh man if we had a do over again, we wish we could’ve done this or we wish we would’ve done that.” One of the biggest things was the print statement. So in Python, actually if you can go ahead and drop into my computer I'm going to show them something right now. In Python 2.7.6, so this is Python 2X, if you go ahead and zoom in, if I wanted to print all I’d have to do, and this is kind of cool, print hello world. Oh that’s not how you spell hello, Right?

Shannon: Now can you show us how you got into this program right here?

Fr. Robert: Oh sure, so when we install Python that you actually showed us, it’s going to give you a little icon and this is the Python 2.7.6 shell. It’s right at the bottom here, which installed and I just – see, look if I shit this down again, I’ll just go ahead and jump right into that and I get Python 2.7.6. So anyways in this version if I do print, I can just put in quotations hello world and I get the output. So it’s one of the simplest languages to do because it’s almost like basic however in Python 3.X—

Shannon: I found it.

Fr. Robert: Yatah! It’s Python 3.X, so it looks exactly the same, I got s shell but if I do this now, print hello world, it’s going to give me a syntax error. And the reason why is because they changed it from being a statement to being a function so just like in C#, if I want to invoke a function, I do print and then in quotations hello world. And now it prints.

Shannon: Well, the Python 3 looks a little bit harder than Python 2.

Fr. Robert: Yes and no, I mean there actually are a lot of benefits to running print as a function because then you can do all the things that you can do with a function, right. You can pass parameters, you can do things that you couldn’t do with it as a statement. But, this is one of the kickers, because Python has been around for so long and because they already gone through several revisions and because there's already such a huge installed base of modules that you can pull over, there's a lot of people who aren’t going to 3 because this breaks all those modules.

Shannon: Yes.

Fr. Robert: If all of my compiled modules, all my collected modules had been using print as a statement and suddenly that no longer works, people get upset.

Shannon: And when you get into thousands and thousands of lines of code then it’s going to be really irritating.

Fr. Robert: Right, right. Now, something else that we should probably talk about when we’re talking about Python is the way you end your code lines. In C# it was pretty simple. You remember when we wanted to end a line we put the little—

Shannon: Semicolon.

Fr. Robert: …semicolon, boop. Yeah, that told the IDE, this is the end of the line of code go ahead and start compiling the next line of code.

Shannon: Right.

Fr. Robert: In python we don’t have that. If you go ahead and look at this, remember - actually we just saw an example that. Jump back into my computer, there are no semicolons. If I want to print something, I just go print hiya.

Shannon: And then you just hit enter.

Fr. Robert: Right and that’s because Python doesn’t look at some sort of character to end a line, it looks at whitespace. So if you hit enter, it knows there's a new line.

Shannon: I see.

Fr. Robert: Yeah, if you leave a gap—

Shannon: That’s pretty smart.

Fr. Robert: It’s very smart, right. If you leave an indent it knows that that block of code belongs to the thing above it, right. So it’s just like when you're doing word processing. It’s one of the things that sets Python apart from some of the more advanced languages, which is it’s very easy for you to figure out what line of code belongs to what.

Shannon: That’s cool. Okay it’s easy.

Fr. Robert: Yeah, it’s easy. Again, now here’s something that’s not so easy. Do you remember how we declared variables when we were doing C#?

Shannon: Yeah, I kind of did.

Fr. Robert: Remember, you had to do type right?

Shannon: Yes.

Fr. Robert: So it looked something like this. When I had a variable, if you go ahead and go to the chalk board, let’s say I wanted to create an integer, I would put int x there. And I've just declared a variable, right? And that’s because in C# and a lot of other languages, especially compiled languages, I have to tell the computer, I have to tell the compiler what type of variable because the type of variable will determine how much memory it sets aside to use for that variable.

Shannon: Right, yes.

Fr. Robert: And we talked about this before—

Shannon: How many bits.

Fr. Robert: Bits, right. So like an integer would use up two bytes, so sixteen bits of memory. A long integer would use 4 bytes. A character would use 8 bits – oh sorry, yeah. A floating point would use 4 bytes or 32 bits.

Shannon: Right, okay.

Fr. Robert: Now the way that we have in Python it’s actually different. It’s not type defined, it’s called dynamically defined.

Shannon: Oh that’s weird.

Fr. Robert: Yeah, so—

Shannon: What does that mean?

Fr. Robert: What it means is all I have to do is name the variable and because it’s being compiled in real time, it’s being interpreted right, it will determine what kind of variable it is by the type of data I put into it. Yeah, you're puzzled, good.

Shannon: I'm confused.

Fr. Robert: Switch over to my computer and let me show you really quickly. Now this is how you define a variable in Python. If you go ahead and zoom in, and let’s say I want to create a variable called variable one. So var1, it has no type right?

Shannon: Yeah.

Fr. Robert: But I do this, I put var1 = 100.

Shannon: You just named it. Okay so you gave it some numbers.

Fr. Robert: Right.

Shannon: So it automatically knows that it’s going to be an integer.

Fr. Robert: Now it knows it’s an integer because it’s a hundred. Now let’s say I say var2 = “hello world”. Why do I keep putting a w.

Shannon: So you know that that’s going to be a string.

Fr. Robert: It knows it’s going to be a string.

Shannon: It just automatically knows.

Fr. Robert: And let’s put this var3 = 3.14.

Shannon: That is a floating.

Fr. Robert: Right, so exactly. So we've got three types of variables here, I didn’t have to tell it what type it was, it just knew.

Shannon: That’s cool.

Fr. Robert: If it’s a hundred, it’s a whole number, it’s and integer. If it’s a string of characters it knows it’s a string. If it’s 3.14 it knows it’s a floating point. And the cool thing about this now I can do this, I could say print, I'm going to put var2—

Shannon: You just put var, the title of it?

Fr. Robert: Yeah.

Shannon: And it just works.

Fr. Robert: Hello world. Or I could add up var1 and var3 and it should get – so I put var4 = var1 + var3 and then I'm going to print var4.

Shannon: What?

Fr. Robert: 103.14

Shannon: Really?

Fr. Robert: Yeah it’s that simple. This is what makes Python so user friendly.

Shannon: It is so easy.

Fr. Robert: It is so easy right? You understand immediately what you're doing. And the cool thing is I don’t have to worry about “Oh is it an integer? Is it a float?”, no, no, no Python will figure it out for you.

Shannon: That’s so cool. Well now since I feel like I kind of understand the basis C# I could totally just jump into Python.

Fr. Robert: Exactly, now we should mention that Python has several types of data types that it could automatically choose. There are numbers, there are strings, there are lists, which are all raised, which we didn’t cover in C# but we’re going to get into them.

Shannon: Okay.

Fr. Robert: Yeah, and then there are also Tuples.

Shannon: Tuples?

Fr. Robert: Yeah, the read only list. Again, we’ll cover it, we’ll get there, don’t worry about it. Then there’s a dictionary type, which is sort of like a hash table.

Shannon: Oh.

Fr. Robert: Yeah, yeah.

Shannon: Cool.

Fr. Robert: Now all of these data types we will cover in future episodes of Coding 101. You don’t really need to know what they are though because again, Python will automatically do it when – as you're entering in the data, Python figures out what it is and it assigns the right type.

Shannon: Okay, that’s awesome.

Fr. Robert: One last thing. Or actually two last things.

Shannon: Two, oh boy.

Fr. Robert: We need to output to the screen, and we need to come back. Now we already showed you print, and we showed you both Python 2X and Python 3X, right?

Shannon: Yes.

Fr. Robert: Print, just print. Just print, it’s like basic right?

Shannon: It’s easy, right.

Fr. Robert: So print, either in quotations, the string or print space the name of the variable that you wan to print.

Shannon: And then it ends up just printing directly into the idol as they call it.

Fr. Robert: Yeah, yeah and there you go. That’s your screen. But there's the other part, and that is how do you get data from the user, right?

Shannon: Yeah.

Fr. Robert: Because—

Shannon: Yeah, how do you do that?

Fr. Robert: Well in C#, we had console.readline, console.writeline, exactly. In this case, what we’re going to do is we’re going to use a function called raw-input.

Shannon: Oh, okay.

Fr. Robert: And the reason why we know it’s a function is because it actually has parenthesis on it so raw_input looks like that. Now this in and of itself won’t do anything. This is just a function, there's nothing in it right? But what I'm going to do is I'm going to put this. I'm going to put var6  = raw_input and then in quotations I'm going to put gimme data.

Shannon: Feed me Seymour.

Fr. Robert: There we go, right. And now it says gimme data and I put 555, what it’s done is it’s just taken that 555 and it’s put it into the variable called 6, var6.

Shannon: Oh, okay.

Fr. Robert: Yeah, and again, it’s one of those things – looking at that one line of code, most people can figure out what just happened. Variable 6 is equal to a function called raw input that says gimme data inside. When I executed I see—

Shannon: It outputs gimme data.

Fr. Robert: Gimme data, which was inside the function.

Shannon: And it allows you to put some kind of raw input.

Fr. Robert: Which then puts it into var and if I now put print var6, if I spell it right, 555.

Shannon: 555, that’s awesome.

Fr. Robert: Yeah.

Shannon: That’s really cool.

Fr. Robert: I didn’t blow anyone right. Chat room, you got this right? This is pretty simple stuff.

Shannon: This is very simple, yeah.

Fr. Robert: And this is what’s so cool about it. You can pick this up and in a couple of minutes you’ll just be making your own little programs.

Shannon: That’s so cool, I can totally do like math equations, I could do my own – I could bake people enter my own input, oooh.

Fr. Robert: Yes, I know, I know. Now Shannon, it’s been a while since we did one of these Coding modules but do you remember what comes after the ivory tower?

Shannon: Ooh, I think there's a code warrior involved.

Fr. Robert: There might be a code warrior, and you know what, since Lou has obviously died because we had up with Sarah Mclaughlin’s

Shannon: He didn’t die.

Fr. Robert: He didn’t die but he went away for a while. We’ve got a brand spanking new code warrior. We want to welcome to the show Mister Dale Chase from Discovery Digital Networks. Dale, thank you for being our code worker, thank you for coming on.

Dale Chase: What’s up, thanks for having me.

Fr. Robert: Now you sir are a bit of a Python expert. We know that you wouldn’t be on the show if you weren’t but would you like to tell the audience a little about yourself. Why are you on Coding 101? Why are you our code warrior?

Dale: I have been a coding enthusiast pretty much my entire life. So since the Apple 2c, when I was breaking into games written in basic and learning how to write basic on the Apple 2c.

Fr. Robert: Yeah so your bona fetus go way, way back. And beyond all of that, I mean you do this professionally right? This is what you do, you write code for a living.

Dale: Yeah, yeah right now I am doing actually a lot of back end scripting for Discovery Digital Networks. Working mostly in PHP and a little bit of Python.

Fr. Robert: Let me ask you this, and you know you asked me this before the show Shannon, why do you think Python has taken off? I mean it seems so simple, what we just did, anyone could do within five minutes of picking up this compiler, installing it in the computer. But it is used extensively throughout the web, through out the internet, what makes Python so usable?

Dale: It’s so just pick up and go just like you guys were saying. It’s amazing, it’s like my favorite. You can use like any text editor and a couple of lines and you just jump right in. There's no real setup to worry about you know.

Fr. Robert: Yeah, well let’s do that, let’s jump right in. And remember, Dale you're assembling all of this code, you could be a subleg in notepad, right. I mean if you're in Windows, you could just type a couple of lines of code and then go ahead and have the Python idol, the idol compiler, open it up and run it just like that.

Dale: Yeah, yeah pretty much. I mean I'm going to work in Text Wrangler, which is a free editor—

Fr. Robert: Thank you for the free explosion Brian.

Dale: … just because like you know, using something like that you can see the commands show up in a different color and the strings will show up in a different color. So it makes it easier to figure out what you're working with but yeah you can just like a text editor, just a plain old text file if you wanted to.

Shannon: You were working on OSX correct?

Dale: That’s correct.

Shannon: Okay.

Dale: So the difference that you’ll see on my machine is that I’ll be working right in the OSX terminal and putting Python in front of my Script name and running it that way in the terminal as opposed to the console that’ll be popping up for you guys.

Fr. Robert: But again, you could be doing this in any text editor or you could be doing it straight in the Python shell if you wanted to.

Dale: That’s correct.

Fr. Robert: So show us, you’ve got two programs that you wrote that I asked you to do something simple enough for people to understand, to grock and then to break. What’s the first one you want to show us?

Dale: I want to show you this simple addition program. And I’ll just go through line by line?

Fr. Robert: Yeah, guide us through line by line.

Dale: Okay well the – actually what you see at the top here is probably superfluous but this basically to let the interpreter know that this is in fact a Python script that I'm running and which version of Python to look for based on a path variable I set up in your environment. Not really much to worry about here, I mean it’s pretty much kind of superfluous here. The next line is the print statement you guys were just talking about, which basically is just sort of a welcome for this particular program that just says “Hey let’s find the sum of two numbers” and then as you were just showing, I'm using raw input to have the user give us the first value and then assign that to a value to the variable first value.

Fr. Robert: Now, I want to stop you very quickly because there is something very cool in that line, in that you are declaring a variable, you are inputting from the user, and you are outputting to the screen all at the same time, all in one line. That’s an incredibly powerful tool.

Dale: Yes, yes and the second line is the same thing, just using the next variable. And the fourth line is summing up the two values that the users entered along with printing out to the screen the sum at the same time. I've encapsulated the variables with a function called int, which basically verifies that the value will be and integer if it is a number.

Shannon: Ah, okay.

Dale: It’s kind of superfluous if you’ve already written just – it’s kind of—

Shannon: It kind of reminds me of sanitizing.

Fr. Robert: There we go, she was like “Oh I've seen this before” yeah because if someone, some wise arse puts x, you know of course the programs – if you sanitize it the program is going to kick it back and say “No, that’s not a number, give me a number”.

Dale: Yeah, you might even just get an error. Just force of habit for me, I guess. To really sanitize it there’s probably another couple of lines you would’ve thrown in there but just force of habit for me. I just kind of just do that. But you probably don’t even need that for this instance.

Fr. Robert: Yeah, technically you could do that print line just by saying print and then first value, second value.

Dale: Yes.

Fr. Robert: First value plus second value.

Dale: Yeah.

Fr. Robert: But this is the more correct way to do it because, as we said before, you always want to sanitize your inputs.

Dale: Yes and what I want to point out though, so I've got your total is and no space and then a comma.

Shannon: Yeah, I was wondering about that. Where does the comma fit in like how do you know that there's going to be a space between is and the number?

Dale: So, we’ll get to this I guess in a minute but so if the comma will concatenate the rest of the statement to this first string but put in a space between. So I could just use a plus, which would add them together as far as the statement is concerned but then there would be no space between the value and this first string.

Shannon: Oh cool.

Fr. Robert: Right.

Dale: So the comma is what will put the space in between there.

Shannon: Okay, got it. Interesting Python information.

Dale: And to close out we've got this press enter to exit which will floor the folks on the Windows machines will keep the console open after the user has seen the total.

Fr. Robert: Right.

Shannon: This was something that I noticed earlier when I was messing with Dale’s code. I noticed on my Windows machine the raw input press enter to exit was not included at the end of the code so it automatically just closed out as soon as it gave me the output.

Fr. Robert: And that’s because in a Windows machine the console one defaults to close when terminated. You could change that or you could just enter that line of code that keeps the program alive until you hit enter. Now Bryan, if you go to my computer really quickly just to show you that feature again, this is a little something that we just did here. This is showing concatenation, we've got var1 equals hello, var2 equals world and then you just put print var1 comma var2 and what you get is hello world.

Shannon: Comma space.

Fr. Robert: Right, so it concatenates the two variables and adds a space between them.

Shannon: That’s cool.

Fr. Robert: It’s actually very useful. But back to your program Dale, go ahead and show us what happens when you run this.

Dale: All right, so let’s find the sum of two numbers, type a number and press enter. Let’s do 44, hitting enter, type another number and press enter, let’s do 67 and you total is 111.

Shannon: Yay.

Fr. Robert: Yatah, tada, tada.

Shannon: And it does a lot of math on the back end for you because it automatically knows or it checks to make sure that it’s already an integer.

Fr. Robert: Those are integers and you're good to go. All right Dale, so that’s numbers but you’ve got some stringy strings for us, yes?

Shannon: Ooh.

Dale: Yes I do.

Shannon: Yay.

Dale: So let me pull that up. Let’s see—

Fr. Robert: I think I have it on my computer as well.

Dale: Okay, there we go.

Fr. Robert: So in this case – you know actually something else we should probably mention really quickly, this is one of those things that I always forget to mention, when you see a pound symbol in Python it’s a comment. So go back to that screen Bryan. You can see like after the lines of code, you can see that pound, get in the habit of doing that because what you want to do is you always want to comment as much as you possibly can so that anyone picking up your program later on will be able to understand what that line of code is supposed to do. Anything you put—

Shannon: If I remember correctly, C# was two slashes.

Fr. Robert: Right, so in this one it’s just a pound. Anything you put you start something with a pound, Python just know everything after it, ignore it.

Shannon: Okay.

Fr. Robert: It’s not for me.

Dale: Now the one caveat to Python is that it doesn’t have a mechanism for commenting out a huge block of code like you may find by doing a slash, an asterisk and then an asterisk slash in some other languages like, I think C# did that, is that correct?

Shannon: Yes.

Fr. Robert: Yeah.

Shannon: So you do in that case.

Fr. Robert: You’d have to do a pound on every line.

Dale: Exactly, exactly.

Fr. Robert: Pound, pound, pound, pound, pound, pound, pound.

Dale: So the really good text editors, the code editors will allow you to kind of highlight a group and it will automatically put like the pound on every line if you do a certain key command.

Fr. Robert: Right.

Shannon: Oh.

Fr. Robert: All right, show us some strings.

Dale: All right, so this program works similarly where it asks you “Tell me where you live.” This was apparently written by the NSA.

[laughter]

Dale: So we’ll do a raw input “Which state do you live in?” and this will assign that value that the user enters to a variable requiring state.

Shannon: Okay.

Dale: And then we’ll do—

Shannon: The same thing with city.

Fr. Robert: Um-hmm.

Dale: Exactly, the same thing with city. And so here—

Shannon: Oh that’s weird. So you have a comma space – oh, I see what you're doing. So when you print that line it’s going to say you live in, space, the city so I’ll say Springfield, comma, space and then the state, and the state would be whatever you inputted.

Dale: That’s correct.

Shannon: Okay.

Fr. Robert: Good call.

Dale: So shall we go ahead and run this.

Fr. Robert: Yeah run that.

Dale: All right, what state do we live in.

Shannon: Tell me where you live NSA.

Dale: California and I live in Oakland. And I live in Oakland, California.

Shannon: Cool, so we have where you live in Oakland, space or Oakland comma space California.

Dale: That’s correct.

Shannon: Cool.

Fr. Robert: Now Dale, of course these programs are incredibly simple and the reason why they're incredibly simple is because I asked you for incredibly simple. But this is what it will do for our people who taking home your code warrior exercise, your homework. And that is it’ll let them play with different types of data, right? You’ve got strings and you’ve got numbers. I think for homework Shannon, what we should be asking for people to do is write a piece of Python, and remember these pieces of code are going to be up in the git hub, that combines the two.

Shannon: Ooh.

Fr. Robert: Yeah write a program that’s going to combine both integers and string. Maybe you can even throw in couple of different data types. This is one of those things where you can search on the web and find really quickly all the different types of mathematical instructions that you can use and all the different types of variables that you can use.

Shannon: I already have a few ideas myself.

Fr. Robert: Yeah, I think you can get to it.

Fr. Robert: Now Dale, do you want to tease next week, I think we’re going to get a bit more advanced. When did you want to take the kiddies?

Shannon: Meow.

Dale: Is it soon to do lists?

Fr. Robert: I don’t think so.

Shannon: We could totally do lists. Let’s do it.

Fr. Robert: We had a conversation last night and Dale was like “So is episode one too early to do Youtube integration.” I'm like “Just back it off a tiny bit”

Shannon: A little early.

Fr. Robert: A little early but you know just to keep the kids inspired. Dale, can you tell them what you have been doing with Python and what it’s let Discovery Networks do in their back end.

Dale: Well, what I had done with Python up until recently, I had a situation where I had a Google doc that I needed to keep up to date. And as Discovery started adding more and more shows that I needed to have this data put into this Google doc, I decided that it was getting too cumbersome and I needed a way to kind of automate it so I wrote a Python script that would incorporate using the – what was then the revision 3 API to get information about shows and then using Google’s spreadsheet API to fill in this data for me. And I had it running on a loop at like half hour intervals and I was no longer concerned about it.

Fr. Robert:  Are you having—

Shannon: Sounds really complicated.

Fr. Robert: Complicated but really not that much really because once you learn the basics of Python, all it is, is figuring out how to code that logical exchange. If you’ve ever, ever used a website like Google docs or Youtube and you’ve figured “Oh I would much rather have this with this and this document with it.” We’re now giving you the tools to do it. This is the back end, this is what people write their back end, this is how they access APIs, it’s with Python and you're going to learn it now.

Shannon: Yay, I can’t wait. Thank you so much Dale for joining us. Awesome to have you here.

Dale: No doubt, oh no I'm so glad that you guys asked me to get down with this so thank you for having me join you.

Shannon: Get down, get down.

Fr. Robert: No, no we’re not going to do that to you. Dale thank you so very much and we will see you next week code warrior.

Dale: Catch you guys.

Shannon: Sign out, bye.

Fr. Robert: Now, ladies and gentlemen that’s the end of episode one of our second module. If you liked it you're going to want to subscribe, make sure to drop by our show page at twit.tv/code and subscribe. You'll be able to download our episodes, all of our episodes including the previous module on C# and more importantly you'll get our show notes. You need our show notes because they tell you where to find the code for every episode. We've got a Github set up which lets you download all of our examples and run it on your own computers.

Shannon: And we even have a brand new folder on the Github for Python.

Fr. Robert: Python, make it nice and easy.

Shannon: Also we are on iTunes still, for some reason people keep on subscribing on iTunes, it’s crazy. I guess people like the show or something, it’s so weird.

Fr. Robert: Code monkeys.

Shannon: So if you guys want to watch the show on iTunes we are on there. Please subscribe, if you want to review the show and tell us what you think. I do read the reviews.

Fr. Robert: Yeah, yeah and also you can find us on Youtube. If you one of these people who just eats everything on Youtube, go ahead and drop by youtube.com/twitcoding101.

Shannon: Om nom nom.

Fr. Robert: Om nom nom and you can watch our episodes and catch updates about upcoming Google hang out events.

Shannon: Yeah we totally need to do one of those.

Fr. Robert: We really have to do that. We've been so lazy about that and I totally want to do it. Let’s do it, all right.

Shannon: We’re also on Google Plus, this is the one that we mentioned earlier where you can share your own code, which we do share code on the actual shows. So we’ll be happy to shout out to you guys if you want to share. That Google Plus community is over at gplus.to/twitcoding101. Please join us.

Fr. Robert: Yeah, yeah but if you're not feeling—

Shannon: There's seven hundred people up there.

Fr. Robert: I know right.

Shannon: We’re like nine away.

Fr. Robert: It gets bigger every – please, you know what, actually we need to hit a thousand before the end of this module. Tell your friends and tell them “Look, even if they don’t want to learn coding, we need experts in there” we got people like TJ, T Joe code for sale Joe who helps people who have coding problems. It’s a community, it’s not just a forum, it’s not just a posting, it’s where you can find out how to do the things you want to do. It’s cool like that.

Shannon: And hey, if they're not on Google Plus where else can they find us?

Fr. Robert: Well, they can find us on twitter too I think.

Shannon: Oh yeah.

Fr. Robert: I think I'm twitter.com/ - I'm  @padresj right.

Shannon: Yeah, I believe so and I think I'm @Snubs like that, boop.

Fr. Robert: And you know what, as long as you're watching this, why not watch us live. If you watch us live you get to see all the things that may not make it into the final episode. You can find us every Thursday—

Shannon: Like him taking shots of garlic sauce.

Fr. Robert: Totally didn’t happen but you can find us here every Thursday every week at 1:30 pm. And as long as you're here, don’t we have a chat room?

Shannon: We do, it’s at chat—

Fr. Robert: IRC.

Shannon: IRC.twit.tv

Fr. Robert: IRC.twit.tv

Shannon: I always like chat.

Fr. Robert: It is chat.

Shannon: Yes, irc.twit.tv that’s where you can chat with us during the show. We do read it so a lot of your comments do make it into the show.

Fr. Robert: And that’s it for this episode, I'm father Robert Ballecer.

Shannon: I'm Shannon Morse.

Fr. Robert: End of line.

Shannon: No semicolon.

Fr. Robert: Um-um whitespace.

[laughter]

[fake sobbing]

Fr. Robert: Lou.

Shannon: So precious.

Fr. Robert: Come back to us Lou.

Shannon: Thank you everybody for watching the show, we really had fun, okay thanks bye.

Fr. Robert: Okay, thanks, bye.     

All Transcripts posts