[Tutor] Get variable values
Mário Gamito
gamito at gmail.com
Thu Feb 1 16:03:56 CET 2007
Hi,
I'm new to Python, so forgive me the lame question.
I have this code (following my signature) and i'm trying to get the
value of "content" and insert it into a MySQL database.
I've been reading the docs in www.python.org, but i can't find a solution.
Can someone help me, please ?
Warm Regards,
Mário Gamito
--
def get_date(self, key):
"""Get (or update) the date key.
We check whether the date the entry claims to have been changed is
since we last updated this feed and when we pulled the feed off the
site.
If it is then it's probably not bogus, and we'll sort accordingly.
If it isn't then we bound it appropriately, this ensures that
entries appear in posting sequence but don't overlap entries
added in previous updates and don't creep into the next one.
"""
for other_key in ("updated", "modified", "published", "issued",
"created"):
if self.has_key(other_key):
date = self.get_as_date(other_key)
break
else:
date = None
if date is not None:
if date > self._channel.updated:
date = self._channel.updated
# elif date < self._channel.last_updated:
# date = self._channel.updated
elif self.has_key(key) and self.key_type(key) != self.NULL:
return self.get_as_date(key)
else:
date = self._channel.updated
self.set_as_date(key, date)
return date
def get_content(self, key):
"""Return the key containing the content."""
for key in ("content", "tagline", "summary"):
if self.has_key(key) and self.key_type(key) != self.NULL:
return self.get_as_string(key)
db = MySQLdb.connect(host="localhost", user="planet",
passwd="secret", db="planet_geek")
cursor = db.cursor()
cursor.execute("INSERT INTO blog_posts (title) VALUES (key)")
return ""
More information about the Tutor
mailing list