« first day (1839 days earlier)      last day (3112 days later) » 

DSM
6:00 PM
@MorganThrapp: not sure I'd say it like that.. number of bytes is a property of the encoding, really..len("\t".encode("utf16")) == 4..
 
Walk into an elevator with arms occupied. "Hey bud, can you hit 5 for me?" "A fine choice, monsieur" languorous eye roll.
 
@DSM Wait, really? I thought \t was always one byte. I stand corrected.
 
@MorganThrapp shiraz is ridiculously approachable though...
 
@hiroprotagonist I don't actually know that much about wine. :P I'm just vaguely aware of the different types.
 
There's white, and red, and I'm pretty sure purple.
 
6:03 PM
Red, white, ... the other one. And fizzy!
 
Damnit, pipped by Kevinson again
 
what is the python 3 solution for website scraping by roboting forms?
 
DSM
@MorganThrapp: ehh, you can argue that what you meant is the byte of value 9 anyhow. :-)
 
(that is, html legacy forms but with some security cookies etc)
 
6:04 PM
Some grapes are green and some are red. If there are blue grapes, you should be able to make any color.
 
mechanize still says python 2.x
 
I won't drink any wine that doesn't contain at least 5% food coloring.
 
@Kevin except white one should think...
 
Business plan: market a pinkish wine under the name #FACADE
9
 
Home time - rbrb
 
6:07 PM
@Kevin So a Rosé?
 
For completionism, other valid hex words are ['accede', 'baccae', 'baffed', 'beaded', 'bedded', 'beebee', 'beefed', 'cabbed', 'dabbed', 'daffed', 'decade', 'deeded', 'deface', 'efface', 'facade']
 
had to look up #FACADE, hrmpf! #deadbeef
 
@MorganThrapp, Not unless you're working in four channels.
 
@MorganThrapp oh. beat me to it!
 
6:09 PM
But then, wine does have variable transparency. RGBA is an option.
 
Or CMYK.
 
Actually, #BACCAE would be an appropriate wine name, since it's latin for berry. Uh, I think.
Wait, can you make wine out of berries?
 
@Kevin you're forgetting the use of numbers
 
I don't think leetcode substitutions would sell as well.
 
6:10 PM
@Kevin There is fruit wine.
 
rgb(176, 0, 181)
 
XD
 
it would sell well
how about #C0FFEE
 
off to have a beer. rbrb
 
off, beer, sounds a social combination.
 
6:15 PM
Permitting 1 and 0 as letters quadruples the number of valid hex codes. Along with the aforementioned #C0FFEE, #F00D1E and #B0D1ED are good ones.
Yeah, pretty much. The reference count of the value returned by i.split() drops down to zero after the first print function executes, so it becomes inaccessible. — Kevin 1 min ago
I'm not sure if this is actually true.
 
It's more an issue of scope, if I understand correctly
It's never being assigned to a class/instance variable.
 
@Kevin true, but also not a very good explanation...
 
Yeah, I guess so. Good thing there's already a good enough explanation posted.
 
anyway, this is just what is problematic:
ppl learn from the NLP book, from Django tutorials etc.
 
DSM
I don't like talking about reference counts because that's very CPython-specific, and I don't like talking about accessibility because you can get references to things in weird places (last object in _ at the console, e.g.)..
 
6:27 PM
but none of them teach you how to program Python.
 
The official docs teach you all sorts of interesting things about Python's guts, but there's little discoverability. You have to go in with an idea of what you want to find out.
 
there is the tutorial...
anw, what we need is a book that would teach everyone to think like a computer scientist
but explain it backwards.
so that you do first and then get explained later.
 
DSM
I think the ways I need things explained now are different from the ways I needed things explained when I hadn't yet reached my current intermediate level of Python.
 
Agreed. When I was reading about yield from yesterday, I thought "this wouldn't make any sense if I started with no idea how yield from approximately works"
 
this book for example, I'd prefer to learn from it but
 
6:34 PM
It's useful that it took me from "rough mental model" to "accurate mental model", but not everyone needs that specific transformation
 
it is too front-heavy for general use
 
DSM
Right now when I'm learning something new I want to know (roughly) the objects and the relationships and the structures before I learn any syntax (except as needed to give examples). When I had to learn the webby stuff the other year, looking things up in the flask docs wasn't hard. Learning JS syntax wasn't hard. Learning the stuff no one ever mentioned about where you're supposed to put stuff, and how the whole thing is supposed to hold together, was frustrating.
 
Yeah, I know that feeling.
 
@DSM I'll second that. Project management is still what I feel most uneasy about.
 
Yeah, that's exactly my feelings. I've been working on some PHP for a freelancing project, and the PHP itself isn't hard, it's learning how web frameworks work. How the controller talks to the model talks to the view.
 
6:37 PM
project management? this is not project management :D
it is that coding is easy
software engineering is hard.
 
When we worked with FPGAs in college, the hard part was getting everything set up so your two line assembly program would blink the LED. Everything that followed was fairly smooth sailing.
 
software engineering is a discipline with discipline.
 
(Or, I don't know if FPGA is the right term. A chip that you could flash instructions to from your computer.)
 
if it was an assembly program, it wasn't a FPGA (probably)
at least you didn't work on the FPGA level. Microcontroller.
 
DSM
I think I've finally arrived at a model/view-model/view approach which makes sense to me, but I had to ask davidism whether I was going off track because it felt like I was duplicating information about user state, and I didn't know if my reflexes made sense in this strange new world.
 
6:40 PM
@DSM all the MVC stuff is wrong.
most web frameworks get everything wrong.
 
DSM
Most random people on the internet are wrong too, so you can see my dilemma.
 
Flask is marginally better than some, it only gets 68 % of things wrong
 
My main complaint with the framework I'm working with is that everything inherits/extends at least 6 levels deep.
 
I occasionally use MVC for video game projects. It works pretty well because they involve literal physical views and controllers.
 
For me Pyramid gets least things wrong but I am fscking using Flask-Admin in a pyramid app since no one did a pyramid admin.
what I like about pyramid is that:
you never need to inherit anything from Pyramid's classes.
never.
they can inherit whatever they want, but I don't need to inherit from them.
 
6:48 PM
Pyramid is the name of our eons-old DOS interface to turn accounting data from dBase databases to flat files that our AS/400 can commit
I'm therefore against it on principle.
 
@AdamSmith You use dBase too? I'm not alone!
 
Not on purpose.
 
Yeah, me neither.
 
I need to rewrite my 1 line SQL INSERT into a copy-paste-search-replaced 32-line SQL script where I repeat the value 6 times. "Because it's the standard"
Kind of hating my coworkers right now. I don't mind if they want to make things complicated but at least have the decency to realize it's awful and put it in a procedure.
 
w00t?
 
6:59 PM
wot?
 
DSM
no such column: blocks.is_view: where are you coming from, O Error?
 
Is there a way to convert a variable width string to float with a fixed point? Eg, I know that the first 3 characters will always be on the left of the decimal point, but I have no idea how many points of precision I'll have.
 
Time for grep?
 
werkzeug does it wrong:
OrderedMultiDict.keys returns a generator
 
7:08 PM
@MorganThrapp Give me an example. Surely this is more difficult than decimal.Decimal("{:.2}".format(s))?
 
@AdamSmith That certainly looks like it could work.
1000000
228874
162749
31369438
Those are some examples of strings i need to convert.
 
How about this:
>>> s = "123456"
>>> int(s) * 10 ** (3-len(s))
123.456
>>> s = "1234567891"
>>> int(s) * 10 ** (3-len(s))
123.4567891
 
so 1000000 -> 100.0000 and 228.874 and 162.749 and etc?
 
@Kevin That also looks good.
@AdamSmith Yeah.
 
for s in s_list:
    int_part, dec_part = s[:3], s[3:]
    result = float(int_part + "." + dec_part)
I like working with strings.
math is hard.
 
7:11 PM
I vaguely expect a stringy approach to be more precise than mine
Since there's less opportunities for float arithmetic to go screwy
 
(though I may be off-by-one because string indexes elude me occasionally and I cba to open an interpreter on my lunch)
 
OTOH, strangeness may occur for tiny strings like "12"
 
@Kevin This is a class method, so I'm already filtering out strings under length 4.
 
Good, good
 
I ended up using Adam's string method.
 
DSM
7:14 PM
This guy seems to be working his way through an assignment. That time of year, I guess..
 
strings are magic
 
    int_rate = try_int(rate)
    if len(rate) > 3:
        return try_float(rate[:3] + '.' + rate[3:])
    return int_rate
Beautiful. :)
 
Strings are magic. Friendship is magic. Therefore, friendship is strings.
 
DSM
Transitivity is fun. Fun is bad for you. Therefore, transitivity is bad for you.
6
 
It has caused a number of legal injunctions to be levied against me...
One of which prevents me from discussing the details of all the others.
 
DSM
7:18 PM
I'll just have to pass the bar and become your lawyer. Then you can tell me!
 
Oh wow. The video I was listening to got copyright blocked mid-stream.
 
Well, I can still talk about the injunction to ignore this injunction, because the prosecution is still trapped in the event horizon of the paradox.
Luckily, criminal penalties travel slower than c.
 
DSM
[list(v) for v in product(*((range(10) if c == 'X' else [c]) for c in unknown))]
 
Yep, that'd do it.
I knew product would be the way to go, but I couldn't think of a nice way to give the 'X' values special treatment
 
DSM
Depends on whether or not the two Xs are supposed to be the same or not. I can't tell from the question. I think they're not supposed to be.
 
7:24 PM
I don't think they are
 
My initial assumption was "they can be different" but I don't have any particular reason for believing so
 
DSM
{"X": range(10)}.get(c,[c]) would work too, I guess.
 
I guess because it makes the problem more interesting.
If X is always the same as every other X, you can do it with just a for loop.
 
DSM
Yeah, I guess the OP's original code would have worked if he wanted X0 == X1.
 
what does itertools.product yield? is it tuples?
 
DSM
7:28 PM
Yeah.
 
ok I thought so
 
DSM
s = [_ for _ in l] <- Good example of someone who's done enough Python to know he needs to make a copy, but hasn't read enough of other people's to know the idiomatic way to do it.
 
I'd hire him
 
Don't think I can overlook his use of _, myself
 
I don't see anything wrong with using _ here. It's "Hey there's an element here and I'm using it but I don't care what it is"
 
DSM
7:33 PM
I'd accept l.copy(), l[:], or list(l), but using an empty listcomp for copy purposes?
 
listcomps are cool
 
But you do care a little what it is. I would accept s = [random.randint() for _ in l]...
If _ is in the leftwards expression of the list comp, something has gone wrong.
 
shrug something has gone wrong that he hasn't used the empty slice
once we're there, I feel like it's forgivable
doesn't enumerate make a copy of the list to iterate over?
does he really need to copy l here?
 
I don't think enumerate makes a copy, no
 
DSM
@AdamSmith: yeah, because otherwise after the first step his l won't have any Xs left.
 
7:38 PM
oh I'm thinking backwards
sorry
 
DSM
If he got the locations outside of the loop (which he should do anyway) that wouldn't be as much of a problem.
 
but what if they chaaaaaange? :P
 
DSM
I still like mine best, he said vaingloriously. :-P
 
This question might make a good basis for a deep source dive.
I'm pretty sure @MartijnPieters once explained to me exactly why class methods will change id in this way, but I have since forgotten.
 
DSM
Oh, there's a dup for that. MP might have written the one I'm thinking of, not sure.
Maybe this?
 
7:49 PM
yup
 
The Qs exhibit slightly different behavior, but the answer still applies, I think
 
DSM
I'm never too clear on how close two things need to be before the one is just an application of the other, if you know what I mean. Which is why I tend just to add "maybe relevant: (some link)"..
 
In the one I linked, the id of Foo.fun changes. In the one you linked, the id of C.foo does not change, but the id of cobj.foo changes.
 
DSM
Foo fun C foo cobj foo! Hard to take this seriously.
 
Interestingly, on my machine the id of Foo.fun stays the same, but Foo.fun is Foo.fun returns False anyway.
This is very unusual to me.
 
7:54 PM
x = Foo.fun; y = Foo.fun; id(x) != id(y) (I bet)
 
>>> (lambda a: a is a)(Foo.fun)
True
>>> Foo.fun is Foo.fun
False
 
if you're doing print(id(Foo.fun)) twice, Foo.fun is probably garbage collected in between and the next call gives it the same now-free memory address
 
[psyduck.png]
 
DSM
The first one only has one Foo.fun access, the latter has two.
 
@AdamSmith That is what I'm doing. But print id(Foo.fun), id(Foo.fun) does the same thing.
Maybe garbage collection can happen in the middle of an expression?
 
7:56 PM
oh that's bizarre
 
>>> a = Foo.fun
>>> b = Foo.fun
>>> id(a), id(b)
(44273600L, 45087408L)
Ok, there we go.
Gotta keep that ref count up.
 
>>> Foo.fun is Foo.fun
True
implementation detail
fuhgettabouttit
 
Yeah really
That's basically what I told OP.
If your program cares about memory adresses of class methods, you're a bad person and you should feel bad.
 
DSM
I used to get a kick out of posting how things behaved under pypy, ironpython, and jython when somebody said something about how "Python" behaves. The excitement faded.. :-)
 
New Blog idea: "Python Behaving Badly"
 
7:59 PM
Well, at the very least, I'll link Martijn's post
 
DSM
Oooh, "recommended reading" is good.
Acknowledges relevance without committing to anything in particular.
 
