python - Reading lines from a text file into a variable -


मेरे डेस्कटॉप पर एक टेक्स्ट फाइल मिली है, lines.txt :

  लाइन सामग्री सामान लाइनों नौकाओं नौकाओं लाइनों  

और सभी मैं करने की कोशिश कर रहा हूँ यह एक चर में पढ़ा है, लेकिन हर बार मैं इसे प्रिंट, मैं एक खाली सूची यहाँ मेरा कोड है:

  INF = 'C: /Users/me/Desktop/text.txt' def repeatWords (inF): आयात स्ट्रिंग infile = open (inF, 'r') text = <      

जब मैं प्रिंट (पाठ) infil.readlines () infile.close () प्रिंट (पाठ) repeatWords (inF)

, मुझे जो भी मिलता है वह एक खाली सूची है। क्या मैं गलत कर रहा हूं?

आपके कोड में कई समस्याएं हैं I मुझे नहीं पता है कि आप print (text) कहां कॉल करते हैं, लेकिन इसे के बाद को असाइन किया जाता है। यहाँ एक सही संस्करण है:

  def repeat_words (in_f, out_f): खोलने के साथ (in_f, 'r') infile के रूप में: text = infile.readlines () प्रिंट (टेक्स्ट)  

Comments

Popular posts from this blog

sql - Find last match with latest inserted name in table -

c# - XML serialize base class without knowing derived class -

ios - Invalid IPA: missing embedded provisioning profile. Are you sure this is an ad hoc? -