-2

I would like to save a file with formated text however, I don't know where to put my formatting command.

Here is my reproducible code:

start = "2008-12-08"
end = "2009-12-27"
template ="""- {start} + {end}:
    CycleCalendar:
        start_date: {start}
        start_type: Packing
        end_date: {end}
        end_type: unpacking
        max_duration: 720
    """

with open("conf.txt", 'w') as f:
    f.write(template)

I was thingiking about use .format however, don't know where to put it.

My question is unique because it is using objects for the formatting of the text

Thank you!

Lukáš Tůma
  • 350
  • 2
  • 15

1 Answers1

1

Try this code:

start = "2008-12-08"
end = "2009-12-27"
template ="""- {start} + {end}:
    CycleCalendar:
        start_date: {start}
        start_type: Packing
        end_date: {end}
        end_type: unpacking
        max_duration: 720
    """

with open("conf.txt", 'w') as f:
    f.write(template.format(start=start, end=end))
Massifox
  • 4,369
  • 11
  • 31