Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Marc Haber Newsgroups: de.comp.lang.python Subject: =?utf-8?q?=5BPython-de=5D_Re=3A_Pfade=2C_Modulnamen_und_import-Statements?= Date: Fri, 10 May 2024 11:39:48 +0200 Lines: 54 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de ZFtbkzn2nt+pIb/avxBEeA6kUWBESN/iHMZ6bjq7UwAQ== Cancel-Lock: sha1:JpDhkv2zM8H5e/KUfYKfT4BlF4c= sha256:b5kSKM28iLquJKmo9omtKleavBrXNIu4vTVfgnMvklU= Authentication-Results: mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-MailFrom: mh+python-de@zugschlus.de X-Mailman-Rule-Hits: member-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address Message-ID-Hash: S7R2C5BY5YSHO6FT2FANKNVMCZS6EOBP X-Message-ID-Hash: S7R2C5BY5YSHO6FT2FANKNVMCZS6EOBP X-Mailman-Approved-At: Fri, 10 May 2024 08:14:02 -0400 X-Mailman-Version: 3.3.10b1 Precedence: list List-Id: Die Deutsche Python Mailingliste Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Xref: csiph.com de.comp.lang.python:6060 On Sun, May 05, 2024 at 12:38:18PM +0200, Peter J. Holzer wrote: > On 2024-05-05 08:25, Marc Haber wrote: > > On Sun, May 05, 2024 at 02:26:02AM +0200, Peter J. Holzer wrote: > >> On 2024-05-04 11:12, Marc Haber wrote: > >> > ich hab mal eine Verständnisfrage. > >> > > >> > Gegeben sei ein Verzeichnis . und ein Programm ./keks. > >> > Weiterhin sei die Klasse MyClass1 in d/mc1.py und die Klasse MyClass2 in > >> > d/mc2.py definierrt. > >> > > >> > Wenn ich nun in keks die Klasse MyClass2 benutzen möchte, schreibe ich > >> > "from d.mc2 import MyClass2". Wnn ich in d/mc1.py dasselbe tun möchte, > >> > muss ich dort "from mc2 import MyClass2" schreiben, > >> > >> Nein, das funktioniert nicht: > >> > >> #v+ > >> % ./keks > >> Traceback (most recent call last): > >> File "/home/hjp/tmp/marc/./keks", line 3, in > >> from d.mc1 import MyClass1 > >> File "/home/hjp/tmp/marc/d/mc1.py", line 1, in > >> from mc2 import MyClass2 > >> ModuleNotFoundError: No module named 'mc2' > >> #v- > > > > Mein mc1.py hat eingebauten testcode: > > > > #v+ > > if __name__ == "__main__": > > zdns = Zg2DNSQuery(timeout=2, debug=True) > > > > rootservers = DNSRootDataParser() > > logger.debug(f"{rootservers.get_ipv4_servers()=}") > > #v- > > Ah, dachte ich mir, dass da eine wichtige Information fehlt ;-). Welche? Dass ich den Empfehlungen des Python Tutorials, Kapitel 6.1.1 "Executing modules as scripts" gefolgt bin? War das falsch? > Unter anderem auch aus diesem Grund schreibe ich Test-Code immer in > eigene Files. So werde ich das dann jetzt wohl auch halten. Schade. Grüße Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don't trust Computers. They | Mailadresse im Header Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402 Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421