python

What is the equivalent of object oriented constructs in python?

How does python handle object oriented constructs such as abstract, virtual, pure virtual etc Examples and links would really be good. ...

Getting an input/output error from python with pyserial

I have a python script that writes data packets to an arduino board through pyserial. Sometimes while writing the code to the board pyserial raises an input/output error with errno 5 Some research says that this indicates an error while writing in the file representing the connection to the arduino board. The code that sends, sends on...

trouble with pamie.

I'm having some strange trouble with pamie: http://pamie.sourceforge.net/ . I have written a script to do some port (25) forwarding based on a recepie that I found on the web, Here is the code that matters: # forwardc2s(source, destination): # forwards from client to server. # Tries to post the message to ICE. def forwardc2s(so...

How to strip the 8th bit in a KOI8-R encoded character?

How to strip the 8th bit in a KOI8-R encoded character so as to have translit for a Russian letter? In particular, how to make it in Python? ...

why does this code break out of loop ?

import math t=raw_input() k=[] a=0 for i in range(0,int(t)): s=raw_input() b=1 c=1 a=int(s) if a==0: continue else: d=math.atan(float(1)/b) + math.atan(float(1)/c) v=math.atan(float(1)/a) print v print d print float(v) print float(d) while(): ...

How can I parse a C header file with Perl?

Hi, I have a header file in which there is a large struct. I need to read this structure using some program and make some operations on each member of the structure and write them back. For example I have some structure like const BYTE Some_Idx[] = { 4,7,10,15,17,19,24,29, 31,32,35,45,49,51,52,54, 55,58,60,64,65,66,67,69, 70,72,76,7...

Redirecting console output to a Python string

Possible Duplicate: How can I capture the stdout output of a child process? I'm running a cat-like program in bash from Python: import os os.system('cat foo.txt') How do I get the output of the shell command back in the Python script, something like: s = somefunction('cat foo.txt') ? UPD: Here is a related threa...

customize login in google app engine

I need to add few more options for login and therefor need to customize create_login_url with some html code. Is there a way to add on your code in default login screen of google? ENvironment - python-google app engine. I want to continue having the default google ext class Users behavior to conntinue to be in place. ...

Using python regex to extract namespaces from C++ sources

Hi, I am trying to extract the namespaces defined in C++ files. Basically, if my C++ file contains: namespace n1 { ... namespace n2 { ... } // end namespace n2 ... namespace n3 { ...} //end namespace n3 ... } //end namespace n1 I want to be able to retrieve: n1, n1::n2, n1::n3. Does someone have any suggestion of how I ...

How can this be written on a single line?

I've seen some Python list comprehensions before, but can this be done in a single line of Python? errs = {} for f in form: if f.errors: errs[f.auto_id] = f.errors ...

ctypes in python, problem calling a function in a DLL

Hey! as you might have noticed I have an annoying issue with ctypes. I'm trying to communicate with an instrument and to do so I have to use ctypes to communicate with the DLL driver. so far I've managed to export the DLL by doing this: >>> from ctypes import * >>>maury = WinDLL( 'MLibTuners') >>> maury (WinDLL 'MlibTuners', handle 100...

mod_python caching of variables

I'm using mod_python to run Trac in Apache. I'm developing a plugin and am not sure how global variables are stored/cached. I am new to python and have googled the subject and found that mod_python caches python modules (I think). However, I would expect that cache to be reset when the web service is restarted, but it doesn't appear to ...

KOI8-R: Having trouble translating a string

This Python script gets translit for Russian letters: s = u'Код Обмена Информацией, 8 бит'.encode('koi8-r') print ''.join([chr(ord(c) & 0x7F) for c in s]) # kOD oBMENA iNFORMACIEJ, 8 BIT That works. But I want to modify it so as to get user input. Now I'm stuck at this: s = raw_input("Enter a string you want to translit: ") s = unic...

Using data from django queries in the same view

I might have missed somthing while searching through the documentation - I can't seem to find a way to use data from one query to form another query. My query is: sites_list = Site.objects.filter(worker=worker) I'm trying to do something like this: for site in sites_list: [Insert Query Here] Edit: I saw the awnser and im not s...

IOError "no such file or folder" even though files are present

I wrote a script in Python 2.6.2 that scans a directory for SVG's and resizes them if they are too large. I wrote this on my home machine (Vista, Python 2.6.2) and processed a few folders with no problems. Today, I tried this on my work computer (XP SP2, Python 2.6.2) and I get IOErrors for every file, even though files are in the dire...

Enumeration of combinations of N balls in A boxes?

Hi, I want to enumerate all possible combinations of N balls in A boxes. example: I have 8 balls to deal in 3 boxes : box_1 box_2 box_3 case-1 8 0 0 case-2 0 8 0 case-3 0 0 8 case-4 7 1 0 case-5 7 0 1 case-6 6 2 0 ...

py2exe windows service problem

I have successfully converted my python project to a service. When using the usual options of install and start/stop, everything works correctly. However, I wish to compile the project using py2exe, which seems to work correctly until you install the EXE as a service and try and run it. You get the following error message: Starting ...

Parsing an existing config file

I have a config file that is in the following form: protocol sample_thread { { AUTOSTART 0 } { BITMAP thread.gif } { COORDS {0 0} } { DATAFORMAT { { TYPE hl7 } { PREPROCS { { ARGS {{}} } { PROCS sample_proc } } } } } } The real file may not have these exact fields, a...

Memory Management and Python: how much do you need to know?

I know that a language like Python does garbage collection for you, but for any applications/optimizations or even security, is it important to understand how memory management works? I am very familiar, but I am going to start teaching a student soon, and I'm curious to know whether that's something we should go over. Note: this questi...

Regex in Python

Goal: Given a number (it may be very long and it is greater than 0), I'd like to get the five least meaningful digits dropping any 0 at the end of that number. I tried to solve this with regex, Helped by RegexBuddy I came to this one: [\d]+([\d]{0,4}+[1-9])0* But python can't compile that. >>> import re >>> re.compile(r"[\d]+([\d]{0...