Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754276
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: Python/Ruby

2011-06-15 14:59:08

3.8. Summary

小结

The odbchelper.py program and its output should now make perfect sense.

程序odbchelper以及它的输出你应该都明白了

 

  1. def buildConnectionString(params):
  2.     """Build a connection string from a dictionary of parameters.
  3.  
  4.     Returns string."""
  5.     return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
  6.  
  7. if __name__ == "__main__":
  8.     myParams = {"server":"mpilgrim", \
  9.                 "database":"master", \
  10.                 "uid":"sa", \
  11.                 "pwd":"secret" \
  12.                 }
  13.   print buildConnectionString(myParams)

 

Here is the output of odbchelper.py:

这是程序的输出:

  1. server=mpilgrim;uid=sa;database=master;pwd=secret

Before diving into the next chapter, make sure you're comfortable doing all of these things:

再继续深入下一章之前,首先确定你自己可以轻松的完成下面的事情:

  • Using the Python IDE to test expressions interactively
  • 可以交互的在Python IDE中测试表达式
  • Writing Python programs and running them from within your IDE, or from the command line
  • 写一个Python程序,要么在你的IDE运行,要么在命令行运行
  • Importing modules and calling their functions
  • 能导入模块并可以调用函数
  • Declaring functions and using doc stringslocal variables, and proper indentation
  • 声明函数,并使用文档化字符串(函数注释),局部变量以及适当的缩进。
  • Defining dictionariestuples, and lists
  • 定义字典,tuple以及列表
  • Accessing attributes and methods of any object, including strings, lists, dictionaries, functions, and modules
  • 能够访问任意对象的属性和方法,如字符处啊,列表,字典,函数,模块
  • Concatenating values through string formatting
  • 通过格式化字符串来连接字符串
  • Mapping lists into other lists using list comprehensions
  • 通过列表复合操作能将一个列表映射成其它列表
  • Splitting strings into lists and joining lists into strings
  • 字符串可以分割成列表,同时join将列表连接成字符串

 

阅读(818) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~