WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Saving to MicroSD card through Python  (Read 1860 times)

Offline xuraax

  • Newbie
  • *
  • Posts: 37
Saving to MicroSD card through Python
« on: March 19, 2022, 07:41:17 AM »
I am running a program in Python which needs to save data permanently to the SD card. I am using the normal Python file operations which saves data to a ram file.

What is the recommended method of saving permanently to disk?

Thanks

Xuraax

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1263
Re: Saving to MicroSD card through Python
« Reply #1 on: March 19, 2022, 01:03:58 PM »
Just specify a persistent location to save the data.   Like add a USB drive, or create a separate partition on your SD card.

Offline mbivol10

  • Newbie
  • *
  • Posts: 39
Re: Saving to MicroSD card through Python
« Reply #2 on: March 20, 2022, 11:25:45 AM »
if you want to save to your sd card then:

Code: [Select]
sudo mount /dev/mmcblk0p1 /mnt/mmcblk0p1

then you have the fat32 partition of the sd card which you can write files to using your python program

or

sudo mount /dev/mmcblk0p2 /mnt/mmcblk0p2

which will mount the ext4 partition instead, there you save files to linux filesystem, less supported so you can't just plug it into windows or mac without special programs that read the partition.
However if you have a linux desktop, this should be no issue.

Offline xuraax

  • Newbie
  • *
  • Posts: 37
Re: Saving to MicroSD card through Python
« Reply #3 on: March 21, 2022, 11:20:15 AM »
@mbivol10,

Thanks for your reply.

I, more or less, arrived at the same setup you proposed except I created a third partition to keep my saved files separate.

Furthermore for python to be allowed to save files to this drive I had to change permissions for this drive using chmod 777.

Regards

xuraax