Skip to content

Instantly share code, notes, and snippets.

@isagallerani
Last active October 27, 2017 17:56
Show Gist options
  • Save isagallerani/8498f796dee91cf3ec2aa3490db1bd80 to your computer and use it in GitHub Desktop.
Save isagallerani/8498f796dee91cf3ec2aa3490db1bd80 to your computer and use it in GitHub Desktop.
null created by isagallerani - https://repl.it/NV6L/0
#primeiro, preenche campo por campo e verifica-se o tamanho
#concatena tudo numa unica string e manda pro arquivo (registro)
#bloco sera uma lista de registros
registro = ""
""
def criaArquivo():
global registro
#leitura e verificacao de campos
ra = '012345' # ra = 6 bytes
size = len(ra.encode('utf-8'))
if(size == 6):
registro += ra
elif(size > 6):
#pega os 6 primeiros bytes e ignora o registro
registro += ra[:6]
else:
while (size < 6):
ra += '%'
size = len(ra.encode('utf-8'))
registro += ra
nome = 'Bla Bla Bla' # nome = 50 bytes
size = len(nome.encode('utf-8'))
if(size == 50):
registro += nome
elif(size > 50):
registro += nome[:50]
else:
while(size < 50):
nome += '%'
size = len(nome.encode('utf-8'))
registro += nome
curso = 'Ciencia da Computacao' # curso = 34 bytes
size = len(curso.encode('utf-8'))
if(size == 34):
registro += curso
elif(size > 34):
registro += curso[:34]
else:
while(size < 34):
curso += '%'
size = len(curso.encode('utf-8'))
registro += curso
nascimento = '01/01/1990' # nascimento = 10 bytes
size = len(nascimento.encode('utf-8'))
if(size == 10):
registro += nascimento
elif(size > 10):
registro += nascimento[:10]
else:
while(size < 10):
nascimento += '%'
size = len(nascimento.encode('utf-8'))
registro += nascimento
#talvez fosse melhor por sigla da faculdade por conta do tratamento para data na configuracao dd/mm/aaaa
#criando arquivo e escrevendo a string registro nele
arq = open('caminho aqui', 'w')
arq.write(registro)
arq.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment