Archive for August, 2008

Python Trouble Shooting

Posted on August 10, 2008. Filed under: MySQL, Python, Windows | Tags: , |

1. If you get data from mysql

After the mysql_connection.execute(“some sql”), then get the result by line =mysql_connection.fetchone(), and the results are listed by line[0], line[1], line[2] …..(not the “key”->”value” pair)

2. in wxPython, the toolbar should add toolbar.Realize()

If there is no Realize() at the end of the toolbar show segment, the button will not show

toolbar = self.CreateToolBar()
toolbar.AddTool(ID_ABC, wx.Bitmap(‘icons/icon.png’))
self.Bind(wx.EVT_TOOL, self.OnChangeDepth, id=ID_ABC)
toolbar.Realize()

3.

pytz.UnknownTimeZoneError: ‘US/Central’ after py2exe in python 2.6

I noticed that the old version of pytz I was using compiled each timezone into a .pyc, and these would be included in the resulting library.zip for my programs. When I build against the new pytz, these files are no longer getting compiled to .pyc. Instead, when I check the pytz directory in library.zip, I see these files:
__init__.pyc
reference.pyc
tzfile.pyc
tzinfo.pyc

It appears that the zoneinfo directory is missing.

Solution:
in file build.py/setup.py for the py2exe

import py2exe
setup(
console=[‘test.py’],
options={
‘py2exe’: {
‘packages’ : [‘matplotlib’, ‘pytz’],
}
},
)

The “packages” in “options” is very important.

References:
http://www.py2exe.org/index.cgi/MatPlotLib
http://osdir.com/ml/python.py2exe/2004-10/msg00040.html
http://www.nabble.com/Python-2.6-%2B-Pytz-2009a-%2B–Py2exe-problem-tt22574634.html#a22574634

4.

DeprecationWarning: the sets module is deprecated

There are two methods:
4.1. python -W ignore::DeprecationWarning

4.2. in Python26\Lib\sets.py  comment line 83-85
#import warnings
#warnings.warn(“the sets module is deprecated”, DeprecationWarning,stacklevel=2)

5. Socket timeout in xmlrpclib

import xmlrpclib
import socket
socket.setdefaulttimeout(10)        #set the timeout to 10 seconds
x = xmlrpclib.ServerProxy('http://1.2.3.4')

x.func_name(args)                   #times out after 10 seconds
socket.setdefaulttimeout(None)      #sets the default back

Reference:

http://stackoverflow.com/questions/372365/set-timeout-for-xmlrpclib-serverproxy

http://code.activestate.com/

Advertisements
Read Full Post | Make a Comment ( None so far )

PHP trouble shooting

Posted on August 10, 2008. Filed under: MySQL, PHP |

1. In the php mysql related script:

After use “mysql_query”, if you want to get the real results array, you should call the function “mysql_fetch_assoc” or “mysql_fetch_row”. The result are “key”->”value” pairs where the “key” is the table column name in the mysql_query sentence.

Useful Links:

1.  _SERVER parameter

http://us2.php.net/manual/en/reserved.variables.server.php

2. Getting the current full URL in PHP

http://dev.kanngard.net/Permalinks/ID_20050507183447.html

http://www.phpro.org/examples/Get-Full-URL.html

3. PHP tip: How to convert a relative URL to an absolute URL

http://nadeausoftware.com/node/79#Examples

4. mb_strrchr()

http://www.php.net/manual/en/function.mb-strrchr.php

5.Introduction to PHP Regex

http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

6. urlencode and rawurlencode

http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/

http://www.php.net/urlencode

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...