Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 7th, 2004, 10:48 PM
ryankask ryankask is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 52 ryankask User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 44 sec
Reputation Power: 7
PHP and Python DB

I am designing a website for a hobby of mine and part of it is in XML dynamically generated by using PHP to extract the element's appropriate data from a database and then parsing it with an XSLT stylesheet (again w/ PHP). This can be done fairly easily but part of the purpose of the site is to practice web programming. I wanted to learn Python so I am using that to develop a communications script for a different section. While studying the language, I had an idea and wanted to know how viable it is. What if instead of using MySQL for the database, I used a Python dictionary? It may sound silly, but would it be slow, perhaps just plain stupid? I really don't need any of the special functions of a relational database...but should I just stick to MySQL? Thanks.

Ryan Kaskel - MIA

Last edited by ryankask : June 7th, 2004 at 10:50 PM. Reason: grammar

Reply With Quote
  #2  
Old June 7th, 2004, 11:54 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
It would work, all you'd have to do is show PHP how to parse the dictionary from a file and insert it into a hash. Though I dont see the need for it if your just learning it should be fun . Yes, it might be slower than MySQL; especially with large data sets. Give it a go .

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old June 8th, 2004, 02:41 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
If you can hold all the data in memory all the time, then using a dictionary will be orders of magnitude faster than using a DB. If you have to save and load it from disk each time then I think it will be faster for small data sets, but the DB will overtake it at some point. You may also have the issue of multiple users trying to access the file at the same time, with the potential for data loss.

There is an alternative. Look at the dbm family of modules in the standard library. These look like dictionaries but are simple databases (not relational, so do not have all the overheads associated with that). I recommend bsddb if your OS supports it, since it can support transactions and multiple simultaneous users.

Dave - The Developer's Coach

Reply With Quote
  #4  
Old June 8th, 2004, 12:28 PM
ryankask ryankask is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 52 ryankask User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 44 sec
Reputation Power: 7
So the dbm module with a standard Python distribution? I assume my web host (which supports Python) will have this module preinstalled? Thank you, I will look into it.

Reply With Quote
  #5  
Old June 8th, 2004, 12:38 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
There are actually a number of dbm modules included with Python. Which ones you have will depend on your playform etc. But there is always at least one available. And you can also use the Pickle module for this kind of thing . Check out the Python docs for more info...

Have fun,

Mark.

Reply With Quote
  #6  
Old June 8th, 2004, 12:39 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
Quote:
Originally Posted by ryankask
So the dbm module with a standard Python distribution? I assume my web host (which supports Python) will have this module preinstalled? Thank you, I will look into it.


It is standard but optional, depending on the OS. Most UNIX systems have dbm and/or gdbm. Windows and some UNIX installations have bsddb.

All installations have dumbdbm available, which is a simple implementation in Python, and is meant as a last resort.

If you use anydbm then it will transparently use the best implementation available on that system.

I think only bsddb supports multiple users, so if you are using it in a web app then check with your host to see if it is available (or write a short CGI test script).

Dave - The Developers' Coach

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > PHP and Python DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT