[01:02] <humphreybc> hi all
[01:13]  * pleia2 waves to humphreybc 
[01:14] <humphreybc> ah! hi!
[02:11] <humphreybc> why am I getting an unexpected indent error?
[02:11] <humphreybc> http://paste.ubuntu.com/412854/
[02:12] <humphreybc> wait what
[02:12] <humphreybc> weird
[02:12] <humphreybc> gedit is playing tricks on me
[02:19] <Red_HamsterX> I think you're supposed to be returning those values.
[02:19] <Red_HamsterX> Rather than printing them.
[02:19] <humphreybc> one of the reasons it wasn't working is because gedit is doing something weird with indentation
[02:19] <Red_HamsterX> Dut I dunno for sure.
[02:19] <Red_HamsterX> It looks like gedit is set to use tabs instead of spaces.
[02:20] <Red_HamsterX> Four spaces is the PEP 8 convention.
[02:20] <Red_HamsterX> You can quickly change this by clicking stuff in the lower right of the gedit window.
[02:21] <humphreybc> yeah
[02:21] <humphreybc> i found that
[02:21] <humphreybc> is there a more elegant way of doing the maximum function?
[02:22] <humphreybc> (this is practice for a lab test I have on wednesday)
[02:22] <Red_HamsterX> return max(a, b, ...)
[02:22] <Red_HamsterX> max takes any number of arguments or a sequence.
[02:22] <Red_HamsterX> x = (1, 2, 3,)
[02:22] <Red_HamsterX> max(x)
[02:22] <Red_HamsterX> max(888, 777)
[02:23] <Red_HamsterX> Also, you're using 'or' wrong.
[02:24] <humphreybc> i'm getting stuff like this
[02:24] <humphreybc> Expected: JimBob
[02:24] <humphreybc> Got: 'JimBob'
[02:24] <humphreybc> how can I return it without the single quotes?
[02:24] <Red_HamsterX> Paste your new code.
[02:25] <humphreybc> http://paste.ubuntu.com/412860/
[02:25] <Red_HamsterX> Regarding using 'or' wrong: that should be 'a > b and a > c'.
[02:25] <Red_HamsterX> You need to do two tests, logically.
[02:25] <humphreybc> oh yeah, of course
[02:25] <Red_HamsterX> 'False or c' is valid, but it won't do what you expect.
[02:26] <Red_HamsterX> If c is non-zero, the entire condition will evaluate to whatever c happens to be.
[02:26] <godbyk> What's the point of writing your own maximum function if it just calls Python's built-in max() function?
[02:26] <humphreybc> so i'm getting two failures for the two string things
[02:26] <humphreybc> godbyk, it's just testing our knowledge of python stuff
[02:26] <Red_HamsterX> "False or 'dance'" -> 'dance'
[02:26] <godbyk> I see.
[02:26] <humphreybc> how can I return a string as string instead of 'string' ?
[02:27] <Red_HamsterX> It is being returned as a string.
[02:27] <Red_HamsterX> Does it pass if you do use print?
[02:27] <Red_HamsterX> Maybe the tester's watching stdout instead of return values.
[02:27]  * Red_HamsterX doesn't know.
[02:27] <humphreybc> yeah
[02:27] <humphreybc> it does
[02:27] <Red_HamsterX> Then your instructor's weird.
[02:27] <humphreybc> well, the only goal of the test is to make the doctests pass... so all 10 passed
[02:27] <Red_HamsterX> Just print, in that case.
[02:27] <humphreybc> now, onto the next one
[02:27] <humphreybc> (there are 4)
[02:28] <humphreybc> :)
[02:28] <Red_HamsterX> Als, for is_divisible, you would just write 'return a % b == 0' or 'return not a % b'.
[02:28] <Red_HamsterX> you could*
[02:29] <humphreybc> i don't understand what I have to do for the first one, compare()
[02:29] <humphreybc> http://paste.ubuntu.com/412861/
[02:29] <Red_HamsterX> The result of an == comparison is always a boolean value.
[02:29] <Red_HamsterX> If a > b: +1
[02:29] <Red_HamsterX> If a < b: -1
[02:29] <Red_HamsterX> Else: 0
[02:29] <Red_HamsterX> Python has a built-in for this, too.
[02:29] <humphreybc> ah
[02:30] <humphreybc> oh it does?
[02:30] <Red_HamsterX> You can probably guess at what it is.
[02:30] <Red_HamsterX> Like max() or min().
[02:30] <humphreybc> compare?
[02:30] <Red_HamsterX> dir() is your friend.
[02:30] <godbyk> You can write your own cmp functions for doing fancy comparisons. I've had to write them before.
[02:30] <Red_HamsterX> Learn to love it.
[02:31] <Red_HamsterX> Things surrounded by __s are often exposed through like-named language-level functions.
[02:34] <humphreybc> how to do the count_vowels function? something like 'if 'a' 'e' 'i' 'o' 'u' in count_vowels?
[02:35] <Red_HamsterX> There are a number of ways to do it.
[02:36] <Red_HamsterX> Look at what dir() has to say about a string.
[02:36] <Red_HamsterX> There's a better way to solve this problem, but I think your instructor would be suspicious if you were to use it.
[02:37] <Red_HamsterX> And you'd miss something important about Python's design if I were to just show you.
[02:37] <humphreybc> find?
[02:37] <Red_HamsterX> help(''.find)
[02:37] <Red_HamsterX> Does that look like what you want?
[02:38] <humphreybc> return sentence.find("a", "e", "i", "o", "u")
[02:38] <humphreybc> ?
[02:39] <Red_HamsterX> No, that won't pass the syntax compiler.
[02:39] <Red_HamsterX> And it's not what you want to do anyway.
[02:39] <Red_HamsterX> It'd fail the second test. And the others, for that matter.
[02:39] <Red_HamsterX> Look at the list of attributes attached to a string again.
[02:40] <humphreybc> ugh
[02:40] <humphreybc> okay
[02:41] <Red_HamsterX> I'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] <humphreybc> lol yeah
[02:41] <Red_HamsterX> When in doubt, try things in the interpreter.
[02:42] <Red_HamsterX> "test string".find('e') would give you 1, but "test string".find('i') would give you 8.
[02:42] <humphreybc> right
[02:42] <humphreybc> so it's returning the index
[02:42] <Red_HamsterX> Yeah.
[02:42] <Red_HamsterX> There's another function that'll help, though.
[02:43] <humphreybc> count
[02:43] <Red_HamsterX> Look at its help text and figure out how to apply it.
[02:44] <Red_HamsterX> help() renders the object's docstring.
[02:44] <Red_HamsterX> Just so you know where it's pulling that data from.
[02:45] <Red_HamsterX> The docstring is the unassigned string at the start of any function/class/whatever.
[02:45] <humphreybc> okay, so, on Hello World I ran sentence.count("o") and it returned 2
[02:45] <humphreybc> so it's workiung
[02:45] <humphreybc> but then apparently it only takes at most 3 arguments
[02:45] <Red_HamsterX> It's morning in Austrailia/New Zealand, right?
[02:46] <humphreybc> 1:46pm
[02:46] <Red_HamsterX> Ah. Later than I thought.
[02:47] <humphreybc> so do I have to create a variable called "vowels" that's a list of the things I want to find?
[02:47] <humphreybc> and then run sentence.count(vowels) ?
[02:47] <Red_HamsterX> No.
[02:47] <Red_HamsterX> It doesn't work that way.
[02:48] <Red_HamsterX> You'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] <humphreybc> okay
[02:49] <humphreybc> so firstly I should go sentence.lower()
[02:50] <humphreybc> I 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_HamsterX> You could.
[02:50] <humphreybc> or could you put all of that into one statement?
[02:51] <Red_HamsterX> Variables in Python are not immutable, as they are in math or languages like Haskell.
[02:51] <Red_HamsterX> You could do that, too.
[02:51] <Red_HamsterX> ''.count() + ''.count()...
[02:51] <Red_HamsterX> x = ''.count('a')
[02:51] <Red_HamsterX> x += ''.count('e')
[02:51] <Red_HamsterX> return x
[02:51] <Red_HamsterX> That's probably the cleanest way to write it.
[02:52] <Red_HamsterX> (Barring the advanced technique I mentioned before)
[02:52] <humphreybc> http://paste.ubuntu.com/412871/
[02:53] <Red_HamsterX> You could return it directly, if you really wanted to save a line.
[02:53] <Red_HamsterX> But there's still a problem.
[02:53] <Red_HamsterX> sentence.lower() returns a new string.
[02:53] <Red_HamsterX> It doesn't modify sentence.
[02:53] <Red_HamsterX> Also, variable names like 'x' are icky.
[02:53] <humphreybc> so i have to assign it
[02:54] <humphreybc> sentence = sentence.lower()
[02:54] <humphreybc> return = sentence.count("a") + sentence.count("e") + sentence.count("i") + sentence.count("o") + sentence.count("u")
[02:54] <humphreybc> like that?
[02:54] <Red_HamsterX> You can assign it to 'sentence', but that's commonly frowned upon for non-trivial code.
[02:54] <Red_HamsterX> So it's a good habint to avoid.
[02:54] <humphreybc> right
[02:54] <Red_HamsterX> habit*
[02:54] <humphreybc> so assign it to say, S
[02:54] <humphreybc> and then run count on S
[02:54] <Red_HamsterX> Yeah, that works.
[02:55] <humphreybc> ok
[02:55] <Red_HamsterX> Don'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] <humphreybc> k
[02:56] <Red_HamsterX> return len([v for v in sentence.lower() if v in ('a', 'e', 'i', 'o', 'u',)])
[02:56] <Red_HamsterX> You'll figure out how it works eventually.
[02:56] <humphreybc> righto
[02:57] <humphreybc> okay i've got all the ones in this except the count_words() function
[02:58] <humphreybc> so I have to count something and make it split on a white space
[02:58] <Red_HamsterX> Look at the dir() result again.
[02:58] <Red_HamsterX> I assume you can consider all input sane.
[02:58] <Red_HamsterX> So you won't have tabs or non-space delimiters.
[02:58] <humphreybc> yeah
[03:00] <humphreybc> i've done something like this before
[03:00] <humphreybc> i'm just trying to find where
[03:03] <humphreybc> so I use split
[03:05] <humphreybc> but i don't understand how
[03:07] <humphreybc> i've got S = sentence.split()
[03:07] <humphreybc> then count(S) ? or S.count(S)? S.count() ?
[03:10] <Red_HamsterX> count() isn't what you want.
[03:10] <Red_HamsterX> help(len)
[03:11] <humphreybc> oh
[03:11] <humphreybc> that did it =]
[03:11] <Red_HamsterX> You might want to do sentence.strip().split(), just in case there's a leading or trailing space.
[03:11] <humphreybc> knowing the library of builtin functions is pretty helpful
[03:12] <Red_HamsterX> And actually iterate over the tokens to discard empty ones.
[03:12] <Red_HamsterX> But that's not necessary here.
[03:12] <humphreybc> right i'm going to get something to eat
[03:12] <humphreybc> then i'll start on part 3
[03:12]  * humphreybc thinks that programming might not be for him
[03:13] <Red_HamsterX> It's your first exposure.
[03:13] <Red_HamsterX> Most people find thinking in a C-like mindset hard to do initially.
[03:13] <Red_HamsterX> If you've got a math background, look into Haskell.
[03:18] <humphreybc> it's not the first time, i did PHP and HTML in high school, then last year I did java
[03:18] <humphreybc> i've never really been that good at it
[03:18] <humphreybc> i understand the logic but I can just never, ever remember syntax or methods of doing stuff
[03:19] <humphreybc> maybe as I write more stuff i'll
[03:19] <humphreybc> i'll remember the syntax better*
[04:18] <Red_HamsterX> The 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_HamsterX> When writing code, try to focus on making the logic obvious.
[04:19] <Red_HamsterX> That may help you to think things through and make it all easier to understand.
[09:55] <ubuntujenkins> morning all
[11:26]  * ubuntujenkins hates python when it doesn't work
[11:56] <ubuntujenkins> back working in english and not siberian
[11:57] <ubuntujenkins> serbian or how ever it is spelt
[17:41] <ubuntujenkins> hello all
[18:18] <dutchie> o/
[18:36] <dutchie> is there anything I ought to do before my battery dies?
[18:50] <ubuntujenkins> hello dutchie not as far as i know. You could reinvent the wheel if you have time :P
[18:51] <dutchie> hmm, 3 hours 25 and food in 10 mins
[18:51] <dutchie> I think not
[19:22] <ubuntujenkins> Red_HamsterX: ping
[20:05] <Red_HamsterX> Hi, ubuntujenkins.
[20:07] <ubuntujenkins> hello 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 silly
[20:09] <ubuntujenkins> also there appears to be some progress on the bug i filed with python
[20:13] <Red_HamsterX> Setting the variable's value to 1 is unnecessary
[20:13] <Red_HamsterX> except ...:
[20:13] <Red_HamsterX>  short_code = os.environ.get('LANG')
[20:14] <Red_HamsterX>  if not short_code: raise (some custom error)
[20:15] <Red_HamsterX> Other than that, it should work.
[20:18] <popey> can someone get ben to ping me when he's online
[20:23] <ubuntujenkins> Red_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't
[20:23] <ubuntujenkins> popey: i will if i am still up
[20:24] <ubuntujenkins> brb changing language
[20:27]  * ubuntujenkins ubuntu serbian is intersting
[20:32] <Red_HamsterX> Is it significantly different from, say, Russian?
[20:32]  * Red_HamsterX doesn't know anything about Serbian.
[20:32] <ubuntujenkins> just the person with the code changed to
[20:33] <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 module
[20:33] <ubuntujenkins>             
[20:33] <ubuntujenkins>         if not short_code:
[20:33] <ubuntujenkins>             short_code = os.environ['LANG']
[20:33] <ubuntujenkins>         applied_short_code = short_code
[20:33] <ubuntujenkins> I get an indentaion error i changed the location of the not and removed one line .not my day as usual
[20:36] <ubuntujenkins> i haven't looked at russian I just navigate by knowing where to find stuff
[20:45] <ubuntujenkins> aaahhh spotted the indentaion error but now i get UnboundLocalError: local variable 'short_code' referenced before assignment
[20:47] <ubuntujenkins> i had this this morning which is why the short_code = 1 was there
[20:51] <ubuntujenkins> Red_HamsterX: sorry please can you help me
[20:57] <Red_HamsterX> Sure.
[20:57] <Red_HamsterX> Is the code current or can you paste the function?
[20:59] <ubuntujenkins> Red_HamsterX: let me paste it
[20: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 module
[20:59] <ubuntujenkins>             #short_code = 1
[20:59] <ubuntujenkins>             if not short_code:
[20:59] <ubuntujenkins>                 short_code = os.environ['LANG']
[20:59] <ubuntujenkins>         applied_short_code = short_code
[21:00] <ubuntujenkins> http://pad.ubuntu-uk.org/ZpWtZE8opJ
[21:02]  * ubuntujenkins etherpad should do python highlighting
[21:02] <Daviey> ubuntujenkins: raise a bug :)
[21:02] <ubuntujenkins> Daviey: where do i file it?
[21:02] <ubuntujenkins> and against what ubuntu uk team?
[21:13] <Red_HamsterX> ubuntujenkins, the problem is that the 'if' occurs before the short code is assigned.
[21:13] <ubuntujenkins> thats why i have short_code =1
[21:13] <Red_HamsterX> When the assignment fails, short_code isn't left in some half-declared state.
[21:13] <Red_HamsterX> You can assume it was never set when entering the exception handler.
[21:13] <Red_HamsterX> So just drop the 'if' entirely.
[21:14] <Daviey> ubuntujenkins: will talk later, recording a podcast atm
[21:14] <Daviey> and humphreybc is supposed to be our guest
[21:14] <Daviey> but he's offline :(
[21:14] <ubuntujenkins> ok Daviey have fun
[21:15] <ubuntujenkins> thnaks Red_HamsterX that makes sense obvious as usual
[21:15] <Red_HamsterX> ubuntujenkins, 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:16] <ubuntujenkins> and as the variable is not assigned the if test isn't needed.
[21:16] <Red_HamsterX> Yep.
[21:16] <ubuntujenkins> detail is good helps me to understand
[21:16] <Red_HamsterX> Python, unlike, say, Java, uses something very much like a dict to manage variables.
[21:16] <ubuntujenkins> thanks, i will do a release tonight to the ppas, and upload a cd tomorrow
[21:16] <Red_HamsterX> You could think of each assignment like the following:
[21:16] <Red_HamsterX> object = {}
[21:17] <Red_HamsterX> #Assign to 'short_code':
[21:17] <Red_HamsterX> object['short_code'] = 5
[21:17] <Red_HamsterX> The dictionary has no value for the key until it's actually set.
[21:18] <ubuntujenkins> ok makes sense thank you
[21:21] <ubuntujenkins> dutchie: !!!
[21:22]  * ubuntujenkins hopes dutchies battery hasn't died
[21:33] <Daviey> anyone know where humphreybc is?
[21:34] <ubuntujenkins> Daviey: I am keeping an eye on facebook to see if he comes on, i will shout at him if i see him
[21:34] <ubuntujenkins> Daviey: he could have got daylight savings utc an gmt messed up
[21:54] <Daviey> ubuntujenkins: thanks
[22:12]  * ubuntujenkins has found someone else who has the same locale big we have :-)
[22:12] <ubuntujenkins> *big
[22:12] <ubuntujenkins> ***bug
[22:16] <ubuntujenkins> brb swapping to english
[22:19] <Red_HamsterX> English is overrated.
[22:19] <Red_HamsterX> Needs more Turkish.
[22:19] <ubuntujenkins> its easier to use rather than navigating by memory or icons
[23:01] <ubuntujenkins> night all