« first day (2776 days earlier)      last day (2397 days later) » 
00:00 - 19:0019:00 - 00:00

wim
wim
00:13
>>> class MyDict(dict):
...     def __getitem__(self, item):
...         if item == 'potato':
...             return 'spud'
...         return super().__getitem__(item)
...
>>> def f():
...     pass
...
...
>>> f.__dict__ = MyDict({'k': 'v'})
>>> f.k
'v'
>>> f.potato
AttributeError: 'function' object has no attribute 'potato'
weird
00:37
Add a breakpoint or a print inside __getitem__; it's never getting called.
The fact that it won't allow you to assign a Mapping that isn't a subclass of dict is a good sign that it's planning to go behind type(__dict__)'s back qt some point.
IIRC, the PyObject_GenericSetDict and friends used by just about every builtin except object all have that requirement, and then, if they don't customize tp_getattro or tp_getattr, the default will go directly into the dict storage instead of using __getitem__. But I'd have to check the source.
Also, from what I remember, a bunch of them document __dict__ separately, and some say writing to it is not supported, others say you can write any mapping object, and others say you can only write a dict, but they all use the same code which only accepts a dict or dict subclass, and ignores __getitem__, anyway.
Greetings! I had partly answered a question about speeding up a code. But, the answer is incomplete. I would be interested to know if you guys have any thoughts on if the following code be sped up using numba: stackoverflow.com/questions/50459216/…
01:22
@konstant I don't think jit will help, because it's already almost entirely numpy. Autoparallelize might, but if the code is as trivially parallelizable as it looks (I only skimmed it, to be honest—that's a lot of code with not a lot explanation), explicitly using a thread pool executor should speed things up exactly as well, with even fewer code changes, and without having to cross your fingers.
So that just leaves completely rewriting things in @stencil terms (to make it parallelizable more cleanly), or using CUDA, neither of which is quite as simple as one line of magic.
But meanwhile, why guess whether numba might be able to do magic, when you can just try it and see?
01:57
Is that the second second parameter of tf.log() to specify the base deprecated?
so if I want log_2(x) I can only do tf.log(x) / tf.log(2)?
@Niing Was the second parameter optionally being the base ever a thing? I didn't think it was.. you have to have a change of base as you show.
I don't know... My book says it has a second parameter to change base...
Python's math.log does this.. but yeah I don't think it is a thing in TensorFlow, or NumPy for that matter. NumPy has the convenience functions log2 and log10 though.
Mind if I ask what book?
wim
wim
@abarnert Yes, that seems correct. Works on pypy, btw.
I asked it on main, if you're interested to see. And already collected 2 downvotes somehow (rolleyes.jpg)
 
2 hours later…
03:51
I don't understand why those kind of questions collect downvotes, they are the most interesting I see here
04:10
cbg
cbg
04:25
cbg
cbgg
cbgs.append(new_cbg)
we need more tensorflow question
tensoverflow
04:44
haha
I want to train a lol player called faker
wait for me
04:59
Morning cbg
05:51
cbg
Seems like Andrew, Fred, Judy, and George are trending. And one of the askers tried to do a shoddy job of covering their tracks.
that confuses me quite a bit
wim
wim
@IljaEverilä ugh.. where is the Andrew, Fred, Judy, and George canonical ..
Time to write one, then. "Andrew, Fred, Judy, and George went to a bar..."
06:24
@piRSquared yes
$ python -m timeit -s "s = 'a.'*100" "s.split('.')[-1]"
200000 loops, best of 5: 1.45 usec per loop
$ python -m timeit -s "s = 'a.'*100" "s.rsplit('.', 1)[-1]"
2000000 loops, best of 5: 199 nsec per loop
cabbage
cabbage
@Arne Interesting. On my old machine (32 bit, single core 2GHz), on Python 2.6.6 the speeds are roughly the same, but on 3.6.0, .rsplit is maybe 10% slower.
06:36
I have to look up my laptop's stats =D But I tested with python3.704b
64bit, 2.5GHz .. with I guess 4 cores
07:15
Hi. Can someone please help me with a regex sub? How can I get it to also escape the underscores using the below code?
import re
def EscapeLatexCharacters(aString: str, aCharacters: str ='_#') -> str:
    new = aString
    for char in aCharacters:
        # match characters which are not already escaped and then escape them
        new = re.sub(r'(?<!\\)([{}])'.format(char), '\\' + char, aString)
    return new

print(EscapeLatexCharacters('he__ll#o_oo\_'))
> he__ll\#o_oo\_
Oh wait I see my code is not working is intended... I want to escape all characters in the list which are not already escaped.
So using the string `'h\#e__ll#o_oo\_'`, I expect the following result: `'h\#e\_\_ll\#o\_oo\_'`
Your loop is assigning to new, but replacing in aString. Throw the loop away and do it all in a single step: return re.sub(r'(?<!\\)([{}])'.format(aCharacters), r'\\\1', aString)
Oh I see, thanks.
I'll make that change and check quickly
What does r'\\\1' do?
Thanks. I still have a lot to learn with regex, but I'm getting there....
Your code seems to be working as expected. Thanks
@smci Well, I've edited to make sure I've addressed most of your points. Unicode, I don't really address, but I do make note of some more stuff under "Other Considerations"
By the way, I tried adding a plot for a memory profile, but %memit seems to give near identical results regardless of the size of the DataFrame being benchmarked. I don't know if that's normal but the graph isn't very meaningful that way
user6276743
07:51
if level == 0:
if output.count(output[0]) != len(output):
print(output)
return
cbg
cabbage Andy
user6276743
The code above works, but this doesn't:
if level == 0 and output.count(output[0]) != len(output):
print(output)
return

Gets a recursion depth exceeded error. Aren't they the same thing though? I feel like I'm missing something really obvious.
user6276743
Separating the and statements and putting them on different lines seem to resolve the issue, but I don't get what's causing the problem.
user6276743
Nice guide, unfortunately can't edit anymore. Anyone know what's causing this trivial problem
@coldspeed o/
@WeavingBird1917 they should give same results, would have to see remaining code to really see what's happening
(if my assumption of the indentations is correct)
Also, blank return statements are not needed, you can skip it altogether.
By default functions would return None
user6276743
Someone else found the problem. It's because of the return statement, yes. It must always return when level == 0, however adding the second part makes it return only when the second condition is true. Thanks for helping.
08:34
Yet another happy recipient of the dupe-hammer:
@PM2Ring Oh yes this worked. Thanks a lot for the help. :) — SilentFlame 1 min ago
08:49
CBG! I have a question. I need to do some process on three queries.
All are independent query and now should I use multi - threading/processing ?
multiprocessing
The queries are irrelevant
It's actually text based query for NLP bot.
thanks
@d-coder you mean independent?!
yes
User says Hi! I want to order blahh... Thank you! I want to tokenize the sentence and run it parallel to my bot
Good idea ?
Any better ideas ?
Not so sure now. Depends on the platform / library you are using, and the support it has for parallel processing.
08:53
I will limit the process number to the number of cores in the machine.
Sometimes customers talk a lot you know :P
If you don't, your machine already does that for you :-p
"Hi! I want to order this from there. The weather is so nice I want to order coke too! Please send it across and.... asap..." -> user input. My poor bot struggles it's way through to figure it out.
@shad0w_wa1k3r I can spawn as many process I want right ?
using multiproc ?
I need to brush up my basics
09:18
@d-coder Yes, you can. But depending on the library / platform you are using, I can't be sure that it'd be handled well.
In principle though, yes, you can / should.
 
2 hours later…
11:21
cbg
Can you please help me in understanding that what happens to the daemon thread if it completed its process but the main program execution is still running.
Does the thread get killed automatically or it will be there in the memory till the main execution gets completed?
@HarshDubey a thread has minimal memory in any case and yes, the resources should be freed when it exits
I accidentally discharged my laptop to 3% a few days ago, and now it depletes from 100% to 75% in 10 hours of suspend :/
if it is a daemon thread you cannot join it, so there is nothing left
a non-daemon thread would keep the return value and such
11:25
Ok so if I never stops the main execution and keeps on creating new daemon threads and these threads are finishing their jobs perfectly, then there is no problem in that right?
And we do not explicitly tell the thread that its job is finished. As soon as the method get over the job is done right??
The method I am talking about is the method assigned to that thread.
Wait, threads have return values?
ofc
@Aran-Fey well, pthreads do
Can you access that with python?
11:39
What do you think the "p" in "pthreads" is for?
posix?
I was trying to hint at "python" but whatever
my sense of humour is too advanced for today's society
or too Primitive
12:09
This might be an interesting puzzle to write some code for: math.stackexchange.com/questions/2792802/…
perhaps there's an easy way to refute it by looking at how many cubes you need to use from the core 2x2x2
but no, you can turn corners in the first iteration into corners in the second iteration
And on the 3rd iteration, those 8 corners are fully red, and can go in the interior.
So I guess it's too easy. Since the face cubies are trivial, and the edge cubies can clearly be painted twice and still have a pair of adjacent white faces.
ah, right, I missed that about edges
12:34
It's a bit harder than i first thought.
Ok. Maybe I misunderstood your question. Are you asking is it always possible to make a 4x4x4 white cube after the second round of painting, no matter how the cubes were re-assembled into a 4x4x4 white cube after the 1st round? — PM 2Ring 8 mins ago
surely not, it's easy to break it, right?
ah, maybe not
I'm not sure.
DSM
DSM
Big-day-cabbage for all!
Greetings, DSM.
cabbage
how big?
DSM
DSM
12:46
10-digit big. Stress headache setting in already but it'll just have to wait. :sweat_smile:
that's a huge number
morning cabbage :)
what can be a simple regex to check if the string is in this format, [0-9[0-9]-[0-9[0-9] basically i want to match cases like 1-20 1-8 (1 or 2 digit numbers separated by -)
@Aran-Fey "adding the self to the widget instances" In that question the OP did ttk.Frame() instead of ttk.Frame(master). I wish Tkinter didn't let you do that, but it does. There's an extra complication because a widget's parent in the object hierarchy doesn't have to be the widget that visually contains it.
I think they're asking if they have to turn the widgets that are local variables into attributes of self
@pythonRcpp \d\d?-\d\d? should do what you want, if I understood correctly
12:59
@Aran-Fey Ok. That would make sense if his GUI class were subclassing a Tkinter widget, or tk.TK(), which is a fairly common style, but he's not doing that.
Hmm? Why does the base class matter? If he wants to access the widgets later, he should turn them into attributes
i did
In [200]: pattern = re.compile("\d\d?-\d\d?")
In [201]: a="11-200"

In [202]: if pattern.match(a):
     ...:     print "hi"
     ...: else:
     ...:     print "bye"
     ...:
hi
3 digit number should not have matched
using python 2.x
Oh, right. Didn't notice the print without parentheses. \d\d?-\d\d?$, then.
13:17
@Aran-Fey Ah, right. I seem to be having problems tonight understanding what OPs' actual questions are. :)
Well it's mostly the OPs' fault, really (:
Of course, he might not have any other methods, in which case using locals for the widgets is fine.
\o cbg
13:36
I don't get this question. I don't use Windows, but surely os.path.exists can handle backslashes in paths, can't it? stackoverflow.com/questions/50489552/…
DSM
DSM
Yep.
I suspect the OP has some weird XY problem that they aren't revealing.
mrng cbg
13:52
morning cabbage
wim
wim
14:50
+71 / −21,346 that's the kind of diff I love to see
It might be a silly question, but what does "vendoring" means?
wim
wim
it means they (boto) have copy-pasted the entire source code of requests (and urllib3) into their source tree, instead of just using one installed in site-packages
So a vendor is when you copy pasted source code?
wim
wim
yes pretty much. so, if you are author of myapp and you have a dependency on requests, instead of import requests you do import myapp._requests.
Why do people do that?
wim
wim
14:55
I don't know. I hate it.
i think the boto codebase is a bit notorious for being bad
Well, it seems to defy the whole purpose of all the neat tools we have to manage version and isntall packages
wim
wim
I guess it means you can have multiple versions of a dep installed for different libraries.
Other languages have that out of the box, but since Python has jacked up packaging and import system, we have to resort to hacks (virtualenv)
I guess that patch makes the graph look a bit better for them
15:24
Cabbage All :P
DSM
DSM
Not being able to install different versions of a package simultaneously is indeed annoying. I don't need it often, but when I do, it's a major headache to work around.
SimpleJson lives up to its name
simplejson.read() returns: "What is json?" (maybe)
OR did you mean it is good?
15:42
he means that its dependency graph is simple
wim
wim
IIRC stdlib json and simplejson is the same thing
Why use simplejson anyway? I thought json could do most (or all) things
wim
wim
to dump and load json serialized data?
I have a horrible feeling that Chris has spotted the actual problem:
…did you do anything else to handle those arguments besides consumer_key = 'ck' etc.? Why do you think assigning the string 'ck' to the variable consumer_key would do anything with command-line arguments? — Chris 1 min ago
wim
wim
it's an example of a project that used to be 3rd party and then got merged to stdlib
the old project just hangs around for people who are on ancient python versions
16:13
simplejson has had a few minor improvements over the years that haven't been merged into stdlib. You don't often need any of them—but if you're porting code from 2.5 to 2.7 or 3.6 that might use those features, even unnecessarily, it's usually simpler to just keep using simplejson than to switch to json and then find and identify any problems.
json tries hard... no need to call him simple!
Also, IIRC, json didn't get the full C accelerator until 3.4 or so, which means if you're on 2.7 or 3.3 (and using CPython), simplejson can be faster.
@piRSquared "Simple Jason" is a cousin of "Daft Willie", the semi-famous mentally retarded victim in the Burke & Hare murders. If Bob Ippolito were from Edinburgh, I might suspect that was an intentional joke, but I think it's just a coincidence. Which makes it funnier when you hear David Tennant talk about Simple Jason.
16:40
Which reminds me, are we going to re-open this, and dupe hammer it? stackoverflow.com/questions/50492454/…
It wouldn't make the greatest signpost of all time, that's for sure
wim
wim
@PM2Ring meh. "how do I use argparse?" RTFM
oh that's weird, it had delete (2) link
and when I clicked for the 3rd delete vote, there was a popup "you can not delete this post" and then the delete link vanished
Yeah. That just happened to me too. Maybe it's because of the 3 reopen votes?
wim
wim
@Aran-Fey dupe that shows optparse? meh.
@abarnert if you want faster , go directly to ujson
17:16
@wim Sure. But if you have 2.5 code using simplejson and port it to 2.7 or 3.3, speed may be a reason to keep using simplejson instead of switching to json (although switching to 3.6 instead of 2.7 or 3.3 is almost always an even better answer…).
Doesn't necessarily mean anything - they could be two students from the same class, with the same assignment
@Aran-Fey In that case, “I created cafe management system…” is a lie designed to pretend it’s not a homework assignment, and to pretend the OP has done some work rather than just copying and pasting his instructor’s work…
17:35
Eh, I don't know. Just because they received a skeleton of the program from their prof doesn't mean it's a lie to say "I implemented something"
I agree, maybe what they meant is that they implemented something that happens to break because of some code that was given to them
Might explain why they are at least asking different questions.
So, I'm working w/ a Docker image that doesn't include pip by default. I've got a requirements.txt file, so of course pip would make installing all of those modules pretty simple
the problem is, pip has a toooon of dependencies
Is there a relatively easy way (obviously it won't be as easy as using pip!) to install the modules in requirements.txt without actually using pip (i.e. - without having to install all of those dependencies)
@AmagicalFishy But pip is now a standard module.
17:50
ah. so if it's a standard module, then all of these things are going to be installed anyway, aren't they?
Indeed
i'm using this dockerfile: hub.docker.com/r/jrottenberg/ffmpeg (because seriously using a python-based image and installing ffmpeg is too horrible)
Sorry, I don't know Docker. I've seen lots of people talking about it in here, but I've never used it myself.
ah, np. i just started using it a couple of days ago
Hi guys, I need a little assistance on this please: dpaste.com/0Z1E297
how do I filter out ports with no serial #
18:05
how are you printing the output now ?
^
why not just loop over lines in the input and check if a port is followed by a part number?
If that is the exact format the file and you know that, then just skip every other line
and forget the regex, just split each line and take the part you know you need
getting a carrot character response from AD is a good feeling :D
CBG
@MooingRawr do you have your game 7 face on? you better
cbg idjaw how fairs it in the land of smoke meat :D
18:07
awesome. I was in your province for the last several days
smoke meat sounds frustrating ;)
road tripping
I want Caps to win the East, I got Vegas winning it all but I want the Caps to win
so remove regex and only capture ports that are followed by a serial #
18:08
@Damon for example, if you read each line as a string
next time you are in town (hopefully for pyCon) we should get dinner/drinks :D (hopefully sir DSM would join us too)
you will have something like:
@roganjosh cbg
'Port                       1'
so if you split it you will end up:
>>> s = 'Port                       1'
>>> d = s.split()
>>> d
['Port', '1']
>>>
If I do print on output, it shows like this:
Port 1
Part Number: 018566771
Port 2
Part Number: 018566771
Let me give it a shot
18:13
@MooingRawr Such a shame the Caps are so close and facing the Vegas anomaly
:O cool!
wim
wim
I've put this in my toolchain and enabled everywhere
'Port', '1', 'Part', 'Number:', '018566771',
Pytests.... something I don't get to play with and have no experience with.
18:15
@Damon Don't know how your file is set up, but there seems to not be a proper line break to separate the port number line and serial line
If they were in fact on separate lines, then reading the file, they would be separated by the newline separator
DSM
DSM
pytest is pretty cool. We use it for all our projects.
@wim
cool
I will hardcode the data in a variable and post ful code
@idjaw I actually dislike when sports people are surprised that Vegas is doing well... What did you think was going to happen when you band a group of above average players together.
DSM
DSM
I thought at best they would be somewhat above average. I never thought they'd be this good.
18:16
@MooingRawr Well, look what happened when the Rangers tried to buy the cup. It blew up. So it's not that far fetched
Chemistry is the key and they clicked and kept it consistent and are now at the end. It's wild
DSM
DSM
I was rooting for the Jets and now I'm rooting for Ovie.
What's really great about the Vegas story is that they are a group of players rejected by their previous team and banded together to show them up, or at least that's a fun way to look at it :D
Buying a cup is different from being able to cherry pick a group of guys who are above average. when you buy a cup like the Rangers did, you cheap out on certain areas, iirc their 3rd and 4th line plus their last pair of d's were weak, not to mention like you said, their chemistry wasn't good enough on their other lines
cabbage
18:18
should be able to copy and test
I also don't feel like it's fair to say the players rejected by their previous team. you can't protect everyone, someone is going to have to be let go
cbg coldspeed
Sure, but they were pretty good players and fine on a business level maybe it made sense to get rid of Fleury
I'm not a fan on how they got to pick a full team from the whole league, it's not like the last expansion only picked half their team and then have to draft or go picking from the farms :\
I see where you're coming from, but let's be honest, no one would have predicted this much success.
No one.
18:20
What's I'm trying to say is they were the 11th (don't quote me on that number) best on the team, if they were protected someone else would have been the 11th and it would have been more or less the same story :(
yes I didn't think they would be this good ... until the season ended or near the end of regular season
my prediction is pretty good, I just lost out on nashville not beating jets :( and leafs not making it to the east final :(
@idjaw can you please look at dpaste.com/3WJASCE
I really want Ovie to win one, he deserves a cup :(
@Damon is your output really within that string? Or is it originally from a file?
it is coming from server I SSH to
OK, but you are reading it from somewhere right?
or did you manually get that data and paste it in to that string so you can run your script against it
18:26
yes, i manually hard coded it for testing
so I am not constantly logging into server
but this is exactly how I get it from server
spacing and format is same
I would like it to only output ports that have sr# but I am lost how
for row in output.splitlines():
    row = row.split()
    if row[0] == 'Port':
        port = row[-1]
    else:
        print('Port {} Part {}'.format(port, row[-1]))
Port 1 Part 018566771
Port 2 Part 018566771
Port 3 Part 018566771
Port 5 Part 018566771
Port 8 Part 018566771
It's kinda hard to tell that it's working properly when all the part numbers are identical. ;)
I don't have access to my usual machine with python so I'm running an online jupyter notebook on my browser and using that to answer questions today :)
yes, when i am sending query to server I am piping for only this sr#
I dont see anything print
took brackets of on print as I am runing 2.7
I modified your output string slightly to get rid of the empty line at the start.
wim
wim
is there a stdlib xml parser that works ok with beautiful soup?
18:33
do u just want a list of port number with serial numbers or do u need the serial number as well ?
@Damon If you want to skip blank lines just put if not row.strip(): continue at the start of the loop.
wim
wim
I don't really want to pull in lxml
just port is enough
since all serial are same
I am getting IndexError: list index out of range
on if row[0] == 'Port':
@Damon That will happen if you try to index into row on an empty line.
Hi, I have the following snippet of code pastebin.com/KS1mv9uz and when I run mypy against it I get this error for the 1st line: "error: Incompatible types in assignment (expression has type "BinaryIO", variable has type "str")" the code is working fine, but not sure what the issue is.
DSM
DSM
18:36
So many ways..
port_list = re.findall(r'Port\s+(\d)\nPart Number:\s+\d+', output)
print port_list
this is my way I guess :\
darn it DSM, Kevin'ding me :(
I think this would be safer in case a server returns nothing
@wim No. The bs4 docs say that lxml-xml is the only XML parser.
@Damon Or, after the row = row.split() line put
if not row:
    continue
@crypticツ sorry bud but I've never worked with mypy before :\
18:37
if you know the format, why not just split and grab the index
got it .. thanks guys :)
@wim no but you can always use regex ;)
I am back on tracks .. I can see the light
For some cases a lenient html parser happens to work for parsing xml. But otherwise, you have to either pull in lxml, or drop bs4 and etree it.
wim
wim
any caveats of just using 'html.parser' ?
etree sucks :(
18:39
one of them adds spurious <html><body>... </body></html> tags to your doc
not sure which, think it's html.parser, you should check
Yes. Lots of valid XML isn’t valid HTML, or even close enough to work with a lenient parser. (For example, almost anything with namespaces.) But you can try it and see what happens.
@wim It's a bit low-level, so it can be somewhat tedious. But of course, that makes it easier to know what you're doing. Disclaimer: I haven't used it since Python 2.4 or 2.5, when it was HTMLParser.
@coldspeed Just throw a deep wildcard or a findall at the top and the extra wrapper nodes don’t matter.
And I only used it on HTML, not XML.
wim
wim
holy cow look at those timings
>>> s = '<?xml version="1.0" encoding="UTF-8"?><LOGIN><RESP><RC>0x0</RC><SID>-1041974086</SID><STATE>0x00000001</STATE><STATENAME>OK</STATENAME><DEFCRED>1</DEFCRED></RESP></LOGIN>'
>>> timeit ET.fromstring(s)
10 µs ± 49 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
>>> timeit bs4.BeautifulSoup(s, 'html.parser')
256 µs ± 13 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
>>> timeit bs4.BeautifulSoup(s, 'lxml')
324 µs ± 16.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
18:43
You can always use… I forget which stdlib module, but the one that feels like JS3 XML parsing. So the retro nostalgia buzz overwhelms the crappiness headache.
wim
wim
maybe I should reconsider etree
Have you tried comparing with lxml.etree? Often doesn’t help much for small docs, but for huge ones it’s usually much faster than stdlib etree.
By the way, definitely don’t use lxml’s HTML mode with XML.
wim
wim
>>> b = s.encode()
>>> timeit lxml.etree.fromstring(b)
6.47 µs ± 36.9 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
faster again
why bs4 can't get that speed when using lxml?
BS4 is a higher level of abstraction than etree; it builds a bunch of wrappers and indexes and things.
I bet you'd get faster parsing if you used regex /s
18:52
That’s why its API is so much nicer to use. So if you’re parsing a huge doc once and searching it a zillion times, bs4 wins; if you’re parsing a bunch of small docs and searching each once, it’s a waste.
(Although for that last use case, you should be etree.iterparsing rather than building a tree at all…)
@OneRaynyDay What do you think html.parser uses? Take a look at the source... Admittedly, it does use a lot of normal str methods too.
I think most of them are recursive descent parsers that use regex as an inline tokenizer.
Not actually regex parsers.
@PM2Ring /s for sarcasm, and I meant without recursive descent, just regex
throwback to the whole cthulu thing
Just train a deep learning network to find your data in the XML docs.
Also, put it in the cloud. That always helps.
And use some XML to parse your XML.
00:00 - 19:0019:00 - 00:00

« first day (2776 days earlier)      last day (2397 days later) »