python等笔记
来源:互联网 发布:没有网络怎么重装系统 编辑:程序博客网 时间:2024/06/05 20:07
所用python版本3.3
代码:
poem = '''/
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
'''
f = file('poem.txt', 'w') # open for 'w'riting
f.write(poem) # write text to file
f.close() # close the file
f = file('poem.txt')
# if no mode is specified, 'r'ead mode is assumed by default
while True:
line = f.readline()
if len(line) == 0: # Zero length indicates EOF
break
print (line,)
# Notice comma to avoid automatic newline added by Python
f.close() # close the file
错误提示:
Traceback (most recent call last):
File "D:/Software/Python/006", line 8, in <module>
f = file('poem.txt', 'w') # open for 'w'riting
NameError: name 'file' is not defined
问题分析: 在Python3中,file()被废弃,不过可以用open() 代替,即f = file('poem.txt', 'w')替换为f = open('poem.txt', 'w'), 再f = file('poem.txt')替换为f = open('poem.txt'),更改后运行正常。
注:此文章为蔚蓝光辉博客原创,本人个人网站:www.11eyes.com 转载请注明出处。
================================
>>>def powersum(power, *args):
... '''Return the sum of each argument raised to specified power.'''
... total = 0
... for i in args:
... total += pow(i, power)
... return total
...
>>> powersum(2, 3, 4)
25
请问其中25这个数字怎么得来的我初学,讲解的详细点。
你有 help(pow) 命令可以看到POW是用来做幂运算的,你的POWERSUM(2,3,4)实现的就是:3的平方加上4的平方。
查看进程状态
Linux: top
Solaris: prstat
在Solaris下可以通过pkg-get -i top来下载安装top软件,prstat -L可以进一步显示每个线程的状态
- python等笔记
- python等笔记
- Python学习笔记,数据类型,编码等
- Python学习笔记-3(线程、进程、同步等)
- python计算CRC16等
- #随机#:python、redis等
- python tutorial 学习笔记(四) Input and Output, 字符串的转换等
- 《python简明教程》学习笔记(2)-dict,set,入参等
- Python笔记(6)----列表、元组、字符串、字典等的相关用法
- python学习笔记 --- python中使用哈希方法处理字符与数字,ord()等函数详解
- 正则表达式笔记等
- dll错误等笔记
- top等命令笔记
- HDR等笔记
- matalb等笔记
- Python笔记
- python笔记
- python笔记
- 常用指令
- [Android开发常见问题-2] eclipse安装/卸载svn插件
- 使用gSoap开发Web Service C/C++客户端
- 二分查找——UVa 10706 - Number Sequence
- AIX上提供了XLC编译器也提供了CC编译器,这两个编译器有什么差别呢?
- python等笔记
- 算法导论-第14章
- Java集合总结
- The VC programming specifications - programmers should write code like this
- 添加或删除项并动态记录项的值
- 【鸡肋实验】数据线性相关性对机器学习的影响(一)
- android 框架试用--spring for android
- 《c陷阱与缺陷》笔记--extern
- 事务隔离级别