Path: ...!weretis.net!feeder6.news.weretis.net!i2pn.org!dodin.fr.nf!.POSTED.233.117.226.89.rev.sfr.net!not-for-mail From: yves Newsgroups: fr.comp.lang.python Subject: Re: Projet Python : importation d'un dossier csv sous forme de matrice Date: Fri, 04 Feb 2022 19:11:04 +0100 Organization: Le serveur de jdd pour fr* Message-ID: <87ee4imrif.fsf@l2> References: <61f3037b$0$8902$426a34cc@news.free.fr> <87wniamtpp.fsf@l2> NNTP-Posting-Host: c3066ed76bae8bcc0e476efb157ff758 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ns507557.dodin.fr.nf; posting-host="233.117.226.89.rev.sfr.net:89.226.117.233"; logging-data="10058"; mail-complaints-to="abuse" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:Jc11ykyRpEsxy1oGqvXGEtHWmnY= Bytes: 2027 Lines: 39 yves writes: > Effectivement, c'est inhabituel pour un format csv. Sinon, Alain Ketterlin a donn=C3=A9 une solution compl=C3=A8te. La base du traitement de ton fichier, c'est la m=C3=A9thode split() (googler python split) Un =C3=A9chantillon avec une cha=C3=AEne de caract=C3=A8re s repr=C3=A9sent= ant ton fichier simplifi=C3=A9: s =3D "0.00055 0.00008 0 ; 0.00085 0.00004 0.00007 ; 0.00010 0.00004 0.00= 006" s1 =3D s.split(";") print(s1) >>> ['0.00055 0.00008 0 ', ' 0.00085 0.00004 0.00007 ', ' 0.00010 0.00004= 0.00006'] for elt in s1: print(elt.split()) ['0.00055', '0.00008', '0'] ['0.00085', '0.00004', '0.00007'] ['0.00010', '0.00004', '0.00006'] Il a aussi utilis=C3=A9 une autre pythonnerie qui s'appelle la "list compre= hension" Exemple: l1 =3D ['0.00010', '0.00004', '0.00006'] l2 =3D [ float(elt) for elt in l1] print(l2) >>> [0.0001, 4e-05, 6e-05] --=20 Yves