Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1699 connectés 

  FORUM HardWare.fr
  Programmation
  Python

  Aide script python

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Aide script python

n°889400
suomi
Posté le 03-11-2004 à 13:00:11  profilanswer
 

Bonjour à tous.
Je débute en python, et j'ai besoin d'un peu d'aide.
Je voudrais créer un script me permettant à partir d'un fichier.txt où il y a une chaine de caractère sur plusieurs lignes créer un autre fichier ou chaque ligne de cette chaine ne fait que 50 charactères.
 
voila mon oeuvre qui ne marche pas  :??: :
 

Code :
  1. #! /usr/bin/env python2
  2. import string,re,sys
  3. fasta=open("fichier.txt" ).readlines()
  4. def write_fasta(seq, width=50):
  5.                 """write a sequence in fasta format.
  6.                 The following parameters can be specified
  7.                 seq     - sequence as string
  8.                 width   - number of characters per sequence line (default 50)"""
  9.                 for i in xrange(0, len(seq), width):
  10.                     print seq[i:i+width]
  11. write_fasta(fasta)


 
Le script m'affiche le fichier.txt mais pas avec 50 caractères par ligne.
Merci pour votre aide  :hello:  
 

mood
Publicité
Posté le 03-11-2004 à 13:00:11  profilanswer
 

n°889447
masklinn
í dag viðrar vel til loftárása
Posté le 03-11-2004 à 13:46:04  profilanswer
 

à ton avis, readlines() ca fait quoi? [:itm]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
n°889477
suomi
Posté le 03-11-2004 à 14:21:59  profilanswer
 

readline lit toutes les lignes de mon fichier....
 
Mais pourquoi ma fonction ne marche pas.
Mon width=50 n'est pas pris en compte...
 
Sinon, peut etre devrais-je me tourner sur la création d'un tableau de largeur 50 que je remplit par ma chaine de caractère?

n°889494
masklinn
í dag viðrar vel til loftárása
Posté le 03-11-2004 à 14:43:52  profilanswer
 

...
 
a ton avis, readlines ca rend quoi en sortie?


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
n°889542
suomi
Posté le 03-11-2004 à 15:34:09  profilanswer
 

Ben en gros, f.readlines() utilise f.readline() de façon répétitive, et retourne une liste contenant toutes les lignes de données du fichier.  
 

n°889546
masklinn
í dag viðrar vel til loftárása
Posté le 03-11-2004 à 15:39:22  profilanswer
 

bien, donc dans ton exemple, SEQ c'est quoi?


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
n°889563
suomi
Posté le 03-11-2004 à 15:52:12  profilanswer
 

J'ai apprit que les variables de fonction ne doivent pas avoir les mêmes noms que les variables du programme général.
Pour moi, seq dans la fonction corresponf a Fasta dans le programme.
Le programme met donc en mémoire, Fasta qui correspond à la liste de toutes les lignes de mon fichier et cette variable est assimilée à Seq dans la fonction.
Non?

n°889573
masklinn
í dag viðrar vel til loftárása
Posté le 03-11-2004 à 16:01:32  profilanswer
 

je te demande LE TYPE de seq.
 
je sais bien à quoi ca correspond et pourquoi tu l'utilises, mais je veux que tu me donnes son type et que tu te poses des questions à ce propos


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
n°889577
Valeriand
Posté le 03-11-2004 à 16:07:57  profilanswer
 

Petite aide supplémentaire:
regarder dans la doc les différences entre les fonctions readline() et read()


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Python

  Aide script python

 

Sujets relatifs
Petite aide pour debutant :)script
appel script a un endroit specialmodif script menu deroulant
aide sur programmation pascalFormulaire de l'aide SVP merci
Juste une petite aide svp[SHELL] script en shell (clos)
Erreur compilation (besoin d'aide)Si j'ajoute la balise script, IE rend une page blanche
Plus de sujets relatifs à : Aide script python


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)