Skip to content

Instantly share code, notes, and snippets.

View frruit's full-sized avatar
💭
https://frruit.github.io/frruity-blog/

frruit

💭
https://frruit.github.io/frruity-blog/
View GitHub Profile
@frruit
frruit / abc_with_decorator_pre_and_post
Created March 3, 2017 07:00
My solution how to handle data collection from different tools is to implement an ABC Class end reduce copy past of code in the childs by implementing a decorator with pre an post handling
from abc import ABCMeta, abstractmethod
def prepost(f):
def prepost_wrapper(self, *args, **kwargs):
print('prepost wrapper')
pre_name = 'pre_' + f.__name__
post_name = 'post_' + f.__name__
if hasattr(self, pre_name):
@frruit
frruit / remove_xml_tags.py
Created September 7, 2016 10:45
Remove the namespace from xml tags
from io import StringIO
import sys
from lxml import objectify, etree
ns = '{http://autosar.org/X.X.X}'
file = r'demo_swc.arxml'
file2 = file.replace('demo_swc.arxml', 'demo_swc_without_ns.arxml')
with open(file) as f:
@frruit
frruit / replace_umlaute.py
Last active January 31, 2018 14:11
Small example hot to convert german special characters from unicode to utf-8 and back to unicode
# Small example hot to convert german special characters from unicode to utf-8 and back to unicode
# http://www.utf8-zeichentabelle.de/unicode-utf8-table.pl?start=128&number=128&names=-&utf8=string-literal
#
umlaute_dict = {
'\xc3\xa4': 'ae', # U+00E4 \xc3\xa4
'\xc3\xb6': 'oe', # U+00F6 \xc3\xb6
'\xc3\xbc': 'ue', # U+00FC \xc3\xbc
'\xc3\x84': 'Ae', # U+00C4 \xc3\x84
'\xc3\x96': 'Oe', # U+00D6 \xc3\x96
@frruit
frruit / excel2sql.py
Last active August 29, 2015 14:17
This example shows how to import an excel file into an Sqlite table with pandas and sqlsoup
import pandas as pd
import sqlsoup
db = sqlsoup.SQLSoup('sqlite:///pandas.db')
engine = db.engine
# Read Excel
df = pd.read_excel('excel_file.xlsx',
0, # Sheet
index_col=None,