Difference between io.open vs open in python

Situation in Python3 according to the docs: io.open(file, *[options]*) This is an alias for the builtin open() function. and While the builtin open() and the associated io module are the recommended approach for working with encoded text files, this module [i.e. codecs] provides additional utility functions and classes that allow the use of a wider … Read more

Converting number in scientific notation to int

Behind the scenes a scientific number notation is always represented as a float internally. The reason is the varying number range as an integer only maps to a fixed value range, let’s say 2^32 values. The scientific representation is similar to the floating representation with significant and exponent. Further details you can lookup in https://en.wikipedia.org/wiki/Floating_point. … Read more

Reading binary data from stdin

From the docs (see here): The standard streams are in text mode by default. To write or read binary data to these, use the underlying binary buffer. For example, to write bytes to stdout, use sys.stdout.buffer.write(b’abc’). But, as in the accepted answer, invoking python with a -u is another option which forces stdin, stdout and … Read more

Python requests – Exception Type: ConnectionError – try: except does not work

You should not exit your worker instance sys.exit(1) Furthermore you ‘re catching the wrong Error. What you could do for for example is: from requests.exceptions import ConnectionError try: r = requests.get(“http://example.com”, timeout=0.001) except ConnectionError as e: # This is the correct syntax print e r = “No response” In this case your program will continue, … Read more