python

C#, Pass Array As Function Parameters

In python the * allows me to pass a list as function parameters: def add(a,b): return a+b x = [1,2] add(*x) Can I replicate this behavior in C# with an array? Thanks. ...

How do I send/get a JSON Object with Django?

I know how to use the JQuery ajax feature to call the "url view" of Django. import simplejson as json def the_view(request): fruits = {'color':5, 'type': 22} jfruit = json.dump(fruits) return render_to_response( THE JSON OBJECT!!! ...how? ) ...

check what files are open in Python

I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is? ...

pygtk how to embed external application within my pygtk GUI

I'm desiging a pygtk GUI and want to embed an external application into it. Does anyone have any idea how this can be done? ...

Python-LDAP integration BABY

Hello all. I need to integrate Python with LDAP. I just need to choose the best way to make Python talk to LDAP. I understand there are many ways to do this, including using a prebuilt toolkit such as the AuthKit or writing a thing ourselves with LDAP modules and functions. What do you recommend? Thanks everyone, I love you ...

Postgis - How do i check the geometry type before i do an insert

i have a postgres database with millions of rows in it it has a column called geom which contains the boundary of a property. using a python script i am extracting the information from this table and re-inserting it into a new table. when i insert in the new table the script bugs out with the following: Traceback (most recent call las...

Python 3 Get HTTP page.

How can I get python to get the contents of an HTTP page? So far all I have is the request and I have imported http.client. ...

setuptools "at least one of these" dependency specification

In some cases, there are various modules which each implement a common API (in my case, the old pure-python elementtree, cElementTree, lxml.etree, and the built-in xml.etree). I can write the module using ElementTree to try each of these options, and take the first one that exists according to my own preference order -- but I can't find ...

Using 'super' when subclassing python class that is not derived from `object`(old-style?)

I'm playing with subclassing OptionParser from the std library module optparser. (Python 2.5.2) When I attempt it I get the exception: TypeError: super() argument 1 must be type, not classobj Looking at OptionParser, it is not derived from object. So I added object as a parent class, (shown below) and super works properly. from op...

Lambda, calling itself into the lambda definition

I'm doing a complicated hack in Python, it's a problem when you mix for+lambda+*args (don't do this at home kids), the boring details can be omited, the unique solution I found to resolve the problem is to pass the lambda object into the self lambda in this way: for ... lambda x=x, *y: foo(x, y, <selflambda>) It's possible?, thank...

How do I get cx_Oracle to work on 64-bit Itanium Windows?

I'm running Windows Server 2003 on a 64-bit Itanium server which is also running 64-bit Oracle 10.2, and I'd like to install cx_Oracle for Python 2.5. I've used cx_Oracle before many times on both Windows and Linux, and I've also compiled it before on 32 bit versions of those platforms, but I've never tried an IA64 compile. None of the...

kwargs sent over pyAMF channel

Hello, I'm using cherrypy server to receive requests over a pyAMF channel from a python client. I started with the mock up below and it works fine: Server: import cherrypy from pyamf.remoting.gateway.wsgi import WSGIGateway def echo(*args, **kwargs): return (args, kwargs) class Root(object): def index(self): return "...

2-dimensional interpolation

I want to find a value of z at y = 12 and x = 3.5, given the below example data. How can I do this in C++? y = 10 x = [1,2, 3,4, 5,6] z = [2.3, 3.4, 5.6, 7.8, 9.6, 11.2] y = 20 x = [1,2, 3,4, 5,6] z = [4.3, 5.4, 7.6, 9.8, 11.6, 13.2] y = 30 x = [1,2, 3,4, 5,6] z = [6.3, 7.4, 8.6, 10.8, 13.6, 15.2] My current Python code: import...

View a vmdk file from Python?

Is there any way to view the contents of a vmdk file from Python, and to be able to read files from it? (I have no need to write to it). If not, is there any way to mount a vmdk file on a host machine, or generally any other way to look at a vmdk file without attaching it to a VM and running it? ...

Python - automating MySQL query: passing parameter

Hello Everybody, The code in the sequence is working fine, but looking to improve the MySQL code to a more efficient format. The first case is about a function that received a parameter and returns the customerID from MySQL db: def clean_table(self,customerName): getCustomerIDMySQL="""SELECT customerID FROM customer WHERE ...

Access outer class from inner class in python

I have a situation like so... class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # <-- this is the line in question How can I access the Outer class's method from the Inner class? Edit -- Thanks for the responses. I'm c...

What is the Python equivalent of PHP's set_time_limit()?

I have a python script which is freezing (I think it stalls waiting for socket data somewhere), but I am having trouble getting a backtrace because the only way to stop it is to kill the process in. There is a timeout on the socket also, but it doesn't seem to work. I am hoping that Python has a feature like PHP's set_time_limit() funct...

Django | sort dict in template

I want to print out a dictionary, sorted by the key. Sorting the keys is easy in the view, by just putting the keys in a list and then sorting the list. How can I loop through the keys in the template and then get the value from the dictionary. {% for company in companies %} {% for employee, dependents in company_dict.company.items ...

Is there a Python library/class that can take a piece of text and determine the language?

You pass the string, and it outputs the language: english/spanish/japanese. Is there such library, and is it efficient? ...

What is the relationship between 'unicode' and 'encode'

print u'\xe4\xf6\xfc'.encode('utf-8') print unicode(u'\xe4\xf6\xfc') traceback: 盲枚眉 Traceback (most recent call last): File "D:\zjm_code\a.py", line 6, in <module> print unicode(u'\xe4\xf6\xfc') UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) python shell >>>u"äöü".encode...