mymod.py

来自「python c扩展编写例子」· Python 代码 · 共 40 行

PY
40
字号
#########################################################
# C runs Python code in this module in embedded mode.
# Such a file can be changed without changing the C layer.
# There is just standard Python code (C does conversions).
# You can also run code in standard modules like string.
#########################################################

import string

message = 'original string'
message =message+message

msg_error=""

try:
	text_file = open("text.txt", "r")
	whole_thing = text_file.read()
	text_file.close()
except IOError, (errno, strerror):
	print "I/O error(%s): %s" % (errno, strerror)


def transform(input):
    #input = string.replace(input, 'life', 'Python')
    return string.upper(input)
    
def change_msg(nul):   
    global message #如果没有此行,message是函数里头的局部变量
    message='string changed'
    return message

def r_file(nul):
    return whole_thing

def get_msg(nul):
    return message



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?