Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #4510 > unrolled thread
| Started by | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| First post | 2016-08-24 15:20 +0200 |
| Last post | 2016-08-24 21:37 +0200 |
| Articles | 18 — 7 participants |
Back to article view | Back to de.comp.lang.python
import und vollqalifizierter Dateiname Hermann Riemann <nospam.compb7@hermann-riemann.de> - 2016-08-24 15:20 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Andreas Jung <lists@zopyx.com> - 2016-08-24 15:27 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Hermann Riemann <nospam.compb7@hermann-riemann.de> - 2016-08-24 16:02 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Christopher Arndt <chris@chrisarndt.de> - 2016-08-24 15:32 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Hermann Riemann <nospam.compb7@hermann-riemann.de> - 2016-08-24 15:56 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Andreas Jung <lists@zopyx.com> - 2016-08-24 16:05 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Hermann Riemann <nospam.compb7@hermann-riemann.de> - 2016-08-24 16:37 +0200
Re: [Python-de] import und vollqalifizierter Dateiname "Sven R. Kunze" <srkunze@mail.de> - 2016-08-24 21:35 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Hermann Riemann <nospam.compb7@hermann-riemann.de> - 2016-08-25 07:49 +0200
Re: [Python-de] import und vollqalifizierter Dateiname "Sven R. Kunze" <srkunze@mail.de> - 2016-08-25 12:02 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Christopher Arndt <chris@chrisarndt.de> - 2016-08-24 22:59 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Hermann Riemann <nospam.compb7@hermann-riemann.de> - 2016-08-25 08:21 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Christopher Arndt <chris@chrisarndt.de> - 2016-08-24 16:58 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Hermann Riemann <nospam.compb7@hermann-riemann.de> - 2016-08-25 08:07 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Andreas Jung <lists@zopyx.com> - 2016-08-25 08:17 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Jens <python-de-mailingliste@jensdiemer.de> - 2016-08-25 08:35 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Hartmut Goebel <h.goebel@goebel-consult.de> - 2016-08-25 09:36 +0200
Re: [Python-de] import und vollqalifizierter Dateiname Peter Otten <__peter__@web.de> - 2016-08-24 21:37 +0200
| From | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| Date | 2016-08-24 15:20 +0200 |
| Subject | import und vollqalifizierter Dateiname |
| Message-ID | <e25l8bFpb5rU1@mid.individual.net> |
Beispiel:
5 unterschiedliche Dateien existieren:
/a/b/c/p1.py
/u/v/w/p2.py
/x/y/z/p2.py
/u/v/w/p3.py
/x/y/z/p3.py
Die ersten beide Zeilen von /a/b/c/p1.py wären,
wenn bei import string erlaubt wäre:
import "/u/v/w/p2.py"
import "/x/y/z/p3.py"
Hermann
der das Problem nur ungern mit
Kopiererei auf /tmp und Aufruf von
os.system("python3 /tmp/p0.py") lösen würde.
--
www.hermann-riemann.de
[toc] | [next] | [standalone]
| From | Andreas Jung <lists@zopyx.com> |
|---|---|
| Date | 2016-08-24 15:27 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.281.1472045266.2268.python-de@python.org> |
| In reply to | #4510 |
Bitte was?
-aj
Am 24. August 2016 um 15:20 schrieb Hermann Riemann <
nospam.compb7@hermann-riemann.de>:
> Beispiel:
>
> 5 unterschiedliche Dateien existieren:
>
> /a/b/c/p1.py
> /u/v/w/p2.py
> /x/y/z/p2.py
> /u/v/w/p3.py
> /x/y/z/p3.py
>
> Die ersten beide Zeilen von /a/b/c/p1.py wären,
> wenn bei import string erlaubt wäre:
>
> import "/u/v/w/p2.py"
> import "/x/y/z/p3.py"
>
> Hermann
> der das Problem nur ungern mit
> Kopiererei auf /tmp und Aufruf von
> os.system("python3 /tmp/p0.py") lösen würde.
>
> --
> www.hermann-riemann.de
> _______________________________________________
> python-de maillist - python-de@python.org
> https://mail.python.org/mailman/listinfo/python-de
>
[toc] | [prev] | [next] | [standalone]
| From | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| Date | 2016-08-24 16:02 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <e25nmsFpts6U1@mid.individual.net> |
| In reply to | #4511 |
Andreas Jung schrieb: > Bitte was? Wie bekomme ich syntaktisch richtig das unten beschriebene Beispiel zu laufen? Wenn ich wie unten p1.py ausprobbiere, erhalte ich Syntaxfehler wegen '"'. Wenn ich die Zeichen '"' weglassen, ändert sich nur die Syntax Fehlermeldung. >> Beispiel: >> 5 unterschiedliche Dateien existieren: >> /a/b/c/p1.py >> /u/v/w/p2.py >> /x/y/z/p2.py >> /u/v/w/p3.py >> /x/y/z/p3.py >> Die ersten beide Zeilen von /a/b/c/p1.py wären, >> wenn bei import string erlaubt wäre: >> import "/u/v/w/p2.py" >> import "/x/y/z/p3.py" Hermann der bis jetzt nicht nicht gelesen hat, wie er das Problem direkt mit Python3 lösen kann. -- www.hermann-riemann.de
[toc] | [prev] | [next] | [standalone]
| From | Christopher Arndt <chris@chrisarndt.de> |
|---|---|
| Date | 2016-08-24 15:32 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.282.1472046089.2268.python-de@python.org> |
| In reply to | #4510 |
[Multipart message — attachments visible in raw view] — view raw
Am 24.08.2016 um 15:20 schrieb Hermann Riemann: > der das Problem [...] Welches Problem?
[toc] | [prev] | [next] | [standalone]
| From | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| Date | 2016-08-24 15:56 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <e25ndbFprapU1@mid.individual.net> |
| In reply to | #4512 |
Christopher Arndt schrieb: > Am 24.08.2016 um 15:20 schrieb Hermann Riemann: >> der das Problem [...] > Welches Problem? Bei import geht kein vollqualifizierter Dateiname, der den Buchstabe / enthält. Python3 meint dazu Syntaxfehler. Hermann der in C statt import #include schreiben würde. -- www.hermann-riemann.de
[toc] | [prev] | [next] | [standalone]
| From | Andreas Jung <lists@zopyx.com> |
|---|---|
| Date | 2016-08-24 16:05 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.283.1472047546.2268.python-de@python.org> |
| In reply to | #4513 |
Du solltest Dich mal grundlegend über Python Packages und den Import-Mechanismus von Python informieren. Man kann nicht einfach so ein Modul über einen absoluten Pfad importieren. Das Modul muß in sys.path oder via PYHONPATH erreichbar sein... -aj Am 24. August 2016 um 15:56 schrieb Hermann Riemann < nospam.compb7@hermann-riemann.de>: > Christopher Arndt schrieb: > > > Am 24.08.2016 um 15:20 schrieb Hermann Riemann: > >> der das Problem [...] > > > Welches Problem? > > Bei import geht kein vollqualifizierter Dateiname, > der den Buchstabe / enthält. > Python3 meint dazu Syntaxfehler. > > Hermann > der in C statt import #include schreiben würde. > > -- > www.hermann-riemann.de > _______________________________________________ > python-de maillist - python-de@python.org > https://mail.python.org/mailman/listinfo/python-de >
[toc] | [prev] | [next] | [standalone]
| From | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| Date | 2016-08-24 16:37 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <e25pp0Fqeh9U1@mid.individual.net> |
| In reply to | #4515 |
Andreas Jung schrieb: > Man kann nicht einfach so ein Modul über einen absoluten Pfad importieren. > Das Modul muß in sys.path oder via PYHONPATH erreichbar sein... Funktioniert in meinem Beispiel nicht, da /u/v/w und /x/y/z gleiche Dateinamen mit unterschiedlichen Inhalten haben. Hermann der dann den nicht einfachen Weg (z.B. vielleicht über read und eval ) nehmen muß. -- www.hermann-riemann.de
[toc] | [prev] | [next] | [standalone]
| From | "Sven R. Kunze" <srkunze@mail.de> |
|---|---|
| Date | 2016-08-24 21:35 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.288.1472067322.2268.python-de@python.org> |
| In reply to | #4516 |
Hilft dir das? http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path#answer-67692 On 24.08.2016 16:37, Hermann Riemann wrote: > Andreas Jung schrieb: > >> Man kann nicht einfach so ein Modul über einen absoluten Pfad importieren. >> Das Modul muß in sys.path oder via PYHONPATH erreichbar sein... > Funktioniert in meinem Beispiel nicht, > da /u/v/w und /x/y/z gleiche Dateinamen mit unterschiedlichen > Inhalten haben. > > Hermann > der dann den nicht einfachen Weg > (z.B. vielleicht über read und eval ) nehmen muß. >
[toc] | [prev] | [next] | [standalone]
| From | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| Date | 2016-08-25 07:49 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <e27f6dF820gU1@mid.individual.net> |
| In reply to | #4518 |
Sven R. Kunze schrieb: > Hilft dir das? > http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path#answer-67692 Genau das, was ich gesucht habe. -- www.hermann-riemann.de
[toc] | [prev] | [next] | [standalone]
| From | "Sven R. Kunze" <srkunze@mail.de> |
|---|---|
| Date | 2016-08-25 12:02 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.305.1472119372.2268.python-de@python.org> |
| In reply to | #4521 |
On 25.08.2016 07:49, Hermann Riemann wrote: > Sven R. Kunze schrieb: > >> Hilft dir das? >> http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path#answer-67692 > Genau das, was ich gesucht habe. > Bittesehr. :)
[toc] | [prev] | [next] | [standalone]
| From | Christopher Arndt <chris@chrisarndt.de> |
|---|---|
| Date | 2016-08-24 22:59 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.290.1472072385.2268.python-de@python.org> |
| In reply to | #4516 |
[Multipart message — attachments visible in raw view] — view raw
Am 24.08.2016 um 21:35 schrieb Sven R. Kunze: > Hilft dir das? > > http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path#answer-67692 Ich würde behaupten: nein. Das ist für Leute, die wissen, wie Module und Packages und Imports unter Python normalerweise funktionieren, und dann immer noch der Meinung sind, sie brauchen was anderes. Chris
[toc] | [prev] | [next] | [standalone]
| From | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| Date | 2016-08-25 08:21 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <e27h2fF8fv0U1@mid.individual.net> |
| In reply to | #4520 |
Christopher Arndt schrieb:
> Am 24.08.2016 um 21:35 schrieb Sven R. Kunze:
>> Hilft dir das?
>> http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path#answer-67692
> Ich würde behaupten: nein. Das ist für Leute, die wissen, wie Module und
> Packages und Imports unter Python normalerweise funktionieren,
Da steht die Frage nach normal an.
Im einfachsten Fall
sehe ich
import xy
als
#include modifiziertes_xy
an
wobei bei Modifikation in etwa
#ifndef XY
#define XY
class Xy:
alter xy Inhalt
xy=Xy()
#endif
enthält.
( einiges davon wie Variable
wären in __init__ zu kopieren ..)
> und dann immer noch der Meinung sind, sie brauchen was anderes.
Irgendwann passen Wünsche und Lehrbuchinhalt
nicht zusammen.
wie z.B. bei import
( oder print mit utf8 unter cgi)
Hermann
der nicht alles experimentell lösen kann.
--
www.hermann-riemann.de
[toc] | [prev] | [next] | [standalone]
| From | Christopher Arndt <chris@chrisarndt.de> |
|---|---|
| Date | 2016-08-24 16:58 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.285.1472050711.2268.python-de@python.org> |
| In reply to | #4513 |
[Multipart message — attachments visible in raw view] — view raw
Am 24.08.2016 um 15:56 schrieb Hermann Riemann: > Bei import geht kein vollqualifizierter Dateiname, > der den Buchstabe / enthält. https://docs.python.org/3/tutorial/modules.html https://docs.python.org/3/reference/import.html Merke: Python ist nicht C und ein Python-Modul keine Header-Datei. ;) So geht's (Voraussetzung: alle Verzeichnisse enthalten ein '__init__.py' Datei): import a.b.c.p1 import u.v.w.p2 import u.v.w.p3 import x.y.z.p2 import x.y.z.p3 a.b.c.p1.foo() u.v.w.p2.foo() u.v.w.p2.bar() usw. Oder so: from .a.b.c import p from .u.v.w import p as p2 usw.
[toc] | [prev] | [next] | [standalone]
| From | Hermann Riemann <nospam.compb7@hermann-riemann.de> |
|---|---|
| Date | 2016-08-25 08:07 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <e27g85F89dpU1@mid.individual.net> |
| In reply to | #4517 |
Christopher Arndt schrieb: >> Bei import geht kein vollqualifizierter Dateiname, >> der den Buchstabe / enthält. > > https://docs.python.org/3/tutorial/modules.html > https://docs.python.org/3/reference/import.html Oder auch im Buch "Python 3" von Ernesti Kaiser im Kapitel "Pakete". Ist nützlich. Versagt aber, wenn man z.B. von /home nach /tmp wechseln will. Hermann der beim gelegentlichen Programmieren einige Jahrzehnte C Erfahrung und einige Jahre Python Erfahrung hat. -- www.hermann-riemann.de
[toc] | [prev] | [next] | [standalone]
| From | Andreas Jung <lists@zopyx.com> |
|---|---|
| Date | 2016-08-25 08:17 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.299.1472105825.2268.python-de@python.org> |
| In reply to | #4522 |
Es wäre hilfreich wenn Du erklärst was Du konkret machen willst und was dein reales Problem ist anstatt uns ein paar Pfade und ein paar mehr oder minder nichtssagende Sätze vor die Füsse zu werfen. Auch nach mehrmaligem Lesen des Threads ist nicht komplett klar was Du genau fragen willst...also bitte etwas mehr Mühe geben wenn Du fachlich fundierte Hilfe erwartest. -aj Am 25. August 2016 um 08:07 schrieb Hermann Riemann < nospam.compb7@hermann-riemann.de>: > Christopher Arndt schrieb: > > >> Bei import geht kein vollqualifizierter Dateiname, > >> der den Buchstabe / enthält. > > > > https://docs.python.org/3/tutorial/modules.html > > https://docs.python.org/3/reference/import.html > > Oder auch im Buch "Python 3" von Ernesti Kaiser > im Kapitel "Pakete". > > Ist nützlich. > > Versagt aber, wenn man z.B. von /home nach /tmp > wechseln will. > > Hermann > der beim gelegentlichen Programmieren > einige Jahrzehnte C Erfahrung und > einige Jahre Python Erfahrung hat. > > -- > www.hermann-riemann.de > _______________________________________________ > python-de maillist - python-de@python.org > https://mail.python.org/mailman/listinfo/python-de >
[toc] | [prev] | [next] | [standalone]
| From | Jens <python-de-mailingliste@jensdiemer.de> |
|---|---|
| Date | 2016-08-25 08:35 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.301.1472106935.2268.python-de@python.org> |
| In reply to | #4522 |
Am 25.08.2016 um 08:17 schrieb Andreas Jung: > Es wäre hilfreich wenn Du erklärst was Du konkret machen willst und was > dein reales Problem ist > anstatt uns ein paar Pfade und ein paar mehr oder minder nichtssagende > Sätze vor die Füsse zu werfen. > Auch nach mehrmaligem Lesen des Threads ist nicht komplett klar was Du > genau fragen willst...also > bitte etwas mehr Mühe geben wenn Du fachlich fundierte Hilfe erwartest. Genau sowas in der Art wollte ich gerade schreiben ;) Kann mir höchstens Vorstellen, das es irgendeine (falsche) Art von Plugin System sein soll... -- Mfg. Jens Diemer ---- http://www.jensdiemer.de
[toc] | [prev] | [next] | [standalone]
| From | Hartmut Goebel <h.goebel@goebel-consult.de> |
|---|---|
| Date | 2016-08-25 09:36 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.303.1472110982.2268.python-de@python.org> |
| In reply to | #4522 |
[Multipart message — attachments visible in raw view] — view raw
Am 25.08.2016 um 08:07 schrieb Hermann Riemann: > Versagt aber, wenn man z.B. von /home nach /tmp > wechseln will. Ich glaube, Du möchtest etwas über die Environment-Variable PYTHONPATH lesen. -- 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: http://www.goebel-consult.de/blog/feiertagsarbeit-bei-teletrust Kolumne: http://www.cissp-gefluester.de/2011-08-horrorszenario-bring-your-own-device
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2016-08-24 21:37 +0200 |
| Subject | Re: [Python-de] import und vollqalifizierter Dateiname |
| Message-ID | <mailman.289.1472067540.2268.python-de@python.org> |
| In reply to | #4513 |
Christopher Arndt wrote:
> Am 24.08.2016 um 15:56 schrieb Hermann Riemann:
>> Bei import geht kein vollqualifizierter Dateiname,
>> der den Buchstabe / enthält.
>
> https://docs.python.org/3/tutorial/modules.html
> https://docs.python.org/3/reference/import.html
>
> Merke: Python ist nicht C und ein Python-Modul keine Header-Datei. ;)
>
> So geht's (Voraussetzung: alle Verzeichnisse enthalten ein '__init__.py'
> Datei):
Obwohl es nicht so recht zu "Explicit is better than implicit" passt: in
Python 3 ist ist die __init__.py nicht unbedingt erforderlich:
$ python3 -c 'import a.b.c.p1'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'a'
$ mkdir -p a/b/c/
$ echo 'print("hello from p1")' > a/b/c/p1.py
$ python3 -c 'import a.b.c.p1'
hello from p1
Siehe auch https://www.python.org/dev/peps/pep-0420/
> import a.b.c.p1
> import u.v.w.p2
> import u.v.w.p3
> import x.y.z.p2
> import x.y.z.p3
>
> a.b.c.p1.foo()
> u.v.w.p2.foo()
> u.v.w.p2.bar()
>
> usw.
>
> Oder so:
>
> from .a.b.c import p
> from .u.v.w import p as p2
>
> usw.
[toc] | [prev] | [standalone]
Back to top | Article view | de.comp.lang.python
csiph-web