If migrating from 2 > 3 permanently, usually we can remove weird workarounds. ![]() I’ve seen all sorts of weird things done around these issues, so I don’t have a recipe on how to fix this. Believe it or not, dealing with different types of strings, particularly mixed-use of Unicode and strings, was one thing that gave me the biggest headaches in Python 2, so this is a change I welcome with open arms. Python 3 threw away the differences and now has a single string class, plus a new binary class (bytes). Python 2 has a few object types to deal with words: basestrings, strings, Unicode. It will still work in py2, albeit slightly less efficiently. The fix is to replace every use of xrange() by range(). In Python 3, they put the optimizations of xrange and put them directly in range, then removed xrange. In Python 2, while range() is working, it was somewhat inefficient, and when I was learning Python a decade ago, xrange() was recommended, as it was more efficient. TLDR: Either add parentheses around the stuff to print or delete the whole line. Typing print(“hello world!”) would print a Tuple containing the string “Hello World!” and that’s totally fine by me.Īlso, I find that many print statements aren’t really that useful and were likely added while coding as a way to debug and keep track of things, so the other solution is to remove the line entirely. Worse, Python 2.7 does not by default support the print function, so if we were to replace print statements with print functions, it could change the code’s meaning on older versions of Nuke. It’s not a huge change, but print statements are so commonly used that this will possibly be annoying. print statementīy far, the most common error you will run into is about the print statement that was replaced by a print function. As more errors get discovered, I’ll update this list. Feel free to add more in the comments or ask questions here or on the Nuke forum. I can’t list all errors possible, but I’ll list below the errors I run into as I fix my own projects. The results will now show up, sometimes with tips on how to solve the issue. We’ll make a new inspection profile (2) in the next step.Īt the top, duplicate your current profile, rename it, then modify it as desired.Īfter you click OK, it brings you back to the Inspection Dialog, where you can hit OK to run the inspection. I also want to focus on Python3 errors, none of the other warnings that may show up. We want to inspect the whole project (well, I do, but you do you). ![]() Let’s try to use the code inspection tool of P圜harm: Converting old codebases could still be tedious, so let’s look at a more efficient option: ![]() ![]() This is great while writing code, as it will highlight incompatible code right away. This will now highlight code that is not compatible with both Python 2.7 and 3.7 (The version targeted by the VFX reference platform for 2020). In Pycharm, you can enable code compatibility inspection: Using Pycharm for helpĪs often, when working with Python, a good IDE can help. We could now open that file, fix the error, launch Nuke, find the next error, open, fix, launch, find, etc… Depending on how many packages you have installed, it could take a while. Oh no! Another error! We really didn’t expect that to happen, did we? After opening the file and doubling my slashes, I can now retry to open nuke: This could have been a disaster in Python 2 as well, but somehow it worked. For Windows path, it’s recommended to use \\ instead of \ as backslashes are a special character and are used to escape other characters. In this case, this was mostly a bad line of code. The content of my terminal upon my first launch of Nuke 13
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |