python中split() 后的list 为什么len为1?

str1 = "11,12,13,14"
list1 = str1.split(',')
print(len(list1))
1

1个回答

半角和全角的逗号是两个不同的字符

一个是,一个是 ,

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
python多线下载为什么下载不了?starting failed
代码: ``` from downloader import Downloader #, cStringIO, cPickle from threading import Thread from time import sleep import log2 as log from os.path import basename import requests as req import pickle from os.path import exists db='E:/tmp/download.data' def append(obj): try: if exists(db): with open(db,'rb') as f: data=pickle.load(f) else: data={} except: data={} data[obj['url']]=obj with open(db,'wb') as f: pickle.dump(data,f) def load(url): if not exists(db): return None try: with open(db,'rb') as f: data=pickle.load(f) return data.get(url) except: return None def out(msg): print(msg) import time from os.path import basename, exists, getsize from queue import Queue from threading import Lock, Thread, current_thread import requests as req import random as rand import conf class Downloader: KB=1024 MB=KB*KB GB=KB*MB range_size=MB max_workers=10 spd_refresh_interval=1 user_agents=[ 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1', 'Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2225.0 Safari/537.36' 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36', 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0' ] chunk_size=KB max_error=0.1 #单线程允许最大出错率 max_error_one_worker=0.5 #仅剩一个线程时允许的最大出错率 home='E:/tmp/' #下载目录 def __init__(self,c): self.__locks={i:Lock() for i in ('file','worker_info','itr_job','download_info')} self.__config=c self.__alive=False self.__fails=Queue() self.__conf=c c=conf.load(c['url']) if c: self.__conf=c self.__init_from_conf() else: self.__init_task() def __init_from_conf(self): self.__download_offset=self.__conf['offset'] for i in self.__conf['fails']: self.__fails.put(i) def __get_agent(self): return self.user_agents[rand.randint(0,len(self.user_agents)-1)] def __init_task(self): headers={'Range':'bytes=0-0'} headers = {'Host': 'https://files.pythonhosted.org/packages/','User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER','Referer': 'https://pypi.org/', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, sdch, br', 'Accept-Language': 'zh-CN,zh;q=0.8'} headers['User-Agent']=self.__get_agent() print(headers) try: r=req.get(self.__conf['url'],headers=headers,stream=True) self.__conf['name'] = basename(self.__conf['url']) or str(int(round(time.time()*1000))) self.__conf['206'] = r.status_code == 206 or r.headers.get('Accept-Ranges')=='bytes' if self.__conf['206']: self.__conf['len']=int(r.headers['Content-Range'].split('/')[-1]) elif r.status_code!=200: out('init task err') return else: self.__conf['len']=int(r.headers['Content-Length']) r.close() self.__download_offset=0 self.__conf['init']=True except Exception as e: out(e) def __itr_job(self): if self.__locks['itr_job'].acquire(): if not self.__fails.empty(): ans=self.__fails.get() elif self.__download_offset<self.__conf['len']: o=self.__download_offset ans=(o,min(self.__conf['len']-1,o+self.range_size-1)) self.__download_offset+=self.range_size else: ans=(-1,-1) self.__locks['itr_job'].release() return ans def __has_job(self): if self.__locks['itr_job'].acquire(): ans=self.__download_offset<self.__conf['len'] or not self.__fails.empty() self.__locks['itr_job'].release() return ans def __download_no_206(self): headers={'User-Agent':self.__get_agent()} r=req.get(self.__conf['url'],headers=headers,stream=True) self.__download_offset=0 if r.status_code != 200: r.close() self.__stopped() return try: for con in r.iter_content(chunk_size=self.chunk_size): if self.__kill_signal: break self.__file.write(con) l=len(con) self.__down_bytes+=l self.__download_offset+=l t0=time.time() t=t0-self.__last_time if t>=self.spd_refresh_interval: self.__down_spd=self.__down_bytes/t out('downspd: %d KB/s'%(self.__down_spd/self.KB)) self.__last_time=t0 self.__down_bytes=0 except: pass r.close() self.__stopped() def __download_206(self): file_len=self.__conf['len'] total=0 error=0 kill=False with req.session() as sess: while True: s,e=self.__itr_job() if s==-1: out('no job stop') break headers={'Range':'bytes=%d-%d'%(s,e)} headers['User-Agent']=self.__get_agent() try: r=sess.get(self.__conf['url'],headers=headers,stream=True) total+=1 if r.status_code!=206: self.__fails.put((s,e)) error+=1 if error>self.max_error*total: if self.__locks['worker_info'].acquire(): num=self.__current_workers self.__locks['worker_info'].release() if error>self.max_error_one_worker*total or num>1: break continue for con in r.iter_content(chunk_size=self.chunk_size): if self.__locks['worker_info'].acquire(): if self.__kill_signal: self.__locks['worker_info'].release() kill=True break self.__locks['worker_info'].release() if self.__locks['file'].acquire(): self.__file.seek(s) self.__file.write(con) l=len(con) s+=l self.__locks['file'].release() if self.__locks['download_info'].acquire(): self.__down_bytes+=l t0=time.time() t=t0-self.__last_time if t>=self.spd_refresh_interval: out('downspd: %d KB/s'%(self.__down_spd/self.KB)) self.__down_spd=self.__down_bytes/t self.__down_bytes=0 self.__last_time=t0 self.__locks['download_info'].release() if s<=e and s<file_len: self.__fails.put((s,e)) if kill: break except : self.__fails.put((s,e)) error+=1 if error>self.max_error*total: if self.__locks['worker_info'].acquire(): num=self.__current_workers self.__locks['worker_info'].release() if error>self.max_error_one_worker*total or num>1: break self.__stopped() def __start_worker(self,target): if self.__locks['worker_info'].acquire(): if self.__kill_signal: self.__locks['worker_info'].release() return False if self.__current_workers<self.max_workers: Thread(target=target).start() self.__current_workers+=1 out('new worker started,current workers %d'%self.__current_workers) self.__locks['worker_info'].release() return True def __start_workers(self): for _ in range(self.max_workers): if not self.__start_worker(self.__download_206): break time.sleep(0.8) def start(self): if self.__alive: out('already started!') return if self.__conf.get('status')=='done': out('already done') return self.__alive=True self.__kill_signal=False self.__conf['status']='working' self.__down_bytes=0 self.__down_spd=0 self.__last_time=0 self.__current_workers=0 self.__start_time=time.time() try: path=self.home+self.__conf['name'] self.__file=open(path,(exists(path) and 'rb+') or 'wb' ) if not self.__conf['206']: Thread(target=self.__start_workers).start() else: self.__start_worker(self.__download_no_206) out('starting done!') except: out('starting failed') def stop(self): if self.__kill_signal: return out('stopping') if self.__locks['worker_info'].acquire(): self.__kill_signal=True if self.__conf['status']=='working': self.__conf['status']='stopped' self.__locks['worker_info'].release() def __after_stopped(self): if not self.__kill_signal: self.__kill_signal=True __alive=False self.__file.close() out('total time: %.2f'%(time.time()-self.__start_time)) self.__conf['offset']=self.__download_offset if not self.__has_job(): self.__conf['status']='done' elif self.__conf.get('status')!='stopped': self.__conf['status']='error' leak=0 ls=[] while not self.__fails.empty(): i=self.__fails.get() leak+=i[1]-i[0]+1 ls.append(i) self.__conf['fails']=ls leak+=max(self.__conf['len']-self.__download_offset,0) out('total leak: %d'%leak) conf.append(self.__conf) def __stopped(self): if self.__locks['worker_info'].acquire(): self.__current_workers-=1 out('%s stopped'%current_thread().name) if self.__current_workers==0: self.__after_stopped() self.__locks['worker_info'].release() #!/usr/bin/env python # coding=utf-8 #import importlib,sys #import sys #sys.setdefaultencoding('gbk') '''import sys import imp import sys reload(sys) sys.setdefaultencoding('utf8') ''' ''' import sys sys.setdefaultencoding('utf-8') import jieba import json''' def main(): from bs4 import BeautifulSoup import urllib.request import urllib.parse as parse import ssl import re import os,os.path import codecs import requests def getHtml(url): global html page = urllib.request.urlopen(url) html = page.read() return html def file(url1,file_name,name): print(url1) #file(name,save_path,filename) #url1= +'/' + filename url1=url1.encode() #file = open(name ,'wb+') #file.write(url1 ) #file.close() #print(file_name) headers = {'Host': 'https://files.pythonhosted.org/packages/','User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER','Referer': 'https://pypi.org/', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, sdch, br', 'Accept-Language': 'zh-CN,zh;q=0.8'} #req = urllib.urlretrieve(download_url,headers=headers) #urllib.request.urlopen('https://www.lfd.uci.edu/~gohlke/pythonlibs/') #req = urllib.request.Request(url=url,headers=header) #request = urllib.request.urlopen(url1) #response = urllib.request.urlopen(request) import socket import urllib.request #设置超时时间为30s socket.setdefaulttimeout(5) #解决下载不完全问题且避免陷入死循环 '''try: urllib.request.urlretrieve(url1.decode(),name) except socket.timeout:''' count = 1 while count <= 1: import time # 格式化成2016-03-20 11:45:39形式 print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) # 格式化成Sat Mar 28 22:24:24 2016形式 print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime())) # 将格式字符串转换为时间戳 a = "Sat Mar 28 22:24:24 2016" print(time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y"))) try: urllib.request.urlretrieve(url1.decode(),name) print('\nchangshi'+str(count)+'over\n') break except socket.timeout: err_info = 'Reloading for %d time'%count if count == 1 else 'Reloading for %d times'%count print(err_info) count += 1 except urllib.error.HTTPError: print('urllib.error.HTTPError') except urllib.error.URLError: print('urllib.error.URLError') except ssl.SSLWantReadError: print('ssl.SSLWantReadError') if count > 1: print("downloading picture fialed!") #urllib.request.urlretrieve(url1.decode(),name) global i i += 1 print(url1.decode()) #file = open(name ,'wt+') #file.write(str(req.content())) #file.close() print(file_name) global x print("Completed : .... %d ..." % x) '''for i in range(len(name_list)): j=0 if name_list[i-24:i+1]=='https://pypi.org/project/': name_list1.append(name_list[i+1:i+60])''' print('\n........'+name+'..........complete\n') '''headers = {'Host': 'download.lfd.uci.edu','User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER','Referer': 'https://www.lfd.uci.edu/~gohlke/pythonlibs/', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, sdch, br', 'Accept-Language': 'zh-CN,zh;q=0.8'} #req = urllib.urlretrieve(download_url,headers=headers) #urllib.request.urlopen('https://www.lfd.uci.edu/~gohlke/pythonlibs/') #req = urllib.request.Request(url=url,headers=header) request = requests.get(url=url1,headers=headers) #response = urllib.request.urlopen(request) global i i += 1 file = open(name ,'wb+') file.write(request.content) file.close() print(file_name) print("Completed : .... %d ..." % x)''' save_path = os.getcwd() url = 'https://www.lfd.uci.edu/' html = getHtml(url) html=''' </li> <li><a id="kwant"></a><strong><a href="http://kwant-project.org/">Kwant</a></strong>: quantum transport simulations made easy.<br> Requires <a href="https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy">numpy+mkl</a> and <a href="https://www.lfd.uci.edu/~gohlke/pythonlibs/#tinyarray">tinyarray</a>. <ul> <li><a href="javascript:;" onclick=" javascript:dl([101,116,54,104,51,56,113,108,46,99,118,106,49,119,109,45,50,110,115,95,112,107,47,105,97,53,52,100], &quot;A?:5C9H0ED&lt;G@0&gt;;7I7;&gt;8C34&gt;8C34&gt;&lt;F@BG=J1I7&lt;26&quot;); &quot;javascript: dl(&quot;" title="[2.5 MB] [Jul 06, 2019]">kwant‑1.4.1‑cp38‑cp38‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,45,107,108,97,47,116,113,110,99,56,49,118,46,104,50,115,105,53,112,106,119,52,51], &quot;?&gt;C6B;A541D3750:&lt;E&lt;:08BF908BF90D@7F&gt;&lt;D=2&quot;); &quot;javascript: dl(&quot;" title="[2.1 MB] [Jul 06, 2019]">kwant‑1.4.1‑cp38‑cp38‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,46,48,105,104,110,51,107,108,99,115,118,109,113,55,100,53,47,54,50,49,119,45,116,112,97,95,52,106], &quot;9BK&lt;G:?F@6DH4FEC0J01E8G5=E8G5=;ED24IH;&gt;AJ0D37&quot;); &quot;javascript: dl(&quot;" title="[2.4 MB] [Feb 28, 2019]">kwant‑1.4.0‑cp37‑cp37m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,52,112,106,45,109,51,99,108,48,104,107,46,53,118,97,105,116,113,119,47,55,50,110,49,115], &quot;HE2A1=&lt;@C:B&gt;F@3G;0;83615D3615D43B?F5E;B97&quot;); &quot;javascript: dl(&quot;" title="[2.1 MB] [Feb 28, 2019]">kwant‑1.4.0‑cp37‑cp37m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,112,99,97,49,105,54,113,115,108,109,53,52,116,51,118,106,107,110,104,50,95,47,48,45,119,100,46], &quot;7C?60&gt;:&lt;E@H2A&lt;G3J;JFG10=5G10=59GH4AD29I5;JHB8&quot;); &quot;javascript: dl(&quot;" title="[2.4 MB] [Feb 28, 2019]">kwant‑1.4.0‑cp36‑cp36m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,47,48,107,53,108,49,119,52,105,110,115,50,104,112,106,116,45,51,113,99,97,46,118,109,54], &quot;:;&gt;B=F3?026D9?@5E7E1@C=AH@C=AHG@689A;E6&lt;4&quot;); &quot;javascript: dl(&quot;" title="[2.1 MB] [Feb 28, 2019]">kwant‑1.4.0‑cp36‑cp36m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,97,51,53,50,107,46,105,54,49,47,104,52,109,100,115,118,119,108,48,112,116,45,99,113,110,106,95], &quot;&gt;3IGC?2D9FC1294@0HDE85;5BEFC12EFC12&lt;E@6HJ0&lt;=7;5@:A&quot;); &quot;javascript: dl(&quot;" title="[2.4 MB] [Feb 28, 2019]">kwant‑1.4.0‑cp35‑cp35m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,46,52,50,104,49,118,119,99,48,107,113,97,115,47,51,45,105,110,112,53,108,106,116,109], &quot;&lt;2E:B5CF=7B&gt;C=96;AF?40108?7B&gt;C?7B&gt;CG?6@A&gt;2063D&quot;); &quot;javascript: dl(&quot;" title="[2.0 MB] [Feb 28, 2019]">kwant‑1.4.0‑cp35‑cp35m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,49,108,109,119,46,113,107,97,95,99,105,110,53,51,104,100,116,112,54,50,52,115,45,118,47,106], &quot;ECI5AG&lt;@H9A=DH637;@F04=4CF9A=DF9A=D2F3:;872?BD43&gt;1&quot;); &quot;javascript: dl(&quot;" title="[2.1 MB] [Jan 06, 2018]">kwant‑1.3.2‑cp34‑cp34m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,106,99,112,47,113,97,116,52,51,49,107,53,109,104,105,110,108,119,45,115,46,50,118], &quot;CE042F;6312873:A5?6B9D8DEB1287B1287&lt;BA&gt;?8EDA=@&quot;); &quot;javascript: dl(&quot;" title="[1.8 MB] [Jan 06, 2018]">kwant‑1.3.2‑cp34‑cp34m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,51,110,97,105,113,45,47,104,108,99,112,46,100,109,55,53,95,119,49,106,50,107,54,118,116,52,115], &quot;JDC4:G?H69:D&gt;6EA21H5B;B;059:D&gt;59:D&gt;=5A31@2=&lt;FI;A78&quot;); &quot;javascript: dl(&quot;" title="[13.5 MB] [May 15, 2017]">kwant‑1.1.3‑cp27‑cp27m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,55,113,108,46,104,107,106,49,115,118,99,50,119,47,45,51,97,116,110,53,109,112,105], &quot;8;61E9CA=:E;0=5&lt;@BA&gt;7373?&gt;:E;0&gt;:E;0D&gt;&lt;FB?;3&lt;42&quot;); &quot;javascript: dl(&quot;" title="[6.7 MB] [May 15, 2017]">kwant‑1.1.3‑cp27‑cp27m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,113,99,45,52,119,95,49,111,100,116,48,46,47,118,55,97,112,108,107,115,54,110,105,50,101,104,53,106,109], &quot;CGK0@=J9&lt;1@G&gt;&lt;B4?E926;:;J21@G&gt;2E7EH24FE5?L8D3;4IA&quot;); &quot;javascript: dl(&quot;" title="[13.4 MB] [Sep 11, 2015]">kwant‑1.0.5‑cp27‑none‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,106,47,105,101,113,111,97,108,50,107,45,112,104,118,48,49,110,119,99,115,53,51,46,55,116], &quot;C804;=DH1B;8G19A6@H:?F&gt;FD:B;8G:@5@3:A2@E8FA&lt;7&quot;); &quot;javascript: dl(&quot;" title="[6.7 MB] [Sep 11, 2015]">kwant‑1.0.5‑cp27‑none‑win32.whl</a></li> </ul> </li> <li><a id="la"></a><strong><a href="https://github.com/kwgoodman/la">La</a></strong>: aka larry, the labeled numpy array. <ul> <li><a href="javascript:;" onclick=" javascript:dl([101,97,109,99,108,48,51,46,110,54,50,105,47,95,53,104,113,55,45,100,112,118,52,101,115,106,116,119], &quot;G9H?CD=I;2C5=;30A46@646BFD4A2C5=A2C5=1AJ:7&lt;01B8E6J&gt;3&quot;); &quot;javascript: dl(&quot;" title="[139 KB] [Apr 11, 2016]">la‑0.7.0.dev0‑cp35‑cp35m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,108,55,110,99,112,48,47,116,106,109,115,119,118,100,53,51,104,45,105,113,46,101,50,97], &quot;:F8C4&lt;&gt;7634?&gt;60GA5D1D5D=E&lt;5A34?&gt;A34?&gt;9A;B2?FD;@0&quot;); &quot;javascript: dl(&quot;" title="[137 KB] [Apr 11, 2016]">la‑0.7.0.dev0‑cp35‑cp35m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,109,55,118,110,115,50,106,104,113,116,108,53,97,100,54,101,47,52,105,112,46,95,51,45,99,119,48], &quot;4568C2;9@HCFA@:&lt;GJD1DJD=?2JGHCFAGHCFA0GIB3E&lt;0=&gt;ADI7:&quot;); &quot;javascript: dl(&quot;" title="[137 KB] [Apr 11, 2016]">la‑0.7.0.dev0‑cp34‑cp34m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,105,48,55,112,101,52,53,99,51,115,50,109,97,47,110,118,113,106,116,108,46,119,104,100,45], &quot;9:A@3?6B=7385=C&lt;H1D2D1DG4?1H7385H7385;HE0&gt;8:DEFC&quot;); &quot;javascript: dl(&quot;" title="[136 KB] [Apr 11, 2016]">la‑0.7.0.dev0‑cp34‑cp34m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,45,105,55,100,116,97,99,106,113,101,95,54,50,110,104,47,115,119,118,109,108,52,46,53,48,112], &quot;@&lt;78IBG4?6I&lt;2?D50HF2FHF39BH06I&lt;206I&lt;2C0A1=:5C3;EFA&gt;D&quot;); &quot;javascript: dl(&quot;" title="[137 KB] [Apr 11, 2016]">la‑0.7.0.dev0‑cp27‑cp27m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,119,55,53,48,105,118,112,47,115,45,108,116,97,113,104,99,100,106,51,110,109,46,50,101], &quot;8FA=652;7?6F17:&lt;93E1E3E@G539?6F19?6F1D904CBFE0&gt;:&quot;); &quot;javascript: dl(&quot;" title="[136 KB] [Apr 11, 2016]">la‑0.7.0.dev0‑cp27‑cp27m‑win32.whl</a></li> </ul> </li> ''' print('html done') #html.decode('utf-8') #print(html) '''headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1)AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'} r = requests.get(url, headers = headers) r.encoding = "utf-8" soup = BeautifulSoup(r.text, "html.parser") #html_mod=re.sub(pattern=".",repl=".",string=html.decode('utf-8')) for link in soup.find_all('a'): #soup.find_all返回的为列表 print(link.get('href')) #name_list+=link ''' name_list = html#soup.find_all('a')#re.findall(r']">*-cp38-win_amd64.whl',html.decode('utf-8')) x=1 files=os.listdir(save_path) print(files) print(type(name_list)) name_list=str(name_list) name_list1=[] #print(name_list) #for name in name_list: k=0 # name[k]=str(name1[k]) for i in range(len(name_list)): j=0 if name_list[i-2:i+1]==']">': name_list1.append(name_list[i+1:i+60]) global m if k<len(name_list1): for l in range(len(name_list1[k])): if l-9>=0: if name_list1[k][l-4:l]=='.whl' or name_list1[k][l-3:l]=='.gz' or name_list1[k][l-4:l]=='.zip': j=1 m=l if j==1: name_list1[k]=name_list1[k][0:m] k+=1 '''if j==0: name_list.remove(name)''' #file_name = os.path.join(save_path ,name) i=0 #print(name) print(name_list1) for name in name_list1: j=0 for l in range(len(name)): if l-9>=0: if name[l-4:l]=='.whl' or name[l-3:l]=='.gz' or name[l-4:l]=='.zip': j=1 m=l if j==1: name=name[0:m] k+=1 if name in files: continue '''if name=='Delny‑0.4.1‑cp27‑none‑win_amd64.whl</a></li>\n<li>' or name==Delny‑0.4.1‑cp27‑none‑win32.whl</a></li> </ul> </: continue ''' print('no:'+str(x)) print('\ndownload '+name) # importlib.reload(sys) #imp.reload(sys) for l in range(len(name)): if l-9>=0: if name[l-4:l]=='.whl' or name[l-3:l]=='.gz' or name[l-4:l]=='.zip': j=1 m=l if j==1: name=name[0:m] k+=1 string='https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/' + name#[0:4+name.find('.whl')]#https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/ print('00'+save_path) count=0 v=0 for p in range(len(string)): if string[p]=='\\': if v==0: string=string[:6]+'//'+string[7:] else: string=string[:p]+'/'+string[p+1:] v+=1 if string[p-3:p]=='win': string=string[:p-4]+'-'+string[p-3:] if p<len(string): if (string[p]=='\u2011')==True: if p+1<len(string): string=string[:p]+'-'+string[p+1:] '''if string[p-2]>='0' and string[p-2]<='9' and string[p-1]>='0' and string[p-1]<='9': if (string[p]>='a'and string[p]<='z') or (string[p]>='A'and string[p]<='Z'): string=string[:p]+string[p+1:]''' if p>=len(string): break '''if name[:9]=='ad3‑2.2.1': print('aaa') continue''' conf={'url':string} d=Downloader(conf) d.start() #file(string,save_path,name) x=x+1 print('09'+name_list) print('finished') if __name__ == '__main__': main() ``` 求高手解决
python数据挖掘 关联规则 apriori算法运算中的问题
-*- coding: utf-8 -*- from __future__ import print_function import pandas as pd #自定义连接函数,用于实现L_{k-1}到C_k的连接 def connect_string(x, ms): x = list(map(lambda i:sorted(i.split(ms)), x)) l = len(x[0]) r = [] for i in range(len(x)): for j in range(i,len(x)): if x[i][:l-1] == x[j][:l-1] and x[i][l-1] != x[j][l-1]: r.append(x[i][:l-1]+sorted([x[j][l-1],x[i][l-1]])) return r #寻找关联规则的函数 def find_rule(d, support, confidence, ms = u'--'): result = pd.DataFrame(index=['support', 'confidence']) #定义输出结果 support_series = 1.0*d.sum()/len(d) #支持度序列 column = list(support_series[support_series > support].index) #初步根据支持度筛选 k = 0 while len(column) > 1: k = k+1 print(u'\n正在进行第%s次搜索...' %k) column = connect_string(column, ms) print(u'数目:%s...' %len(column)) sf = lambda i: d[i].prod(axis=1, numeric_only = True) #新一批支持度的计算函数 #创建连接数据,这一步耗时、耗内存最严重。当数据集较大时,可以考虑并行运算优化。 d_2 = pd.DataFrame(list(map(sf,column)), index = [ms.join(i) for i in column]).T support_series_2 = 1.0*d_2[[ms.join(i) for i in column]].sum()/len(d) #计算连接后的支持度 column = list(support_series_2[support_series_2 > support].index) #新一轮支持度筛选 support_series = support_series.append(support_series_2) column2 = [] for i in column: #遍历可能的推理,如{A,B,C}究竟是A+B-->C还是B+C-->A还是C+A-->B? i = i.split(ms) for j in range(len(i)): column2.append(i[:j]+i[j+1:]+i[j:j+1]) cofidence_series = pd.Series(index=[ms.join(i) for i in column2]) #定义置信度序列 for i in column2: #计算置信度序列 cofidence_series[ms.join(i)] = support_series[ms.join(sorted(i))]/support_series[ms.join(i[:len(i)-1])] for i in cofidence_series[cofidence_series > confidence].index: #置信度筛选 result[i] = 0.0 result[i]['confidence'] = cofidence_series[i] result[i]['support'] = support_series[ms.join(sorted(i.split(ms)))] result = result.T.sort_values(['confidence','support'], ascending = False) #结果整理,输出 print(u'\n结果为:') print(result) return result # -*- coding: utf-8 -*- inputfile = 'C:/course/c5_data1.xlsx' outputfile = 'C:/course/c5_answer.xlsx' #结果文件 data = pd.read_excel(inputfile, header = None) print(u'\n转换原始数据至0-1矩阵...') ct = lambda x : pd.Series(1, index = x[pd.notnull(x)]) #转换0-1矩阵的过渡函数 b = map(ct, data.as_matrix()) #用map方式执行 data = pd.DataFrame(list(b)).fillna(0) #实现矩阵转换,空值用0填充 #print(u'\n转换完毕。') #del b #删除中间变量b,节省内存 support = 0.2 #最小支持度 confidence = 0.5 #最小置信度 ms = '---' #连接符,默认'--',用来区分不同元素,如A--B。需要保证原始表格中不含有该字符 find_rule(data, support, confidence, ms) 出现以下 ![图片说明](https://img-ask.csdn.net/upload/202003/05/1583397715_618337.png) ``` ``` ``` ```
求助,python 报错:AttributeError: module 'log0' has no attribute 'out'怎么办?
python代码: ``` from downloader import Downloader #, cStringIO, cPickle from threading import Thread from time import sleep import log0 as log from os.path import basename import requests as req import pickle from os.path import exists db='E:/tmp/download.data' def append(obj): try: if exists(db): with open(db,'rb') as f: data=pickle.load(f) else: data={} except: data={} data[obj['url']]=obj with open(db,'wb') as f: pickle.dump(data,f) def load(url): if not exists(db): return None try: with open(db,'rb') as f: data=pickle.load(f) return data.get(url) except: return None def out(msg): print(msg) import time from os.path import basename, exists, getsize from queue import Queue from threading import Lock, Thread, current_thread import requests as req import random as rand import conf class Downloader: KB=1024 MB=KB*KB GB=KB*MB range_size=MB max_workers=10 spd_refresh_interval=1 user_agents=[ 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1', 'Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2225.0 Safari/537.36' 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36', 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0' ] chunk_size=KB max_error=0.1 #单线程允许最大出错率 max_error_one_worker=0.5 #仅剩一个线程时允许的最大出错率 home='E:/tmp/' #下载目录 def __init__(self,c): self.__locks={i:Lock() for i in ('file','worker_info','itr_job','download_info')} self.__config=c self.__alive=False self.__fails=Queue() self.__conf=c c=conf.load(c['url']) if c: self.__conf=c self.__init_from_conf() else: self.__init_task() def __init_from_conf(self): self.__download_offset=self.__conf['offset'] for i in self.__conf['fails']: self.__fails.put(i) def __get_agent(self): return self.user_agents[rand.randint(0,len(self.user_agents)-1)] def __init_task(self): headers={'Range':'bytes=0-0'} headers['User-Agent']=self.__get_agent() print(headers) try: r=req.get(self.__conf['url'],headers=headers,stream=True) self.__conf['name'] = basename(self.__conf['url']) or str(int(round(time.time()*1000))) self.__conf['206'] = r.status_code == 206 or r.headers.get('Accept-Ranges')=='bytes' if self.__conf['206']: self.__conf['len']=int(r.headers['Content-Range'].split('/')[-1]) elif r.status_code!=200: log.out('init task err') return else: self.__conf['len']=int(r.headers['Content-Length']) r.close() self.__download_offset=0 self.__conf['init']=True except Exception as e: log.out(e) def __itr_job(self): if self.__locks['itr_job'].acquire(): if not self.__fails.empty(): ans=self.__fails.get() elif self.__download_offset<self.__conf['len']: o=self.__download_offset ans=(o,min(self.__conf['len']-1,o+self.range_size-1)) self.__download_offset+=self.range_size else: ans=(-1,-1) self.__locks['itr_job'].release() return ans def __has_job(self): if self.__locks['itr_job'].acquire(): ans=self.__download_offset<self.__conf['len'] or not self.__fails.empty() self.__locks['itr_job'].release() return ans def __download_no_206(self): headers={'User-Agent':self.__get_agent()} r=req.get(self.__conf['url'],headers=headers,stream=True) self.__download_offset=0 if r.status_code != 200: r.close() self.__stopped() return try: for con in r.iter_content(chunk_size=self.chunk_size): if self.__kill_signal: break self.__file.write(con) l=len(con) self.__down_bytes+=l self.__download_offset+=l t0=time.time() t=t0-self.__last_time if t>=self.spd_refresh_interval: self.__down_spd=self.__down_bytes/t log.out('downspd: %d KB/s'%(self.__down_spd/self.KB)) self.__last_time=t0 self.__down_bytes=0 except: pass r.close() self.__stopped() def __download_206(self): file_len=self.__conf['len'] total=0 error=0 kill=False with req.session() as sess: while True: s,e=self.__itr_job() if s==-1: log.out('no job stop') break headers={'Range':'bytes=%d-%d'%(s,e)} headers['User-Agent']=self.__get_agent() try: r=sess.get(self.__conf['url'],headers=headers,stream=True) total+=1 if r.status_code!=206: self.__fails.put((s,e)) error+=1 if error>self.max_error*total: if self.__locks['worker_info'].acquire(): num=self.__current_workers self.__locks['worker_info'].release() if error>self.max_error_one_worker*total or num>1: break continue for con in r.iter_content(chunk_size=self.chunk_size): if self.__locks['worker_info'].acquire(): if self.__kill_signal: self.__locks['worker_info'].release() kill=True break self.__locks['worker_info'].release() if self.__locks['file'].acquire(): self.__file.seek(s) self.__file.write(con) l=len(con) s+=l self.__locks['file'].release() if self.__locks['download_info'].acquire(): self.__down_bytes+=l t0=time.time() t=t0-self.__last_time if t>=self.spd_refresh_interval: log.out('downspd: %d KB/s'%(self.__down_spd/self.KB)) self.__down_spd=self.__down_bytes/t self.__down_bytes=0 self.__last_time=t0 self.__locks['download_info'].release() if s<=e and s<file_len: self.__fails.put((s,e)) if kill: break except : self.__fails.put((s,e)) error+=1 if error>self.max_error*total: if self.__locks['worker_info'].acquire(): num=self.__current_workers self.__locks['worker_info'].release() if error>self.max_error_one_worker*total or num>1: break self.__stopped() def __start_worker(self,target): if self.__locks['worker_info'].acquire(): if self.__kill_signal: self.__locks['worker_info'].release() return False if self.__current_workers<self.max_workers: Thread(target=target).start() self.__current_workers+=1 log.out('new worker started,current workers %d'%self.__current_workers) self.__locks['worker_info'].release() return True def __start_workers(self): for _ in range(self.max_workers): if not self.__start_worker(self.__download_206): break time.sleep(0.8) def start(self): if self.__alive: log.out('already started!') return if self.__conf.get('status')=='done': log.out('already done') return self.__alive=True self.__kill_signal=False self.__conf['status']='working' self.__down_bytes=0 self.__down_spd=0 self.__last_time=0 self.__current_workers=0 self.__start_time=time.time() try: path=self.home+self.__conf['name'] self.__file=open(path,(exists(path) and 'rb+') or 'wb' ) if not self.__conf['206']: Thread(target=self.__start_workers).start() else: self.__start_worker(self.__download_no_206) log.out('starting done!') except: log.out('starting failed') def stop(self): if self.__kill_signal: return log.out('stopping') if self.__locks['worker_info'].acquire(): self.__kill_signal=True if self.__conf['status']=='working': self.__conf['status']='stopped' self.__locks['worker_info'].release() def __after_stopped(self): if not self.__kill_signal: self.__kill_signal=True __alive=False self.__file.close() log.out('total time: %.2f'%(time.time()-self.__start_time)) self.__conf['offset']=self.__download_offset if not self.__has_job(): self.__conf['status']='done' elif self.__conf.get('status')!='stopped': self.__conf['status']='error' leak=0 ls=[] while not self.__fails.empty(): i=self.__fails.get() leak+=i[1]-i[0]+1 ls.append(i) self.__conf['fails']=ls leak+=max(self.__conf['len']-self.__download_offset,0) log.out('total leak: %d'%leak) conf.append(self.__conf) def __stopped(self): if self.__locks['worker_info'].acquire(): self.__current_workers-=1 log.out('%s stopped'%current_thread().name) if self.__current_workers==0: self.__after_stopped() self.__locks['worker_info'].release() #!/usr/bin/env python # coding=utf-8 #import importlib,sys #import sys #sys.setdefaultencoding('gbk') '''import sys import imp import sys reload(sys) sys.setdefaultencoding('utf8') ''' ''' import sys sys.setdefaultencoding('utf-8') import jieba import json''' def main(): from bs4 import BeautifulSoup import urllib.request import urllib.parse as parse import ssl import re import os,os.path import codecs import requests def getHtml(url): global html page = urllib.request.urlopen(url) html = page.read() return html def file(url1,file_name,name): print(url1) #file(name,save_path,filename) #url1= +'/' + filename url1=url1.encode() #file = open(name ,'wb+') #file.write(url1 ) #file.close() #print(file_name) headers = {'Host': 'https://files.pythonhosted.org/packages/','User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER','Referer': 'https://pypi.org/', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, sdch, br', 'Accept-Language': 'zh-CN,zh;q=0.8'} #req = urllib.urlretrieve(download_url,headers=headers) #urllib.request.urlopen('https://www.lfd.uci.edu/~gohlke/pythonlibs/') #req = urllib.request.Request(url=url,headers=header) #request = urllib.request.urlopen(url1) #response = urllib.request.urlopen(request) import socket import urllib.request #设置超时时间为30s socket.setdefaulttimeout(5) #解决下载不完全问题且避免陷入死循环 '''try: urllib.request.urlretrieve(url1.decode(),name) except socket.timeout:''' count = 1 while count <= 1: import time # 格式化成2016-03-20 11:45:39形式 print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) # 格式化成Sat Mar 28 22:24:24 2016形式 print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime())) # 将格式字符串转换为时间戳 a = "Sat Mar 28 22:24:24 2016" print(time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y"))) try: urllib.request.urlretrieve(url1.decode(),name) print('\nchangshi'+str(count)+'over\n') break except socket.timeout: err_info = 'Reloading for %d time'%count if count == 1 else 'Reloading for %d times'%count print(err_info) count += 1 except urllib.error.HTTPError: print('urllib.error.HTTPError') except urllib.error.URLError: print('urllib.error.URLError') except ssl.SSLWantReadError: print('ssl.SSLWantReadError') if count > 1: print("downloading picture fialed!") #urllib.request.urlretrieve(url1.decode(),name) global i i += 1 print(url1.decode()) #file = open(name ,'wt+') #file.write(str(req.content())) #file.close() print(file_name) global x print("Completed : .... %d ..." % x) '''for i in range(len(name_list)): j=0 if name_list[i-24:i+1]=='https://pypi.org/project/': name_list1.append(name_list[i+1:i+60])''' print('\n........'+name+'..........complete\n') '''headers = {'Host': 'download.lfd.uci.edu','User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER','Referer': 'https://www.lfd.uci.edu/~gohlke/pythonlibs/', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, sdch, br', 'Accept-Language': 'zh-CN,zh;q=0.8'} #req = urllib.urlretrieve(download_url,headers=headers) #urllib.request.urlopen('https://www.lfd.uci.edu/~gohlke/pythonlibs/') #req = urllib.request.Request(url=url,headers=header) request = requests.get(url=url1,headers=headers) #response = urllib.request.urlopen(request) global i i += 1 file = open(name ,'wb+') file.write(request.content) file.close() print(file_name) print("Completed : .... %d ..." % x)''' save_path = os.getcwd() url = 'https://www.lfd.uci.edu/' html = getHtml(url) html=''' </li> <li><a id="imagecodecs-lite"></a><strong><a href="https://www.lfd.uci.edu/~gohlke/#python">Imagecodecs-lite</a></strong> (deprecated): a subset of <a href="https://www.lfd.uci.edu/~gohlke/pythonlibs/#imagecodecs">imagecodecs</a>. <ul> <li><a href="javascript:;" onclick=" javascript:dl([101,99,106,112,118,103,115,49,47,119,116,45,104,111,95,51,48,108,105,50,53,101,113,109,97,46,110,121,100], &quot;5B1E23C97AFG4D0&lt;KD05=@A9D:B?B?H6H&gt;6:2J&gt;:I&lt;ID:GIJH8;@&quot;); &quot;javascript: dl(&quot;" title="[1 KB] [Feb 17, 2020]">imagecodecs_lite‑2020.1.31‑py3‑none‑any.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,97,51,110,111,49,45,116,106,101,99,113,105,119,50,108,95,115,48,52,100,118,56,53,47,54,112,103,104,46,57,109], &quot;@=7:IDF6G;N0J893C89@?&gt;;685=A4ML4=L159I1E59I1E5&lt;;2?0NCHBL&lt;K&gt;&quot;); &quot;javascript: dl(&quot;" title="[148 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp38‑cp38‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,49,47,119,100,46,48,110,99,115,50,104,45,57,51,111,108,113,97,56,112,95,106,109,103,116,105,101,53,118], &quot;89E@CLKH1IFAGJ7&gt;3J78D?IHJ;950&lt;4094=;7C=B;7C=B;2I6=942:?&quot;); &quot;javascript: dl(&quot;" title="[120 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp38‑cp38‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,99,112,108,105,119,50,109,103,113,110,45,57,55,48,49,115,118,47,100,111,53,51,95,97,104,101,116,54,46,106,52], &quot;?5M81@DJA36G7I0CBI0?F23JI:5=&gt;;L&gt;5LE:01E&lt;:01E&lt;6:439FG6BKNL4H2&quot;); &quot;javascript: dl(&quot;" title="[145 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp37‑cp37m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,57,47,55,112,101,49,105,106,115,95,99,51,116,50,110,113,53,45,48,108,97,46,118,119,109,111,104,100,103], &quot;8=7?3F@&lt;16HDL4:IK4:89C6&lt;4A=B50E5=E;A:3;2A:3;2HAG6&gt;;=EGJC&quot;); &quot;javascript: dl(&quot;" title="[118 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp37‑cp37m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,115,119,50,54,47,111,112,101,48,105,103,110,100,53,109,99,45,46,97,106,51,52,118,104,95,49,116,108,113,57], &quot;02CL6F=J49&gt;B:7?5&lt;7?0HK9J7@28IMAI2AD@?6D3@?6D3&gt;@19;HB&gt;&lt;3EA1GK&quot;); &quot;javascript: dl(&quot;" title="[137 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp36‑cp36m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,50,110,116,51,97,111,104,45,95,57,103,101,99,119,115,105,118,54,108,113,112,100,109,106,49,47,46,53,48], &quot;&gt;0GCD@K2I?F4:;&lt;5E;&lt;&gt;8B?2;70LH9JH0J37&lt;D3A7&lt;D3AF7=?130J=6B&quot;); &quot;javascript: dl(&quot;" title="[112 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp36‑cp36m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,53,49,51,113,100,108,47,52,118,54,46,106,105,109,99,57,112,103,97,101,110,115,48,95,104,119,50,45,116,111], &quot;EJ;3@80L6&gt;@206&lt;=BAC&gt;M4C&gt;EG5&lt;LCKJF1?:1J:2K&gt;@20K&gt;@20=KI&lt;DGB=497:IH5&quot;); &quot;javascript: dl(&quot;" title="[133 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp35‑cp35m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,46,106,118,49,101,51,109,119,108,47,104,116,53,99,113,50,105,45,100,57,111,112,48,115,95,110,97,103], &quot;G?1&gt;E2&lt;;9=E5&lt;9@6JK4=DB4=GH8@;4A?F3C03?05A=E5&lt;A=E5&lt;6A7@I5?07:8&quot;); &quot;javascript: dl(&quot;" title="[110 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp35‑cp35m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,54,118,48,53,115,45,112,116,110,106,51,46,100,108,99,52,109,55,50,105,47,49,104,97,119,113,103,111,101,95,57], &quot;4B9I6137D&gt;6BADC@GJL&gt;K&lt;L&gt;4M=C7L5B2EN;EB;:5&gt;6BA5&gt;6BA@5HC8MG@&lt;0?;HF=&quot;); &quot;javascript: dl(&quot;" title="[145 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp27‑cp27m‑win_amd64.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,115,51,118,57,104,112,50,110,48,103,109,55,95,49,100,108,116,101,106,45,113,53,46,47,111,99,119,97,105], &quot;06BD52E@GI56;GL:K9AIH&gt;AI0&lt;?L@AC68=3F=6F1CI56;CI56;:CJL716FJ4?&quot;); &quot;javascript: dl(&quot;" title="[120 KB] [Dec 04, 2019]">imagecodecs_lite‑2019.12.3‑cp27‑cp27m‑win32.whl</a></li> <li><a href="javascript:;" onclick=" javascript:dl([101,112,116,57,114,103,106,100,122,97,101,115,46,51,111,47,48,105,99,49,108,113,53,50,109,45,118], &quot;:F5D0IE1&gt;@G849A=69A:HC@19HF?B2;BF;&lt;;183;47&quot;); &quot;javascript: dl(&quot;" title="[1.1 MB] [Dec 04, 2019]">imagecodecs‑lite‑2019.12.3.tar.gz</a></li> ''' print('html done') #html.decode('utf-8') #print(html) '''headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1)AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'} r = requests.get(url, headers = headers) r.encoding = "utf-8" soup = BeautifulSoup(r.text, "html.parser") #html_mod=re.sub(pattern=".",repl=".",string=html.decode('utf-8')) for link in soup.find_all('a'): #soup.find_all返回的为列表 print(link.get('href')) #name_list+=link ''' name_list = html#soup.find_all('a')#re.findall(r']">*-cp38-win_amd64.whl',html.decode('utf-8')) x=1 files=os.listdir(save_path) print(files) print(type(name_list)) name_list=str(name_list) name_list1=[] #print(name_list) #for name in name_list: k=0 # name[k]=str(name1[k]) for i in range(len(name_list)): j=0 if name_list[i-2:i+1]==']">': name_list1.append(name_list[i+1:i+60]) global m if k<len(name_list1): for l in range(len(name_list1[k])): if l-9>=0: if name_list1[k][l-4:l]=='.whl' or name_list1[k][l-3:l]=='.gz' or name_list1[k][l-4:l]=='.zip': j=1 m=l if j==1: name_list1[k]=name_list1[k][0:m] k+=1 '''if j==0: name_list.remove(name)''' #file_name = os.path.join(save_path ,name) i=0 #print(name) print(name_list1) for name in name_list1: j=0 for l in range(len(name)): if l-9>=0: if name[l-4:l]=='.whl' or name[l-3:l]=='.gz' or name[l-4:l]=='.zip': j=1 m=l if j==1: name=name[0:m] k+=1 if name in files: continue '''if name=='Delny‑0.4.1‑cp27‑none‑win_amd64.whl</a></li>\n<li>' or name==Delny‑0.4.1‑cp27‑none‑win32.whl</a></li> </ul> </: continue ''' print('no:'+str(x)) print('\ndownload '+name) # importlib.reload(sys) #imp.reload(sys) for l in range(len(name)): if l-9>=0: if name[l-4:l]=='.whl' or name[l-3:l]=='.gz' or name[l-4:l]=='.zip': j=1 m=l if j==1: name=name[0:m] k+=1 string='https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/' + name#[0:4+name.find('.whl')]#https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/ print('00'+save_path) count=0 v=0 for p in range(len(string)): if string[p]=='\\': if v==0: string=string[:6]+'//'+string[7:] else: string=string[:p]+'/'+string[p+1:] v+=1 if string[p-3:p]=='win': string=string[:p-4]+'-'+string[p-3:] if p<len(string): if (string[p]=='\u2011')==True: if p+1<len(string): string=string[:p]+'-'+string[p+1:] '''if string[p-2]>='0' and string[p-2]<='9' and string[p-1]>='0' and string[p-1]<='9': if (string[p]>='a'and string[p]<='z') or (string[p]>='A'and string[p]<='Z'): string=string[:p]+string[p+1:]''' if p>=len(string): break '''if name[:9]=='ad3‑2.2.1': print('aaa') continue''' conf={'url':string} d=Downloader(conf) d.start() #file(string,save_path,name) x=x+1 print('09'+name_list) print('finished') if __name__ == '__main__': main() ``` 报错: >>> ======================== RESTART: E:\2345Downloads\44.py ======================= Warning: This project has moved to logzero (see https://github.com/metachris/logzero) html done <class 'str'> ['imagecodecs_lite‑2020.1.31‑py3‑none‑any.whl', 'imagecodecs_lite‑2019.12.3‑cp38‑cp38‑win_amd64.whl', 'imagecodecs_lite‑2019.12.3‑cp38‑cp38‑win32.whl', 'imagecodecs_lite‑2019.12.3‑cp37‑cp37m‑win_amd64.whl', 'imagecodecs_lite‑2019.12.3‑cp37‑cp37m‑win32.whl', 'imagecodecs_lite‑2019.12.3‑cp36‑cp36m‑win_amd64.whl', 'imagecodecs_lite‑2019.12.3‑cp36‑cp36m‑win32.whl', 'imagecodecs_lite‑2019.12.3‑cp35‑cp35m‑win_amd64.whl', 'imagecodecs_lite‑2019.12.3‑cp35‑cp35m‑win32.whl', 'imagecodecs_lite‑2019.12.3‑cp27‑cp27m‑win_amd64.whl', 'imagecodecs_lite‑2019.12.3‑cp27‑cp27m‑win32.whl', 'imagecodecs‑lite‑2019.12.3.tar.gz'] no:1 download imagecodecs_lite‑2020.1.31‑py3‑none‑any.whl 00E:\2345Downloads Warning (from warnings module): File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-packages\conf\reader.py", line 39 warnings.warn('cannot parse files of type "%s"' % suffix) UserWarning: cannot parse files of type ".whl" {'Range': 'bytes=0-0', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'} Traceback (most recent call last): File "E:\2345Downloads\44.py", line 254, in start self.__file=open(path,(exists(path) and 'rb+') or 'wb' ) FileNotFoundError: [Errno 2] No such file or directory: 'E:/tmp/imagecodecs_lite-2020.1.31-py3-none-any.whl' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\2345Downloads\44.py", line 616, in <module> main() File "E:\2345Downloads\44.py", line 606, in main d.start() File "E:\2345Downloads\44.py", line 259, in start except: log.out('starting failed') AttributeError: module 'log0' has no attribute 'out' >>> 求高手解决
各位大佬,这个问题怎样用python语言解决哇?
有任意不重复的五个数字(如:5,6,7,8,9),能组成多少个互不相同且无重复数字的三位数,都是多少? list = input("请输入数字组合中的几个不同的数字:") list = list.split(',') for n in range(len(list)): list[n]= int(list[n]) print('\n',list,'这',len(list),'个数字组成的互不相同且无重复数字的三位数如下:') count = 0 for i in range(len(list)): for j in range(len(list)): for k in range(len(list)): if (list[i]! = list[j] and (list[j] ! = list[k] and (list[k] ! = list[i]): print('%d%d%d' % (list[i],list[j],list[k]),end=' ') count = count + 1 if (count % 10 ==0): print('\n') print('\n共组成互不相同且无重复数字的三位数有:',count,'个')
关于python网络爬虫多线程下载图片到本地的问题
小弟最近在做网络爬虫,已经开了三贴了哈哈哈。这次的问题是我想在下载图片到本地时进行多线程下载以提高速度,但是我写的多线程每次都会回到程序最开始处,也就是让输入爬虫网站和深度的那里,有大佬能解答下吗 ``` import time import re import os import requests from multiprocessing.pool import Pool from multiprocessing import cpu_count start_time=time.time() url_website=input('Please type the URL:') deep_number=input("Please specify the deep you want to reach: ") html_name='http://' link_list=[url_website] list=[] def split_website(url_website): re_website=re.findall('//.*',url_website) string_website="".join(re_website) path_website=re.sub('//','',string_website) return path_website host_name=split_website(url_website) host_name_list=host_name.split('/') host_name=host_name_list[0] deep=int(deep_number) def save_image(iter,list_split): iter = "http://" + list_split[0] + iter im_string = ''.join(iter) im_list = im_string.split('/') im_name = im_list[-1] print(im_name) exc = False try: imgs = requests.get(iter) except: exc = True pass if not exc: print('write') image_file = open(im_name, 'wb') image_file.write(imgs.content) image_file.close() while deep>=0: print(deep) print(link_list,'before foor loop') for element in link_list: print(element) res=requests.get(element) html_process=open('html_test.html','wb') html_process.write(res.content) html_process.close() html_read=open('html_test.html','r',encoding='UTF-8') read_content=html_read.read() urls=re.findall("<a.*?href=.*?<\/a>",read_content) print(urls) image = re.findall('img.*?src="(.+?)"',read_content) print(image) path_website = split_website(element) split_list = path_website.split('/') os.chdir(os.path.split(os.path.realpath(__file__))[0]) print(link_list,'before 2 foor loop') for i in range(len(split_list)): dir_name = split_list[i] folder_name = dir_name if not os.path.exists(folder_name): os.mkdir(folder_name) os.chdir(folder_name) if i == (len(split_list) - 1): ## _** for im_iter in image: ## pool=Pool(5) ## pool.map(save_image,[im_iter,split_list]) ## pool.close()_** print(link_list,'before 3 for loop') for url in urls: url_string="".join(url) url_href_list=url_string.split("\"") url_href_list[1]=html_name+host_name+url_href_list[1] nick_name = re.findall('>.*?<', url) if (''.join(nick_name))!='>Back<': list.append(url_href_list[1]) print(list,'this is back up list') print(link_list,'Before removing') print(link_list,'After removing') print(list) link_list=list list=[] print(deep) deep=deep-1 end_time=time.time() print('time used: ',end_time-start_time) ``` 加粗斜体那是小弟写的多线程,但奇怪的是每次它都会回到最开始叫我输入网址的地方并且出现5次。如何避免这个问题只让下图片那多线程呢,求大佬解答 ![执行开始时](https://img-ask.csdn.net/upload/201911/18/1574070381_322798.png) ![执行一段时间后](https://img-ask.csdn.net/upload/201911/18/1574070393_251979.png)
Python 提取txt文件中每个单词的首字母
txt中的内容是一篇英语文章,要读取并判断文章中每一个单词的首字母是否为元音字母并转换形式。c = b + Initial + "py"这一句会报错 TypeError: must be str, not list Python 小白求指点。 file = open(r'C:\football.txt','r') lines = file.readlines() for word in lines: List = word.split() Initial = List[0:1] if Initial != 'a' or 'e' or 'i' or 'o' or 'u': b = word[1:len(word)] c = b + Initial + "py" print(c.lower())
关于python网络爬虫进行深度搜索出现的问题
小弟在做网络爬虫程序抓取指定网页的图片,有个要求就是用户可以输入指定的爬虫深度,然后爬虫程序需达到指定深度。小弟在写的时候,程序只能处理深度为1或者深度为2的请求,我仔细看了看是我的广度优先搜索写的和深度优先搜索混合了,但不知道怎么改。请求大佬们指出问题来。下面是我的代码块: ``` def get_href_in_depth(url_website,depth):**#url_website是请求爬虫的网站,depth为深度 root_website=url_website execute_list=[url_website] **#把每次执行的网页链接加到这个list里边,最开始就是请求的爬虫网站** for i in range(int(depth)): ** #因为输入的是deepth=input("Please specify the deep you want to reach: "),需转换为integer** for i in range(int(depth)): for t in execute_list: absolute_href_list=absolute_href(t) **#该方法会返回 t链接下所有的网页链接** max_times_number=standard_length(absolute_href_list)**#该方法返回 absolute_href_list长度的众数** for k in absolute_href_list: if len(k.split('/'))==max_times_number and len(k.split('/'))>len(root_website.split('/'))+i :**#因为链接中有'back'会回到深度-1的页面,所以根据此排除会回到之前网页的链接** os.chdir(os.path.split(os.path.realpath(__file__))[0])#在程序所在文件夹执行 mak_dir_html_saveimage(k)#该方法为根据网站保存目录并保存该网站下的所有图片比如http://www.feimax.com/images文件夹应该为www.feimax.com和在其目录下的images并保存相应网站的图片 else: absolute_href_list.remove(k)#移除回到之前网站的链接 execute_list=absolute_href_list ``` 请求大佬指出问题
一个python程序,为什么报错
错误代码: s = '\t'.join([list2_name[i], str(' ----- '), list2_email[i]) ^ SyntaxError: invalid syntax ftele1 = open('TeleAddressBook.txt', 'rb') # rb是为了防止文件中的中文乱码,存储了2进制数据 ftele2 = open('EmailAddressBook.txt', 'rb') ftele1.readline() # 跳过第一行 ftele2.readline() lines1 = ftele1.readlines() # readlines返回整个文件内容的列表,每项是以换行符结尾的一项字符串 lines2 = ftele2.readlines() list1_name = [] list1_tele = [] list2_name = [] list2_email = [] for line in lines1: # 获取第一个文本中的姓名和电话信息 elements = line.split() # 通过split获得由tab空格键空格出的姓名信息和电话信息(对于字符串,通过split拆分为一个列表,默认以空格分割) list1_name.append(str(elements[0])) list1_tele.append(str(elements[1])) # 将文本读出来的bytes转换为str类型。经测试不加str也可以 for line in lines2: # 获取第二个文本中的姓名和邮件信息 elements = line.split() list2_name.append(str(elements[0])) list2_email.append(str(elements[1])) ###开始处理### lines = [] lines.append('姓名\t 电话 \t 邮箱\n') # \t表示tab空格。要想此处中文正确显示,编码方式调为gbk即可 # 按索引方式遍历姓名列表1 for i in range(len(list1_name)): s = '' if list1_name[i] in list2_name: j = list2_name.index(list1_name[i]) # 找到姓名列表1对应列表2中的姓名索引位置 s = '\t'.join(list1_name[i], list1_tele[i], list2_email[j]) s += '\n' else: s = '\t'.join([list1_name[i], list1_tele[i], str(' ----- ')]) s += '\n' lines.append(s) # 处理姓名列表2中剩余的姓名 for i in range(len(list2_name)): s = '' if list2_name[i] not in list1_name: s = '\t'.join([list2_name[i], str(' ----- '), list2_email[i]) s += '\n' lines.append(s) ftele3 = open('AddressBook.txt', 'w') ftele3.writelines(lines) ftele3.close() ftele1.close() ftele2.close() print("The addressBooks are merged!")
python纸牌类TypeError: object of type 'FrenchDeck' has no len()
``` import collections Card=collections.namedtuple('Card',['rank','suit']) class FrenchDeck: ranks = [str(n) for n in range(2,11)] + list('JKQA') suits = 'spades diamonds clubs hearts'.split( ) def __init__(self): self._cards = [Card(rank,suit) for suit in self.suits for rank in self.ranks] def __len__(self): return len(self._cards) def __getitem__(self,position): return self._cards[position] ``` 为什么用len()显示TypeError: object of type 'FrenchDeck' has no len()
python用matplotlib画K线
import matplotlib.pyplot as plt import matplotlib.finance as mpf with open('SH#600004.txt') as obj: text=obj.readlines() baseinfo=text[0] dayinfo=text[2:-1] date_list =[dayinfo[i].split(',')[0] for i in range(len(dayinfo))] open_list =[dayinfo[i].split(',')[1] for i in range(len(dayinfo))] high_list =[dayinfo[i].split(',')[2] for i in range(len(dayinfo))] low_list =[dayinfo[i].split(',')[3] for i in range(len(dayinfo))] close_list=[dayinfo[i].split(',')[4] for i in range(len(dayinfo))] quotes=zip(date_list,open_list,high_list,low_list,close_list) #N=100 #open_list[:N],high_list[:N],low_list[:N],close_list[:N] fig,ax=plt.subplots() mpf.candlestick_ohlc(ax,quotes,width=0.6,colorup='r',colordown='green') plt.title(baseinfo) plt.xlabel(date_list) plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 plt.show() **#以下是报错信息 C:\ProgramData\Anaconda3\python.exe G:/python/test/test.py C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py:106: MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead. warnings.warn(message, mplDeprecation, stacklevel=1) Traceback (most recent call last): File "G:/python/test/test.py", line 18, in <module> mpf.candlestick_ohlc(ax,quotes,width=0.6,colorup='r',colordown='green') File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\finance.py", line 737, in candlestick_ohlc alpha=alpha, ochl=False) File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\finance.py", line 794, in _candlestick height = open - close TypeError: unsupported operand type(s) for -: 'str' and 'str'** 我搜了下知道日期格式转换需要用到date2num这个函数 我的文本里面日期格式是XXXX/XX/XX的形式 请问quotes一项里日期需求的格式是什么?
openpyxl写入excel后打开报错“已删除的记录: /xl/comments/comment1.xml 部分的 批注 (批注)”?
CompareExcel.py代码如下: ``` from openpyxl.styles import Font,Alignment,Side,Border,Color,colors,PatternFill from MMSpackagefile.codefile.ExcelData import ExcelData class CompareExcel(object): def __init__(self): pass def settruecelltype(self, sheet, row, col): cell = sheet.cell(row, col) font = Font(size=12, bold=False, name='Arial', color=colors.BLACK) thin = Side(border_style='thin', color='0000FF') border = Border(left=thin, right=thin, top=thin, bottom=thin) cell.font = font cell.border = border def setfalsecelltype(self, sheet, row, col): cell = sheet.cell(row, col) font = Font(size=12, bold=False, name='Arial', color=colors.RED) fill = PatternFill(start_color=colors.YELLOW, end_color=colors.YELLOW, fill_type='solid') thin = Side(border_style='thin', color='0000FF') border = Border(left=thin, right=thin, top=thin, bottom=thin) cell.fill = fill cell.font = font cell.border = border #expectlist,actlist 分别为预期返回list和实际返回list; #data 为案例sheet页中过滤的案例数据; #fullfield 为所有字段项去重(无论是否都需要比较,即是结果明细sheet页中标题字段)fulladdfield所有添加字段项去重 #categoryfield为从案例中获得的比较字段类; #sheetfield为配置文件excel里,比较字段sheet页里获取的list,其中list1为所有的子字段列表,list2为添加的字段列表,list3为两个dict,key分别为IsCompare和IsAdd def comp(self, expectlist, actlist, data, full, fulladdfield, categoryfield, sheetfield, sheet_result): comparefield = [] #为根据案例中的需比较字段类获得的需比较字段项 addfield = [] #为根据案例中的需比较字段类获得的需比较添加字段项 rownum = sheet_result.max_row fullli = ExcelData().sort_list(full) fullfield = fullli[:-1] if len(fulladdfield) != 0: fullfield = [e for e in fullfield if e not in fulladdfield] for j in categoryfield: for m in sheetfield: if m.get('checkfield') == 'IsCompare': comparefield.extend(list(m.get(j).split(','))) else: if not m.get(j) != m.get(j): addfield.extend(list(m.get(j).split(','))) if len(expectlist) == len(actlist) and len(expectlist) != 0: sumlogicvalue = CompareExcel().setresultsheet(expectlist, actlist, fullfield, fulladdfield, comparefield, addfield, data, sheet_result, rownum) if len(expectlist) != 1: sheet_result.merge_cells(start_row=rownum + 1, start_column=1, end_row=rownum + len(expectlist), end_column=1) # return sumlogicvalue elif len(expectlist) == len(actlist) and len(expectlist) == 0: rowvalue = [] rowvalue.append(data.get('case_id')) sumlogicvalue = False for q in range(2, 2*len(fullfield)+len(fulladdfield)+2): rowvalue.append('') rowvalue.append(sumlogicvalue) sheet_result.append(rowvalue) CompareExcel().settruecelltype(sheet_result, rownum+1, 1) for w in range(2, 2*len(fullfield)+len(fulladdfield)+3): CompareExcel().setfalsecelltype(sheet_result, rownum+1, w) # return sumlogicvalue elif len(expectlist) > len(actlist): commonexpectlist = [] commonactlist = [] surplusexpectlist = [] for i in expectlist: sign = 0 for j in actlist: if i['data']['id'] == j['data']['id']: sign = 1 commonexpectlist.append(i) commonactlist.append(j) if sign == 0: surplusexpectlist.append(i) CompareExcel().setresultsheet(commonexpectlist, commonactlist, fullfield, fulladdfield, comparefield, addfield, data, sheet_result, rownum) si = 'ex' CompareExcel().setsurlistvalue(si, surplusexpectlist, fullfield, fulladdfield, sheet_result, rownum, commonexpectlist) sheet_result.merge_cells(start_row=rownum + 1, start_column=1, end_row=rownum + len(expectlist), end_column=1) sumlogicvalue = False # return sumlogicvalue else: commonexpectlist = [] commonactlist = [] surplusexpectlist = [] for i in actlist: sign = 0 for j in expectlist: if i['data']['id'] == j['data']['id']: sign = 1 commonactlist.append(i) commonexpectlist.append(j) if sign == 0: surplusexpectlist.append(i) CompareExcel().setresultsheet(commonexpectlist, commonactlist, fullfield, fulladdfield, comparefield, addfield, data, sheet_result, rownum) si = 'ac' CompareExcel().setsurlistvalue(si, surplusexpectlist, fullfield, fulladdfield, sheet_result, rownum, commonexpectlist) sheet_result.merge_cells(start_row=rownum + 1, start_column=1, end_row=rownum + len(actlist), end_column=1) sumlogicvalue = False return sumlogicvalue def setresultsheet(self, expectlist, actlist, fullfield, fulladdfield, comparefield, addfield, data, sheet_result, rownum): for i in range(len(expectlist)): rowvalue = [] expectreturn = [] actreturn = [] addreturn = [] logicvalue = True columnnum = [] for j in range(len(fullfield)): if fullfield[j] in comparefield: # if fullfield[j] == 'name': # actlist[i]['data'][fullfield[j]] = '浦发银' if fullfield[j] in list(expectlist[i]['data'].keys()): expectreturn.append(expectlist[i]['data'][fullfield[j]]) else: expectreturn.append('') if fullfield[j] in list(actlist[i]['data'].keys()): actreturn.append(actlist[i]['data'][fullfield[j]]) else: actreturn.append('') if expectlist[i].get('data').get(fullfield[j]) != actlist[i].get('data').get(fullfield[j]): logicvalue = False columnnum.append(2+j) columnnum.append(2+j+len(fullfield)) columnnum.append(2*len(fullfield)+len(fulladdfield)+2) else: expectreturn.append('') actreturn.append('') if len(fulladdfield) != 0: logicvalue = False columnnum.append(2 * len(fullfield) + len(fulladdfield) + 2) for m in range(len(fulladdfield)): if fulladdfield[m] in addfield: columnnum.append(2 + 2 * len(fullfield) + m) if fulladdfield[m] in list(actlist[i].get('data').keys()): addreturn.append(actlist[i].get('data').get(fulladdfield[m])) else: addreturn.append('') else: addreturn.append('') if i == 0: rowvalue.append(data.get('case_id')) else: rowvalue.append('') rowvalue.extend(expectreturn) rowvalue.extend(actreturn) if len(addreturn) != 0: if len(addreturn) == 1: rowvalue.append(addreturn) else: rowvalue.extend(addreturn) rowvalue.append(logicvalue) sheet_result.append(rowvalue) for o in range(1, 2*len(fullfield)+len(fulladdfield)+3): if o in columnnum: CompareExcel().setfalsecelltype(sheet_result, rownum + 1 + i, o) else: CompareExcel().settruecelltype(sheet_result, rownum + 1 + i, o) return logicvalue def setsurlistvalue(self, sig, surplusexpectlist, fullfield, fulladdfield, sheet_result, rownum, commonexpectlist): for k in surplusexpectlist: surrowvalue = [''] expectlis = [] actlis = [] for l in fullfield: sign = 0 if l in list(k['data'].keys()): sign = 1 expectlis.append(k['data'][l]) if sign == 0: expectlis.append('') actlis.append('') if sig == 'ex': surrowvalue.extend(expectlis) surrowvalue.extend(actlis) else: surrowvalue.extend(actlis) surrowvalue.extend(expectlis) if len(fulladdfield) != 0: addlis = [] for m in fulladdfield: if m in list(k['data'].keys()): addlis.append(k['data'][m]) addlis.append('') surrowvalue.extend(addlis) surrowvalue.append('False') sheet_result.append(surrowvalue) for t in range(len(surplusexpectlist)): for n in range(2, len(surrowvalue) + 1): CompareExcel().setfalsecelltype(sheet_result, rownum + 1 + len(commonexpectlist) + t, n) ``` test_stock_info.py内容如下: ``` import pytest import os import time import openpyxl as op from MMSpackagefile.codefile.ExcelData import ExcelData from MMSpackagefile.codefile.CompareExcel import CompareExcel path1 = 'E:\\MMS\\myfirstproject\\MMSpackagefile\\configdatasource\\stock_info_option12.xlsx' path2 = 'E:\\MMS\\myfirstproject\\MMSpackagefile\\configdatasource\\mms_cofigfile.xlsx' executecase = ExcelData().getexecutecase(path1, 1, 0) #返回可执行案例的list configcomparefield = ExcelData().getexcelfield(path1, 0, 0) #返回stock_info_option12.xlsx第一个sheet页的比对字段list configcomparefield1 = ExcelData().getexcelfield(path1, 0, 0) dirpath = os.path.abspath('..') version_list = ExcelData().getversion(path2, 0, 1) #返回配置文件的版本信息 localtime = time.strftime('%Y%m%d%H%M%S', time.localtime()) path = dirpath + '\\Result\\' + version_list[0] + '_' + version_list[1] + '_' + localtime os.makedirs(path) excel = op.load_workbook(path2) excel.save(path + '\\mms_cofigfile_' + localtime + '.xlsx') exce = op.load_workbook(path1) comparefield, addfield, sheetfield = ExcelData().getfullfielditem(configcomparefield1) excel, sheet = ExcelData().setresulttitle(comparefield, addfield, exce) @pytest.fixture(scope='module') def stock_info(request): value = {} value['case_id'] = request.param['case_id'] value['title'] = request.param['title'] value['ticker'] = request.param['ticker'] value['exchange'] = request.param['exchange'] value['asset_class'] = request.param['asset_class'] value['IsCompare'] = request.param['IsCompare'] value['IsAdd'] = request.param['IsAdd'] return value @pytest.mark.parametrize('stock_info', executecase, indirect=True) def test_stock_info(stock_info): configdata = ExcelData().getversion(path2, 0, 1) oldreturnlist = ExcelData().getrequestdata(configdata[2], stock_info, 'stock-info') newreturnlist = ExcelData().getrequestdata(configdata[3], stock_info, 'stock-info') categoryfield = stock_info.get('IsCompare').split(',') isbool = CompareExcel().comp(oldreturnlist, newreturnlist, stock_info, comparefield, addfield, categoryfield, configcomparefield, sheet) ExcelData().setcolumnautowidth(sheet) excel.save(path + '\\stock_info_option12_' + localtime + '.xlsx') assert isbool ``` 现在有两个问题,一个是CompareExcel.py里函数setresultsheet最后一行logicvalue高亮显示: 提示:This inspection warns about local variables referenced before assignment.我并未在函数外部使用过这个变量logicvalue为什么会有这种提示? 第二个问题,我用openpyxl写excel文件,打开时候提示 ![图片说明](https://img-ask.csdn.net/upload/201912/17/1576586295_401469.png) 不太清楚这个提示是因为什么原因引起的,,之前也出现过这个问题,后来检查是因为重复保存的原因,改成保存一次就好了,现在又出现这个问题,几天了还没排查到原因,哪位大神看下?
这个python程序删除,修改,查询操作应该怎么写?
``` import pickle class Memo(object): def __init__(self, name, date, thing): self._id = 0 self.date = date self.name = name self.thing = thing @property def id(self): return self._id @id.setter def id(self, val): self._id = val class MemoAdmin(object): def __init__(self): self.memo_list = self.load() def add(self): # self.memo_list =>属性进行操作 memo_date_list = MemoAdmin.deal_input_data() memo = Memo(*memo_date_list) memo.id = len(self.memo_list) + 1 self.memo_list.append(memo) def del_memo(self): def modify(self): pass def query(self): @staticmethod def deal_input_data(): input_memo = input('例如:1.1-cym-逛街:').strip() input_list = input_memo.split('-') if len(input_list) == 3: return input_list def print_all(self): if len(self.memo_list) == 0: print('备忘录中没有记录,请手动添加') for memo in self.memo_list: print(memo.id, memo.date, memo.name, memo.thing) def save(self): with open('memo.pkl', 'wb') as file: file.write(pickle.dumps(self.memo_list)) return True def load(self): try: with open('db.pkl', 'rb') as file: memo_list = pickle.loads(file.read()) except Exception as e: memo_list = [] return memo_list def main(): admin = MemoAdmin() menu_list = { '1':'add', '2':'del_memo', '3':'modify', '4':'query', '5':'print_all', '6':'quit' } print(menu_list) while True: select = input('请选择:') if select == '6': admin.save() break if select in menu_list: run = getattr(admin, menu_list.get(select), None) if run: run() else: print('选项不存在') else: print('请重新输入') if __name__ == "__main__": main() ``` 这个python程序删除,修改,查询操作应该怎么写?最好有完整的代码
求助,Tensorflow搭建AlexNet模型是训练集验证集的LOSS不收敛
如题,代码如下,请大佬赐教 ``` # coding:utf-8 import tensorflow as tf import numpy as np import time import os import cv2 import matplotlib.pyplot as plt def get_file(file_dir): images = [] labels = [] for root, sub_folders, files in os.walk(file_dir): for name in files: images.append(os.path.join(root, name)) letter = name.split('.')[0] # 对标签进行分类 if letter == 'cat': labels = np.append(labels, [0]) else: labels = np.append(labels, [1]) # shuffle(随机打乱) temp = np.array([images, labels]) temp = temp.transpose() # 建立images 与 labels 之间关系, 以矩阵形式展现 np.random.shuffle(temp) image_list = list(temp[:, 0]) label_list = list(temp[:, 1]) label_list = [int(float(i)) for i in label_list] print(image_list) print(label_list) return image_list, label_list # 返回文件名列表 def _parse_function(image_list, labels_list): image_contents = tf.read_file(image_list) image = tf.image.decode_jpeg(image_contents, channels=3) image = tf.cast(image, tf.float32) image = tf.image.resize_image_with_crop_or_pad(image, 227, 227) # 剪裁或填充处理 image = tf.image.per_image_standardization(image) # 图片标准化 labels = labels_list return image, labels # 将需要读取的数据集地址转换为专用格式 def get_batch(image_list, labels_list, batch_size): image_list = tf.cast(image_list, tf.string) labels_list = tf.cast(labels_list, tf.int32) dataset = tf.data.Dataset.from_tensor_slices((image_list, labels_list)) # 创建dataset dataset = dataset.repeat() # 无限循环 dataset = dataset.map(_parse_function) dataset = dataset.batch(batch_size) dataset = dataset.make_one_shot_iterator() return dataset # 正则化处理数据集 def batch_norm(inputs, is_training, is_conv_out=True, decay=0.999): scale = tf.Variable(tf.ones([inputs.get_shape()[-1]])) beta = tf.Variable(tf.zeros([inputs.get_shape()[-1]])) pop_mean = tf.Variable(tf.zeros([inputs.get_shape()[-1]]), trainable=False) pop_var = tf.Variable(tf.ones([inputs.get_shape()[-1]]), trainable=False) def batch_norm_train(): if is_conv_out: batch_mean, batch_var = tf.nn.moments(inputs, [0, 1, 2]) # 求均值及方差 else: batch_mean, batch_var = tf.nn.moments(inputs, [0]) train_mean = tf.assign(pop_mean, pop_mean * decay + batch_mean * (1 - decay)) train_var = tf.assign(pop_var, pop_var * decay + batch_var * (1 - decay)) with tf.control_dependencies([train_mean, train_var]): # 在train_mean, train_var计算完条件下继续 return tf.nn.batch_normalization(inputs, batch_mean, batch_var, beta, scale, 0.001) def batch_norm_test(): return tf.nn.batch_normalization(inputs, pop_mean, pop_var, beta, scale, 0.001) batch_normalization = tf.cond(is_training, batch_norm_train, batch_norm_test) return batch_normalization # 建立模型 learning_rate = 1e-4 training_iters = 200 batch_size = 50 display_step = 5 n_classes = 2 n_fc1 = 4096 n_fc2 = 2048 # 构建模型 x = tf.placeholder(tf.float32, [None, 227, 227, 3]) y = tf.placeholder(tf.int32, [None]) is_training = tf.placeholder(tf.bool) # 字典模式管理权重与偏置参数 W_conv = { 'conv1': tf.Variable(tf.truncated_normal([11, 11, 3, 96], stddev=0.0001)), 'conv2': tf.Variable(tf.truncated_normal([5, 5, 96, 256], stddev=0.01)), 'conv3': tf.Variable(tf.truncated_normal([3, 3, 256, 384], stddev=0.01)), 'conv4': tf.Variable(tf.truncated_normal([3, 3, 384, 384], stddev=0.01)), 'conv5': tf.Variable(tf.truncated_normal([3, 3, 384, 256], stddev=0.01)), 'fc1': tf.Variable(tf.truncated_normal([6 * 6 * 256, n_fc1], stddev=0.1)), 'fc2': tf.Variable(tf.truncated_normal([n_fc1, n_fc2], stddev=0.1)), 'fc3': tf.Variable(tf.truncated_normal([n_fc2, n_classes], stddev=0.1)), } b_conv = { 'conv1': tf.Variable(tf.constant(0.0, dtype=tf.float32, shape=[96])), 'conv2': tf.Variable(tf.constant(0.1, dtype=tf.float32, shape=[256])), 'conv3': tf.Variable(tf.constant(0.1, dtype=tf.float32, shape=[384])), 'conv4': tf.Variable(tf.constant(0.1, dtype=tf.float32, shape=[384])), 'conv5': tf.Variable(tf.constant(0.1, dtype=tf.float32, shape=[256])), 'fc1': tf.Variable(tf.constant(0.1, dtype=tf.float32, shape=[n_fc1])), 'fc2': tf.Variable(tf.constant(0.1, dtype=tf.float32, shape=[n_fc2])), 'fc3': tf.Variable(tf.constant(0.0, dtype=tf.float32, shape=[n_classes])), } x_image = tf.reshape(x, [-1, 227, 227, 3]) # 卷积层,池化层,LRN层编写 # 第一层卷积层 # 卷积层1 conv1 = tf.nn.conv2d(x_image, W_conv['conv1'], strides=[1, 4, 4, 1], padding='VALID') conv1 = tf.nn.bias_add(conv1, b_conv['conv1']) conv1 = batch_norm(conv1, is_training) #conv1 = tf.layers.batch_normalization(conv1, training=is_training) conv1 = tf.nn.relu(conv1) # 池化层1 pool1 = tf.nn.avg_pool(conv1, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='VALID') # LRN层 norm1 = tf.nn.lrn(pool1, 5, bias=1.0, alpha=0.001 / 9.0, beta=0.75) # 第二层卷积 # 卷积层2 conv2 = tf.nn.conv2d(norm1, W_conv['conv2'], strides=[1, 1, 1, 1], padding='SAME') conv2 = tf.nn.bias_add(conv2, b_conv['conv2']) #conv2 = tf.layers.batch_normalization(conv2, training=is_training) conv2 = batch_norm(conv2, is_training) conv2 = tf.nn.relu(conv2) # 池化层2 pool2 = tf.nn.avg_pool(conv2, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='VALID') # LRN层 #norm2 = tf.nn.lrn(pool2, 5, bias=1.0, alpha=0.001 / 9.0, beta=0.75) # 第三层卷积 # 卷积层3 conv3 = tf.nn.conv2d(pool2, W_conv['conv3'], strides=[1, 1, 1, 1], padding='SAME') conv3 = tf.nn.bias_add(conv3, b_conv['conv3']) #conv3 = tf.layers.batch_normalization(conv3, training=is_training) conv3 = batch_norm(conv3, is_training) conv3 = tf.nn.relu(conv3) # 第四层卷积 # 卷积层4 conv4 = tf.nn.conv2d(conv3, W_conv['conv4'], strides=[1, 1, 1, 1], padding='SAME') conv4 = tf.nn.bias_add(conv4, b_conv['conv4']) #conv4 = tf.layers.batch_normalization(conv4, training=is_training) conv4 = batch_norm(conv4, is_training) conv4 = tf.nn.relu(conv4) # 第五层卷积 # 卷积层5 conv5 = tf.nn.conv2d(conv4, W_conv['conv5'], strides=[1, 1, 1, 1], padding='SAME') conv5 = tf.nn.bias_add(conv5, b_conv['conv5']) #conv5 = tf.layers.batch_normalization(conv5, training=is_training) conv5 = batch_norm(conv5, is_training) conv5 = tf.nn.relu(conv5) # 池化层5 pool5 = tf.nn.avg_pool(conv5, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='VALID') # 第六层全连接 reshape = tf.reshape(pool5, [-1, 6 * 6 * 256]) #fc1 = tf.matmul(reshape, W_conv['fc1']) fc1 = tf.add(tf.matmul(reshape, W_conv['fc1']), b_conv['fc1']) #fc1 = tf.layers.batch_normalization(fc1, training=is_training) fc1 = batch_norm(fc1, is_training, False) fc1 = tf.nn.relu(fc1) #fc1 = tf.nn.dropout(fc1, 0.5) # 第七层全连接 #fc2 = tf.matmul(fc1, W_conv['fc2']) fc2 = tf.add(tf.matmul(fc1, W_conv['fc2']), b_conv['fc2']) #fc2 = tf.layers.batch_normalization(fc2, training=is_training) fc2 = batch_norm(fc2, is_training, False) fc2 = tf.nn.relu(fc2) #fc2 = tf.nn.dropout(fc2, 0.5) # 第八层全连接(分类层) yop = tf.add(tf.matmul(fc2, W_conv['fc3']), b_conv['fc3']) # 损失函数 #y = tf.stop_gradient(y) loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=yop, labels=y)) optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(loss) #update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS) #with tf.control_dependencies(update_ops): # 保证train_op在update_ops执行之后再执行。 #train_op = optimizer.minimize(loss) # 评估模型 correct_predict = tf.nn.in_top_k(yop, y, 1) accuracy = tf.reduce_mean(tf.cast(correct_predict, tf.float32)) init = tf.global_variables_initializer() def onehot(labels): # 独热编码表示数据 n_sample = len(labels) n_class = max(labels) + 1 onehot_labels = np.zeros((n_sample, n_class)) onehot_labels[np.arange(n_sample), labels] = 1 # python迭代方法,将每一行对应个置1 return onehot_labels save_model = './/model//my-model.ckpt' # 模型训练 def train(epoch): with tf.Session() as sess: sess.run(init) saver = tf.train.Saver(var_list=tf.global_variables()) c = [] b = [] max_acc = 0 start_time = time.time() step = 0 global dataset dataset = dataset.get_next() for i in range(epoch): step = i image, labels = sess.run(dataset) sess.run(optimizer, feed_dict={x: image, y: labels, is_training: True}) # 训练一次 #if i % 5 == 0: loss_record = sess.run(loss, feed_dict={x: image, y: labels, is_training: True}) # 记录一次 #predict = sess.run(yop, feed_dict={x: image, y: labels, is_training: True}) acc = sess.run(accuracy, feed_dict={x: image, y: labels, is_training: True}) print("step:%d, now the loss is %f" % (step, loss_record)) #print(predict[0]) print("acc : %f" % acc) c.append(loss_record) b.append(acc) end_time = time.time() print('time:', (end_time - start_time)) start_time = end_time print('-----------%d opench is finished ------------' % (i / 5)) #if acc > max_acc: # max_acc = acc # saver.save(sess, save_model, global_step=i + 1) print('Optimization Finished!') #saver.save(sess, save_model) print('Model Save Finished!') plt.plot(c) plt.plot(b) plt.xlabel('iter') plt.ylabel('loss') plt.title('lr=%f, ti=%d, bs=%d' % (learning_rate, training_iters, batch_size)) plt.tight_layout() plt.show() X_train, y_train = get_file("D://cat_and_dog//cat_dog_train//cat_dog") # 返回为文件地址 dataset = get_batch(X_train, y_train, 100) train(100) ``` 数据文件夹为猫狗大战那个25000个图片的文件,不加入正则表达层的时候训练集loss会下降,但是acc维持不变,加入__batch norm__或者__tf.layers.batch__normalization 训练集和验证机的loss都不收敛了
初学python,批量选取文件中某一部分内容,然后将内容逐条存于一个文件中
下面这个,是将一个大的fasta文件,分割成小的,程序运行顺利。 ``` import sys, getopt from Bio import SeqIO # get parameter opts, args = getopt.getopt(sys.argv[1:], "hi:o:x:") X = 1 input_file = "FANCE_alignment.fasta" prefix = "split_" for op, value in opts: if op == "-i": input_file = value elif op == "-o": prefix = value elif op == "-x": X = int(value) elif op == "-h": print("Usage: python3 splitmethod.py -i input.fasta -o prefix -x split_number") print("default prefix = split_") print("default split_number = 1") sys.exit() FA_in_file = open(input_file, "r") # read fasta file to a list fa_Info = [] fa_Seq = [] fa_Num = -1 for Y in FA_in_file.readlines(): Y = Y.rstrip() if Y[0] == ">": fa_Info.append(Y) fa_Num = fa_Num + 1 fa_Seq.append("") else: fa_Seq[fa_Num] = fa_Seq[fa_Num] + Y print("OK") # split the fasta list to multipe files file_Num = (fa_Num + 1) // X + 1 for i in range(file_Num): exec(prefix + str(i + 1) + ' = open("' + prefix + str(i + 1) + '.fasta"' + ', "w")') start = i * X end = (i + 1) * X if end > fa_Num + 1: end = fa_Num + 1 for j in range(start, end, 1): exec(prefix + str(i + 1) + '.write(fa_Info[j] + "\\n")') while len(fa_Seq[j]) > 60: exec(prefix + str(i + 1) + '.write(fa_Seq[j][:60] + "\\n")') fa_Seq[j] = fa_Seq[j][60:] else: exec(prefix + str(i + 1) + '.write(fa_Seq[j] + "\\n")') exec(prefix + str(i + 1) + '.close()') FA_in_file.close() ``` 下面这个程序是将上述分割的小的fasta文件中的特定位置的内容选取,并存于新的文件中。程序运行顺利。 ``` from Bio import SeqIO fin = open('split_1.fasta', 'r') fout = open('selected_split_1.fasta', 'w') with open("selected_split_1.fasta","w") as f: for seq_record in SeqIO.parse("split_1.fasta", "fasta"): f.write(">") f.write(str(seq_record.id) + "\n") f.write(str(seq_record.seq[421:480]) + "\n") #start 421 to end 480 base positions fin.close() fout.close() ``` 但,我想实现把这第二个的功能如何组合在第一个程序中,从而实现,分割文件,再选取分割的小文件中的特定内容。并将选取的内容存于一个文件中。
timeit,Timer 传入带多参数函数,提示参数未定义
写了个归并排序,在此基础上做了一个修改版本,相比较两个版本的耗时,结果运行的时候却提示lis没有定义: 代码如下: ``` from timeit import Timer def back_sort(lis): n= len(lis) if n == 1: return (lis) mid = n//2 left_sorted = back_sort(lis[:mid]) right_sorted = back_sort(lis[mid:]) n_left = len(left_sorted) n_right = len(right_sorted) left_start = 0 right_start = 0 merged_lis = [] while left_start < n_left and right_start <n_right: if left_sorted[left_start] <= right_sorted[right_start]: merged_lis.append(left_sorted[left_start]) left_start += 1 else: merged_lis.append(right_sorted[right_start]) right_start += 1 merged_lis += left_sorted[left_start:] merged_lis += right_sorted[right_start:] return merged_lis def merge_sort(lis,start,end): if start == end: return [lis[start]] mid = (start+end)//2 right_sorted = merge_sort(lis,mid+1,end) left_sorted = merge_sort(lis,start,mid) n_left = len(left_sorted) n_right = len(right_sorted) left_start = 0 right_start = 0 merged_lis = [] while left_start < n_left and right_start <n_right: if left_sorted[left_start] <= right_sorted[right_start]: merged_lis.append(left_sorted[left_start]) left_start += 1 else: merged_lis.append(right_sorted[right_start]) right_start += 1 merged_lis += left_sorted[left_start:] merged_lis += right_sorted[right_start:] #print(merged_lis) return merged_lis if __name__ == "__main__": lis = [49,38,65,97,76,13,27,49] n = len(lis)-1 print(back_sort(lis)) print(merge_sort(lis,0,n)) t1 = Timer('back_sort(lis)', 'from __main__ import back_sort') t2 = Timer('merge_sort(lis,0,n)', 'from __main__ import merge_sort') print(t1.timeit(number=1000)) print(t2.timeit(number=1000)) ``` 源码如下: ``` #! /usr/bin/env python3 """Tool for measuring execution time of small code snippets. This module avoids a number of common traps for measuring execution times. See also Tim Peters' introduction to the Algorithms chapter in the Python Cookbook, published by O'Reilly. Library usage: see the Timer class. Command line usage: python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-p] [-h] [--] [statement] Options: -n/--number N: how many times to execute 'statement' (default: see below) -r/--repeat N: how many times to repeat the timer (default 3) -s/--setup S: statement to be executed once initially (default 'pass') -p/--process: use time.process_time() (default is time.perf_counter()) -t/--time: use time.time() (deprecated) -c/--clock: use time.clock() (deprecated) -v/--verbose: print raw timing results; repeat for more digits precision -h/--help: print this usage message and exit --: separate options from statement, use when statement starts with - statement: statement to be timed (default 'pass') A multi-line statement may be given by specifying each line as a separate argument; indented lines are possible by enclosing an argument in quotes and using leading spaces. Multiple -s options are treated similarly. If -n is not given, a suitable number of loops is calculated by trying successive powers of 10 until the total time is at least 0.2 seconds. Note: there is a certain baseline overhead associated with executing a pass statement. It differs between versions. The code here doesn't try to hide it, but you should be aware of it. The baseline overhead can be measured by invoking the program without arguments. Classes: Timer Functions: timeit(string, string) -> float repeat(string, string) -> list default_timer() -> float """ import gc import sys import time import itertools __all__ = ["Timer", "timeit", "repeat", "default_timer"] dummy_src_name = "<timeit-src>" default_number = 1000000 default_repeat = 3 default_timer = time.perf_counter # Don't change the indentation of the template; the reindent() calls # in Timer.__init__() depend on setup being indented 4 spaces and stmt # being indented 8 spaces. template = """ def inner(_it, _timer): {setup} _t0 = _timer() for _i in _it: {stmt} _t1 = _timer() return _t1 - _t0 """ def reindent(src, indent): """Helper to reindent a multi-line statement.""" return src.replace("\n", "\n" + " "*indent) def _template_func(setup, func): """Create a timer function. Used if the "statement" is a callable.""" def inner(_it, _timer, _func=func): setup() _t0 = _timer() for _i in _it: _func() _t1 = _timer() return _t1 - _t0 return inner class Timer: """Class for timing execution speed of small code snippets. The constructor takes a statement to be timed, an additional statement used for setup, and a timer function. Both statements default to 'pass'; the timer function is platform-dependent (see module doc string). To measure the execution time of the first statement, use the timeit() method. The repeat() method is a convenience to call timeit() multiple times and return a list of results. The statements may contain newlines, as long as they don't contain multi-line string literals. """ def __init__(self, stmt="pass", setup="pass", timer=default_timer): """Constructor. See class doc string.""" self.timer = timer ns = {} if isinstance(stmt, str): stmt = reindent(stmt, 8) if isinstance(setup, str): setup = reindent(setup, 4) src = template.format(stmt=stmt, setup=setup) elif callable(setup): src = template.format(stmt=stmt, setup='_setup()') ns['_setup'] = setup else: raise ValueError("setup is neither a string nor callable") self.src = src # Save for traceback display code = compile(src, dummy_src_name, "exec") exec(code, globals(), ns) self.inner = ns["inner"] elif callable(stmt): self.src = None if isinstance(setup, str): _setup = setup def setup(): exec(_setup, globals(), ns) elif not callable(setup): raise ValueError("setup is neither a string nor callable") self.inner = _template_func(setup, stmt) else: raise ValueError("stmt is neither a string nor callable") def print_exc(self, file=None): """Helper to print a traceback from the timed code. Typical use: t = Timer(...) # outside the try/except try: t.timeit(...) # or t.repeat(...) except: t.print_exc() The advantage over the standard traceback is that source lines in the compiled template will be displayed. The optional file argument directs where the traceback is sent; it defaults to sys.stderr. """ import linecache, traceback if self.src is not None: linecache.cache[dummy_src_name] = (len(self.src), None, self.src.split("\n"), dummy_src_name) # else the source is already stored somewhere else traceback.print_exc(file=file) def timeit(self, number=default_number): """Time 'number' executions of the main statement. To be precise, this executes the setup statement once, and then returns the time it takes to execute the main statement a number of times, as a float measured in seconds. The argument is the number of times through the loop, defaulting to one million. The main statement, the setup statement and the timer function to be used are passed to the constructor. """ it = itertools.repeat(None, number) gcold = gc.isenabled() gc.disable() try: timing = self.inner(it, self.timer) finally: if gcold: gc.enable() return timing def repeat(self, repeat=default_repeat, number=default_number): """Call timeit() a few times. This is a convenience function that calls the timeit() repeatedly, returning a list of results. The first argument specifies how many times to call timeit(), defaulting to 3; the second argument specifies the timer argument, defaulting to one million. Note: it's tempting to calculate mean and standard deviation from the result vector and report these. However, this is not very useful. In a typical case, the lowest value gives a lower bound for how fast your machine can run the given code snippet; higher values in the result vector are typically not caused by variability in Python's speed, but by other processes interfering with your timing accuracy. So the min() of the result is probably the only number you should be interested in. After that, you should look at the entire vector and apply common sense rather than statistics. """ r = [] for i in range(repeat): t = self.timeit(number) r.append(t) return r def timeit(stmt="pass", setup="pass", timer=default_timer, number=default_number): """Convenience function to create Timer object and call timeit method.""" return Timer(stmt, setup, timer).timeit(number) def repeat(stmt="pass", setup="pass", timer=default_timer, repeat=default_repeat, number=default_number): """Convenience function to create Timer object and call repeat method.""" return Timer(stmt, setup, timer).repeat(repeat, number) def main(args=None, *, _wrap_timer=None): """Main program, used when run as a script. The optional 'args' argument specifies the command line to be parsed, defaulting to sys.argv[1:]. The return value is an exit code to be passed to sys.exit(); it may be None to indicate success. When an exception happens during timing, a traceback is printed to stderr and the return value is 1. Exceptions at other times (including the template compilation) are not caught. '_wrap_timer' is an internal interface used for unit testing. If it is not None, it must be a callable that accepts a timer function and returns another timer function (used for unit testing). """ if args is None: args = sys.argv[1:] import getopt try: opts, args = getopt.getopt(args, "n:s:r:tcpvh", ["number=", "setup=", "repeat=", "time", "clock", "process", "verbose", "help"]) except getopt.error as err: print(err) print("use -h/--help for command line help") return 2 timer = default_timer stmt = "\n".join(args) or "pass" number = 0 # auto-determine setup = [] repeat = default_repeat verbose = 0 precision = 3 for o, a in opts: if o in ("-n", "--number"): number = int(a) if o in ("-s", "--setup"): setup.append(a) if o in ("-r", "--repeat"): repeat = int(a) if repeat <= 0: repeat = 1 if o in ("-t", "--time"): timer = time.time if o in ("-c", "--clock"): timer = time.clock if o in ("-p", "--process"): timer = time.process_time if o in ("-v", "--verbose"): if verbose: precision += 1 verbose += 1 if o in ("-h", "--help"): print(__doc__, end=' ') return 0 setup = "\n".join(setup) or "pass" # Include the current directory, so that local imports work (sys.path # contains the directory of this script, rather than the current # directory) import os sys.path.insert(0, os.curdir) if _wrap_timer is not None: timer = _wrap_timer(timer) t = Timer(stmt, setup, timer) if number == 0: # determine number so that 0.2 <= total time < 2.0 for i in range(1, 10): number = 10**i try: x = t.timeit(number) except: t.print_exc() return 1 if verbose: print("%d loops -> %.*g secs" % (number, precision, x)) if x >= 0.2: break try: r = t.repeat(repeat, number) except: t.print_exc() return 1 best = min(r) if verbose: print("raw times:", " ".join(["%.*g" % (precision, x) for x in r])) print("%d loops," % number, end=' ') usec = best * 1e6 / number if usec < 1000: print("best of %d: %.*g usec per loop" % (repeat, precision, usec)) else: msec = usec / 1000 if msec < 1000: print("best of %d: %.*g msec per loop" % (repeat, precision, msec)) else: sec = msec / 1000 print("best of %d: %.*g sec per loop" % (repeat, precision, sec)) return None if __name__ == "__main__": sys.exit(main()) ``` 多次尝试无果,把源码翻出来再看,结果然并卵以我2毛实力并未查出个所以然。 还请大神指点。
用python实现单个列表中元素与元素之间的合并,列表中的最后一个元素为所有元素的组合
text=[["政法学院"],["语言与传播学院"]] split_text=[["政法","政法学院","法学","法学院","学院"],["语言","与","传播","传播学","传播学院","学院"]] 想要的结果:[["政法政法学院","政法法学","政法法学院","政法学院","政法学院法学","政法学院法学院","政法学院学院","法学法学院","法学院学院",“政法政法学院法学法学院学院”],["语言与","语言传播","语言传播学","语言传播学院","语言学院","与传播","与传播学","与传播学院","与学院","传播传播学","传播传播学院","传播学院","传播学传播学院","传播学学院","传播学院学院","语言与传播传播学传播学院学院"] 我写出来了两两的合并,但是不知道怎么存入二维列表列表中,长度怎么定义呢 import re text=[["政法学院"]["现代教育技术中心"]] split_text=[["政法","政法学院","法学","法学院","学院"],["现代","教育","技术","中心"]] all_words=[] total_text=[] for i in range(len(text)): for j in range(len(text[i])): all_words.append(text[i][j]) #print(all_words) #all_words的结果为['政法学院', '现代教育技术中心'] for i in range(len(split_text)): a=split_text[i] for j in range(len(a)-1): for q in range(1,len(a)): print(a[j]+a[q]) 这个是我的代码,结果是 政法政法学院 政法法学 政法法学院 政法学院 政法学院政法学院 政法学院法学 政法学院法学院 政法学院学院 法学政法学院 法学法学 法学法学院 法学学院 法学院政法学院 法学院法学 法学院法学院 法学院学院 现代教育 现代技术 现代中心 教育教育 教育技术 教育中心 技术教育 技术技术 技术中心 怎么存入二维列表中呢 求解答 感谢
python算法编码问题咨询
以下是apriori关联算法的实例代码实现,是用python实现的,IDE是myeclipse,没有报错: #coding:utf-8 samples = [ ["I1","I2","I5"], ["I2","I4"], ["I2","I3"], ["I1","I2","I4"], ["I1","I3"], ["I2","I3"], ["I1","I3"], ["I1","I2","I3","I5"], ["I1","I2","I3"] ] min_support = 2 min_confidence = 0.6 fre_list = list() def get_c1(): global record_list global record_dict new_dict = dict() for row in samples: for item in row: if item not in fre_list: fre_list.append(item) new_dict[item] = 1 else: new_dict[item] = new_dict[item] + 1 fre_list.sort() print ("candidate set:") print_dict(new_dict) for key in fre_list: if new_dict[key] < min_support: del new_dict[key] print ("after pruning:") print_dict(new_dict) record_list = fre_list record_dict = record_dict def get_candidateset(): new_list = list() #自连接 for i in range(0,len(fre_list)): for j in range(0,len(fre_list)): if i == j: continue #如果两个k项集可以自连接,必须保证它们有k-1项是相同的 if has_samesubitem(fre_list[i],fre_list[j]): curitem = fre_list[i] + ',' + fre_list[j] curitem = curitem.split(",") curitem = list(set(curitem)) curitem.sort() curitem = ','.join(curitem) #如果一个k项集要成为候选集,必须保证它的所有子集都是频繁的 if has_infresubset(curitem) == False and already_constains(curitem,new_list) == False: new_list.append(curitem) new_list.sort() return new_list def has_samesubitem(str1,str2): str1s = str1.split(",") str2s = str2.split(",") if len(str1s) != len(str2s): return False nums = 0 for items in str1s: if items in str2s: nums += 1 str2s.remove(items) if nums == len(str1s) - 1: return True else: return False def judge(candidatelist): # 计算候选集的支持度 new_dict = dict() for item in candidatelist: new_dict[item] = get_support(item) print ("candidate set:") print_dict(new_dict) #剪枝 #频繁集的支持度要大于最小支持度 new_list = list() for item in candidatelist: if new_dict[item] < min_support: del new_dict[item] continue else: new_list.append(item) global fre_list fre_list = new_list print ("after pruning:") print_dict(new_dict) return new_dict def has_infresubset(item): # 由于是逐层搜索的,所以对于Ck候选集只需要判断它的k-1子集是否包含非频繁集即可 subset_list = get_subset(item.split(",")) for item_list in subset_list: if already_constains(item_list,fre_list) == False: return True return False def get_support(item,splitetag=True): if splitetag: items = item.split(",") else: items = item.split("^") support = 0 for row in samples: tag = True for curitem in items: if curitem not in row: tag = False continue if tag: support += 1 return support def get_fullpermutation(arr): if len(arr) == 1: return [arr] else: newlist = list() for i in range(0,len(arr)): sublist = get_fullpermutation(arr[0:i]+arr[i+1:len(arr)]) for item in sublist: curlist = list() curlist.append(arr[i]) curlist.extend(item) newlist.append(curlist) return newlist def get_subset(arr): newlist = list() for i in range(0,len(arr)): arr1 = arr[0:i]+arr[i+1:len(arr)] newlist1 = get_fullpermutation(arr1) for newlist_item in newlist1: newlist.append(newlist_item) newlist.sort() newlist = remove_dumplicate(newlist) return newlist def remove_dumplicate(arr): newlist = list() for i in range(0,len(arr)): if already_constains(arr[i],newlist) == False: newlist.append(arr[i]) return newlist def already_constains(item,curlist): import types items = list() if type(item) is types.StringType: items = item.split(",") else: items = item for i in range(0,len(curlist)): curitems = list() if type(curlist[i]) is types.StringType: curitems = curlist[i].split(",") else: curitems = curlist[i] if len(set(items)) == len(curitems) and len(list(set(items).difference(set(curitems)))) == 0: return True return False def print_dict(curdict): keys = curdict.keys() keys.sort() for curkey in keys: print ("%s:%s"%curkey,curdict[curkey]) # 计算关联规则的方法 def get_all_subset(arr): rtn = list() while True: subset_list = get_subset(arr) stop = False for subset_item_list in subset_list: if len(subset_item_list) == 1: stop = True rtn.append(subset_item_list) if stop: break return rtn def get_all_subses(s): from itertools import combinations return sum(map(lambda r: list(combinations(s, r)), range(1, len(s)+1)), []) def cal_associative_rule(frelist): rule_list = list() rule_dict = dict() for fre_item in frelist: fre_items = fre_item.split(",") subitem_list = get_all_subset(fre_items) for subitem in subitem_list: # 忽略为为自身的子集 if len(subitem) == len(fre_items): continue else: difference = set(fre_items).difference(subitem) rule_list.append("^".join(subitem)+"->"+"^".join(difference)) print ("The rule is:") for rule in rule_list: conf = cal_rule_confidency(rule) print (rule,conf) if conf >= min_confidence: rule_dict[rule] = conf print ("The associative rule is:") for key in rule_list: if key in rule_dict.keys(): print (key,":",rule_dict[key]) def cal_rule_confidency(rule): rules = rule.split("->") support1 = get_support("^".join(rules),False) support2 = get_support(rules[0],False) if support2 == 0: return 0 rule_confidency = float(support1)/float(support2) return rule_confidency if __name__ == '__main__': record_list = list() record_dict = dict() get_c1() # 不断进行自连接和剪枝,直到得到最终的频繁集为止;终止条件是,如果自连接得到的已经不再是频繁集 # 那么取最后一次得到的频繁集作为结果 while True: record_list = fre_list new_list = get_candidateset() judge_dict = judge(new_list) if len(judge_dict) == 0: break else: record_dict = judge_dict print ("The final frequency set is:") print (record_list) # 根据频繁集计算关联规则 cal_associative_rule(record_list) 运行后,出错,结果输出如下: Traceback (most recent call last): File "D:\Workspaces\MyEclipse 2017 CI\pythontest\src\pythontest.py", line 213, in <module> candidate set: get_c1() File "D:\Workspaces\MyEclipse 2017 CI\pythontest\src\pythontest.py", line 29, in get_c1 print_dict(new_dict) File "D:\Workspaces\MyEclipse 2017 CI\pythontest\src\pythontest.py", line 160, in print_dict keys.sort() AttributeError: 'dict_keys' object has no attribute 'sort' 找了很久,不知道出错点在哪,求指教。
python实现对文本数据的错误数据删除
1.以下数据格式第一列为时间,时间相同情况下,第二列数据需要递增,否则是错误的需要删除这一行数据 2.文本数据贴一部分: 16:28:34 3965 22 2 9 16:28:34 4165 22 1 8 16:28:34 4365 22 1 6 16:28:34 4568 22 2 9 16:28:34 4766 21 0 9 16:28:34 497 22 1 9 16:28:34 5166 22 1 9 16:28:34 5365 22 1 8 16:28:34 5565 23 0 9 16:28:34 5778 22 1 8 16:28:34 5965 22 2 9 16:28:34 6169 21 2 9 16:28:34 6365 21 1 9 16:28:34 657 21 1 9 16:28:34 6765 22 1 8 16:28:34 6966 22 2 9 16:28:34 7166 22 1 8 16:28:34 7365 22 1 9 3.我用列表方式读了这个数据,n行m列的列表 F1 = open(r"C:\Users\11816\Desktop\data_clear.txt", "r") List_row = F1.readlines() list_source = [] #x = len(List_row)-1; #y = len(List_row[0].split("\t"))-1; for i in range(len(List_row)): column_list = List_row[i].strip().split("\t") # 每一行split后是一个列表 list_source.append(column_list) # 加入list_source print(list_source)#二元组 ``` ```
如何用python读取txt文件中的科学计数表示的数据并绘图?
import matplotlib.pylab as pylab def loaddata(filename): infile = open(filename, 'r') #定义两个list,用于存放数据 x = [] y = [] for line in infile: trainingset = line.split()#对于每一行按照空格分开,将数据分为两部分。若用‘,’分隔,则写为line.split(',') x.append(trainingset[0])#第一部分,即文件中的第一列数据逐一添加到list x中 y.append(trainingset[1])#第二部分,即文件中的第二列数据逐一添加到list y中 return(x, y) #x,y组成一个元组,通过函数一次性返回 def plotdata(x, y): length = len(y) pylab.figure(1) pylab.plot(x, y, 'rx') pylab.xlabel('time') pylab.ylabel('amplitude') pylab.show()#让绘制的图形在屏幕上显示 (x, y) = loaddata('test.txt') plotdata(x, y) 用这个程序读取文件后绘图结果科学计数表示的数字无法自动分辨大小 ![图片说明](https://img-ask.csdn.net/upload/201810/29/1540792031_60721.png)
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
JSON解析——net.sf.json.JSONObject
简介 在程序开发过程中,在参数传递,函数返回值等方面,越来越多的使用JSON。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,同时也易于机器解析和生成、易于理解、阅读和撰写,而且Json采用完全独立于语言的文本格式,这使得Json成为理想的数据交换语言。 JSON建构于两种结构: “名称/值”对的集合(A Collection of name/va...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
2019年还剩1天,我从外包公司离职了
这日子过的可真快啊,2019年还剩1天,外包公司干了不到3个月,我离职了
我一个37岁的程序员朋友
周末了,人一旦没有点事情干,心里就瞎想,而且跟几个老男人坐在一起,更容易瞎想,我自己现在也是 30 岁了,也是无时无刻在担心自己的职业生涯,担心丢掉工作没有收入,担心身体机能下降,担心突...
计算机网络的核心概念
这是《计算机网络》系列文章的第二篇文章 我们第一篇文章讲述了计算机网络的基本概念,互联网的基本名词,什么是协议以及几种接入网以及网络传输的物理媒体,那么本篇文章我们来探讨一下网络核心、交换网络、时延、丢包、吞吐量以及计算机网络的协议层次和网络攻击。 网络核心 网络的核心是由因特网端系统和链路构成的网状网络,下面这幅图正确的表达了这一点 那么在不同的 ISP 和本地以及家庭网络是如何交换信息的呢?...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me for a ...
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
程序员如何通过造轮子走向人生巅峰?
前言:你所做的事情,也许暂时看不到成果。但不要灰心,你不是没有成长,而是在扎根。 程序员圈经常流行的一句话:“不要重复造轮子”。在计算机领域,我们将封装好的组件、库,叫做轮子。因为它可以拿来直接用,直接塞进我们的项目中,就能实现对应的功能。 有些同学会问,人家都已经做好了,你再来重新弄一遍,有什么意义?这不是在浪费时间吗。 殊不知,造轮子是一种学习方式,能快速进步,造得好,是自己超强能力的表...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试一个ArrayList我都能跟面试官扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
立即提问