def dyS2L(): #用pandas包读取指定xlsx文档,转换为list数据格式 urlList = readFile().iloc[:, 0].tolist() #创建名为“geturl”的功能,输入参数为url def geturl(url): res = requests.head(url) #获取具体的长链接 url = res.headers.get('location') #返回变量 return url #创建名为list1的变量 list1 = [] #长度为urlList变量行数的循环 for i in urlList: a = geturl(i) #把返回得到的变量储存在变量名为list1的数组里 list1.append(a) print(a) time.sleep(2) #写出list1里的所有内容到"iris.csv"文档里,不带有列名 pd.DataFrame(list1).to_csv(BASE_DIR + "\抖音结果.csv", header=None, index=False)
def test_33(self): res = " class myClass_1; class myClass_2 how are you; class myClass_22 how ; class myClass_23 how; class myClass_3 ; class myClass_33 ; class myClass_4 ; class myClass_5;" line = readFile("TestFiles/TestClass.cpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) self.assertEqual(5, length)
def test_88(self): res = " " line = readFile("TestFiles/comments.hpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) self.assertEqual(0, length)
def test_44(self): res = " NGI_LOG_DEBUG(\"Original Flight period to get booking class filter for ASM TIM Wdc: \" << ioScheduleChange.getFlightPeriod()->shortDump()); NGI_LOG_DEBUG(\"Flight period to get booking class filter for ASM TIM Wdc: \" << theNewFlightPeriod.shortDump()); NGI_LOG_DEBUG(\"Selected booking class filters:\");" line = readFile("TestFiles/TestFallClass.cpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) self.assertEqual(1, length)
def test_55(self): res = " class TestTestCalss : public COM::Abstract { friend class CoverTestTestCalss; friend class CoverTestClass2 ; }; } " line = readFile("TestFiles/TestFriendClass.cpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) self.assertEqual(3, length)
def test_99(self): res = " #include \"iostream\" using namespace std; class myClass{ public: void setpVar(int pvar){pVar = pvar;} void setpfvar(int pfvar){this.pfvar = pfvar;} void setplvar(long plvar){ this.plvar = plvar; } private: int piVar; float pfvar; long plvar; std::string myString; }" line = readFile("TestFiles/class_method/Test.hpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) self.assertEqual(1, length)
def test_2(self): res = " #include <iostream> using namespace std; class Shape2 { public: void setWidth2(int w) { width2 = w; } void setHeight2(int h) { height2 = h; } protected: int width2; int height2; }; class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { height = h; } protected: int width; int height; }; class Rectangle: public Shape { public: int getArea() { return (width * height); } }; class Box : public Shape { public: int getArea() { return (width * height); } }; class SecondBox : public Shape { public: int getArea() { return (width * height); } }; class ThirdBox : public Shape { public: int getArea() { return (width * height); } }; class FourthBox : public Shape { public: int getArea() { return (width * height); } }; class FifthBox : public Shape { public: int getArea() { return (width * height); } }; class SixthBox : public Shape { public: int getArea() { return (width * height); } }; class SeventhBox : public Shape { public: int getArea() { return (width * height); } }; class EighthBox : public Shape ,Shape2 { public: int getArea() { return (width * height); } }; class NinethBox : public Shape ,Shape2 { public: int getArea() { return (width * height); } }; int main(void) { Rectangle Rect; Rect.setWidth(5); Rect.setHeight(7); cout << \"Total area: \" << Rect.getArea() << endl; return 0; }" line = readFile("TestFiles/Inheriteance.cpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) self.assertEqual(12, length)
def test_66(self): res = " DequeueAction Test_Calss::dequeueCallback(Message& msg) { try { std::string theMessageAsString; } NGI_SUPERCATCH_ACT_L(\"unexpected exception in first callback\", _aSC = NULL; return DequeueAction::MOVE_TO_EXCEPTION_QUEUE;); }" line = readFile("TestFiles/TestMultiline.cpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) print(class_name) self.assertEqual(0, length)
def test_77(self): res = " #include <iostream> #include <vector> using namespace std; int main() { vector<int> g1; for (int i = 1; i <= 5; i++) g1.push_back(i); cout << \"Output of begin and end: \"; for (auto i = g1.begin(); i != g1.end(); ++i) cout << *i <<; return 0; }" line = readFile("TestFiles/comments.cpp") self.assertEqual(res, line) class_name = classname() mainloop(line, class_name) length = len(class_name.listClasses) print(class_name) self.assertEqual(0, length)
def encode(filename): filepath = Path(filename) # checking to see if the file we have been given is valid if not filepath.is_file(): print("Error, cannot find file: " + filename) return # calling the parser to decode the file file_str, frequency = readFile(filename)
def main(): (char_to_int, int_to_char) = readFile() valid_set = loadFile(mode='valid') for i in range(50): sentence = predict(i, char_to_int, int_to_char, valid_set) for wd in sentence: print wd, print('\n') '''
def weChatBiz(): # 读取txt文档但不读取文档的抬头,把位置为在最左的字串更换为list数据格式 wechatlist = readFile()[0].tolist() chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--window-size=400,600') #创建两个新变量 name = [] biz = [] for i in wechatlist: browser = webdriver.Chrome(options=chrome_options, executable_path=".\chromedriver.exe") url = 'https://weixin.sogou.com/weixin?type=1&s_from=input&query='+ i +'&ie=utf8&_sug_=n&_sug_type_=' # 打开浏览器预设网址 browser.get(url) urls = browser.find_elements_by_xpath("//a") window_before = browser.window_handles[0] time.sleep(0.5) if (urls[17] is not None) and (urls[17].get_attribute("href") != "javascript:void(0);") : urls[17].click() window_after = browser.window_handles[1] browser.switch_to_window(window_after) time.sleep(0.5) res3 = requests.get(browser.current_url) a = re.findall('var biz = "(\w+==)',res3.text) b = re.findall('var title ="([a-zA-Z0-9_\u4e00-\u9fa5]+)', res3.text) biz.append(a) name.append(b) else: a = [] b = [] biz.append(a) name.append(b) browser.quit() print(a, b) final=pd.DataFrame((pd.Series([x[0] if len(x[:])!=0 else x[:] for x in name]),pd.Series([y[0] if len(y[:])!=0 else y[:] for y in biz]))).T final.to_excel(BASE_DIR + "\微信biz结果.xlsx", header=["name", "biz"], index=False)
def weiboM2W(): data = readFile() # 历遍每个网址 for i in range(data.shape[0]): # 以“://m.weibo”判断是否为手机端 if "://m.weibo" in data.iloc[i, 0]: # 将每个手机端网址的后16位取出来 mobile_url = data.iloc[i, 0][-16:] # 后七位进行转换 first = changeBase(int(mobile_url[-7:]), 62) # 后八 -- 十四位进行转换 second = changeBase(int(mobile_url[-14:-7]), 62) # 前两位进行转换 third = changeBase(int(mobile_url[:2]), 62) # 微博机制:如果7位十进制数字转换后不满4个占位符,则需要在前面加一个0 if len(second) != 4: second = "0" + second if len(first) != 4: first = "0" + first # 转换后的62进制,位数必定是9位 fix_url = third + second + first # 将原有的10进制数字替换成62进制 data.iloc[i, 0] = data.iloc[i, 0][:30] + fix_url # 规整格式 data.iloc[i, 0] = data.iloc[i, 0].replace("m.", "") data.iloc[i, 0] = data.iloc[i, 0].replace("cn", "com") else: pass # 更换表头名 data.columns = ['网页端url'] # 输出excel return data.to_excel(BASE_DIR + "\微博网页URL结果.xlsx", index=False)
def test_8(self): res = " " line = readFile("TestFiles/comments.hpp") self.assertEqual(res, line)
def test_7(self): res = " #include <iostream> #include <vector> using namespace std; int main() { vector<int> g1; for (int i = 1; i <= 5; i++) g1.push_back(i); cout << \"Output of begin and end: \"; for (auto i = g1.begin(); i != g1.end(); ++i) cout << *i <<; return 0; }" line = readFile("TestFiles/comments.cpp") self.assertEqual(res, line)
def test_6(self): res = " DequeueAction Test_Calss::dequeueCallback(Message& msg) { try { std::string theMessageAsString; } NGI_SUPERCATCH_ACT_L(\"unexpected exception in first callback\", _aSC = NULL; return DequeueAction::MOVE_TO_EXCEPTION_QUEUE;); }" line = readFile("TestFiles/TestMultiline.cpp") self.assertEqual(res, line)
def test_5(self): res = " class TestTestCalss : public COM::Abstract { friend class CoverTestTestCalss; friend class CoverTestClass2 ; }; } " line = readFile("TestFiles/TestFriendClass.cpp") self.assertEqual(res, line)
def check_for_duplicates(paths, hash=hashlib.sha1): hashes_by_size = {} hashes_on_1k = {} hashes_full = {} duplicates = [] for path in paths: for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: full_path = os.path.join(dirpath, filename) try: file_size = os.path.getsize(full_path) except (OSError, ): # not accessible (permissions, etc) - pass on pass duplicate = hashes_by_size.get(file_size) if duplicate: hashes_by_size[file_size].append(full_path) else: hashes_by_size[file_size] = [ ] # create the list for this file size hashes_by_size[file_size].append(full_path) # For all files with the same file size, get their hash on the 1st 1024 bytes for __, files in hashes_by_size.items(): if len(files) < 2: continue # this file size is unique, no need to spend cpy cycles on it for filename in files: small_hash = get_hash(filename, first_chunk_only=True) duplicate = hashes_on_1k.get(small_hash) if duplicate: hashes_on_1k[small_hash].append(filename) else: hashes_on_1k[small_hash] = [ ] # create the list for this 1k hash hashes_on_1k[small_hash].append(filename) # For all files with the hash on the 1st 1024 bytes, get their hash on the full file - collisions will be duplicates for __, files in hashes_on_1k.items(): if len(files) < 2: continue # this hash of fist 1k file bytes is unique, no need to spend cpy cycles on it for filename in files: full_hash = get_hash(filename, first_chunk_only=False) duplicate = hashes_full.get(full_hash) if duplicate: duplicates.append((filename, duplicate)) print("Duplicate found: %s and %s" % (filename, duplicate)) else: hashes_full[full_hash] = filename # Writing to the file. mfile = open('../Docs/duplicates.txt', mode='w') for row in duplicates: mfile.write("Duplicate found: %s and %s \n" % (row[0], row[1])) mfile.close() # Deleting duplicates. means = [] for i in range(1, 9): means.append(findMean(i)) genres = { "Metal": 1, "Rock": 2, "Jazz": 3, "Rap": 4, "Electronic": 5, "Pop": 6, "Soundtrack": 7, "Classical": 8 } for row in duplicates: dup1genre = row[0].split("/")[-3] dup2genre = row[1].split("/")[-3] song = readFile(row[0], 0) distance1 = distance.euclidean(song[1:], means[genres[dup1genre] - 1]) distance2 = distance.euclidean(song[1:], means[genres[dup2genre] - 1]) if distance1 > distance2: if os.path.isfile(row[0]): os.remove(row[0]) else: os.remove(row[1]) else: if os.path.isfile(row[1]): os.remove(row[1]) else: os.remove(row[0]) '''for row in duplicates:
from readFile import * lst = readFile('test.txt') print(lst) print('*' * 120) print('\n') for y in lst: for x in y: a = int(x) if (int(x) < 0) is True: print(x, end='\t\t') print('')
def test_4(self): res = " NGI_LOG_DEBUG(\"Original Flight period to get booking class filter for ASM TIM Wdc: \" << ioScheduleChange.getFlightPeriod()->shortDump()); NGI_LOG_DEBUG(\"Flight period to get booking class filter for ASM TIM Wdc: \" << theNewFlightPeriod.shortDump()); NGI_LOG_DEBUG(\"Selected booking class filters:\");" line = readFile("TestFiles/TestFallClass.cpp") self.assertEqual(res, line)
def test_9(self): res = " #include \"iostream\" using namespace std; class myClass{ public: void setpVar(int pvar){pVar = pvar;} void setpfvar(int pfvar){this.pfvar = pfvar;} void setplvar(long plvar){ this.plvar = plvar; } private: int piVar; float pfvar; long plvar; std::string myString; }" line = readFile("TestFiles/class_method/Test.hpp") self.assertEqual(res, line)
message = {} message['packettype'] = "change" message['sendingNode'] = "CostEditor" message['node'] = node message['cost'] = cost message['port'] = port message = json.dumps(message) sock.sendto(message.encode(), ('localhost', port)) #reads the original distances between the nodes #nodes: stores the read files data nodes = {} for x in range(1, len(sys.argv)): node = sys.argv[x][-5] nodes[node] = readFile(sys.argv[x]) #pointer: keep tracks of the arrow which points to the current highlighted option #userInput: stores input from the keyboard; 'n' means no input #nodestaken: used as a flag when nodes to be changed hace been selected pointer = 0 userInput = 'n' nodestaken = False while True: os.system("cls") print("\n\t COST EDITOR\n") print("\t Use Q and W for cursor\n\t Use double E to select\n\n") print("=" * 44) #done: stores the nodes that have been printed; #makes sure same distances are not repeated that
from scipy.io import loadmat from svmTrain import * import numpy as np from getVocabList import * # ==================== Part 1: Email Preprocessing ==================== # To use an SVM to classify emails into Spam v.s. Non-Spam, you first need # to convert each email into a vector of features. In this part, you will # implement the preprocessing steps for each email. You should # complete the code in processEmail.m to produce a word indices vector # for a given email. print('\nPreprocessing sample email (emailSample1.txt)\n') # Read file file_contents = readFile('emailSample1.txt') word_indices = processEmail(file_contents) # Print Stats print('==== Word Indices ==== \n') print(word_indices, '\n') input('Program paused. Press enter to continue.\n') # ==================== Part 2: Feature Extraction ==================== # Now, you will convert each email into a vector of features in R^n. print('\nExtracting features from sample email (emailSample1.txt)\n') # Extract Features
os.system("cls") print("=" * 56) print("\n I am Router " + self.name + '\n') for node in self.routingTable: if self.routingTable[node][ 'cost'] != math.inf and node != self.name: print( " Least cost path to router " + node + " : through " + self.routingTable[node]['through'] + " with cost " + str("{0:.1f}".format(self.routingTable[node]['cost']) + "\n")) print("=" * 56) def displayPacket(self, packet, sendingNode): print("\nProcessing packet from ", sendingNode) for x in packet: print(x + " through " + packet[x]['through'] + " cost ", packet[x]["cost"]) print() def change(self, message): self.neighbours[message['node']]['cost'] = float(message['cost']) self.routingTable[message['node']]['cost'] = float(message['cost']) print(message['node'] + " set to ", self.neighbours[message['node']]['cost']) if __name__ == '__main__': node = Node(sys.argv[1], sys.argv[2], readFile(sys.argv[3])) node.run() input()
def test_3(self): res = " class myClass_1; class myClass_2 how are you; class myClass_22 how ; class myClass_23 how; class myClass_3 ; class myClass_33 ; class myClass_4 ; class myClass_5;" line = readFile("TestFiles/TestClass.cpp") self.assertEqual(res, line)