Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to write out full numbers with texttable?

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
Bob@mail.com
Bob Street 121
Alex Ericsson
1233213211
Alex@mail.com
Alex Street 112
Chris Philips
018207129387
Chris@mail.com
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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

+---------------+---------------+------------+-------------+
|     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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading