Aide script python

Aide script python - Python - Programmation

Marsh Posté le 03-11-2004 à 13:00:11    

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:  
 

Reply

Marsh Posté le 03-11-2004 à 13:00:11   

Reply

Marsh Posté le 03-11-2004 à 13:46:04    

à 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
Reply

Marsh Posté le 03-11-2004 à 14:21:59    

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?

Reply

Marsh Posté le 03-11-2004 à 14:43:52    

...
 
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
Reply

Marsh Posté le 03-11-2004 à 15:34:09    

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.  
 

Reply

Marsh Posté le 03-11-2004 à 15:39:22    

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
Reply

Marsh Posté le 03-11-2004 à 15:52:12    

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?

Reply

Marsh Posté le 03-11-2004 à 16:01:32    

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
Reply

Marsh Posté le 03-11-2004 à 16:07:57    

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

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed