diff --git a/500 - Python style/README.md b/500 - Python style/README.md index 87dfc3e..a38e5b8 100644 --- a/500 - Python style/README.md +++ b/500 - Python style/README.md @@ -45,6 +45,8 @@ import this > > In particular: do not break backwards compatibility just to comply with this PEP! +### [🎡 The PEP 8 Song 🎡] + ### What is Lint? > In computer programming lint or lint-like tools performing static analysis of > source code checking for symantec discrepancies. @@ -52,11 +54,25 @@ import this > β€œLinting” means running a basic quality tool against your code. > The tool will check your code syntax and provide instructions on how to clean it. -Python Lint tools: +From [What is Flake8 and why we should use it?] + +#### Python Lint tools: * [flake8] * [pylint] +* [black] + +```shell +# in env +pip install flake8 pylint +flake8 ugly_module +# flake8 is complaining +pylint ugly_module +# pylint is complaining even more +black ugly_module +# black makes some changes +``` +* [ugly_exercise.py](ugly_module/ugly_exercise.py) -### [🎡 The PEP 8 Song 🎡] ## Exercises: * [enum_exercise.py](enum_exercise.py) @@ -65,7 +81,8 @@ Python Lint tools: [PEP 8 - Style Guide for Python Code]: https://www.python.org/dev/peps/pep-0008/ [PEP 20 - The Zen of Python]: https://www.python.org/dev/peps/pep-0020/ [PEP 8 β€” the Style Guide for Python Code (for humans)]: https://pep8.org/ +[🎡 The PEP 8 Song 🎡]: https://www.youtube.com/watch?v=hgI0p1zf31k [What is Flake8 and why we should use it?]: https://medium.com/python-pandemonium/what-is-flake8-and-why-we-should-use-it-b89bd78073f2 [flake8]:https://flake8.pycqa.org/en/latest/ [pylint]: https://pylint.org/ -[🎡 The PEP 8 Song 🎡]: https://www.youtube.com/watch?v=hgI0p1zf31k +[black]: https://pypi.org/project/black/ diff --git a/500 - Python style/ugly_module/__init__.py b/500 - Python style/ugly_module/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/500 - Python style/ugly_module/ugly_exercise.py b/500 - Python style/ugly_module/ugly_exercise.py new file mode 100644 index 0000000..28c8c20 --- /dev/null +++ b/500 - Python style/ugly_module/ugly_exercise.py @@ -0,0 +1,28 @@ +import os + +fileToDump = 'duped_class.json' + +from random import randint + +class SomeClass: + def __init__(self, ATTR1, attr2): + self.ATTR1 = ATTR1 + self.attr2 = attr2 + + def printAttributes(self): + print(f'attrs: {self.ATTR1}, {self.attr2}') + +class inheritedClass(SomeClass): + def printAttributes(self): + print(f"attrs: {self.attr2}, {self.ATTR1}") + +def generate_int() -> str: + return randint(0, 10) + +if __name__ == '__main__': + Number = generate_int() + classInstance = SomeClass(Number, 'other attribute') + classInstance.printAttributes() + + subclassInstance = inheritedClass(Number, "other attribute") + subclassInstance.printAttributes() diff --git a/510 - Requests/README.md b/510 - Requests/README.md index e2cebda..6cdd6be 100644 --- a/510 - Requests/README.md +++ b/510 - Requests/README.md @@ -71,9 +71,9 @@ print(curl.parse(response3)) #### Result: ``` -curl -X POST -H 'Accept: */*' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: python-requests/2.28.0' -d 'title=t&body=b&userId=1' https://jsonplaceholder.typicode.com:443/posts -curl -X POST -H 'Accept: */*' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'User-Agent: python-requests/2.28.0' -d '{"title": "t", "body": "b", "userId": 1}' https://jsonplaceholder.typicode.com:443/posts -curl -X POST -H 'Accept: */*' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'User-Agent: python-requests/2.28.0' -d '{"title": "t", "body": "b", "userId": 1}' https://jsonplaceholder.typicode.com:443/posts +curl -X POST -H ... -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: python-requests/2.28.0' -d 'title=t&body=b&userId=1' https://jsonplaceholder.typicode.com:443/posts +curl -X POST -H ... -H 'User-Agent: python-requests/2.28.0' -d '{"title": "t", "body": "b", "userId": 1}' https://jsonplaceholder.typicode.com:443/posts +curl -X POST -H ... -H 'Content-Type: application/json' -H 'User-Agent: python-requests/2.28.0' -d '{"title": "t", "body": "b", "userId": 1}' https://jsonplaceholder.typicode.com:443/posts ``` ## Fake REST API [{JSON} Placeholder][]