Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Searching the values in a list for values of a list of mysql values

Posted on 2009-05-13
3
Medium Priority
?
255 Views
Last Modified: 2012-05-06
If it's not obvious from the code, I'm really new to Python, but I've some experience in JavaScript and PHP.  In my code I'm attempting to check the extensions of a list of files to see if they have a certain extension.  I know that I could use the glob module to create a list of only the files with the extensions, but I the extensions I'm looking for need to be taken from a mysql database.  This is a cgi script.  Anyways, when the extensions list is printed it prints like this:
(('aac',), ('aif',), ('ape',), ('flac',)
I'm getting an error message about my regular expression, which I'm not really sure about:
<class 'sre_constants.error'>: nothing to repeat
Can you point out the mistake in my logic and or syntax?
I'd also accept an alternative method that would achieve the same thing.
Thanks ahead of time.
#!C:\Python26\python.exe
print "Content-Type: text/html"
print 
import cgitb
import MySQLdb
import os
import re
 
cgitb.enable()
 
db = MySQLdb.connect('localhost', 'root', 'rootpass', 'ccs', 3307)
c=db.cursor()
 
extensions = []
c.execute("""SELECT ext FROM fileext WHERE filetypeid=2""")
extensions = c.fetchall()
print extensions
c.close()
 
#files
path = 'H:\\'
allfiles = []
for root,dir,files in os.walk(path):
	filelist = [os.path.join(root,fi) for fi in files]
	for f in filelist:
		for ext in extensions:
			if re.search(fi, str(ext)):
				dbCheck(fi)
				break
 
def dbCheck(file):
	print file
	filesize = os.stat(file).st_size
	c=db.cursor()
	c.execute("""SELECT*FROM musicfiles WHERE (filepath, filesize) = (%s, %s)""", (file, filesize,))
	row = c.fetchone()
	if(row):
		print row
	else:
		print "No matches."
 
print "<title>Scan Music Folders</title>"

Open in new window

0
Comment
Question by:khsater
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 2000 total points
ID: 24381443
Shouldn't that be:

if re.search(str(ext), fi):
0
 
LVL 4

Author Closing Comment

by:khsater
ID: 31581300
Wow, that's really embarrassing.  I was looking right at the manual when I typed that.
Thanks!
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24381456
:) glad to help, sometimes you just need that 2nd set of eyes!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question