Re: zenity substitution

2018-10-28 Thread Bob Gailer
On Oct 28, 2018 10:17 PM, "listo factor via Python-list" < python-list@python.org> wrote: > > Hi all, > I'm new to Python, but not to programming. > > As a teaching exercise, I am converting a bunch of bash shell > scripts to Python, so that they can be run on all three OS-es > (Linux, Windows, Mac

zenity substitution

2018-10-28 Thread listo factor via Python-list
Hi all, I'm new to Python, but not to programming. As a teaching exercise, I am converting a bunch of bash shell scripts to Python, so that they can be run on all three OS-es (Linux, Windows, MacOS). The scripts in questions make extensive use of Linux "zenity" dialogs. Is there an equivalent f

Re: Manual parameter substitution in sqlite3

2017-03-02 Thread Tim Chase
On 2017-03-02 09:55, Christian Gollwitzer wrote: > you could do it "the (theoretical) right way", which is using > another table. Insert your keys into a table, maybe temporary one, > and then do > > select * from mumble where key in (select key from keytable) > > In theory that should also be fa

Re: Manual parameter substitution in sqlite3

2017-03-02 Thread Christian Gollwitzer
Am 28.02.17 um 18:28 schrieb Skip Montanaro: Most of the time (well, all the time if you're smart), you let the database adapter do parameter substitution for you to avoid SQL injection attacks (or stupid users). So: curs.execute("select * from mumble where key = ?", (key,))

Re: Manual parameter substitution in sqlite3

2017-03-01 Thread Serhiy Storchaka
On 28.02.17 19:28, Skip Montanaro wrote: Most of the time (well, all the time if you're smart), you let the database adapter do parameter substitution for you to avoid SQL injection attacks (or stupid users). So: curs.execute("select * from mumble where key = ?", (key,))

Re: Manual parameter substitution in sqlite3

2017-02-28 Thread Tim Chase
On 2017-03-01 04:40, Chris Angelico wrote: > curs.execute("select * from mumble where key in (" + > ",".join(["?"]*len(keys)) + ")", keys) > > If this is combined with another parameter, it'd be messier, but you > could do something like: > > curs.execute("select * from mumble where key in (" + >

Re: Manual parameter substitution in sqlite3

2017-02-28 Thread Neil Cerutti
On 2017-02-28, Skip Montanaro wrote: > Some database adapters provide a function to do explicit > substitution (e.g., mySQLdb.escape, psycopg2._param_escape), > but the sqlite3 adapter doesn't. It's clunky but you can use sqlite's core "quote" function.

Re: Manual parameter substitution in sqlite3

2017-02-28 Thread Skip Montanaro
On Tue, Feb 28, 2017 at 12:42 PM, Chris Angelico wrote: > That isn't what you were doing in your post, so it seemed worth > mentioning. Sorry, my original post was a bit abbreviated. I can't copy text from inside to outside, so have to retype everything. I guess I missed that. S -- https://mail

Re: Manual parameter substitution in sqlite3

2017-02-28 Thread Chris Angelico
On Wed, Mar 1, 2017 at 5:40 AM, Skip Montanaro wrote: > On Tue, Feb 28, 2017 at 11:40 AM, Chris Angelico wrote: >> Testing with PostgreSQL (which *does* transform lists) suggests that >> "in" doesn't work; I used "key = any(%s)". I'd try that with sqlite3 >> first, just in case it makes a differe

Re: Manual parameter substitution in sqlite3

2017-02-28 Thread Skip Montanaro
On Tue, Feb 28, 2017 at 11:40 AM, Chris Angelico wrote: > Testing with PostgreSQL (which *does* transform lists) suggests that > "in" doesn't work; I used "key = any(%s)". I'd try that with sqlite3 > first, just in case it makes a difference. Probably it won't, but > worth a try. Yeah, doesn't wo

Re: Manual parameter substitution in sqlite3

2017-02-28 Thread Peter Otten
Skip Montanaro wrote: > Most of the time (well, all the time if you're smart), you let the > database adapter do parameter substitution for you to avoid SQL > injection attacks (or stupid users). So: > > curs.execute("select * from mumble where key = ?", (key

Re: Manual parameter substitution in sqlite3

2017-02-28 Thread Chris Angelico
On Wed, Mar 1, 2017 at 4:28 AM, Skip Montanaro wrote: > Some database adapters provide a function to do explicit substitution > (e.g., mySQLdb.escape, psycopg2._param_escape), but the sqlite3 > adapter doesn't. Is there a function floating around out there which > does the righ

Manual parameter substitution in sqlite3

2017-02-28 Thread Skip Montanaro
Most of the time (well, all the time if you're smart), you let the database adapter do parameter substitution for you to avoid SQL injection attacks (or stupid users). So: curs.execute("select * from mumble where key = ?", (key,)) If you want to select from several possible ke

Re: Regular expression and substitution, unexpected duplication

2015-08-19 Thread Laurent Pointal
MRAB wrote: > On 2015-08-18 22:42, Laurent Pointal wrote: >> Hello, >> ellipfind_re = re.compile(r"((?=\.\.\.)|…)", re.IGNORECASE|re.VERBOSE) >> ellipfind_re.sub(' ... ', >> "C'est un essai... avec différents caractères… pour voir.") > (?=...) is a lookahead; a non-capture group is (?:..

Re: Regular expression and substitution, unexpected duplication

2015-08-18 Thread MRAB
On 2015-08-18 22:42, Laurent Pointal wrote: Hello, I want to make a replacement in a string, to ensure that ellipsis are surrounded by spaces (this is not a typographycal problem, but a preparation for late text chunking). I tried with regular expressions and the SRE_Pattern.sub() method, but I

Regular expression and substitution, unexpected duplication

2015-08-18 Thread Laurent Pointal
Hello, I want to make a replacement in a string, to ensure that ellipsis are surrounded by spaces (this is not a typographycal problem, but a preparation for late text chunking). I tried with regular expressions and the SRE_Pattern.sub() method, but I have an unexpected duplication of the repl

Re: Regex substitution trouble

2014-11-05 Thread Eugene
massi_...@msn.com wrote: > Hi everyone, > > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) > Here is the problem, I'm trying to write a regex in order to substitute > all the occurences in the form $"

Re: Regex substitution trouble

2014-10-28 Thread Cameron Simpson
On 28Oct2014 04:02, massi_...@msn.com wrote: I'm not really sure if this is the right place to ask about regular expressions, but since I'm usin python I thought I could give a try :-) Here is the problem, I'm trying to write a regex in order to substitute all the occurences in the form $"some

Re: Regex substitution trouble

2014-10-28 Thread MRAB
On 2014-10-28 12:28, massi_...@msn.com wrote: Hi Chris, thanks for the reply. I tried to use look ahead assertions, in particular I modified the regex this way: newstring = re.sub(ur"""(?u)(\$\"[\s\w(?<=\\)\"]+\")""", subst, oldstring) but it does not work. I'm absolutely not a regex guru so I

Re: Regex substitution trouble

2014-10-28 Thread Tim
On Tuesday, October 28, 2014 7:03:00 AM UTC-4, mass...@msn.com wrote: > Hi everyone, > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) > Here is the problem, I'm trying to write a regex in order to substi

Re: Regex substitution trouble

2014-10-28 Thread TP
On Tue, Oct 28, 2014 at 4:02 AM, wrote: > Hi everyone, > > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) > Here is the problem, I'm trying to write a regex in order to substitute > all the occurences i

Re: Regex substitution trouble

2014-10-28 Thread Chris Angelico
(Please quote enough of the previous text to provide context, and write your replies underneath the quoted text - don't assume that everyone's read the previous posts. Thanks!) On Tue, Oct 28, 2014 at 11:28 PM, wrote: > Hi Chris, thanks for the reply. I tried to use look ahead assertions, in >

Re: Regex substitution trouble

2014-10-28 Thread massi_srb
Hi Chris, thanks for the reply. I tried to use look ahead assertions, in particular I modified the regex this way: newstring = re.sub(ur"""(?u)(\$\"[\s\w(?<=\\)\"]+\")""", subst, oldstring) but it does not work. I'm absolutely not a regex guru so I'm surely missing something. The strings I'm d

Re: Regex substitution trouble

2014-10-28 Thread Chris Angelico
On Tue, Oct 28, 2014 at 10:02 PM, wrote: > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) Yeah, that sort of thing is perfectly welcome here. Same with questions about networking in Python, or file I/

