=== kermiac_ is now known as kermiac
=== kermiac is now known as kermiac_
=== gator is now known as Guest97081
=== kermiac_ is now known as kermiac
=== pd is now known as Guest76958
=== me is now known as Guest6622
leoquantcan someone make an announcement on top of this channel for a live session this Saturday? Ref.: https://wiki.ubuntu.com/Packaging/Training10:23
persialeoquant: What'S the subject for Saturday?10:25
persialeoquant: Shouldn't it rather be added to http://people.ubuntu.com/~nhandler/classroom.html ?10:26
qensepersia: "How to effectively use a PPA and providing updated package"10:26
* persia pokes nhandler10:26
qenseby Rohan Garg and rowinggolfer at 17.00 UTC10:26
leoquantqense indeed10:26
persialeoquant: In fact, you probably want to get nhandler to list all your Packaging/Training topics (as they are scheduled).10:27
persiaI think ClassBot will then do the right thing.10:27
persiaCool.  That does work.  But I still don't really want to change the /topic unless there's no other option.10:28
leoquantpersia i am ask to fix this as soon as possible10:29
persialeoquant: fix which?10:30
persiaWas the class previously scheduled for now?10:30
leoquantthe annoucement persia10:30
persiaOh, to make the announcement for the event?10:31
persiaAh, go ahead and announce it then.10:31
persianhandler should be around in a few hours, and can add it to the schedule.10:31
=== JOAKO is now known as Guest41411
=== Guest41411 is now known as JOAKO[ARG]
joakodlzEmilse-Paez hi!13:10
=== Jan is now known as Guest7818
=== gator is now known as Guest4606
cjohnstonleoquant: persia qense I need the instructors nicks please13:46
persiacjohnston: For the upcoming event?13:46
persialeoquant: ^^13:46
qenseI don't know their nicks, I was just asked if I was interested in helping with translating the session.13:47
cjohnstonCould someone find out please... I need their nicks to be able to schedule it13:48
qenseI'll try if I can find it out.13:48
persiaqense: What are the names again?13:48
persiaOr if you're looking lp.net/people might help :)13:48
qensepersia: Rohan Garg and rowinggolfer13:49
qensethe second session is done by persia himself13:49
persiaThe 4th, right?13:49
qensepersia: the second13:49
persiaRohan Garg is shadeslayer13:50
qenseI find these two people on LP: rohangarg13:50
qenseand rowinggolfer13:50
persiaqense: The 2nd?  I'm *really* busy on the 2nd.  Are you sure?13:50
qensepersia: ah, date13:50
qenseindeed, the 4th13:50
qenseright in the middle of the UODW13:50
persiaNeil Wallace is rowinggolfer13:50
persiaBut at a sane time of day when nobody is ranting about upstream coding :)13:51
qense6 UTC sane!13:51
qenseThe only reason I'm awake at that time is because I have to cycle to school! :P13:51
cjohnstonqense: so its rowinggolfer and shadeslayer ?13:52
qensecjohnston: indeed, like persia said13:52
bintiah i dont have to register my nick?13:52
persiabinti: Depends what you're trying to do :)13:53
bintiregistering my nick..., didn't work13:53
qenseI would recommend anyone who's often on IRC to register his or her nick.13:53
cjohnstonfwiw, the timedate link on the first class for packaging training is wrong13:54
cjohnstonthe two classess have been added to the training calendar13:56
qensecjohnston: 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 schedule13:57
persiacjohnston: Thanks!13:57
cjohnstonsure are qense13:59
qensecjohnston: good!13:59
bintimy first classroom in 27 years and xchat hangs14:17
bintianyone else working with loqui ?14:19
=== lukjad007 is now known as lukjad86
=== jubesz is now known as Guest51540
bintifixed, the problem was gnome xchat14:27
=== jubesz_2nd is now known as jubesz
=== Jan is now known as Guest3397
binti_python class in 2 hours ?14:55
hemanthin 5mins14:55
molokmore like 5 mins14:55
binti_:) thanks14:55
rickspencer3is anyone here?14:59
cjohnstonno.. im here14:59
cjohnstonat my house14:59
cjohnstonI dont know where you are14:59
cjohnstonLets see if she works14:59
rickspencer3I am in Seattle, and I am about to try to introduce the notion of programming in Python to folks who haven't programmed before15:00
rickspencer3and I am really pumped15:00
rickspencer3cjohnston, so I just go?15:00
rickspencer3is there fanfare?15:00
cjohnstonI'm wondering why ClassBot isnt setting things up15:00
rickspencer3trumpets, red carpet, curtain pulled back?15:00
Pendulumrickspencer3: well we can pull them out if you really want, but we're a bit lazy ;)15:01
rickspencer3Pendulum, yes, I require fanfare15:01
cjohnstonrickspencer3: go ahead and start.. ill work on classbot15:01
rickspencer3cjohnston, thanks15:01
rickspencer3so, I guess if I ask things here, people answer in #ubuntu-classroom-chat, right?15:01
rickspencer3so first, everyone who is here doesn't know a programming language yet, but is interested in getting started right?15:02
NVSBLmonstrMore or less15:02
* CaptainHero too15:02
cjohnstonthere you go.. sorry15:05
rickspencer3due to my compulsive personality, I found it necessary to more or less write out the class first15:05
rickspencer3so you can follow along there if it helps15:05
rickspencer3what I hope to do in the next hour is to give you a taste of programming and how Python works15:05
rickspencer3so that you can go off and start really learning it15:05
rickspencer3so, when I was a boy, the line between using a computer and programming it were a bit blurry15:06
rickspencer3you had a computer, and to use a program you got a listing of the program printed it out, and you typed in the source yourself15:06
rickspencer3typically using Basic (an early and pretty easy language)15:07
rickspencer3so I wrote an "adventure game" for my first program15:07
rickspencer3one of those text adventures where you go north, look in the gave, put the bird in the cage, etc...15:07
rickspencer3does everyone know what I mean?15:07
rickspencer3so we'll start making one in this session15:08
rickspencer3but first, a few things about a program15:08
rickspencer3a program is just a series of instructions that you type out for the computer to follow15:08
rickspencer3computers are not smart at all15:08
rickspencer3they are just very very obedient, and they can count really fast15:09
rickspencer3this means that if you have a small error in what you type, the computer gets confused15:09
rickspencer3like if I was "seattle" instead of "Seattle" any human can cope with that error15:09
rickspencer3but to a computer, those two words are totally different, and the program will choke15:09
rickspencer3(for the record that is called "case sensitivity")15:10
rickspencer3so that's an example of how really stupid computers are15:10
rickspencer3any questions before we start working on the game?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
rickspencer3ok, let's start them15:10
rickspencer3it's a good idea usually to sketch out what your program will do sometimes15:11
rickspencer3so I designed the game, and there is a picture of it on the wiki15:11
rickspencer3basically, the player has to get the fork and the bulb from the living room ...15:12
rickspencer3go to the kitchen, stick the fork in the toaster which will cause the bulb to light up ...15:12
rickspencer3so they can see in the pantry, where they win15:12
rickspencer3so let's get ready to write the program15:12
rickspencer3open up your text editor, probably gedit, and save a blank file15:13
rickspencer3I called it "prize_hunt.py"15:13
rickspencer3it 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
rickspencer3you also need a terminal window open15:13
rickspencer3the terminal should be in the same directory where you saved the file15:14
rickspencer3I'll give folks a moment to get that set up15:14
rickspencer3let me know when I should move on15:14
rickspencer3any questions?15:14
rickspencer3let's write some code!!15:15
rickspencer3this is the fun part :)15:15
rickspencer3let's start by making the computer say things to player15:15
rickspencer3in Python we do that with a command called "print"15:15
rickspencer3it doesn't print to the printer, it prints to console15:15
rickspencer3's my first line:15:15
rickspencer3print "You are outside the front door of the house. The prize is inside."15:15
rickspencer3that's the first line of the file15:16
rickspencer3save it15:16
rickspencer3now we need to run the program15:16
rickspencer3(it's very important to save the file!)15:16
rickspencer3we run the program with the terminal by telling python to run it:15:16
rickspencer3$python prize_hunt.py15:17
rickspencer3python prize_hunt.py15:17
rickspencer3the "$" is just a convention to show you type it on the terminal15:17
rickspencer3is ti working for everyone?15:17
rickspencer3you just wrote a program!15:17
rickspencer3believe it or not, that's pretty much all there is to it15:17
rickspencer3from here on out it's just refining that basic idea15:18
rickspencer3we probably want to tell the player some  more stuff15:18
rickspencer3so let's add some more printing to our program to get started15:18
rickspencer3print "You can enter commands to do stuff"15:19
rickspencer3print "The commands are go, look, take, use, and put"15:19
rickspencer3print "Use commands with objects that you see around"15:19
rickspencer3print "For example, you can enter 'look door'"15:19
rickspencer3just add those lines and run it15:19
rickspencer3(or similar, it's your game after all_15:19
rickspencer3any questions?15:19
rickspencer3is it working?15:19
rickspencer3save and run again to make sure it's working15:19
rickspencer3ok, great15:20
=== stevefed5291_ is now known as stevefed5291
rickspencer3so let's move on15:20
rickspencer3we can tell the player stuff, so now let's let the player tell us stuff15:20
rickspencer3this will introduce two basic concepts that you will use over and over and over again in programming15:20
rickspencer3using a variable, and calling a function15:20
ClassBothemanth asked: how to decide on the quotes?15:20
rickspencer3can you explain the question a little more?15:21
rickspencer3is this about using " versus ' ?15:21
ClassBothemanth asked: yes "" ' '15:21
rickspencer3so ...15:22
rickspencer3a string is a collection of characters15:22
rickspencer3surrounded by either " or '15:22
rickspencer3in python yu can choose eiher15:22
rickspencer3I prefer " most of the time15:22
rickspencer3so, moving on15:23
rickspencer3let's get some user input15:23
rickspencer3if command == "look door":15:23
=== pd is now known as Guest66583
rickspencer3wrong line15:23
rickspencer3command = raw_input("Enter a command:")15:23
rickspencer3ok, that's the correct one15:23
rickspencer3add this to your program and run it15:23
rickspencer3"command" is a variable15:24
rickspencer3a variable is a word that you use in your program that is kind of a container for values15:24
rickspencer3specifically values that can *vary* depending on what the program does15:24
rickspencer3"command" is a variable that will store the results of "raw_input"15:25
rickspencer3raw_input is a function15:25
rickspencer3You "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
rickspencer3Some 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
rickspencer3this is a bit to digest, but using it may help you understand15:26
rickspencer3is everyone's program running?15:26
ClassBotliemily asked: Does raw_input expect anything other than carriage return?15:26
=== B is now known as Guest81195
rickspencer3raw_input expects a string to be typed into the console15:27
rickspencer3ended with a carriage return15:27
rickspencer3but the carriage return is not added to the string15:27
ClassBothemanth asked: why is raw_input called so? cos it's bound to any data type when read?15:27
rickspencer3raw_input will be a string15:27
rickspencer3'T use input()15:27
rickspencer3input is weird, it tries to interpret what is given to is as Python code, so weird stuff can happen15:28
rickspencer3so you get a string from raw_input() and it's easy to work with that way15:28
rickspencer3so are folks getting raw_input to work in the console?15:29
rickspencer3shall we go ahead and actually use the provided input?15:29
ClassBotJohonunu asked: are there types of variable like int,double,... or there is single one like in php ?15:29
rickspencer3Johonunu, yes15:29
rickspencer3but you can set a variable to any type15:29
rickspencer3if you know another language already, the next session might be good, as I will15:30
rickspencer3help you make a map from your current language to Python15:30
rickspencer3this class assumes zero programming experience15:30
rickspencer3let's go ahead and look at the user input15:31
ClassBotm_anish asked: Can raw_input be made to accept multiple lines, and special ASCII characters15:31
rickspencer3m_anish, I have never done that, so I don't know15:31
rickspencer3I assume you could add "\n" to add a carriage return15:31
rickspencer3might be something fun for you to test out!15:32
rickspencer3shall we move on to using the input?15:32
rickspencer3this next block will introduce a couple of concepts15:33
rickspencer3add this to your program15:33
rickspencer3if command == "look door":15:33
rickspencer3    print "The door to the house. It looks unlocked"15:33
rickspencer3elif command == "go door":15:33
rickspencer3    print "You go through the door into the living room"15:33
rickspencer3    print "You can't do that here"15:33
rickspencer3can 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
rickspencer3Typically, programmers will read this as "if command equals 'go door'".15:34
rickspencer3The 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
rickspencer3Note 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
rickspencer3let me know when you've tried this out, and what questions you might have15:35
rickspencer3Line 3 says "elif" to start. elif is read "else if"15:36
rickspencer3The "else" is important, because if the user did type in "look door", you just want to run the code for that condition.15:36
ClassBotvirtuald_ asked: can't i use a tab for indentation?15:36
rickspencer3virtuald_ yes15:36
rickspencer3BUT don't15:36
rickspencer3it's best to set gedit to use spaces for tabs and to use four spaces for the tabs15:37
rickspencer3while the language permits other indentation schemes, the Python programmers of the world have agreed on 4 spaces for a tab15:37
ClassBotstevefed529192 asked: I know you can use tabs for indentation as well, is there any reason one would opt for spaces over tabs?15:37
rickspencer3you can't tell the difference between spaces and tabs in most editors15:37
rickspencer3if we don't all do it the same way, we will go crazy trying to read each other's code15:38
ClassBotdeegee asked: is it a must to have 4 spaces of indentation?15:38
rickspencer3also, when your programs get big, you might find it's easy to read that way15:38
rickspencer3deegee, again, technically you can use any number of spaces, but your life will be easier if you go with the standard15:39
rickspencer3a lot of my early python programs I used 1 space instead of 415:39
rickspencer3I regret it now15:39
rickspencer3ok, is this new code making sense to folks?15:39
=== jcsims is now known as Guest56648
rickspencer3btw, this is called "conditional branching" and is one of the key concepts in programming15:40
rickspencer3So you may notice that whatever happens, you code ends after testing the conditions.15:40
rickspencer3not a very fun game15:41
rickspencer3Really what you want is your code to branch off and do stuff depending on what happened.15:41
rickspencer3you probably want some code to handle the situation of the user going into the living room15:41
rickspencer3They key thing to think about is that you want your code to "do something"15:41
rickspencer3Sounds like it could use a function. So you can make your own function for entering the living room.15:41
rickspencer3here's the code for a new function to put at the top of your code file:15:42
rickspencer3def 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
rickspencer3this needs to go at the top for reasons that will be clear soon15:42
rickspencer3save the file and make sure your program still runs15:42
rickspencer3still working for everyone?15:43
rickspencer3You 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 function15:43
rickspencer3Then there is the name for your function15:43
rickspencer3The empty parens mean that your function can just work, it doesn't need any information15:43
rickspencer3raw_input needs some information to work, it needs to know what you want it to display15:44
rickspencer3so it has an "argument"15:44
rickspencer3enter_living_room has no arguments15:44
ClassBotARR asked: Whats better to learn now, python 3 or 2.6 ? I have heard python 3 is quite different.15:44
rickspencer3ARR I would stick with 2.6 for now15:45
rickspencer3you will need lots of samples and people to ask, etc...15:45
rickspencer3python 3 is not yet widely adopted15:45
rickspencer3also, python 3 is not supported everywhere yet15:45
rickspencer3others may have different opinions, though15:45
rickspencer3ok, so we need to call the function that we just created, shall we do that, or are there more questions now?15:46
rickspencer3Note 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
ClassBotimmy asked: what version of python do ubuntu developers use?15:46
rickspencer3well, Ubuntu developers are comprised of folks from all over15:47
rickspencer3Canonical folks tend to use 2.615:47
rickspencer3so do most other Ubuntu developers15:47
rickspencer3let's go ahead and call the function now15:48
rickspencer3if command == "look door":15:48
rickspencer3    print "The door to the house. It looks unlocked"15:48
rickspencer3elif command == "go door":15:48
rickspencer3    print "You go through the door into the living room"15:48
rickspencer3    enter_living_room()15:48
ClassBotvirkang asked: Will Lucid have Python 3 installed by default ?15:48
rickspencer3    print "You can't do that here"15:48
rickspencer3virkang, I dunno15:48
rickspencer3if so, it would be in the repos by now15:48
rickspencer3ok, does everyone see where I added the call to our new function?15:49
rickspencer3Notice 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
rickspencer3The 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
rickspencer3oops, never mind15:49
rickspencer3you can see the whole listing on the wiki15:49
rickspencer3so creating and calling  your own functions is a big big part of programming15:50
rickspencer3any questions?15:50
rickspencer3let's do a bit more with variables15:50
rickspencer3Let's handle looking at the lamp and getting the bulb in the living room.15:50
rickspencer3First, we want the player to see that there is a bulb that they can take.15:51
rickspencer3But if they already took the bulb, we don't want them to keep seeing the bulb right?15:51
rickspencer3So we handle this by creating a global variable15: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
rickspencer3Create a global variable at the top for your code file like this:15:51
rickspencer3global has_bulb15:51
rickspencer3has_bulb = False15:52
rickspencer3save your program and make sure it runs15:52
rickspencer3If you don't want the variable to be available everywhere in your program, just leave out line 115:53
rickspencer3but in this ase we do15:53
rickspencer3, we assigned the variable to be "False"15:53
rickspencer3note that this is False, not false !15:53
rickspencer3As in, the player does not yet have the bulb, right?15:53
rickspencer3so we start out the program saying that the player does not have the bulb15:54
rickspencer3make sense?15:54
rickspencer3you don't have to declare variable first15:54
rickspencer3you just have to declare them *before* you use them15:54
ClassBottheopensourcerer asked: so you do not have to declare variables first?15:54
rickspencer3theopensourcerer, so for global variable, it's easier to put them at the top15:54
rickspencer3also, it makes it easier to read your cod a bit15:55
rickspencer3If 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
ClassBotBoyan23 asked: I get NameError: name 'command' is not defined?15:55
rickspencer3this sounds like you are trying to use the command variable before you've declared it15:56
rickspencer3we're a bit running out of time, but perhaps we can try to debug it later15:56
rickspencer3are other people having this same bug?15:56
rickspencer3sorry Boyan23 I promise to help you later :)15:57
=== himurake1 is now known as himura-mobile
rickspencer3so lets use has_bulb in our enter_living_room function15:57
ClassBotragesoss asked: I must have missed this... on the wiki, line 5 is blank. Why? A blank line means calling the function?15:57
rickspencer3a blank line is just a blank line15:58
rickspencer3it is useful for making your code easier to read15:58
rickspencer3it's usually a good idea to stick a blank line in between chunks of code that are logically seperated15:58
rickspencer3so your code forms "chunks" that are easier to skim and read15:58
rickspencer3remember you will read your code 1000 times more than you will write it!15:59
rickspencer3readability is very important15:59
rickspencer3ok, where was I15: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
ClassBotragesoss 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
rickspencer3so 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 yet16: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(almost done, last thing)16:00
rickspencer3if you want to assign a value to has_bulb, you'll need to tell the enter_living_room() function about it16:01
rickspencer3def enter_living_room():16:01
rickspencer3    global has_bulb16: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 = True16:01
rickspencer3        enter_living_room()16:01
rickspencer3so notice I redeclared has_bulb as a global within the "scope" of the function16:01
rickspencer3notice that I called the function from within itself!!16:01
rickspencer3pretty cool, a function can call itself16:01
rickspencer3this keeps the program from exiting16:02
rickspencer3so we're two minutes over16:02
rickspencer3how about if you want to, you can try working on the game today/tonight, and then tomorrow if you have questions ...16:02
rickspencer3track me down and I can try to help16:02
rickspencer3maybe set up a follow up session for next week if folks want16:02
rickspencer3Ready for the next class?16:03
ClassBotshift_wreck asked: could you pastebin the code?16:04
rickspencer3shift_wreck, (nice nick btw) -  sure if the wiki doesn't work for you16:04
rickspencer3but doing another class now16:04
rickspencer3anyone here for Python for For Folks who know another language?16:05
rickspencer3alright then16:06
rickspencer3let us rock16:06
rickspencer3if you know me at all, you can predict that I created a wiki page and over pre-pared for the class :)16:06
rickspencer3keep in mind - I am not a python expert16:06
rickspencer3but I have learned lots and lots of languages over the years16:07
rickspencer3so whenever I learn a new language I have to create a kind of map in my mind that maps old languages to the new one16:07
rickspencer3so, what I want to do is just give you a jump start by providing that mental map16:08
rickspencer3to me, Python is one of the "native" languages of the Ubuntu desktop16:09
rickspencer3because Ubuntu is a Gnome based distro16:09
rickspencer3it's well suited to app development and,16:09
ClassBotdscassel asked: For me, language is lesss of an issue than environment, tooling and libraries. We'll get to that, yes?16:09
rickspencer3over the years I have come to love programming in Python16:09
rickspencer3dscassel, a bit, I'll answer your question in a moment16:10
rickspencer3when I first started with python it seemed weirdly terse and constrictive16:10
rickspencer3but now I find that my creativity really flows through the language16:10
rickspencer3to dscassel question, what is python?16:10
rickspencer3it is a language16:10
rickspencer3but it is *also* a standard library16:11
rickspencer3it's hard to talk about one without the other16:11
rickspencer3so I won't try to make hard and fast distinctions here, I'll just mix it up16:11
rickspencer3but I put a link to the language ref and the library ref on the wiki page16:11
ClassBotJohonunu asked: is python procedural or object oriented language ?16:12
rickspencer3python is also on interpreter16:12
rickspencer3Johonunu, yes16:12
rickspencer3Python supports both paradigms well16:12
rickspencer3I prefer to use the OO approach for larger programs, so I will cover that syntax near the end of this session16:13
rickspencer3let's rock16:13
rickspencer3if you type "python" into your terminal window16:13
rickspencer3you get the python interpreter16:13
rickspencer3where you can write a bit of python16:13
rickspencer3in samples if you see a >>>16:13
ClassBotAdamK19 asked: what makes Python so great? any notable advantages over say, C# or Java?16:13
rickspencer3that means the sample was done in the "interactive shell"16:13
rickspencer3AdamK19, well, linguistic choices are perosnal to some degree16:14
rickspencer3I know C# and Java both quite well16:14
rickspencer3I find Python to have significantly less syntactic and semantic overhead, and easier to read other people's python code16:14
rickspencer3but I won't say one is "better"16:14
rickspencer3Python is great for Ubuntu because it is a real FOSS community language in terms of origins and the community around it16:15
rickspencer3let's start with some language concepts16:15
rickspencer31. Indentation levels16:15
ClassBothemanth 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 level16:15
rickspencer3# you will get used to it, and probably format you code this way anyway16:15
rickspencer3so this means that white space is meaningful in a way it is not in other languages16:16
rickspencer3you will have many bugs in your code from this the first few days of using python16:16
rickspencer3you may find you hate this at first, but you may learn to love it16:16
rickspencer3anyway, real programmers indent their code for readability, so you probably have this habbit already16:17
ClassBotabgalphabet asked: python gets different implementation, is it a language spec too?16:17
rickspencer3for i in xrange(5,20):16:17
rickspencer3    print i16:17
rickspencer3"print i" is indented 4 spaces, thus the it is within the scope of the for loop16:18
rickspencer3hemanth, deep question, let's talk later16:18
rickspencer3abgalphabet, yes16:18
ClassBotabgalphabet asked: 4 spaces? not tab?16:18
rickspencer34 spaces!16:18
rickspencer3technically, the language support both, but 4 spaces is standard16:19
rickspencer3set your editor to do 4 spaces for tab with python, you will be much happier in the long run that way!16:19
rickspencer3let's talk typing real quick16:19
rickspencer3Python is Dynamically typed, but it is also Strongly typed16:19
rickspencer3>>> x = 116:20
rickspencer3>>> x16:20
rickspencer3>>> type(x)16:20
rickspencer3<type 'int'>16:20
rickspencer3>>> x = "string"16:20
rickspencer3>>> x16:20
rickspencer3>>> type(x)16:20
rickspencer3<type 'str'>16:20
rickspencer3this shows dynamic typing16:20
rickspencer3x is an int just because I said it was16:20
rickspencer3I said it was by assigning an int to it16:20
rickspencer3then I changed x to be a string16:20
rickspencer3I did this by assigning a string to it!16:21
rickspencer3so you don't declare the type of a variable because you can change the type laer16:21
rickspencer3thus "dynamic" typing16:21
rickspencer3but unlike some other dynamically typed languages, Python is strongly typed16:21
rickspencer3so types are converted from one to other automatically16:21
ClassBotkript asked: probably stupid,but how do you run code in the emulator?16:21
rickspencer3>>> x = 116:22
rickspencer3>>> print x + " is a string"16:22
rickspencer3Traceback (most recent call last):16:22
rickspencer3  File "<stdin>", line 1, in <module>16:22
rickspencer3TypeError: unsupported operand type(s) for +: 'int' and 'str'16:22
rickspencer3kript, if you mean in the interactive shell, you just type it in16:22
rickspencer3it will run as blocks of code are complete16:22
rickspencer3also, install iPython16:22
rickspencer3it's an interactive shell that supports tab completion16:23
rickspencer3so you can inspect data structures and such as you are typing16:23
ClassBottheopensourcerer asked: Can you enforce type so you can't change it later?16:23
rickspencer3theopensourcerer, not that I know of, as it is a dynamically typed language16:23
rickspencer3(but there may be a way I don't know about)16:23
rickspencer3if you are used to statically typed languages this seems weirdly dangerous16:24
rickspencer3but after a while static typing will seem like unneceesary programing overhead16:24
rickspencer3ok, so moving on16:24
rickspencer3since it is a strongly typed language, there are types16:24
rickspencer3it's easy to look up the types, so I won't bore you with details here16:25
rickspencer3but here is some info to get your mental map started16:25
rickspencer3there are numeric types16:25
rickspencer3Integer, Long Integer, Float, Complex16:25
ClassBotAdamK19 asked: does python have something like c# interfaces (and if, how dose it fit with dynamic types)16:25
rickspencer3AdamK19, no16:25
rickspencer3interfaces are necessary for strongly typed languages16:25
rickspencer3because you want different implementations to be callable, right?16:26
rickspencer3so in Python, you just add the members to your class that will be needed by the caller16:26
rickspencer3however, Python does have multiple inheritance, so you can do interface like things, but include a default implementation16:26
rickspencer3(at least that's the way I understand it)16:27
rickspencer3ok so one thing abut numeric types is that you can mix em up in your math16:27
rickspencer3the result will always be the least restrictive type16:27
rickspencer3so if you add an in to a float, the result will be a float16:28
ClassBotm_anish asked: Is there a way to declare constant variables like we do in C/C++16:28
rickspencer3if you want the result to be an int, you can conver it to an int like this:16:28
rickspencer3x = int(x)16:28
rickspencer3m_anish, I don't know for sure16:28
rickspencer3there is a convention to use all caps16:28
rickspencer3MY_CONSTANT_VARIABLE = "foo"16:29
rickspencer3but I don't know that the language can enforce immutability16:29
rickspencer3moving on16:29
rickspencer3a quick word on string16:29
rickspencer3strings are highly functional in Python16:29
rickspencer3this is an example of where the line between language and library is nicely blurred16:30
rickspencer3note that there is no "character" type16:31
rickspencer3you can concat with "+" and stuff like that16:31
ClassBotmalev asked: capitals does not make a variable inmutable, sorry16:31
rickspencer3and you get "foo".endswith("o"), etc... for free16:31
rickspencer3you can use " or ' to surround your string16:31
rickspencer3malev, no, it's just a convention16:31
rickspencer3so when people read your code, they think "ah, all caps, the author believes this should not change"16:32
ClassBotabgalphabet asked: is python case-sensitive16:32
rickspencer3abgalphabet, yes16:32
rickspencer3so more on types16:32
rickspencer3there is an object called None16:32
rickspencer3it is of the type NoneType16:32
rickspencer3it;s kind of like null16:33
rickspencer3None is an instance of NoneType16:33
rickspencer3undeclared variables *are not* None, they are just undeclared16:33
rickspencer3so you can't do:16:33
rickspencer3if foo is not None:16:33
rickspencer3    #do something16:33
rickspencer3to test if foo is declared16:33
rickspencer3that will be an error16:34
rickspencer3so python has three types are very feature rich16:34
rickspencer3Lists, Tuples, and Dictionaries16:35
rickspencer3lists and tuples are kind of like arrays in other languages16:35
rickspencer3but they aren't typed16:35
rickspencer3it would be like an array of Objects in C# or java16:35
rickspencer3by "not typed", I mean, this is fine:16:35
rickspencer3my_tuple = (1,"one",False)16:35
rickspencer3you can mix up types in them16:36
rickspencer3very cool16:36
rickspencer3the main difference between tuples and lists is that tuple are immutable16:36
rickspencer3this makes them a bit faster to iterate and stuff like that16:36
rickspencer3also keeps other parts of your program from messing with them16:36
ClassBotmcphargus 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
rickspencer3mcphargus, nope16:37
rickspencer3you cannot add or remove items from a tuple16:37
rickspencer3I assume that you can change an object that is in a tuple from outside of tuple16:38
rickspencer3but I'm not 100% certain16:38
rickspencer3I use tuple for stuff like this:16:38
rickspencer3>>> wintermonths = ("December","January","February")16:38
rickspencer3>>> wintermonths16:38
rickspencer3('December', 'January', 'February')16:38
rickspencer3like I know I won't change that list, I care about the order, and I'll be iterating it16:38
* rickspencer3 tries changing a value in a tuple16:39
rickspencer3>>> foo = "boo"16:39
rickspencer3>>> t = (1, foo)16:39
rickspencer3>>> t16:39
rickspencer3(1, 'boo')16:39
rickspencer3>>> foo = "baz"16:39
rickspencer3>>> t16:39
rickspencer3(1, 'boo')16:39
rickspencer3immutable :)16:39
rickspencer3tuple are created with ()16:40
rickspencer3lists with []16:40
rickspencer3>>> grades = ["A","A-","B","C"]16:40
rickspencer3>>> grades16:40
rickspencer3['A', 'A-', 'B', 'C']16:40
rickspencer3you index lists and tuples with [] as in most languages16:40
rickspencer3>>> wintermonths16:41
rickspencer3('December', 'January', 'February')16:41
rickspencer3>>> wintermonths[0]16:41
rickspencer3one sweet thing is that you can start from the back!16:41
rickspencer3>>> grades16:41
rickspencer3['A', 'A-', 'B', 'C']16:41
rickspencer3>>> grades[-1]16:41
rickspencer3>>> grades[-2]16:41
rickspencer3getting the last item in a list or tuple is so easy16:41
rickspencer3to test if a list or tuple (or dictionary for that matter) contains a value (or key for a dictionary), use "in"16:42
rickspencer3it's sweet"16:42
rickspencer3>>> grades = ["A","A-","B","C"]16:42
rickspencer3>>> grades16:42
rickspencer3['A', 'A-', 'B', 'C']16:42
rickspencer3>>> "A" in grades16:42
rickspencer3>>> "F" in grades16:42
ClassBothemanth asked: how immutability increases speed in iterations ?16:42
rickspencer3hemanth, I have no idea, I assume it's implementation specific16:43
rickspencer3so, let's move on to dictionaries16:43
rickspencer3these are really common to use in Python and save tons and tons of time and code16:43
rickspencer3a dictionary is basically a hash table, but it's built into the langauge16:43
ClassBotvirkang 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
rickspencer3virkang, I suppose16:44
rickspencer3this has never been something that I cared to do in a Python program16:44
rickspencer3there may be other experts that could better answer that for you16:44
rickspencer3like I say, I'm not a Python expert, I just know lots of languages ;)16:44
rickspencer3so moving on to dictionaries:16:45
rickspencer3>>> grades = {"English":"D","Math":"A-","History":"C+"}16:45
rickspencer3>>> grades16:45
rickspencer3{'History': 'C+', 'Math': 'A-', 'English': 'D'}16:45
rickspencer3using {} you can easily create a dictionary16:46
rickspencer3again, they don't require certain types to be used for keys and values16:46
rickspencer3though some types can't be used for keys16:46
rickspencer3like you can't use a dictionary to be a key in another dictionary16:46
ClassBothemanth asked: i was unclear when you said "this makes them a bit faster to iterate and stuff like that"16:46
rickspencer3hemanth, 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 tuple16:47
rickspencer3because it won't have to support "append" and all this16:47
rickspencer3so it can be optimized inside the Python run time16:47
rickspencer3at least that's what I think16:47
rickspencer3so, dictionaries16:48
rickspencer3use 'em, love 'em16:48
rickspencer3looks like I screwed up the wiki a but16:48
rickspencer3a bit, even16:48
rickspencer3I'll add the dictionary stuff in later today16:48
ClassBottheopensourcerer asked: So a dictionary is like an associative array?16:48
rickspencer3Note 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>>> grades16:49
rickspencer3{'History': 'C+', 'Math': 'A-', 'English': 'D'}16:49
rickspencer3>>> grades["History"]16:49
rickspencer3To change the value associated with a key, simply reassign to the indexed key:16:49
rickspencer3>>> grades16:49
rickspencer3{'History': 'C+', 'Math': 'A-', 'English': 'D'}16:49
rickspencer3>>> grades["History"] = "B-"16:49
rickspencer3>>> grades16:49
rickspencer3{'History': 'B-', 'Math': 'A-', 'English': 'D'}16:49
rickspencer3You can add a key/value pair the exact same way:16:49
rickspencer3>>> grades16:49
rickspencer3{'History': 'B-', 'Math': 'A-', 'English': 'D'}16:49
rickspencer3>>> grades["Gym"] = "F"16:49
rickspencer3>>> grades16:49
rickspencer3{'Gym': 'F', 'History': 'B-', 'Math': 'A-', 'English': 'D'}16:49
rickspencer3To delete a key/value pair, use the global del() function:16:49
rickspencer3>>> grades16:49
rickspencer3{'Gym': 'F', 'History': 'B-', 'Math': 'A-', 'English': 'D'}16:49
rickspencer3>>> del(grades["English"])16:49
rickspencer3>>> grades16:49
rickspencer3{'Gym': 'F', 'History': 'B-', 'Math': 'A-'}16:50
rickspencer3You 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>>> grades16: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
rickspencer3to see if a dictionary has a certain key, don't look in keys, just look in the dictionary16:50
rickspencer3so you go:16:50
rickspencer3if Gym in grades:16:50
rickspencer3    #do something16:50
rickspencer3Remember 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
rickspencer3never count on a dictionary having anything in a particular order!16:51
ClassBotabgalphabet asked: dictionary created by {}?16:51
rickspencer3abgalphabet, right16:51
rickspencer3very similar to json16:51
ClassBottheopensourcerer asked: Can you have multi-dimension dictionaries?16:51
rickspencer3also like jason, a list is defied with[]16:51
rickspencer3theopensourcerer, yes, a dictionary can be a value in another dictionary, but it can not be a key in another dictionary16:52
rickspencer3let's skip to OO syntax since someone asked about that at the beginning, and I only have 7 minutes16:53
rickspencer3sound ok?16:53
rickspencer3if I wanted to define a class called "program2" I do it like this:16:54
rickspencer3class program2:16:54
ClassBotwharp asked: grades and grades.items() produce the same output, is there a difference?16:54
rickspencer3if I want program3 to derive from program2, I do it like this16:54
rickspencer3wharp. that's just because of what would be the to_string() funciton in other languages16:54
rickspencer3in the interactive interperted when you just type a variable, it tries to print something sensible for you to read16:55
rickspencer3in a program grades and grades.items() are very different16:55
rickspencer3grades is the dictionary, grades.items() returns a list of the values16:55
rickspencer3so, back to classes real quick16:56
rickspencer3a couple of points I want to touch on16:56
rickspencer3before we break16:56
rickspencer3this is a function that is more or less the constructor for a class16:56
rickspencer3it is optional16:56
rickspencer3unless your super class has one, your subclass has to call the super class's __init__() at some point16:57
rickspencer3finally, a point about private members16:57
rickspencer3this is a bit odd in Python16:57
rickspencer3*there are no private members in Python*16:57
rickspencer3this badly breaks encapsulation16:58
rickspencer3however, there are two ways around this16:58
rickspencer3if you want a private member that you want to be available to subclasses16:58
rickspencer3use a single underscore to start the variable name16:58
rickspencer3it's not really private, but the underscore is a convention16:59
rickspencer3if you don't want it to be accessible to sub classes, use two underscores16:59
rickspencer3python will "munge" the variable name at run time17:00
rickspencer3so it won't be accessible17:00
rickspencer3well, it kind of will be, but it's harder for other programmers to get at it17:00
rickspencer3ok, I am out of time :/17:00
rickspencer3sorry, there was more I wanted to go into17:00
cjohnstonmore classes!17:00
rickspencer3I would stay, but I have to run to a meeting17:01
rickspencer3please let jono know if you would like more or a follow up or something17:01
rickspencer3also, #ubuntu-all-devel is a good place for questions17:01
rickspencer3sorry, 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
jakiw_Will it be 9.14?17:06
jakiw_Is it really Year and Month???17:06
abhi_navwhat is ubuntu-classroom?17:07
jakiw_So 10.04 hasnt to be a new OS, just a new version of 9.04?17:07
cjohnstonthe next version.. after 9.1017:07
binti_can i re run the python class ?17:07
cjohnstonbinti_: you mean the logs17:08
cjohnstonabhi_nav: a place for teaching classess17:08
cjohnstonbinti_: irclogs.ubuntu.com17:08
abhi_navplace for teaching Ubuntu?17:08
abhi_navcjohnston: 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
cjohnstonabhi_nav: ubuntu, programming, other stuff17:08
binti_thanks ! for the log link17:09
jakiw_And when/how do u teach here_17:09
cjohnstonwindows 7 is a new version of windows... 10.5 is a new version of osx....17:09
RainCTjakiw_: there is no "new OS", just new releases every 6 months17:09
abhi_navcjohnston: How #ubuntu-classroom is different from #ubuntu?17:09
cjohnstonjakiw_: look at the link in the topic17:09
cjohnstonabhi_nav: #ubuntu is a support channel17:10
MustafaAlisorry guys I missed the class17:10
cjohnstonthis isnt a support channel17:10
cjohnstonMustafaAli: get it on the logs. :-)17:10
RainCTabhi_nav: #ubuntu is for asking all sorts of questions, this channel is for scheduled sessions with someone teaching some topic related to Ubuntu17:10
abhi_navcjohnston: so I cannt ask question here, I just have to enroll in the current running class? Is class timings are defined?17:11
MustafaAlicould you please tell me how17:11
cjohnstonMustafaAli: irclogs.ubuntu.com17:11
abhi_navcjohnston: 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
RainCTabhi_nav: Yeah. (You can only ask questions about the running class, in #ubuntu-classroom-chat)17:11
cjohnstonabhi_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 class17:11
MustafaAlithanks for help17:11
RainCTAnd the schedule for the next classes should be somewhere on the wiki17:12
cjohnstonMustafaAli: yup17:12
abhi_navRainCT: how to get the class schedule?17:12
cjohnstonabhi_nav: the link in the topic17:12
ubottuPlease read the channel topic whenever you enter, as it contains important information. To view it at any time after joining, simply type /topic17:13
abhi_navand what about time zones?17:13
abhi_navI am from India17:13
ubottuPlease read the channel topic whenever you enter, as it contains important information. To view it at any time after joining, simply type /topic17:14
cjohnstonall times are in UTC17:14
abhi_navthen how to know that what that time means India?17:14
abhi_navIndia is GMT +5.3017:14
cjohnstonrun date -u in the command line17:15
hemanthabhi_nav, date -u17:15
abhi_navdate -u17:15
cjohnstonthis isnt the command line17:15
hemanthabhi_nav, Thu Feb 25 17:15:16 UTC 201017:16
abhi_navUTC uses 24 hours clock?17:16
ubottuThe official ubuntu support channel is #ubuntu. Also see http://ubuntu.com/support and http://ubuntuforums.org17:16
abhi_navyah i know ok17:16
cjohnstoni was testing17:16
hemanthha ha17:17
hemanthdate -u +'%I.%M.%S' get it in 0..12 hrs clock17:21
jakiw_Damned, I passed the python class today :D17:31
binti_irclogs.ubuntu.com 25 feb17: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
=== per is now known as Guest77747
=== yofel_ is now known as yofel
=== Micke is now known as Guest92152
timburyHi, all. Are we waiting for Rick to start?21:16
pleia2timbury: that was several hours ago21:18
pleia2logs are here: http://irclogs.ubuntu.com/2010/02/25/%23ubuntu-classroom.html21:18
timburyThanks, pleia2. I missed the UTC, I think. ;)21:19
pleia2I figured, it happens :)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!