Questions tagged [del]

Short for delete, this is a keyword/command/function that deletes objects (Python, et al.) or files (Windows/DOS cmd / batch).

Short for delete, this is a command/keyword that deletes... - files in Windows cmd (command prompt) / batch. Another equivalent to this is the erase command, also in cmd / batch. - a keyword/function name in Python and various languages and software libraries, that deletes objects - also often used in other places to denote a deletion operation - a key on the keyboard

313 questions
5
votes
1 answer

del *a: can't use starred expression here

The grammar for del statement: del_stmt: 'del' (expr|star_expr) (',' (expr|star_expr))* [','] It allows deleting starred expressions. So, the parser doesn't mind this, even though it would be causing SyntaxError: can't use starred expression here…
wim
  • 338,267
  • 99
  • 616
  • 750
5
votes
4 answers

how to achieve - file write open on __del__?

I m trying to do a some activity on class obj destruction. How do I achieve file open in __del__ function? (I m using Python 3.4) class iam(object): def __init__(self): print("I m born") def __del__(self): f =…
Kaymatrix
  • 615
  • 2
  • 8
  • 16
4
votes
3 answers

Remove parent elements with certain key-value pairs using JQ

I need to remove elements from a json file based on certain key values. Here is the file I am trying to process. { "element1": "Test Element 1", "element2": { "tags": "internal", "data": { "data1": "Test Data 1", "data2":…
ccrichter
  • 43
  • 4
4
votes
3 answers

Python: Removing a single element from a nested list

I'm having trouble figuring out how to remove something from within a nested list. For example, how would I remove 'x' from the below list? lst = [['x',6,5,4],[4,5,6]] I tried del lst[0][0], but I get the following result: TypeError: 'str'…
Emily
  • 41
  • 1
  • 1
  • 2
4
votes
1 answer

numpy delete shape of passed value error

I'm trying to do a very simple delete on a numpy dataset using dataset = pd.read_csv('putty.log', sep='\s+', header = 0) badData = np.argwhere(np.isnan(dataset.loc[:,'Temp'])) np.delete(dataset, badData, 0) but I get an error saying ValueError:…
summershoe
  • 43
  • 5
4
votes
2 answers

del statement not working for list

I have a long list where each element is a list of length 2. The first element of each is a list is a string and the second element of each list is an integer corresponding to the string. I want to loop through the long "parent" list and delete any…
Alex Zhang
  • 63
  • 1
  • 6
4
votes
1 answer

Python slice with del statement

Why does this: del a[:] delete all entries in the list a? As far as I understand, a[:] returns a copy of a. So shouldn't del a[:] delete the copy of a?
spiderface
  • 1,025
  • 2
  • 11
  • 16
4
votes
1 answer

Will del a[0] in Python copy the whole list?

I am trying to use a simple list with del a[0] to mimic the deque.popleft(). Just want to understand how does del in Python work. For example: a = [0,1,2,3,4,5] a is in a continuous space in memory. After I call del a[0], will Python allocate new…
Xing Shi
  • 2,152
  • 3
  • 21
  • 32
4
votes
3 answers

How can I delete all zeros except for x of them in every run of consecutive zeros within a list?

For every run of x or more consecutive zeros in a list in Python, I would like to del all zeros in the run except for x of them. If x = 0, then delete all zeros. I was thinking of a Python function that took a list, L, and a number, x, as…
b_ron_
  • 197
  • 1
  • 1
  • 10
3
votes
2 answers

Delete field from standard Django model

NOTE: this was asked before AbstractUser existed, which is probably what you'd want to use these days. Basically I would like to delete the default email field from the default Django User class... class MyUser(User): field =…
Mark
  • 18,730
  • 7
  • 107
  • 130
3
votes
3 answers

How to debug uncalled __del__()

I use __del__() to write a warning log in case the object gets deleted while in a wrong internal state (please no wrath about it). I tried to test it but although I use del my_object in the test, the __del__() doesn't seem to be called. __del__()'s…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
3
votes
0 answers

Why does deleting columns or parts of a DataFrame increase memory usage, and how to ensure garbage collection on unused slices of DataFrame

When dealing with large DataFrames, you need to be careful with memory usage (for example you might want to download large data in chunks, process the chunks, and from then on delete all the unnecessary parts from memory). I can't find any resources…
Marses
  • 1,464
  • 3
  • 23
  • 40
3
votes
2 answers

How to delete object assigned to variable?

I have the following code: class Node: def __init__(self, item): self.item = item node1 = Node(12) cur = node1 Is it possible to delete node1using cur? I tried del cur but it doesn't give the desired outcome cur now no longer exists but…
Tobias Wilfert
  • 919
  • 3
  • 14
  • 26
3
votes
1 answer

Does a del statement open up memory?

I wrote a python script that backs up my files while I'm sleeping at night. The program is designed to run whenever the computer is on and to automatically shut down the computer after the backups are done. My code looks like this: from datetime…
Jeff Moorhead
  • 181
  • 1
  • 15
3
votes
1 answer

"Wiping the slate clean" in python

This should be pretty basic, but I can't find anything on it, so ... In python, if I want to just clear out my whole session and start all over without shutting down and starting over, how do I do it? I want to delete all objects, class defs,…
bob.sacamento
  • 6,283
  • 10
  • 56
  • 115
1 2
3
20 21