batch pretty (color) print of python code?

J

John Hunter

Humpdydum> Any freeware/open-source that does that? Windows- OR
Humpdydum> Linux-based is fine. On Linux it would be s/t like
Humpdydum> "pyprint -r *.py > out.ps" where -r indicates
Humpdydum> recursive. Done a search on google and nothing solid
Humpdydum> comes up. So far I've been using Boa's print feature,
Humpdydum> which means one file at a time, tedious. Thanks,
Humpdydum> Oliver


I've been very happy with the latex listings package, which supports
python.

http://www.atscire.de/index.php?nav=products/listings

JDH
 
H

Humpdydum

Any freeware/open-source that does that? Windows- OR Linux-based is fine. On
Linux it would be s/t like "pyprint -r *.py > out.ps" where -r indicates
recursive. Done a search on google and nothing solid comes up. So far I've
been using Boa's print feature, which means one file at a time, tedious.
Thanks,
Oliver
 
J

Josh Close

Any freeware/open-source that does that? Windows- OR Linux-based is fine. On
Linux it would be s/t like "pyprint -r *.py > out.ps" where -r indicates
recursive. Done a search on google and nothing solid comes up. So far I've
been using Boa's print feature, which means one file at a time, tedious.
Thanks,
Oliver

Do you want the text to be colored on the command line? Not exactly
sure what you mean. If so, gentoo has a very nice module for that,
that comes with portage. It's located here

/usr/lib/portage/pym/output.py

All it does is uses \ values for color.

-Josh
 
P

Paul McNett

Humpdydum said:
Any freeware/open-source that does that? Windows- OR
Linux-based is fine. On Linux it would be s/t like "pyprint
-r *.py > out.ps" where -r indicates recursive. Done a search
on google and nothing solid comes up. So far I've been using
Boa's print feature, which means one file at a time, tedious.

I believe you are looking for py2pdf.py, the most recent version
that I can find being included in ReportLab, in the tools
directory.

It is very configurable, and the defaults are nice. It doesn't
offer recursion or output redirection like you want, but you
could probably take the code and run with it. What it will do
out of the box is to convert your specified files to individual
pdf files. For example:

python py2pdf.py *.py

results in a .pdf file for every .py file in the directory.

http://www.reportlab.org/downloads.html
 
F

Fernando Perez

Humpdydum said:
Any freeware/open-source that does that? Windows- OR Linux-based is fine. On
Linux it would be s/t like "pyprint -r *.py > out.ps" where -r indicates
recursive. Done a search on google and nothing solid comes up. So far I've
been using Boa's print feature, which means one file at a time, tedious.
Thanks,
Oliver

You said linux was OK. A simple enscript alias works wonders:

planck[python]> which codeprint
codeprint: ein Alias fur enscript -G2rjE --color !*
planck[python]> which codeps
codeps: ein Alias fur enscript -G2rjE --color -o !*.ps !*; gv !*.ps

That's what I use for all kinds of source, it does a pretty decent job with
python (and knows about C, C++, perl,...)

Cheers,

f
 
P

Paul McNett

Fernando said:
You said linux was OK. A simple enscript alias works
wonders:

planck[python]> which codeprint
codeprint: ein Alias fur enscript -G2rjE --color !*
planck[python]> which codeps
codeps: ein Alias fur enscript -G2rjE --color -o
!*.ps !*; gv !*.ps

That's what I use for all kinds of source, it does a pretty
decent job with python (and knows about C, C++, perl,...)

That's great! Thanks for turning me on to that. Here is the
alias I'm now using:

alias codeps='enscript -G2rjE --color -o -'

This takes input on stdin and sends the output to stdout, so the
OP can type:

codeps *.py > output.ps

and that is pretty close to what the OP wanted (minus
recursion).
 

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,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top