详解Python中的正则表达式的用法

WBOY
Release: 2016-06-10 15:15:40
Original
947 people have browsed it

如果直接在命令行中利用input和raw_input读入一个文件来处理,并且想要采用直接将文件拖入命令行来处理的方式,

input方法可以直接处理,而如果要采用raw_input的方法的话,读入文件地址会带有引号,还需要自己手动去掉引号才能处理文件。


在ipython中测试一下代码:(读入一个图片文件的地址字符串)

   a = input("input a:\n") 
  print "the input method: ",a 
  b = raw_input("input b:\n") 
  print "the raw_input method: ",b 
   
  input a: 
  '/home/sunny/caffe-master/examples/images/cat.jpg' 
  the input method: /home/sunny/caffe-master/examples/images/cat.jpg 
   
  input b: 
  '/home/sunny/caffe-master/examples/images/cat.jpg' 
  the raw_input method: '/home/sunny/caffe-master/examples/images/cat.jpg' 
Copy after login



另外,对于两种输入方式另一个直观区别就是input自带运算处理功能,也就是输入算式的话会直接输出结果,而raw_input会原汁原味(raw)地输出:


  #! -*- coding:utf-8 -*-  
  print raw_input(u'测试raw_input:\n') 
   
  print input(u'测试input:\n') 
Copy after login

测试结果:

201549161858658.jpg (310×239)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!