Partial Function Application -- Advantages over normal function?
Hi, I am a newbie in python and would like to learn GUI programming. I would like to know what exactly is Partial Function Applicaton (functool.partial())? Or how is it advantageous compared to normal functions? Or is there any advantange? Thanks in advance. Regards, Kurian Thayil. -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial Function Application -- Advantages over normal function?
On Tue, Jul 19, 2011 at 11:52 AM, Thomas Jollans wrote: > On 19/07/11 00:33, Thomas 'PointedEars' Lahn wrote: > > Thomas 'PointedEars' Lahn wrote: > > > >> Dave Angel wrote: > >>> On 01/-10/-28163 02:59 PM, Terry Reedy wrote: > >>>> def makeadder(y) > >>>> def _add(x): return x+y > >>>> add2 = makeadder(2) > >>> > >>> A couple of typos in that code: > >>> > >>> def makeaddr(y): > >>> def _add(x): return x+y > >>> return _add > >> > >> I agree about the `return' statement, but not about the factory name; > this > >> has nothing to do with addresses (addr). > > > > Supplemental: The above can be simplified to > > > > def makeadder(y): return lambda x: x + y > > > > In turn: > > makeadder = lambda y: lambda x: x + y > > Smells of Haskell. > -- > http://mail.python.org/mailman/listinfo/python-list > Hi All, Thanks guys for the reply. I now understand something. Since Im a newbie, let me read over and over so that I will get the complete picture of everyone's idea. :-) Regards, Kurian Thayil. -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb compiled -- Import issue
Hi All, I am just a month old with Python and trying to learn CGI with Python. I was trying to install MySQLdb module in my new CentOS 5.3 box with Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb module (MySQL-python-1.2.3c1). Did build as normal user and install as root. MySQL server version that I'm using is 5.1.41, if that has anything to do with the error. I then copied, libmysqlclient_r.so.16 library to /usr/lib/ folder and then I am able to import the module as root user. But cannot do this as normal user. Now, while doing import MySQLdb as normal user, I get the following error message. The scripts will be run as apache and hence cannot have this error. Please check the following output. Also I have attached the output while doing build and install process. [kuria...@server MySQL-python-1.2.3c1]$ python Python 2.4.3 (#1, Jan 21 2009, 01:10:13) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path It would be a great help if I understand what's going on!!! Thanks in advance. Regards, Kurian Mathew Thayil. [kuria...@server MySQL-python-1.2.3c1]$ python setup.py build running build running build_py creating build creating build/lib.linux-i686-2.4 copying _mysql_exceptions.py -> build/lib.linux-i686-2.4 creating build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/__init__.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/converters.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/connections.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/cursors.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/release.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/times.py -> build/lib.linux-i686-2.4/MySQLdb creating build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.4/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.linux-i686-2.4 gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/local/include/mysql -I/usr/include/python2.4 -c _mysql.c -o build/temp.linux-i686-2.4/_mysql.o -DUNIV_LINUX -DUNIV_LINUX In file included from _mysql.c:36: /usr/local/include/mysql/my_config.h:1050:1: warning: "HAVE_WCSCOLL" redefined In file included from /usr/include/python2.4/pyconfig.h:4, from /usr/include/python2.4/Python.h:8, from pymemcompat.h:10, from _mysql.c:29: /usr/include/python2.4/pyconfig-32.h:648:1: warning: this is the location of the previous definition gcc -pthread -shared build/temp.linux-i686-2.4/_mysql.o -L/usr/local/lib/mysql -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -o build/lib.linux-i686-2.4/_mysql.so [r...@server MySQL-python-1.2.3c1]# python setup.py install running install running bdist_egg running egg_info writing MySQL_python.egg-info/PKG-INFO writing top-level names to MySQL_python.egg-info/top_level.txt writing dependency_links to MySQL_python.egg-info/dependency_links.txt reading manifest file 'MySQL_python.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'MySQL_python.egg-info/SOURCES.txt' installing library code to build/bdist.linux-i686/egg running install_lib running build_py copying MySQLdb/release.py -> build/lib.linux-i686-2.4/MySQLdb running build_ext creating build/bdist.linux-i686 creating build/bdist.linux-i686/egg copying build/lib.linux-i686-2.4/_mysql.so -> build/bdist.linux-i686/egg copying build/lib.linux-i686-2.4/_mysql_exceptions.py -> build/bdist.linux-i686/egg creating build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/connections.py -> build/bdist.linux-i686/egg/MySQLdb creating build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/CR.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/__init__.py -> build/bdist
Re: MySQLdb compiled -- Import issue
On Wed, 2010-03-24 at 20:15 -0700, Sean DiZazzo wrote: > On Mar 24, 7:59 pm, Kurian Thayil wrote: > > Hi All, > > > > I am just a month old with Python and trying to learn CGI with Python. I > > was trying to install MySQLdb module in my new CentOS 5.3 box with > > Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb > > module (MySQL-python-1.2.3c1). Did build as normal user and install as > > root. MySQL server version that I'm using is 5.1.41, if that has > > anything to do with the error. I then copied, libmysqlclient_r.so.16 > > library to /usr/lib/ folder and then I am able to import the module as > > root user. But cannot do this as normal user. > > > > Now, while doing import MySQLdb as normal user, I get the following > > error message. The scripts will be run as apache and hence cannot have > > this error. Please check the following output. Also I have attached the > > output while doing build and install process. > > > > [kuria...@server MySQL-python-1.2.3c1]$ python > > Python 2.4.3 (#1, Jan 21 2009, 01:10:13) > > [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information.>>> > > import MySQLdb > > > > /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: > > UserWarning: Module _mysql was already imported from > > /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, > > but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to > > sys.path > > > > It would be a great help if I understand what's going on!!! Thanks in > > advance. > > > > Regards, > > > > Kurian Mathew Thayil. > > > > MySQLdb-build.txt > > 3KViewDownload > > > > MySQLdb-Install.txt > > 6KViewDownload > > > > signature.asc > > < 1KViewDownload > > The warning looks familiar. Are you running python from the MySQLdb > source directory? ie. /opt/downloads/py-modules/MySQL-python-1.2.3c1 > > I think you just need to change directories and the warning will go > away. Check what's happening on line 3 of _mysql.py I don't have the > source in front of me. > > ~Sean Hi Sean, You are right. I was trying to import the module sitting on the source folder :"-). Thanks for your quick response and let me try further. Regards, Kurian Mathew Thayil. <> signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Python - MySQL fetching values
Hi All, I am pretty new to python, and I have an issue with fetching values in python using MySQLdb module. The query executed is *SELECT TIME(DATE_ADD(info_last_calltime, INTERVAL %s MINUTE)) FROM rem_call_info WHERE info_ctrlid=%s""", (retryinterval,controlid1,)* where retryinterval=30 and controlid=2, the expected output is *05:35:05*. Now, here is code snippet, cursor1=getconnect1.cursor() getrows=cursor1.execute("""SELECT TIME(DATE_ADD(info_last_calltime, INTERVAL %s MINUTE)) FROM rem_call_info WHERE info_ctrlid=%s""", (retryinterval,controlid1,)) rawstatus20result=cursor1.fetchone() print "Raw result is",rawstatus20result status20result=rawstatus20result[0] print "The query result for Status 20:",status20result,";Time now is",timeformat The output is: Raw result is (datetime.timedelta(0, 20105),) The query result for Status 20: 5:35:05 ;Time now is 05:22:00 Match not found. New call to be made Getting next value if any... If you look closer, the time fetched by python module was 5:35:05 instead of 05:35:05. How can I get this time format? Thanks in advance. Regards, Kurian Thayil. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python - MySQL fetching values
On Thu, May 6, 2010 at 2:42 PM, Chris Rebert wrote: > On Thu, May 6, 2010 at 1:47 AM, Kurian Thayil > wrote: > > > the expected output is 05:35:05. > > > > Now, here is code snippet, > > > > cursor1=getconnect1.cursor() > > getrows=cursor1.execute("""SELECT > > TIME(DATE_ADD(info_last_calltime, INTERVAL %s MINUTE)) FROM rem_call_info > > WHERE info_ctrlid=%s""", (retryinterval,controlid1,)) > > rawstatus20result=cursor1.fetchone() > > print "Raw result is",rawstatus20result > > status20result=rawstatus20result[0] > > print "The query result for Status > > 20:",status20result,";Time now is",timeformat > > > > The output is: > > > > Raw result is (datetime.timedelta(0, 20105),) > > The query result for Status 20: 5:35:05 ;Time now is 05:22:00 > > Match not found. > > New call to be made > > Getting next value if any... > > > > If you look closer, the time fetched by python module was 5:35:05 instead > of > > 05:35:05. How can I get this time format? Thanks in advance. > > You're getting back a time delta (i.e. quantity/duration of time, e.g. > "3 hours") rather than an actual time (i.e. temporal coordinates for a > particular instant of time, e.g. "5:15PM and 2 seconds"), and > timedelta defines its stringification differently, hence your issue. I > would guess that getting back a timedelta instead of a time is some > quirk of MySQLdb; haven't used it though, so I'm just guessing. > > Anyway, you can work around this by converting the timedelta object to > a time object yourself: > #Untested Code! > from datetime import time > minutes, seconds = divmod(status20result.seconds, 60) > hours, minutes = divmod(minutes, 60) > time_result = time(hours, minutes, seconds, status20result.microseconds) > print "The query result for Status 20:",time_result,";Time now > is",timeformat > > Cheers, > Chris > -- > http://blog.rebertia.com > That worked Chris. Thank you. Regards, Kurian Thayil. -- http://mail.python.org/mailman/listinfo/python-list
mail sending -- smtplib
Hi All, I am a newbie in python. Just 2-3 days old wanting to learn this amazing programming language. I was trying to send mails using smtplib module, so did some google and found a code snippet. The mail gets sent, but doesn't come in the right format when a for-loop is introduced (Not MIME standard?). Without the for-loop the script works fine. Can anyone advice? * #!/usr/bin/env python import smtplib for i in range(1,5): print "I is ",i fromaddr='kurianmtha...@gmail.com' toaddr='kurianmtha...@gmail.com' print toaddr mssg="""From: Kurian Thayil To: Kurian Thayil MIME-Version: 1.0 Content-type: text/html Subject: 12345 -- Reloaded :) Hey dude.. how are you Regards, Kurian """ print "message is ",mssg smail=smtplib.SMTP('smtp.gmail.com',587) smail.ehlo() smail.starttls() smail.ehlo() smail.login(fromaddr,'*******') smail.sendmail(fromaddr,toaddr,mssg) print "Over" * Regards, Kurian Thayil. -- http://mail.python.org/mailman/listinfo/python-list
Re: mail sending -- smtplib
Got it fixed. It was a very silly mistake. mssg variable had each line with indent. Removed the indent and it worked. Regards, Kurian Thayil. On Tue, Sep 7, 2010 at 9:57 AM, Kurian Thayil wrote: > Hi All, > > I am a newbie in python. Just 2-3 days old wanting to learn this amazing > programming language. I was trying to send mails using smtplib module, so > did some google and found a code snippet. The mail gets sent, but doesn't > come in the right format when a for-loop is introduced (Not MIME standard?). > Without the for-loop the script works fine. Can anyone advice? > * > #!/usr/bin/env python > > import smtplib > > for i in range(1,5): > print "I is ",i > fromaddr='kurianmtha...@gmail.com' > toaddr='kurianmtha...@gmail.com' > print toaddr > mssg="""From: Kurian Thayil > To: Kurian Thayil > MIME-Version: 1.0 > Content-type: text/html > Subject: 12345 -- Reloaded :) > > Hey dude.. how are you > > > Regards, > > Kurian > """ > print "message is ",mssg > > smail=smtplib.SMTP('smtp.gmail.com',587) > > smail.ehlo() > smail.starttls() > smail.ehlo() > smail.login(fromaddr,'***') > > smail.sendmail(fromaddr,toaddr,mssg) > print "Over" > * > > Regards, > > Kurian Thayil. > -- http://mail.python.org/mailman/listinfo/python-list