« first day (4191 days earlier)      last day (750 days later) » 

3:12 AM
Hrm. My PyTest creations are altering the database permanently for some reason now?
Like any test I run that creates some objects w/ factory_boy is doing something such that those objects persist in the database
which is weird because that usually doesn't happen :c
 
3:28 AM
it's weird because some things are persisting and others aren't :l
 
3:54 AM
i figured it out
 
 
5 hours later…
8:32 AM
cbge
 
9:14 AM
Does anyone know whether asyncio may run another task/callback between the end of a future and invoking its callback?
 
asyncio is pretty bleak, yeah.
I'm still dealing with the fallout of "asyncio thinks your tasks are garbage", and the nicest solution is to add a callback to every task/future to clean up when done. Now, on the plus side that means we can use that mechanism for other cleanup things but one of them would introduce a race condition if the callback does not run immediately.
 
Have you considered submitting better tasks?
 
I've considered turning it off and not turning it on again. :P
The task itself works pretty well. It's a background task that just shovels items from a queue into a buffer to run commands in bulk. Since we now have to clean up the bulk commands explicitly, I thought about having the background task remove itself when there is no work todo. But that relies on precisely knowing whether the task is around so that it can be restarted if needed.
 
 
1 hour later…
10:39 AM
Wouldn't it be simpler to "just" have the background task wait until its next input appears? I presume there's something that means this is inadvisable.
 
10:50 AM
It's what we had before and it works well enough. The major problem is it means that then the background task is only cleaned up via garbage collection, which triggers a misleading ResourceWarning.
 
Recently a client requested "a link to an expense summary table, which sums values from the expense table, grouped by cost". Coworker[0] said, "Oh good, no changes needed to the website. Just alter the 'export to excel' button so it adds the summary as a second sheet". Coworker seems adamant that when client says "a link to X", they mean "put both these things in the exported file" rather than "an HTML <a> tag aka hyperlink to X". I am skeptical.
 
In case you are taking bets: three quatloo on them wanting a hyperlink.
 
10:56 AM
On one hand, I know what the average person means when they say "link". On the other hand, coworker[0] is competent and experienced with this specific industry and these specific clients. On the third hand, coworker[0] has mentioned being distracted lately thanks to the many many demands on their time. Which is incidentally why I have not scheduled a get together to ask "are you really really sure?"
 
Non-techy people often say stuff they don't mean, so your coworker might well be right... but what worries me is that he's adamant about it
 
yeah, one can only be sure if the client has said something similarly confused earlier, in which case this needs to be said
 
On a related note, I yesterday spent 20 minutes on the phone asking a coworker how she wants me to set up her laptop, and we spent 19 of those minutes talking past each other...
(And the 1 remaining minute was "Hey, I have a problem with my iPhone, can you help me with that?")
 
It was a genial kind of adamantness, like "ah, this funny client of ours, he says X and means Y, but don't worry, you just implement Y and it will work out". Rather than "you will obey me!" plus a swift whack to my shins with a stick
I think I'll implement Y, but with a little extra modularity so I can reuse a big chunk of the logic if I'm asked to implement X later
 
I was just about to say, it's probably best to assume you'll have to implement both...
 
11:06 AM
Change summary.send_to(excel_worksheet2) to summary.send_to(website), easy
 
11:16 AM
Anyone that regularly spends time in this room will gain a great deal of experience with talking past one another. It's my default state, given that I am often standing at a right angle to conventional reality.
I have many conversational tools for coralling the other person towards the information I need. None of them ever work, but they look nice in my toolbelt.
 
That's what matters the most :P
 
11:55 AM
A plumber carries a wrench because it increases his apparent plumberness. It is only a happy coincidence that it also helps fix pipes.
 
Need your help guys...
I need to convert this code into a command line.
magick \
test.jpg \
\( +clone \
-set option:WW %[fx:w*0.8] \
-set option:DX %[fx:w*0.1] \
-set option:HH %[fx:h] \
-set option:DY 0 \
-crop %[WW]x%[HH]+%[DX]+%[DY] \
-blur 0x10 \
-fuzz 10% \
-trim \
-trim \
-trim \
-set option:OW "%[fx:(h+160)*3/4]" \
-set option:OH "%[fx:h+160]" \
-set option:OX "%[fx:(page.width-h*3/4)/2]" \
-set option:OY "%[fx:page.y-70]" \
+delete \
\) \
-crop %[OW]x%[OH]+%[OX]+%[OY] +repage \
"test_out.jpg"
normally i would do
os.system(convert test.jpg -geometry 1800x2400^ -gravity center -crop 1800x2400+0+0 test_out.jpg")
but now i'm having hard time with the syntax of "-set option:WW %[fx:w*0.8]" and the others
 
12:13 PM
Consider using subprocess.run
 
I use imagemagick's convert a fair bit in my projects. In my experience, convert is a bit picky, and is more likely to work with subprocess.run than os.system. And it's much more likely to work if you call run with a list rather than a string.
I think the first thing you should do is, put Python aside and write a command that works directly in the command line, and fits all on one line. (it's fine if it's a very long line). Those "\\"s are often a source of trouble, so better to eliminate them where you can.
Here is one of the places I call convert in my projects. It doesn't have as many options and things as yours, but maybe it will give you a general idea.
 
12:38 PM
Thank you Kevin.
 
 
2 hours later…
2:16 PM
hi everyonne
<p class="search-result-address">
59 Margate Road, Herne Bay CT6&nbsp;7BH
</p>
how can i get this address as it does not have any selector or class/id
 
? It does have a class
 
yes but it if use a class it returns empty list
this class*
 
Well, that shouldn't happen. You're doing something wrong, and using a different selector probably won't make the problem go away
So, let me help you rephrase your question. The question you should ask is "Here's my HTML. Here's my code. Why does it return an empty list, and how can I select this address?"
 
maybe i am wrong, but i have been able to use selectors in past using something like "p.search-result-address" this
 
That is correct, yes
 
2:24 PM
but in this case it returns empty list
that is why i was wondering what's going wrong
 
I'm wondering that, too. But unlike you, I don't have the information I need to figure it out.
 
okay no problem
 
Ok, look, I'll make one last attempt here: If you want our help, you have to show us your HTML and your code.
 
2:50 PM
@MalikZaib stackoverflow has a full help page on how to ask this kind of question stackoverflow.com/help/minimal-reproducible-example
 
3:18 PM
If I ever encounter a genie, I'll use my first wish to replace every ounce of helpfulness in my body with Schadenfreude. Instead of wasting my energy trying to get all the information we need to help someone with their problem, I'll just laugh at them
 
Tehehe.
 
While I consider it morally acceptable to find joy in the pain of others, I can't do it with other programmers, because I know I'll be fixing their workarounds one day
 
There's a a fine balance between helping people so they can become good programmers, and helping them so they can stay crap programmers.
9
 
Wisdom
 
first time I heard about flutter
 
3:25 PM
Wisdom
 
80% of my help is so the person improves. 20% is so they can go back to work and I can have one extra minute of peace
 
Wait, you guys help people?
 
Rarely. Only when they let us.
 
4:10 PM
I need the karmic balance. Every time I solve someone's problem and they say "you really saved my life!", I go out and perform one felony.
 
Hi all.
I have a question on optimization.
 
I better put my felony sweater in the wash... Ok, I'm ready.
 
Here is the question:
I used a Python to try out lots of values for $x_1, x_2, x_3$.
 
I recommend... Triangularizing. That's all I remember from college.
 
This gave me an answer of $x_3=4$ for the minimum value of $f(x_1,x_2,x_3)$.
But the correct answer was $x_3 = 3.125$.
In addition, the Professor provided a hint, which I really didn't understand how to implement.
That's why I tried a loop, which gave me the wrong answer.
 
4:15 PM
Unfortunately, a Python for loop cannot loop over all rational numbers, even if you have an infinite amount of time.
 
@Kevin I know. Do you have any idea how I can follow the Professor's hint?
 
I don't know what the hint was, so right now no
Oh, it's in the image.
 
Yup
If you could explain how that works or how I could implement in Python, that would be great.
 
Wait, didn't you have a similar such problem a few days ago?
 
@MisterMiyagi That's right! You remember.
 
4:19 PM
How did you solve that one?
 
I'm pretty sure you gotta triangularize. If you're not sure what that is, I'm mad at your professor.
 
@MisterMiyagi Actually, that one was easier, because as Kevin said above, I just plotted out the function's domain and evaluated the function at each one of the intersection boundary points. Then, whichever point gave me the minimum was the correct point.
Here, however, the function contains absolute values, three variables, ... yep.
 
So you solved the last one graphically?
 
Yep.
 
Linear programming doesn't get too much harder when you add more variables. You just have to move more stuff around.
 
4:21 PM
In fact, I think I still have that Desmos graph.
 
Linear programming (LP, also called linear optimization) is a method to achieve the best outcome (such as maximum profit or lowest cost) in a mathematical model whose requirements are represented by linear relationships. Linear programming is a special case of mathematical programming (also known as mathematical optimization). More formally, linear programming is a technique for the optimization of a linear objective function, subject to linear equality and linear inequality constraints. Its feasible region is a convex polytope, which is a set defined as the intersection of finitely many half spaces...
 
That's it.
 
Once you get it into standard form, all that remains is lots and lots of arithmetic
 
OK, I'll try some more, but thank you @Kevin for the help.
 
I wonder if numpy.org/doc/stable/reference/generated/… would help. I have never used it.
 
4:24 PM
Wow, you really saved my life!
 
That's for the karmic balance.
 
@rb3652 You know Kevin's going to go out and murder someone because of you, right?
 
Accounting for Andras' doubt, I'll mark that down as 0.75 lives saved
 
4:25 PM
@Aran-Fey hehe
He was here with us, I swear
 
I was thinking public intoxication this time. Sit on my balcony and yell at the geese.
 
Not a bad alibi, but wouldn't it be more believable if you said ducks?
 
the infamous flock of Jersey geese
 
Geese are more common in my neighborhood. Baseless conjecture: maybe it's because the nearby river is moderately polluted, and large birds are more tolerant of pollution than smaller birds.
and by nearby I mean I'm looking at it through my window right now
Just sitting there... Being all polluted... Maybe it's not the geese I should be yelling at
Tomorrow's felony will be wedging comically large corks into the waste output pipes of the industries upstream of me
 
Does anyone have a favourite list comprehension going completely overboard? I know the exact suspect to go searching through their profile <cough>Ajax</cough> but I wonder if there's a really juicy one that people remember off the top of their head?
 
4:35 PM
I wrote a hideous .forEach chain in JavaScript the other day, but that's another matter
I remember thinking, "this would be perfectly elegant in Python, but nooooo, JS is too good to let me do for (idx, item in enumerate(seq)){"
Possibly a seasoned JS dev is perfectly able to write elegant forEaches that involve enumerate, but my powers are limited
 
Just writing functioning JS is enough of a win for me. Nothing fancy to see there
 
In an alternate universe, JS!Kevin is complaining that Python's map only supplies an item argument to the callable, and not index or array. "I see, Python is too good to let me iterate over values and indices at the same time. Boo, Python, boo!"
 
Lol, I'm just going to pretend they don't exist. I've found list(filter(lambda x:all(x[i+1] - x[i] == 1 for i in range(len(x)-1)), [[int(cards.get(b, b)) for b in i] for i in subs])) which should be suitable enough to demo for this presentation
I'm sure there have been worse, but close enough
 
5:14 PM
So it seems things like
`contextlib.redirect_stderr(io.StringIO()) as f`
don't work when text is emitted from external libraries. I wonder if there is a function that does work.
 
@Mikhail yes, os.dup/dup2
E.g. stackoverflow.com/questions/24277488/… but there's a better Q&A I can't find right now
I can check later from laptop
 
Hi guys
im having some troubles with pandas and a xlsx file, can someone help me?
when i use this structure the file gets corrupted
 
sure
 
thanks
hopefully needless to say, but you should repost your block of code with working formatting
 
6:31 PM
Like the formatting guide says, there's a sandbox room where you can practice
 
well, lets skip code part, its possible to modify existing sheets in a xlsx file? im having a lot of problems with that
 
it's a bit convoluted but one can get it right in a few tries
 
Maybe the file gets garbled when the writer throws an exception, even if you catch it. Is there any other way to check if a sheet exists, besides catching a "no sheet exists" exception?
Hmm, to begin with, why do you need to delete the sheet, when you are going to overwrite it anyway? Couldn't you delete the try and except blocks entirely?
 
ill try
 
 
1 hour later…
7:47 PM
python 3.8
I have a Box base class and want to create a "Boxes" object List[Box]
It should be a Typing Hint and I want to perform actions with it.

If I create Boxes as a Class, with no other class-values than the list of Box objects, I have to redefine multiple of the base functions (__contains__,__iadd__,__isub__,__iter__, __len__) to be able to work with it the same I would with `Boxes = List[Box]`. But on the other side I can now define class functions, e.g. draw(), that calls Box.draw() for all boxes.
class Box:
    def __init__(self, x,y,width,height):
        ...

class Boxes:
    def __init__(self, boxes: List[Box]):
        self.instances: List[Box] = boxes
        # no other values!
 
I suspect you could do class Boxes(list): and you could build up from that
 
@Brizar I feel like two things are being conflated here. If your "boxes" are just lists containing Boxes then you shouldn't create a class for them, just use an actual list that contains Box instances, and type hint corresponding arguments as List[Box]. On the other hand if you want these "list of Boxes" objects to also have methods such as .draw(), you will need a custom type.
and yeah, as Kevin said, you could inherit from list or UserList (I never know if the latter is still necessary)
 
"you need a custom type"
what do you mean?

Inheriting List seems like it could work.
 
No, not List. list or collections.UserList
And then you'd type hint with just Boxes which would be its own type.
@Brizar "custom type" as in class Boxes like you wrote. As opposed to using a built-in list that happens to contain Box instances.
 
I think then I'll keep my naive approach.

thanks you two
 
Whenever a typing problem reaches this level of difficulty, I consider it a divine signal that your project has enough type annotation, and you're allowed to stop
 
class Boxes(list):
def __init__(self, seq=()):
self.seq: List[Box] = seq


Then I would be inheriting all functions form list and did make sure to have annotation of List[Box] ?
 
Either inherit from list, or use a .seq attribute (composition).
class Boxes(list):
    def draw(self):
        return [box.draw() for box in self]  # TODO: make sure we only contain boxes

boxes = Boxes()
boxes.append(Box(sender='John Doe'))
 
@Kevin I try to annotate mostly everything on Projects thet get bigger. Force of habit.
 
something like that ^ (untested)
If you want your type to look like a List[Box] then I don't think you can (easily?) use composition. Not sure though, I'm not a typing person.
 
8:06 PM
so as long as I do not need more attributes than .seq I dont need to create a custom init ? think thats where I always went wrong...
 
No no no. If you need anything that a raw list doesn't give you on instantiation, you need a custom __init__. What I'm saying is that you might not need a .seq attribute in the first place. If you do need it, you'd need __init__. But if you inherit from list, you'd also have to call super().__init__ to be safe if you override __init__.
 
@AndrasDeak--СлаваУкраїні Boxes is fine. I just wanted Boxes to behave like List[Box] which it does in you example
@AndrasDeak--СлаваУкраїні okay. Think I got it :)
 
