0

I want to create tarfile with Turkish characters(like "ö") but I get an error. I'm using python 2.7 on Windows 8.1.

Here is my code:

# -*- coding: utf-8 -*-
import tarfile
import os
import sys

foldername = "klasör"

foldername = foldername.decode(sys.getfilesystemencoding())

tar = tarfile.open(foldername + ".tar.gz", "w:gz", compresslevel=5)
tar.add(foldername)
tar.close()
Matt
  • 74,352
  • 26
  • 153
  • 180
Ayse
  • 43
  • 1
  • 5

1 Answers1

2

Use "u" before the name like so.

foldername = u"klasör"

You do not need to encode/decode it, instead leave it as unicode and open like you did.

Bharel
  • 23,672
  • 5
  • 40
  • 80