diff options
author | luke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937> | 2012-07-04 01:57:12 +0000 |
---|---|---|
committer | luke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937> | 2012-07-04 01:57:12 +0000 |
commit | e539f3a64cfa8b8906f664933508467556a27fb8 (patch) | |
tree | ddeb8b98322449ea3948481f50c02ac3f9a9d52d | |
parent | bcc9dbcc3419c81cba7e079aafb67b5f1b56903c (diff) | |
download | python-prettytable-e539f3a64cfa8b8906f664933508467556a27fb8.tar.gz |
Fixed Python 3 compatibility bug - Py3k requires __str__ to return unicode for print() to work, duh!
git-svn-id: http://prettytable.googlecode.com/svn/trunk@83 0f58610c-415a-11de-9c03-5d6cfad8e937
-rw-r--r-- | prettytable.py | 8 | ||||
-rw-r--r-- | prettytable_test.py | 10 |
2 files changed, 11 insertions, 7 deletions
diff --git a/prettytable.py b/prettytable.py index 410fd74..1fbd42d 100644 --- a/prettytable.py +++ b/prettytable.py @@ -209,8 +209,12 @@ class PrettyTable(object): raise Exception("Index %s is invalid, must be an integer or slice" % str(index)) return newtable - def __str__(self): - return self.__unicode__().encode(self.encoding) + if py3k: + def __str__(self): + return self.__unicode__() + else: + def __str__(self): + return self.__unicode__().encode(self.encoding) def __unicode__(self): return self.get_string() diff --git a/prettytable_test.py b/prettytable_test.py index 5736f5d..e5a8696 100644 --- a/prettytable_test.py +++ b/prettytable_test.py @@ -1,4 +1,3 @@ -#import cProfile, pstats import unittest import sys sys.path.append("../src/") @@ -468,9 +467,10 @@ class HtmlOutputTests(unittest.TestCase): </table> """.strip() +class PrintTest(CityDataTest): + + def testPrint(self): + print(self.x) + if __name__ == "__main__": - #cProfile.run("unittest.main()", "fooprof") - #p = pstats.Stats("fooprof") - #p.sort_stats("time") - #p.print_stats() unittest.main() |