« first day (2921 days earlier)      last day (2027 days later) » 
00:00 - 21:0021:00 - 00:00

12:51 AM
I know im rather new but is this real syntax i have never seen this
-2
Q: Randomly pick numbers from one function to another

Mass17Sorry for my ignorance in Python and programming in general. I am testing a function similar to this; def test1(self): return x # This returns a set of numbers. e.g [1, 5, 7, 8, 12] def test2(self, a, b): # now I want to pick two numbers randomly from test1 into the function test2 functi...

 
 
2 hours later…
2:35 AM
@vash_the_stampede test1.[n] is invalid. Those functions have a 1st arg of self, which is conventional in definitions of the methods of a class, but the OP hasn't shown us the rest of the class, and they may just be confused. BTW, your version of the test1 function is pointless. Mind you, the OP's version isn't that hot either. ;)
 
Yeah I was trying to run with whatever he had going he wanted to pass the variable straight through I just wanted to show him how to make what he was doing work
I have a good bit of knowledge in classes and fuctions that’s why I was curious I knew the OP was brand new but I wanted to make sure I didn’t miss out some magical operations like test1.[]
 
 
2 hours later…
5:05 AM
from collections import Counter

lst = [6,5,4,3,3,3,3,3,3,3,3,3,1,7,7,7,7]
k = Counter(lst).most_common(1)[0][1]
res = sorted(lst[:k], reverse=True) + sorted(lst[k:])
print(res)
# [9, 9, 1, 2, 3, 4, 7, 7, 10, 10]
what complexity is this?
 
5:50 AM
hi guys, little help here

    "I don't want to put unknown encodings of group image in to a classifier"

    what i did was find Matches for each of the encoding and trying to remove encodings with matches=0


    for encoding in encodings:
         matches =np.count_nonzero(face_recognition.compare_faces(data["encodings"],
         encoding))
         d["encods"]=[matches,encoding]

    for k,v in list(d.items()):
    if v[0]==0:
    del d[k]

    print("dict",d)
 
cbg
 
6:42 AM
cbg
@PM2Ring Good point, seems like i have to go back to test with isinstance.. the try except was just so short and sweet =)
 
7:26 AM
Cabbage @Jerry :-) Long time
 
7:42 AM
yea @thefourtheye I'm back xD was busy with some business travel and lots of work and lost the habit of visiting SO as a whole
it's a bit better now :3
and I started learning python for real now, so I'm checking some questions out when I get some time to see how much I can attempt solving lol
 
It must have been long because I don't remember seeing you
 
yea, 3 years maybe xD
that's when I started travelling
that's also when I stopped posting on SO regularly
 
wb =D
 
melon! xD
 
8:08 AM
@Jerry Its really good to have you back here :-)
Does my evil twin know that you are back? cc @JonClements
 
8:24 AM
@thefourtheye me the evil twin?... you need to stop spreading that rumour you evil puppy :)
And yeah... I said hello to our favourite mudkip yesterday :)
 
Yay, we all caught up then :-)
 
9:02 AM
-1
Q: C programming: A pyramid with asterisks

Devin MorlanWhat am I doing right? I am trying to learn a function. This should be like this output: * *** ***** ******* My code: #include <stdio.h> #include <stdlib.h> void pyramid (int n) { int width = 0; if ( n ) { ++width; pyramid( f, n - 1 ); for ( uns...

amazing...
cbg @Jerry
 
cbg antti
 
10:07 AM
anyone used twisted library?
 
> Ask your question directly. Avoid asking if it's okay to ask, or if anyone knows about a topic. Users may want to see your question before speaking up, and users who join later can see it.
 
I have written basic code which uses socket to listen to a port. When a request comes, it forks a new thread using multiprocessing module and then handles the request in that thread. How can we do this using twisted library? Any link? Or this is default behavior in basic twisted implementation: twistedmatrix.com/documents/current/core/howto/…
 
10:57 AM
cbg all
Does pipenv lock regularly hit gigabytes of downloads or is this indicative of a bug?
 
11:33 AM
Hello
First time here, so nice to see we have a SO chat
 
Welcome :)
 
11:47 AM
https://stackoverflow.com/questions/52789325/how-to-set-size-of-hidden-state-vector-in-lstm-keras

Anyone? Completely lost here...
 
@yaminigoel I added the python tag which might help with visibility. I don't know keras but your question seems quite short compared to usual. Are you certain all necessary information is included to clearly define your problem?
your question has only been viewed 22 times in 2 days so the primary problem is probably visibility
 
@AndrasDeak I am completely new to keras and NN, I just wanted to know how to set the variable so I think that's all the required info...
 
Well I have added my reason of confusion
let's see, someone may come to my rescue
 
let's hope so :)
 
12:05 PM
IANAKE but the q could have more info in it... @yaminigoel
 
("I am not a keras expert" for those wondering)
 
@AnttiHaapala more info like? I don't know what more can I add to explain my problem properly...
 
@yaminigoel (not a keras expert either, but) I don't see an actual problem in your question. It would be best if you could showcase a concrete example where not knowing what the parameter controls leads to a wrong result, or something like that.
 
That's another ques, I am pretty sure that the problem is bcz of the vectors
but since I am not 100% sure I cannot say that
 
That question looks a lot more answerable (by someone who is not me and knows more ab about the matter) to me.
 
12:12 PM
Also, I have asked ppl(the prev ques) on quora and they claim this is how you set it, so I just don't have anything to prove
 
It's notoriously hard to get good answers in the ML section of python and stackoverflow in general, because examples are so hard to reproduce, and often require not only understanding to code, but also the data
Not to discourage you, but that's unfortunately how it is
 
exactly! And here I am just a grad student, completely new to NN with noone to help
 
@yaminigoel you need to read books, articles (the literature) and experiment :D
that's what you ought to learn at the uni :D
 
Yaa... :(
 
notice that when you're doing your thesis, it doesn't look good if you cite N00b, F. M. (October 2018). Error when checking target: expected simple_rnn_1 to have shape (20, 50) but got array with shape (3, 1). Retrieved from https://stackoverflow.com/questions/52794689/error-when-checking-target-expected‌​-simple-rnn-1-to-have-shape-20-50-but-got
 
12:19 PM
Lol! true that
 
... though... at least those questions on Stack Overflow that I see might be peer-reviewed more scrupulously than the standard journal articles ;)
4
... because we get Internet Points and VP from it.
@yaminigoel in the other q you should really have the input sample and also expected output - what are you trying to do? classify samples?
 
Getting it...I
 
cbg
Having fun with unicode identifiers: gist.github.com/ptmcg/391d46d4df8fe35b28e5982f1864482b
中文 = Chinese = object()
漢字 = Kanji = object()
カタカナ = Katakana = object()
ひらがな = Hiragana = object()
日本語 = Japanese = object() # will be the union of Kanji, Katakana, and Hiragana
한국어 = Korean = object()
# CJK will be the union of Chinese, Japanese, and Korean
Ελληνικά = Greek = object()
кириллица = Cyrillic = object()
ไทย = Thai = object()
العربية = Arabic = object()
I'm setting up character ranges in pyparsing
 
12:34 PM
https://chat.stackoverflow.com/transcript/message/44267741#44267741

anything ? :(
 
@anir Have you tried any of the Twisted tutorials? Twisted (and async programming in general) is a different mindset from threading.
 
@PaulMcG nice:D
 
What I've stubbed in as simple object()'s will be namespace classes with lazily initialized class attributes for alphas, nums, alphanums, and printables.
 
>>> bắp_cải = 'cabbage'
@PaulMcG having fun and RTL in LTR don't mix.
 
yup just tried the basic chat client server example. Yes it involves creating protocol, handling its various events etc.

Do you mean twisted is unsuited for my scenario?
 
12:42 PM
@anir Not at all - Twisted is/was very common in web service applications. But writing and working with Deferred's involves an inversion of control/thinking that takes some practice.
@AnttiHaapala Not familiar with these TLAs ???
 
right to left
 
Ah, the Arabic - yes, that takes some getting used to.
Wait! I left out Hebrew!
 
12:55 PM
Here is a nice table of the various Unicode ranges jrgraphix.net/research/unicode_blocks.php - I don't want to play favorites, but I just don't get a lot of requests from folks writing parsers in Unified Canadian Aboriginal Syllabics (not yet, anyway).
Fortunately the language-specific classes are just range definitions - all the property defns are done in a base class.
 
@PaulMcG as long as you support Dingbats - I'm cool :)
 
@JonClements You mean ✂✅✆✇✈✉✋✌✎✨❄❦❶?
(actually, that's probably not a valid Python identifier)
 
1:11 PM
class ಠ_ಠ(Exception):
 
In Dingbats, all the circled numbers return True for isdigit(), so I expect they would be legal in an identifier.
Correction: the circled 10's do not return True for isdigit()
 
Makes sense.
 
1:26 PM
I just want to do things like: ✇safe✇ = True :)
 
>>> ノºДºノ = 'flipping tables'
>>> class ノºДºノミ凵 (Exception):
...     pass
...
this one works
 
1:59 PM
\o cbg
 
On a recent question I wrote an answer pointing out a fairly common logic error (if a != b or c) and the OP self-deleted shortly afterwards. I'm not too rustled about that in itself, but I was just about to edit my post to point out an additional considerably more difficult-to-solve problem, but now I can't.
Or, I mean, I guess I could edit my now-deleted post, but the odds of that information getting to OP is pretty low.
 
they'll come back if they can't solve it
 
They'll post a new question and I'll answer it and they'll self delete, and the green grass grows all around
 
at least you are getting "exercise" :D
 
2:15 PM
@Kevin What is the more difficult problem related to not understanding (if a != b or c)?
 
It wasn't directly related. The post was Stuck in While Loop Python 2.7 and the additional problem was that they create prompt = '' outside of both while loops, which means that it will only ever prompt the user for input exactly once. Responding "y" to "Calculate another age?" will cause the program to calculate ages indefinitely, since prompt is permanently set to 'y' with no opportunity to reassign it.
"That doesn't sound considerably more difficult to me," the hypothetical reader thinks. Sure, a seasoned dev can fix this in an instant, but at OP's level it might be a bang-your-head-against-a-wall-for-hours tier problem.
 
Ah... so I guess users with some level of rep can see deleted answers? I cannot at the moment. The only good thing about a bang-your-head-against-a-wall-for-hours problem is the euphoria associated with the resultant "aha!" moment.
 
"surely even a beginner can pick out a logic error like that fairly quickly?". Depends on the beginner. The other two beginner-tier posts I've seen today are Python list error - int is not subscriptable [on hold] and String manipulation loops, which give me approximately zero faith in anything.
@W.Dodge Yeah, it's part of the 10k rep moderation tools
 
Awesome, I'll be able to see deleted answers when I'm fifty! Give or take a decade
 
... why can't I withdraw my reopen vote :( ...
"solved a bug I've been continuously working at since 1.5+ days now by simply reverting to non-cached session storage" - cbg
 
2:27 PM
ahhh... blaming caching... that old chestnut :)
 
that's what you get when you over optimise from the start :shrug:
eh, at this point I'm just happy it's gone, may try and dive deeper in future if needed (read as never)
 
premature optimisation, caching... you sure you haven't got an off by one error somewhere to make it a hat-trick? :p
 
pretty sure I only have this 1 issue only :-p
 
Back when I didn't understand memoization, I wrote a function that looked like
cache = {}
def frob(*args):
    key = hash(args)
    if key not in cache:
        result = complicated_expression_goes_here
        cache[key] = result
    return cache[key]
... And I was baffled when, every millionth call or so, the function would return a cached value even though I had never called it with those arguments before.
 
Hash collisions?
 
2:32 PM
Exactly.
Replacing key = hash(args) with key = args ranks up there in my worst time-spent-debugging to size-of-required-change ratio
 
morning cbg
 
2:51 PM
A recent question says, "I'm very new to python and lost when trying to reverse understand this". I love the concept of "reverse understanding".
 
morning cbg
 
recbg
 
Presumably the OP meant "reverse-engineering" but I prefer the mental image of frantically trying to forget facts you already know
 
Sounds like too much hard work... I can forget things without even trying :)
 
Reverse-understanding is what I do whenever I have to imagine what fundamental misconceptions the OP started with to arrive at their baffling question
 
3:14 PM
What's up?
 
Umm... a pixar film?
 
Indeed it is!
 
That took me four re-reads
and then I got it.
 
@AaronHall \o/... do I win a cookie? :)
 
Hmm, is there a str.format specifier to add leading zeroes to a float? E.g. specifier.format(-1.0) gives "-001.0".
 
3:19 PM
@JonClements I have some year-old gourmet cookies in my desk and I'll be happy to put your name on one.
 
It's easy enough to add pad characters to the left of any string, but then I'd end up with '00-1.0'
 
yum... still good
 
>>> "{:0=7.03f}".format(-1.0)
'-01.000'
Ah ha B-)
 
@AaronHall gourmet cookies with customisation... sounds good to me :)
@idjaw umm.. well... I've not been raiding your cupboards for coffee recently so you've no excuse :)
 
Hmm, but this is unsuitable for having exactly N digits before the decimal point, since positive numbers will have one more digit than negative numbers.
 
3:26 PM
They're like Nilla wafers but thicker and slightly chocolate, and in the shape of a heart.... My wife had a few, put them in our pantry, and now refuses to eat them, so I munch on one every week or so... :D
 
>>> "{:0=7.03f}".format(-1.0)
'-01.000'
>>> "{:0=7.03f}".format(1.0)
'001.000'
 
recbg
 
>>> "{:0= 7.03f}".format(1.0)
' 01.000'
>>> "{:0= 7.03f}".format(-1.0)
'-01.000'
Hmm, good enough.
 
I share you a French-speaking joke that I've invented discovered: int ceci_nest_pas_un_pointeur[3][3];
 
hello
 
3:31 PM
@Daniel howdy
 
@DanielNewell cabbage
 
i finally got enouh rep to talk here
 
morning cabbage
 
so does everyi=one here just talk about python?
 
3:32 PM
Once we've run out of other things to talk about.
 
Monty Python (also collectively known as the Pythons) were a British surreal comedy group who created their sketch comedy show Monty Python's Flying Circus, which first aired on the BBC in 1969. Forty-five episodes were made over four series. The Python phenomenon developed from the television series into something larger in scope and impact, including touring stage shows, films, numerous albums, several books, and musicals. The Pythons' influence on comedy has been compared to the Beatles' influence on music. Their sketch show has been referred to as "not only one of the more enduring icons of...
 
interesting
 
This python ^
 
most of the time we talk about everything else...
 
oh ok
i have a python question
 
@DanielNewell No need to tell us that you have a question - if you just ask the question, we can figure out that you had it
 
@PaulMcG I was just waiting for the actual question
 
Anyone ever have conversation deja vu?
 
Are you shivering with anticipation?
 
@AaronHall was it the same cat?
 
3:40 PM
Yeah.
 
@PaulMcG I'm avoiding actual work in anticipation.
@AaronHall sounds like a glitch in the Matrix to me
 
@DanielNewell What is your quest? ion?
 
In a recent question I commented "you're probably not calling this class' method until after the class exists". I wanted to write "you're definitely not calling..." but I wasn't sure if that's true in all cases. Is it possible to define a class containing a method that gets called before the class gets bound to a name? In other words, is it possible to complete this class definition so this code generates a NameError:
class Fred:
    #add additional methods and/or assignment statements here

    #this can be staticmethod or classmethod, if you want
    def troz(whatever parameters):
        #this should raise a NameError
        Fred
 
What if you add blurt = troz() to define a class attribute of Fred?
 
I thought maybe decorating it as staticmethod, and adding a = troz() after the method, would do it. But no, that gives TypeError: 'staticmethod' object is not callable. Doing a = Fred.troz() generates a NameError, but that's cheating, since I want troz to raise the NameError, not Fred.
@PaulMcG Like this?
class Fred:
    def troz():
        Fred
    blurt = troz()
That meets my criteria :-)
I'm surprised that this is possible. I didn't know that you could access non-decorated methods without it trying to perform self-binding magic.
I mean, obviously there's no instance to bind self to, but I didn't think Python was smart enough to notice
docs.python.org/3/reference/… implies that, before the class object is created, the body of a class behaves mostly like an ordinary scope. The big exception being that methods can't see names at the class scope.
But statements at the class scope can see methods, which is the important bit.
Ok, so TLDR: I was correct to say "probably" in that comment.
 
4:06 PM
today, is testing day...or rather finish-fixing-tests day
and these aren't really unit tests...they are more integration tests with selenium. So I get to sit here staring at my screen for like five minutes at a time while the tests run.
 
