python

Parsing a document with BeautifulSoup while not-parsing the contents of <code> tags

I'm writing a blog app with Django. I want to enable comment writers to use some tags (like <strong>, a, et cetera) but disable all others. In addition, I want to let them put code in <code> tags, and have pygments parse them. For example, someone might write this comment: I like this article, but the third code example <em>could have...

GAE: what are the args of webapp.RequestHanderls get(*args)

I read the document http://code.google.com/appengine/docs/python/tools/webapp/requesthandlerclass.html but I cant find any information of the args parameters ...

Appending at run-time to a dictionary

I have a function named OpenAccount() which takes in the details from the User and appends it to my database dictionary. I have a database file(module) which is imported in my function file. I have a function called AppendRecord(key,**dictvalues) which appends values to my database file. However I am not able to call the function and ...

Transaction collision for sequential insert on Google App Engine. Why?

I am inserting a set of records on Google App Engine. I insert them in batch to avoid deadline exceptions. When there is a large number of records (for example 1k) I always receive an unexpected: Transaction collision for entity group with key datastore_types.Key.from_path(u'GroupModel', u'root', _app=u'streamtomail'). R...

Can't read appended data using pickle.load() method.

I have written two scripts Write.py and Read.py. Write.py opens friends.txt in append mode and takes input for name, email ,phone no and then dumps the dictionary into the file using pickle.dump() method and every thing works fine in this script. Read.py opens friends.txt in read mode and then loads the contents into dictionary using p...

Do all Mac OS X versions (above 10.4) have python preinstalled?

Do all Mac OS X versions (above 10.4) have python preinstalled? ...

python program that plays flash games for me

Yes, that's what I need to achieve, don't ask why:) So, since this is mainly OS dependent stuff I will be using Windows or Linux (whatever is simpler) Every second my program will: 1. do a screenshot, analyze the board and other stuff (this I can do) 2. then move the mouse to some XY and do a left-click that's all My main concern is: is...

Python: how to get the edge values from this list

Hi, I've got a python list like a = [ [[1,2,(3,4)],[1,2,(5)],[-3,3,(3)],[8,-2,(5)]], [[1,2,(3,4,5)],[-1,222,(3,4,5)],[99,2,(3)],[8,-2,(4,5)]] ] The tuple in each list element is total useless, please ignore that but delete them I want to get the max min value from each list element in each position The exepected output struc...

In mako template: call python function within html string

How do I do this in mako: <%! import cherrypy %> ... <link rel="stylesheet" href="${cherrypy.url('/media/layout.css')}" type="text/css" /> AttributeError: 'Undefined' object has no attribute 'url' edit Solved ...

how to implement the options/arguments for the command line functions in python

my python version is 2.4.3. Now I am developing a CLI with cmd module from python for a CD player. I have some classes like CDContainer (with method like addCD, removeCD, etc), CD (with method like play, stop, pause). Now, I want to add some options for the commands and also if the options inputs are not correct, the CLI could return pr...

Python: I am unable to comprehend the concept of a For Loop, apparently.

I've got a list of 400 numbers, and i want to but them in a 20x20 grid using Python. I've made a "2d array" (not really because Python doesn't support them, I've had to use a list of lists.) When i try to loop through and assign each subsequnt item to the next box in the grid, it fails. i end up assinging the last item in the list to ...

Does ftplib work in py2app?

Hi. I have a Python application that backs up to an afp server. I also need to get some information from an ftp server. When I just run my Python script from Terminal, it works just fine. But then if I compile it into an application using py2app, it gives me an error. py2app doesn't really say what the error is. If I comment out the lin...

Passing user data with glade/gtkbuilder

Hi all, I am a newbie of glade/pygtk. I am doing with some radio menu items. I created a signal handler on the signals tab, handler: on_group_menu_change user data: 7 what I expected is pass the int(or str) value 7 as user param to the handler. However, at startup, I found such warning: Could not lookup object 0 on signal gro...

calling function in django manager object from template

i am using django ratings application into this fields.py module,i added new function to RatingManager class which is get_bayesian see below http://github.com/dcramer/django-ratings/blob/master/djangoratings/fields.py def get_real_rating(self): """get_rating() Returns the unmodified average rating.""" if not (self.votes a...

web server returns "500 Internal Server Error" after sending this FormRequest using Scrapy

I construct the following FormRequest according to httpFox(Firefox addon)'s content. However, web server alway returns "500 Internal Server Error". Could someone help me on this? The original url is: http://www.intel.com/jobs/jobsearch/index_ne.htm?Location=200000008 Here is my spider's skeleton: class IntelSpider(BaseSpider): ...

List membership in Python without "in"

How to define a function is_member() that takes a value (i.e. a number, string, etc) x and a list of values a, and returns True if x is a member of a, False otherwise. (Note that this is exactly what the in operator does, but for the sake of the exercise I should pretend Python did not have this operator. This is what I've come up with,...

Appengine: How can I set another cookie when use google OAuth login logout.

I want set another cookie when user login, I use google.appenine.api.users.create_loginurl() to create the login url, it's /_ah/login, how can I extend this handler and add another cookie. The same as logout. ...

Is there something like PyFlakes for PHP?

Pretty straight forward question. I'm quite happy with my simple text editor but sometimes it'd be nice to run something like PyFlakes on my code before running to check for any obvious errors like undeclared variables or syntax errors. ...

How to pad with n characters in Python

I should define a function pad_with_n_chars(s, n, c) that takes a string 's', an integer 'n', and a character 'c' and returns a string consisting of 's' padded with 'c' to create a string with a centered 's' of length 'n'. For example, pad_with_n_chars(”dog”, 5, ”x”) should return the string "xdogx". ...

QListWidget and Multple Selection

Hi all, I have a regular QListWidget with couple of signals and slots hookedup. Everything works as I expect. I can update, retrieve, clear etc. But the UI wont support multiple selections. How do I 'enable' multiple selections for QListWidget? My limited experience with PyQt tells me I need to create a custom QListWidget by subclassi...