Skip to content

Instantly share code, notes, and snippets.

@lixingcong
Created April 18, 2017 17:07
Show Gist options
  • Select an option

  • Save lixingcong/1f8daa4c68f3fda2f62e27c0897ce347 to your computer and use it in GitHub Desktop.

Select an option

Save lixingcong/1f8daa4c68f3fda2f62e27c0897ce347 to your computer and use it in GitHub Desktop.
将当前文件名转义空格或者中文
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
usage:
find /var/www/downloads > /tmp/1.txt
python this_script.py /tmp/1.txt
"""
import urllib
import sys
def main():
if len(sys.argv) != 2:
print "Error params, see usage below:"
print "# find /var/www/files > /tmp/1.txt"
print "# python %s /tmp/1.txt"%sys.argv[0]
sys.exit(1)
with open(sys.argv[1],'r') as f:
for line in f:
url=line.rstrip('\n')
print urllib.quote(url,'/:')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment