471,338 Members | 1,001 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Moving a file

14
Hi there,
I'm trying to figure out how to move a file from one directory to another (all C drive). I've read that shutil is the module to go with. Ok, I think "move" command is what I'm looking for. When I'm trying to run simple tests in command line python that looks like this:
Expand|Select|Wrap|Line Numbers
  1. import shutil
  2. move('C:\\....', 'C:\\....')
  3.  
i get an error "NameError: name 'move' is not defined"
I've looked inside shutil.py module and there is a module "move". My guess is that I probably need to use the form like:
Expand|Select|Wrap|Line Numbers
  1.  something.move('C:\\....', 'C:\\....')
is that correct? or what's the right way to use "move" ?

Thank you
Sep 12 '07 #1
5 6496
bvdet
2,851 Expert Mod 2GB
Hi there,
I'm trying to figure out how to move a file from one directory to another (all C drive). I've read that shutil is the module to go with. Ok, I think "move" command is what I'm looking for. When I'm trying to run simple tests in command line python that looks like this:
Expand|Select|Wrap|Line Numbers
  1. import shutil
  2. move('C:\\....', 'C:\\....')
  3.  
i get an error "NameError: name 'move' is not defined"
I've looked inside shutil.py module and there is a module "move". My guess is that I probably need to use the form like:
Expand|Select|Wrap|Line Numbers
  1.  something.move('C:\\....', 'C:\\....')
is that correct? or what's the right way to use "move" ?

Thank you
The correct usage would be:
Expand|Select|Wrap|Line Numbers
  1. import shutil
  2. shutil.move(src, dst)
where src is the source file or directory name and dst is the destination.
Sep 12 '07 #2
Memozio
14
The correct usage would be:
Expand|Select|Wrap|Line Numbers
  1. import shutil
  2. shutil.move(src, dst)
where src is the source file or directory name and dst is the destination.
Here we go!
Thank you, bvdet
Just a follow up question: So, whenever we don't have any object for "smth" in smth.method(arg, arg) then we need to use module name for left hand side?
Sep 12 '07 #3
bvdet
2,851 Expert Mod 2GB
Here we go!
Thank you, bvdet
Just a follow up question: So, whenever we don't have any object for "smth" in smth.method(arg, arg) then we need to use module name for left hand side?
You can also do this:
Expand|Select|Wrap|Line Numbers
  1. from shutil import move
  2. move(src, dst)
I would tend to term move() a user-defined function which is a callable object created at the module level. Where are you getting 'smth'?
Sep 12 '07 #4
bartonc
6,596 Expert 4TB
Here we go!
Thank you, bvdet
Just a follow up question: So, whenever we don't have any object for "smth" in smth.method(arg, arg) then we need to use module name for left hand side?
"something.method()" syntax is used once you have created an instance of some class object. Modules may export function and/or classes and in may be a little confusing at first because object creation and function call syntax look the same. For example:
Expand|Select|Wrap|Line Numbers
  1. import time
  2. timeAsFloat = time.time()  #calls a function in the time module
  3.  
  4. import datetime
  5. aDateObj = datetime.date(0,0,0) # create a date object
The key is to understand the interface to the module and name your variable in order to remind yourself whether it is a simple variable type or an instance of a class. I often use the ....Obj for the latter case.
Sep 12 '07 #5
Memozio
14
"something.method()" syntax is used once you have created an instance of some class object. Modules may export function and/or classes and in may be a little confusing at first because object creation and function call syntax look the same. For example:
Expand|Select|Wrap|Line Numbers
  1. import time
  2. timeAsFloat = time.time()  #calls a function in the time module
  3.  
  4. import datetime
  5. aDateObj = datetime.date(0,0,0) # create a date object
The key is to understand the interface to the module and name your variable in order to remind yourself whether it is a simple variable type or an instance of a class. I often use the ....Obj for the latter case.
got ya,
thx, bartonc!
Sep 13 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Hemant Shah | last post: by
1 post views Thread by Arif | last post: by
2 posts views Thread by fuzzybr80 | last post: by
7 posts views Thread by =?Utf-8?B?TW9iaWxlTWFu?= | last post: by
4 posts views Thread by =?Utf-8?B?R1Q=?= | last post: by
reply views Thread by linkswanted | last post: by
reply views Thread by linkswanted | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.