Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b3a48296
Commit
b3a48296
authored
Mar 18, 2010
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
show a common usage of detect_encoding
parent
00888934
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
Doc/library/tokenize.rst
Doc/library/tokenize.rst
+11
-1
No files found.
Doc/library/tokenize.rst
View file @
b3a48296
...
...
@@ -98,7 +98,17 @@ function it uses to do this is available:
but disagree, a SyntaxError will be raised. Note that if the BOM is found,
``'utf-8-sig'`` will be returned as an encoding.
If no encoding is specified, then the default of ``'utf-8'`` will be returned.
If no encoding is specified, then the default of ``'utf-8'`` will be
returned.
:func:`detect_encoding` is useful for robustly reading Python source files.
A common pattern for this follows::
def read_python_source(file_name):
with open(file_name, "rb") as fp:
encoding = tokenize.detect_encoding(fp.readline)[0]
with open(file_name, "r", encoding=encoding) as fp:
return fp.read()
Example of a script re-writer that transforms float literals into Decimal
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment