If using backslash, because it is a special character in Python, you must remember to escape every instance: 'C:\\Users.Therefore, you can refer to the file as 'C:/Users/narae/Desktop/alice.txt'. Python lets you use OS-X/Linux style slashes "/" even in Windows.Python allows using both in a Windows system, but there are a couple of pitfalls to watch out for. That is because natively, Windows file path employs the backslash "\" instead of the slash. In Windows, there are a couple additional ways of referencing a file. You can look up a file's full directory path and file name through its "Properties". Directories are separated by a slash "/". In Linux and OS-X, it starts with "/", which is called root. In Windows, a full file directory path starts with a drive letter (C:, D. myfile = open( '/Users/narae/Desktop/alice.txt') # Mac and Linux > mytxt = myfile.read()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |