Exceptions: Logging TB and local variables?

2007-10-09 Thread allen.fowler
Hi,

My code looks like this:

for item in bigset:
  self.__sub1(item)
  self.__sub2(item)
  self.__sub3(item)

# the subX functions, in turn, use various 3rd party modules.


Now, I would like to do this:

for item in bigset:
  try:
self.__sub1(item)
self.__sub2(item)
self.__sub3(item)
  except StandardError:
# Log error and continue to next item in set.
log_error_to_file()


In the error log, I would like to record various local variables that
existed in subX at the time the Exception was thrown... (even though
the actuall exception may have been thrown from deep inside some 3rd
party module that subX called)

How can I do this?

Thank you,
Allen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exceptions: Logging TB and local variables?

2007-10-10 Thread allen.fowler
> Two possibilieies:
>
> You will need to determine ALL the exceptions that the 3rd party party modules
> can raise.  If they are custom exceptions you will need to import them into 
> your
> application from their modules.
>
> example:
>
> say that 3rd party modules raise TransientError, IOError, and ValueError
> exceptions.  TransientError is a custom exception from module foo
>
> from foo import TransientError
>
> for item in bigset:
>try:
>  self.__sub1(item)
>  self.__sub2(item)
>  self.__sub3(item)
>except (TransientError, IOError, ValueError):
>  # Log error and continue to next item in set.
>  log_error_to_file()
>
> 2) Hook exception traceback handler
>
> def myTraceBackHandler(type, value,tb):
>  global 
>  #
>  # This function allows the user to redefine what happens if the program
>  # aborts due to an uncaught exception.
>  # This provides a way to get a "partial" session log if the program
>  # aborts"as well as some information about what caused the program to
>  # abort.
>  #
>  import traceback
>  #
>  # Get traceback lines
>  #
>  tblines=traceback.format_exception(type, value,tb)
>  #
>  # Write some lines to log
>  #
>  log_error_to_file()
>  #
>  # Always write the exceptions to screen
>  #
>  sys.exit('\n'.join(tblines))
>
> Hope this helps.
>
> -Larry

This looks interesting...

What is myTraceBackHandler?  Is it some sort of event handler? Can you
clarify?

Thanks,
Allen





-- 
http://mail.python.org/mailman/listinfo/python-list


Simple HTML template engine?

2007-10-14 Thread allen.fowler
Hello,

Can anyone recommend a simple python template engine for generating
HTML that relies only on the Pyhon Core modules?

No need for caching, template compilation, etc.

Speed is not a major issue.

I just need looping and conditionals. Template inheritance would be a
bonus.

I've seen Genshi and Cheetah, but they seem way too complex.

Any ideas?

I'm sure I could build something myself, but I'm sure this has already
been done quite a few times.  Why re-invent the wheel, right?


Thank you,
Allen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple HTML template engine?

2007-10-15 Thread allen.fowler
CherryPy looks nice... though I am just looking to generate static
reports.

Thanks anyway... I'll keep it in mind for the future.

On Oct 15, 4:38 am, "Ciprian Dorin Craciun"
<[EMAIL PROTECTED]> wrote:
> Have you tried CherryPy?http://www.cherrypy.org/
>
> It's not a template engine, but a simple web server engine, and
> you could code your conditionals and loops directly in Python... When
> I have tried it, it looked very nice and easy.
>
> Ciprian.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple HTML template engine?

2007-10-15 Thread allen.fowler
On Oct 15, 1:26 am, John Nagle <[EMAIL PROTECTED]> wrote:
> allen.fowler wrote:
> > Hello,
>
> > Can anyone recommend a simple python template engine for generating
> > HTML that relies only on the Pyhon Core modules?
>
> > No need for caching, template compilation, etc.
>
> > Speed is not a major issue.
>
> > I just need looping and conditionals. Template inheritance would be a
> > bonus.
>
>  HTMLTemplate is a minimal system for that sort of thing.
> It doesn't drag in some big "framework".
>
> John Nagle


This look exactly like what I need.

Google first led me to the "HTML::Template" perl library.

But now i've got the right one at: 
http://freespace.virgin.net/hamish.sanderson/htmltemplate.html

Thank you.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple HTML template engine?

2007-10-15 Thread allen.fowler
On Oct 15, 1:26 am, John Nagle <[EMAIL PROTECTED]> wrote:
> allen.fowler wrote:
> > Hello,
>
> > Can anyone recommend a simple python template engine for generating
> > HTML that relies only on the Pyhon Core modules?
>
> > No need for caching, template compilation, etc.
>
> > Speed is not a major issue.
>
> > I just need looping and conditionals. Template inheritance would be a
> > bonus.
>
>  HTMLTemplate is a minimal system for that sort of thing.
> It doesn't drag in some big "framework".
>
> John Nagle

Thanks...
Wait a sec... this is a Perl module...

Am I missing something?  :)


Allen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple HTML template engine?

2007-10-15 Thread allen.fowler
CherryPy looks nice... though I am just looking to generate static
reports.

Thanks anyway... I'll keep it in mind for the future.

On Oct 15, 4:38 am, "Ciprian Dorin Craciun"
<[EMAIL PROTECTED]> wrote:
> Have you tried CherryPy?http://www.cherrypy.org/
>
> It's not a template engine, but a simple web server engine, and
> you could code your conditionals and loops directly in Python... When
> I have tried it, it looked very nice and easy.
>
> Ciprian.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI and external JavaScript nightmare

2007-10-17 Thread allen.fowler

>
> One CGI question - since all of my CGIs are spitting out HTML is their
> source code safe? wget and linking to the source deliver the output
> HTML. Are there any other methods of trying to steal the source CGI I
> need to protect against?
>
> Thank you.

Not sure I fully understand the question.

Can you post the CGI code here?

-- 
http://mail.python.org/mailman/listinfo/python-list


Edit MP4 and/or WMV file metadata?

2008-03-04 Thread allen.fowler
Hello,

I have many WMV files with bad embedded author/title/date information.

However, the correct information is correctly encoded in the file
name.. i.e. "title-author-date.wmv"

I am about to conver these fiiles to MP$ for use on an iPod. The video
software I am using will, I think, transfer the metadata from the WMV
to MP4 files.

So, two questions:

1) Is there a python module I can use to edit the metadata in MP4
files?

2) Failing that, is there a python module I can use to edit the
metadata in the WMV files, and hope the data makes it through the
conversion?

-- Thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


How to set object parameters nicely?

2009-12-01 Thread allen.fowler
Hello,

I've got a bunch of code that looks something like:

class MyOb(object):
  def __init__(self, p1=None, p2=None, p3=None, ...):
self.p1 = p1
self.p2 = p2
self.p3 = p3
self.pN = ...


ob1 = MyOb(p1="Tom", p3="New York")
ob2 = MyOb(p1="Joe", p2="j...@host", p3="New Jersey")

... and so on.

This is fine for only a few parameters, but it's very ugly and a lot
of duplicate typing once I've got 10+ parameters and 5 kinds of
objects.

Is there a better way to do this?

Thanks,
:)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set object parameters nicely?

2009-12-01 Thread allen.fowler

> > Is there a better way to do this?
>
> class MyOb(object):
>      def __init__(self, **kwargs):
>          self.__dict__.update(kwargs)
>
> ob1 = MyOb(p1="Tom", p3="New York")
> ob2 = MyOb(p1="Joe", p2="j...@host", p3="New Jersey")

I've tried this, but have found two issues:

1) I can't set default values.
2) I can't set required values.

In both of the above cases, if the object is created without the
"exact" dict() I expect, all the assumption my methods make about what
is available in "self" fall apart.

Perhaps, as Diez mentioned, my approach is wrong.   What would be the
right thing to do in this situation?

-- AF
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set object parameters nicely?

2009-12-02 Thread allen.fowler
> >>> Is there a better way to do this?
> >> class MyOb(object):
> >>      def __init__(self, **kwargs):
> >>          self.__dict__.update(kwargs)
>
> >> ob1 = MyOb(p1="Tom", p3="New York")
> >> ob2 = MyOb(p1="Joe", p2="j...@host", p3="New Jersey")
>
> > I've tried this, but have found two issues:
>
> > 1) I can't set default values.
> > 2) I can't set required values.
>
> > In both of the above cases, if theobjectis created without the
> > "exact" dict() I expect, all the assumption my methods make about what
> > is available in "self" fall apart.
>
> > Perhaps, as Diez mentioned, my approach is wrong.   What would be the
> > right thing to do in this situation?
>
> There is no general answer to this. It depends on your actual problem.
>
> Diez

What are some of the patterns that tend to be used?

-- AF
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set object parameters nicely?

2009-12-02 Thread allen.fowler
On Dec 2, 6:36 pm, Carl Banks  wrote:

> For the record, I don't really agree that a lot of parameters is code
> smell.  It's maybe a red flag that you are doing too much in one
> function and/or class, but nothing inherently shady.
>
> One thing to ask yourself: are there a lot of combinations of
> parameters that don't make sense?  For example, do you have a lot of
> cases where, say, if one parameter is set to x, then parameters a, b,
> c, and d do nothing?  That would indicate that you should break your
> function/class up into smaller, more targeted parts.
>
> However, if all your parameters are orthogonal, that is, if all or
> most combinations make sense, then there's no reason ten or twenty
> parameters isn't perfectly reasonable.
>
> Whenever I have ten parameters in an __init__, I ususally just write
> out the assignments, although more often than not the object's
> attributes don't correspond to the parameters one-to-one, so I'd have
> to write them out anyway.
>

Thank you for the thoughtful insight.

In this case, and I am trying to create a number of ORM-like objects.
(Though, there is no database involved.)

So, instances of these classes are acting as records that are shuttled
around in the system, and the object's properties are acting as
values.  The parameters are (mostly) orthogonal, but do need defaults,
and some must be required.


-- 
http://mail.python.org/mailman/listinfo/python-list