Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This project serves as a comprehensive guide to executing shell commands and handling files using Python.

License

NotificationsYou must be signed in to change notification settings

VolkanSah/Python-Command-Overview-for-handling-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WebviewPython comman overview for big files

This project serves as a comprehensive guide to executing shell commands and handling files using Python.Installation.

Table of Contents

Installation

You can install Python through the official website:https://www.python.org/downloads/

Requiments

pipinstallPyPDF2python-docxpandasbeautifulsoup4

Usage

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:

Creating and writing to a file

withopen("filename.txt","w")asf:f.write("Hello, World!")

Reading from a file

withopen("filename.txt","r")asf:print(f.read())

Appending to an existing file

withopen("filename.txt","a")asf:f.write("More text.")

Deleting a file

importosos.remove("filename.txt")

Checking if a file exists

importosos.path.exists("filename.txt")

Creating a directory

importosos.mkdir("directory_name")

Large File Handling

Working with large files requires a different set of Python commands. Here are some examples:

Opening a file

file=open('large_file.txt','r')

Reading a file line by line

withopen('large_file.txt','r')asfile:forlineinfile:print(line)

Reading a specific number of lines

fromitertoolsimportislicewithopen('large_file.txt','r')asfile:head=list(islice(file,5))

Searching within a large file

withopen('large_file.txt','r')asfile:forlineinfile:if'some_text'inline:print(line)

Writing to a large file

withopen('large_file.txt','w')asfile:file.write('some_text')

Splitting files

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)

Handling Specific File Formats

Python can read various file formats using specific libraries. Here are some examples:

Reading PDF files

importPyPDF2withopen('example.pdf','rb')asfile:reader=PyPDF2.PdfFileReader(file)page=reader.getPage(0)print(page.extract_text())

Reading Word documents

fromdocximportDocumentdoc=Document('example.docx')forparaindoc.paragraphs:print(para.text)

Reading Excel files

importpandasaspddata=pd.read_excel('example.xlsx')print(data)

Reading HTML files

frombs4importBeautifulSoupwithopen("example.html")asfp:soup=BeautifulSoup(fp,'html.parser')print(soup.prettify())

Credits

This README was generated with the help of ChatGPT4, an AI developed by OpenAI &Volkan Sah.

Usefull

❤️ Thank you for your support!

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.

Releases

No releases published

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp