Re: Why 'files.py' does not print the filenames into a table format?
On 17/6/2013 10:00 πμ, Steven D'Aprano wrote: On Mon, 17 Jun 2013 09:11:05 +0300, Νίκος wrote: everything work as expected but not the part when the counter of a filename gets increased when the file have been requested. I don't see how since: if filename: #update file counter cur.execute('''UPDATE files SET hits = hits + 1, host = %s, lastvisit = %s WHERE url = %s''', (host, lastvisit, filename) ) There isn'tmuch to say ehre. You already know the code that im using inside files.pu and the question is that this execute never gets to execute. # = # Make sure that ALL database records are filenames in existance # = filenames = [] # Switch filenames from (utf8 bytestrings => unicode strings) and trim them from their paths for utf8_filename in utf8_filenames: filenames.append( utf8_filename.decode('utf-8').replace( '/home/nikos/public_html/data/apps/', '' ) ) # Check the presence of a database file against the dir files and delete record if it doesn't exist cur.execute('''SELECT url FROM files''') data = cur.fetchall() # Delete spurious database records for rec in data: if rec not in filenames: cur.execute('''DELETE FROM files WHERE url = %s''', rec ) # Load'em for filename in filenames: try: # Check the presence of current filename against it's database presence cur.execute('''SELECT url FROM files WHERE url = %s''', filename ) data = cur.fetchone() if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) # = # Display ALL files, each with its own download button # = print(''' ''') try: cur.execute( '''SELECT * FROM files ORDER BY lastvisit DESC''' ) data = cur.fetchall() for row in data: (filename, hits, host, lastvisit) = row lastvisit = lastvisit.strftime('%A %e %b, %H:%M') print(''' %s %s %s ''' % (filename, hits, host, lastvisit) ) print( '' ) except pymysql.ProgrammingError as e: print( repr(e) ) sys.exit(0) After a spcific file gets selected then files.py is reloading grabbign the filename as a variable form and: # = # If user downloaded a file, thank the user !!! # = if filename: #update filename's counter if cookie does not exist cur.execute('''UPDATE files SET hits = hits + 1, host = %s, lastvisit = %s WHERE url = %s''', (host, lastvisit, filename) ) but the execute never happesn. i ahve tested it if data: print soemthing but data is always empty. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Why 'files.py' does not print the filenames into a table format?
On 17/6/2013 12:07 μμ, Simpleton wrote: # Load'em for filename in filenames: try: # Check the presence of current filename against it's database presence cur.execute('''SELECT url FROM files WHERE url = %s''', filename ) data = cur.fetchone() if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) Also i just alternated the above code to: # Load'em for filename in filenames: try: # try to insert the file into the database cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) except pymysql.ProgrammingError as e: # Insertion failed, file already into database, skip this, go to next filename pass Isn't more compact and straightforward this way? but i have to set the url's type into unique type for the abpve to work? -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Why 'files.py' does not print the filenames into a table format?
On 17/6/2013 12:07 μμ, Simpleton wrote: On 17/6/2013 10:00 πμ, Steven D'Aprano wrote: On Mon, 17 Jun 2013 09:11:05 +0300, Νίκος wrote: everything work as expected but not the part when the counter of a filename gets increased when the file have been requested. I don't see how since: if filename: #update file counter cur.execute('''UPDATE files SET hits = hits + 1, host = %s, lastvisit = %s WHERE url = %s''', (host, lastvisit, filename) ) There isn'tmuch to say ehre. You already know the code that im using inside files.pu and the question is that this execute never gets to execute. # = # Make sure that ALL database records are filenames in existance # = filenames = [] # Switch filenames from (utf8 bytestrings => unicode strings) and trim them from their paths for utf8_filename in utf8_filenames: filenames.append( utf8_filename.decode('utf-8').replace( '/home/nikos/public_html/data/apps/', '' ) ) # Check the presence of a database file against the dir files and delete record if it doesn't exist cur.execute('''SELECT url FROM files''') data = cur.fetchall() # Delete spurious database records for rec in data: if rec not in filenames: cur.execute('''DELETE FROM files WHERE url = %s''', rec ) # Load'em for filename in filenames: try: # Check the presence of current filename against it's database presence cur.execute('''SELECT url FROM files WHERE url = %s''', filename ) data = cur.fetchone() if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) # = # Display ALL files, each with its own download button # = print(''' ''') try: cur.execute( '''SELECT * FROM files ORDER BY lastvisit DESC''' ) data = cur.fetchall() for row in data: (filename, hits, host, lastvisit) = row lastvisit = lastvisit.strftime('%A %e %b, %H:%M') print(''' %s %s %s ''' % (filename, hits, host, lastvisit) ) print( '''''' ) except pymysql.ProgrammingError as e: print( repr(e) ) sys.exit(0) After a spcific file gets selected then files.py is reloading grabbign the filename as a variable form and: # = # If user downloaded a file, thank the user !!! # = if filename: #update filename's counter if cookie does not exist cur.execute('''UPDATE files SET hits = hits + 1, host = %s, lastvisit = %s WHERE url = %s''', (host, lastvisit, filename) ) but the execute never happesn. i ahve tested it if data: print soemthing but data is always empty. So any ideas why the update statements never gets executed? -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: Now, in languages like Python, Ruby, Java, and many others, there is no table of memory addresses. Instead, there is a namespace, which is an association between some name and some value: global namespace: x --> 23 y --> "hello world" First of all thanks for the excellent and detailed explanation Steven. As for namespace: a = 5 1. a is associated to some memory location 2. the latter holds value 5 So 'a', is a reference to that memory location, so its more like a name to that memory location, yes? Instead of accessing a memory address with a use of an integer like "14858485995" we use 'a' instead. So is it safe to say that in Python a == &a ? (& stands for memory address) is the above correct? I say this because here you said that: Instead, there is a namespace, which is anassociation between some name and some value: When you say that you mean that a is associated to some value as in memory location or to that memory location's address? -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 17/6/2013 2:58 μμ, Michael Torrie wrote: In python just think of assignment as making a name *be* an object. And if you assign one name to another name, that makes both names be the same object. When names are unbound (either they go out of scope or you manually unbind them), the objects they are bound to are garbage collected. "Object" here being the memory location, right? When we say a = 5 a = an easy way for calling that "fixed memory location" that holds our value, instead of calling it in binary format or in hex format. This is the direct object a is pointing too. Correct? 5 = *this* is the indirect object that a outputs when we print a. Are the above statements correct Michael? a = 5 b = a a <---> memory address b <---> memory address I like to think a and b as references to the same memory address -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 17/6/2013 5:22 μμ, Terry Reedy wrote: On 6/17/2013 7:34 AM, Simpleton wrote: On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: Now, in languages like Python, Ruby, Java, and many others, there is no table of memory addresses. Instead, there is a namespace, which is an association between some name and some value: global namespace: x --> 23 y --> "hello world" First of all thanks for the excellent and detailed explanation Steven. As for namespace: a = 5 1. a is associated to some memory location 2. the latter holds value 5 This is backwards. If the interpreter puts 5 in a *permanent* 'memory location' (which is not required by the language!), then it can associate 'a' with 5 by associating it with the memory location. CPython does this, but some other computer implementations do not. Please tell me how do i need to understand the sentence 'a' is being associated with number 5 in detail. Why don't we access the desired value we want to, by referencing to that value's memory location directly instead of using namespaces wich is an indirect call? i feel we have 3 things here a , memory address of a stored value, actual stored value So is it safe to say that in Python a == &a ? (& stands for memory address) is the above correct? When you interpret Python code, do you put data in locations with integer addresses? I lost you here. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On 16/6/2013 9:39 μμ, Antoon Pardon wrote: If nikos's project was a college project we would have told him he has to make his homework himself. This is where you all mistaken. You see, my website could be done ina CMS like (Joomla or Drupal) or even in DreamWeaver. I choosed Python because i like Python. Mny of my friends and clients told me hey man your website is very simple, how not Joomla-lize it with cool animation effects and stuff? Well, i could, but i dont want to because: 1. i want to learn Python 2. i want to have full control of my webisite, knowing each and every lien does, since i'm writing it. > But now he is earning > money with it, you seem to find it acceptable his job is done > for him. No. I first try and inevitably i fail. Than i ask, and ask not only to be shown to the correct way of handling the code, but i want to be informed of how you thought of implementing the situation at hand. This way i learn from your experience and iam getting better and better every day as we speak, which in turn make me fond of Python increasingly. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On 17/6/2013 7:14 μμ, Grant Edwards wrote: But failing _isn't_ inevitible. If you take the time to actually learn Python by reading the references people provide, by studying small examples, and by experimenting with Python code, there's no reason why you should fail. I'am and i feel better expressing my questions to a live human being that read help file after help file to find some answer to a problem i have to deal with. Of course i spent you guys reply-time but many others(even experts) benefit from all this experience, not only me. Also what i have learned here the last month would have taken me way longer if i was researching for my self from doc=>doc reference until i was able to understand something. I like things to be put up simple and i'am not trolling this group. I respect this group. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Updating a filename's counter value failed each time
Hello again, something simple this time: After a user selects a file from the form, that sleection of his can be found form reading the variable 'filename' If the filename already exists in to the database i want to update its counter and that is what i'm trying to accomplish by: --- if form.getvalue('filename'): cur.execute('''UPDATE files SET hits = hits + 1, host = %s, lastvisit = %s WHERE url = %s''', (host, lastvisit, filename) ) --- For some reason this never return any data, because for troubleshooting i have tried: - data = cur.fetchone() if data: print("something been returned out of this"_ Since for sure the filename the user selected is represented by a record inside 'files' table why its corresponding counter never seems to get updated? Thank you. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list