« first day (2831 days earlier)      last day (2103 days later) » 

 
3 hours later…
4:43 AM
Good morning!
 
 
3 hours later…
7:36 AM
cbg
 
cbg
 
Good day :)
 
8:01 AM
@AndrejKesely Doing timee = ("%s" % some_string) does exactly the same thing as timee = some_string, except that the former is more complicated & less efficient.
Also, there's no need to parse a time or date string manually when the datetime module functions can do it for you. And in this case it's particularly pointless since the OP has needlessly converted a time into a string; the best approach is to eliminate the time -> string -> time round trip. (In case anyone's wondering what I'm talking about, these comments are in reference to this question)
 
8:19 AM
@PM2Ring Yes, I know...probably I should edited my answer. I wanted to make the OP's code to work in minimum changes
 
8:34 AM
@AndrejKesely Fair enough. But IMHO when OPs do dumb stuff like that it's a good idea to educate them, even if it's not the main point of their question.
 
Is there SO chat application for Android? The official app is just redirecting me to mobile HTML version.
@PM2Ring And I should learn to edit my messages :) (I know it's hard to acknowledge not all my solutions are best in the world :D
 
@AndrejKesely I just use the mobile site in the browser on my Android phone. I've heard that there is an Android app for chat, but at last report it's not any better than the mobile site. IIRC, Andras Deak has used it.
 
8:59 AM
I'm trying to find a SO or SE Meta question regarding the posting of unattributed 3rd-party code. Specifically, the OP has posted some code they didn't write, and there's no author or other source information for the code, or anything to indicate that they have permission to post that code. I want to tell the OP "Please don't do that, and here's a link explaining why".
I can find plenty of info about not using code from SO without attribution, but not the other way around.
 
 
2 hours later…
10:37 AM
what does x = y = [] mean?
 
@MNSH It creates an empty list and binds it to the names x and y.
x = y = []
x.append('MNSH')
print(x, y)
#output
['MNSH'] ['MNSH']
 
Thanks; thought it made separate lists so i had an infinite loop on a site
 
If you want 2 empty lists you can do: x, y = [], []
 
@PM2Ring I vaguely remember one post where the problem was sidestepped by saying "stackoverflow is not liable for the code you upload to it."
 
10:53 AM
@Arne Oh, ok. I ended up posting this comment.
But I wonder what would happen if someone did post a bunch of closed-source code on SO... I guess it would just get deleted.
 
@PM2Ring The post that spawned the discussion was actually some professor complaining that his students were posting his lesson-code to SO.
He wanted it deleted, I don't remember if it actually was
 
@Arne That rings a bell. But IIRC, copyright wasn't an issue to the professor, he was concerned about students using SO to cheat on their homework. But I guess copyright issues may have been mentioned as part of the discussion, so I'll try & track down that question.
I think this is the question you were talking about: meta.stackoverflow.com/questions/295420/…
 
11:16 AM
Yes, that's the one
Fair use makes the problem really easy for SO, the only thing that's left as a comment would then be 'how to be a developer with good ethics'.
 
11:46 AM
The best I've found is What should I do when I see copyright violations posted on Stack Overflow?. However, I don't want to accuse the OP of intentionally violating copyright, and I already told him that he might be doing that.
My primary intention is let him know that it's bad etiquette to post code that isn't yours without some form of attribution. But I guess I've already done that. And it's not like the code he's posted is some heavily-protected critical code from a closed-source project. :)
 
 
1 hour later…
1:14 PM
 
@RobertGrant Ok, but that question's 4 years old.
 
All the more egregious that OP couldn't edit in clarifying information, even with 1,000+ days at their disposal ;-)
 
From here: « since you are using python 2.x, you have to encode it with utf-8 as follows u'\u2014'.encode('utf-8').decode('utf-8').replace("-","") » :facepalm:
 
DSM
Okay, "insanitizing" is clever. Don't know how welcoming, but definitely accurate.
 
That question bugged me but I didn't give OP any guff because it reminded me of an actual problem I had a couple weeks ago, which was: how can I tell ahead of time whether a unicode character has a single-glyph representation in the font my shell is using, or whether it will be displayed as an escape sequence? I never did find that out.
 
DSM
1:28 PM
Belated cabbage, by the way.
 
There are a number of questions on SO about finding the "width" of a string, but those have more to do with combining characters and zero width joiners, than characters that the environment doesn't know how to print
 
\o thinking it was Wednesday, but it's only Tuesday cbg
 
DSM
You get one more day of free life!
 
what a wholesome way of looking at it. :P To be honest, I'm just looking forward to Aug 9th.
 
What happens on Aug 9th?
 
1:38 PM
Monster Hunter Worlds comes to PC :D
I get to go hunting for monsters and be sad when the game forces me to slay younglings
Also, TIL that when you close a question with more than one "off-topic" it lists them, I thought it only picked the most popular vote (for close).
 
@PM2Ring Ah! no, i'm not sure, i've just read that in a couple of SO problems dealing w/ python looking at wave-as-array files (that is, javascript definitely uses floating point arrays, and i've only read that others do too, but have never experienced it)
 
Javascript's only numeric type is float, so it may be an outlier in this circumstance
 
@Kevin Oh, I agree that Unicode can be tricky. And confusing when you don't really know much about it. I was hoping the OP would clarify why he wants to get rid of non-ASCII Unicode (or at least Unicode that can't be encoded to the code page he's using), but I guess he's stuck in XY problem land. But I'm more annoyed with the answerer, whose Unicode knowledge is only marginally better than the OP's, incorrectly describing the problem, and posting useless code.
 
Yeah.
 
1:57 PM
@PM2Ring nope, just new mobile view in browser
 
@AndrasDeak Ah, ok.
 
cbg all
 
cbg
 
Have I missed something or has there been a major regression with the latest pytest and astroid?
 
Oh boy, I love working with OAuth2. Took me 4 hours to figure out that the error message "The authorization code provided is invalid" actually means "You have to pass a value for the state parameter if you want our server to return something useful".
 
2:12 PM
@Kevin In some context, string width can refer to its size in pixels if rendered in the current font. In PostScript, stringwidth returns the (x, y) change in the current point that would occur. Normally, the y value is 0, but it can be non-zero with some Asian fonts. And I guess maybe if you're rendering letters with accents with the accent as a separate character.
 
E1101: Module 'tensorflow' has no 'reshape' member (no-member) this seems like an almost unshakable false-positive
how do I get pylint to not complain at all about a single line?
 
PIL has a textsize method. If the problem ever comes up again, I should play around with it.
 
Ugh can do ` # pylint: disable=no-member` but already have a mypy # type: ignore on the same line, don't think I can do both
 
wim
still without accepted answer, since 2013 ...
 
2:20 PM
@Aran-Fey It's a rule in crypto that you don't leak details about how a login failed.
 
@wim curses maybe?
 
wim
that's what a comment said too, but nobody provided a curses answer
 
I haven't touched it in ages
sorry :(
I want to know the answer too
 
@PM2Ring That's reasonable, but if your server has non-standard requirements (like a non-empty state field), that becomes a bit of a problem...
 
wim
and every time I've started to implement something in curses I've realised why it's named that way. ("f*$k this s@!t") ...it's like writing C in python
 
2:24 PM
@wim Find out the terminal's font & do the calculation in PostScript. :D But on a more serious note, the PIL textsize function should do the trick. FWIW, a lot of typography / 2D graphics interfaces closely follow the PostScript model, so once you know PostScript it's generally pretty easy to learn a new one.
 
while total != (total := total + term):
    term *= mx2 / (i*(i+1))
    i += 2
return total
seriously, who can read this thsi?
btw, this would have undefined behaviour in C...
it is that bad :F
 
wim
did you see assignment expressions in the wild already?
why people contort themselves to avoid while True: / if something: break
simple, readable, best!
 
@wim not yet apparently.
so now, people can write garbage that would be undefined in C, in Python and it has "defined" semantics that no one can really tell :D
anyway, I am going to do self-qa on assignment expressions
 
@AnttiHaapala To be fair wasn't this one of hettinger's examples as an argument against assignment expressions? I know I've seen that before somewhere
cbg all
 
2:42 PM
> No command 'pyhton' found, did you mean:
I didn't think someone would actually ask a question with this error...
 
I guess the answer would be alias pyhton="python"
 
3:08 PM
How do I keep a console window open after my python program terminates to see any errors produced? is a curious question, because in my experience Python has never closed a console window it didn't open itself, and I'm hard-pressed to think of any program that closes the console window you run it in.
Not counting spectacular failures such as segfaults, since you'd at least get an error box.
 
@PM2Ring is that a thing?
 
Kevin, I'm going to guess they are running a script - they see the window opened by python & just want it to remain open after - as they probably aren't sure about handling logs with python as an alternative
 
@RobertGrant I don't normally bother closing questions that are that old if they aren't actually dangerous, eg there are answers containing bad / misleading info. Or the question is badly off-topic and we don't want to leave it around as an example of something that's a permissible question. But I guess the question you linked kind of falls into that category.
 
I'm pretty sure this is not the well-tread problem of the user double-clicking on the .py file, and seeing the console window appear and then disappear, since the OP explicitly says he's typing the file name in
 
I googled a specific error message and got that, which just seems like noise!
 
3:15 PM
@RobertGrant Oh, ok. If Google thinks that question's a useful search result, then that's a good reason to kill it.
 
Hey guys can I ask some tips? When do you decide to create a new .py file to organize your code? How do you segregate the code?
 
I make a new file when my current file is too big. I put one class in each file.
 
So 1 class for each file
 
I try to put one idea in each file -- I work with a lot of APIs so I'll often have a client.py, a models.py, a translator.py...
 
Even a class with 5 lines?
Right I guess that can work as well
Sorry one last noob question. How do I call code from another .py file?
I just recently switched to python
 
3:23 PM
@MarcSantos meet import :)
 
Oh right same as modules thanks
 
sP_
Low priority! Naming paralysis victim.
I have an api that takes data and name of analysis algorithm. What's a good name for such api? is this okay? www.blah.com/api/run or ..is there some general term for these?
 
get classy and thru a greek name in there with it or nordic god name :)
 
@sP_ that sounds simple and usable, but I'm no api naming guru
 
I've run into a mypy issue where I have tests passing in 3.5 but not 3.6 due to PEP 0526 python.org/dev/peps/pep-0526. Specifically in 3.5 I don't have an easy way of introducing a variable type definition into an __init__ without actually creating a variable. In python 3.6 I'd annotate the instance variable but how can I work around that not being supported in 3.5?
 
sP_
3:39 PM
@MoxieBall I'll go with this for now then, will change if required before production!
 
rb folks
 
new question, new tag for PEP 572 :p
hmm
can I undelete a question that I have deleted?
 
4:00 PM
Yes, you can
 
so perhaps I should delete that q as I am repcapped already :D
 
@shuttle87 Why are you annotating a variable that you don't define anyway?
 
Interface in a base class
 
Hmm. Maybe you could define it as an abstract property?
class Interface(abc.ABC):
    @property
    @abc.abstractmethod
    def foo(self) -> int:
        pass
 
oh interesting
I just shifted to the older type annotation comments, probably will have to put the newer style back in when we drop 3.5 support lol
 
4:16 PM
I'm puzzled by the behaviour in overexchange's last question. \b is defined as a \w \W transition or vice versa, so why does the pattern stop matching when it encounters a \W char that's not followed by a \w char?
>>> import re
>>> pat = re.compile(r'\b\S+\b')
>>> pat.search(' a(1,0)z ')
<_sre.SRE_Match object; span=(1, 8), match='a(1,0)z'>
>>> pat.search(' a(1,0) ')
<_sre.SRE_Match object; span=(1, 6), match='a(1,0'>
 
@MoxieBall lol thanks :D
 
that question/answer pair is one of those things where you can really only hope nobody ever does it, but someone is inevitably going to
 
@MoxieBall did you find any more than these 3?
that's why I wrote it beforehand :D
 
@PM2Ring: 0 is a word character.
 
i'm getting an error that seems related to distutils . . . it seems to be an old error that a lot of people have encountered . . . but i'm not sure how to fix it in my particular case . . . anyone care to help?
TypeError: dist must be a Distribution instance
 
4:33 PM
@user2357112 Sure. But the non-space portion of the string contains a few word/nonword and nonword/word transitions but it's only the final nonword char that's not followed by a word char that gets dropped.
 
\S+ is always greedy
 
So the pattern says: "Look for a start-word boundary, keep matching non-space chars unless you get to a nonword char that's not eventually followed by a word char before you get to the end of the non-spaces". Is that right?
 
my issue isn't getting any attention in this chat, which is sort of a bummer, so i felt resigned to post a question. here it is if anyone becomes interested at some point:
0
Q: TypeError: dist must be a Distribution instance

dblissThis is an error that many people have encountered, in many different contexts. I've found several discussions of this error online, but they all seem to be rooted in the particular context in which the error occurred. I think a general-purpose solution to this error is needed. The error seems...

 
Yeah it can be a bit of a crapshoot getting advice in chat pertaining to third party libraries, or even standard libraries that are less well-tread
 
i thought distutils and setuptools were pretty fundamental
 
@davidism: if they start with '/dir/basename' then matches = glob.glob(item + '.*'); if len(matches) == 1: return os.path.splitext(matches[0])[1] might have been the answer. But the question was too garbled to make much sense of it.
e.g. a question about how to find if there exists a file with that prefix and if so, get the extension given that there would only be one match.
 
Or more succinctly: "Look for a start-word boundary, keep matching non-space chars until there are no more word chars"
 
@MartijnPieters based on their last comment, I think it's actually a duplicate of "how to serve static files in Flask".
 
Yeah, which would explain why they added a flask tag to the post.
 
I hammer at least one of those a day, along with "are global variables thread safe in Flask". ;_;
 
4:53 PM
@dbliss you still need to have a [mcve] in your question.
 
@Martijn Do you any advice regarding this? The OP has posted some code they didn't write, and there's no author information for the code, or anything to indicate that they have permission to post that code. I want to tell the OP "Please don't do that, and here's a link explaining why". I ended up posting this comment.
 
Apparently this occurs because setuptools monkeypatches the distutils
 
@PM2Ring: The \S+ matches non-space characters greedily, then backs off one character at a time in backtracking until the \b matches.
 
@AnttiHaapala i'll work on getting a minimum example (i'm assuming that's what mcve stands for)
 
wow 3.4k and not knowing what a MCVE is :D
 
4:55 PM
@AnttiHaapala yes I think that's what causes that
 
It matches everything up to the space, then \b fails to match, so it backs off one character, and \b matches between the 0 and the ).
 
@user2357112 Ah, that makes sense. I guess it has to do that, but I didn't realise that a simple \b can invoke backtracking. Thanks.
 
... so if the setuptools is monkeypatched while the distutils is doing its magic...
 
any Distribution that was created before setuptools was run cannot possibly be a subclass of the setuptools.something.Distribution...
 
4:57 PM
@PM2Ring not much more than that comment that you can do.
 
@shuttle87 there are many issues on github related to this error . . . you found one of them
 
@MartijnPieters Ok. Thanks.
 
@AnttiHaapala you seem to be very close to fully understanding this
 
it may be that the current copyright owner decides it needs taken down, at which point they can file a DMCA request, but moderators can't do anything here.
 
4:58 PM
@dbliss I might be if I had that mcve :P
 
:D
gimme a sec
 
but not tonight :D
thou
 
I've run into this before but it was a long time ago, iirc this bugs.python.org/issue23102 was my issue
 
all i can say so far is that the particular arguments used in the call to setup within numpy.distutils.core seem to matter
 
I seem to remember it being a race condition
though the packages I depend now don't use distutils directly so I haven't had to think about this in a long time
 
5:11 PM
@shuttle87 it's very possible that i just have a weird combination of versions of numpy, distutils, and maybe some other stuff
 
Does everything resolve if you install everything with setuptools?
 
i'm not trying to install anything
deliberately
i'm doing a bifurcation analysis in pydstool
the comment above the line in pydstool that throws the error is:
# Use distutils to perform the compilation of the selected files
 
oh I see, well I very deliberately try to install everything via pip to avoid these types of isses
 
i just don't see how that applies to my situation
wait, unless you mean that i should uninstall something and reinstall it with pip
 
if all the packages are already installed then you won't have to install via whatever mismatched thing goes on in this
 
5:21 PM
Hey, that's me. I can confirm it is a ghastly existence.
 
Another poor dev stuck writing new software for Python 2. :( stackoverflow.com/questions/51386698/deploy-python-apps
 
Broken Window Theory predicts that simply skipping over lower quality questions will cause lower quality questions to increase in number disproportionately
 
i legit can't believe i was just banned from this room
 
You weren't. You were kicked for 1 minute because you were starting a pretty standard and annoying rant.
 
5:27 PM
Hmm, What is the purpose of the Modules/clinic directory in the Python source? Does "clinic" imply that the code is somehow... Diagnostic? In need of further development?
 
DSM
Wasn't "Argument Clinic" a thing once?
 
@Kevin BWT is an interesting concept but almost definitely awful as a policing mindset (for actual police, maybe not on SO)
 
Trying to figure out if _tkinter.c.h has any actual impact on the tkinter module.
 
Can anyone please help me with paramiko multi-threading: dpaste.com/2FE87AC
 
annyway, my problem has myteriously disappeared
 
5:29 PM
Working with BeautifulSoup. I've got some HTML being returned by an API and I'd like to parse it, although the HTML is in a String in some JSON, so it's escaped. How can I remove all the \n and `` escaped characters the right way. I'm thinking there must be some built in BS way?
 
It has a declaration _tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold);, which may be a hint towards What is the n parameter of tkinter.mainloop function?
 
Currently it is creating new thread for each device in devices.txt and I would like it to limit like 10 threads at a time etc
I tried using this but couldn't figure it out:
sema = threading.Semaphore(value=maxthreads)
 
@dbliss if you reinstalled with pip there's nothing mysterious about it
 
i didn't reinstall anything
 
5:31 PM
@TristanWiley Not sure why it would matter if it's escaped. It's json, so use a json parser to parse it. If it's still "escaped" after that, then something's wrong.
 
Ah, I was close. Should have looked one directory up.
 
Jesus I'm an idiot
I was trying it out in the Python console and I forgot to actually parse the JSON. So I was just throwing the entire JSON object into BS and being like, hey, this is HTML
 
aight i'm tripping right now . . . just ran the script, no error . . . closed python and ran the script again . . . same error is back
 
Cat pic for you
 
the only thing i'd done is open the relevant module in pydstool and add a pdb breakpoint . . .
(which was never encountered, for some reason)
 
5:35 PM
@dbliss like i said before it's a race condition
 
i see, yeah
 
and different behavior comes up depending on how you import because the setuptools monkeypatch is saved off __main__ iirc
 
well, i suppose i need to figure out what pydstool is trying to install
 
Well yes and open an issue with them because they have a broken system if this comes up
 
to pre-install the thing pydstool is trying to install was your advice earlier, right?
 
