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


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

Re: [Python-de] import Problem

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Hermann Riemann <nospam.ng@hermann-riemann.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] import Problem
Date Fri, 28 Apr 2017 13:21:20 +0200
Lines 39
Message-ID <emgmtgFo31tU1@mid.individual.net> (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>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace individual.net lCarbHTCzXp1cyaTBFoB5QAqsTwVQ0chPOzGjKBjixHJrDSlYw
Cancel-Lock sha1:eAl+hc7fC/3mUZ9gR9aV2yvx5XA=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
In-Reply-To <mailman.481.1493376504.2951.python-de@python.org>
Xref csiph.com de.comp.lang.python:4756

Show key headers only | View raw


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 seine globale Datei
    in eine Datei einmal mit globale Variable
    und noch in etliche Dateien mit Funktions- und Klassenarten
    zerlegen möchte.

-- 
http://www.hermann-riemann.de

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