473,381 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 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 776

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: valued customer | last post by:
Is there a way in python to indicate that you want your "base level of indentation" to be four spaces instead of zero? As far as I know now, the only way is by introducing some sort of language...
1
by: Dan W. | last post by:
I've been acting as messenger the past few days between the BOOST and Digital Mars peoples, and they can't seem to come to an agreement about the semantics of using ## vs. juxtaposition. The...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
18
by: Exits Funnel | last post by:
Hello, I'm a little confused about where I should include header files and was wondering whether there was some convention. Imagine I've written a class foo and put the definition in foo.h and...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
4
by: ethan | last post by:
Hi All, I'd like ask some question about macro. If I define a variable set, such as {5, 2, 10} or {1,3}. #define X {5,2,10} 1) Is it possible to write a macro to get the number of items...
6
by: AzizMandar | last post by:
There is probably a better way to do this and if so I'm just as happy to see that way. I have a program where I have factories that each create various objects abstracted from a base class. ...
6
by: ludovicd | last post by:
Hi to all, There is my question, Let's say I got a fonction which takes a numeric argument long enough so that there has to be spaces in it to represent it correctly. (Ex. 0xf63a002c5ff0338ec...
6
by: news.inode.at | last post by:
Sorry for this stupid question, but i am lost. If i write an stringlib with += overload operators (no i do not, but my thing is much more complicated) , and i have to precalculate the strlen() --...
5
by: arjor | last post by:
hey guys i was wondering what's the difference between the following commands: #ifndef #if !defined looks to be the same or is it ?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.