Ask Your Question
1

How to import the print function from __future__ ?

asked 2017-03-21 09:41:27 -0500

anonymous user

Anonymous

updated 2017-03-21 11:00:36 -0500

I did from __future__ import print_function

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

But it shows error.

edit retag flag offensive close merge delete

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 ( 2017-03-21 11:02:31 -0500 )edit

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 ( 2017-03-21 11:05:15 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-03-21 09:55:35 -0500

tmonteil gravatar image

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

sage: print('text',end='\n')
text
edit flag offensive delete link more

Comments

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

screened00 gravatar imagescreened00 ( 2017-03-21 11:00:15 -0500 )edit

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 ( 2017-03-21 11:54:46 -0500 )edit

Works in Sage cell

kcrisman gravatar imagekcrisman ( 2017-03-21 12:18:12 -0500 )edit

@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 ( 2017-03-23 11:35:45 -0500 )edit

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 ( 2017-03-23 11:36:20 -0500 )edit

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: 2017-03-21 09:41:27 -0500

Seen: 74 times

Last updated: Mar 21