« first day (2813 days earlier)      last day (2360 days later) » 

00:00
I did some updates but I'm still on 3.6.4
Yep still faster
(base) C:\Users\Simon\Desktop>python test.py
0.020469036165636945
0.019048324707992313
 
3 hours later…
03:13
@PM2Ring Yes thanks, I figured that out and fixed it
 
3 hours later…
06:32
@user3483203 don't help that stackoverflow.com/questions/51095580/…
06:50
@OneRaynyDay are you sure the module needs to be there?
@Simon with 3 digits I'd expect a lot of overhead. Try a bit more and see if it's consistent.
Morning(ish) cbg
@AndrasDeak honestly I have no idea
07:16
@OneRaynyDay so try importing it and check a __file__ for instance
Or, you know, try using it :P
@AndrasDeak good try except keras.__file__ does not work. Surprisingly.
I have tried using it; doesn't work: stackoverflow.com/questions/51092421/…
07:50
I think only files have __file__, modules don't. Don't the latter have __path__? On mobile now, can't check. Surely bunch of dupes for "where's my module".
recbg
@OneRaynyDay not all modules have __file__ - builtins don't.
08:08
@AndrasDeak sounds good. I'll try that, thank you.
08:52
np.__path__ exists for me which is promising
09:38
@MartijnPieters ^ :D
10:09
Cabbage!
10:25
Hello, i have finally some use for python in data science
Where can i start
I want a good library for text manipulation
10:38
I tried num = 1111111111111122222222222222222333333333333333333333 and now the first is faster 0.304803213 vs0.39357393100000015
I don't know if long ints start to behave differently with respect to the mathy bits...
try with sys.maxint and sys.maxint+1 (I think) to check (oops, python2 only; sys.maxsize may be similar)
might or might not be informative...
>>> sys.maxsize
2147483647
>>>
32 bits?
>>> sys.maxsize
9223372036854775807
My installation is... Am I correct in guessing yours is a x64
yup, always
so I have no idea if there's a difference in the machinery between small ints and big ints in 3
10:47
Everything’s a long.
typewise yes, but does that also mean that divmod on 9999999999999999999999999999999999999 is the same as divmod on 10?
11:11
it will likely give different results, but yeah
12:06
I have written java client and python server communicating over SSL.
I used SSLSocket class for both python and java.
When I read general description of how SSL works, I realized that in most implementation (say browsers), client creates a session key and sends it to the server. Further explanation works using session key.
But when I read docs of java/python classes, it does not say anything like this.
The question is does those classes implement the session key under the hood and use it, or I have to generate them explicitly?
12:42
It's a shame that How to convert any word into an integer in Python is so informally specified, because in the past I've needed to reversibly convert a (byte) string to a unique int, so it would be nice to have a canonical post for the problem.
12:54
IIRC my solution was something like to_int = lambda b: sum([x<<(i*8) for i,x in enumerate(b)]), with the reverse being to_str = lambda x: bytes((x >> (i*8))%256 for i in range(int(1+(math.log(x,2**8)))))
... Might have a fencepost error in that log calculation there.
Not really feeling inclined to write an answer for that post, since the hash solution got accepted. Which has about as much practical utility as return random.randint(1, 2**64) if you ask me
DSM
DSM
In [19]: int.from_bytes('cabbage'.encode('utf-8'), 'little')
Out[19]: 28542640607879523
does bin(that) match the concatenation of the bytes of cabbage?
>>> to_int = lambda b: sum([x<<(i*8) for i,x in enumerate(b)])
>>> to_int(b"cabbage")
28542640607879523
Yep
Now searching for a bytes.from_int method...
In [29]: f"{int.from_bytes('cabbage'.encode('utf-8'), 'little'):x}"
Out[29]: '65676162626163'

