Chinaunix

标题: import urandom的疑惑。。。 [打印本页]

作者: chishanmingshen    时间: 2015-01-23 09:07
标题: import urandom的疑惑。。。
本帖最后由 chishanmingshen 于 2015-01-23 09:18 编辑

/usr/lib64/python2.6/os.py 查看没有定义urandom


但是,使用成功!
[root@python2.6]# python
Python 2.6.6
Type "help", "copyright", "credits" or "license" for more information.
>>> from os import urandom
>>>


不解, 求解!谢谢!

作者: Linux_manne    时间: 2015-01-23 14:28
urandom 是从posix 来的
作者: chishanmingshen    时间: 2015-01-23 19:11
具体在哪个文件里?谢谢
作者: haooooaaa    时间: 2015-01-26 10:04
查了一下, 还真没有这个东西,

然后google了, 人家说这个是用的

/dev/urandom 这个东东....

还真不知道从哪去调用 的.
作者: shou55    时间: 2015-01-26 17:38
本帖最后由 shou55 于 2015-01-26 23:02 编辑

回复 1# chishanmingshen
如图,我查看是有的

   

1738277ns7r526qaa7tf62.jpg (30.96 KB, 下载次数: 38)

1738277ns7r526qaa7tf62.jpg

作者: chishanmingshen    时间: 2015-01-27 06:57
但是我们确实在os.py里没有定义。可能跟版本有关?


有高手解答下,谢谢了
作者: chishanmingshen    时间: 2015-01-28 19:45
等解答,谢谢
作者: chishanmingshen    时间: 2015-02-01 08:34
等高手,谢谢
作者: chishanmingshen    时间: 2015-02-01 08:35
等高手,谢谢
作者: chishanmingshen    时间: 2015-02-02 12:41

但是我们确实在os.py里没有定义。那为何还不报错?

等高手解答,谢谢
作者: chishanmingshen    时间: 2015-02-11 21:26
等高手,谢谢了。。。。。
作者: chishanmingshen    时间: 2015-02-12 12:40
等高手,谢谢了。。。。。
作者: weishuo1999    时间: 2015-02-12 14:51
我觉得很可能是用扩展做的,就是说通过动态库的方式扩展了os的module的方法,貌似解释的过去,具体实现倒是可以看看python的源码,我抽空看看,再回答
作者: weishuo1999    时间: 2015-02-12 15:24
看了一下源码,urandom这个定义实在posix的模块里面的,然后在os.py里面import 了posix的*,所以自然就有了urandom,2.6的版本是这样的

新的版本os.py里面会判断一次,如果没有urandom会再定义下
作者: chishanmingshen    时间: 2015-02-17 11:30
回复 14# weishuo1999


    具体Posix哪个文件?没找到啊!谢谢啦
作者: weishuo1999    时间: 2015-02-25 09:43
在python的c源码里面的posixmodule.c里面
回复 15# chishanmingshen


   




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2