Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string.template
#1
Hello,

Is it possible to generate a .qml file using string.template?

Thank u ^^
Reply
#2
you would need more than one print format, but so long as you choose the proper template to match your variables, I don't see why not.

There are better ways to do this.
You'd be better off using something like PLY (python Lex-Yacc subs): http://www.dabeaz.com/ply/
Reply
#3
Hey, this is my python code
if shape == "rectangle":
            x,y,w,h = cv2.boundingRect(c)
            cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),0)
            from string import Template
            from string import Template
            def main():
                cordinates=[]
                cordinates.append(dict(abscisse=x,ordonee=y,width=w,height=h))
                t=Template("""
            x: $abscisse
            y: $ordonee
            w: $width
            h: $height
                           """)                
                print '    Rectangle:'
                print("      {")
                for data in cordinates:
                    print (t.substitute(data))
                    print("      }")
            if __name__=="__main__":                
                main()
and I'm not sure how to extract/generate a .qml file from it!
Thank u for ur help
Reply
#4
this is not a snippet that can be run, so hard to analyze.
Reply
#5
if __name__ == "__main__": shouldn't be nested inside another block, and there's really no reason here for a function to be nested in that block, either.
Reply
#6
Thank u guys
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  template string format specifiers VincentLamphier 3 7,449 Jan-13-2019, 07:47 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020