繁体   English   中英

Python追溯:没有错误,但脚本没有输出

[英]Python Traceback: no error, yet no output from script

enter code here使用Eclipse与PyDev的,并试图让一个简单的脚本工作即时通讯:

编辑代码:

import time
import os
import json
import tarfile
source_config='/Users/brendanryan/scripting/brendan.json'
backup_dir = '/myapp/target/'

def main():

        with open(source_config) as f:
                data = json.load(f)
                for entry in data["source_include"]:
                    #base_filename = os.path.basename(entry)
                    #source_dirs = [ name for name in os.listdir(entry) if os.path.isdir(os.path.join(entry, name)) ]
                    full_dir = os.path.join(entry)
                    tar = tarfile.open(os.path.join(backup_dir, '.tar.gzip'), 'w:gz')
                    tar.add(full_dir)
                    tar.close()

if __name__ == '__main__':
        main()

JSON:

{
    "source_type": "folder",
    "tar_type": "gzip",
    "tar_max_age": "10",
    "source_include": ["/myapp/conf", "/myapp/db"],
    "target_path": "/myapp/target"
}

应该可以工作了。 但事实并非如此。 当代码被破坏时,我可以使用各种各样的Traceback...。 现在,我只得到“” ...,没有错误,没有输出,没有结果的.tar.gz,运行它时什么也没有。 我愿意尝试一切以立即使它工作...

对于初学者,应该读取json(它们是变量),并使用它来选择源文件夹,然后对其进行tar.gz并将生成的归档文件放置在另一个文件夹中。 我不知道该怎么做,但是实际上只将“ source_include”,tar.gz中的所有文件夹并以当前日期命名就好了。 那将是真棒!

编辑:添加main()...谢谢! 因此,通过编辑,现在的回溯是:

再次编辑:现在,没有回溯。 再次。 没有输出...

肮脏的语言消失了(Eclipse说现在的代码很酷)...但是没有输出。 总体而言,就像没有稀释档案一样。 回到原点。

实际上,您似乎根本没有在调用main函数。 要调用函数,您需要使用括号: main()

(而且,如果您要做的只是打印一条无用的固定消息,则不应捕获异常。最好让该异常传播,以便您可以查看实际出了什么问题。)

ValueError: Expecting , delimiter: line 6 column 2 (char 120告诉我您的JSON文件中有错误。

JSON:
{
    "source_type": "folder",
    "tar_type": "gzip",
    "tar_max_age": "10",
    "source_include": ["/myapp/conf", "/myapp/db"], !!!COMMA GOES HERE
    "target_path": "/myapp/target"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM