« first day (4014 days earlier)      last day (1159 days later) » 

01:41
Is it possible to construct a dictionary such that when a user tries to access a particular key, a function is run and the function output is returned?
Probably one needs to override getitem
I haven't written any decently useful python code outside of Stack Overflow for months (years), feelsbadman
and I could even argue that my more recent answers on questions have not served any useful purpose beyond helping the person who asked said question
as is typically the case anyway
 
3 hours later…
04:53
can somebody solve this problem defined in this link stackoverflow.com/questions/69491050/…
basically I am unable to start installed python based windows service
05:43
kindly help me to solve this problem
@Aran-Fey
No. Stop pinging people just because they're here, that's rude
ok sorry for this
06:37
How can I get realtime history of web browser by using python?
06:50
hello guys, does anybody know how to launch a function in a loop, so that the function understands that it has to use the content of the loop iterator rather than the variable is pointing? I'm using the observe function from ipywidgets and having:
foo(i):
do something with the i

w=widgets.somewidget()

for i in range(3):
w.observe(lambda change: foo(i,change) ,name='value')

I need w to observe 3 functions foo(0) ,foo(1), foo(2) rather than only foo(2)
Short answer is lambda change, i=i:
@duhaime There's defaultdict and dict.__missing__ to run code when a lookup fails.
07:07
kinda bummed that int('7.9') gives error :(
cbg btw
@AndrasDeak thanks a lot <3
07:22
Hi
Can I catch current url of browser using python?
it depends on your web framework, yes?
i don't think there's a javascript-y solution to that in python
I am a python progammer.
I don't the current URL of the browser is well-defined.
I currently have two open browsers with a total of 3 active tabs and… many lots other tabs.
3 active tabs in 2 browsers? How? O.o
one browser has two windows maybe?
07:33
^Arne'd
I want know how to get the lastest url.
So you have 3 open browsers then :|
Filtering by timestamp
Which is the last url?
I want get this.
using python.
for any browser that might be installed on the system, or a specific one?
@Aran-Fey That's too philosophical after just half a cup of coffee. D:
07:37
any browser
@bituniverse are you trying to build a trojan, just curious
@PIngu No
I want catch all urls requesting out.
from my computer.
@bituniverse well, sounds like a project that will take a serious amount of free time before it works
@bituniverse So a network sniffer then?
Tracking request.
I'm using browser-history package now.
But it gets history not in real-time.
07:44
wireshark but for python, huh
I know it.
there you go, always a pywatchamacall it for something you need to do
But it needs wireshark.
I can use only python packages.
I see ... out of curiosity, can wireshark be installed inside a docker image?
This is my client's decision.
I can only use python.
07:49
I see
Nobody knows how to get real-time history of brower using python?
I'm actually decently sure that you can't
 
1 hour later…
09:23
Could someone tell me why int("7.9") does not work?
I always thought the output would be 7
int(7.9) does what you want. Strings passed to int must contain string literals.
Oh so "7.9" is not a string literal?
Nope. It's a float literal.
For the same reason why int('5j') doesn't work. There's a high probability that you messed up, so it's safer to throw an exception.
Oh I see, thanks :D
10:03
@MisterMiyagi just confused, how is "7.9" a float literal? anything with quotes is a string literal right
so here CoolCloud was right?
in the context of the conversation, i think it's safe to assume that the intended meaning, from both parties, was along the lines of "string literal containing/representing an int" vs "string literal containing/representing a float". seems like a mouthful.
so something like repr of int vs repr of float, where both are strings?
Ah, sorry. Yes it's a string literal of a string containing a float literal.
yeah. purely terminology wise, if anything is written within quotes like this "blahblah" it's a string literal only. (doesnt matter if its a literal containing an int, float, etc)
ok thanks guys, @CoolCloud might want to read this though in case he was also confused
10:14
@MisterMiyagi wat
@MisterMiyagi ah, OK
I am going to shamelessly tell you were python_user'd :p (to an extent)
Rolls off the tongue, doesn't it? :P
laurel, well, there goes my 5 seconds of fame
Well, I'll just be wearing the hat of shame for a bit, so feel free to wear the hat of fame.
Is there a limit to the number of network IO call one can make using async libraries (aiohttp), in thread I would have, say 100 threads and that would guarantee me 100 concurrent calls, is there a such limit / factor in asyncio where I can control the concrurency?
or is this not a meaningful assumption to take in terms of asyncio
10:29
Just replace the word "thread" with "coroutine" or "task"
"As much as the scheduler can mange" I'd say.
so I can just fire 1000 coroutines and the scheduler would take care?
The coros would also have to cooperate well, right?
There might be a limit to how many coroutines you can have, but I kinda doubt it
asyncio should take care of the cooperation.
10:33
ah, neat
You can have as many coroutines as memory allows.
Though the workload must still fit into one CPU performance wise.
that is really cool
@MisterMiyagi that just means that performance gets degraded after a while, but that's different from "can only handle N coroutines", right?
I'm always hesitant to make any assertions about low-level asyncio stuff, because there have been at least 2 occasions where something that (in my mind) "should obviously work" actually didn't work
"can" vs "should"
10:35
Like, why can't I start an event loop inside another event loop?
10:47
so the reason I asked this was to know if I can "simulate" a normal synchronous behavior in async, similar to how I can make a threaded program synchronous by using 1 thread in the thread pool
just to see timings
@AndrasDeak Depends how you define "can handle N coroutines" I guess. If the coroutines must respond in time, then no.
@python_user How is the "run 1000 concurrent coroutines" limit helping you with a sequential limit?
@MisterMiyagi will it be worse than overallocating vanilla threads?
In principle you can also have threads as many as you want memory permits, but at some point they won't be able to do their tasks anymore.
@AndrasDeak I just wanted to see if async was really giving me the benefit, I wanted an easy solution to just "turn off" async by setting some limit, I wanted to try both extremes
OK, so when you said "the reason I asked this", you didn't actually mean the reason you asked that.
10:50
@AndrasDeak Depends. I would prefer chocolate threads.
instead the reason you asked about asyncio in general is because you want to use asyncio
Or did you mean that you expected there to be a MAX_COROS envvar that is 100 by default and you'd set it to 1?
because that would be very XY-y
Not that it really matters; I just got hung up on the semantics of what you said :P
I wanted to see if I can set MAX_COROS to 1000 to see how it works, and to 1 to see how it works
my assumption was MAX_COROS=1 would behave like a normal synchronous code
possible coroutine overheads aside
So perhaps you should ask "is there a way to limit the number of concurrent coroutines?"
you might get a different result
well I guess "is there a such limit / factor in asyncio where I can control the concrurency?" in my older messages was that? chat.stackoverflow.com/transcript/message/53216927#53216927
Ah, fair enough, I glossed over that part.
I was misled by the start of that sentence
> Is there a limit to the number of network IO call one can make using async libraries (aiohttp), in thread I would have, say 100 threads and that would guarantee me 100 concurrent calls
OK, it's on the both of us then
10:54
laurel, could say that :D
we may continue :P
I will have to run some timings check, TIL using google.com as a test url for 1000 IO calls actually makes you solve captchas (if you later open google.com in a browser) :/
I don't think any "N coros" limit would make sense TBH. Coros already run single-threaded, so you can't really limit the parallelism that way. Switching off concurrency is guaranteed to break things.
So as long as the machine can stomach it, go for it...
^ I am going to do this
 
3 hours later…
13:43
Thinking about lamps today
Looking for enlightenment?
🥁🥁🐍
@Kevin these ones?
Actual desk lamps. In particular the kinds with adjustable positions. I'm curious how they work mechanically.
I have a couple of those, so I can tell you that the fundamental principle is magic.
Fig 1 and 2. Gooseneck and swing arm lamps. Center gadget's purpose is unknown.
I own a gooseneck lamp and casual examination reveals little
13:57
The centrepiece is for attaching the thing to the desk.
14:08
It seems like my lamp's arm is made out of a corkscrew-shaped strip of metal that winds around about 100 times over the span of a foot. In the recesses there's more metal, probably of the same material. I'm guessing that's a corkscew too.
Perhaps the metal is naturally bendy, at least when it's fashioned into a slinky™ shape like this, and the lamp stays in place thanks to the friction that each corkscrew exerts on the other.
If friction is the primary element at play here, I'm surprised that the neck hasn't gotten floppy or rusty or anything over the decade that I've owned it. Basically daily use too, this neck has a lot of city miles on it
Wikipedia isn't helpful, other than noting that "Similar to its natural counterpart, it can be bent in almost any direction and remain in that position."
Can't say I've ever met a goose who would stay in position after doing the bendy bendy thing with it.
@Kevin what else would the primary element be?
You normally need water or high humidity to rust. And it could be made of stainless steel that doesn't corrode easily.
And there could be magic juice incide the tube formed by the corkscrews, right?
14:28
Yeah hydraulics or some such
unlikely, but anyway there could be a plastic core in there or something, I don't know
but the swing arm seems transparent enough
Wikipedia claims it's basically two intertwined helix screws.
No magic, sadly. 😔
that just means that two intertwined helix screws are magic
14:56
en.wikipedia.org/wiki/Balanced-arm_lamp looks relevant to my interests
15:40
Well my prototype is quite floppy but I did come up with a practical linkage design
basically, a parallelogram with free axle joints lets me position the lamp arm at whichever angle I like, while assuring that the free end remains parallel to the base. Good for keeping your lamp pointing in a particular direction while you position it
Granted, the only stable position my prototype lamp has is with its free end resting gently on the desk, but I still feel like I've made strides here
I think I can replicate the spring design from en.wikipedia.org/wiki/Balanced-arm_lamp#/media/… using rubber bands. That should at least ensure the lamp stays upright, although I'm still in the dark about how to fine-tune the tensions and weights so all positions are stable
I might get to use Hooke's Law for the first time since I learned it in elementary school. Very exciting
15:56
Is there a simple means to concatenate several tuples into one?
I currently have sum(((1, 2) for _ in range(5)), start=()) and it feels weird (the genexp looks different in the real code).
How do you feel about reduce
trick question, nobody likes reduce except Lisp programmers
Now I feel guilty. 😅
what about itertools chain
stackoverflow.com/questions/11574195/… looks relevant. TLDR: itertools.chain
oops beaten
woah, i kevin'd kevin!
3
16:01
I sense great power here
but yeah, just throw a chain.from_iterable at it if you have a container of tuples. should flatten it right out.
For the sake of completion:
>>> import functools
>>> import operator
>>> tuples = [(1,2), (3,4,5), (), ("foobar",)]
>>> functools.reduce(operator.add, tuples, ())
(1, 2, 3, 4, 5, 'foobar')
First to kevin'd takes the price, I'm afraid.
I'm pretty sure this allocates like O(N^2) bytes of intermediary tuples that get discarded almost immediately, so I can't recommend it
Same reason Python yells at you if you try to use sum on strings
It's for about 16 items, so no worries there. :P
16:07
> Rubber is generally regarded as a "non-Hookean" material because its elasticity is stress dependent and sensitive to temperature and loading rate.
Ah heck.
2
A: How should I use the Optional type hint?

Alon BaradUp until Python 3.9 if you wanted to hint for a nullable value you had two options: import typing def foo(bar: typing.Optional[str]): .... def foo(bar: typing.Union[str, None]): .... From Python 3.9 you are not required to use typing module: def foo(bar: str = None): ....

This answer is kinda wrong, some coworker linked to it
I agree that None is different from the empty string, in particular by having different types. I'd have to go brush up on some reading to determine what implications this has for type hints
Good thing that we now have ... | None instead of fiddling around with Optional and Union. :/
That question is just one huge misunderstanding.
I'm confused by python.org/dev/peps/pep-0484/#union-types. I can't tell if def handle_employee(e: Employee = None) is valid or not.
16:23
Its valid in the sense the type hinting system will take it, but invalid in the sense that at runtime you immediately violate the typehint contract?
"By default, None is an invalid value for any type, unless a default value of None has been provided in the function definition" makes it sound like = None in the function signature is the one permitted exception, but then it goes on to say "assum[ing] an optional type when the default value is None [...] is no longer the recommended behavior"
Really the question is what do external tools like pylint believe
@Kevin See the end of that section: "This is no longer the recommended behavior. Type checkers should move towards requiring the optional type to be made explicit."
Right, I think we're on the same page. I'm just squinting at "By default, A. This PEP used to recommend A, but B is now recommended" and trying to figure out how to make the actual text square up with the apparent intended meaning
maybe the PEP is outdated
16:26
It only works for historical reasons. Using a type checker with strict checking (e.g. MyPy --strict) should reject it.
The PEP parts are a nice way of saying "we did the wrong thing but it takes a while to change that. please don't do the wrong thing."
Arguably, PEPs can't be outdated because they're the ethereal platonic ideal of the language. If an implementation contradicts a PEP, it's the implementation that's wrong. </half-serious>
More like the British legal system where new laws replace old laws if they conflict in language?
Well nice chatting, g2g and practice longbow: forbes.com/2010/06/16/…
A new PEP can replace an old PEP, and in fact this has happened many times
[citation needed]
PEPs have a "superseded by" field
AFAIK there are still regular updates to PEP 484. It's more of an encoding of what the ecosystem should do, not a specific Python version.
16:30
throw a rock at a bush of pattern matching PEPs and a superseded one will jump out
Is there an in-house type checker that serves as a "model implementation" the way that CPython is the model for Python? If so, that would resolve my confusion
"By default, our in-house checker does A. But that's outdated, so if you're writing a new checker, do B"
MyPy kind of was. But now Guido sits at Microsoft and they have their own bridge to sell...
I will accept "kind of" as good enough
In any case they should probably clean up the smattering of = Nones that show up elsewhere in examples in the PEP
I wonder if there's a practical solution to this, then: what if I want foo(123) to be legal, and foo(), but not foo(None)? How do I annotate "union with None only when default"?
@MisterMiyagi bit late to the party, but there's also tuple(val for _ in range(5) for val in (1, 2))
Parallel question, is it even a good idea to forbid foo(None)?
16:39
I don't think so. It doesn't really get you anything.
As for type checking, you can forbid it using @overload.
Using a private sentinel type can get you the same thing in practice, but that's usually because None is a valid value in these cases.
Yeah, I've done that a couple of times
17:13
Hello again
Does anyone know if there's a way to obtain the maximum positive number representable as a python float without using sys library?
Or is that the only way?
17:27
why not use sys library? well, you could always just calculate and hardcode it
I was going to joke and say "start at 0.0, and add 1 until right before you reach infinity" but I'm pretty sure floats eventually become sparse enough that incrementing a value doesn't actually change it
>>> x = 1e200
>>> x == x + 1
True
indeed
float shennanigans are fun
If you only need an estimate that's accurate to within an order of magnitude or two, multiplication by ten might suffice:
import sys #only used for illustrative purposes
x = 1.0
while x * 10 != float("inf"):
    x *= 10
print("estimated max float:", x)
print("actual max float:", sys.float_info.max)
#estimated max float: 9.999999999999998e+307
#actual max float: 1.7976931348623157e+308
that "is equal to float inf" check looks pretty bad
import sys #only used for illustrative purposes
x = 1.0
while (z:=(y:=(x * 10)) / y) == z:
    x *= 10
print("estimated max float:", x)
print("actual max float:", sys.float_info.max)
Mm, walrusy
17:43
that hurts my brain.
@AndrasDeak Now that looks much better!
goo goo
@Kevin That would hardly be fun lol
@ParitoshSingh Because that's what I'm checking my code against
@AmnesiaSmith may I ask what kind of code that is?
or what kind of check
I'm not sure that answers the question of why you want to calculate the max float and check it against sys.max_float
17:54
No clue, I'm wondering how to do this task tbh tho the easy check is just float_info.min
after doing
from sys import float_info
@AmnesiaSmith again, what is "this task"?
I think I missed something. How does min tell you the max?
sorry max
If "this task" is "get the max float", then sys.float_info.max solves the task. What is there to check?
Oh ok
17:55
@Kevin sounds like something philosophical Kevin. you'll understand it one day.
Either you have a very good idea of what that number should be, in which case use that very well-defined number, or you have "whatever python tells me", in which case there's sys.float_info.max which honestly has far fewer room for bugs.
I'm asked to find the maximum positive number representable as python float - I need to test whether the number is equal to infinity by using float('inf')
@AmnesiaSmith test_result = sys.float_info.max == float('inf')
which i should compare with
float_info.max
17:57
yea
It's plausible that you have a teacher that said "find sys.float_info.max without the sys module", but then you have to tell us that. Otherwise you're responsible for explaining this nonsense question.
it's not a question that's a priori nonsense, but your refusal to clarify what you're trying to do makes it gradually more nonsense with each passing message
Definitionally, the maximum positive number float can't possibly be infinity, because infinity isn't a number*. Which means the problem is solved, and you didn't have to write any code to begin with :-)
I mean I mentioned before that I can't use sys
(*for certain definitions of "infinity" and "number" and "isn't")
i also suspect whether the teacher wanted you to calculate it theoretically based on the explanation of floats as you were taught in class perhaps
@AmnesiaSmith why?
17:59
@AmnesiaSmith you asked if there was a way without sys, and if it was the only way with sys. You didn't say you "can't use sys"
@ParitoshSingh We were just given textbook links that told us how floats were stored
And you especially didn't say "I can't use sys because this is a homework with arbitrary restrictions"
@AndrasDeak Yes because I wanted to try it myself -- what is the issue here?
I wanted to know it if was even possible -- 1
if so then I was gonna use float('inf') somehow -- 2
@AmnesiaSmith because when people ask arbitrarily confused things, we tend to help them do the right thing. If the question is intentionally confused thanks to a third party, that needs telling to the people you're asking help from.
@Aran-Fey. Thanks. Appreciated. So, this means 143,859 characters!
18:01
hopefully that clarifies things but yea you were just being rude.
thank you for your time though
@AmnesiaSmith basically, some things make sense not by brute forcing, but by theoretical approaches. "common sense math" tends to break down near the max value of floats, and as such, the real answer to your question is this: approach it theoretically.
I have a strict 100% money back guarantee, if that helps.
@Avra Python scripts can contain any unicode character
@Aran-Fey. Thanks. This means Python script could have 143,859 characters!
I'd like to have some context on that one.
Hold the mustard.
18:04
@MisterMiyagi in case you missed it, chat.stackoverflow.com/messages/53220887/history
that's probably not what you meant, but anyway
I'm also curious why someone needs to know the answer to that question tbh
Best case scenario: Sheer curiosity
@AndrasDeak. :/
@AndrasDeak.
you edited the first message with a reply
@AndrasDeak Weird. I can see only two of those message. The oldest two have the same url.
it happens
@MisterMiyagi "oldest two"?
18:08
@AndrasDeak. My PC is hacked probably :/
If it is, you're lucky this is the damage the hacker chooses to do
@AndrasDeak Ah, got it. Sorry, I misinterpreted what I was seeing.
a stuck up arrow key is more likely perhaps
Andras, I would hereby like to thank your people for inventing goulash. Truly an underappreciated contribution to society.
<3
I wonder if we have the same notion of goulash... but considering your country, maybe.
I'm told the more West you go, the weirder ideas people have when they eat goulash :D But K.u.K. should be worth something!
You might also like "chicken paprikash" (honestly, we call them gulyás and paprikás csirke or csirkepaprikás). One of the other signature foods we have that I actually love.
18:22
Onions with meat, onions, paprika, and onions. Also bread or noodles. And more onions.
And potatoes!
Wait, really? I don't think we put potatoes in ours
depends
Wait, potatoes? I was thinking of tomatos. We definitely don't use potatoes
When you say gulyás you normally mean gulyás soup, which has potatoes. If you mean gulyás stew, that's typically bográcsgulyás (~cauldron gulyás), which is more like what you said.
I'll have to check the Goulash article helpfully linked from en.wikipedia.org/wiki/Guly%C3%A1sleves
actually, the stew one also often has potatoes (I got confused for a moment with beef stew, yumm)
that you'd probably like
18:27
Wikipedia doesn't list onions as a main ingredient for either one of those O.o
it definitely is, don't worry
where there's paprika there's onions
mine's like 30% onions, 30% meat, 30% noodles
What kind of noodles? Spätzle?
the remaining 10% is paprika
That sounds more like pörkölt. Excellent choice, might I add. en.wikipedia.org/wiki/P%C3%B6rk%C3%B6lt
18:29
Oof. Pasta, my weakness. They're not Spätzle, they're tube-shaped
ah, actual pasta
It's acceptable, with pörkölt. Although I prefer fusilli over penne and whatnot :P
Spirals? Yeah, those work too
I hope there aren't any italians listening
One day you should try "beef stew with red wine", a.k.a. "vörösboros marhapörkölt". Best made in a cauldron.
I can see a youtube video from channel "kitchen paprikash", that's piqued my interest. But no time to certify its contents right now.
I don't like the taste of alcohol, so wine is out of the question for me. But wow, there sure are many variations of this dish
I don't like it either (taste of alcohol nor taste of wine). After a few hours of boiling it only makes it more... savoury?
My family usually makes beef stew out of pork, and we joke that it's "wild boar stew" because the wine makes it wild.
(it's not a funny joke)
18:42
I mean, for family jokes that's par for the course
19:31
Cabbage
cbg
Paul: I'll be back!
Long time no see, everybody!
Weird: who's seeing this?
cbg the pair of you, especially PaulMcG (we've been talking behind your back and stuff :P )
Is this thing on?
19:32
Hope you've been well @PaulMcG!
Well, I've been learning Golang... but my heart is still with Python!
Has anyone used the match statement in production code yet?
My fun discovery is that match is a soft keyword, so you can write things like match match: case case:
I've realised that I've been lax with the room meet pencilled for tomorrow as a few things came up. I'm just trying to sort out a google meet now but I'm not sure whether people are still interested
Completely lost touch with this because reasons, so I'm happy to see that serendipity has smiled on me with this chance visit to the room.
19:39
That's tomorrow at 6pm UTC? (just read your starred message, not sure if there has been any updated schedule)
I've put an hour in the calendar at that time. Google Meet or what?
I've just started a room here: meet.google.com/gzc-qiqy-cob?pli=1 can you check it quick @holdenweb please? I'm in the pub atm, I'm assuming the link will live until tomorrow for the proper meet
If it lives, I'll star it
Or anyone actually, but I can't hang around for a long chat because it'll be broadcast to the pub. I just need to know whether that link is public
Asked to join ...
It's not come through. Hmm
So I can access the page, but someone has to let me in. I have to run myself, chapters to write doncha know. Hope the lorries are still moving ;-)
Perhaps if click the button ...
20:05
@roganjosh Worked for me - see you tomorrow
For the room meet tomorrow: meet.google.com/gzc-qiqy-cob?pli=1 All are welcome, it'll be nice to meet some new faces. Thanks also for PaulMcG and holdenweb for confirming the link works :)
 
3 hours later…
22:51
Sorry, 13th Oct at 6pm UTC
rbrb

« first day (4014 days earlier)      last day (1159 days later) »