Created
April 18, 2017 17:07
-
-
Save lixingcong/1f8daa4c68f3fda2f62e27c0897ce347 to your computer and use it in GitHub Desktop.
将当前文件名转义空格或者中文
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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