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
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
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
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(
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
&
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:
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.
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
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
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
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:
>
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
---
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
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',
;']
['"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
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
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",
17 matches
Mail list logo