내가 아주 간단한 될 것입니다 확신 어떤 것을 다시 확실 해요 ...스크립트로 인해 정의되지 않은 기능을 기본적으로
여러 다른 스크립트 erroring를 호출, 내 첫 번째 스크립트 호출을하기 위해 노력하고있어
다음from datetime import date, timedelta
from sched import scheduler
from time import time, sleep, strftime
import random
s = scheduler(time, sleep)
random.seed()
def periodically(runtime, intsmall, intlarge, function):
## Get current time
currenttime = strftime('%H:%M:%S')
## If currenttime is anywhere between 23:40 and 23:50 then...
if currenttime > '23:40:00' and currenttime < '23:50:00':
## Call clear
clear()
## Update time
currenttime = strftime('%H:%M:%S')
## Idle time
while currenttime > '23:40:00' and currenttime < '23:59:59' or currenttime >= '00:00:00' and currenttime < '01:30:00':
## Update time
currenttime = strftime('%H:%M:%S')
runtime += random.randrange(intsmall, intlarge)
s.enter(runtime, 1, function,())
s.run()
def callscripts():
print "Calling Functions"
errors = open('ERROR(S).txt', 'a')
try:
execfile("data/secondary.py")
except Exception as e:
errors.write(str(e))
errors.write("""
""")
errors.close()
while True:
periodically(2, -1, +1, callscripts)
은 다음과 같습니다/
가첫 번째 스크립트/주요 스크립트 ... 다른 스크립트의 무리를 실행하지만 문제는 각 개별 스크립트가 자신의 기능을 처음 secript에서 호출 할 수 없습니다 포함시킬 것입니다 secondary.py
import win32con
from win32api import *
from win32gui import *
class WindowsBalloonTip:
def __init__(self, title, msg):
message_map = { win32con.WM_DESTROY: self.OnDestroy,}
# Register the window class.
wc = WNDCLASS()
hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = 'PythonTaskbar'
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = RegisterClass(wc)
# Create the window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = CreateWindow(classAtom, "Taskbar", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None)
UpdateWindow(self.hwnd)
# Icons managment
iconPathName = "icon1.ico" ## LOCATION TO THE ICON FILE
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
try:
hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
except:
hicon = LoadIcon(0, win32con.IDI_APPLICATION)
flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, 'Tooltip')
# Notify
Shell_NotifyIcon(NIM_ADD, nid)
Shell_NotifyIcon(NIM_MODIFY, (self.hwnd, 0, NIF_INFO, win32con.WM_USER+20, hicon, 'Balloon Tooltip', msg, 200, title))
# self.show_balloon(title, msg)
sleep(5)
# Destroy
DestroyWindow(self.hwnd)
classAtom = UnregisterClass(classAtom, hinst)
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, nid)
PostQuitMessage(0) # Terminate the app.
# Function
def balloon_tip(title, msg):
w=WindowsBalloonTip(title, msg)
balloon_tip("test test", "Running")
def hi():
print "hi"
hi()
오류 :
global name 'WindowsBalloonTip' is not defined
전체 오류 :
Traceback (most recent call last):
File "C:\Main.py", line 48, in <module>
periodically(2, -1, +1, callscripts)
File "C:\Main.py", line 27, in periodically
s.run()
File "C:\Python27\lib\sched.py", line 117, in run
action(*argument)
File "Main.py", line 34, in callscripts
execfile("data/secondary.py")
File "data/secondary.py", line 93, in <module>
balloon_tip("test test", "Running")
File "data/secondary.py", line 78, in balloon_tip
w=WindowsBalloonTip(title, msg)
NameError: global name 'WindowsBalloonTip' is not defined
가 어떻게이 문제를 해결 가겠어요? 사전에
감사 Hyflex
게시하시기 바랍니다 전체 ** ** 오류 추적은 - 그것의 정보는 도움을주기위한 것입니다 코드를 디버깅하여 게시해야합니다. – Brionius
그 파일에서 전체 오류 추적입니다, 만약 당신이 그것을 실행하고 잘 작동하는 main.py를 통해 그것을 실행하는 경우 작동하지 않는 의도로 자신을 실행하는 경우 secondary.py. 위의 두 스크립트는 오류를 완벽하게 재현 할 수 있습니다. – Ryflex
추적을 사용하지 않고 문제를 실제로 확인할 수는 없습니다. 하지만 모듈을 작성하고 import 문을 사용하는 방법을 살펴볼 수 있다고 생각합니다. 함수를 파일에 정의하고 모듈 수준에서 그 함수를 호출하는 대신'import secondary'와 같은 첫 번째 스크립트에서 모듈을 가져와'secondary.balloon_tip()'과 같은 함수를 호출해야합니다. 이것은 모듈 식 코드를 작성하는 올바른 방법입니다. – Iguananaut