Fri, Nov 29, 12:31 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 Sep 18 2:50 am)

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: Best way to write this line?


pikusuru ( ) posted Mon, 16 October 2006 at 8:21 PM · edited Fri, 29 November 2024 at 10:42 AM

This is probably a stupid question but I would like your advice.  What's the best way to write this?

This:

<span style="background-color:rgb(255,255,255);">self.vertices.append(map(float,l.split(' ',1)[1].split()))</span>  

or this: vertex = l.split(' ',1)[1].split()
self.vertices.append(map(float,vertex))

or this: vLine = l.split()
vertex = vLine[1:]
self.vertices.append(map(float,vertex))

They are all meant to take the a string 'v 1.0 2.0 3.0' and return a list [1.0,2.0,3.0] where each item in the list has been converted to a float.

The first obviously takes up less space but isn't as readable.  Does it matter?

Thanks.


bushi ( ) posted Mon, 16 October 2006 at 10:02 PM

Of the three, I'd always go with the last style. I use to find it extremely frustrating to go back to a script months after writing it and have to spend a lot of time trying to figure out what I'd done earlier. Being more verbose and breaking steps up into individual lines helps that greatly. Also a nice comment block for each proc with an explanation of what it's suppose to be doing, what the inputs and outputs are and an overview of the intended algorithm are very useful when updating old code.


pikusuru ( ) posted Mon, 16 October 2006 at 10:20 PM

Thanks a lot.  You're right looking at that first line after some time would be kind of weird.


tromnek ( ) posted Tue, 17 October 2006 at 6:52 AM

If you want your scripts to be Poser Pro Pack compatible, then you also need to call string methods using the 'string' module instead of the object way. So;

vline = l.split()
    would become
vline = string.split(l)

Although, I understand that the 'string' module will (or has been) be depreciated and dropped in later python releases.
Maintaining Pro Pack compatibility can be a chore sometimes.


pikusuru ( ) posted Tue, 17 October 2006 at 9:20 AM

Thanks tromnek!  My future self thanks you for saving him from head bruises.


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.