今天就跟大家聊聊有关python语法中导入import与from时的代码怎么编写,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
import cgi import datetime import wsgiref.handlers from google.appengine.ext import db from google.appengine.api import users from google.appengine.ext import webapp
创建一个模块,相当于一个数据表,也相当于一个类
class Greeting(db.Model): author = db.UserProperty() content = db.StringProperty(multiline=True) date = db.DateTimeProperty(auto_now_add=True)
MainPage也是类吧,参数似乎是继承的意思
class MainPage(webapp.RequestHandler): def get(self): self.response.out.write('') greetings = db.GqlQuery("SELECT * " "FROM Greeting " "ORDER BY date DESC LIMIT 10") for greeting in greetings: if greeting.author: self.response.out.write('%s wrote:' % greeting.author.nickname()) else: self.response.out.write self.response.out.write(' %s ' % cgi.escape(greeting.content))
编码self.response.out.write("""
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('')
greetings = db.GqlQuery("SELECT * "
"FROM Greeting "
"ORDER BY date DESC LIMIT 10")
for greeting in greetings:
if greeting.author:
self.response.out.write('%s wrote:' % greeting.
author.nickname())
else:
self.response.out.write
self.response.out.write('
%s
' %
cgi.escape(greeting.content))
双引号里使用双引号的方法action设定为url
""") # class Guestbook(webapp.RequestHandler): def post(self): greeting = Greeting()
看完上述内容,你们对python语法中导入import与from时的代码怎么编写有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注编程网行业资讯频道,感谢大家的支持。