« first day (4318 days earlier)      last day (615 days later) » 

12:21 AM
stackoverflow.com/questions/42724173/python-doesnt-find-pyomo another example of the "import to wrong installation" question
 
seems like they keep attracting bad answers with library-specific advice that isn't actually relevant, and worked for the answerer because the answerer only ever had an unrelated problem.
 
 
2 hours later…
2:32 AM
stackoverflow.com/questions/9979970 Is there a counterpart to this for "Q. why didn't I get a syntax error after misaligning my if/else? A. Because the else pairs with an outer for or while instead"?
 
3:13 AM
374
Q: Else clause on Python while statement

IvanI've noticed the following code is legal in Python. My question is why? Is there a specific reason? n = 5 while n != 0: print n n -= 1 else: print "what the..."

that?
 
3:38 AM
stackoverflow.com/questions/2438938 Opinions: is this a duplicate of what I previously linked as a see-also?
@metatoaster good enough, I think, if I add an appropriate small-text note to the question; so I think I will.
 
4:25 AM
another one of these pip vs python executable mismatch issue stackoverflow.com/questions/73318198/…
 
4:59 AM
I stumbled on stackoverflow.com/questions/15286401, which is a nice canonical to have
 
5:48 AM
One more in the mix for "how do I get information out of a function?" stackoverflow.com/questions/26468640/…
This has the advantage of specifically asking about getting the information back, without a particular focus on the context where it will be used (e.g. passing things *between* functions). It's also quite popular.

You can guess the disadavantages from the title.
stackoverflow.com/questions/55826026 Do we consider these typos, or should we scrounge up a canonical?
 
6:03 AM
wait wait wait hold the phone
stackoverflow.com/questions/3052793/… after all this time, I think finally found the right question for "how do I get information out of a function?"
and it's been closed inappropriately - a near miss, but there isn't any confusion about print here which is the purpose of that canonical. I'll reopen, at minimum.
 
@KarlKnechtel I think we can class it as a typo / braino. The OP's comments they simply forgot to use the parentheses. And we don't really want it hanging around as a signpost: it shadows input, and using this instead of self, and the lower-case class name aren't great for newbies to see, either.
@KarlKnechtel The only blemish is the use of print statements. I guess that shouldn't confuse too many newbies, but I prefer canonicals to use modern syntax, when possible.
 
6:21 AM
@PM2Ring I intend to improve it, and write my best possible essential-information-for-beginners answer as well
(well, essentials up top, and comprehensive ways-to-do-it underneath, As One Does)
 
6:41 AM
Sounds good to me.
@JonClements Emily & Cara cover the Everly Brothers, Crying In The Rain. I didn't realise it was a Carole King tune.
 
6:57 AM
Cbg everyone
Does anyone know if a serious fork of Atom is in the works? At least until this Zed thing becomes testable.
 
 
2 hours later…
8:40 AM
@PM2Ring Lovely harmony singing there. Also, I'm enjoying exploring the tunes from Molly Tuttle and the Golden Highway.
 
9:01 AM
@JRichardSnape Their voices blend beautifully. Emily also plays guitar. Cara is a multi-instrumentalist and a painter.
Here's Golden Highway with Dobro master Jerry Douglas. youtu.be/v0n28IQFEvU
Cara & Emily do Aerosmith youtu.be/tlTExSl_s7A
A wistful original song from Cara, Golden Hour. Joni's Little Green. Fleetwood Mac's The Chain
Molly's incredible playing on her "signature tune", White Freightliner. Jamming with Billy Strings on Little Maggie
Here's Bronwyn from Golden Highway with her previous band.
Sep 27, 2021 at 15:45, by PM 2Ring
@Félix For a change of pace after that sublime masterpiece, here's a bluegrass band, Mile Twelve. Their fiddle player is Bronwyn Keith-Hynes. They're performing Elton John's Rocket Man.
 
@PM2Ring It's amazing she can do that with pick/plectrum. The accuracy of the human body's movement when trained is quite something.
 
9:45 AM
Indeed! Molly was the 1st woman to win the International Bluegrass Musician Association's Guitarist of the Year award. She also plays banjo, both bluegrass & clawhammer style. And she's one of the few guitarists who've adapted clawhammer to guitar, eg Take The Journey
 
9:59 AM
Molly is good friends with Sierra Hull, who was the 1st woman to win the IBMA Mandolin Player of the Year. Here she's jamming with Chris Thile from the Punch Brothers. Chris & Sierra have been jamming together since she was 10. :) The speed & precision here is amazing, especially considering that it's snowing. youtu.be/DHznTAqc_3c
 
10:38 AM
I am using django reversion and I want to get last revisions before a certain date for all the users in object id
How should I modify following query to get this result
Version.objects.get_for_model(GameProfileAttribute).filter(
object_id__in=cur_values_dict.keys(),
revision__date_created__lte=leaderboard.schedule.start_date,
).order_by("object_id")
 
 
3 hours later…
1:21 PM
@PM2Ring ooo we're talking bluegrass? Béla Fleck and the Flecktones - Big Country youtube.com/watch?v=_K_PMVdb-c0
 
1:33 PM
Hi guys I have a quick question, what happens if the OP doesn't give the bounty and your post has a score of at least +2, but the OP has posted his/her own answer and accepted it. Will the bounty be awarded to no one?
 
I reckon that falls under the third paragraph of "how is a bounty awarded?" at stackoverflow.com/help/bounty. If so, the bounty would be awarded to the OP, which is effectively the same as not awarding anything.
There don't seem to be any explicit exceptions for answers that were written by the question asker
 
@Kevin I think it has to be +2 score still though
the page is quite vague
"(or the full amount, if the answer is also accepted)"
also may denote the answer has to have a score of at least +2, not sure ...
 
If I interpret the text with maximum pedantry, I get:
If bounty is not awarded:
    candidates = every answer with a minimum score of two that was created after the bounty was started
    if len(candidates) >= 1:
        answer = max(candidates, key = lambda x: (x.score, -x.timestamp))
        if answer.is_accepted:
            answer.give_rep(bounty.value)
        else:
            answer.give_rep(bounty.value/2)

    if bounty.creator == question.creator:
        if question.accepted_answer is not None:
            question.accepted_answer.give_rep(bounty.value)
 
If it's right then self-answers are ignored
 
1:47 PM
@PM2Ring Dang, she can play.
 
Which means that the highest voted answer gets half the bounty, and the accepted answer gets the full bounty. Good way to multiply points by 1.5, I guess.
 
@Kevin Don't think that's how it works :P
 
Create a question, put a 5,000 point bounty on it, answer it, get +2 points, accept it, let bounty expire. Result: 5,000 rep award from the first conditional block, and 5,000 from the second
 
Either one gets all or auto-award to someone for half
 
1:48 PM
@0x263A Nice
 
should this be asked on Meta or something? This is confusing me
 
@DialFrost seen my link?
 
@AndrasDeak--СлаваУкраїні Ya, it sorta answers my question
But not about the +2 score part
 
@AndrasDeak--СлаваУкраїні If you're right, then either my pedantic analysis is wrong, or the FAQ is wrong. I refuse to accept the possibility that either of us is wrong, so it must be the FAQ.
 
This bounty thing can easy happen. Wasn't a certain 500 point bounty that the OP figured out was it...? I think accepting your own (based on experience rather than the explanations) meant "never mind, I've figured it out, here's the answer and I've wasted my rep". Mind you, it was some years since I answered a question as I've been on ... errr ... hiatus
At one point, for reasons I can't remember, there was a rep threshold that it was useful to meet, so I remember answering a few bounty questions. When bounty first came in, there were some really interestingly difficult ones in the queue.
 
1:53 PM
@Kevin step 0: you can't end up with your own bounty
 
@AndrasDeak--СлаваУкраїні Yup that's the no. 1 rule
 
Step 1: if there's reasonable doubt that bounty offerer likes an answer, assign full score
 
I think the FAQ should be a bit clearer on the OP posting his/her own answer and accepting it
 
step 2: otherwise assign half score on a best-effort basis
 
It's fine to have that as a business logic requirement, but there's no Python statement that means "it's impossible for X to happen, no matter when where or how". If you want to enforce the rule, you have to do it yourself.
"Ok", you hypothetically think, "but you're mentioning Python in a conversation where nobody but you has mentioned Python. Why do you think you can lean on a premise that hasn't been accepted by anybody?". Good question. The answer is: because I am loony.
To make my point more abstractly, if you describe the behavior of a system in a contradictory way, and you don't describe what happens when there is a contradiction, then you have not sufficiently described the system.
 
1:59 PM
Agreed to an extent @Kevin
 
@Kevin thank goodness this never happens in specs I'm given to code up :p
Now browsing through my old answers. Past me was very kind. These days, my two top answers I'd be tempted to answer with "RTFM". The top one, I almost did say that, TBH.
 
"I go outside every day. If I go outside on a rainy day, I take my umbrella. I can't take my umbrella outside on Saturdays. Tomorrow is a Saturday and it will rain all day". Each sentence is perfectly consistent by itself, but the system as a whole is contradictory, and the reader can't determine what the speaker will do tomorrow. Maybe reality will bluescreen.
 
Should this be reported to Meta?
 
If it did get reported, I might feel moderate emotional closure. I don't expect the verbiage on the page to change though.
 
hmm ok
moderate emotional closure?
 
2:09 PM
Yes.
 
What does that mean? :P
 
I would get a nice feeling because I noticed a problem and told the proper authorities about the problem.
 
Hmm, so I should report it I guess? Not sure, it will probably receive opposers
 
If you do, remember that a low score doesn't mean you did a bad job. It only means that people disagree with you.
 
Hmm, haven't really thought about it like that before! I'll keep it in mind!
Well gn! (at least for me :P)
 
2:24 PM
brief cbg folks
@JRichardSnape not seen you in a while - how's things?
 
@JonClements All good thanks Jon. You? I'm popping in as often as I remember now I've got a job that allows it more easily.
 
Can't complain I guess... same old stuff :p
 
Well - as long as it's keeping you in puppy snacks...
 
ooo... scooby snacks... licks lips...
 
I'm back working on modelling the energy system again. Pretty timely in the UK...
 
2:32 PM
lmao... just do * 2 and you'd probably be bang on :p
 
@JonClements :D
 
doing a free tutorial thingy for blender.org - definitely feeling it's not the way my brain works... I get the maths behind it but arhghghg
doesn't help they make it look so yamming easy
 
2:51 PM
I use blender a lot and I think people get caught up in the math n'stuff. At the end of the day it's "just" 3d photoshop. I try and break tasks down the same way I do when programming and that seems to help.
 
@JonClements if you have a spare moment could you please reopen and reclose as dupe stackoverflow.com/questions/73335411/… -> stackoverflow.com/questions/52968312/… ?
Needs 2 mortal votes to reopen and I don't want to risk answers being posted
 
@AndrasDeak--СлаваУкраїні trusting your judgement as didn't read it... but done
 
Windows users, dearest of all my friends...
When a process receives signal.CTRL_C_EVENT, is the signal.SIGINT handler invoked?
 
@JonClements much obliged <3 exact dupe
 
The council of house Windows acknowledges Miyagi of house Miyagi
I have consulted our astronomers. They say "ask again in February". An auspicious month for event handlers.
 
3:00 PM
@Kevin bows to The Kevin
 
import signal
def on_sigint(signum, stack_frame):
    print("Handling signal with number", signum)
signal.signal(signal.SIGINT, on_sigint)
print("Waiting for user to press ctrl-C...")
while True:
    pass
I ran this code, and pressed ctrl-C four times. The result:
Waiting for user to press ctrl-C...
Handling signal with number 2
Handling signal with number 2
Handling signal with number 2
Handling signal with number 2
The program is still running. Normally I would exit using ctrl-C, but...
 
Hmmm, how about Ctrl-D?
 
press it like you mean it
 
Unless you're against that school of thoughts.
 
I clicked on the X on the cmd window. It might still be running, but at least I don't have to look at it.
I am not particularly against any school of thought relating to signals. This is because I don't know what any of them are.
 
3:08 PM
Oh you're one of them not-afraid-of-the-unknown type of persons :P
 
I am a little pebble at the bottom of the stream. Sometimes I am still, and sometimes I am moved to a new place. the Why and How are beyond me.
 
@Kevin but well rounded? :p
 
Yes. Rounder each day, even. This, too, is beyond me.
 
Man, your wisdom goes smoothly with my wine.
 
@Kevin The Internet claims you can SIGINT it to death. As for how to make Windows SIGINT it... well... ¯\_(ツ)_/¯
 
3:15 PM
My wisdom is 95% pretentiousness by volume
 
3:50 PM
@MisterMiyagi did you see my replies from last time? I know it's not as helpful as saying "here the amount of signals that it doesn't implement on Windows" but I guess it still count as an hint
found this, although this is mostly for subprocesses: gist.github.com/ubershmekel/119697afba2eaecc6330
@Kevin your honesty humbles me
 
@NordineLotfi Yes. Even though it turned out not immediately helpful for my case, it does contribute well to the rising evidence that I shouldn't be winging it.
 
see the gist link I posted above. It seems like it could work although it's beyond me since it use ctypes
 
In practice, I'm not the one creating the subprocess. That means I cannot rely on the process being a group leader.
 
right, but you could see if whatever the code in the gist is doing could work for the main process ;)
I mean it has a higher probability of working than the local signal module since, you know, it doesn't have some signals on windows implemented
@MisterMiyagi btw, here is the code I used for my cases when I was on Windows: dpaste.org/2dV7V
you can see the docs for the taskkill command and the different flags, since the one I used were to just stop the main process (don't think it's sending sigint since it was a while ago, and I usually use linux anyway)
 
4:16 PM
I think with what Kevin has shown, my problem now is that both CTRL_C_EVENT and SIGINT will show up as 2 (SIGINT). So there isn't really a way for the program to record and reraise the signal that killed it.
Not to mention that re-raising is ill-defined anyway, since the process cannot know whether it is a group leader and thus how to send the signal to the same group.
 
@MisterMiyagi does it matter?
 
@AndrasDeak--СлаваУкраїні Yes. SIGINT on windows is a guaranteed kill. Obviously.
 
The first argument to os.kill also has different meanings for CTRL_C_EVENT and SIGKILL. Obviously.
 
But then a signal 2 can't be SIGINT, right? :P
 
4:19 PM
Well, it can, since Python apparently pretends SIGINT == CTRL_C_EVENT for the purpose of event handling...
Since, like, everyone uses SIGINT to mean CTRL+C, assuming sane operating systems.
 
@Kevin How humble of you to admit it. :D
 
At least that's what the evidence by Kevin, plus what a handful of DenverCoders wrote on the Internet, suggests.
 
I think I also saw a detail about how Windows implement it's signals handling on some gist.github but I can't find it...welp
this isn't the gist I mentioned, but this is even better: stackoverflow.com/a/35792192/12349101
 
Possibly not useful information, but for the record,
>>> import signal
>>> repr(signal.SIGINT)
'<Signals.SIGINT: 2>'
>>> repr(signal.CTRL_C_EVENT)
'<Signals.CTRL_C_EVENT: 0>'
Despite them being treated identically(?) in certain contexts, they aren't literally equal to one another
 
Obwinously.
 
4:33 PM
I do enjoy stating things that everyone already knows, or never needs to know
 
I wish I either already knew that or never needed to. :P
 
@Kevin sounds like me
btw Miyagi, maybe signal.raise_signal could work?: stackoverflow.com/a/72637975/12349101
 
@MisterMiyagi I know this feeling
 
@NordineLotfi No, that just uses os.kill under the hood.
 
ah, nvm then
but did you see the two link above? doesn't it introduce some new layer of understanding?
or maybe it only did to me hmm
one of the commenter do sum it up nicely if sys.platform == 'win32': abandon_all_hope_ye_who_enter_here()
 
4:51 PM
Do we have a dupe for UnboundLocalError: local variable 'foo' referenced before assignment where foo is conditionally defined earlier? See stackoverflow.com/questions/73337330/…
All I can find are questions like stackoverflow.com/questions/370357/python-variable-scope-error where a variable is defined outside a function, then reassigned inside.
 
5:04 PM
at least I saw it being referenced as dupe in other related question
 
@NordineLotfi No, that's still an issue where variables defined outside of a function are being modified inside the function without a global declaration or being passed to the func as an argument. What I'm looking for is the situation like this:
cond = False
if cond:
    foo = "bar"
print(foo)
Wait, that'd be a NameError. Check the original question I linked to.
 
hmm, I'm not as much of an expert dupe finder as others here but, I found stackoverflow.com/questions/10851906/… and stackoverflow.com/questions/68763804/… to be suitable candidate
or at least related
 
5:36 PM
OK, here's an MRE. The code above needs to be wrapped in a function.
>>> def func(cond=False):
...     if cond:
...         foo = "bar"
...     print(foo)
...
>>> func()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in func
UnboundLocalError: local variable 'foo' referenced before assignment
 
6:28 PM
How do you language hint an indented code block? I tried <!-- language: lang-py -->, like we used to be able to do, but it doesn't seem to work. language-all doesn't work either. I'm looking at a question tagged with both and , and the code is in Python, but is being syntax highlighted as R.
 
@MattDMo go for triple backticks (code fences) with ```py
 
Yeah, but then I have to unindent all the code, and that's a bit of a pain - copy to Sublime, unindent, paste back.
 
That was it. Thanks!
 
7:13 PM
Ha, I also answered that question! Strange...
 
7:32 PM
helping your future self is always weird like that
one example is writing the right comments at the right place, and forgetting months later that you were the one who made whatever that is.
 
8:31 PM
Heya guys. I'm having a stupid problem to which I'm sure there's an answer somewhere but I can't find it.

Basically, I'm creating a pure red RGBA image, and then add an alpha layer from some data. This result in an image that looks good. I then want to convert it to RGB, but that just removes the alpha layer and results in a pure red image again.. What can I do to convert the RGBA image to RGB and keep it looking like the RGBA image?
red = Image.new('RGBA', (512, 512), (255, 0,0,255))
red = np.asarray(red)
red[:,:,3] = some_data


im = Image.fromarray(red, 'RGBA')
im
 
It should look like the second
The first you shared is 1-image?
 
No, the first is my usual dark mode in chat, the second is the regular chat background colour. Both are just screenshots from here in chat.
My point is that "I want it to look like the RGBA image" is inherently ill-defined. The whole point of transparency is that you see what's behind the image. It depends on your background colour.
 
I see your point. I want it too look like it's on a white background
 
OK. I'm not familiar with how this is done, but it's not trivial. You'll have to look up how this conversion can be done properly :P
that looks surprisingly straightforward which I find slightly surprising
 
8:45 PM
There's a python function in there. Lemme try that.
 
that won't work with your numpy arrays as-is
you want something like red_normed = red / 255; bg_normed = np.ones(red_normed.shape[:-1] + (3,)); composite = (1 - red_normed[..., -1]) * bg_normed + red_normed[..., -1] * red_normed[..., :-1]
I might have the two terms swapped
Yeah, hold on, editing still
OK, something like that
it's cleaner if you separate alpha = red_normed[..., -1]; red_normed_rgb = red_normed[..., :-1]
 
Hmm, this is going over my head a little bit. The composite line is throwing operands could not be broadcast together with shapes (512,512) (512,512,3)
 
yeah, sorry, I edited the message about four times
ah, no, OK, it's still buggy, sorry
let me write it down properly
 
Thanks a ton already. I tried the python function from the link to - adapted it to take my np arrays but it's results in the same as Image.convert('rgb'), i.e., full red image
 
9:02 PM
import numpy as np

# dummy data
nx, ny = 512, 512
i, j = np.indices((nx, ny))
red = np.zeros((nx, ny, 4), dtype=np.uint8)
red[..., 0] = 255
red[..., -1] = 255 * np.sin(2*i/nx*np.pi) * np.cos(3*j/ny*np.pi)

red_normed = red / 255  # shape (nx, ny, 4), dtype float
alpha = red_normed[..., -1:]  # shape (nx, ny, 1) for broadcasting
red_normed_rgb = red_normed[..., :-1]  # shape (nx, ny, 3)
#bg_normed = np.zeros_like(red_normed_rgb)  # shape (nx, ny, 3) <-- black background
bg_normed = np.ones_like(red_normed_rgb)  # shape (nx, ny, 3)
created with:
import matplotlib.pyplot as plt

fig, axs = plt.subplots(ncols=2)
axs[0].imshow(red)
axs[0].set_title('RGBA input')
axs[1].imshow(composite)
axs[1].set_title('RGB composite')
fig.tight_layout()
plt.show()
 
Thanks! Lemme try this!
 
the missing part was "shape (nx, ny, 1) for broadcasting", that's why you got an error with the original version
 
I'm unfamiliar with this syntax red[..., 0]. That's just the same as red[:,:,0]?
 
yup
Ellipsis in a numpy array will always fill in the appropriate amount of colons in the given position.
 
Ahh, so it just fills whatever, except for the last 0. So red[...,0,0] is identical (but a silly way I guess to write) red[:,0,0]
Thanks - learned something new besides getting help! 2 for the price of one
 
9:07 PM
Indeed. It also works for zero colons. It's "I don't care how many dimensions there are". It's especially useful for code that broadcasts over an arbitrary number of dimensions.
 
Yeah! It works perfectly. Thanks a ton!
Made my day
 
 
2 hours later…
11:21 PM
@0x263A Bela with an all-star cast, including Molly, Sierra, Billy, and Bryan Sutton & Michael Cleveland. youtu.be/qY3qnEqi7q8
Hot off the press: Golden Highway with White Freightliner
 
stackoverflow.com/questions/70538524/… I just canonicalized the dupe here, but I'm not sure it's quite the same question being asked.
I think OP is expecting the recursive call to act like a "goto" back to the beginning.
 

« first day (4318 days earlier)      last day (615 days later) »