472,988 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 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 6614
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

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

Similar topics

6
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? ...
1
by: Arif | last post by:
Following are my text file(IndxItms.txt) contents: --------------------------------------------------- 0000 0 0002 52 0020 260 0045 312 0051 364 0087 416
5
by: Franck | last post by:
Hello, I've just moved to visual developper 2005 to do so, I also had to use the convert assistant. what it did; moving my file resx files that i had in a diresctory called resx to a new...
11
by: ulyses | last post by:
Let's assume I have following file: 2938929384902491233..... 923949919199191919112.... File contains INTs only. What is more they are huge. For example first row in file may contain integer...
2
by: fuzzybr80 | last post by:
I am using MySQL 5.0 with a number of innodb tables whose ibdata files are growing quite quickly and filling up the /var partition (file is /var/mysql/ibdata1). Earlier on I followed instructions...
7
by: =?Utf-8?B?TW9iaWxlTWFu?= | last post by:
Hello everyone: I am looking for everyone's thoughts on moving large amounts (actually, not very large, but large enough that I'm throwing exceptions using the default configurations). We're...
2
by: Paul | last post by:
I am moving an existing app written years ago to a new server. It uses Sigma Template 1.3 and Quickform 1.1.1 and PEAR.php,v 1.1.1.1 2004/02/16 The directory structure is like this: /site...
4
by: =?Utf-8?B?R1Q=?= | last post by:
I have a Form which has a great number of events. I thought I would organize the project by moving some of the code into multiple '.cs' files (since the Form.cs was getting huge). When I move them,...
0
by: linkswanted | last post by:
We are your trusted source. World Moving & Storage is bonded and licensed by the U.S. Department of Transportation and is one of the largest residential moving and corporate relocation company in...
0
by: linkswanted | last post by:
We are your trusted source. World Moving & Storage is bonded and licensed by the U.S. Department of Transportation and is one of the largest residential moving and corporate relocation company in...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.