def shan_chu(): ''' 删除学生条目 ''' l = Rf.read_file() # print(l) sc = input('输入需要删除的学生的姓名:') for i in l: if i['姓名'] == sc: print('您要删除的是:', i['姓名'], '请确认(y/n)') qr = input() if qr == 'y': shan_chu = l.pop(l.index(i)) print('删除了:', shan_chu) # from imp import reload # reload(get_path) Wf.write_file(l, 'w') return else: print('已放弃操作') ts.tishi('即将返回目录', 4) return print('没有此人') ts.tishi('返回目录', 5)
def train(self, training_data_file): self.train_file_str = read_file(training_data_file) self.train_pfs = preprocess_line(self.train_file_str) self.train_counts = count_ngrams(3, self.train_pfs) self.train_discounts = gt_discount(self.train_counts) self.train_probs = estimate_probs(self.train_discounts) write_file(self.train_probs)
def save_data(self): content = self.text.get("1.0", tk.END) if not content.split(): return False #now = colored(full_date(), "cyan") #change color during seasons?? now = full_date() #think about: only time if multiple posts one day write_file(self.name, now, response=False) #consider "\n"+now write_file(self.name, content, response=False) self.text.delete("1.0", tk.END) #clear all data in text box return True
def train(self, training_data_file): self.train_file_str = read_file(training_data_file) self.train_pfs = preprocess_line(self.train_file_str) self.train_counts = count_trigrams(3, self.train_pfs) ans = raw_input("Smooth the counts? [y/n]") if ans.lower() == 'y': self.train_discounts = gt_discount(self.train_counts) self.train_probs = estimate_probs(self.train_discounts) else: self.train_probs = estimate_probs(self.train_counts) write_file(self.train_probs)
def main(): url = sys.argv[1] #first argument is going to be url ip = start_host(url) #uses start_host functioni wordlist = sys.argv[2] print('IP Address found:' + ip) path = os.getcwd() #defines path as current working directory project_dir = path + '/RobustRecon: ' + ip try: os.mkdir(project_dir) print('RobustRecon directory created.') except: print('RobustRecon directory already exists') print("[+] Starting Web Application Firewall using wafw00f...") waf_detect = start_wafw00f(ip) write_file(project_dir + '/waf_detect.txt', waf_detect) print('waf_detect.txt created') print("[+] Starting to get a Estimate on the CMS...") cms = (estimate_cms(ip)) write_file(project_dir + '/cms.txt', cms) print('cms.txt created') print("[+] Starting to bruteforce directory paths...") brute = (bruteforce(ip, wordlist)) write_file(project_dir + '/directorybruteforce.txt', brute) print('directorybruteforce.txt created') print("[+] Starting to run a nikto scan") nikto = start_nikto(url) write_file(project_dir + '/nikto.txt', nikto) print('nikto.txt created')
def ChiSquared_TypeandPepbondPoi(self, subspects, orginalpois, computeflag='length'): """ compute the chi-squared statistic for Type and Pepbond‘s poisition Args: -subspects: a set of subspectrum -orginalpois: a ndarray of subbins -computeflag: choose compute mode, include length and mass Return: -chiValues : a list of chisquared value """ choicepois = [1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,1,1] # by people need to change # choicepois = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] # by people orgpois = [choicepois[i] and orginalpois[i] for i in range(len(orginalpois))] orgpois = filter((lambda x: x>0), orgpois) ionpbptables = self.generateIonPepbondpoiTable(subspects,orgpois, computeflag) keyChiV = {} chiValues = [] chi = ChiSquared() for key in ionpbptables: # print key table = np.array(ionpbptables[key].T) chiValue = chi.OrgainChiSquard(table) chiValues.append(chiValue) keyChiV[key] = chiValue fw = write_file() filename = "SubSpectrumData/"+"pepbondpoi_Chivalue" fw.writeFile_cp(filename, keyChiV) return chiValues
def top_by_country(): #Create the directory to store the results if not path.exists(directory): makedirs(directory) #path of the output result file_path = directory + "/" + "country_top50_" + date + ".txt" #Sort the ISO code list of the countries to get a sorted result file #The list is sorted by ISO code and not by country current = (s for s in sorted(list(countries), key=lambda c: c.alpha_2)) result = [] #Browse the sorted list of ISO code to compute the result sorted by code for country in current: try: c = country.alpha_2 #First check if there are streams from the current country #countries_list[c] contains all the listening of c #Counter() will count all the repetition of each song id #write_file function will return a string which will be stored in result #result is the variable which will be written in the output file if (c in countries_list): result.append(write_file(Counter(countries_list[c]), c)) except: print("Error with", c.name) #We make only one write operation to reduce the execution time open(file_path, "w").write("\n".join(result)) print("Top 50 songs by country has been written for the", log_name, "file")
def ChiSquared_TypeandType(self, subspects, orginalpois): """ compute the chi-squared statistic for Type and Type Args: -subspects: a set of subspectrum -orginalpois: a ndarray of subbins Return: -chiValues : a list of chisquared value """ choicepois = [ 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 ] # by people # choicepois = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] # by people orgpois = [ choicepois[i] and orginalpois[i] for i in range(len(orginalpois)) ] orgpois = filter((lambda x: x > 0), orgpois) iontables = self.generateIonTable(subspects, orgpois) fw = write_file() filename = "SubSpectrumData/" + "typetype_iontable" fw.writeFile_cp(filename, iontables) chiValues = {} chi = ChiSquared() for key in iontables: table = np.array(iontables[key].T) chiValue = chi.OrgainChiSquard(table) chiValues[key] = chiValue return chiValues
def ChiSquared_TypeandType(self, subspects, orginalpois): """ compute the chi-squared statistic for Type and Type Args: -subspects: a set of subspectrum -orginalpois: a ndarray of subbins Return: -chiValues : a list of chisquared value """ choicepois = [1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,1,1] # by people # choicepois = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] # by people orgpois = [choicepois[i] and orginalpois[i] for i in range(len(orginalpois))] orgpois = filter((lambda x: x>0), orgpois) iontables = self.generateIonTable(subspects,orgpois) fw = write_file() filename = "SubSpectrumData/"+"typetype_iontable" fw.writeFile_cp(filename, iontables) chiValues = {} chi = ChiSquared() for key in iontables: table = np.array(iontables[key].T) chiValue = chi.OrgainChiSquard(table) chiValues[key] = chiValue return chiValues
def xiu_gai(): ''' 修改学生条目 ''' xg = input('输入需要修改的学生的姓名:') l = r_f.read_file() count = 0 for i in l: if i['姓名'] == xg: count += 1 print('您要修改的是:', '姓名:%s,年龄:%s,成绩:%s' % (i['姓名'], i['年龄'], i['成绩'])) print( '\n 要修改:\n 姓名 输入1 \n 年龄 输入2 \n 成绩 输入3 \n 可自由修改需要的信息,修改全部输入123') qr = input() if '1' in qr: Nname = input('输入新的名字:') i['姓名'] = Nname if '2' in qr: Nage = input('输入新的年龄:') i['年龄'] = Nage if '3' in qr: Nscore = input('输入新的成绩:') i['成绩'] = Nscore break if count == 0: print('没有这个人哦') print('重新输入吗?(y/n)') s0 = input(' ') if s0 == 'y': xiu_gai() return else: return else: # from imp import reload # reload(get_path) w_f.write_file(l, 'w') return
def top_by_user(): #Create the directory to store the results if not path.exists(directory): makedirs(directory) #If the file has alreadey been computed we remove it #We can't use the "w" in the write function because write information #in the loop and we have to use "a" file_path = directory + "/" + "user_top50_" + date + ".txt" if path.exists(file_path): remove(file_path) #range(30) is used to be sure to get all saved information by the log_reader script #this is because we do not know the exact number if we execute the two scripts in a row #to avoid useless round we make a breaking loop if the file number i does not exist for i in range(30): #Create the path of the file users_path = data_directory + "/usersStream_" + str( i) + "_" + date + ".npy" #Get the extracted data from the saved dictionary if path.exists(users_path): user_tmp = np.load(users_path, allow_pickle=True) #Transform the ridden data to dictionary users_list = user_tmp.item() else: break #Sort the id of the users to get a sorted result file current = (s for s in sorted(users_list)) #result where the content to write will be stored result = [] #For each user its result is precessed for user in current: try: #users_list[user] contains all the listening of user #Counter() will count all the repetition of each song id #write_file function will return a string which will be stored in result #result is the variable which will be written in the output file result.append(write_file(Counter(users_list[user]), user)) except: print("Error with user number", user) #We make only few writes operations to reduce the execution time open(file_path, "a").write("\n".join(result)) print("Top 50 songs by user has been written for the", log_name, "file")
def startprocessing(self, title, text): """Starts Processing the title and text to create tf-idf for the current document""" docid = self.count freq = processtext(docid, text) titlefreq = processtitle(docid, title) f = open('titles.txt', 'a+') if self.first == 1: f.write('\n') if self.first == 0: self.first = 1 tr = str(docid) + ' ' + title f.write(tr.encode('utf-8')) f.close() for word in titlefreq: if word in freq: freq[word]['t'] += titlefreq[word] else: freq[word] = dict(d=docid, t=titlefreq[word], b=0, i=0, c=0, l=0, r=0) for word in freq: if len(word) < 3 or word.startswith('0'): continue freq[word]['d'] = str(docid) if word not in self.invindex: self.invindex[word] = list() self.invindex[word].append(''.join(tag + str(freq[word][tag]) for tag in freq[word] if freq[word][tag] != 0)) if self.count % 1000 == 0: write_file(self.invindex, self.filecount, sys.argv[2]) self.invindex = dict() self.filecount += 1
def ChiSquared_TypeandPepbondPoi(self, subspects, orginalpois, computeflag='length'): """ compute the chi-squared statistic for Type and Pepbond‘s poisition Args: -subspects: a set of subspectrum -orginalpois: a ndarray of subbins -computeflag: choose compute mode, include length and mass Return: -chiValues : a list of chisquared value """ choicepois = [ 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 ] # by people need to change # choicepois = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] # by people orgpois = [ choicepois[i] and orginalpois[i] for i in range(len(orginalpois)) ] orgpois = filter((lambda x: x > 0), orgpois) ionpbptables = self.generateIonPepbondpoiTable(subspects, orgpois, computeflag) keyChiV = {} chiValues = [] chi = ChiSquared() for key in ionpbptables: # print key table = np.array(ionpbptables[key].T) chiValue = chi.OrgainChiSquard(table) chiValues.append(chiValue) keyChiV[key] = chiValue fw = write_file() filename = "SubSpectrumData/" + "pepbondpoi_Chivalue" fw.writeFile_cp(filename, keyChiV) return chiValues
print orginalpois # file_name = 'data/new_CHPP_LM3_RP3_2.mgf' # parser = SpectrumParser() # specs = list(parser.readSpectrum(file_name)) # orignal datas file # # spectMaxInt = iglearner.generateMaxIntentity(specs) file_name3 = "SubSpectrumData/"+"SpectMaxInt" spectMaxInt = iglearner.generateMaxIntentityFile(file_name3) ionLists = iglearner.generateIonGroup_Int(atypesubspects, orginalpois, spectMaxInt) file_name4 = "SubSpectrumData/"+"IonGroups_AtypeInt" wfile = write_file() # wfile.writeSpectMaxInt(spectMaxInt) # iglearner.paintMaxInt(spectMaxInt) # wfile.writeIonPoi(orginalpois) wfile.writeIonGroups(ionLists, file_name4) # ## ionLists = iglearner.generateIonGroup(subspects, orginalpois) # ################################ Test 5##################################### # names=['y10+ '] # for name in names: # filename1 = "SubSpectrumData/"+"new_CHPP_LM3_RP3_2_"+name+"_intensity_20160120" # subparser = SubSpectrumGenerator() # atypesubspects = list(subparser.generateSubSpecfile(filename1,'intensity')) #
if word not in self.invindex: self.invindex[word] = list() self.invindex[word].append(''.join(tag + str(freq[word][tag]) for tag in freq[word] if freq[word][tag] != 0)) if self.count % 1000 == 0: write_file(self.invindex, self.filecount, sys.argv[2]) self.invindex = dict() self.filecount += 1 if __name__ == "__main__": try: os.remove('titles.txt') except OSError as e: if e.errno != errno.ENOENT: raise if not os.path.exists('./tmp/'): try: os.makedirs('./tmp/') except OSError as exc: if exc.errno != errno.EEXIST: raise parser = xml.sax.make_parser() Handler = IndexGenerator() parser.setContentHandler(Handler) parser.parse(sys.argv[1]) if Handler.count % 1000 > 0: write_file(Handler.invindex, Handler.filecount, sys.argv[2]) Handler.filecount += 1 mergefiles(Handler.filecount, 'tmp')
print orginalpois # file_name = 'data/new_CHPP_LM3_RP3_2.mgf' # parser = SpectrumParser() # specs = list(parser.readSpectrum(file_name)) # orignal datas file # # spectMaxInt = iglearner.generateMaxIntentity(specs) file_name3 = "SubSpectrumData/" + "SpectMaxInt" spectMaxInt = iglearner.generateMaxIntentityFile(file_name3) ionLists = iglearner.generateIonGroup_Int(atypesubspects, orginalpois, spectMaxInt) file_name4 = "SubSpectrumData/" + "IonGroups_AtypeInt" wfile = write_file() # wfile.writeSpectMaxInt(spectMaxInt) # iglearner.paintMaxInt(spectMaxInt) # wfile.writeIonPoi(orginalpois) wfile.writeIonGroups(ionLists, file_name4) # ## ionLists = iglearner.generateIonGroup(subspects, orginalpois) # ################################ Test 5##################################### # names=['y10+ '] # for name in names: # filename1 = "SubSpectrumData/"+"new_CHPP_LM3_RP3_2_"+name+"_intensity_20160120" # subparser = SubSpectrumGenerator() # atypesubspects = list(subparser.generateSubSpecfile(filename1,'intensity')) #
def writetoFile(self, spects, filename): wf = write_file() wf.writeSampleFile(spects, filename)
import Tkinter as tk import tkFileDialog import matplotlib matplotlib.use('TkAgg') from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.figure import Figure from write_file import write_file from SubSpectrumProcessor import SubSpectrumProcessor from SubSpectrumGenerator import SubSpectrumGenerator from SpectrumParser import SpectrumParser from PeptideProcessor import PeptideProcessor from IonGroupLearner import IonGroupLearner from SpectrumProcessor import SpectrumProcessor import os fw = write_file() class showproject(object): def __init__(self): self.root = tk.Tk() self.root.title("Show Project") # self.root.geometry('470x320') # menu self.menu = tk.Menu(self.root) # menu initial self.menuTest() self.root.config(menu=self.menu) # drawpiture
def write(self, option, account): return write_file(option, account)
import read_file import scoring import write_file books = [] libraries = [] nbDays = read_file.reading_file("SubmitInput/b_read_on.txt", books, libraries) #print(books) #print(libraries) #librarie = libraries[:] libToScan = scoring.scoreAllLibs(libraries, nbDays) #print(libToScan) write_file.write_file(libToScan)
from write_file import write_file if __name__ == '__main__': write_file('file') print('***') write_file('file.txt') print('***') write_file('file', 'Hello there') print('***') write_file('new_file.txt', 'Hello there') print('***') # check with a non-empty file write_file('example.txt', 'A new message') print('***')
def choose_option(): myobj = dbclassPY.DB_communication() print("Hey Hoh, what do you want to do?:\n") if myobj.runningval == 1: print("db accessible") inputvar = "init" while inputvar != "exit": inputvar = input( "<make> entry, <read> db, <export> , <barplot> or <exit>\n") if inputvar == "make": title = input("Titel:\n") description = input("Description:\n") person = input("Person:\n") datestart = input("(optional)Start d m Y:\n") try: start = datetime.datetime.strptime(datestart, "%d %m %Y").date() except: start = datetime.date.today() print(start) myobj.insert_entry(title, person, description, start) elif inputvar == "read": entrylist = myobj.read_all() print(entrylist) elif inputvar == "export": data = myobj.file_export() try: write_file.write_file(data) rsubcall.rsub_call() except: print("fail... export") elif inputvar == "barplot": show_bar.show_barplot() #print(os.getcwd()) #myobj.export_csv() #expobj = class_exporter.Exporter() #expobj.export_query_txt(content) elif inputvar.startswith("read "): try: words = inputvar.split() if len(words) > 1: if words[1] == "opentasks": datalist = myobj.filter_open() elif words[1] == "all": datalist = myobj.read_all() else: datalist = myobj.filter_person(words[1]) if len(words) > 2: if words[2] == "txt": name = words[1] write_file.write_file(datalist, name) else: write_file.write_cmd(datalist) except: print("invalid input...\n") elif inputvar == "cls": cmd_commands.cls() else: print("local mode:") inputvar = "init" while inputvar != "exit": inputvar = input("<export>, <barplot> or <exit>\n") if inputvar == "export": try: rsubcall.rsub_call() except: print("writing failure\n") elif inputvar == "barplot": show_bar.show_barplot()
## main.py ## Gets words from corncob list and applies "proper" ending from read_words import read_words from find_by_endings import find_by_endings from make_correct_endings import make_correct_endings from show_off import show_off from write_file import write_file words = read_words("corncob_lowercase.txt") latin_us = find_by_endings(words, "us") latin_us_plurals = make_correct_endings(latin_us, "us", "i") show_off_with_latin_plurals = show_off(latin_us, latin_us_plurals, "plural") write_file("latin_plurals.txt", show_off_with_latin_plurals)
def writetoFile(self, spects, filename): wf = write_file() wf.writeSampleFile(spects,filename)
from parser import parse from write_file import write_file from bootstrap import createBootstrap # converts relative jump instructions to absolute jump instructions from relative_instruction import map_relative_instructions fileOrPath = sys.argv[1] # initialize string to have bootstrap code at beginning concatenatedFiles = createBootstrap() # if argument is a directory, convert all .vm files to .asm try: folderName = os.path.basename(os.path.normpath(fileOrPath)) # if listdir throws an exception, then the argument was a file not a directory fileList = os.listdir(fileOrPath) for fileName in fileList: if (fileName.endswith('.vm')): concatenatedFiles = concatenatedFiles + parse(open(fileOrPath + fileName, 'r').read(), fileName) # maps the relative instructions to absolute jump instruction lines in assembly concatenatedFiles = map_relative_instructions(concatenatedFiles) write_file(concatenatedFiles, fileOrPath + folderName + '.vm') # if argument is a single file, convert it to .as except: translatedCode = parse(open(fileOrPath, 'r').read(), os.path.basename(fileOrPath)) write_file(translatedCode, fileOrPath)
import Tkinter as tk import tkFileDialog import matplotlib matplotlib.use('TkAgg') from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.figure import Figure from write_file import write_file from SubSpectrumProcessor import SubSpectrumProcessor from SubSpectrumGenerator import SubSpectrumGenerator from SpectrumParser import SpectrumParser from PeptideProcessor import PeptideProcessor from IonGroupLearner import IonGroupLearner from SpectrumProcessor import SpectrumProcessor import os fw = write_file() class showproject(object): def __init__(self): self.root = tk.Tk() self.root.title("Show Project") # self.root.geometry('470x320') # menu self.menu = tk.Menu(self.root) # menu initial self.menuTest() self.root.config(menu=self.menu) # drawpiture
def edit_users(self, number, name, pin, type, cc, balance, file): write_file()