python

Python C-API Making len(...) work with extension class

When creating a class in Python, I can simply make a def __len__(self): method to make the len(InstanceOfMyClass) work, however I can't find out how to do this with an extension class via the C-API. I tried adding a __len__ method, but that appears to not work {"__len__",(PyCFunction)&TestClass_GetLen,METH_NOARGS,""}, Python test cod...

how to avoid storing different type of objects in the same place when they represent the same but with a different data structure

This is in my opinion an abstract problem and I hope I can explain it well. I happened to find the same kind of problem in a completely different project and now I have it again and I would like to avoid it if possible. I'm creating some classes to simplify some tasks for some specific requirements we have in some projects at work. I ...

Why python does not allow hyphens

I have always wondered why can't we use hyphens in between function names and variable names in python Having tried functional programming languages like Lisp and Clojure, where hyphens are allowed. Why python doesn't do that. # This won't work -- SyntaxError def is-even(num): return num % 2 # This will work def is_even(num): ...

Python not all in operation

How do I check if a list is a subset of a bigger list. i.e. a = [1,2,3] is a subset of b = [1,2,3,4,5,6] Can I do something like if a all in b ...

Executing python code from script and getting interpreter-style output

I need to execute code from my python script and take interpreter-style output like it's done here. I am creating website on GAE using django, it must run user-entered code and print interpreter-style output as text. ...

multiprocessing.Process subclass works on Linux but not Windows

Hi, I'm trying to get python-gasp working on Windows, but when I do import gasp; gasp.begin_graphics() I get the following traceback: File "C:\Python26\lib\site-packages\gasp\backend.py", line 142, in create_screen screen.updater.start() File "C:\Python26\lib\multiprocessing\process.py", line 104, in start self._popen = ...

Facebook connect on Google App Engine with Django Patch

We are building a website on Google App Engine, using django patch. We would like to use Facebook connect for two purposes: Authenticate users. Access user's social data. Searching for a solution in the usual places (google, FB, SO) brigs up a lot of noise, many partial solutions and no clear answer. So the question is this: does a...

wxFrame with title bar but non resizable

hai guyz I need to create a login window for that window i need a title bar for dragging but it should not be a resized I need a fixed size for this window ...

Python: Best method to reload class in XMLRPC Server

I have a multit-threaded xmlrpc service running which stores a huge amount of data ~2G in memory. Currently, if I want to update a method the server exposes I have to restart the service. The problem here is that if I restart the service it needs to load all of the data it had in memory back into memory by using a database or using she...

Jinja-like for Pdf in Python

I am looking for the best accurate tool for PDF in Python that works like Jinja do for HTML. What are your suggestions? ...

Using wget with subprocess

Hi! I'm trying to use wget with subprocess. my attempts worked until I tried to download the page to a specified directory with this code: url = 'google.com' location = '/home/patrick/downloads' args = ['wget', 'r', 'l 1' 'p' 'P %s' % location, url] output = Popen(args, stdout=PIPE) if I run this code in /home/patrick I get index.ht...

Passing arguements into SUDS client statement

Hello, I am using SUDS (Like SOAP) to test WSDL files. The methods contain types that are linked to further functions. I am not sure how to access the variables stored in the types that are displayed. Some sample code is below: from suds.client import Client client=Client('http://eample.wsdl') print client response is: Ports (1): ...

Python equivalent of pointers

in python everything works by reference: >>> a = 1 >>> d = {'a':a} >>> d['a'] 1 >>> a = 2 >>> d['a'] 1 i want something like this >>> a = 1 >>> d = {'a':magical pointer to a} >>> d['a'] 1 >>> a = 2 >>> d['a'] 2 what would you substitute for 'magical pointer to a' so that python would output what i want i would appreciate general s...

python parent class 'wrapping' child-class methods

Hello all, I have the following situation in my python code: class Parent(object): def run(self): print "preparing for run" self.runImpl() print "run done" class Child(Parent): def runImpl(self): print "child running" However, I have several such 'decorators', doing different setup/teardown ste...

UDP packet encryption

This appears to be reasonably trivial if using the ssl module for TCP communication, but how would encrypted communication be done via UDP? Can the ssl module still be used? if so, what steps would need to be performed for the client and server to be in a position where data can be sent to-and-fro as normal? ...

Parsing, securing python expression before passing it to eval()

Hello, I want to take an input from the user may be like foo() > 90 and boo() == 9 or do() > 100 and use eval on the server side to to evaluate this expression. For security I want to restrict user to add limited functions and operators by keeping a check (against some data-structure) before I pass it to eval function. PS: Input comes...

Linear Fit to Planet Positions

An astounding alignment occurs 2048/5/28 with the inner 5 planets having heliocentric longitudes (in degrees): 248.229, 66.631, 246.967, 249.605, 67.684. The planets are at most 0.875 degrees from the line (through Sol) with slope 67.823 degrees. In this case, the method sought (PA) would give: PA(248.229, 66.631, 246.967, 249.605...

Python get all numbers that add up to a number

I'm trying to find a way to display all the possible sets of X integers that add up to a given integer. for example to get all 2 integer sets that make 5 I would have: 1, 4 2, 3 Or for 3 integers that make 6: 1, 1, 4 1, 2, 3 2, 2, 2 I only need whole numbers not including 0 and it only needs to work on up to about 15 in a set and 3...

Unknown Authn provider: wsgi ... fail!

I have working wsgi authentication on another server, however a second server is not accepting the same configuration and errors upon reload with the message: Syntax error on line 12 of /etc/apache2/sites-enabled/mydomain.com Unknown Authn provider: wsgi ... fail Here is the relevant portion of the config file (line 12 is WSGIAuth...

A clean algorithm for sorting a objects according to defined dependencies?

Given a list of classes inheriting from this base: class Plugin(object): run_after_plugins = () run_before_plugins = () ...and the following rules: Plugins can provide a list of plugins that they must run after. Plugins can provide a list of plugins that they must run before. The list of plugins may or may not contain all pl...