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

Don Parris webdev at matheteuo.org
Wed Jun 29 18:24:41 CEST 2005


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

> Don Parris wrote:
> > On Tue, 28 Jun 2005 05:50:54 -0400
> > Kent Johnson <kent37 at tds.net> wrote:

<SNIP>

Thanks for the explanation of indentation!  I kind of understood that, but
wanted to be sure I understood correctly what was happening with the text
file inside the for loop.  And if that sounds a little loopy, well... :)

> 
> 'Global name "rows" is not defined means that Python doesn't know what
> 'rows' means - you haven't assigned any value to that name. I'm surprised
> your code didn't work when you add the line "rows = Results" as indicated
> above; what error do you get then? But a simpler way is just to use
> Results in the call to indent:
> 
>     mbrPhone.write(indent(Results, hasHeader=False, separateRows=False,
>                               prefix='| ', postfix=' |'))
> 
> What happens if you try that?
> 

Well this is kind of instructive.  Assigning rows = Results and using
Results as an argument to indent() produce the same traceback message.  I
was right that the "rows" argument needed the value of "Results", so I *am*
learning something.  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.  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))

Traceback (most recent call last):
  File "ekklesia.py", line 9, in ?
    from ekklesia_db import *  
  File "/home/donp/python/ekklesia/ekklesia_db.py", line 64
    mbrPhone.close()
           ^
SyntaxError: invalid syntax
### end function call and traceback ###

mbrPhone.close() is properly indented.  I even put the whole indent() call
on one single line.  So now I'm not sure where to go.  I know that error
messages can sometimes be misleading.  I also know that close() takes
exactly 0 arguments.  So maybe I need to look back at indent()?


> > BTW, I really appreciate your patience and willingness to help me
> > understand this.
> 
> No problem, that's what we do here. At least on a good day :-)
> 
> > If I had ever dreamed that I would have a desire to program 20 years
> > after the fact, I would have stopped passing notes in Math class.  I do
> > it well, but hate it.  Yet, I find myself drawn further and further into
> > the code, actually wanting to know more about it - why it does what it
> > does.
> 
> I don't know about the 'hating it' part, but you are certainly not alone
> in finding yourself fascinated with programming in Python. But snakes can
> do that, can't they? We are all trapped by its hypnotic stare... ;-)
> 
You bet!

> BTW have you found a tutorial you like? There are many free Python
> tutorials, take a look at this page:
> http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
> 
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.


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


More information about the Tutor mailing list