Skip to content

Instantly share code, notes, and snippets.

@DanielOaks
Created April 16, 2014 08:50
Show Gist options
  • Save DanielOaks/10835439 to your computer and use it in GitHub Desktop.
Save DanielOaks/10835439 to your computer and use it in GitHub Desktop.
Adds the correct extension to a provided library path
# platform library extension adder for Python or something
import os
import sys
__PLATFORM_LIBRARY_EXTENSIONS = {
'windows': 'dll',
'darwin': 'dylib',
'linux': 'so',
}
def add_library_extension(original_name):
"""Add the platform's library file extension to the given file name.
If we don't know what extension this platform uses, returns None.
"""
if sys.platform in __PLATFORM_LIBRARY_EXTENSIONS:
return '{}{}{}'.format(original_name, os.extsep, __PLATFORM_LIBRARY_EXTENSIONS[sys.platform])
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment