Python日常学习杂记

  • python -c 的作用

在命令行里执行python时,如果加上 -c,即

python -c xxx

那么,xxx就被当做一条指令(command)来执行,否则,就当做脚本路径,去找script,然后执行里面的内容。比如:

$ python 'import this'
/root/anaconda3/bin/python3.7: can't open file 'import this': [Errno 2] No such file or directory

这里就把这个string作为路径去找了,没有找到文件。如果加上-c的话,就当做一条python命令执行了。

$ python -c 'import this'
The Zen of Python, by Tim PetersBeautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

2019-08-14 16:20:00

  • autopep8自动代码格式修改工具

链接:https://pypi.org/project/autopep8/

PEP8是Python的编码规范。https://www.python.org/dev/peps/pep-0008/

利用autopep8,可以自动将Python脚本整理成符合PEP8规范。

用法

autopep8 --in-place -r  --aggressive 文件夹名

options列表如下:

usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename][--ignore-local-config] [-r] [-j n] [-p n] [-a][--experimental] [--exclude globs] [--list-fixes][--ignore errors] [--select errors] [--max-line-length n][--line-range line line] [--hang-closing] [--exit-code][files [files ...]]Automatically formats Python code to conform to the PEP 8 style guide.positional arguments:files                 files to format or '-' for standard inoptional arguments:-h, --help            show this help message and exit--version             show program's version number and exit-v, --verbose         print verbose messages; multiple -v result in moreverbose messages-d, --diff            print the diff for the fixed source-i, --in-place        make changes to files in place--global-config filenamepath to a global pep8 config file; if this file doesnot exist then this is ignored (default:~/.config/pep8)--ignore-local-configdon't look for and apply local config files; if notpassed, defaults are updated with any config files inthe project's root directory-r, --recursive       run recursively over directories; must be used with--in-place or --diff-j n, --jobs n        number of parallel jobs; match CPU count if value isless than 1-p n, --pep8-passes nmaximum number of additional pep8 passes (default:infinite)-a, --aggressive      enable non-whitespace changes; multiple -a result inmore aggressive changes--experimental        enable experimental fixes--exclude globs       exclude file/directory names that match these comma-separated globs--list-fixes          list codes for fixes; used by --ignore and --select--ignore errors       do not fix these errors/warnings (default:E226,E24,W50,W690)--select errors       fix only these errors/warnings (e.g. E4,W)--max-line-length n   set maximum allowed line length (default: 79)--line-range line line, --range line lineonly fix errors found within this inclusive range ofline numbers (e.g. 1 99); line numbers are indexed at1--hang-closing        hang-closing option passed to pycodestyle--exit-code           change to behavior of exit code. default behavior ofreturn value, 0 is no differences, 1 is error exit.return 2 when add this option. 2 is existsdifferences.

2019-08-26 10:45:14

  • 为文件名添加时间
import datetime
jetzt = str(datetime.date.today())
print(jetzt)>>> 2019-08-28

可以将日期附到文件名中,便于日后根据时间查找。

2019-08-28 11:24:06

Python日常学习杂记相关推荐

  1. 【python日常学习】爬取4K桌面壁纸

    [python日常学习]爬取4K桌面壁纸 这个网站都是4K的桌面壁纸. 不多说,直接上代码 import re import requests import osdef get_page():page ...

  2. python壁纸4k_【python日常学习】爬取4K桌面壁纸

    [Python] 纯文本查看 复制代码import re import requests import os from time import sleep def get_page(): page = ...

  3. Python日常+笔面试

    Python日常学习 三维转二维: 例:X(200,200,106)->newX(40000,106) newX = np.reshape(X, (-1, X.shape[2])) 二维变三维: ...

  4. Python数据结构学习笔记——队列和双端队列

    目录 一.队列的定义 二.队列 实现步骤分析 三.队列的Python实现代码 四.队列的应用 六人传土豆游戏 五.双端队列的定义 六.双端队列 实现步骤分析 七.双端队列的Python实现代码 八.双 ...

  5. python语言学习零基础教学视频_Python告白小白视频教程(零基础入门)

    1 Python编程基础入门篇通过本次课程的学习,我们每个人都可以进入python世界里,从简单到高级,让人人都能学会python,我们在学习的时候,python让我们的运维变得更有乐趣,让我们的运维 ...

  6. python怎么学习一门语言_如何学习Python这一门语言

    Python现在非常火,语法简单而且功能强大,很多同学都想学Python! 如果你选择了自学,我想给你提几点建议: 找浅显易懂,例程比较好的教程,从头到尾看下去.不要看很多本,专注于一本.把里面的例程 ...

  7. Python爬虫学习框架介绍

    对于初学者来说,摸索清楚一个领域的知识体系往往比单纯学习某个技术要重要得多,因为技术总会跟随时代发生快速变化,而知识体系往往变化较小,今天我们以自学的角度来了解一下Python爬虫的知识体系吧. 一. ...

  8. Python总结-学习方向和方法

    目录 前言... 2 (一)如何学习Python. 2 (二)一些Python免费课程推荐... 3 (三)Python爬虫需要哪些知识?... 4 (四)Python爬虫进阶... 6 (五)Pyt ...

  9. 日常学习记录——pycharm+tensorflow简单图像识别

    日常学习记录--pycharm+tensorflow简单图像识别 写在前面 1 实验代码 2 实验结果 2.1 测试集的正确率 2.2 单个预测结果 2.3 集体预测结果 总结与标记 写在前面 使用p ...

最新文章

  1. 如何让hybris启动加快
  2. [云炬商业计划书阅读分享]无水洗车市场推广策划书
  3. 《转》cout和printf的混用而产生的顺序问题
  4. ReSharper 配置及用法(ZHUANG)
  5. 循序渐进PYTHON3(十三) --8-- DJANGO之ADMIN
  6. DJANGO,获取当前用户名,用户组名,用户组权限
  7. Hibernate 语句总结
  8. Word2013中制作按钮控件
  9. C语言的inline
  10. Python3小程序:把连续的16进制UTF8编码转换为字符串
  11. 重磅炸弹!马云正式宣布:1天1个亿,全世界沸腾了!
  12. 如何在树莓派上进行python编程_树莓派Python编程指南
  13. Java实习面试一般问什么?选大公司还是小公司?
  14. 计算机主机的储存,电脑截屏保存在哪里 电脑截屏保存位置【图文】
  15. zzulioj1116: 删除元素
  16. 端游开发用什么技术可以让用户更短时间内体验游戏?端游分发
  17. JavaEE初阶---网络原理初识+网络编程套接字+网络原理之TCP_IP
  18. 编写程序描述影视歌三栖艺人。需求说明:请使用面向对象的思想,设计自定义类,描述影视歌三梄艺人。...
  19. Linux命令 --- cp与scp
  20. P2P 之 UDP穿透NAT的原理与实现(附源代码)

热门文章

  1. 亲爱的用户,您使用了广告屏蔽软件,广告是CSDN向您免费提供服务与产品的重要支持...
  2. python淘宝_Python模拟登录淘宝
  3. 大数据显示“男人不如狗” 我和几个男同事聊了聊
  4. 精密空调监控:不会这个技巧,千万不要尝试
  5. mfc 计算dgi+ 字符宽度_Python综合应用:教你用字符打印一张怀旧风格的照片
  6. 02_第一个 Python 程序及常见错误合集
  7. vue学习笔记--webpack的使用
  8. 燕尾槽刀具如何加工设置
  9. nise_bosh 在openstack集群上搭建CloudFoundry
  10. 使用Palm®(奔迈)Mojo 框架开发JavaScript程序 #1