alice.txt is a pre-existing text file in the same directory as the foo.py script. ![]() Use the encoding argument just once and for all. Below, myfile is the file data object were creating for reading. That's way too much bother for zero gain. Summary: Don't call encode or decode yourself when all you are doing is using them to process a homogeneous stream that's all of it in the same encoding. See how much easier that is? Let the stream object handle any low-level encoding or decoding for you. Now if you the file you made, you’ll see that it says: $ cat /tmp/sample.utf8Īnd you can see that those are the right code points this way: $ uniquote -x /tmp/sample.utf ![]() With open("/tmp/sample.utf8", mode="w", encoding="utf8") as f: You do not want to muck around with manually encoding each and every piece of data like that! Simply pass the encoding as an argument to open, like this: #!/usr/bin/env python3.2
0 Comments
Leave a Reply. |