Few coding suggestions

Ganesh Pal ganesh1pal at gmail.com
Sun Jan 11 12:44:35 CET 2015


Hello Team,

Iam trying to generate a file which would will should the contents in
the below format

# cat  /root/schedule.conf

Sunday 10:20 10:30
Sunday 10:30 10:40
Sunday 10:50  10:60


I have to build the above format on the local linux machine using
python 2.7 version and then copy the file to the remote machine.

Here is the progress and few questions on the same ,

Program :

node-1# cat time_range.py
def yield_times():
    from datetime import date, time, datetime, timedelta
    start = datetime.combine(date.today(), time(23, 50))
    yield start.strftime("%A %H:%M")
    while True:
        start += timedelta(minutes=10)
        yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(05):
     print gen.next()

node-1# python time_range.py
Sunday 23:50
Monday 00:00
Monday 00:10
Monday 00:20
Monday 00:30

(a)  How do I modify the output to have an another column with a
difference of 5 mins

Example :

node-1# python time_range.py

Sunday 23:50 23:05
Monday 00:00 00:05
Monday 00:10 00:05
Monday 00:20 00:15
Monday 00:30 00: 20

(b)  how to copy the above output (i.e with the new column to a file.)


(c)  The  final output should be a file , having the entries  day ,
start , end time of the remote file. how do  i pass the  this to
yeild-times()

import time

/* Assuming I retrive the below values h,m,d from the remote machine*/

h = time.strftime("%H")
m = time.strftime("%M")
d = date.today()


def yield_times():
      global h,m,d
    from datetime import date, time, datetime, timedelta
    start = datetime.combine(date.today(), time(int(h),int(m))) /*
converting string to int)
    yield start.strftime("%A %H:%M")
    while True:
        start += timedelta(minutes=10)
        yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(15):
     print gen.next()


Regards,
Ganesh



More information about the Python-list mailing list