« first day (4070 days earlier)      last day (861 days later) » 

12:05 AM
I have this pastebin.com/zcki82Kz JSON response and I would like to make a list of all the values that fall in the field "tweet_text" however no matter what I do I am not able to access that, how do I make a list of all values in the key "tweet_text" from the response?
 
 
1 hour later…
1:15 AM
NVM figured it out
 
 
7 hours later…
7:53 AM
Cbg
 
8:39 AM
cbg
 
 
1 hour later…
9:45 AM
Hey I get: Cannot find reference 'URLError' in 'request.pyi' but it's there. Where would I need to add it, so that pycharm recognizes it? I remember there being a file where one should add it and many libs do that, but not all and not for all the objects they define
 
10:00 AM
maybe this helps
disclaimer: i dont know pycharm.
 
Unfortunately no, I mean it's a valid workaround, but I'd like to fix the problem at the root. Which is the lib itself should define something additional somewhere, so that the warning will disappear for everybody using urlib. The other thin just fixes it for me
 
gotcha
 
@Hakaishin wait, is the name you mentioned above 'request.pyi' the actual name or? since there an additional i in the name
 
@Hakaishin Is the pyi from PyCharm itself or from typeshed?
 
from pycharm, it's the normal urlib.request module
 
10:17 AM
URLError is from urllib.error, not urllib.request though
 
ah lol, it imports it from there which imports it from error right. I didn't even check assumed it's the other issue which happens sometimes. Thanks :)
While we're at it, does somebody know if there is a way that I can call django functions without a request parameter? Because 80% I don't need it, but django needs it, otherwise it fails
 
10:41 AM
Use Flask? :P
 
"Have you tried turning it off and doing something else?"
 
VSCode + Flask gives me a chance. PyCharm + Django is the worst combo for me to help with! That said, I don't think you need to pass the Request through every function call?
 
@roganjosh not every, just the most top level, but still I'm adding # noinspection PyUnusedLocal like crazy :D
 
Is there some reliable way to copy a WeakSet? I get timing issues with threads when doing list(weak_set) because items get discarded during the copy iteration.
 
I don't think that's true, though, because it's needed to keep the context alive?
 
10:49 AM
@MisterMiyagi What are "timing issues"?
 
A nice way of saying "things blow up with Heisen-RuntimeError: set changed size during iteration"
If I'm unlucky and the other thread runs at the wrong time, the items of the WeakSet get garbage collected while the current thread copies the set via list(weak_set).
 
Huh, I thought WeakSet had protection against that problem built in
 
it does-ish but not thread safe apparently.
 
I've found various Q&A like this one which TLDR to "it's all perfectly safe. Unless you use threads, LOL".
 
Hmm, why is it not thread-safe? I can't see anything wrong with it
 
11:00 AM
Well, for starters I don't see a single bit of synchronisation anywhere in there.
But so far I only know for sure that it doesn't work. ^{TM}
I can try to build a MRE later on.
 
Oh, it really isn't thread-safe. Thread 1 runs if self._iterating:, then Thread 2 creates the iteration guard and starts iterating, and then Thread 1 runs self.data.discard(item).
 
its safent
 
That seems extremely unlikely to me, but apparently Miyagi-PC disagrees
 
11:52 AM
Hey guys, just trying to understand a function in this library, my question is that do I need to do json.dumps('variable') or do I not?
the from_json method, does it want me to use json.dumps(...)
I guess I want to do knwo, what does this mean?
Deserialize a JSON-serialized instance.
 
12:04 PM
From what I've seen it can be anything that can be read as JSON
 
@S.Code it means take something that was put in a json (aka serialized.) and bring it back into your in-memory object (in this case, a ServiceAccountCredentials Object)
 
Nevermind then
 
So deserializing is reading a json and converting it back into some in memory object (be it dictionary, lists, specific classes, or so on)
 
I'll stick to perl laurel
 
@S.Code You can do either. The function accepts a dict, but if you pass it a string of JSON it will load it into a dict itself.
From the source:
    if not isinstance(json_data, dict): json_data = json.loads(_helpers._from_bytes(json_data))
 
12:32 PM
@PM2Ring this code you sent is complicated for a newbie to python like me haha
but its cool, i have given up on this task for now, shall get to it another time haha
 
@Aran-Fey PyPy3 unittests on github actions disagree. The best kind of error situation there is! 🥳
 
1:28 PM
import subprocess

