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 20 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 2 of 3 — ← Prev page 1 [2] 3  Next page →


#58484

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 10:53 +0200
Message-ID<l5abn1$v5t$1@dont-email.me>
In reply to#58482
Στις 5/11/2013 10:21 πμ, ο/η Chris Angelico έγραψε:
> 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).



data = cur.fetchall

for row in data:

the only thing i can understand by looking the above 2 lines is this:

'fo'r fails to iterate over 'data' because for some reason 'data' 
haven't resulted as a list of rows that can be iterated.

But that just doesn't hlp me much.

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


#58485

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 10:54 +0200
Message-ID<l5abnk$v9u$1@dont-email.me>
In reply to#58482
Στις 5/11/2013 10:21 πμ, ο/η Chris Angelico έγραψε:
> 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).


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

The only thing i can understand by looking the above 2 lines is this:

'for' fails to iterate over 'data' because for some reason 'data' 
haven't resulted as a list of rows that can be iterated row by row.

But that just doesn't help me much.

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


#58487

From"M.F." <morefool@gmail.com>
Date2013-11-05 17:10 +0800
Message-ID<l5acl9$qgm$1@speranza.aioe.org>
In reply to#58485
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.
> for row in data:
> ===============
>
> The only thing i can understand by looking the above 2 lines is this:
>
> 'for' fails to iterate over 'data' because for some reason 'data'
> haven't resulted as a list of rows that can be iterated row by row.
>
> But that just doesn't help me much.

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


#58490

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 11:34 +0200
Message-ID<l5ae3r$aie$1@dont-email.me>
In reply to#58487
Στις 5/11/2013 11:10 πμ, ο/η M.F. έγραψε:
> 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.
>> for row in data:
>> ===============
>>
>> The only thing i can understand by looking the above 2 lines is this:
>>
>> 'for' fails to iterate over 'data' because for some reason 'data'
>> haven't resulted as a list of rows that can be iterated row by row.
>>
>> But that just doesn't help me much.
>

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.

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


#58491

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 11:56 +0200
Message-ID<l5afbl$ft4$1@dont-email.me>
In reply to#58490
Στις 5/11/2013 11:34 πμ, ο/η Nick the Gr33k έγραψε:
> Στις 5/11/2013 11:10 πμ, ο/η M.F. έγραψε:
>> 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.
>>> for row in data:
>>> ===============
>>>
>>> The only thing i can understand by looking the above 2 lines is this:
>>>
>>> 'for' fails to iterate over 'data' because for some reason 'data'
>>> haven't resulted as a list of rows that can be iterated row by row.
>>>
>>> But that just doesn't help me much.
>>
>
> 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.


Still similar error here:

=================================
		# if first time for webpage; create new record( primary key is 
