Message94176
That's a good point, Marco. I'd forgotten about the distinction.
Converting 'filename' to a Python string with 'str()' fixed the problem.
> However, when I tried to run your example, newWF.py, and tried to open a
> file from the menu, I got this:
>
> controls.nch: 1024
> Controls Window data shape: (511, 1024)
> Data file: None
> /home/marco/Programmi/Python-2.6.3/pyconfig.h
> Traceback (most recent call last):
> File "issue7158.py", line 277, in openDataFile
> head,tail = os.path.split(filename)
> File "/usr/lib/python2.5/posixpath.py", line 77, in split
> i = p.rfind('/') + 1
> AttributeError: 'QString' object has no attribute 'rfind'
>
I'm sorry about the confusion. In the file I attached I had tried using
'os.path.split()', with no luck.
> Why does this happen?
> `filename` is a QString object. (you can see why here:
> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qfiledialog.html#getOpenFileName
> )
>
> So how do you split your filename? I don't know.
>
Python's 'split()' works, like this:
basename = filename.split('/')[-1]
self.datafile.setText(basename)
Also, with less code,
self.datafile.setText(os.path.basename(str(filename)))
> I should close this bug.
>
Yes. Please do. I guess it's useful though to have our e-mail exchange
on record for anyone else who stumbles over the Python string vs QString
distinction.
Thanks and regards
Tom
> ----------
> nosy: +markon
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue7158>
> _______________________________________
> |
|
Date |
User |
Action |
Args |
2009-10-17 14:09:20 | kuiper | set | recipients:
+ kuiper, markon |
2009-10-17 14:09:19 | kuiper | link | issue7158 messages |
2009-10-17 14:09:18 | kuiper | create | |
|