Skip to main content

Sort methods, imports and classes in a python source file

Project description

Rearrange methods alphabetically in a Python source file. - Python3

sortorder

  1. docstring

  2. future imports

  3. imports first on alphabet then on length (apo, alpha-pipe-organ)

  4. from, modules on apo, imports on alpa

  5. classes sorted on baseclass then on classname alpha (internals of class unchanged)

  6. methods sorted on methodname alpha

example

Source file before sort

"""
Docstring is required
"""
import sys
import http
import email
import concurrent.futures
import os

class Zorro(object):
    pass

def foobar():
    pass

def helloworld():
    pass

def applemethod():
    pass

class Alpha(object):
    pass

class ZZ(object):
    pass

class AA(ZZ):
    pass

Run command

sortpythonmethods -f myfile.py

Sorted source file

#!/usr/bin/env python3
# coding=utf-8
"""
Docstring is required
"""

import email
import http
import os
import sys
import concurrent.futures


class Alpha(object):
    pass


class Zorro(object):
    pass


def applemethod():
    pass


def foobar():
    pass


def helloworld():
    pass

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sortpythonmethods-8.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file sortpythonmethods-8.tar.gz.

File metadata

File hashes

Hashes for sortpythonmethods-8.tar.gz
Algorithm Hash digest
SHA256 11cba8adfa95308b85a0a9ebdc5eb055596dd5c330cee47e02c53da172615048
MD5 3e50f58834491d028d495fd653936f4b
BLAKE2b-256 bcee2d58bfa4913e4302fdd695f103b826f13777b3ff86ce5453a4ffe7f1c85d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page