简体   繁体   中英

Replacing the first character of a file with python 3

I have made a script, with python 3, that downloads single files from github repositories. It uses requests, but when it saves to a file it has the format b'text' I need to get rid of the b (which is always the first character of the line), but I can't just use.replace as that gets rid of all bs. If anyone has any has any idea as how to replace the first character of the file (b) and are willing to help, thank you.

You have confused that 'b' for a character. See here What does the 'b' character do in front of a string literal?

To get rid of it, you need to decode it

url = "https://projecteuler.net/project/resources/p067_triangle.txt"
content = requests.get(url).content.decode('utf8')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM