我正试图绕过日期时间模块.我知道现在的时间作为一个时代和事件最后发生的时间(作为一个纪元时间).我需要做的是弄清楚该事件是否发生在昨天的午夜和午夜之间.
t = time.time() # is now
t2 = 1234567890 # some arbitrary time from my log
Run Code Online (Sandbox Code Playgroud)
24小时前是t - 86400,但我怎样才能将它上下调整到午夜.我很难找到一种方法来获取时间戳进出日期时间,或者操纵日期时间来设置时间.
我需要在 RPM 的 %post 部分以不同的用户身份运行命令。
目前我正在通过 python 使用一些 hack 但它不是最好的方法(它确实感觉有点脏)......
%post -p /usr/bin/python
import os, pwd, subprocess
os.setuid(pwd.getpwnam('apache')[2])
subprocess.call(['/usr/bin/something', 'an arg'])
Run Code Online (Sandbox Code Playgroud)
有没有合适的方法来做到这一点?
你会如何在bash中实现这一目标.这是我在面试中被问到的一个问题,我可以用高级语言来思考答案,但不能用shell来思考答案.
据我了解,tail的真正实现寻求到文件的末尾,然后向后读.
我正在尝试使用格式化的字符串向sys.stderr打印消息,但最后我得到了一个神秘的%.
如果我写:
sys.stderr.write("One argument (file name) expected, got %d" % (len(sys.argv) -1))
Run Code Online (Sandbox Code Playgroud)
我得到一个输出:
One argument (file name) expected, got 0%
如果我用打印功能替换它,它的行为符合预期.此外,%有一个白色背景,所以它可能是我的shell无法识别的字符.