Skip to content

Instantly share code, notes, and snippets.

@berndGEO
Last active January 14, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berndGEO/be5bcdf319f4d6282699b7efb4d28d77 to your computer and use it in GitHub Desktop.
Save berndGEO/be5bcdf319f4d6282699b7efb4d28d77 to your computer and use it in GitHub Desktop.
a simple module to create funtions and classes in python3
# -*- encoding: utf8 -*-
"""Generic function/Class
by Bernd Kassler www.c3is.de
bernd@c3is.de
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)
@berndGEO
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment