= datetime return datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S%z') datetime.datetime.strftime('%Y-%m-%dT%H:%M:%S%z') = csv == Default settings === "Text import" dialog Character set = Unicode (UTF-8) Language = Default - English (USA) From row = 1 Separator Options Separated by = 🗸 Tab 🗸 Comma 🗸 Semicolon String delimiter = " === "Export Text file" dialog Character set = Unicode (UTF-8) Field delimiter = , String delimiter = " ✔ 🗸 Save cell content as shown === python stdlib import csv class LibreOfficeCalcDefaultDialect(csv.Dialect): """LibreOffice Calc uses this dialect per default""" delimiter = ',' quotechar = '"' lineterminator = '\n' doublequote = True quoting = csv.QUOTE_MINIMAL skipinitialspace = False csv.register_dialect('calc', LibreOfficeCalcDefaultDialect) # reading a file with open('source.csv', newline='') as fd: reader = csv.reader(fd, 'calc') for row in reader: print(row) # writing a file import io out = io.StringIO() w = csv.writer(out) w.writerow(['foo', 'bar']) w.writerow(['Hi "hello"', 'world,!']) w.writerow(['tiraen;itaren', 'iare,eitrane']) print(out.getvalue()) print(dir(out)) # exported example file: foo,bar "Hi ""hello""","world,!" tiraen;itaren,"iare,eitrane" == geo coordinate conversion import math def num2dms(num): absDeg = abs(num) floorAbsDeg = int(absDeg) degrees = (1 if num >= 0 else -1) * floorAbsDeg mins = int(60 * (absDeg - floorAbsDeg)) secs = int(3600 * (absDeg - floorAbsDeg) - 60 * mins) return (degrees, mins, secs) def convert_num2dms(lat, lon): la, lo = num2dms(lat), num2dms(lon) lav = '{}°{}\'{}"'.format(*la) lov = '{}°{}\'{}"'.format(*lo) return '{}N {}E'.format(lav, lov) data = 32.80505643723761, 130.70981726528734 print(convert_num2dms(*data)) # output: 32°48'18"N 130°42'35"E == handling XML === XML writer import io import xml.sax.saxutils def create_xml(elem): out = io.StringIO() doc = xml.sax.saxutils.XMLGenerator(out, 'utf-8', short_empty_elements=True) doc.startDocument() doc.startElement(elem, {}) doc.startElement("sub", {}) # inner element doc.characters("Hello World") # characters doc.endElement("sub") doc.endElement(elem) doc.endDocument() return out.getvalue() xml_doc = create_xml("text:itöaren") print(xml_doc) === XML parser import xml.etree.ElementTree as ET tree = ET.parse('example.xml') root = tree.getroot() === XML SAX parser import xml.sax.handler import xml.sax class XMLSAXReader(xml.sax.handler.ContentHandler): def __init__(self): self.current_depth = 0 self.current_namespace = None @property def indentation(self): return (2 * self.current_depth) * ' ' #def startElementNS(self, name, qname, attributes): def startElement(self, name, attributes): print(self.indentation, name, dict(attributes) or '') self.current_depth += 1 #def endElementNS(self, name, qname): def endElement(self, name): self.current_depth -= 1 def characters(self, data): if not data.strip(): return r = repr(data) if len(r) > 40: r = r[:40] + ' …' print(self.indentation, r) # NOTE: or .parse(…) for a file descriptor xml.sax.parseString(xml_doc, XMLSAXReader())