Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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:使用参数覆盖函数中的文件/新文件_Python_File_Function_Overwrite_Argv - Fatal编程技术网

Python:使用参数覆盖函数中的文件/新文件

Python:使用参数覆盖函数中的文件/新文件,python,file,function,overwrite,argv,Python,File,Function,Overwrite,Argv,我对Python非常陌生,我花了一段时间尝试使用一个函数将pwdump格式的文件剪切到username:NTLMhash函数中。理想情况下,我希望代码能够将剪切后的散列从输入文件输出到一个新的文本文件中,但是如果新文件有点太多,那么覆盖就足够了 任何帮助都将不胜感激: 谢谢 我还没有运行此功能,但它应该接近您想要的功能 import sys def pwdump_snip(file): with open(file) as i: with open("outfile.t

我对Python非常陌生,我花了一段时间尝试使用一个函数将pwdump格式的文件剪切到username:NTLMhash函数中。理想情况下,我希望代码能够将剪切后的散列从输入文件输出到一个新的文本文件中,但是如果新文件有点太多,那么覆盖就足够了

任何帮助都将不胜感激:


谢谢

我还没有运行此功能,但它应该接近您想要的功能

import sys

def pwdump_snip(file):
    with open(file) as i:
        with open("outfile.txt","a") as o: # open for appending/change to "w" to overwrite
            for line in i: s
                s = line.split(':')
                o.write(s[0] + ':' + s[3])

if __name__=="__main__":
    pwdump_snip(sys.argv[1])

使用python name_of_py.py some_file运行脚本

避免重写正在读取的文件。它可以工作,但相当棘手。最好写到它旁边的另一个文件。文件不是按行组织的,而是按字节数组组织的。谢谢您的帮助。获取索引错误:列表索引超出范围'Through?:添加一个输入示例,我将看到您需要更改的内容。输入文本文件的格式为:name:id:numbers2,我只希望“name:numbers2”作为输出,以覆盖输入文件,或创建包含这些内容的新文件。以python pwdump.py pwdump.txt的形式运行它pwdump.txt中有什么?