newb question: file searching

Gabriel Genellina gagsl-py at yahoo.com.ar
Tue Aug 8 18:11:42 EDT 2006


At Tuesday 8/8/2006 17:55, jaysherby at gmail.com wrote:

>I must ask, in the interest of learning, what is
>
>[file for file in files if file.endswith(extension)]
>
>actually doing?  I know that 'file' is a type, but what's with the set
>up and the brackets and all?  Can someone run down the syntax for me on
>that?

Note: "file" is really a bad name here; rebinding builtins is never a 
good idea. But unfortunately names like "file", "dir", "dict" are 
very handy when you need a dummy variable like this, so people tend 
to use them.
This has exactly the same meaning:

[x for x in files if x.endswith(extension)]


>I still need to know how I can dynamically get the name of the
>directory that my script is in.

os.path.dirname(os.path.abspath(sys.modules[__name__].__file__))

>Also, how can I get it to add the full
>path of the file to "images" instead of just the file name.  See, when
>I go to use a particular image name later on, it won't do me much good
>if I don't have the path to it.

Look at os.path.join()



Gabriel Genellina
Softlab SRL 


	
	
		
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas




More information about the Python-list mailing list