Difference between revisions of "Template dictionary python"

From Second Life Wiki
Jump to navigation Jump to search
(creating page)
 
(Page repair: <python></python> replaced with <syntaxhighlight lang="python"></syntaxhighlight>)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<pre>
name this file makepacketdict.py in order to use it
 
<syntaxhighlight lang="python">
# uses the client's message_template.msg file to create a dictionary of name and other relevant packet info...
# uses the client's message_template.msg file to create a dictionary of name and other relevant packet info...
# make sure that message_template.msg has had all leading spaces removed and replaced with the correct number of  tabs --I was exceedingly lazy when I wrote this and assumed a consistent tabbing scheme in the template


import re
import re
Line 7: Line 10:
def makepacketdict():
def makepacketdict():
     dict = {}
     dict = {}
     for line in open("message_template.msg", ).xreadlines():
     for line in open("message_template.msg"):
         results = re.match("^\t([^\t{}]+.+)",line)
         results = re.match("^\t([^\t{}]+.+)",line)
         if results:
         if results:
Line 13: Line 16:
             aline = aline.split()
             aline = aline.split()
             if aline[1] == "Fixed":  
             if aline[1] == "Fixed":  
                 dict[(aline[1],int("0x"+aline[2][8:],16))] = (aline[0],aline[3], aline[4])
                 dict[(aline[1],int(aline[2][8:],16))] = (aline[0],aline[3], aline[4])
             else:
             else:
                 dict[(aline[1],int(aline[2]))] = (aline[0],aline[3], aline[4])
                 dict[(aline[1],int(aline[2]))] = (aline[0],aline[3], aline[4])
     return dict
     return dict
</pre>
</syntaxhighlight>
 
 
[[Category: AW Groupies]]

Latest revision as of 04:40, 19 April 2016

name this file makepacketdict.py in order to use it

# uses the client's message_template.msg file to create a dictionary of name and other relevant packet info...
# make sure that message_template.msg has had all leading spaces removed and replaced with the correct number of  tabs --I was exceedingly lazy when I wrote this and assumed a consistent tabbing scheme in the template

import re


def makepacketdict():
    dict = {}
    for line in open("message_template.msg"):
        results = re.match("^\t([^\t{}]+.+)",line)
        if results:
            aline = results.group(1)
            aline = aline.split()
            if aline[1] == "Fixed": 
                dict[(aline[1],int(aline[2][8:],16))] = (aline[0],aline[3], aline[4])
            else:
                dict[(aline[1],int(aline[2]))] = (aline[0],aline[3], aline[4])
    return dict