PyMyFile is a python library for advance file handeling in the easiest possible way
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymyfile-1.0.1.tar.gz
.
File metadata
- Download URL: pymyfile-1.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96240441721fa29db8de4621e6d94fc7a3df543d2d74de2c4d26522f763a8d71 |
|
MD5 | fd8d4f114cd9beacfc9b4626791c4aec |
|
BLAKE2b-256 | 0df6fc05a4188675a0e9a8f4e42d80428075f974bfc2ad14e1030ba97fc971d1 |
File details
Details for the file pymyfile-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pymyfile-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 474f46ea9329b39be2fa9eea5a5a656d05b510e9dc808b43cf6c6b8fd7176569 |
|
MD5 | f943a712c27a5d91b3b1d14c2c1c860b |
|
BLAKE2b-256 | c62d0a2b659c5275573359c0f98ddbeb0ee1dbba9f63bff344a73beee094ee4a |