def get_article_boilerplate(model: str, article: Article, descr: str) -> str: """ Genera contenuto boilerplate per un nuovo articolo Passare il contenuto di questa funzione a `create_new_article_file` :param model: il template di partenza :param article: :param descr: la descrizione del modulo :return: la stringa boilerplate """ tmpl = string.Template(model) name, purpose = article.title.split('-') values = { 'categoria': article.artcat.descr, 'modulo': name.strip().title(), 'scopo': purpose, 'descrizione': descr, 'indicizza': 'sì' if article.indexed else 'no' } return tmpl.safe_substitute(values)
def insert_into_row(self, row: dict) -> Contact: ''' Returns Contact object. ''' name = row.get('name', None) or '' email = row.get('email', None) or '' phone_number = row.get('phone number', None) or '' # Check if fields aren't empty. if phone_number.strip() != '' and email.strip() != '' and name.strip() != '': contact, created = Contact.objects.get_or_create( phone=phone_number ) if created: contact.name = name contact.phone = phone_number contact.email = email contact.save() return contact return None
else: # as expected by Eclipse, paths on Windows will be converted from # '/c/dir1/dir2\dir3\...' format to 'c:/dir1/dir2/dir3/...' return re.sub( r'^/(\w)/', r'\1:/', path.replace( '\\', '/' ) ) # the script is expected to be in scripts folder in the source root srcRoot = convertToPosixPath( dirname( dirname( abspath( argv[ 0 ] ) ) ) ) with open(join(srcRoot, 'projects/make/ci-init-env.mk')) as file: properties = {} for line in file: line = line.strip() if line.startswith( "#" ) or "=" not in line: continue name, value = line.split('=') properties[name.strip()] = value.strip() distRootDeps1 = convertToPosixPath( properties['DIST_ROOT_DEPS1'] ) distRootDeps2 = convertToPosixPath( properties['DIST_ROOT_DEPS2'] ) distRootDeps3 = convertToPosixPath( properties['DIST_ROOT_DEPS3'] ) projectRootDir = "baselib" #### configurations linuxBuildConfigurations = { 'gcc492' : 'TOOLCHAIN=gcc492', 'clang35' : 'TOOLCHAIN=clang35', 'gcc630' : 'TOOLCHAIN=gcc630', 'clang391' : 'TOOLCHAIN=clang391', 'clang730' : 'TOOLCHAIN=clang730',
for dirpath, dirnames, filenames in walk(input_directory): #three separate temporary variables are created: directory pathway(s), directory name(s), file name(s) filenames_list.extend(filenames) #add names of file(s) to empty list declared above this loop break #don't need to search subdirectories gnomad_dp10_set = set() #Like dictionaries, a set() utilizes a hash table. This making it very efficient to search the set (it is O(n), i.e. constant regardless of set size). case_dp10_set = set() inputVCF_str, gnomad_path, case_path = '', '', '' #Read in files for name in filenames_list: #loop through list that contains strings of all files within input directory if '_FINAL' in name: #true if tagged as an input .vcf file if 'gnomad' in name: gnomad_path = input_directory + slash + name print 'Input control VCF: %s' % (name) else: case_path = input_directory + slash + name inputVCF_str = name.strip('.vcf') print 'Input case VCF: %s' % (name) elif 'coverage' in name: if 'gnomad' in name: print 'Gnomad coverage site reference: %s' % (name) with open(input_directory + slash + name, 'r') as input: print 'Reading in coverage site file...' for line in input: if line[0] != '#': line_list = line.strip('\n').split('\t') gnomad_dp10_set.add(':'.join([line_list[0].strip('chr'), line_list[1]])) if 'case' in name: print 'Case coverage site reference: %s' % (name) with open(input_directory + slash + name, 'r') as input: print 'Reading in coverage site file...' for line in input:
def __init__(self,names): """ Create names filler :names Preprocessed array of names, first for is name following ones are surname. Empty records and ones starting with name shortcut are valid and ignored """ self.extenders={} valid_regex=re.compile(r"^\w\w+ \w+") #Get possible extenders extenders={} for name in names: name=name.strip() name=NameExtender.__white_regex.sub(' ',name) if name=='': continue if not valid_regex.match(name): continue name_letter=name[0] if str.isdigit(name_letter): continue white_index=name.find(' ') end_index=name.find(' ',white_index+1) if end_index==-1: end_index=len(name) surname=name[white_index+1:end_index] if len(surname)<3 or str.isnumeric(surname): continue key=(name_letter,surname) if key in extenders: if not name in extenders[key]: extenders[key].append(name) else: extenders[key]=[name] #Filter extenders for key,value in extenders.items(): num=len(value) if num==1: #Sure extender extenders[key]=value[0] continue if num==2: #Valid only if similarity >.85 if SequenceMatcher(a=value[0],b=value[1]).ratio()>.85: extenders[key]=value[0] else: extenders[key]=None continue #Get average distance to each entry accuracy=[] for entry in value: partial=0 for entry2 in value: if not entry is entry2: partial+=SequenceMatcher(a=entry,b=entry2).ratio() accuracy.append(partial/(len(value)-1)) mx=max(accuracy) if mx<.9 or min(accuracy)<.77: #filter out sets with big distance extenders[key]=None continue extenders[key]=value[accuracy.index(mx)] #Push all extenders into main extenders dict for key,value in extenders.items(): if not value is None: value=(value.count(' ')+1,value) if key[0] in self.extenders: self.extenders[key[0]][key[1]]=value else: self.extenders[key[0]]={key[1]:value}
from os import name with open('C:\\Users\\Pratima Hake\\Desktop\\name.txt', 'r') as name_file: with open('C:\\Users\\Pratima Hake\\Desktop\\body.txt', 'r') as body_file: body = body_file.read() for line in name_file: mail = "Hello" + name + body with open(name.strip() + ' .txt', 'w') as mail_file: mail_file.write(mail)