Hello!
I am trying to run the code provided in the texttable module documentation (http://jefke.free.fr/coding/python/texttable/) as shown in the code, but it returns a name error which tells that Texttable is not defined.

import texttable
table = Texttable()
table.set_cols_align(["l", "r", "c"])
table.set_cols_valign(["t", "m", "b"])
table.add_rows([ ["Name", "Age", "Nickname"], ["Mr\nXavier\nHuon", 32, "Xav'"], ["Mr\nBaptiste\nClement", 1, "Baby"] ])
print table.draw()

I don't know how to solve it, as I am importing the module. Has anyone experimented the same error and solved it?
Cheers!

Dani

>>> import texttable
>>> dir(texttable)
['ArraySizeError',
 'Texttable',
 '__all__',
 '__author__',
 '__builtins__',
 '__credits__',
 '__doc__',
 '__file__',
 '__license__',
 '__name__',
 '__package__',
 '__revision__',
 '__version__',
 'len',
 'string',
 'sys',
 'textwrap']


>>> table = Texttable()
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
NameError: name 'Texttable' is not defined


table = texttable.Texttable()  #ok
#We change import line
from texttable import Texttable

table = Texttable()
table.set_cols_align(["l", "r", "c"])
table.set_cols_valign(["t", "m", "b"])
table.add_rows([ ["Name", "Age", "Nickname"], ["Mr\nXavier\nHuon", 32, "Xav'"], ["Mr\nBaptiste\nClement", 1, "Baby"] ])
print table.draw()

'''-->Out
+----------+-----+----------+
|   Name   | Age | Nickname |
+==========+=====+==========+
| Mr       |     |          |
| Xavier   |  32 |          |
| Huon     |     |   Xav'   |
+----------+-----+----------+
| Mr       |     |          |
| Baptiste |   1 |          |
| Clement  |     |   Baby   |
+----------+-----+----------+
'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.