我可以在一个脚本中打开一个文本文件,然后在子脚本中写入该文件吗?
这是一个有点奇怪的问题,但我有一堆自动化脚本(使用 Sikuli/Jython),我想从父脚本运行它们以用于回归目的。现在我还有一种捕获异常的方法,我想将其记录到文本文件中。这是它目前的工作原理:
Master Script --> specific test script
--> specific test script
--> etc (how ever many scripts there are)
我正在和我的一个朋友交谈,他建议每个脚本处理自己的错误,并且父脚本只打开一个文件,使文件位置成为全局变量,而子脚本只是附加到该文件。
基本上,我需要在 python 中做一些特殊的事情才能实现这一点吗?或者主脚本基本上只是“触及”其他脚本可以使用的文件。
这是“父脚本”的示例(其中没有任何代码来处理错误,也不打开文件,只是执行脚本)
for dirpath, dirnames, filenames in os.walk("c:\directory\to\the\scripts"):
for filename in [f for f in filenames if f.endswith(".py")]:
directory.append(os.path.join(dirpath, filename))
for entry in directory:
execfile(entry)
This is a little bit of a strange question, but I have a bunch of automation scripts (using Sikuli/Jython), that i want to run from a parent script for regression purposes. Now I also have a method of capturing exceptions that I want to log to a text file. SO here's how it currently works:
Master Script --> specific test script
--> specific test script
--> etc (how ever many scripts there are)
I was talking to a friend of mine, and he recommended that each script handles its own errors, and that the parent script just opens a file, makes the file location a global variable, and the child scripts just append to that file.
Basically, do I need to do anything special in python to make this possible? or is the master script basically just "touching" a file that other scripts can use.
Here is an example of the "parent script" (this does not have any code to handle errors in it, nor does it open a file, just executes the scripts)
for dirpath, dirnames, filenames in os.walk("c:\directory\to\the\scripts"):
for filename in [f for f in filenames if f.endswith(".py")]:
directory.append(os.path.join(dirpath, filename))
for entry in directory:
execfile(entry)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
日志记录
。 http://docs.python.org/library/logging.html问题已经已经被他们解决了。没有工作适合你。
Use
logging
. http://docs.python.org/library/logging.htmlThe problem has already been solved by them. No work for you.