« first day (3667 days earlier)      last day (1264 days later) » 

5:16 AM
@smci indeed, but first I best make sure it's actually decent code :) I'll review it over the weekend
 
 
5 hours later…
9:47 AM
Cabbage! I should show my nose here more often..
 
cbg Martijn =)
 
I answered a question on the use of function attributes, and something is really puzzling me. The 3 other accounts that interacted by commenting or answering on that question, all mention monkey patching, as if function attributes are the most important aspect of the whole concept monkey patching.
 
Which makes me almost question my sanity; monkey patching has almost nothing to do with function attributes, insofar that the common use is to patch names in a module or methods on a class.
So I am assuming that they are all Googling about function attributes so they can answer the question and find something that makes them bring in monkey patching.
 
Perhaps there's some popular new tutorial playing fast and loose with terms?
 
9:51 AM
But.... I can't for the life of me find a combination of search keywords that bring up a monkey patching hit in the top results.
Yeah, could be.
I feel a little bit like the old veteran on the bench outside the pub, bewildered at what the youngsters are up to today and how they are using familiar terms completely differently. get of the lawn, you young whippersnappers!.
The question wording may have something to do with it; the title is What are the rules for adding members to Python methods safely?, mixing terminology from other OO languages into the Python vocabulary.
Monkey Patching is certainly concerned with safely replacing methods on Python classes. Just not so commonly with attributes on function objects.
anywho, if anyone knows of a search query that brings those things together, I can lay that brain itch to rest ;-)
 
They blame it on the zope wiki... ;)
Aaaand, I'm going to backtrack immediately...
That's actually exactly what you described, not patching the function.
 
