python

Python Base64 print problem

Hi all, I have a base64 encoded string When I decode the string this way: >>> import base64 >>> base64.b64decode("XH13fXM=") '\\}w}s' The output is fine. But when i use it like this: >>> d = base64.b64decode("XH13fXM=") >>> print d \}w}s some characters are missing Can anyone advise ? Thank you in advanced. ...

Python Web Server - Getting it to do other tasks

Hi guys. Using the following example I can get a basic web server running but my problem is that the handle_request() blocks the do_something_else() until a request comes in. Is there any way around this to have the web server do other back ground tasks? def run_while_true(server_class=BaseHTTPServer.HTTPServer, handler_c...

Using urllib2 for posting data, following redirects and maintaining cookies

I am using urllib2 in Python to post login data to a web site. After successful login, the site redirects my request to another page. Can someone provide a simple code sample on how to do this in Python with urllib2? I guess I will need cookies also to be logged in when I get redirected to another page. Right? Thanks a lot in advace. ...

Starting with Android: Java or Python (SL4A)

I just ordered an Android smartphone and want to start playing around with creating my own applications. Now the question is which language to use, the native Java or Python using SL4A (former ASE). I tend to Python, as I know it much better than Java, but I'm wondering what I would be missing using a "second class" language on Android....

How do the PIL ImageFilter enhancement filters work?

Where can I find information on what algorithms the PIL ImageFilter functions use? Like how does edge_enhance work? I'm looking to implement a difference of Gaussians filter but if PIL has a filter that works similarly I'll use that. ...

Python: Email problem

I'm using the script below to send an email to myself, the script runs fine with no errors but I don't physically receive an email. import smtplib sender = '[email protected]' receivers = ['[email protected]'] message = """From: From Person <[email protected]> To: To Person <[email protected]> Subject: SMTP e-mail test This is a test e-mail ...

How can one use the logging module in python with the unittest module?

I would like to use the python logging module to log all of the output from unittest so that I can incorporate it into a testing framework I am trying to write. The goal of this is to run the tests with 2 sets of output, one with simple output that tells the test case steps and a more debug level output so that when things go wrong we h...

python -- callable iterator size?

I am looking through some text file for a certain string with the method. re.finditer(pattern,text) I would like to know when this returns nothing. meaning that it could find nothing in the passed text. I know that callable iterators, have next() and __iter__ I would like to know if I could get the size or find out if it returns no s...

Things to avoid in Python

Possible Duplicate: Common pitfalls in Python Hello all, inspired by this question Fastest way to learn Python? I've read the Dive into Python 3 webpage. I learned the basics, wrote a few simple programs and started to like the language. However i also started running into bugs, i did things wrong and my programs did not work...

Error when trying make cleaned_data()! Django

Must be simple solution. But I do not see it. Please help me. Looks like 'gorod' is in request but when i trying cleaned_data() it gives me KeyError KeyError at /ticket/ 'gorod' Request Method: POST Request URL: http://localhost:8000/ticket/ Exception Type: KeyError Exception Value: 'gorod' Exception Location: C:\...

python -- for with an if statement

I dont understand why, when i run my code the for each loop under the if statement isn't run. Even when the number of found is greater than 0! def findpattern(commit_msg): pattern = re.compile("\w\w*-\d\d*") group = pattern.finditer(commit_msg) found = getIterLength(group) print found if found > 0: issues = ...

Referencing further pages with ReportLab

I'm using ReportLab to create long questionnaires and I need to create text like If you do not have allergies, proceed to page 168 Does ReportLab present some feature that can help me with this referencing task? I understand that this problem probably needs a two-pass algorithm. In the first pass, the pages' numbers are found. T...

Gmail SMTP + XOAuth mystery

Hi everyone, I am using python smtplib and xoauth and I am trying to send an email. I am using the code posted by Google: http://code.google.com/p/google-mail-xoauth-tools/source/browse/trunk/python/xoauth.py I am actually authenticating against Gmail and i get this reply reply: '235 2.7.0 Accepted\r\n' after sending my XOAuth string...

python csv - not closing file

im reading a csv file and then writing a new one: import csv with open('thefile.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter = collections.defaultdict(int) for row in data: counter[row[11]] += 1 writer = csv.writer(open('/pythonwork/thefile_subset1.csv', 'w')) for row in data: if counter[row[11]] ...

confusing python urlencode order

okay, so according to http://docs.python.org/library/urllib.html "The order of parameters in the encoded string will match the order of parameter tuples in the sequence." except when I try to run this code: import urllib values ={'one':'one', 'two':'two', 'three':'three', 'four':'four', 'five':'five...

script as module and executable

I have a script in python that can be invoked from the command-line and uses optparse. script -i arg1 -j arg2 In this case I use (options, args) = parser.parse_args() to create options then use options.arg1 to get arguments. But I also want it to be importable as a module. from script import * function(arg1=arg1, arg2=arg2) I've m...

py2exe on PIL ImageStat.Stat throws Exception: argument 2 must be ImagingCore, not ImagingCore

I'm trying to create a .exe from a python program using py2exe, but when I run the .exe I get a log file with Exception in thread Thread-1: Traceback (most recent call last): File "threading.pyc", line 532, in __bootstrap_inner File "threading.pyc", line 484, in run File "webcam.py", line 66, in loop File "ImageStat.pyc", line 5...

python : getting rid of extra line:

import csv with open('thefile.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter = collections.defaultdict(int) for row in data: counter[row[10]] += 1 with open('/pythonwork/thefile_subset11.csv', 'w') as outfile: writer = csv.writer(outfile) for row in data: if counter[row[10]] >=...

Wrong ELF class - Python

Hi folks, I'm trying to install this library for LZJB compression. PyLZJB LINK The library is a binding for a C library, the file is located here PyLZJB.so Unfortunately by copying to the site-packages directory when import I get the "Wrong ELF class" error. >>> import PyLZJB Traceback (most recent call last): File "<stdin>", li...

python: inserting a whole line into a list

import csv with open('thefile.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter = collections.defaultdict(int) for row in data: counter[row[10]] += 1 with open('/pythonwork/thefile_subset11.csv', 'w') as outfile: writer = csv.writer(outfile) sample_cutoff=500 b[] for row in data: ...