Re: help to install MySQL-python module
On 6/7/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dear python users, I have an account on a Linux Cluster. I installed python version 2.3.5 on my account. I need to install the module MySQL-python to interact with a MySQL server already installed on the cluster. However, I read the README file but running python setup.py build the system fails to build the module and gives me the following error: error: invalid Python installation: unable to open /usr/local/lib/python2.3/config/Makefile (No such file or directory) How can I solve this problem? Thank you in advance Ernesto Ernesto, Where did the install put Python - the obvious situation is that the Makefile is not where the install of MySQL-Python thinks it is. Lou -- Artificial Intelligence is no match for Natural Stupidity -- http://mail.python.org/mailman/listinfo/python-list
Re: Expanding Search to Subfolders
On 5 Jun 2006 10:01:06 -0700, PipedreamerGrey [EMAIL PROTECTED] wrote: This is the beginning of a script that I wrote to open all the text files in a single directory, then process the data in the text files line by line into a single index file. os.chdir(C:\\Python23\\programs\\filetree) mydir = glob.glob(*.txt) index = open(index.rtf, 'w') for File in mydir: count = 1 file = open(File) fileContent = file.readlines() for line in fileContent: if not line.startswith(\n): if count == 1: I'm now trying to the program to process all the text files in subdirectories, so that I don't have to run the script more than once. I know that the following script will SHOW me the contents of the subdirectories, but I can't integrate the two: def print_tree(tree_root_dir): def printall(junk, dirpath, namelist): for name in namelist: print os.path.join(dirpath, name) os.path.walk(tree_root_dir, printall, None) print_tree(C:\\Python23\\programs\\filetree) I've taught myself out of online tutorials, so I think that this is a matter of a command that I haven't learned rather a matter of logic. Could someone tell me where to learn more about directory processes or show me an improved version of my first script snippet? Thanks -- http://mail.python.org/mailman/listinfo/python-list How about something like: import os, stat class DirectoryWalker: # a forward iterator that traverses a directory tree, and # returns the filename def __init__(self, directory): self.stack = [directory] self.files = [] self.index = 0 def __getitem__(self, index): while 1: try: file = self.files[self.index] self.index = self.index + 1 except IndexError: # pop next directory from stack self.directory = self.stack.pop() self.files = os.listdir(self.directory) self.index = 0 else: # got a filename fullname = os.path.join(self.directory, file) if os.path.isdir(fullname) and not os.path.islink(fullname): self.stack.append(fullname) else: return fullname for file, st in DirectoryWalker(.): your function here not tested Lou -- Artificial Intelligence is no match for Natural Stupidity -- http://mail.python.org/mailman/listinfo/python-list
Re: creating a new database with mysqldb
On 5/17/06, Philippe Martin [EMAIL PROTECTED] wrote: John Salerno wrote: Since the connect method of mysqldb requires a database name, it seems like you can't use it without having a database already created. So is there a way to connect to your mysql server (without a specified database) in order to create a new database (i.e., the CREATE DATABASE query)? Thanks.I'm no expert but: can't you spawn mysql with a script/scheme ?Philippe MySQLdb.connect does not require a database name. ie.: import MySqlDB db = MySQLdb.connect(host='localhost', user='root', passwd='') csr = db.cursor () csr.execute('''show databases''')6L for d in csr.fetchall(): print d('cc',)('cc_41',)('mysql',)('purchaseorder',)('test',)('xsldb',) csr.execute('''create database newdb''')1L csr.execute('''show databases''')7L for d in csr.fetchall(): print d('cc',)('cc_41',)('mysql',)('newdb',)('purchaseorder',) ('test',)('xsldb',) Later,Lou-- Artificial Intelligence is no match for Natural Stupidity -- http://mail.python.org/mailman/listinfo/python-list
Re: Aggregate funuctions broken in MySQLdb?
Try these:http://sourceforge.net/docman/?group_id=22307and for the Python DB API overall:http://www.python.org/dev/peps/pep-0249/ LouOn 5/15/06, Lorenzo Thurman [EMAIL PROTECTED] wrote: Thanks, that was my problem. Can you point me to some documentation onMySQLdb? I've been googling to get answers and that obviously has notbeen working.In article [EMAIL PROTECTED], Wade Leftwich [EMAIL PROTECTED] wrote: Works fine for me, and I certainly hope MySQLdb is ready for prime time, because I use the heck out of it. Maybe you're getting fooled by the fact that cursor.execute() returns the count of result rows. To actually see the result rows, you have to say cursor.fetchone () or fetchall() -- In [34]: cur.execute(select article_id from articles limit 10) Out[34]: 10L In [35]: cur.fetchall() Out[35]: ((3L,), (4L,), (5L,), (6L,), (7L,), (8L,), (9L,), (10L,), (11L,), (12L,)) In [36]: cur.execute(select count(article_id) from articles where article_id 13) Out[36]: 1L In [37]: cur.fetchall() Out[37]: ((10L,),) In [38]: cur.execute(select sum(article_id) from articles where article_id 13) Out[38]: 1L In [39]: cur.fetchone() Out[39]: (75.0,) In [40]: cur.execute(select avg(article_id) from articles where article_id 13) Out[40]: 1L In [41]: cur.fetchone() Out[41]: (7.5,)-- http://mail.python.org/mailman/listinfo/python-list-- Artificial Intelligence is no match for Natural Stupidity -- http://mail.python.org/mailman/listinfo/python-list
Re: where do you run database scripts/where are DBs 'located'?
On 5/13/06, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Fri, 12 May 2006 21:00:49 -0400, John Salerno[EMAIL PROTECTED] declaimed the following in comp.lang.python: Latest development: I turned off my firewall and it worked. :) Next step -- figure out what rule you need to define to the firewallto permit it to work...--WulfraedDennis Lee Bieber KD6MOG [EMAIL PROTECTED] [EMAIL PROTECTED]HTTP://wlfraed.home.netcom.com/(Bestiaria Support Staff: [EMAIL PROTECTED])HTTP://www.bestiaria.com/-- http://mail.python.org/mailman/listinfo/python-listThe default port that the MySQL server listens on is 3306. This can be changed during install.-- Artificial Intelligence is no match for Natural Stupidity -- http://mail.python.org/mailman/listinfo/python-list
Re: Gettings subdirectories
import os.pathos.path.isdir(file)LouOn 5/4/06, Philippe Martin [EMAIL PROTECTED] wrote: Hi,The second edition of Programming Python - O'REILLY - Mark Lutz shows how to do that using os.path.walkPhilippeFlorian Lindner wrote: Hello, how can I get all subdirectories of a given directories? os.listdir() gives me all entries and I've found no way to tell if an object is a file or a directory. Thanks, Florian--http://mail.python.org/mailman/listinfo/python-list -- Artificial Intelligence is no match for Natural Stupidity -- http://mail.python.org/mailman/listinfo/python-list
Re: os.startfile() - one or two arguments?
On 28 Apr 2006 08:06:02 -0700, BartlebyScrivener [EMAIL PROTECTED] wrote: Can any Windows user give a working example of adding a command verbto os.startfile()?When I try it, it squawks that it takes only one argument. os.startfile('d:/','explore') ry: os.startfile([d:/, explore]) you want a list for the args Traceback (most recent call last):File interactive input, line 1, in ? TypeError: startfile() takes exactly 1 argument (2 given)from os modulestartfile(path[, operation])Start a file with its associated application.When operation is not specified or 'open', this acts like double-clicking the file in Windows Explorer, or giving the file nameas an argument to the start command from the interactive command shell:the file is opened with whatever application (if any) its extension is associated.When another operation is given, it must be a ``command verb'' thatspecifies what should be done with the file. Common verbs documented byMicrosoft are 'print' and 'edit' (to be used on files) as well as 'explore' and 'find' (to be used on directories).Thanks,rpdGive a man a fire and keep him warm for a day. Light a man on fire andhe will be warm for rest of his life. --Terry Pratchett --http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: an error in commented code?
Hmmm, runs fine for me:IDLE 1.1.3 RESTART C wins:['B', 'D', 'A', 'C']C wins:['D', 'B', 'A', 'C'] When I pasted your code the last line was 58On 4/28/06, John Salerno [EMAIL PROTECTED] wrote:Here's my code, with the error following it:props = ['A', 'B', 'C', 'D'] group1 = ['C', 'A', 'D', 'B', 17]group2 = ['A', 'B', 'D', 'C', 32]group3 = ['D', 'B', 'C', 'A', 34]group4 = ['B', 'A', 'C', 'D', 17]# Submitter: Michael Daviesdef all_perms(str): if len(str) =1: yield str else: for perm in all_perms(str[1:]): for i in range(len(perm)+1): #nb str[0:1] works in both string and list contexts yield perm[:i] + str[0:1] + perm[i:] def checkOrder(x, y): x_votes = 0 y_votes = 0 if group1.index(x) group1.index(y): x_votes += group1[4] else: y_votes += group1[4] if group2.index (x) group2.index(y): x_votes += group2[4] else: y_votes += group2[4] if group3.index(x) group3.index(y): x_votes += group3[4] else: y_votes += group3[4] if group4.index(x) group4.index(y): x_votes += group4[4] else: y_votes += group4[4] if x_votes y_votes: return x else: return y for order in all_perms(props):# if reduce(checkOrder, order) == 'A':# print 'A wins:'# print order# if reduce(checkOrder, order) == 'B':# print 'B wins:'# print order if reduce(checkOrder, order) == 'C': print 'C wins:' print order# if reduce(checkOrder, order) == 'D':# print 'D wins:'# print order *** Error in script or command! Traceback (most recent call last): File C:\Python24\myscripts\ecco\1-1-1.py, line 60 # print order ^SyntaxError: invalid syntax Line 60 also happens to be the very last line, which is commented. I'vetried a couple of different things to see if it's a whitespace problem,but it doesn't seem to be. I'm just confused why it detects an error in the commented code anyway.Thanks.--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list