[Zope] Copy file in filesystem

Tino Wildenhain tino@wildenhain.de
Thu, 26 Jul 2001 22:42:20 +0200


Hi Gitte,

unfortunately this is as wrong as it can be ;)
Hint: you can get a bit familar with python, if you
just run the interpreter binary and type some
code interactively.

"import copy" puts the _module_ named "copy" in the namespace.
This module happens to define a function called copy.
So if you want to use that function, you have either
type copy.copy() or use another flavour of the import statement:

from copy import copy

While this would solve your first error, you will probably
get a new then, since this copy function is not for copying
files in the filesystem. Its for copying python objects.
(So you can copy the fileobject (but this is only a handle to
the file on disk))

I'm afraid there is no copy for the filesystem. You can do it
by opening one file for reading and another for writing.
While its ok for small files to read all into memory, this
can make problems, if the files are very large.

So you might copy in smaller chunks:

source=open(sourcefile) # if you are on windows and want to copy binary
                        # files, you must use open(sourcefile,'rb')

dest=open(destfile,'w') # or 'wb' for binary

chunk=1 # dummy value for while

while chunk:
    chunk=source.read(65536) # 64 KB in one chunk, you can tune this value
    dest.write(chunk)

dest.close()
source.close()

HTH
Tino Wildenhain
while chunk

--On Donnerstag, 26. Juli 2001 16:22 +0200 Gitte Wange 
<gitte@mmmanager.org> wrote:

> Hello out there ..
>
> I know this is a python question (please forgive me) but I couldn't find
> an  answer in the python docs.
>
> The problem is very simple - I need to make a copy of a file in the
> filesystem in a pythhon module.
>
> I have tried with this:
> import copy
>
> <a lot of code>
> copy(file_reposit, new_fnreposit)
> </a lot of code>
>
> I get this error:
>
> Zope Error
>
> Zope has encountered an error while publishing this resource.
>
> Error Type: TypeError
> Error Value: call of non-function (type module)
>
> If I don't use the import copy Zope just returns an error saying that
> copy  isn't defined.
>
> How do I then make a copy of a file ???
>
> Regards,
>
> --
> Gitte Wange Jensen
>
> Sys Admin, Developer and a lot more
> MMmanager.org Aps, Denmark
>
> Phone: +45 29 72 79 72
> Email: gitte@mmmanager.org
> Web: www.mmmanager.org
>
> Quote of the day:
> In the beginning, there was Fortran.
>
> 	- James Gray
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )