Skip to content

Instantly share code, notes, and snippets.

@davidszotten
Created October 20, 2020 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidszotten/bceffbab7e5241047536749da6609ac4 to your computer and use it in GitHub Desktop.
Save davidszotten/bceffbab7e5241047536749da6609ac4 to your computer and use it in GitHub Desktop.
python filename to module syntax
#!/usr/bin/env python
import sys
def main():
try:
filename = sys.argv[1]
except IndexError:
filename = ''
if filename.startswith('src/'):
filename = filename[4:]
print(filename.replace('.py', '').replace('/', '.'))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment