473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Deprecation in String.joinfields()

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'

Thank you for your help

Anoop

Sep 25 '06 #1
4 3167

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

Sep 25 '06 #2
"Anoop" wrote:
I am getting the following error while trying to use deprecation
deprecation ?
>>>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'
you're trying to call the "joinfields" method on a list object. lists don't have
such a method. to join strings in a list using a separator, use

separator.join(list)

or in your case,

newname = ".".join(li[:-1])

older code sometimes use the "join" function from the "string" module in-
stead:

import string
newname = string.join(li[:-1], separator)

string.joinfields is a really old spelling of string.join. that's been deprecated
for a decade, or so.

</F>

Sep 25 '06 #3
Hello,

Anoop wrote:
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'

Thank you for your help
joinfields is just an alias for join and only the latter is a method of the
string class (which should be used instead of the deprecated string.join
function), which means that the string "." has a method join which takes
the list as an argument.

So what you want should be written as:

newname = ".".join(li[:-1])
HTH

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
Sep 25 '06 #4
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'

Thank you for your help

Anoop
I think you want:

newname1='.'.join(li[:-1])

-Larry Bates
Sep 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Robin Becker | last post by:
It seems that the rotor module is being deprecated in 2.3, but there doesn't seem to be an obvious alternative. I'm using it just for obfuscation. It seems we have ssl available in 2.3 for sockets,...
12
by: zhi | last post by:
Really confused, when I use keyword style argument as following: >>> input(prompt="hello") Traceback (most recent call last): File "<pyshell#52>", line 1, in -toplevel- input(prompt="hello")...
3
by: steve morin | last post by:
http://www.python.org/doc/2.4.1/lib/node110.html These methods are being deprecated. What are they being replaced with? Does anyone know? Steve
7
by: TeamHubbell | last post by:
Hello, I was wondering if anyone has some suggestions on how to deprecate C routines from a n already released API. I would like to be able to do this via the gcc compiler and be warn the end...
185
by: Martin Jørgensen | last post by:
Hi, Consider: ------------ char stringinput ..bla. bla. bla. do {
1
by: psreddy71 | last post by:
i am trying to solve deprecation warning problem from past days.can any body help me please ? i am getting deprecation warning at method .can any body compile this program under jdk1.5 and...
1
by: Gennaro Prota | last post by:
James Kanze wrote: I see. You imply that, in theory, it couldn't be canceled? Or that it would require some long workflow? Yes, I know the etymology (BTW, terms of direct Latin derivation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.