Friday, November 19, 2010

Fatching SQL table as python dictionary

'''
tableName:
a        b
--------------
as      uu
'''
conn = MySQLdb.connect (host = "localhost",
                           user = "root",
                           passwd = "",
                           db = "dbName",
                           cursorclass=MySQLdb.cursors.DictCursor
                           )

cursorDict = conn.cursor()
cursorDict.execute("SELECT * FROM tableName")
rowDict = cursorDict.fetchone()

print rowDict

# this will print {"a":"as", "b":"uu"}

Monday, June 21, 2010

কুমড়োপটাশ

সুকুমার রায় 

 
        (যদি) কুম্‌ড়োপটাশ নাচে—
        খবরদার এসো না কেউ আস্তাবলের কাছে;
        চাইবে নাকো ডাইনে বাঁয়ে চাইবে নাকো পাছে;
        চার পা তুলে থাকবে ঝুলে হট্টমূলার গাছে।

(যদি) কুম্‌ড়োপটাশ কাঁদে—
খবরদার! খবরদার! বসবে না কেউ ছাদে;
উপুড় হয়ে মাচায় শুয়ে লেপ কম্বল কাঁধে,
বেহাগ সুরে গাইবে খালি 'রাধে কৃষ্ণ রাধে!'

        (যদি) কুম্‌ড়োপটাশ হাসে—
        থাকবে খাড়া একটি ঠ্যাঙে রান্নাঘরের পাশে;
        ঝাপসা গলায় ফার্সি কবে নিশ্বাসে ফিস্‌ফাসে;
        তিনটি বেলা উপোস করে থাকবে শুয়ে ঘাসে!

  (যদি) কুম্‌ড়োপটাশ ছোটে—
সবাই যেন তড়বড়িয়ে জানালা বেয়ে ওঠে;
হুঁকোর জলে আলতা গুলে লাগায় গালে ঠোঁটে;
ভুলেও যেন আকাশ পানে তাকায় না কেউ মোটে!

        (যদি) কুম্‌ড়োপটাশ ডাকে—
        সবাই যেন শ্যামলা এঁটে গামলা চড়ে থাকে;
        ছেঁচকি শাকের ঘন্ট বেটে মাথায় মলম মাখে;
        শক্ত ইঁটের তপ্ত ঝামা ঘষতে থাকে নাকে।

        তুচ্ছ ভেবে এ–সব কথা করছ যারা হেলা,
        কুম্‌ড়োপটাশ জানতে পেলে বুঝবে তখন ঠেলা।
        দেখবে তখন কোন্ কথাটি কেমন করে ফলে,
        আমায় তখন দোষ দিও না, আগেই রাখি বলে।

Monday, May 31, 2010

error: command 'gcc' failed with exit status 1, in Ubuntu : Solved

I got the error:

error: command 'gcc' failed with exit status 1

while I was trying to install mysql-python.

While this problem almost make my hair white, I found this easy solution:

In terminal:
sudo apt-get install python-dev 

And thats it,
That's work for me...

Thanks,
Sakib

Sunday, May 30, 2010

In Ubuntu the error: EnvironmentError: mysql_config not found :- Solved

I was trying to install mysql-python. But the it gives me a error like this:

EnvironmentError: mysql_config not found

Then I have tried to install the mysql client and try to install mysql-python again, the result is same.

After searching a lot, I have found a solution. Then I have followed the following steps:

in terminal:

sudo apt-get install libmysqlclient15-dev
sudo easy_install MySQL_python-1.2.3c1-py2.5-linux-i686.egg



And its works for me!!!!

Thanks
Sakib

Friday, May 28, 2010

Writing Polish text into a file using Python

i need to write some polish text into a new file, so I have tried:

myLines = somePolishText
file = open('myText.txt', 'w')
file.writelines(myLines)


at this point, I've got an error like this:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0119' in position 29: ordinal not in range(128)


After lots of recharch and findings, I have change the same code like this:

import codecs

myLines = somePolishText
file = codecs.open('myText.txt', 'w', 'utf-8')
file.writelines(myLines)


and its works for me pritty well.

Thanks
Sakib