Reputation: 42093
Looking for a clear way to name my variables. Below is an example of the values they will store.
'IMG_5123.JPG'
'/path/to/IMG_5123.JPG'
'/path/to/'
'JPG'
I was thinking filename, filename_full, path, extension. Is there a "proper" way to name these items?
Upvotes: 0
Views: 517
Reputation: 4772
In Unix and Unix-like operating systems you have the dirname and basename commands. If you use their widely used nomenclature then:
file basename: 'IMG_5123.JPG'
file name: '/path/to/IMG_5123.JPG'
file dirname: '/path/to/'
file suffix: 'JPG'
But nothing is ever that neat. The basename is also called the filename; the name is also called the full pathname; the dirname is often called the path, and the suffix is often called the extension.
Upvotes: 0
Reputation: 136
This is just my perspective and you can of course select any scheme that you want.
Because they all represent parts of the same filename, I would prefix them all with "filename" or "fn" (if it's really clear what it means). Therefore: filename, filename_abs, filename_path, filename_ext or a similar set.
If they are going to represent images specifically I would probably modify that.
Upvotes: 2
Reputation: 251041
you should read pep 8 to learn proper styling in python.
Upvotes: 1
Reputation: 3080
Your variables look ok to me. If you need additional inspiration you can check the std lib ofr os.path that's dealing with a lot of these concepts: http://docs.python.org/library/os.path.html
Upvotes: 3