LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-11-2006, 02:42 AM   #1
BongHongXanh
LQ Newbie
 
Registered: Jan 2005
Posts: 14

Rep: Reputation: 0
Copy file by script python !


#/root/anh.txt -> contain packages name Rpm
#/RedHat/RPMS -> all packages Rpm
# i want to copy from some file "/RedHat/RPMS" to "/mnt/RPMS" in list "anh.txt"
# Os: Fedora2
# copyfile.py

import sys
import shutil
f=open('/root/anh.txt', 'r')
f.readline();
for line in f:
print line
shutil.copyfile('/RedHat/RPMS/$line','/mnt/RPMS')

Error:

setup-2.5.33-1

Traceback (most recent call last):
File "readline2.py", line 7, in ?
shutil.copyfile('/RedHat/RPMS/$line','/mnt/RPMS')
File "/usr/lib/python2.3/shutil.py", line 37, in copyfile
fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: '/RedHat/RPMS/$line'
 
Old 01-11-2006, 03:30 AM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 48
I don't think in Python you can do direct interpolation like '/RedHat/RPMS/$line'

instead, try
Code:
'/RedHat/RPMS/%s' % $line

Last edited by spooon; 01-11-2006 at 03:34 AM.
 
Old 01-11-2006, 08:26 PM   #3
BongHongXanh
LQ Newbie
 
Registered: Jan 2005
Posts: 14

Original Poster
Rep: Reputation: 0
Red face

Quote:
Originally Posted by spooon
instead, try
Code:
'/RedHat/RPMS/%s' % line
Thank You


##
import sys
import shutil
f=open('/root/anh.txt', 'r')

f.readline();
for line in f:
print line
shutil.copyfile('/RedHat/RPMS/%s'%line,'/mnt/RPMS')

#################
But error other :

setup-2.5.33-1

Traceback (most recent call last):
File "readline2.py", line 8, in ?
shutil.copyfile('/RedHat/RPMS/%s'%line,'/mnt/RPMS')
File "/usr/lib/python2.3/shutil.py", line 37, in copyfile
fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: '/RedHat/RPMS/setup-2.5.33-1\n'-> i want remove "\n" but i can'nt !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'./file' meaning in python & shell script Chowroc Programming 7 12-30-2005 02:32 AM
Shell script to copy file name with part of directory Transition Linux - General 5 01-18-2005 05:40 PM
shell script to copy lines from a file Warmduvet Programming 2 09-14-2004 09:25 PM
Run script during file copy or create in directory neranjana Linux - General 1 01-13-2004 06:57 AM
copy 1 file to multiple dir script carpman Linux - General 14 02-07-2002 09:29 AM


All times are GMT -5. The time now is 01:31 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration