Saturday, 21 July 2018

python - How can i use enviroment variables like %homepath% to list files in a Directory

I want to use System variables to access certain directories without hardcoding the path.



Im Running Python 3.7 on a Windows 10 64 bit machine. The whole idea is, to later acess some executable files that exist in the desired directory.




import os
path = r'%homepath%/Desktop'
dirlist = os.listdir(path)
print(dirlist)



I expect the output to be a list of files on the desktop. What i get is an error message saying that the specified directory cannot be found. If i use the explizit path things work out just fine.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...