« first day (3918 days earlier)      last day (1029 days later) » 

12:04 AM
What do you guys think of this oddity? I can't explain why 4 is added.
(Pdb) np.finfo(np.float16).max
65500.0
(Pdb) float(np.finfo(np.float16).max)
65504.0
 
 
3 hours later…
3:39 AM
cbg
 
 
2 hours later…
user16280768
5:16 AM
How to do parallel processing for multiple files in a directory?
 
5:59 AM
 
 
2 hours later…
Cant enter the url
 
@Kwsswart why?
 
Wasn't working at first but got it in the end ^^
 
is there a way I can create a "nested itemgetter"?
my_dict = {'a': {'b': {'c': 'value'}}} I want something like operator.itemgetter('a', 'b', 'c')(my_dict) which will give me 'value'
what I shown does not do what I want (I understand it checks for keys 'a', 'b', 'c'), but I want itemgetter to work in a nested manner
 
8:05 AM
Did somebody try the github copilot? It sounds mostly useless, but I'd still like to try it. Sadly it only works in VS Code not pycharm. i wonder if this could be the next killer feature for IDEs
 
@python_user lambda my_dict: my_dict['a']['b']['c']
In other words, no
 
ok, maybe I am approaching it wrong, context in case: I get a "path" like /a/b/c which I have to use to get the value from a dict
stackoverflow.com/questions/14692690/… guess I will just use normal dict indexing
 
8:34 AM
@Hakaishin So far I haven't been happy with "AI assist" for code.
They tend to replicate the average quality of public code.
 
Is it out for testing?
 
Speaking of other tools. Haven't tried the GH copilot itself.
I'm right now looking at the promo snippet of kite. Would make for a nice drinking game on deprecated/inadvisable coding practices.
 
I have mixed feelings about those tools. On one hand, they all suck. On the other hand, some of them probably suck less than vscode's builtin auto completion.
 
@CoolCloud if you sign up
 
Yea I did, they are like wait till its out?
 
8:45 AM
Well I guess that's that :P I stopped at the signup
 
that looks cool, but I am not sure how well it is in actual practice
 
@Aran-Fey I have not been disappointed with vs code's auto completion(yet) but sometimes they cause annoyance, they show everything except what I want in the top.
 
@CoolCloud for me they show everytime everything i don't want in the top. Or nothing at all.
 
@Aran-Fey Is it that bad? I mostly use typehinted code these days, so autocompletion is a freebie for the IDE.
Now syntax autocompletion, like writing a __main__ guard on keyword – I'm probably too old to appreciate these things.
 
I imagine it has improved over time, but I'm not really sure because I basically turned it off. When I started using vscode, it was absolutely terrible
We're talking like "I pressed Enter after writing if True: and it inserted a whole line of code... in the same line" kind of terrible
 
8:51 AM
PyCharm does that as well. Hate it.
 
@MisterMiyagi wait what? No? I never did that?
 
Anything that interferes with just typing things is super annoying.
 
Sometimes I'd write an __init__ method and get a Logger.__init__(some, random, arguments, but, no, self) out of nowhere
 
@Aran-Fey Okay, that does sound worse than what I'm annoyed by. :P
 
9:08 AM
it is my understanding that vscode semi recently completely rehauled their auto completion
 
Interesting. I've also been getting some warning messages about some deprecated config values, so maybe I should try resetting my settings
 
@ParitoshSingh They did something funky that I can't replicate in some versions of the server version (it's on one of my workspaces but I can't remember which). It insists that import numpy as np should be import numpy as numpy and you have to fight it :/
 
that sounds like a downgrade, not an upgrade haha
but ive heard very good things about their new python language server stuff
so maybe your workspace still has it disabled perhaps?
 
There's a few things wonky with the server version (at least as it's implemented in our workspaces). For example python-indent just isn't in the package repo for some reason. The Desktop version, though, has great auto-completion facilities now
 
9:33 AM
i must admit vscode has been doing some stuff that makes me tempted to give it another shot, such as codespaces and native notebooks for example
i just wish i liked it out of the box more. my biggest gripe about tools that give a bunch of options is that often users are expected to tweak them to get a good experience, and many users are perfectly happy with that. i am not.
 
