Skip to main content

PyMyFile

PyMyFile is a python library for advance file handeling in the easiest possible way

Installation

pip install pymyfile

Usage

Consider a file "sample.txt" with following content

This is first line of the file.
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.

First import the library and initiate the file object

import pymyfile
myfile = pymyfile.file("sample.txt")

Then calling the functions will make the desired changes to the file, here's a berief explaination to each.

read()

This will return the content of the file, you don't need to close().

readline(line_num)

This will return the specified

>>> content = myfile.readline(line_num = 3)
>>> print(content)
This is third line of the file.

readlines(from_line_num, to_line_num)

This will return line in range from_line_num to _to_line_num. This will include both ends.

>>> contents = myfile.readlines(from_line_num = 2, to_line_num = 5))
>>> print(content)
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.

append(data)

This will append data to the file, you don't need to close().

>>> myfile.append(data = "This is appended line.")

This will be the final content of the sample.txt.

This is first line of the file.
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.
This is appended line.

append_line(line_num,data)

This will append data to that line

>>> myfile.append_line(line_num = 5, data = " This is appended data to line.")

This will be the final content of the sample.txt.

This is first line of the file.
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file. This is appended data to line.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.

write(data)

This will write to the file

>>> myfile.write("This is some data.")

This will be the final content of the sample.txt.

This is some data.

write_line(line_num,data)

This will write that particular line of the file.

>>> myfile.write_line(line_num = 2, data = "This is new content of the line.")

This will be the final content of the sample.txt.

This is first line of the file.
This is new content of the line.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.

replace_word(line_num, old_word, new_word, occurence=ALL, from_word_num=None, to_word_num=None)

This will replace that particular word from that particular line

>>> myfile.replace_word(line_num = 1, old_word = "file", new_word = "some word")

This will be the final content of the sample.txt.

1. This is first line of the some word.
2. This is second line of the file.
3. This is third line of the file.
4. This is fourth line of the file.
5. This is fifth line of the file.
6. This is sixth line of the file.
.
.
.
.
n. This is n(th) line of the file.

numiphy()

This will add numbers at the begining of each line

>>> myfile.numiphy()

This will be the final content of the sample.txt.

1. This is first line of the file.
2. This is second line of the file.
3. This is third line of the file.
4. This is fourth line of the file.
5. This is fifth line of the file.
6. This is sixth line of the file.
.
.
.
.
n. This is n(th) line of the file.

denumiphy()

This will revert the changes caused by numiphy()

>>> myfile.numiphy()

This will be the final content of the sample.txt.

This is first line of the file.
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.

bulletiphy()

This will add bullets "•" at the begining of each line.

>>> myfile.bulletiphy()

This will be the final content of the sample.txt.

• This is first line of the file.
• This is second line of the file.
• This is third line of the file.
• This is fourth line of the file.
• This is fifth line of the file.
• This is sixth line of the file.
.
.
.
.
• This is n(th) line of the file.

debulletiphy()

This will revert the changes caused by bulletiphy().

>>> myfile.debulletiphy()

This will be the final content of the sample.txt.

This is first line of the file.
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.

asteriphy()

This is same as bulletiphy() but this will add "*" instead of bullet.

>>> myfile.asteriphy()

This will be the final content of the sample.txt.

* This is first line of the file.
* This is second line of the file.
* This is third line of the file.
* This is fourth line of the file.
* This is fifth line of the file.
* This is sixth line of the file.
.
.
.
.
* This is n(th) line of the file.

deasteriphy()

This will revert the changes caused by asteriphy().

>>> myfile.deasteriphy()

This will be the final content of the sample.txt.

This is first line of the file.
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.

phy(phy)

This is same as asteriphy() or bulletiphy() but add the custom phy instead.

>>> myfile.phy(phy = "hmm")

This will be the final content of the sample.txt.

hmm This is first line of the file.
hmm This is second line of the file.
hmm This is third line of the file.
hmm This is fourth line of the file.
hmm This is fifth line of the file.
hmm This is sixth line of the file.
.
.
.
.
hmm This is n(th) line of the file.

deasteriphy()

This will revert the changes caused by phy(phy).

>>> myfile.dephy(phy = "mum")

This will be the final content of the sample.txt.

This is first line of the file.
This is second line of the file.
This is third line of the file.
This is fourth line of the file.
This is fifth line of the file.
This is sixth line of the file.
.
.
.
.
This is n(th) line of the file.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Metadata

Release files for pymyfile 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymyfile 1.0.1
File Size Uploaded
pymyfile-1.0.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymyfile 1.0.1
File Interpreter ABI Platform
pymyfile-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / pymyfile-1.0.1.tar.gz

Download URL pymyfile-1.0.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
96240441721fa29db8de4621e6d94fc7a3df543d2d74de2c4d26522f763a8d71
BLAKE2b-256 checksum
How to use checksums
0df6fc05a4188675a0e9a8f4e42d80428075f974bfc2ad14e1030ba97fc971d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0

Release files / pymyfile-1.0.1-py3-none-any.whl

Download URL pymyfile-1.0.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
474f46ea9329b39be2fa9eea5a5a656d05b510e9dc808b43cf6c6b8fd7176569
BLAKE2b-256 checksum
How to use checksums
c62d0a2b659c5275573359c0f98ddbeb0ee1dbba9f63bff344a73beee094ee4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page