suppress newlines in my script
sloan949 at gmail.com
sloan949 at gmail.com
Fri May 24 09:59:43 EDT 2013
On Thursday, May 23, 2013 1:49:02 PM UTC-7, sloa... at gmail.com wrote:
> I am importing lines from an external csv file and when I iterate through the lines and increment, new lines are introduced.
>
> How would I cut out the newlines. I have attempted several pythonic strip() and rstrip() how can i implent this?
>
>
>
>
>
> import sys, os
>
>
>
> f=open('europe_csv')
>
> lines=f.readlines()
>
>
>
> BU = 'Company,,,,,,,,,,,,,,'
>
> PPP = 'Pre-Prod,,,,,,,,Prod,,,,,,'
>
> C1 = ',,,,,,,,,,,,,,'
>
> Title = 'Site,Environment,'
>
> NET1 = lines[4]
>
> GW1 = lines[5]
>
> M1 = lines[6]
>
> PS1 = lines[7]
>
> PE1 = lines[8]
>
> C2 = ',,,,,,,,,,,,,,'
>
> NET2 = lines[10]
>
> GW2 = lines[11]
>
> M2 = lines[12]
>
> PS2 = lines[13]
>
> PE2 = lines[14]
>
>
>
>
>
>
>
> for count in range(64, 127):
>
> print NET1.format(count)
>
> print GW1.format(count)
>
> print M1
>
> print PS1.format(count)
>
> print PE1.format(count)
>
> print C2
>
> print NET2.format(count)
>
> print GW2.format(count)
>
> print M2
>
> print PS2.format(count)
>
> print PE2.format(count)
Thanks for the tip about the CSV module. I did not know about that.
Here are two lines from the CSV file:
,,172.20.{0}.0/27,172.20.{0}.32/27,172.20.{0}.64/27,29,172.20.{0}.96/27,,,,172.21.{0}.0/27,172.21.{0}.32/27,172.21.{0}.64/27,29,172.21.{0}.96/27
GW:,,172.20.{0}.1,172.20.{0}.33,172.20.{0}.65,,172.20.{0}.97,,GW:,,172.21.{0}.1,172.21.{0}.33,172.21.{0}.65,,172.21.{0}.97
This is the output:
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
GW:,,172.20.126.129,172.20.126.161,172.20.126.193,,172.20.126.225,,GW:,,172.21.126.129,172.21.126.161,172.21.126.193,,172.21.126.225
''''''''''''''''''
There are blank lines between and I am assuming that these are from newlines being introduced.
The idea of this script is/was to abstract the csv data so that I dont need to place them in the file as there are many seperate CSV files to import.
I hope I answered your questions.
The majority of the script is below.
#!/usr/bin/python
import sys, os
#import pdb
#pdb.set_trace()
f=open('europe_germanyfinalcsv')
lines=f.readlines()
BU = 'Europe Germany,,,,,,,,,,,,,,'
PPP = 'Pre-Prod,,,,,,,,Prod,,,,,,'
C1 = ',,,,,,,,,,,,,,'
Title = 'Site,Environment,vApp Web,vApp App,vApp Data,Hosts Per Net,Reserved,,Site,Environment,vApp Web,vApp App,vApp Data,Hosts Per Net,Reserved'
NET1 = lines[4]
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)
More information about the Python-list
mailing list