list() doesn't work in appengine?

Go To


i am trying to use set function in appengine, to prepare a list with unique elements. I hit a snag when i wrote a python code which works fine in the python shell but not in appengine + django

This is what i intend to do(ran this script in IDLE):

import re
value=', dash@ben,,  ,    '
value = value.lower()
value = list(set(re.split('^\s*|\s*,+\s*|\s*$', value)))
if (value[0] == ''):
print value       

The desired output is(got this output in IDLE):

['dash@ben', '', '']

Now when i do something equivalent in my file in appengine :

import os
import re
import django
from django.http import HttpResponse
from django.shortcuts import render_to_response # host of other imports also there
def add(request):

    value=', dash@ben,,  ,    '
    value = value.lower()
    value = list(set(re.split('^\s*|\s*,+\s*|\s*$', value)))
    if (value[0] == ''):

    return render_to_response('sc-actonform.html', {
        'value': value,

I get this error while going to the appropriate page(pasting the traceback):

Traceback (most recent call last):
File "G:\Dhushyanth\Google\google_appengine\lib\django\django\core\handlers\" in get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "G:\Dhushyanth\development\AppengineProjects\trunk_sanjhachoolha\sandbox\dushyanth\sanjhachoolha\" in add
  148. value = list(set(re.split('^\s*|\s*,+\s*|\s*$', value)))
File "G:\Dhushyanth\development\AppengineProjects\trunk_sanjhachoolha\sandbox\dushyanth\sanjhachoolha\" in list
  208. return respond(request, None, 'sc-base', {'content': responseText})
File "G:\Dhushyanth\development\AppengineProjects\trunk_sanjhachoolha\sandbox\dushyanth\sanjhachoolha\" in respond
  115. params['sign_in'] = users.create_login_url(request.path)

  AttributeError at /sanjhachoolha/acton/add
  'set' object has no attribute 'path'

on commenting out:

#value = list(set(re.split('^\s*|\s*,+\s*|\s*$', value)))

I get the desired output in the appropriate webpage:, dash@ben,, ,

I am sure the list() is the root of my troubles. CAn anyone suggest why this is happening. Please also suggest alternatives. The aim is to remove duplicates from the list.


2009-06-16 09:33
by Dhushyanth
Sorry ..the list() is the trouble..The question is still valid thoug - Dhushyanth 2009-06-16 09:39


It seems like you implemented your own list() function. Its return statements should be at line 208 of your file ( You should rename your list() function to something else (even list_()).

EDIT: Also you can change you regexp, like this:

import re
value=', dash@ben,,  ,    '
value = value.lower()

#value = list(set(re.split('^\s*|\s*,+\s*|\s*$', value)))
#if (value[0] == ''):
#    value.remove('')

value = set(re.findall(r'[\w\d\.\-_]+@[\w\d\.\-_]+', value))

print value

re.findall() returns a list of all matched occurences.

2009-06-16 09:51
by uolot
thanks...that seems to be the cause of the problem. silly m - Dhushyanth 2009-06-16 10:02