Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MacOS can't make it
#1
Lightbulb 
Hello, folks! Im only starting my python journey. Now Im learning walk function in OS and its simply doesn't work. Can you suggest me something please? May be its because of Mac OS? So, I attach screen below, the code and the result.
Larz60+ write May-29-2022, 07:30 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post code in BBCode tags. refrain from using attachments.

Attached Files

Thumbnail(s)
       
Reply
#2
using pathlib:
from pathlib import Path
from BadgePaths import BadgePaths

bpath = BadgePaths()
path = Path(bpath.htmlpathNh)

for p in path.rglob("*"):
     print(p.name)
BadgePaths.py looks like:
import os
from pathlib import Path


class BadgePaths:
    def __init__(self, depth=0):
        os.chdir(os.path.abspath(os.path.dirname(__file__)))
        dir_depth = abs(depth)

        HomePath = Path(".")

        while dir_depth:
            HomePath = HomePath / ".."
            dir_depth -= 1

        rootpath = HomePath / ".."

        self.datapath = rootpath / "data"
        self.datapath.mkdir(exist_ok=True)

        self.csvpath = self.datapath / "csv"
        self.csvpath.mkdir(exist_ok=True)

        self.htmlpath = self.datapath / "html"
        self.htmlpath.mkdir(exist_ok=True)

        self.htmlpathNh = self.htmlpath / "NewHampshire"
        self.htmlpathNh.mkdir(exist_ok=True)

        self.samplesNh = self.htmlpathNh / 'Samples'
        self.samplesNh.mkdir(exist_ok=True)
        
        self.imagepath = self.datapath / 'images'
        self.imagepath.mkdir(exist_ok=True)
        
        self.logpath = self.datapath / 'logs'
        self.logpath.mkdir(exist_ok=True)
        
        self.prettypath = self.datapath / "pretty"
        self.prettypath.mkdir(exist_ok=True)

        self.srcpath = rootpath / 'src'
        self.srcpath.mkdir(exist_ok=True)

        self.textpath = self.datapath / 'text'
        self.textpath.mkdir(exist_ok=True)

        self.tmppath = self.datapath / "tmp"
        self.tmppath.mkdir(exist_ok=True)


if __name__ == "__main__":
    BadgePaths()
partial results:
Output:
NhBusinessListingsPage9993.html NhBusinessListingsPage9994.html NhBusinessListingsPage9995.html NhBusinessListingsPage9996.html NhBusinessListingsPage9997.html NhBusinessListingsPage9998.html NhBusinessListingsPage9999.html Samples
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python installation for old MacOS Yonix 1 495 Sep-21-2023, 03:32 PM
Last Post: menator01
  Why is IDLE not opening on a MacOS Montery 12.6 and using Python 3.10.7? Merlin385 7 1,717 Oct-08-2022, 08:36 PM
Last Post: Merlin385
  Text widget -macOS apffal 1 1,768 Sep-23-2021, 10:12 PM
Last Post: apffal
  Installing Python3 on MacOS using brew zazas321 5 5,249 May-28-2021, 06:19 AM
Last Post: perfringo
  Building from source on MacOS: installing certificates ardim 1 1,995 Feb-09-2020, 10:16 PM
Last Post: ardim
  can't open excel with my macos dcc 0 2,393 Oct-30-2019, 04:18 AM
Last Post: dcc
  pymysql on macos seirra tony1812 5 4,573 Sep-17-2017, 03:24 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020