[Tutor] Opening filenames with unicode characters

Jerry Hill malaclypse2 at gmail.com
Thu Jun 28 19:58:18 CEST 2012


On Thu, Jun 28, 2012 at 1:55 PM, James Chapman <james at uplinkzero.com> wrote:
> 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)

You have to create a unicode-string, not a byte-string.  So, like this:

filename = u"blah£.txt"
open(filename)

-- 
Jerry


More information about the Tutor mailing list