« first day (3372 days earlier)      last day (1581 days later) » 
00:00 - 18:0018:00 - 00:00

12:12 AM
I've finally read the descriptor howto. It was surprisingly helpful.
 
Reopen, please? https://stackoverflow.com/questions/40258083/recursive-itemgetter-for-python

This doesn't seem like a great dupe, the questions are very related but are fundamentally asking for different things---the selected dupe requires parsing a string and that's not what is asked. Furthermore there already is one single answer which is certainly not the only way of answering the question, and the other question has a jumble of various quality answers.
 
Any chance that there's a better dupe target? We can edit that list without reopening.
 
wim
@AndrasDeak It needs an update for 3.6+ though. It's completely missing the newer __set_name__ part of the API.
 
@alkasm looking good; added
and the dupe source is a good signpost
 
Yea I think those are both good phrasing for the q
Also, I like the accepted answer better on the dupe target lol
I can't uh, cancel my reopen vote. That's annoying.
 
yeah, same with delvotes
 
wim
I actually liked that answer better than the one in the dupe.
 
12:35 AM
Oh well, I didn't realize adding a dupe target was an option. Is that a 20k privilege?
ah gold badge
 
yup, latter
 
@wim to each their own, I prefer the functional style for data transformations, but I know I'm not in the majority when it comes to Python. I just find it (usually) more expressive to the abstract idea of what your transform does. Either way, that's why we can have multiple answers :)
I agree that this looks uglier:
import operator
import functools
def nested_itemgetter(*items):
    return functools.partial(functools.reduce, operator.getitem, items)
but mostly because of the nice things being hidden into libraries :P
 
wim
good in functional language, just doesn't look like Python
 
yeah I don't disagree
 
wim
and the benefits that you would get here in a true functional language, you don't really get in a Python runtime. operator and functools are kind of both dumping grounds for trash :)
 
12:49 AM
I'm aware. Operationally, it doesn't benefit you in Python. I just prefer how it expresses a transformation, from a grammar point-of-view. Also it does meld nicely with Python's excellent iteration protocols
 
operator.itemgetter and friends are still superior to the equivalent lambdas. Having sorting and min/max in mind.
 
But I mean I'm okay with list comps and genexps and whatnot too :)
 
wim
true, but being superior to lambda is sort of like .. uhh.. being smarter than ralph wiggum
 
lol
 
1:17 AM
I was told that type annotations don't affect runtime
>>> from functools import singledispatch
...
... @singledispatch
... def foo(arg):
...     return arg + 2
...
... @foo.register
... #def _(arg):  # error
... def _(arg: str):
...     return arg * 2
...
 
wim
funny you should mention, hynek posted updated an article about this just yesterday hynek.me/articles/serialization
 
 
1 hour later…
2:46 AM
i just wanted to say that I wished python had a javascript-like syntax for dictionaries
 
AMC
3:30 AM
Hello Python people. I have seen many questions recently about getting a certain element when parsing HTML/web scraping. Do you know of a more general workflow-type question which could be used to cut down on the noise these questions create? If there aren’t any solid options, I can always try to write one myself.
 
 
2 hours later…
5:24 AM
Hello Guys need help on date conversion format i have date column with 43191 to 01/04/2018.
 
 
2 hours later…
7:06 AM
@wim Ah, I see the point. What a mess, it looked like my browser would crash.
 
7:23 AM
@NabiShaikh what is 43191? timetamp?
 
@NabiShaikh I'm on my phone so I can't check but that looks like an excel date stamp
 
7:52 AM
@roganjosh Yes it was in excel and when i convert it to csv , the foemat remain same . i have such 50 files .manually in csv i am able to change the date format to 01/04/2018 . But i am looking for how i can do with python ...pls suggest would save my day thank you
@MrSoloDolo Yes its a time stamp , earlier it was in excel file , then converted in csv but then the format remain the same . manually i am to do . i have 50 files as such so i m trying how can we do with python ..pls suggest on this thank you
 
