I'm not great on all the technical terms so I'll do my best to explain my problem.
I've written a small script to open android SDK and check for attached devices (using windows 10 and python 2.7.14). The code I've got is as follows:
import os
import datetime
import time
print 'Current Directory:', os.getcwd()
print 'Opening Android SDK...'
os.chdir('C:\android-sdk\platform-tools')
print 'Current Directory:', os.getcwd()
t = time.ctime()
print t
print 'Checking for connected devices:'
os.system('adb devices -l')
That all works fine, but I want to get the last 3 lines to save to a text file. I've tried f = open('logfile.txt', 'w')
then converting it all to a string using s = str(t, 'Checking for connected devices:', os.system('adb devices -l'))
and writing it to the file and closing it, but it's not working. It's not even creating the file, let alone writing anything to it.
I'm probably missing something key but I'm a newbie at this so please be nice!
Any help would be much appreciated.
Many thanks
Edit: whole code with the write stuff included:
import os
import datetime
import time
print 'Current Directory:', os.getcwd()
print 'Opening Android SDK...'
os.chdir('C:\android-sdk\platform-tools')
print 'Current Directory:', os.getcwd()
t = time.ctime()
f = open('logfile.txt', 'w')
s = str(t, 'Checking for connected devices:', os.system('adb devices -l'))
f.write(s)
f.close()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…