This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: io.path.ismount gives "local variable 'p' referenced before assignment" error on Windows versions (
Type: compile error Stage:
Components: Windows Versions: Python 3.0
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: g.moralis, jcsalterego
Priority: normal Keywords:

Created on 2009-06-25 12:56 by g.moralis, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg89704 - (view) Author: Georgios Moralis (g.moralis) Date: 2009-06-25 12:56
It returns with the following error:
UnboundLocalError: local variable 'p' referenced before assignment

Example causing this:


import os

def show_cwd_list():
    alpha = os.listdir(os.getcwd())
    for dirnm in alpha[:]:
        if os.path.isdir(os.getcwd() + os.sep + dirnm):
            print("d ", dirnm)
        elif os.path.ismount(os.getcwd() + os.sep + dirnm):
            print("m ", dirnm)
        elif os.path.isfile(os.getcwd() + os.sep + dirnm):
            print("f ", dirnm)
        elif os.path.islink(os.getcwd() + os.sep + dirnm):
            print("l ", dirnm)
        elif os.path.isabs(os.getcwd() + os.sep + dirnm):
            print("a ", dirnm)
    return alpha


--- END OF CODE ---

The definition of ismount from the

def ismount(path):
    """Test whether a path is a mount point (defined as root of drive)"""
    unc, rest = splitunc(path)
    seps = _get_bothseps(p)
    if unc:
        return rest in p[:0] + seps
    p = splitdrive(path)[1]
    return len(p) == 1 and p[0] in seps

--- END OF CODE ---

As it seems, variable 'p' is used before it is initialized (_get_bothseps)
msg89707 - (view) Author: Jerry Chen (jcsalterego) Date: 2009-06-25 13:27
Duplicate of

Fixed in r70676
Date User Action Args
2022-04-11 14:56:50adminsetgithub: 50590
2009-06-25 13:31:02r.david.murraysetstatus: open -> closed
resolution: duplicate
2009-06-25 13:27:57jcsalteregosetnosy: + jcsalterego
messages: + msg89707
2009-06-25 12:56:44g.moraliscreate