Article From:https://segmentfault.com/q/1010000012144786
Question:

with open(‘E:/filter.txt’, ‘rb’) as f:

for i in f:
    i = str(i)
    if 'mailbox' in i:
        a = re.match('b.*/(.*)".*', i)
        e = '"' + a.group(1) + '"'
        print(e)
    if 'name' in i:
        i = i.replace('"', '').replace("'", '').replace('bname=', '').replace('\\r\\n', '')
        n = '"' + i + '"'
        print(n)
        
        

It is printed out:
“loic@gmail.com”
“Loic”

How can I print it out to say it is:
“loic@gmail.com” “Loic”

Let it be on the same line?

Xiao Bai, thank you

Answer 0:

change into

print(n, end=" ")

endThe default is"\n"

Answer 1:

The answer on the first floor is OK. If you need more operations, you can do this.

for i in f:
    i = str(i)
    mail, name = '', ''
    
    if 'mailbox' in i:
        a = re.match('b.*/(.*)".*', i)
        mail = '"' + a.group(1) + '"'
        
    if 'name' in i:
        i = i.replace('"', '').replace("'", '').replace('bname=', '').replace('\\r\\n', '')
        name = '"' + i + '"'
    
    
    if mail and name:
        # Or do other operations, such as storing in a database together, etc.Print ('%s,%s'% (mail, name))

Answer 2:

print(e) A comma is followed by a comma: Print (E),

Leave a Reply

Your email address will not be published. Required fields are marked *