python

Accessing python variables in a list

In the following code below, how to retrieve the value of id,Id has multiple values in it.How to access the values of id and update it to result1 def parse_results (): try: xml = minidom.parseString(new_results) for xmlchild in xmldoc.childNodes[0].childNodes : result1 = {} result1.update ({'f...

python datetime.time operation

t1 = datetime.time(12, 10, 0, tzinfo=GMT1()) # 12:10 t2 = datetime.time(13, 13, 0, tzinfo=GMT1()) #13:13 t3 = datetime.time(23, 55, 0, tzinfo=GMT1()) #23:55 t4 = datetime.time(01, 10, 0, tzinfo=GMT1()) #01:10 I need the minute interval between between two times. For instance a non working one: def minute_interval(start,end): re...

Accessing child nodein an xml in python

How to retrieve the value of type in the below XML <info><category>Flip</category><info>2</info><type>Tree</type></info> ...

Returning the lowest index for the first non whitespace character in a string in Python

What's the shortest way to do this in Python? string = " xyz" must return index = 3 ...

Installing a python module on windows

Hi, so i tried asking this question before but i seemed to word it wrongly I am trying to install a module called Swish-E 0.5 and for some reason im getting an error when running the command python setup.py install i keep getting this error no matter what module i try to install. Ive tried installing other modules to see if the prob...

pycurl and lot of callback functions

I have big URL list, which I have to download in parallel and check one of headers that is returned with each response. I can use CurlMulti for parallelization. I can use /dev/null as fb, because I am not interested in body, only headers. But how can I check each header? To receive header, I must set HEADERFUNCTION callback. I get tha...

Getting pubsubhubbub hub working

I have followed the instructions found at code.google.com/p/pubsubhubbub/wiki/DeveloperGettingStartedGuide , however when I start the hub I get some warnings (http://pastie.org/853356), and when I point my browser to localhost:8080 I get a nasty exceptions.AttributeError thrown in my face ( http://pastie.org/853357 ) in browser & console...

Python modules matching a pattern

I'd like to run doctests for a set of modules (glob: invenio.webtag*) from a single module, but I'll need a way to import all these (and only these) modules and run doctest.testmod() on all of them. Any ideas? Edit: The solution: import doctest import glob import os import pkgutil pkgpath = pkgutil.extend_path([], 'invenio')[0] for mod...

Python AST processing

I have a Python AST [as returned by ast.parse()]. I know this is an AST of a class method. How do I find all calls to other methods of the same class? Basically, I want to collect something like: ['foo', 'bar'] for a code snippet like: def baz(self): # this is a class method '''baz docstring''' self.foo() + self.bar() I ...

Python's AppKit and ObjectiveC Delegates

AppKit allows Python programs on a Mac to use ObjectiveC classes. I am not very familiar with ObjectiveC, but I want to access the NSSound class using AppKit in order to create an audio player. My player should perform some action, such as loading the next item from the playlist, when the current audio finishes playing. There is a metho...

Django Admin filter on Foreign Key property

I want to add a filter in an admin changelist by a property of a foreign key, e.g. class Address(model.Models): street = models.CharField(max_length=25) city = models.CharField(max_length=25) country = models.CharField(max_length=25) class Customer(models.Model): name = models.CharField(max_length=25) ...

Introspection of win32com module / pythoncom module

Hi, what is the best way to see what all functions that can be performed using pythoncom module? Specifically, i was working with the win32com module to operate upon excel files. I was not able to find introspection for it as we do for the rest of the modules. Can anyone please suggest how can i retrieve this information? ...

Make distutils look for numpy header files in the correct place

In my installation, numpy's arrayobject.h is located at …/site-packages/numpy/core/include/numpy/arrayobject.h. I wrote a trivial Cython script that uses numpy: cimport numpy as np def say_hello_to(name): print("Hello %s!" % name) I also have the following distutils setup.py (copied from the Cython user guide): from distutils.c...

PyQt QTreeWidget problem with custom delegate

Hi, All! I'm trying to write simple property editor. I have automatically generated pyqt class (WorkZone in the code below), and I need to view/edit some of it's properties with PropertyEditor, with the delegate PropertyEditorDelegate, that uses custom editors ColorEditor, LineEditor, etc. Main idea is that WorkZone knows what propertie...

Can hotshot be used in multiple threads?

I have a long-running multithreaded program, and I'd like to occasionally like to call a function with Profile.runcall and dump the data to a file. The hotshot documentation states: Note: The hotshot profiler does not yet work well with threads. It is useful to use an unthreaded script to run the profiler over the code you’re interested...

Converting date/time in YYYYMMDD/HHMMSS format to Python datetime

I have a date in YYYYMMDD format and a time in HHMMSS format as strings in the 4th and 5th elements in a list. I.E.: data[4] = '20100304' data[5] = '082835' I am creating an instance of datetime (in a field named generates) like this: generatedtime = datetime.datetime(int(data[4][:4]),int(data[4][4:6]),int(data[4][6:]),int(data[5][:...

Determine current Mac Safari web page using Python

Is there a way to determine programmatically, using Python, which web page is currently active in Safari? ...

How to identify what function call raise an exception in Python?

i need to identify who raise an exception to handle better str error, is there a way ? look at my example: try: os.mkdir('/valid_created_dir') os.listdir('/invalid_path') except OSError, msg: # here i want i way to identify who raise the exception if is_mkdir_who_raise_an_exception: do some things if is_listdir_w...

Simple implementation of N-Gram, tf-idf and Cosine similarity in Python

I need to compare documents stored in a DB and come up with a similarity score between 0 and 1. The method I need to use has to be very simple. Implementing a vanilla version of n-grams (where it possible to define how many grams to use), along with a simple implementation of tf-idf and Cosine similarity. Is there any program that can...

Django doctests in views.py

The Django documentation on tests states: For a given Django application, the test runner looks for doctests in two places: The models.py file. You can define module-level doctests and/or a doctest for individual models. It's common practice to put application-level doctests in the module docstring and model-level doctests in...