Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
Thanks to everyone who responded on this thread, your time is greatly appreciated. It appears however that my problem is related to the environment. I sent my original email right before leaving work and have since been working on a physical machine without any problems. I've copied some of that c

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread Prasad, Ramit
> The name of the file I'm trying to open comes from a UTF-16 encoded text file, > I'm then using regex to extract the string (filename) I need to open. However, > all the examples I've been using here are just typed into the python console, > meaning string source at this stage is largely irreleva

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread Jerry Hill
On Thu, Jun 28, 2012 at 3:48 PM, James Chapman wrote: > Informative thanks Jerry, however I'm not out of the woods yet. > > >> Here's a couple of questions that you'll need to answer 'Yes' to >> before you're going to get this to work reliably: >> >> Are you familiar with the differences between b

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread Tim Golden
On 28/06/2012 20:48, James Chapman wrote: The name of the file I'm trying to open comes from a UTF-16 encoded text file, I'm then using regex to extract the string (filename) I need to open. OK. Let's focus on that. For the moment -- although it might well be very relevant -- I'm going to igno

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
Informative thanks Jerry, however I'm not out of the woods yet. > Here's a couple of questions that you'll need to answer 'Yes' to > before you're going to get this to work reliably: > > Are you familiar with the differences between byte strings and unicode > strings? I think so, although I'm

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread Jerry Hill
On Thu, Jun 28, 2012 at 2:55 PM, James Chapman wrote: > Why can I not convert my existing byte string into a unicode string? That would work fine. > In the mean time I'll create my original string as unicode and see if that > solves my problem. > fileName = unicode(filename) > > Traceback (

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
Why can I not convert my existing byte string into a unicode string? In the mean time I'll create my original string as unicode and see if that solves my problem. >>> fileName = unicode(filename) Traceback (most recent call last):   File "", line 1, in UnicodeDecodeError: 'utf8' codec can't deco

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread Jerry Hill
On Thu, Jun 28, 2012 at 1:55 PM, James Chapman 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, no

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
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 pyt

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread Tim Golden
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. Shor

[Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
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. >>> filename = "This is_a-test'FILE to Ensure$ that£ stuff^ works.txt.js" >>> open(filename) Traceback (most recent