Re: Adding 'download' column to existing 'visitors' table (as requested)

2013-11-05 Thread Nick the Gr33k

Ah great!!!

I just examined my other MySQL database which just stored webpages and 
their corresponding visits and voila.


Someone was able to pass values into my counters table:

look:

http://superhost.gr/?show=stats

thats why it didn't had 1 or 2 or 3 as 'counterID' but more values were 
present.


Someone successfully manipulated this part of my code:

if cookieID != 'nikos' and ( os.path.exists( path + page ) or 
os.path.exists( cgi_path + page ) ) and re.search( 
r'(amazon|google|proxy|cloud|reverse|fetch|msn|who|spider|crawl|ping)', 
host ) is None:


try:
		# 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 )

..
..

I see no way of messing with the above statement other that tweak with 
the 'page' variable but its not clear to me how.


You as more experience can you tell how the aboev code of database insertio
--
https://mail.python.org/mailman/listinfo/python-list


Adding 'download' column to existing 'visitors' table (as requested)

2013-11-05 Thread Nick the Gr33k

I have decided to take your advice.
I wasn't able to fit those 'lists' of mine into MySQL's varchar() 
datatype after converting them to long strings and that sads me.


My implementation is like the following.
I do not use an extra table of downlaods that i asoociate with table 
visitors with a foreing key but decided to add an additional 'download' 
column into the existant visitors table:


Here it is:

=
# ~ DATABASE INSERTS ~
=
try:
		# 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 )

# get the primary key value of the new added record
cID = cur.lastrowid

# add this visitor entry into database (hits && downloads are 
defaulted)
		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s)''',

(cID, ref, host, city, useros, 
browser, lastvisit) )

con.commit()
except pymysql.ProgrammingError as e:
print( repr(e) )
con.rollback()
sys.exit(0)

=



=
# ~ Presentation Time
=
def coalesce( data ):
newdata = []
seen = {}
for host, refs, city, useros, browser, visits, hits, downloads 
in data:
# Here i have to decide how to group the rows together
			# I want an html row for every unique combination of (host) and that 
hits should be summed together

key = host
if key not in seen:
newdata.append( [ host, [refs], city, useros, browser, [visits], 
hits, [downloads] ] )

seen[key] = len( newdata ) - 1  # Save 
index (for 'newdata') of this row
			else:		# This row is a duplicate row with a different referrer && 
visit time && torrent download

rowindex = seen[key]
newdata[rowindex][1].append( refs )
newdata[rowindex][5].append( visits )
newdata[rowindex][6] += hits
newdata[rowindex][7].append( downloads )
return newdata


	cur.execute( '''SELECT host, refs, city, useros, browser, visits, hits, 
downloads FROM visitors
	WHERE counterID = (SELECT ID FROM counters WHERE url = %s) ORDER BY 
