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
12
votes
2 answers

Python attributeError on __del__

I have a python class object and I want to assign the value of one class variable class Groupclass(Workerclass): """worker class""" count = 0 def __init__(self): """initialize time""" Groupclass.count += 1 …
Shih-Min Lee
  • 9,350
  • 7
  • 37
  • 67
9
votes
4 answers

Python - Delete (remove from memory) a variable from inside a function?

I have to load this massive object A (that can weight almsot 10go) that I need to pass to a function, that extracts from it a parameter B to further exert some heavy computations on it. A = load(file) def function(A): B = transorm(A) …
Dominique Makowski
  • 1,511
  • 1
  • 13
  • 30
9
votes
1 answer

How does del operator work in list in python?

I have read the python docs for list and how the del operators works, but I need explanation for the following behavior In this case, c and l points to the same object(list), so doing changes on one affects the other, but deleting one does not…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
8
votes
1 answer

Python del on classes

Lets assume we have a class in python: class A(object): def __del__(self): print "Del!" __del__ is called upon deleting/garbage collection of any A instance. Is is possible to do the same for a class? I would like to have some method…
pajton
  • 15,828
  • 8
  • 54
  • 65
8
votes
1 answer

Delete Temp Files in Laravel Mix

I'd like to remove temp build files during or after my laravel-mix build. Here's some code that I have currently, but del isn't working: const mix = require('laravel-mix'); const del = require('del'); // compile sass into temp css…
brad
  • 1,407
  • 19
  • 33
8
votes
2 answers

Is overriding __del__() the best choice here?

I am trying to figure out the best way to remove something, preferably without having to write in a lot of code. In my project I am simulating chemical compounds - I have Element instances bonded to other Element instances via a Bond instance. In…
Dan Oberlam
  • 2,435
  • 9
  • 36
  • 54
7
votes
4 answers

How to delete and shift values in a pandas df column

I have a pandas df that I want to manipulate so it's ordered. So for the df below, I'd like ['I'] to be ordered. So values would read 10-50. I have 2 options to do this; 1) Try to delete values in Column ['G'] or ['H']. So if values are == X then…
user9410826
7
votes
6 answers

Pythonic way to delete variable from self if it exists in a list

I have a list of strings ['foo1', 'foo2', ...] that represent variables that I want to delete from self if they are part of self. What is a Pythonic and compact way to do this? My first attempt is if hasattr(self, 'foo1'): del self.foo1 if…
RoachLord
  • 993
  • 1
  • 14
  • 28
7
votes
2 answers

python del not freeing all the memory

In my python program, I use pandas to read a csv file and store in memory: data = pandas.read_csv('data.csv') Before running the above command I check the free memory with free -m and the output is 1704. After running the above command the output…
user2725109
  • 2,286
  • 4
  • 27
  • 46
7
votes
2 answers

__del__ method being called in python when it is not expected

I am new to python and have been working through the examples in Swaroop CH's "A Byte of Python". I am seeing some behavior with the __del__ method that is puzzling me. Basically, if I run the following script (in Python 2.6.2) class Person4: …
ELee
  • 83
  • 1
  • 5
6
votes
2 answers

Unable to reference an imported module in __del__()

I'm using an object's __del__() to unsubscribe it from an event (using an event scheme similar to this): import my_enviroment class MyClass(): def __del__(self): my_environment.events.my_event -= self.event_handler_func Oddly I received…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
6
votes
1 answer

Proper finalization in Python

I have a bunch of instances, each having a unique tempfile for its use (save data from memory to disk and retrieve them later). I want to be sure that at the end of the day, all these files are removed. However, I want to leave a room for a…
6
votes
4 answers

Why does values of both variable change in Python?

I have a small piece of code and a very big doubt. s=['a','+','b'] s1=s print s1 del s1[1] print s1 print s The output is value of s1 ['a', '+', 'b'] value of s1 ['a', 'b'] value of s ['a', 'b'] Why is the value of variable 's' changing when I am…
mea
  • 121
  • 1
  • 2
  • 8
5
votes
3 answers

Calling 'del' on a list

class ToBeDeleted: def __init__(self, value): self.value = val # Whatever... def __del__(self): print self.value l = [ToBeDeleted(i) for i in range(3)] del l This prints 2, 1, 0. Now, is the order of the deleted…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
5
votes
8 answers

Python: Delete all list indices meeting a certain condition

to get right down to it, I'm trying to iterate through a list of coordinate pairs in python and delete all cases where one of the coordinates is negative. For example: in the array: map = [[-1, 2], [5, -3], [2, 3], [1, -1], [7, 1]] I want to…
Will
  • 53
  • 1
  • 3
1
2
3
20 21