2005年04月13日 星期三 21:37
简单哪,调用一个系统脚本,让专门授权的脚本来执行就好哪?? 在05-4-13,Meaglith Ma<meaglith.ma at mypress.com.cn> 写道: > 我在一个程序中执行一个命令,使用os.system()。 > 但是这个命令是root才有权限执行的,所以我想切换用户到root再执行怎么办 > 我在前面加了一个os.system('su root'),然后再执行os.system('my command')也不可以。 > 请教怎么来做呢? > > ---------------------------------------- > 欢迎访问我的Blog: > http://spaces.msn.com/members/meaglith/ > > ---------------------------------------- > .--. > |o_o | > |:_/ | > // \ \ > (| | ) > /'\_ _/`\ > \___)=(___/ > ---------------------------------------- > 沧海笑 滔滔两岸潮 浮沉随浪记今朝 > 苍天笑 纷纷世上潮 谁负谁胜天知晓 > 江山笑 烟两遥 涛浪淘尽红尘俗也知多少 > 竟惹寂寥 一襟晚照 > 苍生笑 不再寂寥 豪情仍在痴痴笑笑 > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- [Time is unimportant, only life important!]
2005年04月13日 星期三 21:58
编写一个shell脚本,在前面写上su root这样可以么? 05-4-13,Zoom Quiet <zoom.quiet at gmail.com> 写道: > > 简单哪,调用一个系统脚本,让专门授权的脚本来执行就好哪?? > > 在05-4-13,Meaglith Ma<meaglith.ma at mypress.com.cn> 写道: > > 我在一个程序中执行一个命令,使用os.system()。 > > 但是这个命令是root才有权限执行的,所以我想切换用户到root再执行怎么办 > > 我在前面加了一个os.system('su root'),然后再执行os.system('my command')也不可以。 > > 请教怎么来做呢? > > > > ---------------------------------------- > > 欢迎访问我的Blog: > > http://spaces.msn.com/members/meaglith/ > > > > ---------------------------------------- > > .--. > > |o_o | > > |:_/ | > > // \ \ > > (| | ) > > /'\_ _/`\ > > \___)=(___/ > > ---------------------------------------- > > 沧海笑 滔滔两岸潮 浮沉随浪记今朝 > > 苍天笑 纷纷世上潮 谁负谁胜天知晓 > > 江山笑 烟两遥 涛浪淘尽红尘俗也知多少 > > 竟惹寂寥 一襟晚照 > > 苍生笑 不再寂寥 豪情仍在痴痴笑笑 > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > -- > [Time is unimportant, only life important!] > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- 欢迎访问我的Blog: http://spaces.msn.com/members/meaglith/ http://blog.360.yahoo.com/genednaparadox ---------------------------------------- .--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/ ------------------------------------------------- 沧海笑 滔滔两岸潮 浮沉随浪记今朝 苍天笑 纷纷世上潮 谁负谁胜天知晓 江山笑 烟两遥 涛浪淘尽红尘俗也知多少 竟惹寂寥 一襟晚照 苍生笑 不再寂寥 豪情仍在痴痴笑笑 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050413/b01b0074/attachment.htm
2005年04月13日 星期三 22:09
>>> round(1.25,1)
1.3
>>> round(1.255,2)
1.25
~~~~~~~~~~~ 为什么不是期望中的 1.26 ?
我找了源代码中的实现:
static PyObject *
builtin_round(PyObject *self, PyObject *args)
{
double x;
double f;
int ndigits = 0;
int i;
if (!PyArg_ParseTuple(args, "d|i:round", &x;, &ndigits;))
return NULL;
f = 1.0;
i = abs(ndigits);
while (--i >= 0)
f = f*10.0;
if (ndigits < 0)
x /= f;
else
x *= f;
if (x >= 0.0)
x = floor(x + 0.5);
else
x = ceil(x - 0.5);
if (ndigits < 0)
x *= f;
else
x /= f;
return PyFloat_FromDouble(x);
}
感觉没有问题阿?
致
礼!
albertlee
hanzhupeng at 163.com
2005-04-13
2005年04月13日 星期三 22:22
俄,找到原因了,是浮点数的表示
1.255 在内存中是 1.2549999999999999
不知道这个问题,算不算是个bug
======= 2005-04-13 22:09:35 您在来信中写道:=======
>>>> round(1.25,1)
>1.3
>>>> round(1.255,2)
>1.25
>~~~~~~~~~~~ 为什么不是期望中的 1.26 ?
>
>我找了源代码中的实现:
>
>static PyObject *
>builtin_round(PyObject *self, PyObject *args)
>{
> double x;
> double f;
> int ndigits = 0;
> int i;
>
> if (!PyArg_ParseTuple(args, "d|i:round", &x;, &ndigits;))
> return NULL;
> f = 1.0;
> i = abs(ndigits);
> while (--i >= 0)
> f = f*10.0;
> if (ndigits < 0)
> x /= f;
> else
> x *= f;
> if (x >= 0.0)
> x = floor(x + 0.5);
> else
> x = ceil(x - 0.5);
> if (ndigits < 0)
> x *= f;
> else
> x /= f;
> return PyFloat_FromDouble(x);
>}
>
>感觉没有问题阿?
>
>
>
>
> 致
>礼!
>
>
> albertlee
> hanzhupeng at 163.com
> 2005-04-13
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
= = = = = = = = = = = = = = = = = = = =
致
礼!
albertlee
hanzhupeng at 163.com
2005-04-13
Zeuux © 2025
京ICP备05028076号