Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of a backslash at the end of a line?

Just found the following module import in a Python code:

from sqlalchemy.ext.declarative import declarative_base,\
      AbstractConcreteBase

I am curious about the backslash \ at the end of the first line. What's the purpose of it? Wouldn't it be the same as the following?

from sqlalchemy.ext.declarative import declarative_base, AbstractConcreteBase
like image 209
fedorqui 'SO stop harming' Avatar asked Apr 17 '13 12:04

fedorqui 'SO stop harming'


1 Answers

Yep, it's exactly the same and this is the point of the backslash — it escapes the newline, allowing this long line to be split in two. An alternative is to use parentheses:

from sqlalchemy.ext.declarative import (declarative_base,
      AbstractConcreteBase)

While this is a syntax error:

from sqlalchemy.ext.declarative import declarative_base,
      AbstractConcreteBase
like image 102
Pavel Anossov Avatar answered Oct 07 '22 11:10

Pavel Anossov