« first day (1452 days earlier)      last day (3499 days later) » 

12:01 PM
Did __cmp__ get removed in 3.x? The 2.7 docs list it right below __ge__, but it's gone in the 3.4 docs.
 
Aye it did.
 
yesi t had to give way to rich comparison methods and total_ordering class decorators.
so basically you guys would prefer the if elsif else solution, right?
 
Yeah it's more obvious what you're doing.
Plus can cmp return values that are greater than 1 / less than -1 ?
Will things break if you did a - b and that came to -5?
I don't know exactly, but if they do then I can guarantee it'll be in the worst place imaginable and will be a right swine to track down the reason :P
 
If a and b are members of your class instances, and they themselves are types that already support cmp, I'd do return cmp(a,b)
 
the docs just say negative zeor or positive
Kevin: They're just ints in this case as far as I have dissected the code :^)
 
12:08 PM
class Student:
    def __init__(self, name, grade):
        self.name = name
        self.grade = grade
    def __cmp__(self, other):
        #ordering is done by grade.
        return cmp(self.grade, other.grade)

a = Student("Fred", 75)
b = Student("Barney", 80)
print a < b
 
I just forwarded the calll that looks best for my taste, and it simply uses the already available functionality.
i.e. return cmp(a, b)
 
Like that. It's nice if you're like me and can never remember which numbers correspond to which (greater than | less than | equal) state
 
@Kevin yep :)
That's where ruby's symbols or whatever they're called come in handy
 
actually that might have been an SO posting since a Google search did not turn up anything about that.
 
:first_is_greater, :second_is_greater, :equal
 
12:10 PM
is there a policy that allows turning chat stuff into SO questions to document the solution? It sounds good to me.
 
Go for it. As long as you write a full question and answer that doesn't require someone to come to chat.
 
No, it should be fine, provided the question meets SO's usual standards
 
or is that programmers.stackexchange? It is more a style question, not a real problem, that's basically why I have NOT asked a question on SO yet
 
Ha, I think I wrote some code myself using first_is_greater constants when I was composing an especially gnarly comparator in a C# project.
 
@Kevin Shouldn't that compare the name of the students if the grades compare equal?
 
12:15 PM
Not if the school treats all students as interchangeable parts with no real identity ;-)
Let's use the magical short circuiting nature of or, and do return cmp(self.grade, other.grade) or cmp(self.name, other.name)
 
Damnit. Why did I even CONCEIVE Aardvark Grant
 
Kevin: Evil! But nice
reminde me of those Lua idioms 'a = a or {}'
 
12:32 PM
<w:commentRangeStart w:id="0"/> ,in this xml tag (which is within a w:p) which is the best function to store the id value? Objectify looks a bit confusing..
 
Define "store"
how about with open("storage.txt", "w") as file: file.write(id)?
 
a dictionary ..
 
Ok, myDict["id"] = id then
 
for p in lxml_tree.xpath('.//w:p', namespaces={'w': w}):
     p.xpath('./w:commentRangeStart[@id',namespaces={'w': w}))
right way to iterate?
 
Dunno, never used lxml_tree. The answer to your question is the same as the answer to "if you run it, does it work?"
 
12:35 PM
a bit confused.. do i need to go all over to commentrangestart or can i access it via w:p directly?
 
I loathe writing User Guides
Many years ago, I wouldn't have felt the need to write the following sentence - "To save your system parameters, press the “SAVE” button - and to cancel any changes press the “CANCEL” button."
I have since lost faith in humanity
 
In another ten years, you'll be writing a user guide for your user guide.
To read a sentence, move your eyes across the page and use the "literacy" you learned in elementary school to interpret the meaning of the symbols
But if they can't read the reading instructions, then how will they learn...
A problem already explored by XKCD, of course.
 
@Kevin 6 drinks -> I should try installing FreeBSD -- LMAO.. LOL..
 
I occasionally wonder if an alien species could learn one of our Earthly languages, if they only had access to, say, a dictionary.
 
@Kevin that might be harder to start with than just regular text
 
12:47 PM
@Kevin most dicts has a short intro to the language itself (to make it easier to understand what the different terms means in the dict itself)
 
Sure, human babies can learn language even without an instruction guide, but they have a lot of instant feedback. ex. parents responding positively when they make meaningful noises.
If all you have is a bunch of text, though...
 
Learning languages works by having some context to the words. A dict alone wouldn't work I think. "Fire -- BAD!" pointfingertofire
 
I guess you could start by making reasonable assumptions like "an empty space between symbols indicates where one 'word' ends and another begins"
and "words composed of fewer symbols tend to have a more general meaning"
(ex. compare the general "bad" with the specific "arthritis")
 
A dictionary? English to what?
 
Makes me think of Darmok and Jalad at Tanagra!
 
12:52 PM
Just an English dictionary. English to something else would probably complicate matters, as the aliens would have to translate two languages.
 
Unless it were English to ancient Mesopotamian
And by some incredible coincidence the aliens also spoke ancient Mesopotamian
 
@Kevin You mean English - English dictionaries? Their vocabulary would be brilliant, but sentence formation and grammar?
 
Maybe a frequency analysis of words would help. "The" is the number one most common word? Must be some kind of essential particle of the language.
 
@thefourtheye just a normal English dictionary, he means :)
 
@Kevin Alas. A modern problem for our times
 
12:54 PM
@Kevin yeah, regular text will be much easier I think
They can Rosetta Stone it
And not the DVD, the ancient...stone thing
 
@hochl Thanks. I had managed to expunge that episode from my mind. Until now
 
The Rosetta Stone was cheating, because it was one text written in three languages :-)
 
@Ffisegydd v2.0 committed! => I tried to add everything which was relevant (already in there) however I stayed at the strict 80 columns rule (just to make you happy) :P
 
@IntrepidBrit Was it that bad? I'd say it was one of those interesting episodes, of course not much action there.
 
@Kevin This is where archaeologists find out the stone is subtle Greek satire...
 
12:56 PM
@Peter ewww
I'll proof-read it again then and submit a new PR?
 
Haha. Thus invalidating decades of ancient Egyptian cultural studies.
 
@Ffisegydd eww 2.0? or eww 80 columns? :P
 
80 columns of course ;)
 
@Ffisegydd that would be awsome!
 
Might be able to do it tonight, depends on SO.
 
12:57 PM
and now you can work on the master -- all the branches are clean now :)
 
We have tons of people here that will gladly write lines with 200+ columns and are totally resistant to any kind of limit. Image how that sucks.
 
@hochl I would have said it made an interesting story to read, but to enjoy on a visual audio medium? I found it a bit stifling :)
 
Is there a sqrt variant that returns a complex number if you give it a negative argument? Might be useful for this guy.
 
@IntrepidBrit Yeah true ... I wonder if they will ever make a new star trek series [preferably NOT in the alternate timeline].
 
@hochl I like the alternative timeline personally. It's refreshing.
But a new series would probably go the same way of Stargate Universe
 
1:02 PM
@IntrepidBrit UGH ... SGU ... they just should have continued in the same manner as before ... it was too dark! Totally disliked it.
 
@hochl I liked what they tried to do with it. I think it should have ran simultaneously with Atlantis, as they wanted it to. But noo, TV channel bosses got in the way....
 
Thanks :-)
 
In [6]: from cmath import sqrt

In [7]: sqrt(-9)
Out[7]: 3j
 
@IntrepidBrit Those dudes that already killed firefly :(
 
1:04 PM
I approve of Python's choice of j for the imaginary unit.
 
@hochl I was waiting for a Firefly mention :)
 
wha does (char*)&a means
 
In what language?
 
Ah. I see. This is the Python room though :)
 
1:06 PM
pointers
 
@RobertGrant That's the MTTFM (mean time to firefly mention) timespan after someone mentions TV bosses :P
 
@SusanSweedyk Take the value pointed at by a, and cast it to a char pointer
Which may, or may not be sane.
 
#include <stdio.h>

int main()
{
float a=3.14;
char *j;
j=(char*)&a;
printf("%d",*j);
return 0;
}
this was the question
output was -61
 
Which exam are you studying for?
 
