Thanks Tim, while this works, I need the name to be stored in a variable as it's dynamic.
In other words, how do I rewrite open(u"blah£.txt") to be filename = "blah£.txt" open(filename) At Thursday, 28/06/2012 on 18:39 Tim Golden wrote: On 28/06/2012 18:19, James Chapman wrote: > Hi there python list. > > I'm trying to open a text file named "This is_a-test'FILE to Ensure$ > that£ stuff^ works.txt" (without the quotes) but I'm struggling to > find a way to open it. Happily, you're using Windows, which makes this very much easier. Short Explanation Do this: open (u"blah £3.50.txt").read () # note the u- prefix Long Explanation: There's way too many levels of indirection between you and the disk to go into it all, but basically you're telling Python to create a (byte) string from those characters using its default encoding for code, which is UTF-8. UTF-8 maps "£" to the one-byte 0x9c. Somewhere in the layers between that string and the representation on disk, a mismatch occurs. TJG _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor