def calendar_(): cal = calendar.month(2017, 6) # by default w=2 l=1 print cal # 2017年6月份日历 print '--------------------' # calendar内置函数 #calendar of year 2017: c=distance(month); l=line(week); w=distance(day) print calendar.calendar(2017, w=2, l=1, c=6) #lenth(line)= 21* W+18+2* C print calendar.firstweekday() # start weekday, 0 by default, i.e. Monday # calendar.setfirstweekday(weekday) # 0(Monday) to 6(Sunday) print calendar.isleap(2017) # return True or False print calendar.leapdays(2000, 2016) # number of leap years between year 1 and year 2 print calendar.month(2017, 6) print calendar.monthcalendar(2017, 6) print calendar.monthrange(2017, 6) # return (a, b) a=starting weekday b=days in month calendar.prcal(2017, w=2, l=1, c=4) # equals to print calendar.calendar(2017, w=2, l=1, c=4) calendar.prmonth(2017, 6) # equals to print calendar.month(2017, 6) print calendar.timegm(time.localtime()) #和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍 print calendar.weekday(2017, 6, 30) # calendar.weekday(year,month,day) return date code
def program(): # Inputs for month and year month = input('Please enter month: ') year = input('Please enter year: ') try: # Return month current month if no inputs are entered if (month == '') and (year == ''): print('The current month is: ', datetime.now().month) # Returns month and current year if only month is entered elif (month != '') and (year == ''): calendar.prmonth(datetime.now().year, int(month)) # Returns the whole calendar of that year if month is not entered elif (month == '') and (year != ''): calendar.prcal(int(year)) # Returns the month and year if both are entered else: calendar.prmonth(int(year), int(month)) except ValueError: print('Inputs are not in integer. Please try again.') # Restart program if there's an error program() finally: restart = input('Enter a new date? y or n: ') while (restart != 'y') and (restart != 'n'): restart = input('Please input y or n: ') else: if restart == 'y': program() elif restart == 'n': print('End Program')
def _cal(): '''打印全年日历表 打印接下来10日的交易情况''' fmt = '%Y-%m-%d' year_now = time.strftime("%Y", time.localtime(time.time())) calendar.prcal(int(year_now)) print(time.ctime()) for x in range(10): time_now_struct = time.localtime(time.time() + x * 86400) date_str = time.strftime(fmt, time_now_struct) week_str = time.strftime('%a', time_now_struct) week_num = time.strftime('%W', time_now_struct) if market_status.date_justify(date_str) == 0: result = '休市\33[0m' else: result = '\33[1;33m交易\33[0m' print("%d %s %s 第%s周 %s" % ( x, date_str, result, week_num, week_str, )) #return [] pass
def calendar_(): cal = calendar.month(2017, 6) # by default w=2 l=1 print cal # 2017年6月份日历 print '--------------------' # calendar内置函数 #calendar of year 2017: c=distance(month); l=line(week); w=distance(day) print calendar.calendar(2017, w=2, l=1, c=6) #lenth(line)= 21* W+18+2* C print calendar.firstweekday() # start weekday, 0 by default, i.e. Monday # calendar.setfirstweekday(weekday) # 0(Monday) to 6(Sunday) print calendar.isleap(2017) # return True or False print calendar.leapdays( 2000, 2016) # number of leap years between year 1 and year 2 print calendar.month(2017, 6) print calendar.monthcalendar(2017, 6) print calendar.monthrange( 2017, 6) # return (a, b) a=starting weekday b=days in month calendar.prcal( 2017, w=2, l=1, c=4) # equals to print calendar.calendar(2017, w=2, l=1, c=4) calendar.prmonth(2017, 6) # equals to print calendar.month(2017, 6) print calendar.timegm( time.localtime()) #和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍 print calendar.weekday( 2017, 6, 30) # calendar.weekday(year,month,day) return date code
def myCal(*args): print(args) if len(args) == 3: calendar.prmonth(int(args[2]), int(args[1]), w=0, l=0) elif len(args) == 2: calendar.prcal(int(args[1])) else: print(datetime.date(datetime.now()))
def any_year(): """ Prompt for year and print calendar. Two-digit years are converted according to the POSIX or X/Open standard: values 69-99 are mapped to 1969-1999, and values 0–68 are mapped to 2000–2068. """ y= int( input( " ENTER: Year.............? " ) ) if 69 <= y <= 99: y = y + 1900 elif 0 <= y <= 68: y = y + 2000 calendar.prcal( y )
def printyear(): while True: try: year = int(input("\nEnter the year(1..9999) : ")) if year > 9999 or year < 1: print("year is out of range!!") raise Exception("Error!") else: break except: print("Please enter a valid value within 1 to 9999!!") print("\n") print("=" * 20, "<<< PRINTING CALENDAR>>>", "=" * 20, "\n") prcal(year)
def kalendor(self, model, mtime): print("*" * 40) if (model == "y"): print("Below is year " + mtime + "calendar: ") calendar.prcal(int(mtime)) elif (model == "q"): mran = mtime.split(",") year = mran[0] print("Below is year " + year + "calendar: ") q = mran[1] if (q == "1"): mst = 1 med = 3 elif (q == "2"): mst = 4 med = 6 elif (q == "3"): mst = 7 med = 9 elif (q == "4"): mst = 10 med = 13 else: self.error.error3() return -1 for i in range(mst, med + 1): m = calendar.month(int(year), i) print(m) elif (model == "c"): mran = mtime.split(",") year = int(mran[0]) print("Below is year %d calendar: " % (year)) mst = int(mran[1]) med = int(mran[2]) if (mst <= 0 or med > 12): self.error.error3() return -1 for i in range(mst, med + 1): m = calendar.month(int(year), i) print(m) else: mran = mtime.split(",") year = int(mran[0]) print("Below is year %d calendar: " % (year)) m = int(mran[1]) print(calendar.month(int(year), m)) print("*" * 40)
print(prime_no1) # 16.Reverse a string print("vishalsm"[::-1]) # 17.Sum of n numbers i.e 0 to 10 from functools import reduce print(reduce(lambda x,y:x+y,range(11))) #another method print(10*(10+1)/2) #easy method print(sum(range(11))) # 18.Display Calender import calendar calendar.prcal(2020) # 19.Display Current date and Time from datetime import datetime now = datetime.now() print(now.strftime("%d-%m-%Y %H:%M:%S")) # 20.Get words having more than 4 characters txt="i am creating powerful python one liners" print([x for x in txt.split() if len(x)>4 ]) # 21.Display characeter and index in a string a='abcdefg' print([(i,a.index(i)) for i in a]) print([(a[i],i) for i in range(len(a))])
i = u - i u = u - i print(u, i) print() print("random no priting") print() import random print(random.randint(0, 56)) print() print("kilo to miles") print() kilo = float(input("enter ")) convfact = 0.62137 miles = kilo * convfact print("miles is ", miles) print() print("celcius to fahrenheit") print() cel = float(input("enter")) fahren = (cel * 1.8) + 32 print("%0.1f celcius is equal to %0.1f fahrenheit" % (cel, fahren)) print() print("print Calender") print() import calendar g = int(input("enter year")) h = int(input("enter month")) print(calendar.month(g, h)) print(calendar.prcal(2020))
import calendar cal = calendar.calendar(2018, w=0, l=1, c=0) print(cal) print(calendar.isleap(2019)) print(calendar.leapdays(1984, 2018)) print(help(calendar.leapdays)) print(calendar.month(2018, 9)) w, k = calendar.monthrange(2018, 9) print(w) print(k) print(help(calendar._locale)) calendar.prcal(2018) calendar.prmonth(2018, 3) print(calendar.prweek(2018, 9, 16))
""" Homework 1 >Problem 3 Author: Derrick Unger Date: 1/16/20 CSC232 Winter 2020 """ import calendar as cal cal.setfirstweekday(6) print(cal.prcal(2020))
t1 = time.time() a = time.strftime("%B %dth %A %I:%M", time.localtime()) print(a) time1 = time.ctime(1234567) print(time1) print(time.strftime(time1)) import calendar calendar.calendar(2000) calendar.prcal(2000) print(calendar.monthrange(2015, 10)) print(calendar.monthrange(1994, 9)) import random # 중복없이 무작위로 뽑아줌 # rr = random.sample(range(100),10) # print(rr) # rrr = random.shuffle(rr) # rrrr= random.choice(rrr) # print(rrrr)
time.time())) #'05/01/01' %x : 현재 설정된 로케일에 기반한 날짜 출력. 05/01/01 time.strftime('%c', time.localtime( time.time())) #'05/01/01 17:22:21' %c : 날짜와 시간을 출력. #time.sleep : 루프 안에서 많이 쓰임. 일정시간 간격을 주기 위해 사용된다. #sleep1.py import time for i in range(10): print(i) time.sleep(1) #1초 간격으로 0부터 9까지의 숫자를 출력한다. time.sleep()안에 실수형으로 들어갈 수 있다. 0.5등 #달력쓰기(calender) import calendar print(calendar.calendar(2017)) calendar.prcal(2017) #이 둘은 같은 결과를 보여준다. #2001년 4월만 보기 calendar.prmonth(2001, 4) #요일보기 calendar.weekday(2001, 4, 28) #5 #0 : 월요일 ~~ 6 : 일요일 #calendar.monthrange(년도, 월) : 해당 당의 1일이 무슨 요일인지, 그달이 몇일까지 있는지를 보여준다. calendar.monthrange(2001, 4) #(6, 30) 1일이 일요일이고, 30일까지 있음을 의미한다. #난수 발생시키기(random) import random random.random() #0.0에서 1.0 사이의 실수값 중에서 난수값을 돌려준다. random.randint(1, 10) #1에서 10사이의 정수중 난수로 하나를 준다. random.randint(1, 55) #1에서 55사이
filename = tempfile.mkdtemp() import time time.time() time.localtime(time.time()) time.asctime(time.localtime(time.time())) time.ctime() time.strftime('%c', time.localtime(time.time())) for i in range(10): print(i) time.sleep(1) import calendar print(calendar.calendar(2019)) calendar.prcal(2016) calendar.prmonth(2015, 6) calendar.weekday(2015, 6, 30) #0~6 -> 0 = 월, 1 = 화 .... 6= 일 calendar.monthrange(2015,12) import random random.random() random.randint(1, 10) random.randint(1, 55) def random_pop(data): number = random.randint(0, len(data) - 1) return data.pop(number) if __name__ == "__main__": data = [1, 2, 3, 4, 5]
import calendar year = input("Type in the year number: ") calendar.prcal(year)
#!/usr/bin/env python # 12_Modules import calendar year = int(input('Type in the bloody year: ')) calendar.setfirstweekday(calendar.SUNDAY) calendar.prcal(year) # Prints the calendar for an entire year as returned by calendar(). from time import time, ctime prev_time = "" while True: the_time = ctime(time()) if prev_time != the_time: print("The time is:", ctime(time())) prev_time = the_time
# prmonth(year, month) 打印给定月份的日历 calendar.prmonth(2015, 9) """ September 2015 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [Finished in 0.3s] """ # prcal(year) 打印给定年份的日历 calendar.prcal(2015) """ 2015 January February March Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 1 1 5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8 12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15 19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22 26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29 30 31 April May June Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
from calendar import prcal year = input("Type in the year number: ") prcal(year)
from calendar import prcal from calendar import month year = input(" Type the year number: ") prcal(year) print month(year, 9)
#!/usr/bin/env python # cal.py # emulate the original Unix `cal` command # TBD: highlight the current day (cross-platform Linux + Windows) import sys import calendar import time # simpler than datetime calendar.setfirstweekday(calendar.SUNDAY) if len(sys.argv) == 2: Y= sys.argv[1] calendar.prcal( int(Y) ) elif len(sys.argv) == 3: Y= sys.argv[1] m= sys.argv[2] calendar.prmonth( int(Y), int(m) ) else: Y= time.strftime('%Y') m= time.strftime('%m') calendar.prmonth( int(Y), int(m) ) #EOF
#!/usr/bin/python # -*-coding:utf-8-*- """ @author__ = 'kaerser' @time:2016/9/13 23:12 """ import calendar # yy = int(raw_input('请输入年份:')) # mm = int(raw_input('请输入月份:')) # print calendar.month(yy,mm) # print calendar.month(2016,9) print type(calendar.prcal(2016))
print(datetime.datetime.now()) print() print("creating date object") print(datetime.datetime(2018, 12, 10)) print() print("creating date object #2") print(datetime.datetime(2018, 12, 10, 14, 15, 10)) print() from datetime import datetime as dt print("Comparing time b/w 8 am to 4 pm") if dt(dt.now().year, dt.now().month, dt.now().day, 8) < dt.now() < dt(dt.now().year, dt.now().month, dt.now().day, 16): print("Working hours") else: print("Fun hours") print() import calendar print("printing calendar of month dec 19") cal = calendar.month(2019, 12) print(cal) print() print("printing the calendar of whole year") calendar.prcal(2019)
print(time.time()) # UTC 실수 print(time.localtime(time.time())) print(time.asctime(time.localtime(time.time()))) print(time.ctime()) print(time.strftime('%c', time.localtime(time.time()))) for i in range(2): print(i) time.sleep(1) # calendar import calendar calendar.prcal(2015) # print(calendar.calendar(2015)) calendar.prmonth(2015, 11) print(calendar.weekday(2015, 11, 25)) # 2 weekday (mon=0, sun=6) print(calendar.monthrange(2015, 11)) # (0, 30) weekday, day count # random import random print(random.random()) print(random.randint(1,10)) # 1~10 print(random.choice(['a', 'b', 'c'])) d = [1,2,3]
# create variable localtime using the time.localtime function on the ticks format it using time.asctime() print(localtime) # prints out the time can be reformatted cal = calendar.month(2013, 12) # create a new calender called cal set it for the year 2013, month 12 (december) print(cal) # print out the calendar we created, it is already formatted offset = time.altzone # sets variable offset to local time in seconds behind utc. !ONLY USE IF DAYLIGHT IS NONZERO! offset1 = offset/3600 # perform math on offset divide it by 3600(60 seconds * 60 minutes) to get the hours print(offset1) # print the offset from utc users localtime is time.ctime() # converts a time expressed in seconds since the 1/1/1970 to a string representing local time time.gmtime() # converts a time expressed in seconds since the epoch to a struct_time in UTC # struct_time(tm_year=, tm_mon=, tm_mday=, tm_hour=, tm_min=, tm_sec=, tm_wday=, tm_yday=, tm_isdst=) time.localtime() # similar to gmtime() but it converts number of seconds to local time time.mktime(t) # converts the arguments in the () to seconds since 1/1/1970 time.sleep(1) # suspends execution of next command by number of seconds specified in the () # converts tuple or struct_time representing a time returned by gmtime(), localtime() as string specified by format args time.strftime("%b %d %Y %H:%M:%S", time.gmtime()) # %b=abbr. month, %d=day of month, %Y=year, %H:%M:%S= hours:min:secs # parses a string representing time in a format. The return value is a struct_time as returned by gmtime(), localtime() structure_time = time.strptime("30 Nov 00", "%d %b %y") # format is (time, formatting) time.tzname # returns the name of the local timezone (est or edt) calendar.firstweekday() # returns the setting for first day of week default it is monday, use setfirstweekday to change calendar.calendar(2013, w=2, l=1, c=6) # Returns a multiline string with a calendar for year specified # w = width in characters of each date, l = number of lines for each week, c = number of spaces between columns calendar.isleap(2013) # returns true if year specified is a leap year else returns false calendar.leapdays(2000, 2013) # Returns the total number of leap days in the years within range(y1,y2) calendar.month(2013, 1, w=2, l=1) # Returns a multiline string with a calendar for year/month specified calendar.monthcalendar(2013, 1) # returns a list of days in each week for the month specified in the year calendar.monthrange(2013, 1) # returns first day (0 is monday - 6 is sunday) of the month and number of days in month calendar.prcal(2013, w=2, l=1, c=6) # like print calendar.calendar(year, w, l, c) calendar.prmonth(2013, 1, w=2, l=1) # like print calendar.month(year, month, w, l) # calendar.timegm(tupletime) accepts a time instant in time-tuple form and returns the same instant as number of seconds calendar.weekday(2013, 1, 21) # Returns the weekday code for the given date (monday)
import calendar __author__ = 'Egidio' '''This program show you the calendar year ''' calendar.prcal(2015) # Insert the year than you want show
#!/usr/bin/python import calendar ''' calendar.month(year,month,w=2,l=1) Returns a multiline string with a calendar for month month of year year, one line per week plus two header lines. w is the width in characters of each date; each line has length 7*w+6. l is the number of lines for each week. ''' cal=calendar.month(2008,2,6,2) print "Here is the calendar: " print cal; cal1=calendar.prcal(2008,2,1,6) ''' in the above code we don't required to use the print statement like print calendar.calendar(year,w,l,c) ''' cal2=calendar.prmonth(2012,6,2,1) #print cal2; ''' Like print calendar.month(year,month,w,l). '''
import calendar nam = input("Nhap nam : ") calendar.prcal(name)
#!/usr/bin/python # -*- coding: UTF-8 -*- import calendar as cld #calendar.calendar(year,w=2,l=1,c=6) #返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。 #每日宽度间隔为w字符。每行长度为21* W+18+2* C。l是每星期行数 print(cld.calendar(2017, 1, 2, 2)) cld.prcal(2017, 1, 1, 3) # = print cld.calendar(2017, 1, 1, 3) #返回一个多行字符串格式的year年month月日历,两行标题,一周一行 cal = cld.month(2017, 4, 1, 1) print('\n', u'2017年4月份的日历:') print(cal) print('\n', u'2017年5月份的日历:') print(cld.prmonth(2017, 5, 1, 1)) # = print cld.month(2017, 5, 1, 1) #是闰年返回True,否则为false。 print(cld.isleap(2017)) #返回在Y1,Y2两年之间的闰年总数 print(cld.leapdays(2000, 2017)) #返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。 #Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。 print(cld.monthcalendar(2017, 4)) #返回两个整数。第一个是该月的星期几的日期码,第二个是该月的日期码。 #日从0(星期一)到6(星期日);月从1到12。 print(u'本月开始星期%d+1,本月有%d天' % cld.monthrange(2017, 4))
def year(): calendar.prcal(localtime()[0])
def get_cal(year): a = calendar.prcal(year) return a
# -*- coding: UTF-8 -*- import calendar cal = calendar.month(2016, 1) print cal print calendar.calendar(2016, w=2, l=1, c=6) print calendar.month(2017, 8, w=2, l=1) print calendar.monthcalendar(2017, 5) print calendar.monthrange(2017, 8) calendar.prcal(2017, w=2, l=1, c=6) calendar.prmonth(2016, 2, w=2, l=1) print calendar.weekday(2017, 8, 9)
import calendar cal = calendar.prcal(2018) print(cal)
import calendar c = calendar.calendar(2020) print(c) # calendar模块用法 calendar.calendar(year, w=2, l=1, c=6) # 返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。 每日宽度间隔为w字符。每行长度为21* W+18+2* C。l是每星期行数。 calendar.firstweekday() # 返回当前每周起始日期的设置。默认情况下,首次载入caendar模块时返回0,即星期一。 calendar.isleap(year) # 是闰年返回True,否则为false。 calendar.leapdays(y1, y2) # 返回在Y1,Y2两年之间的闰年总数。 calendar.month(year, month, w=2, l=1) # 返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7* w+6。l是每星期的行数。 calendar.monthcalendar(year, month) # 返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。 calendar.monthrange(year, month) # 返回两个整数。第一个是该月的星期几的日期码,第二个是该月的日期码。日从0(星期一)到6(星期日);月从1到12。 calendar.prcal(year, w=2, l=1, c=6) # 相当于 print calendar.calendar(year,w,l,c). calendar.prmonth(year, month, w=2, l=1) # 相当于 print calendar.calendar(year,w,l,c)。 calendar.setfirstweekday(weekday) # 设置每周的起始日期码。0(星期一)到6(星期日)。 calendar.timegm(tupletime) # 和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍(1970纪元后经过的浮点秒数)。 calendar.weekday(year, month, day) # 返回给定日期的日期码。0(星期一)到6(星期日)。月份为 1(一月) 到 12(12月)
# Stretch goal: if the user doesn't specify anything on the command line, show # the calendar for the current month. See the 'datetime' module. # Hint: this should be about 15 lines of code. No loops are required. Read the # docs for the calendar module closely. import calendar import datetime import sys currentDate = datetime.datetime.now() print('DateNow: {}'.format(currentDate)) m, y = None, None print('\n Month: {0}\n Year: {1}\n'.format((m), (y))) for i in range(1, len(sys.argv)): if int(sys.argv[i]) < 12 and int(sys.argv[i]) >= 0: m = sys.argv[i] elif int(sys.argv[i]) > 12: y = sys.argv[i] if m and y: calendar.prmonth(int(y), int(m)) elif m: calendar.prmonth(currentDate.year, int(m)) elif y: calendar.prcal(int(y)) elif not m and not y: calendar.prmonth(currentDate.year, currentDate.month)
def calendar_func(): ''' 日历相关的操作 默认星期一作为一周的第一天, 可设置 ''' # === Calendar === # Calendar(firstweekday=0) // Calendar对象 firstweekday:一周的第一天,0周一(默认),6周日 calen = calendar.Calendar() calen_iter = calen.iterweekdays() # 迭代器,一周的星期数字 => 0 1 2 3 4 5 6 calen_iter = calen.itermonthdates( 2017, 5) # 迭代器, x年x月中所有天 => 2017-05-01 2017-05-02 017-05-03 ... calen_iter = calen.itermonthdays2( 2017, 5) # 迭代器, x年x月中所有(日,星期) => (1, 0) (2, 1) (3, 2) ... calen_iter = calen.itermonthdays(2017, 5) # 迭代器, x年x月中的所有天 => 1 2 3 ... calen_iter = calen.monthdatescalendar( 2017, 5) # 迭代器, x年x月中data(年,月,日)对象 => date(2017, 5, 1) date(2017, 5, 2) ... calen_iter = calen.monthdays2calendar( 2017, 5) # 迭代器, x年x月中(日,星期)的周列表 => [(1, 0), (2, 1) ...] [ ... ] ... calen_iter = calen.monthdayscalendar( 2017, 5) # 迭代器, x年x月中日的周列表 => [1,2,3 ...] [...] ... calen_lists = calen.yeardatescalendar(2017, width=3) # x年所有data(年,月,日)对象的月列表 calen_lists = calen.yeardays2calendar(2017, width=3) # x年所有(日,星期)的月列表 calen_lists = calen.yeardayscalendar(2017, width=3) # x年所有日的月列表 # === TextCalendar === # TextCalendar(firstweekday=0) // 纯文本的日历 calen_text = calendar.TextCalendar() calen_str = calen_text.formatmonth(2017, 5, w=0, l=0) # x年x月所有日 calen_text.prmonth(2017, 5, w=0, l=0) # (打印) x年x月所有日 calen_str = calen_text.formatyear(2017, w=2, l=1, c=6, m=3) # x年所有日 calen_text.pryear(2017, w=2, l=1, c=6, m=3) # (打印) x年所有日 # === HTMLCalendar === # HTMLCalendar(firstweekday=0) // HTML的日历 calen_html = calendar.HTMLCalendar() calen_str = calen_html.formatmonth(2017, 5, withyear=True) # x年x月的所有日 calen_str = calen_html.formatyear(2017, width=3) # x年所有日 calen_str = calen_html.formatyearpage(2017, width=3, css='calendar.css', encoding=None) # (完整编码) x年所有日 # === calendar 模块的函数 === calendar.setfirstweekday( calendar.SUNDAY ) # 设置每周开始的工作日(默认:0周一,6周日),如设置星期天为第一个工作日(calendar.SUNDAY) 参数:MONDAY / TUESDAY / WEDNESDAY / THURSDAY / FRIDAY / SATURDAY / SUNDAY num = calendar.firstweekday() # 返回每周的第一天的星期 boolean = calendar.isleap(2017) # x年是否为闰年 num = calendar.leapdays(2010, 2020) # x年到y年的闰年数 num = calendar.weekday(2017, 5, 6) # x年x月x日的星期几 strs = calendar.weekheader(1) # 星期E名, 1为名字长度 weekday, days = calendar.monthrange(2017, 5) # x年x月 (星期, 月天数) calen_lists = calendar.monthcalendar(2017, 5) # x年x月的月历 calen_lists = calendar.prmonth(2017, 5, w=0, l=0) # x年x月的日历 calen_strs = calendar.month(2017, 5, w=0, l=0) # 月历 calendar.prcal(2017, w=0, l=0, c=6, m=3) # (打印) 整年日历 calen_strs = calendar.calendar(2017, w=2, l=1, c=6, m=3) # 整年日历 time_s = calendar.timegm(time.gmtime(time.time())) # 时间元组 转为 时间戳 calen_iter = calendar.day_name # 迭代器, 星期E名称 calen_iter = calendar.day_abbr # 迭代器, 星期E缩写名称 calen_iter = calendar.month_name # 迭代器, 月E名称 calen_iter = calendar.month_abbr # 迭代器, 月E缩写名称
# Gestión y generación de calendarios print("Gestión y generación de calendarios") import calendar print() # Crearemos un calendario del año 2001 completo print("Calendario año 2001 completo") print() # Creación de la variable del año 2001 year2001 = 2001 # Uso de la función prcal que imprime el calendario de todo el año indicado print("- Forma 1:") calendar.prcal(year2001) print() print("- Forma 2:") # Uso de la función prcal que imprime el calendario de todo el año indicado, pero lo mostraremos en forma diferente a la anterior # w=0, l=0, c=6, m=3; respectivamente, indican: el ancho entre dos columnas, linea en blanco entre dos filas, espacio entre dos meses y número de meses por fila. Esta es la forma que sal por defecto al usar prcal # En este caso, cambiaremos las dimensiones anteriores por: w=2, l=1, c=10, m=6 calendar.prcal(year2001, w=1, l=2, c=10, m=3) print() # Ahora imprimiremos solamente un mes de este mismo año usando prmonth. En el argumento de esta función, se de primero el año y de segundo, el mes que se quiere mostrar print("- Marzo del año 2001") print() calendar.prmonth(year2001, 3) print()
__author__ = 'jszheng' from calendar import prcal #year = int(input("Type the year number:")) prcal(2015) ''' test class attribute''' class rect: """this is a test""" l = 8 @classmethod def display(cls): print(cls.l) @staticmethod def disp_msg(): print("Length is 50") print(rect.__name__) print(rect.__bases__) print(rect.__dict__) print(rect.__doc__) print(rect.__module__) i1 = rect() i1.display() rect.disp_msg() i1.disp_msg() class rect:
# 制作中文日历35-makecalendar.py import calendar print(calendar.month(2021, 3)) print(calendar.calendar(2021)) calendar.isleap(2021) calendar.monthcalendar(2021, 3) calendar.prcal(2020, w=0, l=0, c=6, m=3) def pri_calen(k, ws, day): if day > 10: print(f"{int(3+k*7)*ws}{day}", end="") else: if day == 10: print(f"{int(4+k*7)*ws}{day}", end="") else: print(f"{int(3+k*8)*ws}{day}", end="") year = eval(input("请输入需要制作日历的年份,输入后请回车year=")) print("{:>29}".format("2021年日历")) for i in range(1, 13): mlist = calendar.monthcalendar(year, i) print("") print("{:>27d}".format(i), "月") print("") print("星期日 星期一 星期二 星期三 星期四 星期五 星期六 ") ww = len(mlist) for w in range(ww): k = 0 for d in range(7):
def main(): from calendar import prcal year = int(input('Type in the year number: ')) prcal(year)
import time t1 = time.localtime(time.time()) print(t1) import time t1 = time.asctime(time.localtime()) print(t1) import calendar c1 = calendar.month(2020, 9) print(c1) import calendar c1 = calendar.prcal(2020) print(calendar.isleap(2020))
def main(): import calendar # This line is a command to import a module year = int(input('Type in the year number: ')) # in this case Calendar calendar.prcal(year) # this prints the calendar for the year
if __name__ == "__main__": import calendar year = int(input("Masukkan Tahun: ")) calendar.prcal(year)
import calendar print(calendar.month) print(calendar.prcal(2021))
#Programming 101 #week14 #demo 6 import calendar print(calendar.calendar(2019)) #印出2019年的日曆 print(calendar.month(2019, 6)) #印出2019年6月的日曆 calendar.prcal(2019) #印出2019年的日曆,效果等於print搭配calendar() calendar.prmonth(2019, 6) #印出2019年6月的日曆,效果等於print搭配month() print(calendar.isleap(2019)) #2019是否為閏年 print(calendar.leapdays(2000, 2019)) #2000~2019年之間有幾個閏年 #calendar.month_name裡面有12個月份的英文名稱,但需要透過索引值1~12去個別取出 print(calendar.month_name) for i in range(1, 13): #印出1月到12月的英文名稱 print(calendar.month_name[i])
print(d.__str__()) print(d.ctime()) time.sleep(2) # sleeps for 2 seconds print(time.strftime("%b", time.localtime())) print(time.strptime("31 Dec 1995", "%d %b %Y")) print(calendar.month(2018, 1)) print(calendar.month(2017, 12, 3, 2)) print(calendar.calendar(2018)) print(calendar.monthcalendar(2017, 12)) print(calendar.monthrange(2017, 12)) # (4,31) 4 is friday 31 days current month print(calendar.prcal(2020)) # print calender for 2020 print(calendar.prmonth(2020, 4)) # for month print(calendar.weekday(2020, 4, 5)) print(calendar.timegm(time.localtime())) os.system("cls") print("----- calendar -----") print(calendar.Calendar(firstweekday=0)) c = calendar.Calendar(firstweekday=1) for i in c.iterweekdays(): print(i) c = calendar.Calendar(firstweekday=0) for i in c.itermonthdates(2019, 12):
from datetime import * import calendar print "Calendario!" anno = input("Anno: ") print datetime.today() calendar.prcal(anno) calendar.prmonth(anno,1)
import time import datetime import calendar print ("Example Input year : 2020") x = input("Input year: ") print("\nexecuting the code....") time.sleep(2) print("On....going....") time.sleep(2) print("Finished!") print(datetime.datetime.now()) calendar.prcal (int(x))
''' prcal(year) 打印给定年份的日历, 如 下例 所示. ''' import calendar calendar.prcal(2017) ''' 注意这里的日历是按照欧洲习惯打印的, 也就是说星期一是一个星期的第一天, 其他情况需要请参考模块中的几个类. (和咱们一样, 不用管了) 该模块中的其他类或函数可以帮助你输出自己需要的格式. '''
#sleep1.py import time for i in range(10): print(i) time.sleep(1) 위 예는 1초 간격으로 0부터 9까지의 숫자를 출력한다. 위 예에서 볼 수 있듯이 time.sleep 함수의 인수는 실수 형태를 쓸 수 있다. 즉, 1이면 1초, 0.5면 0.5초가 되는 것이다. calendar calendar는 파이썬에서 달력을 볼 수 있게 해주는 모듈이다. calendar.calendar(연도)로 사용하면 그 해의 전체 달력을 볼 수 있다. 결과값은 달력이 너무길어 생략하겠다. >>> import calendar >>> print(calendar.calendar(2015)) calendar.prcal(연도)를 사용해도 위와 똑같은 결과값을 얻을 수 있다. >>> calendar.prcal(2015) 다음의 예는 2015년 12월의 달력만 보여 준다. >>> calendar.prmonth(2015, 12) December 2015 Mo Tu We Th Fr Sa Su 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 calendar.weekday calendar 모듈의 또 다른 유용한 함수를 보자. weekday(연도, 월, 일) 함수는 그 날짜에 해당하는 요일 정보를 리턴한다. 월요일은 0, 화요일은 1, 수요일은 2, 목요일은 3, 금요일은 4, 토요일은 5, 일요일은 6이라는 값을 리턴한다.