SebastienPattyn
SebastienPattyn

Reputation: 403

python executable keeps crashing

I have a small python script that prints my total memory on my computer:

# !/usr/bin/env python3
import psutil

if __name__ == '__main__':
    print('test')
    mem = psutil.virtual_memory()
    result = mem.total
    print(result)

When I execute it by using:

sebastien@sebastien-PC:~/Documents$ python3 python-tests/metrictest.py 

I get the right output. Now I changed it to an executable file and it keeps crashing.

sebastien@sebastien-PC:~/Documents$ ls -al python-tests/metrictest.py 
-rwxr-xr-x 1 sebastien sebastien 161 Jun  9 12:27 python-tests/metrictest.py

It is doing nothing untill I start clicking elsewhere and my cursor becomes a double cross and then I get the following error.

sebastien@sebastien-PC:~/Documents$ python-tests/metrictest.py 
python-tests/metrictest.py: line 6: syntax error near unexpected token `'test''
python-tests/metrictest.py: line 6: `    print('test')'

How can I fix this that I just get the result that I need?

Upvotes: 0

Views: 162

Answers (1)

Błotosmętek
Błotosmętek

Reputation: 12927

Remove the space between # and ! in your first line.

Upvotes: 2

Related Questions