3

I am trying to print this statement:

a= 'Hi %s, \n The meeting is scheduled for %s %sth \n if you have an  questions please contact %s' % (cfname, meetingmonth, meetingday, cleadfname)
print a

I'm also trying to bold every variable insert (i.e. cfname, meetingmonth etc.). Basically, I have a script asking the enduser for input which writes this statement to a .doc format. Is there a simple way to bold things when writing something in python?

I've tried the bold brackets around the word and that doesn't seem to work. Any help would be great!

user3527972
  • 89
  • 2
  • 7

3 Answers3

4

print produces plain text, not Microsoft Word documents. If you add HTML formatting tags (<html>, <body>, <strong>, <br />, etc.) where necessary, then give the resulting text file the .doc extension, it will open with Word, which - assuming you have a reasonably recent version that understands HTML - will parse the HTML and display the result you're looking for.

Sample:

a= '<html><head></head><body>Hi %s, </br> The meeting is scheduled for <strong>%s %sth</strong> <br /> if you have an  questions please contact %s</body></html>' % (cfname, meetingmonth, meetingday, cleadfname)
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
1

try using termcolor

>>> from termcolor import cprint
>>> cprint("Hello", attrs=['bold'])
0

You might have some success with a module that helps python output Rich Text Format, like PyRTF.

However, it has been suggested that HTML is easier to work with:

Fonts formatting in python output

Community
  • 1
  • 1
repurposer
  • 145
  • 5