本文整理汇总了Python中outputty.Table.to_text_file方法的典型用法代码示例。如果您正苦于以下问题:Python Table.to_text_file方法的具体用法?Python Table.to_text_file怎么用?Python Table.to_text_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类outputty.Table
的用法示例。
在下文中一共展示了Table.to_text_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_input_and_output_character_encoding_in_method_to_text_file
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import to_text_file [as 别名]
def test_input_and_output_character_encoding_in_method_to_text_file(self):
temp_fp = tempfile.NamedTemporaryFile(delete=False)
temp_fp.close()
my_table = Table(headers=['Álvaro'.decode('utf8').encode('utf16')],
input_encoding='utf16', output_encoding='iso-8859-1')
my_table.rows.append(['Píton'.decode('utf8').encode('utf16')])
my_table.to_text_file(temp_fp.name)
fp = open(temp_fp.name)
file_contents = fp.read()
fp.close()
os.remove(temp_fp.name)
output = dedent('''
+--------+
| Álvaro |
+--------+
| Píton |
+--------+
''').strip().decode('utf8').encode('iso-8859-1')
self.assertEqual(file_contents, output)
示例2: test_should_save_data_into_text_file
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import to_text_file [as 别名]
def test_should_save_data_into_text_file(self):
temp_fp = tempfile.NamedTemporaryFile(delete=False)
temp_fp.close()
my_table = Table(headers=['ham', 'spam', 'eggs'])
my_table.rows.append({'ham': '', 'spam': '', 'eggs': ''})
my_table.rows.append({'ham': 1, 'spam': 2, 'eggs': 3})
my_table.rows.append({'ham': 11, 'spam': 22, 'eggs': 33})
my_table.to_text_file(temp_fp.name)
fp = open(temp_fp.name, 'r')
contents = fp.read()
fp.close()
os.remove(temp_fp.name)
self.assertEqual(contents, dedent('''
+-----+------+------+
| ham | spam | eggs |
+-----+------+------+
| | | |
| 1 | 2 | 3 |
| 11 | 22 | 33 |
+-----+------+------+
''').strip())
示例3: Table
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import to_text_file [as 别名]
#!/usr/bin/env python
from outputty import Table
my_table = Table(from_csv='nice-software.csv')
my_table.to_text_file('nice-software.txt')