开发者

How to access a drive by volume label in a python script in Ubuntu

I am writing a python script that copies some data to an external drive attached to Ubuntu host. I do not want to pass the device file of the drive to the python script. But I can set the Volume label of the drive and export it as an environment variable in the linux shell.

My quest开发者_运维技巧ion is how to I access this shell environment variable in my python script ?

Thanks!


The os module provides access to environmental variables. Suppose that you have exported $VOL="/BLAH". Then, in Python:

import os
my_path = os.environ['VOL']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