some1
some1

Reputation: 1747

Open a file on Windows with Python 3.5

Just installed Python 3.5 on Windows. Trying to open a file, per the documentation, I'm supposed to use fopen for file reads.

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

f = open(C:\Users\median\Desktop\ics\2014_work_order_detail4.txt)
  File "<stdin>", line 1
    f = open(C:\Users\median\Desktop\ics\2014_work_order_detail4.txt)
              ^
SyntaxError: invalid syntax

 f = open(C:\Users\median\Desktop\ics\2014_work_order_detail4.txt);
  File "<stdin>", line 1
    f = open(C:\Users\median\Desktop\ics\2014_work_order_detail4.txt);
              ^
SyntaxError: invalid syntax

 f = open("C:\Users\median\Desktop\ics\2014_work_order_detail4.txt");
  File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

How do I open this file? Documentation does not seem to address these issues on Windows.

Is it a pathing problem?

Upvotes: 0

Views: 5316

Answers (1)

zanseb
zanseb

Reputation: 1435

Try to use:

f = open(r"C:\Users\median\Desktop\ics\2014_work_order_detail4.txt");

Upvotes: 3

Related Questions