python

python error checking

I am using code below. How Do add error checking. If anything is error, replace continue reading Ex: if volume is N\a or missing , replace with 'a value.' Don't skip line, don't stop. reader = csv.reader(idata.split("\r\n")) stocks = [] for line in reader: if line == '': continue stock, price, volume, stime = line ...

smtplib.sendmail not working with smtp4dev

I am running Python 2.5 on Windows 7 x64 with smtp4dev running in the background. When I run the following script: import smtplib s=smtplib.SMTP('localhost',25) tolist=['[email protected]'] msg=''' From: [email protected] Subject: testin'... This is a test ''' s.sendmail("[email protected]",tolist,msg) s.quit() After a 30-second timeout, I receive this e...

apropos / find context related information

Hi folks, On unix-like systems we have apropos to search the manual page names and descriptions so we can find context related information. For example apropos delete would give me a list of all kinds of software related to "deleting" stuff. Does anybody know if that already exist for Python or do I have to code it? What I basically w...

Top 3 questions to test someones Python level, what would they be?

If you had to judge someones level of Python understand in just 3 questions, what would you ask? ...

returning xml documents from cherrypy

I am new to web programming and am trying to return an xml document from the cherrypy web server. But, what I see in the browser is a string value stripped off all the xml tags. i.e. <Foo> <Val1> </Foo> <Bar> <Val2> </Bar> shows up in the browser as Val1 Val2 I am sure that I am generating the document correctly but somewhere a...

I get OSError: [Errno 13] Permission denied: <dir name>, and os.walk exits

Hello all. I have a script to report me about all files, in a directory, so that users will be required to erase them (it's a really badly managed cluster, w/o real superuser). When I run the script I get: OSError: [Errno 13] Permission denied: ' ls: : Permission denied I can't write the dir name (company policy) The code is: #!/depot/P...

wx Text with outline

Hello SO, I have a video player written in wxpython and am overlaying the current FPS onto the video. My text is black, so if the video is sufficiently dark the FPS counter is not visible. I am looking for a way to draw text with an outline so it will stand out no matter what the video is displaying. E.g. I want black text with a whit...

How to package example scripts using distribute?

I use distribute to package a small python library. I made a directory structure as described in the Hitchhiker's Guide to Packaging. My question: Where (in the directory structure) do I place an example scripts that shows how to use the library and what changes are necessary to the setup.py? ...

Python 2.7 or 3.1.2?

Possible Duplicate: python 2.6 or python 3.1? Hi, I'm new to the python world and it seems that there are currently two parallel versions in development, which would be the 2.7 versus the 3.1.2. I'm wondering what version should I use to start, and why? ...

Python 'source HOME/.bashrc' with os.system()

I am writing a python script (Linux) that is adding some shell aliases (writes them to HOME/.bash_aliases). In order to make an alias available immediately after it was written I should issue the following bash built-in: source HOME/.bashrc source is a bash built-in so I cannot just: os.system(source HOME/.bashrc) If i try somethi...

Rfc 1123 in python

Hi guys. Just want to use 'datetime' or 'time' modules. I based the following code on this question: import time def rfc1123 (gmt): weekday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][gmt.tm_wday] month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][gmt.tm_mon] return "%s, ...

SPOJ ADDREV Problem

Guys, got the answer in C ; THank you for all the help . Hey , I did go through the other threads on this(ADDREV Problem )(https://www.spoj.pl/problems/ADDREV/ ) but sadly, i am not able to get an answer by any of the three programs that i have written. ( in C , python and java ) . I am attaching the code snippets of all three. T...

Dropping a file onto a script to run as argument causes exception in Vista

edit:OK, I could swear that the way I'd tested it showed that the getcwd was also causing the exception, but now it appears it's just the file creation. When I move the try-except blocks to their it actually does catch it like you'd think it would. So chalk that up to user error. Original Question: I have a script I'm working on that I...

Suspending function calls in Python for passing later (functional paradigm)

I'm writing a python command line program which has some interdependent options, I would like for the user to be able to enter the options in whichever order they please. Currently I am using the getopts library to parse the command line options, unfortunately that parses them in-order. I've thrown together a system of boolean flags to...

Design question in Python: should this be one generic function or two specific ones?

I'm creating a basic database utility class in Python. I'm refactoring an old module into a class. I'm now working on an executeQuery() function, and I'm unsure of whether to keep the old design or change it. Here are the 2 options: (The old design:) Have one generic executeQuery method that takes the query to execute and a boolean com...

How to remove tags from a string in python using regular expressions? (NOT in HTML)

I need to remove tags from a string in python. <FNT name="Century Schoolbook" size="22">Title</FNT> What is the most efficient way to remove the entire tag on both ends, leaving only "Title"? I've only seen ways to do this with HTML tags, and that hasn't worked for me in python. I'm using this particularly for ArcMap, a GIS program. I...

PIL convert from cmyk to rgb looses xmp metadata

hi, i need to convert cmyk images to rgb in my python app. unfortunately the metadata gets lost in this process. import Image path = '/path/to/image.jpg' im = Image.open(path) im.convert('RGB').save(path, 'JPEG', quality=95) thank you for any advice ...

how do matlab do the sort??

How is the sort() working in matlab? Code in pure matlab: q is an array: q = -0.2461 2.9531 -15.8867 49.8750 -99.1172 125.8438 -99.1172 49.8750 -15.8867 2.9531 -0.2461 After q = sort(roots(q)), I got: q = 0.3525 0.3371 - 0.1564i 0.3371 + 0.1564i 0.2694 - 0.3547i 0.2694 + 0.3547i ...

BeautifulSoup chokes on paths with back slashes

I wrote a script to automate the process of creating an image gallery. I used os.path.join() for creating paths to new image directories. I only relized after creating all the galleries that using os.path.join() was not such a good idea as it creates paths with \ (on windows) which causes problems with firefox (it doesn't seem to unders...

python comparing dictionaries

level: beginner word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} i want to know if word is entirely composed of letters in dict2 my approach: step 1 : convert word to dictionary(dict1) step2: for k in dict1.keys(): if k in dict2: if dict1[k] != dict2[k]: return False ...