In [30]: "".join(f"{b:x}" for b in 'cabbage'.encode('utf8')[::-1])
Out[30]: '65676162626163'
I have a bad feeling that there isn't one, because from_bytes isn't reversible, because several different bytes objects can be converted to zero, in particular the empty byte string and any byte string composed only of repetitions of "\0"
Which is also a failing of my own handmade approach
DSM
DSM
13:06
Yeah. We can get around it with the usual protocol tricks for adding message length.
I was hoping for a nice bijection between byte strings and the non-negative integers, but I don't think most protocols give you that
Why not? Can't you zero-pad bits of the bytes, and then concatenate the result and get your int? Then if you write your int in binary you know you have to cut it up every 8th place
doesn't the fact that the number is a concatenation of hex already do that?
ah, no, because of the leading zeros
Ex. If we use the protocol "a variable-length header indicating the number of bytes, followed by a number representing the values of those bytes" then you could construct an integer that corresponds to "a header indicating the message is 4 bytes long, followed by a body of 200 bytes", then that would either be considered a "syntax error" for having too many characters, or the last 196 bytes would simply be ignored
DSM
DSM
I guess the most natural mapping is that a zero-length string becomes 0, all 1-length strings are between 1 and 257, etc.
In [43]: "".join(f"{b:2x}" for b in 'cabbage POTATO'.encode('utf8')[::-1])
Out[43]: '4f5441544f502065676162626163'
does this not work?
13:12
The bijection fails one way or the other: either two integers map to one string, or one integer maps to nothing
yes, some integers may be excluded
You're right, bijection won't work.
but you can define a bijection between any string and the corresponding ints with no ambiguity
@DSM Yeah, that's what I was thinking
DSM
DSM
I'm on a notebook and not at a real keyboard but I think we could implement that approach in only a few lines.
3 upvotes and accepted answer for someone providing a dictionary to lookup values in a Numpy array. dict(enumerate(array_of_unique_values)). What's better array_of_unique_values[0] or dict(enumerate(array_of_unique_values))[0]. My apologies, its just frustrating to see how votes go sometimes.
I wonder if this protocol would work: take the int.from_bytes() value, and prefix it with a "1" bit followed by however many "0" bits is necessary to make log(result, 256) == len(original_string)+1
Except for the empty string, which continues to map to 0
DSM
DSM
13:21
Wow, my arithmetic is awful. If I want 256 separate values, that's from 1 to 256. Maybe I can pretend my range was upper-exclusive, being a Python dev and all..
cbg \o
Or, hmm, maybe that would map every string to a unique int, but not vice versa, since having a leftmost byte of anything other than 0b1 would be a syntax error
13:37
Here's a bad implementation of DSM's concept:
import itertools

def slow_to_int(b):
    b = tuple(b)
    idx = 0
    for i in itertools.count():
        for seq in itertools.product(range(256), repeat=i):
            if seq == b:
                return idx
            idx += 1

result = slow_to_int(b"\0\0\0")
print(result, hex(result))
Which is horribly slow for any byte string of practical size but it at least can give some insight about the structure of the results
"" maps to 0. "\0" maps to 0x1. "\0\0" maps to 0x101. "\0\0\0" maps to 0x10101. "\0\0\0\0" maps to 0x1010101. I assume this pattern continues.
What is the most advanced toolkit for python for analysing unstructured data i.e find patterns and stuff
A faster implementation might look like: construct a 0x10101...01 value corresponding to the "\0" filled string that has the same length as your input string. Then take int.from_bytes(your_input_string), and... XOR them together? Something like that.
anyone?
Can't say I know anything about that.
13:50
C:\Users\Kevin\Desktop>test.py
b'' maps to 0x0
b'\x00' maps to 0x1
b'\x01' maps to 0x0
b'\x02' maps to 0x3
b'\x03' maps to 0x2
b'\x04' maps to 0x5
b'\x05' maps to 0x4
Ok, XOR doesn't work perfectly
DSM
DSM
can't you just add?
Let's see.
C:\Users\Kevin\Desktop>test.py
b'' maps to 0x0
b'\x00' maps to 0x1
b'\x01' maps to 0x2
b'\x02' maps to 0x3
b'\x03' maps to 0x4
b'\x04' maps to 0x5
b'\x05' maps to 0x6
b'\x06' maps to 0x7
Think I better test on larger values also...
morning cabbage
Looks like sum(1 << i*8 for i in range(len(b))) + int.from_bytes(b, "little") first fails when b equals b'\x00\x01'. We would prefer it to return 0x102, but it returns 0x201
sounds like you have an endianess issue
13:56
Maybe.
maybe change "little" to "big"?
I'll try... It's passing my tests
Just crossed the length-of-three barrier without problems so I'm satisfied that it's working.
def faster_to_int(b):
    x = sum(1 << i*8 for i in range(len(b)))
    y = int.from_bytes(b, "big")
    return x+y
