redis的安装和使用
可以在GitHub下载redisdesktopmanager,这是一个交互软件,不用下载最新的,要收费。以前的版本是免费的
在GitHub上下载redis
redis的使用教程可以看官方文档。
redis官方文档
在爬虫设置ip代理池的时候需要用到
python super()函数
继承父类的函数
python classmethod()函数
不用实例化就能用到类里面的函数
from datetime import date
# random Person
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
#注意这里的@classmethod,cls接受类Person作为参数,而不是Person的对象/实例
@classmethod
def fromBirthYear(cls, name, birthYear):
return cls(name, date.today().year - birthYear)
def display(self):
print(self.name + "'s age is: " + str(self.age))
person = Person('Adam', 19)
person.display()
#这里可以通过实例person调用frombirthyear函数,这个函数返回name,age给Person类
person.fromBirthYear('yu',1997).display()
#这里不需要实例化,可以看成直接从Person类中调用frombirthyear函数。
person1 = Person.fromBirthYear('John', 1985)
person1.display()
python 装饰器
def make_pretty(func):
def inner():
print("I got decorated")
func()
return inner
def ordinary():
print("I am ordinary")
ordinary()
pretty = make_pretty(ordinary)
#这里将ordinary函数传入make_pretty所需的参数中,添加ordinary()函数给inner()函数,然后再返回给pretty。
pretty()
@make_pretty
def ordinary():
print("I am ordinary")
#函数头顶有个@,说明这个oridinary函数是要当成参数添加到make_pretty函数当中的。
#用@的方法和下面这种等价
def ordinary():
print("I am ordinary")
pretty = make_pretty(ordinary)