Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?

It is my understanding that the range() function, which is actually an object type in Python 3, generates its contents on the fly, similar to a generator. This being the case, I would have expected the following line to take an inordinate amount of time because, in order to determine whether 1 quadrillion is in … Read more

Convert bytes to a string

I’m using this code to get standard output from an external program: >>> from subprocess import * >>> command_stdout = Popen([‘ls’, ‘-l’], stdout=PIPE).communicate()[0] The communicate() method returns an array of bytes: >>> command_stdout b’total 0\n-rw-rw-r– 1 thomas thomas 0 Mar 3 07:03 file1\n-rw-rw-r– 1 thomas thomas 0 Mar 3 07:03 file2\n’ However, I’d like to … Read more