I recently created this example and am surprised at the results. I will demonstrate this with code:
File1: b.py :
delta = 0.0 def example(): global delta delta = 1 def ret_delta(): return delta
File2: a.py :
from b import * example() #WHY ARE THESE DIFFERENT? print(delta) # prints: 0.0 print(ret_delta()) # prints: 1
This makes no sense! Why does accessing a variable and calling a function returning this variable have any meaning?
For your reference, I am using python 3.5.2 for Windows 32 bit
When you do
from b import *
a.py, , b ( delta) a. float Python, a.delta b.delta, . , print() a.delta, b.delta.
a.py
b
delta
a
float
a.delta
b.delta
print()
from b import * a. b name. .
, Python - ; "" . , . , b a, from b import * .
< delta b. 0.0 float. , delta a.
0.0
, a.delta b.delta; b.delta = 1 a.delta, .
b.delta = 1
, , Python; . Python Ned Batchelder.
Source: https://habr.com/ru/post/1650301/More articles:Onboarding - how to prioritize key actions - androidКак избежать состояния гонки, обнаруженного в следующем коде? - javaLive chat using Ionic and laravel at the end of the API - cordovaC # - Rtrow exception in catch block, after returning - c #FadeIn and FadeOut effect using React JS - javascriptRunning a script conditionally doesn't work in travis.yml, why? - bashhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1650303/how-to-find-out-what-causes-file-permissions-to-change-when-checking-out-files-with-git&usg=ALkJrhiWaKPgJgaWc5XGzFVus-fV1HnnVQОтладка переадресации портов для удаленного использования ноутбука Jupyter - sshCustomization and tools for several C ++ platforms - c ++What makes git post-receive umask different from umask user? - gitAll Articles