用python代码做configure文件
作者:hebedich 时间:2023-08-17 13:33:58
(在lua中通过loadfile, setfenv实现)
python当然也可以:
cat config.py
bar = 10
foo=100
cat python_as_config.py:
ns = {}
execfile('config.py', ns)
print "\n".join(sorted(dir(ns)))
print "*"*80
print ns['foo']
print ns['bar']
缺点是不像lua那么可以以成员的方式访问table中的变量,如ns.foo, ns.bar...
例子: https://github.com/baiyanhuang/blog/tree/master/arena/python/python_as_config
标签:python,configure
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现下载指定网址所有图片的方法
2021-05-17 22:12:16
Python OpenCV视频截取并保存实现代码
2023-01-05 06:04:21
python基本算法之实现归并排序(Merge sort)
2023-04-06 03:20:07
![](https://img.aspxhome.com/file/2023/7/112037_0s.gif)
Python开发毕设案例之桌面学生信息管理程序
2021-03-02 14:56:08
![](https://img.aspxhome.com/file/2023/2/76752_0s.png)
我们需要的是怎样的分页?
2007-09-28 20:24:00
![](https://img.aspxhome.com/file/UploadPic/20079/28/2007928202636587s.gif)
python scipy.misc.imsave()函数的用法说明
2022-11-01 13:04:24
Python使用draw类绘制图形示例讲解
2022-04-06 01:16:31
![](https://img.aspxhome.com/file/2023/4/101164_0s.png)
Python装饰器中@property使用详解
2022-04-22 04:46:44
MySQL 分表分库怎么进行数据切分
2024-01-14 06:15:29
![](https://img.aspxhome.com/file/2023/5/115585_0s.jpg)
浅谈Python响应式类库RxPy
2021-12-24 12:44:26
![](https://img.aspxhome.com/file/2023/3/78453_0s.png)
SQLServer 2000 数据库同步详细步骤[两台服务器]
2024-01-21 11:18:03
在Python中操作列表之List.append()方法的使用
2021-07-07 04:09:45
Python使用文件操作实现一个XX信息管理系统的示例
2022-07-12 15:28:31
![](https://img.aspxhome.com/file/2023/0/133280_0s.jpg)
python如何将两张图片生成为全景图片
2021-08-03 23:42:26
![](https://img.aspxhome.com/file/2023/0/81480_0s.jpg)
python paramiko模块学习分享
2021-11-10 16:57:00
python3用urllib抓取贴吧邮箱和QQ实例
2022-05-15 16:25:18
python tarfile压缩包操作保姆级教程
2022-03-29 21:38:30
Python查询缺失值的4种方法总结
2023-10-29 13:42:08
![](https://img.aspxhome.com/file/2023/1/90871_0s.png)
检测你的SQL Server是否有特洛伊木马
2009-02-05 15:58:00
vue监听页面中的某个div的滚动事件并判断滚动的位置
2024-05-09 15:08:49