This project serves as a comprehensive guide to executing shell commands and handling files using Python. Installation.
- Installation
- Usage
- Install Requirements
- Shell Commands with Python
- Large File Handling
- Handling Specific File Formats
- Credits
- Useful Resources
You can install Python through the official website: https://www.python.org/downloads/
pip install PyPDF2 python-docx pandas beautifulsoup4
This project can be used as a reference guide for executing shell commands and file handling in Python. Shell Commands with Python
This project makes use of Python to execute shell commands. Here are some of the Python commands used in this project:
with open("filename.txt", "w") as f:
f.write("Hello, World!")
with open("filename.txt", "r") as f:
print(f.read())
with open("filename.txt", "a") as f:
f.write("More text.")
import os
os.remove("filename.txt")
import os
os.path.exists("filename.txt")
import os
os.mkdir("directory_name")
Working with large files requires a different set of Python commands. Here are some examples:
file = open('large_file.txt', 'r')
with open('large_file.txt', 'r') as file:
for line in file:
print(line)
from itertools import islice
with open('large_file.txt', 'r') as file:
head = list(islice(file, 5))
with open('large_file.txt', 'r') as file:
for line in file:
if 'some_text' in line:
print(line)
with open('large_file.txt', 'w') as file:
file.write('some_text')
chunk_size = 1000000 # 1 MB
with open('large_file.txt', 'r') as file:
chunk = file.read(chunk_size)
while chunk:
with open('chunk.txt', 'w') as chunk_file:
chunk_file.write(chunk)
chunk = file.read(chunk_size)
Python can read various file formats using specific libraries. Here are some examples:
import PyPDF2
with open('example.pdf', 'rb') as file:
reader = PyPDF2.PdfFileReader(file)
page = reader.getPage(0)
print(page.extract_text())
from docx import Document
doc = Document('example.docx')
for para in doc.paragraphs:
print(para.text)
import pandas as pd
data = pd.read_excel('example.xlsx')
print(data)
from bs4 import BeautifulSoup
with open("example.html") as fp:
soup = BeautifulSoup(fp, 'html.parser')
print(soup.prettify())
This README was generated with the help of ChatGPT4, an AI developed by OpenAI & Volkan Sah.
If you appreciate my work, please consider supporting me:
- Become a Sponsor: Link to my sponsorship page
- ⭐ my projects: Starring projects on GitHub helps increase their visibility and can help others find my work.
- Follow me: Stay updated with my latest projects and releases.