I'm stuck on a problem with encoding (or possibly decoding).

I'm extracting dates from web pages with regular expressions.  Now I want to
parse those dates into Python date objects.  Generally speaking, this is no
big deal.  It takes some effort because I'm dealing with a number of
different date formats, but I expected that.

I'm using mx.DateTime.strptime to parse the datetimes out of the strings
that I've captured with regexes.  That works fine much of the time.  It
fails when the string is utf-8 and there are characters that can't be
converted (a familiar problem).

The weird thing is that when I decode the original date string to latin-1,
Django seems to eat the entire string that I build out of that date.
Perhaps I should clarify.  I have a web page that shows me what text was
captured by the regex (so I can see that it is getting the correct chunk)
and it also shows me the output of strptime (using the pattern string for
the relevant date format).

So... when I display the parsed data via Django, there's nothing there.  But
when I add a character count for what my views.py script is sending to the
template, it shows that there is plenty of text there.  Somewhere in the
templating, that text is getting lost - it doesn't show up at all in on the
resulting page.  I know that my code is producing text because I can run it
stand-alone and see the generated text.

I don't quite even know how to figure out where it is disappearing... but
I'm hoping somebody here has seen something similar - vanishing string after
encoding...?

Thanks in advance for any insights.

Nick

P.S. As often happens, describing the problem helped a bit... it seems to be
related to mixing unicode and non-unicode strings.  When I decode the
results to utf-8, my text is back.... but I still can't get strptime to work
on these strings, even after decoding to latin-1, which I thought might do
it.  So frustrating that it looks like plain ascii on the page, but I can't
get it to behave like plain ascii!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to