[Tutor] unicode to plain text conversion

Pirritano, Matthew MPirritano at ochca.com
Tue Apr 7 00:48:05 CEST 2009


Hello python people,

I am a total newbie. I have a very large file > 4GB that I need to
convert from Unicode to plain text. I used to just use dos when the file
was < 4GB but it no longer seems to work. Can anyone point me to some
python code that might perform this function?

Thanks
Matt

Matthew Pirritano, Ph.D.
Research Analyst IV
Medical Services Initiative (MSI)
Orange County Health Care Agency
(714) 568-5648


-----Original Message-----
From: tutor-bounces+mpirritano=ochca.com at python.org
[mailto:tutor-bounces+mpirritano=ochca.com at python.org] On Behalf Of
AdamC
Sent: Monday, April 06, 2009 12:31 AM
To: Python Tutor
Subject: [Tutor] Checking for string in a list strangeness

I'm writing a small cgi application for children to use and I want to
check that the name they enter isn't a swear word.

I've populated a database with a swear word list and then check this
list against the input, but it always shows up as not being a swear
word.

Can anyone see why this would always throw up FALSE, even if I supply
a word which is in the list?
TIA
Adam

Code (with some of my debugging - so this is not the finished article).

#!/usr/bin/env python
from random import *
from cgi import *
import cgitb; cgitb.enable()
import string
import MySQLdb
print "Content-type: text/html\n\n"
try:
    connection =
MySQLdb.connect(host="learningtimes.db",user="adcripps",
passwd="ed3oq3zu", db="times")
except MySQLdb.Error, e:
    print "Error %d %s" %(e.args[0], e.args[1])
    sys.exit(1)
mycursor = connection.cursor()
print """<h1>Join the game</h1>"""

print """<form action = "join.py" method=get>
            <input type = text name = "team" />
            <input type = "Submit" value="Join" />
            """
#Popluate my swear word list from the db.
mycursor.execute("select badword from badwords")
myrowcount = int(mycursor.rowcount)
swearlist = []
for i in range (0, myrowcount):
    myrow = mycursor.fetchone()
    swearlist.append(str(myrow))

team = FieldStorage()

#Need some kind of swear checker here.

#for i in swearlist:       # shows swear list OK
#    print i;

checkteam = team.getvalue('team')
#print """<p>"""+str (checkteam) + """</p>""";           # this works OK
#print str(swearlist)
    # As does this

print "name = " + str(team.getvalue('team'))
if str(team.getvalue('team')) in swearlist:                 # This is
fail!
    print "swearing"
else:
    print "not swearing"
if team.getvalue('team'):
    if team.getvalue('team') in swearlist:                    #This
also is fail.
        print "swear"
        sys.exit(0)
    else:
        print "no swear"
        team = team.getvalue('team')
        statement = """insert into pupil (nickname, points, played,
morepoints, moreplayed, footballteam) values ('""" + team + """',
0,0,0,0,0)"""
        mycursor.execute(statement)
        print """<br />You have now joined.<br /><a
href="/times/football/football.py">You should now support a
team.</a>"""

# disconnect the database
mycursor.close()
connection.close()

--
You back your data up on the same planet?
http://www.monkeez.org
PGP key: 0x7111B833
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list