Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

terminal exercises

Views: 2497
1
To run a python script there are two approaches.
2
3
Suppose the script is called script.py.
4
5
You can always do this from the terminal:
6
7
$ python3 script.py
8
9
10
Alternatively, you can make the script executable.
11
12
This requires that the first line of the script give the path to python3:
13
14
#! /usr/bin/python3
15
16
If you don't know where python3 is you can find it like this:
17
18
$ which python3
19
20
Now we need to tell the OS that script.py is an executable file type.
21
22
To make a python script script.py executable:
23
24
$ chmod +x script.py
25
26
Now you can run the script like this:
27
28
$ ./script.py
29
30
31
32