hi everybody , I have a program (below) but don't know how to direct the out put to the printer , can anyone help thanks

from calendar import *
setfirstweekday(5)      #saturday
prcal(2008)
raw_input('hit a key')

another question is that I tried writing " saturday " instead of "5" and it gave me error , how else can I do it so that it would be more undrestandable ?

Recommended Answers

All 4 Replies

...
tried writing " saturday " instead of "5" and it gave me error , how else can I do it so that it would be more undrestandable ?

well, calendar.setfirstweekday() takes parameter of type integer, you try this workarround for understandable or whatever...

>>> import calendar
>>> wday_map = {'monday':0,'tuesday':1,'wednesday':2, 'thursday':3, 'friday':4, 'saturday':5, 'sunday':6}
>>> wday_map['saturday']
5
>>> calendar.setfirstweekday(wday_map['saturday'])

hope this helps.

kath.

thanks, Iused that and it worked

The Python code snippet at:
http://www.daniweb.com/code/snippet399.html
gives you an idea on how to send a string to a printer on a Windows machine.

Your code in this case might look like this ...

# type/draw a text string to the default printer
# needs the win32 extensions package
# from: http://starship.python.net/crew/mhammond/win32/Downloads.html

import win32ui
import win32print
import win32con

import calendar as cd

# set monthly calendar so it will start with a Saturday
cd.setfirstweekday(cd.SATURDAY)
# put a year's monthly calendars into a string
str1 = cd.calendar(2008)
# test it ...
print str1

raw_input('make sure printer is ready then hit enter key ... ')

try:
    hDC = win32ui.CreateDC()
    print win32print.GetDefaultPrinter()  # test
    hDC.CreatePrinterDC(win32print.GetDefaultPrinter())
    hDC.StartDoc("Test doc")
    hDC.StartPage()
    hDC.SetMapMode(win32con.MM_TWIPS)
    
    # draws text within a box (assume about 1400 dots per inch for typical HP printer)
    ulc_x = 1000    # give a left margin
    ulc_y = -1000   # give a top margin
    lrc_x = 11500   # width of text area-margin, close to right edge of page
    lrc_y = -15000  # height of text area-margin, close to bottom of the page
    hDC.DrawText(str1, (ulc_x, ulc_y, lrc_x, lrc_y), win32con.DT_LEFT)
    
    hDC.EndPage()
    hDC.EndDoc()
except:
    print "Printer not online"  # does not work!

thanks vegaseat , I am learning alot from your
ali

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.