1

I am trying to execute a python file located in some folder named : folder1

for this I am using :

~$ python /folder1/a.py (doesn't work)

When i go to that folder and then execute everything works fine:

~/folder1$ python a.py (works)

I think I am using a file write operation in code written in file a.py because of which first way of execution is not working. Please give some suggestions to fix this.

1
  • can you please share the error message you get? Commented Jan 8, 2014 at 14:39

2 Answers 2

2

The path on the first try: /folder1/a.py starts searching from root directory (/), that's why it doesn't find the script. It would be correctly done like this:

~$ python folder1/a.py

Notice how I removed the beginning / character. Take a look at man path_resolution(7) to see how UNIX/Linux OS look up commands and files.

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

2 Comments

Hi Paulo, thanks for quick response.. but this is not the problem i am facing. actually the problem is if i work with a file which doesn't have file write operation in there it works from any directory. but when I use file write operation it works only from the directory where the python code file is kept.
@RajanRai That's kind of weird, can you add more information to the question? Like the error messages, file permissions and the exact execution command?
0

The File was always going to home folder.. I grabbed the absolute path and it worked perfectly for me..

and thanks to Paulo's hint about permissions of file.

Comments

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.