注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

gmd20的个人空间

// 编程和生活

 
 
 

日志

 
 

Python语言入门  

2008-07-15 17:04:32|  分类: 程序设计 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

学习参考文档:
Python v3.0b1 documentation   http://www.python.org/doc/

Python Tutorial http://docs.python.org/tut/tut.html

深入 Python :Dive Into Python 中文版 http://www.woodpecker.org.cn/diveintopython/toc/index.html

[root@widebright /]# which python
/usr/bin/python
[root@widebright /]# python
Python 2.3.4 (#1, Sep 26 2006, 17:23:01)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "I am widebright^_^"
I am widebright^_^
>>>

[root@widebright /]# cat widebright.py
#! /usr/bin/env python

import os
import time

print "I am widebright"
print "Now time is " + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())

print "The os type is " + os.name
print "login user is " + os.getlogin()

ls = os.popen('ls -l ;uname -a')
output= ls.readlines();
ls.close()
print "The output text of \"ls -l ;uname -a\" is "
for x in output:
        print x

print "--------------------------------------"


class widebright:
        name = "widebright"
        age = 0

        def introduce (self):
                print "I am " + self.name +", age " , self.age

        def __init__(self, name,age):
                self.name = name
                self.age = age

widebright1 = widebright("haha",40)
widebright1.introduce()

widebright2 = widebright("widebright",20)
widebright2.introduce()


运行脚本后后得到

[root@widebright /]# ./widebright.py
I am widebright
Now time is Tue, 15 Jul 2008 08:56:20 +0000
The os type is posix
login user is root
The output text of "ls -l ;uname -a" is
total 282

drwxr-xr-x    2 root root 4096 Apr 10 2007 bin

drwxr-xr-x    4 root root 1024 Apr 9 2007 boot

drwxr-xr-x    9 root root 4680 Jul 9 23:28 dev

-rw-r--r--    1 root root    91 Oct 24 2007 dull

drwxr-xr-x   84 root root 12288 Jul 13 04:02 etc

drwxr-xr-x    4 root root 4096 Jul 31 2007 home

drwxr-xr-x    2 root root 4096 Aug 12 2004 initrd

drwxr-xr-x   11 root root 4096 Apr 10 2007 lib

drwxr-xr-x    3 root root 4096 Jul 9 23:28 media

drwxr-xr-x    2 root root 4096 Jul 11 2006 misc

drwxr-xr-x    4 root root 4096 May 7 02:53 mnt

drwxr-xr-x    2 root root 4096 Aug 12 2004 opt

dr-xr-xr-x 180 root root     0 Jul 9 19:27 proc

drwxr-xr-x    4 root root 4096 Mar 9 23:31 qa

drwxr-x---   26 root root 4096 Jul 15 04:55 root

drwxr-xr-x    2 root root 12288 Apr 10 2007 sbin

drwxr-xr-x    2 root root 4096 Aug 12 2004 srv

drwxr-xr-x    9 root root     0 Jul 9 19:27 sys

drwxrwxrwt   10 root root 4096 Jul 15 04:02 tmp

drwxr-xr-x   16 root root 4096 Oct 24 2007 usr

drwxr-xr-x   22 root root 4096 Apr 9 2007 var

-rwxr-xr-x    1 root root   749 Jul 15 04:53 widebright.py

Linux widebrihgt 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux

--------------------------------------
I am haha, age 40
I am widebright, age 20


至此,排名前十位的语言我都用过啦,哈哈

Python语言入门 - widebright - widebright的个人空间

  评论这张
 
阅读(381)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017