scripts on os-module and platform-module of Python3
diff --git a/python3/os-module/Python-Logo.jpg b/python3/os-module/Python-Logo.jpg
new file mode 100644
index 0000000..5b02e36
--- /dev/null
+++ b/python3/os-module/Python-Logo.jpg
Binary files differ
diff --git a/python3/os-module/README b/python3/os-module/README
new file mode 100644
index 0000000..ea8c011
--- /dev/null
+++ b/python3/os-module/README
@@ -0,0 +1,3 @@
+OS module provides a way of using OS dependent functionality.
+
+
diff --git a/python3/os-module/dir1/sample1 b/python3/os-module/dir1/sample1
new file mode 100644
index 0000000..724ae58
--- /dev/null
+++ b/python3/os-module/dir1/sample1
@@ -0,0 +1 @@
+sample1
diff --git a/python3/os-module/dir1/sample2 b/python3/os-module/dir1/sample2
new file mode 100644
index 0000000..d45470c
--- /dev/null
+++ b/python3/os-module/dir1/sample2
@@ -0,0 +1 @@
+sample2
diff --git a/python3/os-module/dir1/sample3 b/python3/os-module/dir1/sample3
new file mode 100644
index 0000000..94b339b
--- /dev/null
+++ b/python3/os-module/dir1/sample3
@@ -0,0 +1 @@
+sample3
diff --git a/python3/os-module/f1.py b/python3/os-module/f1.py
new file mode 100755
index 0000000..fcf159a
--- /dev/null
+++ b/python3/os-module/f1.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python3
+
+#getch() waits for one character to be typed without a return
+
+#Bash command "read -n 1" waits for a key to be typed
+
+#os.system doesnot return result of called shell commands
+
+import os
+
+def getch():
+  os.system("bash -c \"read -n 1\"")
+
+getch()
diff --git a/python3/os-module/f10.py b/python3/os-module/f10.py
new file mode 100755
index 0000000..fa7621c
--- /dev/null
+++ b/python3/os-module/f10.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python3
+
+#working with os module to get information about a file
+
+import os, time
+
+file = "Python-Logo.jpg"
+
+def dump(st):
+  mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = st
+  print ("Size: ", size, "bytes")
+  print ("Owner: ", uid, gid)
+  print ("Created: ", time.ctime(ctime))
+  print ("Last accessed: ", time.ctime(atime))
+  print ("Last modified: ", time.ctime(mtime))
+  print ("mode: ", oct(mode))
+  print ("inode/dev: ", ino, dev)
+ 
+st = os.stat(file)
+
+print ("Stat: ", file)
+
+dump(st)
+
+print ()
+
+fp = open(file)
+
+st = os.fstat(fp.fileno())
+
+print ("fstat: ", file)
+dump(st) 
diff --git a/python3/os-module/f11.py b/python3/os-module/f11.py
new file mode 100755
index 0000000..c5de387
--- /dev/null
+++ b/python3/os-module/f11.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+
+#Use of os module to change a file's priviledges and timestamps
+
+import os, stat, time
+
+infile = "Python-Logo.jpg"
+outfile = "out.jpg"
+
+fi = open(infile, "rb")
+fo = open(outfile, "wb")
+
+while 1:
+  s = fi.read(10000)
+  if not s:
+    break
+  fo.write(s)
+
+fi.close()
+fo.close()
+
+st = os.stat(infile)
+os.chmod(outfile, stat.S_IMODE(st[stat.ST_MODE]))
+os.utime(outfile, (st[stat.ST_ATIME], st[stat.ST_MTIME]))
+
+print ("original", "=>")
+print ("Mode: ", oct(stat.S_IMODE(st[stat.ST_MODE])))
+print ("atime: ", time.ctime(st[stat.ST_ATIME]))
+print ("mtime: ", time.ctime(st[stat.ST_MTIME]))
+
+print ("copy", "=>")
+st = os.stat(outfile)
+print ("Mode: ", oct(stat.S_IMODE(st[stat.ST_MODE])))
+print ("atime: ", time.ctime(st[stat.ST_ATIME]))
+print ("mtime: ", time.ctime(st[stat.ST_MTIME]))
diff --git a/python3/os-module/f12.py b/python3/os-module/f12.py
new file mode 100755
index 0000000..0cac026
--- /dev/null
+++ b/python3/os-module/f12.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python3
+
+#This script uses the os module to run an OS command
+
+#os.system() runs a new command under current process and waits for it to finish
+
+import os
+
+if os.name == "nt":
+  command = "dir"
+else:
+  command = "ls -l"
+
+os.system(command)
diff --git a/python3/os-module/f13.py b/python3/os-module/f13.py
new file mode 100755
index 0000000..b718c45
--- /dev/null
+++ b/python3/os-module/f13.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python3
+
+#This script uses os module to start a new process
+
+#exec function starts a new process, replacing teh current one 
+#execvp searches for the program along standard path, passes arguments and runs it under current environment
+
+
+import os, sys
+
+program = "python"
+arguments = ["f11.py"]
+
+print (os.execvp(program, (program,) + tuple(arguments)))
+print ("Goodbye") #This is never printed
+
+
diff --git a/python3/os-module/f14.py b/python3/os-module/f14.py
new file mode 100755
index 0000000..058ab68
--- /dev/null
+++ b/python3/os-module/f14.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python3
+
+#Using os module to run another program 
+
+#Fork: makes a copy of current process
+#wait: waits for child process to finish
+
+import os, sys
+
+def run(program, *args):
+  pid = os.fork()
+  if not pid: #we are in the new process
+    os.execvp(program, (program,) + args)
+  return os.wait()[0]
+
+run("python", "f11.py")
+print ("goodbye")
diff --git a/python3/os-module/f15.py b/python3/os-module/f15.py
new file mode 100755
index 0000000..66cd91d
--- /dev/null
+++ b/python3/os-module/f15.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python3
+
+#This script is basically to show usage of spawn or fork/exec to run another program. A cross platform script to run on Windows and Unix both
+
+import os, string
+
+if os.name in ("nt", "dos"):
+  exefile = ".exe"
+else:
+  exefile = ""
+
+def spawn(program, *args):
+  try:
+    return os.spawnvp(program, (program,) + args)
+  except AttributeError:
+    pass
+  try:
+    spawnv = os.spawnv
+  except AttributeError:
+    pid = os.fork()
+    if not pid:
+      os.execvp(program, (program,) + args)
+    return os.wait()[0]
+  else:
+      for path in string.split(os.environ["PATH"], os.pathsep):
+        file = os.path.join(path, program) + exefile
+        try:
+          return spawnv(os.P_WAIT, file, (file,) + args)
+        except os.error:
+          pass
+  raise IOError("cannot find executable")
+
+spawn("python", "f11.py")
+print ("goodbye")
+
+
+
diff --git a/python3/os-module/f16.py b/python3/os-module/f16.py
new file mode 100755
index 0000000..bfea1ce
--- /dev/null
+++ b/python3/os-module/f16.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python3
+
+#Using os module to run as daemon
+
+import os, time
+
+pid = os.fork()
+if pid:
+  os._exit(0) #kill original
+
+print ("daemon started")
+time.sleep(10)
+print ("daemon terminated")
diff --git a/python3/os-module/f17.py b/python3/os-module/f17.py
new file mode 100755
index 0000000..2420e52
--- /dev/null
+++ b/python3/os-module/f17.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+#Using os module to exit current process
+
+#os._exit() function terminates current process. Unlinke sys.exit(), it works even if caller happens to catch SystemExit exeception.
+
+import os, sys
+
+try:
+  sys.exit(1)
+except SystemExit as value:
+  print ("Caught exit(%s)" % (value))
+
+try:
+  os._exit(2)
+except SystemExit as value:
+  print ("Caught exit(%s)" % (value))
+
+print ("Bye!")
diff --git a/python3/os-module/f18 b/python3/os-module/f18
new file mode 100644
index 0000000..ec81fed
--- /dev/null
+++ b/python3/os-module/f18
@@ -0,0 +1,37 @@
+>>> import os
+
+Returns group id of current process
+>>> os.getgid()
+1000
+
+Returns user id of current process
+>>> os.getuid()
+1000
+
+Returns process id of current process
+>>> os.getpid()
+2464
+
+Returns information identifying current operating system
+>>> os.uname()
+posix.uname_result(sysname='Linux', nodename='localhost.localdomain', release='4.0.4-301.fc22.x86_64', version='#1 SMP Thu May 21 13:10:33 UTC 2015', machine='x86_64')
+
+-------------------------------------------------------------------------------------------------------------------
+os.rename renames the file/ directory from "source" to "destination"
+
+[dshikhar@localhost os-module]$ ls
+dir1    f11.py  f13.py  f15.py  f17.py  f2.py  f4.py  f6.py  f8.py  out.jpg          README  sample.tmp
+f10.py  f12.py  f14.py  f16.py  f1.py   f3     f5.py  f7.py  f9.py  Python-Logo.jpg  sample
+
+[dshikhar@localhost os-module]$ python3
+Python 3.4.2 (default, Jan 12 2015, 12:13:20) 
+[GCC 4.9.2 20150107 (Red Hat 4.9.2-5)] on linux
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import os
+>>> os.rename("dir1", "dir2")
+>>> quit()
+
+[dshikhar@localhost os-module]$ ls
+dir2    f11.py  f13.py  f15.py  f17.py  f2.py  f4.py  f6.py  f8.py  out.jpg          README  sample.tmp
+f10.py  f12.py  f14.py  f16.py  f1.py   f3     f5.py  f7.py  f9.py  Python-Logo.jpg  sample
+
diff --git a/python3/os-module/f2.py b/python3/os-module/f2.py
new file mode 100755
index 0000000..f3fd18d
--- /dev/null
+++ b/python3/os-module/f2.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+#f1.py works well only on Linux. This is a platform independent script
+
+import os, platform
+
+if platform.system() == "Windows":
+  import msvcrt
+
+def getch():
+  if platform.system() == "Linux":
+    os.system("bash -c \"read -n 1\"")
+  else:
+    msvcrt.getch()
+
+print("\nType a key")
+getch()
+print("\nOkay")
+  
diff --git a/python3/os-module/f3 b/python3/os-module/f3
new file mode 100644
index 0000000..0468d49
--- /dev/null
+++ b/python3/os-module/f3
@@ -0,0 +1,10 @@
+This script shows how we can execute shell scripts and return output of these scripts using os.popen()
+
+os.popen() opens a pipe to or from command
+
+>>> import os
+>>> dir = os.popen("ls").readlines()
+>>> print (dir)
+['f1.py\n', 'f2.py\n', 'README\n']
+>>> 
+
diff --git a/python3/os-module/f4.py b/python3/os-module/f4.py
new file mode 100755
index 0000000..147e6fc
--- /dev/null
+++ b/python3/os-module/f4.py
@@ -0,0 +1,16 @@
+#!/usr/bin/python3
+
+import os
+
+command = " "
+
+while (command != "exit"):
+  command = input("Command: ")
+  handle = os.popen(command)
+  line = " "
+  while line:
+    line = handle.read()
+    print (line)
+  handle.close()
+
+print("\nBye. This is it")
diff --git a/python3/os-module/f5.py b/python3/os-module/f5.py
new file mode 100755
index 0000000..957adfc
--- /dev/null
+++ b/python3/os-module/f5.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python3
+
+#Using os module to rename and remove files
+
+import os, string
+
+def replace(file, search_for, replace_with):
+  back = os.path.splitext(file)[0] + ".bak"
+  temp = os.path.splitext(file)[0] + ".tmp"
+
+  try:
+    os.remove(temp)
+  except os.error:
+    pass
+
+  fi = open(file)
+  fo = open(temp, "w")
+
+  for s in fi.readlines():
+    fo.write(string.replace(s, serach_for, replace_with))
+  
+  fi.close()
+  fo.close()
+
+  try:
+    os.remove(back)
+  except os.error:
+    pass
+
+  os.rename(file, back)
+
+  os.rename(temp, file)
+
+file = "sample"
+
+replace(file, "hello", "tjena")
+replace(file, "tjena", "hello") 
diff --git a/python3/os-module/f6.py b/python3/os-module/f6.py
new file mode 100755
index 0000000..6493453
--- /dev/null
+++ b/python3/os-module/f6.py
@@ -0,0 +1,8 @@
+#!/usr/bin/python3
+
+#Using os module to list files in a directory
+
+import os
+
+for file in os.listdir("dir1"):
+  print (file)
diff --git a/python3/os-module/f7.py b/python3/os-module/f7.py
new file mode 100755
index 0000000..6e998c9
--- /dev/null
+++ b/python3/os-module/f7.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python3
+
+#using os module to change working directory
+
+#os.cwd() returns the path of current working directory.
+
+import os
+
+cwd = os.getcwd()
+print("Current Working Directory:\n %s" %(cwd))
+
+os.chdir("dir1")
+print("\nWe go to chile directory using os.chdir().\nNow Current Working Directory:\n %s" %(os.getcwd()))
+
+os.chdir(os.pardir)
+print("\nWe go to parent directory using os.pardir().\nNow Current Working Directory:\n %s" %(os.getcwd()))
+
+
diff --git a/python3/os-module/f8.py b/python3/os-module/f8.py
new file mode 100755
index 0000000..05387e2
--- /dev/null
+++ b/python3/os-module/f8.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python3
+
+import os
+
+#os.makedirs is used to create multiple directory levels
+os.makedirs("test/multiple/levels")
+
+fp = open("test/multiple/levels/file", "w")
+fp.write("hello")
+fp.close()
+
+#os.remove is used to remove a certain file
+os.remove("test/multiple/levels/file")
+
+#os.removedirs is used to remove all empty directories along the given path
+os.removedirs("test/multiple/levels")
+
diff --git a/python3/os-module/f9.py b/python3/os-module/f9.py
new file mode 100755
index 0000000..a2d8ed9
--- /dev/null
+++ b/python3/os-module/f9.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python3
+
+#os.mkdir and os.rmdir can handle only single directory levels
+
+import os
+
+os.mkdir("test")
+os.rmdir("test")
+
+#This will fail
+#os.rmdir("hello")
+
diff --git a/python3/os-module/out.jpg b/python3/os-module/out.jpg
new file mode 100644
index 0000000..5b02e36
--- /dev/null
+++ b/python3/os-module/out.jpg
Binary files differ
diff --git a/python3/os-module/sample b/python3/os-module/sample
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/python3/os-module/sample
@@ -0,0 +1 @@
+hello
diff --git a/python3/os-module/sample.tmp b/python3/os-module/sample.tmp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python3/os-module/sample.tmp
diff --git a/python3/platform-module/README b/python3/platform-module/README
new file mode 100644
index 0000000..caa44ec
--- /dev/null
+++ b/python3/platform-module/README
@@ -0,0 +1,4 @@
+Platform module is used to access underlying platform's data like:
+1. hardware
+2. OS
+3. interpreter version
diff --git a/python3/platform-module/f1 b/python3/platform-module/f1
new file mode 100644
index 0000000..2bbe407
--- /dev/null
+++ b/python3/platform-module/f1
@@ -0,0 +1,57 @@
+>>>import platform
+
+To return the version of python interpreter as major.minor.patch-level:
+>>> platform.python_version()
+3.4.2
+
+To return bit architecture:
+>>> platform.architecture()
+('64bit', 'ELF')
+
+To return machine type:
+>>> platform.machine()
+x86_64
+
+To return computer's network name:
+>>> platform.node()
+localhost.localdomain
+
+To return a single string with underlying useful platform information:
+>>> platform.platform()
+'Linux-4.0.4-301.fc22.x86_64-x86_64-with-fedora-22-Twenty_Two
+
+To return processor name:
+>>> platform.processor()
+'x86_64'
+
+Returns a tuple stating Python build number and date as strings:
+>>> platform.python_build()
+('default', 'Jan 12 2015 12:13:20')
+
+Returns string identifying compiler used fir compiling:
+>>> platform.python_compiler()
+'GCC 4.9.2 20150107 (Red Hat 4.9.2-5)'
+
+Returns a string identifying Python implementation:
+>>> platform.python_implementation()
+'CPython'
+
+Returns system release:
+>>> platform.release()
+'4.0.4-301.fc22.x86_64'
+
+Returns the OS name:
+>>> platform.system()
+'Linux'
+
+Returns OS release:
+>>> platform.version()
+'#1 SMP Thu May 21 13:10:33 UTC 2015'
+
+Returns a tuple of strings identifying underlying platform:
+>>> platform.uname()
+uname_result(system='Linux', node='localhost.localdomain', release='4.0.4-301.fc22.x86_64', version='#1 SMP Thu May 21 13:10:33 UTC 2015', machine='x86_64', processor='x86_64')
+
+
+
+