Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #5128
| From | Hartmut Goebel <h.goebel@goebel-consult.de> |
|---|---|
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] Verständnis-Problem mit python3 import |
| Date | 2018-03-01 12:21 +0100 |
| Organization | Goebel Consult |
| Message-ID | <mailman.163.1519903295.2835.python-de@python.org> (permalink) |
| References | <8df4c688-813f-74c4-9523-f9ed0a4b00ae@redcor.ch> <9ec5fcde-954f-0fae-ea40-0d2f395d2ec1@goebel-consult.de> |
[Multipart message — attachments visible in raw view] - view raw
Am 01.03.2018 um 10:38 schrieb robert: > from . import globaldefaults > from globaldefaults import GLOBALDEFAULTS Laut Syntax kommt [1] nach dem "from" ein "relative_module", als der Name eines Modules. Das zweite import-Statement verwendet also nicht den Identifier "globaldefaults" sondern sucht das Modul mit dem Namen "globaldefaults". In Python 2 funktioniert das so, wie Du es erwartet, weil "globaldefaults" als relativer Import interpretiert wird. In Python 3 ist es aber ein absoluter Import - und ein globales Module/Package "globaldefaults" hast Du nicht. Für python 3 muss also das zweite Import-Statement lauten (funktioniert auch mit Python 2.7): from .globaldefaults import GLOBALDEFAULTS [1] https://docs.python.org/3/reference/simple_stmts.html#the-import-statement -- 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/eilt-petition-auf-weact-gegen-vds-jetzt-unterschreiben Kolumne: http://www.cissp-gefluester.de/2011-09-kommerz-uber-recht-fdp-die-gefaellt-mir-partei
Back to de.comp.lang.python | Previous | Next | Find similar
Re: [Python-de] Verständnis-Problem mit python3 import Hartmut Goebel <h.goebel@goebel-consult.de> - 2018-03-01 12:21 +0100
csiph-web