专栏名称: 编程派
Python程序员都在看的公众号,跟着编程派一起学习Python,看最新国外教程和资源!
目录
相关文章推荐
Python开发者  ·  外网热议:为什么 DeepSeek ... ·  10 小时前  
51好读  ›  专栏  ›  编程派

“抄”代码,再也不用上谷歌复制粘贴了!

编程派  · 公众号  · Python  · 2020-10-29 11:40

正文

请到「今天看啥」查看全文


'*/*' , 'Accept-Encoding' : 'gzip, deflate' , 'Connection' : 'close' , 'Content-Length' : '16' , 'Content-Type' : 'application/json' , 'Host' : 'httpbin.org' , 'User-Agent' : 'python-requests/2.4.3 CPython/3.4.0' , 'X-Request-Id' : 'xx-xx-xx' }, 'json' : { 'key' : 'value' }, 'origin' : 'x.x.x.x' , 'url' : 'http://httpbin.org/post' }

看起来还不错对不对。

比如我想搜 Python 里面怎么把 timestamp 转 datetime,输入这样的命令:

howdoi python timestamp to datetime

返回结果就是这样:

from datetime import datetimets = int("1284101485")
# if you encounter a "year is out of range" error the timestamp# may be in milliseconds, try `ts /= 1000` in that caseprint(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))

那 Java 它会吗?试试看:

howdoi java timestamp to datetime

返回结果就是这样:

Timestamp stamp = new Timestamp(System.currentTimeMillis());Date date = new Date(stamp.getTime());System.out.println(date);

有点牛逼啊,搜啥答案都有,准确率还蛮高。

以上是怎么实现的?没错,就是借助于 howdoi 这个项目。

howdoi

那么这个 howdoi 究竟是个什么?我们 GitHub 上就能找到,链接地址为:https://github.com/gleitz/howdoi。

看下简介:

Are you a hack programmer? Do you find yourself constantly Googling for how to do basic programming tasks?

Suppose you want to know how to format a date in bash. Why open your browser and read through blogs (risking major distraction) when you can simply stay in the console and ask howdoi.

意思就是说,如果你想搜一些编程相关的解决方案,我们可以不用再去开浏览器,然后再去读文档或者博客,你可以通过 howdoi 就能直接得到答案。

操作就是上面我们讲的。

howdoi 是一个 Python 项目,我们可以 pip 命令安装:

pip3 install howdoi

如果是 Mac 的话,推荐使用 brew 来安装:

brew install howdoi

安装完了就能使用 howdoi 命令了。

完整用法如下:







请到「今天看啥」查看全文