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