Which one is good practice about python formatted string?
<p>Suppose I have a file on <code>/home/ashraful/test.txt</code>. Simply I just want to open the file. 
Now my question is:</p>

<p>which one is good practice?</p>

<p><strong>Solution 1:</strong> </p>

<pre><code>dir = "/home/ashraful/"
fp = open("{0}{1}".format(dir, 'test.txt'), 'r')
</code></pre>

<p><strong>Solution 2:</strong> </p>

<pre><code>dir = "/home/ashraful/"
fp = open(dir + 'test.txt', 'r')
</code></pre>

<p>The both way I can open file. </p>

<p>Thanks :) </p>

<p>If your goal is to open files/directories, as others have mentioned, you should use the <code>os.path.join()</code> method. However, if you want to format string in Python -- as your question title suggests -- then your first approach should be preferred. To quote from <a href="https://www.python.org/dev/peps/pep-3101/" rel="nofollow">PEP 310</a>:</p>

<blockquote>
  <p>This PEP proposes a new system for built-in string formatting
      operations, intended as a replacement for the existing '%' string
      formatting operator.</p>
</blockquote>

python file