打印格式化的键,值字符串时出错

时间:2017-11-29 10:30:37

标签: python dictionary printing

打印字典的格式化键值对时,我得到IOError: [Errno 0] Error,如下所示:

假设我有一个字典只保存字符串(字典的所有值都是表示我的运行的一些参数的字符串):

        sub_params = {'n_points': n_points, 
                      'n_cores': n_cores, 
                      'input_dat': input_dat, 
                      'input_png': input_png,
                      'algorithm': algorithm, 
                      'sub_size': sub_size, 
                      'n_iterations': n_iterations, 
                      'run_idx': dir_index,
                      'img': img}

现在一个获取所有参数的函数因此创建了上面的dict并调用:

    print '\n' + 30*'= '
    print '\tRun parameters:'
    for key, value in sub_params.iteritems():
        print '{:20}: {}'.format(key, value)
    print '{:20}: {}'.format('iter_idx', iter_idx)

我循环遍历持有不同参数集的运行。它工作了一段时间然后突然崩溃:

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
        Run parameters:
n_cores             : 1
n_iterations        : 5
sub_size            : None
run_idx             : 7
img                 : square.png
algorithm           : chan_merge_var
input_dat           : points_n_50000_img_square.dat
input_png           : points_n_50000_img_square.png
n_points            : 50000
iter_idx            : 0

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
        Run parameters:
n_cores             : 1
n_iterations        : 5
sub_size            : None
run_idx             : 7
img                 : square.png
algorithm           : chan_merge_var
input_dat           : points_n_50000_img_square.dat
input_png           : points_n_50000_img_square.png
n_points            : 50000
iter_idx            : 1

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
        Run parameters:
n_cores             : 1
n_iterations        : 5
Traceback (most recent call last):
sub_size            : None
  File "C:/Users/mathee/CLionProjects/dphpc-project/python/scripts/grid_run_exe.
py", line 10, in <module>
run_idx             : 7    run.main_grid_loop()
  File "C:\Users\mathee\CLionProjects\dphpc-project\python\libs\execution\GridRu
nHandler.py", line 141, in main_grid_loop
    sub_dir=sub_dir)
  File "C:\Users\mathee\CLionProjects\dphpc-project\python\libs\execution\GridRu
nHandler.py", line 86, in run_algorithm
    print '{:20}: {}'.format(key, value)
IOError: [Errno 0] Error

编辑:
我重新安装了python anacondy发行版,没有帮助。我确实在Linux集群上运行 - &gt;工作得非常好。我在Windows shell中运行它 - &gt;工作得非常好。它实际上似乎是CLion IDE的一个问题。我重新安装了Clion,更新了版本,两者都没有解决问题。我将在JetBrains网页上发布此内容并被迫从shell运行直到那时,这很糟糕,因为我无法使用调试器。

0 个答案:

没有答案