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 ??

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

thank you !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.