0

hello to all
i need help getting the output of this program
to write into a file


elif choice == "3":
print "all users list :"
print"\n"
import active_directory
for user in active_directory.search ("objectCategory='Person'", "objectClass='User'"):
print user

""

that lists all active directory personal ..
in rows

how can i pipe this into a csv file or even a txt file ??

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by shiva666
0

python is really useful when it comes to saving files. There is a csv module if i am not wrong. But you can do simple text file manipulation with just standard python.

#open file.txt and set to write (w) mode
f = open("file.txt",'w')

#write lines to file, need to state the new line with a new line character
f.write("First line\n")

f.write("Second Line\n")

#close the file. This saves all data to the file and frees it up
f.close()

Just adapt that so instead of printing user you are writing the user to the text file! :)

Hope that helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.