cgi中明明有escape,,为什么不能import

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

cgi中明明有escape,,为什么不能import

James liu-2
抄 python cookbook的一个例子
code:
  1 print "Content-type: text/html"                                               
  2 print                                                                         
  3 print "<html><head><title>Situation snapshot</title></head><body><pre>"       
  4                                                                               
  5 import sys                                                                    
  6 sys.stderr = sys.stdout                                                       
  7                                                                               
  8 import os                                                                     
  9                                                                               
 10 from cgi import escape                                                        
 11 print "<strong>Python %s</strong>" % sys.version                              
 12 keys = os.environ.keys ()                                                      
 13 keys.sort()                                                                   
 14 for k in keys:                                                                
 15     print "%s\t%s" % (escape(k), escape(os.environ[k]))                       
 16 print "</pre></body></html>" 



# python testcgi.py
Content-type: text/html

<html><head><title>Situation snapshot</title></head><body><pre>
Content-type: text/html

<html><head><title>Situation snapshot</title></head><body><pre>
Traceback (most recent call last):
  File "testcgi.py", line 10, in <module>
    from cgi import escape
  File "/usr/local/lib/python2.5/cgi.py", line 9, in <module>
    # /usr/bin.  So let those vendors patch cgi.py to match their choice
ImportError: cannot import name escape
--


 
regards
j.L
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: cgi中明明有escape,,为什么不能import

James liu-2
这个问题是不是有点怪?

我baidu不到。所以来问的。

2008/1/14 j. L <[hidden email]>:
抄 python cookbook的一个例子
code:
  1 print "Content-type: text/html"                                               
  2 print                                                                         
  3 print "<html><head><title>Situation snapshot</title></head><body><pre>"       
  4                                                                               
  5 import sys                                                                    
  6 sys.stderr = sys.stdout                                                       
  7                                                                               
  8 import os                                                                     
  9                                                                               
 10 from cgi import escape                                                        
 11 print "<strong>Python %s</strong>" % sys.version                              
 12 keys = os.environ.keys ()                                                      
 13 keys.sort()                                                                   
 14 for k in keys:                                                                
 15     print "%s\t%s" % (escape(k), escape(os.environ[k]))                       
 16 print "</pre></body></html>" 



# python testcgi.py
Content-type: text/html

<html><head><title>Situation snapshot</title></head><body><pre>
Content-type: text/html

<html><head><title>Situation snapshot</title></head><body><pre>
Traceback (most recent call last):
  File "testcgi.py", line 10, in <module>
    from cgi import escape
  File "/usr/local/lib/python2.5/cgi.py", line 9, in <module>
    # /usr/bin.  So let those vendors patch cgi.py to match their choice
ImportError: cannot import name escape
--


 
regards
j.L



--
regards
j.L
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: cgi中明明有escape,,为什么不能import

Qiangning Hong
2008/1/15 j. L <[hidden email]>:
> 这个问题是不是有点怪?
>
> 我baidu不到。所以来问的。

你是不是只贴了部分代码?反正我运行你贴出来的部分没有问题。怀疑是你其他部分或者配置的问题。

--
Qiangning Hong
http://www.douban.com/people/hongqn/
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: cgi中明明有escape,,为什么不能import

James liu-2
换成2.4就好了。。谢谢。

2008/1/15 Qiangning Hong <[hidden email]>:
2008/1/15 j. L <[hidden email]>:
> 这个问题是不是有点怪?
>
> 我baidu不到。所以来问的。

你是不是只贴了部分代码?反正我运行你贴出来的部分没有问题。怀疑是你其他部分或者配置的问题。

--
Qiangning Hong
http://www.douban.com/people/hongqn/
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese



--
regards
j.L
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese