Raj
Raj

Reputation: 15

Importing data from notepad to python editor

I have created a list in microsoft notepad...i would like to know if it is possible to import that data to edit in my python editor?

i have used this code but im not sure why it is not working.

f = open("productlist.txt","r+")
d = f.readlines()
f.seek(0)
for i in d:
    if i != "Servers":
        f.write(i)
f.truncate()
f.close()

Upvotes: 1

Views: 510

Answers (1)

Max
Max

Reputation: 1363

The problem in your code is that you are taking the value of f.readlines() into the variable d. so, when you are iterating, you are not going through the file, instead, you are going through the first line of the file. Try doing d = f.readlines instead.

Upvotes: 2

Related Questions