我尝试执行一些 python 代码,但我在传递参数时遇到了问题。我的python代码如下:
#!/usr/bin/python
import MySQLdb
class Sim(object):
def print_db_parameters(self):
print "Host = %s" %self.host
print "User = %s" %self.user
print "Password = %s" %self.password
print "Database = %s" %self.database
def main():
host = "localhost"
user = "root"
password = "root"
database = "sim"
sim_test = Sim(host,user,password,database)
sim_test.print_db_parameters()
if __name__ == "__main__":
main()
当我运行它时,我收到以下错误:
Traceback (most recent call last):
File "Sim.py", line 21, in <module>
main()
File "Sim.py", line 17, in main
sim_test = Sim(host,user,password,database)
TypeError: object.__new__() takes no parameters
你有什么主意吗?