Difference between revisions of "Python - File operations"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) |
PeterHarding (talk | contribs) |
||
Line 12: | Line 12: | ||
ifh = open('Machines.txt', 'r') | ifh = open('Machines.txt', 'r') | ||
print ' | print 'Name,QuotedName,Label,LoginId,QuotedLoginId' | ||
while True: | while True: | ||
Line 21: | Line 21: | ||
line = line[:-1] | line = line[:-1] | ||
( | (login_id, description) = line.split(',') | ||
( | (label, name, rest) = description.split(';') | ||
print "%s,%s,%s,%s,%s" % ( | print "%s,%s,%s,%s,%s" % (name, urllib.quote(name), label, login_id, urllib.quote(login_id)) | ||
ifh.close() | ifh.close() |
Latest revision as of 12:13, 2 April 2009
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 'Name,QuotedName,Label,LoginId,QuotedLoginId' while True: line = ifh.readline() if not line: break line = line[:-1] (login_id, description) = line.split(',') (label, name, rest) = description.split(';') print "%s,%s,%s,%s,%s" % (name, urllib.quote(name), label, login_id, urllib.quote(login_id)) ifh.close()