[Tutor] latest version and results.

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu, 22 Nov 2001 00:41:49 -0800 (PST)


On Thu, 22 Nov 2001, Kirk Bailey wrote:

[some code cut]
> for line in inf.readlines():
>         addr = line.strip() + "@" + domain
[more code cut]
> 
> Traceback (innermost last):
>   File "./filedomainadd.py", line 26, in ?
>     addr = line.strip() + "@" + domain
> AttributeError: 'string' object has no attribute 'strip'
> $ 
> -----------------end-------------------------------
> 
> intresting, seems something wants an attribute, and I do not
> comprehend what STRIP is or deos, I just took the code offered and
> implemented it. WTF, over please?

Hi Kirk,

The expression:

    line.strip()

means: "Take the string 'line', and strip() from it all whitespace on
either side of it."  It's often used to remove trailing newlines.


However, the line above uses "string method" syntax, and that was
introduced into the Python language around version 1.6.  Older versions of
Python didn't have this syntax, so that's why the AttributeError is being
flagged.  Thankfully, there's an equivalent expression we can use, with
the help of the string module:

    string.strip(line)

With this compatibility correction, your line will look like this:

    addr = string.strip(line) + "@" + domain

and that should work better for you.  However, you might want to see if
upgrading your Python is possible, since there's been quite a few bug
fixes and improvements to the language since 1.52.


For more documentation on string.strip(), you can look at:

    http://www.python.org/doc/lib/module-string.html


Good luck to you.