python

Elegant way to compare sequences

Does python provide an elegant way to check for "equality" of sequences of different types? The following work, but they seem rather ugly and verbose for python code: def comp1(a, b): if len(a) != len(b): return False for i, v in enumerate(a): if v != b[i]: return False return True The following...

Understanding python imports

In the process of learning Django and Python. I can't make sense of this. (Example Notes:'helloworld' is the name of my project. It has 1 app called 'app'.) from helloworld.views import * # <<-- this works from helloworld import views # <<-- this doesn't work from helloworld.app import views # <<-- but this...

Need help with the class and instance concept in Python

I have read several documentation already but the definition of "class" and "instance" didnt get really clear for me yet. Looks like that "class" is like a combination of functions or methods that return some result is that correct? And how about the instance? I read that you work with the class you creat trough the instance but wouldnt...

Django not picking up changes to INSTALLED_APPS in settings.py

I'm trying to get South to work - it worked fine on my PC, but I'm struggling to deploy it on my webhost. Right now it seems that any changes I make to add/remove items from INSTALLED_APPS aren't being picked up by syncdb or diffsettings. I've added south to my list of INSTALLED_APPS, but the tables it needs aren't being created when I ...

finding substring

hi, Thanks in advance.I want to find all the substring that occurs between K and N,eventhough K and N occurs in between any number of times. for example a='KANNKAAN' OUTPUT; [KANNKAAN, KANN , KAN ,KAAN] ...

Replace in Python-* equivalent?

If I am finding & replacing some text how can I get it to replace some text that will change each day so ie anything between (( & )) whatever it is? Cheers! ...

Python library for XSS filtering?

Is there a good, actively maintained python library available for filtering malicious input such as XSS? ...

Dynamic function calls in Python using XMLRPC

I'm writing a class which I intend to use to create subroutines, constructor as following: def __init__(self,menuText,RPC_params,RPC_call): #Treat the params #Call the given RPC_call with the treated params The problem is that I want to call the function on the pattern "rpc.serve.(function name here)(params)", where rpc is a ser...

Python: Joining Multiple Lists to one single Sentence

Howdy, I've got multiple lists. For example: [u'This/ABC'] [u'is/ABC'] [u'not/ABC'] [u'even/ABC'] [u'close/ABC'] [u'to/ABC'] [u'funny/ABC'] [u'./ABC'] [u'O/ABC'] [u'noez/ABC'] [u'!/ABC'] I need to join this List to This/ABC is/ABC not/ABC even/ABC close/ABC to/ABC funny/ABC ./ABC O/ABC noez/ABC !/ABC How do I do that please? Yes,...

How do I include image files in Django templates?

I'm new to Django and I'm trying to learn it through a simple project I'm developing called 'dubliners' and an app called 'book'. The directory structure is like this: dubliners/book/ [includes models.py, views.py, etc.] dubliners/templates/book/ I have a JPG file that needs to be displayed in the header of each Web page. Where shoul...

Wxwidget Grid

Hi. I posted this in the mailing list, but the reply I got wasn't too clear, so maybe I'll have better luck here. I currently have a grid with data in it. I would like to know if there is a way to give each generated row an ID, or at least, associate each row with an object. It may make it more clear if I clarify what i'm doing. It is ...

Executing *nix binaries in Python

I need to run the following command: screen -dmS RealmD top Essentially invoking GNU screen in the background with the session title 'RealmD' with the top command being run inside screen. The command MUST be invoked this way so there can't be a substitute for screen at this time until the server is re-tooled. (Another project for anot...

python factory functions compared to class

Just working through learning python and started to look at nested/factory functions (simple example): def maker(N): def action(X): return X * N return action Are there any advantages of factory functions over creating a class? performance? memory? clean up? ...

Python OSError: [Errno 2]

I have the following code that is attempting to start each of the "commands" below in Linux. The module attempts to keep each of the 2 commands running if either should crash for whatever reason. #!/usr/bin/env python import subprocess commands = [ ["screen -dmS RealmD top"], ["screen -DmS RealmD top -d 5"] ] programs = [ subprocess.Po...

Why can I not view my Google App Engine cron admin page?

When I go to http://localhost:8080/_ah/admin/cron, as stated in Google's docs, I get the following: Traceback (most recent call last): File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 501, in __call__ handler.get(*groups) File "C:\Program Files\Google\google_appengine\google\appengine\ext\adm...

Auto-restart system in Python

I need to detect when a program crashes or is not running using python and restart it. I need a method that doesn't necessarily rely on the python module being the parent process. I'm considering implementing a while loop that essentially does ps -ef | grep process name and when the process isn't found it starts another. Perhaps thi...

Django, custom template filters - regex problems

I'm trying to implement a WikiLink template filter in Django that queries the database model to give different responses depending on Page existence, identical to Wikipedia's red links. The filter does not raise an Error but instead doesn't do anything to the input. WikiLink is defined as: [[ThisIsAWikiLink | This is the alt text]] Her...

How to use variables in SQL statement in Python?

Ok so I'm not that experienced in Python. I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where var1 is an integer, var2 & var3 are strings. How can I write the variable names without python including them as part of the query text? ...

Problem with my hangman game

I'm trying to learn python and I'm attempting a hangman game. But when I try and compare the user's guess to the word, it doesn't work. What am I missing? import sys import codecs import random if __name__ == '__main__': try: wordlist = codecs.open("words.txt", "r") except Exception as ex: print (ex) pri...

Issue with adding new properties to existing Google AppEngine data models / entities

In GAE, I have a model called Foo, with existing entities, and attempt to add a new property called memcached to Foo that takes datetime values for the last time this value was set to memcache. If I try to query and sort on this property, or even filter for entities that do not have a value for memcached, entities that haven't had a val...