@Kevin yes it is
though you need a metaclass
 
Today is config day. And spotting bugs in the tests day - that upon fixing show more test failures...
 
done
 
Someone did a homework dump on the xkcd coding forum... forums.xkcd.com/viewtopic.php?f=11&t=125314
 
I'm not surprised xD
 
4:21 PM
@Kevin Yep. In fact, you can define a decorator inside a class definition, and then apply it to a method, if you want, since at that stage both the decorating & the decorated function are just seen as regular functions.
@Kevin Another option is to use troz to set a default arg of a method. (At least, I think that'd work. I'm on my phone, so it's not easy to test stuff.)
 
>>> class Fred:
...     def troz():
...         Fred
...     def zort(a=troz()):
...         pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in Fred
  File "<stdin>", line 3, in troz
NameError: name 'Fred' is not defined
Yep
 
Apparently to renew my driver's license this year I have to present in person because I'm a dangerous foreign national or something...this is new.
 
4:54 PM
Maybe they just wanted to hang out with you
 
5:31 PM
we always have to renew our driver's licenses in person :(
 
I had to go in person last time, but I don't think I did the time before that. Maybe it's a "once every N renewals" thing.
 
redundant answers from May and July.........
 
@Kevin here I think in-person renewal is required every other time
 
people redundantly reposting trivial answers really get my goat
 
wim
5:40 PM
Yeah the "protected" feature should be more like a restriction to 5k+ rep or something
it's usually some newbies doing that.
 
it's only against proper spammers
 
first time here. is it possible to ask quick questions here?
 
Yes
Funnily enough whenever anyone asks "can I ask a quick question?" it usually takes them upwards of five minutes to actually write it out
 
i have a bottleneck with my comparison and wanted to know if it can be parallelized
 
We've got one from today that's going on three hours now.
 
5:46 PM
2 for loops with enumerate and a final if comparison
lol mine is not 3 hours Kevin
 
user10043886
Hi, I had a query which I didn't readily find answered on Stack Overflow. Are bit operations like XORing large binary strings slower by a large margin in Python than in C?
 
user10043886
Could someone provide me references if possible
 
Python does not have a "binary string" type, and as far as I know, neither does C. Please clarify.
 
wim
you can't use ^ on string in Python, that's a TypeError
 
user10043886
@wim Let's say something like 0000101010101010110010101010101. Just a large binary integer (that's the terminology?). Not a string
 
user10043886
5:53 PM
C wouldn't support too large integers like that even in float afaik
 
Python has an integer type, but it does not have a binary integer type. There are binary integer literals, for example 0b1010 but those are represented as ordinary integers in memory.
>>> a = 123
>>> b = 0b1010
>>> c = 0xa123abc
>>> a
123
>>> b
10
>>> c
168966844
>>> type(a), type(b), type(c)
(<class 'int'>, <class 'int'>, <class 'int'>)
 
user10043886
@Kevin I see, interesting
 
user10043886
Are there any external packages which do support binary integers?
 
wim
you probably want a bytearray
 
user10043886
I basically need to pairwise XOR on several million 24-bit binary numbers
 
5:56 PM
Integers are already binary, more or less. Unless you're running on truly weird hardware.
 
user10043886
@Kevin But normal integer types take up more memory space I guess?
 
Ordinary integers can handle XOR just fine. And in fact I would expect XOR operations to run quite quickly on non-long integers
"non-long" here meaning "32 bits or less"
 
@Blue If you want to save RAM and time, use Numpy.
 
The slowdown part is where you say "pairwise ... several million..."
 
@Blue Certainly, a Python int takes up more space than a C int. Simply because every object in Python has additional overhead for tracking the object's type. That's just a consequence of the dynamic typing system.
 
user10043886
6:00 PM
Got it. Thanks!
 
@Starter One possible improvement is to redesign s so that it is a dictionary, not a list. You could have -HVC1 and -HVC2 as keys, and each value would be a list of tuples. Then instead of iterating over s in O(len(s)) time, you can directly access values in O(1) time. That's one less nested for loop.
 
@Starter You can make that comparison code more efficient by converting those numeric strings to int before you start the comparison loops. And do the m == i[0] test at the top of the m, n loop, before you enter the j, k loop.
 
Awesome @Kevin, I will try that now. @PM2Ring are you saying convert to int?
 
numpy.int64 can give you vectorized operations
oh, the point is that those binaries are large
 
@Starter So basically something like pastebin.com/2CXbbjGj. On my machine, this produces the output ['Contains', 'allons', '0gallons']. I notice that some of the strings are cut off, but I suspect that's a problem with the numbers in s, and not a problem with the algorithm.
I removed the enumerate entirely because you don't really need to manually go through every character of a string in order to create a substring out of it. You can just use regular old slicing.
 
6:08 PM
@AndrasDeak No, they're only 24 bit, so uint32 is probably fine. I guess they could be signed, but it's pretty unusual to do bitwise stuff on signed integers.
 
well np.int64 is signed
 
geez the questions are pouring in today I cant even read chat im like 20 tabs behind where I need to be :(
 
Now twiddling my thumbs waiting for Starter to tell me "you have incorrectly assumed that my real data is structured like my test data, in particular that every odd-numbered line starts with a hyphen and every hyphenated line appears in the dict. This is not always the case"
 
user10043886
Umm, another query: How would XORing two 24-bit binary numbers (say in bitarray format) using Python compare to XORing two 24-bit binary numbers in C (using say uint32), in terms of speed/performance?
 
user10043886
Should they be about the same?
 
6:12 PM
@Blue How are you getting those numbers into your program? Are you reading them from a file, or does your program generate them itself?
 
user10043886
@PM2Ring Reading from a file
 
@Kevin oh ok but I am trying to comparing something different in the link you sent me
 
Is it a text file, or are the numbers encoded in some binary format?
 
user10043886
@PM2Ring It's a text file
 
user10043886
Few more text files too actually
 
user10043886
6:14 PM
That's one sample
 
@Blue I would expect C to be faster. To pull a number out of thin air, let's call it... 50 times faster.
 
@Blue Ah. Ok. So strings of 0 & 1 chars, separated by spaces. I assume there's one 24 bit integer per line?
 
Numpy closes the gap considerably, but practically by definition a CPython program can't be faster than a C program that's doing the same thing
 
user10043886
@PM2Ring Yup
 
@Blue Python is always slower than C, so the trick is to use as little Python as possible :D
24 bits and there is no discussion, C is going to be way faster.
it is just one assembly opcode, period.
pypy could come close
 
6:18 PM
@AnttiHaapala "What are you trying to tell me? That I can write Python?" "No, Neo. I'm trying to tell you that when you're ready, you won't want to."
(also cbg)
 
No matter what you write this in, the XOR operation is relatively cheap, compared to converting those bit strings to integers. It might work out faster to just do the XOR bit by bit, especially if you want the output in the same format.
 
so a C program could easily xor 16 gigabytes per second on a modern processor.
 
user10043886
@AnttiHaapala How to use that? :P
 
if the data is in cache. The CPython ceval loop runs hundreds or thousands machine instructions per one python bytecode op
 
user10043886
6:26 PM
BTW could someone recommend me any text on memory optimization/usage of the various datatypes in Python and the overheads due to the objects, etc? Unlike C or Java textbooks, I couldn't find any text which deals with them thoroughly
 
wim
@Kevin They sure are faster to write though
 
@Blue There's sys.getsizeof(), which tells you the basic size in bytes of an object, but it's not recursive, so it won't tell you the actual RAM that's consumed by a list and all its items.
@Blue So what are you actually doing with that data? Do you just want a program that reads 2 files and does the XOR of a pair of corresponding lines? Or do you need to do something more complicated?
 
I kind of feel like you could have written a complete implementation of this project in C in the time this conversation has taken so far
 
user10043886
@PM2Ring I need to run the k-means clustering algorithm. The binary numbers are the nodes and the pairwise Hamming distances are the edgeweights
 
user10043886
@Kevin Hehe :) Implementing isn't my primary concern at the moment. I'm trying to learn a bit of how Python works
 
6:39 PM
@Blue In that case, write it in Python. The running time will be slower than C, but not hugely so if you use Numpy. But the development time will be much faster.
 
"Which language is faster for this very specific programming problem?" sounds very little like "trying to learn a bit of how Python works"
 
wiki.python.org/moin/TimeComplexity is a good overview of the complexity of operations of Python's basic types. It's not going to tell you how many seconds any particular operation takes, since that's pretty much impossible to measure objectively.
 
user10043886
@AndrasDeak It was obvious that C is almost always faster. The question was: by how much? I guess I got the answer now :)
 
user10043886
@PM2Ring Indeed, I'll do that now
 
Perhaps one important thing to learn about how Python works is: the priorities of the language and community. C might have a philosophy of "performance at the expense of all other things", and Python very much does not.
 
user10043886
6:43 PM
@Kevin Makes sense. Python sounds more useful from the faster development perspective
 
user10043886
and easier maintenance
 
One semi-reputable source that does actually time things is the n body benchmark. Looks like my "50x slower" guess was only off by a factor of two.
 
And I guess it makes sense to keep those binary numbers as separate numbers (eg uint8, or bytes in a bytearray, if using plain Python), since you want to be able to quickly count the number of 1 bits in a number. OTOH, there are reasonably fast ways in Python to do that popcount operation on smallish integers.
 
user10043886
@Kevin How do you read that page? What does the secs column stand for?
 
Seconds it took for the program to complete, presumably
 
user10043886
6:48 PM
I mean which program?
 
user10043886
secs = seconds, I can understand :P
 
user10043886
Oh, it's clickable
 
@AndrasDeak now we just need a honey badger
 
user10043886
@Kevin Aha, thanks
 
6:53 PM
Some good info about counting 1 bits in Python: stackoverflow.com/questions/9829578/… GMP is the winner, but the table-based algorithms are quite good, and they can be optimized further to handle 24 bit integers.
 
@Kevin Do you know if is there a more full list of this "leaderboard"? I see the ranks kind of get skipped past a point
 
If you're saying "hey how come the x column skips from 218 to 539, shouldn't there be a bunch in between?", I don't think that represents a ranking, but rather the ratio of runtimes of that row and the fastest implementation. Matz' Ruby #2 isn't the 539th fastest program, it's 539 times slower than C++ g++ #3.
 
ahh
all right
yea it makes more sense now xD thanks
 
I guess they don't want formal numbered rankings because that would be fairly easy to game, since one language can appear multiple times on the list. If the insidious cabal of Fortran programmers wanted to destroy Rust's reputation, they would only need to submit 999 Fortran implementations that are faster than Rust's one submission. Then Rust would be in 1000th place, despite being reasonably fast
 
*rubs hands insidiously*
 
7:04 PM
But in our universe, Rust would still be in 1.6th place, albeit it would be hard to tell without scrolling down a long way.
 
I've inherited a medium-sized codebase that uses a bunch of classes where there should be dicts. Lots of stuff like class SomeModuleConfig: # a dozen or fewer class attributes and that's all. I'm getting pushback on converting them to dictionaries because they like the dotted syntax for attribute access. How crazy is it to implement a DottedDict that inherits from dict but implements __getattr__ so dotted syntax still works?
 
isn't that what the fancy new dataclasses are for?
 
ooh what's that
 
@AdamSmith been there, done that.
actually it was nested dotted dict
 
7:13 PM
 
the 3 in that URL is also a problem right now.
I'm working on that.
 
supported both dictionary and attribute access for and to nested dicts to ['foo.bar'] = ['foo']['bar'] = .foo.bar
@AdamSmith wowo
 
@AdamSmith well I did say "new" :P
 
yeah, I hadn't heard of them -- I'm reading :)
 
the 3 in the URL is not a problem.
it is the solution.
 
7:15 PM
agreed
 
to the problem you have.
 
I quite like using dicts as plain old data containers, but replacing existing classes with dicts would be contrary to their primary selling point: they're less work. Rewriting things is more work than keeping things the way they are.
 
I wrote this up:
class DottedDict(dict):
    """Utility class to help transition from the abundance of special-case classes
    to a more uniform set of Python dicts, while retaining the dotted attribute access
    syntax the code base is currently using.
    """

    def __getattr__(self, key):
        try:
            return self[key]
        except KeyError as e:
            raise AttributeError(e.message)
    def __setattr__(self, key, value):
        self[key] = value

    @classmethod
    def from_class(cls, to_convert):