visits DESC''', page )

data = cur.fetchall()
newdata = coalesce( data )


for row in newdata:
(host, refs, city, useros, browser, visits, hits, downloads) = 
row
# Note that 'refs' && 'visits' && 'downloads' are now lists

print( '' )

print( ' %s ' % host )

print( '' )
for ref in refs:
print( ' %s ' % ref )
print( '' )

for item in (city, useros, browser):
print( ' %s ' % 
item )

print( '' )
for visit in visits:
visittime = visit.strftime('%A %e %b, %H:%M')
print( ' %s ' % visittime )
print( '' )

print( ' %s ' % 
hits )

# populate torrent list
torrents = []
for download in downloads:
if download:
torrents.append( download )

# present visitor's movie picks if any
if torrents:
print( '' )
for torrent in torrents:
print( ' %s ' % torrent )
print( '' )
else:
			print( ' Δεν πραγματοποίηθηκαν 
ακόμη! ' )

break

print( '' )

sys.exit(0)
=


At least my webpage http://superhost.gr is working now, but i look into 
by lookinto into phpmyadmin whats into the database and what is being 
presented somethign is worng.


This is a screenshot of my database visit sicne l

Re: install package from github repository

2013-11-05 Thread C. Ng
Ok, that seems to work... I modified from another package.
I don't understand how setup.py does it exactly, but got it done anyways.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: install package from github repository

2013-11-05 Thread C. Ng

nope there is no installation instructions
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to find out utf or not

2013-11-05 Thread Dave Angel

On 5 Nov 2013 15:30:19 GMT, Neil Cerutti  wrote:

On 2013-11-05, Dave Angel  wrote:
> On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh 
>> May be it initialized with myVar = u'x' or myVar = 'x'


My solution assumed he wanted to distinguish between those two cases.


>> So i need determine content of myVar that it's utf-8 or not, how 


I failed to notice thetypo in that line or the misunderstanding it 
implies.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code

2013-11-05 Thread Dave Angel

On Tue, 5 Nov 2013 17:51:00 -0800 (PST), chovd...@gmail.com wrote:

result  +=  ((-1) ** (k+1))/2*k-1


One of two things are happening here. Maybe both.

You're using Python 2.x (and should havesaid so) where integer 
division is truncated.


You're missing around some part of the intended denominator. Check 
operator precedence rules.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Dave Angel
On Tue, 5 Nov 2013 09:45:15 -0600, Tim Chase 
 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

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Larry Hudson

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

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code

2013-11-05 Thread Steven D'Aprano
On Tue, 05 Nov 2013 17:51:00 -0800, chovdary wrote:

> Hi friends
> 
> help me with the following code. Im able to execute the code but getting
> wrong output
[snip code]

You have this critical expression in your code:

result  +=  ((-1) ** (k+1))/2*k-1


It looks to me like you are using Python 2. Unfortunately, Python 2 had a 
design flaw that wasn't corrected until Python 3, where division is the 
integer division operator:

1/2 => 0 rather than 0.5.

There are three ways to fix this:

1) convert one of the numbers to a float:

   result  +=  float((-1) ** (k+1))/2*k-1


will probably do the trick. Although I'm not sure if the denominator is 
meant to be just 2, as you have above, or (2*k-1).


2) Put "from __future__ import division" as the very first line of your 
program. It must appear before any other code.

3) Avoid floating point numbers and use actual fractions, which will give 
you exact values instead of approximate. At the beginning of your code, 
put

from fractions import Fraction

and then change the code to look something like this:

result  +=  Fraction((-1) ** (k+1))/Fraction(2*k-1)




-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code

2013-11-05 Thread MRAB

On 06/11/2013 01:51, chovd...@gmail.com wrote:

Hi friends

help me with the following code. Im able to execute the code but getting wrong 
output

def sequence_b(N):
 N = 10
 result = 0
 for k in xrange (1,N):
 result  +=  ((-1) ** (k+1))/2*k-1
 print result
print sequence_b(10)

This is the output which im getting
-1
-4
-5
-10
-11
-18
-19
-28
-29


But i want output as
1
-1/3
1/5
-1/7
1/9
-1/11
1/13
-1/15
1/17
-1/19


1. Multiplication and division take precedence over addition and
subtraction, and both multiplication/division and addition/subtraction
are calculated left-to-right, so an expression like x/2*k-1 is
calculated as ((x/2)*k)-1.

2. In Python 2, dividing an integer by an integer gives an integer
result, e.g. 7/2 gives 3, not 3.5. The simplest way of fixing
that is to introduce a float into either the numerator or denominator.

That means that your expression should be, say:

((-1) ** (k + 1)) / (2.0 * k - 1)

3. It won't print fractions like 1/5, but instead decimals like 0.2.

4. You're adding the result of the expression to 'result' and then 
printing the value of 'result', so your output would be the results of:


-1
-1+(-1/3)
-1+(-1/3)+(1/5)

and so on.

5. Your function prints the result but doesn't return anyhing, so, by
default, it'll return None. Therefore, 'print sequence_b(10)' will
print 'None'. What you'll get is a series of numbers and then a None.

--
https://mail.python.org/mailman/listinfo/python-list


Representing fractions (was: Help me with this code)

2013-11-05 Thread Ben Finney
chovd...@gmail.com writes:

> def sequence_b(N):
> N = 10
> result = 0
> for k in xrange (1,N):
> result  +=  ((-1) ** (k+1))/2*k-1

Every number here is an integer. Python 2 will keep all the computations
integers by default::

$ python2
>>> 1 / 2
0

You want to use Python 3, which does “true division” by default::

$ python3
>>> 1 / 2
0.5

> But i want output as
> 1
> -1/3
> 1/5
> -1/7
> 1/9
> -1/11
> 1/13
> -1/15
> 1/17
> -1/19

You're not going to get that output from Python built-in number types.

If you want numbers which represent fractions (as opposed to integers,
or decimal numbers, or floating-point numbers), you want the ‘fractions’
module http://docs.python.org/3/library/fractions.html> which will
represent the number explicitly with numerator and denominator::

$ python3
>>> import fractions
>>> result = fractions.Fraction(1) / fractions.Fraction(2)
>>> result
Fraction(1, 2)
>>> print(result)
1/2

-- 
 \  “A hundred times every day I remind myself that […] I must |
  `\   exert myself in order to give in the same measure as I have |
_o__)received and am still receiving” —Albert Einstein |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Help me with this code

2013-11-05 Thread chovdary
Hi friends

help me with the following code. Im able to execute the code but getting wrong 
output

def sequence_b(N):
N = 10
result = 0
for k in xrange (1,N):
result  +=  ((-1) ** (k+1))/2*k-1
print result
print sequence_b(10)

This is the output which im getting
-1
-4
-5
-10
-11
-18
-19
-28
-29


But i want output as
1
-1/3
1/5
-1/7
1/9
-1/11
1/13
-1/15
1/17
-1/19


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Ben Finney
Denis McMahon  writes:

> You have been told several times by several people how to do this 
> properly. You insist on using your bodged up solution instead. OK, we'll 
> all try and help you bodge up a solution[…]

Why? No-one here is obligated to help with implementing a solution we
agree is bad.

Now that helpful suggestions have been offered, and the OP continues to
obstinately refuse to learn, why not leave it there? Why not leave this
person to his own obstinacy and stop giving him the attention he
demands?

-- 
 \ “Computers are useless. They can only give you answers.” —Pablo |
  `\   Picasso |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Nick the Gr33k

Στις 6/11/2013 12:54 πμ, ο/η John Gordon έγραψε:

The code i provided only worked once before it failed and managed to
store this:

counterID,host,refs,city,userOS,browser,visits,hits,download
-
1, 176-92-96-218.adsl.cyta.gr, Europe/Athens, Windows, Chrome,
-00-00 00:00:00, 1, ''

You've got a data inconsistancy here.  You give nine column names, but
only eight values.  It's impossible to tell which value belongs to which
column.  Which value is missing?



Yes, you have a point but thats why because 'refs' was an empty string 
for some reason and i have should have made this clear by putting a '' 
like i did with the 'downloads' at the end.


So it is not a matter of inconsistency.
Its weird though why it was stored this way, refs and downloads that is 
as an empty strings.


How, do i i proceed?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Denis McMahon
On Wed, 06 Nov 2013 00:35:56 +0200, Nick the Gr33k wrote:

> Now i realizes i just cannot store lists into it's columns because it
> does not support a collection datatype.

All databases support storing of collections, but *NOT THE WAY YOU WANT 
TO DO IT*

You refuse to do it the proper way, so you have to bodge a solution  
oh wait  I'm having a flashback here 

You have been told several times by several people how to do this 
properly. You insist on using your bodged up solution instead. OK, we'll 
all try and help you bodge up a solution, but I will tell you now, in 
advance, in very clear terms:

*ONE DAY YOUR BODGED UP SOLUTION WILL BREAK BECAUSE THE TOTAL LIST OF 
TORRENTS THAT A USER HAS DOWNLOADED, WHEN PACKAGED INTO A STRING, WILL BE 
BIGGER THAN THE DATABASE STRING FIELD YOU ASSIGNED*

There may be another issue that you need to consider.

Supposing a torrent file name is 40 characters long. Supposing a user 
downloads up to 20 torrents a day. That means in one year, their list 
will contain 7300 entries, and the character string in the database will 
be 365 * 20 * 40 + 365 * 20 - 1 = 299299 characters.

And you're going to convert this huge string into a list and then back 
into a string 20 times a day for every user just to add another 40 
characters to the end.

Do you expect 100 users? 1,000? 10,000? 100,000?

Let's assume that you have a million users. In a year, every day you're 
reading and writing about 6000 Gbytes a day from and to the database.

Holy smoke batman, that's a lot of data.

Or you could use the database properly, and just write the 40 byte 
torrent file name to the database with a pointer to the user's record 
every time a user downloads another torrent.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to find out utf or not

2013-11-05 Thread Gisle Vanem

"Steven D'Aprano"  wrote:

If myVar is a Unicode string, you don't need to care about the encoding 
(UTF-8 or otherwise) until you're ready to write it to a file. Then I 
strongly recommend you always use UTF-8, unless you have to interoperate 
with some old, legacy system:


assert isinstance(myVar, unicode)
byte_string = myVar.encode('utf-8')


An excellent summary of the mystics around text-encoding. Thank you.

--gv
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Mark Lawrence

On 05/11/2013 22:31, Cameron Simpson wrote:

On 05Nov2013 20:09, Nikos  wrote:

O even better an rdbms than allows complex data such as tuples,
lists, dicts to be saved into the db as they are so i dont have to
cobvet back and forth each time.


If you're just using the db for storage or adhoc and arbitrary
python objects (and not querying the stored values via SQL - eg
WHERE), then: make a column of type BLOB, convert Python values to
bytes using pickle, store. And of course the reverse.

It is not a great use of an RDB, but it seems to adhere to what you ask.



How do expect the OP to understand a BLOB or pickle or chutney when he 
doesn't understand why he can't iterate around a Nonetype object?


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

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread bob gailer

There is also the shelve module.

It uses pickle to marshal a Python object, then stores it in a file 
under a key.


Sample code from the module documentation:

import shelve

d = shelve.open(filename) # open -- file may get suffix added by 
low-level library


d[key] = data   # store data at key (overwrites old data if using an 
existing key)
data = d[key]   # retrieve a COPY of data at key (raise KeyError if no 
such key)

del d[key]  # delete data stored at key (raises KeyError if no such key)
flag = key in d# true if the key exists
klist = list(d.keys()) # a list of all existing keys (slow!)


--
Bob Gailer
919-636-4239
Chapel Hill NC

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Cameron Simpson
On 05Nov2013 20:09, Nikos  wrote:
> O even better an rdbms than allows complex data such as tuples,
> lists, dicts to be saved into the db as they are so i dont have to
> cobvet back and forth each time.

If you're just using the db for storage or adhoc and arbitrary
python objects (and not querying the stored values via SQL - eg
WHERE), then: make a column of type BLOB, convert Python values to
bytes using pickle, store. And of course the reverse.

It is not a great use of an RDB, but it seems to adhere to what you ask.
-- 
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread John Gordon
In  Nick the Gr33k  
writes:

> The code i provided only worked once before it failed and managed to 
> store this:
>   
> counterID,host,refs,city,userOS,browser,visits,hits,download
> -
> 1, 176-92-96-218.adsl.cyta.gr, Europe/Athens, Windows, Chrome, 
> -00-00 00:00:00, 1, ''

You've got a data inconsistancy here.  You give nine column names, but
only eight values.  It's impossible to tell which value belongs to which
column.  Which value is missing?

> 'visit's column is full of zeroes. Perhaps this is considered  as Null 
> for Python?

Python does not consider zero to be a null value.  (It will compare as
equal to False, but that's not the same.)

> But ref is also null, why the code didn't complain for 'ref' which is 
> retrieved just before 'visits'?

Are you sure refs is null?  According to the sample values you gave, refs
is 'Europe/Athens'.

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Mark Lawrence

On 05/11/2013 22:28, Nick the Gr33k wrote:

Στις 6/11/2013 12:06 πμ, ο/η John Gordon έγραψε:

In  Nick the Gr33k 
writes:


# 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()



if cur.rowcount:
# unpack data into variables
(ref, visit, download) = data

visit = visit.split()

[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218] visit =
visit.split()
[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218]
AttributeError: 'NoneType' object has no attribute 'split'


It appears that in the row you're fetching from the visitors table, the
'visits' column is NULL.

Your next step is track down why.


Indeed.

The code i provided only worked once before it failed and managed to
store this:


counterID,host,refs,city,userOS,browser,visits,hits,download
-
1, 176-92-96-218.adsl.cyta.gr, Europe/Athens, Windows, Chrome,
-00-00 00:00:00, 1, ''

'visit's column is full of zeroes. Perhaps this is considered  as Null
for Python?

But ref is also null, why the code didn't complain for 'ref' which is
retrieved just before 'visits'?

How, i eman what si the way to investigate this further?



Don't worry about it.  Just leave it with the crack team that I've put 
together for you.  We should have some answers some time tomorrow.


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

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Nick the Gr33k

Στις 6/11/2013 12:15 πμ, ο/η Piet van Oostrum έγραψε:

Nick the Gr33k  writes:



IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.

ALL I WANT IT TO DO IS JUST

1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
2. CONVERT LONG STRINGS TO LISTS
3. ADD SOME CURRENT VALUES TO THOSE LISTS
4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST
PYTHON DATATYPE TO MYSQL SCALAR STRING.

EVERYHTIGN I TRIED FAILED.


Then why don't you use the simple solution: use a relational database to store 
the data?




--
How you mean?

Up until now i was using for years MySQL.
Now i realizes i just cannot store lists into it's columns because it 
does not support a collection datatype.


perhaps its time to use postgresql so to avoid these coversions?

does postgresql support "collection" columns?

and is its synta
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Nick the Gr33k

Στις 6/11/2013 12:06 πμ, ο/η John Gordon έγραψε:

In  Nick the Gr33k  
writes:


# 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()



if cur.rowcount:
# unpack data into variables
(ref, visit, download) = data

visit = visit.split()

[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218] visit =
visit.split()
[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218]
AttributeError: 'NoneType' object has no attribute 'split'


It appears that in the row you're fetching from the visitors table, the
'visits' column is NULL.

Your next step is track down why.


Indeed.

The code i provided only worked once before it failed and managed to 
store this:



counterID,host,refs,city,userOS,browser,visits,hits,download
-
1, 176-92-96-218.adsl.cyta.gr, Europe/Athens, Windows, Chrome, 
-00-00 00:00:00, 1, ''


'visit's column is full of zeroes. Perhaps this is considered  as Null 
for Python?


But ref is also null, why the code didn't complain for 'ref' which is 
retrieved just before 'visits'?


How, i eman what si the way to investigate this further?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Piet van Oostrum
Nick the Gr33k  writes:

>
> IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.
>
> ALL I WANT IT TO DO IS JUST
>
> 1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
> 2. CONVERT LONG STRINGS TO LISTS
> 3. ADD SOME CURRENT VALUES TO THOSE LISTS
> 4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST
> PYTHON DATATYPE TO MYSQL SCALAR STRING.
>
> EVERYHTIGN I TRIED FAILED.

Then why don't you use the simple solution: use a relational database to store 
the data?
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread John Gordon
In  Nick the Gr33k  
writes:

>   # 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()

>   if cur.rowcount:
>   # unpack data into variables
>   (ref, visit, download) = data
>   
>   visit = visit.split()
>   
> [Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218] visit = 
> visit.split()
> [Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218] 
> AttributeError: 'NoneType' object has no attribute 'split'

It appears that in the row you're fetching from the visitors table, the
'visits' column is NULL.

Your next step is track down why.

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Chris Angelico
On Wed, Nov 6, 2013 at 8:17 AM, Mark Lawrence  wrote:
> I've taken a different approach. I've put the contract out to tender and
> hereby give you the winners
> http://www.mudefordwoodcommunitycentre.co.uk/playgroup-and-tiny-tots/

Sounds good! But I don't see a list of their technologies - do they
use open source tools like Python, or is it proprietary stuff like
Fisher-Price(tm) "My First Website"? The latter is probably sufficient
for these tasks, but I would hope that your contractors are able to
master real-world problems too.

Nikos, once again you are getting yourself into a tizz over this,
because the problem is urgent to you. You need to stop programming
professionally and make it a hobby, so that you remove the time
pressure. You cope badly with pressure, so why torture yourself? Get
into a completely different industry for your day job, and do all your
programming in the evenings. You'll find lots of things easier and
less stressful.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Mark Lawrence

On 05/11/2013 21:17, Mark Lawrence wrote:

On 05/11/2013 20:19, John Gordon wrote:

In  Nick the Gr33k 
writes:


IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.



ALL I WANT IT TO DO IS JUST



1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
2. CONVERT LONG STRINGS TO LISTS
3. ADD SOME CURRENT VALUES TO THOSE LISTS
4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST
PYTHON DATATYPE TO MYSQL SCALAR STRING.



EVERYHTIGN I TRIED FAILED.


How did it fail?

Error message?
No results at all?
Different results than you wanted?  If so, how did they differ?



Dear John,

This approach has already been tried by Dave Angel, Steven D'Aprano and
Chris Angelico amongst others and has failed dismally so why should you
be any different?

I've taken a different approach. I've put the contract out to tender and
hereby give you the winners
http://www.mudefordwoodcommunitycentre.co.uk/playgroup-and-tiny-tots/

Part of the rationale is that they're literally 100 yards from my front
door so communicating with them effectively should be extremely easy.
This will be particularly useful when it comes down to debugging such
difficult issues as "> TypeError: 'NoneType' object is not iterable".

I'm looking forward to working in partnership with them and am convinced
that within a few days all of Nikos' problems will have been solved.



Oh dear it looks as if we might have to renegotiate the contract as I 
understand that we've an almost intractable problem to solve it's 
"AttributeError: 'NoneType' object has no attribute 'split'".


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

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 10:19 μμ, ο/η John Gordon έγραψε:

In  Nick the Gr33k  
writes:


IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.



ALL I WANT IT TO DO IS JUST



1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
2. CONVERT LONG STRINGS TO LISTS
3. ADD SOME CURRENT VALUES TO THOSE LISTS
4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST
PYTHON DATATYPE TO MYSQL SCALAR STRING.



EVERYHTIGN I TRIED FAILED.


How did it fail?

Error message?
No results at all?
Different results than you wanted?  If so, how did they differ?




I know i'm close to solution, i can feel it but i have some issues.
The code we arr discussing is the following:


=
# ~ DATABASE INSERTS ~
=
if cookieID != 'nikos' and ( os.path.exists( path + page ) or 
os.path.exists( cgi_path + page ) ) and re.search( 
r'(amazon|google|proxy|cloud|reverse|fetch|msn|who|spider|crawl|ping)', 
host ) is None:


try:
		# 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()

ref = visit = download = []
if cur.rowcount:
# unpack data into variables
(ref, visit, download) = data

# retrieve long strings and convert them into lists 
respectively
ref = ref.split()
visit = visit.split()
download = download.split()
else:
# initiate these values
ref = ref
visit = lastvisit
download = ''

refs = visits = downloads = []
# add current values 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, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
		ON DUPLICATE KEY UPDATE refs = %s, visits = %s, hits = hits + 1, 
downloads = %s''',
		(cID, refs, host, city, useros, browser, visits, downloads, refs, 
visits, downloads) )


