Check if variable is an instance of a File object

sc_wizard29 at hotmail.com sc_wizard29 at hotmail.com
Fri Sep 15 03:18:14 EDT 2006


Hi everyone,

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 ?

#1 : should I start by checking that 'file' is indeed an instance of a
File object ? (and how do I do this ?)
#2 : should I do nothing ? (but I don't like the idea of risking to
have a runtime exception raised somewhere)

Thanks for helping...




More information about the Python-list mailing list