-3

So I grabbed an email body from Gmail Imap server. Now That File contain format like b"some line /d/n some line /d/n". Mine aim is to get that some line by anyway. but I am unable to do that.

I tried Split() method but that does not works.

def main():
    yes = open("file.txt", "r")
    byte_object= yes.read()
    print(byte_object.decode('utf8')) #Nothing changes

main()

I expect output as Lines between those tags

sanyassh
  • 8,100
  • 13
  • 36
  • 70
  • Are you sure it is `"/d/n"`, not `"\d\n"`? – DYZ Apr 03 '19 at 03:04
  • Yes. Let me Give You File Format. (''b"Google Logo\r\n\r\n\r\nThis is Text Message\r\n\r\n") this is File Text, i wana grab Text, such as "this is Text Message There . – Gopal Mandal Apr 03 '19 at 10:36

2 Answers2

0

Finally I found Mine answer. it was easy :) Well This is code to get those lines

    yes = 'b"Google Logo\r\n\r\n\r\nYHello This is message \r\n\r\n"'
    Yes2 = yes.decode('UTF8')
    for f in Yes2.split("\r\n\r"):
       print(f)

So this will print Line except those "/n/r" codes :)

-1

Similar question: What does the 'b' character do in front of a string literal?

The example provided there is: b'\xE2\x82\xAC'.decode('UTF-8'). Note, use capital UTF and put a dash in between.

Mikolaj Figurski
  • 133
  • 1
  • 2
  • 12
  • 1st Of all Thanks for commenting Here, But i checked that post and i tried but still not working in mine case (b"Google Logo\r\n\r\n\r\nYHello This is message \r\n\r\n") This is Format. – Gopal Mandal Apr 03 '19 at 10:39