Python论坛  - 讨论区

标题:[python-chinese] Python新手:有关任意读取文档内容的问题

2006年05月18日 星期四 01:58

Zhou Wei gogogo26 at gmail.com
Thu May 18 01:58:19 HKT 2006

大家好:
我在做一个猜谜的游戏,任意读取文本文档已经写好的问题和答案,我用random模块的时候出现了一些问题

部分代码如下:
while len(stage.line) > 0:
    question_item = []
    stage.line = stage.f.readline()  # read 1 line : should be the question
    question_item.append(stage.line)   # put it as first element
    stage.line = stage.f.readline()  # read 1 line : should be a number
    answer_list = []                 # create the list of questions
    stage.line = stage.f.readline()  # read 1 line : should be first answer
    answer_list.append(stage.line)     # set it as first element of the
aswers list
    stage.line = stage.f.readline()  # read 1 line : should be second answer
    answer_list.append(stage.line)     # set it as second element of the
aswers list
    stage.line = stage.f.readline()  # read 1 line : should be third answer
    answer_list.append(stage.line)     # set it as third element of the
aswers list
    stage.line = stage.f.readline()  # read 1 line : should be forth answer
    answer_list.append(stage.line)     # set it as forth element of the
aswers list

    question_item.append(answer_list)

    question_item = Q[ random(len(Q)) ]
    print quetion_item

但是运行时有如下错误:

Traceback (most recent call last):
  File "q1.py", line 109, in ?
    question_item = Q[ random(len(Q)) ]
TypeError: 'module' object is not callable



请问是怎么回事,谢谢
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060517/37c0cde6/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月18日 星期四 03:05

swordsp sparas2006 at gmail.com
Thu May 18 03:05:16 HKT 2006

查random的文档

random.choice(Q)

On 5/18/06, Zhou Wei <gogogo26 at gmail.com> wrote:
>
> 大家好:
> 我在做一个猜谜的游戏,任意读取文本文档已经写好的问题和答案,我用random模块的时候出现了一些问题
>
> 部分代码如下:
> while len(stage.line) > 0:
>     question_item = []
>     stage.line = stage.f.readline()  # read 1 line : should be the
> question
>     question_item.append(stage.line)   # put it as first element
>     stage.line = stage.f.readline()  # read 1 line : should be a number
>     answer_list = []                 # create the list of questions
>     stage.line = stage.f.readline()  # read 1 line : should be first
> answer
>     answer_list.append( stage.line)     # set it as first element of the
> aswers list
>     stage.line = stage.f.readline()  # read 1 line : should be second
> answer
>     answer_list.append(stage.line)     # set it as second element of the
> aswers list
>     stage.line = stage.f.readline()  # read 1 line : should be third
> answer
>     answer_list.append(stage.line)     # set it as third element of the
> aswers list
>     stage.line = stage.f.readline()  # read 1 line : should be forth
> answer
>     answer_list.append(stage.line)     # set it as forth element of the
> aswers list
>
>     question_item.append(answer_list)
>
>     question_item = Q[ random(len(Q)) ]
>     print quetion_item
>
> 但是运行时有如下错误:
>
> Traceback (most recent call last):
>   File "q1.py", line 109, in ?
>     question_item = Q[ random(len(Q)) ]
> TypeError: 'module' object is not callable
>
>
>
> 请问是怎么回事,谢谢
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060518/a2ec713d/attachment-0001.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号