getting the variable type
Mark Lawrence
breamoreboy at yahoo.co.uk
Sun Jul 11 09:46:51 EDT 2010
On 11-7-2010 14:23, Rene Veerman wrote:
> hi.
>
> i need to know the type of variable i'm dealing with.
>
> take this list:
>
> files = [
> "lib/jquery/jquery-1.4.2.source.js",
> "lib/jquery-ui-1.8.1/development-bundle/ui/jquery-ui-1.8.1.custom.js",
> "lib/jquery-ui-1.8.1/development-bundle/ui/jquery.ui.tabs.js",
> "lib/jquery/jquery.scrollTo-min.js",
> "lib/jquery/jquery.corner.js",
> "lib/jquery/jquery.mousewheel.js",
> "lib/jquery/jquery.em.js",
> "lib/jquery/jScrollPane.js",
> "lib_rv/logAndHandler-1.1.0/lah.source.js",
> "lib_rv/visCanvasLoaderIcon-1.1.0/visCanvasLoaderIcon.source.js",
> self.getJavascript_getbootJSPHP,
> "js/mbCore_boot.js",
> "content/mediaBeez_custom.js"
> ]
> # output a list of the files.
> html = '';
> for i in range(len(files)):
> file = files[i]
You could write for file in files:
*BUT* using file will override the builtin name, better (say)
for fn in files:
>
> f = open (file, 'r')
hence:- f = open (fn, 'r')
> html += f.read()
>
> page = {
> 'html' : html
> }
> the third-last item in the list is not a string, it's a function.
> how do i test for that?
>
Check out the isinstance function here.
http://docs.python.org/library/functions.html
HTH.
Mark Lawrence
More information about the Python-list
mailing list