I'm real good at avoiding commitment :-) ... :-(
(still can't find a good emoticon for "dawning realization of getting owned by self")
 
user559633
 
user559633
better in non-tacky corel draw gradient
 
user559633
 
8:12 PM
@Kevin, @DSM: yup, that's a dupe.
 
I associate that emoticon more with "just noticed your neighbor's lamp made of skin for the first time"
 
@Kevin: read my answer carefully, on Python 3 classobj.functionname returns the function object, as the notion of an unbound method was dropped.
 
I think I remember you telling me that last time too :-)
(all of my experiments above were in 2.7, for the record)
 
Ah, then you got id reuse.
Remember that id(Foo.fun) creates a new method object, then records the id, then garbage collects the method object.
 
user559633
is there an itertools for doing the minimum number of comparisons in a list?
 
8:14 PM
Leaving the memory address free to be reused for the next time you do that.
 
I expect allocating a just-freed memory slot gives some kind of caching advantage
Or it's just an artifact of malloc's implementation
 
I don't know.
 
Yeah definitely in deep "implementation dependent" territory there.
I'm looking at C dynamic memory allocation and there's like eight different ways to do it
I vaguely recall reading about a heap allocation strategy where you store blocks of varying powers of two, and how it's subsequently likely that freeing one block and mallocing a block of the same size will give you the same address you just freed.
 
can I use xrange to count backwards in Python2? xrange(n, 1, -1)?
(I don't have a Python2 interpreter on this machine)
 
Yep
 
8:24 PM
thanks
and it's half-open like counting forwards? So that will give [n, n-1, n-2, ..., 2] right?
 
Yeah
 
>>> for i in xrange(10, 1, -1):
...  print i
...
10
9
8
7
6
5
4
3
2
 
thanks
 
2.7.6
 
I should really just install py2 on this system
:P
 
8:25 PM
:) it helps. I have 2.7, 3.4 and 3.5
 
In a pinch, you can always use ideone.com
 
Do we have a canonical dupe for "How do I text file"?
Way too broad.
 
9:13 PM
Community bot dupe hammered for me! my hero! :)
 
DSM
[''.join(p) for p in product(*(myDict[c] for c in myString))] Lots of itertools.product questions today.
 
user559633
Well, that's one way for network television to pass the Bechdel test. (H/T @hypatiadotca ). https://t.co/pikwssn66B
 
DSM
9:32 PM
"P.S. I'll remove the question as soon as it's answered." Well, that's honest, at least.
 
and it's a fizzbuzz!!
yaay!
 
I've lost my hobnobs.
 
DSM
Did you look under the bed?
 
My bed goes all the way to the floor.
 
DSM
Where do you keep all your stuff?!
 
9:39 PM
Mornings
 
On top of my wardrobes.
 
DSM
shakes head Things are very different across the pond.
 
9:50 PM
morning @PeeHaa
 
o/
 
this stupid integer partitioning puzzle is gonna kill me
 
DSM
Heh. I can't remember: were you after the partitions themselves or just the number of them?
 
just the number
I'm thinking I can figure it out if I approach it as A*m + B*n + C*o + ... = k
rather than 1+1+1+1+1 = 5 do 5*1 = 5
that should save me from having to worry about duplicates
I'm just not strong with the math
and that's showing through right now :P
 
10:49 PM
vim wizards (who are hopefully more magical than yours truly): how would I apply an action to every line in a file? In this case I used a macro and just did @@ a bunch of times, but it's appending text to the end of every line
 
A<text><esc>, then use . to repeat.
basically append end of line with text you want.
alternatively use a regex on a visually selected range
:'<,'>s/$/foo/
appends foo to every end of line within the visually selected range.
 
11:13 PM
Yeah I thought about repeating action using ., but then it's j.j.j.j.j.j.j. instead of recording the "down line" action in the macro and just doing @@@@@@@@@@@@
 
stackoverflow.com/questions/33425883/… floating point math is broken.
BTW, I just added the canonical question to sopython
 
hammered boom thwack
 
cbg
 
cabbage @TigerhawkT3
 
attacking any codewars tonight @AdamSmith ?
 
11:21 PM
haven't come up with a solution I'm satisfied with
 
DSM
11:47 PM
I'm going to bring up one of Kevin's earlier hints: the problem is much easier if you think of it in 2D instead of one. If you define a function which specified two things about the nature of the partitions, it's much easier to see how the recursion should go. (There are other ways to do it, but this is the canonical one.)
 
I'm probably dumber than I look because I don't really understand the hint. The method I'm trying to use right now is to recurse with a function header f(n: "remaining total", pending: "list of numbers left to try") -> int
so f(5) will build pending as [2, 3, 4, 5], pop the last pending into current and recurse on f(n-current, pending)
default case is pending being the empty list (meaning there's no numbers to try other than 1 and there's only one way that a set of 1s adds up to n) or n<2
 

« first day (1839 days earlier)      last day (3112 days later) »