python

Python ignores SIGINT in multithreaded programs - how to fix that?

Hello. I have Python 2.6 on MacOS X and a multithread operation. Following test code works fine and shuts down app on Ctrl-C: import threading, time, os, sys, signal def SigIntHandler( signum, frame ) : sys.exit( 0 ) signal.signal( signal.SIGINT, SigIntHandler ) class WorkThread( threading.Thread ) : def run( self ) : while Tru...

pygtk - update a gtk.liststore adds blank line

I'm having issue with adding extra lines to gtk.liststore. below is a snipped of the code. The glade definition can be found here. When I add a row the row seperators appear but where text should appear i keeps empty... please help define everything with glade interface designer. class GTKInterface(gobject.GObject): __gsignals__ = { ...

XML-RPC for an object broker

Hi, is there any good reason not to use XML-RPC for an object-broker server/client architecture? Maybe something like "no it's already outfashioned, there is X for that now". To give you more details: I want to build a framework which allows for standardized interaction and the exchange of results between many little tools (e. g. comma...

Language specific redirect

I want to create simple application that detects language(using Google API) of phrase and send it to corresponded search engine. For example, if search query is in Russian then I need to redirect it to Yandex.ru in all other cases to Google. That's how I do this: def get(self): ...

Python: Existing environment variables which need to be added again to execute

I'm trying to execute a command which runs a program that uses perl and python. Although both of them are already in PATH, I get this error 'perl' is not recognized as an internal or external command,operable program or batch file. 'python' is not recognized as an internal or external command,operable program or batch file. So I tried o...

Can an object's methods act on itself?

I'm not sure where to put some methods. Let's say I want to send an email. Which of the following options should I choose: email = new Email("title", "adress", "body"); email.send(); or email = new Email("title", "adress", "body"); Postman.send(email); Because how can an email send itself? And isn't it better to have a central ob...

Average the duplicated values from two paired lists in Python

Hello, in my code I obtain two different lists from different sources, but I know they are in the same order. The first list ("names") contains a list of keys strings, while the second ("result_values") is a series of floats. I need to make the pair unique, but I can't use a dictionary as only the last value inserted would be kept: inst...

efficient and complete input check for command line argument and option with python

I am developing cli with python version 2.4.3. i want to have the input exception check. The following is part of the code. With this code, I can type addcd -t 11 and if I type addcd -t str_not_int or addcd -s 3 I will catch the error of wrong type argument and wrong option. However, it is not sufficient. e.g. addcd s 11 or...

Context locals - how do they make local context variables global?

I was reading through the Flask doc - and came across this: ... For web applications it’s crucial to react to the data a client sent to the server. In Flask this information is provided by the global request object. If you have some experience with Python you might be wondering how that object can be global and how Flask ...

How to make Django admin site accessed by non-staff user?

Hello all, I would like to implement a 2nd admin site which provides a subset of feature of the primary admin site. That's possible and described in the Django docs However, I would like to limit access on the primary admin site. Some users can access the 2ndary site but not the primary site. In order to implement that feature, I woul...

python pty.fork - how does it work

http://docs.python.org/library/pty.html says - pty.fork()¶ Fork. Connect the child’s controlling terminal to a pseudo-terminal. Return value is (pid, fd). Note that the child gets pid 0, and the fd is invalid. The parent’s return value is the pid of the child, and fd is a file descriptor connected to the child’s controlling te...

First programming language to be taught - C or Python?

I know that there is a long debate regarding this matter. I also understand that this is strictly not a programming question. But I am asking here as this platform contains wide range of experts from different realms. When we got admitted in a Computer Science and Engineering(CSE) course in university, we were first taught C. The cours...

how to insert some string in the given string at given index in python

Hi, I am newbie in python and facing some problem , my problem is that how to insert some fields in already existing string for example: suppose i have read one line from any file which contains: line=Name Age Group Class Profession now i have to insert 3rd Field(Group) 3 times more in the same line before Class field...

Pytables vs. CSV for files that are not very large

Hello All, I recently came across Pytables and find it to be very cool. It is clear that they are superior to a csv format for very large data sets. I am running some simulations using python. The output is not so large, say 200 columns and 2000 rows. If someone has experience with both, can you suggest which format would be more conv...

Storing images in google datastore using Flask (Python)

Hi all, I am using flask on google app engine and am desperately looking for help to solve this. The GAE documentation talks of storing images in the datastore using the BlobProperty , which should be done something like this:- class MyPics(db.Model): name=db.StringProperty() pic=db.BlobProperty() Now the image should be ...

Intels Open Source uPNP SDK Has absolutely 0 documentation, why?

basically, here is the address... http://opentools.homeip.net/dev-tools-for-upnp they are the recommended dll's to use for upnp as they implement the standards better then microsofts upnp.dll - but the intels open source upnp tools have absolutely no documentation, not on their website, not on any other website. is there a reason for th...

Memory efficient int-int dict in Python

Hi, I need a memory efficient int-int dict in Python that would support the following operations in O(log n) time: d[k] = v # replace if present v = d[k] # None or a negative number if not present I need to hold ~250M pairs, so it really has to be tight. Do you happen to know a suitable implementation (Python 2.7)? EDIT Removed i...

Omitting fields on model "save" in django

I have a model, which has several "automatic" fields, like this: class Message(Model): subject = CharField(max_length = 200) message = TextField() created = DateTimeField() last_status_change = DateTimeField() status = CharField(max_length = 10) In my database (Postgres) I set up default values for created, last_st...

How does numpy zeros implement the parameter shape?

I want to implement a similar function, and want to accept an array or number that I pass to numpy.ones. Specifically, I want to do this: def halfs(shape): shape = numpy.concatenate([2], shape) return 0.5 * numpy.ones(shape) Example input-output pairs: # default In [5]: beta_jeffreys() Out[5]: array([-0.5, -0.5]) # scalar I...

Why are certain elements of this python list ignored?

Hi, I'm new to Python, and i'm struggling to understand the output of this simple program: list = os.listdir(os.getcwd()) print(list) print() for element in list: print(element) if 'txt' not in element: list.remove(element) Which gives me this output : ['examples_list.txt', 'generate_patterns.py', 'lehoczky_example_3.txt', '...