python

Python: How to get last 9 items of a list?

I need the last 9 numbers of a list and I'm sure there is a way to do it with slicing but I can't seem to get it. I can get the first 9: num_list[0:9] Any help would be great. Thanks in advance :) ...

Getting pywin32 excelAddin.py working on Excel 2007

I'm trying get pywin32 excelAddin.py demo script on winXP MS Office Excel 2007, python 2.5.4. Though the Com add-in registers itself succesfully and is displayed in "com add-ins" list in Excel, it does not work. Only error feedback i get is on the "Load behaviour" line in excel's "com add-ins" dialog, says "Not loaded. A runtime error ...

pir sensors + arduino + python + email alerts

hello we are working on a project for school, we have 2 pir motion sensors running off an arduino micro controller, we able to view the output of the serial port in both ardunio IDE and python IDLE what we want to do next is after about 30 seconds of motion being detected, send out an email alert, being that we don't have ethernet capa...

How to tell whether a file is executable on Windows in Python?

I'm writing grepath utility that finds executables in %PATH% that match a pattern. I need to define whether given filename in the path is executable (emphasis is on command line scripts). Based on "Tell if a file is executable" I've got: import os from pywintypes import error from win32api import FindExecutable, GetLongPathName def ...

Workflow for configuring apache on a webfaction account via ssh and ftp. (django/python)

I'm new at this, however, when it comes to configuring mod_python/apache or wsgi/apache I suffer. I've been able to use the python debugger tool.. pdb.set_trace() to success, especially when using the django development server, i.e. it out puts to the terminal all of the server activity, including the pdb interface. So, how does one do...

Anyone have a simple example for webkit?

Does anyone know of a simple "Hello World" example for using the Webkit library in Python? I have a GTK window, and inside I want to put Webkit. With Python/mozembed (Mozilla/Gecko), this is simple: mozembed = gtkmozembed.MozEmbed() mozembed.load_url('http://google.com/') ..and I have already created my browser, how do I do this with...

Python xml ElementTree from a string source?

The ElementTree.parse reads from a file, how can I use this if I already have the XML data in a string? Maybe I am missing something here, but there must be a way to use the ElementTree without writing out the string to a file and reading it again. xml.etree.elementtree ...

Python: Abstract Base Class and ZopeInterface

What's the point of both? When do you think it's appropriate to use either? ...

Why can I not paste the output of Pythons REPL without manual-editing?

A huge amount of example Python code shows the output of the Python REPL, for example: >>> class eg(object): ... def __init__(self, name): ... self.name = name ... def hi(self): ... print "Hi %s" % (self.name) ... >>> greeter = eg("Bob") >>> greeter.hi() Hi Bob >>> Now, the obvious thing you want to do...

Provide discount to preferred customer with Satchmo?

I am new to Satchmo -- picked it up because I needed payment processing for site subscriptions and physical product. My site will have two classes of users: paid subscribers and free users. Both can order a physical product. Paid subscribers get an automatic discount on all orders. I don't see a configuration for this in the admin. (D...

Multiple overlapping plots with independent scaling in Matplotlib

I currently have code that calls matplotlib.pylab.plot multiple times to display multiple sets of data on the same screen, and Matplotlib scales each to the global min and max, considering all plots. Is there a way to ask it to scale each plot independently, to the min and max of that particular plot? ...

How do I forward a complete email without downloading attachments?

Hello (and thanks in advance!) I'm working in Python and I got IMAP and SMTP to work with my Gmail account. I now need to forward select messages to another account (after reading their body). How do I do this without downloading the attachments and recreating the entire message? Thanks! Tal. ...

How can I know python's path under windows?

I want to know where is the python's installation path. For example: C:\Python25 But however, I have no idea how to do. How can I get the installation path of python? Thanks. ...

python, regex split and special character

How can I split correctly a string containing a sentence with special chars using whitespaces as separator ? Using regex split method I cannot obtain the desired result. Example code: # -*- coding: utf-8 -*- import re s="La felicità è tutto" # "The happiness is everything" in italian l=re.compile("(\W)").split(s) print " s> "+s prin...

Why can't Python's raw string literals end with a single backslash?

Technically, any odd number of backslashes, as described in the docs. >>> r'\' File "<stdin>", line 1 r'\' ^ SyntaxError: EOL while scanning string literal >>> r'\\' '\\\\' >>> r'\\\' File "<stdin>", line 1 r'\\\' ^ SyntaxError: EOL while scanning string literal It seems like the parser could just treat bac...

Trapping MySQL Warnings In Python

I would like to catch and log MySQL warnings in Python. For example, MySQL issues a warning to standard error if you submit 'DROP DATABASE IF EXISTS database_of_armaments' when no such database exists. I would like to catch this and log it, but even in the try/else syntax the warning message still appears. The try/except syntax does ca...

socket trouble in python

I have a server that's written in C, and I want to write a client in python. The python client will send a string "send some_file" when it wants to send a file, followed by the file's contents, and the string "end some_file". Here is my client code : file = sys.argv[1] host = sys.argv[2] port = int(sys.argv[3]) sock = socket.socket(soc...

File handling in Django when posting image from service call

Hi all, I am using PyAMF to transfer a dynamically generated large image from Flex to Django. On the Django side i receive the encodedb64 data as a parameter: My Item model as an imagefield. What i have trouble to do is saving the data as the File Django Field. def save_item(request, uname, data): """ Save a new item """ i...

Python - test that succeeds when exception is not raised

I know about unittest Python module. I know about assertRaises() method of TestCase class. I would like to write a test that succeeds when an exception is not raised. Any hints please? ...

wxPython auinotebook.GetSelection() return index to the first page.

Why do 'GetSelection()' return the index to the first page and not the last created in 'init' and 'new_panel'? It do return correct index in the 'click' method. The output should be 0 0 1 1 2 2, but mine is 0 0 0 0 0 0. Running latest version of python and wxpython in ArchLinux. Ørjan Pettersen #!/usr/bin/python #12_aui_notebook1.py...