Bonjour à tous !

Je viens de commencer à programmer en Python et j'aimerais pouvoir lier deux paramètres de fichiers différents.

Voici mon code :

fich1.py

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import optparse
import sys
 
try:
    # xml.etree.ElementTree is new in Python 2.5
    from xml.etree.ElementTree import ElementTree
except ImportError:
    sys.exit("This script needs the Python ElementTree module. Please install it")
 
 
parser = optparse.OptionParser(
        "%prog [options] -H HOSTADDRESS")
 
parser.add_option('-H', dest="hostname", help="Hostname to scan")
 
 
opts, args = parser.parse_args()
 
if not opts.hostname:
        parse.error("Requires one host to scan (option -H)")
 
hostname = opts.hostname
 
# TODO : launch from fich2.py with parameter -t = parameter -H
...
fich2.py

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import optparse
import sys
import os
import tempfile
import subprocess
from fich1 import *
 
try:
    # xml.etree.ElementTree is new in Python 2.5
    from xml.etree.ElementTree import ElementTree
except ImportError:
    sys.exit("This script needs the Python ElementTree module. Please install it")
 
VERSION = '0.1'
 
parser = optparse.OptionParser(
    "%prog [options] -t targets",
    version="%prog " + VERSION)
 
parser.add_option('-t', '--targets', dest="targets",
                  help="Scanning targets.")
...
J'aimerais lancer mon fichier fich2.py dans mon fichier fich1.py et faire en sorte que les paramètres -t et -H aient la même valeur.

Des idées ?

Merci d'avance pour vos réponses