Skip to content

Instantly share code, notes, and snippets.

View DanielSzoska's full-sized avatar

Daniel Szoska DanielSzoska

  • Friedenfels, Bavaria, Germany
View GitHub Profile
@DanielSzoska
DanielSzoska / TextPatcherBase.py
Created October 9, 2012 07:44
Basisklasse für TextPatcher mit zu überschreibender Methode statt einer Helper-Funktion
class TextPatcherBase(object):
def mangle_doc(self, doc, rflag, mapping):
raise NotImplementedError
def mangle_docs(self, patchfunc, mappings):
self.ndocs_patched = 0
for doc in self.docs:
if doc.key in mappings:
self.mangle_doc(doc, True, mappings[doc.key])
@DanielSzoska
DanielSzoska / TextPatcher.__init__.modified.py
Created October 9, 2012 07:34
Auszug aus TextPatcher.__init__
with io.open(..) as f:
# do something
pass
# save the type of newlines
self.newlines = f.newlines
@DanielSzoska
DanielSzoska / preserve_newline_type.py
Created October 3, 2012 12:21
preserve type of newlines in textfile while doing something with it
# open textfile
filename = 'text.txt'
with open(filename, 'rU') as f:
lines = f.readlines()
newline = f.newlines
if not newline:
raise IOError, "no newlines in %s, possible no textfile" % filename
if isinstance(newline, tuple):
raise IOError, "more than one type of newlines in %s" % filename