python

Python to C code ?

Hi, I wrote a program in python (using standard python libraries) long ago. Now I need to write the same program in standard C due to the lack of python support for that device. Please suggest me programs or conversion method to convert that python code into C code. Thanks in advance. ...

Accessing a class's variable in Python

class Example(object): def the_example(self): itsProblem = "problem" theExample = Example() print(theExample.itsProblem) How do I access a class's variable? I've tried adding this definition: def return_itsProblem(self): return itsProblem Yet, that fails also. ...

simplify simple C++ code -- something like Pythons any

Hi, Right now, I have this code: bool isAnyTrue() { for(std::list< boost::shared_ptr<Foo> >::iterator i = mylist.begin(); i != mylist.end(); ++i) { if( (*i)->isTrue() ) return true; } return false; } I have used Boost here and then but I couldn't really remember any simple way to write it somewhat lik...

SVG images dont appear after compiling PyQt4 python code with py2exe

hi, I wrote python application using svg images as icons. QtGui.QIcon(':icons/icon.svg') <- just like this it works on my comuter but after compiling it with py2exe and running on another computer, theres no icons. if i try e.g. bmp format, all works fine. so i think it could be some library problem. I don't know what PyQt4 uses for s...

Python : Allowing methods not specifically defined to be called ala __getattr__

Hi, I'm trying to write a Python class that has the ability to do the following: c = MyClass() a = c.A("a name for A") # Calls internally c.create("A", "a name for A") b = c.B("a name for B") # Calls internally c.create("B", "a name for B") A and B could be anything (well, they're defined in a database, but I don't want to explicitly...

App Engine Bulk Data Upload URLError: "Connection reset by peer"

Hi. I'm trying to upload some records to my local data store using appcfg.py Only a small number of records are actually inserted and I get the following output (with a ton of errors): $ appcfg.py upload_data --config_file=bulkloader.yaml --filename=/output.csv --kind=AutoCompleteIndex --url=http://localhost:8084/remote_api . ...

Creating a UI in maya using python scripting

Hi all, I am creating a custom UI inside maya using python. I encountered some errors, Hope you guys could help. I attached my script below. Basically my script is trying to create a UI with buttons inside that do stuffs. In this case, I am trying to create a textfield button which the user keys in a set of coordinates and the locator ba...

What is the best Python IDE for Mac OS X?

Possible Duplicate: Whats a good IDE for Python on the Mac? Hi, I'm going to start a quite big python project development under Mac OS X. What is the best python IDE for Mac OS X -recommended freeware-. ...

Unpacking big-endian encoded port number

Hey there! I'm trying to convert a big-endian 2 byte string into a numeric port number. I've already got some code, but I have no idea if it's right: from struct import unpack def unpack_port(big_endian-port): return unpack("!H", big_endian-port)[0] The port (using Python repr() ) is \x1a\xe1, and I get 6881 out of that function. ...

determining the first sprite to animate in python/pygame

so I have this spritesheet (4 sprites in a row and 3 in a coloumn) which I use to animate a character in a game I make. It animates just fine without a problem, like I want it to the problem start to arise when I want to change the state from "dash" (running to the enemy) to "attack" (well, attack the enemy) it doesn't seem to play the ...

App Engine Bulk Data Upload- Authentication Error

Hi guys. When I try to upload data using appcfg.py I get an authentication error regardless of my login details being completely correct. appcfg.py upload_data --config_file=bulkloader.yaml --filename=/output.csv --kind=AutoCompleteIndex . Application: qwertifyy; version: dev. Uploading data records. [INFO ] Logging to bulkloader...

Multi-split in Python

How would I split a string by two opposing values? For example ( and ) are the "deliminators" and I have the following string: Wouldn't it be (most) beneficial to have (at least) some idea? I need the following output (as an array) ["Wouldn't it be ", "most", " beneficial to have ", "at least", " some idea?"] ...

I need a message/queuing solution for my web-based system

Hi, I am looking for a message/queuing solution for my web based system running on Ubuntu. The system was built on the following technologies: Javascript (Extjs framework) - Frontend PHP Python (Daemon service which interacts with the encryption device) Python pyserial - (Serial port interactions) MySQL Linux - Ccu...

Mako or Jinja2 ?

I didn't find a good comparison of jinja2 and Mako. What would you use for what tasks ? I personnaly was satisfied by mako (in a pylons web app context) but am curious to know if jinja2 has some nice features/improvements that mako doesn't ? -or maybe downsides ?- ...

Datetime/time issue with python (18 hours off)

I'm working on making a small ban system, and the snippet below will tell the client how much time of their ban is remaining. The problem: When you call Bans.timeleft_str(), rather then showing something less then a day, it will show the timestamp + 18 hours. Snippet: http://pastebin.com/Zumn0tLv This problem occurs if I change self.l...

Confusion while counting elapsed time in python?

So I wanted to compare the performance of python between 2.6 and 3.1, so I wrote this simple program test.py that will perform some basic lengthy operation: from time import time start = time() q = 2 ** 1000000000 q += 3 << 1000000000 print(q.__sizeof__(), time() - start) I didn't get what I expected, since after launching the command...

mongodb union $or problems

I have a collection which is an action log between two users. It has a src_id and a dest_id. I'm a looking to fetch all the records that are actions between id1 and a list of ids - "ids = [id2, id3, id4]". The following two statements work properly: act_obs = self.db.action_log.find( {'src_id': id1, 'dest_id': {'$in': ids} } ...

Having some beautifulsoup htmlparse errors, how to revert to a different version?

I am using beautifulsoup, and I am getting some htmlparser errors with start tags etc. I read on crummy's site that one suggestion is to go back to an older version (3.08). I am using Ubuntu, where I did: sudo apt-get install python-beautifulsoup to install it. how can I check what version I have now? how can I force a specific ver...

Accessing the underlying struct of a PyObject

I am working on creating a python c extension but am having difficulty finding documentation on what I want to do. I basically want to create a pointer to a cstruct and be able to have access that pointer. The sample code is below. Any help would be appreciated. typedef struct{ int x; int y; } Point; typedef struct { PyObject_HEAD ...

3D pie graph in matplotlib

Is there a way to render a 3D pie in matplotlib? Or do you know at least a Python package that can generate 3D pies? EDIT: I actually already knew about pygooglechart, but I'm looking for something that can be done offline. My apologies for forgetting to include this information. For those who offered pygooglechart, thanks for the effor...