« first day (2764 days earlier)      last day (2409 days later) » 

00:46
hello yal!
Currently I'm testing out a decorator and it works but dont know why its not asserting my PermissionDenied Exception from django.
00:59
re: WSGI, my Frankenstein monster works. Even though its naive Python <-> Node ABIs its still pretty stable and pretty snappy.
01:55
Is there a repl for python that's easy to use with linux terminal or atom?
02:08
Have you used ipython?
@chrisz oops. I'm thinking of a repl wrong. I'm looking for something that's like nodemon. I want to listen for changes and the rerun my script.
like a watcher that sees a file save and then runs the script
if IPython has a file watcher feature (the two methods of action are very similar if you think about it, only I want mine at the file system level) I'm willing to learn how to use it, but I can't remember it having that feature.
02:27
@DavidKamer what are you trying to do?
You could just use nodemon you know ?
@ShrekOverflow really?
holy crap
it accepts an --exec
is the flag set before or after the file argument?
iirc before
you can also watch dicts, just look at the docs
@ShrekOverflow thanks. Can't believe I didn't realize it was just a glorified file watcher. I'll have to see if it can map python packages, but that's more than I was asking for.
02:47
Hello, I am new to chat. But I am having a PySide issue
1
Q: PySide2 Qt removing an item from a QListWidget -takeItem causing crashes

winteralfsI am trying to remove an item from a QListWidget when that item is highlighted. Whenever I select the item, the item will not be removed if there is only one item in the list. If the list has more then one item, then it seems like the previously added item is removed rather than the one selected....

If you check out the channel rules, you aren't supposed to link to recently asked questions until they are eligible for bounties, so > 48 hours old.
L1=[1,2,3,4]
M apoligies, let me try and delete it
mmm, not sure how to edit the message.
03:04
If anyone's at PyCon, please find me and say hi!
03:17
@DavidKamer you can just watch the entire directory 😛
03:44
L1=[1,2,3,4] , L2=L1, L2.append(5); why is L1 changing
04:14
@AayushGadia please read nedbatchelder.com/text/names.html and let us know if the behaviour is still unclear :)
04:48
trivialish no-effort filtering dupe stackoverflow.com/questions/50285028/…
 
2 hours later…
06:36
@AndrasDeak: Thanks a lot!!! It was very helpful!!!
I'm very glad to hear that :) Mutability is central to python
With really shitty C bindings to interpolate errors and objects b/w python and node
@ShrekOverflow going forward please avoid using expletives
:o
ok, sorry!
I mean naive*
No worries
06:54
hey
how do people in python cope with the fact that it's a dynamic language and sometimes you want to call a static, well defined API?
are there any ways to transform the type annotations in functions to exceptions?
@BartekBanachewicz wow, I am looking for that similar thing in the C Api side
@ShrekOverflow I could do that in the native code, but that sounds like way more work
27
A: How to use Python decorators to check function arguments?

jfsFrom the Decorators for Functions and Methods: def accepts(*types): def check_accepts(f): assert len(types) == f.func_code.co_argcount def new_f(*args, **kwds): for (a, t) in zip(args, types): assert isinstance(a, t), \ "arg ...

is something like this generally frowned upon?
07:09
LGTM but I am not very python savvy
I mean most of the Python's "conventions" are horrible, so I wouldn't be surprised to learn that there's some zealotry around it
38
A: Best way to check function arguments in Python

bruno desthuilliersThe most Pythonic idiom is to clearly document what the function expects and then just try to use whatever gets passed to your function and either let exceptions propagate or just catch attribute errors and raise a TypeError instead. Type-checking should be avoided as much as possible as it goes ...

So naive.
@BartekBanachewicz [citation needed]
@AndrasDeak It's literally one message below.
I meant for 'most of the Python's "conventions" are horrible'
If you hate idiomatic python it's probably not for you
Or your sources suck
QQ to CPython Speakers is there a quick way to get exception.__class__.__name__
from here docs.python.org/2/c-api/exceptions.html I don't see an easy way
07:21
type(exception) instead of __class__ for starters
Oh you mean in the C API
Yes
I can kinda do it the way you suggested the with the ABI but its way too expensive plus I'll have a dangling reference until v8 then cleans it
are you forced to use python 2 by the way?
Nope
But most of my native code so far is for Python 2 so I have decided to add support for Python 3 over the weekend
OK :)
Use 3 whenever you can
At the moment I have some really fragile code like
    if (PyErr_GivenExceptionMatches(py_exception_type, PyExc_IndexError) != 0) {
        js_exception = Exception::RangeError(js_message);
    } else if (PyErr_GivenExceptionMatches(py_exception_type, PyExc_ReferenceError) != 0) {
        js_exception = Exception::ReferenceError(js_message);
    } ... so on ...
07:25
Do these checks have to be in C?
I am trying to move them out of C :D
Naive question
I think it'd be better if I can just get the name of the Exception and then handle it on Node side, for context this is Node <-> C <-> Python all running in the same process
you can get the whole exception msg without dunder methods
07:36
Hello. I need your advice. Is using this: gist.github.com/maguayo/6caa4aa29981769a16f4a674172d0691 a good idea for production?
I don't like that I have to force the timeout on the request
What do you think?
@AndrasDeak I don't have any real "citations", but I think it's pretty petty to make a language that allows everything and then get angry when people use it in a way you don't like
the conventions are supposed to help people write better code, but they're treated as religious rules and not rules-of-thumb which can be overriden and adjusted. I've seen examples of discussion being shut down just because something was "not idiomatic" enough.
@AndrasDeak Then again, it's not my choice here. I don't "hate" Python, I think it's reasonably ok for what it is (i.e. I'm not trying to compare it to real languages ;)), but sometimes you just need to step outside the usual use and it'd really help if the community embraced and supported that instead of handwaving real problems away
For good reasons (i.e. no good idiomatic way) nobody should tell you off for doing something non-idiomatic
but then doing something and posting it to SO are different things
People take hacks in answers and embrace them as Something Good
So there's more pushback on SO because of that
08:15
@AndrasDeak my understanding of 'canonical' is 'used as a primary reference'/'standard', 'archetypal', 'typical', or 'unique distinguished exemplar'. There are many more canonical questions than the short list maintained by this chatroom. As to "Most gold badgers will use what they know or find.", that's disorganized not to add necessary new ones to the canonical list, ...
@smci yes, my point was "meta is irrelevant"
I'm sure adding more well-searchable canonicals to the sopython canon is not an issue
...and especially for a fast-changing package like pandas, to have old obsolete answers floating around without package release numbers (e.g. "for pandas 0.18 do X, for 0.19-0.22 do Y, but be aware in future it'll be deprecated"). The motivating case in point to this was discovering the ongoing breakage from Deprecation of groupby.agg() with a dictionary when renaming....
Look at 5 years of obsolete yet upvoted answers at Naming returned columns in Pandas aggregate function?
Well if meta is a bad place to shop for suggestions or discuss, how do I highlight when a topic needs more canonicals, and also the current most-upvoted answers are obsolete? (in those cases where I may not able to write a canonical answer myself). Posting here in chat doesn't seem to get responses.
sorry, I'm probably missing your point
I thought you were talking about the sopython canon list. If you just want to get people up in arms to gather canonical pandas posts, I guess you could try on meta, I don't know what the response would be. But since there's no "collection of canonical posts" other than ours that I know of, I'm not sure what the outcome of that meta would be. But don't take my skepticism as an objection or anything, this is just my uneducated opinion. You're more than welcome to try handling the situation.
08:43
wow, I just spent 10 minutes looking for nans when it was just that I used hard-wired ylimits in my plot :(
another promising day for science
08:59
cbg
I think I've just seen the most ridiculous question ever concocted by HR ever
They're interviewing for mechanical engineering apprentices and the question got passed to me because none of the engineers could work out whether any applicant had answered the question correctly
"You see this symbol on a Windows task bar. What does it mean?" Then there were 4 choices
invitation to flip table
I hope this was a trick question where the correct answer is "ew, windows"
One was along the lines of reopening a file, another was that there was CD already in the drive
Well, I work predominantly on Windows and there wasn't a hope in hell I could pick an answer from their list
Thankfully the engineers have sense, so every applicant was correct on that :)
.... Export maybe?
09:08
Wasn't an option
What were the other other two options?
it was probably the file reload one
But, I mean, this is for apprentices to come in and fix machines, they probably wouldn't even go on a company computer. I just can't fathom what went through HR's head
What like, reopen recent? Do you even have a program that has an option for that directly in the taskbar instead of a dropdown?
Yeah it's, a really odd question.
@roganjosh "I don't know anything about computers. Oh damn, I wrote on my CV that I'm good with computers. OK, focus, focus! Here's the mouse, here's this picture thingy...hmm, interesting, what does that button do?"
rbrb for a while
09:12
Maybe I misinterpreted the intention. Maybe it was like one of those crazy Google questions like "You find yourself stuck in a salad bowl. How do you get out?". Definitely identifies the people most qualified to come and fix some machines
If that was the case, shouldn't they have advised the interviewers further?
(HR should have, I mean)
I was being facetious. Doing that would require communication between departments; are you insane?
Hahahaha touche
Ugh I just remembered Jetbrains' software is sold on a subscription model. RIP excitement over Humble Bundle.
09:29
Hey guys
I haven't been on in a while
Hi, I'm new 0/
Aha cool!
It's been like a year since I have been on here
I should probably set an image... but, without some kind of copyright breach I'll surely sink 5+ hours into generating a pattern I'm content with xD
Ah, welcome back!
Lol
(I'm not particularly comfortable staring at images of myself, for reasons I've never identified)
09:32
I am trying to make a snake game in TkInter
lol
I keep making it crash tho...
Cool o:
RIP
xD
That's why I came here lol
Ooops
How do I send code blocks again?
I've never used TkInter myself. In general I tend to tinker with a minimal number of libraries in a maximimal number of languages. Mainly because learning new languages entertains me more xD
uh in posts code blocks are any text indented with at least 4 spaces
Lets test this..
def create(self, event):
self.canvas.unbind("<Key>")
self.snake = self.canvas.create_rectangle(0, 0,10,10, fill="yellow")
self.canvas.update()
self.canvas.bind("<Up>", self.move_up)
self.canvas.bind("<Down>", self.move_down)
self.canvas.bind("<Right>", self.move_right)
self.canvas.bind("<Left>", self.move_left)
#self.movement()
while self.stop == False:
    if direction == 'left':
        self.coorsx = -10
        self.coorsy = 0
    elif direction == 'right':
        self.coorsx = 10
        self.coorsy = 0
