Python | os.path.normpath() method Last Updated : 16 Sep, 2021 Comments Improve Suggest changes Like Article Like Report OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name manipulation. os.path.normpath() method in Python is used to normalize the specified path. All redundant separator and up-level references are collapsed in the process of path normalization. For example: A//B, A/B/, A/./B and A/foo/../B all will be normalized to A/B. On Windows operating system, any forward slash ('/') in the path is converted to backslash ('\'). Syntax: os.path.normpath(path)Parameter: path: A path-like object representing a file system path. Return Type: This method returns a string value which represents the normalized path. Code #1: Use of os.path.normpath() method Python3 # Python program to explain os.path.normpath() method # importing os.path module import os.path # Path path = '/home//user/Documents' # Normalize the specified path # using os.path.normpath() method norm_path = os.path.normpath(path) # Print the normalized path print(norm_path) # Path path = '/home/./Documents' # Normalize the specified path # using os.path.normpath() method norm_path = os.path.normpath(path) # Print the normalized path print(norm_path) # Path path = '/home/user/temp/../Documents' # Normalize the specified path # using os.path.normpath() method norm_path = os.path.normpath(path) # Print the normalized path print(norm_path) Output/home/user/Documents /home/Documents /home/user/Documents Code #2: Use of os.path.normpath() method (On Windows) Python3 # Python program to explain os.path.normpath() method # importing os.path module import os.path # Path path = r'C:/Users' # Normalize the specified path # using os.path.normpath() method norm_path = os.path.normpath(path) # Print the normalized path print(norm_path) # Path path = r'C:\Users\.\Documents' # Normalize the specified path # using os.path.normpath() method norm_path = os.path.normpath(path) # Print the normalized path print(norm_path) # Path path = r'C:\Users\admin\temp\..\Documents' # Normalize the specified path # using os.path.normpath() method norm_path = os.path.normpath(path) # Print the normalized path print(norm_path) Output: C:\\Users C:\\Users\\Documents C:\\Users\\admin\\Documents Reference: https://docs.python.org/3/library/os.path.html Comment More infoAdvertise with us Next Article Python | os.path.normpath() method I ihritik Follow Improve Article Tags : Python python-os-module Python OS-path-module Practice Tags : python Similar Reads Python | os.path.expanduser() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common pathname mani 4 min read Python | os.path.expandvars() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path the module is a submodule of OS module in Python used for common pathname 3 min read Python | os.path.getatime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.getmtime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.getctime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.size() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system-dependentthe functionality. os.path module is a submodule of the OS module in Python used for common path 2 min read Python | os.path.isabs() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python os.path.isfile() method The os.path.isfile() method in Python is used to check if a path refers to a regular file (not a directory or any other type of file system object). This method can be particularly useful when you need to validate file paths before performing file operations like reading, writing, or modifying files 2 min read os.path.isdir() method - Python os.path.isdir() method in Python checks whether the specified path is a directory or not. This method follows the symbolic link, which means if the specified path is a symbolic link pointing to an existing directory then the method will return True.Example: Using os.path.isdir() methodThis code demo 2 min read Python | os.path.islink() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Like