Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Access file system using objects

License

NotificationsYou must be signed in to change notification settings

bagrat/pyerarchy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pyerarchy is a Python package for easy file system surfing and manipulation. It enables to interact with the file systemdirectly as Python objects without making implicit calls toos package. Finally it makes the code much more readableand nice.

Basic Usage

The central point of Pyerarchy is the Node. The basic usage starts by initializing an entry point Node and manipulatingit further:

node = Node('entry/point/path')  # Initialize a new nodechildren = node.ls()  # List all child entities of the nodenode.mkdir('newdir').mkdir('anotherdir')  # Create a new directory under node, and another one under the new one :)# Now access the newly created directoriesanotherdir = node/'newdir'/'anotherdir'  # This is the most common way to access nodeschildren = node.newdir.anotherdir.ls()  # This method can be used to invoke an operation on the result node# What about files?myfile = node.myfile# And even...myfile = node.myfile.open('w')# Or...contents = node.myfile.read()  # ...which handles everything# What if the filename contains a dot, dash, etc?# Well...myfile_node = node/'filename.with.dots-and-dashes'# And then do your stuff on myfile_nodewith myfile_node.open('r') as f:    ...# Or again...contents = myfile_node.read()# And finally, just iterate...for child in node    # The child is also a Node object    ...

Another useful feature of Pyerarchy is very handy in Python modules to interact with static files included in the module:

static_data_node = ThisModuleNode()/'path/to/the/static/data/relative/to/module'some_file_node = static_data_node/'some/static/text/file'contents = some_file_node.read()

About

Access file system using objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp