« first day (2523 days earlier)      last day (2426 days later) » 

4:00 PM
@enderland No, that’s a different behavior
 
anyone knows a library that simply wraps the logging api without all the awful camelCase? most can be avoided by using dictConfig but logging.getLogger() - the one thing that's likely to be used a lot in a bigger application - dumps its ugliness all over the codebase
 
@poke why? I'm missing the obvious thing here
 
if exc_type is true, but self.failure_exception is not, you want e_to_raise to be TimeoutError regardless of self.long_running_exception or self.failure_exception.
 
(I know I could just monkeypatch logging or add a mypkg.log module containing a get_logger function, but i'm curious whether there's already something out there)
 
@poke ahhhh right, I moved all that out a level. gah
 
4:03 PM
hi all!
 
hola! (or as we like to say in room 6, "cabbage!")
 
@ThiefMaster if you're feeling adventurous, there's logbook, but that's not exactly what you asked for.
I'm surprised that forked off into it's own org instead of being part of pocoo/pallets.
 
@Kevin pseudo-bool. It's actually np.bool_ or something, or any bool inside a np array
 
@PaulMcG good Spanish!
 
I can check at home
 
4:07 PM
And I didn't even need Google Translate! (6 years of grade school Spanish, though I've forgotten most of it)
 
I can keep speaking in Spanish if you want then...
 
No no, room rules dictate that English is to be used
 
@ThiefMaster hmm couldn't you make an automatic wrapper :P
 
xD
just kidding
 
SO/SE chat rules, actually
 
4:09 PM
from snakecase import logging
 
DSM
Relatively few of us have second languages in common anyhow, although we have pretty good coverage..
 
anyway, I promise Spanish lessons for some Python help
 
You can thank log4j for all that java-ey stuff in logging - the API just oozes Java
 
@PaulMcG it blows my mind how complicated logging is
 
DSM
@AndrasDeak: in a strange coincidence, last night I was reading about the Aranycsapat! (Not sure if the suffix is right there..)
 
4:10 PM
I'm getting this error but I'm not writing nor reading any file
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
I found this on Stack Overflow: stackoverflow.com/questions/7955138/…
but I cannot understand the solution
I will appreciate any help
 
Hold on, powering up my psychic remote code viewer... nothing.
 
lol... @davidism that's mean
 
Yuk - accepted answer with 2 instances of try:... except: pass
 
that's from interpreter shutdown
it is not really easy to make a mcve for that :D
 
just a minute
a was creating a remote file for the code
 
4:13 PM
but if you can, it would be super.
 
DSM
It's been a really long time since I've seen that error in the wild.
 
it's driving me nuts
 
@DanielGarcíaBaena the file refers to stdout, stderr, stdin probably
 
but I'm not using any of them
it's weird
 
of course you're using them
for prints or something...
 
4:15 PM
Or we can go with your theory, that nothing is going wrong, and the error is lying.
 
let me show you the code
 
and now the close fails, and then another failure is that sys.except_hook is missing, and sys.stderr is cgone.
@DanielGarcíaBaena or... could it be that the code doesn't have stdout, stderr to begin with...
ah no because then nothing would be printed
 
any code sharing tool preferences?
 
something with syntax highlighter :D
 
4:19 PM
so not pastebin
ah it does have too :D
 
Something that does not require me to register
 
@DanielGarcíaBaena no paywall would be nice as well...
@DanielGarcíaBaena no swearing
 
collabedit?
 
just post
 
4:21 PM
OK
 
if less than 5 lines...
 
you've taken more time worrying about this than actually asking relevant parts of your question
 
it's so the garlic can fully mature. :D
 
@poke thanks for the rubberducking btw. I feel kind of embarrassed in hindsight by that...
 
so should I buy iPhone X?
 
4:23 PM
Y? Zzz.
 
bored
 
@corvid go for Nokia 8
 
@davidism as suspected, the MCVE really doesn't make it easier...
 
4:24 PM
I'm not touching that code, for multiple reasons.
 
@DanielGarcíaBaena ok so your next task is removing the code until it stops giving the error, and then undo the last step :D
 
done it! xD
 
No you haven't.
 
I promise
 
then try again
 
4:26 PM
if you remove the inner try, does it still show thta error?
 
there's a lot of stuff there that's superflous
 
So, for example, a loop over web data to create a JSON array is absolutely necessary to this MCVE?
Try again.
 
the for statement is not necessary...
 
And it really requires a stemmer, not just selenium? And it really requires connecting to TOR?
Keep going.
 
I'm definitely not the best Python coder but I cannot understand anyway the error message
 
4:30 PM
@DanielGarcíaBaena as I told you it is probably when the python executable is shutting down, it is destructing objects in wrong order.
and there is something causing that...
 
but there are 5 "somethings" there now, and lots of unrelated stuff.
 
Something buried in one of the very complex libraries you're using. So you have to narrow it down to which one, at which point you can probably report a bug to the relevant library.
 
my guess is that it is just the phantomjs, but it is just a psychic guess. I might be wrong.
I cannot and won't run your code.
 
OK
I'll review everything again and try to refactor it
 
4:35 PM
not refactor..
you're to remove stuff, to produce a mcve.
 
seriously, as others said
is not easy to get mcve with this kind of errors
 
I understand, I'm just pointing you at the resources. Despite its difficulty, we can't do anything else.
 
I know
but I already knew where these resources are
 
I feel like there should be a straightforward solution for this, but I can't think of anything.
I have a list of objects with a duration, which I want to chop into segments of a certain length. For each segment, I want to find the object that overlaps with that segment the most.
Example: input list is [('a',2), ('b',7), ('c',3)], segments should be of length 5
# Visual representation:
input:   aabbbbbbbccc
chopped: aabbb bbbbc cc
winners: b     b     c
output: ['b', 'b', 'c']
any ideas?
 
probably itertools
 
>>> seq = [('a',2), ('b',7), ('c',3)]
>>> s = "".join(c*n for c,n in seq)
>>> s
'aabbbbbbbccc'
>>> chopped = [s[i:i+5] for i in range(0, len(s), 5)]
>>> chopped
['aabbb', 'bbbbc', 'cc']
>>> [max(slice, key=slice.count) for slice in chopped]
['b', 'b', 'c']
 
chain(repeat(k, n) for k, n in data) gets you an iterator over the visual input
 
DSM
How do you want to break ties?
 
4:49 PM
What if my numbers were larger by a factor of 1000? Think [('a',2000), ('b',7000), ('c',3000)]
 
That max call is O(N^2) but NBD if N is always going to be 5
 
@DSM it is :) That's the root of "golden team"
 
@DSM toss a coin, doesn't matter :d
 
@DSM freeze them with liquid nitrogen
or dishonor their families
no one obvious way...
 
Hmm,
>>> [Counter(slice).most_common()[0][0] for slice in chopped]
['b', 'b', 'c']
I wonder if this is any faster.
 
@Rawing I bet there's a nice dynamic programming solution that will get you better-than-O(sum_of_numbers) behavior
You don't need to spend 400 iterations going over 2000 A's to know that the first 400 slices all have a winner of "a"
All you really need to inspect is the borders
 
dynamic programming sounds like overkill tbh
I guess I'll try to finish my headache-inducing implementation with way too many variables and nested loops, but I just can't shake the feeling that there's an easy way to do this...
(easy and more memory efficient than using itertools on a list of tens of thousands of objects)
 
On second thought you don't need recursion, just a loop
Something like pastebin.com/pBqyWWyB
Or possibly exactly like that, if I happened to write a bug-free implementation first try with no testing, against all odds
 
5:13 PM
Informed student that they have a fever, so they have to go home and cannot return tomorrow. Student now googling "how to get fever".
 
Why would the student google that when they already have a fever? Or did they mess up the tense and actually want to know "how did I get a fever" so they can learn what not to do next time?
 
@enderland Sure thing, that’s what I’m here for :P
Sometimes, I would really like to do >_<"
 
I'm always here when someone needs their posts downvoted
 
I think I made this more complicated than it needed to be, in order to handle semi-malformed input like (('a', 2), ('b', 0), ('c', 3))
 
no, can’t have you lose more rep. You need all of it to get the 20k tools.
 
5:20 PM
tell me about it
I'm -> <- this close to the almighty power of protecting questions
soon no unprotected question with deleted low-rep answers will be safe from me
 
@Kevin They want to get more days off? SMH
 
where I'm from the old-school tip is "eat chalk", but I haven't seen anyone who actually tried that
 
When your superior sends you home for being sick, wait until you get home before you start looking up ways to keep being sick
I would have been out the door before the end of the sentence "you have to go home"
 
Students can't just walk off campus, but otherwise, I concur completely.
 
plot twist: register their absence in the log
"Yeah, you can't come as long as you're sick. But it's still absence. We just don't want to catch your germs"
 
5:28 PM
Sounds like a variant on "we don't have sick time, we just have a general leave pool that you can draw from for whatever reason. Yes, this means if you get the flu you won't have enough hours for the summer vacation you've been planning, why do you ask?"
 
@Kevin That gave me some good ideas. I was working with too many indices, popping items from the list like you did is much better. Mutating the input might also come in handy. Thank you!
 
And suddenly attendance skyrockets, and so does the rate of infection, which crashes productivity
 
there was a recent discussion about correlations between frequency of use and and actual quality of stuff
 
cbg all
 
cbg
 
5:39 PM
cbg, you changed your pic
 
weeks ago
and a few times before that ;)
 
even months, probably
 
I've only seem Byte today :(
 
idk
:)
@Kevin @Rawing interesting problem, I came up with a solution using yield. I believe it is quite elegant, but I haven't done much testing yet.
#!/usr/bin/env python3

def chopmax(seq, size):
    rest = {}
    for item, amount in seq:
        while amount:
            if not rest and amount >= size:
                amount -= size
                yield item  # uniform chunk
            else:
                missing = sum(rest.values()) if rest else size
                added = min(amount, missing)
                rest[item] = rest.get(item, 0) + added
                amount -= added
                if added == missing:
                    amount -= missing
Hmm, sorry. That was a premature post. Doesn't quite work yet.
 
the output should be ['b', 'b', 'c'] not ['a', 'b', 'c']. haven't found the bug yet though
 
5:44 PM
For the built-in test case, it should return ["b", "b", "c"] though.
(should means it does that on my machine)
 
ordered dict implementation?
 
why ordered?
 
because it seemed to me that Rawing and you get different results from the same python 3 code
 
@ByteCommander you have ordered dicts, rawing doesn't
 
one reason could be the implicit orderedness of 3.6 dicts; just a long shot
 
5:46 PM
Huh?
 
huh. It gives me abc in python3 and acc in python2
 
I use 3.5
 
then no :D
 
and I get bbc
 
then you have a fluke.
 
5:47 PM
now I'm maximum-confuseld
 
Also dictionary order should not affect it, except on ties maybe
Uh, wat?
 
rest[item] = rest.get(item, 0) + added is a red flag that you should be using collections.Counter anyway
 
heisenbug
 
Now I get random results...
acc or bbc
wtf
 
5:48 PM
The cat is finally dead.
hash randomization too.
 
why though!!??
 
because you opened the box
(you monster!)
 
because your algorithm is bogus
 
I did not mean that...
apparently, but I don't understand the reason yet
 
(though idk why)
 
5:49 PM
there's something wrong with the values you put into the rest dict. the values seem to be the same for all keys
 
Rawing, you got your answer yet ? not clear if you have or haven't
 
nope, no finished code yet.
 
ahhh maybe I might jump on this train :D
 
wim
@ThiefMaster take a look at github.com/cjw296/shoehorn
 
though I haven't tested Kevin's, I continued working on my own implementation with the newfound ideas I got from Kevin's code
 
5:54 PM
and I got a new own idea, but no idea why it doesn't work... xD
 
wim
that will be like:
from shoehorn import get_logger
logger = get_logger(name)
and you get to use structured logging for free with logger.bind(k1='v1', k2='v2')
structlog also is snake_case, I haven't tried this one yet though.
 
Oh, it needs to be missing = (size - sum(...)) if ...
but still not fully working
 
wim
@PM2Ring finally found a counter-example for that unicode-escape thing
 
oh another thing I just learnt, you can't unpack and and operate at the same time, ie:
 
wim
I don't know why I didn't think of it earlier. You just need a string which can not be the result of an .encode('unicode_escape') call, e.g. a single backslash '\\'.
 
5:59 PM
x, y-2 = tupleOfNumbers
 
wim
and the accepted answer suffers from the same bug as yours, unfortunately.
 
Rawing, I got a solution, it's ugly but it works (I think), but It's not the best solution, just the first thing that popped into my mind: repl.it/KzvH/1
 
@MooingRawr why should that work? y - 2 = tupleOfNumbers[1] doesn’t work either.
 
I don't know why I thought it would work, The thing was I never thought of it .... until just now.
My thought process: "This isn't a thing? wait it's not a thing... Oh operation on 'assignment' isn't a thing..... maybe it should be a thing.... oh well TIL"
 
(y-2)[0] = 23 is syntactically valid, on the other hand
Although you may have difficulty finding an instance of y that doesn't crash on this line
 
6:07 PM
@MooingRawr that doesn't look right. If I set length = 5000, I get ['b', 'a', 'b'] as output
 
Really I get a 'y' does get found
@Rawing Oh right, forgot to check the length limit exceeds the first bit
 
DSM
> I'm very newbie to python math. Can any one help me how to create a list of 1 to 100 real numbers.
 
DSM
I think [4.5]*73 technically qualifies..
 
math? list ? :\
 
6:08 PM
>>> class Blah:
...     def __sub__(self, other):
...             return self
...     def __setitem__(self, idx, value):
...             pass
...
>>> y = Blah()
>>> (y-2)[0] = 23
>>> #tadaaaaa
 
sighest of sighs
 
>>> class ListWindow:
        def __init__(self, lst, offset = 0):
            self.lst = lst
            self.offset = offset
        def __getitem__ (self, index):
            return self.lst[self.offset + index]
        def __setitem__ (self, index, value):
            self.lst[self.offset + index] = value
        def __add__(self, offset):
            return ListWindow(self.lst, self.offset + other)
        def __sub__(self, offset):
            return ListWindow(self.lst, self.offset - other)
@Kevin Great minds and stuff…
 
Mine's lazier and I'm not sure whether I should be proud of that
 
ARGH. AND BROKE IT
DAMMIT xD
@poke s/other/offset/g
 
6:13 PM
awww
 
@poke note to self: poke is in room 6 purely to help me rubber duck problems. err... wrong takeaway :P
 
That’s what I get for coding inside the edit textfield here in chat :(
 
ask one of our mods :P
 
@DSM realList =[ __import__("random").randint(0,100)]*100
 
Speaking of mods, anyone seen Bhargav lately?
 
6:14 PM
100 real numbers
chosen randomly
 
@ByteCommander Looking good! Hasn't returned an incorrect result yet.
Now to understand the code...
 
 
not PEP-8
 
@Rawing at a quick glance that looks like the logic that I'd have tried
good thing I looked at it before finishing my coffee and reinventing it myself :D
 
6:18 PM
PEP 8 only has phenomenal cosmic power in the realm of Python, alas
 
for some reason I always end up using waaaaaaay too many variables when I approach this problem... my code so far...
 
wim
@Kevin got a challenge for you
 
DSM
I think I'm going to clean up the recent conversation. @kkkkk, feel free to take your conversation elsewhere, but this is the Python room.
 
wim
can you one-liner itertools.count
 
\o/
 
6:24 PM
cbg
 
cbg :)
 
wim
    def count(firstval=0, step=1):
        x = firstval
        while 1:
            yield x
            x += step
 
@ByteCommander I thought it through and I couldn't find any mistakes in your code, so I'll be stealing it, thanks ;D
 
@Kevin Itty bitty living space?
 
6:26 PM
@Rawing no problem, was a fun challenge :D
 
DSM
@JonClements: cabbage for the puppy!
 
I still don't understand why I got random results earlier though. Wrong - yes, but why random...
 
Yay! Haven't had cabbage in a while... drools in anticipation...
 
puppy party!
 
DSM
I got distracted into paid work. @ByteCommander, were you working in an env which did hash randomization?
 
6:27 PM
@wim Hmm
 
Python 3.5. I don't know what it internally does, but dictionaries are not ordered, so probably the answer is yes.
I don't see how dictionary order changes the result here though...
Whatever, seems to work now.
 
as close as I'll get now:
>>> firstval = 3; step = 5
>>> k = [0]*firstval
>>> mycount = ([len(k),k.extend(step*[l])][0] for l in iter(int,1))
>>> next(mycount)
3
>>> next(mycount)
8
>>> next(mycount)
13
>>> next(mycount)
18
the l could be _ of course
 
> Your profile is ideal for our initial ... Senior Software Engineer ... we will send you a Hacker Rank Test ... basic proficiency in Python and SQL
This is (part of) the response I got from saying "I'm interested" to an SO jobs contact.
So either they didn't actually read my profile, or they did and don't care. :-|
 
is SO jobs a model of SO main?
 
Senior Engineer that only requires a basic proficiency? :p
 
6:32 PM
or they think you are not basically proficient in python
 
"look at all the information you provide that I don't read!"
 
it's always nice when companies more or less say "we found you via keyword search and didn't read anything"
 
I'm debating sending back "If you want to do a phone screen that's fine, but I'm not interested in sitting on Hacker Rank for 90 minutes."
 
DSM
TBH I'd have to be awfully interested in the firm before I'd follow up such a silly response on their part.
 
@davidism just link to a certain framework you might know a bit about and say "I wrote this"
 
6:37 PM
I've got an idea but I have to remember how y combinators work
 
wim
I bootstrapped Andras' idea
>>> mycount = ((l.__setitem__(0, l[0]+1) or l)[0] for l in [[-1]] for i in iter(int, 1))
>>> next(mycount)
0
>>> next(mycount)
1
>>> next(mycount)
2
>>> next(mycount)
3
>>> next(mycount)
4
as a bonus, now it doesn't run the computer out of memory
 
count = (lambda f: lambda start, step: f(f,start, step))(lambda f, start, step: [((yield start), (yield from f(f, start+step, step))) for _ in range(1)])
iter = count(5, 3)
print(next(iter))
print(next(iter))
print(next(iter))
#result:
#5
#8
#11
No mutation required B-)
 
0
Q: converting first fail to another fail

Kertrudmi'm new at programming and i need help with converting first fail to another fail. The task is: "Write a program that asks the user for two filenames. The first one should mark any existing text file. The second filename may be new, so the file with this name may not exist. The program's task i...

 
wim
wow, wtf
 
I learned something new today: "fail" is Estonian for "file"
 
DSM
6:41 PM
Wait, are we one-lining itertools.count for some reason?
 
wim
how does that even work
 
I, uh, actually don't know.
I copied a bit of the code samples from stackoverflow.com/questions/32139885/… and modified it to my purposes
 
wim
horrific
 
Without ever really understanding how yield in a list comp is actually supposed to behave
 
@TemporalWolf I went to edit the grammer/formatting there...someone is already editing it
 
6:43 PM
As a two-for-one, this answers a question that I posed many months ago which I'm not sure ever got answered: "can you make a one-line infinite generator using only builtins?" Turns out you can, if you use the darkyst of majycks
 
wim
huh? that's already there, just iter(int, 1)
 
Hmm, maybe it did get answered then.
 
wim
not exactly dark magic
 
@toonarmycaptain I already put in a reject for that edit... capitalizing 3 "I"s? seriously?
 
@TemporalWolf I should ask about my fájl-related [*shudder*] problems
 
6:49 PM
count = lambda start=0, step=1: iter(lambda v={'v': start - 1}, s=step: v.update(v=v['v'] + s) is None  and v['v'], None)
That's a rough stab at it...
 
Extra credit: a one-line infinite generator that doesn't have side-effects (so no append, update, setitem, etc), and which doesn't take advantage of oversights in the syntax and/or bugs (so no yield in a list comp)
 
can it generate zeros?
 
wim
iter(int, 1) still satisfies that
 
Whoops, forgot that constraint: and it has to yield something other than the same value forever
 
yup
 
wim
6:51 PM
ok, iter(random, -1)
 
I'll refrain from __import__ing itertools
 
Why is this discussion going on anyway? :p
 
we're feeling wimsical
 
>>> x = iter(lambda: _+1, 0)
>>> 1
1
>>> next(x)
2
>>> next(x)
3
>>> next(x)
4
>>> next(x)
5
>>> next(x)
6
>>> next(x)
7
This one counts as cheating.
 
_ only works in the REPL, right?
 
6:52 PM
yup
 
wim
iter(object, None)
 
DSM
Badger's being clever..
 
I'll begrudgingly give points for that one.
 
>>> count = lambda f,s: (f+i*s for i,_ in enumerate(iter(lambda: None, 0)))
>>> z = count(5,2)
>>> next(z)
5
>>> next(z)
7
>>> next(z)
9
 
Hmm, how to formally define "same" so that it has an intuitive meaning that excludes cute tricks like float("NaN") and other values that compare unequal to themselves
 
6:54 PM
December needs to come faster. Can't wait for AoC :(
 
While including obviously identical-in-all-but-address objects like empty object instances
 
@TemporalWolf I was going to fix all of it tenses etc(I hadn't noticed the 'I's yet TBH), and the formatting of the code.
 
@Kevin predictable stream of real values?
 
@toonarmycaptain OP reverted most of the grammar/spelling fixes... brace for an english war.
 
wim
yah, I want to see if from aocd import data continues to "just work" in 2017 without changes needed my part
 
6:56 PM
@TemporalWolf probably by mistake, they started editing earlier
 
@PaulMcG Nice.
 
huh, that ^
 
@wim you've tempted me to write my own example getter.
 

« first day (2523 days earlier)      last day (2426 days later) »