Created
July 18, 2011 12:04
-
-
Save rodrigoamaral/1089309 to your computer and use it in GitHub Desktop.
Inserindo coluna em arquivo CSV
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
| #coding:utf-8 | |
| """ | |
| Exemplo de uso do módulo csv para ler e escrever arquivos do | |
| tipo comma separated values e do módulo sys para tratar | |
| parâmetros de linha de comando. | |
| Uso: python inserird.py ARQUIVO_ENTRADA ARQUIVO_SAIDA | |
| Mais informações na documentação oficial: | |
| http://docs.python.org/library/csv.html | |
| http://docs.python.org/library/sys.html | |
| """ | |
| import csv | |
| import sys | |
| def main(): | |
| if len(sys.argv) > 2: | |
| leitor = csv.reader(open(sys.argv[1], 'rb')) | |
| escritor = csv.writer(open(sys.argv[2], 'wb')) | |
| for linha in leitor: | |
| escritor.writerow(linha[:1] + ['D'] + linha[1:]) | |
| else: | |
| print """Uso: python inserird.py ARQUIVO_ENTRADA ARQUIVO_SAIDA""" | |
| if __name__ == '__main__': | |
| main() | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Editei a docstring do módulo para exibir o modo de uso.