简体   繁体   中英

Writing cross-compatible python2/python3 code in pycharm

I've taken care to make sure library works on both python2 and python3, but pycharm adds some vexatious red squiggles as seen below

在此输入图像描述

If I switch the project interpreter to python 3.5 instead, the nag just moves onto the other import. Which inspection is this? I want to turn it off.

Although it doesn't solve the issue for all cases, you can solve this particular problem by using the future package.

As you can see here , the future package provides its own version of builtins for python 2 and python 3. By relying on this package instead of doing it yourself, you can import future 's implementation of builtins, thus removing the problematic code and avoiding Pycharm's (erroneous) error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM