Difference between revisions of "Python - File operations"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (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...) |
PeterHarding (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
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() | ||
</pre> | </pre> | ||
[[Category:Python]] | |||
[[Category:LoadRunner]] |
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()