Can I read enviromenz variables?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
uraich
Posts: 56
Joined: Tue Mar 26, 2019 12:24 pm

Can I read enviromenz variables?

Post by uraich » Mon Sep 05, 2022 1:40 pm

Hi,
I would need to figure out the user's home directory on the unix port. So... I could try to find out what $HOME corresponds to. Can this be done in micropython?

TheSilverBullet
Posts: 50
Joined: Thu Jul 07, 2022 7:40 am

Re: Can I read enviromenz variables?

Post by TheSilverBullet » Mon Sep 05, 2022 3:06 pm

import os
os.getenv('HOME')

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Can I read enviromenz variables?

Post by bulletmark » Mon Sep 05, 2022 11:38 pm

uraich wrote:
Mon Sep 05, 2022 1:40 pm
Hi,
I would need to figure out the user's home directory on the unix port. So... I could try to find out what $HOME corresponds to. Can this be done in micropython?
Think about how you would do this in ordinary Python and always try that first. I.e. exactly as posted above.

uraich
Posts: 56
Joined: Tue Mar 26, 2019 12:24 pm

Re: Can I read enviromenz variables?

Post by uraich » Tue Sep 06, 2022 10:23 am

@TheSilverBullet: Thanks, this works! I could have seen it myself with help(os)

Post Reply