Pythonprint
はクラスメソッド名での使用(または他の予約語)を禁止していますか?
$ cat a.py
import sys
class A:
def print(self):
sys.stdout.write("I'm A\n")
a = A()
a.print()
$ python a.py
File "a.py", line 3
def print(self):
^
SyntaxError: invalid syntax
print
他の名前 (例: ) に変更してもaprint
、エラーは発生しません。そんな制限があるとは驚きです。C++ やその他の言語では、これは問題になりません。
#include<iostream>
#include<string>
using namespace std;
class A {
public:
void printf(string s)
{
cout << s << endl;
}
};
int main()
{
A a;
a.printf("I'm A");
}