$ cat a.py
'/t.py'
$ cat /t.py
print 'hello world';
What I did is here :
$ chmod +x a.py # made a.py executable
$ ./a.py # and run it
This caused my PC to freeze. What have I done wrong?
$ cat a.py
'/t.py'
$ cat /t.py
print 'hello world';
What I did is here :
$ chmod +x a.py # made a.py executable
$ ./a.py # and run it
This caused my PC to freeze. What have I done wrong?
A couple of observations:
#!/usr/bin/env python
at the top of each script, your code will not be interpreted as python unless you do something like python a.py
. If this was intended, you should change the name to something more useful, like a.sh
for a shell script.a.py
was interpreted as python, it would do nothing. The string literal '/t.py'
by itself doesn't do anything useful. If you want to run the file /t.py
, then you have a couple of options, which are discussed in some depth here. One of the simplest would be to use execfile
.Changing a.py
to the following should do what you want:
#!/usr/bin/env python
execfile('/t.py')
As an aside, you really shouldn't be logged into your box as the root user and it's generally not considered good housekeeping to put files at the root of your filesystem.
I'm really not sure why what you were doing originally was causing your computer to hang.