Skip to content

Instantly share code, notes, and snippets.

@hygull
Last active February 12, 2023 05:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hygull/7db576c5d739e87832aa2341dbeb5242 to your computer and use it in GitHub Desktop.
Save hygull/7db576c5d739e87832aa2341dbeb5242 to your computer and use it in GitHub Desktop.
Install pycodestyle then autopep8 to format the Python code to conform to the PEP 8 style guide.

Visit here or see the follwoing usage guide.

  • Open terminal

  • Run

pip install pycodestyle
  • then run
pip install --upgrade autopep8
  • cd(navigate) to the directory where your python file does exist(suppose your file name is encdec.py).

  • Run the follwowing command to format the encdec.py to conform to the PEP 8 style guide.

autopep8 --in-place --aggressive --aggressive encdec.py
  • Modify or corrode the code formatting(like increasing the spacing between operands and operator etc.)

  • Rerun the autopep8 command

You will see your code formatted.

MacBook-Pro:mobmsg admin$ pip install pycodestyle
Collecting pycodestyle
  Downloading pycodestyle-2.3.1-py2.py3-none-any.whl (45kB)
    100% |████████████████████████████████| 51kB 273kB/s 
Installing collected packages: pycodestyle
Successfully installed pycodestyle-2.3.1
MacBook-Pro:mobmsg admin$ pip install --upgrade autopep8
Collecting autopep8
  Downloading autopep8-1.3.2-py2.py3-none-any.whl (42kB)
    100% |████████████████████████████████| 51kB 288kB/s 
Requirement already up-to-date: pycodestyle>=2.3 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from autopep8)
Installing collected packages: autopep8
Successfully installed autopep8-1.3.2
MacBook-Pro:mobmsg admin$ ls
LICENSE			mobmsg			setup.py
README.md		sample_output.md
MacBook-Pro:mobmsg admin$ cd mobmsg/
MacBook-Pro:mobmsg admin$ ls
__init__.py	__init__.pyc	encdec.py	encdec.pyc
MacBook-Pro:mobmsg admin$ autopep8 --in-place --aggressive --aggressive encdec.py
MacBook-Pro:mobmsg admin$ autopep8 --in-place --aggressive --aggressive encdec.py
MacBook-Pro:mobmsg admin$ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment