Changes between Version 1 and Version 2 of python


Ignore:
Timestamp:
Aug 25, 2016, 4:05:34 PM (3 years ago)
Author:
nik
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • python

    v1 v2  
    33* [[wsgi]]
    44* [[flask]]
     5
     6== python tips ==
     7
     8* 자동으로 file encoding 확인하기 (BOM도..)
     9{{{
     10bytes = min(32, os.path.getsize(filename));
     11raw = open(filename, 'rb').read(bytes);
     12if raw.startswith(codecs.BOM_UTF8):
     13        encoding = 'utf-8-sig'
     14else:
     15        result = chardet.detect(raw);
     16        encoding = result['encoding'];
     17
     18report_file = io.open(filename, "r", encoding=encoding);
     19}}}