Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Alphabetize finds grouped lines of variables within your files and orders them alphabetically. This is useful for cleaning up codebases.
The organisation priority is:
The variable 'a' is ordered last as it depends on the other variables.
b = 10
c = 20
d = 40
a = b + c + d
UPPERCASE and lowercase variables are separated when ordered.
A = 10
B = 20
C = 30
a = 10
b = 20
c = 30
pip install alphabetize
alphabetize myfile.py
alphabetize path/to/myfile.py
The provided argument can either be the relative path or absolute path to a Python file.
Consider the following Python script (unordered_code.py
)
import datetime
from time import time
# First Variable Block
c_variable = 60
A_variable = 10
a_variable = 40
B_variable = 20
b_variable = 50
C_variable = 30
class TestClass:
def __init__(self):
self.c_variable = 30
self.a_variable = 10
self.b_variable = 20
def test_function():
c_variable = time()
a_variable = 10
b_variable = datetime
a_list = [a_variable, b_variable, c_variable]
bb_variable = 20
aa_variable = 10
cc_variable = aa_variable + bb_variable
return a_list, cc_variable
Calling:
alphabetize unordered_code.py
Results in the following output:
import datetime
from time import time
# First Variable Block
A_variable = 10
B_variable = 20
C_variable = 30
a_variable = 40
b_variable = 50
c_variable = 60
class TestClass:
def __init__(self):
self.a_variable = 10
self.b_variable = 20
self.c_variable = 30
def test_function():
a_variable = 10
b_variable = datetime
c_variable = time()
a_list = [a_variable, b_variable, c_variable]
aa_variable = 10
bb_variable = 20
cc_variable = aa_variable + bb_variable
return a_list, cc_variable
Depending on the variable names found within grouped lines, alphabetize
can be called multiple times to further reorder the grouped lines of variables.
This particularly comes into play when independent and dependent variables are mixed within the same grouped lines block.
Consider the following Python script (unordered_code_multi.py
)
def test_function():
c_variable = 30
a_variable = 10
b_variable = 20
list = [a_variable, b_variable, c_variable]
bb_variable = 20
aa_variable = 10
cc_variable = aa_variable + bb_variable
return list, cc_variable
Calling alphabetize unordered_code_multi.py
for the first time produces:
def test_function():
a_variable = 10
b_variable = 20
c_variable = 30
aa_variable = 10
bb_variable = 20
list = [a_variable, b_variable, c_variable]
cc_variable = aa_variable + bb_variable
return list, cc_variable
Then calling alphabetize unordered_code_multi.py
a second time produces a further ordered file:
def test_function():
a_variable = 10
aa_variable = 10
b_variable = 20
bb_variable = 20
c_variable = 30
cc_variable = aa_variable + bb_variable
list = [a_variable, b_variable, c_variable]
return list, cc_variable
When using alphabetize
it is recommended that you lint and format your files in the following order:
It is recommended to run alphabetize
a second time to catch any caught dependent variables. Then a further flake8
to ensure your file is formatted and adheres to PEP8 correctly.
FAQs
Alphabetize variables within your files
We found that alphabetize demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.