Help me with this code PLEASE

J

John Gordon

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

counterID,host,refs,city,userOS,browser,visits,hits,download

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'.
 
B

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!)
 
M

Mark Lawrence

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

Dennis Lee Bieber

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

He /is/ using a relational database (MySQL, please, no complaints)...
He just doesn't understand what it means to be a relational database:
normalization, primary keys, joins, etc. -- so he is treating the database
like a flat file and trying to fit into one field multi-valued data.
 
D

Denis McMahon

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

Nick the Gr33k

Στις 6/11/2013 12:54 πμ, ο/η John Gordon έγÏαψε:
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?
 
A

Antoon Pardon

Op 05-11-13 22:26, Nick the Gr33k schreef:
I know i'm close to solution, i can feel it but i have some issues.
The code we arr discussing is the following:

No you are not. You are just doing random changes, without any
understanding. If you had followed my suggestion and actually
read the documentation of fetchone, you would have realised
this wouldn't have worked either.

Your resistance to reading the documentation is making you lose
more time than you hoped to win by just going ahead and trying
things blindly.
[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 <module>
[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'

This is essentially the same error you had before. You have an object
of NoneType where you expect something different. Changing your code
to use split instead of iteration won't change the fact that you have
an object of NoneType.
 
M

Mark Lawrence

How, do i i proceed?

If at first you don't succeed, keep asking on comp.lang.python until
someone gives me the completely bodged solution that I keep asking for
even if it's complete nonsense.
 
J

Joel Goldstick

If at first you don't succeed, keep asking on comp.lang.python until someone
gives me the completely bodged solution that I keep asking for even if it's
complete nonsense.


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

Mark Lawrence

Nikos,

I believe we are passed the time again where your enquiries slip from
legitimate questions to trolling behavior. As was pointed out you
aren't close to any solution. You should go off taking the advice and
tutoring you have had here, do some reading (yes, actually learn and
understand something), perhaps start from scratch reading basics of
computer programming, databases, html, unicode, operating systems, web
servers, etc. and come back when you have a solid basis to ask a
question.

I take my profession seriously. Its fun, but it takes a lot of
reading and studying and practice to be good at it. The fact that you
even presume that you are doing what software designers, or engineers
or programmers do to ply the craft is disgusting. Its not that you
don't know, its that you don't know and are an arrogant idiot to
assume that you do.

Your threads all end up being a very poor man's version of the movie
Ground Hog Day. The fact that you don't recognize how rude and
insulting you are, and how little you bring to the discussion will
inevitably lead to more personal attacks since you aren't holding up
your end of the technical back and forth.

Your repeated behavior of starting new threads is just a boring
childish method to demand attention. You have our attention. I
believe that most of us if not all of us think you are the most
aggravating, incompetent, rude, needy, manipulating, person we have
ever seen online ever. Go away, and come back (months from now at
least) when you have some redeeming human qualities.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,090
Messages
2,570,603
Members
47,223
Latest member
smithjens316

Latest Threads

Top