This code: will raise TypeError on 3.5.2: whereas it runs fine on 3.6. Same problem if I spell out Optional as Union[None, Type[Foo]]. Is there any workaround for 3.5.2, while still accurately annotating the return type? Answer This is a bug in Python 3.5.2. Optional[cls] is a wrapper for Union[cls, type(None)], which uses __subclasses__() to establish whether one class is
Tag: python-3.x
python: codingbat no_teen_sum – why my function isn’t working as expected?
Below is the code I used for the no_teen_sum and subsequent fixed_teen functions. The first code is what I submitted – and worked for all test cases: And the fix_teen function that is called: However, looking at this I saw a lot of repitition and realized maybe I had misread what the question was asking. It was valid in terms
Cannot install openCV 3.1.0 with python3. CMAKE not including or linking python correctly
I’m trying to get OpenCV 3.1.0 installed with Python3 on my machine. Because I have Ubuntu 16.04, I am following this guide exactly: http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/ However, I have trouble in step 4, after running cmake. The output of my cmake program has this snippet: The cmake file doesnt seem to properly link the missing properties under the python section (libraries, numpy,
How to redirect from a view to another view In Django
This is a view written for my posts app in Django. The problem is that after filling the update form and submitting it happens successfully. But it creates confusion for the user because the same HTML page is there and how can I redirect into the updated object? Answer You can use redirect from http shortcuts. Here is the link
Create a Full Text Search index with SQLAlchemy on PostgreSQL
I need to create a PostgreSQL Full Text Search index in Python with SQLAlchemy. Here’s what I want in SQL: Now how do I do the second part with SQLAlchemy when using the ORM: Answer You could create index using Index in __table_args__. Also I use a function to create ts_vector to make it more tidy and reusable if more
How can I get multiple lists as separate results from a list comprehension?
Suppose I have this code: How can I neatly get a result like this? Answer Note that return 2*x,x is short for return (2*x,x), i.e. a tuple. Your list comprehension thus generates a list of tuples, not a tuple of lists. The nice thing of zip however is that you can easily use it in reverse with the asterisk: Note
Python 3.6 install win32api?
This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. Is there a way to install the win32api module for python 3.6 or do I have to change my version of python? Everytime I try to install it using pip I get the following error: Answer Information
Error UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte
https://github.com/affinelayer/pix2pix-tensorflow/tree/master/tools An error occurred when compiling “process.py” on the above site. Traceback (most recent call last): What is the cause of the error? Python’s version is 3.5.2. Answer Python tries to convert a byte-array (a bytes which it assumes to be a utf-8-encoded string) to a unicode string (str). This process of course is a decoding according to utf-8 rules.
Representation of all values in Flag enum
I would like to have a “ALL” flag in my python Flags enum for which holds true. I currently have: Because this enum might grow at any state of development I would like to have something like This does not work: Please note that this question currently only relates to python 3.6 or later. Answer There are a few ways
Using openpyxl module to write to spreadsheet creates a damaged spreadsheet, how to fix with zipfile module?
I have a program which writes to a spreadsheet using openpyxl. Upon execution of the program, the cells are filled as expected but the spreadsheet becomes damaged. Excel repairs the spreadsheet and I can then view it again. I have tried using the Open XML SDK Productivity Tool from Microsoft to compare a good and bad file with each other