@Kevin decorating each class with @DottedDict.from_class shouldn't be bad
Honestly: most of this stuff should just be a yaml file
maybe I should approach it from that angle instead.
 
e.message should be str(e) for python 3 compat
 
@Aran-Fey thanks that's helpful :)
 
7:22 PM
@AdamSmith Config data is often immutable, so named tuples may be suitable. They can be indexed like plain tuples, or accessed using dot notation. Under the hood, a namedtuple is just a class instance, but it uses __slots__ instead of a dict for the attributes.
 
@PM2Ring I thought about namedtuples, but I'm not sure how the syntax would work. These are all singletons
 
Oh, ok. In that case, namedtuples aren't so useful.
 
module_config = namedtuple("SomeModuleConfig", "path_to_thing")("/some/path") is kind of icky.
 
lst = list(zip_longest(*[iter(lst)]*2))
lst = [[i[0]] if any(j == None for j in i) else [i[0],i[1]] for i in lst]
@PM2Ring I modified this to remove the None, how would you go about it ?
 
But yes, if the current code uses a bunch of singleton classes like that, it's a good sign that they should be dicts (or DottedDicts) instead.
 
7:26 PM
[1, 6]
[5, 3]
[4, 2]
[1]
for this expecation of course
 
any(j == None for j in i) seems like a roundabout way of saying None in i
 
Why not use something from this answer? stackoverflow.com/a/312464/2301450
 
@AndrasDeak those dataclasses look awesome. Maybe I should hold off on this change and float that as a carrot to get us onto Py3 ;-)
 
@vash_the_stampede The zip_longest technique is good if you want padding. Otherwise, just use a loop with range, like in vaultah's link. That's faster, and cleaner than adding padding that gets removed on the next line.
But anyway, lst = [i[:1] if i[1] is None else i for i in lst]
 
@AdamSmith It worked in my workplace to convince people to move from 3.5 to 3.7
 
7:40 PM
@vaultah that is a cool trick
 
not as significant, but many of the features dataclasses bring are of the type that python critics like. so you can bait them =)
 
@PM2Ring ty
 
7:50 PM
@Arne I'm the only python-focused developer in the windows shop I work in. They're not exactly Python critics, just writing Python like C#.
To their credit, they've deferred to my professional opinion about nearly every change I've suggested.
 
Don't they miss typing? in my experience, c# people always do
dataclasses have type hinting baked in
 
I saw, and frankly I miss typing :)
 
Python has typing, but only if you really believe
 
def my_copyfile(recursive: float) -> IOError:
 
@Kevin well - Python, having no fingers, does find typing awkward - does its best though.
3
 
7:56 PM
@JonClements oh is THAT why the duck does it?
 
user image
9
 
@AdamSmith Ouch, reading that line of code causes physical pain
 
wim
@AdamSmith don't reinvent the box
 
@wim hrm I'm not sure if that's not a little heavier-weight than I need, plus I currently have classes not dicts, so I'd have to rewrite a bunch of definitions
and install box on every developer's machine (because who uses requirements.txt anyway)
also on the "Give Adam Python3 Pleeease" list is venv...
 
user10043886
Is there anything equivalent to numpy.unique in ordinary python?
 
8:06 PM
@AdamSmith yes! :)
 
user10043886
(for lists)
 
and closed
 
wim
@AdamSmith installing 3rd-party code on other machine is no harder than installing your own code on other machine
 
@Kevin Caption: "Hey! What'd you think of my T-Rex impression!?" :p
 
wim
8:15 PM
Also your from_class implementation is bogus. It should return a DottedDict instance, not a functools.partial object.
 
"fun"
 
8:33 PM
@wim The answer above it from last year isn't brilliant, either.
 
wim
yeh, downvoted both
 
@wim No, it's decorating the class so it needs to return a callable that gives a DottedDict instance.
@DottedDict.from_class
class Foo(object):
    pass

# Foo() should be an instance of DottedDict, not Foo
and "installing 3rd-party code on other machine is no harder than installing your own code on other machine" is only true if we use a standard method of installing code on dev machines. There's DEFINITELY some stuff that needs changing here, but let me assure you that adding new 3rd-party dependencies will be considerably harder than adding 1st-party libraries.
 
00:00 - 21:0021:00 - 00:00

« first day (2921 days earlier)      last day (2027 days later) »