Monday 12 October 2020

shims/python: line 21: /usr/local/Cellar/pyenv/1.2.19/libexec/pyenv: No such file or directory

This seems to be a pyenv usage question and I'm not sure if any of us use it. If pyenv works like rbenv then pyenv rehash may fix this.


from : https://github.com/Homebrew/brew/issues/1457

Enable Pytest for your project

  1. Open the Settings/Preferences | Tools | Python Integrated Tools settings dialog as described in Choosing Your Testing Framework.

  2. In the Default test runner field select pytest.

  3. Click OK to save the settings.


from :  https://www.jetbrains.com/help/pycharm/pytest.html#enable-pytest

Wednesday 7 October 2020

timestamp2datetime and datetime2timestamp

def timestamp2Datetime(timeStamp :int) :
    '''
    时间戳转日期时间
    例如 1557502800转换成 2019-05-10 23:40:00
    '''
    timeArray = time.localtime(timeStamp)
    otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    return otherStyleTime

def timestamp2Date(timeStamp :int) :
    '''
    时间戳转日期
    例如 1557502800转换成 2019-05-10
    '''
    timeArray = time.localtime(timeStamp)
    otherStyleTime = time.strftime("%Y-%m-%d", timeArray)
    return otherStyleTime

print(timestamp2Datetime(1557502800)) 

print(timestamp2Date(1557502800)) 


def _datetime2timestamp(self, datetime_str='2020-01-31 00:00:00', convert_to_utc=True):
dt = datetime.datetime.strptime(datetime_str,'%Y-%m-%d %H:%M:%S')
if convert_to_utc:
dt = dt + datetime.timedelta(hours=8)
return int(datetime.datetime.timestamp(dt))

from: https://zhuanlan.zhihu.com/p/101978992