<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Answer My Searches &#187; Python</title>
	<atom:link href="http://www.answermysearches.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.answermysearches.com</link>
	<description>Answers to everything I search for, every day</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:27:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python &#8211; How to use MySQLdb when MySQL Isn&#8217;t Installed Locally</title>
		<link>http://www.answermysearches.com/python-how-to-use-mysqldb-when-mysql-isnt-installed-locally/2284/</link>
		<comments>http://www.answermysearches.com/python-how-to-use-mysqldb-when-mysql-isnt-installed-locally/2284/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 14:15:22 +0000</pubDate>
		<dc:creator>Greg Pinero (Primary Searcher)</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.answermysearches.com/?p=2284</guid>
		<description><![CDATA[It turns out there&#8217;s a new MySQL connection library called MySQL Connector.
I installed it and then I just imported that into my script and everything else seemed to work normally.  At least for my simply import script.  
import mysql.connector as MySQLdb
I believe this library is designed for those who want to connect to [...]]]></description>
			<content:encoded><![CDATA[<p>It turns out there&#8217;s a new MySQL connection library called <a href="https://launchpad.net/myconnpy">MySQL Connector</a>.</p>
<p>I installed it and then I just imported that into my script and everything else seemed to work normally.  At least for my simply import script.  </p>
<p><code>import mysql.connector as MySQLdb</code></p>
<p>I believe this library is designed for those who want to connect to MySQL on another server.  It doesn&#8217;t seem to require any MySQL libraries to be installed.</p>
<p>When I tried to install mySQLdb it complained with the following message.  I&#8217;m guessing the problem was that it requires MySQL to be installed:</p>
<p><code>  File "/Users/pinerog/Downloads/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config<br />
    raise EnvironmentError("%s not found" % (mysql_config.path,))<br />
EnvironmentError: mysql_config not found<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.answermysearches.com/python-how-to-use-mysqldb-when-mysql-isnt-installed-locally/2284/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python zipfile &#8211; Fixing Error: Unable to unarchive &#8220;..&#8221; into &#8220;Downloads&#8221;</title>
		<link>http://www.answermysearches.com/python-zipfile-fixing-error-unable-to-unarchive-into-downloads/2278/</link>
		<comments>http://www.answermysearches.com/python-zipfile-fixing-error-unable-to-unarchive-into-downloads/2278/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 12:48:07 +0000</pubDate>
		<dc:creator>Greg Pinero (Primary Searcher)</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.answermysearches.com/?p=2278</guid>
		<description><![CDATA[I made a zip file in Python and tried to open it on my mac.  I got the error mentioned in the title.
Investigating further, I got this information from running:
lm1:Downloads pinerog$ unzip -t costume_spreadsheets_from_jackrabbit.zip

Archive:  costume_spreadsheets_from_jackrabbit.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one [...]]]></description>
			<content:encoded><![CDATA[<p>I made a zip file in Python and tried to open it on my mac.  I got the error mentioned in the title.</p>
<p>Investigating further, I got this information from running:</p>
<p><code>lm1:Downloads pinerog$ unzip -t costume_spreadsheets_from_jackrabbit.zip</code></p>
<pre>
Archive:  costume_spreadsheets_from_jackrabbit.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of costume_spreadsheets_from_jackrabbit.zip or
        costume_spreadsheets_from_jackrabbit.zip.zip, and cannot find costume_spreadsheets_from_jackrabbit.zip.ZIP, period.</pre>
<p>Well, silly me, I forgot to close the zip file I made in Python.  Here is the correct code for generating a zip file.  Make sure you close the zip file object!</p>
<pre class="python">
import zipfile
import glob, os

file = zipfile.ZipFile("test.zip", "w")
for name in glob.glob("samples/*"):
    file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
file.close()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.answermysearches.com/python-zipfile-fixing-error-unable-to-unarchive-into-downloads/2278/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python &#8211; Excel &#8211; How to merge cells with xlwt</title>
		<link>http://www.answermysearches.com/python-excel-how-to-merge-cells-with-xlwt/2276/</link>
		<comments>http://www.answermysearches.com/python-excel-how-to-merge-cells-with-xlwt/2276/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 14:37:06 +0000</pubDate>
		<dc:creator>Greg Pinero (Primary Searcher)</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.answermysearches.com/?p=2276</guid>
		<description><![CDATA[The sheet object has this method:
write_merge(r1,r2,c1,c2,label,style)
Style and label are optional.
There is an example of its use here:
https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/examples/merged0.py
]]></description>
			<content:encoded><![CDATA[<p>The sheet object has this method:</p>
<p><code>write_merge(r1,r2,c1,c2,label,style)</code></p>
<p>Style and label are optional.</p>
<p>There is an example of its use here:</p>
<p><a href="https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/examples/merged0.py">https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/examples/merged0.py</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.answermysearches.com/python-excel-how-to-merge-cells-with-xlwt/2276/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Is there a limit to the number of items in an &#8220;in&#8221; clause</title>
		<link>http://www.answermysearches.com/mysql-is-there-a-limit-to-the-number-of-items-in-an-in-clause/2248/</link>
		<comments>http://www.answermysearches.com/mysql-is-there-a-limit-to-the-number-of-items-in-an-in-clause/2248/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 14:50:57 +0000</pubDate>
		<dc:creator>Greg Pinero (Primary Searcher)</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.answermysearches.com/?p=2248</guid>
		<description><![CDATA[I couldn&#8217;t find any documentation on this, so I wrote a quick Python script to test this:

"""
Test how many items can be in MySQL's in clause

Table I'm using for testing:
CREATE
    TABLE INTEST
    (
        id bigint NOT NULL,
      [...]]]></description>
			<content:encoded><![CDATA[<p>I couldn&#8217;t find any documentation on this, so I wrote a quick Python script to test this:</p>
<pre>
"""
Test how many items can be in MySQL's in clause

Table I'm using for testing:
CREATE
    TABLE INTEST
    (
        id bigint NOT NULL,
        PRIMARY KEY (id)
    )
    ENGINE=InnoDB DEFAULT CHARSET=latin1
"""
import MySQLdb

conn = MySQLdb.connect(host = 'localhost',
    user = 'root', passwd = '*****', db = 'scratch', charset='latin1')
curs = conn.cursor()

#test maximum sql in clause
def test_sql_in():
    test_up_to = 20000
    curs.execute('truncate table INTEST')
    for i in range(1,test_up_to):
        curs.execute('INSERT INTO INTEST (id) VALUES (%s)', (i,))
    conn.commit()
    for i in range(1,test_up_to):
        in_str = ','.join([str(v) for v in range(1,i+1)])
        select_sql = "select * from INTEST where id in (%s)" % in_str
        curs.execute(select_sql)
        rows = curs.fetchall()
        assert len(rows) == i
        if i % 100 == 0: print i

test_sql_in()
</pre>
<p><br/><br/></p>
<p>It ran fine.  I tried it up to 20,000 items.  Though it does get pretty slow, even with the index.</p>
<p>Note: I only tried this on MySQL 5.1.55 on Fedora 14.</p>
<p>Your homework:</p>
<ul>
<li>How does it run for other MySQL engines such as MyISAM?</li>
<li>Can it handle a higher number like 1 million?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.answermysearches.com/mysql-is-there-a-limit-to-the-number-of-items-in-an-in-clause/2248/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Python Error &#8211; global name &#8216;r&#8217; is not defined</title>
		<link>http://www.answermysearches.com/python-error-global-name-r-is-not-defined/2244/</link>
		<comments>http://www.answermysearches.com/python-error-global-name-r-is-not-defined/2244/#comments</comments>
		<pubDate>Wed, 11 May 2011 16:35:37 +0000</pubDate>
		<dc:creator>Greg Pinero (Primary Searcher)</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.answermysearches.com/?p=2244</guid>
		<description><![CDATA[Avid Answer my searches reader Jody writes in with this strange error:
weird error here. Couldn&#8217;t find my error on google anywhere.  Might be rare.  The error is within the urllib2 library.  Not sure what happened.
python 2.7.0
active python install
Windows
urllib2.urlopen(r&#8217;http://www.google.com&#8217;)
url open gives &#8220;NameError: global name &#8216;r&#8217; is not defined&#8221;
Not sure what caused this.  [...]]]></description>
			<content:encoded><![CDATA[<p>Avid Answer my searches reader Jody writes in with this strange error:</p>
<blockquote><p>weird error here. Couldn&#8217;t find my error on google anywhere.  Might be rare.  The error is within the urllib2 library.  Not sure what happened.</p>
<p>python 2.7.0<br />
active python install<br />
Windows</p>
<p>urllib2.urlopen(r&#8217;http://www.google.com&#8217;)<br />
url open gives &#8220;NameError: global name &#8216;r&#8217; is not defined&#8221;</p>
<p>Not sure what caused this.  But repairing the python install didn&#8217;t fix it.  I had to uninstall/reinstall python to get this working again.  Upgraded to python 2.7.1 also.  </p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.answermysearches.com/python-error-global-name-r-is-not-defined/2244/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

