Post

3 followers Follow
0
Avatar

EASI GetFileBasename in Python

Hello,

I have been using EASI for years to create custom workflows for repetitive tasks. Recently, I decided to learn and transition to python in Geomatica. However, I’m having difficulties performing certain EASI operations in python.

In EASI there was a built-in function called GetFileBasename() that allowed me to get a file name without the path or the extension. Does the python api have a similar built-in function?

TIA,
Herb.

Herbert Bergmann Answered

Please sign in to leave a comment.

1 comment

2
Avatar

Hi Herb,

There isn’t a built-in equivalent of GetFileBasename() in Geomatica for Python. Python has a large number of built-in functions, and has built-in functions that can be applied to return the base name without the extension.

In the example below, there are two functions you’ll need to use, basename and split. Basename will return the file name with the extension, and split will partition the string into a list using a specified delimiter.

import os
data = r'c:\data\scene_01.pix'
base = os.path.basename(data) 
print base
scene_01.pix
print base.split('.')
['scene_01', 'pix']
print base.split('.')[0]
scene_01

You can also group these functions together into a single line.

os.path.basename(data).split('.')[0]

I hope this helps. If you have anymore questions don't hesitate to ask. Good luck with Python!

Jean Bouffard 2 votes