Python Snippets
June 7, 2026•102 words
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())