Last active
January 14, 2017 12:00
-
-
Save berndGEO/be5bcdf319f4d6282699b7efb4d28d77 to your computer and use it in GitHub Desktop.
a simple module to create funtions and classes in python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf8 -*- | |
"""Generic function/Class | |
by Bernd Kassler www.c3is.de | |
[email protected] | |
13. JAN 2017 | |
""" | |
#import numpy as np | |
#import h5py | |
#from scipy import signal as sgl | |
#import scipy.io as sio | |
#import sympy as smb | |
#import matplotlib.pyplot as plt | |
#import math | |
#import os | |
import sys | |
#import openpyxl | |
#import time | |
#import xlrd | |
#import xlwt | |
# from netCDF4 import Dataset | |
#import mpltools | |
#import obspy | |
class Clear: | |
''' Use "-clear" to clear the screen, i.e: | |
>>> -clear | |
Or call it as a function: | |
>>> clear() | |
Or if you're on a shell, you can also type: | |
>>> clear | |
This file can be called as a regular program, also. | |
cf. https://gist.github.com/jmendeth/3130325 | |
''' | |
def __call__(self): | |
import os | |
if os.name=='linux': os.system('clear') | |
else: print('\n'*120) | |
def __neg__(self): self() | |
def __repr__(self): | |
self();return '' | |
class Gen : | |
"""Useful constants and functions | |
function_one (val) does something | |
""" | |
#math. constants in CAPITALS | |
NIL=None # NULL string 0x0 | |
MAXINT=sys.maxsize # a big Integer | |
YNF=1.e100 # a big number | |
ZERO=1/YNF # a small number | |
# ++++++++++++++++++++++++++++++++++++++++ | |
def __init__(self): | |
pass | |
#end Attribute Nutz++++++++++++++++++++++++++++ | |
@staticmethod | |
def function_one( val, # a variable as input | |
): | |
"""does something with variable val | |
""" | |
x=val | |
return x | |
# end function_one ++++++++++++++++++++++++++++++++ | |
# defining some functions as static: | |
function_one= staticmethod(function_one) | |
#end class GEN ##################################### | |
############################################### | |
# TEST environment (main program) | |
# | |
if __name__ =='__main__': | |
print('START test run _____________________________________________________________________________') | |
print() | |
print ('Hello world! ', Gen.MAXINT) | |
print() | |
print('______________________________________________________________________________________ready !') | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use the class Gen to start with programming a new code in python3. During the exercises at the University python workshops I have different exercises to solve but for every function/program i need the almost same 'headers' therefore a generic function seems to be quite useful for me.