From 6a6879065376da78d658b1d7cef4f2a01ec76e4d Mon Sep 17 00:00:00 2001 From: Gabe R Date: Sun, 28 Jun 2020 23:57:55 -0500 Subject: [PATCH] Cleaned up wv_helper.py * Formatted with autopep8 * Removed unused import typing.Any * Adding Coding Magic * Renamed argument input->inp to avoid shadowing python builtin * Removed unnecessary dummy variable creation --- src/wireviz/wv_helper.py | 71 +++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 1c803fd..b06d40e 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -1,33 +1,37 @@ -from typing import Any, List +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +from typing import List + def awg_equiv(mm2): awg_equiv_table = { - '0.09': 28, - '0.14': 26, - '0.25': 24, - '0.34': 22, - '0.5': 21, - '0.75': 20, - '1': 18, - '1.5': 16, - '2.5': 14, - '4': 12, - '6': 10, - '10': 8, - '16': 6, - '25': 4, - '35': 2, - '50': 1, - } + '0.09': 28, + '0.14': 26, + '0.25': 24, + '0.34': 22, + '0.5': 21, + '0.75': 20, + '1': 18, + '1.5': 16, + '2.5': 14, + '4': 12, + '6': 10, + '10': 8, + '16': 6, + '25': 4, + '35': 2, + '50': 1, + } k = str(mm2) if k in awg_equiv_table: return awg_equiv_table[k] else: return 'unknown' -def nested(input): + +def nested(inp): l = [] - for x in input: + for x in inp: if isinstance(x, list): if len(x) > 0: n = nested(x) @@ -37,25 +41,26 @@ def nested(input): if x is not None: if x != '': l.append(str(x)) - s = '|'.join(l) - return s + return '|'.join(l) -def int2tuple(input): - if isinstance(input, tuple): - output = input + +def int2tuple(inp): + if isinstance(inp, tuple): + output = inp else: - output = (input,) + output = (inp,) return output -def flatten2d(input): - output = [[str(item) if not isinstance(item, List) else ', '.join(item) for item in row] for row in input] - return output -def tuplelist2tsv(input, header=None): +def flatten2d(inp): + return [[str(item) if not isinstance(item, List) else ', '.join(item) for item in row] for row in inp] + + +def tuplelist2tsv(inp, header=None): output = '' if header is not None: - input.insert(0, header) - input = flatten2d(input) - for row in input: + inp.insert(0, header) + inp = flatten2d(inp) + for row in inp: output = output + '\t'.join(str(item) for item in row) + '\n' return output