Re: Print formatting

2019-10-18 Thread D'Arcy Cain

On 10/18/19 5:00 PM, D'Arcy Cain wrote:

Finally, if this is in a loop do this.

FMT = '{0[0]:<12s}{0[3]:>12s}'.format
for temp_list in GetLists(): print FMT(temp_list)


Oops.  Time warp.  I meant "print(FMT(temp_list))

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Print formatting

2019-10-18 Thread D'Arcy Cain

On 10/18/19 2:21 PM, Jagga Soorma wrote:

I seem to have found a way to do this with the following:

  print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3])))

Still let me know if there is a better way to format this output :)


I would start with removing the redundant parens.

print('{:<12s}{:>12s}'.format(temp_list[0],temp_list[3]))

But then I would simplify it further.

print('{0[0]:<12s}{0[3]:>12s}'.format(temp_list))

You can do a similar thing with dictionaries.

print('{0[data0]:<12s}{0[data3]:>12s}'.format(temp_dict))

You can even mix and match.

print('{0[0]:<12s}{1[data3]:>12s}'.format(temp_list, temp_dict))

Finally, if this is in a loop do this.

FMT = '{0[0]:<12s}{0[3]:>12s}'.format
for temp_list in GetLists(): print FMT(temp_list)

Cheers.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Print formatting

2019-10-18 Thread Jagga Soorma
I seem to have found a way to do this with the following:

 print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3])))

Still let me know if there is a better way to format this output :)

Thanks,
-J

On Fri, Oct 18, 2019 at 10:03 AM Jagga Soorma  wrote:
>
> Hello,
>
> I am new to python and trying to write a script that outputs some data
> about users.  I was able to write it and dump the data but can't seem
> to align the output in column 2 correctly.  Here is what I am trying
> to do:
>
> --
> output:
> user1 data1
> username2 data2
> user3 data3
>
> snip from script:
> print(str(temp_list[0]) + "\t\t" + str(temp_list[1]))
> --
>
> Adding the tabs does not seem to work and I am sure there is a better
> way to do this.  Any help would be appreciated.
>
> Thanks,
> -J
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Print formatting

2019-10-18 Thread MRAB

On 2019-10-18 18:03, Jagga Soorma wrote:

Hello,

I am new to python and trying to write a script that outputs some data
about users.  I was able to write it and dump the data but can't seem
to align the output in column 2 correctly.  Here is what I am trying
to do:

--
output:
user1 data1
username2 data2
user3 data3

snip from script:
print(str(temp_list[0]) + "\t\t" + str(temp_list[1]))
--

Adding the tabs does not seem to work and I am sure there is a better
way to do this.  Any help would be appreciated.

A tab advances the output position to the next tab stop, but there's no 
universal standard for where those tab stops are, although they're 
commonly at every 8 characters, assuming a monospaced (fixed-width) font.

In your example, if the tabs are at every 8 characters then you'll get:

|   | <= The tab positions
user1   data1
username2   data2
user3   data3

"username2" has already passed the first tab, so it advances to the 
second tab, causing the misalignment.


The simplest solution, if you're using a monospaced font, is to use 
spaces instead. Find the width of the first column (the longest entry in 
the first column is 9 characters) and then pad all of the first entries 
with spaces to that width (use string formatting or the .just method) 
when outputting each line.

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


Print formatting

2019-10-18 Thread Jagga Soorma
Hello,

I am new to python and trying to write a script that outputs some data
about users.  I was able to write it and dump the data but can't seem
to align the output in column 2 correctly.  Here is what I am trying
to do:

--
output:
user1 data1
username2 data2
user3 data3

snip from script:
print(str(temp_list[0]) + "\t\t" + str(temp_list[1]))
--

Adding the tabs does not seem to work and I am sure there is a better
way to do this.  Any help would be appreciated.

Thanks,
-J
-- 
https://mail.python.org/mailman/listinfo/python-list


print formatting

2010-03-13 Thread vsoler
Hello,

My script contains a print statement:

 print '%40s %15d' % (k, m)

However,

 1- the string is right adjusted, and I would like it left
adjusted
 2- the number is a decimal number, and I would like it with
the thousands separator and 2 decimals

If possible, the thousands separator and the decimal separator should
use my local settings.

Is there any way to achieve this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: print formatting

2010-03-13 Thread Steve Holden
vsoler wrote:
 Hello,
 
 My script contains a print statement:
 
  print '%40s %15d' % (k, m)
 
 However,
 
  1- the string is right adjusted, and I would like it left
 adjusted
  2- the number is a decimal number, and I would like it with
 the thousands separator and 2 decimals
 
 If possible, the thousands separator and the decimal separator should
 use my local settings.
 
 Is there any way to achieve this?

Left-alignment is achieved by using a negative width.

You can use the locale module to generate thousands-separated numeric
string representations:

 from locale import *
 setlocale(LC_ALL, '') # locale is otherwise 'C'
'en_US.UTF-8'
 locale.format(%12.3f, 123456.789, grouping=False)
'  123456.789'
 locale.format(%12.3f, 123456.789, grouping=True)
' 123,456.789'

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: print formatting

2010-03-13 Thread Peter Otten
vsoler wrote:

 My script contains a print statement:
 
  print '%40s %15d' % (k, m)
 
 However,
 
  1- the string is right adjusted, and I would like it left
 adjusted
  2- the number is a decimal number, and I would like it with
 the thousands separator and 2 decimals
 
 If possible, the thousands separator and the decimal separator should
 use my local settings.
 
 Is there any way to achieve this?

 import locale
 locale.setlocale(locale.LC_ALL, )
'de_DE.UTF-8'

Traditional:
 print '%-40s|%15s' % (k, locale.format(%d, m, grouping=True))
hello   |  1.234.567

New:
 {0:40} {1:15n}.format(k, m)
'hello  1.234.567'

See also:
http://docs.python.org/dev/py3k/library/string.html#formatstrings

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


float print formatting

2007-02-13 Thread hg
Hi,

Considering the float 0.0, I would like to print 00.00.

I tried '%02.02f' % 0.0 ... but I get 0.00

Any clue ?

Thanks,

hg

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


Re: Mulig SPAM: float print formatting

2007-02-13 Thread NOSPAM plz
hg skrev:
 Hi,

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00

 Any clue ?

 Thanks,

 hg

   
Try this:

a = 45.45 # the floating number

print some text,
print a,
print some text again

or just this:

print some text,
print 45.45,
print some text again

Hope it helped :D

Andreas


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


Re: float print formatting

2007-02-13 Thread Neil Cerutti
On 2007-02-13, hg [EMAIL PROTECTED] wrote:
 Hi,

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00

 Any clue ?

Yes. How wide (total) is 0.00, compared to 00.00?

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


Re: float print formatting

2007-02-13 Thread hg
Neil Cerutti wrote:

 On 2007-02-13, hg [EMAIL PROTECTED] wrote:
 Hi,

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00

 Any clue ?
 
 Yes. How wide (total) is 0.00, compared to 00.00?
 
 --
 Neil Cerutti

I do not get it


s = '%02.02f' % 0.0
s
 '0.00'
len(s)
 4


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


Re: Mulig SPAM: float print formatting

2007-02-13 Thread hg
NOSPAM plz wrote:

 hg skrev:
 Hi,

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00

 Any clue ?

 Thanks,

 hg

   
 Try this:
 
 a = 45.45 # the floating number
 
 print some text,
 print a,
 print some text again
 
 or just this:
 
 print some text,
 print 45.45,
 print some text again
 
 Hope it helped :D
 
 Andreas

Sorry,

must be very slow or not enough coffee yet ... my purpose is to display a
justified report, so I format my floats into strings which I next draw in a
bitmap.

hg


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


Re: float print formatting

2007-02-13 Thread Peter Otten
hg wrote:

 Considering the float 0.0, I would like to print 00.00.
 
 I tried '%02.02f' % 0.0 ... but I get 0.00
 
 Any clue ?

The first integer specifies the total width:

 %05.2f % 0
'00.00'

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


Re: float print formatting

2007-02-13 Thread hg
Peter Otten wrote:

 hg wrote:
 
 Considering the float 0.0, I would like to print 00.00.
 
 I tried '%02.02f' % 0.0 ... but I get 0.00
 
 Any clue ?
 
 The first integer specifies the total width:
 
 %05.2f % 0
 '00.00'
 
 Peter

Many thanks !

hg

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


Re: float print formatting

2007-02-13 Thread Neil Cerutti
On 2007-02-13, hg [EMAIL PROTECTED] wrote:
 Neil Cerutti wrote:

 On 2007-02-13, hg [EMAIL PROTECTED] wrote:
 Hi,

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00

 Any clue ?
 
 Yes. How wide (total) is 0.00, compared to 00.00?
 
 --
 Neil Cerutti

 I do not get it

 s = '%02.02f' % 0.0

The first number after the percent is the minimum width specifier
for the ENTIRE field.

 s
 '0.00'
 len(s)
 4

It is the MINIMUM width specifier for the entire field.

-- 
Neil Cerutti
The eighth-graders will be presenting Shakespeare's Hamlet in the church
basement on Friday at 7 p.m. The congregation is invited to attend this
tragedy. --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: float print formatting

2007-02-13 Thread hg
Neil Cerutti wrote:

 The eighth-graders will be presenting Shakespeare's Hamlet in the church
 basement on Friday at 7 p.m. The congregation is invited to attend this
 tragedy. --Church Bulletin Blooper

;-) I like that !

hg

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


Re: float print formatting

2007-02-13 Thread Grant Edwards
On 2007-02-13, hg [EMAIL PROTECTED] wrote:
 Hi,

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00
^^
That's the specifierfor how many total columns you want to use
(including the decimal point and all digits to either side).

 Any clue ?

 %05.02f % 0.0
'00.00'

-- 
Grant Edwards   grante Yow!  Yow!! Janitor
  at   trapped in sewer uses ESP
   visi.comto find decayed burger!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mulig SPAM: float print formatting

2007-02-13 Thread Grant Edwards
On 2007-02-13, hg [EMAIL PROTECTED] wrote:
 NOSPAM plz wrote:

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00

 Try this:
 
 a = 45.45 # the floating number
 
 print some text,
 print a,
 print some text again

 Sorry,

 must be very slow or not enough coffee yet...

Don't worry.  I do know what you did wrong and how to fix it,
and I have absolutely no idea what NOSPAM plz is trying to
say  either.

-- 
Grant Edwards   grante Yow!  I'm in a twist
  at   contest!! I'm in a
   visi.combathtub! It's on Mars!! I'm
   in tip-top condition!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: float print formatting

2007-02-13 Thread hg
Grant Edwards wrote:

 On 2007-02-13, hg [EMAIL PROTECTED] wrote:
 Hi,

 Considering the float 0.0, I would like to print 00.00.

 I tried '%02.02f' % 0.0 ... but I get 0.00
 ^^
 That's the specifierfor how many total columns you want to use
 (including the decimal point and all digits to either side).
 
 Any clue ?
 
 %05.02f % 0.0
 '00.00'
 
 --
 Grant Edwards   grante Yow!  Yow!! Janitor
   at   trapped in sewer uses
   ESP
visi.comto find decayed
burger!!

Thanks

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