Nur einzelne von Modul a nach modul b importieren
Verfasst: Dienstag 15. November 2016, 19:39
Hallo Leute,
Wie schaffe ich das dass man von einem Modul nur eine bestimmte Variable in einem anderen Modul importiert
irgendwie importiert er beim zweiten modul wirklich alles vom ersten modul. und führt sogar modul "liveplot" komplett aus. Ich will aber nur dass
die variable xs importiert wird vom modul "liveplot".....
Wie schaffe ich das dass man von einem Modul nur eine bestimmte Variable in einem anderen Modul importiert
Code: Alles auswählen
# liveplot.py
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
style.use('fivethirtyeight')
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
global xs
def animate(i):
lines = open('live.txt','r').read().split('\n')
xs = []
ys = []
for line in lines:
if len(line) > 1:
x, y = line.split(',')
xs.append(x)
ys.append(y)
ax1.clear()
ax1.plot(xs, ys)
ani = animation.FuncAnimation(fig, animate, interval = 1000)
plt.show()
Code: Alles auswählen
from liveplot import xs
print(liveplot.xs)
die variable xs importiert wird vom modul "liveplot".....