[Tutor] os.symlink can't find target

Bob Williams linux at barrowhillfarm.org.uk
Mon Feb 24 18:09:57 CET 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 24/02/14 16:56, Mark Lawrence wrote:
> On 24/02/2014 16:36, Peter Otten wrote:
>> Bob Williams wrote:
>> 
[...]
>>> Thanks,
>> 
>> os.symlink(existing_file, symlink_to_create)
>> 
>> fails with that error if the directory that shall contain the new
>> symlink does not exist. You can create it before making the
>> symlink with
>> 
>> try: os.makedirs(os.path.dirname(symlink_to_create)) except
>> OSError as err: # Assume the directory exists. # A thorough coder
>> would check the errno here pass
>> 
> 
> Python 3.3+ allows finer grained error handling than that shown
> above, so you could catch FileExistsError, see 
> http://legacy.python.org/dev/peps/pep-3151/ for the details.
> 
I'm using a module (mutagen) elsewhere in this script, which only
works in Python 2 (so far). Also, I'm fairly new to this, so getting
things working takes precedence over 'good practice' like error
trapping. But I'm also aware that it's best to establish good habits
early on.

Bob
- -- 
Bob Williams
System:  Linux 3.11.10-7-desktop
Distro:  openSUSE 13.1 (x86_64) with KDE Development Platform: 4.12.2
Uptime:  12:00pm up 11 days 20:00, 5 users, load average: 0.14, 0.17, 0.22
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlMLfOMACgkQ0Sr7eZJrmU4IgQCgn5MeqNsCOgiS3QY8g2jjMooR
65oAnjcWZaHrfe78C2WvHjMNlqZqjgo1
=CnnC
-----END PGP SIGNATURE-----


More information about the Tutor mailing list