Regex substitution trouble

2014-10-28 Thread massi_srb
Hi everyone, I'm not really sure if this is the right place to ask about regular expressions, but since I'm usin python I thought I could give a try :-) Here is the problem, I'm trying to write a regex in order to substitute all the occurences in the form $"somechars" with another string. This i

Re: extracting string.Template substitution placeholders

2014-01-17 Thread Mark Lawrence
On 17/01/2014 06:07, gmflanagan wrote: On Sunday, January 12, 2014 3:08:31 PM UTC, Eric S. Johansson wrote: As part of speech recognition accessibility tools that I'm building, I'm using string.Template. In order to construct on-the-fly grammar, I need to know all of the identifiers before the

Re: extracting string.Template substitution placeholders

2014-01-16 Thread gmflanagan
On Sunday, January 12, 2014 3:08:31 PM UTC, Eric S. Johansson wrote: > As part of speech recognition accessibility tools that I'm building, I'm > > using string.Template. In order to construct on-the-fly grammar, I need > > to know all of the identifiers before the template is filled in. what i

Re: extracting string.Template substitution placeholders

2014-01-14 Thread Eric S. Johansson
On 1/13/2014 2:24 AM, Steven D'Aprano wrote: On Sun, 12 Jan 2014 10:08:31 -0500, Eric S. Johansson wrote: Now just walk the template for $ signs. Watch out for $$ which escapes the dollar sign. Here's a baby parser: found a different way import string cmplxstr="""a simple $string a longer $s

Re: extracting string.Template substitution placeholders

2014-01-12 Thread Steven D'Aprano
On Sun, 12 Jan 2014 10:08:31 -0500, Eric S. Johansson wrote: > As part of speech recognition accessibility tools that I'm building, I'm > using string.Template. In order to construct on-the-fly grammar, I need > to know all of the identifiers before the template is filled in. what is > the best wa

extracting string.Template substitution placeholders

2014-01-12 Thread Eric S. Johansson
As part of speech recognition accessibility tools that I'm building, I'm using string.Template. In order to construct on-the-fly grammar, I need to know all of the identifiers before the template is filled in. what is the best way to do this? can string.Template handle recursive expansion i.e.

Re: Embedding a for inside an html template for substitution

2013-03-05 Thread Roland Koebler
Hi, On Mon, Mar 04, 2013 at 09:22:38AM -0800, Ferrous Cranus wrote: > can i just put the liens you provided me inside "files.html" and thwy > will work? > > Thats pure pythjon code! There are several template-engines where you more or less include python-code into the template, e.g.: empy, mako,

Re: Embedding a for inside an html template for substitution

2013-03-04 Thread nagia . retsina
Τη Δευτέρα, 4 Μαρτίου 2013 5:14:00 μ.μ. UTC+2, ο χρήστης Νίκος Γκρ33κ έγραψε: > Hello pythonistas! > > > > I'am tryign to populate a table with dictionary keys and values: > > > > Foe that iam using an html template and the questions is what i should write > inside 'files.html' so then then

Re: Embedding a for inside an html template for substitution

2013-03-04 Thread Michael Torrie
On 03/04/2013 01:06 PM, Ferrous Cranus wrote: > What do you advise me to do? > Generate html via python code like print '''stuf..''' or use an > html templating system? > Up until now i was using the first method and i though it would be a > nice idea to seperate design from code. > > But p

Re: Embedding a for inside an html template for substitution

2013-03-04 Thread Ferrous Cranus
Τη Δευτέρα, 4 Μαρτίου 2013 5:59:34 μ.μ. UTC+2, ο χρήστης Michael Torrie έγραψε: > On 03/04/2013 08:14 AM, Ferrous Cranus wrote: > > > Instead of writing the above html data inside my html template how > > > would i write it with a for that then will be substituted by the > > > python script? >

Re: Embedding a for inside an html template for substitution

2013-03-04 Thread Michael Torrie
On 03/04/2013 08:14 AM, Ferrous Cranus wrote: > Instead of writing the above html data inside my html template how > would i write it with a for that then will be substituted by the > python script? What templating system are you using? Django's? > can you please write an example for me that use

Embedding a for inside an html template for substitution

2013-03-04 Thread Ferrous Cranus
Hello pythonistas! I'am tryign to populate a table with dictionary keys and values: Foe that iam using an html template and the questions is what i should write inside 'files.html' so then then the python script populate the table. SuperHost - Economy Χώρος στο δίσκο: 1 GB

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-18 Thread jkn
Hi Hans [...] > > > However, once he does that, it's simpler to cut out xargs and invoke > > "sh" directly. Or even cut out "sh" and "test" and instead use > > os.path.isfile and then call md5sum directly. And once he does that, > > he no longer needs to worry about single quotes. > Yes i

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-14 Thread Hans Mulder
On 13/11/12 22:36:47, Thomas Rachel wrote: > Am 12.11.2012 19:30 schrieb Hans Mulder: > >> This will break if there are spaces in the file name, or other >> characters meaningful to the shell. If you change if to >> >> xargsproc.append("test -f '%s/{}'&& md5sum '%s/{}'" >>

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-13 Thread Thomas Rachel
Am 12.11.2012 19:30 schrieb Hans Mulder: This will break if there are spaces in the file name, or other characters meaningful to the shell. If you change if to xargsproc.append("test -f '%s/{}'&& md5sum '%s/{}'" % (mydir, mydir)) , then it will only bre

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-13 Thread Thomas Rachel
Am 09.11.2012 02:12 schrieb Hans Mulder: That's what 'xargs' will do for you. All you need to do, is invoke xargs with arguments containing '{}'. I.e., something like: cmd1 = ['tar', '-czvf', 'myfile.tgz', '-c', mydir, 'mysubdir'] first_process = subprocess.Popen(cmd1, stdout=subprocess.PIPE)

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread jkn
Hi Hans [...] > > >         xargsproc.append("test -f %s/{} && md5sum %s/{}" % (mydir, > > mydir)) > > This will break if there are spaces in the file name, or other > characters meaningful to the shell.  If you change if to > >         xargsproc.append("test -f '%s/{}' && md5sum '%s/{}'" >      

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread Hans Mulder
On 12/11/12 18:22:44, jkn wrote: > Hi Hans > > On Nov 12, 4:36 pm, Hans Mulder wrote: >> On 12/11/12 16:36:58, jkn wrote: >> >> >> >> >> >> >> >> >> >>> slight followup ... >> >>> I have made some progress; for now I'm using subprocess.communicate to >>> read the output from the first subprocess,

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread jkn
Hi Hans On Nov 12, 4:36 pm, Hans Mulder wrote: > On 12/11/12 16:36:58, jkn wrote: > > > > > > > > > > > slight followup ... > > > I have made some progress; for now I'm using subprocess.communicate to > > read the output from the first subprocess, then writing it into the > > secodn subprocess. T

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread jkn
On Nov 12, 4:58 pm, Rebelo wrote: > Dana četvrtak, 8. studenoga 2012. 19:05:12 UTC+1, korisnik jkn napisao je: > > > Hi All > > >     i am trying to build up a set of subprocess.Ponen calls to > > > replicate the effect of a horribly long shell command. I'm not clear > > > how I can do one part of

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread Rebelo
Dana četvrtak, 8. studenoga 2012. 19:05:12 UTC+1, korisnik jkn napisao je: > Hi All > > i am trying to build up a set of subprocess.Ponen calls to > > replicate the effect of a horribly long shell command. I'm not clear > > how I can do one part of this and wonder if anyone can advise. I'm o

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread Hans Mulder
On 12/11/12 16:36:58, jkn wrote: > slight followup ... > > I have made some progress; for now I'm using subprocess.communicate to > read the output from the first subprocess, then writing it into the > secodn subprocess. This way I at least get to see what is > happening ... > > The reason 'we' w

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread jkn
slight followup ... I have made some progress; for now I'm using subprocess.communicate to read the output from the first subprocess, then writing it into the secodn subprocess. This way I at least get to see what is happening ... The reason 'we' weren't seeing any output from the second call (th

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread jkn
Hi Hans thanks a lot for your reply: > That's what 'xargs' will do for you.  All you need to do, is invoke > xargs with arguments containing '{}'.  I.e., something like: > > cmd1 = ['tar', '-czvf', 'myfile.tgz', '-c', mydir, 'mysubdir'] > first_process = subprocess.Popen(cmd1, stdout=subproces

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-08 Thread Hans Mulder
t from a shell > guru). > > IIUC, when called like this, the two occurences of '{}' in the xargs > command will get replaced with the file being added to the tarfile. > > Also IIUC, I will need two calls to subprocess.Popen() and use > subprocess.stdin on the second

how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-08 Thread jkn
args command will get replaced with the file being added to the tarfile. Also IIUC, I will need two calls to subprocess.Popen() and use subprocess.stdin on the second to receive the output from the first. But how can I achive the substitution of the '{}' construction across these two ca

Re: Liskov substitution principle

2011-07-15 Thread Ben Finney
would break the Liskov substitution principle, yes. Anything that asks for a Student instance should receive an object that can do at least everything Student can do. If you want to implement something that can't do some of the things Student can do, the Liskov substitution principle says you a

Re: Liskov substitution principle (was: list(), tuple() should not place at "Built-in functions" in documentation)

2011-07-15 Thread Chris Angelico
On Sat, Jul 16, 2011 at 10:04 AM, Ben Finney wrote: >        def study(self, subject): >            raise NotImplementedError > > See? We can have overstretched analogies *and* remain within the Liskov > substitution principle. > Hehe! Of course I was speaking utterly in jes

Liskov substitution principle (was: list(), tuple() should not place at "Built-in functions" in documentation)

2011-07-15 Thread Ben Finney
Chris Angelico writes: > The analogy with reality breaks down a bit here. I've seen plenty of > students with no idea of what it means to study. But Python can handle > that too - just 'del' the method in the subclass. No, please don't. That would break the Liskov

Re: String substitution VS proper mysql escaping

2010-09-04 Thread Aahz
In article , =?UTF-8?B?zp3Or866zr/Pgg==?= wrote: > >After all () used to define tuples and [] usedd to define lists. Why >commas? No, "()" does *not* define tuples, except for the empty tuple. The comma defines tuples, with parentheses simply used for visual effect: >>> 1, 2, 3 (1, 2, 3) -- A

Re: String substitution VS proper mysql escaping

2010-08-30 Thread John Nagle
you substitute into the placeholders must end up looking like SQL literals. That means string values need to be in quotes, and probably dates as well, although numbers don't. When you use the execute method's own parameter substitution mechanism, things are different. It'

Re: String substitution VS proper mysql escaping

2010-08-30 Thread MRAB
On 30/08/2010 17:34, Alexander Kapps wrote: Nik the Greek wrote: cursor.execute(''' SELECT hits FROM counters WHERE page = %s and date = %s and host = %s ''' , a_tuple ) and cursor.execute(''' SELECT hits FROM counters WHERE page = %s and date = %s and host = %s ''' , (a_tuple) ) are both sy

Re: String substitution VS proper mysql escaping

2010-08-30 Thread MRAB
syntactically valid SQL. The values that you substitute into the placeholders must end up looking like SQL literals. That means string values need to be in quotes, and probably dates as well, although numbers don't. When you use the execute method's own parameter substitution mechanism,

Re: String substitution VS proper mysql escaping

2010-08-30 Thread Alexander Kapps
Nik the Greek wrote: cursor.execute(''' SELECT hits FROM counters WHERE page = %s and date = %s and host = %s ''' , a_tuple ) and cursor.execute(''' SELECT hits FROM counters WHERE page = %s and date = %s and host = %s ''' , (a_tuple) ) are both syntactically correct right? buw what about c

Re: String substitution VS proper mysql escaping

2010-08-30 Thread Nik the Greek
actically valid SQL. The values that you substitute > into the placeholders must end up looking like SQL literals. > That means string values need to be in quotes, and probably > dates as well, although numbers don't. > > When you use the execute method's own parameter substitut

Re: Using a function for regular expression substitution

2010-08-30 Thread naugiedoggie
On Aug 30, 8:52 am, naugiedoggie wrote: > On Aug 29, 1:14 pm, MRAB wrote: > > > > > > > On 29/08/2010 15:22, naugiedoggie wrote: > > > I'm having a problem with using a function as the replacement in > > > re.sub(). > > > Here is the function: > > > def normalize(s) : > > >      return > > > urll

Re: Using a function for regular expression substitution

2010-08-30 Thread naugiedoggie
On Aug 29, 1:14 pm, MRAB wrote: > On 29/08/2010 15:22, naugiedoggie wrote: > > I'm having a problem with using a function as the replacement in > > re.sub(). > > Here is the function: > > def normalize(s) : > >      return > > urllib.quote(string.capwords(urllib.unquote(s.group('provider' >

Re: String substitution VS proper mysql escaping

2010-08-30 Thread Gregory Ewing
end up looking like SQL literals. That means string values need to be in quotes, and probably dates as well, although numbers don't. When you use the execute method's own parameter substitution mechanism, things are different. It's not a textual replacement, and you don't p

Re: String substitution VS proper mysql escaping

2010-08-29 Thread Nik the Greek
t; cursor.execute(''' SELECT hits FROM counters WHERE page = '%s' and > >>> date = '%s' and host = '%s' ''' % (page, date, host) ) > > >>> does work, while same thign qithout the quotes > > >>> cursor.

Re: String substitution VS proper mysql escaping

2010-08-29 Thread MRAB
cursor.execute(''' SELECT hits FROM counters WHERE page = %s and date = %s and host = %s ''' % (page, date, host) ) doesn't. Dont know why but quotes somehopw confuse me both in strings and sql_queries as well when it comes to substitutions. Don't qu

Re: String substitution VS proper mysql escaping

2010-08-29 Thread Nik the Greek
= %s and date > > = %s and host = %s ''' % (page, date, host) ) > > > doesn't. Dont know why but quotes somehopw confuse me both in strings > > and sql_queries as well when it comes to substitutions. > > Don't quote the placeholders yourself. Let the

Re: String substitution VS proper mysql escaping

2010-08-29 Thread MRAB
On 30/08/2010 02:38, Νίκος wrote: On 29 Αύγ, 21:34, MRAB wrote: It likes the values to be in a tuple. If there's one value, that's a 1-tuple: (page, ). I noticed that if we are dealing with just a single value 'page' will do, no need to tuple for 1-value. it handles fine as a string. I tri

Re: String substitution VS proper mysql escaping

2010-08-29 Thread Νίκος
On 29 Αύγ, 21:34, MRAB wrote: > It likes the values to be in a tuple. If there's one value, that's a > 1-tuple: (page, ). I noticed that if we are dealing with just a single value 'page' will do, no need to tuple for 1-value. it handles fine as a string. > >> cursor.execute('''SELECT hits FROM

Re: String substitution VS proper mysql escaping

2010-08-29 Thread MRAB
On 29/08/2010 06:13, Νίκος wrote: On 28 Αύγ, 23:12, MRAB wrote: On 28/08/2010 20:51, Νίκος wrote: On 28 Αύγ, 22:35, MRABwrote: """When there's more than one value you provide a tuple. It's makes sense from the point of view of consistency that you also provide a tuple when ther

Re: Using a function for regular expression substitution

2010-08-29 Thread MRAB
On 29/08/2010 15:22, naugiedoggie wrote: Hello, I'm having a problem with using a function as the replacement in re.sub(). Here is the function: def normalize(s) : return urllib.quote(string.capwords(urllib.unquote(s.group('provider' This normalises the provider and returns only tha

Re: Using a function for regular expression substitution

2010-08-29 Thread Terry Reedy
On 8/29/2010 10:22 AM, naugiedoggie wrote: Hello, I'm having a problem with using a function as the replacement in re.sub(). Here is the function: def normalize(s) : return urllib.quote(string.capwords(urllib.unquote(s.group('provider' To debug your problem, I would start with print

Re: Using a function for regular expression substitution

2010-08-29 Thread Roy Smith
In article <9170aad0-478a-4222-b6e2-88d00899d...@t2g2000yqe.googlegroups.com>, naugiedoggie wrote: > Hello, > > I'm having a problem with using a function as the replacement in > re.sub(). > > Here is the function: > > def normalize(s) : > return > urllib.quote(string.capwords(urllib.unq

Using a function for regular expression substitution

2010-08-29 Thread naugiedoggie
Hello, I'm having a problem with using a function as the replacement in re.sub(). Here is the function: def normalize(s) : return urllib.quote(string.capwords(urllib.unquote(s.group('provider' The purpose of this function is to proper-case the words contained in a URL query string param

Re: String substitution VS proper mysql escaping

2010-08-28 Thread Νίκος
On 28 Αύγ, 23:12, MRAB wrote: > On 28/08/2010 20:51, Νίκος wrote: > > > > > > > > > > > On 28 Αύγ, 22:35, MRAB  wrote: > > >> """When there's more than one value you provide a tuple. It's makes sense > >> from the point of view of consistency that you also provide a tuple when > >> there's only on

Re: String substitution VS proper mysql escaping

2010-08-28 Thread MRAB
On 28/08/2010 20:51, Νίκος wrote: On 28 Αύγ, 22:35, MRAB wrote: """When there's more than one value you provide a tuple. It's makes sense from the point of view of consistency that you also provide a tuple when there's only one value.""" Can you write something that make use of more than one

Re: String substitution VS proper mysql escaping

2010-08-28 Thread MRAB
when there's only one value.""" cursor.execute(sql_query, (page, )) is different than? cursor.execute(sql_query, page, ) ? Yes. The first has 2 arguments: a string and a tuple containing the value of 'page'. The second has 2 arguments: a string and the value of

Re: String substitution VS proper mysql escaping

2010-08-28 Thread Rami Chowdhury
2010/8/29 Νίκος : > On 28 Αύγ, 22:35, MRAB wrote: > >> """When there's more than one value you provide a tuple. It's makes sense >> from the point of view of consistency that you also provide a tuple when >> there's only one value.""" > > Can you write something that make use of more than one valu

Re: String substitution VS proper mysql escaping

2010-08-28 Thread Νίκος
On 28 Αύγ, 22:35, MRAB wrote: > """When there's more than one value you provide a tuple. It's makes sense > from the point of view of consistency that you also provide a tuple when > there's only one value.""" Can you write something that make use of more than one value? Perhaps you mena somet

Re: String substitution VS proper mysql escaping

2010-08-28 Thread Νίκος
t;"When there's more than one value you provide a tuple. It's makes sense > from the point of view of consistency that you also provide a tuple when > there's only one value.""" cursor.execute(sql_query, (page, )) is different than? curso

Re: String substitution VS proper mysql escaping

2010-08-28 Thread MRAB
On 28/08/2010 20:10, Νίκος wrote: On 20 Αύγ, 09:04, Nik Gr wrote: With regard to the "%" operator, it considers the string on the left to be a format string with multiple %blah things in it to replace. The thing on the right is a sequence of items to place into the format string. Can you plea

Re: String substitution VS proper mysql escaping

2010-08-28 Thread Νίκος
On 20 Αύγ, 09:04, Nik Gr wrote: > With regard to the "%" operator, it considers the string on the left to > be a format string with multiple %blah things in it to replace. The > thing on the right is a sequence of items to place into the format > string. Can you please clarify what you mean by th

