« first day (964 days earlier)      last day (3969 days later) » 

6:52 AM
saw this on some newsletter - might be of some use: github.com/CamDavidsonPilon/…
 
Morning
 
heya @max
 
 
1 hour later…
8:27 AM
Hi
 
Hello there
 
8:40 AM
Lol, saw martijn's name and thought he was here
Then I realised that was 9 hours ago :(
 
:P
 
stackoverflow.com/questions/16957542/… Have I misunderstood the questin?
Hmm, it got an upvote, maybe I'm right
 
I think he is talking about the difference between creating and instance of a class then calling its atributes versus using setters and getters
So you did answer his question but not fully i think
 
8:55 AM
"Sorry. I meant object's attributes. I have corrected the question"
Classes are objects :p
 
9:12 AM
oh lol
 
9:26 AM
cabbage guys
 
cabbage @PeterVaro
 
9:51 AM
hey :-)
 
I'm only curious: what are the most popular (based on user number), the most complex (based on the problem it is solving) and the most active (based on developer activity) full-blown applications in 2013, which are 100% written in python?
I was searching for this, but old threads were found or not relevant matches
 
i dont know
 
Zac
Hey my python socket thread pauses on socket.listen(1) if I want to close the program while it is doing that is there a way to interrupt it ?
 
HELLO!!!!!
 
cabbage
 
10:01 AM
cabbage to you
 
10:36 AM
Is it me or is pip search broken?
It always dies with an ExpatError, presumably because it's getting back a blank response from PyPI.
 
 
2 hours later…
Zac
12:43 PM
Anyone know how to terminate a blocked call to socket.listen(1) ?
 
Before calling listen, call settimeout to specify how many seconds should elapse before the operation times out.
 
ctrl - C ? *joke*
:-P
 
Zac
the problem with setting a timeout is I don't want it to time out, but rather to go on listening. The issue is the python interpreter crashes when I close the interpreter. I can't use ctrl- C either for similar reasons, the python interpreter is running on a chat client
I might be able to set the time out to a short time and put the listen call in a loop with an exit flag
that might work
but it doesn't seem very elegant
 
Eureka! I was just about to suggest that :-)
 
Or maybe using a thread?
 
Zac
12:50 PM
it is already in a separate thread to main
so that it doesnt' block other execution, the problem only occurs when I want to close the program while it is still listening
 
ok clear.
 
Zac
I can't work out if it is blocking on the s.listen(1) command or the conn, addr = s.accept() command anyone know ?
 
Why don't you ask this question on stackoverflow? Probably you will get a lot more exposure
 
Seems like you could figure out which is blocking, quite easily.
print "starting to listen..."
s.listen(1)
print "listening complete."
print "starting to accept..."
conn, addr = s.accept()
print "accepting complete"
If the most recent message in your console is "starting to listen", then listening is blocking. If the most recent message is "starting to accept", then accept is blocking.
In any case, what does it matter which one is blocking? If you settimeout and put the whole thing in a while loop with an exit flag, who cares which one blocks?
 
1:12 PM
Immutable objects are so cool.
 
Counterpoint: immutable objects are dumb.
I want to append to strings, darn it
Immutable objects are useful in writing functions that have no side effects, though. Good for maintainability.
 
Zac
@Kevin I have the following :
try:
s.bind(sa)
s.listen(1)
except socket.error as msg:
print "socket error"
s.close()
s = None
continue
break
if s is None:
print 'could not open socket'
sys.exit(1)
conn, addr = s.accept()
print 'Connected by', addr
if I put the accept or listen in a while loop I guess I'll need an if statement to break it when it returns a connection rather than no connection. I guess I need to know the return value if there is no connection vs a connection so I can test that
how do I format that
		try:
			s.bind(sa)
			s.listen(1)
		except socket.error as msg:
			print "socket error"
			s.close()
			s = None
			continue
		break
	if s is None:
		print 'could not open socket'
		sys.exit(1)
		conn, addr = s.accept()
		print 'Connected by', addr
oops tab on conn line is wrong
should be indented
 
You mean this line? conn, addr = s.accept()
If you indent that, it's a syntax error.
 
Zac
yep
ok hold on I'll have to go back and run this badboy
 
or do you mean, un-indented? Are we moving it left or right?
 
Zac
1:22 PM
left
 
ok
 
2990 rep, lol
I had 3k then someone removed up vote :P
 
@Kevin -- I was just reading the implementation of str.rsplit
It can be super efficient because strings are immutable -- No copy of the actual string data is necessary.
 
Night guys
 
If you're asking how to find whether a connection was made, blocking functions raise a timeout exception if the timeout period has elapsed before the operation has completed.
 
Zac
1:25 PM
ah ok
so I'll put a continue statement in the except part for that accept() method try block which will allow it to loop I guess, but then how to I break the loop when it returns with a connection ?
 
Would break work?
 
Zac
I have
	while(running):
		try:
			conn, addr = s.accept()
		except:
			print "timed out"
			continue
running will be my shutdown flag
but I need it to break when s.accept doesn't error
so break after that line
will work right ?
 
Yeah
 
Zac
only one way to find out
thanks Kevin
 
1:44 PM
I know I should learn (and not be annoyed), but darn it why can't the OP's just upvote/accept rather than just "Thanking" in the comments. grr...
 
awwww.... you okay Andy?
 
while(running): - please remove those ugly parentheses
and NEVER EVER use a bare except: block.
you probably want except socket.error: there
 
No.
 
@AndyHayden -- How about an upvote?
I've got 40 votes for the day -- Surely you can have one of them :)
@ThiefMaster -- I don't actually mind the parenthesis, but I agree about the bare except.
 
Would it count as a voting ring if we started a chat room for people who got "thanks" comments but no accept?
 
1:49 PM
Hang on - you mean this room isn't for the purpose of garnering upvotes from one's peers?
 
However, it might create an odd incentive to get not-accpeted-but-thanked answers, if the pity upvotes give more rep than an accept would
 
@JonClements are you watching Hannibal?
 
@PeterVaro Should I be?
 
@JonClements Wait -- It's not? Oh man ... I've been going about this completely wrong ...
 
I think it is just too late in the day for work... too much sun outside. Thank you for the pity votes :)
 
1:50 PM
@Kevin It would be somewhat fishy for sure. But you could ask on meta.
 
@mgilson I know - it sucks. I was going to point out that stackoverflow.com/questions/12726373/… hasn't got to 20 yet and I haven't had a badge in a while...
 
The problem I see is that posting an answer in such a room would most likely get more upvotes than a regular answer or an answer posted in a "normal" room
 
@JonClements ABSOLUTELY! It is far more than amazing. Almost no story — but the colors, the lights, the noises and the music, and dialogs and the characters... it is dark, I have to say, but..
sooo kewl.
 
@PeterVaro is that the one where there's the bloke at the table eating his own brains?
 
What about posting answers as @JonClements just did?
 
1:52 PM
@JonClements that is the film. This is the series
 
@mgilson no I didn't cough
 
He posted a question...
 
I don't see anything really wrong with that ... It's a good answer, why shouldn't it get upvotes?
 
@AndyHayden exactly!
 
:)
 
1:53 PM
You could pick any of the excellent answers to upvote on it
 
and the "hasn't got to 20 yet" was a factual statement ;)
 
And having seen the question and answer, I'd be inclined to upvote it -- but now I'm worried to do it for fear of disciplinary action.
That seems silly to me.
Especially considering some users (e.g. Jon Skeet) get upvotes now just because of the 500+k rep that is displayed next to their name.
 
I was reading a post on meta - that apparently - higher rep does not mean more upvotes for the sake of upvotes
(I don't think that anyone really disputes that it does in some sense)
 
It's kinda amazing that Alex Martelli hasn't logged-in in two and a half years, and still hits 200 rep regularly... but that's more due to the thousands of answers he's written to get 250k rep.
 
250k??????????? OMG
 
2:01 PM
@AndyHayden -- Alex has great answers to some of the most fundamental questions about the python language. They're constantly getting traffic from google searches.
 
Yeah I agree! I must have upvoted quite a lot of those questions :)
 
It's not like the questions we see today: "How do I parse something from a file formatted like this that nobody has ever seen before ..."
 
Hmm, FGITW, writ large.
 
I still think it's "kinda amazing"
 
I'm not doing badly for 15 months ;)
gimme time guys - we can't all be Martijn ;)
 
2:04 PM
Martjin (nearly) has answered the most python questions of anyone in the world...
 
I heard rumours that he might actually be human though... ;)
 
jon, your quite a wizard in condensing code
let's say i got something like
if func(value) > value:
is there some way to somehow catch the return of that func inside the if?
without first storing it in a var
(ie i dont want to do temp = func(value))
 
@BasJansen -- Not without some trickery -- This isn't C after all...
:)
 
Damn my C mind :(
i'd be interested in the trickery you had in mind tho?
 
2
Q: Is there a way to get the return value of a function and test it's "nonzero" at the same time?

mgilsonI have code that looks like this: if(func_cliche_start(line)): a=func_cliche_start(line) #... do stuff with 'a' and line here elif(func_test_start(line)): a=func_test_start(line) #... do stuff with a and line here elif(func_macro_start(line)): a=func_macro_start(line) #... do s...

 
2:10 PM
hmm, lemme read that
I was trying things like if temp = func(value) > value
but py didnt like me for trying that :p
 
lambda abuse is possible ;)
 
@JonClements -- I'm not seeing the lambda abuse possiblities ...
I suppose globals abuse is possible...
 
eeww
 
@mgilson how about context manager abuse?
 
No, never mind... I can't even figure out how to do it with globals ...
Ultimately, the point is that we want to do this nicer :)
 
2:14 PM
indeed
 
Who doesn't like an opportunity to abuse the system though ;)
 
hmm, my wannabe rogue like creation manages to hit the other object for negative damage, how cute
(yes i'm a bit bored, waiting to go to the airport
 
@mgilson I answered your question :p
 
Yes, I see ... I'm trying to think of what I was trying to do back when I asked that question. I think your answer is a valid approach to solving that particular problem.
Ahh right, the problem was that the stuff to be done in each of the cases was different.
So, with your answer, even though I have the first "true-like" result, I don't know what stuff to do after that.
 
You could wrap the stuff to do (the code inside each if block) into it's own function and have that returned from the generator as well
 
# ontopic
 
@PeterVaro given the nature of the room - I think explicitly stating "on-topic" is required before going "off-topic" :)
 
:):):)
 
ooo, I had a response from the PSF
 
2:32 PM
oh, wow
what are they saying?
did you send them the logo as well?
 
No - it was a general email - and I wrote it at 1am - so it's not exactly a very good email either
 
Dear Sir/Madam,

I am a room owner on Stackoverflow.com for the Python language. We also have a website set-up (for commonly used questions/FAQ's) and was wondering about the legality of using the Python logo on our website.

We have an existing design (this was just me being lazy and just doing whatever - that currently exists), or we were thinking about an adaptation of the existing design.

Our interest is purely in the interest of the Python community - so we would sincerely appreciate any advice on this matter.
 
uuuuuuhh:) It sounds serious.
 
2:35 PM
That's gotta be close to one of the worst emails I've ever sent
Hi Jon,

I have cc'ed our trademark committee. You should hear from them soon.

Thanks,

Ewa
PSF Admin
 
hehe
 
"You should hear from them soon".... ummm... hopefully not a bunch of lawyers knocking on my door though ;)
I think I'm all out of shotgun ammo...
 
Sometimes you just don't know what to say ... stackoverflow.com/q/16965090/748858
 
@mgilson in some way I feel sorry for all the downvotes these poor guys have, although, I feel sorry for ourselves, because we read their (most of time long and) useless questions..
 
2:51 PM
It's not that ... It's just that ... they're clearly out of their depth.
 
It's one of those questions where, if they could succinctly explain their starting conditions and desired output, there wouldn't be a question.
The question is primarily, "figure out what I have and what I want"
Which isn't to say that their problem isn't "real", or that it's due to laziness on their part. It's just that they're not likely to get satisfactory help from a Q&A site.
 
And then there are people like this guy
Apparently he's gotten pretty good at asking questions around here ...
(I answered one of his questions last night and I was like ... 10k rep, but pretty basic question. I wonder what his primary language is ...)
 
Anyone think that all mutable python base types should have a .copy method?
 
Not GvR apparently ;) And besides if he did, then he'd want it to be copy() rather than a method
 
