Ask Your Question
1

How to import the print function from __future__ ?

asked 8 years ago

anonymous user

Anonymous

updated 8 years ago

I did from __future__ import print_function

print('text',end='\n')

But it shows error.

Preview: (hide)

Comments

sorry I can't edit it , as I get the error : null value in column "ip_addr" violates not-null constraint DETAIL: Failing row contains (39710, 0, 23402, 2017-03-21 11:01:36.084769-05, None, I did from __future__ import print_function print('text',end=..., How to import the print function from __future__ ?, import, f, 37014, f, null, null, f, null, null).

screened00 gravatar imagescreened00 ( 8 years ago )

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_9.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 -*-\n" + _support_.preparse_worksheet_cell(base64.b64decode("Zm9yIGkgaW4gMyw0LDQsMjM6CiAgICBwcmludChpLCdlcicsZW5kPScgJyk="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/tmp/tmpd1blu3/___code___.py", line 4 print(i,'er',end=' ') ^ SyntaxError: invalid syntax*

screened00 gravatar imagescreened00 ( 8 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

tmonteil gravatar image

\n is not defined, you have to consider the string '\n' (with quotes):

sage: print('text',end='\n')
text
Preview: (hide)
link

Comments

I know @tmonteil but I still get the error, It was a typo actually.

screened00 gravatar imagescreened00 ( 8 years ago )

It works for me. Could you please give us some informations so that someone can try to reproduce your problem:

  • which version of Sage did you use ?
  • which OS ?
  • did you install Sage from the binaries, and which ones ?
  • did you compile Sage yourself ?
  • which notebook did you use (Sage notebook or jupyter notebook) ?
  • did you use the command line ?
  • which commands did you type precisely to get the error ?
  • which error message did you get ?
  • ... ?
tmonteil gravatar imagetmonteil ( 8 years ago )

Works in Sage cell

kcrisman gravatar imagekcrisman ( 8 years ago )

@tmonteil hi I use ubuntu xenial. I use sagemath 7.2 latest version obviously, as I downloaded the binaries from their site for ubuntu. So the error is huge, I don't know where to paste it?

screened00 gravatar imagescreened00 ( 8 years ago )

ok here is the error @tmonteil Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_3.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("cHJpbnQoJ3NmJyxlbmQ9J1xuJyk="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/tmp/tmpKltQiS/___code___.py", line 2 print('sf',end='\n') ^ SyntaxError: invalid syntax

screened00 gravatar imagescreened00 ( 8 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 788 times

Last updated: Mar 21 '17