python

Simple "for" question

How can I fix this statement: for i in LISTA and i not in LISTB: print i ...

Python regular expression help

I've got a python string s = "Abc(problem=None, fds=5, sff=(2, 1, 0))" s2 = "Abc(problem=None)" What I want to do is remove the "problem=None, " So it'll looks like s = "Abc(fds=5, sff=(2, 1, 0))" s2 = "Abc()" Please mind the ',' How to achieve this? Thanks very much!! ...

Pass Password to runas from Python

I need to run a file as another user without it prompting for a password, from my script. How is this done? ...

Python 2.7/Windows: Create resizable, multiline tkinter/ttk labels with word wrap

Is it possible to create a multi-line label with word wrap that resizes in sync with the width of its parent? In other words the wordwrap behavior of Notepad as you change the width of the NotePad window. The use case is a dialog that needs to present a block of multi-line text (instructions) in its entirety without having the text clip...

Python 2.7/Windows: tkinter/ttk widgets with transparent backgrounds, ttk frame background colors

Is it possible to configure tkinter or ttk widgets (Label, Entry, Text) with a transparent background so that they can be placed in containers with custom background colors or on top of canvas graphics or images? I'm also looking for a way to change the background color of a ttk Frame widget? Do I need to use the new ttk Style objects ...

A question about lists in Python...

I'm having some trouble with a couple of hmwk questions and i can't find th answer- How would you write an expression that removes the first or last element of a list? i.e. One of my questions reads "Given a list named 'alist' , write an expression that removes the last element of 'alist'" ...

How do I send midi Control Change messages (CC's) using pyPortMidi or pygame?

I'm using Python along with Pygame which uses pyPortMidi for it's midi module, and I'm currently sending NoteOn and NoteOff messages through Midi Yoke to Ableton live, which works great. But I can't seem to figure out how I send CC messages.. Anyone? The (working) class basically looks like this. class MidiIO: def __init_...

Installing MySQLdb on Snow Leopard

Hello, I followed this tutorial to install Django with MySQL on my Snow Lepard : http://programmingzen.com/2007/12/22/how-to-install-django-with-mysql-on-mac-os-x/ When I run this command : python setup.py build I get a lot of errors, the last one is : error: command 'gcc-4.0' failed with exit status 1 These are the first lines t...

Medical information extraction using Python

Hello there, I am a nurse and I know python but I am not an expert, just used it to process DNA sequences We got hospital records written in human languages and I am supposed to insert these data into a database or csv file but they are more than 5000 lines and this can be so hard. All the data are written in a consistent format let me s...

Python: The _imagingft C module is not installed

I've tried lots of solution that posted on the net, they don't work. >>> import _imaging >>> _imaging.__file__ 'C:\\python26\\lib\\site-packages\\PIL\\_imaging.pyd' >>> So the system can find the _imaging but still can't use truetype font from PIL import Image, ImageDraw, ImageFilter, ImageFont im = Image.new('RGB', (300,300), 'whi...

Conditional statements with Python lists

Hello, I am trying to learn Python lists. In this code I am trying to add a string s coming from a form to table row as long as the string is the same. When the string is different; the new string is written to the next column. I could write the string from column 0 to column 1 but I had problems adding the same string on column 1 corr...

Regexp to check if an IP is valid

I'm wondering if it's possible to compare values in regexps with the regexp system in Python. Matching the pattern of an IP is easy, but each 1-3 digits cannot be above 255 and that's where I'm a bit stumped. ...

How to get the smallest list of duplicate items from list of lists ?

Hi everyone, I'm a Python newbie, I worked with list for 2 months and I have some questions. I have some list and they have duplicate items. I can get duplicate items between 2 lists, now I want the number of lists and the deepness increased like this example: http://i219.photobucket.com/albums/cc213/DoSvn/example.png. I want to get pare...

About the image size that generated from matplotlib

Hi, I generated a histogram by using matplotlib import numpy as np import pylab as P mu, sigma = 200, 25 x = mu + sigma*P.randn(10000) P.figure() bins = 10 n, bins, patches = P.hist(x, bins, normed=1, histtype='bar', rwidth=0.8) P.show() I want to make the picture smaller, how could I do that? Thanks for your help ...

Python Colon(:) in list index

Hello All: I'm new to Python. I see : used in list index especially when it's associated with functional calls, for e.g., python 2.7 document suggests that lists.append translates to a[len(a):] = [x]. Why do one have to suffix len(a) with a colon? I understand that : is used to identify keys in dictionary. Thanks in advance for the hel...

Django - Replicating the admin list_display

What's the easiest method to get list_display functionality in my main website (outside of the admin pages). I have a group of elements I'd like to select and perform an action. Any ideas? ...

Is it bad that I don't follow PEP 8 and cut my lines at 79 characters?

I think every Python code has seen PEP 8. The part that sticks out to me is: Limit all lines to a maximum of 79 characters. I'm sitting here on a widescreen monitor and coding right across the screen. I'm not coding in a terminal and don't plan on coding in a terminal. I therefor have no problems with character-line limits. How many ...

Python: in what encoding is sys.argv?

In what encoding are the elements of sys.argv, in Python? are they encoded with the sys.getdefaultencoding() encoding? sys.getdefaultencoding(): Return the name of the current default string encoding used by the Unicode implementation. PS: As pointed out in some of the answers, sys.stdin.encoding would indeed be a better guess. I...

Python md5 password value

I have this change password request form.In which the user enter their oldpasswords. this oldpassword is the md5 format. How to compare the md5 value from db to the oldpassword entered by user import md5 oldpasswd_byuser=str("tom") oldpasswd_db="sha1$c60da$1835a9c3ccb1cc436ccaa577679b5d0321234c6f" opw= md5.new(oldpasswd_byuse...

Python WSGI deployment on Windows for CPU-bound application

What options do I have for the deployment of a CPU bound Python-WSGI application on Windows? The application benefits greatly from multiple CPUs (image manipulation/encoding) but the GIL prevents it from using them. My understanding is: mod_wsgi has no support for WSGIDaemonProcess on Windows and Apache itself only runs with one proc...