Formatted input function
clp2 at rebertia.com
Sat Sep 5 20:16:03 CEST 2009
On Sat, Sep 5, 2009 at 8:00 AM, Terry Reedy<tjreedy at udel.edu> wrote:
> Chris Rebert wrote:
>> On Sat, Sep 5, 2009 at 3:13 AM, candide<candide at free.invalid> wrote:
>>> I have a text file and the first line provides the best score of a game.
>>> line has the following format :
>>> Best score : 42
>>> In order to update the score, I try to retrieve the score value.
>>> In C, we would manage this with the following statement :
>>> fscanf(foo_file, "Best score : %d", &score);
>>> Does Python provide an equivalent ?
>> Not an exact one, but it's still easily accomplished:
>> score = int(foo_file.read().split(":").strip())
> One must, of course, select the second item from the list returned by
One should not answer threads at 3AM local time without
double-checking the solution...
More information about the Python-list