Forum: Poser Python Scripting


Subject: Py2 to Py3 conversions

structure opened this issue on Nov 08, 2020 ยท 6 posts


structure posted Sun, 08 November 2020 at 10:31 AM Forum Coordinator

A thread to assist in the conversion of python 2 to python 3. Anything you come across that you have found a conversion for can be placed in this thread. examples

python 2 : 
print x 
Python 3:
print( x )

python2 
wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
python3:
wx.SystemSettings().GetFont(wx.SYS_DEFAULT_GUI_FONT)

python2:
outfile.write( "[advanced]" + "\n")
python3:
outfile.write( bytes("[advanced]" + "\n"), encoding = 'utf8' )

Locked Out


adp001 posted Sun, 08 November 2020 at 10:52 AM

The standard Python way works fine for file writing:

with open("test.txt", "w") as fh:
    for idx in range(10):
        print(f"Line {idx}: Test", file=fh)  # The 'f' prefix means: format, Py3 only.

with open("test2.txt", "w") as fh:
    for idx in range(10):
        fh.write(f"Line {idx}: Test\n")




Dizzi posted Sun, 08 November 2020 at 1:03 PM

https://wxpython.org/Phoenix/docs/html/MigrationGuide.html https://docs.python.org/3/howto/pyporting.html



structure posted Sun, 08 November 2020 at 11:45 PM Forum Coordinator

Thanks Dizzi - useful info :)

Locked Out


Dizzi posted Thu, 19 November 2020 at 8:26 AM

If you saved objects with pickel in older poser versions and want to load them in Poser 12 you will have to do something like that:

with open(filename, "r") as fd:
 lines = [line.rstrip("rn") for line in fd.readlines()]
 result = pickle.loads(bytes("n".join(lines), encoding='Latin 1'))



3dcheapskate posted Wed, 11 May 2022 at 9:55 PM

Can we make this thread a sticky/pin/whatever-you-call-it ?


The 3Dcheapskate (also available in DAZ and HiveWire3D flavours) occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.