Pyhon script not working

I dont know why, but my print function in python does not work.

this is my test script:
`import maya.cmds as cmds
import sys

def todo():
sel = cmds.ls(sl=True)
sys.stdout.write(‘heloow’)
if len(sel) == 0:
sys.exit(“Not enought objects selected.”)
print sel
print (sel)
print 'asd: ’ + str(sel)

todo()`

I am using Maya 2019, the “sys.exit” does work, but none of the prints or sys.stdout.write functions.
Can somebody say why?

line 9:
print sel

you forgot the brackets.

I was testing different methods to print something because apparently nothing gives me output…
I tried without brackets, with brackets, only a string and a string + another object, nothing works…

I dont know why you invoke the sys module, when maya.cmds have error handle.
Is very funny, because your code.. is working to me.
I writed another code more optimized, i hope is helped for you.

`import maya.cmds as cmds

def todo():
sel = cmds.ls(sl=True)
if len(sel) == 0:
cmds.error(“Not enought objects selected.”)
else:
print(‘heloow:%s’ %sel)

todo()`

Oh, i use Maya 2018.4

The exit command invoked stops your program if nothing is selected. So code coming after it is never executed. Could that be the problem?

Oh, I did not know that the maya.cmds module has an error handle, thanks! :slight_smile:

After several restarts it works now! ^^

1 Like

This topic was automatically closed after 87 days. New replies are no longer allowed.