2017-08-13 110 views
-4

我有一个机器人,它的设置方式是从网站的前端获取命令,然后在机器人上运行命令。例如Python - 互换两个文件目录

if command == 'CF': 
    os.system('aplay /home/pi/sound/wavycf.wav') 

我需要财产以后,将交换两个文件/images/hud.pngimages/special/hud.png到每个人的目录....我希望是有道理的

+0

_我希望这是有道理的不是。再试一次。此外,向我们展示您迄今为止所尝试的内容并发布您的代码。 SO不是一种编码服务。 – DyZ

+0

[如何使用Python重命名文件]的可能重复(https://stackoverflow.com/questions/2491222/how-to-rename-a-file-using-python);交换两个文件与两个(或三个)重命名操作没有区别。 – ppperry

回答

0

只是把一个进入时间位置,移动和其它移动比第一从温度到最终位置

os.system("move /images/hud.png /images/special/hud.png.tmp") 
os.system("move /images/special/hud.png /images/hud.png") 
os.system("move /images/special/hud.png.tmp /images/special/hud.png") 

或做对一切使用python:

# load file 1 into buffer 
data = "" 
with open("/images/hud.png", "rb") as f: 
    data = f.read() 
# copy file 2 into file 1 
with open("/images/special/hud.png", "rb") as f1: 
    with open("images/hud.png", "wb") as f2: 
     f2.write(f1.read()) 
# save file 1 from buffer 
with open("/images/special/hud.png", "wb") as f: 
    f.write(data) 
# clear memory 
del data