471,325 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Question about how to use cog as a preprocessor :-(

I have the following module:

#! /usr/bin/python
COG_DEBUG=1
def wrapper( dd ):
if dd == 1:
def dfunc( *args ):
print "print ",
for ii in args:
print repr(ii)
print "compd dfunc"
return dfunc
else:
def nfunc( *args ):
pass
print "compd nfunc"
return nfunc
dbgprint = wrapper(COG_DEBUG)
print "dbgprint = ", repr(dbgprint)
dbgprint("called from def hunk")
print "hello1"

This does what I want, but when I use this code inside cog then the call
to dbgprint doesn't do anything.

Here's the input to cog:

#! /usr/bin/python
[[[cog
import cog
def wrapper( dd ):
if dd == 1:
def dfunc( *args ):
cog.out( "print " )
for ii in args:
cog.out( repr(ii) )
print
print "compd dfunc"
return dfunc
else:
def nfunc( *args ):
pass
print "compd nfunc"
return nfunc
dbgprint = wrapper(COG_DEBUG)
print "dbgprint = ", repr(dbgprint)
dbgprint("called from def hunk")
]]]
[[[end]]]

print "hello1"
[[[cog dbgprint( "Hello from dbg" )]]]
[[[end]]]
print "Doo dis"

and this is the cmdline: cog.py -D COG_DEBUG=1 -d -o d1out.py d1.py

And the output is just

#! /usr/bin/python
import sys
print "hello1"
print "Doo dis"

DOes anyone have any ideas? :-(

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
Jul 18 '07 #1
0 736

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by valued customer | last post: by
1 post views Thread by Dan W. | last post: by
205 posts views Thread by Jeremy Siek | last post: by
18 posts views Thread by Exits Funnel | last post: by
21 posts views Thread by Jon Slaughter | last post: by
4 posts views Thread by ethan | last post: by
6 posts views Thread by AzizMandar | last post: by
6 posts views Thread by ludovicd | last post: by
6 posts views Thread by news.inode.at | last post: by
5 posts views Thread by arjor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.