# -*- coding: utf-8 -*-importsyssys.path.extend(['/home/charlie/ssd/toshan'])fromstock_research.data_functionsimport*# 先import自己的包,如果重复需要用比如pandas,后面再import,之前的话都是灰色了fromdatetimeimportdatetimeimportmatplotlib.pyplotaspltimportosfromcollectionsimportOrderedDict# python 3.7 ...
pythonCopy codeimport logging logging.basicConfig(filename='app.log',level=logging.DEBUG,format='%(asctime)s - %(levelname)s - %(message)s') 2. 使用配置文件 对于复杂的应用程序,使用配置文件来配置 logging 更为方便。可以通过fileConfig函数加载配置文件,其中配置文件采用 INI 格式。 代码语言:javascri...
在我的电脑上(MacBook Pro),这是我拥有的最新 Python 版本: >>>importsys>>>print(sys.version)3.7.0a3(default,Jan272018,00:46:45)[Clang9.0.0(clang-900.0.39.2)] 因此,你可以看到这个版本是 Python 3.7 的 alpha 版本,将于 2018 年 6 月发布。前面的文本是我在控制台中输入的一小段 Python 代码。
import configparser config=configparser.ConfigParser() config['url']={'url':'www.baidu.com'} #类似于字典操作 with open('example.ini','w') as configfile: config.write(configfile) 1. 2. 3. 4. 5. 6. 7. 2.JSON格式 JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全...
Walking Through Dictionary Values: The .values() MethodAnother common need that you’ll face when iterating through dictionaries is to loop over the values only. The way to do that is to use the .values() method, which returns a view with the values in the underlying dictionary:...
2. from .. import 如果想直接使用其他模块的变量或其他,而不加'模块名+.'前缀,可以使用from .. import。 例如想直接使用sys的argv,from sys import argv 或 from sys import * 3. 模块的__name__ 每个模块都有一个名称,py文件对应模块名默认为py文件名,也可在py文件中为__name__赋值;如果是__name_...
fromioimportBytesIOdefget(app, path ='/', query =''): response_status = [] response_headers = []defstart_response(status, headers): status = status.split(' ',1) response_status.append((int(status[0]), status[1])) response_headers.append(dict(headers)) ...
>>> import weakref, gc >>> class A: ... def __init__(self, value): ... self.value = value ... def __repr__(self): ... return str(self.value) ... >>> a = A(10) # create a reference >>> d = weakref.WeakValueDictionary() >>> d['primary'] = a # does not cre...
1import functools 2import time 3 4# ... 5 6def timer(func): 7 """Print the runtime of the decorated function""" 8 @functools.wraps(func) 9 def wrapper_timer(*args, **kwargs): 10 start_time = time.perf_counter() 11 value = func(*args, **kwargs) 12 end_time = time.perf...
[0]="List item 1 again"# We're changing the item.>>>mylist[-1]=3.21# Here, we refer to the last item.>>>mydict={"Key 1":"Value 1",2:3,"pi":3.14}>>>mydict["pi"]=3.15# This is how you change dictionary values.>>>mytuple=(1,2,3)>>>myfunction=len>>>printmy...