« first day (895 days earlier)      last day (4056 days later) » 

Zac
3:11 AM
Hello
 
Zac
3:40 AM
anyone about ?
 
4:12 AM
Hello anyone here
0
Q: SSL throwing error 185090050 while authentication via Oauth

NishI am trying use Google's Oauth to connect to Google adsense and am getting this error. Any clues to fix it? Anyone has faced such a issue before in python? Traceback (most recent call last): File "get_all_saved_reports.py", line 56, in <module> main(sys.argv) File "get_a...

 
 
2 hours later…
6:16 AM
morning
 
 
2 hours later…
8:12 AM
it's great when a talk is both entertaining and informative pyvideo.org/video/1779/pythons-class-development-toolkit
first time is see the legendary Hettinger dude
 
hey ppl ! how u all doing today ... i was wondering if i have a huge file of numbers and if i have to do a binary search on it .. how would i approach it
 
@Sandy what is huge?
 
umm i mean anything huge ... something that will run out of memory if i have to read it into a list
maybe i can use generator? but how would i approach this kind of a situation
 
8:27 AM
can't you do a line-by-line search on the file?
"for line in f"?
 
it wont be efficient if i have to find all pairs that sum upto X .. what i was thinking is while looping i will take the first element as the key and look for X-key in binary search .. so the run time complexity of O(NlgN)
and for any comparison sort the runtime is omega(NlgN) is the lower bound .. so that will make it a good algorithm
 
sorry, am not familiar with these things
 
hmm .. can i post a question on that :S i am so scared of the community these days :D
 
don't be scared
search first though
 
sure...
 
8:34 AM
whenever you are not sure, apply this philosophy: docs.python.org/2/glossary.html#term-eafp
although this philosophy will be highly appreciated by the more experienced users: docs.python.org/2/glossary.html#term-lbyl
 
cool the file object has a seek method with which i can jump to any line number but wonder how would the pointers work ... i mean i need one pointer that runs line by line and i need another pointer that look for X-key to complete the pair
brb
 
9:10 AM
Morning everyone
 
hi @JosKraaijeveld
 
9:30 AM
@Sandy - just a silly morning guess: can you open the file twice, once in reverse, and keep your upper and lower bound pointers in separate files?
 
@JosKraaijeveld thanks for the suggestion i need to explore the options .. i have call now .. so i will be back in another half an hour
 
Alright! Good luck :)
 
10:22 AM
happy pentacoast (i think) and morning chaps
 
10:33 AM
hey guys!
i am new to python and i need some help
 
hey @AbdulRahman
 
i am using eclipse with pydev for python
i have programmed quite a lot with java before and want to try out python
since functions in python dont have arg types specified on them, i cant use code assist much
 
yes
 
i was wondering if i can get around this situation so that at least the IDE knows which args are what
 
I must be old fashioned for still programming in VI, can't help you there ;(
 
10:36 AM
like by just using casting or some technique so i can use code assist properly
is there a way to cast in python?
 
ofcourse
float(var)
 
is something like this valid?
SomeClass(var)
 
you have to do that when printing a string with numerical function anyhow, yielding something like print "Value is "+str(variable)
hmm, I would think so altho I myself have only casted to the standard types before with Python
 
is there any other way to cast?
 
that's not really a cast just like you would cast in C, it's more like using a constructor if i'm not mistaken
float('2') works because its constructor can take a string as a parameter
 
10:41 AM
oh ok
 
hmm, I must really stop assuming things based on C experience
 
int a = 2;
void *b = a;
can't be done in python
 
makes the language 'easier' to understand for most I guess, especially when you get double pointers and references thrown in there
 
I really wish python lists would have indexes without having to create my own iterator over them... it feels so redudant to first create an iterator to just calculate the step size (in C it would be just float interval = list[0][0] - list[1][0];
 
10:51 AM
thanks Ben and rxdazn
 
@BasJansen I don't understand this. Can you expand a bit. Don't lists already have indexes... li[n]?
 
you cant adress the index (in your case do interval = bla bla followed by n+= interval)
to skip elements, without creating your own iterator
 
still am not understand sir, sorry
 
ie
list q
for j in q:
perform some if statement:
j+= value
is not possible (without the iterator)
just feels redudant
 
thanks
I think this is a good Q, making the downvote strange:
0
Q: How does sqlachemy query method work?

CarlLeeI am learning sqlachemy, I'm relatively new to Python. When I read its documentation, I saw this kind of usage, for example: query.filter(User.name == 'ed') Wouldn't Python evaluate the expression User.name == 'ed' and then pass the result, which is a boolean, to query.filter method? How ...

 
11:02 AM
agreed
 
nice answer too :)
 
11:33 AM
not halfway through the day yet, but this guy has already reached rep cap: stackoverflow.com/users/100297/martijn-pieters?tab=reputation
 
he's scary but nice ;P
 
12:22 PM
hey guys
 
hi
 
Already got your max daily rep it seems martijn :P
 
bloody friday :/
 
euh... i just overwrote my old message, woops
 
12:24 PM
@ColinO'Coal what's that?
 
It's vodka plus tomato juice. No, wait, that's a bloody mary.
 
a bloody x-day is each day that I'm not liking
 
but... but... its a holiday!
sort of
 
Not the kind of holiday you throw confetti for, however.
Also, it's a full moon out, so that's bad luck right there.
 
lies! full moons are good luck ;)
 
12:38 PM
Depends on where you are on the planet. Interaction of gravitational waves and the Earth's magical leylines, that kind of thing.
 
never really bothered thinking about that, I just like the view shrug
 
Over here, it tends to cause broken dishes, uncautious drivers, and high tide.
 
Martijn you here?
doing var = int((x-float(y)/z) will make var of type int yes?
 
yes
 
for some reason doing next(islice(list,var,var),None) complains about it not being of type int
 
12:42 PM
let's see. When I type type(int((2-float(3)/4))) into my interpreter, I get <type 'int'> back. So I'm going to go with "yes".
 
it was semi-rhetorical leading up to second part
 
what is islice?
 
islice is from itertools. "Return an iterator whose next() method returns selected values from an iterable."
 
I hate holidays
feeling so old ^^
 
12:44 PM
Not me. My employer tends to celebrate holidays by letting everyone leave 1 hour early :-)
 
@Tshepang what that line does is basically throw away the next (var) elements of the list and goto the element after it
 
am reading up on it, thanks
 
i use it to quickly jump to an element of interest
in a list
and not evaluate all the nested lists of non-interesting elements
 
@BasJansen, even if I plug floats into islice, it doesn't cause an exception. Strange. next(itertools.islice([1,2,3], 1.5, 1.5), None)
 
ValueError: Indices for islice() must be None or an integer: 0 <= x <= maxint.
must be something else about the function call then
digs
 
12:49 PM
Maybe my version is more permissive than yours. Are you on 3.x? I'm on 2.7
 
2.7 here as well
also my q is an iter
so it would be more comparable to test=[1,2,3]
q = iter(test)
and then next(itertools.islice(q,var,var),None)
hmm i think i see the culprit
            RT_step = int((low_time-float(j[0]))/RT_interval)
            print "Step is "+str(RT_step)+" and type is "+ str(type(RT_step))
 
In any case, shouldn't it be islice(q, var, var+1) if you want to get a single element?
 
Step is -64 and type is <type 'int'>
dont want a single element, i put the iterator at the end of the slice
 
@Tshepang: For the next(islice(iterable, n, n), None) trick, scroll down to the recipes part of the itertools docs.
The consume recipe.
What it does is slice iterable[n:n] which has the side effect of skipping n elements.
 
stop making me hungry
:P
 
12:53 PM
@Kevin: No, it is not var + 1.
 
:)
 
@BasJansen: I am sitting upstairs with easter buns being baked downstairs.
The smell....
 
!!!!!
go nom
It's still 1 of the neatest recipes i'v seen so far in Python ;)
(from my limited experience so far)
 
@BasJansen how limited is it?
 
@Kevin: islice(q, var, var+1) would return the element at position var, not just skip to that point. The point of the recipe is to just advance the iterable.
 
1:00 PM
@Tshepang 1.5 week?
 
I see. The purpose of the line was not apparent to me until I read the recipe.
 
so you first started using Python ~10 days ago?
 
yep
 
wow!
u make me feel like an old-timer
 
I saw Py being used a lot at my old department at the UvA but I only decided to 'try' it recently to make some scripts to extract data from raw data
in such a way that other colleagues that dont want to use cygwin (for c programs) could also use it
 
1:10 PM
oooh, I get to eat the Hot Cross Buns now!
is off for lunch!
 
1:26 PM
Hacker News has a post on a Minecraft clone in 580 lines of Python.
Cue feeling of superiority: Python does in 580 lines what Java does in 10,000.
(Although in reality, it's an unfair comparison, since Minecraft has a zillion bells and whistles that this clone does not have)
 
Still though, I find that amazing
 
Yes, I agree. If I attempted to clone that Minecraft clone, I'm certain it would take me thousands of lines.
 
1:56 PM
bloody browser close button
 
2:19 PM
Hi Martin n Kevin
 
Hello.
 
I want some clarification on "as" in "except ZeroDivisionError as e:"
 
It stores the exception in a local variable.
So the thrown exception can now be referred to via e.
 
so, here in "e"?
like we have e.printstacktrace in java?
 
You can give it any legal name.
 
2:22 PM
It's roughly the same as "catch (Exception e) { } in Java
 
except ZeroDivisionError as zdexception
 
But with the optional naming/using of it
 
aha...
 
Older python versions used a slightly more confusing syntax, instead of as you used a ,.
That still works in Python 2 but is deprecated and discouraged.
 
okay!
 
2:24 PM
You can catch multiple exceptions with except Exception1, Exception2 as caughtexception:
where you specify a tuple of exceptions (with or without () parenthesis).
the old syntax requires you to use parenthesis for the exceptions list.
and that was often forgotten, leading to strange errors.
 
ok..
 
Python exceptions do not have a .printStackTrace() method; use the traceback module to explicitly print stack traces instead if you need that functionality.
 
Hey guys i'm struggling with the idea of how i would, search through 'dyhomng' to see if i can spell the word 'dog'. I have this sort of pseudocode
keep going while theFirstLetter of dog does not equal firstLetter of random
when it is, do to next didget of dog, and remove the first letter of dog from random
I geuss i could use itertools for random then just keep cycling through it, within a while/for loop controlling which letter of dog i would be on
Going to write this into a question,
 
2:40 PM
If this isn't homework, and you're free to use whatever modules you like, I suggest using collections.Counter.
 
Nah it's not home work, more of i would like to know how to do this so i can implement it into a program i mat need to do,
Will that a look at that, thanks.
 
from collections import Counter

#returns true if you can take some letters out of string `a`
#and use them to spell the string `b`
def contains(a,b):
    aCounter = Counter(a)
    bCounter = Counter(b)
    for key in bCounter:
        if key not in aCounter or aCounter[key] < bCounter[key]:
            return False
    return True

print contains("dyhomng", "dog")
#output: True
This function essentially iterates through the unique letters in "dog", asking, 'does "dyhomng" have as many d's as "dog"? does it have as many o's as "dog"?' ...Etc
 
Thanks kevin i created a question here, stackoverflow.com/questions/15705546/… if you want to copy paste it there for some rep thanks :)
 
Nah, my chat room work is pro bono.
@MartijnPieters' answer makes very interesting use of the truthiness of empty dicts. I learned something today :-)
 
Indeed it is :) thanks alot.
 
3:38 PM
hello, one an all
 
Hello.
 
hihi
 
hello there, @bernie
 
@Kevin and @MartijnPieters thanks for that info on counters, amazing what you can find out if you ask, would have taken me ages of doing nested statements otherwise!
 
The Python library is full of hidden gems.
 
Zac
3:55 PM
hello
I want to check if a global variable flag is true and if not return the function before it does stuff
if (greet == true):
continue
else:
return
sorry still can't work out how to get that to format properly
it looked indented to me
anyway that doesn't work
global greet
if (greet == true):
    continue
 
I don't think continue does what you think it does. Maybe you should try pass instead...
Or better yet, just do:
if not greet:
    return
 
Zac
ah yeah that is better
 
BTW, if myVariable == True: is a little verbose. It's easier just to write if myVariable:
 
Zac
I guess but I thought python was all about making things readable
does that have a performance cost ?
 
Yes, it adds needless bytecode and tests.
 
4:01 PM
In my opinion, if myVariable is more readable than if myVariable == True
 
Note that True and False, like None are singletons
so you can test for myVariable is True too.
But it is redundant.
because the if statement evaluates the expression, then calls bool() on it.
and then if the result of that is True, it'll execute the block, otherwise it won't.
It is very pythonic to leave the boolean truth testing to the if statement.
Adding == True only adds noise.
 
Zac
ok great to this loop for example
if ((randomGreet) and not (inUserList)):
is faster than this one:
if ((randomGreet == True) and (inUserList == False)):
worth bearing in mind
 
The parenthesis are, again, redundant.
if randomGreet and not inUserList:
is clean, and very clear.
 
Zac
ok
 
You should aim for readability first.
 
Zac
4:06 PM
do the parenthesis also factor into performance ?
Yeah I was trying to do that
 
Readability counts -- Tim Peters, Zen of Python
The parenthesis are removed by the parser.
 
Zac
I personally thought if something equals true is more humanly readable that if something
^than
 
