Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throws NameError: name 'pathlib' is not defined with Python 3.4

I was using pathlib module, for directory browsing. Here is the snippet i was trying.

import sys,os
from pathlib import Path

root = "C:\"
for path, subdirs, files in os.walk(root):
    for name in files:
        print(pathlib.PurePath(path, name))

I get the following exception: "NameError: name 'pathlib' is not defined"

like image 240
Hari Kallae Avatar asked Dec 14 '22 21:12

Hari Kallae


1 Answers

You used from .. import ... statement instead of import ...

Replacing following line:

from pathlib import Path

with:

import pathlib

will solve your problem.

like image 117
falsetru Avatar answered Dec 22 '22 01:12

falsetru