Deprecation in String.joinfields()

John Machin sjmachin at lexicon.net
Mon Sep 25 10:25:06 EDT 2006


Anoop wrote:
> Hi All,
>
> I am getting the following error while trying to use deprecation
>
> Please help
>
> >>> li = ["a", "b", "mpilgrim", "z", "example"]
> >>> newname = string.joinfields (li[:-1], ".")
> >>> newname
> 'a.b.mpilgrim.z'
> >>> newname = li[:-1].joinfields(".")
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> AttributeError: 'list' object has no attribute 'joinfields'
>
> >>> newname1 = string.join (li[:-1], ".")
> >>> newname1
> 'a.b.mpilgrim.z'
> >>> newname = li[:-1].joinfields(".")
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> AttributeError: 'list' object has no attribute 'join'
>

Hi Anoop, and welcome to Python.
1. Pretend the string module doesn't exist. "Deprecated" means
"outdated; *don't* use it".
2. Instead use methods of string objects (more precisely, str objects
and unicode objects, which have mostly the same methods).

In this case

| >>> '.'.join(li)
| 'a.b.mpilgrim.z.example'

Yes, I know it looks strange -- FAQ: why not li.join('.') -- but that's
the way it is.

What tutorial or textbook are you using that led you down the
string-module path?

Cheers,
John




More information about the Python-list mailing list