Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python(提供的awk示例)文件分隔器中执行此代码_Python_Python 3.x - Fatal编程技术网

如何在python(提供的awk示例)文件分隔器中执行此代码

如何在python(提供的awk示例)文件分隔器中执行此代码,python,python-3.x,Python,Python 3.x,如果我想将以下awk代码作为python代码执行,那么最好的方法是什么?如果我要使用一个列表,我将如何弹出该列表,以便最终可以将字段1和3打印回输出列表并将其写入文件 谢谢 格雷厄姆 测试文件 Error code 27: This is error code 27:Ihave no comment here Error code 24: This is error code 27:Ihave no comment here Error code 27: This is error code 2

如果我想将以下awk代码作为python代码执行,那么最好的方法是什么?如果我要使用一个列表,我将如何弹出该列表,以便最终可以将字段1和3打印回输出列表并将其写入文件

谢谢 格雷厄姆

测试文件

Error code 27: This is error code 27:Ihave no comment here
Error code 24: This is error code 27:Ihave no comment here
Error code 27: This is error code 27:Ihave no comment here
Error code 26: This is error code 27:Ihave no comment here
Error code 27: This is error code 27:Ihave no comment here
Error code 29: This is error code 27:Ihave no comment here
Error code 01: This is error code 27:Ihave no comment here

我不会说AWK,我怀疑有很多python程序员都不会。因此,您最好包含输入文件的预期输出,从中,您可以不看AWK代码就知道python解决方案。因此,您最好包含输入文件的预期输出,从中,您可以在不查看AWK代码的情况下找出python解决方案
Error code 27: This is error code 27:Ihave no comment here
Error code 24: This is error code 27:Ihave no comment here
Error code 27: This is error code 27:Ihave no comment here
Error code 26: This is error code 27:Ihave no comment here
Error code 27: This is error code 27:Ihave no comment here
Error code 29: This is error code 27:Ihave no comment here
Error code 01: This is error code 27:Ihave no comment here
f = open(file_name)
for line in f:
  s = line.split(':')
  print s[0],s[2]