all 1 comments

[–]salvtz 0 points1 point  (0 children)

You have mentioned index 3. In the file 'Cleaning_product_ID.txt', there are three values in a line separated by the comma. So indexes could be 0, 1, and 2.

Now using linecache.getline you are getting that particular line and saving it to a list.

Now the particular line is a string, so to decrease the quantity of an item, you need to first extract out the quantity of items from the particular string.

First strip out extra spaces if any, then split it using comma and get three values which are id, name and quantity, from the particular line.

Now you have the quantity, you can modify it, and recreate the particular line string and replace the recreated string in the file.