expandtabs acts unexpectedly

2009-08-19 Thread digisat...@gmail.com
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type help, copyright, credits or license for more information.
 ' test\ttest'.expandtabs(4)
' test   test'
 'test \ttest'.expandtabs(4)
'testtest'

1st example: expect returning 4 spaces between 'test', 3 spaces
returned
2nd example: expect returning 5 spaces between 'test', 4 spaces
returned

Is it a bug or something, please advice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: expandtabs acts unexpectedly

2009-08-19 Thread Xavier Ho
On Wed, Aug 19, 2009 at 5:57 PM, digisat...@gmail.com
digisat...@gmail.comwrote:

 Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
 [GCC 4.3.3] on linux2
 Type help, copyright, credits or license for more information.
  ' test\ttest'.expandtabs(4)
 ' test   test'
  'test \ttest'.expandtabs(4)
 'testtest'

 Is it a bug or something, please advice.
 --


 It is completely working as intended. What were you expecting instead?

Regards,
-Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: expandtabs acts unexpectedly

2009-08-19 Thread Peter Brett
digisat...@gmail.com digisat...@gmail.com writes:

 Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
 [GCC 4.3.3] on linux2
 Type help, copyright, credits or license for more information.
 ' test\ttest'.expandtabs(4)
 ' test   test'
 'test \ttest'.expandtabs(4)
 'testtest'

 1st example: expect returning 4 spaces between 'test', 3 spaces
 returned
 2nd example: expect returning 5 spaces between 'test', 4 spaces
 returned

 Is it a bug or something, please advice.

Consider where the 4-space tabstops are relative to those strings:

 test   test
testtest
^   ^   ^

So no, it's not a bug.

If you just want to replace the tab characters by spaces, use:

test\ttest.replace(\t, )
  ' testtest'
   test \ttest.replace(\t, )
  'test test'

HTH,

   Peter

-- 
Peter Brett pe...@peter-b.co.uk
Remote Sensing Research Group
Surrey Space Centre
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: expandtabs acts unexpectedly

2009-08-19 Thread digisat...@gmail.com
On Aug 19, 4:16 pm, Peter Brett pe...@peter-b.co.uk wrote:
 digisat...@gmail.com digisat...@gmail.com writes:
  Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
  [GCC 4.3.3] on linux2
  Type help, copyright, credits or license for more information.
  ' test\ttest'.expandtabs(4)
  ' test   test'
  'test \ttest'.expandtabs(4)
  'test    test'

  1st example: expect returning 4 spaces between 'test', 3 spaces
  returned
  2nd example: expect returning 5 spaces between 'test', 4 spaces
  returned

  Is it a bug or something, please advice.

 Consider where the 4-space tabstops are relative to those strings:

  test   test
 test    test
 ^   ^   ^

 So no, it's not a bug.

 If you just want to replace the tab characters by spaces, use:

     test\ttest.replace(\t,     )
   ' test    test'
    test \ttest.replace(\t,     )
   'test     test'

 HTH,

                                Peter

 --
 Peter Brett pe...@peter-b.co.uk
 Remote Sensing Research Group
 Surrey Space Centre

You corrected me for the understanding of tab stop. Great explanation.
Thank you so much.
-- 
http://mail.python.org/mailman/listinfo/python-list