Re: [Tutor] Fwd: List of tuples

2016-04-20 Thread Alan Gauld via Tutor
On 20/04/16 06:52, isaac tetteh wrote:

>> Thanks things are working good now. The only problem is 
>> i want to print the for loop output on one line instead of on each line.
>> Example [1,2,3,4,5]
>> Output 
>> 1 2 3 4 5 
>> I would to do this in Jinja 

I don;t know what Jinja is but...

When you say 'print', where do you want to print it?
It seems you are using Flask so presumably the output goes to a web
page? So presumably you really want to output a string? Or do you
literally want to print to the console?

If you want a string from a list of values you can use join():

s = ' '.join([str(n) for n in outputList])

If you want to print to console you can use

for n in outputList:
   print n, # note the comma

in Python v2 or

for n in outputList:
print (n, end=' '))

in Python v3

or just combine the techniques:

s = ' '.join([str(n) for n in outputList])
print(s)


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: List of tuples

2016-04-20 Thread isaac tetteh

> From: isaac tetteh 
> Date: April 19, 2016 at 9:05:04 PM CDT
> To: Danny Yoo 
> Subject: Re: [Tutor] List of tuples
> 
> Thanks things are working good now. The only problem is i want to print the 
> for loop output on one line instead of on each line.
> Example [1,2,3,4,5]
> Output 
> 1 2 3 4 5 
> I would to do this in Jinja 
> 
> Sent from my iPhone
> 
>> On Apr 19, 2016, at 8:35 PM, Danny Yoo  wrote:
>> 
>> Okay, in the context of a function, the error you're seeing makes more sense.
>> 
>> You need to ensure that the return value of the function is of the right 
>> type.  In  SingleView, the intended return value appears to be a structured 
>> response value.  
>> 
>> Given that, then any other return statements in the body of the function are 
>> suspect: return is a statement that will finish a function.
>> 
>> If a function returns a value of a tour that it isn't supposed to, expect 
>> that to produce very strange error messages.  That's essentially what you're 
>> seeing.
>> 
>> Looking at the construction of the response at the end:
>> 
>> > return render_template("view.html",data=data,formB=formB)
>> >
>> 
>> I'm wondering: perhaps you can collect the extracted column and add it as an 
>> additional value in you're template?
>> 
>> If you have questions, please feel free to ask.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor