When I type this code into a python shell it works perfectly fine but within a program it gives an error.
import os
h = os.environ['HOME']
within a script it gives this error:
AttributeError: 'str' object has no attribute 'environ'
Why is this happening and is there any way I can fix it?
(I’m kinda just learning python so I dont know much. Google didn’t help)
Somewhere, you’ve created a string and named it
os. The.is the attribute lookup operator, so it’s complaining about the thing to the left of the., in this case,os.