python

Is there a faster alternative to BeautifulSoup?

I have a piece of code that basically extracts text from a page. It uses BeautifulSoup to first remove script, style and noscript tags and then find all the text in the page and return it. I don't want to do anything fancy, just get all the text in a page. However, it turns out that BeautifulSoup is rather slow, as it takes an appreciab...

make a change to an element within a list within a list

i am reading a csv file into a data: def get_file(start_file): #opens original file, reads it to array with open(start_file,'rb') as f: data=list(csv.reader(f)) i need to go through every row and add a value to row[1] like this. initially row[1] = 'Peanut', i need to add 'Butter' so the result would be row[1]='PeanutButter' ...

sqlachemy, says decimal is not defined?

Trying to make a column of type decimal: Column('cost', DECIMAL) Erorr, name 'DECIMAL' is not defined. SqlAlch seems to support decimal, am I missing an import? BTW, how do I also create a longtext column? I'm using mysql. ...

Django object extension / one to one relationship issues

Howdy. I'm working on migrating an internal system to Django and have run into a few wrinkles. Intro Our current system (a billing system) tracks double-entry bookkeeping while allowing users to enter data as invoices, expenses, etc. Base Objects So I have two base objects/models: JournalEntry JournalEntryItems defined as follows: ...

help on getting image src from a table cell using BeautifulSoup

So I have a html page that has a form, and a table inside the form that has rows of products. I got to the point now where I am looping through the table rows, and in each loop I grab all the table cells. for tr in t.findAll('tr'): td = tr.findAll('td') Now I want to grab the image src url from the first td. Html looks like: <t...

how do I halt execution in a python script?

Possible Duplicates: Programatically stop execution of python script? Terminating a Python script I want to print a value, and then halt execution of the script. Do I just use return? ...

Mac ports Mysql install

I completed my install on Leopard with Mac Ports. I also installed Mysqld via Mac Ports for use with python. I set the password for mysql on mysql start. Everything seemed to be fine except when I invoke mysql-start from the command line now I get this: mysql-start ***Password: Starting MySQL . SUCCESS! demetrius-fords-macbook-pro-17:~ ...

Solving AttributeErrors in nested attributes

I am writing a small mocking class to do some tests. But this class needs to support the idea of having nested attributes. This example should provide some insight to the problem: class Foo(object): def __init__(self): self.x = True From the above class, we can have: f = Foo() f.x I know I can add attributes falling ...

setting up mysql on Mac

I first installed Macports so it would be easier. Then installed mysql5,mysql5-server and py26-mysql. Everything went ok. When I typed: which mysql5 it returns `/opt/local/bin/mysql5 But when i try to enter the server: mysql5, an error is generated: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var...

Store Information In MySQL Database with Python

I am working on a huge project. I have been working on it for a while now, and decided to "up" the security on the way the software handles data. I already know how to encrypt and decrypt the data strings using DES encryption, but what I am not sure about is where to put that encrypted data. I would like to store everything in a MySQL da...

Can someone please explain this bit of Python code?

I started working in Python just recently and haven't fully learned all the nuts and bolts of it, but recently I came across this post that explains why python has closures, in there, there is a sample code that goes like this: y = 0 def foo(): x = [0] def bar(): print x[0], y def change(z): global y ...

Using BeautifulSoup, how to guard against elements not being found?

I am looping through table rows in a table, but the first 1 or 2 rows doesn't have the elements I am looking for (they are for table column headers etc.). So after say the 3rd table row, there are elements in the table cells (td) that have what I am looking for. e.g. td[0].a.img['src'] But calling this fails since the first few rows...

Django MySql setup

I set up Mysql5, mysql5-server and py26-mysql using Macports. I then started the mysql server and was able to start the prompt with mysql5 In my settings.py i changed database_engine to "mysql" and put "dev.db" in database_name. I left the username and password blank as the database doesnt exist yet. When I ran python manage.py syncdb...

How can I extract EDB (ms exchange storage file) to PST Under Linux? (preferably in Python)

I can extract and read messages from PST files using libpst , but i want to extract from edb files too (not online exchange server but from offline files). And in Linux. Any python lib or any kind for linux commandline tool should help. Thanks. ...

Object propert is an integer, have to use regex to clean input, looking for good style

I have some text that looks like: California(2342) My object has a property that I need to assign the value 2342 to. I'm looking for input on how to go about doing this, and guarding against any potential for errors in the input. c = SomeClass() c.count = re.compile(r'(\d*)').groups[0] Does that look ok? Or should I do an IF sta...

sqlachemy created mysql table, but I modified table now says 'unknown column url'

I added a url column in my table, and now sqlalchemy is saying 'unknown column url'. Why isn't it updating the table? There must be a setting when I create the session? I am doing: Session = sessionmaker(bind=engine) Is there something I am missing? I want it to update any table that doesn't have a property that I added to my Tabl...

Width of widget

In PyGTK what is the easiest way to figure out the dimensions of a widget? I know that it is easy to do with the gtk.Window object, but I can't find in the reference manual any way to get dimensions for the other objects. Any help is greatly appreciated thanks :D ...

Captcha solution which can be used with App Engine?

Is there a simple captcha solution which can be easily integrated with a form deployed using Google App Engine? I am using Python. ...

beautifulsoup, Find th with text 'price', then get price from next th

My html looks like: <td> <table ..> <tr> <th ..>price</th> <th>$99.99</th> </tr> </table> </td> So I am in the current table cell, how would I get the 99.99 value? I have so far: td[3].findChild('th') But I need to do: Find th with text 'price', then get next th tag's string value. ...

name and value lookup collection, loaded from a dropdown list using beautifulsoup

On my html page I have a dropdown list: <select name="somelist"> <option value="234234234239393">Some Text</option> </select> So do get this list I am doing: ddl = soup.findAll('select', name="somelist") if(ddl): ??? Now I need help with this collection/dictionary, I want to be able to lookup by both 'Some Text' and 2342342...