I thought you were already won over ages ago?
 
nah, i tried to like it, but it just didn't stick
for me, i think i got spoilt by spyder somewhat. it's integration with an ipython repl is unparalleled. but for me, vscode by default was showing a lot fewer lines of code on my screen too, and trying to resize the app always seemed to make something feel off
 
Huh, bad memory on my side :/ FWIW there are a couple of things that are fiddly (for some reason I can open settings.json accidentally but never when I actually want it. But once you get familiar with the config you like and the plugins you want, it's literally a 5 min job to set it up from scratch on a new PC
 
the real nail in the coffin was issues with trying to activate conda environments
 
Environment swapping is just a quick dropdown now, and it'll list your conda envs as well as any custom envs in your project directory
 
9:38 AM
i think that was a thing even when i tried it maybe? but either it's detection, or more specifically it's activation was a bit wonky
 
Not sure, it could be that my complete defuddlement in setting up Python on my Mac somehow landed in a happy place that means it can find them. I don't even want to think about the snake pit I managed to create when I first started. <Insert tie-wearing dog "I have no idea what I'm doing" meme>
 
hehe. i do think that i might be able to give vscode a fairer shot now that i know more about it, so it's definitely on me too in that sense
 
10:32 AM
@ParitoshSingh conda ugh. I don't really like vs code, but there I would blame conda
 
heh, conda is fantastic, and you can't change my mind there, im afraid :)
 
10:50 AM
@ParitoshSingh I've been teaching for 4 years now and I have seen it butcher systems so completely. Especially on Macs. and that more than once. But I guess this might be more connected to the user and less with the tool.
 
possibly. one big learning is that you really should use environments if you're ever messing with conda. though i suppose that applies to python in general as well
but it's been rather fantastic at installing packages and dependencies where the packages themselves arent necessarily "just python". and it's really come through on some installs that have otherwise been absolutely miserable.
 
@ParitoshSingh ah there is the problem. It tries to do more than one should do :P It's just python or c++, nothing else needed xD
 
11:08 AM
hm. that's like telling git that it's doing too much, it should stop the version control from it. conda is for installing binaries, it doesn't care what language you're using. but that's always been what it's built for. this isn't on conda if people want to use it for a much narrower scope and then blame the tool that they decided to pick, really.
 
12:04 PM
*scratches head*
y = 1

def foo(x=(y := 2)):
    print('y' in locals())  # False
    print(y)  # 2

foo()
 
so asspression in function definition is global?
 
Oh, that actually makes sense
Yeah, it does overwrite the global y
 
print(globals()) FTW ;)
 
12:19 PM
so def foo(local_x = (global_x:=[])) is the same reference?
 
@MisterMiyagi should be the abstract of the PEP
 
laurel
 
sorry what does := do within these
 
you don't want to know (it assigns)
read the PEP linked by Miyagi, only to know what not to use (almost) ever
 
but essentially assigns the same as = or am I missing the use
 
12:27 PM
It's meant to be the brilliant feature of C's assignment which you can put anywhere, because python was too readable
If you want to see lukewarm reasoning for why it's necessary, read the PEP
Just beware that some of the official examples require eye bleach
 
Will do
 
@AndrasDeak In my heart, it always will be.
 
Disclaimer: it's a divisive and controversial feature, and you're only hearing one side from me (but that side's all you'll ever need)
 
I like how there are more exceptions than use cases
@AndrasDeak amen. I was initially totally against it like you, reading the pep again it does not sound so bad, although I don't see myself ever using it. And Arans example is so confusing if you don't know it.
@Kwsswart it's = in places where you would never think of putting an assignment
 
@Hakaishin It's very useful in very specific situations. My main gripe with it is that it's way too easy to abuse the syntax in way too many wrong situations, so the tradeoff was not worth it.
 
12:32 PM
Struggle to see why I would need to use it but good to know its there ^^
 
yes, you don't need to use it
 
the best thing 3.8 brought are format strings, otherwise I haven't used any new features
 
@Hakaishin 3.6 you mean
 
yes :P
But I only learned about them in 3.8 :D
 
I'd hate asspressions with 1% of the current vigor if it were only allowed in [whatever the header of conditionals and loops are called]
 
12:36 PM
@AndrasDeak not a massive fan... but very convenient if you're doing an re.search or simliar
(jget more annoyed by people throwing so much into f-strings)
 
@JonClements which would normally look like if res:=re.search(patt, str): ..., correct?
 
I use the walrus operator from time to time, for non-silly purposes.
I thought I would use it all the time for silly purposes, e.g. intentionally complicated one-liners, but it's almost too easy to use for that
 
 
1 hour later…
2:06 PM
Man caches have ruined 3 consecutive days now. Why can't everything be live
I wish I could have an orb around me of a few dozen meters which sets all devices and things in existence to debug mode and disables caches
 
The IT industry really does need more powerful orbs
 
2:40 PM
I have tried the 'Hardest Refresh' and it worksss :)
 
 
1 hour later…
4:03 PM
the last step in that process is to login to a central server to push logs. Unfortunately, only the first "lo" from "login" made it into the logs... and the system crashed from a buffer overflow
 
 
1 hour later…
5:17 PM
If I have a python project and I make a venv for it and do some work in a git branch, but then need to switch to a different branch to do some work that also involves changing depedencies, do I need to remove/remake or somehow otherwise update the venv when I switch branches?
 
If the dependencies are different and non-compatible, I would use a different venv for the other branch.
Unless you store the venv within Git itself...
 
stackoverflow.com/questions/6590688/… suggests variations upon the core idea of "keep your requirements.txt file in your repo, and generate your venv from that"
 
6:10 PM
> I use pip freeze to get the packages I need into a requirements.txt file
That's the top answer? Sad
 
Is this one of those things where the answer with 400 upvotes was the industry best practice in 2012, and now it's hilariously primitive?
 
Given the popularity of that pip freeze thing I suspect you're right, but I'm pretty sure it was never a good idea
pip freeze lists all the modules you have installed, which is decidedly different from your project's dependencies. (Because the modules you have installed include the dependencies of your dependencies.) It's a quick and dirty way to get a list of modules you can install to make the code run, but that's it. It's not something you should use for your setup.py/pyproject.toml
Maybe one day module A will no longer depend on module B, but B will still be there in your venv and your requirements.txt forever
 
6:28 PM
Ok, sensible
 
Or maybe A depends on B if you're on Windows, and on C if you're on linux... and every time someone makes a commit from a different OS, the requirements.txt gets rewritten for no reason
 
Are there any tools more suited to finding your True dependencies? I suppose a bulletproof solution is undecideable, but you can probably get pretty far just walking over the AST looking for import statements
 
i guess the best way is to still maintain the list from beforehand if possible
 
Quick google search led me to pipreqs
 
6:40 PM
Yeah, usually you do it manually, and if you have a proper testing setup you'll catch missing dependencies quickly anyway
 
Yeah manual is probably the sensible choice, but I do love automating things that shouldn't be automated
 
honestly, this should be automated. it just is a lot easier to do if you haven't already "done the damage" so to speak
like, if you start from a new env this is trivial to create automatically and keep synced
 
@Kevin there's wim's johnnydep, not sure if that's for direct dependencies or recursive ones
probably both
Hmm, or maybe not, that might use this information as input
 
user14492304
7:18 PM
:52584950
 
user14492304
y = 1

def foo(x=(y := 2)):
print('y' in locals()) # False
print(y) # 2
Can you explain this?
 
It's already been explained though? It sets the global y to 2
 
user14492304
I mean this line x = (y: = 2)) .does this work like golang??
 
user14492304
y:=?
 
user14492304
Is this new in Python?
 
7:27 PM
that's the walrus operator, aka asspression. New as of Python 3.8
 
On the other hand, the scoping of default value expressions is not new. It's why def f(x=[]): does what it does.
(For those unfamiliar with the default mutable gotcha:)
>>> def f(x=[]):
...     x.append(1)
...     print(x)
...
>>> f()
[1]
>>> f()
[1, 1]
>>> f()
[1, 1, 1]
>>> f()
[1, 1, 1, 1]
>>> f()
[1, 1, 1, 1, 1]
 
