printing with python3+

25 views
Skip to first unread message

vince touache

unread,
Jul 8, 2021, 1:05:25 PMJul 8
to Python Programming for Autodesk Maya
hi all,

With previous versions of maya, I was using a lot 
print 'foo', 
with the coma in the end, which was forcing my print to show up in the 1-line listener embedded to the maya main window (just like a mel.eval('print "foo";') would do).
However, with python 3 and the new print() syntax, this trick doesn't seem to work anymore.

Is there another way I could make sure my prints are visible not only from the script editor but also from the main windows? (other than using mel.eval)?

cheers

Justin Israel

unread,
Jul 8, 2021, 1:40:25 PMJul 8
to python_in...@googlegroups.com


On Fri, 9 Jul 2021, 5:05 am vince touache, <fruit...@gmail.com> wrote:
hi all,

With previous versions of maya, I was using a lot 
print 'foo', 
with the coma in the end, which was forcing my print to show up in the 1-line listener embedded to the maya main window (just like a mel.eval('print "foo";') would do).
However, with python 3 and the new print() syntax, this trick doesn't seem to work anymore.



The python3 print function accepts an end parameter that defaults to a newline. So just set it to some other character. 

print("my line", end=" ") 


Is there another way I could make sure my prints are visible not only from the script editor but also from the main windows? (other than using mel.eval)?

cheers

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d4761b10-aa3a-45d7-a5ca-b7ad576b1076n%40googlegroups.com.

vince touache

unread,
Jul 9, 2021, 8:54:13 AMJul 9
to Python Programming for Autodesk Maya
brilliant, I didn't know that. However, for some reason, it still doesn't show up in the main gui one-liner widget. 
Any other suggestions?

Thank you

Justin Israel

unread,
Jul 12, 2021, 12:38:27 AMJul 12
to python_in...@googlegroups.com
On Sat, Jul 10, 2021 at 12:54 AM vince touache <fruit...@gmail.com> wrote:
brilliant, I didn't know that. However, for some reason, it still doesn't show up in the main gui one-liner widget. 
Any other suggestions?

I don't really know why that behaviour is different. But could you just not rely on the python print formatting, and instead maybe switch to using the explicit support in Maya's command api for pushing messages into the message status line?


vince touache

unread,
Jul 12, 2021, 8:56:08 AMJul 12
to Python Programming for Autodesk Maya
I didn't know about this command, thank you! However, I'd like a software-agnostic solution. I also noticed MGlobal.displayMessage also does the job, but again, maya-only. The benefit of using print is that it works regardless of the software, but shows up in the message line if you're on maya.
Another option is to simply use a logger, where I format my output to get rid of the logger name, but that means I sort of mess around with my existing logger structure. Still, this is what I did. But I miss my simple yet effective "print" solution =]

thanks for the 2 new things I learnt!

Reply all
Reply to author
Forward
0 new messages