__peter__ at web.de
Thu Aug 19 16:55:47 CEST 2004
JASON JESSO wrote:
> 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, sys.argv )
> 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)) the permissions are all screwed
oct() converts an integer to the octal _string_ representation - that's why
python sees a string where an integer is required. Internally there is no
such thing as a decimal or an octal integer. Therefore you just have to
convert the octal string representation given on the command line to an
integer. This is done like so:
Here the second parameter is the base (the default being, of course, 10).
More information about the Python-list