Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用google app从字符串中检索字符_Python_Google App Engine - Fatal编程技术网

Python 使用google app从字符串中检索字符

Python 使用google app从字符串中检索字符,python,google-app-engine,Python,Google App Engine,我在我的google应用程序中编写了一个小python程序。我用它从字符串中提取特定字符,就像这样 +CMGL:14,“记录读取”,“+918000459019”,“11/11/04,18:27:53+22” C " 我正在使用拆分函数,但它没有拆分字符串。有什么线索吗? 它给了我这种[u'+CMGL:14,“REC READ”,“+918000459019”,“11/11/04,18:27:53+22”\n C']结果 def prog (self,strgs): self.respo

我在我的google应用程序中编写了一个小python程序。我用它从字符串中提取特定字符,就像这样 +CMGL:14,“记录读取”,“+918000459019”,“11/11/04,18:27:53+22” C " 我正在使用拆分函数,但它没有拆分字符串。有什么线索吗? 它给了我这种[u'+CMGL:14,“REC READ”,“+918000459019”,“11/11/04,18:27:53+22”\n C']结果

def prog (self,strgs):
    self.response.out.write(strgs)
    temp1= strgs
    self.response.out.write(temp1)
    message_split=temp1.split('\n')
    #self.response.out.write(message_split)
    temp=message_split
    self.response.out.write(temp)
    message_split_second=strgs.split(',')
    m_list=message_split[1:]
    self.response.out.write(message_split_second)
    collect_strings=''
    for j in m_list:
        collect_strings=collect_strings+j

    message_txt=collect_strings

    message_date=message_split_second[0]
    message_date=message_date.replace('"',"")
    dates=message_date

    message_time=message_split_second[0]
    message_time=message_time.split('/n')
    message_time=message_time[0]
    message_time=message_time.replace('"',"")
    temp=message_time.split('+')
    message_time=temp[0]
    times=message_time

    cell_number=message_split_second[0]
    cell_number=cell_number.replace('"',"")
    cellnum=cell_number
    return message_txt,dates,times,cellnum

函数第一部分中的拆分应该起作用。下面是我刚刚在Python 2.6中做的一个实验:

>>> s = '+CMGL: 14,"REC READ","+918000459019",,"11/11/04,18:27:53+22"\n C '
>>> s.split('\n')
['+CMGL: 14,"REC READ","+918000459019",,"11/11/04,18:27:53+22"', ' C ']
>>> s.split(',')
['+CMGL: 14', '"REC READ"', '"+918000459019"', '', '"11/11/04', '18:27:53+22"\n C ']
如果您的
self.response.out.write调用没有执行相同的操作,请尝试将函数缩减为显示异常行为的最短的操作。并检查您是否确切知道作为
strgs
参数传入的内容


我看不出其余部分有什么错,除了在某一点上,当您可能打算使用
\n

时,您尝试在
/n
上拆分,如果您不发布代码,我们将无能为力。您似乎在尝试解析CSV文件。你知道这个模块吗?@PetrViktorinIt是一条从手机上读取的短信。我已经在控制台上测试了整个代码,它工作得很好,但当我在应用程序中实现它时,它没有显示出适当的结果。