it adds noise.
You padded the line with extra tests that mean nothing, really.
and and or and not are all boolean operators.
They immediately tell me you are doing boolean comparisons.
no need to add == True or == False.
 
Zac
can I connect to this chat using an IRC client ?
 
they actually introduce potential for error.
but I'm not sure what it's current state is.
no commits in 3 years..
 
Zac
4:11 PM
I see, because I'm writting my own personal greeting bot in python through IRC I could have demo'd it :)
its pretty finished now
I'm quite proud, took me about 3 days work with the help of people here
 
4:28 PM
def checkWord(answer):
myFile = open("words.txt","r")
for eachLine in myFile:
if answer in eachLine:
return True
return False
sorry
And it is meant to search for that eact words
except it is searching to see if that word is within anyof the words as well not just the whole word.
 
def checkWord(answer):
    myFile = open("words.txt","r")
    for eachLine in myFile:
        if answer in eachLine:
            return True
    return False

print(checkWord("agnat"))
 
def checkWord(answer):
    myFile = open("words.txt","r")
    for eachLine in myFile:
        if answer in eachLine:
            return True
    return False
Did I guess your indentation properly? :-)
 
Yes sorry
just when i copy pasted it lost it
i was going to edit it but you beat me to it
 
Yeah, the markup is a little tricky.
Took me a few days experimenting in the Sandbox before I got the rules down.
 
Haha thanks
I'll be sure to use that
 
4:31 PM
So, does words.txt have a single word per line?
 
yes
 
you might try, if answer == eachLine.strip():
 
It's like this but lots more of them
 
that will check for exact equality, minus newlines
 
Awesome thank you
 
4:34 PM
yea, if answer == eachLine should do it. if you use in, it literally checks if answer is contained in eachLine
 
Cool makes sense
not sure how i didn't see that
 
Yes, that's right. You only need strip if you're iterating through the file.readlines() list, since that leaves the newlines in.
 
return any(answer in eachLine for eachLine in myFile)
Will return True as soon as a answer in eachLine evaluates to True.
it'll return False if there are none.
 
awesome
 
In this question, the OP falls prey to a "gotcha" caused by the existence of a datetime module, and a datetime object inside that module.
I try to avoid this in my own code by having different capitalization between my files and classes. Ex. point.py contains a definition for the Point class.
But I'm not certain this is the best strategy. Any opinions?
 
4:49 PM
Usually that is the best strategy.
Tim Peters used lowercase for the types in that module to mirror the other built-in types.
int, set, list, ... date, timedelta.
 
Is there a neater way to create this loop until the user wishes to stop?
x = '1'
while x != 'stop':
    text = chooseLetters()
    userAnswer(text)
    x = input("Would you like to play again? Enter 'stop' to stop! :")
@JohnMerlino Hey
 
Is there a stackexchange site that allows people to grade your code from F to A?
 
Catch KeyboardInterrupts maybe?
 
Hmm, if only we had a do...while loop
@JohnMerlino, the closest thing would be Code Review, although they just make suggestions for improvement rather than give letter grades.
 
@Ngenator Sounds interesting i'll have a look
 
4:54 PM
@jack: You could use a break instead perhaps.
 
while True:
    text = chooseLetters()
    userAnswer(text)
    if input("would you like to stop?") == "stop":
        break
 
Exactly.
 
So break just stops the program?
 
break stops the innermost loop you are in, IIRC
in this case, the while True:
 
Omg how have i not known about this
I've been thinking there must be something like this for ages!
argh
thanks!
 
4:57 PM
The other one you want to know about is continue
which ends the current iteration early and moves to the next iteration.
These work in for loops too
 
@MartijnPieters So datetime is lowercase to mirror other built-in types. But then, why is the calendar.Calendar type upper case? Different module author? Or is datetime more built-in-like than Calendar somehow?
 
Calendar is a python class
datetime is a C type.
See the sets module.
That was added before the set time was added to the language.
the module contains a sets.Set class.
but yes, also different authors.
 
Ah, that explains this interpreter output then:
>>> datetime.datetime
<type 'datetime.datetime'>
>>> calendar.Calendar
<class 'calendar.Calendar'>
 
the distinction is fading.
but basic, functional types in Python are all lowercase, so the datetime types are too.
a Calendar does not qualify, it is built on top of primitive types.
 
I just stumbled upon the document, Unifying types and classes in Python 2.2. So I guess it's been fading for some time.
 
5:05 PM
New-style classes, now the default in Python 3, have been inching in version by version.
Wow, 1000 lines of changelog for 2.7.4 RC1: hg.python.org/cpython/file/cd63c8928528/Misc/NEWS
 
Incidentally, I dislike it when something's name contains the descriptor "new". Ex. The new adventures of Superman certainly was new... 47 years ago!
 
That is why you no longer refer to them as new in Python 3. :-)
 
It's like in the 90's when everything cool and futur-y had "2000" tacked on the end.
 
But in Py 2 it is relevant, because the old style is still there.
 
That's an acceptable use then. As long as there's no chance of us introducing a third even newer style of classes into python 2.
 
5:11 PM
No way, jose.
Python 2 is at the end of the line.
No new 2.x releases beyond 2.7.
 
Ok, so we'll have 2.7.9, 2.7.99, 2.7.999... All the way to the end of time :-)
 
> The Python 2.7 series is scheduled to be the last major version in the 2.x series before 2.x moves into an extended maintenance period.
and from the 3.2 description:
> Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only.
 
From this code
''.join(random.sample(s,len(s)))
It's code to randomize the order of a string ie : 'abcd' >> 'cbda'
what is the '' at the start doing, i can't get my head around this one,
 
"".join(seq) is a common recipe for turning a list of characters seq into a string.
 
Yeah, one of my favourites why I like python so much ^^.
 
5:22 PM
Ex. "".join(['c', 'b', 'd', 'a']) becomes 'cbda'
 
Hey guys, I have been using KomodoEdit IDE for Python. It is a nice IDE, but I would like to know what you guys prefer.
 
I use the basic one, works fine for me :/
 
@jack idle?
 
Yes
The lower case j in my name is annoying me but i cannie change it :(
 
@jakebird451 PyCharm
 
5:27 PM
hmm... I am not too much of a fan for IDLE. No split view, and very limited features.
 
PyCharm is mostly for web stuff though. I started off using Aptana
 
@Ngenator I figure you like using the Django features?
Looks nice.
Good price as well
 
@jakebird451 Definitely. I haven't bought it for myself yet, I use it at work and still have some time left on the license for my school
 
I'm still using Aptana/Eclipse ... but sometimes it's more easy and convenience to use a good editor like Sublime2, Emacs, or something else :/.
IDEs didn't support mostly the bandwide of libraries and tools (paver, nose, code-checker, etc. pp) in that way, that the IDE will to the stuff for you.
So a good editor and still opend terminal/cmd.exe works perfectly at the most time for me.
 
@ColinO'Coal Emacs, well done. I used that for C++ back in high school.
I remember writing out all the short cut commands in a notebook for quick reference.
 
5:37 PM
Oh I hate Emacs and would never use it - not to mention to take it with a pliers ^^.
But I didn't want to leave it out in my enumeration, because it's really well-known.
I like GUI tools with a good look'n'feel. Emacs has never bid that for me ;).
Before I become software developer, I was a mouse pusher purist par excellenge. I like good looking user interfaces/surfaces.
 
@jakebird451 As a starter to python would you reccomend me to continue with IDLE, or pick up something like Komodo?
 
abstain from IDLE
 
@ColinO'Coal I must agree
@jack Eclipse would probably be a good choice, or Komodo Edit.
 
it comes out of the box but it's horrible
I would recommend to start with just a good text editor (with syntax highlighting) and a shell.
 
almost like notepad++?
I'm installing komodo edit to have a look atm,
 
5:43 PM
Eclipse is rather bloated and may not look as good as the other environments, but it is well known in the industry and constantly maintained.
 
The best way to learn to analysing and interpreting python's
**stacktraces**.
yeah, notepad++ is quite a good choice
 
@jack It is like notepad++ for a LOT of languages. If you purchase the actual komodo, it is a full IDE with debuggers. But it is about $300 I think
 
Wow, bit much for a student tbh
lol "starting at just 295$"
thats like a month of food
 
@jack Yea, which is why I use the free komodo edit
I like using komodo edit for server stuff since I have to run the application on the server.
But for locally run applications, it can be annoying not having a debugger and run commands.
Which is why I am looking for an IDE the rest of the python community enjoys.
It looks I will try out Eclipse again, as well as pyCharm.
 
Hmm in komodo how would i just run my module?
Can't seem to find it
 
5:50 PM
I run things via terminal the old fashion way for komodo. python main.py
 
Zac
Just ran into a self created bug using
 
bloody browser close button *grrr*
 
ah mac user i'm guessing
 
Zac
 if "play" in message.lower():
also triggers if the string is a substring
how do I get it to only trigger if equal ?
 
5:52 PM
use ==
 
Zac
that simple huh
 
yarp
 
welcome to python
^^
 

« first day (895 days earlier)      last day (4056 days later) »