Меню

Синтаксическая ошибка неожиданный символ после символа продолжения строки

Can anybody tell me what is wrong in this program? I face

syntaxerror unexpected character after line continuation character

when I run this program:

f = open(D\python\HW\2_1 - Copy.cp,"r");  
lines = f.readlines();

for i in lines:  
    thisline = i.split(" ");

Tonechas's user avatar

Tonechas

13.2k15 gold badges43 silver badges78 bronze badges

asked May 4, 2011 at 8:41

user642564's user avatar

0

You need to quote that filename:

f = open("D\python\HW\2_1 - Copy.cp", "r")

Otherwise the bare backslash after the D is interpreted as a line-continuation character, and should be followed by a newline. This is used to extend long expressions over multiple lines, for readability:

print "This is a long",
      "line of text",
      "that I'm printing."

Also, you shouldn’t have semicolons (;) at the end of your statements in Python.

answered May 4, 2011 at 8:45

unwind's user avatar

unwindunwind

387k64 gold badges467 silver badges600 bronze badges

2

Replace

f = open(D\python\HW\2_1 - Copy.cp,"r");

by

f = open("D:\python\HW\2_1 - Copy.cp", "r")

  1. File path needs to be a string (constant)
  2. need colon in Windows file path
  3. space after comma for better style
  4. ; after statement is allowed but fugly.

What tutorial are you using?

answered May 4, 2011 at 8:47

John Machin's user avatar

John MachinJohn Machin

80.3k11 gold badges139 silver badges185 bronze badges

2

The filename should be a string. In other names it should be within quotes.

f = open("D\python\HW\2_1 - Copy.cp","r")
lines = f.readlines()
for i in lines:
    thisline = i.split(" ");

You can also open the file using with

with open("D\python\HW\2_1 - Copy.cp","r") as f:
    lines = f.readlines()
    for i in lines:
        thisline = i.split(" ");

There is no need to add the semicolon(;) in python. It’s ugly.

answered Dec 2, 2020 at 15:05

Trect's user avatar

TrectTrect

2,6112 gold badges28 silver badges35 bronze badges

Can anybody tell me what is wrong in this program? I face

syntaxerror unexpected character after line continuation character

when I run this program:

f = open(D\python\HW\2_1 - Copy.cp,"r");  
lines = f.readlines();

for i in lines:  
    thisline = i.split(" ");

Tonechas's user avatar

Tonechas

13.2k15 gold badges43 silver badges78 bronze badges

asked May 4, 2011 at 8:41

user642564's user avatar

0

You need to quote that filename:

f = open("D\python\HW\2_1 - Copy.cp", "r")

Otherwise the bare backslash after the D is interpreted as a line-continuation character, and should be followed by a newline. This is used to extend long expressions over multiple lines, for readability:

print "This is a long",
      "line of text",
      "that I'm printing."

Also, you shouldn’t have semicolons (;) at the end of your statements in Python.

answered May 4, 2011 at 8:45

unwind's user avatar

unwindunwind

387k64 gold badges467 silver badges600 bronze badges

2

Replace

f = open(D\python\HW\2_1 - Copy.cp,"r");

by

f = open("D:\python\HW\2_1 - Copy.cp", "r")

  1. File path needs to be a string (constant)
  2. need colon in Windows file path
  3. space after comma for better style
  4. ; after statement is allowed but fugly.

What tutorial are you using?

answered May 4, 2011 at 8:47

John Machin's user avatar

John MachinJohn Machin

80.3k11 gold badges139 silver badges185 bronze badges

2

The filename should be a string. In other names it should be within quotes.

f = open("D\python\HW\2_1 - Copy.cp","r")
lines = f.readlines()
for i in lines:
    thisline = i.split(" ");

You can also open the file using with

with open("D\python\HW\2_1 - Copy.cp","r") as f:
    lines = f.readlines()
    for i in lines:
        thisline = i.split(" ");

There is no need to add the semicolon(;) in python. It’s ugly.

answered Dec 2, 2020 at 15:05

Trect's user avatar

TrectTrect

2,6112 gold badges28 silver badges35 bronze badges

Can anybody tell me what is wrong in this program? I face

syntaxerror unexpected character after line continuation character

when I run this program:

f = open(D\python\HW\2_1 - Copy.cp,"r");  
lines = f.readlines();

for i in lines:  
    thisline = i.split(" ");

Tonechas's user avatar

Tonechas

13.2k15 gold badges43 silver badges78 bronze badges

asked May 4, 2011 at 8:41

user642564's user avatar

0

You need to quote that filename:

f = open("D\python\HW\2_1 - Copy.cp", "r")

Otherwise the bare backslash after the D is interpreted as a line-continuation character, and should be followed by a newline. This is used to extend long expressions over multiple lines, for readability:

print "This is a long",
      "line of text",
      "that I'm printing."

Also, you shouldn’t have semicolons (;) at the end of your statements in Python.

answered May 4, 2011 at 8:45

unwind's user avatar

unwindunwind

387k64 gold badges467 silver badges600 bronze badges

2

Replace

f = open(D\python\HW\2_1 - Copy.cp,"r");

by

f = open("D:\python\HW\2_1 - Copy.cp", "r")

  1. File path needs to be a string (constant)
  2. need colon in Windows file path
  3. space after comma for better style
  4. ; after statement is allowed but fugly.

What tutorial are you using?

answered May 4, 2011 at 8:47

John Machin's user avatar

John MachinJohn Machin

80.3k11 gold badges139 silver badges185 bronze badges

2

The filename should be a string. In other names it should be within quotes.

f = open("D\python\HW\2_1 - Copy.cp","r")
lines = f.readlines()
for i in lines:
    thisline = i.split(" ");

You can also open the file using with

with open("D\python\HW\2_1 - Copy.cp","r") as f:
    lines = f.readlines()
    for i in lines:
        thisline = i.split(" ");

There is no need to add the semicolon(;) in python. It’s ugly.

answered Dec 2, 2020 at 15:05

Trect's user avatar

TrectTrect

2,6112 gold badges28 silver badges35 bronze badges

Can anybody tell me what is wrong in this program? I face

syntaxerror unexpected character after line continuation character

when I run this program:

f = open(D\python\HW\2_1 - Copy.cp,"r");  
lines = f.readlines();

for i in lines:  
    thisline = i.split(" ");

Tonechas's user avatar

Tonechas

13.2k15 gold badges43 silver badges78 bronze badges

asked May 4, 2011 at 8:41

user642564's user avatar

0

You need to quote that filename:

f = open("D\python\HW\2_1 - Copy.cp", "r")

Otherwise the bare backslash after the D is interpreted as a line-continuation character, and should be followed by a newline. This is used to extend long expressions over multiple lines, for readability:

print "This is a long",
      "line of text",
      "that I'm printing."

Also, you shouldn’t have semicolons (;) at the end of your statements in Python.

answered May 4, 2011 at 8:45

unwind's user avatar

unwindunwind

387k64 gold badges467 silver badges600 bronze badges

2

Replace

f = open(D\python\HW\2_1 - Copy.cp,"r");

by

f = open("D:\python\HW\2_1 - Copy.cp", "r")

  1. File path needs to be a string (constant)
  2. need colon in Windows file path
  3. space after comma for better style
  4. ; after statement is allowed but fugly.

What tutorial are you using?

answered May 4, 2011 at 8:47

John Machin's user avatar

John MachinJohn Machin

80.3k11 gold badges139 silver badges185 bronze badges

2

The filename should be a string. In other names it should be within quotes.

f = open("D\python\HW\2_1 - Copy.cp","r")
lines = f.readlines()
for i in lines:
    thisline = i.split(" ");

You can also open the file using with

with open("D\python\HW\2_1 - Copy.cp","r") as f:
    lines = f.readlines()
    for i in lines:
        thisline = i.split(" ");

There is no need to add the semicolon(;) in python. It’s ugly.

answered Dec 2, 2020 at 15:05

Trect's user avatar

TrectTrect

2,6112 gold badges28 silver badges35 bronze badges

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Система виндовс обнаружила на этом диске ошибки которые необходимо исправить закройте это окно ssd
  • Синтаксическая ошибка незавершенный список параметров