Python end=

python

(Edward) #1

Why?

a, b = 0, 1
while b < 1000:
…print(b, end=’,’)
…a, b = b, a+b

does not work in ghpython 0.6.0.3.

at the end of the tutorial
https://docs.python.org/3/tutorial/introduction.html


#2

Rhino is using IronPython 2.7x, not Python 3.

https://docs.python.org/2.7/tutorial/introduction.html


(Giulio Piacentino) #3

I haven’t tried, but maybe you could try this:

Btw, in general, it would help if you attached the definition you are working on.


#5

try this:

from __future__ import print_function
print(b, end=’,’)


(Edward) #6

Hey! From the future? What do you mean with future?


#7

__future__ contains Python 3 functions that have been back-ported to v2


Please note that for some reason, the underscores were missing in my earlier post. I didn’t tag it as pre-formatted text.
Using __future__ will make it much easier to port to v3


(Giulio Piacentino) #8

2 posts were split to a new topic: Printing a tuple with a single item


Printing a tuple with a single item
(Edward) #9

Sorry, I do not understand how it works.
Do I have to install ‘future?’ What is port to v3?
Or did I missed it in the documentation?

https://docs.python.org/3/tutorial/controlflow.html
I am now studying paragraph 4.6 of the pyhton tutorial.

python -end- problem.gh (2.2 KB)


(qythium) #10

The error message on your component tells you what to do - __future__ imports are special and must be placed at the very top of the script.
Just reorder the first 3 lines to :

from __future__ import print_function
import math
import rhinoscriptsyntax as rs

and the rest works :slight_smile:

PS. Rhino/Grasshopper only runs on IronPython 2.7.x, so you should be reading the Python 2 version of the tutorials, not Python 3.


(Edward) #11

Thank you :slight_smile: