Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: What behavior would you expect? Date: Thu, 19 Feb 2015 22:18:10 -0800 Organization: A noiseless patient Spider Lines: 16 Message-ID: <87r3tlds2l.fsf@jester.gateway.pace.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="c694756f1077760bb5296aae16c74092"; logging-data="1733"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9hfNFpIEthCNBXUvRNOhh" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:+LR/bRvtnQLQ9csEqM/3Wq4RVmM= sha1:BEnw6ZmftlHRH1zIA/Fu4cURwtA= Xref: csiph.com comp.lang.python:85953 Dan Sommers writes: > I'd still prefer an exception to None, and we agree on that an empty > string is bad because it's not a non-string and it could be too easily > mistaken for a filename. Empty string would be bad. Sometimes I like to simulate an option type, by returning the value as a 1-element list if there's a value, otherwise as an empty list. So you could say filename = get_filename(...)[0] if you want an exception in the failure case, or you could do something like fs = get_filename(...) if len(fs) == 0: ... # didn't get a filename