-1

I'm writing a script I can use at work for bulk lotus note user registration.

Basically I need to manipulate a text file that contains a list of usernames into a file i can import into domino administrator.

For example I have a text file that contains,

Gordan.Freeman
Gordan.Freeman1
Gordan.Freeman2

And I need to get it looking like

Freeman;Gordan;;;12345678;D:\lotus\NotesIDs\Users\;GordanFreeman.id;SERVER01;mail\users\;GordanFreeman.nsf;;;;;;;;;;template.ntf;
Freeman1;Gordan;;;12345678;D:\lotus\NotesIDs\Users\;GordanFreeman1.id;SERVER01;mail\users\;GordanFreeman1.nsf;;;;;;;;;;template.ntf;
Freeman2;Gordan;;;12345678;D:\lotus\NotesIDs\Users\;GordanFreeman2.id;SERVER01;mail\users\;GordanFreeman2.nsf;;;;;;;;;;template.ntf;

I've only gotten as far as reading from the text file into a list, but from what i can tell I need to convert it back into a string before i can write to a new text file.

    textloc = input(r"  Enter the file path of your list (eg.'C:\names_list.txt) --> ")
    textopen = open(textloc, 'r')
    nameslistraw = textopen.read().split('\n')
    nameslist = [i.split('.') for i in nameslistraw]

I've been fiddling around with this for hours. Any help would be great :)

Jose Luis
  • 3,307
  • 3
  • 36
  • 53
Aidan
  • 3
  • 2
  • Welcome to Stack Overflow! It's always important to tell people [what you have tried](http://whathaveyoutried.com/), including snippets of any failed attempts so that they can understand what avenues you have missed. It's important because it motivates people to answer and it's important because it makes it *easier* to give high quality, relevant answers. With the current state of the question, this hasn't been achieved. If you edit the question, it's possible that the question can be prevented from being closed and the quantity, quality and clarity of answers you get will improve as well. – Veedrac Sep 21 '14 at 04:57
  • @Aidan, with all due respect, don't you confuse `any help` and `do it for me please` ? Show your code and tell, what parts do not work as expected. –  Sep 21 '14 at 05:01
  • Added a few lines I've got so far. Really just need a push in the right direction. – Aidan Sep 21 '14 at 05:04

1 Answers1

0

Here is a working script that does what you appear to want.

file = open('myfile.txt', 'r')
temp = []
for line in file:
    item = line.strip('\n').split('.')
    temp.append(';'.join(item[::-1])+';'*3+'12345678;D:\lotus\NotesIDs\Users\;'+''.join(item)+'.id;SERVER01;mail\users\;'+''.join(item)+'.nsf;;;;;;;;;;template.ntf;')

file.close()

file = open('myfile.txt', 'w')

file.write('\n'.join(temp))

file.close()

Which transforms the following:

Gordan.Freeman
Gordan.Freeman1
Gordan.Freeman2

Into:

Freeman;Gordan;;;12345678;D:\lotus\NotesIDs\Users\;GordanFreeman.id;SERVER01;mail\users\;GordanFreeman.nsf;;;;;;;;;;template.ntf;
Freeman1;Gordan;;;12345678;D:\lotus\NotesIDs\Users\;GordanFreeman1.id;SERVER01;mail\users\;GordanFreeman1.nsf;;;;;;;;;;template.ntf;
Freeman2;Gordan;;;12345678;D:\lotus\NotesIDs\Users\;GordanFreeman2.id;SERVER01;mail\users\;GordanFreeman2.nsf;;;;;;;;;;template.ntf;
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76
  • This is exactly what I was after. Did come across some interesting errors though. I kept getting a unicode error "malformed \N character escape". I prefixed all the strings with a r and it now works a treat. Thanks – Aidan Sep 21 '14 at 06:34
  • 1
    I suggest you to use the `with` statement instead open and close. It is generally preferred and more pythonic. – alec_djinn Jul 03 '15 at 08:40