代码之家  ›  专栏  ›  技术社区  ›  Dhushyanth

list()在谷歌应用引擎中不起作用?

  •  0
  • Dhushyanth  · 技术社区  · 16 年前

    我正在尝试使用App Engine中的set函数,准备一个包含唯一元素的列表。我在编写Python代码时遇到了一个问题,该代码在Python Shell中运行良好,但在App Engine+Django中运行不佳

    import re
    value='   r.dushaynth@gmail.com, dash@ben,,  , abc@ac.com.edu    '
    value = value.lower()
    value = list(set(re.split('^\s*|\s*,+\s*|\s*$', value)))
    if (value[0] == ''):
        value.remove('')
    print value       
    

    ['dash@ben', 'abc@ac.com.edu', 'r.dushaynth@gmail.com']
    

    现在,当我在App Engine的views.py文件中执行等效操作时:

    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='   r.dushaynth@gmail.com, dash@ben,,  , abc@ac.com.edu    '
        value = value.lower()
        value = list(set(re.split('^\s*|\s*,+\s*|\s*$', value)))
        if (value[0] == ''):
            value.remove('')
    
    
        return render_to_response('sc-actonform.html', {
            'value': value,
        })
    

    我在转到相应页面(粘贴回溯)时遇到此错误:

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

    评论出来:

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

    我在相应的网页上得到了所需的输出:

    r.dushaynth@gmail.com, dash@ben,, , abc@ac.com.edu
    

    谢谢!

    1 回复  |  直到 6 年前