10:30 AM
@MartijnPieters anecdotal evidence: as a non-software-engineer "assign attributes to a function" definitely ticks the "monkey-patching" box in my head. Any kind of attribute assignment on instances (that weren't there in __init__), for that matter.
so perhaps it's just general confusion
 
@AndrasDeak: perhaps. I always emphasise that self is nothing special, it is just another reference to the instance, and self.foo = ... is no different from instance.foo = ... when teaching, but the notion that 'inside' and 'outside' a method body are not any different is hard to eradicate.
 
Yup, self is just Python's way of letting a method know which instance to operate on.
 
@AndrasDeak I can plus-one the sentiment, but my google foo has failed to turn up any notable examples on this. :/
 
Nowadays one meets fewer Python programmers who are aware of the equivalence between instance.method() and instance.__class__.method(instance).
The trouble when you sell Swiss army knives is, sooner or later they'll get popular enough that some people will start trying to slice bread with the corkscrew. Then they end up here, asking how to sharpen their corkscrew ...
 
For what it's worth I'm aware that self is just the instance and that it doesn't matter where you assign to an attribute. It's the terminology that's off in my head.
 
10:44 AM
Speaking of which, does anyone have a good way to explain how methods actually work to beginner/intermediate programmers?
Sprinkling on enough "descriptors!" without scaring people off with meta-details.
 
I think I know the issue. A core (wrong!) notion of monkey-patching in my head has been "unintended use". Hence adding function attributes (which is not a common thing to do) and adding new attributes after __init__ (which, I gathered, should generally be avoided). Whereas the core notion of monkey-patching is replacing existing functionality.
 
11:04 AM
Oh dang. i've somehow always assumed that "monkey-patching" always involved modifications to functionality at run-time, and does not distinguish between adding and replacing functionality.
 
11:21 AM
#bpf filter
filters=[(Constants.BPF_LD | Constants.BPF_H | Constants.BPF_ABS,0,0,12),
(Constants.BPF_JMP | Constants.BPF_JEQ | Constants.BPF_K,0,2,0x800),
(Constants.BPF_LD | Constants.BPF_W | Constants.BPF_ABS,0,0,26),
(Constants.BPF_RET | Constants.BPF_A,0,0,0),
(Constants.BPF_RET | Constants.BPF_K,0,0,0),
]

fprog=bpf_fprog(5,ctypes.pointer((bpf_inst*5)(*filters)))

is this filter correct? but,it returns full packet...I want to get return of packet[26:30] ...any solution?
 
Obligatory question: If you want packet[26:30], why don't you ask for packet[26:30]?
 
that line refer to that ,
(Constants.BPF_LD | Constants.BPF_W | Constants.BPF_ABS,0,0,26) #packet[26:30] loads to accumulator ... but,I didn't get the output of that ,I got whole packet as output...I want to get the output as packet[26:30]
 
11:37 AM
Honestly, that seems very specific to that library (whatever library that is).
Not sure if anyone here knows how it works.
 
It is not a specific library.
Code
 
Am I correct this is some new Linux kernel operation thingy, seeing how you define your own flags instead of using those from socket?
Apologies if these questions appear dumb, but I'm literally laying my eyes on what looks like code for kernel-specific, low-level socket flags for the first time.
 
you mean the SO_ATTACH_FILTER ? it is in built with syscall.
 
I mean Constants.BPF_LD and the like.
 
it is not from socket library.... it is in bpf instructions.
 
11:53 AM
Now assume I don't know off the top of my head what bpf is, or where these bpf instructions are...
NB: Actionable question still being "Am I correct this is some new Linux kernel [...] thingy", since I do not have any recent Linux kernel available.
 
So, Linux or BSD kernel?
 
Linux kernel
 
Alrighty, then I need to defer to some other people anyway.
 
@MisterMiyagi valiant effort
 
12:22 PM
Meh, my valiant effort batteries are low these days.
 
I mean figuring out what we're even talking about :P
I was about to prepare the waterboard...
 
It beats my current dayjob task.
I'm staring at 10 lines of bash for the entire morning now. Trying to figure out whether deploying it is "no one will notice" bad or "end of the world" bad. And whether there is any hope in delaying the stuff until it can be rewritten properly.
Trailing the single instance that is running for an hour now does not bode well...
 
morning cabbages, folks
 
@MisterMiyagi just don't rm -rf that network mount
 
12:40 PM
Nah, that was five years ago for me.
 
Have the night tremors subsided somewhat?
 
This time the worst case is just having 1.200.000 CPUh unaccounted for.
 
blame it on bitcoin miners
...unless you accidentally mined bitcoin with all that CPU time
 
shifty eyes
 
import tempfile
import io
import json


with tempfile.SpooledTemporaryFile() as f:
    tf = io.TextIOWrapper(f, encoding='utf-8')
    json.dump({}, fp=tf)
this.
when busy, I need to go write a bug report.
 
12:48 PM
I vaguely remember someone else also complaining that it's not a proper replacement for a file object.
 
that's just another *tty excuse of bad programming in the Python standard library.
@MisterMiyagi both io.BytesIO and TemporaryFile would work.
 
1:14 PM
just saying, there likely is a ticket already
 
@MisterMiyagi of course there is. Opened 4 years ago and period.
 
1:39 PM
Feel free to submit a PR any time :^)
 
@Kevin well there is a PR patch...
I am free to patch my source any time and build my own Python Epsilonthon
 
In defense of named lambdas:

Why is this okay

    get_last_name = operator.attrgetter("last_name")

but not this

    get_last_name = lambda person: person.last_name
 
Feel free to gain trust with the core devs over the course of several years to the point they invite you into their ranks so you can accept the existing patch :^)
 
the other has named argument.
 
Controversial opinion: I think named lambdas are fine.
 
1:48 PM
the problem is not named lambdas... but naming anonymous functions is wrong :D
 
@PaulMcG in the first case, there is no alternative. In the second case, making it a proper named function does literally everything better.
 
stackoverflow.com/questions/38381556/… suggests that the main problem with assigning lambdas is that it looks like <function <lambda> at 0x00F6B970> in the stack trace, rather than showing the name you assigned to it.
 
And the whole "single expression, no statement" thing.
 
Funnily, showing the lambda in the stack trace seems to be more information than what attrgetter gives you, i.e. nothing.
>>> (lambda x: x.foo)(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <lambda>
AttributeError: 'int' object has no attribute 'foo'
>>>
>>>
>>> operator.attrgetter("foo")(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'foo'
The resistance to assigning lambdas honestly feels a bit insincere to me... It kind of seems like PEP 8 noticed that there was more than one obvious way to write a one line function, and sought an after-the-fact justification for why one of the ways wasn't obvious, actually
(which is not to say that everyone convinced by PEP 8's argument is also acting insincerely)
 
@MisterMiyagi Did I tell you about the time, back when disk backup was literally a drive-to-drive copy, that I started running the backup FROM the backup disk ONTO the live drive.?
I had to find out a lot about the structure of the filesystem to recover as much as I did in the end. Had to rewrite the changes we'd lost ...
Fortunately it was the system disk, and not the data disk. That would have been REALLY bad.
 
2:04 PM
I bet you were as popular as an old boss of mine was in a story he told me about when he started out, he managed to tip over a trolley full of punch cards he was taking to get loaded...
 
@PaulMcG I don't personally see in your second example why it's even preferable to write get_last_name(person) instead of person.last_name. It adds a level of indirect that increases code obscurity and lowers comprehensibiity/readability.
 
I would do this as part of creating a key function for sort and/or groupby. I just put up an introductory blog post on groupby, hence where this is coming from.
 
@JonClements Had a colleague do that with a 3,500 line (two drawers full of cards) Fortran program. She spent a happy few hours with the poor geologist who'd written the code. Happily about 90% of the cards had been sequence-punched in the original program, but it was still a week before his program was running again.
@PaulMcG Yeah, but naming such a short function obscures the simplicity of the selection and seems OTT. I'd just use the lambda inline. In general I tend to prefer code that doesn't reference attributes using string names, so I'd use the second one inline.
 
@PaulMcG when using as a key you need not predefine it and the lambda is fine
I guess you pulled it out for educational purposes
 
This is the post, where I use the method thingspython.wordpress.com/2020/10/30/…. It comes up when I'm using groupby, but first want to sort. When doing this, it is usually the same method as the key function for both, so I'd rather not duplicate the lambda in the sort and groupby calls.
 
2:15 PM
Yeah
 
I, too, have used the "sort and groupby with the same key" pattern.
 
@holdenweb lights a fire and hands around a bottle of booze Stories such as these are always welcome.
 
Usually what I really want is something like d = defaultdict(list); for item in seq: d[key(item)].append(item)
 
I have overwritten my hard disk partition table several times.
and twice the same thing,
i.e. I had bios software raid, and in bios I thought that I can "unraid the disk" in bios
what it meant was that it wrote like megabyte worth of zeroes to the beginning of both disks :D
 
@AnttiHaapala I'm sure that was a valuable learning experience.
 
2:24 PM
well, I did it twice
so I guess the first time wasn't enough.
 
And you've never done it again since, ergo you've learned better ...
 
but I did it some other way :P
but I've never lost data so...
/me knocking...
 
Good techies make the same mistake exactly twice xkcd.com/242
 
@Kevin And there's only one way to find out!
 
@PaulMcG Urgh, I've often wished for having sorted+groupby in one. I always need it exactly once, so there is never a clear winner for defining a sorted+groupby helper versus a separate key function.
 
2:28 PM
Real luminaries think "I wonder if that happens on the (N+1)th try?" but they tend not to live that long
 
@MisterMiyagi asspressions
 
@AndrasDeak That's a clear loser!
 
 
2 hours later…
4:58 PM
cbg
 
5:29 PM
Hi Guys. I hope you all had a great week! Enjoy the weekend and prepare for the upcoming week. 👍
 
I had a terribly work-laden week
But thanks, you too ;)
 
5:44 PM
burns 10 lines of bash
Splendid week! :)
 
Don't worry Andras, the work will go well. Thanks a lot.
Laurel Mister
I will go off for now. Bye guys.
 
6:00 PM
The last couple of evenings, there's people wandering around the graveyard next to the house with high-powered torches pointing them around randomly and often at our windows. The rational part of my brain says it's just the workmen that turned up to dig the road up... but the part of my brain that wins is that there's some alien-abduction-like stuff going on. Why be in the graveyard as road workers?
Or they work for the govt. and there's zombies. Also a possibility
 
halloween...
 
Ok, zombies is the working theory now
 
i.e. digging pits to capture halloweeners to abduct
 
Oh, for a minute I felt a little more calm - "well, at least if it is due to zombies, Boris has dispatched some special forces to 'fix it'". But you've just flipped that back to being disconcerting :P
 
@roganjosh have you watched any of the new series of Spitting Image...? (mind have already asked you that though)
 
6:11 PM
Nope. I didn't even know it had been restarted
 
wow... okay... yeah... it's exclusive to britbox but a lot of it is on youtube... youtube.com/watch?v=6Xw8tkDk5uY seems about right...
 
I can't really remember it. Maybe I was too young for satire at the time or my mum just banned me from watching it (keep in mind, I wasn't allowed to watch the old Japanese Godzilla films until I was ridiculously above an appropriate viewing age). My sister got a smoother journey being the second child :)
 
lol... but yeah... the channel for snippets is youtube.com/channel/UCCov3Uxwgh6Fq_2F7oW9-hA
 
Heh, yeah, they just swore in the clip I'm watching now. Definitely banned from my childhood.
 
definitely not quite the same as it was... but still a good parody take of things :)
bbiab
 
6:23 PM
@JonClements perhaps I've asked you before, but you ever watch The Thick of It? In the Talking Heads tribute it's just come up. Malcolm Tucker has to be one of my favourite TV personalities ever created. "You're like that coffee machine in the corner. From bean to cup, you **** up!" :P
 
Have watched all of 'em - brilliant show. Peter Capaldi was awesome as Tucker.
(also big fan of Roger Allam)
 
Ah, now I'm getting deja vu. I think we have talked about the show before :)
I will have to add Spitting Image to my watch list though
 
7:07 PM
hey guys what do you think of numba
 
Err. I think it's a neat library for certain applications. I'm not sure what kind of answer you're looking for
 
7:19 PM
@Matiiss 10/10, would recommend
subscribe and follow their insta
 
In the middle of this meta answer is "It is not in the interest of this community that users who think it is okay to post that kind of attacks are given a warning or a second chance or are shielded for consequences of red flags.". Am I reading correctly that they are suggesting no second chances?
 
Oct 28 '19 at 18:32, by Andras Deak
in other news, numba is both amazing and infuriating
@roganjosh that's literally what he says there :P
 
I'm just sanity-checking myself because it got 65-to-1 upvote-to-downvote and even I think that stance is out of whack
 
It might make sense in context. I haven't read the question, nor the severity of the content that's being discussed.
 
My own personal opinion agrees with the sentiment, but it offends my checks-and-balances I place on myself :)
 
 
2 hours later…
9:48 PM
Does anyone know how to print out the radius from a list of radii? My program keeps only printing out the last radii in the list.
 
@ShaneBeacham please don't ask for help here with fresh questions on the main site as per our rules
you even got answers right after asking...
Unless you really are asking about how to print each of those radii... well, print them inside the loop, not after the loop
 
 
2 hours later…
11:28 PM
Litmus test: I'm building a python framework that'll build a complex JSON payload of a problem to solve. It'll send this via a ZeroMQ socket to a Java program that will solve the issue and send the solution back. In theory the python framework would be built to catch any malformed input and never send a bad payload to the Java server, so it "won't error" in Java. This approach has worked for years but under a veil of secrecy. <to be cont.>
The alternative seems to employ a RESTful-type interface on the Java server too, just to accept POST requests and solve the problem in the payload (and nothing else). I'm not too concerned on the specific details, but more around the "on a scale of 'cabbage potato' to 'WILL SOMEONE PLEASE THINK OF THE CHILDREN?!' how bad do you feel this approach is?
"cabbaged potato" was probably a bad example, given Salad. Take it to mean "meh".
I'm conflicted between "well anecdata tells me that this has always worked" and "now someone will actually see how this setup actually works". If it really strikes people as awful, I'll put hours into building out the whole API on the Java side... but I know it works without doing that
 

« first day (3667 days earlier)      last day (1264 days later) »