Python 2 backup output

I have a python module with python 2 fallback reserve installed with try / catch.

try:
    from urllib.parse import urlencode
except ImportError:
    from urlib import urlencode

When I pylint the file, I do not get the name 'urlencode' in the module 'urllib' and similar errors. In any case, to indicate python 2 linting for the block, disable all drag and drop for the block, or am I stuck in my hand, wriggling all the errors?

+4
source share
1 answer

I settled on this better by disabling jumper errors at the beginning of the python 2 block, and then turning them back on at the end.

# pylint: disable=no-name-in-module, import-error
from urllib import urlencode
from urllib2 import urlopen
# pylint: enable=no-name-in-module, import-error
0
source

Source: https://habr.com/ru/post/1608531/


All Articles