1
 podList = str(raw_input('Enter pipe separated list of PODS : ')).upper().strip()
   #pipelst = str(raw_input('Enter pipe separated list  : ')).split('|')
    filepath = '/fsnadmin/SAAS_SUPPORT/pod_data_from_FM.txt'
    for lns in open(filepath):
        split_pipe = lns.split(':', 1)
        if split_pipe[0] in podList:
            #print split_pipe[0], ' details : ', split_pipe[1]
            podList.remove(split_pipe[0])
    for lns in podList : print lns,' is wrong input'
    items = podList.split("|")
    count = len(items)
    print  'Total Distint Pod Count : ',  count

When I run the above code get below error:

Enter pipe separated list of PODS : EDL|ACP|ANP|GGG

Traceback (most recent call last):

File "./main_menu.py", line 966, in

pPODName()   File "./main_menu.py", line 905, in pPODName

podList.remove(split_pipe[0])

AttributeError: 'str' object has no attribute 'remove'

Please assist me for the workaround here.

Himanshu
  • 49
  • 2
  • 8
  • 2
    Well, `str` has no attribute `remove`. See [documentation for str objects](https://docs.python.org/2/library/stdtypes.html#string-methods). – Peter Wood Apr 22 '15 at 13:47
  • What is your desired outcome? You're trying to use remove on a string. – Daniel Timberlake Apr 22 '15 at 13:47
  • My Input : EDL|ACP|AAA|GGG My Desied o/p is GGG is wrong input Total Distint Pod Count : 4 becuse other entries are present in .txt file which I am passing in python code and GGG is not present in .txt file but with replacing method I am getting like below : E is wrong input D is wrong input L is wrong input | is wrong input A is wrong input C is wrong input P is wrong input | is wrong input A is wrong input A is wrong input A is wrong input | is wrong input G is wrong input G is wrong input G is wrong input – Himanshu Apr 22 '15 at 14:21

3 Answers3

0

In Python a String hasnt the method remove.

podList.remove(split_pipe[0])

If you want to remove a substring belonging to a string you have to do this

podList = podList.replace(split_pipe[0], "")
lapinkoira
  • 8,320
  • 9
  • 51
  • 94
  • My Input : EDL|ACP|AAA|GGG My Desied o/p is GGG is wrong input Total Distint Pod Count : 4 becuse other entries are present in .txt file which I am passing in python code and GGG is not present in .txt file but with replacing method I am getting like below : E is wrong input D is wrong input L is wrong input | is wrong input A is wrong input C is wrong input P is wrong input | is wrong input A is wrong input A is wrong input A is wrong input | is wrong input G is wrong input G is wrong input G is wrong input podList.replace(split_pipe[0], "") – Himanshu Apr 22 '15 at 14:30
  • What do you have in split_pipe[0]? – lapinkoira Apr 22 '15 at 14:36
  • I am calling a file here : podList = str(raw_input('Enter pipe separated list of PODS : ')).strip('|') #pipelst = str(raw_input('Enter pipe separated list : ')).split('|') filepath = '/fsnadmin/SAAS_SUPPORT/pod_data_from_FM.txt' for lns in open(filepath): split_pipe = lns.split(':', 1) if split_pipe[0] in podList: #print split_pipe[0], ' details : ', split_pipe[1] podList.remove(split_pipe[0]) for lns in podList : print lns,' is wrong input' – Himanshu Apr 22 '15 at 14:47
  • Sorry I cant follow your input/output – lapinkoira Apr 22 '15 at 15:11
0

Python strings are immutable. You can create a new string with characters replaced by other characters:

>>> s = 'hello'
>>> s.replace('e', 'a')
'hallo'
Peter Wood
  • 23,859
  • 5
  • 60
  • 99
0

In Python str does not have a remove method.

What you probably want is a list of str in which each str is one POD. Then you can delete the strings from the list. The idea is already there in your example code, but commented out.

Since I don't know what the lines in your file look like, this is untested code:

podList = str(raw_input('Enter pipe separated list of PODS : ')).upper().strip()
pipelst = podList.split('|')
filepath = '/fsnadmin/SAAS_SUPPORT/pod_data_from_FM.txt'
with open(filepath) as f:
    for lns in f:
        split_pipe = lns.split(':', 1)
        if split_pipe[0] in pipelst:
            #print split_pipe[0], ' details : ', split_pipe[1]
            index = pipelst.index(split_pipe[0])
            del pipelst[index]

for lns in pipelst:
    print lns,' is wrong input'

count = len(pipelst)
print  'Total Distint Pod Count : ',  count
Community
  • 1
  • 1
alsuna
  • 73
  • 6