python

Restore Python class to original state

I have a class where I add some attributes dynamically and at some point I want to restore the class to it's pristine condition without the added attributes. The sistuation: class Foo(object): pass Foo.x = 1 # <insert python magic here> o = Foo() # o should not have any of the previously added attributes print o.x # Should raise exc...

Finding length of items from a list

Hi everyone, I have two list in a python list1=['12aa','2a','c2'] list2=['2ac','c2a','1ac'] First- Finding combinations of each two item from list1. Second- Finding combinations of each two item from list2. Third- Finding combinations of each two items from list1 and list2 Fourth- Calculating each combinations total length Advic...

Convert python to c#

Can someone please help me convert the following two lines of python to C#. hash = hmac.new(secret, data, digestmod = hashlib.sha1) key = hash.hexdigest()[:8] The rest looks like this if you're intersted: #!/usr/bin/env python import hmac import hashlib secret = 'mySecret' data = 'myData' hash = hmac.new(secret, data, digest...

list.extend and list comprehension

When I need to add several identical items to the list I use list.extend: a = ['a', 'b', 'c'] a.extend(['d']*3) Result ['a', 'b', 'c', 'd', 'd', 'd'] But, how to do the similar with list comprehension? a = [['a',2], ['b',2], ['c',1]] [[x[0]]*x[1] for x in a] Result [['a', 'a'], ['b', 'b'], ['c']] But I need this one ['a', 'a...

Adding and removing audio sources to/from GStreamer pipeline on-the-go

I wrote a little Python script which uses an Adder plugin to mix two source streams together. After starting the program, you hear a 1kHz tone generated by the audiotestsrc plugin. When you press Enter, an another 500Hz test tone is connected to the Adder so you hear them together. (By the way, i don't really get why should i set the pi...

Issues with 2D-Interpolation in Scipy

Hi! In my application, the data data is sampled on a distorted grid, and I would like to resample it to a nondistorted grid. In order to test this, I wrote this program with examplary distortions and a simple function as data: from __future__ import division import numpy as np import scipy.interpolate as intp import pylab as plt # De...

Will the real path.py please stand up?

There was a good module, path.py, written by Jason Orendorff. If I recall correctly, there was some discussion about adding it to the standard library then it faded away. It looks now that there are multiple outgrowths of the original one. I can find so far unipath, what looks like a forked path.py, another one, and a few others accordi...

How to check whether elements appears in the list only once in python?

I have a list: a = [1, 2, 6, 4, 3, 5, 7] Please, explain mne how to check whether element appears only once in in the list? Please, also explain if all elements from 1 to len(a) are in the list. For inctance, in list 'a' element from 1 to 7 are in the list, but if the list is b = [1, 4, 3, 5], then not all elements from 1 to 4 are not...

How to change the font size on a matplotlib plot

How does one change the font size for all elements (ticks, labels, title) on a matplotlib plot? I know how to change the tick label sizes, this is done with: import matplotlib matplotlib.rc('xtick', labelsize=20) matplotlib.rc('ytick', labelsize=20) But how does one change the rest? ...

How o Delete ALL Pages of agw.aui.notebook in One shot ?

Hi, I have a auiNotebook built from agw library. Now i have added few pages Now i have to delete ALL pages at one shot. Please let me know how to do this. Or is there any method which gives me List of Page Indexs for All Added Pages so that i can use Delete Page method to delete all pages Enviroment: Windows,wxpython ...

Python strip() multiple characters?

I want to remove any brackets from a string. Why doesn't this work properly? >>> name = "Barack (of Washington)" >>> name = name.strip("(){}<>") >>> print name Barck (of Washington ...

Accessing a Panatone Huey via Python

I have a Panatone Huey, a monitor calibration probe (device you attach to the monitor, and it gives you colour readings) - I want to get readings from the device in Python. Having never written such a device driver before, I'm not sure where to start. I've found are two open-source C/C++ projects that interface with the Heuy - ArgyllCM...

Ignore an element while building list in python

Hello, I need to build a list from a string in python using the [f(char) for char in string] syntax and I would like to be able to ignore (not insert in the list) the values of f(x) which are equal no None. How can I do that ? ...

Lists in Python

Possible Duplicate: What is the easiest way to convert list with str into list with int? =) Is it possible to transform: a = ['1', '2', '3', '4'] to a = [1, 2, 3, 4] Thank You! ...

How to detect CPU speed and H.D.D rpm in objective-c or python

I'm new to objective-c, for an academic reason I need to read CPU speed and H.D.D rpm What is the simplest way to access some system setting in objective-c or python I can choose between objective-c and python for this project, so any help will appriciate ...

Understanding what files in the TCL are required for distributing frozen Python Tkinter apps

I'm trying to figure out which files in Python's (Python 2.6/Python 2.7) tcl folder are required in order to distribute frozen Python Tkinter apps using Py2exe or similar. The quick and dirty way to do this (using pyexe as an example) is to follow the 2nd example on the following page and then xcopy your python's tcl folder to your dis...

Writing a TCP to RS232 driver

I need to expose an RS232 connection to clients via a network socket. I plan to write in python a TCP socket server which will listen on some port, allow client to connect and handle outgoing and manage and control requests and replies to from the R2232 port. My question is, how do I synchronize the clients, each client will send some ...

python: Convert tcpdump into text2pcap readable format

Recently there was a requirement for me to convert the textual output of "tcpdump -i eth0 -neXXs0" into a pcap file. So I wrote a python script which converts the information into an intermediate format understandable by text2pcap. Since this is my first program in python there would obviously be scope for improvement. I want knowledgeab...

access to google with python

hello guys ... how i can access to google !! i had try that code urllib.urlopen('http://www.google.com') but it's show message prove you are human or some think like dat some people say try user agent !! i dunno ! ...

Access Model Data from Django Base Template

I have a model Category, and I want its objects to always be displayed in a navigation menu in my base.html template (which all of my other templates extend). I want to learn best-practices so would like to know what the correct/accepted way of providing this data to the template is. ...