python> Change file owner> os.chown ("path / to / file", uid, gid)

I want to change the created file to an owner other than root.

http://stackoverflow.com/questions/25791311/creating-a-file-with-python-using-sudo-makes-its-owner-root

chOwn1.py


import os
os.chown("path/to/file", uid, gid)

chOwn2.py


import os

uid = int(os.environ.get('SUDO_UID'))
gid = int(os.environ.get('SUDO_GID'))

os.chown("path/to/file", uid, gid)

It is unconfirmed how the SUDO_UID and SUDO_GID parts correspond to the user pi.

https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=73924 Maybe I should check / etc / passwd.

Recommended Posts

python> Change file owner> os.chown ("path / to / file", uid, gid)
[Python] Change standard input from keyboard to text file
[Work efficiency] How to change file names in Python
How to change Python version
[python] Change the image file name to a serial number
Change the standard output destination to a file in Python
[Python] How to change EXCEL file saved in xlsb to xlsx
File / folder path manipulation in Python
[Python] Write to csv file with Python
Output to csv file with Python
Change python default encoding to utf-8
File upload to Azure Storage (Python)
[Python] Change the alphabet to numbers
Did not change from Python 2 to 3
[Python Kivy] How to get the file path by dragging and dropping
[Python] How to convert db file to csv
Change Python 64bit environment to 32bit environment with Anaconda
[Python] Convert csv file delimiters to tab delimiters
Convert psd file to png in Python
Get the path to the systemd unit file
How to read a CSV file with Python 2/3
[Python] How to change the date format (display format)
Import Excel file from Python (register to DB)
From file to graph drawing in Python. Elementary elementary
How to create a JSON file in Python
[Python] How to read excel file with pandas
Convert svg file to png / ico with Python
Writing logs to CSV file (Python, C language)
Diffusion MRI bvec file polarity change by Python
How to add a Python module search path
Output python log to both console and file
Export Python3 version OpenCV KeyPoint to a file
[Introduction to Algorithm] Find the shortest path [Python3]
I want to write to a file with Python
Sample to put Python Kivy in one file
2017-02-19 Python> Link> Redirect to output file immediately> sys.stdout.flush ()