con.commit()
except pymysql.ProgrammingError as e:
print( repr(e) )
con.rollback()
sys.exit(0)
===


[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 274, in 
[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218] visit = 
visit.split()
[Tue Nov 05 23:21:52 2013] [error] [client 176.92.96.218] 
AttributeError: 'NoneType' object has no attribute 'split'

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Mark Lawrence

On 05/11/2013 20:19, John Gordon wrote:

In  Nick the Gr33k  
writes:


IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.



ALL I WANT IT TO DO IS JUST



1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
2. CONVERT LONG STRINGS TO LISTS
3. ADD SOME CURRENT VALUES TO THOSE LISTS
4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST
PYTHON DATATYPE TO MYSQL SCALAR STRING.



EVERYHTIGN I TRIED FAILED.


How did it fail?

Error message?
No results at all?
Different results than you wanted?  If so, how did they differ?



Dear John,

This approach has already been tried by Dave Angel, Steven D'Aprano and 
Chris Angelico amongst others and has failed dismally so why should you 
be any different?


I've taken a different approach. I've put the contract out to tender and 
hereby give you the winners 
http://www.mudefordwoodcommunitycentre.co.uk/playgroup-and-tiny-tots/


Part of the rationale is that they're literally 100 yards from my front 
door so communicating with them effectively should be extremely easy. 
This will be particularly useful when it comes down to debugging such 
difficult issues as "> TypeError: 'NoneType' object is not iterable".


I'm looking forward to working in partnership with them and am convinced 
that within a few days all of Nikos' problems will have been solved.


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

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread John Gordon
In  Nick the Gr33k  
writes:

> IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.

> ALL I WANT IT TO DO IS JUST

> 1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
> 2. CONVERT LONG STRINGS TO LISTS
> 3. ADD SOME CURRENT VALUES TO THOSE LISTS
> 4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST 
> PYTHON DATATYPE TO MYSQL SCALAR STRING.

> EVERYHTIGN I TRIED FAILED.

How did it fail?

Error message?
No results at all?
Different results than you wanted?  If so, how did they differ?

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Denis McMahon
On Tue, 05 Nov 2013 20:09:42 +0200, Nick the Gr33k wrote:

> Denis, i have already provided my code trying to do what i need and i
> need some commendation on how to make it work.

Nick, you're obviously trying to code way above your abilities.

If you want me to write your code, you will have to pay my day rate, and 
you can't afford it. If you could afford it, you'd be paying someone 
competent already.

Here, have a code example, this works, although the formatting might get 
broken. The database "ntg1" has a single table called str_idx defined as 
follows:

create table idx_str ( idx int primary key, str varchar[1024] );

#!/usr/bin/python

import random
import sqlite3

def make_list( length ):
l = []
if ( length < 1 ):
return l
for count in range( 0, length ):
s = '';
for i in range( 1, random.randrange( 4, 12 ) ):
c = chr( random.randrange( 97, 123 ) )
s += c
l.append( s )
return l

def list_to_string( l ):
return "|".join( l )

def string_to_list( s ):
return s.split( "|" )

l1 = make_list( 10 )
print "l1 -> ", l1
s = list_to_string( l1 )
print "s -> ", s
l2 = string_to_list( s )
print "l2 -> ", l2
print "l1 == l2 -> ", l2 == l1

l2 = make_list( 10 )
l3 = make_list( 10 )
l4 = make_list( 10 )

print "Original Lists"
print "l1 -> ", l1
print "l2 -> ", l2
print "l3 -> ", l3
print "l4 -> ", l4

conn = sqlite3.connect( "ntg1" )
cur = conn.cursor()
cur.execute( "delete from idx_str where idx is not null" )
cur.execute( 
"insert into idx_str values ( 1, '{0}' )".format( 
list_to_string( l1 ) ) )
cur.execute( 
"insert into idx_str values ( 2, '{0}' )".format( 
list_to_string( l2 ) ) )
cur.execute( 
"insert into idx_str values ( 3, '{0}' )".format( 
list_to_string( l3 ) ) )
cur.execute( 
"insert into idx_str values ( 4, '{0}' )".format( 
list_to_string( l4 ) ) )
conn.commit()
conn.close()

print "Lists now in DB"
print "Reading 1 record at a time"

conn2 = sqlite3.connect( "ntg1" )
cur2 = conn2.cursor()

cur2.execute( "select * from idx_str where idx = 1" );
row = cur2.fetchone()
print "stored 1 -> ", row[ 1 ]
print "l1 -> ", string_to_list( row[ 1 ] )

cur2.execute( "select * from idx_str where idx = 2" );
row = cur2.fetchone()
print "stored 2 -> ", row[ 1 ]
print "l2 -> ", string_to_list( row[ 1 ] )

cur2.execute( "select * from idx_str where idx = 3" );
row = cur2.fetchone()
print "stored 3 -> ", row[ 1 ]
print "l3 -> ", string_to_list( row[ 1 ] )

cur2.execute( "select * from idx_str where idx = 4" );
row = cur2.fetchone()
print "stored 4 -> ", row[ 1 ]
print "l4 -> ", string_to_list( row[ 1 ] )

conn2.close()

print "Reading all records at once"

conn3 = sqlite3.connect( "ntg1" )

cur3 = conn3.cursor()

cur3.execute( "select * from idx_str" );

row = cur3.fetchone()

while not row == None:

print "stored ", row[ 0 ], " -> ", row[ 1 ]
print "list ", row[ 0 ], " -> ", string_to_list( row[ 1 ] )
row = cur3.fetchone()

conn3.close()

One thing you haven't considered, what happens if a user has so many 
downloads in his list that the converted list doesn't fit in the declared 
string column width in your database?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Joel Goldstick
On Tue, Nov 5, 2013 at 1:11 PM, Tobiah  wrote:
> All this problem arises because MySQL's hasn't got a datatype able to store
> an array of elements, a list.
>
> Um, yes it does.  It's called a table.
> --
> https://mail.python.org/mailman/listinfo/python-list

Perhaps we are splitting hairs, but a relational database will let you
stuff any text you want in a text field, but First Normal Form is a
necessary (and not complete) requirement (from wikipedia)

First normal form (1NF) is a property of a relation in a relational
database. A relation is in first normal form if the domain of each
attribute contains only atomic values, and the value of each attribute
contains only a single value from that domain.[1]

If you don't have a single thing in a field, you can't search or sort
it or filter by its value with sql.  Since those are very important
properties of sql, not using 1nf is similar to tossing a whole
warehouse of stuff in a warehouse without any sort of organization for
where different things are to be put, and therefore, where they can be
found.

If you don't have first normal form data, you are misusing a
relational database.  If you don't want to learn about relational
databases and what they can do to help you construct software that
solves interesting problems, then perhaps you are not curious enough
to ever become competent in the field.

That said, sql is a different beast than is python or php or any
procedural (or oops) language.  Just like writing HTML and CSS is
something that people who write computer programs for the web might
do,  its a total shift in thinking from writing python.

There is no rule that a person must be a computer programmer, but if a
person wants to be a competent and successful computer programmer, one
must learn from the evolving understanding of the last 50 years or so.
 Its a craft of understanding how to divide impossibly large problems
into understandable pieces -- using the best tools for each piece.
You may say this is just one person's opinion -- but then again, I'm
not the one screaming in all caps about the same several problems over
and over for the last year or more on this list.  The results show no
more understanding or growth in skills, and an attitude that never
shows a glimmer of interest in learning.




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Tobiah

All this problem arises because MySQL's hasn't got a datatype able to store an 
array of elements, a list.

Um, yes it does.  It's called a table.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 8:02 μμ, ο/η Denis McMahon έγραψε:

On Tue, 05 Nov 2013 19:06:25 +0200, Nick the Gr33k wrote:


IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.


Try starting with something simple. The following is a step by step guide
to working out how you need to do this. Follow all the steps. Do not skip
any steps. Each stage builds on the previous code.

Write python code to create a list of strings and print out the elements
of the list. This just needs to generate a list of n entries of m
characters in length of random character data.

Write python code to concatenate a list of strings into some longer
string using a separator and print out the long string.

Now add some python code to split the long string into a list based on
the separator, and print out the list elements.

Once you have this code working, make a test table with a single string
column and an integer index field in a test database.

Now this is starting to push the boundaries of your abilities, but write
code to create two lists, and store them with indexes 1 and 2
respectively.

Now, and this is really really going to tax you, write some more code
that will first retrieve the string for index 1, convert it back into a
list, and display the list contents, then do the same for list 2, then
retrieve all the data from the db and reproduce each list in turn.

Then you might be ready to try coding what you're trying to code.




--
Denis, i have already provided my code trying to do what i need and i 
need some commendation on how to make it work.


O even better an rdbms than allows complex data such as tuples, lists, 
dicts to be saved into the db as they are so i dont have to cobvet back 
and forth each time.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Denis McMahon
On Tue, 05 Nov 2013 19:06:25 +0200, Nick the Gr33k wrote:

> IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.

Try starting with something simple. The following is a step by step guide 
to working out how you need to do this. Follow all the steps. Do not skip 
any steps. Each stage builds on the previous code.

Write python code to create a list of strings and print out the elements 
of the list. This just needs to generate a list of n entries of m 
characters in length of random character data.

Write python code to concatenate a list of strings into some longer 
string using a separator and print out the long string.

Now add some python code to split the long string into a list based on 
the separator, and print out the list elements.

Once you have this code working, make a test table with a single string 
column and an integer index field in a test database.

Now this is starting to push the boundaries of your abilities, but write 
code to create two lists, and store them with indexes 1 and 2 
respectively.

Now, and this is really really going to tax you, write some more code 
that will first retrieve the string for index 1, convert it back into a 
list, and display the list contents, then do the same for list 2, then 
retrieve all the data from the db and reproduce each list in turn.

Then you might be ready to try coding what you're trying to code.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 7:41 μμ, ο/η Steven D'Aprano έγραψε:

On Tue, 05 Nov 2013 19:06:25 +0200, Nick the Gr33k wrote:


ALL I WANT IT TO DO IS JUST

1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS 2. CONVERT LONG
STRINGS TO LISTS
3. ADD SOME CURRENT VALUES TO THOSE LISTS 4. CONVERT FROM LISTS TO LONG
STRINGS SO I CAN STORE SUCCESSFULLY LIST PYTHON DATATYPE TO MYSQL SCALAR
STRING.



You cannot do this with Python. You should use a better language more
suited to you. Try this:

http://php.net/manual/en/tutorial.php


I hope that you will be much happier with this, since you are struggling
to get Python to work the way you want it to.





--
Steven, i want switch to php, i uses to start with php, then perl and 
now i ended up with python.


All this problem arises because MySQL's hasn't got a datatype able to 
store an array of elements, a list.


Is there some other database, sql connector i can use except 'pymysql' 
that supports a "collection" record type?


postgresql or somethign similar?
If it does i will switch to that and avoid these tedius convertions from 
long strings => list and backwise.


Somehting that can just take Python's datatypes 'list' or 'tuple' or 
'dict' as tehy are and just store them into the database convertionless.



--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Antoon Pardon
Op 05-11-13 18:41, Steven D'Aprano schreef:
> On Tue, 05 Nov 2013 19:06:25 +0200, Nick the Gr33k wrote:
> 
>> ALL I WANT IT TO DO IS JUST
>>
>> 1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS 2. CONVERT LONG
>> STRINGS TO LISTS
>> 3. ADD SOME CURRENT VALUES TO THOSE LISTS 4. CONVERT FROM LISTS TO LONG
>> STRINGS SO I CAN STORE SUCCESSFULLY LIST PYTHON DATATYPE TO MYSQL SCALAR
>> STRING.
> 
> 
> You cannot do this with Python. You should use a better language more 
> suited to you. Try this:
> 
> http://php.net/manual/en/tutorial.php
> 
> 
> I hope that you will be much happier with this, since you are struggling 
> to get Python to work the way you want it to.

Steve, what went on in your mind? If Nikos follows you advise he will
probably come here with all kinds of php questions.

-- 
Antoon Pardon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Denis McMahon
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, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Steven D'Aprano
On Tue, 05 Nov 2013 19:06:25 +0200, Nick the Gr33k wrote:

> ALL I WANT IT TO DO IS JUST
> 
> 1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS 2. CONVERT LONG
> STRINGS TO LISTS
> 3. ADD SOME CURRENT VALUES TO THOSE LISTS 4. CONVERT FROM LISTS TO LONG
> STRINGS SO I CAN STORE SUCCESSFULLY LIST PYTHON DATATYPE TO MYSQL SCALAR
> STRING.


You cannot do this with Python. You should use a better language more 
suited to you. Try this:

http://php.net/manual/en/tutorial.php


I hope that you will be much happier with this, since you are struggling 
to get Python to work the way you want it to.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread mm0fmf

EVERYHTIGN I TRIED FAILED.


Maybe try some of the advice you have been given instead?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with this code PLEASE

2013-11-05 Thread Antoon Pardon

> =
> 
> IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.
> 
> ALL I WANT IT TO DO IS JUST
> 
> 1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
> 2. CONVERT LONG STRINGS TO LISTS
> 3. ADD SOME CURRENT VALUES TO THOSE LISTS
> 4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST PYTHON 
> DATATYPE TO MYSQL SCALAR STRING.
> 
> EVERYHTIGN I TRIED FAILED.

Don't start a new thread, where you just ask the same question, you already 
asked before.
The answer will not be different just because you started a new thread.

Did you already read the documentation of fetchone?

-- 
Antoon Pardon


-- 
https://mail.python.org/mailman/listinfo/python-list


Help me with this code PLEASE

2013-11-05 Thread Nick the Gr33k

==
# 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
ref = ref.split()
visit = visit.split()
download = download.split()
else:
# initiate these values
ref = ref
visit = lastvisit
download = ''

refs = visits = downloads = []
# add current values 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, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
		ON DUPLICATE KEY UPDATE refs = %s, visits = %s, hits = hits + 1, 
downloads = %s''',
		(cID, refs, host, city, useros, browser, visits, downloads, refs, 
visits, downloads) )

=

IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.

ALL I WANT IT TO DO IS JUST

1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
2. CONVERT LONG STRINGS TO LISTS
3. ADD SOME CURRENT VALUES TO THOSE LISTS
4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST 
PYTHON DATATYPE TO MYSQL SCALAR STRING.


EVERYHTIGN I TRIED FAILED.
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 1:16 μμ, ο/η Dave Angel έγραψε:

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.


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 :( :( :(
--
https://mail.python.org/mailman/listinfo/python-list


Re: how to find out utf or not

2013-11-05 Thread Steven D'Aprano
On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh wrote:

> Dear all,
> 
> Suppose i have a variable such as : myVar = 'x'
> 
> May be it initialized with myVar = u'x' or myVar = 'x'

Can't you just look at the code and tell which it is?


> So i need determine content of myVar that it's utf-8 or not, how can i
> do it?

I think you misunderstand the difference between Unicode and UTF-8. The 
first thing you must understand is that Unicode does not mean UTF-8. They 
are different things. Anyone who has told you that they are the same is 
also mistaken.

Unicode is an abstract collection of characters, a character set. 
(Technically, code points rather than characters, but don't worry about 
that yet.) In Python 2, you normally create a Unicode string with either 
the u"..." literal syntax, or the unicode() function. A Unicode string 
might look like this:

abc§жπxyz

Each character has an ordinal value, which is the same as its Unicode 
code point:

py> s = u'abc§жπxyz'
py> for char in s:
... print char, ord(char)
...
a 97
b 98
c 99
§ 167
ж 1078
π 960
x 120
y 121
z 122


Note that ordinal values go *far* beyond 256. They go from 0 to 1114111. 
So a Unicode string is a string of code points, in this example:

97 98 99 167 1078 960 120 121 122

Of course, computers don't understand "code points" any more than they 
understand "sounds" or "movies" or "pictures of cats". Computers only 
understand *bytes*. So how are these code points represented as bytes? By 
using an encoding -- an encoding tells the computer how to represent 
characters like "a", "b" and "ж" as bytes, for storage on disk or in 
memory.

There are at least six different encodings for Unicode strings, and UTF-8 
is only one of them. The others are two varieties each of UTF-16 and 
UTF-32, and UTF-7. Given the unicode string:

u'abc§жπxyz'

it could be stored in memory as any of these sequences of hexadecimal 
bytes:

610062006300A7003604C003780079007A00

00610062006300A7043603C000780079007A

610062006300A7003604C003780079007A00

00610062006300A7043603C000780079007A

616263C2A7D0B6CF8078797A

6162632B414B63454E6750412D78797A


and likely others as well. Which one will Python use? That depends on the 
version of Python, how the interpreter was built, what operating system 
you are using, and various other factors. Without knowing lots of 
technical detail about your specific Python interpreter, I can't tell 
which encoding it will be using internally. But I can be pretty sure that 
it isn't using UTF-8.

So, you have a variable. Perhaps it has been passed to you from another 
function, and you need to find out what it is. In this case, you do the 
same thing you would do for any other type (int, list, dict, str, ...) 
and use isinstance:

if isinstance(myVar, unicode):
...


If myVar is a Unicode string, you don't need to care about the encoding 
(UTF-8 or otherwise) until you're ready to write it to a file. Then I 
strongly recommend you always use UTF-8, unless you have to interoperate 
with some old, legacy system:

assert isinstance(myVar, unicode)
byte_string = myVar.encode('utf-8')


will return a byte-string encoded using UTF-8.

If myVar is a byte-string, like 'abc' without the u'' prefix, then you 
have a bit of a problem. Think of it like a file without a file 
extension: it could be a JPEG, a WAV, a DLL, anything. There's no real 
way to be sure. You can look inside the file and try to guess, but that's 
not always reliable. Without the extension "myfile.jpg", "myfile.wav", 
etc. you can't tell for sure what "myfile" is (although sometimes you can 
make a good prediction: "my holiday picture" is probably a JPEG.

And so it is with byte-strings. Unless you know where they came from and 
how they were prepared, you can't easily tell what encoding they used, at 
least not without guessing. But if you control the source of the data, 
and make sure you only use the encoding of your choice (let's say UTF-8), 
then it is easy to convert the bytes into Unicode:

assert isinstance(myVar, str)
unicode_string = myVar.decode('utf-8')



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 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 )
...
nikospts/0Nov  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.
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Joel Goldstick
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread 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


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 3:15 μμ, ο/η Dave Angel έγραψε:

On Tue, 05 Nov 2013 14:25:41 +0200, Nick the Gr33k
 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?





ni...@superhost.gr [~]# who
nikospts/0Nov  5 09:57 (176.92.96.218)
ni...@superhost.gr [~]# who > myfile.txt
ni...@superhost.gr [~]# cat myfile.txt
nikospts/0Nov  5 09:57 (176.92.96.218)
ni...@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 "", line 2
print( line )
^
IndentationError: expected an indented block

for line in data:

... print( line )
...
Traceback (most recent call last):
  File "", line 1, in 
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.
--
https://mail.python.org/mailman/listinfo/python-list


Re: how to find out utf or not

2013-11-05 Thread Neil Cerutti
On 2013-11-05, Dave Angel  wrote:
> On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh 
> wrote:
>> Suppose i have a variable such as : myVar = 'x'
>
>> May be it initialized with myVar = u'x' or myVar = 'x'
>
>> So i need determine content of myVar that it's utf-8 or not, how 
> can i
>> do it?
>
> Use the type() function and compare to unicode or str
> respectively. E.g.  If type(myvar)==unicode:

That will tell you wether it's a unicode string or a byte string,
but not the encoding of the source bytes. Unless there's some
context I'm not privy to.

u'x' is (hopefully) decoded already, but the encoding of 'x' is
unknown.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to find out utf or not

2013-11-05 Thread Dave Angel
On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh 
 wrote:

Suppose i have a variable such as : myVar = 'x'



May be it initialized with myVar = u'x' or myVar = 'x'


So i need determine content of myVar that it's utf-8 or not, how 

can i

do it?


Use the type() function and compare to unicode or str respectively.
E.g.  If type(myvar)==unicode:

--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


how to find out utf or not

2013-11-05 Thread Mohsen Pahlevanzadeh
Dear all,

Suppose i have a variable such as : myVar = 'x'

May be it initialized with myVar = u'x' or myVar = 'x'

So i need determine content of myVar that it's utf-8 or not, how can i
do it?


--mohsen



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Dave Angel
On Tue, 05 Nov 2013 14:25:41 +0200, Nick the Gr33k 
 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

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Antoon Pardon
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 
> [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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 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 
[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.

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread 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.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Dave Angel
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.


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

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Dave Angel
On Tue, 05 Nov 2013 11:34:53 +0200, Nick the Gr33k 
 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

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Antoon Pardon
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 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?

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Chris Angelico
On Tue, Nov 5, 2013 at 8:10 PM, M.F.  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Antoon Pardon
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 
> [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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Antoon Pardon
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 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 
[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?

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread 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.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python3 for BeagleBone Black (Angstrom distro)

2013-11-05 Thread Amirouche Boubekki
Use this http://hg.python.org/cpython/file/92022b45e60b/setup.py#l36

Add the list of modules you want to disable and redo make


2013/11/5 Travis Griggs 

>
> On Nov 4, 2013, at 9:22 AM, Travis Griggs  wrote:
>
> > I'm playing with a BeagleBone Black running the angstrom distro. Of
> course, stock python is 2.7, I'd rather use python3. There isn't a python3
> package available for angstrom. So I downloaded the source and compiled. It
> seemed to work pretty well. I used the basic approach outlined in the
> REAMDE:
> >
> > ./configure
> > make
> > make test
> > make install
> >
> > Now, I want to repeat the process, but be a little more judicious about
> what all is compiled. For example, I don't really need tk stuff (in fact,
> it just kept telling me it wasn't there). And there's probably a number of
> other modules/libraries in the kitchen sink known as the stock install,
> that I could forgo on a tiny little computer like this.
> >
> > I see, looking at ./configure --help | less, that I could provide
> --disable-FEATURE and --without-PACKAGE directives to my ./configure
> invocation. But what I don't see is how to generate a list of what
> FEATURES/PACKAGES I could put there for consideration of omission. Is there
> some magic juju that generates that?
> >
>
> Should I have asked this question on python-dev instead? Not currently
> subscribed there… but would if that would generate more informed responses.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread 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.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python 3.3.2 on CentOS 6.4 - unable to find compiled OpenSSL?

2013-11-05 Thread Christian Heimes
Am 05.11.2013 01:23, schrieb Victor Hooi:
> Hi,
> 
> We have a machine running CentOS 6.4, and we're attempting to compile Python 
> 3.3.2 on it:
> 
>   # cat /etc/redhat-release
>   CentOS release 6.4 (Final)
> 
> We've compiled openssl 1.0.1e 11 by hand on this box, and installed it into 
> /usr/local/:

I guess Python picks up OpenSSL header files from /usr/include instead
of /usr/local/include but uses the libraries from /usr/local/lib

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trouble with utf-8 values

2013-11-05 Thread Peter Otten
Ulrich Goebel wrote:

> Hallo,
> 
> again: a python beginner problem... but I spent ours to solve it without
> success.
> 
> I have an object (a variable) name, which gets its value from a
> PostgreSQL database via a SELECT statement, an it sometimes has german
> special characters as ß, ä, ö...
> 
> Then I would like to insert that value into a table in a SQLite
> database. So I make a cursor cur on the table and prepare a SQL
> statement like this:
> 
> sql = 'insert into tbl values(?)'
> cur.execute(sql, (name,))
> 
> That ends up with the exception, for example,
> 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6:
> ordinal not in range(128)
> 
> The "position 6" is exactly the position of the special character, ß in
> this case.
> 
> What to do?

While sqlite works with unicode out of the box it looks like the PostgreSQL 
adapter needs to be convinced first:

http://initd.org/psycopg/docs/usage.html#unicode-handling

Try adding the voodoo suggested above

import psycopg2
import psycopg2.extensions
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)

to your script. I'm of course assuming you are using python 2.x and 
pyscopg2...



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 10:21 πμ, ο/η Chris Angelico έγραψε:

On Tue, Nov 5, 2013 at 7:07 PM, Nick the Gr33k  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.
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 10:21 πμ, ο/η Chris Angelico έγραψε:

On Tue, Nov 5, 2013 at 7:07 PM, Nick the Gr33k  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.
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Antoon Pardon
Op 05-11-13 09:21, Chris Angelico schreef:
> On Tue, Nov 5, 2013 at 7:07 PM, Nick the Gr33k  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Chris Angelico
On Tue, Nov 5, 2013 at 7:07 PM, Nick the Gr33k  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).

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-05 Thread Nick the Gr33k

Στις 5/11/2013 8:54 πμ, ο/η Nick the Gr33k έγραψε:

Στις 5/11/2013 12:46 πμ, ο/η Denis McMahon έγραψε:

On Mon, 04 Nov 2013 19:03:58 +0200, Nick the Gr33k wrote:



There is no built in support in the python / mysql system for puttinga
list straight into a database, because mysql does not have"collection"
record type.


Does postgresql has this 'collection' record type



You could convert the python list into a storable entity, for example
imploding a list of strings with some arbitrary separator to create a
long string, store the long string, then when you read it from the
database explode it back into a list.
Which method you use is up to you. There may be others.
Pick a method and code it.


Okey here is my attempt to code your solution as best as i can get my
head around it:

This is the part that is responsible to do the database insertion
converting scalars to lists and backwards.

=
 try:
 # 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''', cID )
 data = cur.fetchone

 ref = data[0]
 visit = data[1]
 download = data[2]

 # retrieve long strings and convert them into lists respectively
 refs = ref.split()
 visits = visit.split()
 downloads = download.split()

 # add current strings to the each list respectively
 refs.appends( ref )
 visits.appends( visit )
 downloads.appends( download )

 # convert lists back to longstrings
 refs = ', '.join( refs )
 visits = ', '.join( visits )
 downloads = ', '.join( downloads )

 # add this visitor entry into database (hits && downloads are
defaulted)
 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) )

 con.commit()
 except pymysql.ProgrammingError as e:
 print( repr(e) )
 con.rollback()
 sys.exit(0)
===

Please tell me if this logic is correct, for some reason it doesn't do
what i need it to do.

Thank you.



Better version for it, i think, but still none working:

=
		# 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 = (SELECT ID FROM counters WHERE url = %s) ORDER BY visits 
DESC''', page )

data = cur.fetchall

for row in data:
(refs, visits, downloads) = row

# 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.appends( ref )
visits.appends( visit )
downloads.appends( download )

# convert lists back to longstrings
refs = ', '.join( refs )
visits = ', '.join( visits )
downloads = ', '.join( downloads )

# add this visitor entry into database (hits && 
downloads are defaulted)
			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 10:06:57 2013] [error] [client 176.92.96.218] Traceback 
(most recent call last):
[Tue Nov 05 10:06:57 2013] [error] [client 176.92.96.218]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 267, in 
[Tue Nov 05 10:06:57 2013] [error] [client 176.92.96.218] for row in 
data:
[Tue Nov 05 10:06:57 2013] [error] [client 176.92.96.218] TypeError: 
'method' object is not iterable


How is ti possible for data to be none iterab