[vtkusers] VTK writers with unicode path (python)

David Gobbi david.gobbi at gmail.com
Sat Feb 22 15:44:11 EST 2014


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