Cabbage
DSM
DSM
Cabbage for PM2R.
Hard mode: find the reverse of this function. Given x, find the xth byte string in lexicographic order.
14:07
morning cbg
I guess it's not too hard. You can reconstruct the 0x10101...01 value by inspecting the size of the integer, then you can subtract to find the from_bytes result. Then you do magic to it to get the byte sequence (stripped of any leading \0s if it had them), then you un-strip the \0s
DSM
DSM
Well, we know the values "start" at ((2^8)^n-1) /(2^8-1).. and I've just been Kevinned.
I used all of my "avoid fencepost errors" energy writing faster_to_int so now I don't have any left to actually compose an implementation of from_int
14:19
@piRSquared link?
thanks
yup, you're right, that's stupid
"reconstruct the 0x10101...01 value by inspecting the size of the integer" may be more complicated than I intimated, since a one-element byte can turn into either a one byte int or a two byte int. In particular, b"ÿ" maps to x100
And it's not just "the lexicographically-last byte object of length N has N+1 bytes instead of N". bytes([255,0]) maps to a three byte int, and so does bytes([255,1]), and so does bytes([255,2])... etc
Probably you could just iterate up through the (0, 1, 0x1, 0x101, 0x10101) sequence until you find the largest one that's smaller than your number, but I'd hate to use a loop if a closed-form solution exists
sum(2**(2*k+1) for k in range(...))?
I wonder if you can utilize the fact that 0x10101 + 0x1010 == 0x1111
sum(2^(2k+1)) = 2*sum(2^(2k)) = 2*sum(4^k) which has a closed-form result
something like 2*(1-4^N)/(1-4) where N is the number of your terms +- 1
if I'm right you can just express N as a function of your number (something with log4) and take the ceil of that number
I'm not confident of that because I suspect there's more and more drift as you encode longer strings
14:33
what do you mean?
I'm only talking about 0x1010101010...010101
whoops, forgot a negative sign there
I mean, you can construct an 0x10101..01 value of a given length in a reasonably efficient fashion. What's hard is determining the correct length given your number
@AndrasDeak I wasn't even in the mood to answer any questions but I had to respond after seeing that.
14:51
>>> def bininator(num):
...      Nfloat = math.log(num*3/2 + 1)/math.log(4)
...      print(f'{int((4**math.floor(Nfloat) - 1)/3):b}')
...      print(f'{num:b}')
...      print(f'{int((4**math.ceil(Nfloat) - 1)/3):b}')
...
>>> bininator(3523623623)
1010101010101010101010101010101
11010010000001100011101011000111
101010101010101010101010101010101
To rephrase my "drift" concern: call a byte object "askew" if it is N elements long, but maps to an integer larger than N bytes. There is only one askew byte object of length 1. There are ~256 askew byte objects of length 2. I suspect there are 256**2 askew byte objects of length 3.
My fear was that at larger sizes, there may be byte objects of length N that have int representations of length N+2 or larger. Which means you couldn't trivially recover the size of the byte object from the size of the int.
But thinking about it, I don't think this is actually possible. Even though the drift increases exponentially, the number of numbers representable with N bits also increases exponentially. So it balances out, so askew byte objects should only ever be off by one.
@Kevin the f-strings contain the closed-form numbers for the lower-upper limiting 101010... sequences
I'm not sure I understood your point though, but I'm pretty tired
I'm also tired, so I probably didn't convey my point very well
@AndrasDeak Nice proof of concept, although in the actual problem we want 0x101..01, not 0b101..01
oops
>>> def hexinator(num):
...      Nfloat = math.log(num*255/16 + 1)/math.log(256)
...      print(f'{int((256**math.floor(Nfloat) - 1)/255):x}')
...      print(f'{num:x}')
...      print(f'{int((256**math.ceil(Nfloat) - 1)/255):x}')
...
>>> hexinator(3523623623)
1010101
d2063ac7
101010101
then again it's simpler to check len(hex(num)) :)
15:12
But sometimes the bottom number will be smaller than num, for example hexinator(258)
it shouldn't... guess I offed by one
since I realized that you can just construct those ones and zeros from the length of hex(num) I kind of lost enthusiasm for my approach
15:24
@Kevin can you link the beginning of this thread?
At some point it makes sense to throw up your hands and say "on second thought, let's just construct a bijection between the non-negative integers and strings that don't have trailing null terminators"
(yeah, yeah, now you're thinking "bytes are not strings and you should not assume that their use case is similar to strings; having trailing \0s is perfectly valid for bytes and any algorithm that can't handle that is a nonfunctional algorithm")
15:44
@Kevin How about just prepending a non-zero byte to your input bytes string?
from random import seed, randrange, getrandbits
seed(42)
def bytes_to_int(b): return int.from_bytes(b'\x01' + b, 'big')
def int_to_bytes(n): return bytes.fromhex(f'{n:x}'[1:])
# test
encoded = bytes_to_int(b''); decoded = int_to_bytes(encoded)
print(encoded, decoded)
for _ in range(100000):
    bitsize = randrange(1, 10000)
    bytesize = -(-bitsize // 8)
    b = getrandbits(bitsize).to_bytes(bytesize, 'big')
    assert int_to_bytes(bytes_to_int(b)) == b
That satisfies the practical problem of uniquely reversibly mapping every bytes object to an int, but I don't think it's a bijection
Ex. both 1 and 2 map to b''
Of course, I don't expect bytes_to_int to ever return 2, so this is largely academic
15:59
I'm lacking motivation today. Already planning for the weekend, which is mostly going to be moving to a new apartment.
@Kevin No. I wasn't trying to create a bijection, that's too hard. :) My goal was simplicity & speed.
Ok, I thought so. Incidentally, who else here is mad that we have bytes.fromhex but not bytes.fromint
I demand symmetry in my builtin functions, in name if not in behavior. I don't mind if bytes.fromint(int.frombytes(x)) doesn't always equal x.
@Kevin I'm only mildly annoyed, since it's easy enough to use int.to_bytes. And bytes.hex() is a nice compensation.
Thank goodness for silly FGITW questions. :) Of my last 3 questions, one I answered in a couple of minutes with a "Pythonic" loop using enumerate on a product. Another does a breadth-first search of a JSON object to analyse its branching structure. And my most recent one is a recursive generator that produces anagrams. The FGITW answer scored 5 upvotes, the other two are still sitting on zero. Oh well.
let's golf: Most concise way to print out the keys of a dictionary and nothing else except white space.
print(''.join(d))
nvm, kinda lame
16:16
breaks if your keys aren't strings :p
>>> d = dict.fromkeys('cabbage'); print(*d.keys())
c a b g e
print(*d)
Won't that do values :P
@vaultah I'll pay that. :D
16:18
no, keys
Values of keys
Not to be confused with values of values.
or keys of reticules
I saw an api the other day that returned an array of dictionaries where each dict had the structure {key:keyvalue, value:valuevalue}
16:21
Speaking of values, the other day I was reminded of this cute quip. Niklaus Wirth, creator of Pascal, Algol W, Modula, etc, joked that because Europeans pronounce his name properly ("VEER-t"), while Americans pronounce it as "nickel's worth", he is called by name in Europe and called by value in America.
5
wow, just...wow
And if you thought that was bad...
no no no more :P
Kudos to "i am getting following errors" for making it past the title quality filters
16:49
the only title filter that I know of is "this title already exists"
Cbg
Brb gonna make a post with the title "problem [urgent]"
Maybe all of the previous "i am getting following errors" questions have been deleted, so the title wasn't a dupe... assuming the dupe title check doesn't look at deleted questions.
Brb, writing canonical "Getting Error" Q&A
17:02
Some users could genuinely benefit from a "what's the first thing I should do after getting an error message?" post
"read the message, then read the line that the error occurred on" seem to be skills that are missing in an alarming proportion of our user base
we should put it somewhere easy to find, like stackoverflow.com/help/mcve or stackoverflow.com/help/how-to-ask
Sounds like a job for a flow chart
@AndrasDeak did you s.tqrtk
beg your pardon
@AndrasDeak did you start using python 3.7?
17:06
technically I started using it in its alpha, though I had defaulted to 3.6 until yesterday
Sorry... I push enter without paying attention
you can edit/delete messages up to two minutes after posting
Ok, shortly
17:19
Not sure how hard I should dog Python Base64 encoding adds random letters to string for more information about their problem, since it's working on their machine now (despite the self-answer not changing all that much)
Most likely they'll just reply "haha idk this new version just works and the old one just didn't :-)" then I guess I'll close as can no longer be reproduced
DSM
DSM
17:44
Back from work. Did we wind up with a clean inverse function, Kevin?
Reading the transcript got me lost on what you fellows are trying to do so I will go back to lurker. best of luck tho :D
Nope. PM wrote a pretty good non-bijective solution though
DSM
DSM
Okay, I'll take a stab, then.
@Kevin hey, don't doubt the swanky tiger
18:02
Hey @DSM. The other day I mentioned writing code to find stapled intervals. My algorithm is semi brute force, but not as bad as that OP's approach, and it can find solutions for small intervals pretty quickly, just doing a search on every interval.
But I enhanced it using Tim Peter's version of a postponed sieve to look for prime gaps >= the interval size, and only searching in those intervals, which gave a 10x speed increase, although in my tests I was only searching for numbers <50 million.
Here is a non-clean inverse function. Setting the bar low for everyone else.
Oops, "the one where g(cond) is True" is supposed to read "the one where cond(element) is True". Oh well.
18:15
80% chance there's already something in itertools that does what my last_before function is doing, but also handles corner cases better and has a pine-fresh scent
18:28
>>> pair = lambda g: (lambda g1,g2: next(g2) or zip(g1,g2))(*itertools.tee(g))
>>> last_before = lambda g, cond: next(a for a,b in pair(g) if cond(b))
>>> last_before(range(10), lambda x: x > 5)
5
cbg, before I consult on SE, I was wondering if anyone could take a look at this serialization scheme (I don't want to get shot down for my 0 knowledge of proper serialization)
I'm trying to perform serialization on a inheritance hierarchy, and it's kind of bothering me. I know I could do something like super(B,b).__dict__ = a.__dict__, but it just doesn't feel right.
@Kevin There's takewhile, but you have to invert the test.
(and yes, I know, don't explicitly call A, and do super(B,b).deserialize(...) instead)
from itertools import takewhile
for v in takewhile(lambda x: x<5, range(9)):
    pass
print(v)
# output
4
Yeah, but I wanted to do it without binding any names
Currently trying to fix up pair to use islice instead of using next to put the generators one element out of step
>>> pair = lambda g: (lambda g1,g2: zip(g1, itertools.islice(g2, 1, None)))(*itertools.tee(g))
>>> last_before = lambda g, cond: next(a for a,b in pair(g) if cond(b))
>>> last_before(range(10), lambda x: x > 5)
5
That's better.
And the obligatory one liner
>>> (lambda g, cond: next(a for a,b in (lambda g: (lambda g1,g2: zip(g1, itertools.islice(g2, 1, None)))(*itertools.tee(g)))(g) if cond(b)))(range(10), lambda x: x > 5)
5
Could cut out a lot of this is there was an itertools.last()
18:39
You could replace that lambda with the method, although some people may disapprove. :) (5).__lt__
Pretty sure my innermost lambda g: isn't necessary but I'm not going to try too hard to optimize jokey code
Half serious implementation of itertools.last(g): {1:x for x in g}[1]
Combine with PM's serious suggestion for a 75% serious solution
>>> last_before = lambda g, cond: {1: x for x in itertools.takewhile(lambda y: not cond(y), g)}[1]
>>> last_before(range(10), lambda x: x > 5)
5
@OneRaynyDay Don't know much about inheritance but I'm concerned that your .json files can only store one object apiece. What if the user wants to serialize ten A's at once?
18:55
@Kevin don't worry about that. this was meant to be an MVCE
your concerns are addressed properly in my actual codebase ;)
Sometimes when I serialize things, I take a page out of __repr__'s book and package the data in such a way that you could pass it into the type's constructor and get an object equal to the original.
So if, say, Point has a constructor __init__(self, x, y):, I would serialize it as a tuple, (self.x, self.y). Then I can write my deserializer as return Point(*json.load(f))
Yeah, pretty much what I'm doing right now, except with 1 caveat
I don't want to serialize everything into disk. My objects aren't as simple as Point. They have many complex objects like giant numpy arrays
some of which are computed during runtime so you shouldn't ever really serialize them, rather start the model at the initial point and let it generate that data itself
otherwise you end up with a giant, uninterpretable mess of junk on your hard disk
Tricky.
19:08
Shwifty.
The old dilemma of "if I let my deserializer run code to reconstruct my object will I make Skynet?"
I trust that the Skynet overlords will be merciful
It's the paperclip maximizers you need to worry about
@OneRaynyDay That's what the YAML guys said...
Mercy is not paperclips, therefore they will not have it
Still just throwing random ideas around, but I wonder if it would be useful to have a non-staticmethod version of deserialize which updates the attributes of self with the deserialized data, rather than returning a new object
Then B.deserialize could call A.deserialize, passing itself as a parameter, so both A and B's deserializers operate on the same object
DSM
DSM
19:19
@Kevin: mind putting this through its paces?
OK, let's see
DSM
DSM
@PM2Ring: will take a look!
Passes my test up to and beyond length-of-three byteses, so I approve
I must remember .bit_length() for later, that looks useful
I will take any opportunity to not open myself up to the chance of a fencepost error while using math.log
Ok. After only eight hours of work, we can finally post an answer to that post at -5 points that already has given out an accept.
DSM
DSM
4470706d2f21214a217570706c2162217873706f68217576736f2d2167666d6d216a6f7570216221‌​716a752d21626f65216a75217570706c216e662174767371736a746a6f686d7a216d706f682175702‌​1646d6278216e7a2178627a217076752f #newstylespoiler
Yeah, bit_length was a nice addition. It's not the sort of thing you need very often, but when you need it, it's nice to have.
19:31
@DSM Thanks! There's some interesting & useful info at oeis.org/A090318 and oeis.org/A194585 but some of the info at the 2nd link is a bit confusing. Or maybe it's just downright wrong. :)
Hmm, when I copy that number, it seems to have some invisible \u200c\u200b characters in one or two places. Does chat always do that?
DSM
DSM
Hmm. I see them too when I copy it back, but I'm pretty sure they didn't come from source because it's all on one line in the terminal.
Those are ZERO WIDTH NON-JOINER and ZERO WIDTH SPACE for the record
@Kevin Yes, chat does that. I discovered that last year, but I forgot about it.
Just typed out 512 "a"s in the Sandbox room and it injected the zero width characters. Confirmed.
I'm guessing it only does that for messages that don't have a natural break, so it doesn't typically matter for sentences composed of actual words
DSM
DSM
19:40
Ooh, good thought.
Question about when to use inheritance. I have a class that wraps some data, and has some attributes/properties for that data and methods to process it. now I want to make a new class that turns that data into something conceptually pretty different, so it should be a new class (?). I want to keep most of the attributes but I don't need the methods. Is this a good place to use inheritance or should I just copy the properties in my new class's init?
@Kevin "non-joiner"? Does it non-join?
This time last year I wrote a program to download chat transcripts & view them in the terminal. I just had a quick look at it, and it ignores those ZERO WIDTH thingies, since they didn't hurt anything.
I guess non-join means "don't try too hard to keep these bits together on one line"
@AndrasDeak It's like the opposite of a non-break space. It introduces a potential break without a space.
19:44
I still dislike the name
DSM
DSM
Are you opposed to things which are non-stop?
How do you feel about "near miss"?
I could care less about it.
Are these trick questions or just jokes over my head? :P
@CalumYou given the choice of those two, I'd pick inheritance.
19:49
@CalumYou can you have the data and attributes/properties as one class and have two processing classes that extend that with their independent sets of methods?
Other possibilities:
1) just use the existing class everywhere.
2) make a plain-old-data class with no methods, and make two classes that both inherit from it; one with your existing methods, and one with the methods you're about to write
I have a homemade Point class that I use for all manner of geometry-related code, and 50% of the time what I really need is not a point but a Vector, but conceptually they have the same attributes (x, y, and z) and most of the same methods (overriding addition and such) so I haven't bothered to separate them
@MoxieBall i'm trying to think how this would work. i guess the problem is that I want to do processing in sequence. So it would be make data ClassA that sets all the properties, and then use inheriting ClassB() and ClassC() that have their own methods? What if I want ClassD() that works on ClassB() and ClassC()? inheriting here seems like ClassD() now has all of B and C's methods that it doesn't need
The tricky decision is what to do if the two classes only have some attributes in common, but not all. A Dog and a Closet both have a "volume" and "coat" attribute, but they have many other things not in common, and you would not want them to be anywhere close to one another on the inheritance tree
It sounds like maybe you need a processor class that doesn't inherit from the data class, and that has methods that take an instance of the data class and return a processed instance, so you can chain them
this sounds like a "has a" or "uses" relationship more than an "is a"
20:06
Ok that actually does help a lot. yeah D is not really "one of" B or C, so inheriting would be weird. and yes keeping track of what attributes actually make sense where is part of the headache!
20:26
hello
cabbage
hi I need help with a piece of code i'm trying to built
i don't think its that important to post a question for it so i'll just ask here
from time import sleep as t
from subprocess import run as r
r('', shell=True)
print('\n Terminating program\n\n '+'\033[34;1m'+'\u25A1'*15+'\033[15D', end='')
for ex in range(15):
print('\u25A0', end='')
t(1)
print('\x1b[0m')
exit()
when i run that instead of changing the empty boxes to filled one by one it waits for 15sec and replaces them all at once
what am i doing wrong
??
or is my laptop just trolling me?
can I ask about django here?
@NickVen try throwing a sys.stdout.flush() after that print statement in your for loop
20:35
@GabrielMendez Check out the room rules, and ask away, no need to ask to ask
Woah, from time import sleep as t? What is this, are we doing code obfuscation?
lol too bored to write time.sleep every time
oh i had a line above that "from os import system as s"
@NickVen add flush=True to your print calls
well it did work with that sys.stdout.flush()
Go with Aran-Fey's answer, I forgot that was a thing
20:38
ok
and it's a lot nicer and doesn't require you to import sys
as... y?
Might as well throw in a p = print for good measure
hahah
why not
On behalf of everyone who ever has to touch your code, for the love of yams do not import common modules as single letters
DSM
DSM
The lengths some people will go to to avoid having to write return:
20:41
don't worry i'm the only one reading it anyway.. XD
DSM
DSM
x=lambda x : x.isnull().sum()
x.__name__='countNAs'
does't work when i put flush = True
oh never-mind i made a typo
works now
dun dun dunn
:insert hamster meme:
@DSM what is this?
20:45
thanks for everything
@MoxieBall an abomination
what it do
def countNAs(x): return x.isnull().sum()
well not exactly, because it's bound to the name x
what's the purpose/effect of overwriting __name__ on a lambda?
To pretend that it's a full function? I don't know
the first line alone is bad enough
20:49
yuck
DSM
DSM
This, which startled me.
talk about shoehorning
I'll wait a few hours before downvoting so they don't think it was you :P
that'd be a silly assumption, considering the number of upvotes on DSM's comment
silly assumptions and silly code may correlate
DSM
DSM
Certain people are pretty good in general but have a habit of gunning suboptimal answers.
21:12
guyz where I can about expression
{n : v for n, v in zip(smth.target_names, np.bincount(smth.target))}
what is {n : v for n ?
it's called a dict comprehension, and the "for n,v in zip(...)" part is partly called unpacking
it's a combination of two language features
thx
let me know if that's insufficient to follow along
okay
21:41
@AndrasDeak They fixed it... by adding DSM's code to the end of the answer, but leaving that stupid named lambda in place.
I know, thanks; already left a comment
so bitter
Success!
@PM2Ring ... named... lambda??
21:46
named twice
what the yam
Apparently pandas uses a function's __name__ as a column header and OP thought that was the best way to get a function named that?

« first day (2813 days earlier)      last day (2360 days later) »