Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75026 > unrolled thread
| Started by | fl <rxjwg98@gmail.com> |
|---|---|
| First post | 2014-07-22 14:42 -0700 |
| Last post | 2014-08-03 23:49 +0100 |
| Articles | 11 — 7 participants |
Back to article view | Back to comp.lang.python
Why does not pprint work? fl <rxjwg98@gmail.com> - 2014-07-22 14:42 -0700
Re: Why does not pprint work? Chris Angelico <rosuav@gmail.com> - 2014-07-23 07:49 +1000
Re: Why does not pprint work? emile <emile@fenx.com> - 2014-07-22 14:51 -0700
Re: Why does not pprint work? fl <rxjwg98@gmail.com> - 2014-07-22 15:05 -0700
Re: Why does not pprint work? emile <emile@fenx.com> - 2014-07-22 15:17 -0700
Re: Why does not pprint work? Chris Angelico <rosuav@gmail.com> - 2014-07-23 08:19 +1000
Re: Why does not pprint work? Chris Kaynor <ckaynor@zindagigames.com> - 2014-07-22 15:22 -0700
Re: Why does not pprint work? Ned Batchelder <ned@nedbatchelder.com> - 2014-07-22 22:26 -0400
Re: Why does not pprint work? Chris Angelico <rosuav@gmail.com> - 2014-07-23 15:05 +1000
Re: Why does not pprint work? robkotenko@gmail.com - 2014-08-03 14:34 -0700
Re: Why does not pprint work? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-03 23:49 +0100
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2014-07-22 14:42 -0700 |
| Subject | Why does not pprint work? |
| Message-ID | <6e09bc9c-d510-4076-b20d-32df796ca59e@googlegroups.com> |
Hi,
I read web tutorial at:
http://nedbatchelder.com/blog/201308/names_and_values_making_a_game_board.html
I enter the example lines of that website:
import pprint
board = [ [0]*8 ] * 8
pprint(board)
It echos error with Python 2.7:
Traceback (most recent call last):
File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\framework\scriptutils.py",
line 323, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\debugger\__init__.py",
line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\debugger\debugger.py",
line 655, in run
exec cmd in globals, locals
File "C:\cygwin64\home\Jeff\Python_lesson\ppn.py", line 1, in <module>
import pprint
TypeError: 'module' object is not callable
It has similar error with Python 3.4.1.
Why does pprint not work?
Thanks,
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-07-23 07:49 +1000 |
| Message-ID | <mailman.12198.1406065796.18130.python-list@python.org> |
| In reply to | #75026 |
On Wed, Jul 23, 2014 at 7:42 AM, fl <rxjwg98@gmail.com> wrote: > I enter the example lines of that website: > > > import pprint > board = [ [0]*8 ] * 8 > pprint(board) Flaw in the blog post: he didn't actually specify the import line. What you actually want is this: from pprint import pprint Or use pprint.pprint(board), but you probably don't need anything else from the module. Ned, if you're reading this: Adding the import would make the post clearer. :) ChrisA
[toc] | [prev] | [next] | [standalone]
| From | emile <emile@fenx.com> |
|---|---|
| Date | 2014-07-22 14:51 -0700 |
| Message-ID | <mailman.12199.1406065896.18130.python-list@python.org> |
| In reply to | #75026 |
On 07/22/2014 02:42 PM, fl wrote: > Hi, > > I read web tutorial at: > > http://nedbatchelder.com/blog/201308/names_and_values_making_a_game_board.html > > I enter the example lines of that website: > > > import pprint > board = [ [0]*8 ] * 8 > pprint(board) > > pprint is a module name -- you need to invoke the pprint function from within the pprint module: pprint.pprint(board) or alternately, from pprint import pprint pprint(board) or, as I sometime do from pprint import pprint as pp pp(board) Emile
[toc] | [prev] | [next] | [standalone]
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2014-07-22 15:05 -0700 |
| Message-ID | <d7e3d1fa-29d3-4408-acb0-a85f96e57c0a@googlegroups.com> |
| In reply to | #75028 |
On Tuesday, July 22, 2014 5:51:07 PM UTC-4, emile wrote: > On 07/22/2014 02:42 PM, fl wrote: > pprint is a module name -- you need to invoke the pprint function from > within the pprint module: > pprint.pprint(board) Thanks. I am curious about the two pprint. Is it the first pprint the name of the module? The second pprint is the function name? Then, how can I list all the function of pprint? And, is there a way to list the variables I create in Python?
[toc] | [prev] | [next] | [standalone]
| From | emile <emile@fenx.com> |
|---|---|
| Date | 2014-07-22 15:17 -0700 |
| Message-ID | <mailman.12200.1406067501.18130.python-list@python.org> |
| In reply to | #75030 |
On 07/22/2014 03:05 PM, fl wrote: > On Tuesday, July 22, 2014 5:51:07 PM UTC-4, emile wrote: >> On 07/22/2014 02:42 PM, fl wrote: >> pprint is a module name -- you need to invoke the pprint function from >> within the pprint module: >> pprint.pprint(board) > > Thanks. I am curious about the two pprint. Is it the first pprint the name of the > module? The second pprint is the function name? Yes. > Then, how can I list all the function of pprint? use the dir builtin: >>> dir (pprint) ['PrettyPrinter', '_StringIO', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_commajoin', '_id', '_len', '_perfcheck', '_recursion', '_safe_repr', '_sys', '_type', 'isreadable', 'isrecursive', 'pformat', 'pprint', 'saferepr'] > > And, is there a way to list the variables I create in Python? also dir: >>> dir() ['__builtins__', '__doc__', '__name__', 'board', 'mylist', 'pprint', 'reassign'] Emile
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-07-23 08:19 +1000 |
| Message-ID | <mailman.12201.1406067587.18130.python-list@python.org> |
| In reply to | #75030 |
On Wed, Jul 23, 2014 at 8:05 AM, fl <rxjwg98@gmail.com> wrote: > On Tuesday, July 22, 2014 5:51:07 PM UTC-4, emile wrote: >> On 07/22/2014 02:42 PM, fl wrote: >> pprint is a module name -- you need to invoke the pprint function from >> within the pprint module: >> pprint.pprint(board) > > Thanks. I am curious about the two pprint. Is it the first pprint the name of the > module? The second pprint is the function name? Correct. There's a module pprint which provides a function pprint.pprint. It's like you can do this: >>> import math >>> math.sin(3.14/2) 0.9999996829318346 Or this: >>> from math import sin >>> sin(3.14/2) 0.9999996829318346 It's just that in this case, "math" and "sin" are both "pprint". > Then, how can I list all the function of pprint? >>> import pprint >>> help(pprint) > And, is there a way to list the variables I create in Python? Kinda. Try this: >>> dir() There'll be some in there that you didn't make, but that's a start. You could also try vars() or globals(), which will give you their values as well. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Chris Kaynor <ckaynor@zindagigames.com> |
|---|---|
| Date | 2014-07-22 15:22 -0700 |
| Message-ID | <mailman.12202.1406067789.18130.python-list@python.org> |
| In reply to | #75030 |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Jul 22, 2014 at 3:17 PM, emile <emile@fenx.com> wrote: > Then, how can I list all the function of pprint? >> > > use the dir builtin: > > >>> dir (pprint) > ['PrettyPrinter', '_StringIO', '__all__', '__builtins__', '__doc__', > '__file__', '__name__', '_commajoin', '_id', '_len', '_perfcheck', > '_recursion', '_safe_repr', '_sys', '_type', 'isreadable', 'isrecursive', > 'pformat', 'pprint', 'saferepr'] Another useful feature is the "help" function (can be used like "help(pprint)" or just "help()" for interactive usage), which will also provide the documentation for each item in addition to just the names. Chris
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-07-22 22:26 -0400 |
| Message-ID | <mailman.12211.1406082429.18130.python-list@python.org> |
| In reply to | #75026 |
On 7/22/14 5:49 PM, Chris Angelico wrote: > On Wed, Jul 23, 2014 at 7:42 AM, fl <rxjwg98@gmail.com> wrote: >> I enter the example lines of that website: >> >> >> import pprint >> board = [ [0]*8 ] * 8 >> pprint(board) > > Flaw in the blog post: he didn't actually specify the import line. > What you actually want is this: > > from pprint import pprint > > Or use pprint.pprint(board), but you probably don't need anything else > from the module. > > Ned, if you're reading this: Adding the import would make the post clearer. :) Done. > > ChrisA > -- Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-07-23 15:05 +1000 |
| Message-ID | <mailman.12215.1406091942.18130.python-list@python.org> |
| In reply to | #75026 |
On Wed, Jul 23, 2014 at 12:26 PM, Ned Batchelder <ned@nedbatchelder.com> wrote: >> Ned, if you're reading this: Adding the import would make the post >> clearer. :) > > > Done. Thanks Ned! ChrisA
[toc] | [prev] | [next] | [standalone]
| From | robkotenko@gmail.com |
|---|---|
| Date | 2014-08-03 14:34 -0700 |
| Message-ID | <71cc5e7f-9933-4702-b2ac-b0fab6e0457e@googlegroups.com> |
| In reply to | #75026 |
With the way you have imported, you trying to use the module pprint instead of the function pprint.pprint. You need to use pprint.pprint or you need to import as: from pprint import pprint if you want to use the shorter form. On Tuesday, July 22, 2014 5:42:02 PM UTC-4, fl wrote: > Hi, > > > > I read web tutorial at: > > > > http://nedbatchelder.com/blog/201308/names_and_values_making_a_game_board.html > > > > I enter the example lines of that website: > > > > > > import pprint > > board = [ [0]*8 ] * 8 > > pprint(board) > > > > > > It echos error with Python 2.7: > > > > Traceback (most recent call last): > > File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\framework\scriptutils.py", > > line 323, in RunScript > > debugger.run(codeObject, __main__.__dict__, start_stepping=0) > > File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\debugger\__init__.py", > > line 60, in run > > _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) > > File "C:\Python27\Lib\SITE-P~1\PYTHON~2\pywin\debugger\debugger.py", > > line 655, in run > > exec cmd in globals, locals > > File "C:\cygwin64\home\Jeff\Python_lesson\ppn.py", line 1, in <module> > > import pprint > > TypeError: 'module' object is not callable > > > > It has similar error with Python 3.4.1. > > > > > > Why does pprint not work? > > > > > > Thanks,
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-08-03 23:49 +0100 |
| Message-ID | <mailman.12599.1407106210.18130.python-list@python.org> |
| In reply to | #75621 |
On 03/08/2014 22:34, robkotenko@gmail.com wrote: [snipped to bits] Please don't top post, further would you read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web