Answers for "python delete"

38

python delete file

import os
import shutil

if os.path.exists("demofile.txt"):
  os.remove("demofile.txt") # one file at a time

os.rmdir("test_directory") # removes empty directory
shutil.rmtree("test_directory") # removes not empty directory and its content
Posted by: Guest on August-19-2020
2

how to delete in python

#x will be deleted
print("x\b")
Posted by: Guest on March-10-2021
5

remove item from list python

# removes item with given name in list
list = [15, 79, 709, "Back to your IDE"]
list.remove("Back to your IDE")

# removes last item in list
list.pop()

# pop() also works with an index..
list.pop(0)

# ...and returns also the "popped" item
item = list.pop()
Posted by: Guest on October-05-2020
0

delete function python

"""
Since foo is a global, you can delete it from the global definitions:
"""

def delete_func(func):
    del globals()[func.func_name]
Posted by: Guest on October-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language