Comments (5)
You need to do either this:
-----
import prettytable
myTable = prettytable.PrettyTable()
-----
or this:
-----
from prettytable import PrettyTable
myTable = PrettyTable()
-----
This is just the way that Python imports work - all libraries work this way and
it's not an issue specific to PrettyTable.
Sorry for the very slow reply! Hope this helps.
Cheers,
Luke
Original comment by [email protected]
on 9 Sep 2013 at 5:19
- Changed state: Invalid
from prettytable.
Thank you, it works now. Clearly overlooked that.
Thank you for maintaining this project. Very handy!
Original comment by [email protected]
on 12 Sep 2013 at 9:29
from prettytable.
I am very new to programming and having trouble getting this to work. I copied
the example code from the tutorial and added the import code from the previous
response in this thread but still getting the same error as the op:
Traceback (most recent call last):
File "D:\Program Files\PROGRAMMING\Python\test1.py", line 4, in <module>
x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
NameError: name 'PrettyTable' is not defined
My code is:
import prettytable
mytable = prettytable.PrettyTable()
x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
x.align["City name"] = "l" # Left align city names
x.padding_width = 1 # One space between column edges and contents (default)
x.add_row(["Adelaide",1295, 1158259, 600.5])
x.add_row(["Brisbane",5905, 1857594, 1146.4])
x.add_row(["Darwin", 112, 120900, 1714.7])
x.add_row(["Hobart", 1357, 205556, 619.5])
x.add_row(["Sydney", 2058, 4336374, 1214.8])
x.add_row(["Melbourne", 1566, 3806092, 646.9])
x.add_row(["Perth", 5386, 1554769, 869.4])
print(x)
What am I doing wrong?
Original comment by [email protected]
on 5 Nov 2013 at 7:54
from prettytable.
You are basically having the same problem as the person who originally opened
this issue, and the solution is the same.
When you do "import prettytable", this basically lets you use the word
"prettytable" in your code without Python getting confused. Anything else
needs to be prefaced with "prettytable", so to instantiate a PrettyTable object
you'd need to use "prettytable.PrettyTable".
Alternatively you can do "from prettytable import PrettyTable", which then lets
you use PrettyTable directly.
You are correctly instantiating the "mytable" variable on the second line of
your code. But then you go on to try to instantiate the "x" variable
incorrectly, using PrettyTable directly.
The easiest way to change the code you have posted to somethin that works is:
1) Delete line 2 (you aren't using "mytable" anywhere anyway)
2) Change line 3 to start with "x = prettytable.PrettyTable(" (keep the rest of
the line as it is)
This should then display the example table of Australian cities.
Original comment by [email protected]
on 5 Nov 2013 at 8:04
from prettytable.
Wow, thank you for the prompt and easy to understand response! It's working
now.
Original comment by [email protected]
on 5 Nov 2013 at 8:46
from prettytable.
Related Issues (20)
- the data on "how to display chinese character"
- how to display "ambiguous" width in chinese character?
- table.min_width is broken when using PLAIN_COLUMNS style HOT 2
- Field alignment error when using "blessings" module HOT 1
- Adding colors to column values messes up the spacing HOT 2
- Setting float_format in **kwargs does not actually affect output - confusing behavior HOT 1
- Permissions are incorrect HOT 1
- Add date formatting for datetime etc instances HOT 3
- In get_string, end is eval before sortby
- HTML output is lacking borders, alignment
- Cannot print unicode characters, for example: degree symbol °
- Pandas DataFrame Table Factory HOT 3
- Upload new version to pypi
- xterm reset escape sequence not filtered HOT 2
- Support large tables in output HOT 1
- Prettytable 0.7.2 does not handle rowspan correctly
- Creating a PrettyTable inside a for. HOT 1
- Project Future and Plans HOT 5
- Export project to Github (or other git hosting project) HOT 2
- Stretching columns when the data are longer than the header
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettytable.