#working_with_files
Title: Reading Files
Builtin operator
instead of :
can use:
Title: Reading Files
Builtin operator
with
in python will automatically close the file when you are done processing it.instead of :
handle = open("test.txt")
can use:
with open("test.txt") as file_handler
Clean Code Principles
✅Code should be elegant and pleasing to read.
✅No duplication should be allowed. Use DRY (Don't Repeat Yourself)
✅Code should be covered with tests.
✅Every function should do one thing and do it well.
✅Codebase should contain only code that is needed.
✅Code should be elegant and pleasing to read.
✅No duplication should be allowed. Use DRY (Don't Repeat Yourself)
✅Code should be covered with tests.
✅Every function should do one thing and do it well.
✅Codebase should contain only code that is needed.
#compare
all() and any()
all() method demonstrates if List1 has List2 elements
all() and any()
all() method demonstrates if List1 has List2 elements
# List1
List1 = ['python' , 'javascript', 'csharp', 'go', 'c', 'c++']
# List2
List2 = ['csharp1' , 'go', 'python']
check = all(item in List1 for item in List2)
any() checks if the list contains any elements of another one:# List1
List1 = ['python' , 'javascript', 'csharp', 'go', 'c', 'c++']
# List2
List2 = ['swift' , 'php', 'python']
check = any(item in List1 for item in List2)
Time module
time.ctime() - converts a time in seconds since the epoch to a string representing local time ( For Unix systems, the epoch was in 1970).
time.sleep() - suspend execution of your script a given number of seconds like a pause.
time.strftime - create a string that represents the time in a more human readable format.
time.time - returns the time in seconds since the epoch as a floating point number.
time.ctime() - converts a time in seconds since the epoch to a string representing local time ( For Unix systems, the epoch was in 1970).
time.sleep() - suspend execution of your script a given number of seconds like a pause.
time.strftime - create a string that represents the time in a more human readable format.
time.time - returns the time in seconds since the epoch as a floating point number.
A "decorator" takes the function below and does something with it
Builtin decorators
@classmethod
✅Declares a class method.
✅The first parameter must be cls, which can be used to access class attributes.
✅The class method can only access the class attributes but not the instance attributes.
✅The class method can be called using ClassName.MethodName() and also using object.
Source_link
Builtin decorators
@classmethod
✅Declares a class method.
✅The first parameter must be cls, which can be used to access class attributes.
✅The class method can only access the class attributes but not the instance attributes.
✅The class method can be called using ClassName.MethodName() and also using object.
Source_link
Builtin decorators
@staticmethod
✅ Declares a static method in the class.
✅ It cannot have cls or self parameter.
✅ The static method cannot access the class attributes or the instance attributes.
✅ The static method can be called using ClassName.MethodName() and also using object.MethodName().
✅ It can return an object of the class.
Source_link
@staticmethod
✅ Declares a static method in the class.
✅ It cannot have cls or self parameter.
✅ The static method cannot access the class attributes or the instance attributes.
✅ The static method can be called using ClassName.MethodName() and also using object.MethodName().
✅ It can return an object of the class.
Source_link
SQLAlchemy is usually referred to as an Object Relational Mapper (ORM), although it is much more full featured than any of the other Python ORMs .
SQLAlchemy was created by Michael Bayer
Instead of hiding away SQL and object relational details behind a wall of automation, all processes are fully exposed within a series of composable, transparent tools. The library takes on the job of automating redundant tasks while the developer remains in control of how the database is organized and how SQL is constructed.
The main goal of SQLAlchemy is to change the way you think about databases and SQL!
Source
SQLAlchemy was created by Michael Bayer
Instead of hiding away SQL and object relational details behind a wall of automation, all processes are fully exposed within a series of composable, transparent tools. The library takes on the job of automating redundant tasks while the developer remains in control of how the database is organized and how SQL is constructed.
The main goal of SQLAlchemy is to change the way you think about databases and SQL!
Source
Forwarded from Jakhongir Rakhmonov - IT
Updated my course. It now also teaches you how to write your own ORM:
https://mobile.twitter.com/testdrivenio/status/1366746063600762881
https://mobile.twitter.com/testdrivenio/status/1366746063600762881
Twitter
TestDriven.io
Building Your Own Python Web Framework - course updated! testdriven.io/courses/python… We added 4 new chapters on developing your own Object Relational Mapper (ORM) via Test-driven Development! by @rahmon0v #Python
#Some_JWT_Notes
The access token is usually short-lived (expires in 5 min or so, can be customized though).
The refresh token lives a little bit longer (expires in 24 hours, also customizable). It is comparable to an authentication session. After it expires, you need a full login with username + password again.
Source
The access token is usually short-lived (expires in 5 min or so, can be customized though).
The refresh token lives a little bit longer (expires in 24 hours, also customizable). It is comparable to an authentication session. After it expires, you need a full login with username + password again.
Source
Simple is Better Than Complex
How to Use JWT Authentication with Django REST Framework
JWT stand for JSON Web Token and it is an authentication strategy used by client/server applications where theclient is a Web application using JavaScript and some frontend framework like Angular, ...