« first day (2522 days earlier)      last day (2427 days later) » 

wim
7:43 PM
anyone else get bitten by this annoyance?
>>> 'abc'.translate({'a': 'x'})
'abc'
 
nope ;)
 
Yep
 
wim
got me a few times
it should raise exception
 
come to think of it, when I've seen .translate I always saw some table magic to go with it
 
wim
or run the dict through str.maketrans for you
not silently fail :(
 
7:46 PM
I can never remember how maketrans works so usually I just do "".join(d.get(c,c) for c in "abc")
 
wim
if you're going to populate install_requires from requirements, you can't use that syntax rethink what you're doing in the first place
requirements.txt is for pinning versions, install_requires is for specifying deps. don't confuse them!
 
c# makes me have to use double quotes, but I will forever love single quotes; for one they need more love :D
 
MATLAB used to only have single quotes for character arrays, not so long ago they introduced double quotes for a proper string class. I hate it.
 
I get confused every time I write different languages because of how slightly different languages handle quotes
 
triple double quotes """text""" <3
 
7:54 PM
also, True vs true is a major pita for muscle memory
@Rawing what's not to love with "\"text\""
oh...
 
in c# single quotes are for chars only, while double quotes are strings... I have a nasty habit of hitting single quotes, to the point where I'm on the verge of writing a plugin that converts my ' into " when I'm coding c# ... :\
 
if i'm doing something with individual characters I default to single quotes thanks to C, otherwise I use double. Is this blasphemous?
 
definitely heretical. BURN THE HERETIC!
actually I think I might do that too
crap
 
@MooingRawr that's the c in c#
 
y'all be weird... :\ next thing I know, you are telling me you use 4 spaces instead of a tab... :\
 
7:58 PM
mooingrawr is the real heretic
 
@AndrasDeak I actually enjoy coding in c, the uniqueness of memory management was fun :D Though all my c knowledge has been slowly fading away :\ all I remember is alloc and malloc :D
 
or lack thereof
@MooingRawr malloc and calloc?
 
I'm a lazy coder, maybe that's why I enjoy Python so much.... the Lazy evals :D
@AndrasDeak might have been calloc... -looks up wiki- yup calloc, malloc, realloc, and free
 
when you're dynamically allocating a 2d array... ***double ftw
 
I get more * action in c than I do here :)
 
8:22 PM
the curse of dimensionality in C: ********************
 
wim
8:35 PM
anyone have an elegant trick for making SimpleNamespace iterable?
or should I just be bad and use vars(ns).values(), relying on implementation detail
 
namedtuple? :P
 
wim
I can't use those because their equality comparison is broken
 
what implementation detail does that rely on?
 
__dict__?
 
wim
I think that relies on 3.6 dicts being ordered
 
8:40 PM
Isn't the whole point of SimpleNamespace the fact that is has attributes and thus a __dict__?
 
wim
yeah, but it can't be a namedtuple-killer unless you make it iterable somehow :(
 
Do you need ordering? Every dict.values() is iterable, right?
 
AFAIK class attributes are always ordered. But then again, you might lose the order if you instantiate it like SimpleNamespace(a=1, b=2); that depends on how exactly it's implemented
 
hmm, yeah, I think I heard that here not long ago
 
this is the source code: SimpleNamespace = type(sys.implementation) ... that's not very helpful
 
8:44 PM
there's a "rough implementation" in the docs
 
wim
@Rawing LOL. that's like defining dict = type({}) ... eh voila!
who knew python was so easy?! ;)
 
Big Python just wants to keep you in darkness
 
Looks like even if the rough implementation from the docs were an exact implementation, it'd only be reliable in python 3.6+
If you create a subclass and list all the attributes there, the order is maintained. But if you pass kwargs to the SimpleNamespace constructor, you lose the order
 
wim
hey, that thing under it looks pretty cool. types.DynamicClassAttribute .
never knew about that one
 
@Rawing that's true for any kwargs, right?
like trying to instantiate an OrderedDict with kwargs
 
8:51 PM
yes
that's the exact reason why dicts are ordered in 3.6; to make kwargs maintain the order
or at least that's what I learned from my 2-minute google search
 
wim
that's bollocks
there was a PEP to make **kwargs be order preserving
and the PEP was satisfied by taking the compact dict implementation from the pypy guys
that also got cpython a faster and more memory efficient dict, as a bonus
but it wasn't like, dicts are ordered to make kwargs maintain order, more like, kwargs now maintain order (and oh yeah, dicts are ordered, but shhhhh....)
it was kind of an embarrassment to python that OrderedDict(k1=1, k2=2) could return a dict ordered the wrong way..... :D
 
yeah, talk about surprise
but now you have "OrderedDict(**{'k1':1, 'k2':2}) works...but only as an implementation detail"
 
wim
lol, yah, kinda ridiculous that
I expect we will get the guarantee in 3.7 or 3.8
 
I'd be very surprised if any such guarantee were offered before Python 4
 
Having dicts ordered by default in #python 3.6 is not guaranteed yet. But it is so convenient that a guarantee for 3.7 is almost inevitable.
 
9:02 PM
I'm very surprised
 
who kicked up some subtweeting controversy the other day?
 
@MalcolmMcLean not in C, only in 𝕬𝖓𝖈𝖎𝖊𝖓𝖙 𝕮. — Antti Haapala 20 secs ago
<3 unicode
 
@AnttiHaapala you need to edit this lol
 
yup, it was RHettinger. So my point was that perhaps his opinion doesn't represent the eventual design decisions
 
@enderland not working?
 
9:08 PM
@AnttiHaapala no. I mean you posted that you love unicode, but then used an ascii heart!
 
Doesnt work in my phone :F
 
hah
 
The fraktur that is
 
>>> SimpleNamespace(**{5: 5})
namespace()
>>> SimpleNamespace(**{'5': 5, 'foo bar': 'baz'})
namespace(5=5, foo bar='baz')
^ curious ...
 
wim
not really
setattr has to have strings
non-identifier attributes are OK, but non-string attributes are not allowed.
 
9:15 PM
Fair enough, but I'm a little surprised it doesn't throw an error
 
wim
hmm, true
the first one should be an exception huh
 
9:27 PM
hey does anyone have a clue how byteplay code works ?
 
wim
9:43 PM
0
Q: Accepting integers as keys of **kwargs

wimKeywords have to be strings >>> def foo(**kwargs): ... pass ... >>> foo(**{0:0}) TypeError: foo() keywords must be strings But by some black magic, namespaces are able to bypass that >>> from types import SimpleNamespace >>> SimpleNamespace(**{0:0}) namespace() Why? And how? Could yo...

 
inb4 some newbie comments "It accepts raw strings, too!"
 
I bet it will be a HNQ soon
 
I should add a crappy answer then
 
"Smells like a XY problem to me"
 
9:59 PM
Oddly enough, SimpleNamespace seems to have special-cased the non-string attributes in __repr__, because they still show up in the __dict__:
>>> SimpleNamespace(**{5: 5})
namespace()
>>> SimpleNamespace(**{5: 5}).__dict__
{5: 5}
what an odd class
 
Well that's "simple" for you. "Cheap meat has thin juice", to use a Hungarian proverb ;)
 
wim
u can shadow dunders
>>> s = SimpleNamespace(__dict__={})
>>> s.__dict__
{'__dict__': {}}
>>> del s.__dict__
AttributeError: readonly attribute
i guess that's not a simple namespace thing though, just an object model thing
 
hmm, the audio channel seems to be somewhat NSFW there ^
I'm listening to the okeanos livestream so I muted this video
 
"shit" is considered NSFW nowadays?
 
I like to err on the safe side
 
10:10 PM
i doubt people click youtube links at work if they don't use headphones ;)
 
yeah, I thought so, but I don't want to be shouted at just in case :P
 
wim
users have been kicked out of rm 6 for less. but if mods are allowed to write sh1t then perhaps it's alright 🎉🎉🎉
 
10:29 PM
@Rawing Yes, it special-cases strings: github.com/python/cpython/blob/v3.6.2/Objects/…
 
DSM
@ThiefMaster: come on.
 
Oh nice, that code is easier to read than I expected. It had to stare at it for a minute, but it makes sense now.
Haven't really used C/C++ since I crashed Quake3 with it at the tender age of 15
 
you should get into it again; much more ways to abuse python that way ;)
 
maybe I should. I'd probably have more success with it now. I still remember how I "overloaded" a function by making a copy of it and renaming its parameter, with the reasoning "this function only works for things called entities, not rockets"
 
wim
10:53 PM
yeah, CPython source is excellent and clean. You don't even need to understand C to browse it for the most part.
 
well a fundamental understanding of stuff like typecasts probably helps
I remember that being one of the most confusing syntaxes in C for me
 

« first day (2522 days earlier)      last day (2427 days later) »