def saveInit(self): tmp = getfile(self.project,'__init__.py') tmp2 = 'from ' + self.file.replace(' ','_')[:-3] + ' import *' o = tmp.find(tmp2) if o == -1: tmp = tmp.replace('# to be imported','# to be imported\n' + tmp2) writefile(self.project,'__init__.py',tmp)
def clearInit(self): tmp = getfile(self.project, '__init__.py') o = tmp.find('# to be imported') p = tmp.find('# end of import') tmp = tmp[:o] + '# to be imported\n' + tmp[p:] writefile(self.project, '__init__.py', tmp)
def saveFile(self,script): try: o = self.existing.find('###begining of %s###\n' % self.table) p = self.existing.find('###end of %s###\n' % self.table) q = len('###end of %s###\n' % self.table) if o == -1: self.script = self.script + '\n\n' + script else: p1 = self.script[:o] p2 = self.script[p+q:] self.script = p1 + script + p2 writefile(self.project,self.file,self.script) except: return 'fail' else: return 'success'
def writecsv(filename: str, list_of_list: List[List[float]] or List[List[str]], directory: str or None = None, separator: str = ',', newline: bool = True): writecontent: str = "" for row in list_of_list: line: str = "" for value in row[:-1]: line += str(value) + separator line += str(row[-1]) + ("\n" if newline else "") writecontent += line if directory is not None or directory != '': if not u.is_valid_path(directory): os.mkdir(directory) complete_file_path = os.path.join(directory, filename) else: complete_file_path = filename file.writefile(complete_file_path, writecontent)
def saveFile(self): writefile(self.project, self.filename, self.script)
#!/usr/bin/env python # import file for file access import file while True: file.writefile(input("input question here:"), input("input answer here:")) if "n" == input("do you wish to continue?[Y/n]").strip(): break