+ All Categories
Home > Technology > PEP8 and-autopep8 - PyCon APAC 2013 LT

PEP8 and-autopep8 - PyCon APAC 2013 LT

Date post: 17-Jul-2015
Category:
Upload: hattori-hideo
View: 511 times
Download: 0 times
Share this document with a friend
14
PEP 8 and autopep8 PyCon APAC 2013 LT / 2013.09.15 Hideo Hattori
Transcript
Page 1: PEP8 and-autopep8 - PyCon APAC 2013 LT

PEP 8 and autopep8 

PyCon APAC 2013 LT / 2013.09.15 Hideo Hattori

Page 3: PEP8 and-autopep8 - PyCon APAC 2013 LT

PEP 8

coding conventions for the Python code

Nc”úùk1�ÕúßÕc�v��”c�v

göpvz̈v©–−

2013.08.01•ò&\©¤

http://www.python.org/dev/peps/pep-0008/

Page 4: PEP8 and-autopep8 - PyCon APAC 2013 LT

PEP 8 modernisation1�m¤ß”5ðcv�•9¡−l¡

׳•9¡−l¡

Python1.5.2•9¡−l¡w£Œ\©–¤ß

Python2/3•9¡−l¡wûl\©¤ßhttp://hg.python.org/peps/rev/fb24c80e9afb

Page 5: PEP8 and-autopep8 - PyCon APAC 2013 LT

About autopep8simple command-line tool

automatic formatting for Python Code

require

v0.9.4 (2013.09.08)

pep8

$ pip install autopep8

Page 6: PEP8 and-autopep8 - PyCon APAC 2013 LT

For Exampleinvalid PEP 8 code

import sys, os

n = Trueif n != None: print("none")

def f(x): return 2 * x

Page 7: PEP8 and-autopep8 - PyCon APAC 2013 LT

Output Auto-Formatting Code$ autopep8 invalid.py

import sysimport os

n = Trueif n != None: print("none")

def f(x): return 2 * x

Page 8: PEP8 and-autopep8 - PyCon APAC 2013 LT

Aggressive$ autopep8 -a invalid.py

import sysimport os

n = Trueif n is not None: print("none")

def f(x): return 2 * x

Page 9: PEP8 and-autopep8 - PyCon APAC 2013 LT

Print Diff$ autopep8 -d invalid.py

--- original/invalid.py+++ fixed/invalid.py@@ -1,7 +1,10 @@-import sys, os+import sys+import os

n = True if n != None: print("none")

-def f(x): return 2 * x++def f(x):+ return 2 * x

Page 10: PEP8 and-autopep8 - PyCon APAC 2013 LT

Other Featureignore/select errors

max-line

recursive/jobs

Page 11: PEP8 and-autopep8 - PyCon APAC 2013 LT

ofiØ#”O�•PEP 8³

Page 12: PEP8 and-autopep8 - PyCon APAC 2013 LT

⁄¿autopep8³³›–Æ–z“\o

Page 13: PEP8 and-autopep8 - PyCon APAC 2013 LT

 https://github.com/hhatto/autopep8

Page 14: PEP8 and-autopep8 - PyCon APAC 2013 LT

Thank you


Recommended