非常简单的Python时间判断与赋值

判断当前时间为上午还是下午

1
2
3
4
5
6
7
8
9
10
11
12
13
import time

mytime = time.localtime()

if mytime.tm_hour < 12:
payload = 'AM'

print (payload)

else:
payload = 'PM'

print (payload)

内容编码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import time
import sys
import codecs

sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())

mytime = time.localtime()

if mytime.tm_hour < 12:
payload = 'AM'

print (payload)

else:
payload = 'PM'

print (payload)

调用(实现根据时间来输出不同内容)

取值payload

A.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import time
import sys
import codecs

sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())

mytime = time.localtime()

if mytime.tm_hour < 12:
payload = '1'

print (payload)

else:
payload = '2'

print (payload)

B.py

1
2
3
from A import payload
br = payload
print(br)