automatic, hit is defaulted ), if page exists then update record
		cur.execute('''INSERT INTO counters (url) VALUES (%s) ON DUPLICATE KEY 
UPDATE hits = hits + 1''', page )
		cID = cur.lastrowid

		# fetch those columns that act as lists but are stored as strings
		cur.execute('''SELECT refs, visits, downloads FROM visitors WHERE 
counterID = %s and host = %s''', (cID, host) )
		data = cur.fetchone()
		
		# unpack data into variables
		(ref, visit, download) = data
		
		# retrieve long strings and convert them into lists respectively
		refs = ref.split()
		visits = visit.split()
		downloads = download.split()
		
		# add current strings to each list respectively
		refs.append( ref )
		visits.append( visit )
		downloads.append( download )
		
		# convert lists back to longstrings
		refs = ', '.join( refs )
		visits = ', '.join( visits )
		downloads = ', '.join( downloads )

		# save this visit as an entry into database
		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, hits = hits + 1, downloads) VALUES (%s, %s, %s, 
%s, %s, %s, %s, %s, %s)''',
						(cID, refs, host, city, useros, browser, visits, hits, downloads) )
================================


[Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 268, in <module>
[Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218]     (ref, 
visit, download) = data
[Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218] TypeError: 
'NoneType' object is not iterable


Now i have the parenthesis around fetchone().
How the data cant be properly unpacked?

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


#58493

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-11-05 11:20 +0100
Message-ID<mailman.2047.1383646833.18130.python-list@python.org>
In reply to#58491
Op 05-11-13 10:56, Nick the Gr33k schreef:
> Στις 5/11/2013 11:34 πμ, ο/η Nick the Gr33k έγραψε:
>> Στις 5/11/2013 11:10 πμ, ο/η M.F. έγραψε:
>>> 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.
>>>> for row in data:
>>>> ===============
>>>>
>>>> The only thing i can understand by looking the above 2 lines is this:
>>>>
>>>> 'for' fails to iterate over 'data' because for some reason 'data'
>>>> haven't resulted as a list of rows that can be iterated row by row.
>>>>
>>>> But that just doesn't help me much.
>>>
>>
>> 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.
> 
> 
> Still similar error here:
> 
> =================================
>         # if first time for webpage; create new record( primary key is
> automatic, hit is defaulted ), if page exists then update record
>         cur.execute('''INSERT INTO counters (url) VALUES (%s) ON
> DUPLICATE KEY UPDATE hits = hits + 1''', page )
>         cID = cur.lastrowid
> 
>         # fetch those columns that act as lists but are stored as strings
>         cur.execute('''SELECT refs, visits, downloads FROM visitors
> WHERE counterID = %s and host = %s''', (cID, host) )
>         data = cur.fetchone()
>        
>         # unpack data into variables
>         (ref, visit, download) = data
>        
>         # retrieve long strings and convert them into lists respectively
>         refs = ref.split()
>         visits = visit.split()
>         downloads = download.split()
>        
>         # add current strings to each list respectively
>         refs.append( ref )
>         visits.append( visit )
>         downloads.append( download )
>        
>         # convert lists back to longstrings
>         refs = ', '.join( refs )
>         visits = ', '.join( visits )
>         downloads = ', '.join( downloads )
> 
>         # save this visit as an entry into database
>         cur.execute('''INSERT INTO visitors (counterID, refs, host,
> city, useros, browser, visits, hits = hits + 1, downloads) VALUES (%s,
> %s, %s, %s, %s, %s, %s, %s, %s)''',
>                         (cID, refs, host, city, useros, browser, visits,
> hits, downloads) )
> ================================
> 
> 
> [Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218]   File
> "/home/nikos/public_html/cgi-bin/metrites.py", line 268, in <module>
> [Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218]     (ref,
> visit, download) = data
> [Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218] TypeError:
> 'NoneType' object is not iterable
> 
> 
> Now i have the parenthesis around fetchone().
> How the data cant be properly unpacked?
> 
Did you read the documentation of fetchone?

-- 
Antoon Pardon

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


#58495

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 12:33 +0200
Message-ID<l5ahib$rel$1@dont-email.me>
In reply to#58493
Στις 5/11/2013 12:20 μμ, ο/η Antoon Pardon έγραψε:

> Did you read the documentation of fetchone?



fetchone is like fetchall except from the fact that the former returned 
a row of data while the latter returned a list of rows of data.

I dont know why it copmains about:
TypeError: 'NoneType' object is not iterable

what object is supposed to have benn of None type?
how do i check for it?

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


#58496

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-11-05 11:59 +0100
Message-ID<mailman.2049.1383649164.18130.python-list@python.org>
In reply to#58495
Op 05-11-13 11:33, Nick the Gr33k schreef:
> Στις 5/11/2013 12:20 μμ, ο/η Antoon Pardon έγραψε:
> 
>> Did you read the documentation of fetchone?
> 
> 
> 
> fetchone is like fetchall except from the fact that the former returned
> a row of data while the latter returned a list of rows of data.

>From this answer it seems you didn't read the documentation very carefully.

> I dont know why it copmains about:
> TypeError: 'NoneType' object is not iterable
> 
> what object is supposed to have benn of None type?
> how do i check for it?

This is realy rather basic python knowledge. But maybe things
become clear after you read the documentation of fetchone more
carefully.

-- 
Antoon Pardon

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


#58498

FromDave Angel <davea@davea.name>
Date2013-11-05 05:16 -0600
Message-ID<mailman.2051.1383650198.18130.python-list@python.org>
In reply to#58495
On Tue, 05 Nov 2013 12:33:49 +0200, Nick the Gr33k 
<nikos.gr33k@gmail.com> wrote:
> Στις 5/11/2013 12:20 μμ, ο/η Antoon Pardon έγραψε:
> > Did you read the documentation of fetchone?




> fetchone is like fetchall except from the fact that the former 
returned 
> a row of data while the latter returned a list of rows of data.

That's not the only difference. See the word None there in one of the 
descriptions?

> TypeError: 'NoneType' object is not iterable

Examine the statement it's complaining about. It's obvious which item 
it's trying to iterate over.

-- 
DaveA

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


#58510

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 18:20 +0200
Message-ID<l5b5rj$if5$1@dont-email.me>
In reply to#58498
Στις 5/11/2013 1:16 μμ, ο/η Dave Angel έγραψε:
> On Tue, 05 Nov 2013 12:33:49 +0200, Nick the Gr33k
> <nikos.gr33k@gmail.com> wrote:
>> Στις 5/11/2013 12:20 μμ, ο/η Antoon Pardon έγραψε:
>> > Did you read the documentation of fetchone?
>
>
>
>
>> fetchone is like fetchall except from the fact that the former
> returned
>> a row of data while the latter returned a list of rows of data.
>
> That's not the only difference. See the word None there in one of the
> descriptions?
>
>> TypeError: 'NoneType' object is not iterable
>
> Examine the statement it's complaining about. It's obvious which item
> it's trying to iterate over.
>


-- 

So perhaps 'data' coudlnt retrive any values from the database that why 
it cannot unpack them to the 3 variables?

if so i altered the code to:

		# fetch those columns that act as lists but are stored as strings
		cur.execute('''SELECT refs, visits, downloads FROM visitors WHERE 
counterID = %s and host = %s''', (cID, host) )
		data = cur.fetchone()

		ref = visit = download = []
		if cur.rowcount:
			# unpack data into variables
			(ref, visit, download) = data
		
			# retrieve long strings and convert them into lists respectively
			refs = ref.split()
			visits = visit.split()
			downloads = download.split()
		else:
			# initiate these values
			ref = ref
			visit = lastvisit
			download = ''
		
		# add current strings to each list respectively
		refs.append( ref )
		visits.append( visit )
		downloads.append( download )
		
		# convert lists back to longstrings
		refs = ', '.join( refs )
		visits = ', '.join( visits )
		downloads = ', '.join( downloads )

		# save this visit as an entry into database
		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, hits = hits + 1, downloads) VALUES (%s, %s, %s, 
%s, %s, %s, %s, %s, %s)''',
						(cID, refs, host, city, useros, browser, visits, hits, downloads) )
=======================

but this also fail to run :( :( :(

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


#58499

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-11-05 11:49 +0000
Message-ID<5278db56$0$29972$c3e8da3$5496439d@news.astraweb.com>
In reply to#58495
On Tue, 05 Nov 2013 12:33:49 +0200, Nick the Gr33k wrote:

> Στις 5/11/2013 12:20 μμ, ο/η Antoon Pardon έγραψε:
> 
>> Did you read the documentation of fetchone?
> 
> 
> 
> fetchone is like fetchall except from the fact that the former returned
> a row of data while the latter returned a list of rows of data.

Read the documentation of fetchone again:

http://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.fetchone

Take careful note of what it does when there is no more data to fetch.



> I dont know why it copmains about:
> TypeError: 'NoneType' object is not iterable
> 
> what object is supposed to have benn of None type? how do i check for
> it?

Does the name "NoneType" give you a hint? Repeat after me:

"The type of **** is NoneType."

Take a guess what the **** should be. Then test it, in the interactive 
interpreter:

type(****)  # replace the stars with the object


and see what is printed.



-- 
Steven

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


#58500

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 14:25 +0200
Message-ID<l5ao43$tg6$1@dont-email.me>
In reply to#58499
Στις 5/11/2013 1:49 μμ, ο/η Steven D'Aprano έγραψε:
> On Tue, 05 Nov 2013 12:33:49 +0200, Nick the Gr33k wrote:
>
>> Στις 5/11/2013 12:20 μμ, ο/η Antoon Pardon έγραψε:
>>
>>> Did you read the documentation of fetchone?
>>
>>
>>
>> fetchone is like fetchall except from the fact that the former returned
>> a row of data while the latter returned a list of rows of data.
>
> Read the documentation of fetchone again:
>
> http://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.fetchone
>
> Take careful note of what it does when there is no more data to fetch.
>
>
>
>> I dont know why it copmains about:
>> TypeError: 'NoneType' object is not iterable
>>
>> what object is supposed to have benn of None type? how do i check for
>> it?
>
> Does the name "NoneType" give you a hint? Repeat after me:
>
> "The type of **** is NoneType."
>
> Take a guess what the **** should be. Then test it, in the interactive
> interpreter:
>
> type(****)  # replace the stars with the object
>
>
> and see what is printed.
>
>
>


# fetch those columns that act as lists but are stored as strings
cur.execute('''SELECT refs, visits, downloads FROM visitors WHERE 
counterID = %s and host = %s''', (cID, host) )
data = cur.fetchone()
		
print( type(data) )
sys.exit(0)

i tried inserting a type function to notify me of the datatype of 'data' 
but that didnt help too.

Still:
[Tue Nov 05 14:22:32 2013] [error] [client 176.92.96.218]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 268, in <module>
[Tue Nov 05 14:22:32 2013] [error] [client 176.92.96.218]     (ref, 
visit, download) = data
[Tue Nov 05 14:22:32 2013] [error] [client 176.92.96.218] TypeError: 
'NoneType' object is not iterable

Unfortunately i still miss your point.

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


#58501

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-11-05 13:42 +0100
Message-ID<mailman.2052.1383655340.18130.python-list@python.org>
In reply to#58500
Op 05-11-13 13:25, Nick the Gr33k schreef:
> 
> # fetch those columns that act as lists but are stored as strings
> cur.execute('''SELECT refs, visits, downloads FROM visitors WHERE
> counterID = %s and host = %s''', (cID, host) )
> data = cur.fetchone()
>        
> print( type(data) )
> sys.exit(0)
> 
> i tried inserting a type function to notify me of the datatype of 'data'
> but that didnt help too.
> 
> Still:
> [Tue Nov 05 14:22:32 2013] [error] [client 176.92.96.218]   File
> "/home/nikos/public_html/cgi-bin/metrites.py", line 268, in <module>
> [Tue Nov 05 14:22:32 2013] [error] [client 176.92.96.218]     (ref,
> visit, download) = data
> [Tue Nov 05 14:22:32 2013] [error] [client 176.92.96.218] TypeError:
> 'NoneType' object is not iterable
> 
> Unfortunately i still miss your point.

*Read* the documentation of fetchone! The information you need is there.

-- 
Antoon Pardon

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


#58502

FromDave Angel <davea@davea.name>
Date2013-11-05 07:15 -0600
Message-ID<mailman.2053.1383657336.18130.python-list@python.org>
In reply to#58500
On Tue, 05 Nov 2013 14:25:41 +0200, Nick the Gr33k 
<nikos.gr33k@gmail.com> wrote:
> i tried inserting a type function to notify me of the datatype of 
'data' 
> but that didnt help too.

What did that print show ? In what way didn't it help?

It said the type was Charles
It didn'tprint anything
It gave some other error
It formattedmy drive

How far did you get on the exercise I suggested?

-- 
DaveA

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


#58506

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 17:39 +0200
Message-ID<l5b3g4$25s$1@dont-email.me>
In reply to#58502
Στις 5/11/2013 3:15 μμ, ο/η Dave Angel έγραψε:
> On Tue, 05 Nov 2013 14:25:41 +0200, Nick the Gr33k
> <nikos.gr33k@gmail.com> wrote:
>> i tried inserting a type function to notify me of the datatype of
> 'data'
>> but that didnt help too.
>
> What did that print show ? In what way didn't it help?
>
> It said the type was Charles
> It didn'tprint anything
> It gave some other error
> It formattedmy drive
>
> How far did you get on the exercise I suggested?
>



nikos@superhost.gr [~]# who
nikos    pts/0        Nov  5 09:57 (176.92.96.218)
nikos@superhost.gr [~]# who > myfile.txt
nikos@superhost.gr [~]# cat myfile.txt
nikos    pts/0        Nov  5 09:57 (176.92.96.218)
nikos@superhost.gr [~]# python
Python 3.3.2 (default, Aug 26 2013, 06:41:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> infile = open("myfile.txt")
>>> data = infile.readlines
>>> for line in data:
... print( line )
   File "<stdin>", line 2
     print( line )
         ^
IndentationError: expected an indented block
>>> for line in data:
...     print( line )
...
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: 'builtin_function_or_method' object is not iterable

You said that i should try it locally but on my 8.1 i do not have python 
installed i test and run everything on server.

So, i tried it at the interpreter and it gave me the same error.

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


#58507

FromTim Chase <python.list@tim.thechases.com>
Date2013-11-05 09:45 -0600
Message-ID<mailman.2056.1383666227.18130.python-list@python.org>
In reply to#58506
On 2013-11-05 17:39, Nick the Gr33k wrote:
> >>> data = infile.readlines

You're assigning it to the bound function rather than calling the
function.  Use the "call" operator:

  data = infile.readlines()

-tkc

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


#58509

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2013-11-05 17:50 +0200
Message-ID<l5b43a$5sv$1@dont-email.me>
In reply to#58507
Στις 5/11/2013 5:45 μμ, ο/η Tim Chase έγραψε:
> On 2013-11-05 17:39, Nick the Gr33k wrote:
>>>>> data = infile.readlines
>
> You're assigning it to the bound function rather than calling the
> function.  Use the "call" operator:
>
>    data = infile.readlines()
>
> -tkc
>
>


-- 
>>> infile=open("myfile.txt")
>>> data = infile.readlines()
>>> for line in data:
...     print( line )
...
nikos    pts/0        Nov  5 09:57 (176.92.96.218)

>>>

Thanks Tim.
So i see here 2 lines, first being the file contenat's themselves and 
the last one being an empty line.

I can't relate this to the NoneType error iam having in my script.

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


#58548

FromDave Angel <davea@davea.name>
Date2013-11-05 23:36 -0600
Message-ID<mailman.2073.1383716216.18130.python-list@python.org>
In reply to#58506
On Tue, 5 Nov 2013 09:45:15 -0600, Tim Chase 
<python.list@tim.thechases.com> wrote:
> You're assigning it to the bound function rather than calling the
> function.  Use the "call" operator:

>   data = infile.readlines()

Thanks for spoiling the lesson. Nicks needs to learn how to debug 4 
line programs without someone giving him the answer.

-- 
DaveA

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


#58558

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-11-06 08:53 +0000
Message-ID<mailman.2078.1383728104.18130.python-list@python.org>
In reply to#58506
On 06/11/2013 05:36, Dave Angel wrote:
> On Tue, 5 Nov 2013 09:45:15 -0600, Tim Chase
> <python.list@tim.thechases.com> wrote:
>> You're assigning it to the bound function rather than calling the
>> function.  Use the "call" operator:
>
>>   data = infile.readlines()
>
> Thanks for spoiling the lesson. Nicks needs to learn how to debug 4 line
> programs without someone giving him the answer.
>

He needs to learn on short, consise programs before moving up to the 
medium size 4 liners.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


#58508

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-11-05 10:44 -0500
Message-ID<mailman.2057.1383666267.18130.python-list@python.org>
In reply to#58500
As I  read this thread, the original question was how to stuff
multiple values in a single sql column.  Several people pointed out
that the proper way to handle multiple values related to the original
table is to use a second table or perhaps a many to many relationship
with and intermediate join table.  Some people, including the original
poster seem to want to shoe horn the data into a single field. --
blobs, strings, even python lists, etc.  Although there is nothing
stopping a coder from doing that (except lack of skill ;)), it is a
bad idea.  SQL, whether a complete implementation of Codd stuff, or a
reasonable facsimile is a system that makes it possible to make
complex queries on data stored properly.  If you break the normal
forms, you always end up not being able to use sql statements to get
everything out that you put in.

So, some people here seem to think that's ok.  It may get the poster
past his first step more quickly than taking the time to understand
the tools he is using.  But eventually, there will be a big cost to
extending the code.  And we will endure another thread like this.
Personally, I think it demeans the group.

Once again we get the pattern:

How do I do this?

1. Here's how

No, I don't like that way

2. Here's a bad way

Oh good, will you write it for me.







-- 
Joel Goldstick
http://joelgoldstick.com

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


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

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


csiph-web