什么是C++重载的输入流运算符的可接受的python替代品?

Mat*_*hew 2 python input operator-overloading

在C++中,您可以这样做以轻松地将数据读入类中:

istream& operator >> (istream& instream, SomeClass& someclass) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

在python中,我可以找到从控制台读取的唯一方法是"raw_input"函数,它不能很好地适应这种事情.是否有一种pythonic方式来解决这个问题?

wha*_*ick 6

您基本上是在寻找反序列化.Python有很多选项可供选择,具体取决于所使用的库.默认是python 酸洗.您可以在这里查看许多其他选项.