« first day (4325 days earlier)      last day (606 days later) » 

3:09 AM
stackoverflow.com/questions/44803765 This seems to be not reproducible and, in my view, not useful
Oh, here's something worse: stackoverflow.com/questions/1798465 it was once used as a dupe target (which I've since rerouted) for a question that actually did match the title :/
 
 
2 hours later…
5:13 AM
hey all, has anyone used requests-cache.readthedocs.io/en/stable in production code? I want to cache my requests and this seems like a drop in replacement for requests, if you have not used this, how do you cache requests in your projects?
@AntoinePinsard did not know about the timetuple method, thanks
 
 
4 hours later…
9:33 AM
Found an impressive looking OCR engine, but it's somewhat poorly documented, so I looked at the code and now I'm regretting everything
__dir__ = os.path.dirname(__file__)
sys.path.append(os.path.join(__dir__, ''))

tools = importlib.import_module('.', 'tools')
ppocr = importlib.import_module('.', 'ppocr')
ppstructure = importlib.import_module('.', 'ppstructure')
 
Are those relative imports?
 
Yeah. Although there may be subtle differences between that and a from . import tools, not entirely sure
 
 
1 hour later…
10:43 AM
Let me rephrase/correct that: importlib.import_module('.', 'tools') is functionally equivalent to import tools, but it should be a relative import, it just isn't because the project structure is a mess
 
From my experience, a good chunk of frustration about Python's imports and packaging is people complaining that it hurts after shooting their own foot.
 
You're not wrong, but you have to admit that it's pretty tricky to find out how not to shoot your own foot
It's not intuitive and most tutorials are outdated or just bad
 
Is it bad practice to plot inside a method which calls itself using .after
If I had something in a method like:
`plt.plot(data)`
`self.after(time, self.method)`
It doesn't continuously plot on each call of .after
 
11:02 AM
@Govind75 what is self?
Does the recursion depth limit apply to threads?
 
self is a class inheriting the Tkinter Frame
 
I mean, do threads inherit the call stack?
75% confident my question makes sense
@Govind75 does the class work otherwise? I assume it's nontrivial to combine pyplot's event loop with that of tkinter, but I have no experience in this area.
 
Essentially I have a run routine which calls a live_plot routine which reads a file every 10 seconds using the .after method - I then want to plot this data, but whenever I attempt to plot it, the GUI plots the first iteration and then freezes.
@AndrasDeak--СлаваУкраїні Yes the class works otherwise I can receive the data and print it out perfectly on each .after call.
It's just the live-plotting which I am struggling with
 
I have the question on my page if you want more class details :)
 
11:08 AM
No, in fact we ask that you don't bring fresh questions here on the main site sopython.com/chatroom
I don't know these things very well and many users on the main site do
 
ah apologies
cheers though
 
11:40 AM
In my experience it's pretty normal to call after inside the very method that you previously registered using after. I've never had recursion depth problems even when I'm after-ing 60 times a second.
On a conceptual level it should be fine, since each instance(?) of the method will have the opportunity to finish executing before the window's event processing loop continues
"combine pyplot's event loop with that of tkinter" is perhaps possible. you can execute one iteration of the tkinter event loop with root.update(). Or maybe it's root.update_idletasks(). Tkinter can (in principle) play nicely with any other event loop if you periodically call update/update_idletasks within that other event loop.
Disclaimer: I have never actually tried this.
 
I'm looking forward to the first async GUIs showing up
A standardized event loop and no more callback hell. Sign me up
 
I like the idea of an updated version of tkinter that incorporates async, but continues to be a dinosaur in all other respects
Still can't natively listen for touch screen events, but look! It can asynchronously not listen for them.
 
12:03 PM
On the topic of recursion depth problems. I'm trying to decide if it's possible, in Python-powered lambda calculus, to enter an infinite loop without eventually causing a RecursionError. My guess is that it's impossible, but I don't have a rigorous defense.
"Python-powered lambda calculus" is essentially equivalent to: any Python expression that uses only function calls and/or lambda expressions with exactly one argument.
For example, (lambda x:x(x))(lambda x:x(x)) qualifies. It crashes with a RecursionError quite quickly, but I won't hold it against it.
 
Sounds impossible. At any given point, you have two options: Do 1 operation (a function call) or 0 operations (return). Without a way to come back and re-execute an earlier part of the code (like a goto or something), you can't go infinite without blowing up the call stack
 
The thing is my GUI doesn't freeze, it just fails to plot the rest of the graphs and never actually enters the live_plot routine again
 
(lambda g: lambda I: g(g(g(g(g(g(g(g(g))))))))(I)(I))(lambda f: lambda x: f(f(x)))(lambda x: x) runs for, I think, 2^(2^(2^(2^ ...[like 8 iterations of this]...^2))) arbitrary time units, while only reaching a maximum recursion depth of like 16
So it's not too hard to keep the computer busy until the universe dies, but that's a far cry from an infinite loop
 
Okay what's interesting is if I close the window that pops up it actually plots the new data.
And enters the plotting routine which calls itself using .after
 
@Govind75 Sounds like a mainloop issue. I could probably fix it if I had an MCVE.
 
12:18 PM
Is there a way to refresh the plot (simulate closing the window)? Or is my code incorrect, it seems once it plots the graph it remains in that subloop whilst also running the GUI
Should I try and create one for you?
 
Sure :-)
 
Okay the thing is it reads from a file which is updated in real-time, I'm not sure how to simualte that
 
I mean, just get the data from somewhere else. Like a list
 
If a real-time-updated file is truly necessary, I can try to meet you half way. make the rest of the code MCVE-worthy, and I'll figure out the one missing piece
Oh, my lambda expression just finished, after running for about ten minutes. I guess arbitrary time units are pretty short.
Throw in another thirty g's for good measure
 
I made it a list which updates after every call
 
12:33 PM
Say I have a byte with value 0b0010000. In common terminology, is the 1 in the 3rd bit or the 5th one?
 
How can I send you the file?
can i just drop it in here?
 
@MattDMo I'd say in most cases it'd be the 5th
 
You could edit it into your question on the main site. We usually don't like to discuss fresh questions in here, but I think I'll let it slide this time.
 
<3
 
@Aran-Fey Oh, is that the little-endian vs big-endian thing?
 
12:38 PM
I edited it in, its around 50 lines long but the first 25 are just the frame handler
 
No, endianness is about bytes, not bits. It's more about whether it's a number or not. In numbers, the least significant bit is usually considered the "first". If it's not a number, then... probably still the same, but I'm not sure
 
50 lines is reasonable, in my book
 
So yeah, when you close the plot window it then actually plots the new data - but when I leave it it just stays on that window instead of plotting on top of it
 
OK. I'm think it's supposed to be a number, but I'm not 100% sure. It's part of a file header describing the version of the file format, read as 0x10. Anyway, that helps, thanks.
 
I'm pretty sure plt.plot(self.channel) is a blocking operation. In other words, The rest of the live_plot method can't finish executing until the user closes the plot window.
 
12:47 PM
I see, is there a way to resolve that? I've heard of using the animation library of matplotlib but I have 0 experience using it
 
Whoops, I mean plt.show() is a blocking operation. Not plt.plot.
 
Oh
 
I know a handful of things about animation. I will consult the documentation.
 
Much appreciated
215
Q: Plotting in a non-blocking way with Matplotlib

opetrochI am having problems trying to make matplotlib plot a function without blocking execution. I have tried using show(block=False) as some people suggest, but all I get is a frozen window. If I simply call show(), the result is plotted properly but execution is blocked until the window is closed. Fr...

I think this solves it! Let me try
 
1:04 PM
Yeah, I think sticking plt.ion() above the tkinterApp() creation will do it.
plt.ion()
app = tkinterApp()
app.mainloop()
On my machine, this makes the plot window gain new points every second. It's a little obnoxious that the plot window reappears after I X it out. But overall the functionality is there
I think plt.pause(.001) isn't necessary because tkinter does a bit of sleeping on its own. Maybe?
 
1:30 PM
@Kevin Yeah that seems to work, thank you so much
 
I'm glad it worked out :-)
Continuing my geometry problem from yesterday... As a test, I'm using the parametric curve for a figure 8. cx(t) = sin(t); cy(t) = cos(2*t). I believe I can find the point on the curve closest to (px, py) if I solve 0 = (cos(t) * (px - sin(t))) + (-2*sin(2*t) * (py - cos(2*t))) for t.
 
@Aran-Fey as it happens, I have been drafting a QA pair for this
provisional title: "Exactly what conditions need to be satisfied to import a module?"
 
 
That's a short answer. "It needs to be located somewhere on your sys.path" :P
 
I've found the zeroes. [I point at the screen]. There they are.
 
1:46 PM
@Aran-Fey it is, in fact, far more complex than that, even without digging into causes
 
@Aran-Fey Absolutely agree. Tutorials, when it comes to Python are useless and even introduce misconceptions in best case scenarios (e.g: The classic: variables in Python) and just harmful at worst.
 
my top-level outline runs thus:
* It must not already be imported;
* You must use a correct name for it;
* Python must be able to find it;
* Python must not find something else first;
* The code must execute successfully.
 
For module importing however, unfortunately it's a case by case type of scenario. So only time and research will cure that foot
 
that's part of why I want to gather as much case info as possible into one place
like, yes, you have to learn "oh, pypi's name for the package is foo but I have to import bar" individually, from e.g. the documentation on the pypi page
but you can be made aware of the general principle that there can be a mismatch
(as for "variables", well, I get what you mean but the cat is out of the bag. A "name" by any other name...)
 
@KarlKnechtel I would like to understand what you mean by: Python must not find something else first if possible
 
1:50 PM
(and Python is hardly the only language with that kind of issue; I recall Java's "Java has no pointers" marketing running smack into the awkwardly named NullPointerException (which leaks the underlying abstraction))
@dhiaagr as in, math.py in your own project interferes with trying to import math from the standard library (sometimes even indirectly when standard library modules import each other)
if you want import foo to import specifically from the path/to/foo.py you had in mind, then that has to be the first thing that is found by searching the options in sys.path
 
Let Q=sin(t); 0 = cos(t) * (8*Q^3 + (3-4*py)*Q + px). Oh no, cubics!
 
@KarlKnechtel Oh I see. Well that's a given, I believe. For my personal modules, I try to nest them in a main module, so I can achieve main.module otherwise come up with a naming convention
main isn't a name I use for my own modules, I feel like I must emphasize, lol
 
2:06 PM
it's easy enough to understand, but this framework allows me to introduce (I think/hope) every point I want to make about import gotchas.
 
Nothing is a given when it comes to questions asked by users with one hour of experience with Python
My previous cubic was wrong, I actually have to solve 0 = (A^3)*(8*B) + (A^2)(4*px) + (A^1)(-3B - py) + (A^0)(2*px)
 
True. I remember the days where the purpose of __init__.py was as confusing as quantum mechanics. What's this dunder method doing in the filename?
Fortunately, @AndrasDeak--СлаваУкраїні 's tough love pushed me into reading the language reference.
 
the fact that it's named __init__ is a little arbitrary, but they're trying to build intuition by analogy to classes I guess.
(OTOH, a lot of old advice is floating around that greatly overstates the necessity for those files.)
 
2:22 PM
Well, they do come in handy when you want to define behaviors or assignments at import time. It's separation of concerns done right, imo.
But then again,my bias towards Python is only a step removed from fanaticism
 
@Kevin intriguing...
 
That's not the curve for a figure 8, btw. It's cx(t) = sin(2*t); cy(t) = cos(t)
 
I have a feeling you should be able to get it down to a quadratic in A and B (assuming A=cost, B = sint or vice versa)
are you minimising via differentiating sqrt((cx-px)**2 + (cy-py)**2) to find the equation to solve?
Got to clean up my git merges before close of play and then I think I'll try to flex the old differentiation muscles...
 
Yes, A=sin(t) and B=cos(t). I'm using dot product rather than sqrt((cx-px)**2 + (cy-py)**2). My scratchy notes can be found at pastebin.com/raw/M0QhfzmZ
Me and the lads decided yesterday that the shortest path from P to the curve will surely intersect the curve at a right angle
PM correctly guessed that the math would be unbeautiful. But I had to see for myself.
 
2:38 PM
Method looks good to me and the thing about right angles true. I wonder if there's a further trig identity that can make it a bit easier to solve. I sometimes plot the original against my new equation on an online graph site to check I've done all my trig ID's right
 
I've put a couple bits into desmos.com/calculator and none of it looked flagrantly wrong
 
3:04 PM
@KarlKnechtel I'm sorry, I misunderstood. I disagree that it's arbitrary, but I believe you're right. it is a an analogy to the __init__ method in classes.
And it's faithful to the there should be one, and preferably one, way to do stuff postulate.
 
3:32 PM
What do you call a shape with 4 corners? Quadrangle? Tetragon?
 
A quadrilateral ?
 
Is that commonly used in english? I've never heard that, but in german we use this word all the time
 
@Aran-Fey Yup
 
Alright, thanks
 
4:14 PM
I reckon that the average American middle school curriculum includes the textbook definition of "quadrilateral". The average adult probably doesn't remember what it is specifically, but they might make an educated guess. "He's been talking about shapes for fifteen minutes, so it's probably a shape. And 'quad' can be used to describe vehicles with four wheels, decorative plots of grass with four sides, drones with four propellers, and the power up in DOOM that multiplies your damage by four"
And for the 13% of Americans that speak Spanish, they'll skip most of that and think, "oh, quad like quatro. Yeah, must be a four sided shape."
 
Doesn't 4 corners imply 4 sides ? misread, again.
I'm trying to find a branch or a subfield of linguistics that establishes some kind of ratio of rhetoric vs facts in an argumentative text.
I'm sure there is, but I can't seem to find what it's called.
 
In regular Euclidean geometry, I'd expect a shape with four corners to also have four sides, yeah. Maybe there are some other systems where that's not always the case.
 
@Kevin What a chaotic system that would be, lol.
 
On a toroidal surface, you could draw four lines that intersect at only two points. One might argue that the result is a four sided shape with two corners.
Hmm, or would it be three sided... I guess it depends on whether line segment AB is considered a distinct side from line segment BA.
@dhiaagr There's Shannon Entropy, which calculates how much information you can encode in a system. I understand almost nothing about it.
 
4:30 PM
Oh yeah, I brushed that subject while reading this book (I can't recommend it enough). But I believe that separates the semantics from the integrity of a given message.
Which I didn't understand until I read the example* of radio waves.
I'm sure that iwhat I'm looking for is somewhere along the concerns of applied linguistics. But I would like to see some equation.
Not that I will understand it, lol, but just to know it already exists.
 
Knowing that something exists is very useful, especially in this profession
 
Hahaaa, so true. And it's why the Python docs say to keep the Std library documentation under one's bed.
 
 
5 hours later…
9:59 PM
https://stackoverflow.com/a/27680109/6732828
How come when I replicate this answer, I get a different result? Has the way Pandas copies columns changed over the past 8 years this significantly?
df = DataFrame({'x': [1,2]})
df_sub = df[0:1]
df_sub.x = -1
print(df)

x
0 -1
1  2
 
10:52 PM
8 years is a long time
looks like you figured it out and edited in an explanation, though
yeah, modern versions will emit a SettingWithCopyWarning, and not impact df
 
11:11 PM
stackoverflow.com/questions/26350627 I'm impressed that we have this question and that it has 50k views. From OP's perspective it's an idiosyncratic debugging question, but for others it ends up providing an explanation of basic technique... I guess?
 
11:26 PM
somehow, it had all those views and wasn't being used as a dupe target until today o_O
 

« first day (4325 days earlier)      last day (606 days later) »