In <[EMAIL PROTECTED]>, sc_wizard29
wrote:

> Maybe these questions will sound strange to you, but I sometime have a
> hard time switching from Java to Python ;-)
> 
> Let's say I have a function like this :
> 
> def show_lines(file):
>       for next_line in file:
>               ...
> 
> What can I do to be sure that the input argument is indeed a 'File'
> object ?

Why do you want to be sure?  I would even rename the argument:

def show_lines(lines):
    for line in lines:
        ...

This works with *every* iterable that contains "lines".  No need to
"cripple" it with a type checking.

> #2 : should I do nothing ? (but I don't like the idea of risking to
> have a runtime exception raised somewhere)

Then don't use Python.  Except `SyntaxError` almost every
exception is a runtime one.

And what do you do if you check for `file` and it isn't such an instance? 
Raise an exception?  A no, that's something you don't like.  So what else?  ;-)

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to