s243a

dictlist.py

Jul 15th, 2022
1,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. #! /usr/bin/env python3
  2. import sys,os,fcp3,hashlib,io
  3. from datetime import datetime
  4. from datetime import date
  5. import xml.etree.ElementTree as ET
  6. import re #https://pythongeeks.org/regular-expressions-in-python/#:~:text=A%20regular%20expression%20is%20a%20sequence%20of%20characters,%28stands%20for%20the%20regular%20expression%29%20for%20this%20purpose.
  7. #https://realpython.com/python-interface/
  8. class DictList(list):
  9.   def __init__(self,*args):
  10.     super(DictList,self).__init__(args)
  11.     self.sep=";"
  12.     self.asgn="="
  13.   def getSep(self):
  14.     return self.sep
  15.   def getAsgn(self):
  16.     return self.asgn
  17.   def append(self,**kw):
  18.     super(DictList,self).append(kw)
  19.   def __str__(self):
  20.     out=io.StringIO()
  21.    
  22.     #TODO: escape single seperator with doulbe seperator
  23.     #TODO: escape single assign with doulbe asign
  24.     for item in self:
  25.       if isinstance(item,dict):
  26.         for k,v in item.items():
  27.           print(k,v,file=out,sep=self.getAsgn(),end=self.getSep()) #sep=self.getSep()
  28.           #self.strings.extend(
  29.           #  [str(k) + self.getAsgn() +
  30.           #   str(v) for k,v in aString.items()])
  31.       else:
  32.         print(str(item),file=out,end=self.getSep()) #https://www.freecodecamp.org/news/python-new-line-and-how-to-python-print-without-a-newline/
  33.     out_value=out.getvalue()[1:-1]
  34.     out.close()
  35.     return out_value
  36. def dictlist_test():
  37.   global dl
  38.   dl=DictList("bob@hash",{'update_fms_SSK': 'USK@hash'},"some string of data")
  39.   print("Sep=" + dl.getSep())
  40.   print("Sep=" + dl.getAsgn())
  41.   print("String=" + str(dl))
  42.  
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment