How do I get rid of unwanted debug output when importing pyobjc AppKit with Python 3.7

烈酒焚心 提交于 2020-01-14 02:21:26

问题


A script consisting of a single statement

import AppKit

Prints the following to stdout/stderr with Python 3.7 (maybe also other 3.x versions but not with Python 2.7)

bool b'B' <classmethod object at 0x10b41e510> <function ivar.bool at 0x10b464440>
char b'c' <classmethod object at 0x10b41e4d0> <function ivar.char at 0x10b4644d0>
int b'i' <classmethod object at 0x10b41e0d0> <function ivar.int at 0x10b464560>
short b's' <classmethod object at 0x10b41e210> <function ivar.short at 0x10b4645f0>
long b'l' <classmethod object at 0x10b41a790> <function ivar.long at 0x10b464680>
long_long b'q' <classmethod object at 0x10b41af50> <function ivar.long_long at 0x10b464710>
unsigned_char b'C' <classmethod object at 0x10b41aa50> <function ivar.unsigned_char at 0x10b4647a0>
unsigned_int b'I' <classmethod object at 0x10b41afd0> <function ivar.unsigned_int at 0x10b464830>
unsigned_short b'S' <classmethod object at 0x10b41af10> <function ivar.unsigned_short at 0x10b4648c0>
unsigned_long b'L' <classmethod object at 0x10b41ac90> <function ivar.unsigned_long at 0x10b464950>
unsigned_long_long b'Q' <classmethod object at 0x10b41ad10> <function ivar.unsigned_long_long at 0x10b4649e0>
float b'f' <classmethod object at 0x10b41ad90> <function ivar.float at 0x10b464a70>
double b'd' <classmethod object at 0x10b41ae50> <function ivar.double at 0x10b464b00>
BOOL b'Z' <classmethod object at 0x10b41a5d0> <function ivar.BOOL at 0x10b464b90>
UniChar b'T' <classmethod object at 0x10b41a9d0> <function ivar.UniChar at 0x10b464c20>
char_text b't' <classmethod object at 0x10b41a910> <function ivar.char_text at 0x10b464cb0>
char_int b'z' <classmethod object at 0x10b41ab90> <function ivar.char_int at 0x10b464d40>
CFXMLEntityInfo b'{_CFXMLEntityInfo=q^{__CFString=}{_CFXMLExternalID=^{__CFURL=}^{__CFString=}}^{__CFString=}}' <classmethod object at 0x10b4eee10> <function ivar.CFXMLEntityInfo at 0x10b4c4cb0>
CFXMLElementInfo b'{_CFXMLElementInfo=^{__CFDictionary=}^{__CFArray=}Z[3c]}' <classmethod object at 0x10b4f30d0> <function ivar.CFXMLElementInfo at 0x10b4c4d40>
CFXMLAttributeListDeclarationInfo b'{_CFXMLAttributeListDeclarationInfo=q^{_CFXMLAttributeDeclarationInfo=^{__CFString=}^{__CFString=}^{__CFString=}}}' <classmethod object at 0x10b4f3210> <function ivar.CFXMLAttributeListDeclarationInfo at 0x10b4c4e60>
CFXMLElementTypeDeclarationInfo b'{_CFXMLElementTypeDeclarationInfo=^{__CFString=}}' <classmethod object at 0x10b4f33d0> <function ivar.CFXMLElementTypeDeclarationInfo at 0x10b4c4ef0>
CFGregorianDate b'{_CFGregorianDate=iccccd}' <classmethod object at 0x10b4f3690> <function ivar.CFGregorianDate at 0x10b4f7050>
CFXMLExternalID b'{_CFXMLExternalID=^{__CFURL=}^{__CFString=}}' <classmethod object at 0x10b4f3810> <function ivar.CFXMLExternalID at 0x10b4f70e0>
CFUUIDBytes b'{_CFUUIDBytes=CCCCCCCCCCCCCCCC}' <classmethod object at 0x10b4f3d50> <function ivar.CFUUIDBytes at 0x10b4f7170>
CFXMLAttributeDeclarationInfo b'{_CFXMLAttributeDeclarationInfo=^{__CFString=}^{__CFString=}^{__CFString=}}' <classmethod object at 0x10b4f3f10> <function ivar.CFXMLAttributeDeclarationInfo at 0x10b4f7200>
CFSwappedFloat32 b'{_CFSwappedFloat32=I}' <classmethod object at 0x10b4fc0d0> <function ivar.CFSwappedFloat32 at 0x10b4f7290>
CFSwappedFloat64 b'{_CFSwappedFloat64=Q}' <classmethod object at 0x10b4fc250> <function ivar.CFSwappedFloat64 at 0x10b4f7320>
CFXMLDocumentTypeInfo b'{_CFXMLDocumentTypeInfo={_CFXMLExternalID=^{__CFURL=}^{__CFString=}}}' <classmethod object at 0x10b4fc3d0> <function ivar.CFXMLDocumentTypeInfo at 0x10b4f73b0>
CFStreamError b'{_CFStreamError=qi}' <classmethod object at 0x10b4fc590> <function ivar.CFStreamError at 0x10b4f7440>
CFXMLEntityReferenceInfo b'{_CFXMLEntityReferenceInfo=q}' <classmethod object at 0x10b4fc750> <function ivar.CFXMLEntityReferenceInfo at 0x10b4f74d0>
CFXMLProcessingInstructionInfo b'{_CFXMLProcessingInstructionInfo=^{__CFString=}}' <classmethod object at 0x10b4fc950> <function ivar.CFXMLProcessingInstructionInfo at 0x10b4f7560>
CFRange b'{_CFRange=qq}' <classmethod object at 0x10b4fcb50> <function ivar.CFRange at 0x10b4f7680>
CFSocketSignature b'{_CFSocketSignature=iii^{__CFData=}}' <classmethod object at 0x10b4fcd50> <function ivar.CFSocketSignature at 0x10b4f7710>
CFXMLDocumentInfo b'{_CFXMLDocumentInfo=^{__CFURL=}I}' <classmethod object at 0x10b4fced0> <function ivar.CFXMLDocumentInfo at 0x10b4f77a0>
CFGregorianUnits b'{_CFGregorianUnits=iiiiid}' <classmethod object at 0x10b5041d0> <function ivar.CFGregorianUnits at 0x10b4f7830>
CFXMLNotationInfo b'{_CFXMLNotationInfo={_CFXMLExternalID=^{__CFURL=}^{__CFString=}}}' <classmethod object at 0x10b504350> <function ivar.CFXMLNotationInfo at 0x10b4f78c0>
NSEdgeInsets b'{NSEdgeInsets=dddd}' <classmethod object at 0x10b59ac90> <function ivar.NSEdgeInsets at 0x10b571560>
NSHashEnumerator b'{_NSHashEnumerator=QQ^v}' <classmethod object at 0x10b59ae90> <function ivar.NSHashEnumerator at 0x10b5715f0>
NSAffineTransformStruct b'{_NSAffineTransformStruct=dddddd}' <classmethod object at 0x10b59f150> <function ivar.NSAffineTransformStruct at 0x10b571680>
NSRect b'{CGRect={CGPoint=dd}{CGSize=dd}}' <classmethod object at 0x10b59f310> <function ivar.NSRect at 0x10b571710>
NSOperatingSystemVersion b'{_NSOperatingSystemVersion=qqq}' <classmethod object at 0x10b59f510> <function ivar.NSOperatingSystemVersion at 0x10b5717a0>
NSZone b'{_NSZone=}' <classmethod object at 0x10b59f690> <function ivar.NSZone at 0x10b571830>
NSDecimal b'{_NSDecimal=b8b4b1b1b18[8S]}' <classmethod object at 0x10b59f990> <function ivar.NSDecimal at 0x10b5718c0>
NSSize b'{CGSize=dd}' <classmethod object at 0x10b59fb90> <function ivar.NSSize at 0x10b571950>
NSPoint b'{CGPoint=dd}' <classmethod object at 0x10b59fd10> <function ivar.NSPoint at 0x10b5719e0>
NSSwappedDouble b'{_NSSwappedDouble=Q}' <classmethod object at 0x10b59fe90> <function ivar.NSSwappedDouble at 0x10b571a70>
NSMapEnumerator b'{_NSMapEnumerator=QQ^v}' <classmethod object at 0x10b5a70d0> <function ivar.NSMapEnumerator at 0x10b571b00>
NSSwappedFloat b'{_NSSwappedFloat=I}' <classmethod object at 0x10b5a7250> <function ivar.NSSwappedFloat at 0x10b571b90>
NSRange b'{_NSRange=QQ}' <classmethod object at 0x10b5a7450> <function ivar.NSRange at 0x10b571c20>
NSDirectionalEdgeInsets b'{NSDirectionalEdgeInsets=dddd}' <classmethod object at 0x10b6d1d90> <function ivar.NSDirectionalEdgeInsets at 0x10b651710>
NSOpenGLPixelFormatAuxiliary b'{_CGLPixelFormatObject=}' <classmethod object at 0x10b6d1ed0> <function ivar.NSOpenGLPixelFormatAuxiliary at 0x10b6517a0>
NSScreenAuxiliaryOpaque b'{NSScreenAuxiliary=}' <classmethod object at 0x10b6d7050> <function ivar.NSScreenAuxiliaryOpaque at 0x10b651830>
NSOpenGLContextAuxiliary b'{_CGLContextObject=}' <classmethod object at 0x10b6d7190> <function ivar.NSOpenGLContextAuxiliary at 0x10b6518c0>

...Some details because SO has apparently reified its spirit of counterproductive pedantry into its product code and won't let me submit otherwise...


回答1:


This is a bug in PyObjC 6.0. I've just released PyObjC 6.0.1 which fixes this bug.




回答2:


I managed to solve this by something like:

stdout = sys.stdout
sys.stdout = open(os.devnull, 'w')
import AppKit
sys.stdout = stdout

More details at GitHub answer about similar problem in Keras



来源:https://stackoverflow.com/questions/58462950/how-do-i-get-rid-of-unwanted-debug-output-when-importing-pyobjc-appkit-with-pyth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!