पायथन में, आप एक फ़ाइल से एक स्ट्रिंग के रूप में एक पंक्ति पढ़ते हैं। इसके बाद आप स्ट्रिंग के साथ काम डेटा प्राप्त करने के लिए कर सकते हैं:
with open("datafile") as f:
for line in f: #Line is a string
#split the string on whitespace, return a list of numbers
# (as strings)
numbers_str = line.split()
#convert numbers to floats
numbers_float = [float(x) for x in numbers_str] #map(float,numbers_str) works too
मैं यह सब कदम की एक गुच्छा में किया है, लेकिन आप अक्सर देखेंगे लोग उन्हें गठबंधन:
with open('datafile') as f:
for line in f:
numbers_float = map(float, line.split())
#work with numbers_float here
अंत में, गणितीय सूत्र में उनका उपयोग करना भी आसान है।
with open('datafile') as f:
for line in f:
numbers_float = map(float, line.split())
print function(numbers_float[0],numbers_float[1],numbers_float[2])
#shorthand: print function(*numbers_float)
'[नक्शा (नाव, ln ls.strip()] ' –