try:
    subprocess.check_output("curl --request POST -k -s --noproxy "*".....)
    subprocess.check_output('curl --request DELETE -k -s --noproxy "*".....)

except Exception as e:
    print("ERROR: \nIn POST :{} \nIn DELETE {}:".format(e))


If any one fails in try block It should give the respective error messege :

ERROR:
In POST : Some error............

or

ERROR:
In DELETE : Some error............
 
So make 2 separate try blocks then?
 
That the thing I want both to be in same try
 
Why?
 
To donot repeat the try except and messge twice ..
 
Unfortunately there are limits to how DRY your code can be. Writing 2 try blocks is the least bad solution here
 
1:34 PM
Ya I understand , but this to be in one try block only, Can you check for any relative solution, Thanks
 
@rowoc any reason you're calling curl and not using something like requests ?
 
Its been use as a BitBucket's REST API in the script @JonClements
 
well... unless I'm missing something - it doesn't matter - you could still use requests
that'd give you finer grain control of exception handling and error messages
 
But the Script is been already using this , I just need to protect both of then in one try except and giving receptive error message
 
How about using a loop like for method in ('POST', 'DELETE'): try: curl(method)?
 
1:42 PM
It'll be worth bearing in mind: If the return code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and any output in the output attribute. as well
 
POST and DELETE are polar opposites. Handling them both in a single exception makes the code harder to understand
I'd go so far as to ask why there's a single method doing that in the first place
Especially with the DELETE following the POST. I don't know what that code is doing at all
 
@roganjosh DELETE is deleting the branch
 
What branch? You've not given any context behind this
 
The one that was just deleted, I'd guess.
 
@roganjosh git|teamcity branches
 
1:47 PM
Is this supposed to be a test for the API?
 
If we're guessing at your code, this should be a red flag, no, @rowoc?
Before your ambitions of getting an exception handler to deal with two completely different things in a single block - maybe the design needs a rethink?
 
Y'all heard that *BOOM* noise? I think that was the this-is-a-really-bad-idea detector exploding. I swear they don't build these things as sturdy as they used to
 
@Aran-Fey that or just a lot of wear and tear they were never designed for :)
 
@Aran-Fey Sorry, that was me... goes back to weakref'ing
 
Can you get the remains of this thing garbage collected while you're at it? Thanks
 
1:53 PM
so that weakref problem..can you simply make your own iteration for it with a lock
maybe by say, subclassing it for example
 
I don't think that's enough without remaking everything else with locks as well.
I'm currently trying to figure out wether list(some_set) or set(some_set) is GIL-atomic. Then I could copy the internal weakref store safely. Since the weakref callbacks only clean up the original weakref store, my copy would be safe to iterate over.
 
I have a jinja2 filter, what do I call the list to not shadow list?
@register.filter(is_safe=True)
def index(list, i):
    try:
        return list[int(i)]
    except IndexError:
        return None
l is ambigious, my_list sounds stupid
 
@roganjosh Okay, but can all try for once to achieve for this solution. To print respective error message
 
@ParitoshSingh Locking is pointless if you don't lock on both sides - you'd have to monkeypatch self._remove as well
 
makes sense
 
1:58 PM
@rowoc You're asking us to make your code worse. Do you understand that this criticism is meant to help you, not be pedantic
 
My workday has been frustrating enough to consider "just" writing my own WeakSet, and I'm desperately trying to avoid that.
 
@Hakaishin PEP8 says list_. I think.
I recently wrote a WeakList. It's not so bad. Pretty much worked first try
 
@Hakaishin does that actually do anything that isn't already builtin to jinja?
 
@Hakaishin sequence is my go-to alias for lists and friends.
 
@MisterMiyagi I go for sequence if it has a length and indexable... iterable if it can only be consumed or something that is only going to be iterated across even if it's a sequence
 
2:02 PM
@Aran-Fey I'm sure it'll work. I'm just not sure I would stop at that point... :D
Still need an excuse to use Cython after my async trials were a bit hit and miss.
 
Come to think of it, why does self.data.discard(item) even work? I thought weakrefs are only hashable as long as the referenced object is also hashable. When the object dies, what happens to the weakref in the set?
> They will maintain their hash value even after the object was deleted.
That answers that
 
2:54 PM
Looks like set(some_set) is GIL-atomic. If you hear an earth shattering scream from my direction, it's not.
 
On account of it being a NO-OP?
import dis

a = {1, 2, 3}
print(dis.dis("set(a)"))
That's promising, I guess. But I don't know what can happen between LOAD_NAME and CALL_FUNCTION
 
As far as I can tell, it calls set_update_internal which calls set_merge which will directly copy the content.
Probably.
 
Are you analyzing the CPython code or the PyPy code?
 
CPython so far.
 
Tangential: You clearly know a number of languages MM but you're hinting at you using PyPy for some stuff - what's the driver for that?
From my latest introspection scan, I guess I've always thought "I can do this in Python" or "I guess I need some other language". I've never once thought "I need PyPy" but clearly it has a spot; maybe I'm just not seeing it
 
3:12 PM
I've used it for personal stuff and speed comparisons. Just never in a professional setting.
 
It's not so much that we need PyPy but rather that we don't want to lose the option.
 
At least MM is on the side of Python and not that nasty Cobra Kai :)
 
@roganjosh How about "I already have dozens of files and thousands of lines of working, tested code. I wonder if I could easily make it go faster?"
 
Is that the niche, then?
 
Adding recursion to your code automatically makes it better, so using a Python engine written in Python is a no-brainer
6
 
3:19 PM
We're pretty much set on doing things with Python because it's the only thing we can reliably deploy to all the weird systems out there. There's also the problem that most of our minions aren't exactly bred to be programmers. So the non-Python stuff has to be absolutely minimal.
I'm forcing PyPy on our pipeline so that a) we can get that extra speed if we need it and b) because it catches all the weird concurrency bugs that CPython just refcounts away until it doesn't.
 
Moral of the story: Never concur, it only causes problems
 
I concur.
 
Ok. That makes sense. Every time I hear complains about new languages, I just default to a stern expression and "you made me learn R for my first week and expected me to understand that". So far, it's a winning formula
1 week is quite enough. It builds resistance without becoming infected
 
Ugh. I understand that some people need to use R, but I'm happy that I don't.
Tangentially: I finally found PyPy's set implementation! Yay! takes off spelunking gear
 
Having alternatives to CPython is probably good for the ecosystem even if I personally will never use them
 
3:31 PM
It's the one language I take a stand on. "Oh, you want to make a Shiny app for this? You're on your own - I wipe my hands of the whole thing"
 
...and that was the last anyone heard from MM for a very long time... :p
 
I try not to complain about language choice too much. I inherited around 1m LOC of a poorly documented offshoot of BASIC written by people who had no business writing it. I pretty much live in a perpetual state of self loathing. I figure any language choice people have is better than this.
 
Not if it's PERL.
Tangentially: w_set.sstorage = w_iterable.get_storage_copy() looks atomic enough to me.
 
Maybe every once in a while the Pypy team pings the CPython team and asks some obscure Question From Hell about Python's inner workings, which no other team on earth would need to know. Maybe this leads the CPython team to brush the dust off some neglected corners and notice, hey, this could be refactored and made 1% faster
 
AFAIK they're a major driving force behind hpy
 
3:47 PM
I sleep soundly at night knowing these capable warriors are defending me from design problems beyond my comprehension
 
4:34 PM
@MisterMiyagi interesting
 
honestly agree about using Pypy (I have been using it from time to time when I was curious of the speed difference in personal project). I think it's fine to use x,y,z langs, even if it look weird or a niche...as long as you got your priorities checked of course.
 
4:49 PM
I suspecct Pypy aspires to not be considered weird or niche, or an option that should be chosen after carefully weighing one's priorities... They aspire to be the de facto default choice because they're better than the alternatives in every way
 
 
1 hour later…
5:52 PM
I should've asked this earlier, but what is the appropriate flag for plagiarizism in answers?
 
@Axe319 custom flag with a link to what it is plagiarising from...
 
That's what I thought. I didn't include the link to what it's plagiarising but it's the accepted answer in the linked dup.
 
@Axe319 you can retract your flag and raise it again. And please don't onebox crap here. Especially posts that need mod attention.
 
@AndrasDeak My bad. It won't happen again.
 
no worries
 
6:18 PM
The good news: the problem I've been poking at all week is equivalent to a well-understood mathematical discipline, and a variety of techniques can provide me fast and correct solutions.
The bad news: the discipline is linear programming, the one course in college that I fell asleep in the most.
What kind of programming is this, even... It can't even print Hello World
 
6:29 PM
If you can't print hello world because that's modifying impure states, then you're in Functional Programming :)
 
7:24 PM
I think I can skip some of the hard parts while I relearn three months worth of material, because all of the equations I'm trying to solve are guaranteed to have at least one solution
I won't have to watch out for impossible states like a < b; b < c; c < a... Although maybe I will anyway, for the joy of it
 
7:41 PM
Programming is like a volume slider: If it's linear, it's no good
 
I wonder if there are any regulations for sound hardware manufacturers, or if they just arbitrarily decide how to map the volume slider number to real-world loudness
If two different speakers both produce 60 decibels when the slider is at 25, are they guaranteed to also be identical at slider value 42?
 
I don't know about hardware, but when it comes to software it's a mess. Reddit has a terrible volume slider (and terrible video player in general), for example
 
Sounds about right
 
@Kevin this look promising :)
 
"How best to allocate resources to maximise profits" -- bullseye
 
7:51 PM
even found a potential python api for this too, though I didn't try it (but the readme give a rough idea)
uh, the order of things in stuff like prob += x + y <= 2 kinda look like LISP but without parenthesis
maybe that's just me though
 
You don't often see += and <= on the same line, so it's a bit uncanny
 
@Kevin PuLP?
 
that's what I posted above (the other link seems to use it to solve some example too)
 
We use pulp a lot
PuLP/pulp
 
I see; didn't know about it before I searched for Linear Programming and found the two links above
 
8:01 PM
pulp is a solid contender
 
You have that or Google-OR. I'd be using them a whole lot more if their implementation of drivers breaks for vehicle routing problems wasn't broken... for 2 years
Or Gurobi... I have seen the VP drop into this chat once but he didn't saying anything. And they're the market kings
 
 
1 hour later…
9:22 PM
What's the recommended way to annotate an orderable (i.e. supports <, >, ==, etc) object? Any?
 
 
2 hours later…
 
11:41 PM
The Advent of Code site is adventofcode.com/2021
...do people prefer to do AoC in base Python than pandas? What'e the general attitude to package use?
 

« first day (4070 days earlier)      last day (861 days later) »