create file containing '/' in file name in python
Question: how can I create a file in python if the filename contains '/'

    
    
    url='https://www.udacity.com/cs101x/index.html'
    f=open(url,'w')
    f.write('123')
    f.close()
    

above code produces an error as

    
    
    Traceback (most recent call last):
    File "9.py", line 2, in <module>
    f=open(url,'w')
    IOError: [Errno 22] invalid mode ('w') or filename:https://www.udacity.com/cs101x/index.html'
    


Answer: Use os.path.basename() to isolate the filename.

    
    
    import os
    url='https://www.udacity.com/cs101x/index.html'
    filename = os.path.basename(url)
    f=open(filename,'w')
    f.write('123')
    f.close()
    

This will create a file called index.html

