Skip to content

Commit

Permalink
Formatted Python Code Base Using Black (--line-length 85)
Browse files Browse the repository at this point in the history
since it consider its tabindent=4 and I am actually on indent 3
its practically roughly 80ish line length
  • Loading branch information
Penguin98kStudio committed Jun 2, 2021
1 parent c24b87d commit 647e132
Show file tree
Hide file tree
Showing 50 changed files with 213 additions and 273 deletions.
12 changes: 6 additions & 6 deletions Background Proj/CreateBackgroundImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
ext = ".jpg"
outext = ".png"

for i in ('1', '2'):
for i in ("1", "2"):
response = requests.post(
'https://api.remove.bg/v1.0/removebg',
files={'image_file': open(name + i + ext, 'rb')},
data={'size': 'auto'},
headers={'X-Api-Key': '8F5NZTmr74r4g3KnKu9w6pU5'},
"https://api.remove.bg/v1.0/removebg",
files={"image_file": open(name + i + ext, "rb")},
data={"size": "auto"},
headers={"X-Api-Key": "8F5NZTmr74r4g3KnKu9w6pU5"},
)
if response.status_code == requests.codes.ok:
with open(path + name + i + outext, 'wb') as out:
with open(path + name + i + outext, "wb") as out:
out.write(response.content)
else:
print("Error:", response.status_code, response.text)
Expand Down
3 changes: 2 additions & 1 deletion Python Stuff/DataclasswithGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@dataclass
class Student:
"""Student info"""

sid: str
name: str
age: int
Expand All @@ -27,4 +28,4 @@ def details():

print(std)

#https://www.youtube.com/watch?v=T-TwcmT6Rcw&ab_channel=PyCon2018
# https://www.youtube.com/watch?v=T-TwcmT6Rcw&ab_channel=PyCon2018
36 changes: 22 additions & 14 deletions Python Stuff/Ipython_Imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
"functools": ["partial", "wraps"],
"glob": "glob",
"heapq": ["heappop", "heappush"],
"itertools":
["combinations", "permutations", "groupby", "filterfalse", "cycle"],
"itertools": [
"chain",
"combinations",
"cycle",
"groupby",
"permutations",
"filterfalse",
],
"math": ["ceil", "inf", "sqrt"],
"os": "system",
"os.path": ["expandvars", "isdir"],
Expand All @@ -31,18 +37,19 @@
"threading": "Thread",
"time": "sleep",
"tqdm": "trange",
"typing": "Optional"
"typing": "Optional",
}
# fmt: off
__modules = [
"bisect" , "bs4" , "collections", "contextlib", "copy" ,
"dataclasses", "flask" , "functools" , "heapq" , "html" ,
"inspect" , "itertools", "json" , "logging" , "math" ,
"os" , "pathlib" , "pickle" , "platform" ,
"queue" , "random" , "re" , "requests" , "shutil" ,
"signal" , "socket" , "stat" , "struct" , "subprocess",
"sys" , "tempfile" , "textwrap" , "threading" , "time" ,
"tokenize" , "tqdm" , "typing" ,
] # yapf: disable
"os" , "copy", "flask" , "bisect", "platform", "functools",
"re" , "html", "heapq" , "pickle", "requests", "itertools",
"bs4", "json", "queue" , "random", "tempfile", "threading",
"sys", "math", "inspect", "shutil", "textwrap", "contextlib",
"stat", "logging", "signal", "tokenize", "subprocess",
"time", "pathlib", "socket", "collections",
"tqdm", "typing" , "struct", "dataclasses",
]
# fmt: on

for module in __modules:
globals()[module] = importlib.import_module(module)
Expand All @@ -61,6 +68,7 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

__modules.append("numpy as np")
__modules.append("pandas as pd")
__modules.append("matplotlib.pyplot as plt")
Expand Down Expand Up @@ -97,9 +105,9 @@
"""
if sys.version_info.minor == 9:
get_ipython().run_line_magic(
'logstart', '~/Sublime/Ipython_logs/py39log.py rotate'
"logstart", "~/Sublime/Ipython_logs/py39log.py rotate"
)
else:
get_ipython().run_line_magic(
'logstart', '~/Sublime/Ipython_logs/log.py rotate'
"logstart", "~/Sublime/Ipython_logs/log.py rotate",
)
2 changes: 1 addition & 1 deletion Python Stuff/QueuesforMultiThreading.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def userlist_manager():

user_queue.join()

#https://pybay.com/site_media/slides/raymond2017-keynote/threading.html
# https://pybay.com/site_media/slides/raymond2017-keynote/threading.html
2 changes: 1 addition & 1 deletion Python Stuff/Testing/SplitListtoSublists.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

command_list.sort(key=attrgetter("__module__"))
for module, module_commands in groupby(
command_list, lambda x: x.__module__.split('.')[0]
command_list, lambda x: x.__module__.split(".")[0]
):
print(module, module_commands)
2 changes: 1 addition & 1 deletion Python Stuff/Testing/testpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

## ----------------------------------------------------------------------------

print("/".join(path.parts[path.parts.index("SublimeText") + 1:]))
print("/".join(path.parts[path.parts.index("SublimeText") + 1 :]))
print(txtfiles)
5 changes: 3 additions & 2 deletions Python Stuff/Testing/testunpack.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
list1, list2 = [3, 2, 5], [2, 4, 1]
list1, list2 = map(list, (zip(*sorted(zip(list1, list2, strict= True), reverse=True))))
list1, list2 = map(
list, (zip(*sorted(zip(list1, list2, strict=True), reverse=True)))
)
print(list1, list2)


class Point:

def __init__(self, x, y, z=None):
self.x = float(x) if isinstance(x, str) else x
self.y = float(y) if isinstance(y, str) else y
Expand Down
2 changes: 1 addition & 1 deletion Python Stuff/dectobin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def decimaltobinary(number):
ans = 0

while half > 0:
ans += (half%2) * power
ans += (half % 2) * power
power *= 10
half //= 2
return ans
Expand Down
7 changes: 4 additions & 3 deletions Python Stuff/filettype.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import filetype

while True:
val = input("enter:")
kind = filetype.guess(val)
if kind is None:
print('Cannot guess file type!')
print("Cannot guess file type!")
break
else:
print('File extension: %s' % kind.extension)
print('File MIME type: %s' % kind.mime)
print("File extension: %s" % kind.extension)
print("File MIME type: %s" % kind.mime)
6 changes: 3 additions & 3 deletions Python Stuff/idk.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def find(number):
dec = 3
valueset = [(int('1' * x) % number) for x in range(1, number + 1)]
valueset = [(int("1" * x) % number) for x in range(1, number + 1)]
try:
print('1' * (valueset.index(0) + 1))
print("1" * (valueset.index(0) + 1))
except:
for remainder in valueset:
indices = [i for i, x in enumerate(valueset) if x == remainder]
if len(indices) >= 2:
print(int('1' * (indices[1] + 1)) - int('1' * (indices[0] + 1)))
print(int("1" * (indices[1] + 1)) - int("1" * (indices[0] + 1)))
break


Expand Down
3 changes: 1 addition & 2 deletions Python Stuff/kivytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class KivyButton(App):

def disable(self, instance, *args):

instance.disabled = True
Expand All @@ -17,7 +16,7 @@ def update(self, instance, *args):
def build(self):

mybtn = Button(
text="Click me to disable", pos=(300, 350), size_hint=(.25, .18)
text="Click me to disable", pos=(300, 350), size_hint=(0.25, 0.18)
)

mybtn.bind(on_press=partial(self.disable, mybtn))
Expand Down
10 changes: 7 additions & 3 deletions Python Stuff/lol (2).py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
marks = [
["maths", 10], ["english", 70], ["anlsaf", -1], ["economics", 90],
["physics", 65], ["Urdu", 102]
["maths", 10],
["english", 70],
["anlsaf", -1],
["economics", 90],
["physics", 65],
["Urdu", 102],
]
for sub in marks:
subject = sub[-1]
Expand All @@ -9,7 +13,7 @@
"Bonus marks for handwriting"
if sub[0] == "Urdu" and subject < 110
else "error"
) # yapf: disable
)
elif subject > 90:
print("A+")
elif subject >= 80:
Expand Down
37 changes: 21 additions & 16 deletions Python Stuff/matsoup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import matplotlib.pyplot as plt
import numpy as np

# fmt: off
mrks = [
'90.12', '82.12', '81.30', '78.87', '77.60', '77.21', '76.39', '76.10',
'75.80', '75.23', '74.63', '74.08', '73.82', '73.20', '72.98', '72.86',
'72.45', '72.41', '71.92', '71.86', '71.72', '70.47', '70.28', '70.06',
'69.10', '67.49', '67.13', '66.55', '66.52', '65.93', '65.40', '65.35',
'64.98', '64.88', '64.27', '64.18', '64.05', '63.90', '63.85', '63.57',
'62.28', '62.23', '61.58', '61.19', '60.87', '60.79', '56.79', '55.63',
'54.36', '54.07', '53.17', '51.30', '50.87', '49.64', '49.15', '49.15',
'44.20', '39.64', '38.56', '34.86', '22.02', '21.99', '20.55', '17.19',
'15.93', '09.92', '02.63', '01.46', '00.00', '00.00'
'90.12', '82.12', '81.30', '78.87', '77.60', '77.21', '76.39',
'76.10', '75.80', '75.23', '74.63', '74.08', '73.82', '73.20',
'72.98', '72.86', '72.45', '72.41', '71.92', '71.86', '71.72',
'70.47', '70.28', '70.06', '69.10', '67.49', '67.13', '66.55',
'66.52', '65.93', '65.40', '65.35', '64.98', '64.88', '64.27',
'64.18', '64.05', '63.90', '63.85', '63.57', '62.28', '62.23',
'61.58', '61.19', '60.87', '60.79', '56.79', '55.63', '54.36',
'54.07', '53.17', '51.30', '50.87', '49.64', '49.15', '49.15',
'44.20', '39.64', '38.56', '34.86', '22.02', '21.99', '20.55',
'17.19', '15.93', '09.92', '02.63', '01.46', '00.00', '00.00'
]
ids = [
'01', '47', '14', '29', '15', '22', '54', '03', '10', '26', '50', '51', '23',
'02', '40', '34', '28', '37', '38', '17', '55', '72', '09', '36', '08', '53',
'57', '19', '32', '21', '24', '31', '69', '39', '13', '45', '56', '25', '61',
'62', '04', '42', '41', '64', '58', '70', '63', '12', '59', '43', '44', '33',
'30', '52', '49', '68', '48', '74', '11', '31', '73', '46', '71', '07', '66',
'65', '75', '27', '16', '20'
'01', '47', '14', '29', '15', '22', '54', '03', '10', '26',
'50', '51', '23', '02', '40', '34', '28', '37', '38', '17',
'55', '72', '09', '36', '08', '53', '57', '19', '32', '21',
'24', '31', '69', '39', '13', '45', '56', '25', '61', '62',
'04', '42', '41', '64', '58', '70', '63', '12', '59', '43',
'44', '33', '30', '52', '49', '68', '48', '74', '11', '31',
'73', '46', '71', '07', '66', '65', '75', '27', '16', '20'
]
# fmt: on
mrks = [int(float(x)) for x in mrks]
#print(mrks,ids)
# print(mrks,ids)
npmarks = np.array(mrks)
npid = np.array(ids)
dd = np.column_stack((npmarks, npid))
Expand Down
4 changes: 2 additions & 2 deletions Python Stuff/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
file = open('Shrinker.txt')
file = open("Shrinker.txt")
data = file.read()
data.split('\n')
data.split("\n")

# key1 = " \\"
# key2 = ["January","February","March","April","May","June","July","August","September","October","November","December"]
Expand Down
2 changes: 1 addition & 1 deletion Python Stuff/umm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
myfile = open("meh.txt", 'r')
myfile = open("meh.txt", "r")
save = myfile.read()
save = save.split()
name = str(input("enter the sentance\n"))
Expand Down
1 change: 0 additions & 1 deletion SublimeUserPlugins/AutoSideBarReveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class AutoRevealCommand(sublime_plugin.EventListener):

def on_activated(self, view):
if view.window().is_sidebar_visible():
if view.settings().get("auto_sidebar_reveal", True):
Expand Down
2 changes: 0 additions & 2 deletions SublimeUserPlugins/CloseEmptyPane.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class InitialEmptyPaneCheckCommand(sublime_plugin.EventListener):

def on_pre_close(self, view):
window = view.window()
if not window:
Expand All @@ -24,7 +23,6 @@ def on_post_window_command(self, window, command_name, args):


class FinalEmptyPaneCheckCommand(sublime_plugin.TextCommand):

def run(self, edit):
window = self.view.window()
num_groups = window.num_groups()
Expand Down
1 change: 0 additions & 1 deletion SublimeUserPlugins/ContextsListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class ContextsListener(sublime_plugin.EventListener):

def on_query_context(self, view, key, operator, operand, match_all):
if key == "terminus_tag.exists":
return any(
Expand Down
3 changes: 1 addition & 2 deletions SublimeUserPlugins/ConvertImportStatement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class ConvertImportStatementCommand(sublime_plugin.TextCommand):

def run(self, edit):

selection = self.view.sel()
Expand All @@ -20,7 +19,7 @@ def run(self, edit):
(contents.replace("import", "from") + " import ")
if sub == contents
else sub
) # yapf: disable
)
self.view.replace(edit, line, contents)
change = True
if change:
Expand Down
26 changes: 12 additions & 14 deletions SublimeUserPlugins/ConvertLoopToListComprehension.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class ConvertLoopToListComprehensionCommand(sublime_plugin.TextCommand):

def listcomprehension(self, lines):
for_pattern = re.compile(r"^for\s+(.+)\s+in\s+(.+)(?=:\s*)")
if_pattern = re.compile(r"^(\s+)if\s+(.+)(?=:\s*)")
Expand All @@ -15,22 +14,21 @@ def listcomprehension(self, lines):
"condition": None,
"expression": None,
"items": match.group(1),
"iterator": match.group(2).rstrip()
"iterator": match.group(2).rstrip(),
}

match = re.match(if_pattern, lines[1])
comprehension = "[{expression} for {items} in {iterator}]\n"
if match:
attributes["condition"] = match.group(2).rstrip()
attributes["expression"] = "(" + "\n".join(
lines[2:]
) + ")" if len(lines) > 3 else lines[-1].strip()
comprehension = "[{expression} for {items} in {iterator} if {condition}]\n"
else:
attributes["expression"] = "(" + "\n".join(
lines[1:]
) + ")" if len(lines) > 2 else lines[-1].strip()
comprehension = "[{expression} for {items} in {iterator}]\n"

comprehension = comprehension[:-2] + " if {condition}]\n"

index = 2 if match else 1
attributes["expression"] = (
"(" + "\n".join(lines[index:]) + ")"
if len(lines) > index + 1
else lines[-1].strip()
)
return comprehension.format(**attributes)

def run(self, edit):
Expand All @@ -41,7 +39,7 @@ def run(self, edit):
return

region = self.view.full_line(selection[0])
lines = self.view.substr(region).rstrip().split('\n')
lines = self.view.substr(region).rstrip().split("\n")
match = re.match(loop_pattern, lines[0])
if not match:
return
Expand All @@ -52,6 +50,6 @@ def run(self, edit):
selection.add(region.cover(selection[0]))

region = region.cover(selection[0])
lines = textwrap.dedent(self.view.substr(region).rstrip()).split('\n')
lines = textwrap.dedent(self.view.substr(region).rstrip()).split("\n")

self.view.replace(edit, region, self.listcomprehension(lines))
1 change: 0 additions & 1 deletion SublimeUserPlugins/CopyLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class CopyLinesCommand(sublime_plugin.TextCommand):

def run(self, edit, forward=True):
for region in self.view.sel():
line = self.view.line(region)
Expand Down
Loading

0 comments on commit 647e132

Please sign in to comment.