Forum: Poser Python Scripting


Subject: Floating point decimals and binary representation.

structure opened this issue on Aug 24, 2021 ยท 17 posts


odf posted Tue, 24 August 2021 at 6:41 PM

adp001 posted at 6:36PM Tue, 24 August 2021 - #4425963

bagginsbill posted at 8:28AM Tue, 24 August 2021 - #4425960

I cleaned up your function - it can be much simpler.

# make a new ( numbered ) copy of the original file
def uniquify( path, ext ):
    file_name = path + ext
    i = 0
    while isfile(file_name):
        i += 1
        file_name = path + "_copy_" + str(i/10) + ext
    return file_name

To make that work with Poser Versions != 12, you have to execute this first:

from __future__ import  division

If you don't you will get garbage with this function.

My preference is to use str(i / 10.0) which will work correctly in both Python 2 and 3. Similarly, I like to use the // in Python 2 because it won't break when one upgrades to 3.

-- I'm not mad at you, just Westphalian.