Writeing new files

Ignacio Vazquez-Abrams ignacio at openservices.net
Fri Aug 31 21:19:10 EDT 2001


On 31 Aug 2001, eber kain wrote:

> you lost me, whats dir() do, and how do i use it.

dir() returns the attributes (usually methods) attached to an object. For
example (under Python 2.1.1):

---
>>> dir()
['__builtins__', '__doc__', '__name__']
>>> dir('')
['capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find',
'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle',
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex',
'rjust', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
'title', 'translate', 'upper']
>>> dir([])
['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
'sort']
>>> import os
>>> dir(os)
['F_OK', 'NGROUPS_MAX', 'O_APPEND', 'O_CREAT', 'O_DSYNC', 'O_EXCL',
'O_NDELAY', 'O_NOCTTY', 'O_NONBLOCK', 'O_RDONLY', 'O_RDWR', 'O_RSYNC',
'O_SYNC', 'O_TRUNC', 'O_WRONLY', 'P_NOWAIT', 'P_NOWAITO', 'P_WAIT', 'R_OK',
'TMP_MAX', 'UserDict', 'WEXITSTATUS', 'WIFEXITED', 'WIFSIGNALED',
'WIFSTOPPED', 'WNOHANG', 'WSTOPSIG', 'WTERMSIG', 'W_OK', 'X_OK', '_Environ',
'__all__', '__builtins__', '__doc__', '__file__', '__name__', '_execvpe',
'_exists', '_exit', '_get_exports_list', '_notfound', '_spawnvef', 'abort',
'access', 'altsep', 'chdir', 'chmod', 'chown', 'close', 'confstr',
'confstr_names', 'ctermid', 'curdir', 'defpath', 'dup', 'dup2', 'environ',
'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv', 'execve', 'execvp',
'execvpe', 'fdatasync', 'fdopen', 'fork', 'forkpty', 'fpathconf', 'fstat',
'fstatvfs', 'fsync', 'ftruncate', 'getcwd', 'getegid', 'getenv', 'geteuid',
'getgid', 'getgroups', 'getlogin', 'getpgrp', 'getpid', 'getppid', 'getuid',
'isatty', 'kill', 'linesep', 'link', 'listdir', 'lseek', 'lstat', 'makedirs',
'mkdir', 'mkfifo', 'name', 'nice', 'open', 'openpty', 'pardir', 'path',
'pathconf', 'pathconf_names', 'pathsep', 'pipe', 'popen', 'popen2', 'popen3',
'popen4', 'putenv', 'read', 'readlink', 'remove', 'removedirs', 'rename',
'renames', 'rmdir', 'sep', 'setegid', 'seteuid', 'setgid', 'setpgid',
'setpgrp', 'setregid', 'setreuid', 'setsid', 'setuid', 'spawnl', 'spawnle',
'spawnlp', 'spawnlpe', 'spawnv', 'spawnve', 'spawnvp', 'spawnvpe', 'stat',
'statvfs', 'strerror', 'symlink', 'sys', 'sysconf', 'sysconf_names', 'system',
'tcgetpgrp', 'tcsetpgrp', 'tempnam', 'times', 'tmpfile', 'tmpnam', 'ttyname',
'umask', 'uname', 'unlink', 'utime', 'wait', 'waitpid', 'write']
>>>
---

So using it allows you to see what the object supports via <obj>.<method>.

It may be that the object returned by Draw.Create() may provide its name in an
attribute or from a method.

> I should have said earlier, im a C++ person, only started looking into
> Python a few weeks ago.
>
> If i had a choice of something else i wouldnt use python, but its the
> only medium to get the models out of blender.

Heh. I've been programming in Python for two years and I couldn't get Blender
running under either Linux or ME, so I don't think you're doing that badly ;)

> I really have a hard time understanding how the classes in python
> function, and the for statement gives me problems. To be honest i dont
> care for the launguage, if I had looked at it before i started C it
> probably wouldnt look so odd, not even sure if it was around when i
> started in programming.

Just give Python some time, and get the real deal from http://www.python.org/;
you might find that you start to like it.

The for statement takes a sequence of objects (list, tuple, or string) or an
object generator (e.g., xrange(), inputfile.readlines()) and replaces the
variable with the objects one at a time:

---
>>> for a in [1, 2, 3]:
...   print a
...
1
2
3
>>>
---

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>






More information about the Python-list mailing list