本文整理汇总了Python中outputty.Table.write方法的典型用法代码示例。如果您正苦于以下问题:Python Table.write方法的具体用法?Python Table.write怎么用?Python Table.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类outputty.Table
的用法示例。
在下文中一共展示了Table.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_html_with_a_parameter_should_save_a_file
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_to_html_with_a_parameter_should_save_a_file(self):
temp_fp = tempfile.NamedTemporaryFile(delete=False)
temp_fp.close()
my_table = Table(headers=['ham', 'spam', 'eggs'])
my_table.append(['python', 'rules', '!'])
my_table.append({'ham': 'spam', 'spam': 'eggs', 'eggs': 'ham'})
my_table.write('html', temp_fp.name, css_classes=False)
temp_fp = open(temp_fp.name)
output = temp_fp.read()
temp_fp.close()
os.remove(temp_fp.name)
expected = dedent('''
<table>
<thead>
<tr>
<th>ham</th>
<th>spam</th>
<th>eggs</th>
</tr>
</thead>
<tbody>
<tr>
<td>python</td>
<td>rules</td>
<td>!</td>
</tr>
<tr>
<td>spam</td>
<td>eggs</td>
<td>ham</td>
</tr>
</tbody>
</table>
''').strip()
self.assertEquals(output, expected)
示例2: test_should_save_data_into_text_file
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [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.append({'ham': '', 'spam': '', 'eggs': ''})
my_table.append({'ham': 1, 'spam': 2, 'eggs': 3})
my_table.append({'ham': 11, 'spam': 22, 'eggs': 33})
my_table.write('text', temp_fp.name)
output = my_table.write('text')
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())
self.assertEquals(contents, output)
示例3: test_write_csv_should_accept_filepointer
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_write_csv_should_accept_filepointer(self):
temp_fp = tempfile.NamedTemporaryFile()
my_table = Table(headers=['Álvaro'])
my_table.append(['Píton'])
my_table.write('csv', temp_fp)
expected = '"Álvaro"\n"Píton"\n'
temp_fp.seek(0)
output = temp_fp.read()
temp_fp.close()
self.assertEqual(output, expected)
示例4: test_input_and_output_encoding_should_affect_method_write_csv
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_input_and_output_encoding_should_affect_method_write_csv(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.append(['Píton'.decode('utf8').encode('utf16')])
my_table.write('csv', temp_fp.name)
fp = open(temp_fp.name)
file_contents = fp.read()
fp.close()
os.remove(temp_fp.name)
output = '"Álvaro"\n"Píton"\n'.decode('utf8').encode('iso-8859-1')
self.assertEqual(file_contents, output)
示例5: test_to_html_with_headers_and_rows_with_some_columns_empty
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_to_html_with_headers_and_rows_with_some_columns_empty(self):
my_table = Table(headers=['ham', 'spam', 'eggs'])
my_table.append({'ham': 'spam'})
my_table.append({'spam': 'eggs'})
my_table.append({'eggs': 'ham'})
output = my_table.write('html', css_classes=False)
expected = dedent('''
<table>
<thead>
<tr>
<th>ham</th>
<th>spam</th>
<th>eggs</th>
</tr>
</thead>
<tbody>
<tr>
<td>spam</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>eggs</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td>ham</td>
</tr>
</tbody>
</table>
''').strip()
self.assertEquals(output, expected)
示例6: test_should_be_able_to_change_delimiters_on_write
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_should_be_able_to_change_delimiters_on_write(self):
temp_fp = tempfile.NamedTemporaryFile()
temp_fp.close()
my_table = Table(headers=['ham', 'spam', 'eggs'])
my_table.append({'ham': 'ham spam ham', 'spam': 'spam eggs spam',
'eggs': 'eggs ham eggs'})
my_table.write('csv', temp_fp.name, delimiter=';', quote_char="'",
line_terminator='\r\n')
fp = open(temp_fp.name)
contents = fp.read()
fp.close()
os.remove(temp_fp.name)
self.assertEquals(contents, dedent('''\
'ham';'spam';'eggs'\r
'ham spam ham';'spam eggs spam';'eggs ham eggs'\r
'''))
示例7: test_write_csv_should_create_the_file_correctly_with_headers
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_write_csv_should_create_the_file_correctly_with_headers(self):
temp_fp = tempfile.NamedTemporaryFile()
temp_fp.close()
my_table = Table(headers=['ham', 'spam', 'eggs'])
my_table.append({'ham': 'ham spam ham', 'spam': 'spam eggs spam',
'eggs': 'eggs ham eggs'})
my_table.write('csv', temp_fp.name)
fp = open(temp_fp.name)
contents = fp.read()
fp.close()
os.remove(temp_fp.name)
self.assertEquals(contents, dedent('''\
"ham","spam","eggs"
"ham spam ham","spam eggs spam","eggs ham eggs"
'''))
示例8: test_input_and_output_character_encoding_in_method_to_text_file
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [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.append(['Píton'.decode('utf8').encode('utf16')])
my_table.write('text', 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)
示例9: test_read_csv_and_write_csv
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_read_csv_and_write_csv(self):
data = dedent('''
"spam","eggs","ham"
"42","3.0","2011-01-02"
"1","3.14","2012-01-11"
"21","6.28","2010-01-03"
"2","2.71","2"
''').strip() + '\n'
temp_fp = tempfile.NamedTemporaryFile(delete=False)
temp_fp.write(data)
temp_fp.close()
temp_fp_2 = tempfile.NamedTemporaryFile(delete=False)
temp_fp_2.close()
my_table = Table()
my_table.read('csv', temp_fp.name)
my_table.write('csv', temp_fp_2.name)
temp_fp_2 = open(temp_fp_2.name)
contents = temp_fp_2.read()
temp_fp_2.close()
os.remove(temp_fp.name)
os.remove(temp_fp_2.name)
self.assertEquals(contents, data)
示例10: test_vertical_histogram
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_vertical_histogram(self):
seed(1234) # Setting the seed to get repeatable results
numbers = normal(size=1000)
my_table = Table(headers=['values'])
my_table.extend([[value] for value in numbers])
output = my_table.write('histogram', column='values', height=5,
orientation='vertical', bins=10)
expected = dedent('''
265 |
||
|||
||||
||||||
-3.56 2.76
''').strip()
self.assertEquals(output, expected)
示例11: test_to_html_with_only_headers
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_to_html_with_only_headers(self):
my_table = Table(headers=['ham', 'spam', 'eggs', 'blah'])
output = my_table.write('html', css_classes=False)
expected = dedent('''
<table>
<thead>
<tr>
<th>ham</th>
<th>spam</th>
<th>eggs</th>
<th>blah</th>
</tr>
</thead>
</table>
''').strip()
self.assertEquals(output, expected)
示例12: test_write_csv_without_filename_should_return_csv_data
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_write_csv_without_filename_should_return_csv_data(self):
data = dedent('''
"spam","eggs","ham"
"42","3.0","2011-01-02"
"1","3.14","2012-01-11"
"21","6.28","2010-01-03"
"2","2.71","2"
''').strip() + '\n'
temp_fp = tempfile.NamedTemporaryFile(delete=False)
temp_fp.write(data)
temp_fp.close()
my_table = Table()
my_table.read('csv', temp_fp.name)
contents = my_table.write('csv')
os.remove(temp_fp.name)
self.assertEquals(contents, data)
示例13: test_to_html_should_create_CSS_classes_for_odd_and_even_rows
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_to_html_should_create_CSS_classes_for_odd_and_even_rows(self):
my_table = Table(headers=['ham', 'spam', 'eggs'])
my_table.append(['python', 'rules', '!'])
my_table.append({'ham': 'spam', 'spam': 'eggs', 'eggs': 'ham'})
my_table.append(['python', 'rules', '!'])
my_table.append({'ham': 'spam', 'spam': 'eggs', 'eggs': 'ham'})
output = my_table.write('html', css_classes=True)
expected = dedent('''
<table>
<thead>
<tr class="header">
<th>ham</th>
<th>spam</th>
<th>eggs</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>python</td>
<td>rules</td>
<td>!</td>
</tr>
<tr class="even">
<td>spam</td>
<td>eggs</td>
<td>ham</td>
</tr>
<tr class="odd">
<td>python</td>
<td>rules</td>
<td>!</td>
</tr>
<tr class="even">
<td>spam</td>
<td>eggs</td>
<td>ham</td>
</tr>
</tbody>
</table>
''').strip()
self.assertEquals(output, expected)
示例14: test_horizontal_histogram
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
def test_horizontal_histogram(self):
seed(1234) # Setting the seed to get repeatable results
numbers = normal(size=1000)
my_table = Table(headers=['values'])
my_table.extend([[value] for value in numbers])
output = my_table.write('histogram', column='values', height=15, bins=10,
orientation='horizontal')
expected = dedent('''\
265
-3.56:
-2.93:
-2.30: ||
-1.67: ||||
-1.03: ||||||||||
-0.40: |||||||||||||||
0.23 : ||||||||||||
0.87 : ||||||
1.50 : |||
2.13 :''')
self.assertEquals(output, expected)
示例15: str
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import write [as 别名]
# coding: utf-8
# title = Using MySQL plugin
#It's easy to import data from and export data to a MySQL table.
#``outputty`` automatically identify type of data and creates a table in MySQL
#for you with correct data types, so don't worry about converting everyting.
#Let's create a simple table, export it to MySQL and then import it again.
#Note: you need to change ``connection_string`` before run it.
from outputty import Table
from random import randint
# The connection string should be in the format:
# 'username:[email protected][:port]/database/table_name'
connection_string = 'root:[email protected]/testing/test_table_' + \
str(randint(0, 99999))
my_table = Table(headers=['ID', 'First name', 'Last name'])
my_table.append({'First name': 'Álvaro', 'Last name': 'Justen', 'ID': '123'})
my_table.append((456, 'Flávio', 'Amieiro'))
my_table.append(['789', 'Flávio', 'Coelho'])
my_table.write('mysql', connection_string)
print 'Table saved:'
print my_table
print 'The types identified are:', my_table.types
other_table = Table()
other_table.read('mysql', connection_string)
print
print 'Table retrieved:'
print other_table