Learn Python From 'Head First Python' [3] : Exception

1.the using of exception

2.file opration

import os
>>> try:
    data = open(‘sketch.txt‘)
    for each in data:
        try:
            (role,message) = each.split(‘:‘)
            print(role + ‘ says: ‘ + message, end=‘‘)
        except ValueError:
            pass
    data.close()
except IOError:
    print(‘file is missing‘)

you can get the sketch.txt from the python offical webstatie

Learn Python From 'Head First Python' [3] : Exception

时间: 2024-10-13 14:06:34

Learn Python From 'Head First Python' [3] : Exception的相关文章

Learn Python From 'Head First Python' [3](2) : Pickle

1.the use of 'with open... as ...' 2.the use of pickle(dump and load) for Step1: the 'with open ... as...' is the short format of 'try...except...finally' for Step2: you can store a list with pickle.dump() and get the content again with pickle.load()

Learn Python From 'Head First Python' [2] : Sharing

1.publish 2.update print_lol PS: for Step 1. write the code in to a py file. put the py file into a folder named nester. new a py file named 'setup' and the content as below: setup( name = 'nester', version = '1.0.0', py_modules = ['nester'], author

Learn Python From 'Head First Python' [1] : The List

1.the concept of List 2. how to define a method of myself 3.how to iterator a list PS: for Step 2,3. it is related with a key word: 'def'. we define a function like below. def function name: XXXXX e.g. list iterator : 1 def print_lol(the_list): 2 for

Learn Python From 'Head First Python' [0] : Install

1. download software form the python‘s webset 2. install the python and set the class path 3. verify if the install is correct PS: for Step 2. if you use the default install. then undre the disk C:, there will be a dir like Python34. go to the env se

Python之路,Day1 - Python基础1

本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语句 表达式for 循环 break and continue 表达式while 循环 作业需求 一. Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语

Python之路,Day1 - Python基础1---转自金角大王

本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语句 表达式for 循环 break and continue 表达式while 循环 作业需求 一. Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语

Supporting Python 3(支持Python 3)——目录

Supporting Python 3(支持Python 3) 关于本书 关于术语 序 欢迎来到Python 3 是时候了吗? 如果我现在不能切换会怎么样? Python 和它的版本 更多资源 迁移策略 仅支持Python 3 Python 2和Python 3的单独分支 使用2to3转换到Python 3 使用Distribute来支持2to3转换 无需转换支持Python 2 和 Python 3 使用3to2 哪种策略适合你? 应用 Python模块和包 框架 结论 Preparing f

How to install Python 2.7 and Python 3.3 on CentOS

In this guide I will show you how to install Python 2.7 and 3.3 on CentOS 6. The examples below are for Python 2.7.6 and Python 3.3.5, but the procedure is the same for any modern version of Python including the upcoming Python 3.4.0. I make regular

install Python 2.7 and Python 3.3 on CentOS 6

来自:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/ In this guide I will show you how to install Python 2.7 and 3.3 on CentOS 6. The examples below are for Python 2.7.6 and Python 3.3.5, but the procedure is the same for any modern