Export data to a file . cfg

Asked

Viewed 117 times

-1

Could someone give me an example of how to export my models data by pk to a file . cfg?

tried to use Mymodel.objects.get(pk=pk) but it didn’t work out so well.

  • 1

    Do you want to export the object to a file? If so you can use Pickle, Shelve, Marshal or JSON.

  • What is a file .cfg? Is that a standard format? One way to create files of any text-based format - not only HTML, but also JSON, XML, etc, including plain text - is by using the template system. I can give you an example, if you show what the structure of your model is and what format is expected from the output.

1 answer

-2

You can create a file using

arquivo = open('arquivodeconfig.cfg', 'r')
#assim você pode usar arquivo.read() para aparecer o que está no arquivo
print(arquivo.read())
arquivo = open('arquivodeconfig.cfg', 'w') #ao abrir o arquivo no modo w(Write) ele formata o arquivo
input = input('')
arquivo.write(input) #assim ele escreve um input no arquivo

You can also use the a(append) mode to add more information after the original file information using.append(What you want to add). I hope I helped :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.