« first day (4269 days earlier)      last day (673 days later) » 

8:15 AM
hey everyone, hope you are doing well, I have a dictionary like {"key": {"date": "2015-02-13T12:37:49.237", "date": "2015-02-13T12:37:49.237"}} (actual is nested to around 5 levels), and my aim here to convert all the date keys to datetime.datetime, what is the norm on how I should do this? should I have a helper function that does inplace conversion or return a new dictionary without modifying the original?
I can convert using datetime.strptime, I just want to know for such scenarios, is an inplace helper an ok choice or not
performance or memory is not a concern, just concerned about readability / maintenance
 
There seems to be an issue with your example dictionary as it has the same key (date) twice
 
I realized I made a typo with repeating the date key, they are different names
@IvoMerchiers you beat me to it :p
I guess it should not matter (much) for this, the question is on the approach and not on the actual manipulation
 
@Jake Whether to do inplace or copy conversion depends entirely on your use-case. There neither a better nor a right way.
 
Both are valid options. Personally I would create a new dict, as mutating things always has the risk of creating hard-to-detect issues in the future
 
Personally, when all things are equal I prefer copy'ing because that reduces chances of hard to spot errors – but it can come at a serious performance cost, so it's not clearly better.
 
8:24 AM
I am working with around 20k entries so both the approaches do not seem to be tanking the rest of the code, but I guess when I go higher it might bite me
I might as well go with copying, since both you guys seem to have that as your personal opinion
inplace would save me memory, but is inplace any faster that creating a new dict?
 
yes, especially for nested data structures.
You are touching a lot less things that way.
 
thanks
 
8:51 AM
Btw, as you are concerned about readability, the more important thing to do is probably to add type hints to distinguish between both approaches. A pattern that I've seen in other libraries and that I like is that if I return the object, then it's a copy, and if I return nothing, then the object was mutated in-place
mixing both, so returning an object that's actually the original object, but mutated is something that tends to be very contra-intuitive for future work
 
I would like to run pdflatex command in bash from Python code and check if everything goes well. I found that I can call

def execute(command):
return(subprocess.check_call(command, stdout=sys.stdout, stderr=subprocess.STDOUT))

But if the tex file has and error, the pdflatx waits for user to press X. Is there a way to get the output of pdflatex to Python while the process is running and if the pdflatex waits for the X press, it sends the keypress to the program?
 
9:09 AM
You can try directly sending X as input. subprocess.check_call takes an stdin stream, and check_output and the higher-level run directly take an input parameter.
 
9:42 AM
I see. Well, I found that I can also call execute(['pdflatex','-interaction=nonstopmode','/home/jaakko/a.tex']) for my project.
 
 
4 hours later…
2:07 PM
messages = [
    {
        "message": "test message1",
        "tenant_name": "test1"
    },
    {
        "message": "test message2",
        "tenant_name": "test2"
    },
    {
        "message": "test message3",
        "tenant_name": "test2"
    },
    {
        "message": "test message4",
        "tenant_name": "test1"
    }
]
y = ["test1", "test2"]
Expected output is:
{
  "test1": {
    "messages": [
      "test message1",
      "test message4"
    ]
  },
  "test2": {
    "messages": [
      "test message2",
      "test message3"
    ]
  }
}
Tried something like this:
for ten in y:
    for msg in messages:
        message_details[ten] = {
            "message": msg["message"]
        }
print(message_details)
But couldn't get through. :(
This is the output I got:
{'test1': {'message': 'test message4'}, 'test2': {'message': 'test message4'}}
 
messages_by_tenant = collections.defaultdict(list)
for message in messages:
    messages_by_tenant[message['tenant_name']].append(message['message'])
 
@Aran-Fey Awesome! Thanks a lot!
Can you please explain this line? -
messages_by_tenant = collections.defaultdict(list)
 
2:26 PM
Not sure what's there to explain. Have you looked at the documentation of defaultdict?
 
 
3 hours later…
5:35 PM
After all this time, I've found one thing I prefer in R than in Python. One of my colleagues was trying to pass a JSON Lines file through a JSON parser, which obviously crashed. Unlike python's clinical traceback, the error was just trailing garbage which brought a smile to my face
 
 
1 hour later…
6:40 PM
Quick q, I'm trying to setup a custom authenticator for sparkmagic following their readme: github.com/jupyter-incubator/sparkmagic, and it mentions installing your custom authenticator from git with pip install git+git_repo_url/#egg=customauthenticator. Is there a pip equivalent with a local folder?
I know you can do pip install /path/to/project, but I'm unclear what the #egg= is doing
 
 
2 hours later…
8:43 PM
I found the relevant docs, but they're not very helpful
> egg: For specifying the “project name” for use in pip’s dependency resolution logic. eg: egg=project_name
 
Hmm ok, that's helpful enough in that I know what it's used for now. I should be able to figure out what I need from here, thanks!
 
if that helps I have a test env where I have a local git repo installed with pip install -e . and in pip freeze I see -e git+ssh://git@github.com/adeak/repo_name.git@deadbeefc0ffee#egg=repo_name
 
deadbeefc0ffee?
 
there's another one where I think I just did pip install . (not sure about this one) and it says repo_name @ file:///home/adeak/path/to/repo/
@MisterMiyagi well it's actually a commit hash
the repo is also not called repo_name
 
Well, I'm certainly glad that nobody else knows definitively why you need #egg
The best I found suggested to me that it was just a hark back to the transition out of easy_install and it just got carried on
@MisterMiyagi You let the coffee beans ruminate for the lifetime of the cow to assist in you own contemplation
*your own rumination. I ruined my own joke :(
 
9:10 PM
@AndrasDeak--СлаваУкраїні lies, damned lies and examples!
 
9:22 PM
https://stackoverflow.com/questions/72749212/problem-with-the-use-of-break-and-else-in-conjunction-with-a-for-loop

Another book to warn about.
 
Don't judge a book by its cover, judge it by its eval usage
This just in: eval is worth more than 1000 words
 
replace == with is on line 4 and you've got yourself an "example snippet with as many antipatterns as you can fit in it"
 
Hmmm, if an image is worth 1000 words, then a book with less than 1000 words should be judged by its cover
 
That's not a very long book, though.
one random page in that book has 393 words, excluding header and formulae
Well, not entirely, this includes inline formulae.
 
9:36 PM
Children's books are probably shorter than 1000 words
It's not unrealistic
 
For very small children, probably. But then you indeed want to judge by the cover :P
 
https://stackoverflow.com/questions/tagged/time-complexity
this tag is full of homework questions. Isn't there some kind of "how do I analyze code to determine time complexity" canonical? Or else is there any actually on-topic question behind any of these "what is the time complexity of this artificial example code" posts?
 
On topic? Technically yes. Interesting, worth looking at, helpful for future readers? Well...
 
9:53 PM
barring a dupe of some reference (similar to the highly controversial regex reference), I think they are really all too broad. OP seemingly never offers any insight nor highlights any specific point of confusion: it is only ever "please compute the big-O value for me".
I don't see why that is any more on topic than "please run this code and tell me what the output is."
 
> if your question generally covers…

a specific programming problem, or
a software algorithm, or
software tools commonly used by programmers; and is
a practical, answerable problem that is unique to software development

…then you’re in the right place to ask your question!
yes, "please run this code and tell me what the output is" is on topic
 
also, the fundamental techniques in question are really all math questions, not programming questions.
 
saying that CS is not directly related to programming "because it's math" is also a bit of a stretch
 
@AndrasDeak--СлаваУкраїні a horrifying conclusion. I'm tempted to go to Meta to ask them for a reason why this shouldn't be the case.
(also, I mean, we do have cs.se for a reason)
 
@KarlKnechtel knock yourself out
Although first I'd ask myself what close reason you'd use for such a question.
Sounds like you're going for "lacks effort" or "too localized", but, you know, those haven't been close reasons for a long time.
 
9:57 PM
well, yes. this alludes to "seriously, wtf was everyone thinking getting rid of those", round n+1
people have been abusing the other close reasons ever since, arguably in protest but mainly because downvoting doesn't keep the site tidy and lets people have the wrong impression about the intended site culture and vision, while also letting them stew about how mean SO users are with their comment-less downvotes
 
There's a resolution though: not all questions need to be closed. There are many that just have to be buried in downvotes because they are crap questions. On-topicness is not the holy grail of question quality.
 
Perhaps I am the only one who believes that the site is actively made worse by the addition of questions that deserve a negative score, regardless of the formal close reasons or application thereof.
this is partly informed by my experience of other pseudo-social media with voting systems.
 
Well closure is important for roomba. Ideally crap downvoted questions don't get answers so they'll get roombaed too.
 
the roomba itself is too opaque for my liking. Even its existence is only known to meta users and chat regulars, and meta and chat are both in turn not very discoverable.
I certainly can't tell you by rote the rules that it operates off of, nor tell you where to find them.
 
You don't have to. It's enough that it works. But if it makes you feel better: there's a roomba forecaster userscript that tells you if and when a given question will be roombaed and why.
 
10:05 PM
but also, the system actively incentivizes answering crap downvoted questions. Relatively few people notice an arbitrary crap new question, and downvoting it generally reduces its visibility. The answerer, however, has an easy question, and answers disproportionately come from people who will comb through the list for things that are easy to answer, other mechanisms be damned. The answerer has a high probability of getting a +1 from the asker, and expends relatively little effort for it.
 
that's why people should be a lot more generous with downvotes on answers too
 
The would-be duplicate hammerer is not incentivized by reputation (I don't care about reputation since I have >25k and no more privileges are forthcoming, but also I am incentivized by vision). Would-be duplicate voters have an even worse time.
 
Gamification has been an incentive against site quality for a very long time. This is a fundamental problem.
 
yeah, answer DVs are the tool I have, and I've been using it, along with polite comment rebukes for the more experienced users. I don't think a lot of them care; if they're still doing it past 10 years and 100k rep....
 
yeah, the only point of leaving comments on these answers is to get revenge downvotes
 
10:08 PM
I actually haven't been having issues with that lately.
 
Me neither, but then again I've stopped leaving pointless comments :P
 
Separately: https://stackoverflow.com/questions/72749846
Do we have anything like a canonical for "I expected `for x in y:` to give indices rather than elements, so I got an error from doing `y[x]`"?
 
yes, hold on
hmm, I would've sworn we have it in the canon
there has to be something more frequented
stackoverflow.com/questions/51748786/… seems like an exact dupe for what it's worth
 
10:26 PM
also: trying to find the right canonicals for combinatorics questions is an absolute nightmare
stackoverflow.com/questions/104420/… has a lot of useful information, but a bunch of top answers don't actually address the question that was asked, which is itself not very clear and which most OPs would definitely not recognize as a match for what they're doing
a big part of the problem is that the people who ask these questions basically never actually know the relevant terminology, and say "combinations" to mean everything vaguely related
 
that shouldn't stop you from hammering a permutation question with a permutation dupe target
 
I wrote stackoverflow.com/questions/68822603, but the question isn't a great prompt either
er, the answer, I mean. stackoverflow.com/a/68823716/523612
 

« first day (4269 days earlier)      last day (673 days later) »