Jump to content
Krion

Python 3, using old Python 2 scripts

Recommended Posts

Hi,

I have just installed the Python 3 version of Houdini to test out if I can use old code with it. I had read something about an included convert-script.

My own shelf tool which references an old python script in an own PYTHONPATH of mine produces this error:

6048e5ccf3a9c_Screenshot2021-03-10at16_27_49.png.4a85781dc1da68c81b8b75436d1aea16.png

Do I need to rewrite all my old code?

Thanks,

Share this post


Link to post
Share on other sites

There is no such a big difference between Python2 and 3, so re-writing should not be hard. 

In Python 3 "print" is not a statement anymore, it is a function, which means you have to place everything in parentheses: print ('Hello, World!')

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/10/2021 at 7:41 AM, kiryha said:

There is no such a big difference between Python2 and 3, so re-writing should not be hard. 

In Python 3 "print" is not a statement anymore, it is a function, which means you have to place everything in parentheses: print ('Hello, World!')

This is simply not true. There's a huge difference between python 2 and 3. There's a reason why there's still massive amounts of Python 2 code around even after 12 years since Python 3 came out.

Changes to import mechanics, strings and unicode, iterators, metaclasses just to name a few. Switching to Python 3 is not trivial.

For simple scripts, converting manually is a reasonable option, for bigger projects I use this tool: futurize

Quote

Do I need to rewrite all my old code?

Check out this guide: https://docs.python.org/3/howto/pyporting.html

Edited by Stalkerx777
typo
  • Thanks 1

Share this post


Link to post
Share on other sites
18 hours ago, Stalkerx777 said:

There's a huge difference between python 2 and 3.

My bad, you are right. But I was assuming the script is quite simple, and in that case, I guess it can be easy to update.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×