Python API及相关问题

  1. ## jupyter
  2. jupyter nbconvert --to python my_file.ipynb
  3. ## 取整
  4. # 向下取整
  5. >>> a = 14.38
  6. >>> int(a)
  7. 14
  8. # 向上取整
  9. >>> import math
  10. >>> math.ceil(3.33)
  11. 4
  12. >>> math.ceil(3.88)
  13. 4
  14. # 四舍五入
  15. >>> round(4.4)
  16. 4
  17. >>> round(4.6)
  18. 5
  19. ## python3调用c函数接口的错误
  20. # python2的源码直接在python3.7运行(出错):
  21. net = dn.load_net("cfg/yolov3.cfg", "weights/yolov3.weights", 0)
  22. ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
  23. ## python3默认编码与python不一样, utf8转换:
  24. net = dn.load_net("cfg/yolov3.cfg".encode("utf-8"), "weights/yolov3.weights".encode("utf-8"), 0)
  25. import os.path as ops
  26. os.path.abspath(path) # 返回绝对路径
  27. os.path.expanduser(path) # 把path中包含的"~"和"~user"转换成用户目录
  28. os.path.basename(path) # 返回文件名