[英]Python - Exception unhandled "name 'main' is not defined"
I am currently learning python and would like some assistance.我目前正在学习 python 并需要一些帮助。
I am unsure where the syntax is incorrect.我不确定语法在哪里不正确。 It states "name 'main' is not defined"
它指出“名称'main'未定义”
I have seen other examples where the syntax looks the same but for some reason mine is not working.我看过其他语法看起来相同但由于某种原因我的不工作的例子。
class Main(main):
"""description of class"""
def main():
print('starting etl')
# establish connection for target database (sql-server)
target_cnx = pyodbc.connect(**datawarehouse_db_config)
# loop through credentials
# sql-server
for config in sqlserver_db_config:
try:
print("loading db: " + config['database'])
etl_process(sqlserver_queries, target_cnx, config, 'sqlserver')
except Exception as error:
print("etl for {} has error".format(config['database']))
print('error message: {}'.format(error))
continue
target_cnx.close()
if __name__ == "__main__":
main()
Any help will be much appreciated.任何帮助都感激不尽。
Your class Main
tries to inherit from non-existent class main
.您的类
Main
尝试从不存在的类main
继承。
main
is only defined as a method of class Main
. main
仅定义为类Main
的方法。
Looks like you only wanted to have a function main
without the class Main
.看起来您只想拥有一个没有类
Main
的函数main
。
def main():
print('starting etl')
# establish connection for target database (sql-server)
target_cnx = pyodbc.connect(**datawarehouse_db_config)
# loop through credentials
# sql-server
for config in sqlserver_db_config:
try:
print("loading db: " + config['database'])
etl_process(sqlserver_queries, target_cnx, config, 'sqlserver')
except Exception as error:
print("etl for {} has error".format(config['database']))
print('error message: {}'.format(error))
continue
target_cnx.close()
if __name__ == "__main__":
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.