def function returning wrong value (python 2.7) -
so im working def functions first time , documentation looked simple enough. , got few examples. cant relate code. have 2 files langpy , test1:
test1.py
import time import thread import os import sys import ctypes import wmi langpy import lang langpy import port string = "" class service_test: def __init__(self): thread.start_new(self.do_something, tuple()) while true: if getattr(sys,'stopservice', false): sys.exit() time.sleep(0.3) def do_something(self): print(str(lang)) print(str(port)) while true: fname = 'c:\\\\test.txt' f = open(fname, 'a') f.write(str(time.time())) #f.write("%s /n/r") % string f.close() time.sleep(1) if __name__ == "__main__": tst = service_test()
langpy:
import os import time import ctypes import wmi def lang(self, language): windll = ctypes.windll.kernel32 language = str(windll.getuserdefaultuilanguage()) return def port(self, ardport): ardport = "not found" c = wmi.wmi() wql = "select * win32_usbcontrollerdevice" item in c.query(wql): s = str(item.dependent.caption) strfind = "raptor" if (s.find(strfind) >= 0): ardport = str(item.dependent.caption) return
i want return strings ardport = str(item.dependent.caption)
, language = str(windll.getuserdefaultuilanguage())
in test1 code, keeps printing
function lang @ 0x027479f0 function port @ 0x027503b0
(they have <>
on outside forum format wont include them)
i have unedited version of langpy (without defining anything) retunes correct str
import os import time import ctypes import wmi windll = ctypes.windll.kernel32 lang = str(windll.getuserdefaultuilanguage()) print(lang) ardport = "not found" c = wmi.wmi() wql = "select * win32_usbcontrollerdevice" item in c.query(wql): s = str(item.dependent.caption) strfind = "raptor" if (s.find(strfind) >= 0): ardport = str(item.dependent.caption) print (ardport)
you importing these functions correctly:
from langpy import lang langpy import port
however, printing reference these funtions, not return value.
print(str(lang)) print(str(port))
you want call funtion, print gets returned. can so:
print(str(lang())) print(str(port()))
just 1 more set of parenthesis!
edit: upon looking further, not returning functions. try:
def lang(): windll = ctypes.windll.kernel32 language = str(windll.getuserdefaultuilanguage()) return language def port(): ardport = "not found" c = wmi.wmi() wql = "select * win32_usbcontrollerdevice" item in c.query(wql): s = str(item.dependent.caption) strfind = "raptor" if (s.find(strfind) >= 0): ardport = str(item.dependent.caption) return ardport
note: not need argumens these functions, unless there functionality i'm missing.
the self
argument used class methods, know object refer to.
Comments
Post a Comment