Back-End Programming Exam  >  Back-End Programming Videos  >  Python Tutorial in Hindi  >  Python tutorial in Hindi 49 : How to write text files

Python tutorial in Hindi 49 : How to write text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

FAQs on Python tutorial in Hindi 49 : How to write text files Video Lecture - Python Tutorial in Hindi - Back-End Programming

1. कैसे पाठ फ़ाइलें लिखें?
उत्तर: आप Python में 'open()' फ़ंक्शन का उपयोग करके किसी भी टेक्स्ट फ़ाइल को लिख सकते हैं। इस फ़ंक्शन का उपयोग करने के लिए, आपको फ़ाइल का नाम और विधि दोनों दर्ज करनी होगी। उदाहरण के लिए, यदि आप एक नई फ़ाइल बनाना चाहते हैं और उसमें कुछ लिखना चाहते हैं, तो आपको निम्नलिखित कोड का उपयोग करना होगा: ``` file = open("filename.txt", "w") file.write("यह टेक्स्ट फ़ाइल में लिखा गया है।") file.close() ``` इसके बाद, आपकी टेक्स्ट फ़ाइल "filename.txt" में यह लिखा जाएगा।
2. कैसे पाठ फ़ाइलों को बैकअप करें?
उत्तर: पाठ फ़ाइलों को बैकअप करने के लिए, आप उन्हें किसी अन्य नाम से एक अलग फ़ोल्डर में कॉपी कर सकते हैं। इसके लिए, आप निम्नलिखित कोड का उपयोग कर सकते हैं: ``` import shutil source_file = "filename.txt" destination_folder = "backup_folder" shutil.copy(source_file, destination_folder) ``` इसके बाद, "filename.txt" फ़ाइल "backup_folder" नामक फ़ोल्डर में कॉपी होगी।
3. कैसे पाठ फ़ाइलों में डेटा जोड़ें?
उत्तर: आप Python में 'append' विधि का उपयोग करके पाठ फ़ाइलों में डेटा जोड़ सकते हैं। इस विधि का उपयोग करने के लिए, आपको फ़ाइल का नाम और विधि दोनों दर्ज करनी होगी। उदाहरण के लिए, यदि आपके पास एक मौजूदा फ़ाइल है और आप उसमें नए डेटा को जोड़ना चाहते हैं, तो आपको निम्नलिखित कोड का उपयोग करना होगा: ``` file = open("filename.txt", "a") file.write("यह नया डेटा है।") file.close() ``` इसके बाद, आपकी टेक्स्ट फ़ाइल "filename.txt" में नया डेटा जोड़ दिया जाएगा।
4. कैसे पाठ फ़ाइलों को पढ़ें?
उत्तर: आप Python में 'read()' विधि का उपयोग करके पाठ फ़ाइलों को पढ़ सकते हैं। इस विधि का उपयोग करने के लिए, आपको फ़ाइल का नाम और विधि दोनों दर्ज करनी होगी। उदाहरण के लिए, यदि आप एक मौजूदा फ़ाइल को पढ़ना चाहते हैं, तो आपको निम्नलिखित कोड का उपयोग करना होगा: ``` file = open("filename.txt", "r") data = file.read() print(data) file.close() ``` इसके बाद, आपकी टेक्स्ट फ़ाइल "filename.txt" की सामग्री पढ़ी जाएगी और उसे प्रिंट किया जाएगा।
5. कैसे पाठ फ़ाइलें हटाएं?
उत्तर: आप Python में 'remove()' फ़ंक्शन का उपयोग करके पाठ फ़ाइलें हटा सकते हैं। इस फ़ंक्शन का उपयोग करने के लिए, आपको फ़ाइल का पूरा पथ दर्ज करना होगा। उदाहरण के लिए, यदि आप एक फ़ाइल को हटाना चाहते हैं, तो आपको निम्नलिखित कोड का उपयोग करना होगा: ``` import os file_path = "full_path/filename.txt" os.remove(file_path) ``` इसके बाद, आपकी टेक्स्ट फ़ाइल "filename.txt" हटा दी जाएगी।
Related Searches

ppt

,

mock tests for examination

,

Objective type Questions

,

Python tutorial in Hindi 49 : How to write text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

,

Summary

,

Previous Year Questions with Solutions

,

Sample Paper

,

Python tutorial in Hindi 49 : How to write text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

,

past year papers

,

Python tutorial in Hindi 49 : How to write text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

,

study material

,

Exam

,

Important questions

,

practice quizzes

,

Free

,

shortcuts and tricks

,

MCQs

,

pdf

,

Viva Questions

,

Extra Questions

,

video lectures

,

Semester Notes

;