Re: [Tutor] renaming files within a directory

2009-07-27 Thread Alan Gauld
wrote files = set([file for file in glob.glob('Flag_of_*.svg')]) for file in files: file = file[8:-4] Yu probably want to keep the filename unouched and use a variable like country here. if file.startswith('the_'): file = file[4:] if countries.has_key(file): b = 'flag-'+ cou

Re: [Tutor] renaming files within a directory

2009-07-27 Thread davidwilson
Thank you all for your help. Original Message From: Dave Angel Apparently from: srs0=pajg=du=ieee.org=da...@srs.perfora.net To: davidwil...@safe-mail.net Cc: ken...@tds.net, tutor@python.org Subject: Re: Re: [Tutor] renaming files within a directory Date: Mon, 27 Jul 2009 09:01

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Dave Angel
kent3...@gmail.com To: davidwil...@safe-mail.net Cc: m...@timgolden.me.uk, tutor@python.org Subject: Re: [Tutor] renaming files within a directory Date: Mon, 27 Jul 2009 07:01:32 -0400 On Mon, Jul 27, 2009 at 5:10 AM, wrote: files =et([file for file in os.listdir(os.getcwd()) if fil

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Christian Witts
on Apparently from: kent3...@gmail.com To: davidwil...@safe-mail.net Cc: m...@timgolden.me.uk, tutor@python.org Subject: Re: [Tutor] renaming files within a directory Date: Mon, 27 Jul 2009 07:01:32 -0400 On Mon, Jul 27, 2009 at 5:10 AM, wrote: files = set([file for file in os.listdir(

Re: [Tutor] renaming files within a directory

2009-07-27 Thread davidwilson
l.com To: davidwil...@safe-mail.net Cc: m...@timgolden.me.uk, tutor@python.org Subject: Re: [Tutor] renaming files within a directory Date: Mon, 27 Jul 2009 07:01:32 -0400 > On Mon, Jul 27, 2009 at 5:10 AM, wrote: > > > files = set([file for file in os.listdir(os.getcwd()) if &

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Kent Johnson
On Mon, Jul 27, 2009 at 5:10 AM, wrote: > files = set([file for file in os.listdir(os.getcwd()) if > file.endswith('svg')]) > print len(files) > > for file in files: >    file = file.strip('.svg') >    print file > #    if countries.has_key(file): > #       print file > > When I run this I get:

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Alan Gauld
wrote The problem is that for example the file Flag_of_the_United_States.svg when I use the strip('.svg') it is returned as Flag_of_the_United_State Thats because strip removes all of the characters in the given string. You would probably be better removing the extension using the os.path.

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Tim Golden
davidwil...@safe-mail.net wrote: Here is what I have so far: import os import csv countries = {} reader = csv.reader(open("countries.csv")) for row in reader: code, name = row countries[name] = code files = set([file for file in os.listdir(os.getcwd()) if file.endswith('svg')]) You d

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Christian Witts
al Message From: Tim Golden Apparently from: tutor-bounces+davidwilson=safe-mail....@python.org To: Cc: tutor@python.org Subject: Re: [Tutor] renaming files within a directory Date: Sun, 26 Jul 2009 20:41:10 +0100 davidwil...@safe-mail.net wrote: OK I am lost ;( I changed t

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Christian Witts
al Message From: Tim Golden Apparently from: tutor-bounces+davidwilson=safe-mail....@python.org To: Cc: tutor@python.org Subject: Re: [Tutor] renaming files within a directory Date: Sun, 26 Jul 2009 20:41:10 +0100 davidwil...@safe-mail.net wrote: OK I am lost ;( I changed t

Re: [Tutor] renaming files within a directory

2009-07-27 Thread davidwilson
Golden Apparently from: tutor-bounces+davidwilson=safe-mail....@python.org To: Cc: tutor@python.org Subject: Re: [Tutor] renaming files within a directory Date: Sun, 26 Jul 2009 20:41:10 +0100 > davidwil...@safe-mail.net wrote: > > OK I am lost ;( > > > > I changed the code to: >

Re: [Tutor] renaming files within a directory

2009-07-26 Thread Tim Golden
davidwil...@safe-mail.net wrote: OK I am lost ;( I changed the code to: reader = csv.reader(open("countries.csv"), delimiter=";") for row in reader: ... print row ... ['bi', 'Burundi'] ['km', 'Comoros'] ['dj', 'Djibouti'] ['er', 'Eritrea'] ... Now each row is a list with two items ea

Re: [Tutor] renaming files within a directory

2009-07-26 Thread davidwilson
--- From: Tim Golden Apparently from: tutor-bounces+davidwilson=safe-mail@python.org To: Cc: tutor@python.org Subject: Re: [Tutor] renaming files within a directory Date: Sun, 26 Jul 2009 18:32:43 +0100 > davidwil...@safe-mail.net wrote: > > Here is what I have so far

Re: [Tutor] renaming files within a directory

2009-07-26 Thread Tim Golden
davidwil...@safe-mail.net wrote: Here is what I have so far, but I get stuck on the mapping of the filename with the csv file. import os files = [file for file in os.listdir(os.getcwd()) if file.endswith('svg')] files ['Flag_of_Abkhazia.svg', 'Flag_of_Afghanistan.svg', 'Flag_of_Albania.svg',

Re: [Tutor] renaming files within a directory

2009-07-26 Thread davidwilson
;'] ['"et";"Ethiopia"'] Here is where I am at. Not sure how to map the two. Dave Original Message From: Tim Golden Apparently from: tutor-bounces+davidwilson=safe-mail@python.org To: Cc: tutor@pyth

Re: [Tutor] renaming files within a directory

2009-07-26 Thread Tim Golden
davidwil...@safe-mail.net wrote: Hello, I have a directory containing svg/Flag_of_United_States.svg etc... Flag_of_the_Seychelles.svg Flag_of_the_Solomon_Islands.svg Flag_of_the_United_Arab_Emirates.svg Flag_of_the_United_Kingdom.svg Flag_of_the_United_States.svg Flag_of_the_Vatican_City.svg

[Tutor] renaming files within a directory

2009-07-26 Thread davidwilson
Hello, I have a directory containing svg/Flag_of_United_States.svg etc... Flag_of_the_Seychelles.svg Flag_of_the_Solomon_Islands.svg Flag_of_the_United_Arab_Emirates.svg Flag_of_the_United_Kingdom.svg Flag_of_the_United_States.svg Flag_of_the_Vatican_City.svg Also I have a CSV file like "us",