https://pyfilesystem.org
PyFilesystem.org - PyFilesystem
PyFilesystem.org - PyFilesystem PyFilesystem Search Sign in Fork me on GitHub Star Filesystem Abstraction for Python. Work with files and directories in archives, memory, the cloud etc. as easily as your local drive. Write code now, decide later where the data will be stored; unit test without writing real files; upload files to the cloud without learning a new API; sandbox your file writing code; etc. Commercial Support Documentation Help Index of Filesystems Introduction Let's look at a simple use-case. The following function uses the PyFilesystem API to count the number of non-blank lines of Python code in a directory (and any subdirectories): def count_python_loc(fs): """Count non-blank lines of Python code.""" count = 0 for path in fs.walk.files(filter=['*.py']): with fs.open(path) as python_file: count += sum(1 for line in python_file if line.strip()) return count The above code can be made to work with any filesystem, here are just a few examples: # HD with open_fs('.') as fs: print(count_python_loc(fs)) # Zip file with open_fs('zip://projects.zip') as fs: print(count_python_loc(fs)) # FTP Server with open_fs('ftp://ftp.example.org/projects') as fs: print(count_python_loc(fs)) Contrast that with the equivalent code using just the standard library: def count_python_loc(path): """Count non-blank lines of Python code.""" count = 0 for root, dirs, files in os.walk(path): for name in files: if name.endswith('.py'): with open(os.path.join(root, name), 'rt') as python_file: count += sum(1 for line in python_file if line.strip()) return count This version will only work with the local drive. Any other filesystem would require a different API and likely re-implementing the functionality of os.walk. PyFilesystem runs on Python 2.7/3.X — Linux / Mac / Win See Also Commercial Support Documentation Help Index of Filesystems Recently Published Dropboxfs Index of Filesystems Commercial Support Documentation News Announcing S3FS, a filesystem for Amazon S3 New Website © 2017 Will McGugan Powered by Moya — Template by Bootstrapious & Remote Please
en
en
1727833296
https://pyfilesystem.org
Ahitsio ny tranokalanao?
Manao inona ianao?