Variablen Problem im Suchmuster

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Benutzeravatar
cofi
Python-Forum Veteran
Beiträge: 4432
Registriert: Sonntag 30. März 2008, 04:16
Wohnort: RGFybXN0YWR0

Masaru hat geschrieben:... wenn Du nochmal sagen kannst "wo" das steht, klar gerne warum nicht.
Da %-Formatting in Python 3 deprecated wird, bleibt das nur als logischer schluss uebrig ;)
Whats new in Python 3.0 hat geschrieben:PEP 3101: Advanced String Formatting. Note: the 2.6 description mentions the format() method for both 8-bit and Unicode strings. In 3.0, only the str type (text strings with Unicode support) supports this method; the bytes type does not. The plan is to eventually make this the only API for string formatting, and to start deprecating the % operator in Python 3.1
Benutzeravatar
Masaru
User
Beiträge: 425
Registriert: Mittwoch 4. August 2004, 22:17

cofi hat geschrieben:Da %-Formatting in Python 3 deprecated wird, bleibt das nur als logischer schluss uebrig ;)
Ah, wusste ich noch gar nicht, danke :).

So ganz steht es Deinem Zitat nach ja aber momentan noch nicht fest cofi:
"...The plan is to eventually make this the only API for string formatting, and to start deprecating the % operator in Python 3.1 ..."

Ich plane auch meinen Keller bis Januar aufzuräumen ... das leider schon seit so an die 3 Jahren :roll: *pfeif*.

>>Masaru<<
orangenbaum
User
Beiträge: 6
Registriert: Montag 14. Dezember 2009, 13:11

hallo, ich bins nochmal^^
ich komm immernoch nicht mit dem suchmuster klar, ich hab es jetzt so:
ersetzwort= re.compile("((@.*){(%s),)" % kennwort)

(bei der Variante von Zap kommt bei mir einer Fehler)

Jedoch bindet er aber trotzdem nicht die Variable "Kennwort" in das Muster ein, die Suche ergibt None...
hat jemand eine Idee woran das liegen kann?

lg
Zap
User
Beiträge: 533
Registriert: Freitag 13. Oktober 2006, 10:56

Also wenn du alles (bis auf format()) befolgst was gesagt wurde geht's doch...

Code: Alles auswählen

In [23]: kennwort = "hallo"

In [24]: c = re.compile("((@.*){(%s),)" % re.escape(kennwort))

In [25]: c.match("@lalala{hallo,").groups()
Out[25]: ('@lalala{hallo,', '@lalala', 'hallo')
Edit: mit format geht's natürlich auch ;) Ich habe aber gerade nur Python25 im Angebot
Benutzeravatar
Hyperion
Moderator
Beiträge: 7478
Registriert: Freitag 4. August 2006, 14:56
Wohnort: Hamburg
Kontaktdaten:

Ach ich sehe grad, dass die geschweifte Klammer wohl kein Tippfehler war. Dann musst Du das bei .format() entsprechend escapen:

Code: Alles auswählen

In [2]: "((@.*){{({0}),)".format("welt")
Out[2]: '((@.*){(welt),)'
Antworten