Usage of Python join

 jionIt’s like splicing a list or tuple with a string, and of course, splicing a string with a str

The result is naturally a string.

ex1:

results:

 

Case application:

When we read something out of a file, it’s often a list with many string elements, and if we want to convert it directly to str, we can use’. join ()

ex2:

Note: the content of jointest.txt is {‘testcase’:’case1′,’testresults’:’Pass’}.

fd.readlines()The result is [‘{‘testcase’:’case1′,’testresults’:’Pass’}’].

You can use”.join () to change to STR, that is,'{‘testcase’:’case1′,’testresults’:’Pass’}’.

If you want to change dict, you can use json.JSONDecoder.decode ().

result2:

 {‘testcase’:’case1′, ‘testresults’:’Pass’}

Leave a Reply

Your email address will not be published. Required fields are marked *