1:14 PM
sr. sec
 
Ah whoops. Shows that I'm getting rusty. Should have said "the address of" instead of "the value pointed at by"
 
@SusanSweedyk What are you trying to achieve, printing the first 32bits of a float value from memory as an integer? Makes little sense to me... or is that a trick question :)
 
@SusanSweedyk We should probably move this out of the Python room, so we don't clog it with C
 
@IntrepidBrit you could always use the C room :P
 
THAT'S MADNESS. IT'LL NEVER WORK
 
1:21 PM
If you use the 00 room you can even dump core ... xD
 
Ahoy @EP1986!
(and don't think we didn't see you sneak in @hanleyhansen)
 
=D
good ole python room
 
I presume the good is relative :P
 
indeed
 
I have a problem. How do I write good programs?
I tried writing a good program and it didn't work. Please advise.
 
1:31 PM
=)
 
I think you should start by first writing a good line of code. Then write a bunch of those and put them together.
 
Make sure you put them in the correct order though.
 
That doesn't matter
As long as they are all good
 
My algorithm is like, "1. Write some code". Desired output: a good program. Actual output: a program ranging between "bad" and "adequate"
 
I find that I can write lots of good lines of code, but if I don't put them in the right order then it becomes bad.
 
1:32 PM
@Ffisegydd, me too! We should file a bug report.
 
You guys must not be doing it right
 
Evidently not :-(
 
What's your secret?
 
You gotta push the buttons in just the right way.
 
That's it
@Kevin what part of NJ?
 
1:33 PM
"10 examples of terrible programming! You won't BELIEVE what #7 did to get it to compile!"
 
I just Google all lines of code, wrap them together and then pretend to be Ranschich from India ;)
 
@hanleyhansen If you're asking for my location, I'm a 10 minute drive away from Philadelphia.
 
Oh cool. I work for a Philly based company but I live by the shore.
My wife is from that area, Deptford to be exact.
 
It's a nice location. ten minutes from the city, an hour from the beach. There's not much going on in my actual area, but it's adjacent to many interesting things.
 
A lot cheaper than my area and than North Jersey as well which is where I'm from originally
 
1:42 PM
Heh, I wonder how many people will bother to Base64-decode that flagged message.
Because when you do you'll know why it was flagged in the first place.
 
how far back?
 
Well now I have to :-)
 
oh thought you said starred for a sec
 
Ha. Somehow I find it less offensive, since I had to put forth effort to see the message. I guess it's still flag-worthy, though.
 
I suspect it was a test to see if enough people would decode that before the flag expired or something.
 
1:48 PM
WW91IE1VTSdzIGZsYWctd29ydGh5
 
:-o
 
lol
 
snicker.
 
Last weekend I purchased the old-school DOS game Commander Keen. I guess I'm spoiled by modern systems, because I found it unnerving to play a game with no background music, and few sound effects.
 
1:52 PM
I remember that
 
The gameplay itself is solid, though. (although the idea of a limited number of lives is so last century)
 
Reminds me of the fun had in the comments of my robot language post.
 
I was quite annoyed by the control scheme: ctrl to jump, and ctrl+alt to fire your laser.
Fun fact: pressing ctrl-alt-right on my laptop causes the screen to rotate 90 degrees. This happens even if your keypresses are being intercepted by DosBox.
 
how does the with keyword actually work? It needs an __enter__ and __exit__ method if I understand correctly, but how is that implemented?
 
@Kevin that probably adds quite a lot to the game?
 
1:56 PM
Do you mean, "how do I implement enter and exit?"? The normal way. def __enter__(self, args)...
 
@corvid if using a class - otherwise a function can be used
 
@corvid the with pep :)
 
but is it nested within a function?
 
8
A: Is Python *with* statement exactly equivalent to a try - (except) - finally block?

VeedracI'm going to put asside mentions of scope, because it's really not very relevant. According to PEP 343, with EXPR as VAR: BLOCK translates to mgr = (EXPR) exit = type(mgr).__exit__ # Not calling it yet value = type(mgr).__enter__(mgr) exc = True try: try: VAR = value # Only...

 
No nesting required, nah
 
