python - Unexpected behaviour in gui -


for 2 days suffering strange error, can not understand problem asking help. have unique feature.

def find_config(self, path):     dic = list(path.split('/'))     print dic     size = len(dic)     print '/'.join(dic) 

when run within class constructor, works fine, when run inside event handler button, hangs on join function.

constructor:

class mainwindow(qtgui.qmainwindow, ui_mainwindow):     def __init__(self):             qmainwindow.__init__(self)             self.setupui(self)             self.filepath = ""             self.action_open.activated.connect(self.file_open_func)              print self.find_config('/home/juster/asdfa/main.c') 

the handler button:

def file_open_func(self, path = 0):      try:         self.filepath = 0;         if not path:                     self.filepath = qfiledialog.getopenfilename(self, 'open file', self.rootpath, "c/c++ (*.c);; (*.*);; makefile (makefile)")           else:             self.filepath = path          print self.find_config(self.filepath)         f = open(self.filepath, 'a+') 

see else bring enough terminal variable dic

function find_config constuctor:

['', 'home', 'juster', 'asdfa', 'main.c'] 

function find_config handler:

[pyqt4.qtcore.qstring(u''), pyqt4.qtcore.qstring(u'home'), pyqt4.qtcore.qstring(u'juster'), pyqt4.qtcore.qstring(u'asdfa'), pyqt4.qtcore.qstring(u'main.c')] 

this magic?

it looks path string when called handler not regular python str, rather instance of qt class qstring. appears work split, not join. imagine you'll find problem goes away if convert regular string str.

def find_config(self, path):     dic = list(str(path).split('/')) # added str() call line     print dic     size = len(dic)     print '/'.join(dic) 

note dic variable has rather misleading name. it's list, not dictionary, calling dic asking confusion (though list call when created seems unnecessary). i'm not sure function does. seems split string, rejoin was.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -