BASE_URL = 'http://foobar.com?foo=%s'
variable = 'bar'
final_url = BASE_URL % (variable)
J'obtiens ceci 'http://foobar.com?foo=bar'
# Elle ne tient pas compte de la chaîne intérieure.Chaîne à l'intérieur d'une chaîne
Mais je voulais quelque chose comme ça 'http://foobar.com?foo='bar''
Merci pour la réponse.
Pouvez-vous me aider avec presque le même problème:
lst = ['foo', 'bar', 'foo bar']
[str(l) for l in lst if ' ' in l]
-je obtenir ['foo bar']
mais je voulais comme [''foo bar'']
Merci à l'avance.
Pourquoi voulez-vous absolument les citations là-bas en premier lieu? –
En fait, j'essaie d'utiliser l'API de recherche de twitter pour obtenir les résultats de recherche liés à mes mots-clés. Mais quand il ya un espace à l'intérieur d'une chaîne de recherche, il demande comme http://foobar.com?q=foo+OR+bar+OR+'foo bar ' – aatifh
Ahh OK :-) S'il vous plaît toujours aussi écrire pourquoi vous voulez obtenir un certain comportement de votre code.Cela rend plus facile à saisir votre problème entier :-) –