python

Overriding append method after inheriting from a Python List

Hi, I want to create a list that can only accept certain types. As such, I'm trying to inherit from a list in Python, and overriding the append() method like so: class TypedList(list): def __init__(self, type): self.type = type def append(item) if not isinstance(item, type): raise TypeError, 'item i...

cant send SMS vla libgmail - python

Hi All, i'm new to python , and trying to write a script in order to send SMS's , after quick googling i found this lib: libgmail, and successfully installed it , this is the code i use to send SMS: !/usr/bin/env python import libgmail ga = libgmail.GmailAccount("[email protected]", "password") myCellEmail = "[email protected]...

Mongodb - are reliability issues significant still?

Hi, I have a couple of sqlite dbs (i'd say about 15GBs), with about 1m rows in total - so not super big. I was looking at mongodb, and it looks pretty easy to work with, especially if I want to try and do some basic natural language processing on the documents which make up the databases. I've never worked with Mongo in the past, no w...

django Queryset with year(date) = '2010'

Hi there, I'm trying to build this query select * from m_orders where year(order_date) = '2010' the field order_date is a DateTime field. I just don't want to use raw sql queries here. Is it even possible to use e.g. MySQL functions in django quersets? ...

Writing unittests for a function that returns a hierarchy of objects

I have a function that performs a hierarchical clustering on a list of input vectors. The return value is the root element of an object hierarchy, where each object represents a cluster. I want to test the following things: Does each cluster contain the correct elements (and maybe other properties as well)? Does each cluster point to t...

Getting Python under control on OS X - setting up environment and libraries

After starting out with Python on Ubuntu Linux, I've now for a good while been doing most of my sustained work on the Mac, currently OS X 10.6. Unfortunately I've neglected to give proper attention to how Python is installed there and ended up with: Python 2.6.1 (Mac default version?) in /usr/bin (also, 2.5.4, which I'm not sure how it...

Python beginners guide.

Possible Duplicate: Python tutorial for total beginners? Which is the best site or a reference book to learn python programming? Kindly help... ...

Python .format - error

Hi, I'm trying to get the following to work in a Python interpreter, however it gives me an error and I cannot seem to find where my mistake is? (I'm a python newbie) >>> print 'THe value of PI is approx {}.'.format(math.pi) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object has no at...

Which is generally faster, a yield or an append?

I am currently in a personal learning project where I read in an XML database. I find myself writing functions that gather data and I'm not sure what would be a fast way to return them. Which is generally faster: yields, or several append()s within the function then return the ensuing list? I would be happy to know in what situati...

Can I get Python debugger pdb to output with Color?

I'm using PDB a lot and it seems it would be even better if I could add systax highlighting in color. Ideally, I'd like to have to the path to the code a lighter color. The line of actual code would be syntax highlighted. I'm using OS X and the Terminal app. Python 2.7 ...

Python ctypes - dll function accepting structures crashes

I have to access a POS terminal under ms windows xp. I am using python 2.7. The crucial function in the DLL I load that does the payment accepts two pointer to structures, but it crashes returning 1 (Communication error) but without further messages. Please note that when the payment function is called, not all the elements of POSData st...

Task Chaining with Cursor issue on app engine. Exception: Too big query offset. Anyone else get this issue?

Hi, I'm not sure if anyone else has this problem, but I'm getting an exception "Too big query offset" when using a cursor for chaining tasks on appengine development server (not sure if it happens on live). The error occurs when requesting a cursor after 4000+ records have been processed in a single query. I wasn't aware that offsets ...

What tricks do you use to avoid being tripped up by python whitespace syntax?

I'm an experienced programmer, but still a little green at python. I just got caught by an error in indentation, which cost me a significant amount of debugging time. I was wondering what experienced python programmers do to avoid creating such problems in the first place. Here's the code (Part of a much larger program) : class Wizvar(...

Python IDLE is not starting on Windows 7

I used to use Python 2.7 and then IDLE was working. I uninstalled it and installed Python 3.1. Right now Idle cannot launch. What should i do to get it running? NOTE: I tried c:\Python31\pythonw.exe c:\Python31\Lib\idlelib\idle.py i uninstalled 3.1 and installed back 2.7, not working neither... ...

How to make GtkListStore store object attribute in a row?

I'w trying to keep at ListStore non-text objects using snippet I found. These are the objects: class Series(gobject.GObject, object): def __init__(self, title): super(Series, self).__init__() self.title = title gobject.type_register(Series) class SeriesListStore(gtk.ListStore): def __init__(self): super(SeriesListStore, self)....

reason why there is no "if Empty" in python

the zen of python says "Explicit is better than implicit." i find that an is Empty to check whether some sequence is empty is so much more explicit than implicit booleanness if some_sequence is Empty: some_sequence.fill_sequence() compare with if not some_sequence: some_sequence.fill_sequence() this gets even more confusing wi...

Python' smtplib works regularly but not when executing via cron

I have python code that looks like below. It works fine when executed manually. But when executed via a cronjob, the email is not being sent. Here is the code: msg = MIMEMultipart() msg['From'] = sender msg['To'] = to msg['Subject'] = subject msg.attach(MIMEText(message)) mailServer = smtplib.SMTP("smtp.gmail.com", 587) mailServer.ehl...

Python psycopg2 error when changing environment to os x

Hi guys, I have this error when i perform the following task, results = db1.executeSelectCommand(siteSql, (),) TypeError: unbound method executeSelectCommand() must be called with dbConnn instance as first argument (got str instance instead) My code is as follows: class dbConnn: db_con = None execfile("/Users/usera/Do...

Python Module Importing Issues

I run Windows 7, and I can import built-in modules, but when I save my own script and try to import it in IDLE, I get an error saying that the module doesn't exist. I use the Python text editor found by clicking "File" and "New Window" from the Python Shell. I save it as a .py file within a Module folder I created within the Python dire...

getting all child nodes' values of the current node

I am trying to retrieve all of the values in the div. For example: <div>xyz <span> abc </span> def</div> This is the code the_page="<div>xyz <span> abc </span> def</div>" doc = libxml2dom.parseString(the_page, html=1) divs=doc.getElementsByTagName("div") print divs[0].firstChild.nodeValue This only prints "xyz". I tried to just do...