我试图编写一个小脚本来同步(镜像)2个目录应用程序,我有这样一个配置
app 1 app 2
Network_Devices Network Devices
Monitoring_Servers Monitoring Servers
Juice_-_Tomato Juice - Tomato
Hello_World Hello World
File_Server File Server首先,我得到工具1的目录配置"Linux“。
path = '*/some_place/app1'
for directory1 in os.listdir(path): #<type 'str'>在通过REST请求从tool 2获得设置之后
#
... urllib2 library
#
app2conf = json.loads(urllib2.urlopen(request).read() #<type 'dict'>现在我已经准备好执行syn了,如果工具1中的目录存在于工具2中,则打印" exist“否则打印”要创建吗?“我的剧本是这样的:
def sync(directory1, app2conf):
for dirin2 in app2conf: #<type 'unicode'>
if directory1 == str(dirin2.replace(" ", "_")):
print 'Directory already exist'
return str(dirin2) #unicode to string
else:
print 'Do you want to create?'
#
some code to create directories
#
for directory1 in os.listdir(path):
getsync = sync(directory1,app2conf)
print getsync
#
More code
#问题是,返回使我在“打印getsync”中没有获得任何valúes。
Network Devices
Monitoring Servers
None #<type 'NoneType'>
Juice - Tomato
Hello World
File Server对于测量,我在if之后打印al2值
def sync(directory1, app2conf):
for dirin2 in app2conf: #<type 'unicode'>
if directory1 == str(dirin2.replace(" ", "_")):
print directory1
print dirin2我就像这样
Network_Devices
Network Devices
Monitoring_Servers
Monitoring Servers
Juice_-_Tomato
Juice - Tomato
Hello_World
Hello World
File_Server
File Server脚本正在工作,但我不知道为什么返回给我这些值。
谢谢你抽出时间。
发布于 2015-09-08 20:10:30
您需要返回在else子句中创建的项的字符串。否则,同步函数将只返回None ( python函数的缺省值),并且您将不被分配给getsync。
https://stackoverflow.com/questions/32466094
复制相似问题