Select to view content in your preferred language

Problems with signs like "ß", "ä" etc (filenames like Weißstorch.shp)

420
1
Jump to solution
03-20-2019 05:00 AM
JohannesBierer
Frequent Contributor

I get the following error with the this script because of the ß in filename: Weißstorch.shp. Any ideas how to solve this? Python 2.7.10

# -*- coding: utf-8 -*-

import os, time, xlwt
import xlrd
from xlrd import open_workbook

myPath = r"R:\Daten\geo_daten\Arten\2015_SIC\LUBW_Weissstorch_Horststandorte"

SHPCounter = 0

MyList = list()

Zusammengef = r"C:\temp_Geodatenverzeichnis\Nutzung.xls"

for path, dirs, files in os.walk(myPath):
    for file in files:
        if file.lower().endswith('.shp'):
            print path + "\\" + file
            SHPCounter += 1
            print SHPCounter
            
            accessTime = os.path.getatime(os.path.join(path, file)) # last access time
            
            actualTime = time.time()
           
            MyList.append(path + "\\" + file + "___" + file + "___" + ("""{}
            """.format(int((actualTime - accessTime)/3600))))

# Write in excel
data = []
for line in MyList:
    data.append([word for word in line.split("___") if word])

print data

wb = xlwt.Workbook()
sheet = wb.add_sheet("NichtGenutzt")
for row_index in range(len(data)):
    for col_index in range(len(data[row_index])):
        sheet.write(row_index, col_index, data[row_index][col_index])

wb.save(Zusammengef)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Error Message and print statements:

R:\Daten\geo_daten\Arten\2015_SIC\LUBW_Weissstorch_Horststandorte\LUBW_Weißstorch_Horststandorte_E.shp
1
[['R:\\Daten\\geo_daten\\Arten\\2015_SIC\\LUBW_Weissstorch_Horststandorte\\LUBW_Wei\xdfstorch_Horststandorte_E.shp', 'LUBW_Wei\xdfstorch_Horststandorte_E.shp', '1551\n            ']]


UnicodeDecodeError: 'ascii' codec can't decode byte 0xdf in position 74: ordinal not in range(128)

0 Kudos
1 Solution

Accepted Solutions
JohannesBierer
Frequent Contributor

You have to decode the filename first to get it to run and write the filenames to the list.

View solution in original post

0 Kudos
1 Reply
JohannesBierer
Frequent Contributor

You have to decode the filename first to get it to run and write the filenames to the list.

0 Kudos