binding

Searching for sequence of bits in an integer in Python

Searching for sequence of bits in an integer in Python Question: I have two integers, lets call them haystack and needle. I need to check that, if the binary representation of needle occurred in haystack [and OPTIONALLY find the position of the first occurrence] Example haystack = 0b10101111010110010101010101110 needle = 0b1011001 # occurred in position …

Total answers: 2

Binding or protocol for tkinter exit on Mac

Binding or protocol for tkinter exit on Mac Question: My tkinter application, which usually runs on a Mac, needs to save some settings as it exits. If the application is exited by clicking the close box of the window, the following works great: root.protocol("WM_DELETE_WINDOW", saveAndQuit) however, it is more natural to exit on a Mac …

Total answers: 2

Python id of function of instance is inconsistent

Python id of function of instance is inconsistent Question: Please consider the following class A(object): def foo(self): pass a = A() # accessing a’s foo seems consistent init1 = a.foo init2 = a.foo assert init1 == init2 assert id(a.foo) == id(a.foo) # Or is it? foos= [a.foo for i in range(10)] ids = [id(foo) for …

Total answers: 3

tkinter: binding mousewheel to scrollbar

tkinter: binding mousewheel to scrollbar Question: I have this scroll-able frame (frame inside canvas actually). import Tkinter as tk class Scrollbarframe(): def __init__(self, parent,xsize,ysize,xcod,ycod): def ScrollAll(event): canvas1.configure(scrollregion=canvas1.bbox(“all”),width=xsize,height=ysize,bg=’white’) self.parent=parent self.frame1=tk.Frame(parent,bg=’white’) self.frame1.place(x=xcod,y=ycod) canvas1=tk.Canvas(self.frame1) self.frame2=tk.Frame(canvas1,bg=’white’,relief=’groove’,bd=1,width=1230,height=430) scrollbar1=tk.Scrollbar(self.frame1,orient=”vertical”,command=canvas1.yview) canvas1.configure(yscrollcommand=scrollbar1.set) scrollbar1.pack(side=”right”,fill=”y”) canvas1.pack(side=”left”) canvas1.create_window((0,0),window=self.frame2,anchor=’nw’) self.frame2.bind(“<Configure>”,ScrollAll) I would like to bind mouse wheel to the scrollbar so that user can scroll down the …

Total answers: 7

python bindings, how does it work?

python bindings, how does it work? Question: I am exploring python. I curious about python bindings. Could anybody explain, how it is possible that you can have access to C libraries from Python. Asked By: ashim || Source Answers: Answer is simple, python (CPython) interpreter is written in C and it can call other C …

Total answers: 2

Calling Haskell functions from Python

Calling Haskell functions from Python Question: I want to use some Haskell libraries (e.g. Darcs, Pandoc) from Python, but it seems there’s no direct foreign function interface to Haskell in Python. Is there any way to do that? Asked By: minhee || Source Answers: Provided you can get your Python code to call C, you …

Total answers: 6

List comprehension rebinds names even after scope of comprehension. Is this right?

List comprehension rebinds names even after scope of comprehension. Is this right? Question: Comprehensions are having some unexpected interactions with scoping. Is this the expected behavior? I’ve got a method: def leave_room(self, uid): u = self.user_by_id(uid) r = self.rooms[u.rid] other_uids = [ouid for ouid in r.users_by_id.keys() if ouid != u.uid] other_us = [self.user_by_id(uid) for uid …

Total answers: 6

Local functions in Python

Local functions in Python Question: In the following Python code, I get an UnboundLocalError. As I understand it, local functions share the local variables of the containing function, but this hardly seems to be the case here. I recognise that a is an immutable value in this context, but that should not be a problem. …

Total answers: 3