0

I have the following Python script:

#!/usr/bin/python
import glob, os

os.chdir("/data")
for file in glob.glob("*.gz"):
    print(file)

When I run this script I get error:

Traceback (most recent call last):
  File "python.py", line 3, in <module>
    os.chdir("/data")
1
  • The error message is missing at the end. E.g. I get "OSError: [Errno 2] No such file or directory: '/data'" if there is no /data directory. Commented Nov 18, 2016 at 7:31

1 Answer 1

1

Check if you have permission to your /data directory. Also check if it isn't in your home directory.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, you are right, but now I get error: File "python.py", line 7 with open(file) as fd: ^ IndentationError: expected an indented block
That's an syntax error. You have not done the indentation right in your code
You've probably mixed tabs and spaces in your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.