How can i Open binary files with Django?

55 views
Skip to first unread message

Lucas Matos

unread,
Feb 13, 2023, 3:56:18 PM2/13/23
to Django users
I tested so many ways to do it, however a only found how to open text files. Someone can help me?

atleta

unread,
Feb 13, 2023, 7:24:51 PM2/13/23
to Django users

You don't open files with django. You open files with the built-in function 'open'. Which allows you to specify text or binary mode. See the documentation: https://docs.python.org/3.11/library/functions.html#open

Lucas Matos Matos

unread,
Feb 14, 2023, 11:54:10 AM2/14/23
to django...@googlegroups.com
In my case i want to take the file with a input type file from a form, that is in binary, open it and convert it to a text file, identify its characteristics  and return  something based in its characteristics to the user.
Can i use this method (open) to do it ?

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/gaXW-MyFR0Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/09553009-4ed2-472d-a86c-a7687308b4b9n%40googlegroups.com.

Kasper Laudrup

unread,
Feb 14, 2023, 12:58:15 PM2/14/23
to django...@googlegroups.com
On 14/02/2023 17.52, Lucas Matos Matos wrote:
> In my case i want to take the file with a input type file from a form,
> that is in binary, open it and convert it to a text file, identify its
> characteristics  and return  something based in its characteristics to
> the user.

This might be what you're looking for:

https://pypi.org/project/python-magic/

Kind regards,

Kasper Laudrup
OpenPGP_0xE5D9CAC64AAA55EB.asc
OpenPGP_signature

Anh Nguyen

unread,
Feb 14, 2023, 2:53:52 PM2/14/23
to django...@googlegroups.com
Use struct to unpack binary file

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a904182-202d-b909-f9c0-7ecf9b3eee2c%40stacktrace.dk.
Reply all
Reply to author
Forward
0 new messages