Python论坛  - 讨论区

标题:[python-chinese] ¹ØÓÚstdinµÄÎÊÌ⣬Çë½Ì£¡

2005年06月12日 星期日 13:31

ÒÊÃÉɽÈË dreamingpython at 163.com
Sun Jun 12 13:31:52 HKT 2005

ÈçÏÂ:

    from xml.dom.ext.reader.Sax2 import FromXmlStream
    doc=FromXmlStream(sys.stdin)

ÔÚÕâÀïFromXmlStreamµÄ²ÎÊýʱsys.stdin£¬¼ÓÈëÎÒÓÐÒ»¸öxmlÎļþ£¬ÎļþÃûΪ
test.xml£¬
ÎÒ¸ÃÈçºÎ°ÑÕâ¸ö sys.stdinÖØ¶¨Ïòµ½Õâ¸ötest.xmlÎļþÄØ£¿
ÄúÄܸø°ïÎÒдһ¸öÀý×Óô£¬¹ØÓÚÕâ¸östdinµÄ¶«Î÷ÎÒÒ»Ö±ºÜÄ£ºý£¬°üÀ¨C++ÖеÄÄÇÐ©Íæ
Ò⣬

лл£¡




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

2005年06月12日 星期日 20:24

limodou limodou at gmail.com
Sun Jun 12 20:24:40 HKT 2005

我想:
f=file('test.xml')
sys.stdin = f
不过为什么不直接:
doc = FromXmlStream(f)
呢?

在 05-6-12,沂蒙山人<dreamingpython at 163.com> 写道:
> 如下:
> 
>     from xml.dom.ext.reader.Sax2 import FromXmlStream
>     doc=FromXmlStream(sys.stdin)
> 
> 在这里FromXmlStream的参数时sys.stdin,加入我有一个xml文件,文件名为
> test.xml,
> 我该如何把这个 sys.stdin重定向到这个test.xml文件呢?
> 您能给帮我写一个例子么,关于这个stdin的东西我一直很模糊,包括C++中的那些玩
> 意,
> 
> 谢谢!
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 


-- 
I like python! 
My Donews Blog: http://www.donews.net/limodou
New Google Maillist: http://groups-beta.google.com/group/python-cn

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

2005年06月12日 星期日 22:42

Qiangning Hong hongqn at gmail.com
Sun Jun 12 22:42:15 HKT 2005

沂蒙山人 wrote:
> 如下:
> 
>     from xml.dom.ext.reader.Sax2 import FromXmlStream
>     doc=FromXmlStream(sys.stdin)
> 
> 在这里FromXmlStream的参数时sys.stdin,加入我有一个xml文件,文件名为
> test.xml,
> 我该如何把这个 sys.stdin重定向到这个test.xml文件呢?
> 您能给帮我写一个例子么,关于这个stdin的东西我一直很模糊,包括C++中的那些玩
> 意,
> 
> 谢谢!

方法1、改程序:
   doc = FromXmlStream(file('test.xml'))

方法2、修改sys.stdin:
   sys.stdin = file('test.xml')
   doc = FromXmlStream(sys.stdin)

方法3、shell重定向:
   python yourapp.py < test.xml

-- 
Qiangning Hong

 __________________________________________________________
/ When a camel flies, no one laughs if it doesn't get very \
\ far!                                                     /
 ----------------------------------------------------------
      \                    / \  //\
       \    |\___/|      /   \//  \\
            /0  0  \__  /    //  | \ \
           /     /  \/_/    //   |  \  \
           @_^_@'/   \/_   //    |   \   \
           //_^_/     \/_ //     |    \    \
        ( //) |        \///      |     \     \
      ( / /) _|_ /   )  //       |      \     _\
    ( // /) '/,_ _ _/  ( ; -.    |    _ _\.-~        .-~~~^-.
  (( / / )) ,-{        _      `-.|.-~-.           .~         `.
 (( // / ))  '/\      /                 ~-. _ .-~      .-~^-.  \
 (( /// ))      `.   {            }                   /      \  \
  (( / ))     .----~-.\        \-'                 .~         \  `. \^-.
             ///.----..>        \             _ -~             `.  ^-`  ^-_
               ///-._ _ _ _ _ _ _}^ - - - - ~                     ~-- ,.-~
                                                                  /.-~

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

2005年06月13日 星期一 09:09

ÒÊÃÉɽÈË dreamingpython at 163.com
Mon Jun 13 09:09:06 HKT 2005

    Ô­À´ÕâÑù°¡£¬Ö»Òª½«Ò»¸öfile¶ÔÏó¸ºÖµ¸østdin¾Í¿ÉÒÔÁ˰¡£¬Ð»Ð»£¡Ð»Ð»£¡
"ÒÊÃÉɽÈË" <dreamingpython at 163.com> дÈëÓʼþ
news:d8ggtc$qni$1 at sea.gmane.org...
> ÈçÏÂ:
>
>     from xml.dom.ext.reader.Sax2 import FromXmlStream
>     doc=FromXmlStream(sys.stdin)
>
> ÔÚÕâÀïFromXmlStreamµÄ²ÎÊýʱsys.stdin£¬¼ÓÈëÎÒÓÐÒ»¸öxmlÎļþ£¬ÎļþÃûΪ
> test.xml£¬
> ÎÒ¸ÃÈçºÎ°ÑÕâ¸ö sys.stdinÖØ¶¨Ïòµ½Õâ¸ötest.xmlÎļþÄØ£¿
> ÄúÄܸø°ïÎÒдһ¸öÀý×Óô£¬¹ØÓÚÕâ¸östdinµÄ¶«Î÷ÎÒÒ»Ö±ºÜÄ£ºý£¬°üÀ¨C++ÖеÄÄÇÐ©Íæ
> Ò⣬
>
> лл£¡
>
>
>




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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号