« first day (2751 days earlier)      last day (2195 days later) » 

1:41 AM
oof
 
 
3 hours later…
4:14 AM
Cbg
 
 
4 hours later…
cbg
 
Cabbage
 
8:46 AM
I'm tempted to post a question about eval and exec... I'm really curious, but on the other hand, who cares about eval and exec?
 
@Aran-Fey Antti wrote an excellent answer on that stuff... give me half a minute.
311
Q: What's the difference between eval, exec, and compile in Python?

andrewdotnichI've been looking at dynamic evaluation of Python code, and come across the eval() and compile() functions, and the exec statement. Can someone please explain the difference between eval and exec, and how the different modes of compile() fit in?

 
Oh wow, that's a lot of text
I think that doesn't address the question I want to ask. I'm curious how they interact with __future__ imports.
 
9:04 AM
@Aran-Fey Hmmm. Antti does discuss the differences between Python 2 & 3 exec, but there isn't anything in __future__ about it, from what I can see. You can see for yourself:
import __future__; help(__future__)
 
As far as I can tell, it's not really documented if __future__ imports apply to code executed by eval and exec, or if performing a __future__ import with exec has an effect on anything
 
Ah, right. I thought you were wondering if you could enable the Python 3 behaviour of exec in Python 2 via __future__
 
Oh, you mean turning the exec statement into a function?
 
Yes
But anyway, it looks like eval respects __future__:
from __future__ import division
print eval('3 / 4')
"if performing a __future__ import with exec has an effect on anything" Good question. __future__ is a bit funny, because it has to be the first import.
 
9:45 AM
If anyone's curious, it's already been answered. My last 3 4 questions were answered quickly enough to make me feel bad about my google-fu.
 
10:15 AM
recbg
@Aran-Fey also
>>> eval(compile('3 / 4', '<string>', 'eval'))
0.75
>>> c = compile('3 / 4', '<string>', 'eval')
>>> 3/4
0
>>> from __future__ import division
>>> eval(c)
0
>>> 3/4
0.75
 
makes sense
 
10:54 AM
@Aran-Fey i.e. compile inherits the flags from the callee
@Aran-Fey this would make sense as a separate question if it is not to be found
you can self-answer it :)
 
jon's answer already explains that though
 
@Aran-Fey hmm, I missed that
been triggered by the recent Slack Overflow blog post :F
 
11:18 AM
cbg all
 
11:32 AM
So I'm just using flask right now along with SQLAlchemy, is declarative_base something that I need to use here?
Specifically is db.Model the same as the declarative_base?
 
 
1 hour later…
 
2 hours later…
2:29 PM
@shuttle87 a) you don't need to use declarative base but it makes some things easier. b) db.Model is declarative_base and then some more
 
 
1 hour later…
3:45 PM
Oh look, it's yet another "how do I group stuff" question that doesn't have a great duplicate... Maybe I'll try to write a canonical after all
 
3:57 PM
@Aran-Fey I guess the OP was happy enough with my link... Maybe. :)
 
I think it's more likely that they're ranting about how elitist StackOverflow is right about now :p
 
ah yes, the good old reddit den of SO hate
 
cbg
 
cbg
 
they think we close questions for points or because we're "on a power trip" smh
I really hope the SO folks will follow up their blog post with something good
 
I find it very unlikely tbh
 
wim
4:57 PM
the comment thread is hilarious
 
I never read comment threads, and reddit is made entirely of comment threads
 
5:15 PM
There is one interesting thing in the blog post though. Did anyone take the implicit bias test?
I'd not seen/heard about it before and it does seem to be US-centric but it was interesting to do
 
wim
I started to take it but it was getting too long and boring so quit ...
Gosh, just lost all confidence in sympy after reading this
Surprised they could screw up something so basic
 
It takes less than 10 mins. I was quite shocked at how difficult I found the task.
Baring in mind that the task is to answer as quickly as possible
 
stackoverflow.com/questions/16474599/else-syntax-error-python another question with a typo and a 2nd syntax error
I'm a janitor today
 
5:31 PM
@wim there was a bug fixed a few months back where 0.1 cos(x)**2 + 0.1 sin(x)**2 wouldn't equal 0.1, or something along those lines
wouldn't watching for x=0 in x/x pop up everywhere when simplifications are used?
 
wim
yes, but it should at least add it to the _assumptions on the result
 
yeah, but my point is that it may cause a mountain's worth of assumptions which is not interesting in all the practically relevant cases :P
I wonder if this is was a conscious choice or it just happened
 
wim
disagree
the division should not be simplified at all unless the "nonzero" assumption is set on the denominator explicitly
 
the answer posted there is interesting; being able to define x/x in two different ways, with one giving you 1 and the other x/x
 
wim
not interesting imo. Only a consequence of the fact that __truediv__ impl is just return Mul(self, Pow(other, S.NegativeOne)) (without the evaluate=False)
 
5:51 PM
Bah, found another python 2 answer of mine. I should go back and eliminate all of these
 
wim
Yeah, I've been doing that too. Either deleting if they have low views/votes, or updating code to Python 3 otherwise.
 
Guys, I am trying to translate some coordinates to a new co-ordinate system with only positive `x` and `y`. Can I do this better?
https://pastebin.com/JJb8Arbs
 
use numpy
 
Hmm....
But not getting answer....and running out of time....
 
That's unfortunate
 
So, what is generally talked about here?
 
This is a Python room. We usually talk about Python (or, at least more often than other rooms do)
 
Yeah.....what specifically about python?
 
6:21 PM
Anything Python-related
 
how often they shed, whether they like to slither up trees, etc.
3
 
@Andras Thanks :) pastebin.com/yBq1DuQN
 
looks much better
but you can even spare separating the arrays
coords = np.array(coords)
mins = coords.min(axis=0)
shift = np.minimum(mins, 0)
coords += shift
something like that ^ (with a bit less lazy naming, of course)
sorry, the singleton injection was wrong in the last step; edited
bah, except you need -= instead of +=, too late to edit
 
okay thanks, so min can give me the minimums along an axis
 
yup, most things in numpy will do that
 
6:36 PM
Is there a canonical duplicate for "My if statement that compares the return value of [raw_]input() to an integer isn't working"? I just saw two of those questions posted within three minutes of each other.
 
I usually use the general How can I read inputs as integers?
 
@vaultah: VTCed, thanks.
 
And if you add tags to those questions, I'll be able to hammer them ;)
 
6:54 PM
I have a B&W image (stored as a boolean two-dimensional numpy array), and I'd like to remove the white/truthy area, but make everything "inside" it white/truthy. Given the image below, I want to get a white smiley on a black background. Is there a nice way to do that using numpy?
I guess that may involve checking neighbourhoods of black/falsy parts somehow
 
7:12 PM
@vaultah yup, hold on
hmm, when I read it in I get aliased values
perhaps that's due to how your image is exported, doesn't matter
 
Yeah, that's not really an image from numpy, sorry. I can convert it though
For an actual MCVE
 
nah, it's fine
I'm trying to use scipy.ndimage.label but it's kicking my butt with that image
if it were specifically about that image, I'd just take invert the image and copy the middle into another all-black image :P
but I keep getting a single feature from ndimage.label which is silly
 
awww
 
wim
@vaultah isn't that just flood fill white from any edge pixel, and then invert the image?
 
7:27 PM
yes
that's what I was trying to do
ooooh yam I know what's the problem
there is only one feature!
@vaultah is this only about that specific image?
hmm, some of the black not connected
bah this is harder than I thought
 
@AndrasDeak no, but other images look the same. There is always a big white area with several black spots/holes
@wim googling that
 
import scipy.ndimage as ndi
img = ((1 - ndi.imread('1iDxQ_vaultah.png', mode='F')) >= 0.5).astype(float) # thresholded float image
label,num_features = ndi.label(img)
for feat in range(1,num_features + 1):
    inds = np.where(label == feat)
    if 0 in inds[0] or img.shape[0]-1 in inds[0] or 0 in inds[1] or img.shape[1]-1 in inds[1]:
        img[inds] = 0
I'm sure the "check if this blob touches the border of the image" check could be made more elegant
np.isin([img.shape[0]-1, img.shape[1]-0], np.transpose(inds)) can check for the upper bounds
whatever I can think of right now is hacky
sorry, I forgot to leave a comment that in the first step I inverted the image
if this is not robust enough for your use case, you can also try not inverting, but adding a small constant to your zero values and work with blobs that are outside the bounding box of the white blob
 
7:57 PM
@AndrasDeak that also worked well on other images. You're awesome, thank you! :)
 
I'm glad it did! No problem :)
 
wim
 
do you have or want a very fluffy dog?
 
It baffles me how often I have to explicitly state that I'm looking for a documented solution and not some kind of "you can do it by accessing this private, undocumented attribute" garbage
 
no no, calling it garbage is offensive
you have to call it recyclable material
@wim may I interest you in a couple of malamutes? youtube.com/watch?v=RqYXM8Xy_to
@Aran-Fey that still needs 3 votes :(
@Aran-Fey I missed that request; why didn't you wait?
 
8:08 PM
I already gave up on it ¯\_(ツ)_/¯
 
it wasn't going anywhere and I could've edited :/
feel free to ping me next time if you see I'm right here
 
I had like half a dozen tabs of duplicates open that I wanted to get rid of. I'm not a patient man
(half a dozen tabs is a lot, okay?)
But sure, I'll ping you next time. Thanks.
 
8:46 PM
cbg
 
cbg
 
Just got done with the semester. Did I miss much? :)
 
nope
 
9:23 PM
@cᴏʟᴅsᴘᴇᴇᴅ just Flask 1.0 (unless you caught that)
 
9:37 PM
@AndrasDeak if any(np.in1d([0,dim-1],ind).any() for dim,ind in zip(img.shape,inds)) \o/ :D
 
hah, Makoto fgitws meta questions
 
9:54 PM
Cabbage. :D
 
10:12 PM
I am still having a web scraping problem.
I am scraping a page with li. I am getting the value with raw_data.li.text. My problem is how can I move on to the next li value. I have seen next_sibling but I don't know how to use it.
 
wim
@AndrasDeak yes!
 
@Simon why not iterate over all the lis with something like find_all and explicitly take the next one?
 
Yeah but then i would need to pass it into BeautifulSoup(newdata, 'html.parser') to parse the value of newdata
 
what do you mean?
 
Wait a minute please, I'll type up an example.
Hmm what I had in mind is generating an error: dpaste.com/0H740QQ TypeError: 'NoneType' object is not callable
Simply print(i.text)
Ah fixed. I don't need to pass it to BeautifulSoup() again.
@AndrasDeak Yes that was it. Thank you.
 
10:33 PM
no problem
you're lucky I played with bs4 a few days ago
 
Laurel. I was lucky indeed.
 
10:47 PM
This puzzle has me stumped: You have to arrange a bunch of numbers in a grid so that each number has the correct amount of neighbors. So for example each number 2 has to have exactly 2 neighbors, each number 3 has to have 3 neighbors, etc. Diagonals don't count. The numbers are 4, 3, 3, 3, 3, 2, 2, 2, 2, 2. I'm starting to think that this isn't actually possible.
Obviously I need a number on each side of the 4. But I don't know where to go from there. The closest I can get is this:
232
343
232
But that leaves me with an extra 2 that I can't fit anywhere
nvm I just solved it by sheer luck ¯\_(ツ)_/¯
 
11:08 PM
@Aran-Fey glad to help
 
Rhubarb all. Back in a few days time.
 
rbrb
 
Thank you once again, and rhubarb (I am really going now). :)
 
@AndrasDeak proving once again that rubber ducking and mindlessly trying different combinations can solve all kinds of problems :D
 
wow, I just got a bronze badge second of all time
it's funny because my tag score was inflated due to my canonical, so I just had to post a few answers (even with 0 score) to get the bronze badge
 
11:14 PM
? A somewhat obscure tag, to be sure. Congratz though.
 
thanks, I wouldn't have it without cheating, so it's not really a proper achievement
 
posting answers isn't cheating
even if the question is your own
 
No, I meant the canonical rep inflation :D
I've been sitting at 18/20 answers for months now, because I didn't want to half-ass answers just to get the badge
 

« first day (2751 days earlier)      last day (2195 days later) »