Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pydoc messes up with -*- coding: utf-8 -*-

I edit Python scripts with Emacs, and I always put this at the beginning of my scripts:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

It is recommended (at least, not discourage) in PEP 0236.

However, I just found that pydoc doesn't recognize (ignore) it correctly:

$ pydoc myscript.py
Help on module myscript:

NAME
    myscript - # -*- coding: utf-8 -*-

Is there a way to fix that? Or a good alternative to using -*- coding: utf-8 -*-?

I'm using Python 2.6

like image 985
Frank Avatar asked Sep 28 '12 18:09

Frank


1 Answers

It appears that if you actually provide a documentation string the encoding line will be skipped.

File contents:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Documentation for myscript"""

pydoc output:

$ pydoc myscript.py
Help on module myscript:

NAME
    myscript - Documentation for myscript
like image 107
Andrew Clark Avatar answered Oct 06 '22 22:10

Andrew Clark