3:06 PM
Well, there already is copy.copy()
 
@JonClements oppinions about this?
 
It just seems silly that dict.copy() and set.copy() exist but list.copy() doesn't.
 
stackoverflow colors + python typo
 
@PeterVaro that is sexy
 
more abstract, more geometrical version of the logo
 
3:08 PM
big +1 from me
 
yuhhu
:)
I have to refine the colors — but you got the idea
 
yup drools :)
 
and it is based on a 4*4 grid (16bit?) :)
well, I have to get back to work
brb
~
 
You weren't kidding when you said you were a designer... ;)
@mgilson errrr...... 1floatify: Forcing a number to be a floar <-----
 
2 floar: same thing as float
 
3:23 PM
;)
Or the punchline of a rather bad joke involving floor and float ?
 
def floar(x):
     return float(int(x))
 
touche? :)
 
3:46 PM
:)
* wishes for more memory *
 
3:59 PM
I'm fairly sure I have 16mb EDO RAM from an old machine somewhere..... ;)
 
 
3 hours later…
6:39 PM
Why would you post a duplicate question to an question you've answered only minutes before...
Ah, the OP points out that it is clearly a different issue...
 
Looks like the first problem was solved, as in "I'm no longer getting this particular error message", but not solved as in, "the line does what I want it to do"
 
yeah...
 
Zac
7:04 PM
I'm trying to understand JSONs right now and not really very clear how they create objects
I accessed a JSON from twitch.tv
and put it into a python dictionary
now I want to search it and return an object
but it is really big and complex
 
how have you put it into a python dictionary?
json.load ?
 
Zac
import json
import urllib2

u = urllib2.urlopen('https://api.twitch.tv/kraken/chat/emoticons')
mydata = json.load(u)
u.close()
mydata contains a massive series of nested dictionaries for what I can tell
I want to for instance search one object for the regex "MVGame" and return its associated url image
 
#First, search through the emoticons list and locate the items that have regex "MVGame"
matchingItems = filter(lambda item: item["regex"] == "MVGame", mydata["emoticons"])
#pick out the first one I guess?
item = matchingItems[0]
#retrive the images from the item
images = item["images"]
#pick the first one I guess?
image = images[0]
#retrieve the url
url = image["url"]
print url
 
Zac
7:20 PM
thanks I'll try that
 
You could also make some kind of recursive regexey thing, which maybe returns the keys of where it's found, but it shouldn't really be necessary (first explore the keys/items as Kevin suggests)
 
Zac
That works, If I just wanted to put all the regex pairs into a new dictionary and pair them with their urls is it similar?
I notice I have to index things with numbers after the first name
for instance
mydata['emoticons'][1]
I think I'm slowly getting it
hummm
 
Nah, mydata['emoticons'][0]['images'] returns a list
 
Zac
yep
you're right
so mydata['emoticons'][0]['images'][0]['url'] returns the string of that objects url pair thingy
 
It returns one of possibly many urls, yes
 
Zac
7:32 PM
okeydokey I'll play with it for a bit
 
Zac
7:45 PM
I'm still doing something wrong here
import json
import urllib2

u = urllib2.urlopen('https://api.twitch.tv/kraken/chat/emoticons')
mydata = json.load(u)
u.close()


emoticonDictionary = {}

for i in mydata['emoticons']:
	emoticonDictionary = {(mydata['emoticons'][i]['regex']) : (mydata['emoticons'][i]['images'][0]['url'])}
 
remember, mydata['emoticons'] is a list.
So when you do for i in mydata[emoticons], i becomes the values of that list. You can't use the value as an index into the list.
That would work if mydata[emoticons] were a dictionary, perhaps. Because for k in myDict iterates through the keys of myDict, so it then makes sense to use k as an index into myDict
 
Zac
how do I get the loop to iterate over all the items in the emoticons list ?
 
In any case, during each iteration of that for loop, you're redefining emoticonDictionary entirely, destroying any data that it had previously
for item in mydata['emoticons']:
So, you had it right, except for a misleading variable name.
It's the line following that that's no good. You want something like,
 
Zac
ok so emoticonDictionary[(mydata['emoticons'][i]['regex']] = mydata['emoticons'][i]['images'][0]['url']
 
regex = item['regex']
url = item['images'][0]['url']
emoticonDictionary[regex] = url
mydata['emoticons'][i] doesn't make any sense. i isn't an integer, you can't use it as a key to the mydata['emoticons'] list.
 
Zac
7:54 PM
thanks, I was thinking i would be an integer, I've seen enumerate used before I'm not used to these python for loops
 
Yeah, seems like most languages use something like foreach when you want to iterate directly through a collection without mucking with indexes.
Python's kind of the odd one out, using just for
But as they say, optimize for the common case. And 99% of the time, I don't care about indexes, so Python saves me four character strokes every time I write for instead of foreach
 
Zac
I can see if you know what to write, it is very readable
 
while i was using django and python, i found that either i have to use mrkdown laguage or escape the html properly in the textarea, but in php we donot need to do that.. but why in django do we need to do it?
also using this in markdown language an xss attack can be done:
> hello <a name="n"
> href="javascript:alert('xss')">*you*</a>
then how to properly escape the html inputs
 
Zac
8:27 PM
how do I replace all instances of a word within a dictionary in a string? The following only temporarily changes the string and could be dangerously recursive if allowed to work on altered strings.
import json
import urllib2

u = urllib2.urlopen('https://api.twitch.tv/kraken/chat/emoticons')
mydata = json.load(u)
u.close()


emoticonDictionary = {}

for item in mydata['emoticons']:
	regex = item['regex']
	url = "<img src=\"" + item['images'][0]['url'] + "\">"
	emoticonDictionary[regex] = url

mystring = "Hello everyone this is a string MVGame test."

for key in emoticonDictionary:
	resultString = mystring.replace(key, emoticonDictionary[key])
	print resultString
 
Zac
8:41 PM
ok found this code previous answer.. don't understand it but it works
import json
import urllib2
import re

u = urllib2.urlopen('https://api.twitch.tv/kraken/chat/emoticons')
mydata = json.load(u)
u.close()


emoticonDictionary = {}

for item in mydata['emoticons']:
	regex = item['regex']
	url = "<img src=\"" + item['images'][0]['url'] + "\">"
	emoticonDictionary[regex] = url

mystring = "Hello everyone this is a string MVGame test."

pattern = re.compile(r'\b(' + '|'.join(emoticonDictionary.keys()) + r')\b')
results = pattern.sub(lambda x: emoticonDictionary[x.group()], mystring)
 
 
1 hour later…
9:44 PM
Darn it, I'm sure I remember a really neat solution to this question (why I didn't post it), I'm sure there is a decorator for this in a standard library: stackoverflow.com/questions/12218578/…
 
Cabbage all
 
Cabbage @MartijnPieters !
 
@AndyHayden: the functools.wraps decorator will copy the docstring from the wrapped function to the wrapper, is that what you are thinking of?
There are no other decorators in the stdlib that touch the docstring as far as I know.
 
Ah.. it was this stackoverflow.com/a/12219675/1240268 non standard library (ply), so I can't use it (doh!)
yup functool.wraps it the way to go, thanks :)
Or perhaps yoinking the source for TOKEN is the way forward: code.google.com/p/ply/source/browse/trunk/ply/lex.py#1047
(ooooh and it plays nice with class methods)
 
10:21 PM
@MartijnPieters How are you finding the UK ??
 
Too much to deal with at the time to get much of an impression
but had a great evening at a pub tonight, so that's fun.
Next week the movers will unload our stuff at the new house, so in a week or 3 I'll have had a chance to actually get my bearings! :-)
 
Living from a suitcase?
Are you bringing everything ?
 
Living from a suitcase atm
we are bringing everything.
 
Wow! I think I would have to throw away so much stuff...
 
64cbm total, 3 kids (two teenagers), 4 cats.
 
10:30 PM
We do accrue things over the years :)
(congrats on answering the most python questions of anyone in the world btw.)
 
Nah, I don't think I hold that title just yet.
stackoverflow.com/tags/python/topusers sez Ignacio has a few more on his name still.
 
11:02 PM
give it an hour :) (to update)
 
It updates at 3 UTC, I think, so it'll have to be a bit longer.
But yeah, I probably will have passed him by on that.
 

« first day (964 days earlier)      last day (3969 days later) »