How to read a file object
How do I go about reading a Zope file object in Python? I'd appreciate it if anyone could point me to a repository of small code snippets which illustrate some simple techniques usable in Python scripts running under Zope. -- John
--On 1. Juni 2005 10:01:22 +0100 John Poltorak <jp@warpix.org> wrote:
How do I go about reading a Zope file object in Python?
Define what "reading a Zope File object" means? You mean you want the body of an upload file? -aj
On Wed, Jun 01, 2005 at 12:46:44PM +0200, Andreas Jung wrote:
--On 1. Juni 2005 10:01:22 +0100 John Poltorak <jp@warpix.org> wrote:
How do I go about reading a Zope file object in Python?
Define what "reading a Zope File object" means? You mean you want the body of an upload file?
-aj
I mean the thing that is created when I click on 'File' from the drop down menu of ZMI. I'm trying to learn some Python basics and hoping to use Zope as front end for writing and running a few snippets of code which may help me get a better understanding of how Zope and Python interact. -- John
--On 1. Juni 2005 12:03:39 +0100 John Poltorak <jp@warpix.org> wrote:
On Wed, Jun 01, 2005 at 12:46:44PM +0200, Andreas Jung wrote:
--On 1. Juni 2005 10:01:22 +0100 John Poltorak <jp@warpix.org> wrote:
How do I go about reading a Zope file object in Python?
Define what "reading a Zope File object" means? You mean you want the body of an upload file?
-aj
I mean the thing that is created when I click on 'File' from the drop down menu of ZMI.
When you upload a file through HTTP upload then you can access the body as context.REQUEST['yourfile'].read(). Means the uploaded file is temporarily stored as file like object...I am pretty sure this is explained in the Zope Book *wink*. -aj
John Poltorak wrote:
On Wed, Jun 01, 2005 at 12:46:44PM +0200, Andreas Jung wrote:
--On 1. Juni 2005 10:01:22 +0100 John Poltorak <jp@warpix.org> wrote:
How do I go about reading a Zope file object in Python?
Define what "reading a Zope File object" means? You mean you want the body of an upload file?
-aj
I mean the thing that is created when I click on 'File' from the drop down menu of ZMI.
Suppose your file 'myFile' and your script 'myScript' in the same folder. You can get file data in your script using 'data' property: fileData = container.myFile.data ...
--On 1. Juni 2005 15:02:16 +0300 Vital Lobachevsky <tick@web.vi> wrote:
Suppose your file 'myFile' and your script 'myScript' in the same folder. You can get file data in your script using 'data' property:
fileData = container.myFile.data
You should *not* do that. You are using an implementation detail that is unlikely thought to be used for public use. You should use str(container.myFile) instead. -aj
Am Mittwoch, den 01.06.2005, 15:02 +0300 schrieb Vital Lobachevsky:
John Poltorak wrote:
On Wed, Jun 01, 2005 at 12:46:44PM +0200, Andreas Jung wrote:
--On 1. Juni 2005 10:01:22 +0100 John Poltorak <jp@warpix.org> wrote:
How do I go about reading a Zope file object in Python?
Define what "reading a Zope File object" means? You mean you want the body of an upload file?
-aj
I mean the thing that is created when I click on 'File' from the drop down menu of ZMI.
Suppose your file 'myFile' and your script 'myScript' in the same folder. You can get file data in your script using 'data' property:
fileData = container.myFile.data ...
beside the fact its a not really public attribute, it isnt even garantied to be s simple string. Most of the time its a Pdata object chain. And yes, file/image really lack file semantics. -- Tino Wildenhain <tino@wildenhain.de>
John Poltorak wrote:
I'm trying to learn some Python basics and hoping to use Zope as front end for writing and running a few snippets of code which may help me get a better understanding of how Zope and Python interact.
As one who picked up Python and Zope/Plone together I'd HIGHLY, HIGHLY recommend that you avoid the extra complication of Zope when learning Python. Once you're past that, make sure you install the ExternalEditor product for editing. Use a simple text editor and run python on the command line (or look for a GUI/context sensitive editor if you're into that sort of thing). You'll save yourself a lot of headaches vs. starting inside Zope. Python tutorials abound on the web, but I've not looked at them enough to recommend any particular one. Cheers, Nikko
On 6/1/05, John Poltorak <jp@warpix.org> wrote:
I'm trying to learn some Python basics and hoping to use Zope as front end for writing and running a few snippets of code
In that case you should use Zope3. Zope2 is highly-unpythonic, and using it pretty much requires you to learn Zope first, and Python later. Zope2 should be used if you want to build a site with a content management tool like CPS or Plone or Silva, or if you otherwise have some software you wnat to use that runs on Zope2. But if you want to learn python, or create stuff from scratch, Zope3 is generally a much better option.
which may help me get a better understanding of how Zope and Python interact.
When it comes to Zope2: Trust me, you don't want to know. :) -- Lennart Regebro, Nuxeo http://www.nuxeo.com/ CPS Content Management http://www.cps-project.org/
On Wed, Jun 01, 2005 at 10:01:22AM +0100, John Poltorak wrote:
I'd appreciate it if anyone could point me to a repository of small code snippets which illustrate some simple techniques usable in Python scripts running under Zope.
http://zopelabs.com/ Note there is a "Python(Script)" category with over 100 recipes: http://zopelabs.com/cookbook/byCategory?category=Python%28Script%29 -- Paul Winkler http://www.slinkp.com
participants (7)
-
Andreas Jung -
John Poltorak -
Lennart Regebro -
Nikko Wolf -
Paul Winkler -
Tino Wildenhain -
Vital Lobachevsky