Search code examples
pythonfileshortcut

python-opening a shortcut file in write mode gives me a return value 41


I was experimenting on files using python when I found out that opening a shortcut file in write mode returns 41, this is the code i used:

>>>with open('programs.lnk - Copy','w') as f:
       f.write("C:\\Users\\DEVDHRITI\\AppData\\Local\\Programs")

    
>>>41

is this a bug or some specific id??


Solution

  • No. It's not a bug. It's is part of the API. Quoting from the documentation,

    f.write(string) writes the contents of string to the file, returning the number of characters written.

    >>> f.write('This is a test\n')
    15