Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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中使用字符串中的冒号_Python_Google App Engine - Fatal编程技术网

在python中使用字符串中的冒号

在python中使用字符串中的冒号,python,google-app-engine,Python,Google App Engine,我正在使用python 2.6.5为google app engine开发一个应用程序——我对python不太熟悉,但我正在学习 我正在尝试将url放入字符串中,以便variable=“string” 然后我把字符串打印出来。问题是,如果冒号(在http之后)在字符串中,我不会得到任何输出,我也不知道为什么 我尝试用以下方法来转义字符串: “”“http://domain.name“”“ r“http://domain.name" “http\://domain.name” “http\://

我正在使用python 2.6.5为google app engine开发一个应用程序——我对python不太熟悉,但我正在学习

我正在尝试将url放入字符串中,以便variable=“string”

然后我把字符串打印出来。问题是,如果冒号(在http之后)在字符串中,我不会得到任何输出,我也不知道为什么

我尝试用以下方法来转义字符串:

  • “”“http://domain.name“”“
  • r“http://domain.name"
  • “http\://domain.name”
  • “http\://domain.name”
  • “http\\\//domain.name”
  • “http://domain.name”
它们似乎都不管用,我也不知道还有什么好尝试的

背景是这样的

variables.py是:

...
HOST_URL = "http://domain.name"
...
logout.py示例

import variables
import sys

...

class Logout(webapp.RequestHandler):
    """ RequestHandler for when a user wishes to logout from the system."""
    def post(self):
        self.get()

    def get(self):
        print(variables.HOST_URL)
        print('hi')
        self.redirect(variables.HOST_URL)
        sys.exit()

在文件functions.py中

import variables
import sys

...

def sendhome(requesthandler)
    print 'go to '+variables.HOST_URL
    requesthandler.redirect(variables.HOST_URL)
    sys.exit()
从如下上下文调用:

from functions import sendhome

...

class Logout(webapp.RequestHandler):
    """ RequestHandler for when a user wishes to logout from the system."""
    def post(self):
        self.get()

    def get(self):
        sendhome(self)
任何帮助都将不胜感激


谢谢

如果我没有大错特错的话,GAE使用WSGI,您不只是打印东西,您应该返回一个正确的HTTP响应对象(它不是PHP)

我猜如果您使用firefox+firebug访问页面,并查看网络->标题,您将看到浏览器将http:作为http标题,其值为“//domain.name”


编辑:顺便问一下,您是否应该使用“self.response.out.write”而不是“print”?

如果我没有大错特错,GAE使用WSGI,您不只是打印东西,您应该返回一个正确的HTTP响应对象(它不是PHP)

我猜如果您使用firefox+firebug访问页面,并查看网络->标题,您将看到浏览器将http:作为http标题,其值为“//domain.name”


编辑:顺便问一下,您是否应该使用“self.response.out.write”而不是“print”?

问题在于调用print或redirect后的sys.exit()

问题在于调用print或redirect后的sys.exit()

您是说“print”“”没有打印出整个字符串吗?这似乎不太可能。直到我从下面删除了sys.exit()之后才出现这种情况。我不知道为什么会阻止打印URL而不是HI,但它确实做到了。您可能也想考虑使用Python 2.5——尽管与您的问题无关,但这是一个很好的实践。因为,您是说“打印”“不打印出整个字符串吗?”这似乎不太可能。直到我从下面删除了sys.exit()之后才出现这种情况。我不知道为什么会阻止打印URL而不是HI,但它确实做到了。您可能也想考虑使用Python 2.5——尽管与您的问题无关,但这是一个很好的实践,因为它是在您要求的上下文中。sys.exit()google.appengine.ext.webapp.WSGIApplication比CGI好得多。因此,如果调用sys.exit(),我假设使用webapp.RequestHandler设置的头不会发送。有什么办法可以绕过它吗?基本上,我想防止任何进一步的执行,如果重定向发生返回将使您退出函数或方法调用。sys.exit()google.appengine.ext.webapp.WSGIApplication比CGI好得多。因此,如果调用sys.exit(),我假设使用webapp.RequestHandler设置的头不会发送。有什么办法可以绕过它吗?基本上,我想防止任何进一步的执行,如果重定向发生返回将使您退出函数或方法调用。