誰告訴你字符串可以直接用dict()轉(zhuǎn)換為字典的?
已經(jīng)解決了 缺少mysqlclient
pip install mysqlclient
用pd.concat([df1,df2],axis=1,join='inner'),取并集
url > 1024 這個問題怎么說呢,確實有點保守了,我已經(jīng)把源代碼hack 了,所以不存在這個問題,一般瀏覽器都是支持到2048長度
并不是200就一定代表成功,目測這應(yīng)該是豆瓣的一個默認(rèn)攔截頁面,可能判斷到你的請求非法,然后自動跳轉(zhuǎn)到一個默認(rèn)頁面了。
已解決:
import threading
import time
def test1():
while True:
print '111111111111'
time.sleep(2)
def test2():
while True:
print '22222222222'
time.sleep(10)
print '222222222222end'
break
return
def test3():
thread_list_all = threading.enumerate()
while True:
thread_list1 = threading.enumerate()
thread_list_number = len(thread_list1)
if thread_list_number < 4:
dead_thread = list(set(thread_list_all).difference(set(thread_list1)))
for item_thread in dead_thread:
fun_name = item_thread.getName()
if fun_name == 'test1':
t1 = threading.Thread(target=test1,name='test1')
t1.start()
t1.join()
elif fun_name == 'test2':
t2 = threading.Thread(target=test2,name='test2')
t2.start()
t2.join()
time.sleep(1)
t1 = threading.Thread(target=test1,name='test1')
t2 = threading.Thread(target=test2,name='test2')
while True:
if t1.isAlive() is False:
t1 = threading.Thread(target=test1,name='test1')
t1.start()
# t1.join()
if t2.isAlive() is False:
t2 = threading.Thread(target=test2,name='test2')
t2.start()
# t2.join()strip()的參數(shù)不支持正則表達(dá)式,參數(shù)是字符序列,字符串收尾包含在那個序列里的就刪除,舉個例子:
In [1]: se = "+dwjsdd"
In [2]: se
Out[2]: '\+dwjsd\d'
In [3]: se.strip("d+")
Out[3]: 'wjs'
proc = subprocess.Popen(args,shell=True,stdout=open(outimploc, 'w'), stderr=open(outimplocerr,'w'),stdin = subprocess.PIPE, cwd=self.tranusConf.workingDirectory).communicate()
原來要這樣處理,不會報錯winerror 6
import subprocess
from Action.SYS.get import *
from Action.SYS.Log import *
from Action.File.FileEvent import *
import os
class System:
__get=None
__OS=''
__file=None
def __init__(self):
self.__get=get()
self.__OS=self.__get.getOS()
self.__file=FileEvent()
def serverListenByPort(self,address, port, netstatus="ESTABLISHED"):
result = []
statuspos=0
if self.__OS=='Linux':
subp = subprocess.Popen('netstat -ano | grep %s:%s' % (address, port), stdout=subprocess.PIPE)
statuspos=5
while True:
buff = subp.stdout.readline()
buff = str(buff, encoding='utf-8')
buffers = buff.split()
try:
if str(buffers[statuspos]).strip() == netstatus:
buffers.append(self.__OS)
result.append(buffers)
except Exception as e:
pass
if buff == '' or buff == None:
break;
if self.__OS=='Windows':
try:
outimploc = self.__file.get_dir() + '/out.txt';
outimplocerr = self.__file.get_dir() + '/error.txt';
tranusConf = self.__file.get_dir()
subp = subprocess.Popen('netstat -ano', stdout=open(outimploc, 'w'), stderr=open(outimplocerr, 'w'),stdin=subprocess.PIPE, cwd=tranusConf).communicate()
statuspos = 3
try:
f = open(outimploc, 'r')
while True:
line=''
try:
line = f.readline()
linsplit = str(line).strip().split()
if linsplit[1].strip() == '%s:%s' % (str(address).strip(),str(port).strip()):
if linsplit[3].strip()==netstatus:
linsplit.append(self.__OS)
result.append(linsplit)
except Exception as e:
Log.log('error', str(e))
if line == '' or line == None:
break;
f.close()
except Exception as e:
Log.log('error', str(e))
except Exception as e:
Log.log('error',str(e))
return resultpython 有全局解釋鎖(GIL),出現(xiàn)這現(xiàn)象是應(yīng)該的。如果希望同時執(zhí)行,需要用多進(jìn)程模塊(multiprocess)
首先回答你的問題:程序主進(jìn)程退出之后,其子進(jìn)程或子線程都會終止。
在簡單說下你上面的例子的線程:
1,os.fork是個比較特殊的方法,一般函數(shù)都是一次調(diào)用一次返回,但是它不同,它是一次調(diào)用兩次返回(一次在主進(jìn)程一次在子進(jìn)程),所以你看到print('main')執(zhí)行之后,其實主進(jìn)程還沒有退出(可以將sleep時間加大,然后通過ps命令查看);
2,第二個例子就很好的說明了:程序主進(jìn)程退出之后,其子進(jìn)程或子線程都會終止。
上代碼:
地址池創(chuàng)建
class Mysql(object):
__instance = None
def __new__(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = super(Mysql, cls).__new__(cls, *args, **kwargs)
return cls.__instance
def __init__(self):
self.mysql = PooledDB(creator=pymysql, mincached=10, maxcached=20,
host='127.0.0.1', port=3306, user='chinamap', passwd='p-0p-0p-0',
db='operation', charset="utf8")
def getAll(self, sql):
print(id(self.mysql))
_conn = self.mysql.connection()
_cursor = _conn.cursor()
_cursor.execute(sql)
result = _cursor.fetchall()
_cursor.close()
_conn.close()
return result
另外兩個 引用的代碼
from tt4 import Mysql
import time
mysql = Mysql()
print(id(mysql))
ssql= "select * from tz_ioip"
while True:
result = mysql.getAll(ssql)
print(result)
time.sleep(5)
傳入可變參數(shù)時,用 PyTuple_Size() 獲取參數(shù)個數(shù),然后用 PyTuple_GetItem() 循環(huán)讀取每個參數(shù)值,最后根據(jù)情況轉(zhuǎn)換參數(shù)值。
請參考下面的代碼
/*
此 python 擴展示例代碼,計算整數(shù)數(shù)組和,如下:
from liyi import psum
psum(1, 2)
psum(10, 20, 30)
try:
psum('a', 1)
except TypeError:
pass
## 編譯命令(以 linux 為例)
cc -g -Wall `python3.6-config --cflags` -o demo demo.c `python3.6-config --ldflags`
## 參考
https://docs.python.org/3/c-api/index.html
*/
#include <Python.h>
// 計算整數(shù)數(shù)組和
static PyObject* psum(PyObject *self, PyObject *args)
{
int sum = 0;
for (int i=0; i<PyTuple_Size(args); i++) {
PyObject *item = PyTuple_GetItem(args, i);
// 數(shù)組元素必須是整型
if (!PyLong_Check(item)) {
char message[128];
snprintf(message, sizeof(message), "%d-th item must be long", i);
PyErr_SetString(PyExc_TypeError, message);
return NULL;
}
sum += PyLong_AsLong(item);
}
return PyLong_FromLong(sum);
}
static PyMethodDef Methods[] = {
{"psum", psum, METH_VARARGS, "Return sum of integer array"},
{NULL, NULL, 0, NULL}
};
static PyModuleDef Module = {
PyModuleDef_HEAD_INIT,
"liyi", NULL, -1, Methods,
NULL, NULL, NULL, NULL
};
static PyObject* PyInit(void)
{
return PyModule_Create(&Module);
}
int main(int argc, char *argv[])
{
PyImport_AppendInittab("liyi", &PyInit);
Py_Initialize();
PyRun_SimpleString(
"from liyi import psum\n"
"for numbers in [(1,2), (10,20,30)]:\n"
" print('%s = %d' % ('+'.join(map(str, numbers)), psum(*numbers)))\n"
"try:\n"
" psum('a', 1)\n"
"except TypeError:\n"
" import traceback; traceback.print_exc()\n"
);
if (Py_FinalizeEx() < 0) {
exit(1);
}
return 0;
}你這已經(jīng)是線性時間復(fù)雜度了,再低的話除非是對數(shù)時間
這有啥需要遞歸的, 一個for 加個if 判斷不就完事了。。。 或者你的想法沒有表達(dá)清楚?
字典取值
···python
for i in list:
if i["isEnd"] == no:
request
else:
break
···
mysqldump備份腳本加個參數(shù) --single-transaction
感謝β_3000的啟發(fā),原來好多東西在紙上畫畫就會清楚很多。
a = arange(12).reshape(3,4)
i = array( [ [0,1],
[1,2] ] )
j = array( [ [2,1],
[3,3] ] )
print(a[i])
print(a[i,j])
a是一個二維數(shù)組,用二維數(shù)組i索引后竟然變成一個三維數(shù)組,如圖:
那么a[i,j]就是在a[i]上再按j索引一次?我不知道對不對,至少從結(jié)果上看是對了。
外鍵在mysql系統(tǒng)里只是一個邏輯結(jié)構(gòu)定義,為了性能考慮,mysql會自動為每個外鍵創(chuàng)建一個索引結(jié)構(gòu)段,而你定義了兩個外鍵,其中有一個已經(jīng)是主鍵或者某個索引的組成部分,并且滿足最左匹配原則,所以只會為你創(chuàng)建另外一個外鍵的索引
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國制造2025”,實現(xiàn)中華民族偉大復(fù)興的升級產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。