Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
A convenient Python API for working with the text files CSV, JSON, TXT
The library allows handling csv, txt and json files easily from within Python.
pip install textfiles
Import TextFile: Once you install the library you can import the TextFile class into your Python code. To do this, simply add the following line to your code:
from textfiles.file_factory import TextFile
Use TextFile: You can now use the TextFile class to create instances of CsvFile, TxtFile, and JsonFile classes. The factory has two methods:
make_file_instance: This method creates an instance of the file class for an existing text file.
make_file: This method creates a new file and a corresponding Python instance of it.
To create an instance of a CsvFile, TxtFile, or JsonFile class, simply call the appropriate static method and pass in the necessary parameters. The factory will then return an instance of the appropriate class.
Examples: Here are some examples of how to use TextFile:
To create an instance of an existing file:
file = TextFile.make_file_instance('csv', 'path/to/file.csv', has_header=True, delimiter=',')
file = TextFile.make_file_instance('txt', 'path/to/file.txt')
file = TextFile.make_file_instance('json', 'path/to/file.json')
To create a new file:
file = TextFile.make_file('csv', 'path/to/file.csv', ['Header1', 'Header2'])
file = TextFile.make_file('txt', 'path/to/file.txt')
file = TextFile.make_file('json', 'path/to/file.json')
Note - When creating a CSV file, it is mandatory to pass a header.
self.get_content()
self.search()
self.count()
my_csv = CsvFile('/path/to/my/csv/file.csv')
my_csv.update_cell(column=3, row=2, value='New content')
with open ("example.json", "w") as f:
json.dump(f, {"State": "New York", "cities": ["New York", "Albeny", "New Paltz"]})
my_json = JsonFile('/path/to/my/json/file.json')
new = my_json.search("new")
print(new)
output:
[{'State': 'New York'}, {'cities': [{'index[0]': 'New York'}, {'index[2]': 'New Paltz'}]}]
FAQs
Managing the text files txt, csv and json
We found that textfiles demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.