Fri, Jan 10, 9:12 PM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Dec 02 3:16 pm)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: [File]-[Run Python Script] issue?


jadeite123 ( ) posted Sat, 16 January 2021 at 5:36 AM · edited Fri, 10 January 2025 at 9:06 PM

When I run a script with [File]-[Run Python Script] on the Windows version of 12.0.340, I get an error.
It seems that the error occurs depending on the pathname.

D:\usr\poser\scripts\test.py

import sys
print(sys.version)

Results

File "", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated uXXXX escape
3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]


Is "\usr" in the pathname interpreted as an escape in the internal process....?
Changing the pathname to "D:\poser\scripts\test.py" works fine.


adp001 ( ) posted Sat, 16 January 2021 at 6:24 AM · edited Sat, 16 January 2021 at 6:24 AM

Same error if you write

print("Something")

a line before

import sys

?

If not, "sys.version" seems to return a bytearray and "print" cant use that as is.

(Can't check it myself because no P12 here)




jadeite123 ( ) posted Sat, 16 January 2021 at 6:50 AM

adp001 posted at 6:39AM Sat, 16 January 2021 - #4410436

Same error if you write

print("Something")


Thank you for your response.
I tried as follows.

script

print("!!! test !!!")
import sys
print(sys.version)


Results (D:\usr\poser\scripts\test.py)

File "", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated uXXXX escape
!!! test !!!
3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]


Results (D:\poser\scripts\test.py)

!!! test !!!
3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]


The results are the same as before.


FVerbaas ( ) posted Sat, 16 January 2021 at 8:44 AM · edited Sat, 16 January 2021 at 8:45 AM
Forum Coordinator

As code it works fine for me from a location with similar path.

Schermafbeelding 2021-01-16 154125.jpg

Solution: Try to copy your code to notepad and save from there in a new file.

I have had similar issues with code I copied from a conversation in Slack. In my case that had left some non-printable chacarcters. Notepad is not sophisticated enough to deal with those so it just filters them out.!


jadeite123 ( ) posted Sat, 16 January 2021 at 10:15 AM · edited Sat, 16 January 2021 at 10:21 AM

FVerbaas posted at 9:57AM Sat, 16 January 2021 - #4410453

Solution: Try to copy your code to notepad and save from there in a new file.

Thank you for your response.
I created a new script by copying and pasting on Notepad, but the trouble was not solved.

D:\usr\poser\scripts> type test.py         * <- old script
print("!!! test !!!")
import sys
print(sys.version)

D:\usr\poser\scripts>
D:\usr\poser\scripts> type test2.py        * <- new(copied) script
print("!!! test !!!")
import sys
print(sys.version)

D:\usr\poser\scripts>
D:\usr\poser\scripts> fc /b test.py test2.py
Comparing files test.py and TEST2.PY
FC: no differences encountered


D:\usr\poser\scripts>
D:\usr\poser\scripts> certutil -dump test.py
  0000  ...
  0037
    0000  70 72 69 6e 74 28 22 21  21 21 20 74 65 73 74 20   print("!!! test
    0010  21 21 21 22 29 0d 0a 69  6d 70 6f 72 74 20 73 79   !!!")..import sy
    0020  73 0d 0a 70 72 69 6e 74  28 73 79 73 2e 76 65 72   s..print(sys.ver
    0030  73 69 6f 6e 29 0d 0a                               sion)..
CertUtil: -dump command completed successfully.

D:\usr\poser\scripts>


Results (D:\usr\poser\scripts\test2.py)

File "", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated uXXXX escape
!!! test !!!
3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]


Results (D:\poser\scripts\test2.py)

!!! test !!!
3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]


That seems to be a problem that depends on my environment.
I would like to solve it by using "D:\poser\scripts".


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.