newbie

Paul Watson pwatson at redlinepy.com
Thu Aug 19 17:14:55 CEST 2004


"JASON JESSO" <jesso1607 at rogers.com> wrote in message
news:mailman.1958.1092926275.5135.python-list at python.org...
> I'm trying to add a mode to a mkdir program a got off
> the python cookbook.
>
> The error I get is:
> ./mkdir.py jason 0777
> Traceback (most recent call last):
>   File "./mkdir.py", line 31, in ?
>     _mkdir( sys.argv[1], sys.argv[2] )
>   File "./mkdir.py", line 25, in _mkdir
>     os.mkdir( newdir, mode )
> TypeError: an integer is required
>
> When I convert the mode from a string to an octal with
> oct(int(sys.argv[2])) the permissions are all screwed
> up.

Specifying the base on int() suggested by Peter is probably the
best way.  Here is another.

$ python
Python 2.1 (#1, May 23 2003, 11:43:56) [C] on aix4
Type "copyright", "credits" or "license" for more information.
>>> import string
>>> s = '0777'
>>> v = string.atoi(s, 8)
>>> v
511
>>> oct(v)
'0777'





More information about the Python-list mailing list