conn.execute(“””insert into %s (a, b, c, d) values(%%s, %%s, %%s, %%s)””” %tablename,(a, b, c, d))
conn.execute(“””insert into %s (a, b, c, d) values(%%s, %%s, %%s, %%s)””” %tablename,(a, b, c, d))
I just compiled and installed mysqldb for python 2.7 on my mac os 10.7. import MySQLdb as mysql def main(): conn = mysql.connect( charset=”utf8″, use_unicode=True, host=”localhost”,user=”root”, passwd=””,db=”” ) if __name__ == ‘__main__'(): main() When executing it I get the following error message Traceback (most recent call last): File “/path/to/project/Python/src/cvdv/TestMySQLdb.py”, line 4, in import MySQLdb as
There are cases when you keep downloading files repeatedly, in your download folder. But fail to delete it. This happens when you are testing something or looking at files repeatedly. To fix this, this app basically can be run, which deletes your files at regular intervals. Git repository: git clone https://bitbucket.org/kmdarshan/spaceclaimer.git
I know they must be thousands of programs to do this, but just thought i would give it a try. Its pretty easy. I will keep editing this as and when I improve my regular expression to do this. import urllib as ulimport BeautifulSoup as bsimport re myFile = ul.urlopen(http://www.sfbay.craigslist.org/roo/)soup = bs.BeautifulSoup(myFile)#print soup.prettify()for anchor in
When I was researching about downloading pages and all content from a website. I got this crawler..its very simple. and you need to take a look at it. Its real cool and simple. http://code.google.com/p/harvestman-crawler/wiki/WorldsSimplestCrawler windows user if you have cygwin installed it would be helpful.
LJS93K 1300 10500J38ZZ9 700 4750 What do you do when you have multiple spaces but not constant spaces in between words. You could you split in python but what that does is either strips all spaces or gives you a single space for each space found. this wouldnt be want you wanted. So you could
This is a small script I wrote to extract all posts from my blogger which was in the form a xml or aton feed and insert into a wordpress database. import feedparser import re d = feedparser.parse(“C:\Python25\programs\blog.xml”) count = len(d[‘entries’]) loopVar = 0 p = re.compile(r'[‘”]’) mainInsertString = “INSERT INTO `wp_posts` (`ID`, `post_author`,” s2 =
I wrote this script to replace all carriage return and tab in my wordpress database and put it in a PHP page. import MySQLdb conn = MySQLdb.connect (host = “localhost”, user = “root”, passwd = “”, db = “test”) cursor = conn.cursor () cursor.execute (“SELECT post_title,post_content FROM wp_posts”) rows = cursor.fetchall () cnt =0 for
My 0.02C that a novice facebook developers need to do, when developing a new application is look at this console given by facebook itself. the links are below: http://developers.facebook.com/tools.php Basically the above has both php and XML links for developers to easily develop. Attaching a screenshot below:
I was having a tough time downloading some 100 files continuously. It always used to timeout and then I had to start the script again. So I did the following: while(1): try: fh = urllib.urlopen(www.yahoo.com) var2=1 except: print “THIS IS BAD1” var2 = 0 if(var2==1): break
We use doctest to check whether a written method is giving the correct output or to check for the docstrings for interactive examples or for regression testing or to write documentation. Consider this example def multiplyTwoNumbers(a,b): product = a*b return product this method is used for multiplying two numbers. But there is no way to
The best way to insert values into a database using MySQLDB would be to simply use ‘%s’. This placeholder does all the work on conversion into other data types. You dont need to worry about converting any values into their respective datatypes in mysql.
Of the many ways to inset values into a MySQL database, we could use the below also: insert_query = “INSERT INTO %s(symbol, date,open,high,low,close,volume) VALUES( %s,%s, %s , %s , %s , %s, %s )” insert_cursor.execute(insert_query %(symbol_Nasdaq, symbol_Nasdaq, row_Nasdaq[0], row_Nasdaq[1], row_Nasdaq[2], row_Nasdaq[3], row_Nasdaq[4], volume_fin)) The above query will most likely give you an error stating the
More than once I seem to have done this mistake. The situation is like this. I was inserting some elements into a database at irregular intervals. I needed to know that I dont insert duplicate symbols. So I was wrote a small method to check this. The below code is not exactly the same method,
when trying to run a query in mysqldb from python I was getting the error 11001. the best option would be run the query as below: conn = ms.connect(host=”localhost”,port=3307, user = “root”, passwd = “”, db = “xxx”) This error would be seen because I changed the port when I was installing MySql. So when
try dividing 10/100 in python. You get 0. you can do this 1/2. You get 0. This is not an error. Python is like this. You can refer here http://www.python.org/doc/2.2.3/whatsnew/node7.html for more details. To rectify this you can do the following: import __future__ import division This will return the floating point results.
A simple and effective way to read a xml using the DOM parser in python is shown below:Sample example XML: Hello World. Python program to print the XML: #import the dom from the xml folder.from xml.dom import minidomxmldoc = minidom.parse(Greeting.xml)#print the xml in the command promptprint xmldoc.toxml()
Suppose you have a below class in python: class Complex: def __init__(self, realpart, imagpart): self.r = realpart self.i = imagpart >>> x = Complex(3.0, -4.5) What happens? Even though you have not given the arguments for the class, the arguments get initialized to the default constructor.Therefore 3.0 and -4.5 will be set to realpart and
I was reading this book dive into python and thought this would be helpful. So..When defining your class methods, you must explicitly list self as the first argument for each method, including __init__. When you call a method of an ancestor class from within your class, you must include the self argument. But when you
1) Goto to http://twistedmatrix.com/trac/wiki/Downloads and download the pycrypto package .exe for windows/python2.5. This is needed for running paramiko. 2) Next, download the paramiko package from http://www.lag.net/paramiko/. 3) Unzip paramiko to a temporary folder, better if you unzip it to the folder where python is installed. 4) Go into the folder for paramiko. 5) Open command
Now this part is very easy. You just need to follow the signs of Inno Setup. At first download the executable from Inno Setup. Then go and click on the new setup script. A wizard opens up. Over there you got select the .exe you created in the previous post, and then select all the
1) Goto www.py2exe.org. download the package and install it. Even though you cannot see the installed py2exe in the startup folder, it gets stored whereever python is installed. 2) Next you would have to get your setup file ready to prepare the exe.Below is the setup.py file. You would have to edit according to your
First of all, download the rarfile.py from http://grue.l-t.ee/~marko/src/rarfile/README.html. This python program contains all the classes and methods to handle a .rar file. Download it and save it in the LIB folder. # check if it is rarfile where f is a file if tarfile.is_rarfile(f): # if it is a rar file then open the file
Recently, I was developing a tool for my own use which could help me find a keyword in a heap of files based on the keyword importance,date modified and so on. I was developing this tool to increase my own productivity, so that I could find the keywords I need, and then deploy the files
I was trying to insert values into a table from a blog post. Problem code: filehandle.write(“, 1, ‘2009-06-03 17:11:58’, ‘2009-06-03 17:11:8’,’”) e = d.entries[val] content = e.content[0].value #print content filehandle.write(str(content)) Issue: Since we are trying to write a junk value in to a file, and this is not ascii supported we get the below error.
Being a bit of code crazy guy, I am, i found it would be foolish to go to each and every post in my blog and choose File -> Save as option. So..just a hack/or anything you want to call it. Download and configure HarvestMan from http://code.google.com/p/harvestman-crawler/wiki/WorldsSimplestCrawler. Now just replace the URL in the tutorial
I just wrote this small code snippet to read a rss/xml/atom using the feedparser library. Hope you might find it useful. I read from the XML, which is my feed and then write to file which represents a SQL query for easy insertion into a DB> import feedparser d = feedparser.parse(“blog.xml”) print d[‘feed’][‘title’] total_len =
Here is script to download images, from a website. I have taken the example of zune.net to download the images to my local disk. you can alter it as you please: import sgmllib import re class MyParser(sgmllib.SGMLParser): A simple parser class. def parse(self, s): Parse the given string s. self.feed(s) self.close() def __init__(self, verbose=0): Initialise