我已经在我的class foo
中定义了__str__
和__repr__
当我 print foo()
时,它工作正常。
当然,将 stdout 重新定义为 file
对象并调用 print foo()
会将字符串表示形式写入文件,但这是最符合 Python 风格的方法吗?< br/>
最佳答案
关于python - 将类实例的字符串表示写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19330089/