I guess you'll see in practice :) Do come back if you find something weird.
 
8:37 PM
with your solution, nothing makes sure, that I just insert any object.

Boxes([Box(..), "string", 1, (1,2,3,4))

does work which it shouldn't. But now I have to create an __init__(self, input: List[Box]) and call super().__init__(input).
This seems to kinda work. Its just typing no validation, but better than nothing...
 
@Brizar Yeah, actually verifying that your items are all Boxes is the "TODO" part in my snippet.
If you want to enforce that then you have to override append(), extend() and anything else that can add to your list. In fact you should also override __setitem__ so that mutation doesn't put non-Box objects in there. Unless there's something like pydantic validators that enforce type checks for you.
In the off chance that you don't actually want to mutate the list you could (probably?) subclass tuple and then you have fewer things to override. __init__ and __add__ come to mind.
 
8:52 PM
If you use typing then you generally don't want to verify types at runtime as well. (Unless they come from input for multiple types, like JSON or ast.literal_eval.) The type checker should do that for you already.
 
(that would be "equivalent" to typing with Tuple[Box, ...])
 
Note that you can inherit from list[Box] and the type checker will automatically know that the list operations return/require things as if it were just a list[Box].
class Box:
    ...

class Boxes(list[Box]):
    __slots__ = ()
Add additional methods as needed.
 
exploding head emoji
Is that already true on 3.8?
list[Box] looks sus
 
Oh, right. Pre-3.9 you need to inherit from List[Box].
 
8:57 PM
I'm starting to know way too much about typing for my taste. Miyagi, I'm holding you responsible.
 
It's been an honour!
 
Quick question as new to python, curious about such type of function definition , def foo(string: str) -> str:
is this implying in takes string input and output string?
 
yepp
Note that this isn't actually checked at runtime, though. You need a separate type checker like MyPy to check your program for typing errors.
 
But it doesn't actually check or enforce it. It's just a nudge nudge wink wink.
What he said.
 
thanks
 
9:45 PM
@AndrasDeak--СлаваУкраїні I just used set instead of list, no duplicates. way fewer methods.
@MisterMiyagi this sounds great, thanks
 
9:59 PM
@Brizar set is still mutable which was my point. boxes.add('oh no') will easily succeed.
 
10:11 PM
Is there a purpose to the memory address in things like <generator object <genexpr> at 0x10dfb45f0>?
 
Perhaps so you can determine the result of gen_a is gen_b without actually using is
 
I guess "eyeballing" is a good enough reason. I'm pre-empting a question tomorrow and I don't have a better answer for why it'd be in the __repr__ :)
 
10:27 PM
If you're designing a language, and your object() instances have no distinguishing qualities besides "occupies a unique spot in memory", you may as well put that one identifying feature in the repr ¯\_(ツ)_/¯
 
10:38 PM
Something something "__repr__ is for recreating objects" while "__str__ is for human-readable stuffs n things". But I don't think I can do anything with that memory address
Good job I like gesticulating. The Data Model will be covered in 10 mins, tops :P
 
If a feature has been around since Python 0.91, it is perhaps too late to question its utility
Like looking at hand paintings made on a cave wall in the paleolithic and saying "the perspective is a bit wonky, isn't it?"
Faintly, in the part of your brain that hasn't changed in 100,000 years, you should sense drums, and the crash of thunder, and the glint of sharp teeth belonging to something just outside of your firelight. This is not a branch on the tree of history, it is the trunk
 
OK, that's worthy of an asterisk in the presentation to cover my behind. Thanks!
 
11:44 PM
It appears to be at least 32 years old: github.com/python/cpython/blame/…
I have colleagues younger than the default repr
4
 

« first day (4191 days earlier)      last day (750 days later) »