Re: String substitution VS proper mysql escaping

2010-08-21 Thread Lawrence D'Oliveiro
In message , Νίκος wrote: > I would expect that: > > ("nikos") is a single element tuple. Then how would you do a simple parenthesized expression? -- http://mail.python.org/mailman/listinfo/python-list

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Nik Gr
Στις 20/8/2010 8:22 πμ, ο/η Cameron Simpson έγραψε: [...snip...] | Why does the page variable which is actually a string needs to be a | tuple or a list and not just as a string which is what it actually | is? With regard to the "%" operator, it considers the string on the left to be a format s

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Cameron Simpson
On 19Aug2010 21:50, Nik Gr wrote: | Στις 19/8/2010 6:58 μμ, ο/η Tim Chase έγραψε: | >It can be written as a non-3-quote string, you just have to escape | >the inner quotes (single & double) and the backslash to be seen: | > | > name = 'My name is "Nikos" and I\'m from Thessaloniki\\Greece' | >

Re: String substitution VS proper mysql escaping

2010-08-19 Thread John Nagle
ors WHERE page = |>| '%s' ORDER BY date DESC ''' % (page) ) |>| === |>| |>| Someone told me NOT to do string substitution ("%") on SQL statements |>| and to let MySQLdb do it |>| for me, with proper escaping like the follow

Re: String substitution VS proper mysql escaping

2010-08-19 Thread MRAB
Nik Gr wrote: [snip] Why does the page variable which is actually a string needs to be a tuple or a list and not just as a string which is what it actually is? I have a strong desire to use it like this: cursor.execute( '''SELECT hits FROM counters WHERE page = %s''' , page ) opposed to tuple.

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Nik Gr
Στις 19/8/2010 6:58 μμ, ο/η Tim Chase έγραψε: It can be written as a non-3-quote string, you just have to escape the inner quotes (single & double) and the backslash to be seen: name = 'My name is "Nikos" and I\'m from Thessaloniki\\Greece' name = "My name is \"Nikos\" and I'm from Thessal

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Tim Chase
niki\\Greece" And i dont have to use the 'r' in fornt of it too. Using the 'r' in front would make it much more challenging, because it would prevent the backslashes from being seen as escaping. :) (1,) + (2,) to return "(1,2)" This is actually joinin

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Nik Gr
Στις 19/8/2010 2:32 μμ, ο/η Tim Chase έγραψε: (1,) + (2,) to return "(1,2)" This is actually joining two single element tuples (1,) and (2, ) to a new bigger tuple of two elements, correct? -- http://mail.python.org/mailman/listinfo/python-list

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Nik Gr
by pairs of single or double quotes, correct? And i dont have to use the 'r' in fornt of it too. === Also if you please comment on my mysql string substitution example i've posted in my previous post just to make it work. I want it to be able to delete my data but it

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Stefan Schwarzer
Hi Νίκος, On 2010-08-19 09:10, Νίκος wrote: > On 18 Αύγ, 12:50, Cameron Simpson wrote: >> >> ("nikos",) is a single element tuple. >> ["nikos"] is a single element list. >> ["nikos",] is also a single element list, just written like the tuple. > > It makes more sense if i: > > "nikos" is just a

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Tim Chase
On 08/19/10 02:10, Νίκος wrote: ("nikos",) is a single element tuple. ["nikos"] is a single element list. ["nikos",] is also a single element list, just written like the tuple. It makes more sense if i: "nikos" is just a string ("nikos") is a single element tuple ["nikos"] is also a single ele

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Νίκος
ing ("nikos") is a single element tuple ["nikos"] is also a single element list After all () used to define tuples and [] usedd to define lists. Why commas? Also is there a difference between 'nikos' or "nikos" or '''nikos'''

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Νίκος
Y date DESC''', page) instead which i tend to like more, would there i have a problem? Also how how this part here page=%s doesn't need to be written as page='%s' which is the way i used to have it written with myssql string substitution? ==

Re: String substitution VS proper mysql escaping

2010-08-18 Thread Tim Chase
On 08/18/10 04:50, Cameron Simpson wrote: ("nikos",) is a single element tuple. ["nikos"] is a single element list. ["nikos",] is also a single element list, just written like the tuple. You don't see the ["nikos",] form very often because ["nikos"] is not ambiguous. I most frequently see/use

Re: String substitution VS proper mysql escaping

2010-08-18 Thread Cameron Simpson
' ORDER BY date DESC ''' % (page) ) | >| === | >| | >| Someone told me NOT to do string substitution ("%") on SQL statements | >| and to let MySQLdb do it | >| for me, with proper escaping like the following | >| | >|

Re: String substitution VS proper mysql escaping

2010-08-18 Thread Nik Gr
===== | | Someone told me NOT to do string substitution ("%") on SQL statements | and to let MySQLdb do it | for me, with proper escaping like the following | | === | cursor.execute('''SELECT host, hits, date F

Re: String substitution VS proper mysql escaping

2010-08-17 Thread Cameron Simpson
On 17Aug2010 20:15, Νίκος wrote: | === | cursor.execute( ''' SELECT host, hits, date FROM visitors WHERE page = | '%s' ORDER BY date DESC ''' % (page) ) | === | | Someone told me NOT to do string su

Re: String substitution VS proper mysql escaping

2010-08-17 Thread Daniel Kluev
2010/8/18 Νίκος > a) I wanted to ask what is proper escaping mean and > > Proper escaping means that value is wrapped in quotes properly, and quotes and backslashes (or any other special to RDBMS symbol) are escaped with backslashes. why after variable page syntax has a comma > Comma just means

String substitution VS proper mysql escaping

2010-08-17 Thread Νίκος
=== cursor.execute( ''' SELECT host, hits, date FROM visitors WHERE page = '%s' ORDER BY date DESC ''' % (page) ) === Someone told me NOT to do string substitution ("%") on SQL statements and

Re: substitution

2010-01-22 Thread Duncan Booth
Wilbert Berendsen wrote: > # sort the keys, longest first, so 'aa' gets matched before 'a', because > # in Python regexps the first match (going from left to right) in a > # |-separated group is taken > keys = sorted(mapping.keys(), key=len, reverse=True) > This would do just as well (although

  1   2   3   >