does anyone have experience with Python-Sphinx here?
 
do we have a canonical for the common beginner question "why is my string split up into a list of individual characters?" need a cv-pls dupe for stackoverflow.com/questions/59659285/loops-list-extraction
 
user10984358
8:19 AM
@bad_coder i have generated "bare minimum docs" with a little help from here and a medium article
 
hi @TheNamesAlc man, I've been through a tough couple of weeks trying to get Sphinx rolling...
 
user10984358
what is it you are doing, if i cant help regulars here will
 
I got it installed, working, etc...But I still can't find a good working example anywhere...I mean, going on the official Sphinx leaves me about as confused as I arrived...
 
user10984358
are you generating docs for a module or for a library?
 
I mean, I lack a good cookbook/recipe set for even the most basic examples.
for a bunch of modules in a bunch of packages
 
user10984358
8:23 AM
what have you tried? are you not even able to get a single html page?
 
user10984358
medium.com/@eikonomega/… iirc this was the link i used, idk how much accurate it is, but with the version i used it deviated a little, but this was enough for me to generate html pages for my numpy docstring formatted code
 
user10984358
setting themes and having the option to show source codes all are one line configs that i think is not in that article but you can easily google that
 
I got the HTML page working and linking with the autodoc with lots of class and functions. It's easy as long as the automatic stuff works. But if you want to costumize a class with an odd signature, or an Enum for example you're left in a tough spot.
 
user10984358
i am sorry i cant help you with that aspect, i just had basic signatures, the code was long but not any that differed much from the tuts online, people here will help you out once they see
 
I've gone through those sites, and they only explain superficially how to do the most standard stuff.
ok, thank you I appreciate your time.
 
8:55 AM
@bad_coder i did a bunch of sphinx and autodocs. if you want you can link to a specific problem and I can take a look
 
can copy 1 RST where you use autodoc with autoclass but take over control for some members and methods please?
something mixing the two aspects
*sorry type, I meant to ask if you can send me a RST code example with those carachteristics please.
 
ok, I might not be able to help ^^ I just keep them separate in my own stuff to avoid that kind of issue
 
Kein problem, und danke für deine hilffe.
 
I will take one more look, I remember repos that might have done that kind of mixing. I'll ping you if I find something
also, this room is english-only, moderators might remove messages that are written in a different language
just for your information, not meant as a reprimand
 
ok I'll send a problem I'm having
class Dirs(Enum):
"""Enumerates internal directory structure. Permits reduction in directory syntax.

A more elaborate text.
"""

#: this tries one
DICTIONARY = Path(_PATH_BASE, _DIR_DICTIONARIES)
#: this tries two
OUT = Path(_PATH_BASE, _DIR_OUTPUT)
 
9:03 AM
Please take a look at the code formatting guide for chat, pinned message on the right.
 
requires these simple imports:
from enum import Enum
from pathlib import Path
files module
============

.. automodule:: files
   :members:
   :undoc-members:
   :show-inheritance:

   .. autoclass:: files.Dirs

      .. autoattribute:: DICTIONARY
         :annotation: some annotation
ok now this would be the corresponding .rst
first problem was having to use "sphinx directives" in the python enum otherwise members wouldn't appear in correct order or some of the docstring would simply get "lost in translation"
now that was annoying, because you'd expect not having to change change your python source code for the documentation to pick it up (and in that respect I did miss javadoc a lot!!!....)
then, using the .rst I just showed I was forced to use " sphinx annotations" to document the enum members, but that made inheritance dissapear from the docs.
-then, sphinx documentation says this about autodoc and I quote:
For classes and exceptions, members inherited from base classes will be left out when documenting all members, unless you give the inherited-members option, in addition to members:".. autoclass:: Noodle
:members:
:inherited-members:"
 
but guess what, the exact .rst code from the official documentation simply doesn't work!
and I just went through every SO thread on the subject and the official Sphinx docs....I'm pretty sure at this point there's not a single clear answer for even the most basic stuff anywhere.
Sphinx documentation is the worst API I ever read. It was written to be unusable and not contain any working examples.
 
9:20 AM
@NabiShaikh I already linked you to the canonical
 
@bad_coder yeah, it's a lot of pain to get running correctly. it has its upsides too, but "easy basic setup" is not one of them
you are using sphinx-apidoc to generate the .rst, right?
 
yes
 
could you paste your conf.py in dpaste.org or something like that and link it here?
 
there's nothing special to it
 
true
what would you say is your goal? to have a single table of contents where you can find all your code's documentation in the same hierarchy as the source is structured, or to mix prose with class references to safe time while writing the docs by hand?
but either way, you don't get around writing rst compliant docstrings if you want to make it look good, that might be something that you might have been missing
for example, the class documentation for timing in the docs for this module vs its docstring
 
9:39 AM
problem is this: in writing .rst compliant .py files you have to break almost every previous convention you had learnt. and basically change your whole code.
 
if you check the docs' rst source, it looks quite neat, but only because all the work happened during the writing of the docstrings.
there might be plugins that transform more readable docstring styles into proper rst
 
yes you are right. this is gonna be a pain. and I didn't have anyone to talk with about this.
 
I like to use napoleon, which is builtin and looks quite good.
but its features are only a very small subset of the real deal.
 
hey, I started with RestructuredText because it seemed like the most canonical. Should I really go Napoleaon..??? Because it seems like one more change leading to a lot of pain for little gain.
 
no no, napoleon is not a file format
 
9:42 AM
yes I know it's a format for your docstrings
(trust me, I've read everything except a decent API and working recipes...)
 
i see
well, if you are fine with writing compliant rst all the time, then there is no reason to use napoleon
i just like to use it because it looks a lot cleaner and I just avoid using stuff that I can't express in it
 
hey, send me your favorite recipe/guide...the one that contained all the answers/examples for you and wasn't the official pshinx site....because I do feel like throwing the laptop out the window when I look at the sphinx docs.
I reached saturation with Sphinx sometime last week....
" I just avoid using stuff that I can't express in it" <- Perhaps I ought to take this approach
I had missed those 2 links you sent me...I'm reading through it now.
 
I used this document as a reference for napoleon style.
for everything else I just tried to stray as little as possible from a minimal example that I got to work consistently (e.g. the docs folder in this project I maintain, plus the commands to run it), and stealing getting inspired by other projects where I liked how their docs looked
like the one that I linked above
 
10:11 AM
:) @Arne I really appreciate your help. I understood what you showed me. Thank you. Like they say: it's a small world. I hope we'll see each other around.
 
hope so too, good luck!
 
Garbage, I am having an error which says "IntegrityError: null value in column “user_id” violates not-null constraint" when I added this code :                                                  def form_valid(self, form)
       form.instance.user = self.request.user
        return super(CreateNewProperty, self).form_valid(form)
I got this error: File "C:\Users\s1900147\Documents\rentalContractApp\rental_contract_app\rental_contract_app\views.py", line 13
def form_valid(self, form)
^
SyntaxError: invalid syntax. This is my code: http://dpaste.com/3T2RAPW
 
10:28 AM
you forgot a colon for the function form_valid in line 15
 
Thanks @Arne
 
no problem. consider using an IDE such as pycharm (has a good & free community edition) to write python code, it will catch stuff like that for you
 
I will have a look at that. Thanks @Arne
@Arne, I got another error: "Reverse for 'property_list.html' not found. 'property_list.html' is not a valid view function or pattern name.". And I have the html in the list. What do you think might be the problem?
 
that sound like something django specific, which I have no clue about, sorry
 
10:44 AM
I try to debug it again. Thanks
 
That function does not eat a template name
 
11:01 AM
Kiitos @Antti, I will have a look now.
 
11:18 AM
@superv ollos hyvä. not much-of-a-Django-user either, but I guess a fully-qualified view functoin name, like foo.bar.my_view_func
 
11:33 AM
@superv was "garbage" a Finnicism, or did you mistype cabbage? :D
also, if you rearrange kiitos you can get kosiit which is almost köszi...
half-life 3 confirmed
 
user10984358
i like how people can somehow end up with half life 3 and Illuminati confirmed, mostly in youtube comments
 
@AndrasDeak garbage was a typo. sorry about that. but you are so funny tho :)
 
12:33 PM
Is the time-complexity of iterative string append actually O(n^2), or O(n)? is great, so I'm adding it to the canon. I had to edit the title because it only said "Is this time complexity actually O(n^2)?", which is useless. Are there any other good items on time/space-complexity, big-O that deserve including?
 
if you are in a terminal
and you do "less readme.txt"
and you get back out of it?
 
Anyone who can advise, please help edit the draft sopython.com/canon/136/… . If I want to cite two questions, do I put those both in 'Body' and nothing in 'Questions'? How much of the text description should go in 'Excerpt' vs what in 'Body'? etc.
@3141 Does github tell you the cloners' usernames? IPs? or only the count? Have you tried emailing github to ask, saying you're worried about bots cloning you? Did you distribute the URL to anyone? Please let us know once you figure it out
@AndrasDeak Also, I don't think there's any perfplot-type library that can automate runs across multiple Python versions, and/or other package versions, e.g. pandas, sklearn etc.
 
12:51 PM
could be
@smci you can look at sopython.com/canon/18/… and sopython.com/canon/128/… for inspiration. The questions linked like that are fine. Write something about the problem in the body, and a ~one-sentence description in the excerpt. Just judging by the overall look of sopython.com/canon
but there's markdown bug in your title
 
1:15 PM
@AndrasDeak Fixed, to: O(n\^2). I just posted the title as-is, nowhere does it say it has to be in Markdown.
@AndrasDeak I still think iterative-string-append is an antipattern; I've been hunting for which specific cPython version implemented the speedup, anyone know?
 
1:28 PM
Good afternoon Gentlemen!
Does anyone know Kivy well?
 
1:42 PM
Yesterday I wished I could identify mojibake dialects on sight, and today I continue to wish it, as it would have saved me ten minutes of effort trying to write a solution for stackoverflow.com/questions/59665022/python-utf-8-hex-decoding, which apparently has a readymade decoder in the stdlibs if only you know what it is
 
@smci it might not be markdown, I don't remember. I just meant formatting in a broader sense
 
I guess quoted-printable encoding is not technically mojibake, but having dominion over all mojibake would have told me "this is not mojibake" which would have been a useful hint
 
how do you return an error?
return -1?
 
@Permian needs more context
 
if some condition is not
i want to return an error
 
1:44 PM
One popular way to signal an error condition is to raise an exception
 
"popular"
bit of an understatement there :P
 
how do i do it then?
 
If you want to signal an error by returning -1, you certainly can, but don't expect any reader of your code to automatically understand what that means. Documentation helps :-)
 
I bet there's half a dozen functions in the stdlibs that return an integer status code
 
1:46 PM
in C?
 
integer status codes are pretty idiomatic in C, IIRC, so sure. But I wouldn't be surprised to see it pop up in Python from time to time
 
I don't think I've run into any
I can imagine that buffery/sockety things might give you zeros or something on fails
 
@roganjosh I diddnt get you
 
ten demerits to both the python.org search engine and google for taking a query like "-1" and returning all instances of the digit 1 regardless of whether there's a minus sign in front of it
 
@NabiShaikh There is a hyperlink in my first message to a question showing you how to do what you are asking me
6 hours ago, by roganjosh
@NabiShaikh I'm on my phone so I can't check but that looks like an excel date stamp
 
1:52 PM
In the absence of good research tools, I will give exactly one example: str.find. Now you will say "but does the absence of the desired substring in the target string really count as an 'error'?", but I have already slipped out the back and skipped town.
 
2:04 PM
I think the candidate pool increases substantially if you count functions that return a named constant like fileReticulator.FILE_MELTED, which just happens to equal -1 if you ever inspected it, but you never do because there's no reason to
 
regarding int status codes, exit() might be cheating since it's meant to interact with the terminal and not python code, but it's normal to send a 0 for success and >0 for some kind of error in it
 
that's still just C
 
Fred pulls the mask off the captured monster labeled "Python", revealing that it's just old farmer C in disguise
8
 
@AndrasDeak how do you mean that?
I mean, it is a python function
and i use it in my python code
 
Yes, but return values are, as you said, facing a terminal which is just C's int main(void) convention. It's probably not C that started it, but it's definitely not a python thing.
 
2:11 PM
Delineating Python from C is like trying to draw a border between the beach and the ocean
 
if your feet get wet it's the ocean
 
so in python your feet get a little wet if you use exit
because then you're standing in the ocean C
 
Heh
 
"Oh I, could tell you why, the ocean's near the shore. I'd think of things I'd never thunk before. And then I'd stop, and think some more. ... If I only had a brain."
Oz cabbage
 
if you're in Oz you better stay near the shore
 
2:33 PM
Style poll. I have a string, x, and I want to find all instances of that string, but only if it is not inside another word. Should I do re.findall(r"\b" + x + r"\b", s)? Or re.findall(fr"\b{x}\b", s)? Or something else?
raw strings and f strings are great, but I don't know if they go great together. Like ketchup and ice cream.
 
I use them together all the time in pyplot axis labels
if you don't have literal braces in your string I'd definitely go with the latter
 
Style poll 1a: fr"\b{x}\b" or rf"\b{x}\b"?
 
my vim recognizes neither and I usually use rf
(because it's a raw f-string, not an f- raw string)
that also happens to be the standard order of rm -rf :P
 
also follows the order in which vocals are usually pronounced to sound more pleasant, e after a
 
Hmm, wise council
 
2:38 PM
yeah, I've heard a lot of bad things about EA
 
I guess I'm leaning into the "dazzle neophytes with techniques they won't find in any 'Learn Python in 24 hours' book" aesthetic for this answer
 
2:53 PM
Just curious, do you often use abstract classes (and or interface modules) in python?
 
never
 
In rare situations. But then, I barely use inheritance to begin with.
 
But what do you do when you want to specify that all classes share and comply to the same contract then?
Do you just type it out in the doc of those classes?
 
I use abstract classes in that case. You have determined exactly the rare situation I was alluding to ;-)
Your ten pounds sterling prize will arrive in the mail in 6-8 weeks
Duck typing is also a possibility if I have faith that the people implementing my interface know what they need to implement without having a guide to go by
This is usually the case if the person implementing the interface is me, thirty seconds after I designed the interface in my head
 
3:01 PM
I don't think I am a fan of the duck typing thingy. It just seems like much could go wrong -- perhaps it's because I am not totally sure on what it involves.
 
Duck typing is effectively characterized by what it does not involve. In other words, you incorporate it into your code not by adding something, but by taking something away.
That something being, the abstract class
 
result_list = []
for i in q_0.queue:
result_list.append(q_0.popleft())
why doesnt this way of iterating work?
 
Dog and Cat both have an eat_kibble method, but their common parent class Animal does not. Tadaa, duck typing
 
q_0 = deque() was the line befor
 
@Permian Short answer: you almost never want to modify the size of a collection while you're iterating over it.
 
3:05 PM
how do i empty a queue into an array
 
Either iterate over the collection without modifying it, e.g. for item in the_queue: result.append(item), or modify it without doing so inside a for loop, e.g. while not the_queue.empty(): result.append(the_queue.popleft())
 
@SebastianNielsen in my experience, many things can still go wrong even if you design a big complex type structure around your code, and those things also usually happen to be the more difficult problems. so why increase the complexity of your code if it doesn't help you all that much?
but lots of people disagree, so there is a good chance that I'm wrong
 
@Kevin deque mutated during iteration
 
But in this specific case I don't think you need iteration at all, since you can just do result = list(the_queue)
 
@Kevin thanks
 
Incidentally, terminology nitpick: lists and arrays are different things. If you're not sure if your collection is an array or a list, it's almost certainly a list.
arrays can only store ints, floats, and strings; and you can't mix and match them. So they're not a popular choice for a general-use ordered collection like list is.
 
Hey, [this doesn't seem so bad](https://docs.python.org/3/glossary.html#term-abstract-base-class).

It is described as being a nice complement to duck-typing.
 
cbg all
@wim Well technically that's Carol's words, but I'm going to try and make them clearer.
 
3:22 PM
I agree that abstract base classes aren't so bad. I avoid them because of my hubris, not because they're difficult to implement or a poor design choice or whatever.
I have never once inherited from abc.ABC, though. That's deep in YAGNI territory, on my map.
 
You make me feel bad for using it now ...
 
Take a grain of salt, here. Whenever you hear me say "this builtin module is useless to me, and therefore everybody else", I'm probably wrong.
 
elif(l_sum % 3 == 2):
if(q_2.pop()):
q_2.pop()
it claims it cant pop from an empty queue
how else should i write the if statement
 
But ... You are much more experienced than me, so when you say that it's YAGNI territory, and I feel like it's the best design choice for my situation ... it's probably means that I am about to make a not so great design choice.
 
@Permian Can you describe in words what you want the code to do?
 
3:30 PM
if the queue is non empty @Kevin
get rid of right most element
 
if q_2:
    q_2.pop()
 
@SebastianNielsen Well, the good news is, it's a low-stakes decision in this case. If you decide to inherit from ABC when you don't really need to, then the consequences of your decision are: your code is a couple lines longer than it would have otherwise been.
 
only if q_2 is empty, the if statement would evaluate to true, and the pop operation happens
 
True
And that's why I am going to use it despite your opinion of it.
 
@DeveshKumarSingh thanks
 
3:33 PM
Excellent. Critical analysis is a rare and valuable skill.
 
for k in range(len(l)):
if l[k] != {0,1,2,3,4,5,6,7,8,9}
return -1
is that valid?
line 2
 
If you add a colon to the end, it's a syntactically valid line. But it might not do what you want.
It is equivalent to "if l[k] is not exactly equal to the set containing all the integers from 0 to 9". If you're trying to do "if l[k] is not equal to any of 0, 1, 2, ... 9", perhaps you were trying to do if l[k] not in {0,1,2,3,4,5,6,7,8,9}:
 
for k in range(len(l)):
        if (l[k] != [0,1,2,3,4,5,6,7,8,9]):
            return -1
that worked
oh no
i meant "not in"
 
>>> a = 4
>>> b = 23
>>> a != [0,1,2,3,4,5,6,7,8,9]
True
>>> b != [0,1,2,3,4,5,6,7,8,9]
True
>>> a not in [0,1,2,3,4,5,6,7,8,9]
False
>>> b not in [0,1,2,3,4,5,6,7,8,9]
True
 
3:40 PM
curly or square?
 
Either one. We were debating that the other day actually.
I think we determined that list literals (aka square brackets) are a smidgen faster?
Depending on the expected type of l[k], it may also make sense to skip the not in logic and do if not (0 <= l[k] <= 9) instead
if l[k] is an integer, then the logic is effectively the same. If l[k] can be something else, like a float, then it might not necessarily do what you want
>>> c = 1.5
>>> c not in [0,1,2,3,4,5,6,7,8,9]
True
>>> not (0 <= c <= 9)
False
 
@wim would
* If a :keyword:`finally` clause includes a :keyword:`return` statement, the :keyword:`finally` clause's :keyword:`return` statement will execute instead of, the :keyword:`return` statement in a :keyword:`try` clause (but after the *value* of the :keyword:`try` clause's :keyword: `return` statement is evaluated).

be better?
 
@Kevin tuples
 
Ok, in that case @Permian should not use either curly or square, and instead use round, as in (0,1,2,3,4,5,6,7,8,9)
Assuming they haven't switched to the not (0 <= c <= 9) form which may or may not fulfill the desired logic
 
@Kevin Ran into this the other day
In[2]: 99 in range(0, 100)
Out[2]: True
In[3]: 99.9 in range(0, 100)
Out[3]: False
 
3:54 PM
some_int in range(a,b) is quite efficient these days but I'm hesitant to use it seriously because I still have the ancestral memory of when it was O(N)
 
99.0 in range(0, 100) -> True
 
@PaulMcG That's what I'd expect
 
I wasn't sure if the modified range() in test was just lower <= x < upper or something more smart.
 
It probably solves the Diophantine equation
 
It's a little smarter. It has to be, if it needs to return sensible values for ranges with non-one step values
 
3:57 PM
it's all about step
 
I'm guessing it's something like lower <= x < upper and (x-lower)%step == 0
 
Fail
In[5]: 99.9 in range(0, 100, 0.1)
Traceback (most recent call last):
  File "/Users/paulmcg/venvs/auto36/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-5-af835ea29e3b>", line 1, in <module>
    99.9 in range(0, 100, 0.1)
TypeError: 'float' object cannot be interpreted as an integer
 
It would be a shame if x in range(a, b) differed from x in list(range(a,b))
If you want a <= x < b we can do just that
 
/* result = ((int(ob) - start) % step) == 0 */. TLDR: it pretty much does what I said.
 
My computer rarely does what I say
 
4:00 PM
Same
"Please ping the router"
"But what if... I _didn't_ ping the router"
"Computers do exactly as they are told" and "my computer does not do what I say" are not contradictory if some rube at Dell told my computer firewall to block all ipv4 pings and I don't know where the checkbox for that is
 
Still struggling with the route of all evil?
 
Yeah. Unfortunately friend X refused to give me one of their bones so I could use it as a tech-demon-repelling reliquary
 
Ask for an appendix
 
Oops, I left a comment on a question saying "Windows doesn't let you create always-on-top windows unless you maliciously push every other window down sixty times a second" and now I am looking at the documentation for HWND_TOPMOST which means I am just straight-up wrong
"always on top of all windows, including all windows with the HWND_TOPMOST z order" is still impossible though
 
hey guys, is there a way for me to list what modules I've imported? I know there is - I've done this before. But for the life of me, I can't remember how
 
4:13 PM
HWND_TOPMOSTEST then
 
there's a dictionary that retains module names somewhere...
aha! it's sys.modules!
 
wim
4:36 PM
@toonarmycaptain I don't know, still seems a bit wordy. At least that's no longer incorrect.
Maybe just something like "if both try and finally return a value, the return value from the finally block is used"
 
@wim I'll add that suggestion as a comment to my PR. Cheers: :)
@wim I'm making it 'from the finally block is returned.'
 
4:52 PM
I thought that the kicker here was not so much which return value was used, but that a return in a finally clause would suppress a raised exception.
Is that already in the docs? (too lazy to search)
 
I suspect it's in the language spec somewhere, although I don't have a link for you
 
@PaulMcG I think the unexpected (to me) was that a return value in a try doesn't get returned if there is a return value in a finally (even though the expression in the try's return is executed/evaluated first).
 
It might be one of those situations of "you can deduce how X Y and Z interact if you carefully read the documentation for all three"
 
has anyone here ever worked with heroku before?
 
Markup, y u no allow nested square brackets
"The return value of a function is determined by the last return statement executed. Since the finally clause always executes, a return statement executed in the finally clause will always be the last one executed"
Conclusion: both surprising behaviors are documented.
I won't say they're well documented, but they're documented
 
5:09 PM
    Say I defined a lot of classes inside one single file:

    class A: ...
    class B: ...
    ... a lot of them ...
    class Q: ...

How do I collect them at the end of the file into a tuple consisting of a reference to each class? Sample output:

class_references = (A, B, ..., Q)
I tried something like this:

for name, obj in inspect.getmembers(sys.modules[__name__]):
	if inspect.isclass(obj):
		print(name)
 
I don't hate class_references = (A, B, ..., Q), necessarily. If I wanted something fancy and automatic, I might do something wacky with metaclasses or decorators
 
are you trying to reimplement __all__?
tangentially related to your problem, not directly
 
Hmm, I am not sure. I'll take a look at _all_
 
I'm only concerned about what you'll do with class_references
 
@Kevin To me that's just as unclear, because the finally return won't be the last one executed in the sense of returning a value, it is the only one that returns.
 
5:12 PM
executed as in return foo(), return bar(). Each will be called as appropriate, but only the last return's "value" gets returned
 
When I say decorators I mean something like pastebin.com/1fj1uJAN
 
@AndrasDeak I'll just have a tuple organizing my Task classes in my Tasks class.
 
I think perhaps my C# side is showing because tagging classes and other callables with metadata is pretty common procedure, but Python doesn't have a super native way of doing that kind of
 
Uh, wow, I gotta look into that Kevin! Thanks
That looks like an awesome solution to my problem
 
Using a decorator here is just a little bit like pounding a screw in with a hammer
 
5:14 PM
Well, what are the alternatives ¯_(ツ)_/¯
Your solution is very neat!
 
That might be a rhetorical question, but I'll answer it anyway. With metaclasses, I think it would be possible to collect every subclass of a class, without having to annotate it in any way, and it would even work if they were defined in lots of different files
This is very theoretical for me because I've made a working metaclass like once ever
 
Wow, okay, that sounds like an even better solution. Sadly, though, I have no experience using metaclasses in Python
 
I do this by just having all the classes inherit from an abstract base class. Then you can get the classes from the base class's cls.__subclasses__() classmethod.
 
@AndrasDeak Yes. The terms executed/evaluated/run and the distinction between return func(), return, and func() are difficult to make clear here I guess.
 
Here is a small prototype using metaclasses.
 
5:24 PM
If the classes are spread across multiple files, then you have to make sure you've imported them all first.
 
Exercises for the reader: how can you make it so only subclasses of BaseClass appear in class_references? How can you make it so that there are separate lists for the subclasses of multiple classes that use the Collectable metaclass?
And by "exercise for the reader", I mean I didn't bother to figure out either of these and I don't know if they're even possible
@PaulMcG Oh, that sounds good. I couldn't remember if there was such a method, or if it was only possible to get parent classes.
"make sure you've imported them all first" also applies to my metaclass approach
 
@PaulMcG Yes! This is, without doubt, the best solution!
Thanks
 
When I give non-best solutions I feel like I'm the spectral guide that shows what the world would be like if the best solution doesn't exist. I'm less about actionable advice and more about making you appreciate the nice things you already have
"and this is what you'd have to do if __subclasses__ was never born!" "Enough, spirit! I will see no more of this horrible world! [sobbing] Take me home..."
 
Haha, yeah
 
Take care if you have this:
class AbstractClass:
class A(AbstractClass):
class ASub(A):
AbstractClass.__subclasses__() will only give you A, not ASub.
I was showing the class hierarchy
 
5:36 PM
Ah, so my metaclass approach has some merit if you want a flat collection of every descendant of BaseClass, and can't be bothered to derive it by recursing through the __subclasses__ of every subclass
 
Okay, so in other words, .__subclasses__() only yields the immediate children of the class of which it is called upon.
 
Honestly it's probably still less work to just recurse through __subclasses__ ¯\_(ツ)_/¯
def descendants(class_):
    to_visit = [class_]
    seen = []
    while to_visit:
        children = to_visit.pop().__subclasses__()
        seen.extend(children)
        to_visit.extend(children)
    return seen

print(descendants(BaseClass))
Disclaimer: may have duplicate entries when diamond inheritance is involved
 
5:57 PM
morning cabbage
 
00:00 - 18:0018:00 - 00:00

« first day (3372 days earlier)      last day (1581 days later) »