0

I am making a program with Python with subprocess and take with stdout specific part of the messages(specific word) and make it string. Then I am saving this word to a .txt. But the problem is that this word is surrounded with this chars ['word'] . When it is string I am trying to remove them, but the result is the same. If someone know why I have this chars or other way to remove them I will be greatfull.

def remove_char(string):
    string=list(string)
    string.remove('\'')
    string.remove('[')
    string.remove(']')
    #string.remove('F')
    return''.join(string)
#code

newID=str(ID)
remove_char(newID)
file=open('C:\\Users\\admin\\Desktop\\...\\...\\proba.txt', 'w')
file.write(newID)
file.close
  • But I am making the text list, then I am remove the chars and finally I am join it to string....Because the string is immutable – Ivan Kozaliev Jun 06 '18 at 08:05
  • 1
    `newID = remove_char(newID)` – Pycz Jun 06 '18 at 08:13
  • @IvanKozaliev if you know the string is immutable, why did you expect the string to change? In any event, you can achieve the above for any string using simply `s.translate(str.maketrans('', '', '\[]'))` – juanpa.arrivillaga Jun 06 '18 at 08:19

0 Answers0