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
  • 72,564
  • 26
  • 147
  • 178
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
  • 20,128
  • 3
  • 33
  • 62