File Processing in Python (Python में फाइल प्रोसेसिंग) :-
File Processing वह प्रक्रिया है जिसमें computer program के माध्यम से file को खोलना, पढ़ना, लिखना, उसमें data जोड़ना और file को बंद करना शामिल होता है।
Python में file processing के लिए मुख्य रूप से open(), read(), write() और close() जैसे functions और methods का उपयोग किया जाता है।
English -
File Processing is the process of opening, reading, writing, adding data to, and closing a file through a computer program.
In Python, functions and methods such as open(), read(), write(), and close() are mainly used for file processing.
File Processing के मुख्य चरण (Main Steps)-
Step 1: Open a File — फाइल खोलना -
File को access करने के लिए open() function का उपयोग किया जाता है।
file = open("student.txt", "r")
Step 2: Perform an Operation — कार्य करना -
File से data पढ़ सकते हैं:
data = file.read() print(data)
या file में data लिख सकते हैं:
file.write("Hello Python")
ध्यान दें: write() के लिए file को write करने योग्य mode में खोलना आवश्यक है।
Step 3: Close the File — फाइल बंद करना
file.close()
File बंद करने से संबंधित resources मुक्त करने में सहायता मिलती है।
Complete Example: Writing and Reading a File
Output:
Welcome to Python File Processing Explanation (व्याख्या)-
पहले message.txt को write mode में खोला गया।
write() से message file में store किया गया।
close() से file बंद की गई।
फिर उसी file को read mode में खोला गया।
read() से पूरा text पढ़ा गया।
print() से text screen पर दिखाया गया।