Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: de.alt.folklore.computer Subject: Re: COMAL Date: 22 May 2025 09:10:38 GMT Organization: Stefan Ram Lines: 101 Expires: 1 Jun 2026 11:59:58 GMT Message-ID: References: <1006u01$2vsuo$1@news1.tnib.de> <100en1o$3i1vf$1@news1.tnib.de> <1t682cb016i265761n3e8%sfroehli@Froehlich.Priv.at> <11t682e0e0ai7803en3e8%sfroehli@Froehlich.Priv.at> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de Q7AM7gc0GZimC6GpUa1jBgpslYrBJx61G2jPhWx+bURs5j Cancel-Lock: sha1:9Nq5/Ua2L1GFJPLxiCP2TGSx4Ns= sha256:PcejLBJMfk6MJnIxFkQKT6SxIGF44lZA+k8gb5fjmhc= X-Copyright: (C) Copyright 2025 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: de-DE-1901 Xref: csiph.com de.alt.folklore.computer:50123 "Peter J. Holzer" schrieb oder zitierte: >On 2025-05-21 19:43, Stefan Froehlich wrote: >> #v+ >> if (true): >> print("a"); >> print("b"); >> >> print("c"); >> #v- >> ...so und nur so geschrieben werden kann >Wie würdest Du es denn gern anders schreiben? Mir fällt keine andere >sinnvolle Einrückung ein. Für Leute, die Python nicht kennen, sollte man sagen, daß die Tiefe der Einrückung (zum Beispiel, ob zwei oder vier Leerzeichen) in Python frei festgelegt werden kann, und daß "true" in Python ein Name ist (der Wahrheitswert wäre "True") und nicht eingeklammert werden muß. Leerzeilen können frei hinzugefügt oder entfernt werden. Man könnte auch schreiben: if true: print( "a" ); print( "b" ) print( "c" ) oder print( end = "a\nb\nc\n" if true else "c\n" ) oder print( end = true and """a b c """ or """c """ ) oder execute(""" if( true ) { print("a"); print("b"); } print("c"); """) . >Naja, Python hat keine Klammern für Blöcke. SERP-Ausschnitt: |brackets · PyPI pypi.org › project › brackets | |Brackets is a yet-another, a not just a pre-processor, a |language built on top of Python, allowing to use {} instead |of indentation in Python. . Anhang: Definition von "execute": import re def execute(code): # Remove leading/trailing whitespace code = code.strip() # Replace if( ... ) with if ... : def if_replacer(match): condition = match.group(1).strip() # Remove outer parentheses if present if condition.startswith('(') and condition.endswith(')'): condition = condition[1:-1].strip() return f'if {condition}:' code = re.sub(r'if\s*\((.*?)\)', if_replacer, code) # Split code into tokens, keeping braces tokens = re.split(r'(\{|\})', code) # Prepare for indentation indent = 0 lines = [] for token in tokens: token = token.strip() if not token: continue if token == '{': indent += 1 elif token == '}': indent -= 1 else: # Split token into statements by semicolon statements = [stmt.strip() for stmt in token.split(';') if stmt.strip()] for stmt in statements: # Skip empty statements if not stmt: continue lines.append(' ' * indent + stmt) py_code = '\n'.join(lines) exec(py_code, globals())