本文整理汇总了Python中writer.Writer.write方法的典型用法代码示例。如果您正苦于以下问题:Python Writer.write方法的具体用法?Python Writer.write怎么用?Python Writer.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类writer.Writer
的用法示例。
在下文中一共展示了Writer.write方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write [as 别名]
def main():
print "Welcome to draugiem.lv message downloader "
sys.stdout.write("Email: ")
sys.stdout.flush()
email = raw_input()
password = getpass.getpass()
try:
downloader = MessageDownloader(email, password)
except DraugiemException:
print "invalid username/password"
sys.exit(1)
def progress_show(current, total):
sys.stdout.write("%3d of %d\r" % (current, total))
sys.stdout.flush()
print "[1/4] downloading inbox"
downloader.get_messages(type = 'in', progress_callback = progress_show)
print "[2/4] downloading outbox"
downloader.get_messages(type = 'out', progress_callback = progress_show)
print "[3/4] sorting messages"
msgs = downloader.get_all_messages()
sys.stdout.write("Enter path: ")
sys.stdout.flush()
path = raw_input()
if not os.path.exists(path):
os.mkdir(path)
print "[4/4] writing"
for user in msgs:
w = Writer(os.path.join(path, "%s.html" % (downloader.get_user_info(user).replace("/", ""))))
w.start(downloader.users[user])
for item in msgs[user]:
w.write(item)
w.end()
示例2: handle_standard_io
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write [as 别名]
def handle_standard_io(parser):
parser.read_file(sys.stdin)
#parser.print_file() # what is this for?
parser.build_structure() # build doc from actual file
writer = Writer()
writer.write(parser.node_file)
for line in writer.buffer:
print line.rstrip()
示例3: main
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write [as 别名]
def main(args):
stats = Stats()
transactions = TransactionsList(args.infile)
if args.algorithm == 'apriori':
algorithm = Apriori(transactions, args.minsup)
else:
algorithm = Dic(transactions, args.minsup, args.m)
large_sets, counter = algorithm.get_large_sets_and_counter()
stats.record_post_large_sets()
rules = RulesGenerator.generate_rules(large_sets, args.minconf, counter, transactions)
stats.record_post_rules()
writer = Writer(args.outfile)
writer.add_args(args)
writer.add_stats(stats)
writer.add_rules(rules)
writer.write()
示例4: handle_files
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write [as 别名]
def handle_files(parser, files, dir_source, dir_dest):
for filename in files:
print '--------', filename, '--------'
# TODO: handle exceptions on file
file = open(filename, 'r')
node_file = parser.read_file(file)
file.close()
#parser.print_file() # what is this for?
parser.build_structure(node_file) # build doc from actual file
writer = Writer()
writer.write(node_file)
filepath = fs.transform_filepath(filename, dir_source, dir_dest)
print 'path', filename, dir_source, dir_dest, filepath
# TODO: handle exceptions on file
file = open(filepath, 'w')
file.write(''.join(writer.buffer))
file.close()
示例5: handle_buffer
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write [as 别名]
def handle_buffer(buffer):
markup_input = markup.find_markup('rst', 'python')
markup_output = markup.find_markup('rst', 'python')
#print buffer
if not markup_output:
markup_output = markup_input
# TODO pass markup directly instead of assigning to Node
Node.writer = markup_output.writer
Node.reader = markup_input.reader
Node.lang = markup_input.lang
parser = markup_input.parser
node = parser.read_file(buffer)
#parser.print_file() # what is this for?
parser.build_structure(node) # build doc from actual file
writer = Writer()
writer.write(node)
return writer.buffer
示例6: Writer
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write [as 别名]
'''
w = Writer()
vb = Voicebox()
source_texts = os.listdir('texts')
add_another = ''
choices = []
while add_another != 'n':
for i in range(len(source_texts)):
print "%s %s" % (i + 1, source_texts[i])
choice = raw_input('Enter the number of the voice you want to load:\n')
source = source_texts[int(choice) - 1]
choices.append(source)
source_texts.remove(source)
print "added %s!" % source
add_another = raw_input('Load another voice? y/n\n')
for source_text in choices:
vb.addVoiceFromFile(source_text)
rand_word= raw_input('Use random words? y/n\n')
w.set_rand(rand_word)
w.write(vb)
示例7: Compiler
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write [as 别名]
class Compiler(Visitor):
"""
Die Hauptklasse zur Übersetzung.
"""
def __init__(self, module):
self.module = module
self.buf = Writer() # modul-ebene
self.function_buf = Writer() # funktionen kommen seperat
self.label_count = 0
self.jump_table = {} # offsets der funktionen
def _gen_label(self):
"""
Erstellt ein einzigartiges Lebel nach dem Muster "Lx", wobei "x"
eine beliebige Integerzahl ist.
"""
self.label_count += 1
return "".join(("L", str(self.label_count)))
def compile(self):
"""
Diese Funktion ist die einzige, die direkt von außerhalb aufgerufen wird.
Sie steuert den Prozess der Übersetzung.
"""
for node in self.module.ast:
node.resolve(self.module)
self.visit(node)
self.buf.append("EOF") # ende des globalen scopes
self.buf.append(self.function_buf) # func-decls kommen ans ende des moduls
self.buf.write(FILENAME) # Just for fun file writing
return str(self.buf)
def visit_FunctionDecl(self, node):
"""
Während der Übersetzung der Funktion wird ein temporäres Writer-Objekt
zum neuen Buffer, in den der Bytecode geschrieben wird. Dadurch
werden unnötige Sprünge vermieden.
"""
backup = self.buf
self.buf = self.function_buf
func_label = self._gen_label()
self.buf.append(Label(func_label))
self.jump_table[str(node.ident)] = func_label
for arg in node.args:
self.buf.append("STORE")
self.buf.append(str(arg))
for subnode in node.body:
self.visit(subnode)
self.buf = backup
def visit_FunctionCall(self, node):
"""
Übersetzt einen Funktionsaufruf.
"""
for arg in reversed(node.args):
self.visit(arg)
self.buf.append("PUSH_SCOPE") # Scope der Funktion
jump_back_label = self._gen_label()
self.buf.append("PUSH_ADDRESS") # Ruecksprung
self.buf.append(Marker(jump_back_label))
self.buf.append("JUMP") # Aufruf, func-offset
self.buf.append(Label(jump_back_label)) # ruecksprung-label
self.buf.append(Marker(self.jump_table[str(node.ident)]))
def visit_ReturnStatement(self, node):
"""
Übersetzt eine Return-Anweisung.
"""
self.visit(node.expr)
self.buf.append("POP_SCOPE")
self.buf.append("RET")
def visit_BinaryOp(self, node):
"""
Übersetzt einen binären Ausdruck, wie beispielsweise "2 + 2".
"""
self.visit(node.right)
self.visit(node.left)
if node.op in math_symbols:
operator = math_symbols[node.op]
elif node.op in comparison_symbols:
operator = comparison_symbols[node.op]
self.buf.append(operator)
def _load_const(self, node):
self.buf.append("LOAD_CONST")
self.buf.append(str(node.val))
def visit_Integer(self, node):
self._load_const(node)
#.........这里部分代码省略.........