Posts filed under 'Python'
python to pythoning ……



I
ts not a dramatic change in me for switching from “Java” to python And i did not. …. well , all i wanted to have fun coding in python rather than “Java” …. Intially i was totally confused whether i should learn ruby or groovy or python or whatever that suppose to make me smile while coding…. But i learned python that its one of the more popular , strong ,dynamic bla bla bla …… And i am still a novice , i started with byte of python tutorial which is excellent tutorial by swaroop (http://www.swaroopch.com/byteofpython/) …. Ya just started out with python shell executing all basic stuffs using IDLE … Its amazing thing to learn python .. if you python then surely you will never turn off from your mind … get addicted to it , like i am . Till now i learned so many things that i wouldn’t have learned from any other language … beacause its very simple , ease … and only thing that you have to apply some common sense while pythoning ….
You can write sophisticated taks within in few lines … what you code in java/c++/c can be done within few lines ….. you will more over concentrate on solution to the problem rather than syntax !… And it has got numerious GUI and Web frameworks and its still amazing .
Today i found libgmail.py library , where i can play around with GMAIL account using python…. (http://libgmail.sourceforge.net/)
Which is a Library to provide access to Gmail via Python
After downloading libgmail … all i have to extract to my /lib directory .
some examples i worked out …..
SEND MAIL
import libgmail
import mechanize as ClientCookie
ga = libgmail.GmailAccount(“username@gmail.com”, “password”)
ga.login()
msg = libgmail.GmailComposedMessage(‘to@gmail.com’,’subject’,'body’)
ga.sendMessage(msg)
print ‘\nEmail sent’
READ MAIL
import libgmail
ga = libgmail.GmailAccount(“username@gmail.com”, “password”)
ga.login()
folder = ga.getMessagesByFolder(“inbox”, True)
for thread in folder:
print “Thread:”, thread.id, “Subject:”, thread.subject
for msg in thread:
print “Msg:”, msg.id, “,Author”, msg.author, “,Subject:”, msg.subject
To send attachment files
import libgmail
ga = libgmail.GmailAccount(“username@gmail.com”, “password”)
ga.login()
myFiles = ["/file1", "/file2", "/file3"]
msg=libgmail.GmailComposedMessage(“friend@gmail.com”, “SubjectHere”, “BodyHere”, filenames=myFiles)
ga.sendMessage(msg)
Infact you can read contacts , read trash , read Unread mails etc ……..
Isnt it amazing !! …. poetic way to python ….
6 comments September 1, 2008

