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

S

Steven W. Orr

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top