StructuredText & LocalFS in Python Script
Dear List, having the following objects: sourceFolder points to a LocalFS-Instance, fileId points to a file in the LocalFS-Instance, and convert_nonascii_1(string) is just a method to exchange some text in string. in DTML I can do the following: <dtml-var "convert_nonascii_1(_.str(_.getitem(sourceFolder, 1)[fileId]))" fmt=structured-text> But how is it done in Python Script? if myLFSname is the name of the LocalFS-Instance and file.txt the name of a file in the LocalFS-Instance this works fine: context.myLFSname['file.txt']() But as soon as I try to do it with sourceFolder and fileId, I get only errors even if the Script can resolve both. Does anybody know why? And how do I use structured Text in Python Script as in DTML: <dtml-var my Var fmt=structured-text> Thanks a lot for your help, Elena
it seems sourceFolder holds the id of your LFS instance, ie. its a string, right? you get the LFS instance with getattr(), for example: myLFS = getattr(context, sourceFolder) return myLFS[fileId]() # or whatever it is you want to do with the LFS i'd stick with DTML to output structured text -- just pass the return value of the pyscript above to DTML, sth like: <dtml-var pyScript fmt=structured-text> hth peter. Elena Schulz wrote:
Dear List,
having the following objects:
sourceFolder points to a LocalFS-Instance, fileId points to a file in the LocalFS-Instance, and convert_nonascii_1(string) is just a method to exchange some text in string.
in DTML I can do the following:
<dtml-var "convert_nonascii_1(_.str(_.getitem(sourceFolder, 1)[fileId]))" fmt=structured-text>
But how is it done in Python Script?
if myLFSname is the name of the LocalFS-Instance and file.txt the name of a file in the LocalFS-Instance this works fine:
context.myLFSname['file.txt']()
But as soon as I try to do it with sourceFolder and fileId, I get only errors even if the Script can resolve both. Does anybody know why? And how do I use structured Text in Python Script as in DTML: <dtml-var my Var fmt=structured-text>
Thanks a lot for your help,
Elena
_______________________________________________ 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 )
On Fri, Aug 02, 2002 at 09:49:21AM +0200, Elena Schulz wrote:
Dear List,
having the following objects:
sourceFolder points to a LocalFS-Instance, fileId points to a file in the LocalFS-Instance, and convert_nonascii_1(string) is just a method to exchange some text in string.
in DTML I can do the following:
<dtml-var "convert_nonascii_1(_.str(_.getitem(sourceFolder, 1)[fileId]))" fmt=structured-text>
But how is it done in Python Script?
if myLFSname is the name of the LocalFS-Instance and file.txt the name of a file in the LocalFS-Instance this works fine:
context.myLFSname['file.txt']()
But as soon as I try to do it with sourceFolder and fileId, I get only errors even if the Script can resolve both. Does anybody know why?
Sorry, my head hurts thinking about this!
And how do I use structured Text in Python Script as in DTML: <dtml-var my Var fmt=structured-text>
Thanks a lot for your help,
Elena
I define a pythonscript stx_ps with parameter text and body from Products.PythonScripts.standard import structured_text if not text: return '' return structured_text(text) The only reason for the extra method is the guard. stx gets upset if passed an empty string. Jim Penny
_______________________________________________ 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 )
participants (3)
-
Elena Schulz -
Jim Penny -
peter sabaini