Search code examples
pythonpython-3.xlinecache

Python code to run for next 100 days from today


I want to run below line of code for 200 days from today. Suppose today is 1st days so my code is-

line = linecache.getline("lines1.txt",1)
print(line)

Suppose today is 2nd days so my code is-

line = linecache.getline("lines1.txt",2)
print(line)

Suppose today is 3rd days so my code becomes-

line = linecache.getline("lines1.txt",3)
print(line)

I want above 1,2,3,4,5......200 to be calculated everyday. I don't want a loop to run for 200 days.

I just need to get 1,2,3,4,5......200 count from python Date system or any other counting system.


Solution

  • set a marker date then calculated difference between today dan marker date

    (datetime.datetime(2016,9,2) - datetime.datetime(2016,9,1) ).days
    output:
    1