A library to read data from a file and convert it into python dictionary
Project description
What is Dift?
Dift is a Python library that makes it easy to read information from a file and store it as a dictionary in your Python script.
Installation
Installing Dift is easy. Simply run the following command in your terminal or command prompt: pip install Dift
Getting Started
To start using Dift in your script, you first need to import it:import Dift
The readData() function
The readData() function is the main function in Dift, and it's used to read information from a file and store it in a dictionary. The function takes one main argument (the file to be read) and several optional arguments to customize its behaviour.
Main argument: file
The file argument is the main argument in the readData() function, and it specifies the file that you want to read data from. The file should be formatted like this:
Student's Name : Alex Corey
Mother's Name : Branda Corey
Father's Name : John Corey
Example of code using the readData()
function
import Dift
file = open('details.txt','r')
dict = Dift.readData(file)
Optional argument: ctype
The ctype argument is an optional argument that you can use to specify whether integer values should be stored as integers or strings in the dictionary. If ctype is set to False, integer values will be stored as strings. If ctype is set to True (which is the default), integer values will be stored as integers.
Example:-
d = readData(file,ctype=False)
Optional argument: separator
The separator argument is an optional argument that you can use to specify the sign used to separate the keys and values in the file. The default separator is a colon (:).
d = readData(file,seperator=":")
Optional argument: ignore
The ignore argument is an optional argument that you can use to ignore errors that may occur when the specified separator isn't used in the file. If ignore is set to True (which is the default), the errors will be ignored. If ignore is set to False, an error will be raised if the specified separator isn't used in the file.
d = readData(file,ignore=True)
Comments
You can add comments to your file by starting a line with the # sign. Comments are ignored by Dift and are used to add notes or explanations to your file.
Example Here's an example of how to use the readData() function:
import Dift
file = open('details.txt', 'r')
data = Dift.readData(file)
in this example, the contents of the details.txt file are read and stored in a dictionary called data. The values in the file will be stored as integers if ctype is set to True, and the separator used in the file is a colon (:).
Project details
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 dift-0.0.7.tar.gz
.
File metadata
- Download URL: dift-0.0.7.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd2b5fe8c85c74cf9de0feb8ff31b4c65505a49c826d9be17d7be7a71db9a032 |
|
MD5 | 1e94d1d3b9f2dc2248ffcfd7ef6634d2 |
|
BLAKE2b-256 | 82daf9ba6ff71ceb6a1d8e545643e1a9210c1f0405c81f417f3de5f948e6210b |
File details
Details for the file dift-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: dift-0.0.7-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56d0f5ab4e79058e444a2e6c93a8c7de37d01691c4064ba4b4675c6dc712ae1b |
|
MD5 | 7f8089eab67b1f91bab0c2a7e2cd9642 |
|
BLAKE2b-256 | 14d964c271ac7fea6b630d596fbdaf9a09d3413e83498bc26041cd080346726b |