The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Thu, 8 Nov 2012 23:57:00 +1100
Subject: Re: isinstance(.., file) for Python 3
On Thu, Nov 8, 2012 at 11:05 PM, Ulrich Eckhardt
<ulrich.eckha...@dominolaser.com> wrote:
Can you use the inverted check "isinstance(p, str)"? It's more likely
> Firstly, I have code that allows either a file or a string representing its > content as parameter. If the parameter is a file, the content is read from > the file. In Python 2, I used "isinstance(p, file)" to determine whether the > parameter p is a file... that you'll want to pass a file-like object than a string-like object. This would work on Python 2 as well, though it's semantically different; to safely check for both Unicode and bytes strings on both Py2 and Py3, this may work: # Once-off:
# Is p a string?
It abuses the fact that isinstance will happily accept the
ChrisA
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||