Important Notice:

Types of Files Processing

Types of Files Processing

8 views 3 min read

Types of Files (फाइलों के प्रकार) :-

Data को store करने के तरीके के आधार पर computer files को मुख्य रूप से दो प्रकारों में बाँटा जाता है:

English

Based on how data is represented and stored, files are commonly classified into two main types:

  1. Text Files (टेक्स्ट फाइलें)

  2. Binary Files (बाइनरी फाइलें)

 

Text Files (टेक्स्ट फाइलें) :-


Text file वह file है जिसमें data को किसी character encoding, जैसे UTF-8, के अनुसार text characters के रूप में represent किया जाता है।

Text files का उपयोग सामान्य text, विद्यार्थी के records, notes, source code और CSV data को store करने के लिए किया जाता है।

English -

A text file is a file whose contents are represented as text characters using a character encoding such as UTF-8.

Text files are commonly used to store plain text, records, notes, source code, and CSV data.

Text File के उदाहरण -

student.txt
notes.txt
marks.csv
program.py

student.txt file में निम्न data हो सकता है:

Name: Rahul
Class: O Level
Marks: 85

Python में Text File बनाना और लिखना -

file = open("student.txt", "w", encoding="utf-8")

file.write("Name: Rahul\n")
file.write("Class: O Level\n")
file.write("Marks: 85\n")

file.close()

Explanation (व्याख्या):

  • open() file को खोलता है या आवश्यकता होने पर बनाता है।

  • "student.txt" file का नाम है।

  • "w" write mode है।

  • encoding="utf-8" text encoding निर्धारित करता है।

  • write() file में text लिखता है।

  • \n नई line शुरू करता है।

  • close() file को बंद करता है।


File में लिखा गया Data -

Name: Rahul
Class: O Level
Marks: 85

Python में Text File पढ़ना-

file = open("student.txt", "r", encoding="utf-8")

data = file.read()

print(data)

file.close()

Output:

Name: Rahul
Class: O Level
Marks: 85

Text Files की विशेषताएँ (Characteristics) -
  1. इनमें text characters store किए जाते हैं।

  2. इन्हें सामान्य text editor में अक्सर पढ़ा जा सकता है।

  3. Python में text mode default होता है।

  4. Text encoding, जैसे UTF-8, characters को bytes में represent करने के लिए उपयोग होती है।

  5. इनका उपयोग notes, reports और textual records के लिए किया जाता है।

Advantages (लाभ) -
  • Text data को पढ़ना और समझना आसान होता है।

  • इन्हें आसानी से edit किया जा सकता है।

  • Data को विभिन्न programs के बीच साझा किया जा सकता है।

  • कई text formats सरल और portable होते हैं।

Limitations (सीमाएँ) -
  • हर प्रकार के data के लिए text format उपयुक्त नहीं होता।

  • Text में save करने पर कुछ data का original binary representation सुरक्षित नहीं रहता।

  • बड़े या जटिल media data के लिए specialized formats अधिक उपयुक्त होते हैं।

Important Point

In Python, files are opened in text mode by default unless binary mode is specified.

 Binary Files (बाइनरी फाइलें) -

Binary file वह file है जिसमें data bytes के रूप में store और process किया जाता है। इस प्रकार की files का data सामान्य text editor में अक्सर पढ़ने योग्य नहीं होता, क्योंकि उसे समझने के लिए संबंधित format की जानकारी आवश्यक हो सकती है।

English -

A binary file is a file whose data is handled as a sequence of bytes rather than decoded text. Its contents often require suitable software or a program to interpret them correctly.

Binary File के उदाहरण -

  • Image files: .jpg, .png

  • Audio files: .mp3, .wav

  • Video files: .mp4, .avi

  • Executable files: .exe

  • कई document formats: .pdf



Python में Binary File खोलना -

Binary file को पढ़ने के लिए rb और लिखने के लिए wb mode उपयोग किया जाता है।


Example 1: Binary File पढ़ना-

file = open("data.bin", "rb")

data = file.read()

print(data)

file.close()

Possible Output:

b'Hello'

यह output तभी मिलेगा जब data.bin में Hello के bytes हों। Binary mode में read() bytes लौटाता है।

Example 2: Binary File में Data लिखना

file = open("data.bin", "wb")

file.write(b"Hello")

file.close()

Explanation:

  • "wb" binary write mode है।

  • b"Hello" bytes object है।

  • write() bytes को file में लिखता है।

  • यदि file पहले से मौजूद है, तो wb mode उसकी पुरानी सामग्री को मिटाकर नया data लिखना शुरू करता है।


Binary Files की विशेषताएँ (Characteristics)
  1. Data bytes के रूप में पढ़ा और लिखा जाता है।

  2. Binary mode में Python text encoding और decoding अपने-आप लागू नहीं करता।

  3. इनका उपयोग images, audio, video और अन्य binary formats के लिए होता है।

  4. Data को सही तरह समझने के लिए संबंधित file format की जानकारी आवश्यक हो सकती है।

Advantages (लाभ)-
  • Media और अन्य binary data को उनके निर्धारित format में संभाला जा सकता है।

  • Binary mode में bytes को बिना text decoding के पढ़ा या लिखा जा सकता है।

  • यह images, audio, video और structured binary data के लिए उपयोगी है।

Important Point

Binary mode में bytes का उपयोग होता है, जबकि Text mode में strings (str) को पढ़ा और लिखा जाता है।

Binary mode uses bytes, whereas text mode reads and writes strings (str).

 

UTF-8 in Python - (Unicode Transformation Format – 8-bit)

UTF-8 एक character encoding है, जिसका उपयोग text को computer में store करने और पढ़ने के लिए किया जाता है। यह English, Hindi और अन्य languages के characters को represent कर सकता है।

In English-

UTF-8 is a character encoding used to store and read text on a computer. It can represent characters from English, Hindi, and other languages.

Example in Python
with open("data.txt", "w", encoding="utf-8") as file:
    file.write("Hello नमस्ते")

इस program में:

  • open() — File को खोलता है।

  • encoding="utf-8" — Text की encoding UTF-8 निर्धारित करता है।

  • file.write() — File में text लिखता है।

  • "Hello नमस्ते" — English और Hindi दोनों text हैं।

Output in data.txt:

Hello नमस्ते
UTF-8 का उपयोग क्यों करते हैं?
  1. Hindi और English text को सही तरीके से store करने के लिए।

  2. अलग-अलग languages के characters को support करने के लिए।

  3. Text में encoding से जुड़ी समस्याओं को कम करने के लिए।

Exam Point: UTF-8 stands for Unicode Transformation Format – 8-bit.

 

 

Related Notes