Python Snippets

Python Snippets

Get CWD

current_dir = Path.cwd()
print(current_dir)  #or   print(current_dir.name) #only the folder name (without the rest of the path)

Load a single variable from a .mat file

def GetValueFromMatFile(varName):
    data = read_mat('phase1.mat', varName)
    return data[varName]

C = GetValueFromMatFile('C')
print(f"C is {C}")

f String Examp[le

    print(f"RSS: {RSS:3.5f}dBm")

List .mat files in a folder, open one and list it's contents

current_dir = Path.cwd()
print(current_dir)  #or   print(current_dir.name) #only the folder name (without the rest of the path)

mat_files = [f.name for f in Path('.').glob('*.mat') if f.is_file()]
print(mat_files)

data = read_mat('phase1.mat','C')
print(data.keys())




You'll only receive email when they publish something new.

More from Brad G
All posts