杂记

·windows 下设置环境变量

<code>path=%path%;C:\Python #后面是python的安装目录,自行更改</code>

· 编程的方法

The details look different in different languages, but a few basic instructions appear in just about every language:

input:
Get data from the keyboard, a file, the network, or someother device.
output:
Display data on the screen, save it in a file, send it over the network, etc.
math:
Perform basic mathematical operations like addition and multiplication.
conditional execution:
Check for certain conditions and run the appropriate code.
repetition:
Perform some action repeatedly, usually withsome variation.

· 原始字符串操作符(r / R)

-用于一些不希望转义字符起作用的场合
例如:
<code>file = open(r"c:\python\test.py","w")</code>
<code>file = open("c:\\python\\test.py","w")</code>

· python中可以迭代的对象

  • 字符串
  • 列表
  • 元组
  • 字典
  • 文件

· 列表解析

<code>[i + 1 for i in range(10) if i % 2 == 0] #生成一个列表</code>

· 生成器表达式

<code>(i + 1 for i in range(10) if i % 2 == 0) #生成一个生成器</code>

· 循环中的else语句

-如果循环代码从break处终止,跳出循环
-正常循环结束则执行else中的代码

·运行两种版本python 的方法

#! C:\python27\python2.exe
#! C:\python34\python3.exe

上面这个没什么卵用。。。

·python中函数的参数形式

  • 位置或关键字参数
  • 仅位置参数
  • 可变长位置参数: *argst
  • 可变长关键字参数:**argst

·python实现win os自动拨号上网

用到os库里的system方法以及win os下rasdial命令
具体语法如下:

rasdial 连接名称(如宽带连接) username password -->连接
rasdial 连接名称 /disconnect -->断开连接

主要代码如下:

import os

os.system('rasdial networking username password') #get connect
os.system('rasdial networking /disconnect') #disconnect

linux下将python程序改成一个可执行脚本

#!/usr/bin/env python

# your code here

然后进入命令行界面,将程序权限修改为已执行,命令如下:

chmod 755 hello.py

最后输入 ./文件名.py 即可自动运行。

Git 提交所有文件

git add -A && git commit
or
git commit -am "<commit message>"

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容