Bonjour
J'ai un string
monstring = "C:/toto/tata/tonton.hex"
comment faire pour que le plus simplement
monstring = "tonton.exe"
Merci
Version imprimable
Bonjour
J'ai un string
monstring = "C:/toto/tata/tonton.hex"
comment faire pour que le plus simplement
monstring = "tonton.exe"
Merci
bonjour,
voici une proposition:
Code:
1
2 import os monstring = os.path.basename("C:/toto/tata/tonton.hex").replace('.hex','.exe')
il y a une erreur de faute
monstring = "C:/toto/tata/tonton.hex"
comment faire pour que le plus simplement
monstring = "tonton.hex"
en faite il faut enlever C:/toto/tata/
merci
Code:
1
2
3 >>> monstring = "C:/toto/tata/tonton.hex" >>> print monstring.split('/')[-1] tonton.hex
Salut,
Un chouille plus élégant (et portable !), puisqu'on parle de chemins de fichiers, utilisons le module os.path !
edit : cette réponse se trouvait déjà dans le post de kango plus haut.Code:
1
2
3
4
5 >>> import os >>> monstring = "C:/toto/tata/tonton.hex" >>> print os.path.basename(monstring) tonton.hex >>>
:ange: