Home  >  Q&A  >  body text

Python reads the content of a document and extracts it for processing

There is a text document 1, the data is divided into lines, as follows:
12345
32561
96854
12368
52697
......
Another Text document 2 is also data in the same format, as follows:
112233
123456
789652
123698
125896
......
Want to read document 1 For each line of document 2, extract each line of data into a variable; then read each line of document 2, extract each line of data into another variable, and then operate these two variables. How to do this?

仅有的幸福仅有的幸福2712 days ago616

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-18 10:57:56

    with open('a.txt') as f:
        a = f.readlines()
        
    with open('b.txt') as f:
        b = f.readlines()
        

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-18 10:57:56

    with open('a.txt') as f1, open('b.txt') as f2:
        a, b = f1.readlines(), f2.readlines()
        #接下来就可以操作a, b了

    reply
    0
  • Cancelreply