« first day (2779 days earlier)      last day (2169 days later) » 
00:00 - 19:0019:00 - 00:00

7:00 PM
oh, groupby vs dicts, nevermind, I don't know about that
 
@AndrasDeak Ok. 17 if we put a whitespace after the colon. And I guess we really should define a def over 2 lines. And use 4 spaces of indentation.
 
@roganjosh Hettinger promised in 3.7 they would have :P
 
@AnttiHaapala Yeah, but unfortunately that doesn't necessarily help for pandas :/
 
FWIW I came up with the 16-char version myself
 
@AndrasDeak pep compliant?!
 
7:02 PM
I've found myself unable to determine whether local testing results are based on pandas or cpython
 
@PM2Ring I enjoyed it. One question though, is there a specific reason for that challenge in particular?
 
@AnttiHaapala hmm?
 
3 mins ago, by Aran-Fey
that's strictly pep-8 conformant?
 
of course not
16 chars as PM meant
one line and golfed
 
@PM2Ring I don't get this :D
 
7:03 PM
Here's another way:
>>> class f:
...  def __call__(s):return f
 
@PM2Ring which 16 character version were you thinking of :?
 
I thought he meant def f():return f
 
Or as a one-liner:
f=type('f',(),{'__call__':lambda:f})
 
@PM2Ring well though that wouldn't work :D
 
@AnttiHaapala What Andras said.
 
7:04 PM
@PM2Ring perhaps __new__
 
Ah those underscore methods. Yeah I thought it might be one of those to start with
 
def f():return f isn't PEP-8 compliant. PEP 8 even says that def f(): return f shouldn't be used (17 chars).
 
>>> def f():return f
...
>>> f
<function f at 0xb725553c>
>>> f()
<function f at 0xb725553c>
>>> f()()
<function f at 0xb725553c>
 
>>> f=type('f',(),{'__call__':lambda:f})
>>> f()()()()()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: <lambda>() takes 0 positional arguments but 1 was given
A bit too clever for your own good :P
 
For example, is I groupby in pandas, do the indices maintain order because pandas guarantees that or because I happen to be running 3.6. and pandas adds to a dict in a set order. It's not so clear to unpick.
 
7:06 PM
@Aran-Fey Yeah, I just noticed that myself. :oops:
 
@Simon officially 'magic' methods. stackoverflow.com/questions/8689964/…
 
>>> class f:
...     def __new__(cls):
...         return f
...
>>> f()()()()()()()
<class '__main__.f'>
@PM2Ring ^
 
@ArtemisFowl Thank you.
 
no one calls them magic
but dunder
@roganjosh I did 200
 
I think the current official name is "special methods".
 
7:09 PM
Not everyone knows them under that name @AnttiHaapala
 
It works if I give __call__ an arg:
f=type('f',(),{'__call__':lambda s:f})
 
@AnttiHaapala not sure I get you. You tested up to 200 indices?
 
@roganjosh arrow
 
FWIW, Ned Batchelder invented "dunder".
 
FWIW Ned Batchelder is in IRC, freenode #python with nick nedbat...
and it is commendable how he answers questions there :F
 
because otherwise if anything in the world is hostile, then the #python irc channel...
 
@AnttiHaapala now I'm really confused. Accidental cross-pollination in tags?
 
Sorry about that. Minor clipboard error.
 
@roganjosh the тов arrow
@PM2Ring :D:D:D I thought that was fun
 
I don't get how that relates to dataframes maintaining order in groupby
 
7:16 PM
yesterday, by roganjosh
Hilarious and tragic. In school we had some weird memory test to see if we could memorise pi to 20 d.p. in 1 minute. 20 years on I still have that locked in my memory :(
not in 1 minute though :D
 
3.14159265358979326
 
it's like remembering a couple of phone numbers at the same time
 
@roganjosh Almost. The last digit should be 3
 
@PM2Ring I will eat my non-existent hat if I made a mistake
 
A nice pi approximation discovered by a Chinese mathematician is 1 / pi = 113 / 355
@roganjosh 3.1415926535897932384626
I hope you have a tasty non-existent hat. ;)
 
7:20 PM
323846, it's now going through my head. I was wrong.
I need a moment for my existential crisis
 
I can understand that. I'd be devastated if it happened to me.
 
You're. not. helping.
 
3.141592653589793238462643383279502884197169399375105820
that much I remember only of the 200
and it is hard to write when thinking about the numbers
1+54
 
I memorised pi digits by saying them and writing them. But I still find them easier to say than to write.
 
no I've cut it short :d
damnit.
there are some missing, I should start practising it again.
 
7:24 PM
I can remember all the values of pi quite easily: ╧А
 
@AnttiHaapala Well, the next digit's a 9, but that's ok. You're allowed to truncate.
 
@PM2Ring no in the middle
 
But seriously, I've got myself over that. Is it a python feature in 3.6 or a pandas feature that maintains order in groupby?
 
... but I've rationalized it that should there be an extinction-level event hitting earth, then maybe 20 digits of PI would be enough to rebuild the world until we get enough spare computing power so that we can to calculate some more digits...
 
FWIW, Charles Dodgson, aka Lewis Carroll, memorised the 3 digit logarithm tables, which was quite handy in the days before calculators.
@AnttiHaapala It looks good to me. And mpmath agrees.
>>> from mpmath import mp
>>> mp.dps=60;print(mp.pi)
3.14159265358979323846264338327950288419716939937510582097494
 
7:30 PM
ah
echo 'scale=1000; a(1)*4'|bc -l
 
Help. Why does this throw an AttributeError?
class C:
    def __getattr__(self, attr):
        return attr

print(C.__getattribute__(C(), 'foo'))
Isn't __getattribute__ responsible for calling __getattr__?
 
@AnttiHaapala If you want lots of digits, (a(1/2)+a(1/3))*4 converges faster.
 
@Aran-Fey from the question I answered this morning, I'm pretty sure the try-catch mecanism that handles the AttributeError is outside of the dunder methods
It is part of the getattr protocol, not of the object.__getattribute__ method
 
It certainly looks like you're right
And yet if __getattribute__ throws an AttributeError, __getattr__ is never even called. That's kind of weird.
 
I think you can see it as the function getattr being the one catching the AttributeError and delgating to __getattr__ instead.
 
7:42 PM
5
Q: How is the `__getattribute__` method involved in the lookup procedures?

TimPython in a Nutshell describes: the lookup procedure when getting an attribute from a class, e.g. cls.name (see the first part in Why are the lookup procedures for getting an attribute from a class and from an instance different?) the lookup procedure when getting an attribute from an instance,...

 
Oh wow, I remember that question. I'm not particularly surprised that Tim didn't accept that answer.
 
I just saw a turtle question. Sometimes they're fun to answer, but this one has two star imports, and a whole bunch of globals. I think I'll give it a miss.
 
@PM2Ring ADMIRAL ACKBAR: ____________________!
it is a question to test whether we're nice to newbies.
 
@AnttiHaapala It's here, if you want to take a look: stackoverflow.com/questions/50546402/…
 
that's not even bad
 
7:48 PM
Lucky Python doesn't have a goto as well.
You would be scrolling up 10 lines as well as asking yourself how that variable is defined.
 
All this __getattr__ talk is giving me flashbacks to a pickle question I answered a few weeks ago: stackoverflow.com/questions/50156118/…
@AnttiHaapala I suppose not. But it's almost 6AM here, and I'm not in the mood to deal with star imports.
 
Yeah, 6AM is no time for stars. That's time for sunrise.
 
@Aran-Fey yea I don't see that Aschwin answer as being correct at all
@Aran-Fey that needs a new answer
 
112's answer on the linked question helped me out
But I was actually thinking that the answer probably went over Tim's head for the most part :D
 
8:11 PM
@Aran-Fey well, Tim ... is Tim...
but I am not sure all this object.__getattribute__ thing is correct here...
it has been established that object.__getattribute__ does not call...
 
FWIW, the answer looks incorrect to me, but I'm not confident enough to dispute it
 
If the class also defines __getattr__(), the latter will not be called unless __getattribute__() either calls it explicitly or raises an AttributeError.
as I read this, it is part of Python_GetAttr, getattr...
i.e. __getattribute__ would actually raise an exception before __getattr__ would be called
ah that answer is actually correct, it just didn't really answer well to "how are __getattribute__ and __getattr__ related"
 
9:01 PM
I have no remote and I must watch TV. Sequel short story by Harlan Ellison?
 
9:19 PM
no infra port on your phone?
 
10:04 PM
cbg
I have a small question about exec. I have bot command which performs exec with given input (lets assume it is exclusive for me and all data is safe). If I pass globals in it, it would persist operations like assignment and imports, but then i'm unable to access local variables. If I pass both globals and locals, I lose that ability, and each new call doesnt see previous assignments. Any quick way to fix it?
 
So you want to be able to read local variables, but all assignments should go to the global scope without having to declare global x first?
 
Yes
 
I'd do that with a custom dict
class MyGlobals(dict):
    def __init__(self, globs, locs):
        self.globals = globs
        self.locals = locs

    def __getitem__(self, name):
        try:
            return self.locals[name]
        except KeyError:
            return self.globals[name]

    def __setitem__(self, name, value):
        self.globals[name] = value

globs = MyGlobals(globals(), locals())
exec('global_var = local_var + 2', globs)
 
exec(command, globals()) worked fine, but then I dont see the locals. And adding locals() to call reverts it's behavior back. I can do globals().update({'variable':'value'}) each time I need to do assignment, but this isn't comfortable for me, obviously
oh, let me try this
 
10:20 PM
print("""""""""""""CABBAGE""""""""""""""")
 
*claps* that one took me a second to figure out
 
@MaxLunar the modification to locals isn't supported. Make a copy of the locals dictionary, and keep this dictionary around
 
They don't want to modify the locals anyway
 
l = dict(locals());
exec(code, globals(), l)
 
Hello
 
10:21 PM
if you want to access the modifications, they're in the l dictionary then
 
Airport lounge cabbage ;)
 
@coldspeed copycat!
 
That's how you learn from the best
 
@AnttiHaapala I know this. I need to access locals, not modify its contents
 
you don't need that class^
also, the thing here is: you can construct your own globals as you want...
 
10:27 PM
that class worked fine anyway
 
I don't get it. How do you solve the problem of having to access locals, but assigning to globals?
 
funny thing. I am able to assign value to variable, I also can print it afterwards, but doing del variable leads to NameError
 
implement __delitem__
 
ah, sure
Where can I find example of __delitem__ implementation?
 
def __delitem__(self, name):
        del self.globals[name]
 
10:36 PM
i dont remember what is passed in it, except self
 
thank you, sir
 
10:58 PM
this doesn't make any sense
@MaxLunar what is it that you really want to do here
 
Greetings! I had posted a question about finding adjacent sides of a triangular tessellation. I would really appreciate if you have any thoughts or comments. Here is the link of the question: stackoverflow.com/questions/50537967/…
 
11:09 PM
cbg
 
@konstant too hard to read ;)
is this really a np-hard problem? :d
 
@konstant You should shorten that question, I'm sure a lot of that text is superfluous. Nonetheless, +1 for the nice image
 
11:43 PM
@AnttiHaapala @OlivierMelançon I have shortened the question. It looks kind of long because of the long example arrays I have posted.
 
00:00 - 19:0019:00 - 00:00

« first day (2779 days earlier)      last day (2169 days later) »