On this page
inspect.getmodulename
Prev: inspect.getmodule | Up: inspect | Next: inspect.getmro
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.getmodulename
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import getmodulename
Signature & Overview
inspect.getmodulename(path)
Return the module name for a given file, or None.
Usage
import inspect
assert inspect.getmodulename("/path/to/helper.py") == "helper"
assert inspect.getmodulename("/path/to/readme.txt") is None
Gotchas
- Pure filename check: Does not check whether the file exists on disk.
REPL Inspect
from inspect import getmodulename
help(getmodulename)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/getmodule Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/getmro Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BoundArguments shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClassFoundException shared tags: #inspect, #stdlib