os.stat(filepath).st_size
Assuming by characters, you mean bytes. ETA:
I need a common character counter just like the wc filename command gives me unix
In what mode? wcat its discretion will give you a string, the number of words and bytes (the same as stat), and not Unicode characters.
-m, locale Unicode : , ? Unicode, , , . :
import sys, codecs
def getUnicodeFileLength(filepath, charset= None):
if charset is None:
charset= sys.getfilesystemencoding()
readerclass= codecs.getReader(charset)
reader= readerclass(open(filepath, 'rb'), 'replace')
nchar= 0
while True:
chars= reader.read(1024*32)
if chars=='':
break
nchar+= len(chars)
reader.close()
return nchar
sys.getfilesystemencoding() , wc -m. (, "utf-8" ), .
, .