In python, if I have a few functions that I would like to call based on an input, i can do this:
lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
That is I have a dictionary of function name mapped to the function, and call the function by a dictionary lookup.
How to do this in java?
...
DB Table:
id int(6)
message char(5)
I have to add a record (message) to the DB table. In case of duplicate message(this message already exists with different id) I want to delete (or inactivate somehow) the both of the messages and get their ID's in reply.
Is it possible to perform with only one query? Any performance tips ?.....
I know there is a simple solution to this but can't seem to find it at the moment.
Given a numpy array, I need to know if the array contains integers.
Checking the dtype per-se is not enough, as there are multiple int dtypes (int8, int16, int32, int64 ...).
...
In the project that I'm building, I'd like to have a method called when I paste some text into a specific text field. I can't seem to get this to work, but here's what I've tried
I implimented a custom class (based on NSObject) to be a delegate for my textfield, then gave it the method: textDidChange:
class textFieldDelegate(NSObject):...
I am using something similar to the following simplified script to parse snippets of python from a larger file:
import io
import tokenize
src = 'foo="bar"'
src = bytes(src.encode())
src = io.BytesIO(src)
src = list(tokenize.tokenize(src.readline))
for tok in src:
print(tok)
src = tokenize.untokenize(src)
Although the code is not...
Can somebody recommend a good python learning book, along the lines of "Learning Python", but a little more "quick", (more concise). Although I like "Learning" series from O'Reilly, with Python they've really taken their time.
Preferably something up to 300-400 pages ?
I'd be grateful for all your advices.
...
Hello.
easy_install python extension allows to install python eggs from console like:
easy_install py2app
But is it possible to access easy_install functionality inside a python script? I means, without calling os.system( "easy_install py2app" ) but instead importing easy_install as a python module and using it's native methods?
...
So im currently doing good with Python I think, but still have some issues that are getting to my nervs, for example the difference beetween the __method__, method and _method__ or something.
Until know I read severall explanation about their difference but the idea didnt get really clear to me. So what would be their difference? Is the...
I'm using boto to manage some EC2 instances. It provides an Instance class. I'd like to subclass it to meet my particular needs. Since boto provides a query interface to get your instances, I need something to convert between classes. This solution seems to work, but changing the class attribute seems dodgy. Is there a better way?
from ...
So right now i need to create and implement an extension of the Python logging module that will be used to log to our database. Basically we have several python applications(that all run in the background) that currently log to a random mishmash of text files. Which makes it almost impossible to find out if a certain application failed o...
This is a bit of a tricky question;
I'm working with mod_wsgi in python and want to make an output buffer that yields HTML on an ongoing basis (until the page is done loading).
Right now I have my script set up so that the Application() function creates a separate 'Page' thread for the page code, then immediately after, it runs a con...
Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it.
For example, given a list of all positive integers smaller than 100, determine subsets...
It seems cx_Oracle doesn't.
Any other suggestion for handling xml with Oracle and Python is appreciated.
Thanks.
...
How would one go about retrieving a network device's netmask (In Linux preferably, but if it's cross-platform then cool)? I know how in C on Linux but I can't find a way in Python -- minus ctypes perhaps. That or parsing ifconfig. Any other way?
ioctl(socknr, SIOCGIFNETMASK, &ifreq) // C version
...
This is for a script I'm working on. It's supposed to run an .exe file for the loop below. (By the way not sure if it's visible but for el in ('90','52.6223',...) is outside the loop and makes a nested loop with the rest) I'm not sure if the ordering is correct or what not. Also when the .exe file is ran, it spits some stuff out and I ne...
I need to pass exceptions across a thread boundary.
I'm using python embedded in a non thread safe app which has one thread safe call, post_event(callable), which calls callable from its main thread.
I am running a pygtk gui in a seperate thread, so when a button is clicked I post an event with post_event, and wait for it to finish bef...
The question: How do I create a python application that can connect and send packets over the internet to another computer running the same application? Is there any existing code/library I could use?
The background: I am pretty new to programming (HS senior). I've created a lot of simple things in python but I've recently decided to st...
There seem to be a few good pure Python SSH2 client implementations out there, but I haven't been able to find one for SSH1. Is there some specific reason for this other than lack of interest in such a project? I am fully aware of the many SSH1 vulnerabilities, but a pure Python SSH1 client implementation would still be very useful to th...
I was just bitten by the following scenario:
>>> -1 ** 2
-1
Now, digging through the Python docs, it's clear that this is intended behavior, but why? I don't work with any other languages with power as a builtin operator, but not having unary negation bind as tightly as possible seems dangerously counter-intuitive to me.
Is there a ...
If you raise a KeyboardInterrupt while trying to acquire a semaphore, the threads that also try to release the same semaphore object hang indefinitely.
Code:
import threading
import time
def worker(i, sema):
time.sleep(2)
print i, "finished"
sema.release()
sema = threading.BoundedSemaphore(value=5)
threads = []
for x in ...