Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #6254

[Python-de] Re: Pfade, Modulnamen und import-Statements

From Hartmut Goebel <h.goebel@goebel-consult.de>
Newsgroups de.comp.lang.python
Subject [Python-de] Re: Pfade, Modulnamen und import-Statements
Date 2025-01-26 21:21 +0100
Organization Goebel Consult
Message-ID <913de228-0080-4702-b74b-d2a1ea476d9a@goebel-consult.de> (permalink)
References <ZjYYBgoIiqLkxkB3@torres.zugschlus.de> <la7604FdslU1@mid.individual.net> <Verzeichnisse-20240511131000@ram.dialup.fu-berlin.de> <importe-20250126192659@ram.dialup.fu-berlin.de> <Paket-20250126205332@ram.dialup.fu-berlin.de>

Show all headers | View raw


Am 26.01.25 um 20:55 schrieb Stefan Ram:
>    Nun, "module.py" als Skript starten, und es gibt eine Fehlermeldung!
>    Warum? Weil Python das Verzeichnis "package" nicht als Package sieht.

Nicht ganz.

Neuere Versionen von Python (3.10, evtl. schon früher) betrachten ein 
Verzeichnis auch ohne __init__.py als Package.

Aber "python package/module.py" startet die Datei eben - wie Du 
schreibst - als Skript. Und Skript können keine relativen Importe 
enthalten. Eben weil sie Skripte und keine Module eines Packages sind.

Du könntest allerdings das Module "package.module" ausführen, das geht:

python -m package.module

-- 
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software 
Development

Goebel Consult, Landshut
http://www.goebel-consult.de

Blog: https://www.goebel-consult.de/blog/2019/blockchain-bringts-nicht/
Kolumne: 
https://www.goebel-consult.de/blog/cissp-gefluester/2011-10-aus-der-schublade-in-die-koepfe/ 

Back to de.comp.lang.python | Previous | NextPrevious in thread | Find similar


Thread

[Python-de] Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-04 13:12 +0200
  [Python-de] Re: Pfade, Modulnamen und import-Statements Hartmut Goebel <h.goebel@crazy-compilers.com> - 2024-05-04 19:22 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-05 10:21 +0200
      Re: [Python-de] Re: Pfade, Modulnamen und import-Statements Bastian Blank <usenet@waldi.eu.org> - 2024-05-05 10:32 +0000
        [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-10 11:37 +0200
          [Python-de] Re: Pfade, Modulnamen und import-Statements Hartmut Goebel <h.goebel@crazy-compilers.com> - 2024-05-11 17:49 +0200
  Re: [Python-de] Pfade, Modulnamen und import-Statements "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2024-05-05 02:26 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-05 10:25 +0200
      Re: [Python-de] Re: Pfade, Modulnamen und import-Statements "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2024-05-05 12:38 +0200
        [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-10 11:39 +0200
          Re: [Python-de] Re: Pfade, Modulnamen und import-Statements "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2024-05-10 19:25 +0200
  Re: [Python-de] Pfade, Modulnamen und import-Statements Hermann Riemann <nospam.ng@hermann-riemann.de> - 2024-05-05 12:02 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-05 12:35 +0200
  Re: [Python-de] Pfade, Modulnamen und import-Statements Hermann Riemann <nospam.ng@hermann-riemann.de> - 2024-05-10 20:05 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Christopher Arndt <chris@chrisarndt.de> - 2024-05-11 15:18 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Hartmut Goebel <h.goebel@goebel-consult.de> - 2025-01-26 21:21 +0100

csiph-web