class Game_object:

    def __init__(self,name):

        self.name=name


    def pickUp(self):

       pass       ##这里原本不允许函数为空,所以可以使用pass 先略过。

        #put code here

        #to the player's collectiong


class Coin (Game_object):

    def __init__(self,value):

        Game_object.__init__(self)

        self.value =value

    def spend(self,buyer,seller):

        pass

        #put code here



创建个模板

 

#this is a module.files

def c_to_f(celsius):

    fahrenheit = celsius * 9.0 / 5 + 32

    return (fahrenheit) #注意一定加括号,否则在python 3.0以后版本会报错 

'return' outside function


保存为my_module.py 



import my_module   #调用这个模块 (这里my_module 就是个命名空间)

celsius =float(input("Enter a temperature in Celesius:"))

fahrenheit =my_module.c_to_f(celsius) 注意调用模块的函数一定要模块和函数都要写上。

print ("Thant's",fahrenheit,"degrees Fahrenheit")

以上的也可以用

from my_module import c_to_f

celsius =float(input("Enter a temperature in Celesius:"))

fahrenheit =c_to_f(celsius) #这里就不用指明哪个模块的哪个函数。直接使用函数就行

print ("Thant's",fahrenheit,"degrees Fahrenheit")