« first day (1990 days earlier)      last day (2951 days later) » 

8:04 PM
Besides Javascript, who actually allows that?
 
omg a room for python
finding it through google is easier than through SE
 
DSM
@user2357112: oh, hi! Often see you on mathy questions.
 
Hi, DSM.
 
Hello to the people of this room
 
@Skyler Cbg!
 
DSM
8:08 PM
Hello (or "cabbage" as we say), Skyler! You can read our room policies to find out about our customs, most of them normal, some of them strange..
 
To be fair, it's mostly the people who are strange.
 
anybody here have experience with parsing JSONs?
 
No, no one does. It's too bad, since that's a really common format.
 
DSM
@Skyler: reread the room policy page, looking at #2 under "Asking a question"..
 
8:12 PM
@Morgan'Venti'Thrappuccino I just noticed you changed your name.
It is good.
 
@DSM wasnt that saying its optional to ask a preamble
 
@davidism Thanks. :D I'm taking credit for it when people complement it, otherwise I'm blaming Tristan.
 
DSM
Huh. You kind of have a point. We intended it to mean "please don't", but to be fair it really only says "you don't need to"..
 
@DSM It's passive agressive for "don't"
I think it's clear;)
 
@davidism tell me about it
well anyways
im trying to write a simple function that will just loop through all keys, print them out, while checking to see if there are any lower level values, and if there is it iterates down and repeats the process
 
8:16 PM
@Skyler sorry if the rules wording wasn't clear. Basically: don't ask to ask; just ask :)
 
it's on my todo list
 
Can I ask about if I should ask before I ask or not?
 
Just googling python json gives a good SO answer that covers it on the second hit
 
basically prints something like this
I
Ia
Ib
Ia2
II ...
well here is the issue when i try to do many of those
im trying to do something a tad different
this function doesnt know the formatting of the json
how many layers it has
so doing data[level1][level2] doesnt make sense
 
DSM
The usual approach would be to write a recursive function-- instead of "iterates down", you call the function at a deeper level.
 
8:19 PM
@DSM sorry, I am trying to use a recursive function
def write_data(data):
try:
for value in data:
print(value)
write_data(value)
meant to say recursive instead of iterative
 
So have you even tried to debug this? It would be obvious as soon as you started looking at what the values were.
 
Well, you're just passing the key right now, and the key isn't going to be a nested structure.
 
the key is itself a value
which has keys
 
The key does? That doesn't make sense. Can you give an example of the data?
 
8:25 PM
I don't see any keys that are nested structures. I see keys that point to a nested structure, but none that are themselves nested.
 
3 mins ago, by Skyler
the key is itself a value
that's not json then, keys are only strings in json (not that that matters for the thing you're asking)
 
@davidism The data they provided is JSON, they just seem to be confused.
 
I'm an idiot; ignore this
 
@davidism maybe im using the wrong term then, how would you phrase it given that sample input
@RobertGrant they are necessary for me since im working with outputs from larger software
 
You have a JSON object, and some of the values are also JSON objects.
 
8:27 PM
Duplicates are JSON (according to my quick googling)
But most parsers may barf
 
DSM
Yeah, they are. We were just talking about this a few weeks ago, weren't we? I remember being astonished.
 
But there aren't duplicate keys; I misread the data
 
yeah, just looked at it
 
@Skyler It's {'key': 'value'}, so only the left side of a pair is the key. You have no nested keys.
 
I still have no idea what @Skyler wants. You have a JSON file, just print it and you've already got the representation. Recursing over all its keys and subkeys one by one wouldn't be meaningful for any useful program.
 
8:29 PM
Yeah, I'm pretty confused too.
 
DSM
Maybe if you wanted to prettyprint the output?
 
import json
from pprint import pprint

with open('data.json') as data_file:
    data = json.load(data_file)

pprint(data)
 
@davidism for now the printing is so i can get an idea of how to seperate each element and easily show that am i accessing a specific element
 
DSM
(rolling my eyes) I mean maybe if you had to implement a prettyprint, Morgan. :-)
 
@Skyler you access specific elements by accessing them, not by recursing over the structure.
 
8:31 PM
@davidism well how would i arbitrarily access an element
 
@DSM my_little_pretty_printer = __import('pprint')__.pprint. There, I implemented my own. ;)
 
data['x']['y'][1]['thing'] access the value of the key thing in the second item of the y array from the object x in the data object
 
DSM
@Morgan: if you were a student I'd give you +1 for cleverness. The other 99 points, unfortunately, would stay at zero..
3
 
@davidism well lets say im reading a file and i dont know until reading if it is data[x][y][z] or data[x][y]
 
Starred
 
8:32 PM
@DSM I'll take it.
 
@Skyler then you should figure out what data you need
The API isn't going to trick you and sometimes return a different structure.
 
@davidism if it returns multiple types of different json files (corresponding to different things) how could you parse them though?
 
What api are you using that returns data different that what you ask it for?
 
I think they mean that they don't know the structure of the data automatically
 
@AndrasDeak yes
 
8:36 PM
Why not?
 
@AndrasDeak scientific computing stuff with multiple types of properties that in json files
 
it's a bulky poo output by something written by a researcher:P
 
beta program
yea
 
thank god it's not xml
 
kinda
 
8:37 PM
If I'm using the stackoverflow api, for example, I ask for questions and I get a list of questions, and I can look at that data and see what I need from it. It's not suddenly going to return a list of answers.
 
but if it would return the comments and links in comments, you'd have to check each comment, and check if each comment has a link to it
it's well defined, but not known a priori
Skyler wants exactly this: to crawl along the data and parse each field fully
without knowing in advance how deep those are
 
if i also succeeded in writing this its kind of useful as a general purpose tool so thats why a general solution would be interesting
 
DSM
The problem there is that advice depends on what the intended output is. It's straightforward to recursively walk the dictionary and print things out, but doing anything else depends on what the anything else is.
 
Fair enough, but not sure what the issue is? Just json.parse, then walk the resulting dict and do stuff per value depending on whether the value is another dict, a string or whatever
 
i feel like printing a tree of any json file i ever see that would become trivial
@RobertGrant so when i tried passing the value it passes the string
not the object
 
8:42 PM
If you just want to print it:
12 mins ago, by Morgan 'Venti' Thrappuccino
import json
from pprint import pprint

with open('data.json') as data_file:
    data = json.load(data_file)

pprint(data)
That will print a tree of any JSON you want.
 
@Skyler spend 2 minutes learning how to iterate over a dict; it'll be useful
 
DSM
This is the wrong room to humblebrag about this, but my bracket is currently sitting at the 98.2 percentile on ESPN.. it's not going to last though because I had Oregon and UVA in the championship. Stupid Syracuse. :-P
 
@Morgan'Venti'Thrappuccino with pprint is there a way to suppress those u's
 
@Skyler I have no idea, I suspect not. Those u's aren't actually part of the data.
 
def each_value(obj):
    if isinstance(obj, dict):
        yield from (x for v in obj.values() for x in each_value(v))
    elif isinstance(obj, list):
        yield from (x for v in obj for x in each_value(v))
    else:
        yield obj
 
8:50 PM
yield, woo!
I should really start learning python properly:/
 
@AndrasDeak ditto, first time ive heard of yield
 
for value in each_value(my_weird_data):
    print(value)
 
I have a strong suspicion that all my python code looks like Frankenstein's monster
@Skyler learn about generators
they are fun and cool and pythonic
 
@AndrasDeak second time probably, googling yield python led me to a SO question which I apparently favorited before...
 
:)
maybe one of our resident ninjas favourited it for you
 
8:53 PM
if you want to pretty-print the JSON as actual JSON instead of a python object representation, just use json.dump(the_json, indent=4)
or whatever indent value works for you
 
The yields and generators weren't required. This could have been done with normal recursion. The issue was a lack of understanding of basic Python objects and their usage.
 
@tzaman can i do something like random_var = json.load(the_json) then do json.dump(random_var, indent=4)
 
Which could have been solved by reading a tutorial and exploring the data in an interpreter. IPython's really good for that, it has autocompletion.
 
I do that usually ^
well, the ipython part
 
do we have a canonical for 'strings != names' ? stackoverflow.com/questions/36270972/…
or alternatively, how 2 list
 
8:56 PM
yes, it's in the canon
 
@Skyler yeah, that'll work
 
thanks guys, gotta run
 
DSM
I know I've seen good explanations of name != string != object around. Can't find any now that I want one, of course. :-/
 
Dynamic variable names are the road to eval
 
9:04 PM
At least that answer got downvoted.
 
I'm happy that dict's are a go-to fix for that
did nobody leave a comment for poor exec chap?:D
I've already instructed someone today about eval(input()), so I'll pass
 
Suggesting using exec just to get around a misunderstanding that strings and names are different is just wrong. — davidism 18 secs ago
 
thanks
 
also that answer, there's no point in keeping it.
 
OP might disagree
sorry for assuming that a comment might help:D
 
9:10 PM
I'm addicted to Sword Art Online
 
Prepare to be incredibly disappointed.
 
Dude, spoilers
 
Just stop after the first half of season one.
 
You know I can't do that now
 
The second half was at least tolerable in the books.
 
9:13 PM
I'm waiting for more seasons of that one with the cannibal giants who've taken over the earth other than high-walled cities
 
I got annoyed at that one too, although I lasted longer.
 
I just think their smiles are amazing
Makes them so much creepier than if they were the standard Lovecraftian nightmares
 
Both of them have great premises but are ruined by typical tragic anime character stories / behavior.
 
Yeah lots of anime stories have so much imagination and promise in their setting, but have pretty samey characters
 
Then again, I'm watching and liking Erased from this season, and apparently most people disliked it by the end.
 
9:16 PM
Like a lot of s-f I suppose
Hm, don't know that one
Basically I'm going through what's on Netflix
 
Watch Knights of Sidonia season one, then avoid season two at all costs.
@Kevin can verify that
 
Heh okay
Problem is I struggle with leaving things half-finished
 
Gargantia is on Netflix, I enjoyed that one.
It's a self-contained story, looks good, sounds good, and I don't remember being annoyed by the characters' decisions.
 
Cool. I will add that to the list :)
And KoS
 
Oh wow, Eureka Seven's on Netflix, watch that one too.
One of my favorite soundtracks.
 
9:24 PM
Cool. I will make an actual list now.
 
And there's a hidden second soundtrack: most of the episode titles are real songs.
I need to go through and make a playlist.
 
Thanks for the tips :)
 
user559633
I only watch obscure Afghanistanimation. And before you ask, obviously not dubbed (you philistine).
 
Nice. The Talibanimatrix was excellent.
 
user559633
 
user559633
9:35 PM
Oh. Shit.
 
9:50 PM
shine bright like a diamond
 
@tristan You ate too much plutonium?
 
10:06 PM
in a few pieces:D
though 4-5 kg would feel uncomfortable
so would the supercritical flash
 
Guys Pillars of Eternity is amazing.
 
Hehe I've only played a bit, but it's cool
 
It's basically Baldur's Gate but modernised.
 
Yeah
 
sounds great:)
does modernised mean proper 3d?
 
10:11 PM
I backed it
 
or nice axonometric graphics?
 
No, no 3D
 
@Robert oh really? Nice dude.
 
cool!
 
@Ffisegydd Now I'm the cool one in the room! Finally.
 
10:13 PM
What you've not known @Robert, is that you were cool all along.
 
DSM
Aaargh, used the wrong dup target and then had to retract. Could someone deal with this one?
 
Blossoms into new, confident self
 
@DSM target?
 
heya folks.
 
hey
 
DSM
10:19 PM
Either this or this would be fine.
 
DAMN it wasn't Python tagged.
;_;
 
DSM
Wait, can't I retag it and then you act?
 
Already done it.
I've retagged it.
Someone else may be able to hamma.
 
DSM
I can't because of my retraction. :-(
 
Possibly eating half an easter egg was a bad idea
 
10:26 PM
half? how big was this egg?
 
@inspectorG4dget: you about?
 
Not a massive one, but not bad. 15cm high or something?
 
solid chocolate, or hollow chocolate?
 
@inspectorG4dget: oops, mistaken identity, never mind.
 
Hollow :)
I say it was a bad idea because it's 11:30pm
 
10:28 PM
Google is telling me chocolate late at night can give you nightmares
Say hi to Freddy Krueger for me
 
Say hi to Python 2.4 for me.
 
AARRRRRGHHHH
 
@DSM @Ffisegydd should one of those targets be closed as a dupe of the other as well?
yeah, I'm closing the second one with the first one, edited the titles too
 
@idjaw My usual before-sleep snack is biscuits with nutella
no nightmares so far:D
Interestingly, stress and worries are much more strongly correlated with bad dreams
who would've thought so?:P
 
well now I'm eating chocolate
eating the kids chocolate
:D
gotta do it while they still won't notice their supply has decreased
 
user559633
10:43 PM
@AndrasDeak what is dead may never die
 
@tristan :)
explains your skin tone
 
user559633
git is broken. any tool that complains of change conflicts and those can't be resolved by drinking, screaming internally, and just telling it to prefer the upstream version is broken
 
found your bug
you were screaming internally
you have to make it external
 
user559633
haha externally too
 
user559633
10:51 PM
volkswagen makes a car named the "CC". i'm buying one just for the license plate and sticker jokes
 
It's a nice car
 
wider than the Passat making it more executive-oriented.
executive-oriented? I'll take two
 
If it's already pointed at an executive, why not?
 
lol:D
 
user559633
oh shit, it's wider? :/ i looked at length only
 
user559633
10:54 PM
we're getting pretty close to a that's what she said
 
user559633
shitty, maybe never mind as it's going to be parked on the street
 
oh, so you are actually car shopping?
 
user559633
oh, never mind, it's 73" wide, vs the passat 72.2"
 
user559633
@idjaw do you think i would joke about buying a car called the volkswagen CC so i could make groan-worthy compiler mentions?
 
yes? ....
 
user559633
10:55 PM
yes i'm actually car shopping
 
:D
Is the CC a modification of the same year Passat? Or do they take a previous platform?
because the newly designed Passat is pretty darn sweet
 
user559633
that is actually my criteria and i had a "uhhhhhhhhh" moment when asked by a salesbro
 
user559633
...pun..availability?
 
user559633
if the honda fit was called the honda fitness i'd own 3
 
user559633
yeah, the CC is like a passat+
 
10:58 PM
oh man oh man...was this taking with a cell phone and uploaded? here
this is amazing
yes yes it was...oh this is great
 
niiice, hand-drawn red censor blob
+1
 
@tristan is it pretty much down to the CC? Or do you have a few picked out?
 
user559633
@idjaw probably passat or the CC. i'd be fine with a honda civic, but they're around the same price as the passat, so might as well get something that looks a bit more polished to clients
 
You have to buy it. Then when they give you the keys, you can say "Call me St Francis, because I'm of a CC!"
50 mins ago, by Ffisegydd
What you've not known @Robert, is that you were cool all along.
Phew. Reassuring.
 
user559633
i'm going to get a 2014 or so because i'm street parking it in boston anyway, so there's no point in getting something super nice and new
 
11:04 PM
I thought Honda was called Acura on your continent
 
Yeah no need to get a new one. I got a late 2012 3 series; going fine so far.
 
user559633
acura is honda's luxury branch
 
@AndrasDeak Honda and Acura both exist. Acura is the Luxury line of Honda in North AMerica
 
user559633
@RobertGrant mazda or bmw?
 
user559633
11:05 PM
oh cool
 
@idjaw aaah, I see, thanks
 
@tristan Ah, company car...OK. Have you seen the A3? I think the Quattro is at almost the same price range as the CC.
 
user559633
yeah, if the car isn't something torquey or turbo-d and manual, it can be anything really
 
user559633
@idjaw well "company" as in "when i drive to investors and say 'y\'all got any more of that ramen money'"
 
yeah
I came close to getting the A3....but the non-quattro was pretty much a Golf
 
user559633
11:07 PM
yep!
 
so I couldn't justify the price hike
 
S3 is (was) better value than a Golf R though
 
absolutely
but at the price of an S3...is the A4 better bang for buck?
 
user559633
the new golf R is a beast now that they make one for men again
 
Is the R in North America?
 
11:08 PM
Any Audi that starts with an S or RS is definitely not good value for money
 
user559633
the R is in NA, yeah
 
user559633
offered in 6 speed manual again. not sure wtf is going on with an automatic AWD hot hatch that's meant to be thrown around
 
An old neighbour had an R8
that car was just ridiculous
 
Yeah a guy in our complex in SA had an R8
 
user559633
r8 is my dream car
 
11:10 PM
you can drive an r8 in the winter
that's insane
that guy was driving it in snowstorms
 
user559633
dumb quick and where it's metal, you don't rip it to fuck driving it at speed
 
Given that now I'm someone who's been cool all along, I have to say my dream car is pretty much the one I have now, but with auto folding mirrors.
 
based on the lines of cars we are talking about....if I had to choose something for all year...I really would not mind an S4.
 
user559633
my dream car would be a modern porsche in the body/style of a 1970s bugeye 911
 
Not that I wouldn't love to live in a world where the main oil supply isn't controlled by a bunch of genuine misogynistic pyschos, so I could feel okay about burning way more of it than I needed to, it's not, so I can't.
@tristan Hm yeah that's pretty close. Powered by Mr Fusion, of course.
 
