Re: [Tutor] Loop Issue

2014-03-14 Thread spir

On 03/13/2014 04:42 PM, Dave Angel wrote:

  spir  Wrote in message:

On 03/13/2014 12:40 AM, Danny Yoo wrote:

The context is the beginning of the thread:

  https://mail.python.org/pipermail/tutor/2014-March/100543.html

with the loop:


###
while health != 0:
  ...
###


The point, and reason why this loop was (potentially) infinite, is that the
condition was false. Should be <0 instead ('cause health points are not removed
one by one, so that a health value of 0 exactly can be jumped over).



Well unless I misremember,  the value of health goes down.  So
  you'd want

 while health > 0


oops!
and "the condition was false" --> "wrong"

d

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Printing from python

2014-03-14 Thread Ulrich Goebel

Hallo,

is there another way to pritt a PDF form python?

My problem is a PDF which is printed well by evince, but not with lp, 
even not out of python using


os.system("lp some_options file.pdf")

Later on I have to build the PDF in a python program (using reportlab) 
and then print it, even from the python program.


So I look for a (nice documented) library which give access to the CUPS 
API or something else to print the PDF from python.


Any help is welcome!

Ulrich


--
Ulrich Goebel
Paracelsusstr. 120, 53177 Bonn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing from python

2014-03-14 Thread Ulrich Goebel
I just found a hint, the Qt QPrinter Class. I use Qt, so that could be a 
solution?



Am 14.03.2014 11:40, schrieb Ulrich Goebel:

Hallo,

is there another way to pritt a PDF form python?

My problem is a PDF which is printed well by evince, but not with lp,
even not out of python using

os.system("lp some_options file.pdf")

Later on I have to build the PDF in a python program (using reportlab)
and then print it, even from the python program.

So I look for a (nice documented) library which give access to the CUPS
API or something else to print the PDF from python.

Any help is welcome!

Ulrich




--
Ulrich Goebel
Paracelsusstr. 120, 53177 Bonn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing from python

2014-03-14 Thread Ulrich Goebel



Am 14.03.2014 11:40, schrieb Ulrich Goebel:

is there another way to pritt a PDF form python?


sorry, that doesn't make sense. I should say: is there another way ... 
besides os.system()?



--
Ulrich Goebel
Paracelsusstr. 120, 53177 Bonn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing from python

2014-03-14 Thread Russel Winder
On Fri, 2014-03-14 at 11:40 +0100, Ulrich Goebel wrote:
> Hallo,
> 
> is there another way to pritt a PDF form python?
> 
> My problem is a PDF which is printed well by evince, but not with lp, 
> even not out of python using
> 
> os.system("lp some_options file.pdf")

Python is deprecating os.system in favour of using the subprocess
package.

subprocess.call('lp some_options file.pdf', shell=True)

or

subprocess.call(['lp', *some_options, 'file.pdf')

assuming some_options is a sequence of strings, on option per string.

> Later on I have to build the PDF in a python program (using reportlab) 
> and then print it, even from the python program.
> 
> So I look for a (nice documented) library which give access to the CUPS 
> API or something else to print the PDF from python.
> 
> Any help is welcome!

Debian Sid has packages python-cups and python-cupshelpers which are
Python 2 APIs for working with CUPS. Sadly there do not seem to be
Python 3 versions of these In Debian, but the package in PyPI is pycups
so can be made available to Pytho 3. Also: 

http://cyberelk.net/tim/software/pycups/

I have not used these yet myself, but I have trying them out on my
agenda for later in the spring.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing from python

2014-03-14 Thread Timo

op 14-03-14 12:14, Ulrich Goebel schreef:
I just found a hint, the Qt QPrinter Class. I use Qt, so that could be 
a solution?


This would be your best bet, use the tools which are provided. I'm a GTK 
user and use the GTK printing API to both create and print reports.


If you want to use cups, this is a project with Python bindings for 
cups: https://pypi.python.org/pypi/pycups/1.9.66


Timo




Am 14.03.2014 11:40, schrieb Ulrich Goebel:

Hallo,

is there another way to pritt a PDF form python?

My problem is a PDF which is printed well by evince, but not with lp,
even not out of python using

os.system("lp some_options file.pdf")

Later on I have to build the PDF in a python program (using reportlab)
and then print it, even from the python program.

So I look for a (nice documented) library which give access to the CUPS
API or something else to print the PDF from python.

Any help is welcome!

Ulrich






___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing from python

2014-03-14 Thread Alan Gauld

On 14/03/14 10:40, Ulrich Goebel wrote:


Later on I have to build the PDF in a python program (using reportlab)
and then print it, even from the python program.

So I look for a (nice documented) library which give access to the CUPS
API or something else to print the PDF from python.


I may be mistaken but I don't think CUPS will help you.

PDF documents are effectively programs that have to be interpreted
by a PDF reader of some sort. Some printers have that capability
built in, most require a program such as Acrobat or ghostscript
to do the formatting for them.

I don't think CUPS has an API for rendering PDF directly it
will simply send the PDF direct to a PDF aware printer or take
the image out from a PDF reader and send it to a standard
print driver.

Your Qt solution may support PDF rendering, I don't know Qt,
but its definitely worth pursuing. Failing that you probably
do need to use subprocess to launch ghostscript or similar.
But there is no shame in that, chaining programs together
is standard Unix practice and a sign of good design - one
program does one job.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing from python

2014-03-14 Thread Ben Finney
Ulrich Goebel  writes:

> So I look for a (nice documented) library which give access to the
> CUPS API or something else to print the PDF from python.
>
> Any help is welcome!

The problem isn't really one to be solved within your program, IMO.

Printing is implemented as a service at the operating system (OS) level.
Once you have a document in a form suitable for sending to a printer
(such as a PDF), the OS is where any problems with the actual printing
need to be addressed.

Also, since it is implemented at the OS level, you're not going to find
a solution in a platform-agnostic programming language like Python. The
solution, whatever it is, will be highly dependent on the services
presented by your specific OS.

Of course, once you have a suitable OS service for printing the
document, Python can send the document to that service. But at that
point, the Python code will be trivially easy: probably invoking an
external command via ‘subprocess.call’ or ‘subprocess.check_call’.

In short: printing is a problem to be solved via the OS, not via Python.

-- 
 \ “We are not gonna be great; we are not gonna be amazing; we are |
  `\   gonna be *amazingly* amazing!” —Zaphod Beeblebrox, _The |
_o__)Hitch-Hiker's Guide To The Galaxy_, Douglas Adams |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor