How to write out full numbers with texttable?

Question:

Currently I am trying to write out a table with information from a list.
The list is as followed:

Anna Annasson
4321654321
AnnasEpost
AnnasAdress
Bob Steven
02847661723
[email protected]
Bob Street 121
Alex Ericsson
1233213211
[email protected]
Alex Street 112
Chris Philips
018207129387
[email protected]
Christ Street 902

Currently it is stored in a list, and I write it out as such:

t = Texttable()
        for i in range(0, numeroftimes):
            t.add_rows([['Name', 'Number', 'Email', 'Adress'], [self.listofpeople[n], self.listofpeople[1+ n], self.listofpeople[2 + n], self.listofpeople[3 + n]]])
            n += 4
        print(t.draw())

What i would like is something like this:

+---------------+---------------+------------+-------------+
|     Name      | Number        |   Email    |   Adress    |
+===============+===============+============+=============+
| Anna Annasson | 321313123     | AnnasEmail | AnnasAdress |
+---------------+---------------+------------+-------------+
| Anna Annasson | 321313123     | AnnasEmail | AnnasAdress |
+---------------+---------------+------------+-------------+

Note that I use the first name for example, I have no trouble with writing out every single person as shown below, but for simplicity I show it with only one person

I get the output:

+---------------+---------------+------------+-------------+
|     name      | number        |   Email    |   Adress    |
+===============+===============+============+=============+
| Anna Annasson | 4.322e+09     | AnnasEmail | AnnasAdress |
+---------------+---------------+------------+-------------+
| Anna Annasson | 4.322e+09     | AnnasEmail | AnnasAdress |
+---------------+---------------+------------+-------------+
(Annas phonenumber is 4321654321 and not 4.322e+09)

How do I change it for it to be the full number instead?

I have tried converting it to a string and int in the code, but it does not change anything.

Asked By: Voltz

||

Answers:

You can use set_cols_dtype to set the type of each column explicitly

t.set_cols_dtype(['t', 'i', 't', 't'])

In this case text, integer, text, text. If you omit this all columns use "automatic" (i.e. 'a') and will try to determine the data type.

Answered By: Cory Kramer
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.