[Tutor] Alternative File I/O for Tuples (fwd)

Don Parris webdev at matheteuo.org
Wed Jun 29 19:31:03 CEST 2005

On Wed, 29 Jun 2005 12:37:45 -0400
Kent Johnson <kent37 at tds.net> wrote:

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

> 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))

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
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.

evangelinux    GNU Evangelist
http://matheteuo.org/                   http://chaddb.sourceforge.net/
"Free software is like God's love - you can share it with anyone anytime

More information about the Tutor mailing list