user559633
11:13 PM
 
user559633
i mean
 
oh that's damn nice
 
I'd better sleep. Rbrb!
 
user559633
Take care bobert
 
later @RobertGrant
 
user559633
11:17 PM
unfortunately, my current priorities are safe/dependable/presentable/reliable
 
I have the exact same requirements
except I also added "no minivan"
I put it in my marriage clause before we got married
thought ahead
 
user559633
that restriction is unspoken
 
I refuse to minivan
it's not happening
I'd rather mold two sedans together
 
user559633
i'll van. but i won't minivan
 
yes
well now I'm all in to wanting to talk about cars. So, which CC are you looking to go for?
did you test drive it yet?
 
user559633
11:19 PM
 
user559633
test driving it tomorrow, 2013 2.0t 6 speed manual
 
awesome!
I have a Jetta TSI
I really wanted the GLI ... but I needed to make a decision and I was set on a VW
and none available
but that turbo is pretty sweet
 
user559633
i was also considering those. solid -- the 1.8t is a solid, reliable engine that they know how to build
 
user559633
if the CC doesn't work out and the passat we lined up as a backup is gone, i'll probably go with a jetta
 
get the GLI! :D
it's such a monster
 
user559633
11:23 PM
2.0t?
 
user559633
oh, that's up at 26k base. at that point, my lizard brain is like "dude get an STI or the R. alternatively, buy a new motorcycle, they can't tell you what to do HISSSSS"
 
oh man :(
your prices are so much better than ours
canadian car prices are insane
 
user559633
new business startup idea, sell US edition jettas as the "jettaye buddy" in canada
 
What would be a good close reason for PEBKAC?
 
user559633
^typo/can't repro
 
11:26 PM
agreed
 
No, it's more "OP is an idiot, and should learn about computers before trying to program them"
 
@tristan if we do small mods to it, we can totally do it. Isn't that how AMG got bought by Mercedes?
@MattDMo can you share the link? I'm curious now
 
user559633
Oh neat, a jetta but meant to be driven fast in the snow in the city
 
user559633
alright, time to run. later idjaw
 
later @tristan
 
11:29 PM
This one. Mainly the first part, though the second part is easily google-able.
 
mainly the first part?
I don't even know where to begin providing help
 
Yeah. "Where do I put my files to analyze them in pandas?" Anywhere you want, just pass the path to your initiating function.
Maybe that wasn't a good example.
 
Hey guys, is any of you familiar with multiprocessing?
I'm having a problem and I need advice
 
Please read the room rules. Don't ask if you can ask a question, just ask. If someone can help you (and wants to), they'll speak up.
 
@MattDMo I know the rules, I'm not asking to ask, but I need to initiate a conversation with an expert
I'm afraid it's not just a question
Anyway I'll try
I have a GUI program that I use to acquire data from a device. It uses QThread to create a thread that does the acquisition. I'm originally a C/C++ programmer, so when I first did this, I thought that I'm parallelizing my program until I learned about GIL in python... so now I added one more feature which has shown that my multi-threading is not really multi-threading...
The problem is that everything I do now is in that QThread class... it's all in that object. So I need the easiest way to maintain the program I have, and still spawn a multiprocessing thread that will do the acquisition in a new parallel thread with shared memory
Every idea I think about fails... nothing is working! This is probably I'm thinking about everything in C++ way... I think about pointers, references and values... and python doesn't work that way
How can I do this parallelization in the simplest way without destroying my whole previous work?
 
11:48 PM
Does QThread represent some qt c library object? It's probably not bound by the GIL, that's just for Python threads making Python calls.
 
Actually it's bound by GIL... I learned that the hard way, because I noticed that my GUI is freezing, and then found SO question discussing this problem
The library I use is PySide
@davidism
7
Q: PySide/PyQt - Starting a CPU intensive thread hangs the whole application

user1491306I'm trying to do a fairly common thing in my PySide GUI application: I want to delegate some CPU-Intensive task to a background thread so that my GUI stays responsive and could even display a progress indicator as the computation goes. Here is what I'm doing (I'm using PySide 1.1.1 on Python 2.7...

 
what the....there is no perma-link to the 'Callable types' section of the data model docs. That whole page is missing what should have more perma-links..
not even fixed in py3 docs
thumbs down
 

« first day (1990 days earlier)      last day (2951 days later) »