开发者

How to start printing a StringListProperty() from index [1]?

开发者 https://www.devze.com 2023-02-08 14:29 出处:网络
I have a model class Category(db.Model): merchandise = db.StringListProperty() content = db.StringListProperty()

I have a model

class Category(db.Model):
   merchandise = db.StringListProperty()
   content = db.StringListProperty()         
   topics = db.StringListProperty()

For instanc开发者_开发百科e, merchandise list is ["merchandise","tshirt","book","poster"]

I print the list like this

elif merchandise_type == "merchandise":
    query = Category.all()
    e = query.get()

    self.response.out.write("""<ul>""")
    for i in range(len(e.merchandise)):
        self.response.out.write("""<li><a href="/tag?tag=%s">%s</a></li>""" 
        % (e.merchandise[i], e.merchandise[i]))
    self.response.out.write("""</ul>""")

but I don't want to print "merchandise".

How do I start from e.merchandise[1] instead of e.merchandise[0]?

Thanks!


for merch in e.merchandise[1:]:
    self.response.out.write('<li><a href="/tag?tag=%s">%s<a/></li>' % (merch, merch))

Question, of course, is why do you have such first element in your list in the first place.


for i in range(1, len(e.merchandise)): changing the first argument of range() will start the loop from 1 instead of 0

Edit: changed len() to range(), silly mistake

0

精彩评论

暂无评论...
验证码 换一张
取 消