使用python将2个文本文件合并为一个文件 - python

Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        上个月关闭。
                                                                                            
                
        
'''
大家好,
我有2个文本文件。

file1.txt
1154 1353 G6 
1354 1408 G2 
1409 1592 G3 
1593 1729 G6 


file2 .txt
G1 =1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
G2 =0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
G3 =0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
G4 =0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
G5 =0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
G6 =0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0

我想要一个最终的文本文件,这是两个文件的组合。

file3.txt

1154 1353 G6 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
1354 1408 G2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1409 1592 G3 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1593 1729 G6 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0

如果您能帮助我怎么做,我将非常感激。
'''

参考方案

F1 = open("1.txt","r")
a = ((F1.read()).split("\n"))
a_list = []
for i in a:
    i=i.strip()
    a_list.append(i.split(" "))

F2= open("2.txt","r")
b = ((F2.read()).split("\n"))

b_list = []
for i in b:
    i = i.replace("=",'')
    i = i.strip()
    b_list.append(i.split(" "))

combined_list = []

for i in a_list:
    for j in b_list:
        if i[-1] == j[0]:
            combined_list .append(i + j[1:])

write_str=""
for i in combined_list:
    write_str += ' '.join(map(str, i))
    write_str += '\n'

F3 = open("3.txt","w")
F3.write(write_str)

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…

python:ConfigParser对象,然后再阅读一次 - python

场景:我有一个配置文件,其中包含要执行的自动化测试的列表。这些测试是长期循环执行的。   配置文件的设计方式使ConfigParser可以读取它。由于有两个三个参数,因此我需要通过每个测试。现在,此配置文件由script(s1)调用,并且按照配置文件中的列表执行测试。Script(s1)第一次读取配置,并且在每次测试完成后都会执行。阅读两次的要求:由于可能会…

Python:检查是否存在维基百科文章 - python

我试图弄清楚如何检查Wikipedia文章是否存在。例如,https://en.wikipedia.org/wiki/Food 存在,但是https://en.wikipedia.org/wiki/Fod 不会,页面只是说:“维基百科没有此名称的文章。”谢谢! 参考方案 >>> import urllib >>> prin…

Python GPU资源利用 - python

我有一个Python脚本在某些深度学习模型上运行推理。有什么办法可以找出GPU资源的利用率水平?例如,使用着色器,float16乘法器等。我似乎在网上找不到太多有关这些GPU资源的文档。谢谢! 参考方案 您可以尝试在像Renderdoc这样的GPU分析器中运行pyxthon应用程序。它将分析您的跑步情况。您将能够获得有关已使用资源,已用缓冲区,不同渲染状态上…