You could do something like this:
import osimport ctypesFILE_ATTRIBUTE_HIDDEN = 0x02def write_hidden(file_name, data):""" Cross platform hidden file writer.""" # For *nix add a '.' prefix. prefix = '.' if os.name != 'nt' else '' file_name = prefix + file_name # Write file. with open(file_name, 'w') as f: f.write(data) # For windows set file attribute. if os.name == 'nt': ret = ctypes.windll.kernel32.SetFileAttributesW(file_name, FILE_ATTRIBUTE_HIDDEN) if not ret: # There was an error. raise ctypes.WinError()This has not been tested but should work fine.
Also you may wish to see these other questions that helped me implement this: