Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58323 > unrolled thread

How to add a current string into an already existing list

Started byNick the Gr33k <nikos.gr33k@gmail.com>
First post2013-11-02 13:58 +0200
Last post2013-11-05 09:39 +0100
Articles 6 on this page of 46 — 17 participants

Back to article view | Back to comp.lang.python


Contents

  How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-02 13:58 +0200
    Re: How to add a current string into an already existing list Andreas Perstinger <andipersti@gmail.com> - 2013-11-02 14:03 +0100
      Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-02 18:25 +0200
        Re: How to add a current string into an already existing list Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-02 16:43 +0000
          Re: How to add a current string into an already existing list rusi <rustompmody@gmail.com> - 2013-11-02 10:40 -0700
            Re: How to add a current string into an already existing list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-02 18:28 +0000
            Re: How to add a current string into an already existing list Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-11-02 20:30 +0200
              Re: How to add a current string into an already existing list Chris Angelico <rosuav@gmail.com> - 2013-11-03 08:50 +1100
                Re: How to add a current string into an already existing list Roy Smith <roy@panix.com> - 2013-11-02 18:00 -0400
                  Re: How to add a current string into an already existing list Chris Angelico <rosuav@gmail.com> - 2013-11-03 09:13 +1100
            Re: How to add a current string into an already existing list Walter Hurry <walterhurry@lavabit.com> - 2013-11-02 21:12 +0000
        Re: How to add a current string into an already existing list Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-11-03 19:06 +1300
          Re: How to add a current string into an already existing list Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-03 10:56 +0100
          Re: How to add a current string into an already existing list Roy Smith <roy@panix.com> - 2013-11-03 07:16 -0500
            Re: How to add a current string into an already existing list Chris Angelico <rosuav@gmail.com> - 2013-11-04 00:13 +1100
            Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-04 19:03 +0200
              Re: How to add a current string into an already existing list Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-04 22:46 +0000
                Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 08:54 +0200
                  Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 10:07 +0200
                    Re: How to add a current string into an already existing list Chris Angelico <rosuav@gmail.com> - 2013-11-05 19:21 +1100
                      Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 10:53 +0200
                      Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 10:54 +0200
                        Re: How to add a current string into an already existing list "M.F." <morefool@gmail.com> - 2013-11-05 17:10 +0800
                          Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 11:34 +0200
                            Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 11:56 +0200
                              Re: How to add a current string into an already existing list Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-05 11:20 +0100
                                Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 12:33 +0200
                                  Re: How to add a current string into an already existing list Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-05 11:59 +0100
                                  Re: How to add a current string into an already existing list Dave Angel <davea@davea.name> - 2013-11-05 05:16 -0600
                                    Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 18:20 +0200
                                  Re: How to add a current string into an already existing list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-05 11:49 +0000
                                    Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 14:25 +0200
                                      Re: How to add a current string into an already existing list Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-05 13:42 +0100
                                      Re: How to add a current string into an already existing list Dave Angel <davea@davea.name> - 2013-11-05 07:15 -0600
                                        Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 17:39 +0200
                                          Re: How to add a current string into an already existing list Tim Chase <python.list@tim.thechases.com> - 2013-11-05 09:45 -0600
                                            Re: How to add a current string into an already existing list Nick the Gr33k <nikos.gr33k@gmail.com> - 2013-11-05 17:50 +0200
                                          Re: How to add a current string into an already existing list Dave Angel <davea@davea.name> - 2013-11-05 23:36 -0600
                                          Re: How to add a current string into an already existing list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-06 08:53 +0000
                                      Re: How to add a current string into an already existing list Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-05 10:44 -0500
                            Re: How to add a current string into an already existing list Dave Angel <davea@davea.name> - 2013-11-05 05:00 -0600
                            Re: How to add a current string into an already existing list Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-05 17:48 +0000
                          Re: How to add a current string into an already existing list Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-05 11:07 +0100
                            Re: How to add a current string into an already existing list Larry Hudson <orgnut@yahoo.com> - 2013-11-05 20:52 -0800
                          Re: How to add a current string into an already existing list Chris Angelico <rosuav@gmail.com> - 2013-11-05 21:01 +1100
                    Re: How to add a current string into an already existing list Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-05 09:39 +0100

Page 3 of 3 — ← Prev page 1 2 [3]


#58497

FromDave Angel <davea@davea.name>
Date2013-11-05 05:00 -0600
Message-ID<mailman.2050.1383649248.18130.python-list@python.org>
In reply to#58490
On Tue, 05 Nov 2013 11:34:53 +0200, Nick the Gr33k 
<nikos.gr33k@gmail.com> wrote:
> I see, but because of the traceback not being to express it more 
easily 
> i was under the impression that data wasn't what i expected it to 
be.

Exactly. So why didn't you act on that impression?

Your error message told you that data was a method, and that a method 
is not iterable. The previous line is where you assigned it.

Try debugging this:

infile = open("myfile.txt")
data = infile.readlines
 for line in data:
    print(line)

Not on a server. On your own machine.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#58516

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-11-05 17:48 +0000
Message-ID<l5bb17$fbc$1@dont-email.me>
In reply to#58490
On Tue, 05 Nov 2013 11:34:53 +0200, Nick the Gr33k wrote:

>>> data = cur.fetchall
>>> for row in data:

> I see, but because of the traceback not being to express it more easily
> i was under the impression that data wasn't what i expected it to be.

data wasn't what you expected it to be.

The problem was that you didn't understand that the reason data wasn't 
what you expected it to be was that you had assigned data to be the 
fetchall method of the object cur, when what you wanted to do was assign 
data to be the results of executing the method fetchall on the object cur.

Both of these are legal assignments:

data = cur.fetchall
data = cur.fetchall()

However the following is only valid if data is iterable:

for row in data:

So when it reaches the the line:

for row in data:

and discovers that data is not an iterable type, it gives an error 
message. If you can't decipher the error message to get back to the fact 
that in this case data isn't a y that you can use "for x in y:" to 
iterate over, and then debug intelligently to determine how any why that 
error message occurred, then as has been suggested many times in the 
past, you should stop trying to write code.

Seriously, how many other people do you see repeatedly posting "I don't 
understand the error, help" messages here that have been caused by such 
simple coding mistakes?

Most of us can decipher these error messages ourselves and would be 
embarrassed to post asking for help.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#58492

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-11-05 11:07 +0100
Message-ID<mailman.2046.1383646048.18130.python-list@python.org>
In reply to#58487
Op 05-11-13 10:10, M.F. schreef:
> On 11/05/2013 04:54 PM, Nick the Gr33k wrote:
>>
>>
>> ===============
>> data = cur.fetchall
> data = cur.fetchall()
> That is what the stack trace and Christ tried to inform you.

And now you have depraved Nikos of the opportunity to really learn
something. I'm willing to bet that Nikos will encouter a similar
problem within a year. And because he didn't need to learn how
to find the bug now, he will have no idea how to track the bug
then and will come here again with the expectation that someone
here will just spoon feed him the answer he needs.

And so continues the endless Nikos cycle.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#58547

FromLarry Hudson <orgnut@yahoo.com>
Date2013-11-05 20:52 -0800
Message-ID<D_OdnaygvNRiV-TPnZ2dnUVZ_sSdnZ2d@giganews.com>
In reply to#58492
On 11/05/2013 02:07 AM, Antoon Pardon wrote:
>
> And now you have depraved Nikos of the opportunity to really learn
> something. ...

I know you meant "deprived", but "depraved Nikos" sounds like a good description to me.   ;-)

      -=- Larry -=-

[toc] | [prev] | [next] | [standalone]


#58494

FromChris Angelico <rosuav@gmail.com>
Date2013-11-05 21:01 +1100
Message-ID<mailman.2048.1383647453.18130.python-list@python.org>
In reply to#58487
On Tue, Nov 5, 2013 at 8:10 PM, M.F. <morefool@gmail.com> wrote:
> That is what the stack trace and Christ tried to inform you.

Let's go with "and Chris tried"... no need to promote me to deity status :)

ChrisA

[toc] | [prev] | [next] | [standalone]


#58483

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-11-05 09:39 +0100
Message-ID<mailman.2042.1383640799.18130.python-list@python.org>
In reply to#58481
Op 05-11-13 09:21, Chris Angelico schreef:
> On Tue, Nov 5, 2013 at 7:07 PM, Nick the Gr33k <nikos.gr33k@gmail.com> wrote:
>> How is ti possible for data to be none iterable?
> 
> Do you know how to call a method in Python? If not, go back to the
> beginning of the tutorial and start reading. If so, look through your
> code and see where you have a 'method' object that you are trying to
> treat as iterable. It's really REALLY obvious, and you even have the
> line number to tell you.
> 
> Nick, you *need* to learn how to read Python tracebacks. They are
> incredibly helpful. Be glad you don't just get "Segmentation fault"
> and a process termination (or, worse, a security hole).

No he doesn't. It seems there will always be someone who can't resist
the temptation to spoon feed him. Sooner or later someone will provide
him the answer he craves.

So no, Nikos doesn't need to learn anything.

-- 
Antoon Pardon

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.python


csiph-web