Thread: How to align

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    57
    Rep Power
    11

    How to align


    Hi i wrote a code to display all the files in a directory it works fine but i don't know how to left or right align them can someone help me ???
    or to wait for a key to continue after 20 lines
    Code:
    import sys
    import os
    print os.getcwd()
    as=os.listdir('')
    print " List of All .py Files in Python23 DIR "
    print
    as.sort()
    for i in as:
        print " ", i ,
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Here you go: 2.3.6.2 String Formatting Operations in the Python Library Reference.

    Grim
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You can also use the rjust() and ljust() string methods which will padd the string to a desired lengh on either side (depending on which method you use).

    rjust( width)

    Return the string right justified in a string of length width. Padding is done using spaces. The original string is returned if width is less than len(s).

    ljust( width)

    Return the string left justified in a string of length width. Padding is done using spaces. The original string is returned if width is less than len(s).
    Heres the link to the page grim sugested if you havnt found it already.

    http://www.python.org/doc/current/li...q-strings.html

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo