« first day (3020 days earlier)      last day (1925 days later) » 

12:11 AM
I need to make a more determined effort to remember this. The set() is recalculated in output = ' '.join([item for item in text.split() if item not in set(concepts[1:]) else concepts[0] for item in text])?
Oh man, I could try to write correct syntax first
 
I believe it will act the same way as if it were a proper loop
 
output = ' '.join([item if item not in set(concepts[1:]) else concepts[0] for item in text.split()]) even. Silly mistake.
 
it will create the set on each iteration I think
 
I guess I better test it and reinforce in my head what exactly get recalculated. It seems like a nice optimisation to get the set once but I suspect it is converted each time too
 
res = []
for item in text.split():
    val = item if item not in set(concepts[1:]) else concepts[0]
    res.append(val)
I see no reason why it wouldn't create the set each time
Disassembly of <code object <listcomp> at 0x7f979ce45ed0, file "<dis>", line 1>:
  1           0 BUILD_LIST               0
              2 LOAD_FAST                0 (.0)
        >>    4 FOR_ITER                36 (to 42)
              6 STORE_FAST               1 (item)
              8 LOAD_FAST                1 (item)
             10 LOAD_GLOBAL              0 (set)
             12 LOAD_GLOBAL              1 (concepts)
             14 LOAD_CONST               0 (1)
             16 LOAD_CONST               1 (None)
22 CALL_FUNCTION is right there in the middle of the loop as expected
also, kudos for dis.dis printing the disassembly of the listcomp separately
 
12:19 AM
Yeah, it's a bummer. My 1-liner failed though anyway
 
you can still create the set beforehand and use a two-liner
 
That's 2 lines though, Andras. It probably takes like 500% of the time to run :P
 
you could do it on one line but don't :P
dis.dis("' '.join([item if item not in checkset else concepts[0] for checkset in [set(concepts[1:])] for item in text.split()])")
this has the set call outside the list comp
 
Do you know how?
I suspect the set has been lost? You're now checking against the list?
 
lost?
 
12:23 AM
So you're checking for the contents of the list which is the set as a whole?
 
No, I think what I wrote should do the same thing as your code. It adds a single-iteration loop level to assign set(concepts[1:]) to checkset for the real loop.
But this could still imply that the set gets calculated inside the listcomp loops (but only once). Unless I'm misreading the output of dis.dis the set gets created outside the listcomp loops.
 
I genuinely don't know how that works but it looks like you're right
 
Perhaps some optimization that sees that the object inside that set literal can't change. Let me try putting some mutating thing inside.
 
That seems... hackish. But didn't take you long to come up with. Am I missing something obvious?
 
The one-liner? Yeah, it's very hackish :)
8 mins ago, by Andras Deak
you could do it on one line but don't :P
only for code golf
 
12:30 AM
Nah, the enclosing the in the list :) I thought the one-liner would be a nice parting before bed but now I'm confused why your correction actually works :)
 
rewrite it in proper loops:
for checkset in [set(concepts[1:])]:
    for item in text.split():
        do_things()
the actual part of the listcomp sees checkset as an existing local name, the set is only constructed each time the enclosing loop is iterated (i.e. once)
 
Aha, ok
 
it's too late for me to try and understand if there's some optimization going on that actually puts the set() call outside the listcomp :)
 
Yeah, let's not write 1-liners :P
But really nice work, I have something to get my head around tomorrow :)
 
thanks
 
12:42 AM
rbrb
 
rbrb
 
 
1 hour later…
2:09 AM
stackoverflow.com/q/12383436/4909087 as off topic/no repro. The specific requested feature was added into pandas in v0.13.
 
3:03 AM
@AnttiHaapala After an hour spent debugging the issue, I find myself going down the "objects don't equal themselves in GreaseMonkey" rabbit hole again. I honestly can't be bothered to deal with that rubbish, so basically that's a "won't fix".
 
3:38 AM
What are the better ways to learn Python?
 
4:49 AM
@Aran-Fey so what works?
or nothing works?
perhaps they aren't themselves
 
5:22 AM
stackoverflow.com/a/32240671/4909087 excel answer to pandas question
 
 
3 hours later…
7:54 AM
@AnttiHaapala It works in TamperMonkey. (I didn't realize the new fav button made the script stop working, but I just pushed an update that fixes that)
 
Hey I was wondering if what I'm doing is good style.
I have a file a.py:
def main():
    ip, port = read_config()

def read_config():
    config = get_config()
    ip = config["ip"]
    port = config["port"]
    return ip, port

if __name__ == "__main__":
    main()
Now I would like to use main in another module but just hardcode the port part. At first I didn't know how to do this, but then I decided to go with something like this in b.py:
from a import main

def read_config():
    config = get_config()
    ip = config["ip"]
    port = config["port"]
    return ip, 42

if __name__ == "__main__":
    main(read_config)
It feels kinda wrong, since I'm duplicating the read_config function just to hard_code one part
but then I don't see a problem with this yet, so I'm inclined to go with it...
 
8:14 AM
@Aran-Fey not interested in tampermonkey and their proprietary eulas
 
I found a "fix" for GreaseMonkey in the meantime... but I'm not sure if I want to write terrible code just because GM thinks it can do whatever it wants
 
so what was the exact problem?
 
I'd have to replace an if (this !== Post) with if (this.name !== 'Post'), which is... not horrible I guess, but at this point I'd much rather boycott GM and spend less hours dealing with stupid stuff as a consequence of that
 
it might be related to what level they're operating at
 
Basically I have a class method Post.from_element that does different things depending on whether it's called like Post.from_element(...) or Question.from_element(...) or Answer.from_element(...), and the if (this !== Post) check in that method isn't working correctly because of GM
 
8:22 AM
@Aran-Fey link to code pls :D
 
8:33 AM
@Hakaishin You could consider passing config as an argument to main, like def main(config): ip, port = config['ip'], config['port']
 
why would that be better compared to passing the function?
 
Well, because
config = read_config()
config['port'] = 42
main(config)
is easier than
def patched_read_config():
    ip, port = read_config()
    return ip, 42

main(patched_read_config)
It doesn't look like main needs a config factory, it looks like it just needs a config
 
Ah yes, that makes sense
 
 
1 hour later…
9:56 AM
cbg
 
10:35 AM
@coldspeed add that as an answer before closing
 
@Aran-Fey I am pretty sure it is the setglobal that doesn't work as expected
 
11:07 AM
Okay. I tried a little experiment today. I went through about 1500 very old questions and picked out ones where the answers were outdated or lacking, and wrote answers for about 15 of them. I'll check back in a couple of months and see which/how many of them were upvoted. That should give me an idea of how to optimize my time in the future.
 
11:23 AM
Man I don't get it, matplotlib refuses to close the plotting window and I'm somehow googling the wrong things. Any idea why this leaves the plotting window open?
from subprocess import Popen
from time import sleep

p1 = Popen([r"C:\Users\plot_stuff.exe",
       r"C:\Users\images"])

sleep(20)

p1.terminate()
print("Finished")
The program executes normally and also terminates normally, but the window stays open
and plot stuff is just plt.plot(x) and plt.show() made into an exe with pyinstaller
with x being x = [1,2,3,4]
 
do you ever call plt.close() or similar?
 
yes, but only in the main thread, which does nothing
I want the plot to close as soon as the main thread closes
 
you mean in the main process?
it's plt instance is distinct from the subprocess, the two cannot influence each other
 
yes
but how can I close the plot from my main process?
I want something like a daemonized process, that gets killed as soon as the main process finishes. I checked out python-daemon, but this is only for linux no windows implementation
 
@Hakaishin there's no plotting in that code block
 
11:38 AM
why do you need processes at all?
 
@Hakaishin the point of a daemonized process is that it lives on
you probably need a thread
 
put it in a thread and plt has full control
@AndrasDeak not in Python. A daemon thread/process dies with its parent
 
it does?
 
> When a process exits, it attempts to terminate all of its daemonic child processes.
 
that's multiprocessing
though I guess you're right, I always think of multiprocessing as a parallel computing tool
thanks
 
11:44 AM
subprocess doesn't have a concept of daemons at all - so it probably means whatever one wishes ^^
I am used to both meanings, and it is super confusing at times :/
 
@MisterMiyagi yeah, that's what I'm starting to conclude myself
 
11:56 AM
@Hakaishin plt.close() probably does something like plt.gcf().close(). If the figure lives in another process there's no way for the pyplot of the main process to see figures of the child process.
again, if you use threading, this could be solved
 
... furthermore the use of multiprocessing without the server strategy coupled with threads/windows/whatever is a recipe for sure disaster.
 
they are using subprocess, not multiprocessing
 
cbg
One day of snow; had to abandon work after 2 hours of traffic, only to turn around.
 
@AndrasDeak good
 
12:21 PM
@AnttiHaapala Why? I have one process receiving data, another plotting it. I just want the plotting one to close once the receiving end stops
but yeah, I tried plotting, but got another problem there. Can't remember now, but will try to use threads to see again what it was
 
Can't you just kill() the subprocess?
 
Anyone think of an easy (preferably portable to other implementation's) way a function could determine its caller's module?
 
12:39 PM
@AndrasDeak Thanks, I will have a look
 
@holdenweb why do I get the feeling that a goat will get involved down the line? ;)
 
[whistles innocently] I know nothing of goats.
 
@holdenweb pypy3.5 supports sys._getframe(), which should give you access to all frame inspections of the inspect module
e.g. inspect.stack()
 
I was hoping to avoid that due to its lack of portability.
Didn't realise pypy already implemented it!
Not too worried about IronPython or Jython, truth to tell. Absence of f-strings would hurt, though.
 
Is there something like json.JSONDecoder's object_hook but for json.JSONEncoder? I'd like to call my function for every Python dictionary before it's serialized
 
12:48 PM
@holdenweb IIRC sys._getframe() is required to do that kind of vodoo
though any Py3 implementation should give stack access by raising an exception
then inspecting the traceback attribute
 
Yeah, all still "naughty" to some degree. I might choose to add an explicit parameter instead unless I can come up with something better.
@vaultah The docs say "To extend this to recognize other objects, subclass and implement a default() method with another method that returns a serializable object for o if possible, otherwise it should call the superclass implementation (to raise TypeError)." I didn't find that helpful ...
 
@holdenweb Is the traceback module not up to this task? I wrote an auto-naming namedtuple that did this kind of trick.
 
traceback also uses sys._getframe() under the hood
 
I'm not sure. I'm trying to discourage the team from avoidable deep voodoo, so I'd like to make a strong case for it being UNavoidable :)
Or, better still, avoid it, but I doubt that's possible.
I guess there's no better answer than stackoverflow.com/questions/1095543/…
But the situation is complicated by the functions being decorated to an indeterminate degree, and I haven't fully considered the implications of that yet.
Ah, wait! The undecorated function is passed to the freaking decorator so its __module__ attribte should be available. I am saved! Time for lunch!
 
1:05 PM
Doesn't __module__ point to the module where the function was defined?
 
1:21 PM
Yes. I need to read a data file in the same directory as the caller's module. Ah, that's ambiguous! Perhaps I should have mentioned decorators in the first place. I actually need the directory containing the module from which the call to the decorator is made.
Since decorators inherently decorate the function whose definition follows, that function's __module__.__file__ or similar should serve.
 
1:36 PM
As long as the function has no inner decorators, of course.
 
and as long as the decorator decorates with @decorator, and not decorate(foo) where foo can come from anywhere
 
Yes, I'll be using inline decorations with the @ syntax.
 
yeah, I figured
 
Though were I to use that form I would still want the function's directory, since that's where the appropriate data file lives.
 
@holdenweb What if the decorator uses __wraps__? Will that confound your approach?
 
1:56 PM
I thought I was having a rough monday first work day of the week, but I come in here and y'all are trying to get modules out of frame objects, which really puts my own little troubles in perspective
Imagine one of those charts that show how deep the ocean is, with helpful indicators such as "deepest recorded whale depth" and "a can of Pepsi implodes due to pressure". Except instead of water, it's technical debt, and instead of a can of Pepsi, it's a programmer's ordinarily sterling principles
My thoughts and prayers are with holdenweb as he traverses the abyssal zone
 
what do you guys use to write on to pdfs?
I wish there was a firefox extension for it
or built in support like in chrome
btw can chrome really do that? I only read a comment it could, didn't confirm
 
Pdfs as in "portable" document format are read-only :P
 
I guess, but there are a few tools that can edit them^^
 
I have seen, and written in, pdfs that have editable text boxes. We often use them when fulfilling red tape requirements at work. I don't know how these are created, and I don't know if there's a way to add text boxes to an already existing pdf that doesn't already have them.
 
And I never got why they should be read only, especially since 90% use cases at least in my experience are forms that I need to fill out...
 
2:09 PM
@Hakaishin once you add bells and whistles it's no longer portable
99% of my use cases is disseminating your work
 
Lazy solution: take screenshot. Add text to it in MS Paint. Save as an image, then use image-to-pdf conversion software.
"But won't this make all the text unselectable etc etc?" you ask. Yes, but it sounds like the usual workflow here is "print out pdf, write on it, scan it, email it" in which case the text is both unselectable and twice-degraded. So you're coming out ahead by not getting physical reality involved.
 
I had to return corrections to a paper using annotated pdfs. The only time in the past 10 years or so that I had to use windows.
Needless to say, I was outraged
 
nonportable pdf forms are probably made by the same people that make "first, upload your resume. Then, manually enter all the information from your resume into this form" web pages
 
There are no portable pdf forms
I had to register to a conference using a formed pdf. Filling it worked, but we were asked to flatten the pdf before sending it back, otherwise they probably can't read it.
 
Once my latent telepathic abilities manifest, I will use them to banish those developers into the forest, where they can't bother us any more
I don't necessarily want them to be eaten by bears, but the alternative is that they'll form a functional society, which seems unlikely
 
2:17 PM
Unlikely to form one? Maybe not.
 
"First, form a society. Then, manually recreate all elements of that society -- oops it's winter and we've all frozen"
 
Pretty sure I've used Adobe X to make an editable pdf form
Then again, it was years ago and I have no idea why.
 
@roganjosh yup. And you can later read it with adobe x.
 
@Kevin This! So infuriating
@Kevin Yeah, this is why I was asking for an extension :P
 
Kevin's Very Good PDF Program can create pdf files with embedded autoplaying midis, but they aren't supported by any program other than KVGPDFP
 
2:25 PM
:D
 
Hello everybody, I've seen different post on SO about integrating Flask-JSGlue on a Flask application. But how is it possible to integrate Flask-JSGlue on a socketized Flask-SocketIO application? I'm trying to figure this out with no luck and I've opened a question for this - stackoverflow.com/questions/54310058/…
If anybody has any idea on how to this, any help would be greatly appreciated
 
2:40 PM
I'm in the rows/algebraist category, myself. Or at least, I think I am, because I don't actually know what analysts do.
Fig 1. A wood analyst.
 
\o cbg
 
Analysis would be the delta/epsilon folk. Real analysis, topology and the such
 
I only work with epsilon when I'm in the abyssal zone of technical debt.
 
I'm firmly in the analysis camp. Algebra is often frustrating to me. The proofs are often just thrashing about until I stumble upon the thing I'm trying to prove. In analysis, I feel that I have strong intuition that guides me.
 
"Ah hell, there's no time to find an exact symbolic solution, I'll just do Newton's Method for a hundred iterations or so"
By the time the users discover that it diverges for certain inputs, I'm already three counties away, cashing my check
 
2:54 PM
I have a hard time believing that anyone eats corn in any manner that does not mimic the movement of a typewriter.
 
@Kevin rows/analyst here.
 
Spiral-style is more efficient than rows, since you don't have to move your face back to the beginning of the next row every time.
You could eliminate this inefficiency if you eat in rows boustrophedonically but I don't see anyone seriously advocating that as a natural style
 
I hold the cob vertically against a cutting surface and use a knife to shave off rows of corn. If ever I attempt to eat "tooth to cob" I am attempting to recreate a Nintendo character from my youth on the cob in order to sell it on EBay
 
hi dear friends
 
hello
 
3:22 PM
This could be a good t-shirt for Machine Learning people...
 
s/hi/cbg
 
o/
@PM2Ring I want that shirt
 
All knowledge is questionable.
But it's a real glass half-full / half-empty situation.
 
^ haters gonna hate
 
Because knowledge is questionable, we no longer administer leeches in order to balance the four humors. But we only did that in the first place because of questionable knowledge
 
3:26 PM
@vaultah Not in the standard json module. You can do what you want by subclassing JSONEncoder, but it's a bit tedious. That's basically what I did for my compact JSON encoder, which inlines the innermost nested lists & dicts, overriding the indent arg.
 
Science: the cause of, and solution to, all of life's problems
 
incidentally, we've ordered shirts of a similar vein recently, such as this one
 
cbg
 
@Kevin Not all. Religion, politics, and sex are also to blame. ;)
 
Insert joke here about how an interest in science repels all three of those
(I don't actually believe that, but I will not leave low-hanging fruit just dangling there)
 
3:32 PM
@coldspeed You forgot /g
 
word sixers
 
sup
 
@PM2Ring yeah, I decided to choose another approach
 
Got your PEP8 research, Andras. Thanks. I really gotta just read all of PEP8.
 
just get an editor that does it for you :P
and learn from there
it will yell at you when you do things "wrong"
 
3:35 PM
Maybe put some word boundaries in that regex so it doesn't turn "which IDE should I use?" into "wcbgch IDE should I use?"
 
You can even have it yell at you in Gary Busey's voice.
PyBusey
I think I found my next project
 
@malan no problem
 
Haha. I installed pylint and was going to try that out.
 
Kevin's science comment reminded me of Thomas Midgely Jr, a chemist who became famous for two amazing chemicals which in later decades turned to be a Bad Idea: tetraethyl lead, used in leaded petroleum, and chlorofluorocarbons, aka CFCs.
 
Well CFCs were a great idea. For a while :P
 
3:36 PM
How about phlogiston?
 
No ecosystems, humans, animals, or plants were ever harmed by phlogiston.
IIRC, there were attempts to isolate & purify phlogiston for use in lighter-than-air craft.
 
Now that I think about it aether seems like a similar case
Maybe dark matter will end up being the same sort of theory.
 
In the average 4X game, you have to use the crappy polluting technology for a while until you can unlock fusion plants. If you try to jump straight from iron age to space age, you'll get flattened by Ghandi, and he'll pollute ten times more than you ever did.
CFCs were a necessary invention in order for us to discover the dangers of CFCs
 
Similar arguments are proposed about the holocaust and genocide or the atomic bomb and hiroshima. ಠ_ಠ
 
There are a score of scifi books with the premise "you went back in time and averted WWII, but without the war nobody ever invented sophisticated rocketry, which means no space colonization, which means no FTL travel, which means no time travel. Nice paradox, dummy"
 
3:48 PM
I just played a game with a similar cause/effect
 
I think those are generally fallacies. Scientific progress and invention may seem like happy accidents, but I mostly think its an inevitable track.
 
But it seems likely to me that real life's tech tree is not as coarse as the ones you see in games. You don't need CFCs to invent electric cars.
 
The time patrol spend a lot of their time preventing time travellers from assasinating Hitler. ;)
 
Not that they need to, his kung fu is very powerful, obligatory SMBC etc etc
 
We just need Doctor Emmett Brown
 
3:51 PM
Is your avatar a Lego Van Gogh?
That's awesome
 
You might see that I am not the author of this. But I will have you know this is in fact me.
I am Legogh
 
What do we do about things like this? I trashed my PATH only a couple of weeks ago from setx. This is the first result for me for "Windows add pip to path" and the top answers are just wrong.
setx will truncate the path to 1024 characters and just cut anything else off. This can cause more problems than it solves.
 

« first day (3020 days earlier)      last day (1925 days later) »