How can I add a new line after each object in my generator or list? I tried .join('\n') and that didn't work. Trying to split a newline won't work because that's not an attribute of the generator or list datatype.
My try with a generator = false to use a list using join:
a = conn.extend.standard.paged_search('cn = All.DL Div Controllers - National Group, ou = Distribution Lists, ou = Exchange, dc=google,dc=corpad,dc=net', '(objectClass=*)', attributes=['member'], generator=False)
b = map(str, a) #Stringify each a from generator
b_str = '\n'.join(b) #Join the list of b with a newline
with open ('test.txt', 'w') as file:
file.write(b_str) #Write to file
My output looks like this aaaa, aaaaa, aaaaaa,aaa,aaaaa,aaaaa
I want my output to look like this:
aaaa,
aaaaa,
aaaaaa,
aaa,
aaaaa,
aaaaa,
Here is my attempt using .split(), but it obviously wont' work as .split() is not an attribute of a generator or list datatype.
#a= conn.extend.standard.paged_search('cn = All.DL Div Controllers - National Group, ou = Distribution Lists, ou = Exchange, dc=google,dc=corpad,dc=net', '(objectClass=*)', attributes=['member'])
#for b in a.split('\n'):
# with open ('test.txt', 'w') as file:
# file.write (str(a))
The above is just an example the true output in the console including each print statement is the following:
Code:
national = conn.extend.standard.paged_search('cn = All.DL Div Controllers - National Group, ou = Distribution Lists, ou = Exchange, dc=google,dc=corpad,dc=net', '(objectClass=*)', attributes=['member'], generator=False)
print(national)
Output:
[{'raw_dn': b'CN=All.DL Div Controllers - National Group,OU=Distribution Lists,OU=Exchange,DC=google,DC=corpad,DC=net',
'dn': 'CN=All.DL Div Controllers - National Group,OU=Distribution Lists,OU=Exchange,DC=google,DC=corpad,DC=net',
'raw_attributes': {'member': [b'CN=gji9847,OU=U02562,OU=02562,DC=google,DC=corpad,DC=net',
b'CN=exx8092,OU=U06032,OU=06032,DC=google,DC=corpad,DC=net',
b'CN=EWR8386,OU=U09373,OU=09373,DC=google,DC=corpad,DC=net',
b'CN=HXU9279,OU=U00704,OU=00704,DC=google,DC=corpad,DC=net',
b'CN=KVG6693,OU=U25692,OU=25692,DC=google,DC=corpad,DC=net',
b'CN=JCL6495,OU=U01246,OU=01246,DC=google,DC=corpad,DC=net',
b'CN=RNE9520,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
b'CN=PCN5400,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
b'CN=WPM9271,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
b'CN=JKJ2421,OU=U01692,OU=01692,DC=google,DC=corpad,DC=net']},
'attributes': {'member': ['CN=gji9847,OU=U02562,OU=02562,DC=google,DC=corpad,DC=net',
'CN=exx8092,OU=U06032,OU=06032,DC=google,DC=corpad,DC=net',
'CN=EWR8386,OU=U09373,OU=09373,DC=google,DC=corpad,DC=net',
'CN=HXU9279,OU=U00704,OU=00704,DC=google,DC=corpad,DC=net',
'CN=KVG6693,OU=U25692,OU=25692,DC=google,DC=corpad,DC=net',
'CN=JCL6495,OU=U01246,OU=01246,DC=google,DC=corpad,DC=net',
'CN=RNE9520,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
'CN=PCN5400,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
'CN=WPM9271,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
'CN=JKJ2421,OU=U01692,OU=01692,DC=google,DC=corpad,DC=net']},
'type': 'searchResEntry'}]
Code:
print (len(list(national)))
Output:
1
Code:
controllers = map(str, national) #Stringify each controller from generator
print(controllers)
Output:
<map object at 0x000001BF3AF35080>
Code:
controllers_str = '\n'.join(controllers) #Join the list of controllers with a newline
print(controllers_str)
Output:
{'raw_dn': b'CN=All.DL Div Controllers - National Group,OU=Distribution Lists,OU=Exchange,DC=google,DC=corpad,DC=net',
'dn': 'CN=All.DL Div Controllers - National Group,OU=Distribution Lists,OU=Exchange,DC=google,DC=corpad,DC=net',
'raw_attributes': {'member': [b'CN=gji9847,OU=U02562,OU=02562,DC=google,DC=corpad,DC=net',
b'CN=exx8092,OU=U06032,OU=06032,DC=google,DC=corpad,DC=net',
b'CN=EWR8386,OU=U09373,OU=09373,DC=google,DC=corpad,DC=net',
b'CN=HXU9279,OU=U00704,OU=00704,DC=google,DC=corpad,DC=net',
b'CN=KVG6693,OU=U25692,OU=25692,DC=google,DC=corpad,DC=net',
b'CN=JCL6495,OU=U01246,OU=01246,DC=google,DC=corpad,DC=net',
b'CN=RNE9520,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
b'CN=PCN5400,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
b'CN=WPM9271,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
b'CN=JKJ2421,OU=U01692,OU=01692,DC=google,DC=corpad,DC=net']},
'attributes': {'member': ['CN=gji9847,OU=U02562,OU=02562,DC=google,DC=corpad,DC=net',
'CN=exx8092,OU=U06032,OU=06032,DC=google,DC=corpad,DC=net',
'CN=EWR8386,OU=U09373,OU=09373,DC=google,DC=corpad,DC=net',
'CN=HXU9279,OU=U00704,OU=00704,DC=google,DC=corpad,DC=net',
'CN=KVG6693,OU=U25692,OU=25692,DC=google,DC=corpad,DC=net',
'CN=JCL6495,OU=U01246,OU=01246,DC=google,DC=corpad,DC=net',
'CN=RNE9520,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
'CN=PCN5400,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
'CN=WPM9271,OU=U01673,OU=01673,DC=google,DC=corpad,DC=net',
'CN=JKJ2421,OU=U01692,OU=01692,DC=google,DC=corpad,DC=net']},
'type': 'searchResEntry'}
controllers_str, notb_str. Is this intended?len(list(b)) > 1?'aaaa, aaaaa, aaaaaa,aaa,aaaaa,aaaaa'?