Difference between revisions of "Python - File operations"

From PeformIQ Upgrade
Jump to navigation Jump to search
(New page: =Examples= ==URL Encoding Data== The following example was used to build a data set for LoadRunner testing where some of the data needed to be URL encoded <pre> #!/usr/bin/env python i...)
 
Line 29: Line 29:
ifh.close()
ifh.close()
</pre>
</pre>
[[Category:Python]]
[[Category:LoadRunner]]

Revision as of 09:56, 16 April 2008

Examples

URL Encoding Data

The following example was used to build a data set for LoadRunner testing where some of the data needed to be URL encoded

#!/usr/bin/env python

import urllib

ifh = open('Machines.txt', 'r')

print 'FacilityName,QuotedFacilityName,MachineLabel,MachineId,QuotedMachineId'

while True:
   line = ifh.readline()

   if not line: break
 
   line = line[:-1]

   (machine_ref, description) = line.split(',')

   (facility_name, rest) = description.split(';')

   print "%s,%s,%s,%s,%s" % (facility_name, urllib.quote(facility_name), description, machine_ref, urllib.quote(machine_ref))

ifh.close()