File Processing in Python

File Processing in Python

File is a named location on the system storage which records data for later access. It enables constant storage in a non-volatile memory i.e. hard disk. Since, random access memory (RAM) is volatile which loses its data when computer is turned off, we use files for future use of the data.

 फाइल सिस्टम स्टोरेज पर एक नामित स्थान है जो बाद में एक्सेस के लिए डेटा रिकॉर्ड करता है। यह एक नॉन-वोलाटाइल मेमोरी यानी हार्ड डिस्क में निरंतर स्टोरेज को इनैबल करता है। चूंकि, रैंडम एक्सेस मेमोरी (रैम) अस्थिर है जो कंप्यूटर बंद होने पर अपना डेटा खो देता है, हम डेटा के भविष्य के उपयोग के लिए फाइलों का उपयोग करते हैं।

When we want to read from or write to a file we need to open it first. When we are done, it needs to be closed, so that resources that are tied with the file are freed.

जब हम किसी फाइल से रीड या राईट करना चाहते हैं तो हमें उसे पहले ओपेन करना होगा। जब हम इसे कर लेते हैं, तो इसे क्लोज करने की आवश्यकता होती है, ताकि फाइल के साथ लगे रिसोर्स को मुक्त किया जा सके।

For this requirement we should go for file processing. Hence, you should be quite careful while implementing file handling for reporting or any other purpose. Optimizing a single file operation can help you produce a high-performing application or a strong solution for automated software testing.

इस आवश्यकता के लिए हमें फाइल प्रोसेसिंग के लिए जाना चाहिए। इसलिए, आपको रिपोर्टिंग या किसी अन्य उद्देश्य के लिए फाइल हैंडलिंग को लागू करते समय काफी सावधानी बरतनी चाहिए। एक सिंगल फाइल ऑपरेशन का अनुकूलन करने से आपको हाई परफार्मिंग वाले एप्लिकेशन या स्वचालित सॉफ्टवेयर परीक्षण के लिए एक मजबूत समाधान बनाने में मदद मिल सकती है।

Files are very common permanent storage areas to store our data. In order to use files, we have to understand file I/O operations that means, how data is read or write to a file. This process is nothing but File processing or file handling.

फाइलें हमारे डेटा को संग्रहीत करने के लिए बहुत सामान्य स्थायी स्टोरेज क्षेत्र हैं। फाइलों का उपयोग करने के लिए, हमें फाइल I/0 ऑपरेशन को समझना होगा, जिसका अर्थ है कि डेटा फाइल में कैसे रीड या राईट किया जाता है। यह प्रक्रिया कुछ और नहीं बल्कि फाइल प्रोसेसिंग या फाइल हैंडलिंग है।

What Does File Handling Mean?
फाइल हैंडलिंग का क्या मतलब है?

The concept of file handling has stretched over various other languages, but the implementation is either complicated or lengthy, but alike other concepts of Python, this concept here is also easy and short. Python treats file differently as text or binary and this is important.

फाइल हैंडलिंग का कॉन्सेप्ट विभिन्न अन्य भाषाओं में फैला हुआ है, लेकिन कार्यान्वयन या तो जटिल या लंबा है, लेकिन पायथन की अन्य अवधारणाओं को समान रूप से प्रस्तुत करता है, यहां यह अवधारणा भी आसान और संक्षिप्त है। यहां यह महत्वपूर्ण है कि पायथन फाइल को टेक्स्ट या बाइनरी के रूप में अलग तरह से व्यवहार करता है।

In Python there are two types of files: Like C and C++, Python also supports two types of files i.e., text files and binary files.

पायथन में दो प्रकार की फाइलें होती हैं: C और C++ की तरह, पायथन भी दो प्रकार की फाइलों का समर्थन करता है, अर्थात, टेक्स्ट फाइलें और बाइनरी फाइलें ।

1.Text Files: A text file in which each byte represents one character according to the ASCII code. ASCII files are sometimes called plain text files. Usually we can use text files to store character data, for example biodata.txt

टेक्स्ट फाइलें: एक टेक्स्ट फाइल जिसमें प्रत्येक बाइट ASCII कोड के अनुसार एक कैरेक्टर का प्रतिनिधित्व करता है। ASCII फाइलें कभी-कभी प्लेन टेक्स्ट फाइलें कहलाती हैं। आमतौर पर हम कैरेक्टर डेटा को संग्रहीत करने के लिए टेक्स्ट फाइलों का उपयोग कर सकते हैं, उदाहरण के लिए biodata.txt.

2.Binary Files: A binary file, in which there is no one-to-one mapping between bytes and characters. Usually we can use binary files to store binary data like image, video files, audio files etc.,

बाइनरी फाइलें: एक बाइनरी फाइल, जिसमें बाइट्स और कैरेक्टर के बीच वन-बाई-वन मैपिंग नहीं होती है। आमतौर पर हम बाइनरी फाइलों का उपयोग बाइनरी डेटा जैसे इमेज, वीडियो फाइलों, ऑडियो फाइलों आदि को संग्रहीत करने के लिए कर सकते हैं।

File Paths – फाइल पाथ

When you access a file on an OS, a file path is required. The file path is a string that represents the location of a file. It’s broken up into three major parts:

जब आप किसी OS पर फाइल एक्सेस करते हैं, तो एक फाइल पाथ की आवश्यकता होती है। फाइल पाथ एक स्ट्रिंग है जो फाइल के स्थान का प्रतिनिधित्व करता है। यह तीन प्रमुख भागों में ब्रेक हो गया है:

1.Folder Path: The file folder location on the file system where subsequent folders are separated by a forward slash / (UNIX) or backslash \ (Windows)

फोल्डर पाथः फाइल सिस्टम पर फाइल फोल्डर का स्थान जहाँ बाद के फोल्डर एक फॉरवर्ड स्लैश / (यूनिक्स) या बैकस्लैश (विंडोज) द्वारा अलग किए जाते हैं।

2.File Name: The actual name of the file

फाइल का नाम: फाइल का वास्तविक नाम।

3.Extension: The end of the file path pre-pended with a period (.) used to indicate the file type

विस्तारः फाइल पाथ का अंत फाइल प्रकार को इंगित करने के लिए उपयोग की गई अवधि (.) के साथ प्री-पेन्डेड हैं।

In Python, file processing takes place in the following order:

पायथन में, फाइल प्रोसेसिंग निम्न क्रम में होती है:

1.Open a file which returns a file handle.

एक फाइल ओपेन करें, जो एक फाइल हैंडल पर रिटर्न होती है।

2.Use the handle to perform read or write action.

रीड या राईट की क्रिया करने के लिए हैंडल का उपयोग करें।

3.Close the file handle.

फाइल हैंडल को क्लोज करें।

Before you do a read or write operation to a file in Python, you need to open it first. And as the read/write transaction completes, you should close it to free the resources tied with the file.

इससे पहले कि आप पायथन में एक फाइल पर एक रीड या राईट का ऑपरेशन करें, आपको पहले इसे ओपेन करने की आवश्यकता है और जैसा कि रीड/राईट का लेनदेन पूरा हो जाता है, आपको फाइल के साथ लगे रिसोर्स को मुक्त करने के लिए इसे क्लोज करना चाहिए।

In the next sections, we’ll touch upon all the Python file handling topics one by one.

अगले सेक्शन में, हम एक-एक करके सभी पायथन फाइल को एक-दूसरे से हैंडलिंग के लिए स्पर्श करेंगे।  

Chapter wise Model Paper Link

About Me