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


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

Re: [Python-de] import Problem

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] import Problem
Date Fri, 28 Apr 2017 14:48:43 +0200
Organization None
Lines 50
Message-ID <mailman.490.1493383814.2951.python-de@python.org> (permalink)
References <emg3qcFkefeU1@mid.individual.net> <odurs8$ka2$1@blaine.gmane.org> <mailman.478.1493366431.2951.python-de@python.org> <emggijFmrvvU1@mid.individual.net> <odv6l8$sev$1@blaine.gmane.org> <mailman.481.1493376504.2951.python-de@python.org> <emgmtgFo31tU1@mid.individual.net> <odvdn5$gv8$2@blaine.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace news.uni-berlin.de FOU9jtsd1B99WdVKRrwusQgNeQcxs0lxr1xEyrNofvYw==
Return-Path <gcpgg-python-de@m.gmane.org>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
X-Injected-Via-Gmane http://gmane.org/
User-Agent KNode/4.13.3
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <odvdn5$gv8$2@blaine.gmane.org>
X-Mailman-Original-References <emg3qcFkefeU1@mid.individual.net> <odurs8$ka2$1@blaine.gmane.org> <mailman.478.1493366431.2951.python-de@python.org> <emggijFmrvvU1@mid.individual.net> <odv6l8$sev$1@blaine.gmane.org> <mailman.481.1493376504.2951.python-de@python.org> <emgmtgFo31tU1@mid.individual.net>
Xref csiph.com de.comp.lang.python:4758

Show key headers only | View raw


Hermann Riemann wrote:

> Am 28.04.2017 um 12:48 schrieb Peter Otten:
> 
>>> ########## globale_funktionen.py
>>> import globale_variable
>>> g=globale_variable.variablen
>>> def f():
>>>     global g
>>>     g.x=1
> 
>> Das "global"-Statement ist überflüssig, da du den Namen g nur liest.
> 
> Richtig.
> 
>>> ########## globale_variable.py
>>> class Globale_Variablen:
>>>     def __init__(self):
>>>        self.x=0
>>> variablen=Globale_Variablen()
> 
>> Wenn du sowieso mit Klassen hantierst, mach aus f() doch eine Methode.
> 
> Wenn ich  ########## globale_variable.py zu
> class Globale_Variablen:
>     def __init__(self):
>        self.x=0
>     from globale_funktionen import *
> variablen=Globale_Variablen()
> erweitere, erhalte ich:
> 
> SyntaxError: import * only allowed at module level

> Hermann
      der mit dem Kopf durch die Wand will ;)

*-Imports sind eine Unsitte; die Namen explizit aufzuführen dürfte nicht 
zuviel verlangt sein. Oder du verwendest ein Mix-in:

# methoden.py
class M:
   def f(self): ...
   ...

# gottobjekt.py
import methoden

class G(methoden.M):
   ...

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


Thread

import Problem Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-04-28 07:55 +0200
  Re: [Python-de] import Problem Christopher Arndt <chris@chrisarndt.de> - 2017-04-28 08:45 +0200
    Re: [Python-de] import Problem Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-04-28 09:07 +0200
  Re: [Python-de] import Problem Peter Otten <__peter__@web.de> - 2017-04-28 09:44 +0200
    Re: [Python-de] import Problem Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-04-28 11:33 +0200
      Re: [Python-de] import Problem Peter Otten <__peter__@web.de> - 2017-04-28 12:48 +0200
        Re: [Python-de] import Problem Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-04-28 13:21 +0200
          Re: [Python-de] import Problem Peter Otten <__peter__@web.de> - 2017-04-28 14:48 +0200
  Re: import Problem Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-04-28 14:48 +0200

csiph-web