This code not working, need suggetions

Anirudh Srinivasan anirudh at nutanix.com
Mon Apr 23 02:16:33 EDT 2012


My code lists the files and directory under a folder and if we want to read
the file it uses the function  cat.

But the function cat(get_file) is not working , any suggetions?

Here is my code:


#!/usr/bin/python

import os
import sys
import commands
#import cat

def listdir(s):
   try:
 file  = os.listdir(s)
for files in file:
path = os.path.join(s, files)
 print path
#cmd = 'ls -l '+ path
#g= commands.getstatusoutput(cmd)
 #print g[1]
   except OSError:
print "No such file or directory"


def main():
listdir(sys.argv[1])


if __name__ == "__main__":
 main()

def cat(get_file):
f = open(get_file, "rU")
 text = f.read()
print text,
get_file = raw_input("Which file would you like to browse ?")

-- 
Anirudh Srinivasan | MTS QA | Nutanix.Inc | 408-569-0323
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120422/bb908121/attachment.html>


More information about the Python-list mailing list