среда, 22 апреля 2015 г.

Проблема с записью в файл и печатью на экран / The problem with writing to a file and printing it to the screen

Всем привет,  сегодня я озадачился одной проблемой, у меня есть вот такой отрывок кода:
/
Hi everyone, today I've faced the same problem, I have this piece of code:


if r_value==1:
        r_addition = r_digit + r_digit2
        file_calculation.write  ('{0} + {1}' .format( r_digit, r_digit2))
        file_calculation.write (str(' = %s\n' % r_addition))


В током виде как я написал выше - все работает великолепно, но мне кажется так как то не правильно - не красиво. Сейчас я покажу как я хотел сделать:
/
In the current form as I wrote above - it works great, but I think it as something wrong, it is not beautiful. Now I will show how I wanted to do:



if r_value==1:
        r_addition = r_digit + r_digit2
        file_calculation.write  ('{0} + {1} = {3}' .format( r_digit, r_digit2, r_addition))

В таком виде как я написал выше не работает и выдает синтаксическую ошибку с которой я еще не разобрался. Сами понимаете что такая форма записи на много удобнее и приятнее чем то, что я написал выше.
/
In this form, as I wrote above does not work and throws a syntax error which I haven't figured out yet. You know that this form of entry is much easier and more enjoyable than what I wrote above.

Ошибка:
/
Error:
IndexError: tuple index out of range

Комментариев нет:

Отправить комментарий