Re: TypeError: int argument required

2009-06-18 Thread Lawrence D'Oliveiro
In message mailman.1725.1245281180.8015.python-l...@python.org, Rhodri 
James wrote:

 On Wed, 17 Jun 2009 12:07:15 +0100, Lawrence D'Oliveiro
 l...@geek-central.gen.new_zealand wrote:
 
 [snip example code]
 
 You haven't managed to get rid of the backslashes.
 
 [snip other example code]
 
 Now you've lost track of the original point of the discussion, which is
 about using alternate quotes to avoid backslashes.
 
 Ah, selective amnesia, how useful you are.  The original point of the
 discussion was in fact about using alternative quotes to avoid alternate
 backslashes (or at least excessive ones).

No mention of avoiding alternate backslashes (or at least excessive ones). 
Here's what I said, in message h144tf$gi...@lust.ihug.co.nz:

 In message mailman.1565.1245019944.8015.python-l...@python.org, Rhodri
 James wrote:
 
 On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro
 l...@geek-central.gen.new_zealand wrote:
 
 In message mailman.1510.1244832141.8015.python-l...@python.org, Rhodri
 James wrote:

 2.  That output string has severe leaning toothpick syndrome.  Python
 accepts both single and double quotes to help avoid creating something
 so unreadable: use them.

 Backslashes are more scalable.
 
 That doesn't excuse sprinkling several million backslashes through
 literal constants when there's a more readable alternative.
 
 Perl allows just about any printable character as a quote. I tried
 alternative quotes for many years, and decided making that choice was a
 waste of brain cells.
 
 So no, using alternative quotes does not make things more readable.

Now compare that with Lie Ryan's examples which, instead of using 
backslashes, instead used alternative quotes plus backslashes in one 
example, and in the other example, alternative quotes, alternatives to 
literal quotes, and backslashes. As opposed to my original routine, which 
managed three levels of quoting using just backslashes. Do you begin to 
understand what I mean by scalable?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-18 Thread Rhodri James
On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro  
l...@geek-central.gen.new_zealand wrote:



Now compare that with Lie Ryan's examples which, instead of using
backslashes, instead used alternative quotes plus backslashes in one
example, and in the other example, alternative quotes, alternatives to
literal quotes, and backslashes. As opposed to my original routine, which
managed three levels of quoting using just backslashes. Do you begin to
understand what I mean by scalable?


I do, and I still disagree.  More importantly, Lie Ryan's examples were
much more readable, which is what I was complaining about.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-18 Thread Lie Ryan
Rhodri James wrote:
 On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro
 l...@geek-central.gen.new_zealand wrote:
 
 Now compare that with Lie Ryan's examples which, instead of using
 backslashes, instead used alternative quotes plus backslashes in one
 example, and in the other example, alternative quotes, alternatives to
 literal quotes, and backslashes. As opposed to my original routine, which
 managed three levels of quoting using just backslashes. Do you begin to
 understand what I mean by scalable?
 
 I do, and I still disagree.  More importantly, Lie Ryan's examples were
 much more readable, which is what I was complaining about.

I still remember when I started programming, I wrote in QBASIC without
indentations. I honestly saw no reason to indent because I still can see
the program flow as clearly as the bottom of a bucket of crystalline
water. No decisions to be made, everything is consistently justified left.

I still remember asking a friend, Why is your code jagged like that?
and him looking at me a bit confused at the question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-17 Thread Lawrence D'Oliveiro
In message n4qzl.19093$y61.17...@news-server.bigpond.net.au, Lie Ryan 
wrote:

 out.write (
 '''
 function JSString(Str)
   {
 var Result = '\'
 for (var i = 0; i  Str.length; ++i)
   {
 var ThisCh = Str.charAt(i)
 if (ThisCh == '\\')
   {
 ThisCh = ''
   }
 else if (ThisCh == '\')
   {
 ThisCh = '\\\'
   }
 else if (ThisCh == '\t')
   {
 ThisCh = '\\t'
   }
 else if (ThisCh == '\n')
   {
 ThisCh = '\\n'
   } /*if*/
 Result += ThisCh
   } /*for*/
 return Result + '\'
 } /*JSString*/
 '''
 )

You haven't managed to get rid of the backslashes.

 I might go even further:
 
 out.write (
 '''
 function JSString(Str)
   {
 const dq = '\'
 const slash = '\\'
 
 var Result = dq
 for (var i = 0; i  Str.length; ++i)
   {
 var ThisCh = Str.charAt(i)
 if (ThisCh == slash)
   {
 ThisCh = slash + slash
   }
 else if (ThisCh == dq)
   {
 ThisCh = slash + dq
   }
 else if (ThisCh == '\t')
   {
 ThisCh = slash + 't'
   }
 else if (ThisCh == '\n')
   {
 ThisCh = slash + 'n'
   } /*if*/
 Result += ThisCh
   } /*for*/
 return Result + dq
 } /*JSString*/
 '''
 )

Now you've lost track of the original point of the discussion, which is 
about using alternate quotes to avoid backslashes.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-17 Thread Rhodri James
On Wed, 17 Jun 2009 12:07:15 +0100, Lawrence D'Oliveiro  
l...@geek-central.gen.new_zealand wrote:


[snip example code]


You haven't managed to get rid of the backslashes.


[snip other example code]


Now you've lost track of the original point of the discussion, which is
about using alternate quotes to avoid backslashes.


Ah, selective amnesia, how useful you are.  The original point of the
discussion was in fact about using alternative quotes to avoid alternate
backslashes (or at least excessive ones).  The first example showed this
nicely, actually, within the confines of a language which doesn't give
you much more help.

Yes, I know from past conversations that you have a superhuman ability
to recognise the code in apparent line noise.  That still doesn't make
it legible to anyone else.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-16 Thread Lie Ryan
Lawrence D'Oliveiro wrote:
 In message mailman.1582.1245063756.8015.python-l...@python.org, Rhodri 
 James wrote:
 
 On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro
 l...@geek-central.gen.new_zealand wrote:

 Perl allows just about any printable character as a quote. I tried
 alternative quotes for many years, and decided making that choice was a
 waste of brain cells.

 So no, using alternative quotes does not make things more readable.
 I find it odd that you consider qquoting less scalable than backslashes.
 
 Backslashes are scalable because they can be nested to any depth, without 
 having to decide beforehand which quotes to use at which level. And yes, I 
 do write things like this:

Scalable for the computers, not the eye...

 I also find it odd that you dislike two visuals stutters (at the start
 and end of string) so much that you'll put up with a dozen visual
 stutters in the string to avoid them.  Particular since my years of
 Perl-bashing lead me to the opposite conclusion.
 
 I find it odd you should think so.
 

If found it odd that you think that is more readable and scalable than this:

out.write (
'''
function JSString(Str)
  {
var Result = '\'
for (var i = 0; i  Str.length; ++i)
  {
var ThisCh = Str.charAt(i)
if (ThisCh == '\\')
  {
ThisCh = ''
  }
else if (ThisCh == '\')
  {
ThisCh = '\\\'
  }
else if (ThisCh == '\t')
  {
ThisCh = '\\t'
  }
else if (ThisCh == '\n')
  {
ThisCh = '\\n'
  } /*if*/
Result += ThisCh
  } /*for*/
return Result + '\'
} /*JSString*/
'''
)

I might go even further:

out.write (
'''
function JSString(Str)
  {
const dq = '\'
const slash = '\\'

var Result = dq
for (var i = 0; i  Str.length; ++i)
  {
var ThisCh = Str.charAt(i)
if (ThisCh == slash)
  {
ThisCh = slash + slash
  }
else if (ThisCh == dq)
  {
ThisCh = slash + dq
  }
else if (ThisCh == '\t')
  {
ThisCh = slash + 't'
  }
else if (ThisCh == '\n')
  {
ThisCh = slash + 'n'
  } /*if*/
Result += ThisCh
  } /*for*/
return Result + dq
} /*JSString*/
'''
)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-15 Thread Rhodri James
On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro  
l...@geek-central.gen.new_zealand wrote:



In message mailman.1565.1245019944.8015.python-l...@python.org, Rhodri
James wrote:


On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro
l...@geek-central.gen.new_zealand wrote:

In message mailman.1510.1244832141.8015.python-l...@python.org,  
Rhodri

James wrote:

2.  That output string has severe leaning toothpick syndrome.   
Python

accepts both single and double quotes to help avoid creating something
so unreadable: use them.


Backslashes are more scalable.


That doesn't excuse sprinkling several million backslashes through  
literal

constants when there's a more readable alternative.


Perl allows just about any printable character as a quote. I tried
alternative quotes for many years, and decided making that choice was a
waste of brain cells.

So no, using alternative quotes does not make things more readable.


I find it odd that you consider qquoting less scalable than backslashes.
I also find it odd that you dislike two visuals stutters (at the start
and end of string) so much that you'll put up with a dozen visual
stutters in the string to avoid them.  Particular since my years of
Perl-bashing lead me to the opposite conclusion.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-15 Thread Bearophile
Lawrence D'Oliveiro:
So no, using alternative quotes does not make things more readable.

You think that this:

'rect x=%f y=%f width=%d height=%d
style=fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-
opacity:0.9/ '

Isn't a bit more readable and simpler to write than:

rect x=\%f\ y=\%f\ width=\%d\ height=\%d\
style=\fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-
opacity:0.9\/ 

I think lot of doesn't agree with you.


In such situation it can also be positive to split such string in two
or more parts, for example (untested):

style = (fill:blue; stroke:pink; stroke-width:5; 
 fill-opacity:0.1; stroke-opacity:0.9)

print  fo, 'rect x=%f y=%f width=%d height=%d style=%s/
' % (abs_x, abs_y, w, h, style)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-15 Thread Lawrence D'Oliveiro
In message mailman.1582.1245063756.8015.python-l...@python.org, Rhodri 
James wrote:

 On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro
 l...@geek-central.gen.new_zealand wrote:
 
 Perl allows just about any printable character as a quote. I tried
 alternative quotes for many years, and decided making that choice was a
 waste of brain cells.

 So no, using alternative quotes does not make things more readable.
 
 I find it odd that you consider qquoting less scalable than backslashes.

Backslashes are scalable because they can be nested to any depth, without 
having to decide beforehand which quotes to use at which level. And yes, I 
do write things like this:

out.write \
  (
function JSString(Str)\n
# /* returns a JavaScript string literal that evaluates to Str. */
  {\n
var Result = \\n
for (var i = 0; i  Str.length; ++i)\n
  {\n
var ThisCh = Str.charAt(i)\n
if (ThisCh == \\)\n
  {\n
ThisCh = \\\n
  }\n
else if (ThisCh == \)\n
  {\n
ThisCh = \\n
  }\n
else if (ThisCh == \\\t\)\n
  {\n
ThisCh = \t\\n
  }\n
else if (ThisCh == \\\n\)\n
  {\n
ThisCh = \n\\n
  } /*if*/\n
Result += ThisCh\n
  } /*for*/\n
return Result + \\n
} /*JSString*/\n
  )

 I also find it odd that you dislike two visuals stutters (at the start
 and end of string) so much that you'll put up with a dozen visual
 stutters in the string to avoid them.  Particular since my years of
 Perl-bashing lead me to the opposite conclusion.

I find it odd you should think so.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-14 Thread Lawrence D'Oliveiro
In message mailman.1510.1244832141.8015.python-l...@python.org, Rhodri 
James wrote:

 2.  That output string has severe leaning toothpick syndrome.  Python
 accepts both single and double quotes to help avoid creating something
 so unreadable: use them.

Backslashes are more scalable.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-14 Thread Rhodri James
On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro  
l...@geek-central.gen.new_zealand wrote:



In message mailman.1510.1244832141.8015.python-l...@python.org, Rhodri
James wrote:


2.  That output string has severe leaning toothpick syndrome.  Python
accepts both single and double quotes to help avoid creating something
so unreadable: use them.


Backslashes are more scalable.


Yes, yes, you can print them at any size.  That doesn't excuse sprinkling
several million backslashes through literal constants when there's a more
readable alternative.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-14 Thread Lawrence D'Oliveiro
In message mailman.1565.1245019944.8015.python-l...@python.org, Rhodri 
James wrote:

 On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro
 l...@geek-central.gen.new_zealand wrote:
 
 In message mailman.1510.1244832141.8015.python-l...@python.org, Rhodri
 James wrote:

 2.  That output string has severe leaning toothpick syndrome.  Python
 accepts both single and double quotes to help avoid creating something
 so unreadable: use them.

 Backslashes are more scalable.
 
 That doesn't excuse sprinkling several million backslashes through literal
 constants when there's a more readable alternative.

Perl allows just about any printable character as a quote. I tried 
alternative quotes for many years, and decided making that choice was a 
waste of brain cells.

So no, using alternative quotes does not make things more readable.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-12 Thread mblume
Am Thu, 11 Jun 2009 20:56:24 -0700 schrieb lucius:

 I am trying to
 print some values to a file (using c's printf like method). TypeError:
 int argument required
 # this works, i see value on screen
  print  w, h, absX, absY
 
Are you sure that w or h are not returned as strings?
Hint: try this in an interpreter:
w=100
print %d % (w)

 
 # this fails, I get TypeError: int argument required
  print  fo, rect x=\%f\ y=\%f\ width=\%d\ height=\%d\
 style=\fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-
 opacity:0.9\/  % (absX, absY, w, h)
 

You could simplify such as an expression by writing:
print 'x=%f' % (x)

HTH
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-12 Thread Rhodri James

On Fri, 12 Jun 2009 04:56:24 +0100, lucius lucius.fo...@gmail.com wrote:


I am trying to
print some values to a file (using c's printf like method).
TypeError: int argument required
# this works, i see value on screen
 print  w, h, absX, absY

# where result is the return value of my regular expression.

  w, h, absX, absY = result.group(3), result.group(4), result.group
(5), result.group(6)

w = 100
h = 200

absX = 10.0
absY = 20.0

# this fails, I get TypeError: int argument required
   print  fo, rect x=\%f\ y=\%f\ width=\%d\ height=\%d\
style=\fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-
opacity:0.9\/  % (absX, absY, w, h)

Thank you for any help.


1.  This has to be the most incoherent help request that I've seen that
included actual information.  Figuring out what you were actually doing
was quite a challenge.

2.  That output string has severe leaning toothpick syndrome.  Python
accepts both single and double quotes to help avoid creating something
so unreadable: use them.

3. matchobject.group(n) returns a string, not an int or float.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


TypeError: int argument required

2009-06-11 Thread lucius
I am trying to
print some values to a file (using c's printf like method).
TypeError: int argument required
# this works, i see value on screen
 print  w, h, absX, absY

# where result is the return value of my regular expression.

  w, h, absX, absY = result.group(3), result.group(4), result.group
(5), result.group(6)

w = 100
h = 200

absX = 10.0
absY = 20.0

# this fails, I get TypeError: int argument required
   print  fo, rect x=\%f\ y=\%f\ width=\%d\ height=\%d\
style=\fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-
opacity:0.9\/  % (absX, absY, w, h)

Thank you for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-11 Thread alex23
On Jun 12, 1:56 pm, lucius lucius.fo...@gmail.com wrote:
  w, h, absX, absY = result.group(3), result.group(4), result.group
 (5), result.group(6)

 w = 100
 h = 200

 absX = 10.0
 absY = 20.0

Are you sure those values are ints  floats? I would expect your
regexp would be returning strings...

Try replacing the %f  %d strsubs with %s and see if that works. (You
shouldn't need to typecast the values if you're just reinserting them
into a string...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie help (TypeError: int argument required)

2008-06-08 Thread Iain Adams
Hi,

I am new to python. I have been having trouble using the MysqlDB. I
get an error pointing from the line

cursor.execute(UPDATE article SET title = %s, text = %s WHERE id =
%u, (self.title, self.text, self.id))

Here is the error:

 line 56, in save
cursor.execute(UPDATE article SET title = %s, text = %s WHERE id
= %u, (self.title, self.text, self.id))
  File /var/lib/python-support/python2.5/MySQLdb/cursors.py, line
151, in execute
query = query % db.literal(args)
TypeError: int argument required

However when I print out type(self.id) I get type 'int'.

So surely I have provided an int argument.

Any ideas anyone??
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie help (TypeError: int argument required)

2008-06-08 Thread [EMAIL PROTECTED]
On Jun 8, 1:43 pm, Iain Adams [EMAIL PROTECTED] wrote:
 Hi,

 I am new to python. I have been having trouble using the MysqlDB. I
 get an error pointing from the line

 cursor.execute(UPDATE article SET title = %s, text = %s WHERE id =
 %u, (self.title, self.text, self.id))

 Here is the error:

  line 56, in save
     cursor.execute(UPDATE article SET title = %s, text = %s WHERE id
 = %u, (self.title, self.text, self.id))
   File /var/lib/python-support/python2.5/MySQLdb/cursors.py, line
 151, in execute
     query = query % db.literal(args)
 TypeError: int argument required

 However when I print out type(self.id) I get type 'int'.

 So surely I have provided an int argument.

 Any ideas anyone??
From MySQLdb User's Guide (http://mysql-python.sourceforge.net/
MySQLdb.html):

To perform a query, you first need a cursor, and then you can execute
queries on it:

  c=db.cursor()
  max_price=5
  c.execute(SELECT spam, eggs, sausage FROM breakfast
WHERE price  %s, (max_price,))

In this example, max_price=5 Why, then, use %s in the string? Because
MySQLdb will convert it to a SQL literal value, which is the string
'5'. When it's finished, the query will actually say, ...WHERE price
 5.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie help (TypeError: int argument required)

2008-06-08 Thread bukzor
On Jun 8, 11:43 am, Iain Adams [EMAIL PROTECTED] wrote:
 Hi,

 I am new to python. I have been having trouble using the MysqlDB. I
 get an error pointing from the line

 cursor.execute(UPDATE article SET title = %s, text = %s WHERE id =
 %u, (self.title, self.text, self.id))

 Here is the error:

  line 56, in save
     cursor.execute(UPDATE article SET title = %s, text = %s WHERE id
 = %u, (self.title, self.text, self.id))
   File /var/lib/python-support/python2.5/MySQLdb/cursors.py, line
 151, in execute
     query = query % db.literal(args)
 TypeError: int argument required

 However when I print out type(self.id) I get type 'int'.

 So surely I have provided an int argument.

 Any ideas anyone??

Change your u to an s and you'll be fine. If you want a specific
format on the integer, format it first and pass in the string.
--
http://mail.python.org/mailman/listinfo/python-list