Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
This project serves as a comprehensive guide to executing shell commands and handling files using Python.
License
VolkanSah/Python-Command-Overview-for-handling-files
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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/
pipinstallPyPDF2python-docxpandasbeautifulsoup4
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:
withopen("filename.txt","w")asf:f.write("Hello, World!")
withopen("filename.txt","r")asf:print(f.read())
withopen("filename.txt","a")asf:f.write("More text.")
importosos.remove("filename.txt")
importosos.path.exists("filename.txt")
importosos.mkdir("directory_name")
Working with large files requires a different set of Python commands. Here are some examples:
file=open('large_file.txt','r')
withopen('large_file.txt','r')asfile:forlineinfile:print(line)
fromitertoolsimportislicewithopen('large_file.txt','r')asfile:head=list(islice(file,5))
withopen('large_file.txt','r')asfile:forlineinfile:if'some_text'inline:print(line)
withopen('large_file.txt','w')asfile:file.write('some_text')
chunk_size=1000000# 1 MBwithopen('large_file.txt','r')asfile:chunk=file.read(chunk_size)whilechunk:withopen('chunk.txt','w')aschunk_file:chunk_file.write(chunk)chunk=file.read(chunk_size)
Python can read various file formats using specific libraries. Here are some examples:
importPyPDF2withopen('example.pdf','rb')asfile:reader=PyPDF2.PdfFileReader(file)page=reader.getPage(0)print(page.extract_text())
fromdocximportDocumentdoc=Document('example.docx')forparaindoc.paragraphs:print(para.text)
importpandasaspddata=pd.read_excel('example.xlsx')print(data)
frombs4importBeautifulSoupwithopen("example.html")asfp: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.
About
This project serves as a comprehensive guide to executing shell commands and handling files using Python.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.