Python 在谷歌应用程序引擎中打印新行

Python 在谷歌应用程序引擎中打印新行,python,google-app-engine,newline,new-operator,Python,Google App Engine,Newline,New Operator,当我使用文本属性上传多行数据,然后将其打印回来时,它只打印一行。。。。 我上传ascii六边形码。。。。 因此,回车是0x10,但当从数据存储中以ascii格式打印它时,不会插入新行。。。 相反,它打印为一行 self.response.out.write("\n") 你要把数据打印回哪里?如果它位于HTML内部(除非它在web浏览器中被包围),请尝试使用“查看页面源代码”查看结果 import cgi #import codecs print 'Content-Type: text/plai

当我使用文本属性上传多行数据,然后将其打印回来时,它只打印一行。。。。 我上传ascii六边形码。。。。 因此,回车是0x10,但当从数据存储中以ascii格式打印它时,不会插入新行。。。 相反,它打印为一行

self.response.out.write("\n")

你要把数据打印回哪里?如果它位于HTML内部(除非它在web浏览器中被
包围),请尝试使用“查看页面源代码”查看结果

import cgi
#import codecs
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

import operator

class Vault(db.Model):
    username=db.StringProperty()
    filename=db.StringProperty()
    data=db.TextProperty()

op=""
op1=""
username=""
filename=""


class MainPage(webapp.RequestHandler):
    def get(self):
        stri=""
        global username
        global filename
        stri=""
        username = self.request.get("name")
        filename=self.request.get("filename")
        mac=self.request.get("mac")
        mac=mac.replace(':','')
        q=db.GqlQuery("SELECT * FROM Vault WHERE filename=:1",filename)
        for vault in q:
            stri=cgi.escape(vault.data)
        s=0
        e=12
        cycle=len(stri)/12
        z=""
        for j in range(cycle):
            plain=stri[s:e]
            #print plain
            s1=0
            s2=2
            for i in range(6):
                x=int(plain[s1:s2],16)
                y=int(mac[s1:s2],16)
                s1=s1+2
                s2=s2+2
                z+=chr(operator.xor(x,y))
            mac=plain
            s=s+12
            e=e+12
        print z

application = webapp.WSGIApplication([('/dec', MainPage)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

如果这里的换行符看起来正确,那么@bgporter有正确的解决方案。

@bgporter:我正在加密数据并将十六进制ascii值存储在数据存储中。当我将十六进制解密为ascii并使用self.response.out.write(z)打印它时[其中z包含解密的ascii值]它以直线打印…@HariHaraSudhan这不重要,除非您的未加密函数被破坏。正如@Hugh在其响应中所建议的那样——使用浏览器的视图源查看响应。如果它看起来正确,则浏览器将内容解释为HTML,忽略换行符。您可以将Content-t设置为键入您对
text/plain
的回复的标题以强制解决问题。@HariHaraSudhan-您是否将响应的内容类型设置为text/plain?@bgporter&wooble:我这样做了,但当我在保存python文件后第一次尝试时,它给出了换行符。当我再次请求时,它会返回到相同的onld单行样式添加初始头的代码只有在GAE第一次导入此模块时才执行。将这些代码向下移动到
get()中
方法。当数据写入文件或查看页面源代码时,会看到换行符……但在html页面中看不到换行符。请不要在WSGI应用程序中使用
print
。使用
self.response.out.write
,永远不要
print
。代码顶部的语句也不会像您认为的那样执行.
self.response.out.write(myString.replace("\n", "<br />"))