-1

So I have A code that's running through CMD like so : Python script.py textfile.csv

Inside the script i have something like this :

After its reading the .csv file I'm trying to delete the file from the location , Is that possible to write a code to delete a file that's attached to the Script ? or do i need to link it?

The code :

    rows = csv.reader(f,delimiter=",",lineterminator="\n")
apple = {}
        user['apple'] = row[0]
        user['name'] = row[1]
        users.append(apple)
pault
  • 41,343
  • 15
  • 107
  • 149
Teeext
  • 5
  • 2
  • 3
    Possible duplicate of [How to delete a CSV file in Python](https://stackoverflow.com/questions/29579448/how-to-delete-a-csv-file-in-python) – Shai Léger Aug 07 '19 at 01:53

2 Answers2

0

You can use the os module and os.remove().

import os
os.remove("demofile.txt") 

You can just put the location of the csv file inside the os.remove() function

jsl
  • 1
0

os.remove("textfile.csv") should work.