“OverflowError: Python int too large to convert to C long” on windows but not mac

You’ll get that error once your numbers are greater than sys.maxsize: >>> p = [sys.maxsize] >>> preds[0] = p >>> p = [sys.maxsize+1] >>> preds[0] = p Traceback (most recent call last): File “<stdin>”, line 1, in <module> OverflowError: Python int too large to convert to C long You can confirm this by checking: >>> …

Read more

When using pathlib, getting error: TypeError: invalid file: PosixPath(‘example.txt’)

pathlib integrates seemlessly with open only in Python 3.6 and later. From Python 3.6’s release notes: The built-in open() function has been updated to accept os.PathLike objects, as have all relevant functions in the os and os.path modules, and most other functions and classes in the standard library. To get it to work in Python …

Read more

Catch all routes for Flask [duplicate]

You can follow this guideline: https://flask.palletsprojects.com/en/1.1.x/api/#url-route-registrations from flask import Flask app = Flask(__name__) @app.route(“https://stackoverflow.com/”, defaults={‘path’: ”}) @app.route(‘/<path:path>’) def catch_all(path): return ‘You want path: %s’ % path if __name__ == ‘__main__’: app.run()

Can I get an item from a PriorityQueue without removing it yet?

If a is a PriorityQueue object, You can use a.queue[0] to get the next item: from queue import PriorityQueue a = PriorityQueue() a.put((10, “a”)) a.put((4, “b”)) a.put((3,”c”)) print(a.queue[0]) print(a.queue) print(a.get()) print(a.queue) print(a.get()) print(a.queue) output is : (3, ‘c’) [(3, ‘c’), (10, ‘a’), (4, ‘b’)] (3, ‘c’) [(4, ‘b’), (10, ‘a’)] (4, ‘b’) [(10, ‘a’)] but …

Read more

Using print() (the function version) in Python2.x

Consider the following expressions: a = (“Hello SO!”) a = “Hello SO!” They’re equivalent. In the same way, with a statement: statement_keyword(“foo”) statement_keyword “foo” are also equivalent. Notice that if you change your print function to: print(“Hello”,”SO!”) You’ll notice a difference between python 2 and python 3. With python 2, the (…,…) is interpteted as …

Read more