=== kermiac_ is now known as kermiac | ||
=== kermiac is now known as kermiac_ | ||
=== gator is now known as Guest97081 | ||
=== kermiac_ is now known as kermiac | ||
Pawka | hi | 08:45 |
---|---|---|
hemanth | o/ | 08:48 |
=== pd is now known as Guest76958 | ||
=== me is now known as Guest6622 | ||
leoquant | can someone make an announcement on top of this channel for a live session this Saturday? Ref.: https://wiki.ubuntu.com/Packaging/Training | 10:23 |
leoquant | thx | 10:23 |
persia | leoquant: What'S the subject for Saturday? | 10:25 |
persia | leoquant: Shouldn't it rather be added to http://people.ubuntu.com/~nhandler/classroom.html ? | 10:26 |
qense | persia: "How to effectively use a PPA and providing updated package" | 10:26 |
* persia pokes nhandler | 10:26 | |
qense | by Rohan Garg and rowinggolfer at 17.00 UTC | 10:26 |
leoquant | qense indeed | 10:26 |
persia | leoquant: In fact, you probably want to get nhandler to list all your Packaging/Training topics (as they are scheduled). | 10:27 |
persia | I think ClassBot will then do the right thing. | 10:27 |
persia | Cool. That does work. But I still don't really want to change the /topic unless there's no other option. | 10:28 |
leoquant | persia i am ask to fix this as soon as possible | 10:29 |
persia | leoquant: fix which? | 10:30 |
persia | Was the class previously scheduled for now? | 10:30 |
leoquant | the annoucement persia | 10:30 |
persia | Oh, to make the announcement for the event? | 10:31 |
leoquant | yep | 10:31 |
persia | Ah, go ahead and announce it then. | 10:31 |
persia | nhandler should be around in a few hours, and can add it to the schedule. | 10:31 |
leoquant | ok | 10:32 |
=== JOAKO is now known as Guest41411 | ||
=== Guest41411 is now known as JOAKO[ARG] | ||
Emilse-Paez | hello | 13:05 |
joakodlz | Emilse-Paez hi! | 13:10 |
=== Jan is now known as Guest7818 | ||
=== gator is now known as Guest4606 | ||
cjohnston | leoquant: persia qense I need the instructors nicks please | 13:46 |
persia | cjohnston: For the upcoming event? | 13:46 |
persia | leoquant: ^^ | 13:46 |
cjohnston | yes | 13:46 |
qense | I don't know their nicks, I was just asked if I was interested in helping with translating the session. | 13:47 |
cjohnston | Could someone find out please... I need their nicks to be able to schedule it | 13:48 |
qense | I'll try if I can find it out. | 13:48 |
persia | qense: What are the names again? | 13:48 |
persia | Or if you're looking lp.net/people might help :) | 13:48 |
cjohnston | ty | 13:49 |
qense | persia: Rohan Garg and rowinggolfer | 13:49 |
qense | the second session is done by persia himself | 13:49 |
persia | The 4th, right? | 13:49 |
qense | persia: the second | 13:49 |
persia | Rohan Garg is shadeslayer | 13:50 |
qense | I find these two people on LP: rohangarg | 13:50 |
qense | and rowinggolfer | 13:50 |
persia | qense: The 2nd? I'm *really* busy on the 2nd. Are you sure? | 13:50 |
qense | persia: ah, date | 13:50 |
qense | indeed, the 4th | 13:50 |
qense | right in the middle of the UODW | 13:50 |
persia | Neil Wallace is rowinggolfer | 13:50 |
persia | But at a sane time of day when nobody is ranting about upstream coding :) | 13:51 |
qense | 6 UTC sane! | 13:51 |
qense | ? | 13:51 |
qense | The only reason I'm awake at that time is because I have to cycle to school! :P | 13:51 |
cjohnston | qense: so its rowinggolfer and shadeslayer ? | 13:52 |
qense | cjohnston: indeed, like persia said | 13:52 |
cjohnston | ty | 13:52 |
binti | ah i dont have to register my nick? | 13:52 |
persia | binti: Depends what you're trying to do :) | 13:53 |
binti | registering my nick..., didn't work | 13:53 |
qense | I would recommend anyone who's often on IRC to register his or her nick. | 13:53 |
cjohnston | fwiw, the timedate link on the first class for packaging training is wrong | 13:54 |
shift_wreck | #ubuntu-classroom-chat | 13:54 |
shift_wreck | dur | 13:54 |
cjohnston | the two classess have been added to the training calendar | 13:56 |
qense | cjohnston: now you're here, are the two Adopt-an-Upstream sessions added to the calendar? Jorge and I did place them on the w.u.c/Classroom schedule | 13:57 |
persia | cjohnston: Thanks! | 13:57 |
cjohnston | sure are qense | 13:59 |
qense | cjohnston: good! | 13:59 |
binti | my first classroom in 27 years and xchat hangs | 14:17 |
ghostcube | :D | 14:17 |
binti | anyone else working with loqui ? | 14:19 |
=== lukjad007 is now known as lukjad86 | ||
=== jubesz is now known as Guest51540 | ||
binti | fixed, the problem was gnome xchat | 14:27 |
=== jubesz_2nd is now known as jubesz | ||
=== Jan is now known as Guest3397 | ||
binti_ | python class in 2 hours ? | 14:55 |
hemanth | in 5mins | 14:55 |
molok | more like 5 mins | 14:55 |
binti_ | :) thanks | 14:55 |
rickspencer3 | is anyone here? | 14:59 |
cjohnston | no.. im here | 14:59 |
cjohnston | at my house | 14:59 |
rickspencer3 | hehe | 14:59 |
rickspencer3 | lol | 14:59 |
cjohnston | I dont know where you are | 14:59 |
hemanth | :) | 14:59 |
cjohnston | Lets see if she works | 14:59 |
rickspencer3 | I am in Seattle, and I am about to try to introduce the notion of programming in Python to folks who haven't programmed before | 15:00 |
rickspencer3 | and I am really pumped | 15:00 |
rickspencer3 | cjohnston, so I just go? | 15:00 |
rickspencer3 | is there fanfare? | 15:00 |
cjohnston | I'm wondering why ClassBot isnt setting things up | 15:00 |
rickspencer3 | trumpets, red carpet, curtain pulled back? | 15:00 |
Pendulum | rickspencer3: well we can pull them out if you really want, but we're a bit lazy ;) | 15:01 |
rickspencer3 | Pendulum, yes, I require fanfare | 15:01 |
cjohnston | rickspencer3: go ahead and start.. ill work on classbot | 15:01 |
rickspencer3 | cjohnston, thanks | 15:01 |
rickspencer3 | so, I guess if I ask things here, people answer in #ubuntu-classroom-chat, right? | 15:01 |
cjohnston | yup | 15:02 |
rickspencer3 | so first, everyone who is here doesn't know a programming language yet, but is interested in getting started right? | 15:02 |
binti_ | yep | 15:02 |
NVSBLmonstr | More or less | 15:02 |
papapep | yep | 15:02 |
rickspencer3 | hehe | 15:02 |
* CaptainHero too | 15:02 | |
rickspencer3 | ok | 15:02 |
cjohnston | there you go.. sorry | 15:05 |
rickspencer3 | np | 15:05 |
rickspencer3 | due to my compulsive personality, I found it necessary to more or less write out the class first | 15:05 |
rickspencer3 | https://wiki.ubuntu.com/UbuntuOpportunisticDeveloperWeek/IntroToPythonForTotalBeginners | 15:05 |
rickspencer3 | so you can follow along there if it helps | 15:05 |
rickspencer3 | what I hope to do in the next hour is to give you a taste of programming and how Python works | 15:05 |
rickspencer3 | so that you can go off and start really learning it | 15:05 |
rickspencer3 | so, when I was a boy, the line between using a computer and programming it were a bit blurry | 15:06 |
rickspencer3 | you had a computer, and to use a program you got a listing of the program printed it out, and you typed in the source yourself | 15:06 |
rickspencer3 | typically using Basic (an early and pretty easy language) | 15:07 |
rickspencer3 | so I wrote an "adventure game" for my first program | 15:07 |
rickspencer3 | one of those text adventures where you go north, look in the gave, put the bird in the cage, etc... | 15:07 |
rickspencer3 | does everyone know what I mean? | 15:07 |
rickspencer3 | k | 15:08 |
rickspencer3 | so we'll start making one in this session | 15:08 |
rickspencer3 | but first, a few things about a program | 15:08 |
rickspencer3 | a program is just a series of instructions that you type out for the computer to follow | 15:08 |
rickspencer3 | computers are not smart at all | 15:08 |
rickspencer3 | they are just very very obedient, and they can count really fast | 15:09 |
rickspencer3 | this means that if you have a small error in what you type, the computer gets confused | 15:09 |
rickspencer3 | like if I was "seattle" instead of "Seattle" any human can cope with that error | 15:09 |
rickspencer3 | but to a computer, those two words are totally different, and the program will choke | 15:09 |
rickspencer3 | (for the record that is called "case sensitivity") | 15:10 |
rickspencer3 | so that's an example of how really stupid computers are | 15:10 |
rickspencer3 | any questions before we start working on the game? | 15:10 |
rickspencer3 | . | 15:10 |
rickspencer3 | . | 15:10 |
=== ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - http://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Event: Ubuntu Opportunistic Developer Week Prep - Current Session: Intro to Python for Total Beginners - Instructor: rickspencer3 || Questions in #ubuntu-classroom-chat | ||
rickspencer3 | ok, let's start them | 15:10 |
rickspencer3 | it's a good idea usually to sketch out what your program will do sometimes | 15:11 |
rickspencer3 | so I designed the game, and there is a picture of it on the wiki | 15:11 |
rickspencer3 | basically, the player has to get the fork and the bulb from the living room ... | 15:12 |
rickspencer3 | go to the kitchen, stick the fork in the toaster which will cause the bulb to light up ... | 15:12 |
rickspencer3 | so they can see in the pantry, where they win | 15:12 |
rickspencer3 | so let's get ready to write the program | 15:12 |
rickspencer3 | open up your text editor, probably gedit, and save a blank file | 15:13 |
rickspencer3 | I called it "prize_hunt.py" | 15:13 |
rickspencer3 | it doesn't matter much what you name it so long as it ends in ".py" | 15:13 |
rickspencer3 | (py is for python of course) | 15:13 |
rickspencer3 | you also need a terminal window open | 15:13 |
rickspencer3 | the terminal should be in the same directory where you saved the file | 15:14 |
rickspencer3 | I'll give folks a moment to get that set up | 15:14 |
rickspencer3 | let me know when I should move on | 15:14 |
rickspencer3 | any questions? | 15:14 |
rickspencer3 | ok | 15:15 |
rickspencer3 | let's write some code!! | 15:15 |
rickspencer3 | this is the fun part :) | 15:15 |
rickspencer3 | let's start by making the computer say things to player | 15:15 |
rickspencer3 | in Python we do that with a command called "print" | 15:15 |
rickspencer3 | it doesn't print to the printer, it prints to console | 15:15 |
rickspencer3 | here | 15:15 |
rickspencer3 | 's my first line: | 15:15 |
rickspencer3 | print "You are outside the front door of the house. The prize is inside." | 15:15 |
rickspencer3 | that's the first line of the file | 15:16 |
rickspencer3 | save it | 15:16 |
rickspencer3 | now we need to run the program | 15:16 |
rickspencer3 | (it's very important to save the file!) | 15:16 |
rickspencer3 | we run the program with the terminal by telling python to run it: | 15:16 |
rickspencer3 | $python prize_hunt.py | 15:17 |
rickspencer3 | python prize_hunt.py | 15:17 |
rickspencer3 | the "$" is just a convention to show you type it on the terminal | 15:17 |
rickspencer3 | is ti working for everyone? | 15:17 |
rickspencer3 | ok | 15:17 |
rickspencer3 | you just wrote a program! | 15:17 |
rickspencer3 | believe it or not, that's pretty much all there is to it | 15:17 |
rickspencer3 | from here on out it's just refining that basic idea | 15:18 |
rickspencer3 | we probably want to tell the player some more stuff | 15:18 |
rickspencer3 | so let's add some more printing to our program to get started | 15:18 |
rickspencer3 | print "You can enter commands to do stuff" | 15:19 |
rickspencer3 | print "The commands are go, look, take, use, and put" | 15:19 |
rickspencer3 | print "Use commands with objects that you see around" | 15:19 |
rickspencer3 | print "For example, you can enter 'look door'" | 15:19 |
rickspencer3 | just add those lines and run it | 15:19 |
rickspencer3 | (or similar, it's your game after all_ | 15:19 |
rickspencer3 | any questions? | 15:19 |
rickspencer3 | is it working? | 15:19 |
rickspencer3 | save and run again to make sure it's working | 15:19 |
rickspencer3 | ok, great | 15:20 |
=== stevefed5291_ is now known as stevefed5291 | ||
rickspencer3 | so let's move on | 15:20 |
rickspencer3 | we can tell the player stuff, so now let's let the player tell us stuff | 15:20 |
rickspencer3 | this will introduce two basic concepts that you will use over and over and over again in programming | 15:20 |
rickspencer3 | using a variable, and calling a function | 15:20 |
ClassBot | hemanth asked: how to decide on the quotes? | 15:20 |
rickspencer3 | can you explain the question a little more? | 15:21 |
rickspencer3 | is this about using " versus ' ? | 15:21 |
ClassBot | hemanth asked: yes "" ' ' | 15:21 |
rickspencer3 | ok | 15:22 |
rickspencer3 | so ... | 15:22 |
rickspencer3 | a string is a collection of characters | 15:22 |
rickspencer3 | surrounded by either " or ' | 15:22 |
rickspencer3 | in python yu can choose eiher | 15:22 |
rickspencer3 | I prefer " most of the time | 15:22 |
rickspencer3 | so, moving on | 15:23 |
rickspencer3 | let's get some user input | 15:23 |
rickspencer3 | if command == "look door": | 15:23 |
=== pd is now known as Guest66583 | ||
rickspencer3 | oops | 15:23 |
rickspencer3 | wrong line | 15:23 |
rickspencer3 | command = raw_input("Enter a command:") | 15:23 |
rickspencer3 | ok, that's the correct one | 15:23 |
rickspencer3 | add this to your program and run it | 15:23 |
rickspencer3 | "command" is a variable | 15:24 |
rickspencer3 | a variable is a word that you use in your program that is kind of a container for values | 15:24 |
rickspencer3 | specifically values that can *vary* depending on what the program does | 15:24 |
rickspencer3 | "command" is a variable that will store the results of "raw_input" | 15:25 |
rickspencer3 | raw_input is a function | 15:25 |
rickspencer3 | You "call" a function in a program. A function will do something, and it can also provide back some information. raw_input prints out a message that you tell it to print out and then collects whatever the user types. It then "returns" what the user typed. This line of code is storing what the function returns for you. Make sense? | 15:25 |
rickspencer3 | Some functions need some information before they can work. raw_input needs a string to display. Information that you provide to a function is called an "argument". It is usually goes inside the parenthesis. | 15:25 |
rickspencer3 | this is a bit to digest, but using it may help you understand | 15:26 |
rickspencer3 | is everyone's program running? | 15:26 |
ClassBot | liemily asked: Does raw_input expect anything other than carriage return? | 15:26 |
=== B is now known as Guest81195 | ||
rickspencer3 | raw_input expects a string to be typed into the console | 15:27 |
rickspencer3 | ended with a carriage return | 15:27 |
rickspencer3 | but the carriage return is not added to the string | 15:27 |
ClassBot | hemanth asked: why is raw_input called so? cos it's bound to any data type when read? | 15:27 |
rickspencer3 | raw_input will be a string | 15:27 |
rickspencer3 | DON | 15:27 |
rickspencer3 | 'T use input() | 15:27 |
rickspencer3 | input is weird, it tries to interpret what is given to is as Python code, so weird stuff can happen | 15:28 |
rickspencer3 | so you get a string from raw_input() and it's easy to work with that way | 15:28 |
rickspencer3 | so are folks getting raw_input to work in the console? | 15:29 |
rickspencer3 | shall we go ahead and actually use the provided input? | 15:29 |
ClassBot | Johonunu asked: are there types of variable like int,double,... or there is single one like in php ? | 15:29 |
rickspencer3 | Johonunu, yes | 15:29 |
rickspencer3 | but you can set a variable to any type | 15:29 |
rickspencer3 | if you know another language already, the next session might be good, as I will | 15:30 |
rickspencer3 | help you make a map from your current language to Python | 15:30 |
rickspencer3 | this class assumes zero programming experience | 15:30 |
rickspencer3 | alrighty | 15:31 |
rickspencer3 | let's go ahead and look at the user input | 15:31 |
ClassBot | m_anish asked: Can raw_input be made to accept multiple lines, and special ASCII characters | 15:31 |
rickspencer3 | hmmm | 15:31 |
rickspencer3 | m_anish, I have never done that, so I don't know | 15:31 |
rickspencer3 | I assume you could add "\n" to add a carriage return | 15:31 |
rickspencer3 | might be something fun for you to test out! | 15:32 |
rickspencer3 | shall we move on to using the input? | 15:32 |
rickspencer3 | ok | 15:32 |
rickspencer3 | this next block will introduce a couple of concepts | 15:33 |
rickspencer3 | add this to your program | 15:33 |
rickspencer3 | if command == "look door": | 15:33 |
rickspencer3 | print "The door to the house. It looks unlocked" | 15:33 |
rickspencer3 | elif command == "go door": | 15:33 |
rickspencer3 | print "You go through the door into the living room" | 15:33 |
rickspencer3 | else: | 15:33 |
rickspencer3 | print "You can't do that here" | 15:33 |
rickspencer3 | can you guess what this done? | 15:33 |
rickspencer3 | . Starting with line #1, what this code says is "if command has been set to the string 'look door' then run the lines of codes that are indented below here" | 15:34 |
rickspencer3 | Typically, programmers will read this as "if command equals 'go door'". | 15:34 |
rickspencer3 | The two "=" are important. There are two because sometimes you write code that sets the value of a variable, and that uses only one "=". | 15:34 |
rickspencer3 | Note that line number 2 is indented exactly 4 spaces. Python uses indentation to define what blocks of code go together. So since line 2 is indented, if the users types something other than "look door" it will skip over line 2. Early on you may write lots of bugs because you get indentation wrong. | 15:35 |
rickspencer3 | let me know when you've tried this out, and what questions you might have | 15:35 |
rickspencer3 | Line 3 says "elif" to start. elif is read "else if" | 15:36 |
rickspencer3 | The "else" is important, because if the user did type in "look door", you just want to run the code for that condition. | 15:36 |
ClassBot | virtuald_ asked: can't i use a tab for indentation? | 15:36 |
rickspencer3 | virtuald_ yes | 15:36 |
rickspencer3 | BUT don't | 15:36 |
rickspencer3 | it's best to set gedit to use spaces for tabs and to use four spaces for the tabs | 15:37 |
rickspencer3 | while the language permits other indentation schemes, the Python programmers of the world have agreed on 4 spaces for a tab | 15:37 |
ClassBot | stevefed529192 asked: I know you can use tabs for indentation as well, is there any reason one would opt for spaces over tabs? | 15:37 |
rickspencer3 | yes | 15:37 |
rickspencer3 | you can't tell the difference between spaces and tabs in most editors | 15:37 |
rickspencer3 | if we don't all do it the same way, we will go crazy trying to read each other's code | 15:38 |
ClassBot | deegee asked: is it a must to have 4 spaces of indentation? | 15:38 |
rickspencer3 | also, when your programs get big, you might find it's easy to read that way | 15:38 |
rickspencer3 | deegee, again, technically you can use any number of spaces, but your life will be easier if you go with the standard | 15:39 |
rickspencer3 | a lot of my early python programs I used 1 space instead of 4 | 15:39 |
rickspencer3 | I regret it now | 15:39 |
rickspencer3 | ok, is this new code making sense to folks? | 15:39 |
rickspencer3 | great | 15:40 |
=== jcsims is now known as Guest56648 | ||
rickspencer3 | btw, this is called "conditional branching" and is one of the key concepts in programming | 15:40 |
rickspencer3 | So you may notice that whatever happens, you code ends after testing the conditions. | 15:40 |
rickspencer3 | oops | 15:40 |
rickspencer3 | not a very fun game | 15:41 |
rickspencer3 | Really what you want is your code to branch off and do stuff depending on what happened. | 15:41 |
rickspencer3 | you probably want some code to handle the situation of the user going into the living room | 15:41 |
rickspencer3 | They key thing to think about is that you want your code to "do something" | 15:41 |
rickspencer3 | Sounds like it could use a function. So you can make your own function for entering the living room. | 15:41 |
rickspencer3 | here's the code for a new function to put at the top of your code file: | 15:42 |
rickspencer3 | def enter_living_room(): | 15:42 |
rickspencer3 | print "You are in the living room. There is a tv cabinet, a" | 15:42 |
rickspencer3 | print "table with some dishes, and a lamp." | 15:42 |
rickspencer3 | command = raw_input("Enter a command:") | 15:42 |
rickspencer3 | this needs to go at the top for reasons that will be clear soon | 15:42 |
rickspencer3 | save the file and make sure your program still runs | 15:42 |
rickspencer3 | still working for everyone? | 15:43 |
rickspencer3 | You have just created a function that you can call in the same way you call raw_input. | 15:43 |
rickspencer3 | "def" means define, as in define a function | 15:43 |
rickspencer3 | Then there is the name for your function | 15:43 |
rickspencer3 | The empty parens mean that your function can just work, it doesn't need any information | 15:43 |
rickspencer3 | raw_input needs some information to work, it needs to know what you want it to display | 15:44 |
rickspencer3 | so it has an "argument" | 15:44 |
rickspencer3 | enter_living_room has no arguments | 15:44 |
ClassBot | ARR asked: Whats better to learn now, python 3 or 2.6 ? I have heard python 3 is quite different. | 15:44 |
rickspencer3 | hmmm | 15:44 |
rickspencer3 | ARR I would stick with 2.6 for now | 15:45 |
rickspencer3 | you will need lots of samples and people to ask, etc... | 15:45 |
rickspencer3 | python 3 is not yet widely adopted | 15:45 |
rickspencer3 | also, python 3 is not supported everywhere yet | 15:45 |
rickspencer3 | others may have different opinions, though | 15:45 |
rickspencer3 | ok, so we need to call the function that we just created, shall we do that, or are there more questions now? | 15:46 |
rickspencer3 | btw, | 15:46 |
rickspencer3 | Note that lines 2-4 are indented 4 spaces. The fact that are indented under line 1, and all indented to the same level is how python knows they are part of the same function. | 15:46 |
ClassBot | immy asked: what version of python do ubuntu developers use? | 15:46 |
rickspencer3 | aah | 15:47 |
rickspencer3 | well, Ubuntu developers are comprised of folks from all over | 15:47 |
rickspencer3 | Canonical folks tend to use 2.6 | 15:47 |
rickspencer3 | so do most other Ubuntu developers | 15:47 |
rickspencer3 | let's go ahead and call the function now | 15:48 |
rickspencer3 | if command == "look door": | 15:48 |
rickspencer3 | print "The door to the house. It looks unlocked" | 15:48 |
rickspencer3 | elif command == "go door": | 15:48 |
rickspencer3 | print "You go through the door into the living room" | 15:48 |
rickspencer3 | enter_living_room() | 15:48 |
ClassBot | virkang asked: Will Lucid have Python 3 installed by default ? | 15:48 |
rickspencer3 | else: | 15:48 |
rickspencer3 | print "You can't do that here" | 15:48 |
rickspencer3 | virkang, I dunno | 15:48 |
rickspencer3 | if so, it would be in the repos by now | 15:48 |
rickspencer3 | ok, does everyone see where I added the call to our new function? | 15:49 |
rickspencer3 | Notice that line 5 is where you call the function, and that python knows to run it if the command is "go door" because it's indented. | 15:49 |
rickspencer3 | The reason that you added the function to the top of the code file is to make sure that the function got defined before you tried to use it. Here's the whole file so you can see the context: | 15:49 |
rickspencer3 | oops, never mind | 15:49 |
rickspencer3 | you can see the whole listing on the wiki | 15:49 |
rickspencer3 | https://wiki.ubuntu.com/UbuntuOpportunisticDeveloperWeek/IntroToPythonForTotalBeginners | 15:49 |
rickspencer3 | so creating and calling your own functions is a big big part of programming | 15:50 |
rickspencer3 | any questions? | 15:50 |
rickspencer3 | ok | 15:50 |
rickspencer3 | let's do a bit more with variables | 15:50 |
rickspencer3 | Let's handle looking at the lamp and getting the bulb in the living room. | 15:50 |
rickspencer3 | First, we want the player to see that there is a bulb that they can take. | 15:51 |
rickspencer3 | But if they already took the bulb, we don't want them to keep seeing the bulb right? | 15:51 |
rickspencer3 | So we handle this by creating a global variable | 15:51 |
rickspencer3 | . "global" just means that you can use the variable everywhere in the program, not just within the function where it was defined. | 15:51 |
rickspencer3 | Create a global variable at the top for your code file like this: | 15:51 |
rickspencer3 | global has_bulb | 15:51 |
rickspencer3 | has_bulb = False | 15:52 |
rickspencer3 | save your program and make sure it runs | 15:52 |
rickspencer3 | If you don't want the variable to be available everywhere in your program, just leave out line 1 | 15:53 |
rickspencer3 | but in this ase we do | 15:53 |
rickspencer3 | , we assigned the variable to be "False" | 15:53 |
rickspencer3 | note that this is False, not false ! | 15:53 |
rickspencer3 | As in, the player does not yet have the bulb, right? | 15:53 |
rickspencer3 | so we start out the program saying that the player does not have the bulb | 15:54 |
rickspencer3 | make sense? | 15:54 |
rickspencer3 | you don't have to declare variable first | 15:54 |
rickspencer3 | you just have to declare them *before* you use them | 15:54 |
ClassBot | theopensourcerer asked: so you do not have to declare variables first? | 15:54 |
rickspencer3 | theopensourcerer, so for global variable, it's easier to put them at the top | 15:54 |
rickspencer3 | also, it makes it easier to read your cod a bit | 15:55 |
rickspencer3 | If you assign a variable to be True or False, this is called a boolean, btw. You've already seen that variables can be strings. They can be numbers as well. | 15:55 |
ClassBot | Boyan23 asked: I get NameError: name 'command' is not defined? | 15:55 |
rickspencer3 | oops | 15:55 |
rickspencer3 | this sounds like you are trying to use the command variable before you've declared it | 15:56 |
rickspencer3 | we're a bit running out of time, but perhaps we can try to debug it later | 15:56 |
rickspencer3 | are other people having this same bug? | 15:56 |
rickspencer3 | ok | 15:56 |
rickspencer3 | sorry Boyan23 I promise to help you later :) | 15:57 |
=== himurake1 is now known as himura-mobile | ||
rickspencer3 | so lets use has_bulb in our enter_living_room function | 15:57 |
ClassBot | ragesoss asked: I must have missed this... on the wiki, line 5 is blank. Why? A blank line means calling the function? | 15:57 |
rickspencer3 | a blank line is just a blank line | 15:58 |
rickspencer3 | it is useful for making your code easier to read | 15:58 |
rickspencer3 | it's usually a good idea to stick a blank line in between chunks of code that are logically seperated | 15:58 |
rickspencer3 | so your code forms "chunks" that are easier to skim and read | 15:58 |
rickspencer3 | remember you will read your code 1000 times more than you will write it! | 15:59 |
rickspencer3 | readability is very important | 15:59 |
rickspencer3 | ok, where was I | 15:59 |
rickspencer3 | right | 15:59 |
rickspencer3 | command = raw_input("Enter a command:") | 15:59 |
rickspencer3 | if command == "look lamp": | 15:59 |
rickspencer3 | print "It is a floor lamp. It is not plugged in." | 15:59 |
rickspencer3 | if not has_bulb: | 15:59 |
rickspencer3 | print "There bulb looks new" | 15:59 |
rickspencer3 | enter_living_room() | 15:59 |
=== Christian is now known as Guest96614 | ||
ClassBot | ragesoss asked: thanks. for some reason, enter_living_room wouldn't run before I added that space. But I guess that wasn't the cause, and I'm not sure what was. | 16:00 |
rickspencer3 | so here I use the has bulb variable to make sure I only print the info about the bulb if the player didn't take it yet | 16:00 |
=== ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - http://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Event: Ubuntu Opportunistic Developer Week Prep - Current Session: Intro to Python for programmers - Instructor: rickspencer3 || Questions in #ubuntu-classroom-chat | ||
rickspencer3 | BUT | 16:00 |
rickspencer3 | (almost done, last thing) | 16:00 |
rickspencer3 | if you want to assign a value to has_bulb, you'll need to tell the enter_living_room() function about it | 16:01 |
rickspencer3 | def enter_living_room(): | 16:01 |
rickspencer3 | global has_bulb | 16:01 |
rickspencer3 | print "You are in the living room. There is a tv cabinet, a" | 16:01 |
rickspencer3 | print "table with some dishes, and a lamp." | 16:01 |
rickspencer3 | command = raw_input("Enter a command:") | 16:01 |
rickspencer3 | if command == "look lamp": | 16:01 |
rickspencer3 | print "It is a floor lamp. It is not plugged in." | 16:01 |
rickspencer3 | if not has_bulb: | 16:01 |
rickspencer3 | print "There bulb looks new" | 16:01 |
rickspencer3 | enter_living_room() | 16:01 |
rickspencer3 | if command == "take bulb": | 16:01 |
rickspencer3 | print "You now have a bulb" | 16:01 |
rickspencer3 | has_bulb = True | 16:01 |
rickspencer3 | enter_living_room() | 16:01 |
rickspencer3 | so notice I redeclared has_bulb as a global within the "scope" of the function | 16:01 |
rickspencer3 | also! | 16:01 |
rickspencer3 | notice that I called the function from within itself!! | 16:01 |
rickspencer3 | pretty cool, a function can call itself | 16:01 |
rickspencer3 | this keeps the program from exiting | 16:02 |
rickspencer3 | so we're two minutes over | 16:02 |
rickspencer3 | how about if you want to, you can try working on the game today/tonight, and then tomorrow if you have questions ... | 16:02 |
rickspencer3 | track me down and I can try to help | 16:02 |
rickspencer3 | maybe set up a follow up session for next week if folks want | 16:02 |
rickspencer3 | Ready for the next class? | 16:03 |
ClassBot | shift_wreck asked: could you pastebin the code? | 16:04 |
rickspencer3 | shift_wreck, (nice nick btw) - sure if the wiki doesn't work for you | 16:04 |
rickspencer3 | but doing another class now | 16:04 |
rickspencer3 | anyone here for Python for For Folks who know another language? | 16:05 |
rickspencer3 | alright then | 16:06 |
rickspencer3 | let us rock | 16:06 |
rickspencer3 | if you know me at all, you can predict that I created a wiki page and over pre-pared for the class :) | 16:06 |
rickspencer3 | https://wiki.ubuntu.com/UbuntuOpportunisticDeveloperWeek/IntroToPythonForProgrammers | 16:06 |
rickspencer3 | keep in mind - I am not a python expert | 16:06 |
rickspencer3 | sorry! | 16:06 |
rickspencer3 | but I have learned lots and lots of languages over the years | 16:07 |
rickspencer3 | so whenever I learn a new language I have to create a kind of map in my mind that maps old languages to the new one | 16:07 |
rickspencer3 | so, what I want to do is just give you a jump start by providing that mental map | 16:08 |
rickspencer3 | to me, Python is one of the "native" languages of the Ubuntu desktop | 16:09 |
rickspencer3 | because Ubuntu is a Gnome based distro | 16:09 |
rickspencer3 | it's well suited to app development and, | 16:09 |
ClassBot | dscassel asked: For me, language is lesss of an issue than environment, tooling and libraries. We'll get to that, yes? | 16:09 |
rickspencer3 | over the years I have come to love programming in Python | 16:09 |
rickspencer3 | dscassel, a bit, I'll answer your question in a moment | 16:10 |
rickspencer3 | when I first started with python it seemed weirdly terse and constrictive | 16:10 |
rickspencer3 | but now I find that my creativity really flows through the language | 16:10 |
rickspencer3 | so | 16:10 |
rickspencer3 | to dscassel question, what is python? | 16:10 |
rickspencer3 | it is a language | 16:10 |
rickspencer3 | but it is *also* a standard library | 16:11 |
rickspencer3 | it's hard to talk about one without the other | 16:11 |
rickspencer3 | so I won't try to make hard and fast distinctions here, I'll just mix it up | 16:11 |
rickspencer3 | but I put a link to the language ref and the library ref on the wiki page | 16:11 |
ClassBot | Johonunu asked: is python procedural or object oriented language ? | 16:12 |
rickspencer3 | python is also on interpreter | 16:12 |
rickspencer3 | Johonunu, yes | 16:12 |
rickspencer3 | :) | 16:12 |
rickspencer3 | Python supports both paradigms well | 16:12 |
rickspencer3 | I prefer to use the OO approach for larger programs, so I will cover that syntax near the end of this session | 16:13 |
rickspencer3 | let's rock | 16:13 |
rickspencer3 | if you type "python" into your terminal window | 16:13 |
rickspencer3 | you get the python interpreter | 16:13 |
rickspencer3 | where you can write a bit of python | 16:13 |
rickspencer3 | in samples if you see a >>> | 16:13 |
ClassBot | AdamK19 asked: what makes Python so great? any notable advantages over say, C# or Java? | 16:13 |
rickspencer3 | that means the sample was done in the "interactive shell" | 16:13 |
rickspencer3 | AdamK19, well, linguistic choices are perosnal to some degree | 16:14 |
rickspencer3 | I know C# and Java both quite well | 16:14 |
rickspencer3 | I find Python to have significantly less syntactic and semantic overhead, and easier to read other people's python code | 16:14 |
rickspencer3 | but I won't say one is "better" | 16:14 |
rickspencer3 | Python is great for Ubuntu because it is a real FOSS community language in terms of origins and the community around it | 16:15 |
rickspencer3 | so | 16:15 |
rickspencer3 | let's start with some language concepts | 16:15 |
rickspencer3 | 1. Indentation levels | 16:15 |
ClassBot | hemanth asked: market scope of python vs java ? | 16:15 |
rickspencer3 | # controls scoping instead of {}, "end", etc... | 16:15 |
rickspencer3 | # standard is to use 4 spaces for each indentation level | 16:15 |
rickspencer3 | # you will get used to it, and probably format you code this way anyway | 16:15 |
rickspencer3 | so this means that white space is meaningful in a way it is not in other languages | 16:16 |
rickspencer3 | you will have many bugs in your code from this the first few days of using python | 16:16 |
rickspencer3 | you may find you hate this at first, but you may learn to love it | 16:16 |
rickspencer3 | anyway, real programmers indent their code for readability, so you probably have this habbit already | 16:17 |
ClassBot | abgalphabet asked: python gets different implementation, is it a language spec too? | 16:17 |
rickspencer3 | for i in xrange(5,20): | 16:17 |
rickspencer3 | print i | 16:17 |
rickspencer3 | "print i" is indented 4 spaces, thus the it is within the scope of the for loop | 16:18 |
rickspencer3 | hemanth, deep question, let's talk later | 16:18 |
rickspencer3 | abgalphabet, yes | 16:18 |
ClassBot | abgalphabet asked: 4 spaces? not tab? | 16:18 |
rickspencer3 | 4 spaces! | 16:18 |
rickspencer3 | technically, the language support both, but 4 spaces is standard | 16:19 |
rickspencer3 | set your editor to do 4 spaces for tab with python, you will be much happier in the long run that way! | 16:19 |
rickspencer3 | let's talk typing real quick | 16:19 |
rickspencer3 | Python is Dynamically typed, but it is also Strongly typed | 16:19 |
rickspencer3 | >>> x = 1 | 16:20 |
rickspencer3 | >>> x | 16:20 |
rickspencer3 | 1 | 16:20 |
rickspencer3 | >>> type(x) | 16:20 |
rickspencer3 | <type 'int'> | 16:20 |
rickspencer3 | >>> x = "string" | 16:20 |
rickspencer3 | >>> x | 16:20 |
rickspencer3 | 'string' | 16:20 |
rickspencer3 | >>> type(x) | 16:20 |
rickspencer3 | <type 'str'> | 16:20 |
rickspencer3 | this shows dynamic typing | 16:20 |
rickspencer3 | x is an int just because I said it was | 16:20 |
rickspencer3 | I said it was by assigning an int to it | 16:20 |
rickspencer3 | then I changed x to be a string | 16:20 |
rickspencer3 | I did this by assigning a string to it! | 16:21 |
rickspencer3 | woah | 16:21 |
rickspencer3 | so you don't declare the type of a variable because you can change the type laer | 16:21 |
rickspencer3 | thus "dynamic" typing | 16:21 |
rickspencer3 | but unlike some other dynamically typed languages, Python is strongly typed | 16:21 |
rickspencer3 | so types are converted from one to other automatically | 16:21 |
ClassBot | kript asked: probably stupid,but how do you run code in the emulator? | 16:21 |
rickspencer3 | >>> x = 1 | 16:22 |
rickspencer3 | >>> print x + " is a string" | 16:22 |
rickspencer3 | Traceback (most recent call last): | 16:22 |
rickspencer3 | File "<stdin>", line 1, in <module> | 16:22 |
rickspencer3 | TypeError: unsupported operand type(s) for +: 'int' and 'str' | 16:22 |
rickspencer3 | kript, if you mean in the interactive shell, you just type it in | 16:22 |
rickspencer3 | it will run as blocks of code are complete | 16:22 |
rickspencer3 | also, install iPython | 16:22 |
rickspencer3 | it's an interactive shell that supports tab completion | 16:23 |
rickspencer3 | so you can inspect data structures and such as you are typing | 16:23 |
ClassBot | theopensourcerer asked: Can you enforce type so you can't change it later? | 16:23 |
rickspencer3 | theopensourcerer, not that I know of, as it is a dynamically typed language | 16:23 |
rickspencer3 | (but there may be a way I don't know about) | 16:23 |
rickspencer3 | if you are used to statically typed languages this seems weirdly dangerous | 16:24 |
rickspencer3 | but after a while static typing will seem like unneceesary programing overhead | 16:24 |
rickspencer3 | ok, so moving on | 16:24 |
rickspencer3 | since it is a strongly typed language, there are types | 16:24 |
rickspencer3 | it's easy to look up the types, so I won't bore you with details here | 16:25 |
rickspencer3 | but here is some info to get your mental map started | 16:25 |
rickspencer3 | there are numeric types | 16:25 |
rickspencer3 | Integer, Long Integer, Float, Complex | 16:25 |
ClassBot | AdamK19 asked: does python have something like c# interfaces (and if, how dose it fit with dynamic types) | 16:25 |
rickspencer3 | AdamK19, no | 16:25 |
rickspencer3 | interfaces are necessary for strongly typed languages | 16:25 |
rickspencer3 | because you want different implementations to be callable, right? | 16:26 |
rickspencer3 | so in Python, you just add the members to your class that will be needed by the caller | 16:26 |
rickspencer3 | however, Python does have multiple inheritance, so you can do interface like things, but include a default implementation | 16:26 |
rickspencer3 | (at least that's the way I understand it) | 16:27 |
rickspencer3 | ok so one thing abut numeric types is that you can mix em up in your math | 16:27 |
rickspencer3 | the result will always be the least restrictive type | 16:27 |
rickspencer3 | so if you add an in to a float, the result will be a float | 16:28 |
ClassBot | m_anish asked: Is there a way to declare constant variables like we do in C/C++ | 16:28 |
rickspencer3 | if you want the result to be an int, you can conver it to an int like this: | 16:28 |
rickspencer3 | x = int(x) | 16:28 |
rickspencer3 | m_anish, I don't know for sure | 16:28 |
rickspencer3 | there is a convention to use all caps | 16:28 |
rickspencer3 | MY_CONSTANT_VARIABLE = "foo" | 16:29 |
rickspencer3 | but I don't know that the language can enforce immutability | 16:29 |
rickspencer3 | sorry | 16:29 |
rickspencer3 | moving on | 16:29 |
rickspencer3 | a quick word on string | 16:29 |
rickspencer3 | strings are highly functional in Python | 16:29 |
rickspencer3 | this is an example of where the line between language and library is nicely blurred | 16:30 |
rickspencer3 | note that there is no "character" type | 16:31 |
rickspencer3 | you can concat with "+" and stuff like that | 16:31 |
ClassBot | malev asked: capitals does not make a variable inmutable, sorry | 16:31 |
rickspencer3 | and you get "foo".endswith("o"), etc... for free | 16:31 |
rickspencer3 | you can use " or ' to surround your string | 16:31 |
rickspencer3 | malev, no, it's just a convention | 16:31 |
rickspencer3 | so when people read your code, they think "ah, all caps, the author believes this should not change" | 16:32 |
ClassBot | abgalphabet asked: is python case-sensitive | 16:32 |
rickspencer3 | abgalphabet, yes | 16:32 |
rickspencer3 | so more on types | 16:32 |
rickspencer3 | there is an object called None | 16:32 |
rickspencer3 | it is of the type NoneType | 16:32 |
rickspencer3 | it;s kind of like null | 16:33 |
rickspencer3 | None is an instance of NoneType | 16:33 |
rickspencer3 | undeclared variables *are not* None, they are just undeclared | 16:33 |
rickspencer3 | so you can't do: | 16:33 |
rickspencer3 | if foo is not None: | 16:33 |
rickspencer3 | #do something | 16:33 |
rickspencer3 | to test if foo is declared | 16:33 |
rickspencer3 | that will be an error | 16:34 |
rickspencer3 | ok | 16:34 |
rickspencer3 | so python has three types are very feature rich | 16:34 |
rickspencer3 | Lists, Tuples, and Dictionaries | 16:35 |
rickspencer3 | lists and tuples are kind of like arrays in other languages | 16:35 |
rickspencer3 | but they aren't typed | 16:35 |
rickspencer3 | ! | 16:35 |
rickspencer3 | it would be like an array of Objects in C# or java | 16:35 |
rickspencer3 | by "not typed", I mean, this is fine: | 16:35 |
rickspencer3 | my_tuple = (1,"one",False) | 16:35 |
rickspencer3 | you can mix up types in them | 16:36 |
rickspencer3 | very cool | 16:36 |
rickspencer3 | the main difference between tuples and lists is that tuple are immutable | 16:36 |
rickspencer3 | this makes them a bit faster to iterate and stuff like that | 16:36 |
rickspencer3 | also keeps other parts of your program from messing with them | 16:36 |
ClassBot | mcphargus asked: I'm unclear on the immutability of tuples, can you add or remove from a tuple? or just not change the objects in the tuple? | 16:37 |
rickspencer3 | mcphargus, nope | 16:37 |
rickspencer3 | you cannot add or remove items from a tuple | 16:37 |
rickspencer3 | I assume that you can change an object that is in a tuple from outside of tuple | 16:38 |
rickspencer3 | but I'm not 100% certain | 16:38 |
rickspencer3 | I use tuple for stuff like this: | 16:38 |
rickspencer3 | >>> wintermonths = ("December","January","February") | 16:38 |
rickspencer3 | >>> wintermonths | 16:38 |
rickspencer3 | ('December', 'January', 'February') | 16:38 |
rickspencer3 | like I know I won't change that list, I care about the order, and I'll be iterating it | 16:38 |
* rickspencer3 tries changing a value in a tuple | 16:39 | |
rickspencer3 | >>> foo = "boo" | 16:39 |
rickspencer3 | >>> t = (1, foo) | 16:39 |
rickspencer3 | >>> t | 16:39 |
rickspencer3 | (1, 'boo') | 16:39 |
rickspencer3 | >>> foo = "baz" | 16:39 |
rickspencer3 | >>> t | 16:39 |
rickspencer3 | (1, 'boo') | 16:39 |
rickspencer3 | >>> | 16:39 |
rickspencer3 | immutable :) | 16:39 |
rickspencer3 | tuple are created with () | 16:40 |
rickspencer3 | lists with [] | 16:40 |
rickspencer3 | >>> grades = ["A","A-","B","C"] | 16:40 |
rickspencer3 | >>> grades | 16:40 |
rickspencer3 | ['A', 'A-', 'B', 'C'] | 16:40 |
rickspencer3 | you index lists and tuples with [] as in most languages | 16:40 |
rickspencer3 | >>> wintermonths | 16:41 |
rickspencer3 | ('December', 'January', 'February') | 16:41 |
rickspencer3 | >>> wintermonths[0] | 16:41 |
rickspencer3 | 'December' | 16:41 |
rickspencer3 | one sweet thing is that you can start from the back! | 16:41 |
rickspencer3 | >>> grades | 16:41 |
rickspencer3 | ['A', 'A-', 'B', 'C'] | 16:41 |
rickspencer3 | >>> grades[-1] | 16:41 |
rickspencer3 | 'C' | 16:41 |
rickspencer3 | >>> grades[-2] | 16:41 |
rickspencer3 | 'B' | 16:41 |
rickspencer3 | getting the last item in a list or tuple is so easy | 16:41 |
rickspencer3 | to test if a list or tuple (or dictionary for that matter) contains a value (or key for a dictionary), use "in" | 16:42 |
rickspencer3 | it's sweet" | 16:42 |
rickspencer3 | >>> grades = ["A","A-","B","C"] | 16:42 |
rickspencer3 | >>> grades | 16:42 |
rickspencer3 | ['A', 'A-', 'B', 'C'] | 16:42 |
rickspencer3 | >>> "A" in grades | 16:42 |
rickspencer3 | True | 16:42 |
rickspencer3 | >>> "F" in grades | 16:42 |
rickspencer3 | False | 16:42 |
ClassBot | hemanth asked: how immutability increases speed in iterations ? | 16:42 |
rickspencer3 | hemanth, I have no idea, I assume it's implementation specific | 16:43 |
rickspencer3 | sorry | 16:43 |
rickspencer3 | so, let's move on to dictionaries | 16:43 |
rickspencer3 | these are really common to use in Python and save tons and tons of time and code | 16:43 |
rickspencer3 | a dictionary is basically a hash table, but it's built into the langauge | 16:43 |
ClassBot | virkang asked: So, you could use a tuple with length 1 to make a constant variable, right ? Is that used like that in practice ? | 16:44 |
rickspencer3 | virkang, I suppose | 16:44 |
rickspencer3 | this has never been something that I cared to do in a Python program | 16:44 |
rickspencer3 | there may be other experts that could better answer that for you | 16:44 |
rickspencer3 | like I say, I'm not a Python expert, I just know lots of languages ;) | 16:44 |
rickspencer3 | so moving on to dictionaries: | 16:45 |
rickspencer3 | >>> grades = {"English":"D","Math":"A-","History":"C+"} | 16:45 |
rickspencer3 | >>> grades | 16:45 |
rickspencer3 | {'History': 'C+', 'Math': 'A-', 'English': 'D'} | 16:45 |
rickspencer3 | using {} you can easily create a dictionary | 16:46 |
rickspencer3 | again, they don't require certain types to be used for keys and values | 16:46 |
rickspencer3 | though some types can't be used for keys | 16:46 |
rickspencer3 | like you can't use a dictionary to be a key in another dictionary | 16:46 |
ClassBot | hemanth asked: i was unclear when you said "this makes them a bit faster to iterate and stuff like that" | 16:46 |
rickspencer3 | hemanth, well, if you don't need to change the contents of a list, you can get some slight speed boosts in your code by using a tuple | 16:47 |
rickspencer3 | because it won't have to support "append" and all this | 16:47 |
rickspencer3 | so it can be optimized inside the Python run time | 16:47 |
rickspencer3 | at least that's what I think | 16:47 |
rickspencer3 | so, dictionaries | 16:48 |
rickspencer3 | use 'em, love 'em | 16:48 |
rickspencer3 | looks like I screwed up the wiki a but | 16:48 |
rickspencer3 | a bit, even | 16:48 |
rickspencer3 | I'll add the dictionary stuff in later today | 16:48 |
ClassBot | theopensourcerer asked: So a dictionary is like an associative array? | 16:48 |
rickspencer3 | Note that dictionaries don't store their items in any particular order, so indexing into them with [] and some integer doesn't work. You must use [] with a key. | 16:48 |
rickspencer3 | >>> grades | 16:49 |
rickspencer3 | {'History': 'C+', 'Math': 'A-', 'English': 'D'} | 16:49 |
rickspencer3 | >>> grades["History"] | 16:49 |
rickspencer3 | 'C+' | 16:49 |
rickspencer3 | To change the value associated with a key, simply reassign to the indexed key: | 16:49 |
rickspencer3 | >>> grades | 16:49 |
rickspencer3 | {'History': 'C+', 'Math': 'A-', 'English': 'D'} | 16:49 |
rickspencer3 | >>> grades["History"] = "B-" | 16:49 |
rickspencer3 | >>> grades | 16:49 |
rickspencer3 | {'History': 'B-', 'Math': 'A-', 'English': 'D'} | 16:49 |
rickspencer3 | You can add a key/value pair the exact same way: | 16:49 |
rickspencer3 | >>> grades | 16:49 |
rickspencer3 | {'History': 'B-', 'Math': 'A-', 'English': 'D'} | 16:49 |
rickspencer3 | >>> grades["Gym"] = "F" | 16:49 |
rickspencer3 | >>> grades | 16:49 |
rickspencer3 | {'Gym': 'F', 'History': 'B-', 'Math': 'A-', 'English': 'D'} | 16:49 |
rickspencer3 | To delete a key/value pair, use the global del() function: | 16:49 |
rickspencer3 | >>> grades | 16:49 |
rickspencer3 | {'Gym': 'F', 'History': 'B-', 'Math': 'A-', 'English': 'D'} | 16:49 |
rickspencer3 | >>> del(grades["English"]) | 16:49 |
rickspencer3 | >>> grades | 16:49 |
rickspencer3 | {'Gym': 'F', 'History': 'B-', 'Math': 'A-'} | 16:50 |
rickspencer3 | You can retrieve all the keys from a dictionary using the "keys()" function, and all of the values using the values() functions. To retrieve all of the key/value pairs as a list of tuples, use items(). | 16:50 |
rickspencer3 | >>> grades | 16:50 |
rickspencer3 | {'Gym': 'F', 'History': 'B-', 'Math': 'A-'} | 16:50 |
rickspencer3 | >>> grades.keys() | 16:50 |
rickspencer3 | ['Gym', 'History', 'Math'] | 16:50 |
rickspencer3 | >>> grades.values() | 16:50 |
rickspencer3 | ['F', 'B-', 'A-'] | 16:50 |
rickspencer3 | >>> grades.items() | 16:50 |
rickspencer3 | [('Gym', 'F'), ('History', 'B-'), ('Math', 'A-')] | 16:50 |
rickspencer3 | to see if a dictionary has a certain key, don't look in keys, just look in the dictionary | 16:50 |
rickspencer3 | so you go: | 16:50 |
rickspencer3 | if Gym in grades: | 16:50 |
rickspencer3 | #do something | 16:50 |
rickspencer3 | Remember that a dictionary does not store items in any particular order, so the list of tuples returned by items() may not be in the order that items were created. | 16:50 |
rickspencer3 | never count on a dictionary having anything in a particular order! | 16:51 |
ClassBot | abgalphabet asked: dictionary created by {}? | 16:51 |
rickspencer3 | abgalphabet, right | 16:51 |
rickspencer3 | very similar to json | 16:51 |
ClassBot | theopensourcerer asked: Can you have multi-dimension dictionaries? | 16:51 |
rickspencer3 | also like jason, a list is defied with[] | 16:51 |
rickspencer3 | theopensourcerer, yes, a dictionary can be a value in another dictionary, but it can not be a key in another dictionary | 16:52 |
rickspencer3 | let's skip to OO syntax since someone asked about that at the beginning, and I only have 7 minutes | 16:53 |
rickspencer3 | sound ok? | 16:53 |
rickspencer3 | if I wanted to define a class called "program2" I do it like this: | 16:54 |
rickspencer3 | class program2: | 16:54 |
ClassBot | wharp asked: grades and grades.items() produce the same output, is there a difference? | 16:54 |
rickspencer3 | if I want program3 to derive from program2, I do it like this | 16:54 |
rickspencer3 | wharp. that's just because of what would be the to_string() funciton in other languages | 16:54 |
rickspencer3 | in the interactive interperted when you just type a variable, it tries to print something sensible for you to read | 16:55 |
rickspencer3 | in a program grades and grades.items() are very different | 16:55 |
rickspencer3 | grades is the dictionary, grades.items() returns a list of the values | 16:55 |
rickspencer3 | so, back to classes real quick | 16:56 |
rickspencer3 | a couple of points I want to touch on | 16:56 |
rickspencer3 | before we break | 16:56 |
rickspencer3 | __init__(self): | 16:56 |
rickspencer3 | this is a function that is more or less the constructor for a class | 16:56 |
rickspencer3 | it is optional | 16:56 |
rickspencer3 | unless your super class has one, your subclass has to call the super class's __init__() at some point | 16:57 |
rickspencer3 | finally, a point about private members | 16:57 |
rickspencer3 | this is a bit odd in Python | 16:57 |
rickspencer3 | *there are no private members in Python* | 16:57 |
rickspencer3 | this badly breaks encapsulation | 16:58 |
rickspencer3 | however, there are two ways around this | 16:58 |
rickspencer3 | if you want a private member that you want to be available to subclasses | 16:58 |
rickspencer3 | use a single underscore to start the variable name | 16:58 |
rickspencer3 | so: | 16:58 |
rickspencer3 | self._private | 16:59 |
rickspencer3 | it's not really private, but the underscore is a convention | 16:59 |
rickspencer3 | if you don't want it to be accessible to sub classes, use two underscores | 16:59 |
rickspencer3 | self.__my_very_private | 16:59 |
rickspencer3 | python will "munge" the variable name at run time | 17:00 |
rickspencer3 | so it won't be accessible | 17:00 |
rickspencer3 | well, it kind of will be, but it's harder for other programmers to get at it | 17:00 |
rickspencer3 | ok, I am out of time :/ | 17:00 |
rickspencer3 | sorry, there was more I wanted to go into | 17:00 |
cjohnston | more classes! | 17:00 |
rickspencer3 | I would stay, but I have to run to a meeting | 17:01 |
rickspencer3 | please let jono know if you would like more or a follow up or something | 17:01 |
rickspencer3 | also, #ubuntu-all-devel is a good place for questions | 17:01 |
cjohnston | #ubuntu-app-devel | 17:01 |
rickspencer3 | oops | 17:01 |
rickspencer3 | sorry, typing and calling :/ | 17:01 |
=== ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - http://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi | ||
jakiw_ | Whats the coming version of Ubuntu called? | 17:05 |
thekorn | lucid | 17:05 |
jakiw_ | Will it be 9.14? | 17:06 |
cjohnston | 10.04 | 17:06 |
cjohnston | YY.MM | 17:06 |
jakiw_ | Is it really Year and Month??? | 17:06 |
Pendulum | yes | 17:06 |
abhi_nav | what is ubuntu-classroom? | 17:07 |
jakiw_ | So 10.04 hasnt to be a new OS, just a new version of 9.04? | 17:07 |
cjohnston | the next version.. after 9.10 | 17:07 |
binti_ | can i re run the python class ? | 17:07 |
abhi_nav | !ubuntu-classroom | 17:07 |
cjohnston | binti_: you mean the logs | 17:08 |
cjohnston | ? | 17:08 |
binti_ | yes | 17:08 |
cjohnston | abhi_nav: a place for teaching classess | 17:08 |
cjohnston | binti_: irclogs.ubuntu.com | 17:08 |
abhi_nav | place for teaching Ubuntu? | 17:08 |
abhi_nav | cjohnston: place for teaching Ubuntu? | 17:08 |
jakiw_ | So how do I see if an OS is just a new Version or a whole new OS (Like Mac OS 10.4 and 10.5) | 17:08 |
cjohnston | abhi_nav: ubuntu, programming, other stuff | 17:08 |
binti_ | thanks ! for the log link | 17:09 |
jakiw_ | And when/how do u teach here_ | 17:09 |
cjohnston | windows 7 is a new version of windows... 10.5 is a new version of osx.... | 17:09 |
RainCT | jakiw_: there is no "new OS", just new releases every 6 months | 17:09 |
abhi_nav | cjohnston: How #ubuntu-classroom is different from #ubuntu? | 17:09 |
cjohnston | jakiw_: look at the link in the topic | 17:09 |
cjohnston | abhi_nav: #ubuntu is a support channel | 17:10 |
MustafaAli | sorry guys I missed the class | 17:10 |
cjohnston | this isnt a support channel | 17:10 |
cjohnston | MustafaAli: get it on the logs. :-) | 17:10 |
RainCT | abhi_nav: #ubuntu is for asking all sorts of questions, this channel is for scheduled sessions with someone teaching some topic related to Ubuntu | 17:10 |
abhi_nav | cjohnston: so I cannt ask question here, I just have to enroll in the current running class? Is class timings are defined? | 17:11 |
MustafaAli | could you please tell me how | 17:11 |
cjohnston | MustafaAli: irclogs.ubuntu.com | 17:11 |
abhi_nav | cjohnston: and RainCT so I cannt ask question here, I just have to enroll in the current running class? Is class timings are defined? | 17:11 |
RainCT | abhi_nav: Yeah. (You can only ask questions about the running class, in #ubuntu-classroom-chat) | 17:11 |
cjohnston | abhi_nav: if you need support help you need to go to #ubuntu... there are classes scheduled here.. that you can attend.. and ask relevant questions to the class | 17:11 |
MustafaAli | thanks for help | 17:11 |
RainCT | And the schedule for the next classes should be somewhere on the wiki | 17:12 |
cjohnston | MustafaAli: yup | 17:12 |
abhi_nav | RainCT: how to get the class schedule? | 17:12 |
cjohnston | abhi_nav: the link in the topic | 17:12 |
abhi_nav | !topic | 17:13 |
ubottu | Please read the channel topic whenever you enter, as it contains important information. To view it at any time after joining, simply type /topic | 17:13 |
abhi_nav | and what about time zones? | 17:13 |
abhi_nav | I am from India | 17:13 |
binti_ | !topic | 17:14 |
ubottu | Please read the channel topic whenever you enter, as it contains important information. To view it at any time after joining, simply type /topic | 17:14 |
cjohnston | all times are in UTC | 17:14 |
abhi_nav | then how to know that what that time means India? | 17:14 |
abhi_nav | India is GMT +5.30 | 17:14 |
cjohnston | run date -u in the command line | 17:15 |
hemanth | abhi_nav, date -u | 17:15 |
abhi_nav | date -u | 17:15 |
cjohnston | this isnt the command line | 17:15 |
angvp | lol | 17:15 |
hemanth | abhi_nav, Thu Feb 25 17:15:16 UTC 2010 | 17:16 |
abhi_nav | ok. | 17:16 |
abhi_nav | UTC uses 24 hours clock? | 17:16 |
cjohnston | yes | 17:16 |
abhi_nav | ok | 17:16 |
abhi_nav | thnx | 17:16 |
cjohnston | !support | 17:16 |
ubottu | The official ubuntu support channel is #ubuntu. Also see http://ubuntu.com/support and http://ubuntuforums.org | 17:16 |
abhi_nav | yah i know ok | 17:16 |
abhi_nav | thnx | 17:16 |
cjohnston | i was testing | 17:16 |
abhi_nav | ok | 17:17 |
hemanth | ha ha | 17:17 |
abhi_nav | :) | 17:17 |
hemanth | date -u +'%I.%M.%S' get it in 0..12 hrs clock | 17:21 |
jakiw_ | Damned, I passed the python class today :D | 17:31 |
binti_ | irclogs.ubuntu.com 25 feb | 17:32 |
=== Micke is now known as Guest6888 | ||
=== digitteknohippie is now known as Digit_away | ||
=== Digit_away is now known as digitteknohippie | ||
=== zen is now known as Guest83419 | ||
=== verilium is now known as verilium|only_pr | ||
Torikun1 | oi | 18:52 |
=== per is now known as Guest77747 | ||
=== yofel_ is now known as yofel | ||
=== Micke is now known as Guest92152 | ||
timbury | Hi, all. Are we waiting for Rick to start? | 21:16 |
pleia2 | timbury: that was several hours ago | 21:18 |
pleia2 | logs are here: http://irclogs.ubuntu.com/2010/02/25/%23ubuntu-classroom.html | 21:18 |
timbury | Thanks, pleia2. I missed the UTC, I think. ;) | 21:19 |
pleia2 | I figured, it happens :) | 21:19 |
timbury | bye. | 21:19 |
=== asd is now known as Guest18442 | ||
=== nhandler_ is now known as nhandler | ||
=== Pendulum_ is now known as Pendulum |
Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!