python-2.7

how do I dynamically resize a pixbuf cellrenderer in a treeview?

末鹿安然 提交于 2021-02-20 19:33:22
问题 I'm using a Gtk3 TreeView that looks like above. The model is a Gtk.TreeStore Gtk.TreeStore(str, GdkPixbuf.Pixbuf) For the picture I could add to the model the correctly sized images via: pixbuf.scale_simple(48,48,GdkPixbuf.InterpType.BILINEAR) However I'm also using the model elsewhere showing the pixbufs in a different manner and the pixbufs can also be a variety of sizes. What I would like to do is force the size of the picture displayed at run-time. The question is - how do I do that? I

Python Datetime: All Items From Yesterday

夙愿已清 提交于 2021-02-20 19:26:26
问题 In Python, if I wanted to do a check for all items from yesterday would I do something like: from datetime import datetime, timedelta if datetime.datetime.today() - timedelta(days=2) < item_to_check < datetime.datetime.today(): Would this pull all items from yesterday and is this the best way to do it? 回答1: I'd try something easier ;-) from datetime import date, timedelta yesterday = date.today() - timedelta(days=1) if item_to_check.date() == yesterday: # yup! Note that your: item_to_check <

Stop SIGALRM when function returns

杀马特。学长 韩版系。学妹 提交于 2021-02-20 13:37:51
问题 I have a problem that I can't seem to solve by myself. I'm writing a small python script and I would like to know why my signal.alarm still works after the function it's located in returned. Here is the code: class AlarmException(Exception): pass def alarmHandler(signum, frame): raise AlarmException def startGame(): import signal signal.signal(signal.SIGALRM, alarmHandler) signal.alarm(5) try: # some code... return 1 except AlarmException: # some code... return -1 def main(): printHeader()

Stop SIGALRM when function returns

≯℡__Kan透↙ 提交于 2021-02-20 13:36:10
问题 I have a problem that I can't seem to solve by myself. I'm writing a small python script and I would like to know why my signal.alarm still works after the function it's located in returned. Here is the code: class AlarmException(Exception): pass def alarmHandler(signum, frame): raise AlarmException def startGame(): import signal signal.signal(signal.SIGALRM, alarmHandler) signal.alarm(5) try: # some code... return 1 except AlarmException: # some code... return -1 def main(): printHeader()

Handling empty case with tuple filtering and unpacking

最后都变了- 提交于 2021-02-20 09:33:23
问题 I have a situation with some parallel lists that need to be filtered based on the values in one of the lists. Sometimes I write something like this to filter them: lista = [1, 2, 3] listb = [7, 8, 9] filtered_a, filtered_b = zip(*[(a, b) for (a, b) in zip(lista, listb) if a < 3]) This gives filtered_a == (1, 2) and filtered_b == (7, 8) However, changing the final condition from a < 3 to a < 0 causes an exception to be raised: Traceback (most recent call last): ... ValueError: need more than 0

Handling empty case with tuple filtering and unpacking

大兔子大兔子 提交于 2021-02-20 09:32:28
问题 I have a situation with some parallel lists that need to be filtered based on the values in one of the lists. Sometimes I write something like this to filter them: lista = [1, 2, 3] listb = [7, 8, 9] filtered_a, filtered_b = zip(*[(a, b) for (a, b) in zip(lista, listb) if a < 3]) This gives filtered_a == (1, 2) and filtered_b == (7, 8) However, changing the final condition from a < 3 to a < 0 causes an exception to be raised: Traceback (most recent call last): ... ValueError: need more than 0

Handling empty case with tuple filtering and unpacking

浪尽此生 提交于 2021-02-20 09:31:43
问题 I have a situation with some parallel lists that need to be filtered based on the values in one of the lists. Sometimes I write something like this to filter them: lista = [1, 2, 3] listb = [7, 8, 9] filtered_a, filtered_b = zip(*[(a, b) for (a, b) in zip(lista, listb) if a < 3]) This gives filtered_a == (1, 2) and filtered_b == (7, 8) However, changing the final condition from a < 3 to a < 0 causes an exception to be raised: Traceback (most recent call last): ... ValueError: need more than 0

iterate through pcap file packet for packet using python/scapy

断了今生、忘了曾经 提交于 2021-02-20 09:08:15
问题 I want to iterate through a pcap file packet for packet using python/scapy. The file has multiple protocols. Current the iteration is protocol-specific, so the iteration makes a "jump" if the next packet is from another protocol. I don't know why it goes like this at the moment. I want packet for packet, no matter what protocol. little example: data = 'new.pcap' zz = rdpcap(data) sessions = zz.sessions() for session in sessions: for packet in sessions[session]: eth_src = packet[Ether].src eth

iterate through pcap file packet for packet using python/scapy

不羁岁月 提交于 2021-02-20 09:04:33
问题 I want to iterate through a pcap file packet for packet using python/scapy. The file has multiple protocols. Current the iteration is protocol-specific, so the iteration makes a "jump" if the next packet is from another protocol. I don't know why it goes like this at the moment. I want packet for packet, no matter what protocol. little example: data = 'new.pcap' zz = rdpcap(data) sessions = zz.sessions() for session in sessions: for packet in sessions[session]: eth_src = packet[Ether].src eth

iterate through pcap file packet for packet using python/scapy

被刻印的时光 ゝ 提交于 2021-02-20 09:03:29
问题 I want to iterate through a pcap file packet for packet using python/scapy. The file has multiple protocols. Current the iteration is protocol-specific, so the iteration makes a "jump" if the next packet is from another protocol. I don't know why it goes like this at the moment. I want packet for packet, no matter what protocol. little example: data = 'new.pcap' zz = rdpcap(data) sessions = zz.sessions() for session in sessions: for packet in sessions[session]: eth_src = packet[Ether].src eth