del

python del not freeing all the memory

你离开我真会死。 提交于 2019-12-22 09:49:18
问题 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 is 729 . I run del(data) to free the memory used by data . Now when I check the free memory the output is 1093 which is much less than the original 1704 . Where did the rest go? How can I free it? I'm running all these in ipython and even exiting

In Python, how do I delete the Nth list item from a list of lists (column delete)?

元气小坏坏 提交于 2019-12-19 05:11:04
问题 In Python, how do I delete a "column" from a list of lists? Given: L = [ ["a","b","C","d"], [ 1, 2, 3, 4 ], ["w","x","y","z"] ] I would like to delete "column" 2 to get: L = [ ["a","b","d"], [ 1, 2, 4 ], ["w","x","z"] ] Is there a slice or del method that will do that? Something like: del L[:][2] 回答1: You could loop. for x in L: del x[2] If you're dealing with a lot of data, you can use a library that support sophisticated slicing like that. However, a simple list of lists doesn't slice. 回答2:

When is del useful in python?

你说的曾经没有我的故事 提交于 2019-12-16 20:02:09
问题 I can't really think of any reason why python needs the del keyword (and most languages seem to not have a similar keyword). For instance, rather than deleting a variable, one could just assign None to it. And when deleting from a dictionary, a del method could be added. Is there any reason to keep del in python, or is it a vestige of Python's pre-garbage collection days? 回答1: Firstly, you can del other things besides local variables del list_item[4] del dictionary["alpha"] Both of which

Python: Using del in for loops

浪子不回头ぞ 提交于 2019-12-13 07:11:43
问题 I was iterating through a list with a for loop, when I realized del seemed to not work. I assume this is because i is representing an object of the for loop and the del is simply deleting that object and not the reference. And yet, I was sure I had done something like this before and it worked. alist = [6,8,3,4,5] for i in alist: if i == 8: del i In my code its actually a list of strings, but the result is the same: even though the if conditional is satisfied, deleting i has no effect. Is

Why doesn't del do the same thing?

无人久伴 提交于 2019-12-13 00:49:58
问题 Why does the following code change both variables: >>> a = [] >>> b = a >>> a.append(9) >>> a [9] >>> b [9] >>> But the del statement does not achieve the same effect? >>> a = [] >>> b = a >>> del(a) >>> a Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined >>> b [] >>> 回答1: When you do: a = b What you're doing is assigning the label b to the same object that the label a is refering to. When you do: a.append(9) You're adding 9 to the list

Python del on classes

本秂侑毒 提交于 2019-12-12 10:43:56
问题 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 called when the class itself is garbage collected, which I assume is being done at the script exit. Thanks in advance for any pointers! Edit: Just as I have expected, everyone is trying to drive me away from using this technique (I would probably make such a

How does gulp treat the Promise of a then()?

ぃ、小莉子 提交于 2019-12-11 15:57:56
问题 I have a strange behaviour using gulp as build tool. I got the following code from another question, which is meant for cleaning up build files before another run: function clean() { var delResult = del(['build/**/*', 'dist/**/*']); return delResult.then(del(['build', 'dist'])); } gulp.task('clean', clean); Then I have my default task which includes the clean task in the rest of the build: gulp.task('default', gulp.series('clean', gulp.parallel('doJsStuff, doCssStuff', 'doEvenMoreStuff'));

Delete all but one file loop with bat script

心不动则不痛 提交于 2019-12-11 08:24:56
问题 I have a loop in a batch file to delete all but one file in a directory (Windows 7). But it hangs up because it still sends the commands to the screen, even though I'd thought I'd suppressed it. Here is the command I'm using: for %i in (*) do if not %i == UPDATE.BAT del /s %i >nul 2>&1 Tested my batch script, log shows it stops right at this command. Tested the command at the command line, outputs the "del /s file.ext >nul 2>&1" command to the prompt for each file in the directory, which is

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

陌路散爱 提交于 2019-12-10 16:35:15
问题 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 inputs. For example, let L = [7, 0, 12, 0, 0, 2, 0, 0, 0, 27, 10, 0, 0, 0, 0, 8] . If x = 0 , then return L = [7, 12, 2, 27, 10, 8] If x = 1 , then return L = [7, 0, 12, 0, 2, 0, 27, 10, 0, 8] If x = 2 , then return L = [7, 0, 12, 0, 0, 2, 0, 0, 27, 10, 0

sys.getrefcount continuation

无人久伴 提交于 2019-12-09 02:04:29
问题 link text I got the concept of reference count So when i do a "del astrd" ,reference count drops to zero and astrd gets collected by gc ? This is the sample codes.These codes I developed after my yesterday's question:link text one.py: def abc(): print "Hello" print "123" print '345' two.py: import one #reload(one) #def defg(): one.abc() three.py: import os,sys,gc from time import sleep import two #reload(two) #two.defg() sleep(20) directory = os.listdir('.') for filename in directory: if