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 Don Parris other posts by this author
Jun 29 2005 10:14AM messages near this date
Re: [Tutor] Alternative File I/O for Tuples (fwd) | Re: [Tutor] Alternative File I/O for Tuples (fwd)
On Wed, 29 Jun 2005 12:37:45 -0400
Kent Johnson <kent37@[...].net>  wrote:

>  Don Parris wrote:
>  > On Wed, 29 Jun 2005 06:38:36 -0400
>  > Kent Johnson <kent37@[...].net> wrote:
>  >>Don Parris wrote:

<SNIP> 
>  
>  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.
>  
That was my own copy/paste error in the e-mail.  It doesn't look that way in
my code.  My bad.

### playing with wrapfunc (all other args are the same) ###
wrapfunc=lambda x:wrap_onspace(str(rows), x))

also
wrapfunc=lambda x:str(wrap_onspace(rows, x)))

both generate the same error:
Traceback (most recent call last):
  File "ekklesia.py", line 9, in ?
    from ekklesia_db import *  #Comment out this line if MySQL not
installed.  File "/home/donp/python/ekklesia/ekklesia_db.py", line 64
    mbrPhone.close()
           ^
SyntaxError: invalid syntax



>  > 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 foreign 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 the 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!
>  
I realize that I'm kind of putting the cart before the horse here - trying
to accomplish a real program without understanding the tools well.  I also
feel like I should play around more with other code (the recipes and Python
programs already available).  I also think I should spend a little time
doing the line-by-line analysis of code in the snippets/programs above to be
sure I understand what I'm reading in the tutorials.  So, aside from trying
to jump to step #10 from step #1, I think I'm doing fairly well. :)

>  When you become more comfortable with the basics you should start to see
>  how they fit together to make useful programs. Just in the snippets we are
>  working on we have touched on looping, file I/O and function calls which
>  should be topics in any tutorial.
>  
>  Kent
>  
I'll get there.

Don
-- 
evangelinux    GNU Evangelist
http://matheteuo.org/                   http://chaddb.sourceforge.net/
"Free software is like God's love - you can share it with anyone anytime
anywhere."
_______________________________________________
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