OS module
os — Miscellaneous operating system interfaces — Python 3.10.4 documentation
OS Module in Python with Examples - GeeksforGeeks
#!/usr/bin/env python
class Server(object):
def __init__(self,ip,hostname):
self.ip = ip
self.hostname = hostname
def set_ip(self,ip):
self.ip = ip
def set_hostname(self,hostname):
self.hostname = hostname
def ping(self,ip_addr):
print("Pinging %s from %s(%s)"%(ip_addr,self.ip,self.hostname))
if __name__ =="__main__":
server = Server('192.168.1.20','bumbly')
server.ping('192.168.1.15')
wes@wes:~/Documents/python/ch1$ cat shell-1
#!/bin/bash
for a in 1 2; do
for b in a b; do
echo "$a $b"
done
done
wes@wes:~/Documents/python/ch1$ sh shell-1
1 a
1 b
2 a
2 b
wes@wes:~/Documents/python/ch1$ cat python-1
#!/usr/bin/env python
for a in [1, 2]:
for b in ['a','b']:
print a,b
wes@wes:~/Documents/python/ch1$ python python-1
1 a
1 b
2 a
2 b
wes@wes:~/Documents/python/ch1$ cat shell-2
#!/bin/bash
if [ -d "/tmp" ]; then
echo "/tmp is a directory"
else
echo "/tmp is not a directory"
fi
wes@wes:~/Documents/python/ch1$ sh shell-2
/tmp is a directory
wes@wes:~/Documents/python/ch1$ cat python-2
#!/usr/bin/env python
import os
if os.path.isdir("/tmp"):
print("/tmp is a directory\n")
else:
print("/tmp is not a directory\n")
wes@wes:~/Documents/python/ch1$ python python-2
/tmp is a directory