Krion Posted March 10, 2021 Share Posted March 10, 2021 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: Do I need to rewrite all my old code? Thanks, Quote Link to comment Share on other sites More sharing options...
kiryha Posted March 10, 2021 Share Posted March 10, 2021 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!') Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted March 16, 2021 Share Posted March 16, 2021 (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 March 16, 2021 by Stalkerx777 typo 1 1 Quote Link to comment Share on other sites More sharing options...
kiryha Posted March 17, 2021 Share Posted March 17, 2021 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. Quote Link to comment Share on other sites More sharing options...
warnerarc Posted July 27, 2021 Share Posted July 27, 2021 If you are a beginner then I would suggest you to just learn Python3 as Python3 will take over Python2 by 2020. But, if you are interested in just the differences than I can tell you a few common difference a beginner should know like - Python 2 vs Python 3 : In Python2 print is like a command but in Python3 print() is a function In Python2 the integer divide works in C/C++ style but Python3 will return the expected result. For example, In Python2 7/2 will return 3 but in Python3 it will return 3.5 In Python 2, a string is by default ASCII. But in Python3 string is by default Unicode Quote Link to comment Share on other sites More sharing options...
GDonkey Posted September 1, 2021 Share Posted September 1, 2021 (edited) Hi there, I'm very new to learning Python and am running the latest version of Houdini with python 3. I was trying to run a simple command from a tutorial ( but it's py2 ) . I figured out that you have to now do print("stuff"). In the tutorial When I run the code with what I thought would be the correct change to syntax: import hou my_obj_context = hou.node('/obj') my_geo = hou.node('/obj/geo1') print (my_geo.children) I get the following result: <bound method Node.children of <hou.ObjNode of type geo at /obj/geo1>> When I try in an older version of Houdini with py2 I get the actual list of nodes ( but with print my_geo.children() ). I can't seem to find any tutorials or guides that can help me get into using python in houdini with version 3 and above. Any advise is welcome. Edited September 1, 2021 by GDonkey I'm bad at links :P Quote Link to comment Share on other sites More sharing options...
pezetko Posted September 2, 2021 Share Posted September 2, 2021 23 hours ago, GDonkey said: print (my_geo.children) I get the following result: <bound method Node.children of <hou.ObjNode of type geo at /obj/geo1>> When I try in an older version of Houdini with py2 I get the actual list of nodes ( but with print my_geo.children() ). Hi, you forget to call the method. print (my_geo.children) prints that method object. Not calling it. You need: print(my_geo.children()) 1 Quote Link to comment Share on other sites More sharing options...
GDonkey Posted September 3, 2021 Share Posted September 3, 2021 Thank you so much ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.