hmm..the two arent related are they?
i thought x just "latches onto" the function object so to speak
 
user14492304
If x is not in foo function locals, then where is it stored?
 
x is in the locals. The default value for it is stored in f.__closure__. Brain fart
It's stored in f.__defaults__
 
They're similar in that the expressions execute in the scope that contains the function. They're different in where the resulting object is stored and/or what it gets bound to
 
user14492304
7:44 PM
def foo(x=(y := 2)):
print(locals()) # False
print(y) # 2
Well here ...where is "y" stored??
 
For the 3rd time... in the global scope
 
 
2 hours later…
9:25 PM
Hello
 
Hola
 
10:16 PM
Lets guess what (0).bit_length() returns :-)
 
0?
 
You'd be right
but the function would be wrong :-)
 
Why, what would you expect? 1?
 
because you need 1 bit to hold 0
Return the number of bits necessary to represent an integer in binary
 
I think 0 is correct. When they say "number of bits necessary to represent an integer in binary", what they really mean is "represent an integer in binary, and leaving enough bits so that all other non-negative integers can be represented as well". If the only 2 integers you need to represent are 7 and 13, you can do that with 1 bit, you don't need 4. Similarly, if 0 is the only integer you need to represent, then you can do that with 0 bits.
In retrospect, the first sentence isn't really related to the other 2. It essentially boils down to: If there's only 1 possible value, why do you need a bit to represent it? There's only one option, so if you know that it's an integer, you know which integer it is.
 
10:31 PM
Similarly, if 0 is the only integer you need to represent, then you can do that with 0 bits.
lol what?
people need this function to figure out the data type they need to pack the bits
so if I pass 255 I know I need 8 bits
 
And if you pass a 0 you need 0 bits. I don't see the problem?
 
ain't do computer data type that is zero bits
lets try to figure out how many bits I need for a python list of elements max([1,2,3,4,2**16-1]). bit_length()
but then I pass a list of all zeros, sad
 
@Mikhail So what? There's also no computer data type that's 3 bits. Or 2. Or 17.
 
@Aran-Fey Yeah there are
C++ has bitfields for 3 bit data types
part of the screw up is how to deal with prefixed zeros
its supposed to ignore leading zeros, so maybe a pure zero number is a leading zero :-/
 
I really don't get why you think the last 0 should be any different from the other leading zeros
 
10:43 PM
Here is CPython's bit length implementation. github.com/python/cpython/blob/…. Interestingly, it refers to a similar implementation belonging to GCC, which is undefined for an argument of zero.
GCC and CPython may disagree on what zero's bit length is and/or whether that is even a meaningful question, but they both seem to be of the opinion that it is not cut-and-dry 1.
bugs.python.org/issue31079 indicates that the devs do not consider (0).bit_length() == 0 to be a bug
 
I mean, that's documented behavior
> It takes as many bits to store the number 0 as the number 1
 
I myself am leaning towards GCC's opinion that the value is not well defined. But in any case I will accept whatever the implementation gives me, as long as it is consistent and documented
 
Oof. Correct if interpreted literally, but incorrect the way they probably meant it
Can we at least agree that if there's only 1 possible value, you don't need any bits to store it?
"The only integer I support is 0. So I wonder what integer this is gonna be... let me read the next bit from this file... yup, it's a 0 after all."
 
gcc's opinion is formed by an implementation that uses an x86 instrinsic to do a log2
log2 != bit_count behavior
 
11:37 PM
@Mikhail Absolutely true. Remember that information is (IMHO) best thought of as representing choices. If you have only one alternative, zero information is required to select among the available alternatives, and hence no bits are required to store that information.
 
Yeah but you still need 1 bit to know if you have a choice :-)
ultimately, the function is named as something that determine the minimal number of bits to represent a value and it fails to do that
Thing is called "bit_length" not "information_length" or entropy or whatever
every use of the function requires some kind of check against zero
because it was implemented with a log2
 
@Mikhail I don't get it. What choice could you possibly have?
You read 1 bit from some input source. If the bit is 0, you set your integer to 0. If the bit is 1, you throw an error because that's not a valid value. So what was the point of that bit again?
 

« first day (3918 days earlier)      last day (1029 days later) »