How to `eval` code with `def`?

Ben Finney ben+python at benfinney.id.au
Sun May 28 23:09:46 EDT 2017


Steve D'Aprano <steve+python at pearwood.info> writes:

> #!/usr/bin/env python
> # fileencoding=utf-8:
> # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1

Even better, the source code encoding declaration for Python is
compatible with a Vim text encoding declaration. So you can just do one:

=====
#! /usr/bin/env python
# vim: set fileencoding=utf-8 noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 :
=====

See <URL:https://www.python.org/dev/peps/pep-0263/#defining-the-encoding>
for a discussion of how Python expects to find the source code encoding
declaration.

> although I prefer:
>
> # -*- coding: utf-8 -*-

Yes. Jamming all the editor hints at the top of the file is IMO
needlessly distracting; both Vim and Emacs will look for them at the end
of the file, where they're less intrusive.

I prefer to have Python's source code encoding delcaration at the top of
the file, and have a block of editor hints at the end of the file.

-- 
 \     “I know you believe you understood what you think I said, but I |
  `\         am not sure you realize that what you heard is not what I |
_o__)                                     meant.” —Robert J. McCloskey |
Ben Finney




More information about the Python-list mailing list