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?
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)
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.
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)
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
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
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
@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
> 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
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...
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.
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
Up 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
"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"
@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
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>
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"
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"?
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
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)
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')
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 :-)
@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.
@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 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.
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'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
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
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 :)