I have a python code which reads many files.
but some files are extremely large due to which i have errors coming in other codes.
i want a way in which i can check for the character count of the files so that i avoid reading those extremely large files.
Thanks.
I have a python code which reads many files. but some files are extremely
Share
Assuming by ‘characters’ you mean bytes. ETA:
In which mode?
wcon it own will give you a line, word and byte count (same asstat), not Unicode characters.There is a switch
-mwhich will use the locale’s current encoding to convert bytes to Unicode and then count code-points: is that really what you want? It doesn’t make any sense to decode into Unicode if all you are looking for is too-long files. If you really must:sys.getfilesystemencoding()gets the locale encoding, reproducing whatwc -mdoes. If you know the encoding yourself (eg. ‘utf-8’) then pass that in instead.I don’t think you want to do this.