[Tutor] Module webbrowser.os

Steven D'Aprano steve at pearwood.info
Wed Nov 2 21:31:30 EDT 2016


On Wed, Nov 02, 2016 at 09:16:56AM +0000, Alan Gauld via Tutor wrote:
> On 02/11/16 06:44, Palanikumar Gopalakrishnan wrote:

> > webbrowser.os(umask)
> > 
> > But It retruns the following error
> > 
> > *Traceback (most recent call last):  File "<stdin>", line 1, in
> > <module>NameError: name 'umask' is not defined*
> 
> I'm not sure why because it works for me in both Python 2.7 and 3.4.

It may work for you if you ran "from os import *" first. Otherwise, in a 
fresh Python environment, there's no name "umask":

py> uname
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'uname' is not defined

And so webbrowser.os(umask) fails because umask is not defined. If you 
define it, you get a second error:

py> uname = 17
py> webbrowser.os(uname)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable


I think that what Palanikumar intended was:

webbrowser.os.uname


> Which OS are you using? And which Python version?
> 
> But note that umask is a function so
> 
> webbrowser.os(umask)
> 
> returns a function reference. To get the umask value you must
> supply one:
> 
> webbrowser.os(umask(0x777))

I think you've missed the round brackets () and imagined a dot . :-)




-- 
Steve


More information about the Tutor mailing list