
January 26th, 2004, 06:45 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Could have somthing to do with the filename you passing to your files. instead of using the variable 'filename' your passing in a string "filename"
Quote:
C:\Documents and Settings\Mark>cd desktop
C:\Documents and Settings\Mark\Desktop>checkfile.py new.txt
Can read from <open file 'new.txt', mode 'r' at 0x008F6F60>
Can write to <open file 'new.txt', mode 'w' at 0x008F6F60> |
Code:
#!/usr/bin/env python
def check(path):
"""
Check a path to see if the file is readable/writable or not.
"""
try:
print 'Can read from', file(path, 'r')
except IOError:
print 'Cannot read from', path
try:
print 'Can write to', file(path, 'w')
except IOError:
print 'Cannot write to', path
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print 'Usage: ./filecheck <path/filename>'
else:
check(sys.argv[1])
changed things around and it worked fine.. oh  you really dont need a class there; people seems to use classes where a function would be fine, so not just you.
Mark.
__________________
programming language development: www.netytan.com – Hula
|