def __init__(self, type_path): #read ent config self.typePath = type_path self.typeClass = "" self.config = ConfigParser.ConfigParser() self.config.read(type_path) #ent_xml_data.typepath print "Parsed Config Type:", type_path try: self.meshFile = TextUtil.remove_quotes( self.config.get("graphics", "object")) except: self.meshFile = None try: self.speed = float(self.config.get("properties", "speed")) except: self.speed = None try: csv = TextUtil.remove_quotes( self.config.get("properties", "behaviors")) behaviors = csv.split() self.behaviors = [eval("Behaviors." + x) for x in behaviors] except ConfigParser.NoOptionError: self.behaviors = [] self.typeClass = TextUtil.remove_quotes( self.config.get("properties", "type")) fname = os.path.basename(type_path) name = os.path.splitext(fname)[0] self.typeName = name
def __init__(self, type_path): #read ent config self.typePath = type_path self.typeClass = "" self.config = ConfigParser.ConfigParser() self.config.read( type_path ) #ent_xml_data.typepath print "Parsed Config Type:", type_path try: self.meshFile = TextUtil.remove_quotes( self.config.get("graphics", "object" ) ) except: self.meshFile = None try: self.speed = float( self.config.get("properties", "speed" ) ) except: self.speed = None try: csv = TextUtil.remove_quotes( self.config.get( "properties", "behaviors") ) behaviors = csv.split() self.behaviors = [eval("Behaviors."+x) for x in behaviors] except ConfigParser.NoOptionError: self.behaviors = [] self.typeClass = TextUtil.remove_quotes( self.config.get("properties", "type" ) ) fname = os.path.basename( type_path ) name = os.path.splitext(fname)[0] self.typeName = name
def _parseLevel(self, element ): """A recursive function which essentially flattens an xml file and sets the values to attributes of this object. Or, by example, an xml file like: <Root> <Spacing>30</Spacing> <Sea> <SeaLevel>210</SeaLevel> <WaterTexture>..\base\art\land\water.bmp</WaterTexture> </Sea> </Root> Ends up being parsed like this: self.Spacing = 30 self.SeaLevel = 210 self.WaterTexture = '.........' Hackish huh? """ for el in element.getchildren( ): if len( el.getchildren() ): self._parseLevel( el ) elif len( el.attrib ): setattr( self, el.tag, el.attrib ) else: setattr( self, el.tag, TextUtil.encode_string_to_value( str(el.text) ) )
# -*- coding: utf-8 -*- #!usr/bin/env python3 # # File name : use_modules.py # Description : Demonstrate how to use and call the functions in the user-defined module. # Creator : Frederick Hsu # Creation date : Thu. 31 Oct. 2019 # Copyright(C) 2019 All rights reserved. # import TextUtil text = "a puzzling conundrum " print(TextUtil.simplify(text))
#!/usr/bin/env python3 import TextUtil text="a puzzling coundrum" text=TextUtil.simplify(text) print(text)
BeautifulSoupUtil.decomposeDivContinue(soup) BeautifulSoupUtil.decomposePCommentFooter(soup) remove_loadmore = soup.find("div", {'class': 'loadmore hidden'}) remove_loadmore.decompose() for objeto_vazio in soup.find_all(): if len(objeto_vazio.get_text(strip=True)) == 0: objeto_vazio.extract() # Pega todos os nomes dos alunos nomes = list() lista_conteudo = soup.find(class_='comments') items_lista_nome = lista_conteudo.find_all('cite') for nome in items_lista_nome: aluno = TextUtil.remove_html_tags(str(nome.contents)) aluno = aluno.replace('[', '').replace(']', '').replace('\'', '') nomes.append(aluno) comentarios = [] items_lista_comentarios = lista_conteudo.find_all('p') for comentario in items_lista_comentarios: comentarios.append(TextUtil.listToString(comentario.contents)) # Lista com os nomes sem repeticao unique_names = [] with open('../lista_alunos.csv', 'r') as lista_alunos: reader = csv.reader(lista_alunos) for linha in reader: if ''.join(linha).strip(): if linha[0] not in unique_names:
import TextUtil print(TextUtil.is_balanced("(Python (is (not (lisp))))")) print(TextUtil.shorten("The Crossing", 10)) print(TextUtil.simplify(" some text with spurious whitespace ")) print(TextUtil.is_included("test", "111111test11111")) print(TextUtil.is_balanced_2("(Python (is (not (lisp))))")) print(TextUtil.is_balanced_2("(Python )(is (not (lisp))))"))
import TextUtil text = " zahadny \t\n hlavolam " text = TextUtil.simplify(text) print(text)