Re: [Tutor] How to normalize/compress whitespace in a string?

2008-04-11 Thread Alan Gauld
"Alan Gauld" <[EMAIL PROTECTED]> wrote > "Malcolm Greene" <[EMAIL PROTECTED]> wrote in message Oops, sorry. I hit the send button by mistake while aiming for the File menu! >> Any suggestions for how to normalize and compress whitespace in a >> string? >> I know I can use regular expressions

Re: [Tutor] How to normalize/compress whitespace in a string?

2008-04-11 Thread Alan Gauld
"Malcolm Greene" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Any suggestions for how to normalize and compress whitespace in a > string? > > By normalize I mean convert tabs and soft spaces (extended ascii > code > 160) to spaces. > > By compress I mean replace all runs of 2 or

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > As Python/pysqlite stores the items in the db.table as unicode > strings, I've also run the code with q=u"dog" but get the same > error. Same with putting the q as a tuple ie. (q) in the Select (q) is not a tuple, it is a variable surrounded by qu

Re: [Tutor] Old School

2008-04-11 Thread Kent Johnson
Dinesh B Vadhia wrote: > I belong to the Old School where getting my head around OO is just one > big pain. > I write software by modularization executed as a set of > functions - and it works (some call this functional programming!). Some are wrong. That style of programming is correctly cal

Re: [Tutor] Old School

2008-04-11 Thread Tim Golden
Dinesh B Vadhia wrote: > I belong to the Old School where getting my head around OO is just one big > pain. > I write software by modularization executed as a set of functions - > and it works The great thing about Python is that you can use Classes if you want, or not if you don't. I use them

Re: [Tutor] Old School

2008-04-11 Thread Kent Johnson
Dinesh B Vadhia wrote: > I belong to the Old School where getting my head around OO is just one > big pain. I write software by modularization executed as a set of > functions - and it works (some call this functional programming!). > Whenever I review Python books (eg. Lutz's excellent Progra

[Tutor] Old School

2008-04-11 Thread Dinesh B Vadhia
I belong to the Old School where getting my head around OO is just one big pain. I write software by modularization executed as a set of functions - and it works (some call this functional programming!). Whenever I review Python books (eg. Lutz's excellent Programming Python, 3ed) the code is

Re: [Tutor] How to normalize/compress whitespace in a string?

2008-04-11 Thread Kent Johnson
Malcolm Greene wrote: > Any suggestions for how to normalize and compress whitespace in a > string? > > By normalize I mean convert tabs and soft spaces (extended ascii code > 160) to spaces. > > By compress I mean replace all runs of 2 or more spaces (after the > normalization step) to a single

[Tutor] How to normalize/compress whitespace in a string?

2008-04-11 Thread Malcolm Greene
Any suggestions for how to normalize and compress whitespace in a string? By normalize I mean convert tabs and soft spaces (extended ascii code 160) to spaces. By compress I mean replace all runs of 2 or more spaces (after the normalization step) to a single space. I know I can use regular expre

Re: [Tutor] queries from the web & random number

2008-04-11 Thread Kent Johnson
linuxian iandsd wrote: > well, i can assure you i am not. simply because i have a > username/password for this site, plus, I have thier agreement to > automate the process of utilizing thier database all i want from > midnight to 6 am. Perhaps the supplier would give you an interface that does

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Tim Golden
Dinesh B Vadhia wrote: > Okay, I've got this now: > >> con = sqlite3.connect(":memory:") >> cur = con.cursor() >> cur.execute("""CREATE TABLE db.table(col.a integer, col.b text)""") >> con.executemany("""INSERT INTO db.table(col.a, col.b) VALUES (?, ?)""", m) >> con.commit() > >> for row in con.e

Re: [Tutor] queries from the web & random number

2008-04-11 Thread linuxian iandsd
i see no body has replied to my question, probably you are thinking this guy is hijicking someones website ? well, i can assure you i am not. simply because i have a username/password for this site, plus, I have thier agreement to automate the process of utilizing thier database all i want from mi

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Dinesh B Vadhia
Okay, I've got this now: > con = sqlite3.connect(":memory:") > cur = con.cursor() > cur.execute("""CREATE TABLE db.table(col.a integer, col.b text)""") > con.executemany("""INSERT INTO db.table(col.a, col.b) VALUES (?, ?)""", m) > con.commit() > for row in con.execute("""SELECT col.a, col.b FROM

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Steve Willoughby
Simone wrote: > In Python the symbol '%' in a string is a special char: you use it, for > instance, to place a variable inside a string. For completeness, it's worth mentioning in passing that % is only special when you're doing string formatting. It's not otherwise special in strings. > Howeve

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread linuxian iandsd
i forgot to mention that you need to try your sql commands out of your script before trying them inside, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread linuxian iandsd
I m not sure this is your case but i believe you are missing the "cur.fetchall()" command which does fetch data from sql db i suggest you put a print statement for every data you use in your program that way you know whats empty & whats not... here is example of MySQLdb process: con=MySQLdb.c

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Simone
Dinesh B Vadhia ha scritto: > The second problem is that I'm using the LIKE operator to match a > pattern against a string but am getting garbage results. For example, > looking for the characters q='dog' in each string the SELECT statement > is as follows: > > for row in con.execute("SELECT

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > I'm using the LIKE operator to match a pattern against a string > using this SELECT statement: > > for row in con.execute(" > SELECT > FROM > WHERE LIKE '%q%' > limit 25"): > With q="dog" as a test example, I've tried '$q%', '%q%', '%q' Ok,

[Tutor] Fw: SQLite LIKE question

2008-04-11 Thread Dinesh B Vadhia
Try again: I'm using the LIKE operator to match a pattern against a string using this SELECT statement: for row in con.execute("SELECT FROM WHERE LIKE '%q%' limit 25"): .. where , , are placeholders! With q="dog" as a test example, I've tried '$q%', '%q%', '%q' and 'q%' and none of the