Generating Filenames from Feeds

MRAB python at mrabarnett.plus.com
Thu Mar 14 17:07:43 CET 2013


On 14/03/2013 15:38, Chuck wrote:
> HI all,
>
> I am trying to write a podcast catcher for fun, and I am trying to
> come up with a way to generate a destination filename to use in the
> function urlretrieve(url, destination).  I  would like the
> destination filename to end in a .mp3 extension.
>
> My first attempts were parsing out the <pubdate> and stripping the
> whitespace characters, and joining with os.path.join.  I haven't been
> able to make that work for some reason.  Whenever I put the .mp3 in
> the os.path.join I get syntax errors.  I am wondering if there is a
> better way?
>
> I was doing something like
> os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate.mp3), where
> pubdate has been parsed and stripped of whitespace.  I keep getting
> an error around the .mp3.
>
> Any ideas?
>
The filename referred to by pubdate is a string, and you want to append
an extension, also a string, to it. Therefore:

os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate + '.mp3')



More information about the Python-list mailing list