def readInput(path): ''' Will fail on bad input, TypeError Trust the input to not contain floats ''' with cOpen(path, encoding='utf-8') as inFile: # of test cases inFile.readline() for line in inFile: yield int(line.strip())
def extract_from_file(self, tup): """ Trækker dokumentation ud af funktioner. :param tup: Tuple bestående af (sti, filnavn) :returns: Dictionary """ func_dict = defaultdict(lambda: list()) fh = cOpen(tup[0] + '/' + tup[1], 'rb', encoding = 'utf-8') split_lines = [line.split() for line in fh] # Get class name class_name = None if 'class' in split_lines: isClass = True class_name = split_lines[split_lines.index('class') + 1] # Reset file pointer to start of line fh.seek(0) new_func = True docstring = [] src = [] stored_func = '' for line in fh: func_name = self.get_function_name(line) if func_name: stored_func = func_name split = line.split() if split != []: if split[0] == '"""': if split[-1] == '"""' and len(split) > 1: docstring.append(line) print 'in if' else: # Advances filepointer to end of docstring docstr, fh_pos = self.get_doc_string(fh, line) # print docstr docstring.extend(docstr) new_func = '' while new_func != '': line = fh.readline() if line == '': break src.append(line) new_func = self.get_function_name(line) # func_dict contains pathname (for submodules) class name (if any, else None), docstring and source func_name = new_func func_dict[stored_func] = tup[0], class_name, docstring, src print func_dict fh.close() return func_dict
def main(path): results = [] with cOpen(path, encoding='utf-8-sig') as input: testCases = int(input.next().strip()) for i in range(1, testCases + 1): rowOne = takeFive(input) rowTwo = takeFive(input) result = deduceTrick(rowOne, rowTwo) results.append('Case #%s: %s' % (i, result)) return results
def parsePO(po): try: poFile = cOpen(po, "r", "utf8") print ">> parse ", po for line in poFile.readlines(): if line[:6] == "msgstr": line = line.strip() for s in line[8:-1]: s = str(ord(s)) if s not in stringList: stringList.append(s) poFile.close() except IOError, e: print "Unable to open the file:", po, e
def parsePO(po): try: poFile = cOpen(po, 'r', 'utf8') print '>> parse ', po for line in poFile.readlines(): if line[:6] == 'msgstr': line = line.strip() for s in line[8:-1]: s = str(ord(s)) if s not in stringList: stringList.append(s) poFile.close() except IOError, e: print "Unable to open the file:" , po, e