python download images are not saved to the correct directory
<p>When i use python 2.7 to download images from a website, the code as follows:</p>

<pre><code>pic = requests.get(src[0])
f = open("pic\\"+str(i) + '.jpg', "wb")
f.write(pic.content)
f.close()
i += 1
</code></pre>

<p>I want to save the picture into pic directory, but I find that images is saved in the same directory with the name like <code>pic\1.jpg</code>. Is this a bug?</p>

<p>In Windows, it's right, but on Ubuntu, it's an error!</p>

<p><a href="http://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/" rel="nofollow">Windows uses backslashes for file paths</a>, but Ubuntu uses forward slashes. This is why your save path with a backslash doesn't work on Ubuntu.</p>

<p>You probably want to use <a href="https://docs.python.org/2/library/os.path.html#os.path.join" rel="nofollow"><code>os.path.join</code></a> to make your path OS agnostic:</p>

<pre><code>import os
path = os.path.join('pic', '{}.jpg'.format(str(i)))
f = open(path, 'wb)
...
</code></pre>

python file