This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kuiper
Recipients kuiper, markon
Date 2009-10-17.14:09:18
SpamBayes Score 5.7024514e-09
Marked as misclassified No
Message-id <4AD9D009.5060401@jpl.nasa.gov>
In-reply-to <1255778090.32.0.308260191777.issue7158@psf.upfronthosting.co.za>
Content
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>
> _______________________________________
>
History
Date User Action Args
2009-10-17 14:09:20kuipersetrecipients: + kuiper, markon
2009-10-17 14:09:19kuiperlinkissue7158 messages
2009-10-17 14:09:18kuipercreate