« first day (4258 days earlier)      last day (675 days later) » 

user19284560
12:24 AM
Hello!
 
2:35 AM
Hello!
 
 
8 hours later…
10:29 AM
Hello!
 
 
2 hours later…
12:56 PM
I'm playing around with the rich module. The Table class lets you add rows or columns to the table at any time, but you can't delete or update them. Or am I missing something?
 
You are correct
 
"Store your data in a convenient format, and generate a Table when you want to print it. Think of it more like HTML. The table is the finished product you create from your data, but its not how you store the data." Ok, I find this reasonable.
 
1:20 PM
My use-case is to display a table of real-time countdowns for things I have scheduled this week. "take out trash -- 9 hours, 40 minutes, 7 seconds", that kind of thing. My current annoyance is there's no strftime equivalent for datetime.timedelta.
 
1:38 PM
there might be libraries that can do that, i think they call it what, humanize?
in pendulum or arrow or something, i forget where i saw it
well..depends on what you meant actually. you simply want time deltas to be converted to "9 hours, 40 minutes, 7 seconds" this kind of thing?
 
def timedelta_repr(delta):
    minutes, seconds = divmod(delta.seconds, 60)
    hours, minutes = divmod(minutes, 60)
    s = f"{hours:02}:{minutes:02}:{seconds:02}"
    if delta.days:
        return f"{s} + {delta.days} day{'s' if delta.days > 1 else ''}"
    else:
        return s
I want this, but in under twenty characters.
 
what does delta give when casted to a string?
 
Here's one example: "2 days, 8:59:54.229584". Unless days is zero, then it would just be "8:59:54.229584"
I could strip off the milliseconds and insert a leading zero for hours, but it does not spark joy
 
1:56 PM
In any case here is my prototype. Possible v1.1 features: 1) make it clearer that "tomorrow's meeting" isn't happening today, despite having no " + x day(s)" text. 2) if an appointment happened already, move it forward by seven days. Wednesday's meeting should happen every Wednesday.
 
 
1 hour later…
user19284560
3:16 PM
hi
 
3:36 PM
Hello
 
 
3 hours later…
7:02 PM
Sometimes async functions return an object that can be awaited or used as a context manager. Is there a builtin way to create such a function, or do I have to write my own class for it? Example:
# case A
async with api.open('foo') as file:
    content = await file.read()

# case B
file = await api.open('foo')
async with file:
    content = await file.read()
I imagine this could be realized with a function decorator like so:
@awaitable_context_manager
async def open(self, file_name):
    ...
 
I suspect you just need the right dunders. __await__ is probably a good one.
Confidence: 50.01%
 
It's not particularly difficult to implement, I'm just wondering if I have to or if someone's already done it for me
 
Here, have this link which is possibly useless: docs.python.org/3/reference/datamodel.html#awaitable-objects
I feel an ache in my programmer's bone, which means that the useful thing you would like to have, is not readily available. Or possibly a storm's a-comin.
 
Can't you use asynccontextmanager?
 
This thing? docs.python.org/3/library/… Hmm, I better close the storm shutters.
 
7:10 PM
That's the one
 
No, that creates an async context manager, but I want an awaitable async context manager
 
I see
 
I trust your assertion that those things are different things. But I lack the brain cycles to comprehend them directly.
Slithy squamous things, these asyncs, built from right-angled pentagons, and parallel lines that intersect exactly three times
 
7:35 PM
@Aran-Fey Not that I know of. I've got a similar case for await'ing async iterators.
How about making it an awaitable that produces a synchronous context manager? Or do you need async cleanup?
Hm, you need __await__ to alias __aenter__ and aclose to alias __aexit__, correct?
 
An awaitable that returns a synchronous context manager sounds horrifying O.o
with await foo():?!
 
Have you tried ramming the problem with your boat, so it retreats to R'lyeh until the stars are right again?
 
@Aran-Fey Ja! Isn't it beautiful?
> Changed in version 3.9: Acquiring a lock using await lock or yield from lock and/or with statement (with await lock, with (yield from lock)) was removed. Use async with lock instead.
When in asyncio, do as the Spanish Inquisition does.
 
@MisterMiyagi Hmm, that sounds correct in the general case, but in my particular case it's actually a bit different I think. Basically, I have an async context manager AsyncFile, and the async function api.open that does some async stuff and then returns an AsyncFile. In other words, the interface is like async with (await api.open()).
Now I want to make this prettier, which means I need a new context manager where __aenter__ awaits api.open and then __aenter__s the returned AsyncFile
 
So you want something like async with api:?
 
7:48 PM
async with api.open() and async with (await api.open()) should both work
 
Right, then you still need __await__ and __aopen__ to be the same. They also need to be idempotent, though.
Unless you want to make your life needlessly even more complicated.
 
Returning a different context manager sounds easier. This is how I did it
 
denvercoder9 looking at this transcript 6 months from now: :'(
 
@Aran-Fey Huh. Mindbending but clever.
 
Dear denvercoder9: I was right, it has a bunch of dunders. That should get you started.
 
8:00 PM
It's my favorite paste site because it auto-detects the programming language, and it doesn't let me keep the file alive forever, so denvercoder9 will just have to deal with it ¯\_(ツ)_/¯
 
@AndrasDeak--СлаваУкраїні That's what they get for using chat asynchronously!
 
When denvercoder9 arrives in 6 months, they'll say they only arrived too late because we weren't cooperative enough
I dread the day when I have to write documentation for an async library. foo returns an awaitable, bar returns an async context manager, qux returns an awaitable async context manager. It's gonna be a mess
 
8:16 PM
* Awaitable[Cry] *
 
 
2 hours later…
9:56 PM
my_list = [1, 2, 3, 4]
element = my_list[1]
element = 'foo'
print(my_list)
Do we have a dupe target for "why doesn't my_list contain "foo"?
 
hmm...that's similar, but the main list has an extra level of nesting than what I'm looking for.
In particular, stackoverflow.com/questions/72609315/… is a recent question that seems like it should have a dupe target. I went ahead and answered it. But would be better to close as a dupe.
 
@Code-Apprentice there are two cases, the first one is exactly your case, and answers compare the two cases
l = [1, 2, 3, 4]
for i in l:
    i = 0
print(l)
^ that is your case
Not the best dupe, though. But it's the same problem (compared to the nested case).
 

« first day (4258 days earlier)      last day (675 days later) »