del

How to detect when the delete key is pressed on the keyboard?

夙愿已清 提交于 2019-12-08 11:42:30
问题 I want that when the Del key is pressed a certain function is called. How can I achieve that using getch() if possible or otherwise some nested getch() calls? 回答1: The function _getch() returns an "escaped" value for cursor and page control keys. For the keypad and the function keys, that is 0 followed by the key code, for other keys it is 224 followed by the key code. #include <stdio.h> #include <conio.h> #define ESC 27 #define ESC1 0 #define ESC2 224 int main() { int d=-1, e=-1; printf(

Python: Delete all list indices meeting a certain condition

一笑奈何 提交于 2019-12-07 07:06:59
问题 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 remove all the pairs in which either coordinate is < 0, leaving: map = [[2, 3], [7, 1]] My problem is that python lists cannot have any gaps, so if I loop like this: i = 0 for pair in map: for coord in pair: if coord < 0: del map[i] i += 1 All the indices

Calling 'del' on a list

假如想象 提交于 2019-12-07 04:27:53
问题 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 elements defined somewhere in specification or is it implementation-specific? (or maybe I don't understand the underlying mechanics) Could the output, for example, be 0, 1, 2 ? I realize the 2, 1, 0 order is probably done to avoid the memory reallocations for the elements while

python del not freeing all the memory

时光怂恿深爱的人放手 提交于 2019-12-05 22:22:10
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 ipython doesn't free up that memory. Thanks. "Exiting ipython doesn't free up that memory" means that you

Python: Delete all list indices meeting a certain condition

无人久伴 提交于 2019-12-05 15:50:52
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 remove all the pairs in which either coordinate is < 0, leaving: map = [[2, 3], [7, 1]] My problem is that python lists cannot have any gaps, so if I loop like this: i = 0 for pair in map: for coord in pair: if coord < 0: del map[i] i += 1 All the indices shift when the element is deleted, messing up the iteration and causing all sorts of problems. I've

Redis/Jedis - Delete by pattern?

醉酒当歌 提交于 2019-12-04 10:32:29
问题 Normally, I get the key set then use a look to delete each key/value pair. Is it possible to just delete all keys via pattern? ie: Del sample_pattern:* 回答1: It seems, for Jedis, to "delete by pattern" is basically getting all the keys of a specific pattern then loop through it. ie Set<String> keys = jedis.keys(pattern); for (String key : keys) { jedis.del(key); } 回答2: KEYS is not recommended to use due to its inefficiencies when used in production. Please see https://redis.io/commands/keys.

`del` on a package has some kind of memory

懵懂的女人 提交于 2019-12-03 15:31:28
问题 del seems to have some memory which puzzles me. See the following: In [1]: import math In [2]: math.cos(0) Out[2]: 1.0 In [3]: del math.cos In [4]: math.cos(0) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-9cdcc157d079> in <module>() ----> 1 math.cos(0) AttributeError: module 'math' has no attribute 'cos' Fine. Let's see what happens if we delete the whole math package: In [5]: del math In [6]:

`del` on a package has some kind of memory

邮差的信 提交于 2019-12-03 04:11:53
del seems to have some memory which puzzles me. See the following: In [1]: import math In [2]: math.cos(0) Out[2]: 1.0 In [3]: del math.cos In [4]: math.cos(0) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-9cdcc157d079> in <module>() ----> 1 math.cos(0) AttributeError: module 'math' has no attribute 'cos' Fine. Let's see what happens if we delete the whole math package: In [5]: del math In [6]: math.cos(0) --------------------------------------------------------------------------- NameError

Deleting a few list items inside of dictionary

和自甴很熟 提交于 2019-12-02 16:21:25
问题 Deleting a few list items inside of dictionary Hi, I have a dictionary: phone = {"first":100,"second":200,"third":[10,12,5,38],"fourth":400} Let' say I want to remove the 12 and 5 from from "phone" dictionary. Is there a way to do that using a "del" function? I know how to do this, using a .remove() phone["third"].remove(12) phone["third"].remove(5) but I was wondering if it is possible to do it using the del()? Thank you. EDIT: For all those replies concentrating on "del uses index, remove

how to achive - file write open on __del__?

允我心安 提交于 2019-12-02 08:53:32
问题 I m trying to do a some activity on class obj destruction. How do I achive 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 = open("memory_report.txt", "w") f.write("He gone safe") f.close() if __name__ == '__main__': i = iam() print("Script Ends. Now to GC clean memory") Output: I m born Script Ends. Now to GC clean memory Exception ignored in: <bound method iam.__del__ of <__main__.iam object at