python

Integrating a simple web server into a custom main loop in python?

I have an application in python with a custom main loop (I don't believe the details are important). I'd like to integrate a simple non-blocking web server into the application which can introspect the application objects and possibly provide an interface to manipulate them. What's the best way to do this? I'd like to avoid anything tha...

Can i integrate Blender with Phanthom Omni

I have some project about game programming, which have to use blender with phanthom ,Don't know possible to do it ...

Python: Behavior of the garbage collector

I have a Django application that exhibits some strange garbage collection behavior. There is one view in particular that will just keep growing the VM size significantly every time it is called - up to a certain limit, at which point usage drops back again. The problem is that it's taking considerable time until that point is reached, an...

Python threading strange behaviour.

from threading import * from time import * class MyThread(Thread): def __init__(self,x): self.x = x Thread.__init__(self) def run(self): sleep(2) print(self.x) if __name__=='__main__': threads = [] for i in range(5): threads.append(MyThread('Hello')) for i in range(5): threads[i].s...

Pascal's triangle

Hi, I am looking for a Pascals triangle using python script I have done till here and have no idea how to add on numstr= raw_input("please enter the height:") height = int( ) tri = [] row1 = [1] row2 = [1, 1] tri.append(row1) tri.append(row2) while len(tri) < height: ...

Approaches to resize an uploaded image of unknown format with Python

PIL is great for resizing an image 99% of time. But as there are some formats which PIL cannot handle, e.g. interlaced PNG images, I wonder is there any other libraries to work with as a supplement to PIL when we encounter a unsupported image. Besides interlaced PNG images, what other formats are not currently supported by PIL? As users...

bytes vs bytearray in Python 2.6 and 3

I'm experimenting with bytes vs bytearray in Python 2.6. I don't understand the reason for some differences. A bytes iterator returns strings: for i in bytes(b"hi"): print(type(i)) Gives: <type 'str'> <type 'str'> But a bytearray iterator returns ints: for i in bytearray(b"hi"): print(type(i)) Gives: <type 'int'> <type...

Python:: Turn string into operator

How can I turn a string such as "+" into the operator plus? Thanks! ...

XML attributes get sorted

When I create a document using the minidom, attributes get sorted alphabetically in the element. Take this example from here: from xml.dom import minidom # New document xml = minidom.Document() # Creates user element userElem = xml.createElement("user") # Set attributes to user element userElem.setAttribute("name", "Sergio Oliveira")...

sqlalchemy REST serialization

Reading the doc of sqlalchemy, i saw the serialization part. I'm wondering about a possibility to use an xml serializer for matching sa models with Rest webservices like Jax-RS There is a django extension which deal with that : django_roa Do you know if that kind of thing has already been developped for sqlalchemy or if is it possible to...

Lightweight python wiki engine with pluggable auth system

I need to add wiki to my Tornado webapp. i'm new to python so i would like it not too intimidating to be learned and integrated and can use my existing authentication system, hence the lightweight. it would be better if can use mongodb backend. I already take a look at moin-moin and it seems too complex(?). any other alternative? ...

translate python method to ruby

What would be the correct translation of the following Python method to Ruby? def uniqueCombinations(self, items, n): """ items: list of elements n: number in a group """ if n == 0: yield [] else: for i in range(len(items)-n+1): for cc in uniqueCombinations(items[i+1:],n-1): ...

Web.py template error: 'sum' does not exist

I use the built in 'sum' function in a web.py templator template and I get the following error: global name 'sum' is not defined Source code is below: $if profs: $for prof in profs: $sum([1, 2, 3]) I can use 'sum' just fine at a Python REPL in the terminal. What could be the issue? Thanks, Jacob ...

How to make PowerBuilder UI testing application?

Hi. I'm not familiar with PowerBuilder but I have a task to create Automatic UI Test Application for PB. We've decided to do it in Python with pywinauto and iaccesible libraries. The problem is that some UI elements like newly added lists record can not be accesed from it (even inspect32 can't get it). Any ideas how to reach this elemen...

How to ignore "Enter username for Private Proxy Access" prompt?

Hello, I'm using urllib.urlopen with some http proxies and sometimes (probably when they require authorization) I get the following prompt printed into the console: Enter username for Private Proxy Access (country) at xxx.xxx.xxx.xxx:xxxx How can I raise an exception on such thing happening? Here's the example: from urllib import u...

mongodb, pymongo querying

Hello, I've been browsing through the documentation, but I can't seem to figure out a way to perform a find on my mongodb collection using only a key. For example, let's suppose this is what's inside my collection { 'res1': 10 } { 'res2: 20 } How can I query the collection using only the key 'res1', in order to get 10 ? Thank you ...

Google Wave Python Tutorial - Nothing happens

For the Google Wave Python Robot Tutorial, my capabilities.xml is visible and I can add it to a Wave, but the robot isn't actually responding to the events. I checked the logs, but I've fixed it so I'm not getting any more errors. Any suggestions? ...

Email using cron job

i have made app using google app engine in pythonof weekly Project and assessment report submitting... i want to check that on Friday who have submitted the report and who don't just send the scheduled notification mail that he haven't submitted the report in last week... ** but i dont want to send the notification mail on monday who ...

How to use different formatters with the same logging handler in python

Is it possible to log to a single destination (i.e. using one FileHandler) with multiple loggers (i.e. logging.getLogger("base.foo") and logging.getLogger("base.bar")), and use different formatters for each of the loggers. To my understanding it's only possible to assign one formatter to each handle. Maybe it's possible to associate the...

Can SQLAlchemy update the table structure ?

Hello, I am working on my first pylons + SQLAlchemy app (I'm new to both). As I change my mind on the table structure, I wish there was a similar function to metadata.create_all(), that checks if there are new columns definitions and create theme in the database. Does such a function exist ? ...