Oh I did do it right lol
lol
09:34
INDENTATION!!!!!!
Hehe
What's the error message?
(ノಠ益ಠ)ノ彡┻━┻
You get the idea with the function a the top
Yeah so Idk why but that makes it crash...
What do you mean by crash?
I just want it to move after every second...
Err
Is there no error message?
09:36
Like the TkInter window "Stops Responding"
And no, no error message.
Ohhh, it hangs. RIP
Lol
I think I will need to use asyncio
Does it run fine if you only execute the code in the loop once (and remove time.sleep())?
I used Tkinter for all of a day so I'm not really going to be too useful. But it seems that every option for movement would take you to the border of your canvas?
Oh lol
09:39
it's 10x10 and it looks like every key moves you by 10
Doh
If so it could be that the sleep somehow interferes with the way TkInter likes to manage threads, something like the thread never being picked up again, for some magical reason.

Going off the edge of the canvas shouldn't crash, should it?
Actually no, it's a different canvas. I tried; can I get my certificate of participation in a tkinter discussion?
I was thinking of using Asyncio
If it is to do with the sleep, there's probably an alternative in TkInter that roughly calls once every frame, and then you could calculate the movement or next position based on time elapsed.
But yeah, my gut instinct is that something is going weird with the loop/timing.
What's asyncio?
proceeds to google
09:43
Lol
import tkinter as tk

class FirstFrame(tk.Frame):
    def __init__(self, master, **kwargs):
        tk.Frame.__init__(self, master, **kwargs)
        self.pack()
        master.title("Snake")
        master.geometry("1000x600")
        self.canvas = tk.Canvas(master, width=1000, height=600)
        self.canvas.pack()
        self.canvas.focus_set()
        self.canvas.bind("<Key>", self.create, "+")

    def create(self, event):
        self.canvas.unbind("<Key>")
        self.snake = self.canvas.create_rectangle(0, 0,10,10, fill="yellow")
Ah, I see.
That makes a simple moving box
But like... I want to make it repeat until you press the change direction button
Ah. Well, what's in root.mainloop()? Sounds like you could something like a rudementary FSM
i.e.
Honestly........ Idk xD I copied that off someone else
Like the bottom but
bit*
And I have used it ever since
cur_dir = up
def loop_move_thing():
{
up: move_up,
down: move_down,
left: move_left,
right: move_right
}[cur_dir]()

on_keypress_wizardry(keypressed):
cur_dir = {
up_key: up,
down_key: down,
left_key: left,
right_key: right,
a_key: left,
s_key: down,
w_key: up,
d_key: right
}[keypressed]
what happened to my identation..
09:50
lol
Grr xD
You get the idea
Btw, cos I am on school computers so I can't install modules that don't come preinstalled with python
:|
It's probably cleaner to use something /other/ than dicts but, I'm too accustomed to code golf xD
Waiiiiiitttt
wawiiiiittiaiwawit
def movement(self):
if direction == 'left':
    self.coorsx = -1
    self.coorsy = 0
elif direction == 'right':
    self.coorsx = 1
    self.coorsy = 0
elif direction == 'down':
    self.coorsx = 0
    self.coorsy = 1
elif direction == 'up':
    self.coorsx = 0
    self.coorsy = -1
#time.sleep(1)
self.canvas.move(self.snake,self.coorsx,self.coorsy)
That seems to move in one direction.... To the left...
Yeah I do a lot of my coding these days on an AI competition platform so I tend to think mainly in terms of builtins only
09:52
direction = 'left'
Ah fairs
But yeah... It's something to do with the sleep...
And I need it to repeat...
Cabbage
Yeh, so there must be some onframetick() method in TkInter or similar you can supply/overwrite, we'll have to google what it is
Cbbg
Hum...
@PM2Ring are you dissing cabbage.
>>
Did you see what asyncio is?
Cosmo... how new are you...
09:54
cbg PM
I'm new to stack exchange xD
Fairs
Check that web address out :P
I'm a 5th years honours student in Software Engineering with like 10 years hobbiest experience though, so
Welcome back @Jake. If you're going to post more big chunks of code please use an external site like gist, dpaste, pastebin. Etc. Small code blocks (around a dozen lines or so) are ok here, but bigger blocks take up too much space.
Lol I see xD
09:55
Oh sorry!
@Cosmo :slap: for using braces for block structuring. Python doesn't do that! :)
lol
Java
@PM2Ring how on earth are you implying that I did that?
I swear weekday-but-not-friday me hates Friday me. Working with totally illogical data and now I've backed myself into a 7-nested levels hell :/
I used braces for a dictionary.
09:56
@Cosmo No, "cabbage" is a standard greeting around here. See the link in the room rules for details.
@PM2Ring yes Jake corrected me on that, ty.
@Cosmo My deepest apologies! I didn't look closely enough. :( But maybe I can blame that on your total lack of indentation. ;)
That was a copy-paste reformatting issue! (how do I stop pasted whitespaces from getting deleted?)
(Alternatively, how do I block-ident inside the chat text box?)
def movement(self):
    if self.direction == 'left':
        self.coorsx = -1
        self.coorsy = 0
    elif self.direction == 'right':
        self.coorsx = 1
        self.coorsy = 0
    elif self.direction == 'down':
        self.coorsx = 0
        self.coorsy = 1
    elif self.direction == 'up':
        self.coorsx = 0
        self.coorsy = -1
    #time.sleep(1)
    self.canvas.move(self.snake,self.coorsx,self.coorsy)
