Python Forum
Removal of items in .txt using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removal of items in .txt using python
#5
Thank you for all your advice and suggestions.
I tried again. It still doesnt work. I failed to remove the item by user input. This is my code-

animalslist = open ('C:\\Users\\defaultuser100000\\animals.txt')
items = animalslist.read()
nlist = [items]
out = str(input("Enter items to be removed"))
if out == items:
    nlist.remove(out)
animalslist = open('C:\\Users\\defaultuser100000\\animals.txt', 'w' )
animalslist.write(items)
animalslist.close()
nlist = [items.replace('\n',' ') for items in nlist]
print ("You now have")
print (nlist)
print("in your list")
Gribouillis write Sep-01-2022, 03:04 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
RE: Removal of items in .txt using python - by nanakochan - Sep-01-2022, 02:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get all items in SharePoint recycle bin by using sharepy library in Python? QuangHuynh 2 501 Apr-10-2024, 03:09 PM
Last Post: SandraYokum
  Removal of duplicates teebee891 1 1,879 Feb-01-2021, 12:06 PM
Last Post: jefsummers
  concatenating 2 items at a time in a python list K11 3 2,443 Oct-21-2020, 09:34 AM
Last Post: buran
  how to use items combobox in table name sqlite in python hampython 1 2,763 May-24-2020, 02:17 AM
Last Post: Larz60+
  Access list items in Python kamaleon 2 2,448 Dec-31-2019, 11:10 AM
Last Post: kamaleon
  Vertical Seam Removal scott14 0 2,008 Dec-27-2018, 03:03 AM
Last Post: scott14
  Python find the minimum length of string to differentiate dictionary items zydjohn 3 3,771 Mar-03-2018, 05:23 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020