Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:47:23+00:00 2026-06-02T07:47:23+00:00

os.path module seems to be the default module for all path related functions. Yet,

  • 0

os.path module seems to be the default module for all path related functions. Yet, the listdir() function is part of the os module and not os.path module, even though it accepts a path as its input. Why has this design decision been made ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:47:25+00:00Added an answer on June 2, 2026 at 7:47 am

    I personally find the division between os and os.path to be a little inconsistent. According to the documentation, os.path should just be an alias to a module that works with paths for a particular platform (i.e., on OS X, Linux, and BSD you’ll get posixpath, on Windows or ancient Macs you’ll get something else).

    >>> import os
    >>> help(os)
    Help on module os:
    
    NAME
        os - OS routines for Mac, NT, or Posix depending on what system we're on.
    ...
    >>> help(os.path)
    Help on module posixpath:
    
    NAME
        posixpath - Common operations on Posix pathnames.
    

    The listdir function doesn’t operate on the path itself, instead it operates on the directory identified by the path. Most of the functions in os.path operate on the actual path and not on the filesystem.

    This means that many functions in os.path are string manipulation functions, and most functions in os are IO functions / syscalls.

    Examples:

    • os.path.join, os.path.dirname, os.path.splitext, are just string manipulation functions.

    • os.listdir, os.getcwd, os.remove, os.stat are all syscalls, and actually touch the filesystem.

    Counterexamples:

    • os.path has exists, getmtime, islink, and others which are basically wrappers around os.stat, and touch the filesystem. I consider them miscategorized, but others may disagree.

    Fun fact of the day: You won’t find the modules in the top level of the library documentation, but you can actually import the version of os.path for any platform without having to actually run on that platform. This is documented in the documentation for os.path,

    However, you can also import and use the individual modules if you want to manipulate a path that is always in one of the different formats. They all have the same interface:

    • posixpath for UNIX-style paths
    • ntpath for Windows paths
    • macpath for old-style MacOS paths
    • os2emxpath for OS/2 EMX paths

    You can’t do the same thing with os, it wouldn’t make any sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import sys sys.path.append('/home/myuser/svn-repos/myproject') from myproject.settings import * But, it says module not found when
I have a module with multiple functions. Since I've named them in a not-PowerShell-way
Just wondering how many people use a path module in Python such as Jason
Wow, this seems so basic, but I can't get it to work. All I
I like to use the Find in Path function CTRL+SHIFT+F , that searches for
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [path objectAtIndex:0]; NSString *databasePath =
The path to libidl.so.7.1 is in ld.so.conf, and the library is in the cache
I have a Path (a star figure): <Path x:Name=NiceStar StrokeThickness=10 Stroke=#ff000000 StrokeMiterLimit=1 Data=F1 M
If I have a path, like so: c:\windows\system32\inetsrv\abc.exe And I want to make a
After building a filepath ( path , below) in a string (I am aware

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.