# Pyhon script not working

**URL:** https://forum.highend3d.com/t/pyhon-script-not-working/159129
**Category:** Maya
**Tags:** python
**Created:** [March 31, 2019, 12:21pm UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129 "2019-03-31T12:21:54Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![lala\_ghost](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/l/a698b9/32.png) [@lala\_ghost](https://forum.highend3d.com/u/lala_ghost)
#### Post date: [March 31, 2019, 12:21pm UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129/1 "2019-03-31T12:21:54Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![mechaniac](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@mechaniac](https://forum.highend3d.com/u/mechaniac)
#### Post date: [March 31, 2019, 12:51pm UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129/2 "2019-03-31T12:51:53Z")

</div>

line 9:  
print sel

you forgot the brackets.

---

<div class="post-metadata">

### Author: ![lala\_ghost](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/l/a698b9/32.png) [@lala\_ghost](https://forum.highend3d.com/u/lala_ghost)
#### Post date: [March 31, 2019, 2:46pm UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129/3 "2019-03-31T14:46:40Z")

</div>

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…

 ![](https://forum.highend3d.com/uploads/default/original/3X/b/c/bc6c9c33416ef698951dd76a841b3862189960d9.png)

---

<div class="post-metadata">

### Author: ![tomas-herrera](https://forum.highend3d.com/user_avatar/forum.highend3d.com/tomas-herrera/32/4355_2.png) [@tomas-herrera](https://forum.highend3d.com/u/tomas-herrera)
#### Post date: [March 31, 2019, 11:20pm UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129/4 "2019-03-31T23:20:47Z")

</div>

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()`

 ![](https://forum.highend3d.com/uploads/default/original/3X/c/c/cc2fcccc9843f6ba01841600b7565e4c3545d5c6.PNG)

Oh, i use Maya 2018.4

---

<div class="post-metadata">

### Author: ![bart-janssen](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/b/45deac/32.png) [@bart-janssen](https://forum.highend3d.com/u/bart-janssen)
#### Post date: [April 1, 2019, 2:36pm UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129/5 "2019-04-01T14:36:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lala\_ghost](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/l/a698b9/32.png) [@lala\_ghost](https://forum.highend3d.com/u/lala_ghost)
#### Post date: [April 10, 2019, 10:26am UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129/7 "2019-04-10T10:26:21Z")

</div>

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

After several restarts it works now! ^^

---

<div class="post-metadata">

### Author: ![system](https://forum.highend3d.com/user_avatar/forum.highend3d.com/system/32/59311_2.png) [@system](https://forum.highend3d.com/u/system)
#### Post date: [June 27, 2019, 12:41am UTC](https://forum.highend3d.com/t/pyhon-script-not-working/159129/8 "2019-06-27T00:41:36Z")

</div>

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