Python 3 CSV not writing
Question: When I open my csv file I see nothing. Is this the right way to build a csv
file? Just trying to learn it all. Thanks for all your help.

    
    
        import csv
        from urllib.request import urlopen
        from bs4 import BeautifulSoup
    
        html = urlopen("http://shop.nordstrom.com/c/designer-handbags?dept=8000001&origin=topnav#category=b60133547&type=category&color=&price=&brand=&stores=&instoreavailability=false&lastfilter=&sizeFinderId=0&resultsmode=&segmentId=0&page=1&partial=1&pagesize=100&contextualsortcategoryid=0")
        nordHandbags = BeautifulSoup(html)
        bagList = nordHandbags.findAll("a", {"class":"title"})
    
        f = csv.writer(open("./nordstrom.csv", "w"))
        f.writerow(["Product Title"])
    
        for title in bagList:
            productTitles = title.contents[0]
            f.writerow([productTitles])
    


Answer: Really hard to see how you could fail to have at least a `"Product Title"`
header in that file. Are you checking the file _after_ you have tgerminated
the Python interpreter? This, because there is no explicit close of the file
in that code, and until it is closed, its contents may be cached in memory.

More Pythonic, and avoiding this problem, is

    
    
     with open("./nordstrom.csv", "w") as csvfile:
        f = csv.writer( csvfile)
        f.writerow(["Product Title"])
        # etc.
    
     pass # close the with block, csvfile is now closed.
    

Also (grasping at straws) are you opening the file with a text editor to check
it, or just using the `type` command in Windows cmd.exe? Because, if the file
doesn't contain an explicit LF, the `C:\wherever\ >`prompt may overwrite the
header before you see it.

