sys.stdin和sys.argv说开去

Eric.M <[email protected]>
sender-time     Sent at 13:55 (GMT+08:00). Current time there: 8:41 PM. ✆
reply-to        [email protected]
to      [email protected]
date    Fri, Sep 24, 2010 at 13:55
subject Re: [CPyUG] 关于sys.stdin和sys.argv的问题请教

缘起

问题

亮点

具体代码见此==>构建管道,重定向sys.stdin,用管道喂

要么是文件,要么就是管道, 因为是动态构建,就没必要产生文件了还要删除,下面是部分涉及到的代码

   1 i=int(dict["testNum"])
   2 r="\n".join(dict["list_result"].split("\n")[:i])
   3 fdr,fdw=os.pipe()
   4 os.write(fdw,r)
   5 os.close(fdw)
   6 f=os.fdopen(fdr)
   7 sys.stdin=f
   8 sys.stdout  = results_io
   9 
  10 try:
  11     compiled_code = compile(dict["list_fetch_code"].encode("utf-8"), g.list_fetch_code_filename, 'exec')
  12     exec(compiled_code,globals())
  13 except Exception, e:
  14         traceback.print_exc(file=results_io)
  15 
  16 except Exception,e:
  17     print e,"#############################################"
  18 finally:
  19     sys.stdout = save_stdout

Shell原生判定

Shellexy <[email protected]>
sender-time     Sent at 17:52 (GMT+08:00). Current time there: 8:46 PM. ✆
reply-to        [email protected]
to      [email protected]
date    Fri, Sep 24, 2010 at 17:52

去学习现有 Linux 程序的做法,

单行判别

victor lee <[email protected]>
sender-time     Sent at 19:48 (GMT+08:00). Current time there: 8:47 PM. ✆
reply-to        [email protected]
to      [email protected]
date    Fri, Sep 24, 2010 at 19:48

   1 file_=(open(arg[1]) if "-"==arg[1] else sys.stdin) if len(arg)>1 else sys.stdin


反馈

创建 by -- ZoomQuiet [2010-09-24 12:49:12]

MiscItems/2010-09-23 (last edited 2010-09-24 13:07:09 by ZoomQuiet)