/srv/irclogs.ubuntu.com/2010/04/12/#ubuntu-manual.txt

humphreybchi all01:02
* pleia2 waves to humphreybc 01:13
humphreybcah! hi!01:14
humphreybcwhy am I getting an unexpected indent error?02:11
humphreybchttp://paste.ubuntu.com/412854/02:11
humphreybcwait what02:12
humphreybcweird02:12
humphreybcgedit is playing tricks on me02:12
Red_HamsterXI think you're supposed to be returning those values.02:19
Red_HamsterXRather than printing them.02:19
humphreybcone of the reasons it wasn't working is because gedit is doing something weird with indentation02:19
Red_HamsterXDut I dunno for sure.02:19
Red_HamsterXIt looks like gedit is set to use tabs instead of spaces.02:19
Red_HamsterXFour spaces is the PEP 8 convention.02:20
Red_HamsterXYou can quickly change this by clicking stuff in the lower right of the gedit window.02:20
humphreybcyeah02:21
humphreybci found that02:21
humphreybcis there a more elegant way of doing the maximum function?02:21
humphreybc(this is practice for a lab test I have on wednesday)02:22
Red_HamsterXreturn max(a, b, ...)02:22
Red_HamsterXmax takes any number of arguments or a sequence.02:22
Red_HamsterXx = (1, 2, 3,)02:22
Red_HamsterXmax(x)02:22
Red_HamsterXmax(888, 777)02:22
Red_HamsterXAlso, you're using 'or' wrong.02:23
humphreybci'm getting stuff like this02:24
humphreybcExpected: JimBob02:24
humphreybcGot: 'JimBob'02:24
humphreybchow can I return it without the single quotes?02:24
Red_HamsterXPaste your new code.02:24
humphreybchttp://paste.ubuntu.com/412860/02:25
Red_HamsterXRegarding using 'or' wrong: that should be 'a > b and a > c'.02:25
Red_HamsterXYou need to do two tests, logically.02:25
humphreybcoh yeah, of course02:25
Red_HamsterX'False or c' is valid, but it won't do what you expect.02:25
Red_HamsterXIf c is non-zero, the entire condition will evaluate to whatever c happens to be.02:26
godbykWhat's the point of writing your own maximum function if it just calls Python's built-in max() function?02:26
humphreybcso i'm getting two failures for the two string things02:26
humphreybcgodbyk, it's just testing our knowledge of python stuff02:26
Red_HamsterX"False or 'dance'" -> 'dance'02:26
godbykI see.02:26
humphreybchow can I return a string as string instead of 'string' ?02:26
Red_HamsterXIt is being returned as a string.02:27
Red_HamsterXDoes it pass if you do use print?02:27
Red_HamsterXMaybe the tester's watching stdout instead of return values.02:27
* Red_HamsterX doesn't know.02:27
humphreybcyeah02:27
humphreybcit does02:27
Red_HamsterXThen your instructor's weird.02:27
humphreybcwell, the only goal of the test is to make the doctests pass... so all 10 passed02:27
Red_HamsterXJust print, in that case.02:27
humphreybcnow, onto the next one02:27
humphreybc(there are 4)02:27
humphreybc:)02:28
Red_HamsterXAls, for is_divisible, you would just write 'return a % b == 0' or 'return not a % b'.02:28
Red_HamsterXyou could*02:28
humphreybci don't understand what I have to do for the first one, compare()02:29
humphreybchttp://paste.ubuntu.com/412861/02:29
Red_HamsterXThe result of an == comparison is always a boolean value.02:29
Red_HamsterXIf a > b: +102:29
Red_HamsterXIf a < b: -102:29
Red_HamsterXElse: 002:29
Red_HamsterXPython has a built-in for this, too.02:29
humphreybcah02:29
humphreybcoh it does?02:30
Red_HamsterXYou can probably guess at what it is.02:30
Red_HamsterXLike max() or min().02:30
humphreybccompare?02:30
Red_HamsterXdir() is your friend.02:30
godbykYou can write your own cmp functions for doing fancy comparisons. I've had to write them before.02:30
Red_HamsterXLearn to love it.02:30
Red_HamsterXThings surrounded by __s are often exposed through like-named language-level functions.02:31
humphreybchow to do the count_vowels function? something like 'if 'a' 'e' 'i' 'o' 'u' in count_vowels?02:34
Red_HamsterXThere are a number of ways to do it.02:35
Red_HamsterXLook at what dir() has to say about a string.02:36
Red_HamsterXThere's a better way to solve this problem, but I think your instructor would be suspicious if you were to use it.02:36
Red_HamsterXAnd you'd miss something important about Python's design if I were to just show you.02:37
humphreybcfind?02:37
Red_HamsterXhelp(''.find)02:37
Red_HamsterXDoes that look like what you want?02:37
humphreybcreturn sentence.find("a", "e", "i", "o", "u")02:38
humphreybc?02:38
Red_HamsterXNo, that won't pass the syntax compiler.02:39
Red_HamsterXAnd it's not what you want to do anyway.02:39
Red_HamsterXIt'd fail the second test. And the others, for that matter.02:39
Red_HamsterXLook at the list of attributes attached to a string again.02:39
humphreybcugh02:40
humphreybcokay02:40
Red_HamsterXI'm not going to just give you the answers. It's not like you have something due in a couple of hours, after all.02:41
humphreybclol yeah02:41
Red_HamsterXWhen in doubt, try things in the interpreter.02:41
Red_HamsterX"test string".find('e') would give you 1, but "test string".find('i') would give you 8.02:42
humphreybcright02:42
humphreybcso it's returning the index02:42
Red_HamsterXYeah.02:42
Red_HamsterXThere's another function that'll help, though.02:42
humphreybccount02:43
Red_HamsterXLook at its help text and figure out how to apply it.02:43
Red_HamsterXhelp() renders the object's docstring.02:44
Red_HamsterXJust so you know where it's pulling that data from.02:44
Red_HamsterXThe docstring is the unassigned string at the start of any function/class/whatever.02:45
humphreybcokay, so, on Hello World I ran sentence.count("o") and it returned 202:45
humphreybcso it's workiung02:45
humphreybcbut then apparently it only takes at most 3 arguments02:45
Red_HamsterXIt's morning in Austrailia/New Zealand, right?02:45
humphreybc1:46pm02:46
Red_HamsterXAh. Later than I thought.02:46
humphreybcso do I have to create a variable called "vowels" that's a list of the things I want to find?02:47
humphreybcand then run sentence.count(vowels) ?02:47
Red_HamsterXNo.02:47
Red_HamsterXIt doesn't work that way.02:47
Red_HamsterXYou're going to have to call it five times.02:48
Red_HamsterX(Ten if you need to account for capitals and don't lowercase the string before scanning it)02:48
humphreybcokay02:48
humphreybcso firstly I should go sentence.lower()02:49
humphreybcI don't understand how I can call count 5 times, then add each return value together... do I have to assign each call of count to a different variable and then add them up, then return that value?02:50
Red_HamsterXYou could.02:50
humphreybcor could you put all of that into one statement?02:50
Red_HamsterXVariables in Python are not immutable, as they are in math or languages like Haskell.02:51
Red_HamsterXYou could do that, too.02:51
Red_HamsterX''.count() + ''.count()...02:51
Red_HamsterXx = ''.count('a')02:51
Red_HamsterXx += ''.count('e')02:51
Red_HamsterXreturn x02:51
Red_HamsterXThat's probably the cleanest way to write it.02:51
Red_HamsterX(Barring the advanced technique I mentioned before)02:52
humphreybchttp://paste.ubuntu.com/412871/02:52
Red_HamsterXYou could return it directly, if you really wanted to save a line.02:53
Red_HamsterXBut there's still a problem.02:53
Red_HamsterXsentence.lower() returns a new string.02:53
Red_HamsterXIt doesn't modify sentence.02:53
Red_HamsterXAlso, variable names like 'x' are icky.02:53
humphreybcso i have to assign it02:53
humphreybcsentence = sentence.lower()02:54
humphreybcreturn = sentence.count("a") + sentence.count("e") + sentence.count("i") + sentence.count("o") + sentence.count("u")02:54
humphreybclike that?02:54
Red_HamsterXYou can assign it to 'sentence', but that's commonly frowned upon for non-trivial code.02:54
Red_HamsterXSo it's a good habint to avoid.02:54
humphreybcright02:54
Red_HamsterXhabit*02:54
humphreybcso assign it to say, S02:54
humphreybcand then run count on S02:54
Red_HamsterXYeah, that works.02:54
humphreybcok02:55
Red_HamsterXDon't try to show this to your instructor ('cause it'll be obvious you get help), but you could do the whole thing in one line.02:55
humphreybck02:55
Red_HamsterXreturn len([v for v in sentence.lower() if v in ('a', 'e', 'i', 'o', 'u',)])02:56
Red_HamsterXYou'll figure out how it works eventually.02:56
humphreybcrighto02:56
humphreybcokay i've got all the ones in this except the count_words() function02:57
humphreybcso I have to count something and make it split on a white space02:58
Red_HamsterXLook at the dir() result again.02:58
Red_HamsterXI assume you can consider all input sane.02:58
Red_HamsterXSo you won't have tabs or non-space delimiters.02:58
humphreybcyeah02:58
humphreybci've done something like this before03:00
humphreybci'm just trying to find where03:00
humphreybcso I use split03:03
humphreybcbut i don't understand how03:05
humphreybci've got S = sentence.split()03:07
humphreybcthen count(S) ? or S.count(S)? S.count() ?03:07
Red_HamsterXcount() isn't what you want.03:10
Red_HamsterXhelp(len)03:10
humphreybcoh03:11
humphreybcthat did it =]03:11
Red_HamsterXYou might want to do sentence.strip().split(), just in case there's a leading or trailing space.03:11
humphreybcknowing the library of builtin functions is pretty helpful03:11
Red_HamsterXAnd actually iterate over the tokens to discard empty ones.03:12
Red_HamsterXBut that's not necessary here.03:12
humphreybcright i'm going to get something to eat03:12
humphreybcthen i'll start on part 303:12
* humphreybc thinks that programming might not be for him03:12
Red_HamsterXIt's your first exposure.03:13
Red_HamsterXMost people find thinking in a C-like mindset hard to do initially.03:13
Red_HamsterXIf you've got a math background, look into Haskell.03:13
humphreybcit's not the first time, i did PHP and HTML in high school, then last year I did java03:18
humphreybci've never really been that good at it03:18
humphreybci understand the logic but I can just never, ever remember syntax or methods of doing stuff03:18
humphreybcmaybe as I write more stuff i'll03:19
humphreybci'll remember the syntax better*03:19
Red_HamsterXThe most meaningful advice I can give you about Python is probably that clarity is more important than efficiency. Most people who primarily use Python tend to adopt that mindset.04:18
Red_HamsterXWhen writing code, try to focus on making the logic obvious.04:18
Red_HamsterXThat may help you to think things through and make it all easier to understand.04:19
=== quickshot is now known as ubuntujenkins
ubuntujenkinsmorning all09:55
=== quickshot is now known as ubuntujenkins
* ubuntujenkins hates python when it doesn't work11:26
ubuntujenkinsback working in english and not siberian11:56
ubuntujenkinsserbian or how ever it is spelt11:57
ubuntujenkinshello all17:41
dutchieo/18:18
dutchieis there anything I ought to do before my battery dies?18:36
ubuntujenkinshello dutchie not as far as i know. You could reinvent the wheel if you have time :P18:50
dutchiehmm, 3 hours 25 and food in 10 mins18:51
dutchieI think not18:51
ubuntujenkinsRed_HamsterX: ping19:22
Red_HamsterXHi, ubuntujenkins.20:05
ubuntujenkinshello can you look over my last commit http://bazaar.launchpad.net/~quickshotdevs/quickshot/quickshot/revision/228 it works, I would just like you to see if i have done anything silly20:07
ubuntujenkinsalso there appears to be some progress on the bug i filed with python20:09
Red_HamsterXSetting the variable's value to 1 is unnecessary20:13
Red_HamsterXexcept ...:20:13
Red_HamsterX short_code = os.environ.get('LANG')20:13
Red_HamsterX if not short_code: raise (some custom error)20:14
Red_HamsterXOther than that, it should work.20:15
popeycan someone get ben to ping me when he's online20:18
ubuntujenkinsRed_HamsterX: well i couldn't get it to work this moring before i went out with out the =1 bit i will have a go again in a second if i ddin't20:23
ubuntujenkinspopey: i will if i am still up20:23
ubuntujenkinsbrb changing language20:24
* ubuntujenkins ubuntu serbian is intersting20:27
Red_HamsterXIs it significantly different from, say, Russian?20:32
* Red_HamsterX doesn't know anything about Serbian.20:32
ubuntujenkinsjust the person with the code changed to20:32
ubuntujenkins        20:33
ubuntujenkins        try:20:33
ubuntujenkins            short_code = locale.getdefaultlocale()[0]20:33
ubuntujenkins        except ValueError, e:20:33
ubuntujenkins            #error-log-write("Unable to process locale: %(error)s" % {'error': str(e)})20:33
ubuntujenkins            #this happens when the language code isn't in the module20:33
ubuntujenkins            20:33
ubuntujenkins        if not short_code:20:33
ubuntujenkins            short_code = os.environ['LANG']20:33
ubuntujenkins        applied_short_code = short_code20:33
ubuntujenkinsI get an indentaion error i changed the location of the not and removed one line .not my day as usual20:33
ubuntujenkinsi haven't looked at russian I just navigate by knowing where to find stuff20:36
ubuntujenkinsaaahhh spotted the indentaion error but now i get UnboundLocalError: local variable 'short_code' referenced before assignment20:45
ubuntujenkinsi had this this morning which is why the short_code = 1 was there20:47
ubuntujenkinsRed_HamsterX: sorry please can you help me20:51
Red_HamsterXSure.20:57
Red_HamsterXIs the code current or can you paste the function?20:57
ubuntujenkinsRed_HamsterX: let me paste it20:59
ubuntujenkins        try:20:59
ubuntujenkins            short_code = locale.getdefaultlocale()[0]20:59
ubuntujenkins        except ValueError, e:20:59
ubuntujenkins            logging.getLogger().debug("Unable to process locale: %(error)s" % {'error': str(e)})20:59
ubuntujenkins            #this happens when the language code isn't in the module20:59
ubuntujenkins            #short_code = 120:59
ubuntujenkins            if not short_code:20:59
ubuntujenkins                short_code = os.environ['LANG']20:59
ubuntujenkins        applied_short_code = short_code20:59
ubuntujenkinshttp://pad.ubuntu-uk.org/ZpWtZE8opJ21:00
* ubuntujenkins etherpad should do python highlighting21:02
Davieyubuntujenkins: raise a bug :)21:02
ubuntujenkinsDaviey: where do i file it?21:02
ubuntujenkinsand against what ubuntu uk team?21:02
Red_HamsterXubuntujenkins, the problem is that the 'if' occurs before the short code is assigned.21:13
ubuntujenkinsthats why i have short_code =121:13
Red_HamsterXWhen the assignment fails, short_code isn't left in some half-declared state.21:13
Red_HamsterXYou can assume it was never set when entering the exception handler.21:13
Red_HamsterXSo just drop the 'if' entirely.21:13
Davieyubuntujenkins: will talk later, recording a podcast atm21:14
Davieyand humphreybc is supposed to be our guest21:14
Davieybut he's offline :(21:14
ubuntujenkinsok Daviey have fun21:14
ubuntujenkinsthnaks Red_HamsterX that makes sense obvious as usual21:15
Red_HamsterXubuntujenkins, the error is raised by the call to getdefaultlocale(). Since that fails, nothing is actually returned, so Python jumps directly to the exception handler, bypassing the assignment step entirely.21:15
* Red_HamsterX goes into way too much detail.21:15
ubuntujenkinsand as the variable is not assigned the if test isn't needed.21:16
Red_HamsterXYep.21:16
ubuntujenkinsdetail is good helps me to understand21:16
Red_HamsterXPython, unlike, say, Java, uses something very much like a dict to manage variables.21:16
ubuntujenkinsthanks, i will do a release tonight to the ppas, and upload a cd tomorrow21:16
Red_HamsterXYou could think of each assignment like the following:21:16
Red_HamsterXobject = {}21:16
Red_HamsterX#Assign to 'short_code':21:17
Red_HamsterXobject['short_code'] = 521:17
Red_HamsterXThe dictionary has no value for the key until it's actually set.21:17
ubuntujenkinsok makes sense thank you21:18
ubuntujenkinsdutchie: !!!21:21
* ubuntujenkins hopes dutchies battery hasn't died21:22
Davieyanyone know where humphreybc is?21:33
ubuntujenkinsDaviey: I am keeping an eye on facebook to see if he comes on, i will shout at him if i see him21:34
ubuntujenkinsDaviey: he could have got daylight savings utc an gmt messed up21:34
Davieyubuntujenkins: thanks21:54
* ubuntujenkins has found someone else who has the same locale big we have :-)22:12
ubuntujenkins*big22:12
ubuntujenkins***bug22:12
ubuntujenkinsbrb swapping to english22:16
Red_HamsterXEnglish is overrated.22:19
Red_HamsterXNeeds more Turkish.22:19
ubuntujenkinsits easier to use rather than navigating by memory or icons22:19
ubuntujenkinsnight all23:01

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!