Testing for complete uploaded file
Michael George Lerner
mlerner at NOumichSPAM-PLEASE.edu
Wed May 28 16:29:11 EDT 2003
Carsten Gehling <carsten at gehling.dk> wrote:
<snip>
> I thought that the files might be write-protected during upload, and that I
> therefore could use:
> try: ftest = open(uploaded_filename, "w")
> except: return
> else: ftest.close()
other people have given you some suggestions, but it's worth noting that
open(filename, 'w') (or file(filename, 'w') in newer pythons) will truncate
an existing file, so it's probably not what you want.
see http://python.org/doc/current/lib/built-in-funcs.html#built-in-funcs for
more info.
[mlerner at localhost tmp]$ cat > foo
this file has some information in it.
[mlerner at localhost tmp]$ cat foo
this file has some information in it.
[mlerner at localhost pdbtmp]$ ls -al foo
-rw-r--r-- 1 mlerner mlerner 38 May 28 16:17 foo
[mlerner at localhost tmp]$ python
Python 2.3a2 (#1, Mar 10 2003, 16:10:49)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = open('foo','w')
>>>
[mlerner at localhost tmp]$ cat foo
[mlerner at localhost tmp]$ ls -al foo
-rw-r--r-- 1 mlerner mlerner 0 May 28 16:11 foo
[mlerner at localhost tmp]$
-michael
More information about the Python-list
mailing list