पायथन फ़ाइल राइटलाइन () विधि
उदाहरण
संलग्न करने के लिए "ए" के साथ फ़ाइल खोलें, फिर फ़ाइल में संलग्न करने के लिए ग्रंथों की एक सूची जोड़ें:
f = open("demofile3.txt", "a")
f.writelines(["See
you soon!", "Over and out."])
f.close()
#open
and read the file after the appending:
f = open("demofile3.txt", "r")
print(f.read())
परिभाषा और उपयोग
विधि किसी सूची के आइटम को फ़ाइल में writelines()
लिखती है।
टेक्स्ट कहाँ डाला जाएगा यह फ़ाइल मोड और स्ट्रीम स्थिति पर निर्भर करता है।
"a"
: टेक्स्ट को फ़ाइल के अंत में डिफ़ॉल्ट रूप से वर्तमान फ़ाइल स्ट्रीम स्थिति में डाला जाएगा।
"w"
: फ़ाइल को वर्तमान फ़ाइल स्ट्रीम स्थिति, डिफ़ॉल्ट 0 पर टेक्स्ट डालने से पहले खाली कर दिया जाएगा।
वाक्य - विन्यास
file.writelines(list)
पैरामीटर मान
Parameter | Description |
---|---|
list | The list of texts or byte objects that will be inserted. |
और ज्यादा उदाहरण
उदाहरण
ऊपर जैसा ही उदाहरण है, लेकिन प्रत्येक सूची आइटम के लिए लाइन ब्रेक सम्मिलित करना:
f = open("demofile3.txt", "a")
f.writelines(["\nSee
you soon!", "\nOver and out."])
f.close()
#open
and read the file after the appending:
f = open("demofile3.txt", "r")
print(f.read())