第一种方法:
x = "some data you want to return"
return x, 200, {'Content-Type': 'text/css; charset=utf-8'}
34篇 python related articles
第一种方法:
x = "some data you want to return"
return x, 200, {'Content-Type': 'text/css; charset=utf-8'}
如下,有两个list需要合并
list1 = ['a', 'b', 'c']
list2 = ['c', 'd', 'e']
期望合并结果为
['a', 'b', 'c', 'd', 'e']
以下方法可以合并
list1 + list2
list1.extend(list2)
[*list1, *list2]
list1 += list2
主要是python.linting.flake8Args
中加上 --ignore
参数 即可
{
"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
"python.linting.flake8Args": [
"--max-line-length=248",
"--ignore=F403,F405"
],
"python.linting.pylintEnabled": false
}
标题可能有点难以描述。举个例子。我有一个配置文件。
CONFIG = {
'app_name': 'ZiXi',
'mysql': {
'host': '127.0.0.1',
}
'version': 'v2.0.11',
}
通常可以通过CONFIG['mysql']['host']
这种方式访问,但我们还是想更简单点访问。如
CONFIG.mysql.host
,那么有几种方法。
项目地址:https://github.com/lkiesow/python-feedgen
文档地址:https://lkiesow.github.io/python-feedgen/
示例:
from feedgen.feed import FeedGenerator
def feed():
"""
Generate atom feed
"""
entries = parse_posts(0, C.feed_count)
fg = FeedGenerator()
fg.id(str(len(entries)))
fg.title(C.title)
fg.subtitle(C.subtitle)
fg.language(C.language)
fg.author(dict(name=C.author, email=C.email))
fg.link(href=C.root_url, rel='alternate')
fg.link(href=make_abs_url(C.root_url, 'feed'), rel='self')
for entry in entries:
fe = fg.add_entry()
fe.id(entry.get('url'))
fe.title(entry.get('title'))
fe.published(entry.get('date'))
fe.updated(entry.get('updated') or entry.get('date'))
fe.link(href=make_abs_url(C.root_url, entry.get('url')), rel='alternate')
fe.author(dict(name=entry.get('author'), email=entry.get('email')))
fe.content(entry.get('body'))
atom_feed = fg.atom_str(pretty=True)
return atom_feed
Dockerfile中加上最下面那两句
FROM python:3.8-slim
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
pip install pip-autoremove
pip-autoremove somepackage -y
一行命令更新旧的pip包
pip list --outdated --format freeze|awk -F'=' '{print $1}'|xargs pip install --upgrade
~/.pip/pip.conf
配置参考:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
cat /proc/sys/kernel/random/uuid
#!/usr/bin/python
import uuid
print uuid.uuid1()
print uuid.uuid4()
python3 适用,执行shell命令
import subprocess
def run(args):
out = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
stdout, stderr = out.communicate()
return stdout
print(run(['ls', '-l']))
import os
os.system('ps -ef')
import os
os.popen('ls')