weird problem with python & lists..


(kurppa) #1

whenever I try to print thing with a list (or maby some others also) as returntype Blender2.23 crashes and Blender 2.22&2.21 just print “[” in the shell window and leave it there… after that no output is shown in the shell window even if the script is run again… python version is 2.1.1…

for example:

import Blender

print Blender.Object.Get()
#should get a list of the objects in the scene “[…][…][…]…”

but in shell window just…

[


am I missing something here…? :-? or is this just a stupid no-can-do-bug or something…?


(mxopivypx) #2

I have the same problem on one of my computers…One thing that i may suggest is downloading and installing the full python package from www.python.org…Im not certain if that will fix it, but the computer that it happens to me with is the one that doesn’t have it installed.

That thing where it stops printing is a pain…but i you purposely cause an error at the end of the file everything that you tried to print before it is finally printed out.


(kurppa) #3

what do you mean by “full python package”? I downloaded 2.2.1 installer and installed it… still no good… :frowning:


(macke) #4

At the top:

import sys

At the bottom:

sys.stdout.flush()

IMHO, sys.stdout.write('string
') should be used instead of print, you can redefine print by:

print = sys.stdout.write

Then use print like you would use sys.stdout.write


(kurppa) #5

when I try

sys.stdout.write(Blender.Object.Get())

it gives me

“TypeError: read-only character buffer, list”

sorry if it’s just something obvious but what’s the problem now?


(theeth) #6

Macke: By definition, print IS sys.stdout.write

Kurppa: As far as I know, printing objects returned by the Blender modules often hang the console. Installing a full Python distro will not change anything (btw, you should use Python 2.01, not 2.11 since Blender is based on Python 2.0).

You should try one of these:


import Blender

ObList = Blender.Object.GetSelected()
for Ob in ObList:
        print Ob.name


import Blender

ObList = Blender.Object.GetSelected()
for Ob in ObList:
        print str(Ob)


import Blender

ObList = Blender.Object.GetSelected()
for Ob in ObList:
        print repr(Ob)

Martin


(kurppa) #7

thanks theeth! works now!