« first day (2446 days earlier)      last day (2495 days later) » 

2:00 PM
But not sure if there is another datetime module imported in scope
 
read again what Paul asked
 
I mean, enter those two imports at the Python interpreter, then type dt is datetime. Do you get True or False?
 
"What does `dt is datetime` tell you?"
 
Is this question out of academic curiosity, or is there a reason one might want two module objects that are not referentially equal?
 
Gives back 'True'
 
2:01 PM
@Kevin : There is an implementation where I saw they are using it on Redis.
import redis
import redis as originalRedis
 
"original-anything" sounds monkeypatch-ish
 
`class Redis(redis.Redis):
 
you'd only want to do that if you're mutating your original...yeah
 
implementation goes on
 
Hmm not enough context to determine why the author wants to do that
 
2:03 PM
I think I'll put a question out there.
 
I had a feeling you'd appreciate my Zed Shaw reference @WayneWerner :p
 
there should be a point where redis.something gets mutated/rebound
@d-coder about what?
 
Do they end up updating the entry for 'redis' in __builtins__?
 
the specific application in the redis thingy?
 
@Carpetsmoker very much :D
 
2:04 PM
Can we have two imports of same module which are independent ?
 
Define "independent"
 
Generally, no, unless some nefariosity is employed.
You can import the module multiple times, but it is the same module.
 
two imports with different references
 
I think we have already established this
Well, @Anarach did - @d-coder, did you read/follow the previous comments?
 
Could hardly let the opportunity go by really
 
2:08 PM
I did.
But I think datetime was wrong example.
 
DSM
Morning cabbage for all.
 
cbg
 
cbg @DSM
 
I skimmed through the importlib module to see if there was a way to get independent references to the same module, but the most likely candidates, import_module and reload, just hand you the old reference. So I'm going to go ahead and say it's impossible.
 
DSM
I'm not an enormous fan of Python's import system. I would have liked to be able to import different versions of modules simultaneously and control what other modules they see.
 
2:11 PM
Well yes, if your question was about redis, you probably should have used redis as your example.
 
and see what black magic redis does
 
@Kevin - in the past, I have had reload give me new module bits.
 
I expect that reload can give you a new reference, but it didn't when I tried it on the math module. So my guess is that it doesn't bother recompiling or anything if it knows that no changes have been made to the module and/or the module is a precompiled standard library thing
 
>>> import rеdis
>>> import redis as Redis
>>> rеdis is Redis
False
I don't actually have redis, I used hand-crafted py files
hint:
>>> rеdis.__name__ == Redis.__name__
False
 
Wow!
 
2:15 PM
>>> import redis as RRR
>>> redis is RRR
True
 
to d-coder: my above lines are irrelevant to your question, I'm just playing around
 
I hear you.
 
This is actual redis import
 
I was going to say "Why would you ever need independent references anyway? That would only be useful if you were mutating the module and why would you ever want to do that" but then I remembered that the built-in decimal module exposes a bunch of global mutable state via getcontext
 
@Kevin - this blog post describes my reload experience back in Py2.6 days, I've not revisited it in Py3 world. thingspython.wordpress.com/2010/09/27/…
 
2:17 PM
rhubarb until later
 
So here in this code they have tried to customize the redis implementation
 
>>> __builtins__.__import__ = lambda *args: object()
>>> import math as a
>>> import math as b
>>> a is b
False
 
Oh man the spoiler page needs code markdown :S
that wasn't really obvious to me
 
It has code markdown but you can't use it from the spoiler button user script
Also you have to have at least one line of plaintext
 
2:40 PM
cbg friends
 
I need help with the English language. I can’t think of the correct preposition (?) I need…
 
we shall try to help you, sir.
Ask your question
 
I have a method IsValid that checks whether an expiration date is in the past. For testability reasons, the method takes a relativeDate that is used instead of a static “Now”.
How to document that parameter? I have “Relative date the evaluation is made [derp]” <- what to put in there?
“to”?
 
hmm, well "Relative date the evaluation is made" does not seem right either
what are you trying to explain. Maybe we can help with re-phrasing it.
 
My initial instinct is "in comparison to"
 
2:43 PM
I want to explain that the evaluation is made in regards to that date instead of the current date
 
DSM
I was going to say "with respect to".
 
I assume that it's intentional that the whole sentence is a sentence fragment, as is customary in documentation that describes the purpose of a variable
 
@DSM That works for me!
 
with respect to is a good go-to.
 
Thanks all :)
 
2:44 PM
cheers :)
 
poke: Always having the hardest programming problems…
 
documentation is the hardest programming problem.
I guarantee we all have taken longer thinking of a good method name, than the algorithm for that method.
Almost all the time
 
Truth
 
the worst is when after a few iterations of your overall application you realize that you actually end up refactoring that method out, because you adapted your code to a point where it actually isn't needed.
 
lol
 
2:46 PM
when you completely remove your state management system and have to re-write everything
 
LOL
haha
 
I'm using the requests library to POST to a webserver. When I look at the request in Fiddler, the request had a content-length of 1176 and received a 500 Server error. If I change the content-length to 1220, the server accepts it just fine. The length of the characters in the body is 1776 and not 1220. Any idea why the server is possibly accepting a content-length of 1220 and not 1776 with the same data? Could its backend expect padding or something?
 
do you have access to this webserver?
 
No
I'm just emulating how it's used via a web interface
 
Did you verify that you are using the API properly?
 
2:49 PM
The website's or Python's requests API?
 
the webserver you are communicating with. You are interacting with an API. Are you sending the correct payload per the documentation of that API
 
No documentation on it :(
 
Webservers can return 500 for pretty much any reason. They're tyrannical.
 
Not intended to be used outside of the web interface I guess
 
What did you add/remove between those requests to have that particular content-length then?
 
2:50 PM
I didn't add anything
I just changed the content-length value
Everything else is the same
 
Alright...then you are clearly doing something the webserver was not prepared to handle and does not want to handle most likely deliberately
chances are if you are not allowed to do this, the server code might have been friendlier in sending you a 400-type error instead
 
The web request is the exact same one that gets sent when I use the web interface
 
Does the server tell you anything else than “500”?
 
(other than the content-length)
Nothing other than "500 - Internal server error" "There is a problem with the resource you are looking for, and it cannot be displayed"
 
There is most likely a message in the error log of the webserver that will give more details about this 500 internal error.
 
2:54 PM
he doesn't have access to it.
 
DSM
Is 1220 the smallest value > 1776 for which it works?
 
why not then use the content length value that does actually work?
 
1221 works as well
 
@idjaw Using a content length value that does not match the actual content length seems very wrong to me.
 
I want to understand why I need to change the content-length in the first place
 
2:55 PM
Regardless of whether the server accepts it or not…
 
^^ what @poke said
 
DSM
@Drew: 1221 is greater than 1220. Is 1220 the smallest such value?
 
@poke You are right. yes.
 
Oh
sec
 
Try 1777 first
Maybe it needs a null byte
 
DSM
2:55 PM
@poke: don't steal my theories!
 
Also, if 1220 and 1221 work, you might want to look at what your content looks like when cut to 1220 or 1221 bytes
 
would something like wireshark here help to analyze all this?
if it is not sent over https
you can look at things easily
Also. Using postman here might help to really play around with the request and analyze all this stuff too
inspecting in something like chrome and looking at the network activity might give you some info as well. There are options to further analyze things.
 
Oh, my bad -- 1176, not 1776
 
– that makes more sense
 
DSM
Does 1177 work, then?
 
2:59 PM
out of context, this seems like a confusing history discussion
 
@idjaw If it is, use Fiddler and inject root certificate
 
DSM
I think the spec says that if you put content-length != message it either truncates or null-pads. So if the API needs a null byte at message end and you're not giving one, giving a longer-than-correct content-length will fix the problem, albeit accidentally.
 
@poke That's assuming that this web server is something you have control over no? If you are communicating with some third party closed off web server, you won't be able to do that.
 
Upon further inspection it looks like there's more to it. I thought that I was setting content-length, but Fiddler was going ahead and setting it behind me, which makes more sense. It was just a coincidence that I was trying to set it to the same value Fiddler did.
So this looks like it may be an issue with the requests library
Not sure why it's detecting content-length as 1176 instead of 1220
 
@idjaw No, you just need to trust the certificate on your client computer to allow Fiddler to effectively perform a MITM attack
 
3:01 PM
The character count is 1176
 
DSM
@idjaw: I tried to make a "maybe the server is a fan of Henry III and not a fan of the American revolution" joke earlier but thought better of it.
 
But it seems the actual size of the message is 1220
 
DSM
Character count or byte count?
 
1176 characters, 1220 bytes
 
Is this a better solution than to write this:

s = 'this is a test\n' \
'second line in the test'

s = s.replace(' ', '|').replace('\n', '|').replace('o', '_')

it doesn't seem appropriate to write a lot of "replace" one after another
 
3:02 PM
@DSM - need to work in 1066 and 1588
 
@poke OH! right right...
 
(@idjaw I successfully used Fiddler to reverse engineer HTTPS APIs used by Android apps in the past, so it works pretty well for that ;) )
 
@DSM FWIW I would have appreciated that.
@poke who sly dog you. :P
 
Not my fault when people don’t document (private *cough*) APIs properly!
 
>>> s = 'this is a test\n' \
... 'second line in the test'
>>>
>>> import functools
>>> functools.reduce(lambda s, args: s.replace(*args), ((' ', '|'), ('\n', '|'), ('o', '_')), s)
'this|is|a|test|sec_nd|line|in|the|test'
Eh, not much of an improvement
 
3:05 PM
wtf
 
You can use translate if all of the targets and replacements are one character long
>>> s = 'this is a test\n' \
... 'second line in the test'
>>>
>>> s.translate(str.maketrans(" \no", "||_"))
'this|is|a|test|sec_nd|line|in|the|test'
Although this has slightly different behavior from your original code. "a".replace("a", "b").replace("b", "c") gives a different result than "a".translate(str.maketrans("ab", "bc")) Because the replacements are simultaneous, not sequential
 
Once I encoded the string body to bytes with unicode_escape it changed to the correct length
So issue solved
Thanks for the help
 
Today I am annoyed by questions whose code contains a try-except that silently ignores errors, and the OP is completely baffled about a mysterious silent error they're getting and they can't think of any way to get additional diagnostic information
I put on these sunglasses and now it's too dark, please advise.
 
3:21 PM
1. locate power button
2. press until state changes
 
The average IDE is better at writing good code than the average SO user.
 
@Kevin Doctor! Every time I drink coffee my eye hurts!
 
Remove the straw from the cup.
 
Replicated problem with coffee. Straw is to blame for eye pain
Can confirm
 
3:44 PM
Does anyone have some resource for me on how to efficiently recognize a rectangle in an image? Without using crazy libraries, just using a 2d pixel array. The rectangle only has a fixed 10px border with a solid color that I can safely use for recognition.
My idea was to scan the image for pixels with that color, skipping the border width to recognize potential candidates
But that gives me just a list with possible pixels that could be part of the border. Now I need something to cluster this
 
I feel like this might be Kevin's thing
 
My naive idea would be to walk to the top left from any pixel I found; this would give me the top left corner of the rectangle and allow me to collapse all the duplicate points
 
DSM
Flood fill + rectangle check the results?
 
points = []
for x in range(0, width, BORDER_WIDTH):
    for y in range(0, height, BORDER_WIDTH):
        if c[x][y] == COLOR:
            points.append((x, y))

collapsed = set()
for x, y in points:
    while c[x - 1][y] == COLOR:
        x -= 1
    while c[x][y - 1] == COLOR:
        y -= 1
    while c[x - 1][y] == COLOR:
        x -= 1
    collapsed.add((x, y))
Something like that was my idea
 
If the box is one known exact color, and no other pixel has that color, then I would collect all the pixels of that color into a set and get the bounding box by running min and max on the x and y coordinates of the pixels
 
3:49 PM
I cannot be certain that nothing else has the color
 
This exact problem was a whiteboard interview question at Amazon
I thought I got it right, then later realized a flaw in my algorithm. I know how to do it now
 
I’m listening! :D
 
These were irregular blobs too, so your rectangle finder could make use of shortcuts likeyou said
 
Flood fill may indeed be useful for separating candidates into individual features. Then you can iterate through them and choose the one that's most rectangley. But if the rectangle overlaps with an object of the same color, you're in trouble.
 
Walk each cell of each row, keeping a list of sets of previously-seen blobs.
For each cell, write a little function to return its neighbors. If any neighbor is in a previous blob, add the cell to that blob.
 
3:54 PM
@Kevin Good point, but I have means to avoid that overlapping from happening.
 
My flaw was that I forgot to look for cells that would bridge 2 previous blobs. When this is detected, you have to merge the blobs.
 
With cell you mean every pixel in my case, right?
 
yup
 
But determining which object is most rectangley is the problem you came in here with, effectively
 
Well, I can guarantee that the rectangle I’m looking for is in the image, it’s not overlapping with another element that has the same color, and it’s an exact and correct rectangle.
 
3:55 PM
can the rectangle have a rotation?
 
No, it will be properly aligned
on full pixels and all
 
I was assuming it was axis aligned from the start because the alternative is truly unpleasant
 
I think your earlier idea of looking for the top-left corner is good. For one thing, you'll only look at the top height-rect_height rows, and width-rect_width cols
 
For some context: I’m rendering the rectangle on the screen in one step, and then, in another step, I take a screenshot and have to find it.
I cannot tell before what size the rectangle will be, but the border width is fixed, so I can use that to skip pixels.
 
Hmm, I'm gonna see if I can write a little demo.
 
4:01 PM
That would be very nice
 
how about something like this to measure how much of the border is axis-aligned?
def rectangularity(shape):
    left = min(point[0] for point in shape)
    right = max(point[0] for point in shape)
    top = min(point[1] for point in shape)
    bottom = max(point[1] for point in shape)

    result = sum(((x, top) in shape) for x in range(left, right))
    result += sum(((x, bottom) in shape) for x in range(left, right))
    result += sum(((left, y) in shape) for y in range(top, bottom))
    result += sum(((right, y) in shape) for y in range(top, bottom))
    return result/(2*(right-left)+2*(bottom-top))
 
wim
Hi all, is there any RFC that says something about whether you can/should/shouldn't send query paramaters in a POST request
 
takes a set of point tuples as input, e.g. {(0, 0), (1, 0)}
 
@wim Query parameters are part of the URI. The spec about HTTP methods does not care about what URI you use
Heading home quickly, will be back in a bit
 
4:17 PM
RIP, too late to fix my off-by-one errors in that code
 
cababbages
 
cababbages to you too
 
Are you using a caBabbage Engine?
 
I went to google Babbage's to see if they still existed, and holy crap, they turned into GameStop!? en.wikipedia.org/wiki/GameStop
 
Ok, here is my slapdash effort.
I tested it on this image:
On my machine it properly identifies that there are three red features, one of which is a rectangle with border width 5.
 
4:24 PM
What if there a circle entirely inside or outside of the rectangle?
 
If they're not touching, then they are identified as separate features. If they are touching, they are identified as one feature. But the rectangle-circle feature may still be classified as a rectangle as long as the circle is fully within the boundaries of the rectangle.
I suppose I made is_rectangle overpermissive in that case. I could change it so it verifies that the interior of the feature contains no non-rectangle lines, but it didn't seem that important
 
4:52 PM
wow. I was surprised to see after taking a timeit analysis between a non-regex vs regex solution, the non-regex solution was significantly faster
I did not expect that much of a difference.
 
5:03 PM
@idjaw could I see the regex?
 
@Rawing here
 
cbg
@Kevin I approve of that example image.
@Kevin Is each feature basically a set of all pixels with the same color?
 
That is a lot slower than I expected it to be.
 
yup
 
@poke Yeah.
 
5:09 PM
surprisingly slower
 
Hmm, I wonder how that approach compares to what I tried, given that I can skip a lot of information from the beginning
 
It's O(number of pixels in image) to identify the features, but the rectangle detector has some desirable fail-fast behavior if you pass it something with rounded edges
 
5:24 PM
recbg
 
5:38 PM
@poke define "crazy libraries" ;)
 
I'm gonna take a stab and say... OpenCV.
Not all shopping carts require rocket engines.
 
Anything really :P I’m actually building this in either C#, C or Rust and want as little dependencies as possible. And I certainly don’ need a crazy image recognition library for a simple perfect rectangle ^^
 
ah I see
too bad; scipy.ndimage works like a charm
 
More important than any cpython PR, @Kevin just got something merged into sopython.
 
\o/
 
5:50 PM
Of course that means I have to find time to deploy sopython again.
 
his tentacles reach ever more corners of the internet
 
gross
 
Should probably take some time to remove the PyCon notice kind of on time this year.
 
I, in turn, should try to update the spoiler button userscript so it can do multiline text too. Not that I have any clue how I would accomplish that.
Listen for ctrl-enter button presses and swap out the input field for a text area perhaps
 
5:53 PM
I can't even write a spoiler manually :|
 
Oh also the script stopped working entirely recently. I forgot about that.
Probably because we're https now
Yep, that's why. fixed
 
Now I only need to come to terms with the fact that there are 3 buttons now...
 
Using the `requests` library, I can send a request like so:

```
session = requests.Session()
session.post(postUrl, ..., verify=false)#no verification since Fiddler open
```

and the result shows up in Fiddler just fine, but if I first prepare the request, e.g.

```
session = requests.Session()
request = requests.Request("POST", postUrl, ...)
prepared = session.prepare_request(request)
session.send(prepared, verify=false)
```

The request doesn't show up in Fiddler. I've confirmed the request actually went through with Python -- it's just not showing up in Fiddler. I don't have any filters/
 
Maybe the session is being lazy and says it sent the request but in reality it hasn't done so and won't until you try to inspect the results
 
the session returns a response code, so I don't think the issue is it not being sent
 
6:04 PM
What a flagrant violation of the principle of least astonishment
 
It's not terribly likely since laziness isn't a great idea when you're deferring a slow I/O operation, but who ever said programmers were sane
Maybe the request is being sent over a port that isn't HTTP or HTTPS.
My third and favorite guess is, it's Fiddler's fault.
 
Yam my reading comprehension is dead.
 
user6845426
cbg guys
 
6:23 PM
cbg
 
user6845426
Hows it going o/
 
Fine, thanks. How about you?
 
user6845426
All good, started my first grad job the other day so all is good
 
what's a grad job?
 
user6845426
my first job after graduating :)
 
6:29 PM
ahhh, I see!
awesome :)
 
user6845426
Well technically I still havn't graduated yet but...
 
close enough ;)
 
user6845426
In my mind University is long long gone! lol
 
user6845426
They've got me doing some crappy task though
 
DSM
Welcome to entry-level employment!
 
6:31 PM
hehe:)
does anybody (wink wink @DSM) know whether it's normal that a certain new numpy function doesn't have online docs? I can find the new heaviside and the old isnan but not the new isnat with the same url syntax
 
user6845426
Im just happy to be earning some money :) Can't complain (2 much)
 
I already opened a doc-related issue today and was a bit nosy afterwards, so I don't want to open a new issue unless I'm sure it's not supposed to behave like this
OK, I'll just open an issue, see what happens
 
DSM
@AndrasDeak: I had to open a ticket once about some functions not making it into the documentation, so I can believe it.
 
thanks
posted, let's hope I don't get smitten
> Fixed in #9253
smitten it is :D
Ah, tricky. There was a PR implementing this in the docs, but no issue (which I searched for)
 
7:17 PM
cbg
 
cbg
 
How is your part of the world today?
 
hot :S
like, wiener dogs turning full hotdog
33 degrees celsius... same tomorrow, except a few additional thunderstorms
how about yours?
 
It cannot seem to decide whether to rain or not. I was out walking the river and storm clouds would blow past and then lots of sunshine then more clouds.
Got a few drops of rain, but most of the storm passed to the north.
Helps keep it at a moderate temperature at least.
 
In the past week we've had bursts of thunderstorms, which didn't cool the air/surroundings even a bit :/
it's magic
 
7:26 PM
personally, I enjoy the hot weather. I'd much rather wear shorts and tshirt than have to bundle up.
 
user6845426
33 degrees nice
 
no, the opposite of nice :P
 
re-cbg
 
recbg
 
recbg
@AndrasDeak sounds perfect to me
but then anything below 70 F is cold
 
7:30 PM
currently 13 celsius and raining
we had a cold snap for some reason. Mother nature is angry about something
technically right now our average temperature should be in the 20s
 
I'd love that
 
ugh and just looked at the rest of the week and it is supposed to rain all week.
well this is good for all the yard work I did yesterday. So at least that....
 
I find it strange that Celsius is measured to the nearest degree even though 1 C is almost 2 F (9/5 F to be exact). Would make sense to measure to the nearest tenth C.
 
it is
 
you know what's strange?
you wanna know what's really strange? Fahrenheit.
 
7:32 PM
well, depends on context
 
Godzilla?
 
Benedict Cucumberbatch
 
that's strange....you know what else? miles
and gallons
 
And ounces. All of them.
 
come at me America
 
7:33 PM
Canada challenges South Canada.
 
Yes, our Imperial system that we tend to hang on to is very strange.
 
that's right....we aren't America's hat....America is Canada's pants.
 
In second grade I was supposed to memorize how many feet are in a mile but I didn't do my homework that night and now I still don't know what it is
 
I've studied enough physics and chemistry that I am very comfortable with using the metric system for calculations. I still have to convert for everyday sort of measurements, though.
I use feet and miles, and I only have it memorized to 1 sig fig.
when the exact value has 4 digits.
 
Not as though metric would be any better though because I can't remember how many millimeters are in a meter.
 
7:35 PM
yeah, those factors of 10 can be really confusing
 
@Kevin you don't have to remember that specifically. All the information you need is in the prefix "milli".
 
So, a million?
 
That would actually make some sense. But it's a thousand. Since it is based on Latin, not English.
 
you only need to know milli-micro-nano-pico-femto-atto-yocto and kilo-mega-giga-tera-peta-zetta-exa-yocta (?) for metric
all of those are factors of 10^(+-)3
 
you forgot terra
 
7:36 PM
that!
thanks
 
what kind of computer nerd are you if you forget terra...
 
the moment when regular IT context lets you remember the prefix of 10^12
 
Andras is a physicist in a programmer costume
he can get away with these blunders
 
that ^
 
my experience with computers helps me remember the prefixes for positive powers of 10.
 
7:38 PM
"Get out of nerd jail free" card
3
 
So I sent a resume to a recruiter and got a call back. He couldn't pronounce half the technologies on the job announcement ;-(
 
lol
recruiters ask me for word document versions so they can avoid that :P
 
that doesn't help during a conversation on the phone, though
 
"We're looking for programmers proficient in C Hashtag"
 
In this case, he had to spell "G-I-T"
 

« first day (2446 days earlier)      last day (2495 days later) »