ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] Alternative File I/O for Tuples (fwd)
by Kent Johnson other posts by this author
Jun 29 2005 9:38AM messages near this date
Re: [Tutor] Alternative File I/O for Tuples (fwd) | Re: [Tutor] Alternative File I/O for Tuples (fwd)
Don Parris wrote:
>  On Wed, 29 Jun 2005 06:38:36 -0400
>  Kent Johnson <kent37@[...].net> wrote:
> >Don Parris wrote:
>  However, it seems that the function doesn't like the
>  value I give it.
>  
>  ### Using Results as the argument to indent() ###
>  Traceback (most recent call last):
>    File "ekklesia.py", line 165, in ?
>      Main()
>    File "ekklesia.py", line 160, in Main
>      RunMenu(Menu_Main)
>    File "ekklesia.py", line 31, in RunMenu
>      if len(MenuList[sel]) == 3: MenuList[sel][1](MenuList[sel][2])
>    File "ekklesia.py", line 32, in RunMenu
>      else: MenuList[sel][1]()
>    File "/home/donp/python/ekklesia/ekklesia_db.py", line 63, in mbr_Phone
>      prefix='| ', postfix=' |'))
>    File "/home/donp/python/ekklesia/tbl_Tabs.py", line 24, in indent
>      logicalRows = [rowWrapper(row) for row in rows]
>    File "/home/donp/python/ekklesia/tbl_Tabs.py", line 21, in rowWrapper
>      newRows = [wrapfunc(item).split('\n') for item in row]
>  AttributeError: 'NoneType' object has no attribute 'split'
>  ### end traceback ###
>  
>  My SQL query functions return a tuple, so indent() has to recognize that
>  much.  

This is a tough one to interpret. The value being returned from wrapfunc() is expected to be
 a string, but instead it is None. Calling None.split() generates the AttributeError.

Looking at wrapfunc, in defaults to an identity function that just returns its argument. So 
it looks like the tuples you get back from MySQL have None values in them which is confusing
 indent().

Try with 
  wrapfunc=lambda x: x or ''
which will convert None to an empty string, or
  wrapfunc=lambda x: str(x)
which will convert None to the string 'None'

>  I suspected this has to do with the wrapfunc argument.  I had dropped
>  it at some point, thinking that would help me grasp the problem.  I fed it
>  rows(using the rows= Results at the moment), and got this traceback:
>  
>  ### revised function call and traceback ###
>  mbrPhone.write(indent(rows, hasHeader=False, separateRows=False,
>                                 prefix='| ', postfix=' |'))wrapfunc=lambda
>                                 x:wrap_onspace(rows, 12))

Take another look at the line above, the commas and parens aren't right.

>  I've read the Python tutorial, Alan's tutorial, and have worked through some
>  of the others as well.  It looks simple enough, but when I try things out
>  for myself, I find it difficult to see how the examples apply in my
>  situation.  Which is why I sought out this list.  My Guess is that I need to
>  "just do it" for a while before it'll come to me.

"just doing it" is critical. Learning to program is like learning to write or learning a for
eign language. It just can't be done by reading about it; the only way to learn is to do it.
 One thing to try is to just type in examples from a tutorial. Then think of variations on t
he example; try them out. Play with it, whatever crazy idea you have is good. This will give
 you experience with the basics and also some experience with error messages!

When you become more comfortable with the basics you should start to see how they fit togeth
er to make useful programs. Just in the snippets we are working on we have touched on loopin
g, file I/O and function calls which should be topics in any tutorial.

Kent

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Danny Yoo
Kent Johnson
Don Parris
Don Parris
Kent Johnson
Don Parris
Kent Johnson
Don Parris
Kent Johnson
Don Parris
Kent Johnson
Don Parris

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved