html tool

2013年1月17日星期四

Dive into python 阅读笔记-sys.stdout 类比形式化翻译《黄帝内经》

Chapter 10. Scripts and Streams 的 10.2. Standard input, output, and error
与python无关,只是在阅读中突然想到其实linux的这种处理思想,在理解和形式化翻译<黄帝内经>时应该有帮助。才写下的 
  -----------------------原文----------------------------------------------- 
  P142 
   
  #stdout.py 
  import sys 
  print 'Dive in' 
  saveout = sys.stdout 
  fsock = open('out.log', 'w') 
  sys.stdout = fsock 
  print 'This message will be logged instead of displayed' 
  sys.stdout = saveout 
  fsock.close() 
   
   4 
   [原文]P143 
   
   Redirect all further output to the new file you just opened. 
   [pope译]重定向之后的全部output 到你新打开的文件中。 
   
   【popexizhi: 刚刚意识到sys.stdout = fsock 不是普通的赋值操作,这个是在为系统输出指定新的输出文件啊!系统将之前的默认的IDE或是command line 想这个file一样处理的,这里的redirect操作对sys.out来说是只是换了个文件,设备即文件的概念在这里是个再好不过的体现了吧:)。在这里突然意识到另外一个问题,不同的输出域的定义,是在同类集合中才有切换的可能,设备,文本是同类的定义前提才可以完成这个过程。《黄帝内经》中说的“在天为玄,在人为道,在地为化”的“天,人,地”等,这个过程可以使用 fsock=open('天','w');sys.stdout=fsock 的方式表达了吧!好的,可以进一步翻译一下试试。 】 

没有评论:

发表评论