python's print in maya

2,022 views
Skip to first unread message

efecto

unread,
Jan 7, 2010, 1:35:06 AM1/7/10
to python_inside_maya
I noticed that python's print doesn't output in the message command
line next in the main interface of maya but we can see what's printed
in the script editor fine.

So I decided to use mel in python like below:

import maya.mel as mel
mel.print("test..\n")

and this does not seem to work.. perhaps a syntax problem? Could
someone point me to a right direction?

Thank you all.

Paul Molodowitch

unread,
Jan 7, 2010, 2:57:19 AM1/7/10
to python_in...@googlegroups.com
Python's print does show up in the command output... the problem is, it also "shows" newline statements... and since every normal print statement automatically adds a newline, and the output only shows a single line - you end up seeing nothing.

To see the results of a print statement down there, you have to use the print statement with a final comma:

print "This will show up!",

...the problem then becomes that whatever you print next will need to start with a newline, or else look ugly.  And, of course, anything not printed directly by you will have no such newline.

One way around this - when you explicitly want to show something down there - is to use MGlobal's display* methods:

from maya.OpenMaya import MGlobal

MGlobal.displayInfo("Standard Info")
MGlobal.displayWarning("Danger, Will Robinson!")
MGlobal.displayError("...and the runner advances to 2nd base.")

You also get the added advantage of fancy coloring for Warnings and Errors...

- Paul

efecto

unread,
Jan 7, 2010, 3:39:47 AM1/7/10
to python_inside_maya
Thank you Paul. so importing maya.mel and use mel's print command
doesn't do any good..?

I tried


import maya.mel as mel
mel.print("test..\n")

but this gives an error.

Thanks.

Paul Molodowitch

unread,
Jan 7, 2010, 3:49:51 AM1/7/10
to python_in...@googlegroups.com
The mel module doesn't provide a 'print' statement... only an eval.  To do what you'd want, you'd have to do something like this:

import maya.mel as mel
mel.eval("print foo")

- Paul


swath...@gmail.com

unread,
Jul 25, 2020, 1:01:15 AM7/25/20
to Python Programming for Autodesk Maya
print('test\n'), <-*Add a comma after the print() line, don't know why it works but it does
Reply all
Reply to author
Forward
0 new messages