我有一个关于拆分main.py文件的问题.
现在,我在main.py中有所有内容.我没有其他.py文件.在到达我想编辑的部分之前,我总是需要滚动长行代码.
我该如何拆分?(我将有超过20页,所以这意味着如果我不拆分它,main.py将是巨大的.
PS:另外,我注意到我每次都必须设置模板值,模板路径和调用template.render.有什么方法可以缩短它们吗?
码:
# everything here in main.py
class MainPage(webapp.RequestHandler):
def get(self):
# Models are queried here, results transferred to template_values
template_values = {
'value1': value1,
'value2': value2,
'value3': value3,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Page2(webapp.RequestHandler):
def get(self):
# Models are queried here, results transferred to template_values
template_values = {
'value1': value1,
'value2': value2,
'value3': value3,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Page3(webapp.RequestHandler):
def get(self):
# Models are queried here, results transferred to …Run Code Online (Sandbox Code Playgroud) 我的Feed模型中有十个实体(这是一个App Engine模型)
class Feed(db.Model):
sometext = db.StringProperty()
timestamp = db.DateTimeProperty(auto_now=True)
list_of_keys = ["key1","key2","key3".... "key10"]
Run Code Online (Sandbox Code Playgroud)
所以我使用db.key()方法调用我的实体:
feeds = db.keys(list_of_keys)
# this loop below prints the feed
for feed in feeds:
print humanizeTimeDiff(feed.timestamp)
# humanizeTimeDiff is a function to change the raw timestamp into a human friendly
# version: eg-> 10 mins ago, 20 seconds ago
Run Code Online (Sandbox Code Playgroud)
但现在,如何根据时间戳对Feed进行排序?(我希望最新的饲料位于顶部,最旧的饲料位于底部)
我可以在原始时间戳上使用的任何排序函数?(我的粗略计划是根据原始时间戳进行排序,然后将时差差异化)
PS:我不打算使用GQL查询根据时间戳查询我的实体,因为我以键列表的形式获取输入.使用db.key()是一种更快的方法.
希望我提供足够的信息.希望听到您的想法/解决方案.
我有一个游戏系统的用户模型.需要每小时增加100点.
# the key_name is the userid in this case
class User(db.Model):
points = db.IntegerProperty(default=0)
Run Code Online (Sandbox Code Playgroud)
那么应该准备一个跨所有实体进行GQL查询的处理程序吗?(500k - 100万用户实体会不会有点慢?)
例如:
users = User.all() # if i'm not mistaken, only 1000 queries can be done.
for user in users:
user.points += 100
db.put(user)
Run Code Online (Sandbox Code Playgroud)
我想使用任务队列,并使用分片计数器来克服1000分,我可以将其拉下来
但话又说回来,为什么我不采取用户上次登录的时间差,如果是N个小时,我会奖励用户N*100分?这应该减少我的应用程序的负载.
例如:class User(db.Model):lastlogin = db.DateTimeProperty()points = db.IntegerProperty(default = 0)
你们有什么感想?
我有两个单独的名单
list1 = ["Infantry","Tanks","Jets"]
list2 = [ 10, 20, 30]
Run Code Online (Sandbox Code Playgroud)
所以实际上,我有10个步兵,20个坦克和30个喷气机
我想创建一个类,以便最后,我可以这样称呼:
for unit in units:
print unit.amount
print unit.name
#and it will produce:
# 10 Infantry
# 20 Tanks
# 30 Jets
Run Code Online (Sandbox Code Playgroud)
所以我们的目标是将list1和list2组合成一个可以轻松调用的类.
在过去3小时内尝试了很多组合,没有什么好结果:(
计划写一个死的简单的android应用程序
它基本上是一个图像查看应用程序.
我预装了10张图片.每次滑动(向左或向右)都会导致图像切换.
就是这个!
所以我看了很多android网站,找不到这方面的单一教程.Anddev.org提供了有关显示图形的教程,但那是在2008年,许多人报告了由于版本更改而导致的错误.
我也在寻找CommonsWare网站,他们有3本书,每年40美元.我查看了内容,但看不到任何符合我打算编写的内容.此外,这些书还谈论了很多其他的东西,如GPS,HttpRequests,服务器,数据库 - 在我的案例中我都不需要.
关于我应该如何解决这个问题的任何提示?
或者你们已经写过类似的东西吗?