[Tutor] Reading numbers from a text file

Phil phil_lor at bigpond.com
Wed Jul 10 23:21:36 CEST 2013


On 10/07/13 20:25, Oscar Benjamin wrote:
>> with open("config_file", "r") as file:
>>      myvars = file.read().splitlines()
>>
>>      myvars = [i.split(" ")[0] for i in myvars]
>
> If you just remove the "[0]" from the line above then i.split(" ")
> will return a list of both x and y. Then you can do e.g.:
>
> x, y = myvars[0]
>

Thanks Oscar, I keep overlooking this Python feature. I'm so used to x = 
var[0] any y = var[1].

-- 
Regards,
Phil


More information about the Tutor mailing list