1:57 PM
@corvid The normal way to implement a context manager is the contextmanager decorator
 
@corvid the result of the expression is expected to have both an __enter__ and __exit__ method.
and the __exit__ method is looked up first (in case of exceptions it'll be called, even if the __enter__ method failed).
 
class Fred:
    def __enter__(self):
        print "starting 'with' block!"
    def __exit__(self, *args):
        print "ending 'with' block!"

with Fred() as foo:
    print "Hello, I am inside a 'with' block!"

print "Goodbye, the 'with' block is over!"

#result:
#starting 'with' block!
#Hello, I am inside a 'with' block!
#ending 'with' block!
#Goodbye, the 'with' block is over!
 
@hanleyhansen: sorry, I try to keep my LinkedIn contacts limited to friends and people I've done business with.
E.g. you need to buy me a drink first. :-P
 
@Martijn that "drink" being a crate of Yamazaki whisky?
 
2:07 PM
@JonClements A crate will probably be sufficient. Domo arigato gozaimasu.
 
@JonClements You told me to remind you of a thing but then I forgot so now I the thing.
 
Like opening a box of toys!
 
DSM
Cabbage, all.
 
@Kevin so is with open() really referring to a class?
 
    for p in lxml_tree.xpath('.//w:p', namespaces={'w':w}):
        paracount+=1

In the above expression , I want to increase paracount with paragraphs i.e 1 st paragraph will have paracount=1 and 2nd will have 2 and so on.. but this actually increases paracount with every element in a paragraph.. how could i work through this??
 
2:10 PM
@DSM All Cabbage
 
@MartijnPieters Interesting ...
 
@corvid open() returns a file object, so the with should be calling file.__enter__.
 
@corvid open() returns a TextIOWrapper instance
which has __enter__ and __the_other_one__
It returns a file (also a class) on Python 2
 
@corvid open() is just an expression. The result of that expression (the return value of the open() call) is an object that implements the context manager protocol.
 
@MartijnPieters So much variety... I worry that I'd be meeting with the Emperor and accidentally say "thanks bro" instead of "My lowly self grovels in appreciation" or whatever.
 
@Kevin Japanese is a veritable mine field of social faux pas.
 
Hopefully I'd get some wiggle room, as I am a dumb foreigner and thus can't understand their social labyrinth.
 
DSM
@Kevin: I had to use something on the "my lowly self grovels" level once, having broken a cup..
 
All I know about Japan is that the obnoxious and loud person normally ends up with superpowers in a Mecha
 
@Kevin rule of thumb: more words == more politeness
 
DSM
2:15 PM
And that all authority rests in the student council.
 
If you're expected to grovel over a broken cup, what do you say if you burn down their house by accident?
I expect a tasteful gift is in order.
 
DSM
But not too tasteful, lest you introduce a reciprocal obligation.
 
avi
Is it possible to create a recursive list in python or in any language... a list which contains itself as one of element:

my_list = ['a', 'b', my_list]
 
yes, you can do that
Not sure if you can do it in one line, though
 
x = []; x.append(x)
One line
 
DSM
2:18 PM
Semicolons are cheating.
 
:-)
 
OK
 
one expression.
 
I can do that
 
avi
I tried
>>> l = [1,2]
>>> l.extend(l)
>>> id(l)
4436238208
>>> id(l[2])
140263846644168
>>>
 
2:19 PM
Probably something wacky with lambdas... To the mad computer science lab!
 
(lambda x: x.append(x) or x)([])
@avi You want .append, not .extend
.extend will just double the list's contents
 
@avi extending is not the same as appending.
@avi: you added the elements of l to itself. So id(l[0]) == id(l[2]) is True.
 
avi
works :)
 
l.append(l) would be more meaningful.
 
@DSM Tell me about it. I went to a Japanese school to help teach English for a once off guest session. I brought some of the teachers and head-teacher some Scottish Shortbread. I came back with a beautifully painted watercolour picture painted by the Headmaster's mother.
I was politely mortified
 
2:22 PM
@IntrepidBrit you were obviously already honouring them with your presence. Adding shortbread to the pile overloaded the debt balance.
 
Pro move by the school there. "Oh, thanks. I didn't get you a gift, though... yanks painting off wall. Uh, here you go"
 
@Kevin I worry that this is EXACTLY what happened!
But it was the head-teacher's favourite painting by his late mother that just happened to be in his office
 
Or perhaps they had the headmaster's mother make a painting especially for you.
"Work harder, mom! We have to restore gift parity!"
 
DSM
Which was tough, given her arthritis, but she pushed through, just to make IntrepidBrit happy.
 
Who said us British were past our colonial/imperialism phase?
 
DSM
2:25 PM
Moral of the story: be careful with shortbread.
3
 
A noble sacrifice by the now-late mother
 
@IntrepidBrit or it wasn't handpainted, or by his mother, they just told you it was to try and ensure they could rebalance the scales here.
 
The problem is, I feel like I've fallen behind on gift parity. I'll need to return with some homemade Shortbread AND Tablet made by my mother.
 
Gods, don't do that! They'd dig up mother and reanimate her so she can paint two watercolours for you!
 
DSM
I think the Canadian habit of using beer as the unit of exchange for favours works well in practice, because we accept roughly the same amount of beer independent of the difficulty of the favour. Since it's understood by all parties, everyone's usually satisfied.
 
2:28 PM
And the chain of reciprocal gift-giving of ever increasing magnitude, eventually lead to a gift-based world economy, ushering in a golden age of mankind...
 
DSM
A gift for a gift leaves the whole world broke.
 
@DSM It's also relatively international as well. At least, with the Anglophone nations.
 
While the wrapping paper industry laughs maniacally from their impenetrable oppression palaces.
3
 
@Kevin Where I'm headmaster of a Japanese school?
 
@Kevin I don't think inflation of those levels is good for any economy
 
DSM
2:29 PM
@IntrepidBrit: also in HK, now you mention it. Certainly for "help with moving", anyway.
 
@IntrepidBrit Yes, that seems like a logical consequence. "I have nothing more to give you, other than my very essence. You are the headmaster now"
 
@DSM I suspect it all boils down to being ruled by the UK at some point. Cultural cross-pollination and all that.
 
DSM
Genuine LOL at that, Kevin.
 
Pretty sure that's how all headmasters get their position.
 
@hanleyhansen You did see the IKEA catalog ad then?
 
DSM
2:31 PM
And not by defeating the previous one in battle?
 
@Kevin Duly noted. I can break the cycle. A young programmer comes to my school to help teach English. I offer him a beer. Japanese society collapses?
 
With their birth rates, Japan doesn't need any help in collapsing, thanks very much :-(
@IntrepidBrit Suddenly, their two century long policy of isolationism makes sense.
"No English teachers please, it's for the good of society"
 
gift explosion?
 
@Kevin "Wait, how did he just speak English to me?"
 
2:34 PM
"Moral of the story: be careful with shortbread." -> "While the wrapping paper industry laughs maniacally from their impenetrable oppression palaces." -> "No English teachers please, it's for the good of society"
 
DSM
Welcome to the Python room!
 
"That previous sentence, and the one I'm speaking now, are the only words of English I know"
 
@MartijnPieters About this clausule
 
DSM
@Kevin: ¿qué?
 
considering OP said "But this obviously didn't work that way." I'm not sure the linked duplicate helps
emphasis on "obviously"
 
2:37 PM
Right, and the other post explains the why, why it doesn't work.
 
I don't think the question was about that
 
In this case I'll concede that the question has some unique elements though
reopened.
have fun with it!
 
:)
 
btw is there a SO posting that explains which implementation for cmp is best? I couldn't Google it. Else I might convert my earlier style question into a real SO question.
 
avi
go ahead
@MartijnPieters lol nice one
 
2:41 PM
@hochl Sounds too opinion-based
 
Is it possible to get the country from VISA card number?
 
@Veedrac basically it boils down to this problem... BUT ... I'd like to know which is the `ideal python solution'. I settled with return cmp(a, b) in my code now because it reuses the standard library.
 
@vaultah I think you can get the issuer... not sure about the country per se
 
Yeah, "what's the nicest way to do [thing]?" may not be a good SO question, even if it's useful.
Usefulness is necessary, but not sufficient, to make a post on SO
 
That said, it can work
you just have to be careful
 
avi
2:44 PM
@hochl post in code review.se
 
DSM
What should be done with this?
 
Any subjective Python question magically becomes objective if you can get a quote from Guido Van Rossum that confirms that "this is the one true way to do it"
 
Too Broad imo
Put POB is valid as well.
 
@DSM Very definite close
 
DSM
Couldn't decide between too broad and opinion.
 
2:45 PM
It's closed anyway.
 
DSM
And this is why I should never think about things. I think too slowly compared to other people.
 
@Kevin Any dutch person will do
 
DSM
Will Frisians count in a pinch?
 
"What would guide you in deciding to use a list comprehension instead?" I'm not introspective enough to answer this question. I don't know why I decide anything.
Maybe there's a little goblin in my head pulling levers.
 
"I read the bible to decide such matters"
 
2:46 PM
@Kevin Definitely, the question is is it just one?
 
DSM
shakes "Reply hazy, try again"
 
@MartijnPieters nice lol
 
But this is a recursive problem. When the goblin decides to pull the "use a list comp" lever, what guides HIM in deciding to pull that lever?
 
Turtles.
 
It's goblins all the way in.
 
2:47 PM
hahahahahaha
 
DSM
[Wait, was the Magic Eight-Ball a thing outside of NorthAm? We're too motley a crew.]
 
I think the 8 ball has been around long enough to dissipate through all cultures
 
I know of so-called magic eight balls but I know of them through American television.
 
@DSM I like the Canadian beer philosophy
 
I didn't see one myself until a few years ago.
 
2:48 PM
@Ffisegydd I use to have a magic 8 balll
 
Can I make a business out of it?
"Please give me two beers. Here's a beer for your trouble."
 
@Jon was it how you decided your keys?
 
@Ffisegydd it guided all choices in one's life...
 
@Ffisegydd where to hide the keys perhaps.
 
@Martijn Q: "Oh magic 8 ball - where do I hide the keys?" A: "Yes"
 
2:50 PM
World's worst random-password generator.
 
DSM
It is decidedly so.
 
You could choose a hiding spot using a binary search algorithm. "Should the longitude of my hiding spot be in the west hemisphere?"
 
That's still very low entropy
 
DSM
I think most NorthAm types of the right age can probably rattle off a half-dozen or so eight-ball answers even if they never owned one. "Signs point to yes" is immediately recognizable as a reference.
 
@DSM yeah... it wasn't a very good satnav either...
I remember it from the late 80s I think
Use to be a bit of a trend
 
2:54 PM
For maximum entropy usage, I guess you could encode each of the ball's responses as a base 20 digit.
 
"eight ball: A quantity of cocaine or crystal that weighs an eighth of an ounce, hence an "eight ball", which is equivalent to 3.5 grams."
 
This is assuming the eight ball spirit is willing to play along. It may have philosophical reasons against saying "yes" when it means "the digit 1"
 
See I actually use eight balls to play pool...
 
If you do that, the ones with spirits inside them tend to go a bit wobbly.
 
@Ffisegydd you'd needed larger pockets than even a US pool table has to pocket it though :)
 
2:57 PM
I miss playing pool :(
 
Either owing to the spirit being indignant about its role, or because the indent where the viewing window is makes for poor rolling
 
@Ffisegydd I'll give you a game/two at sopycon :)
 
I have a pool table in my basement :-) We've been using it as a table to hold boxes of tax returns for years :-(
 
@JonClements We should have a mini - league. Loser picks up the tab? ;)
 
It's a very good tax return holder, though. The raised edge really helps guard against boxes falling off.
 
2:59 PM
@Kevin and you've set up cushions and holes on the desk to play pool on?
 
The better you are, the more you'll drink to make the most out of winning. Natural rubber banding system ;)
 
@Jon, of course, Gotta maintain the balance.
 

« first day (1452 days earlier)      last day (3499 days later) »