python

Comparing list item values to other items in other list in Python

I want to compare the values in one list to the values in a second list and return all those that are in the first list but not in the second i.e. list1 = ['one','two','three','four','five'] list2 = ['one','two','four'] would return 'three' and 'five'. I have only a little experience with python, so this may turn out to be a ridiculo...

Using Djangos ImageField to upload an image, rename it to a random filename and create thumbnail

Hay guys, I've wrote a simple upload method for my pictures class Picture(models.Model): path = models.CharField(max_length=200) filename = models.CharField(max_length=200) car = models.ForeignKey('Car') thumb_path = models.CharField(max_length=200) created_on = models.DateField(auto_now_add=True) updated_on = mo...

OAuth with Twitter script in Python is not working.

Hello. I'm writing a script of OAuth in Python. For testing this, I use Twitter API. But it is not working well. def test(): params = { "oauth_consumer_key": TWITTER_OAUTH_CONSUMER_KEY, "oauth_nonce": "".join(random.choice(string.digits + string.letters) for i in xrange(7)), "oauth_signature_met...

getting specific xml nodes attributes

Hello. This might be a newbie question :) but it's irritating me since I'm new to XML. I have the following xml file: <assetsMain> <assetParent type='character' shortName='char'> <asset> pub </asset> <asset> car </asset> </assetParent> <assetParent type='par' shortName='pr'> <asset> camera ...

fabric python install problem

Just installed fabric, trying to use to same fabfile that works on a different server, getting this error here: Traceback (most recent call last): File "/var/lib/python-support/python2.6/fabric.py", line 1211, in main load(fabfile, fail='warn') File "/var/lib/python-support/python2.6/fabric.py", line 467, in load execfile(fi...

PJSIP and Python problem

I want to do with language python Softphone Application. I used to PJSIP. I tried follow this website http://trac.pjsip.org/repos/wiki/Python_SIP/Build_Install I have been following the installation of Windows. Starting build with minGW. Then any change to build from Visual Studio 2008 and downgrade python from 2.6 to 2.4 according to th...

Python - Check network map

I'm looking for some help on logic, the code is not very Pythonic I'm still learning. We map the Z: drive to different locations all the time. Here is what I'm trying to accomplish 1: Check for an old map on Z: say \192.168.1.100\old 2: Map the new location to Z: say \192.168.1.200\new 3: Make sure the new Z: mapping exists and is stil...

How to extract unique values from nested dictionary with Python?

I like to make a function that puts out a list of all values that are in a dictionary. The list must not contain any double items. The list also has to be in alphabetical order. I'm kind of new to Python, I can't come any further than printing all the values of the dictionary with the iteritems() function. The dictionary is: critics={'...

RSS feed parser library in Python

Hello, I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback? ...

How to count both sides of many-to-many relationship in Google App Engine

Consider a GAE (python) app that lets users comment on songs. The expected number of users is 1,000,000+. The expected number of songs is 5,000. The app must be able to: Give the number of songs a user has commented on Give the number of users who have commented on a song Counter management must be transactional so that they alway...

Spawning WSGI example (practical approach to WSGI)

Hi. I'm trying to understand how WSGI works. I know I could read the specs, but I'd still want to know how do I create a spawning application? A complete "hello world". Could someone show me an example? With everything, file naming, creating the module, running it. Every and each step. Thanks. (NB: while spawning seems a great piece of...

how to measure execution time of functions (automatically) in Python

Hello! I need to have a base class which I will use to inherit other classes which I would like to measure execution time of its functions. So intead of having something like this: class Worker(): def doSomething(self): start = time.time() ... do something elapsed = (time.time() - start) print "doSo...

Uncatchable exception in Python

The issue came up in this question, which I'll recapitulate in this code: import csv FH = open('data.csv','wb') line1 = [97,44,98,44,99,10] line2 = [100,44,101,44,102,10] for n in line1 + line2: FH.write(chr(n)) FH.write(chr(0)) FH.close() import _csv FH = open('data.csv') reader = csv.reader(FH) for line in reader: if '\0' in...

markdown/(X)HTML to BBCode converter python module

Is there any (X)HTML to BBCode coverter python module out there? I'd like to migrate my website forum from markdown to BBCode but I didn't found out any simple way. One option is to convert the markdown text to (X)HTML using the built in django markup module and then convert it again to BBCode. Well, I realized that find a (X)HTML to BB...

How does one run Spawning with Django within a virtualenv?

Because of the way Eventlet, which Spawning depends on, installs itself, it can't be installed into a virtualenv. The following error (wrapped for readability) illustrates: Running eventlet-0.9.4/setup.py -q bdist_egg --dist-dir \ /tmp/easy_install-m_s75o/eventlet-0.9.4/egg-dist-tmp-fAZK_u error: SandboxViolation: chmod('/home/myuser/...

Group form fields in django?

Hello, Is there a way in Django to group some fields from a ModelForm? For example, if there's a model with fields like: age, gender, dob, q1, q2, q3 and a form is created based in such Model, can I group the fields like: info_fields = (age, gender, dob) and response_fields = (q1, q2, q3). This would be helpful to display all fields in ...

equivalent ruby library as python's twisted?

Is there an equivalent to Python's Twisted available in Ruby to abstract common networking protocols and make dealing with TCP/IP sockets generally easier? ...

Python: Read configuration file with multiple lines per key

Hi, I am writing a small DB test suite, which reads configuration files with queries and expected results, e.g.: query = "SELECT * from cities WHERE name='Unknown';" count = 0 level = 1 name = "Check for cities whose name should be null" suggested_fix = "UPDATE cities SET name=NULL WHERE name='Unknown';...

is there a simple to get group names of a user in django

for django.contrib.auth.User and django.contrib.auth.Group i am doing like this for g in request.user.groups: l.append(g.name) Got an error TypeError at / 'ManyRelatedManager' object is not iterable Request Method: GET Request URL: http://localhost:8000/ Exception Type: TypeError Exception Value: 'ManyRelatedManager'...

How to go from list of words to a list of distinct letters in Python

Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence. Here's my current code: words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lower() for x in words.split(' ')] # Now conver...