Python: Newbie Code for String Histogram

Well, I have been pretty lazy about blogging lately, so pardon the amateurish code. But well, ever since no_mind egged me on to learn python, I have been learning it. Just finished a few code samples and this looked nice. It actually generates a histogram of the number of occurences of characters in a string.

#! /usr/bin/env python

#python program to input a number and generate a histogram of the characters in it
import string
txt=raw_input()
txtarray=list(string.lower(txt))
chardict={}
for char in txtarray:
    if chardict.has_key(char):
        chardict[char]=chardict[char]+1
    else:
        chardict[char]=1
charlistpair=chardict.items()
charlistpair.sort()
for pair in charlistpair:
    print pair[0], “t”,
    for i in range(0, pair[1]):
        print “|”,
    print

  

Solution: Spell Check in Word 2007 not working

A friend dropped over her laptop saying the spell check in her Word 2007 wasn’t working. Apparently lot of users seem to have this problem.

There are many reasons but in this case, the solution was quite simple as outlined at this forum post.

Apparently the spellcheck add-in was disabled. Word Option>Addins>Disabled Addins and Go… shows the disabled addin which can be easily enabled.

Spell check works now and she owes me one. I am gonna ask for a pizza in return for the troubleshooting session. :p

Solving the include_once error in Pear Mail

I have this hosting from hosting.india.to and helping on a friend’s community development initiative by setting up his website. It may soon move to careforindia.org.

During that, I set up a email form on my system, using PHP’s PEAR mail package to send mail. Though it worked fine on my own system, it didn’t on the hosting server. And no errors either.

First enabled the Error messages by putting this is the first line of the php file.

ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting (E_ALL);

And then out popped the error.

Warning: Mail_smtp::include_once(Net/SMTP.php) [mail-smtp.include-once]: failed to open stream: No such file or directory in /home/username/php/Mail/smtp.php on line 206


Warning: Mail_smtp::include_once()[function.include]: Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username/php/Mail/smtp.php on line 206


Fatal error: Class 'Net_SMTP' not found in /home/username/php/Mail/smtp.php on line 210

Apparently the basedir is set incorrectly and since I need to ask the hosting person to change the configuration, and to avoid the hassle, the simplest solution was to edit line 206 in /home/username/php/Mail/smtp.php to have

include_once '/home/username/php/Net/SMTP.php';

include_once 'Net/SMTP.php';

Yes, that is the full path.

Once I did that, I also got an error from Net/SMTP.php with it finding difficulty in locating Socket.php.

Same solution again and everything looks hunky dory. Clean up the error reporting and any debugging steps in between.

Oh, by the way, the site is at careforindia.jsemmanuel.com/donate.php and will soon be moved to www.careforindia.org