This seems to work...
But I need to make it loop...
@Jake It's not a Good Idea to use time.sleep in Tkinter (or in GUI frameworks in general). sleep freezes the whole process, so the GUI can't update itself or accept user input while it's asleep.
10:00
Sorry if that's too large
Ahah, I was right!
That's why I suggested Asyncio
Removes blocking
asyncio.sleep
And I will also need it to loop
@Jake That's about the limit.
I still assert that the most idiomatic way to do it for TkInter surely is present /in/ TkInter.
You don't need async or threading here. What you want to do is pretty common in a GUI, and Tkinter has stuff to support it.
10:03
Oh cool
So what do you suggest?
What Cosmo said. Tkinter has a couple of methods that are useful here. The main one in the .after method, which is normally called on the root, but it can also be called on a Widget.
So you do stuff like:
But where would I use that...
As it is "after"...
def move_stuff():
    # Move the stuff
    root.after(50, move_stuff)
34
A: Tkinter understanding mainloop

7studtk.mainloop() blocks. What that means is that execution of your python program halts there. You can see that by writing: while 1: ball.draw() tk.mainloop() print "hello" #NEW CODE time.sleep(0.01) You will never see the output from the print statement. Because there is no l...

Ahhh ok
Coolyo
10:05
Where # Move the stuff has the code to perform your animation actions.
Give me a sec and I'll post links to some of my Tkinter anim stuff.
Ah so after implements a timeout? i.e. .after(waittime, callback)?
is this a bad practice?
def filter_bad_images(path, formats=['jpeg', 'png', 'bmp']):
the editor is yelling at me cause default parameter of formats is mutable :(
@Cosmo Yep. Here's a fairly simple example: a stopwatch that counts in seconds.
1
Q: Tkinter timer to start at 0 on button click

GreenSaberI would like to create a timer that starts at 0 when a user presses a button and stop at whatever time it has displayed when the user presses the button again. So far, all of the questions user after that looks at the current time and updates in seconds from whatever time it is like so: def time...

That's a lot like how I implement drawings in JS then, neat. c:
@Neoares it probably thinks you have this issue. Can't you make it a tuple?
10:10
sure
Oh yeah I've fallen into that trap a few times xD @Neoares
Here's a more complex example. It combines Canvas animation with PhotoImage animation to display orbits. gist.github.com/PM2Ring/d7878c904df8da838f76dc4a15c6c746
I didn't even execute it... I guess it would have worked anyway
but yes I just moved it into an inmutable tuple
I just saved myself hours of filtering by doing this
def filter_bad_images(path, formats=('jpeg', 'png', 'bmp')):
    for filename in os.listdir(path):
        full_path = path + '/' + filename
        if imghdr.what(full_path) not in formats:
            os.remove(full_path)
            print("removed" + full_path)
It runs fine; It's just that if you modify that default object at all, the next call to the method will reflect those modifications, and therefore not really be the initial defaults.
@Cosmo oh, nice
so if I call with modified parameter, and then call again without passing anything, the default will be the same as the last call (which was modified)
10:14
Yeah, defaults are pretty much static/persistent variables visible within your function.
uf, good to know
Indeed
I'm training a sfw/nsfw binary classifier using neural networks
@Neoares There's nothing intrinsically wrong with using a default mutable argument; if there were, then Python would simply forbid it. Sometimes you actually do want what it does. But a lot of new Python coders have been bitten by it, partly because they haven't yet assimilated how Python works, so it has a bad reputation.
had to scrap 240k images from pornhub lol
10:16
@Neoares "scrap" or "scrape" ?
hm...
I did scraping
is that scrap or scrape xD
google said scrape :o
Scrape. For example, "I scraped 400k images from pornhub, but 240k of those were rubbish, so I scrapped them".
I did both then xD
I first scraped the images, then scrapped them with the function I shared before
and 14M images from imagenet... but only downloaded 500k
Bah, I'm going to make myself a profile image. SO. I have this script marcoscosmos.github.io/misc-spiral-fractal which basically implements a fractal by drawing a polygon and then recursively drawing subshapes with the points of the child positioned along the sides of the parent. Any quick ideas on neat patterns I could make out of this to use for my profile? o:
default profile image is a thing here
10:23
The way my day is going, wait for it to line up and printscreen, throw it into paint. Keep it simple :)
Yeh, but I'm not content with my current image, @Neoares xD
haha what's happened to you today, @roganjosh?
Well, the 90 minute drive to work that should be 45 minutes kicked it off nicely
I'm going to have to go back and refactor a huge chunk of my code because I no longer understand what I've created on any kind of level
I work in a factory. We have some monitors that count individual products coming off the machines, and we have a database that has item codes that go out of the door. Apparently, asking how many individual items are required for one unit that goes out of the door is a stupid question.
RIP..
I suppose security is a big deal these days, so they seem to have elected to obfuscate all sense out of their databases :)
10:43
Ah, lol
It's no help that there is no endpoint for the databases, so I get data dumped as CSVs and everything I want to go back into the DB has to be dumped as a CSV for it to consume. The pain is marrying all the data together but thankfully I've just noticed something that I might be able to use as a key to make life happier.
hm... are warnings catched the same way as exceptions?
cause I'm having this: UserWarning: Possibly corrupt EXIF data. Expecting to read 13369344 bytes but only got 0. Skipping tag 5
but except UserWarning does nothing
@Neoares A Warning is a type of Exception. See docs.python.org/3/library/warnings.html
yeah I saw that, that's why I was wondering why it wasn't working for me :(
@Neoares It warned you, that's all it does.
10:52
I know, but I want to catch it
Exceptions will break / halt the program most times
Warnings don't
I still want to catch it
... CSVs as a pseudo endpoint, jeez
maybe it's a pillow warning, I don't know...
10:54
@Neoares I don't think you can do that, unless you escalate the warning into an actual error, which you probably don't want to do. Sorry, I've never needed to deal with warnings, so I don't have an instant solution for you. I suggest you read the docs to learn the proper way of dealing with warnings. You probably need to mess around with warning filters.
@PM2Ring ok...
I want to delete the image that is causing that warning... just in case it gives me errors in the future
@Neoares The answer I linked would likely help with that.
Basically filtering for warnings and then catching them like Exceptions.
@Cosmo It's a bit clunky and old fashioned. But it's robust, readable by humans, and easy to deal with in any language, if somewhat tedious.
@Cosmo makes things interesting :) It's a monolith they've had in place since the 80s. There is optional ODBC support but a) it would cost them money and b) I'm petrified of touching the system because I'm not sure my insurance would cover it if I took the system down
@PM2Ring hm, that's fair
@roganjosh also fair xD
11:00
@AshishNitinPatil oh sorry didn't see it
but figured out exactly the same by googling :P
One potential problem is that because you can load a CSV into a text editor people may be tempted to modify them by hand. This can create a horrible mess if the file's edited improperly. ;)
I'm setting the filter to "error" and then back to "default"
@PM2Ring yeah... xD
11:25
recbg
wb
@AndrasDeak ty
11:30
ty
no problem
11:40
Hello. Can someone explain me the meaning of this: "take the first KEYSIZE worth of bytes, and the second KEYSIZE worth of bytes,"
What is that worth of bytes?
"an amount of bytes that is equal to KEYSIZE"
if KEYSIZE=64, take 64 bytes
It's unclear actually, IMHO. KEYSIZE could be measured in bytes, in which case you take KEYSIZE bytes, or, alternatively, KEYSIZE could be in bits, in which case you take KEYSIZE/8 bytes, etc
KEYSIZE is in bits
okay, then it means take KEYSIZE/8 bytes.
thanks @Cosmo, good point
they probably do mean for "KEYSIZE=64 bits, take 8 bytes"
11:47
@AndrasDeak no worries. I vaguely remember dealing with similar terminology issues when I took a course on encryption a while back.
Thank you all, but it seems I still can not understand. I found that phrase here
it's just a figure of speech in English, if that's what concerns you :)
Another way of thinking of it would be "Read the first KEYSIZE/8 bytes, then the next KEYSIZE/8 bytes, and compute the difference between the values"
you cut out the first two (KEYSIZE/8)-byte chunks from your data, that's it
we won't be able to explain it any better, I'm afraid
I think it makes sens what you said, Cosmo. Thank you a lot
Thank you also Andreas Deak
11:50
You're welcome!
My english is getting awful, I must be tired xD
Do not worry, you can not be worse than me in English
no problem, Billeal Begueradj ;)
Hahaha. English is actually all I know. It's just that when I'm tired I type the wrong words out, like autocomplete on smartphones.

« first day (2764 days earlier)      last day (2409 days later) »