0

So I've written a filename to variable

output = '/tmp/file'
output = os.path.abspath(output)

Then I moved the file

shutil.move(output, '/tmp/modified/')

How should I properly update the variable output modified by shutil.move?

0

1 Answer 1

1

shutil.move returns the destination:

output = shutil.move(output, '/tmp/modified/')

Edit on python2 shutil.move doesn't return. so if you have the destination you can just set output equal to it:

shutil.move(output, destination)
output = destination

If you need the absolute path you can use os.path.abspath(destination)

Sign up to request clarification or add additional context in comments.

2 Comments

>>> output = os.path.abspath('/tmp/test2') >>> output = shutil.move(output, '/tmp/modified/') >>> print output None File in fact moves, but variable becomes None
in python3 shutil moves. I guess in python 2 this isn't the case. See edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.