logging not writing to file when called from funct

2019-02-25 21:35发布

Currently if I run the following code from the python command line it writes to the file specified by filename as expected.

import logging
def test():
    logging.basicConfig(format='%(asctime)s %(message)s',
                        datefmt='%m/%d/%Y %I:%M:%S %p',
                        filename=r'C:\Users\theo\Documents\myLog.txt')
    logging.warning('Example logged message.')
test()

But when I copy the code into one of my functions and run the function with Pyscripter, it does not seem to write the file. How can I get logging to appear in Pyscripter?

2条回答
老娘就宠你
2楼-- · 2019-02-25 21:45

Pyscripter has an 'External Run' option ( Run > External Run (Alt + F9)), choosing this made the logging work.

查看更多
可以哭但决不认输i
3楼-- · 2019-02-25 21:52

Switch the Python Engine to Internal. Go to run-->Pyhton Engine-->Internal

查看更多
登录 后发表回答