python document:
https://docs.python.org/2.7/tutorial/controlflow.html#unpacking-argument-lists
https://www.cnblogs.com/vipchenwei/p/7239953.html
https://stackoverflow.com/questions/44718746/decode-hex-pcap-packet-in-scapy/48358392?r=SearchResults#48358392
def read_hex():
old_stdin = sys.stdin
sys.stdin = open(‘new_file’, ‘r’)
pkt=Ether(import_hexcap())
sys.stdin = old_stdin
return pkt
wrpcap(“temp.cap”,pkts)
** params
python document:
https://docs.python.org/2.7/tutorial/controlflow.html#unpacking-argument-lists
#optparse.py
def set_defaults(self, **kwargs):
self.defaults.update(kwargs)
#app.py
@classmethod
def set_defaults(cls, parser):
default_config = {}
with open(cls.default_config_file, 'r') as f:
json_str = json.load(f)
default_config = json.loads(json_str)
#must use "**default_config" instead of "default_config"
#if you use "default_config", you will have the following error
#TypeError: set_defaults() takes 0 positional arguments but 1 was given
parser.set_defaults(**default_config)
dict.pop
pop(key[, default])
If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.
endpoint = self.name + '+' + \
options.pop("endpoint", f.__name__)
pycharm auto import
ModuleNotFoundError: No module named ‘MySQLdb’
pip install mysql-connector-python
SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://root:123456@127.0.0.1:3307/wx_flask'
TypeError: Object of type ‘User’ is not JSON serializable
@api.route('/<int:uid>', methods=['GET'])
def super_get_user(uid):
user = User.query.filter_by(id=uid).first()
return jsonify(dict(user))
class User(db.Model):
id = Column(Integer, primary_key=True)
email = Column(String(24), unique=True, nullable=False)
nickname = Column(String(24), unique=True)
auth = Column(SmallInteger, default=1)
def keys(self):
return ['id', 'email', 'nickname', 'auth']
def __getitem__(self, item):
return getattr(self, item)
sqlachemy can’t create table
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
###must import User here, otherwise you can't create table
from app.models.user import User
db.init_app(app)
db.create_all(app=app)
pycharm robot setting
https://blog.csdn.net/diya323/article/details/82355624
class variable & instance variable
class MyException:
"""class variable & instance variable
"""
code = 600
description = None
fields = ["id", "name"]
def get_code(self):
return self.code
def set_code(self, code1):
self.code = code1
def del_code(self):
del self.code
def del_cls_field(self, field):
self.fields.remove(field)
ex = MyException()
ex.set_code(100)
print(ex.get_code())
ex.del_cls_field("id")
ex1 = MyException()
print(ex1.get_code())