为什么python不运行main函数?

为什么python不运行main函数?,python,csv,main,ttl,Python,Csv,Main,Ttl,我对python是个新手。我在问为什么python在我的例子中不运行main函数。我在主函数的开头放了一个打印函数,但它从不打印。虽然我设法运行其余的代码在internet上创建html上载表单,但我确实设法在上面上载文件。你能帮忙吗 这部分代码始终运行,不要问我如何运行:( 这是主界面,我在这里设置了一个打印到文件的功能,但这个功能从来都不起作用,尽管程序以某种方式运行了第一个功能,生成了我的html格式,并允许我上传我想要的文件。奇怪,对吧 if __name__ == "__main__"

我对python是个新手。我在问为什么python在我的例子中不运行main函数。我在主函数的开头放了一个打印函数,但它从不打印。虽然我设法运行其余的代码在internet上创建html上载表单,但我确实设法在上面上载文件。你能帮忙吗

这部分代码始终运行,不要问我如何运行:(

这是主界面,我在这里设置了一个打印到文件的功能,但这个功能从来都不起作用,尽管程序以某种方式运行了第一个功能,生成了我的html格式,并允许我上传我想要的文件。奇怪,对吧

if __name__ == "__main__":
   outfile_errors = open('C:\Python27\csv_results\errors.csv', 'a')
   outfile_errors.write("in the main beginning" + "\n " )
   app = web.application(urls, globals()) 
   app.run()
   outfile_errors.write("in the main middle" + "\n " )
   transform()
   outfile_errors.write("in the main end " + "\n " )
   outfile_errors.close()


您能帮忙吗?

您没有告诉程序写入正确的变量。请将outfile.write更改为outfile\u错误。在main函数的后半部分写入,因为
app.run()
我认为永远循环,因为它正在侦听web请求。请明确删除name_uuuu=''main'和call语句。也许这会起作用。@rgbimbochamp…这甚至不接近正确的答案…Gohn67有正确的答案OK.app.run()永远循环。知道如何调整我的程序吗?作为回报,谢谢。
def transform():
        outfile_errors = open('C:\Python27\csv_results\errors.txt', 'a')
        outfile_errors.write("in the transform ")
        outfile_errors.close()
#bla bla
if __name__ == "__main__":
   outfile_errors = open('C:\Python27\csv_results\errors.csv', 'a')
   outfile_errors.write("in the main beginning" + "\n " )
   app = web.application(urls, globals()) 
   app.run()
   outfile_errors.write("in the main middle" + "\n " )
   transform()
   outfile_errors.write("in the main end " + "\n " )
   outfile_errors.close()