Re: [Tutor] List of tuples

2016-04-20 Thread Alan Gauld via Tutor
On 19/04/16 21:56, isaac tetteh wrote:
> I have a list like this 

> [
> ("name",2344,34, "boy"),("another",345,47,"boy", "last")
> ]

Assuming this is list_tuple...

> for row in list_tuple:
> for row2 in row:
> return row

This can't work because return needs to be inside a function.
So you obviously are not showing us all of your code.
Also the code above would not give the error you report.

So we need to see the whole code and the whole error message.

Also can you explain how you want the output presented.
Do you want values returned from a function or do you want
them printed on screen or do you want them represented
by a string? Your mail suggests you wanted them printed
but your code suggests you want them returned from a
function. Which is it?


-- 
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


Re: [Tutor] List of tuples

2016-04-20 Thread isaac tetteh
This a flask app that I am connecting to the mysql 

@app.route("/viewSingle", methods=['POST','GET'])
def SingleView():
formB=singleView()
data=[]
if request.method=="POST":
if formB.validate_on_submit:
#if request.form['submit']=="View CONTINENT":
c,conn = connection()
c.execute('''select * from Country''')
data = c.fetchall()
data=list(data)
for row in data:
for a in row:
return row  //this is the problem
#return str(data) 
#data=list(data)
c.close ()
conn.close ()
#return data
return render_template("view.html",data=data,formB=formB)

error 
ValueErrorValueError: too many values to unpackTraceback (most recent call 
last)File 
"/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 
1836, in __call__return self.wsgi_app(environ, start_response)File 
"/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 
1820, in wsgi_appresponse = self.make_response(self.handle_exception(e))File 
"/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 
1403, in handle_exceptionreraise(exc_type, exc_value, tb)File 
"/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 
1817, in wsgi_appresponse = self.full_dispatch_request()File 
"/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 
1478, in full_dispatch_requestresponse = self.make_response(rv)File 
"/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 
1563, in make_responserv, status, headers = rv + (None,) * (3 - 
len(rv))ValueError: too many values to unpack


> From: d...@hashcollision.org
> Date: Tue, 19 Apr 2016 15:01:41 -0700
> Subject: Re: [Tutor] List of tuples
> To: itette...@hotmail.com
> CC: tutor@python.org
> 
> On Tue, Apr 19, 2016 at 1:56 PM, isaac tetteh  wrote:
> > I have a list like this
> > [
> > ("name",2344,34, "boy"),("another",345,47,"boy", "last")
> > ]
> > How do u get each value from it like
> > Output
> > name
> > 2344
> > 34
> > ...
> >
> > What i did was
> > for row in list_tuple:
> > for row2 in row:
> > return row
> >
> > But i get error  too many value to unpack
> 
> 
> Hi Issac,
> 
> Can you copy and paste the exact error message and stack trace that
> you're seeing?  Try not to paraphrase it: we need to see exactly the
> text is saying.  In some cases, we'll even pay attention to whitespace
> and other insanely silly details.  :P
> 
> Since that's tedious for you to retype, just use copy-and-paste.
> Include everything that the error message says, even if it doesn't
> make sense to you.  We'll try to help you interpret what the error is
> saying.  Unfortunately, you paraphrased the error message above too
> much: I have no good guesses from what you've presented so far.
> 
> Also, try to show the entire program that you ran as well.  The
> snippet you showed us is incomplete, because we don't know how the
> program defines "list_tuple".  Generally, you want to include enough
> detail when asking for help that it's really easy for the tutors here
> to "reproduce" your problem.  That way, we can see the same problem
> that you see.  That's important.
> 
> 
> My best guess so far, from all that you've shown us, is that a
> *different* part of the program is responsible for the error you're
> showing us.  That's why we need more details: I think something else
> other than what you're showing us is producing that error.  The reason
> I think so is because no part of the program you're showing us is
> doing tuple unpacking, at least from what I can tell.
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List of tuples

2016-04-19 Thread Danny Yoo
Sorry for typos in response: on cell phone at the moment.  ;p
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List of tuples

2016-04-19 Thread Danny Yoo
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


Re: [Tutor] List of tuples

2016-04-19 Thread Danny Yoo
On Tue, Apr 19, 2016 at 1:56 PM, isaac tetteh  wrote:
> I have a list like this
> [
> ("name",2344,34, "boy"),("another",345,47,"boy", "last")
> ]
> How do u get each value from it like
> Output
> name
> 2344
> 34
> ...
>
> What i did was
> for row in list_tuple:
> for row2 in row:
> return row
>
> But i get error  too many value to unpack


Hi Issac,

Can you copy and paste the exact error message and stack trace that
you're seeing?  Try not to paraphrase it: we need to see exactly the
text is saying.  In some cases, we'll even pay attention to whitespace
and other insanely silly details.  :P

Since that's tedious for you to retype, just use copy-and-paste.
Include everything that the error message says, even if it doesn't
make sense to you.  We'll try to help you interpret what the error is
saying.  Unfortunately, you paraphrased the error message above too
much: I have no good guesses from what you've presented so far.

Also, try to show the entire program that you ran as well.  The
snippet you showed us is incomplete, because we don't know how the
program defines "list_tuple".  Generally, you want to include enough
detail when asking for help that it's really easy for the tutors here
to "reproduce" your problem.  That way, we can see the same problem
that you see.  That's important.


My best guess so far, from all that you've shown us, is that a
*different* part of the program is responsible for the error you're
showing us.  That's why we need more details: I think something else
other than what you're showing us is producing that error.  The reason
I think so is because no part of the program you're showing us is
doing tuple unpacking, at least from what I can tell.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] List of tuples

2016-04-19 Thread isaac tetteh
I have a list like this 
[
("name",2344,34, "boy"),("another",345,47,"boy", "last")
]
How do u get each value from it like 
Output 
name
2344
34
...

What i did was 
for row in list_tuple:
for row2 in row:
return row

But i get error  too many value to unpack 

Please help

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