import time
import random
from multiprocessing import Process
def run(name):
print('%s runing' %name)
time.sleep(random.randrange(1,5))
print('%s running end' %name)
p1=Process(target=run,args=('anne',)) #必须加,号
p2=Process(target=run,args=('alice',))
p3=Process(target=run,args=('biantai',))
p4=Process(target=run,args=('haha',))
p1.start()
p2.start()
p3.start()
p4.start()
print('主线程')
enumerate还可以接收第二个参数,用于指定索引起始值,如:
list1 = ["这", "是", "一个", "测试"]
for index, item in enumerate(list1, 1):
print index, item
>>>
1 这
2 是
3 一个
4 测试
import os
os.path.exists(test_file.txt)
#True
os.path.exists(no_exist_file.txt)
#False
希望仅从非常大的csv的第一行和最后一行创建一个pandas DataFrame。本练习的目的是能够轻松地从这些csv文件中的第一个和最后一个条目中获取一些属性。我使用以下方法抓住csv的第一行没有问题:
pd.read_csv(filename, nrows=1)
我也可以通过各种方式抓取文本文件的最后一行,例如:
with open(filename) as f:
last_line = f.readlines()[-1]
显示动态数据,展示界面!不学习了,现在改用dash,在网页端展示更加合!
Traceback (most recent call last):
File "app_example.py", line 7, in <module>
import dash
File "C:\Users\lizsc\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\dash\__init__.py", line 1, in <module>
from .dash import Dash, no_update # noqa: F401
File "C:\Users\lizsc\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\dash\dash.py", line 18, in <module>
from flask_compress import Compress
File "C:\Users\lizsc\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\flask_compress.py", line 10, in <module>
import brotli
File "C:\Users\lizsc\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\brotli.py", line 8, in <module>
import _brotli
ImportError: DLL load failed while importing _brotli: The specified module could not be found.
In my case helped installing both vc_redist:
x86: vc_redist.x86.exe
x64: vc_redist.x64.exe
from here https://support.microsoft.com/en-gb/help/2977003/the-latest-supported-visual-c-downloads
Additionally make sure that you updated Python/Windows and other software to newest versions and restarted machine.
Tested on Windows 10 Pro, Python 3.8.5, PyCharm 2020.2 .
Share
Follow
这个坑太大了,好久才找到方法。
import datetime
if __name__ == '__main__':
a = datetime.datetime.now().replace(microsecond=0)
print(a, type(a))
运算结果:
2020-05-22 12:13:42 <class 'datetime.datetime'>
Process finished with exit code 0
queryDays = 2
rule = lambda x : '60S' if x <= 10 else ( '2T' if x <=30 else ( '5T' if x <=60 else ( '20T' if x <= 120 else '30T')))
print(rule(queryDays))
timesp = 160000000
timeobj = time.localtime(timesp)
t1 = datetime.datetime.fromtimestamp(timesp)
t = datetime.datetime.strftime(t1,'%Y-%m-%d %H:%M:%S')
print(t)
^\s*(?=\r?$)\n
Host OfficeDBServer01
HostName office.comcj.club
Port 2256
User root
IdentityFile "C:\Users\Administrator\.ssh\id_rsa"
Host AliYunThreeYear
HostName 101.200.91.223
User root
IdentityFile "C:\Users\Administrator\.ssh\id_rsa"
Host OfficeWebServer01
HostName office.comcj.club
Port 2253
User root
IdentityFile "C:\Users\Administrator\.ssh\id_rsa"
在flask中遇到这种错,很容易解决,就是没有设置secret_key,django在配置文件中自动生成secret_key
# 两种方式设置secret_key
# app.secret_key = 'TPmi4aLWRbyVq8zu9v82dWYW1'
app.config["SECRET_KEY"] = 'TPmi4aLWRbyVq8zu9v82dWYW1'
本文章使用limfx的vscode插件快速发布