Jump to content


Ch. 4, Page 129

  • Please log in to reply
2 replies to this topic

#1 njordan2001


    New Member

  • Members
  • Pip
  • 4 posts

Posted 19 February 2012 - 09:20 AM

So, I've edited the nester module. I then referred to chapter 2, and built my distribution and installed it to my local copy of python.

Here's my updated program:
import nester

man = []
other = []

    data = open('sketch.txt')
    for each_line in data:
            (role, line_spoken) = each_line.split(':', 1)
            line_spoken = line_spoken.strip()
            if role == 'Man':
            elif role == 'Other Man':
        except ValueError:
except IOError as oops:
    print('The datafile is missing! ' + str(oops))

    with open('man_data.txt', 'w') as man_file, open('other_data.txt', 'w') as other_file:
        print_lol(man, fh=man_file)
        print_lol(other, fh=other_file)
except IOError as err:
    print('File error: ' + str(err))

But, I'm getting this 'print_lol' is not defined! I have a feeling that I'm just overlooking some small typo or missing one simple line of code...

#2 njordan2001


    New Member

  • Members
  • Pip
  • 4 posts

Posted 19 February 2012 - 09:57 AM

Ok.... I decided to read a little further back in Chapter 2. Yep, found my problem.

I need to either specify that print_lol comes from the nester module:
nester.print_lol(man, fh=man_file)

Or, when I 'import nester', I can specify the 'print_lol' function there:
from nester import print_lol

The whole 'namespace' thing. This time I read it and took some time to think about it a little more and now understand and "agree" with the idea of using the 'nester.print_lol' way.

#3 shamifd


    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 July 2013 - 06:15 AM

I have the same question.

Great Thanks!

Edited by shamifd, 23 July 2013 - 06:15 AM.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users