Précédent   Forum du club des développeurs et IT Pro > Autres langages > Python & Zope
Python & Zope Forum d'entraide sur la programmation en Python et Zope. Avant de poster -> F.A.Q Python
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 18/01/2013, 17h27   #1
jasonboucher
Invité de passage
 
Inscription : janvier 2009
Messages : 1
Détails du profil
Informations forums :
Inscription : janvier 2009
Messages : 1
Points : 0
Points : 0
Par défaut If imbriqués ==> help

Bonjour à tous,

Mon problème est simple, et je ne doute pas que la solution ne l'est pas moins.
Je crée à partir d'une feuille csv un dictionnaire comme:
DICT1[email] = le_reste_de_l_information_de_la_ligne

A partir d'une autre feuille csv, je crée un 2ieme dictionnaire de la meme facon:
DICT2[info] = le_reste_de_l_information_de_la_ligne

Apres, je cherche à:
Code :
1
2
3
4
5
6
7
8
 
for email in DICT1:
    if DICT2.has_key(email) == True:
        faire_un_traitement
    else:
        test_email = "je construis le mail à partir des standards prenom.nom@masociete.com"
        if DICT1.has_key(test_email) == True:
            faire_un_traitement
La partie qu'il me manque est d'arriver à insérer le bout de code qui fera:
Code :
1
2
3
 
if not in any of other "if":
    faire_autre_traitement
Le vrai code que j'ai:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
    for person in SECURID_HEADER:
        phrase = ""
        if POPS_HEADER.has_key(person) == True:
            info_pops = POPS_HEADER[person].split(";")[:2]
            for i in info_pops:
                phrase = phrase + i.replace("\"","") + ";"
            phrase = phrase + person + ";" + person +";" + SECURID_HEADER[person].split(";")[0] + ";"
            phrase = phrase + SECURID_HEADER[person].split(";")[1] + ";" + POPS_HEADER[person].split(";")[28] + ";"
            for data in SECURID_HEADER[person].split(";")[3:]:
                phrase = phrase + data + ";"
 
        elif POPS_HEADER.has_key(person) == False:
            user = SECURID_HEADER[person].split(";")[:2]
            u = user[1].lower() + "." + user[0].lower()
            for ext in EXT:
                if POPS_HEADER.has_key(u + ext) == True:
                    for i in POPS_HEADER[u + ext].split(";")[:2]:
                        phrase = phrase + i.replace("\"","") + ";"
                    phrase = phrase + person + ";" + u + ext + ";"
                    phrase = phrase + SECURID_HEADER[person].split(";")[0] + ";" + SECURID_HEADER[person].split(";")[1] + ";" + POPS_HEADER[u + ext].split(";")[28] + ";"
                    for i in SECURID_HEADER[person].split(";")[3:]:
                        phrase = phrase + i + ";"
Comment je fais?
Est-ce mon explication est suffisament claire?

Merci de votre aide!!!
jasonboucher est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/01/2013, 18h31   #2
wiztricks
Expert Confirmé Sénior
 
Inscription : juin 2008
Messages : 3 739
Détails du profil
Informations forums :
Inscription : juin 2008
Messages : 3 739
Points : 4 581
Points : 4 581
Salut,
Citation:
Est-ce mon explication est suffisament claire?
Pas vraiment!
Code :
1
2
if not in any of other "if":
    faire_autre_traitement
s'écrirait:
Code :
1
2
3
4
    if condition1:
    elif condition2:
    elif condition3:
    else: # là est "if not in any of other "if"
Le code proposé se réduit à:
Code :
1
2
3
4
5
6
   for person in SECURID_HEADER:
        phrase = ""
        if person in POPS_HEADER:
           ....
        else:
           ...
Car avec:
Code :
1
2
3
4
5
6
    for person in SECURID_HEADER:
        phrase = ""
        if POPS_HEADER.has_key(person) == True:
            ...
        elif POPS_HEADER.has_key(person) == False:
            ...
on a condition1 = not condition2 et pas de "if not in any of other "if"
- W
__________________
Architectures Post-Modernes
wiztricks est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 09h23.


 
 
 
 
Partenaires

Hébergement Web