[Tutor] Get variable values

Kent Johnson kent37 at tds.net
Thu Feb 1 20:36:53 CET 2007


Mário Gamito wrote:
> 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 ?

I keep looking at this and your other posts and I just don't understand 
what you are trying to do. What do you mean by "content"? Is this code 
part of some class? It looks like it is from a class that subclasses 
dict. Anyway more context both of code and of what you are trying to do 
might be helpful.

Kent

> 
> 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 ""
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 




More information about the Tutor mailing list