Python Question – 3
Count Prime Numbers up to the given input number
I think this is the error I get:
Traceback (most recent call last):
File “./script1.py”, line 29, in
if not os.path.exists(path):
TypeError: ‘NoneType’ object is not subscriptable
Code:
A:
You have to use os.stat() to check if the path exists. import os path = 'C:/Users/my_user/Desktop/myfile.txt' if not os._stat(path, os.S_ISDIR): Edit: This is because you are using Python 3.x. You can use os._path.join to join the path with the current working directory. Source: https://docs.python.org/3/library/os.html#os.path If you want to avoid the use of os.chdir, you can use the os.makedirs() function.