5:36 PM
Just make sure that whatever is expected in site-packages is already there if this type of thing is going on
 
is it guaranteed that an installation is being attempted?
and i'm confused about how you know where to place the blame
like, which package is the one that is "broken"
 
almost surely PyDStool
seeing as it's the thing installing the packages using disutils
 
eh, it's calling numpy.distutils
 
any pandas wizards here?
 
i'm also not sure why you're 100% convinced that any of this code is trying to install a package
 
5:45 PM
interesting that it goes about it like this, honestly if I were writing this myself I'd not do it this way
 
@shuttle87 i'm with you at that line of code, but that call to setup is to numpy.distutils.setup
numpy.distutils.core.setup
 
Well there's the root of the issue
 
meaning that function is the root of the issue? i guess so . . . i still have no idea what package any of this code would be attempting to install.
 
Can anyone please help me with paramiko multi-threading: dpaste.com/2FE87AC
 
it's also not clear to me that the problem isn't in setuptools
 
5:48 PM
It constructs a bunch of C code in a string then compiles that into a package. That C code is the package
 
ok, well i don't see how i could possibly pre-install that using pip . . .
maybe the problem is in the imports at the top of numpy.distutils.core?
if you look there, there's a conditional that seems weird to me
it might even be designed to deal with this issue.
but be failing for me for some unknown reason
 
Well I don't have any interest in debugging this library, I wish you luck with solving this
rbrb all
 
@Stacksofoverflow ask your question, if someone can help then they will.
 
how often is a repr method used in code outside of debugging/testing?
 
ok, cool . . . earlier you said the bug was in pydstool, now it seems it's in numpy . . . so i'm still not sure which package you think needs debugging . . . but it's fine, thanks for your help to this point
 
5:53 PM
@Ffisegydd got it. More looking to see if someone is down to have a PM with me to teach me a bit of pandas
 
If you'd like to ask about tutoring then best to be up front and ask for it, though honestly I think you'll struggle to find anyone.
 
@CBredlow Never. It's not good for anything besides debugging.
 
ok that's fair!
 
i'm getting an error that involves a call on a particular line of code . . . just above this line i have a print statement . . . but the print statement isn't completing -- nothing is printed to the screen . . . how can this be?
 
Magic.
 
5:56 PM
Stack Overflow doesn't have private messaging, anyway
And if you're thinking "Ok, but if I set up a room between myself and the other guy, who is going to bother to read our transcript?", the answer is me. Love those juicy details.
 
@Kevin, a lot of juicy details in my question: dpaste.com/2FE87AC
:)
 
@dbliss Try sticking a sys.stdout.flush() right after, that helps sometimes
 
yeah I meant private room type of deal
 
Those are only private in the sense that most people will be too disinterested to spy on you
 
fine with me
wrong word choice
to throw it out there
I have two dataframes
one has a users previously watched content + the language it's in
 
6:01 PM
I tend to belabor this point when it comes up, because I don't want anyone accidentally divulging their credit card info or mother's maiden name or whatever when they think it's safe but really it isn't
 
@Kevin
yeah I didn't think of it like that
 
@Kevin thanks
 
the other has some output predictions
 
Not that giving your mother's maiden name to only one Internet stranger is much better than giving it to an unlimited number, I guess
 
well I guess you reduce the probability of theft a little in absolute terms
 
6:03 PM
Sure
 
I want to only keep the rows in the prediction dataframe for each user where the content matches a language they have previously viewed in
trying to avoid a for loop over all user ids
 
Sounds like you want a LEFT OUTER join
 
@Ffisegydd ok thanks I've been experimenting with merge/joining
the thing is the index is non unique
for each UID in the user col a user can have many recommendations
anyway I don't think that matters
I'll try it out
Sample of data:
CID ReleaseDate Genre Language UID rank
79595 7184 2015-02-14 Thriller Tamil 5546 553
110689 8055 2010-09-06 Romance Tamil 5546 989
392102 7164 2011-08-12 Action Telugu 5546 843
394746 7377 2012-08-19 Romance Telugu 5546 289
397378 7458 2012-02-16 Romance Telugu 5546 749
that's the prediction
CID Language UID
0 8782 Tamil 15372552
1 8782 Tamil 9617542
2 8782 Tamil 15474316
3 8782 Tamil 12858630
4 8782 Tamil 16799928
that's the file that has previously watched
 
6:26 PM
@CBredlow If you print a list (or other container), or convert it to a string, each items' __repr__ method is called to convert it to a string. Of course, programs designed to be used by non-programmers don't display a raw list to the user, but tools designed to be used by programmers may do that.
 
Anyone with experience in Python selenium
 
okay, I've recently tried changing the repr method in a public library to something that makes a bit more sense and kinda got shot down since it could 'potentially break someone's code'
 
Try as I might to install chromedriver on this new Mac I'm working with, it's still acting like it's not in my path
Despite both downloading and copying to global /usr/local/bin
and using homebrew
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see sites.google.com/a/chromium.org/chromedriver/home
 
That makes sense (about repr changes potentially breaking code)
 
6:49 PM
cbg
 
7:10 PM
@CBredlow What Fizzy said. Maybe you could give that class a __format__ method, if it doesn't already have one.
 
wim
@Aran-Fey hmm, it used in logging
if you log a list or something you gonna get the reprs
 
logging counts as debugging in my book
 
The Python docs mention that you can reconstruct an object a lot of the time by doing eval(repr(obj)) on it, and while it in no way condones this behavior, it sure has seeded the idea in a lot of readers' minds
Keep your __repr__s eval-able for the sake of people that don't know better
 
def __repr__(self):
    return 'os.remove(inspect.getfile(inspect.currentframe()))'
that oughta teach people not to eval their reprs
 
DSM
7:23 PM
That's really no more dangerous than running the program itself, though.
 
I'm more likely to just paste the repr into my source, or the REPL, rather than to pass it to eval.
 
@DSM lettuce
 
Python: you're doomed no matter what â„¢
3
 
@excaza No, that just encourages sloppy typing. This is how you discourage it: alias pyhton='rm *.py' :evil grin:
 
:D
 
7:31 PM
Pyhton exists, and operates near-identically to Python, except it reverses the outcome of conditionals 0.1% of the time
 
sP_
Hi people, I have a django app that does a time consuming task for every request. I can do 2 tasks at a time. How do I handle multiple incoming requests when both gpus are already occupied?
 
Maybe look at a messaging queue?
 
i saw that as massaging queue and that sounded relaxing
 
sP_
I'll have to look up what a messaging queue is. I'm not new to programming but I'm just stupid :(
 
0
Q: Filter Model Prediction DataFrame

Stacks of overflowI have two dataframes: lang_df = pd.DataFrame(data = {'Content ID': [1, 1, 2, 2, 3, 3], 'User ID': [10, 11, 10, 11, 10, 11], 'Language': ['A', 'A', 'B', 'B', 'C', 'C']}) pred_df = pd.DataFrame(data = {'Content ID': [4, 7, 14, 6, 6,...

 
wim
7:42 PM
If you've had to debug code where some clueless developer has "helpfully" overridden the repr and it made their random class looks indistinguishable from a string in logging .. then you will understand the eval/repr thing
 
posted question here for any pandas wizards
feedback on question structure etc. welcome
 
wim
@Aran-Fey ???
logging.debug is for debugging. logging.info tells you what a program is doing. logging.warning etc is crucial for monitoring.
 
@Stacksofoverflow if you check out the room rules, you're not supposed to link questions in this room until > 48 hours
 
wim
when you pip install and you see some lines printed to the terminal about what packages were downloaded and what's installing, that's logging.
 
Sorry. I'll read the room rules before posting again.
 
7:45 PM
...and you used repr there?
 
@Stacksofoverflow what would be more helpful for me would be to have the expected outcome come from your for loop method. Where has 'Content ID' == 8 come from?
 
Eh, it's got a foot in the gray area because we were talking about the problem before he decided to make it into a proper post
 
users are being recommended content they haven't seen before
 
Oh I didn't realize that, my mistake
 
will fix that error sorry
 
7:46 PM
... and you've just had exactly the same question as a comment now
 
Either way, you should tag questions instead of just , more likely to be seen
 
wim
@Aran-Fey well, pip doesn't, but yeah I do
if you ever log a dict or a list or any object like that you're gonna see reprs
some goes for print, really
 
@wim Like this?:
class Spam:
    def __init__(self, x):
        self.x = x
    def __repr__(self): return '"spam"'

print({Spam(u) for u in range(4)})
#output
{"spam", "spam", "spam", "spam"}
 
wim
yes, exactly like that
TL;DR don't override __repr__
you almost always want __str__ or __format__
 
@sP_ You can read about the concept here: docs.python.org/3/library/queue.html#module-queue
 
7:53 PM
I'm curious about what's happening with this question. Is anyone beavering away at an answer for this? 9 upvotes on the question and only my upvote on one of the answers (which is faster). Or are the upvotes for a refreshingly-researched question and not real interest in making it faster? :)
 
@user3483203 Also, it's fine to ask meta questions about a fresh question in here, that is, asking if it conforms to SO standards, and how to make it more answerable. We just don't want people to answer the fresh question in here.
 
@PM2Ring yeah I don't post often... trying to improve/post quality when I do. I guess the solution is simple I just wasn't seeing it.
 
is there a way to reverse this generator that preserves the filler?
from itertools import zip_longest

n = 6
a = zip_longest(range(0, n+1, 2), range(1, n+1, 2), fillvalue=0)

print([thing for thing in a])
if I just swap the range parameters it doesn't fill the initial tuple
Forward
[(0, 1), (2, 3), (4, 5), (6, 0)]

"Backward":
[(0, 6), (5, 4), (3, 2), (1, 0)]
 
What do mean by "Doesn't fill the initial tuple?"
 
It starts with (6, 5)
 
8:02 PM
by "swap the range parameters" do you mean a,b->b,a or reversed(a), reversed(b)?
 
Does reversed exist in 3.x?
regardless, the former
 
@excaza Of course, but you can't use it on generators, only on finite sequences.
 
>>> a = zip_longest(range(1, n+1, 2), range(0, n+1, 2), fillvalue=0)
>>> print([thing for thing in a])
[(1, 0), (3, 2), (5, 4), (0, 6)]
 
poorly posed question :)
 
Maybe I'm not understanding you
 
8:04 PM
I provided the desired output
 
BTW, [*a] or list(a) are more efficient than [thing for thing in a]
 
noted, I have some logic for the comprehension that I took out
but thank you, I didn't know that
 
wim
you can't reverse a generator
 
is there a way to get the reverse of this generator*
 
wim
may as well do [tup[::-1] for tup in list(a)[::-1]]
or do it smarter with the range in the first place
 
8:12 PM
"smarter" being...what?
rbrb, time to make a mad dash to my car in the break of this torrential downpour
 
This is ugly, but it gives the desired output:
n = 6
m = n + 1
print([*zip(*[map(m.__rmod__, range(m, -1, -1))] * 2)])
#output
[(0, 6), (5, 4), (3, 2), (1, 0)]
 
Cbg
 
8:28 PM
But I think this is closer to what you really want. And it's more efficient.
from itertools import chain
def pairs(n):
    rng = range(n, -1, -1)
    it = iter(rng) if n % 2 else chain([0], rng)
    yield from zip(it, it)

for n in range(4, 8):
    print(n, [*pairs(n)])
# output
4 [(0, 4), (3, 2), (1, 0)]
5 [(5, 4), (3, 2), (1, 0)]
6 [(0, 6), (5, 4), (3, 2), (1, 0)]
7 [(7, 6), (5, 4), (3, 2), (1, 0)]
That can be written as a one-liner, but I wouldn't advise it.
a = zip(*[n%2 and iter(range(n, -1, -1)) or chain([0], range(n, -1, -1))]*2)
 
 
3 hours later…
11:31 PM
Admittedly the wording of the latter assumes you know the right (Pythonic) solution before you ask the question... so we'll need lots of close-as-dupes to make it findable via search for all use cases.
 

« first day (2831 days earlier)      last day (2103 days later) »