Hide output print messages

68 views
Skip to first unread message

likage

unread,
Nov 12, 2014, 10:49:16 PM11/12/14
to python_in...@googlegroups.com
I noticed that my script editor is printing out some additional stuff but I am not exactly sure if this a warning/error etc... despite the fact that my code is still working as it should..

It happens when I clicked onto this button which was connected to the openFile function that I have created.

def openFile(self):
       
""" Module for importing in .txt anim files """
       
        fileFilters
= "Text (*.txt)"
        fileList
= cmds.fileDialog2(fileMode = 1, fileFilter = fileFilters, dialogStyle = 2)

       
if fileList:
            stringConvert
= ''.join(fileList)
           
print "Imported File is opened from : %s" %stringConvert
           
self.importTxt.setText(stringConvert)

As soon as the button is clicked, the following was printed out in my editor:
PySide.QtCore.QEvent.Type.ChildPolished
QFileDialog
PySide.QtCore.QEvent.Type.ChildPolished
QFileDialog
PySide.QtCore.QEvent.Type.ChildRemoved

So I have 2 questions.
1. I am not using PySide but PyQt4 as the importing modules since PyQt was installed in my machine. So where does this PySide comes from?
2. Are there any ways in which I can hide these 5 lines?

Justin Israel

unread,
Nov 13, 2014, 1:15:12 AM11/13/14
to python_in...@googlegroups.com
There seems to be missing information here. What button?
PySide is included since Maya 2014.
Something must be printing.

--
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/2b7c93eb-c9bb-4072-86a8-0d6703cda807%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Nov 13, 2014, 9:49:19 PM11/13/14
to python_in...@googlegroups.com
The following are the codes that are associated with this opening file of mine...
So the button in this case, is this openAnimBtn

import maya.cmds as cmds
from PyQt4.QtCore import *
from PyQt4.QtGui import *

def initUI(self):
   
self.openAnimBtn = QToolButton()
    gridLayout
= QGridLayout()
    gridLayout
.addWidget(self.openAnimBtn, 1, 2, 1, 1)
   
self.setLayout(gridLayout)
   
def createConnections(self):
   
self.connect(self.openAnimBtn, SIGNAL('clicked()'), self.openFile)

def openFile(self):

Marcus Ottosson

unread,
Nov 14, 2014, 2:52:09 AM11/14/14
to python_in...@googlegroups.com

This will append line number and filename to each print statement, maybe it can help you figure out where it’s coming from.
https://gist.github.com/mottosso/7261394e511bc6206ede

(Though I’m having trouble figuring out why it repeats the appended information, I expected flushing to handle it, but it did not)

likage

unread,
Nov 17, 2014, 12:07:28 AM11/17/14
to python_in...@googlegroups.com

Hey Marcus,

Just wanted to ask how do i run the code? Within my own code or append my file into this code of yours?

Cheers!

Marcus Ottosson

unread,
Nov 20, 2014, 2:45:33 AM11/20/14
to python_in...@googlegroups.com

Hi,

Sorry for the late reply, totally missed this!

To run it, I’ll need to give you a little backstory. Whenever you use print "something", you are essentially calling sys.stdout.write("something" + "\n") which means “write to standard out with a new-line”, where “standard out” generally refers to a terminal.

By replacing sys.stdout with the object above, print will instead refer to that class when attempting to write to “standard out”, which will in this case append some additional information before doing so.

The sys.__stdout__ is an extra variable kept per default by Python and refers to the original sys.stdout, in case you overwrite it like we are here. We use it to refer back to where printing would happen normally; which again is generally the terminal. But this time, it will have that extra piece of information coming along with it.

My intent was for you to replace sys.stdout before running any other code, so as to make the rest of your code print its information with line-numbers, so that you could locate exactly where those printed lines where coming from; assuming that it is print statements which was causing them.

Does that help?

Best,
Marcus


--
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.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages