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

    Join Date
    May 2013
    Posts
    10
    Rep Power
    0

    can i suppress newlines in my script?


    I am having difficulty combining strings and numbers all in one long line. The result should increment the number count in the long string. The end result should read like this:

    (snip)172.16.1.0/27 172.16.1.32/27 172.16.1.64/27 (snip)
    The third octet '1' should increment.







    Code:
    #!/usr/bin/pyton
    
    count = 0
    while (count < 64):
     print ',,172.16.' + str(count)
     print ',,172.16.' + str(count)'.0/27,172.16.count.32/27,172.16.count.64/27,29,172.16.count.96/27,,,,172.17.count.0/27,172.17.count.32/27,172.17.count.64/27,29,172.17.count.96/27'
     print 'GW:,,172.16.0.1,172.16.0.33,172.16.0.65,,172.16.0.97,,GW:,,172.17.0.1,172.17.0.33,172.17.0.65,,172.17.0.97'
     count = count + 1
     print count
    print "Done"
    Last edited by sabo; May 23rd, 2013 at 05:11 PM. Reason: Original Problem solved so renaming to reflect new issue
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    451
    Rep Power
    32
    Take a look at string formatting

    Code:
    for count in range(1, 11):
        print '172.16.{0}.0/27 172.16.{0}.32/27 172.16.{0}.64'.format(count)

    Comments on this post

    • b49P23TIvg agrees : Wow. I didn't understand this question whatsoever.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    10
    Rep Power
    0
    Thanks that is what I needed.

    Now I am trying to import lines from a CSV file like this
    Code:
    f=open('finalcsv')
    lines=f.readlines()
    Then I want to take those lines and assign them to another variable. The goal is to print the lines as I iterate through them.


    Code:
    GW1 = lines[5]
    M1 = lines[6]
    PS1 = lines[7]
    PE1 = lines[8]
    ............
    for count in range(64, 127):
     print NET1.format(count)
     print GW1.format(count)
     print M1
     print PS1.format(count)
     print PE1.format(count)
    But the line being imported is sometimes coming in with a blank line in between. Is there a way to eliminate the newlines?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    451
    Rep Power
    32
    To test for an emply line use
    len(line.strip())

IMN logo majestic logo threadwatch logo seochat tools logo