« first day (3336 days earlier)      last day (1626 days later) » 

8:00 PM
Traceback (most recent call last):
  File "c:\Users\Robertson\Desktop\Personal\moveSquare.py", line 98, in <module>
    pygame.draw.rect(surfup, rex.color, rex)
AttributeError: 'Player' object has no attribute 'color'
Obviously, I don't get how inheritance is supposed to work
def __init__(self):
        super().__init__(red, (SCREEN_WIDTH + 10, SCREEN_HEIGHT + 10))
Here's the Player constructor
def __init__(self, color, location):
        super().__init__(location, (20, 20))
        self.color = color
        self.speed = 10
        self.myX, self.myY = location[0], location[1]
        self.alive = True
And this is the Character constructor that Player inherits from
Surely I shouldn't repeat the code from Character's constructor? If Character has a color attribute, why doesn't its child?
 
>>> x = 0
>>> foo = range(x, x := x+5)
>>> [(x, y) for y in foo]
[(5, 0), (5, 1), (5, 2), (5, 3), (5, 4)]  # hey, we can write that more concisely
>>> x = 0
>>> [(x, y) for y in range(x, x := x+5)]
  File "<input>", line 1
SyntaxError: assignment expression cannot be used in a comprehension iterable expression
# >:|
 
That seems weird
 
sure does
 
surely it should just evaluate the range function, then do the list comp
 
i don't know why it doesn't
I should just post those last two lines plus error message to bpo, plus "why tho?"
 
8:12 PM
"Due to design constraints in the reference implementation (the symbol table analyser cannot easily detect when names are re-used between the leftmost comprehension iterable expression and the rest of the comprehension), named expressions are disallowed entirely as part of comprehension iterable expressions"
Someone's already complained about it bugs.python.org/issue38556
Though his list comp made my eyes bleed a little bit more...
[rename(f'{p}{n}', f"{p}{''.join([w[:3] if len(w) > 3 else w for w in re.split('[-_. ]', n)[:-1]])}.{n.split('.')[-1]}") for n in listdir(p := f"{getcwd()}\\{input('Folder: ')}\\")]
 
yeah, that's downright criminal
well, if they just closed the issue with a quote of the docs there is little use to post it again
:'=
sad walrus
@KieranMoynihan thanks for finding that before I embarrass myself over there
 
8:29 PM
@Arne that's life telling you not to do that
unless you're in an obfuscated coding contest
 
hey guys, how do you make one of those functions that takes in any iterable. I see that used in a lot of libraries
 
You implement your function's functionality such that it handles any iterable.
If you really mean "an arbitrary number of input parameters", you need *args
 
i meant more like the first, where a lot of libraries can take in lists, arrays, series, and iterate over them
 
just take an argument and iterate over it
 
Most things in python naturally work like that
 
8:32 PM
objects determine what's iterable, not arguments/names
 
the ones with arrays or series probably convert to either a series or an array under the hood, using np.asarray or np.asanyarray or something similar
 
are they using some set of properties that are common to all these objects, because technically you dont (at least manually) specify that you are iterating over a series
 
@AndrasDeak yielding from a nested comprehension isn't obfuscating, it's just efficient
 
@Skyler yes, it's probably duck typing as an iterable
as in "if you need to iterate it, assume it can be iterated and let objects decide if they can be iterated over"
 
looking a bit more into it it seems there is an __iter__ attribute thats often specified stackoverflow.com/questions/1952464/…
 
8:34 PM
I don't like that there are no anchors here (you'll have to search for "iterable"): docs.python.org/3/glossary.html
 
ok, the link you sent almost perfectly answers that question, thanks\
 
Python is strong with duck typing which is exactly about assuming behaviour, and letting objects comply with that. There are specific protocols in native python that you can conform with, but third-party libraries can also create concepts of duck types. Numpy is working on trying to pin down a "duck array" requirement.
 
I need to duck out for a sec
 
so its a seperate thing from reading in a sense. A dict has its hash table lookup (I think I'm slightly wrong but thats as close as i can get), but then can iterate and return its elements using something like Sequence as mentioned in the glossary
 
@AndrasDeak numpy is working on this? I maybe vaguely remember something along these lines being mentioned but I'm cautious that I'm thinking about pandas introducing an int type that supports nan
Fair enough, I think you did link this to me a while back
I've just been surprised by it all over again as it's been drowned out by all the other stuff I'm looking into :)
 
wim
8:48 PM
@Kevin you can drop the len(s) since you know you're dealing with 6 digit numbers already
 
btw, why did python end up making dicts insertion ordered
 
@roganjosh yup
the numpy.ndarray API has huge surface area, and it's not trivial to reduce it to a complete minimum that everyone can agree on
 
wim
 
Yep, I linked to the same thing under my first comment. We've definitely had this discussion before, apologies for re-asking
 
so it looks like it was a side effect of something else mail.python.org/pipermail/python-dev/2016-September/146327.html
 
8:50 PM
@wim thanks, I didn't bother to check the source this time. At least on hover I don't see anything.
@roganjosh ah, right, sorry
for what it's worth I didn't remember the discussion either
 
wim
@AndrasDeak for the hover event you need a userscript, which already exists: gist.github.com/Aran-Fey/1a0c5fa25617d9325e7baa8682560f92/raw/…
 
meh
 
@Skyler insertion order was desirable to preserve the order of variadic keyword arguments.
 
@wim it's be a lot easier for them to do the site right :P
 
In my (Monty) Python autobiography, I'm calling today's chapter "One more wafer thin query" after I just blew my own webapp apart meddling in pgadmin to delete some things
 
8:52 PM
@MisterMiyagi I thought **kwargs kept order before dicts did
 
wim
shrug it takes about 0.3 seconds to install and is incredibly useful
 
now that I said that I'm not sure it actually makes sense
 
oh im not contesting the usefulness, just wondering why since it sounds like it was almost just a byproduct of optimizations
 
@AndrasDeak they did since 3.6, which is when CPython gained insertion ordered dict
 
ah!
 
wim
8:53 PM
@AndrasDeak no
**kwargs were made ordered precisely because of the new dict implementation
 
Found an earlier discussion starting here
 
and its insertion ordered, rather then any other kind of potential ordering scheme, which is likely a result of mostly optimization considerations
 
Does anyone knows of a dupe target for concatenating lists creating new lists? stackoverflow.com/questions/59184492/…
the answers sure flow in... do we bet on reaching 7 in ten minutes?
 
answering no MCVE is always neat
I've already voted no MCVE though...
 
... damnit I just cast the final vote
 
9:00 PM
@FélixGagnon-Grenier that's not a problem. Leaving a dupe open is a problem.
 
@IljaEverilä you have some impeccable timing recently in walking in when I have postgres questions. I was reading your answer only today; are you at all familiar with APScheduler?
 
wim
@Skyler what a relief to see the top answer actually being correct for once.
often these basic 2009 questions have some garbage answer at the top
 
haha
 
9:12 PM
@roganjosh I'm afraid I haven't heard of it before.
 
btw, when i did a regex using '[^\w\s]' it preserved this " quality/sound "
how do i prevent that from happening
 
wim
riddle: guess the output
class Foo:
    def __getitem__(self, item):
        return __class__.__qualname__[~item]

print(*Foo())
 
@Skyler what would you like to get instead?
 
this is on a split, i was trying to get rid of all punctuation
df.title2=df.title2.str.lower().replace(r'[^\w\s]', '')
so for that and "$99." and similar things it should strip the puntuation still
and i thought \w only preserves underscores (or was it dashes)
 
I think the exact content of \w can depend on your locale, so if you only really want to retain ascii and whitespace, replacing with [^[a-zA-Z]\s] might be better
 
9:20 PM
@IljaEverilä No worries. I've been struck once again by the using-flask-SQLAlchemy bug trying to implement your suggestion. If you launch the app using something like gunicorn then you need to pass --preload to prevent the task being carried out by all the child processes. In doing so, I can't think of a way of using engine.dispose() and restarting the session for the parent process. That's just an FYI for a potential problem btw
 
I'm just guessing though, I still understand very little of what you're trying to achieve
 
Not much more than a corner case, but maybe worth knowing :)
 
wim
correct
 
\o/
 
9:26 PM
I think I understand that
 
wim
this one was too easy for the likes of you two, it's for the kiddos in the room
 
surely you don't mean me :D
 
tbh I kinda cheated... I used a interpreter to calculate the complement
 
wim
uhh yeah that's totally cheating
 
that trick came up a day or two ago
 
wim
9:27 PM
wet interpreters only!
 
@wim eh, "can you calculate two's complement in your head" isn't much of a riddle
 
but spoiler (which is what I learned a day or two ago)
 
wim
@Aran-Fey trivial
@AndrasDeak right. I was trying to get a cool riddle out of this, maybe I posted it too soon ... :D
 
ok then *returns 1st place trophy*
 
ToS-violating low-quality question from earlier stackoverflow.com/questions/59181251/…
 
9:36 PM
@Aran-Fey is 2 complement even well-defined for python integers?
 
@wim is it this?
 
wim
@AndrasDeak don't be so unfriendly , we should help the user because they're new
@Arne pretty close
 
@Arne I made the same mistake, if that helps ;)
 
@MisterMiyagi heck if I know
 
wim
9:38 PM
help them get their measley 3 rep back I mean
 
🤔
 
wim
user error stackoverflow.com/q/59111086/674039 , self-answered
 
can't I just touch my close vote and make it closed with 3 votes?
 
wim
I asked that on meta, no.
retract and reclose not a go either
 
I don't get why the answer is being downvoted to a self-answered question here
 
9:41 PM
I know, it was rhetorical
 
It's not something I understand well, but why disincentivise someone that posts the outcome of their research?
 
I downvoted the initial version and partly to help roomba
The question is a mental flatulence, so the fact that the penny eventually dropped for OP doesn't hold too much value
 
@roganjosh I didn't downvote it, but "read the manual" is not what I consider an answer.
 
wim
If the behavior in the question was in any way surprising I might agree with you
 
But the manual won't give int.to_bytes OverflowError:int too big to convert when convering to 1 byte, which I suspect is what people will be searching
 
wim
9:45 PM
but if every user posts whatever question and answer they figure out before reading the docs properly the site would be an even bigger mess
 
@roganjosh erm, the manual literally says that OverFlowError is raised if the byte length is too small
 
I'm sorta on the fence on that question
@MisterMiyagi Sure, but do you not copy/paste errors into Google as a first-pass?
 
I read the manual first.
 
I certainly do <holds hands up>. If there's an SO answer that points me to the docs, all the better
 
I rarely google first because there is so much low-quality junk around...
 
9:48 PM
Hi, um so I have a question on syntax, looking at some code and I see the following that is operating on two dictonaries
both = set(PA.keys())&set(PB.keys())
I understand that it's getting the intersection, what I don't get is what the .keys() is doing in this context?
Is it comparing only the keys when checking intersection?
 
It gets the keys of the dicts. It's probably superfluous in that context.
 
Alright, thank you.
 
you can try each step yourself on a dummy example dict
 
check PA.keys(), set(PA.keys()), set(PA)
 
9:50 PM
@AndrasDeak actually, set is superfluous. key views are already set-like.
 
@MisterMiyagi I guess
but if you keep forgetting that key views are set-like then calling set on the dict should suffice ;)
 
wim
the second .keys() is redundant too
the left hand side's keys view will duck-type the other dict 🦆
 
I'd definitely use .keys() for both even if I knew/remembered all that
 
wim
why?
 
Because I'd experience a mental bump reading it otherwise.
 
9:52 PM
@MisterMiyagi That would be subjective. I'm usually pulling in a library or 2 a week and still having to maintain the live system, so I don't have the luxury of investigating each library to to-the-full. I should probably have a full understanding but my project can take yam-ups if the system does (<pulls figure from the air>) work 99% of the time.
 
PA.keys() & PB would take 2 more cognitive CPU cycles for me to read (and this is assuming I'm aware of the behaviour)
 
wim
apparently I agreed with you 2 days ago github.com/wimglenn/advent-of-code-wim/blob/… (errr... AoC day 3 spoilers)
 
@MisterMiyagi uhmm, the set is necessary for the & operator to work
 
@solarc no, it's not.
>>> {1:2, 3:4}.keys() & {1:2}
{1}
 
wim
showdown in the REPLdome!
 
9:54 PM
oh
 
puts on his leather jacket
 
wim
solarc down by technical knockout!
 
@MisterMiyagi although, the answer doesn't link the docs, so that's not great
 
then i've been oversetting some of my code
 
at least it's not set in stone
 
wim
9:55 PM
get out
 
I'll unset some time aside to fix it
 
@roganjosh It's not some obscure third-party unmaintained mess. It's a builtin type of the the standard library.
and even then I would expect people to verify that the manual is junk first...
 
df["title2"]=df.title.str.lower().replace('[^[\A-Z\a-z]]\s', '')
didnt fix the phrase
`great quality/sound, average nc`
 
@MisterMiyagi I'm not gonna disagree with that. I left a comment. I don't think anyone has suggested the docs were junk?
 
@Skyler Are those square brackets inside the excluded character class really needed? They exclude literal [ and ]. cc. @Arne
and Arne had the whitespace inside the excluded group
I'm not sure how that pattern is supposed to work...
 
10:01 PM
yea, arne suggested that, couldnt respond since i was relocating
oh wait youre right
messed it up
 
I'd expect either [a-zA-Z] or [^\s] as "word-like" or "text-like" patterns. I didn't read what you're actually trying to do, though...
 
Oh wow, someone done-broken the styling of SO
I wonder how long that will live for :)
 
all 2 devs are working on it
 
PEP8 doing its bit to make questions legible right now :P
 
@roganjosh I was actually here to ask about that and got sidetracked :P
 
@AndrasDeak I want almost that, but also to split "quality/sound"
 
@roganjosh I was just gonna post that
 
oh, this is the fixed version, heh
 
so trim all punctuation
 
@Skyler why do that in one step?
Let me step back instead: can you point me to your original problem?
 
10:12 PM
Doesn't appear to be completely fixed, though
 
57 mins ago, by Skyler
this is on a split, i was trying to get rid of all punctuation
 
I'm gonna go with caching issues
 
@Skyler any earlier?
 
let's see if that fixes it
 
OK, I can see context, nevermind
OK @Skyler, input is 'great quality/sound, average nc', what is the expected output?
 
10:14 PM
Ctrl+F5 didn't fix it. CDN caching issues?
 
Great quality/sound, average NC
 
you're talking about splitting, whereas you're doing .replace
 
Nope, it's definitely broken. Deleting the cache doesn't work. I, for one, welcome my new display. It's making even annoying questions easier to ignore
 
I do a split a few steps later to feed into word2vec
 
@Skyler uuuh...you lost me
 
10:16 PM
thats an input, i do to lower, the regex catches the comma
but not the slash
But the input are usually sentences or titles
 
Thats the full sentence...title thing
 
Can you please read my question again and answer that and not something else?
 
oh oops
actually the output is great quality/sound, average nc
so it actually doesnt do anything...
 
talking about the current output, or the desired output?
 
10:19 PM
current
desired is:
 
okay, good luck
 
great quality sound average nc
 
Any reason you don't just enumerate punctuation in the re?, like [,./:;!?], and then sub with ' '?
 
this is from scraped data in utf-8 so I can try that (on that note any easy way to get a list of all punctuation characters)
but i am worried about other utf characters in the dataset
 
10:24 PM
Be sure to escape the square brackets
 
so it would be like df["title2"]=df.title.str.lower().replace('[^'+string.punctuation'+'], ' ')
cant fix anymore, left a typo there
 
@Skyler I can't comment on the regex, but if that ends up being the approach, consider a list comprehension to do the calculation and reassigning to the column instead of using pandas (if computation time is important)
 
regex101.com is a great resource for interactive re experimentation
 
sadly it didnt work:
`df.title2=df.title2.str.lower().replace('[^'+string.punctuation+']\s', '')`
 
sad
 
10:33 PM
a while back i remember the only way iresolved this was using translate
 
@Skyler don't you need the re module? string replace only replaces simple strings
 
str or compiled regex
You have to call re.compile yourself and pass the result as the arg to replace
 
10:55 PM
afternoon cabbage
 
Hi, sorry back with another simplistic question.
min([abs(x)+abs(y) for (x,y) in stuff])
For this line, is it getting the minimum sum for a matching pair of X, Y
Or is it ANY x + ANY y
And finding the minimum of that?
 
it's any x,y tuple in the list/set called stuff
if stuff = [(0,0), (-1,0)], you'll get back (0,0)
 
Okay!
That's what I was curious about. Thank you.
 
if stuff = [(0,-1), (-2,0)], you'll get back (0,-1), not (0,0)
 
@Rietty The key to understanding this is to look at for (x,y) in stuff. This tells us that x and y come from a matching pair.
 
11:31 PM
@inspectorG4dget ((you'll actually get back 1))
umpteenth variable variables dupe, no roomba stackoverflow.com/questions/59147996/…
 
@Rietty for each x, y pair in stuff it will calculate the value abs(x)+abs(y) as an element in the list resulting from the list comprehension. Then it will take the minimum of the results.
In other words, first the list is generated with an absolute sum of each pair being the values in the list, then it takes the minimum.
 
wim
this kaya3 user frequently answers dupes and off-topic questions
 
hard to get 6k rep in a month from scratch otherwise
 
11:58 PM
compiling regex made it work, thanks guys
 

« first day (3336 days earlier)      last day (1626 days later) »