DEV Community

Cover image for Python File I/O Now Easier
Haider Ali
Haider Ali

Posted on • Updated on

Python File I/O Now Easier

Are you tired of doing this:

with open('main.txt', 'w') as f:
    data = f.read()
    print(data)

Enter fullscreen mode Exit fullscreen mode

Output:

File Content
Enter fullscreen mode Exit fullscreen mode

Well EasyFileHandling solves the problem. Questions rising up in your mind.

  • How is this useful Ok so first of all its Open Source, here is the Github repo link. Its useful because its object oriented, it has good documentation, lets you do soo much with file. You manipulate images with ImageHandler, you can edit, write, and much more with the FileHandler, you also use JsonHandler for JSON files and AsyncFileHandler for async File I/O tasks. All these handlers are classes. Too much talks lets see some examples. Run:
pip install EasyFileHandling
Enter fullscreen mode Exit fullscreen mode

Package Link

FileHandler
We have file named main.txt which has this in it:

Hello World! I like Files LOL

Magic Time

from EasyFileHandling.main import FileHandler 
x = FileHandler("main.txt")
print(x.what_type_of_file())
x.change_file_extension('.txt', '.js')

Enter fullscreen mode Exit fullscreen mode

Let me explain what it did, firstly it told told you what type of file .txt == Text. Get it I hope so then we told it to change the extension from .txt to .js.
You saw how great it is?

One more thing to show rest you find by yourself :)
Sometimes you want to do simple tasks but reading documentation is frustrating. You wanna add filter to an image or add text to it. We have simplified PILLOW library for you.
Need some Blur?

from EasyFileHandling.imagehandler import ImageHandler
x = ImageHandler('robot.png')
x.filter_image('blur')
Enter fullscreen mode Exit fullscreen mode

No need to save the image like you did in PILLOW library. Just press run and it will create a folder automatically and save this file to it.

Well this was the magic of EasyFileHandling, Open Source and Easy

One last thing do you know that EasyFileHandling developers are making easyfilehandling.js for npm. Its out NPM.

Important Link

Top comments (2)

Collapse
 
semihcebrail profile image
SemihCebraiL

but isn't #python (:

Collapse
 
haider__ali profile image
Haider Ali

I don’t get you?