python等笔记

 

所用python版本3.11

 

代码:

 

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的平方。

 

http://wenwen.soso.com/z/q189009642.htm

 

===================================

 

Linux命令与Solaris命令的比较 http://blog.chinaunix.net/u1/46451/showart_364538.html

 

查看进程状态
Linux:   top
Solaris: prstat
在Solaris下可以通过pkg-get -i top来下载安装top软件,prstat -L可以进一步显示每个线程的状态

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值