python中的函数存入list中的实例
最近由于接触了python这个强大的东西,在写代码时考虑到代码的扩展性,就想到了将python的函数名存入list中。有点像习惯的c/c++中的函数指针的意思。
下面上代码:
# coding=utf-8
#!/usr/bin/python
#脚本的用法 python nn_daemon.py
import json, urllib, urllib2, subprocess, sys, os, logging, time, socket, time, calendar, datetime, ConfigParser, socket, fcntl, struct
from xml.etree import ElementTree
from time import strftime def func_1(i):
print "i is %d"%i def func_2(i):
print "i is %d"%i if __name__ == '__main__':
tmp_list = []
tmp_list.append(func_1)
tmp_list.append(func_2) for i in range(len(tmp_list)):
tmp_list[i](i)
结果:
i is 0
i is 1
本菜鸟是python新手,望各种喷。后面会陆续把最近碰到的python问题分享出来。
python中的函数存入list中的实例的更多相关文章
- python之BIF函数在列表中的应用
1 Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AMD64)] on win32 2 T ...
- shell中的函数、shell中的数组、告警系统需求分析
7月16日任务 20.16/20.17 shell中的函数20.18 shell中的数组20.19 告警系统需求分析 20.16/20.17 shell中的函数 函数就是一个子shell就是一个代码段 ...
- Linux centosVMware shell中的函数、shell中的数组、
一.shell中的函数 函数就是把一段代码整理到了一个小单元中,并给这个小单元起一个名字,当用到这段代码时直接调用这个小单元的名字即可. 格式: function _name() { command ...
- JavaScript中的函数和C#中的匿名函数(委托、lambda表达式)
在js中function是一个一个引用类型,所以可以出现这样的代码: 'use strict'; var compare=function(value1, value2) { if (value1&l ...
- C++结构体中使用函数与类中使用函数小结
#include <iostream>#include <string.h>using namespace std;struct stud//学生信息结构体{ char ...
- 解决python中write()函数向文件中写中文时出现乱码的问题
今天看<python编程从入门到实践>的第10章文件.异常,在做练习的时候,向文件中写内容,但是写中文就不行,后来在百度上查了众多资料,解决方法如下: 解决:在open()函数中添加一个e ...
- python内置函数:sorted中的参数key
x.sort和sorted函数中参数key的使用 介绍 python中,列表自带了排序函数sort >>> l = [1, 3, 2] >>> l.sort() & ...
- python在读取配置文件存入列表中,去掉回车符号
self.receiver = map(lambda x: x.strip(), receiver_list) # 去掉list中的回车符号
- python中range函数与列表中删除元素
一.range函数使用 range(1,5) 代表从1到4(不包含5),结果为:1,2,3,4 ,默认步长为1 range(1,5,2) 结果为:1, 3 (同样不包含5) ,步长为2 ...
随机推荐
- DataSet排序
//排序 if (ds != null && ds.Tables.Count > 0) { DataVi ...
- BIOS讲解
首先 BIOS其实没什么神奇的 就是 Bisic input/output System,所以基本输入输出系统是一块装入了启动和自检程序的EPROM或EEPROM集成块,实际上它是被固化在计算机R ...
- bzoj1143
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1143 首先用传递闭包,知道一个点是否可以到达另一个点,即mp[i][j]==1表示i可以到j: ...
- sql server 2000 下载地址
sql server 2000 下载地址 http://pan.baidu.com/share/link?shareid=146152&uk=1225012539
- STL中erase的小心使用
先看如下一道改错题: #include<iostream> #include<vector> using namespace std; void print(vector< ...
- JSON 基本语法
JSON:JavaScript 对象表示法(JavaScript Object Notation). JSON 是存储和交换文本信息的语法.类似 XML. JSON 比 XML 更小.更快,更易解析. ...
- spark1.3的部署
1.下载源码,根据自己的环境编译,我这里下载的是spark1.3版本 本人采用sbt编译, SPARK_HADOOP_VERSION=2.5.2 SPARK_YARN=ture sbt/sbt ass ...
- Operation System - Peterson's Solution算法 解决多线程冲突
Person's solution 是用来一种基于软件的解决关键区域问题的算法(critical-section). 它并不是完美的,有可能不对地工作.并且是限制解决两个进程同步的问题. 可是它非常e ...
- hdu 4666 Hyperspace
曼哈顿距离,两个点设为(x1,y1),(x2,y2),其距离为|x1-x2|+|y1-y2| #include <cstdio> #include <set> #include ...
- C# XML,XmlDocument简单操作实例
private static string _Store = LocalPathHelper.CurrentSolutionPath + "/data/bookstore.xml" ...