I am new to Python. I am trying to use os.path.getsize()
to obtain the file's size. However, if the file name is not in English, but in Chinese, German, French, etc, Python cannot recognize it and does not return the size of the file. Could you please help me with it? How can I let Python recognize the file's name and return the size of these kind of files?
For example: The file's name is: "Показатели естественного и миграционного прироста до 2030г.doc". path="C:\xxxx\xxx\xxxx\Показатели естественного и миграционного прироста до 2030г.doc"
I'd like to use os.path.getsize(path)
. But it does not recognize the file name. Could you please kindly tell me what should I do?
Thank you very much!
import codecs,cStringIO
class UnicodeWriter:
def __init__(self, f, dialect=csv.excel, encoding="utf-8-sig", **kwds):
self.queue = cStringIO.StringIO()
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()
def writerow(self, row):
self.writer.writerow([s.encode("utf-8") for s in row])
data = self.queue.getvalue()
data = data.decode("utf-8")
data = self.encoder.encode(data)
self.stream.write(data)
self.queue.truncate(0)
def writerows(self, rows):
for row in rows:
self.writerow(row)