[vtkusers] VTK writers with unicode path (python)

Michka Popoff michkapopoff at gmail.com
Mon Feb 24 17:14:00 EST 2014


Hi

thanks very much, in fact it was really easy.
I just added :

filename = filename.encode("utf-8")

It's working correctly now. Thanks

Michka

Le 22 févr. 2014 à 21:44, David Gobbi a écrit :

> Hi Michka,
> 
> The SetFileName() method requires an 8-bit encoding, specifically
> it requires the encoding given by the LANG environment variable on
> your system.
> 
> So, you'll probably have to convert the python unicode string to utf-8
> before you can use it.  The python "codecs" module provides methods
> that you can use to convert unicode to utf-8.
> 
>  David
> 
> On Sat, Feb 22, 2014 at 9:23 AM, Michka Popoff <michkapopoff at gmail.com> wrote:
>> Hi
>> 
>> I was wondering if one can use filenames or paths containing unicode
>> characters to the vtkPNGWriter in python ?
>> Here is my code :
>> 
>> #!/usr/bin/env python
>> # -*- coding: utf-8 -*-
>> 
>> import vtk
>> 
>> filename = u"~/Desktop/myfolderü/image.png"
>> writer = vtk.vtkPNGWriter()
>> writer.SetFileName(filename)
>> 
>> 
>> Traceback (most recent call last):
>>  File "test.py", line 7, in <module>
>>    writer.SetFileName(filename)
>> TypeError: SetFileName argument 1: (unicode conversion error)
>> 
>> 
>> Thanks in advance.
>> 
>> 
>> Michka



More information about the vtkusers mailing list