Kenni
Kenni

Reputation: 457

Python date generation

I want to write a python script that generate the following date-formate: Months / day / hour / minutes in a 10min resolution. For example: 1, 1 ,1 ,10 is 1.Jan at 00:10:

import numpy as np
size = (2190,4)
epw = np.zeros(size)
k = 0 # counter

year= [31,28,31,30,31,30,31,31,30,31,30,31]
for months in year:
    for day in months:
        for hour in range(1,25):
            for minute in range(1,7):
                epw[k,0] = months
                epw[k,1] = day
                epw[k,2] = hour
                epw[k,3] = minute *10
                k=k+1

I got the error message: "'int' object is not iterable". Is this even a proper method? If yes, do you have an idea how to fix the error?

Thank you very much

Upvotes: 1

Views: 61

Answers (2)

Kaushal Kumar Singh
Kaushal Kumar Singh

Reputation: 829

import numpy as np
size = (2190,4)
epw = np.zeros(size)
k = 0 # counter

year= [31,28,31,30,31,30,31,31,30,31,30,31]
for months in year:
    for day in range(1, months+1):
        for hour in range(1,25):
            for minute in range(1,7):
                epw[k,0] = months
                epw[k,1] = day
                epw[k,2] = hour
                epw[k,3] = minute *10
                k=k+1

Upvotes: 2

baldr
baldr

Reputation: 2999

Just fix this:

    for day in range(1, months + 1):

Upvotes: -1

Related Questions