Manage Files - Django

 

File Opening Modes

There are modes in which you can open a file in Python. The mode you choose depends on how you plan to use the file, or what kind of data you'll be reading (writing) from (to) the file. This mode is specified when opening a file using the built-in open() method, explained in further detail in the next section.

Let's take a look at some of the possible combinations of file modes:

  • w: Opens a file for writing and creates a new file if it doesn't yet exist. In the case that the file does exist, it overwrites it.
  • w+: Opens a file for writing but also for reading and creating it if it doesn't exist. If a file already exists, it overwrites it.
  • r: Opens a file for reading only.
  • rb: Opens a file for reading in Binary format.
  • wb: Opens a file for writing in Binary format.
  • wb+: Opens a file for writing and reading in Binary format.
  • a: Opens a file for appending at the end of the file.
  • +: In general, this character is used along side r, w, or a and means both writing and reading.



If no file mode is specified, then r will be assumed by default.





https://sayari3.com/articles/19-django-digitalocean-spaces-tutorial/



Material de apoio


Comentários

Postagens mais visitadas deste blog

Weasyprint

Models - Django

Django Mask with JQuery Mask Plugin