I am trying to convert copy / paste text to csv, after which I can split it. The problem is that it has white space tabs that, in my opinion, cannot get rid of
Copy / Paste Example:
Amarr Hybrid Tech Decryptor 12 Decryptors - Hybrid 12 m3 Ancient Coordinates Database 23 Sleeper Components 2.30 m3 Caldari Hybrid Tech Decryptor 17 Decryptors - Hybrid 17 m3 Carbon 17 General 34 m3 Cartesian Temporal Coordinator 4 Ancient Salvage 0.04 m3 Central System Controller 2 Ancient Salvage 0.02 m3
Now I am trying to get something like this:
Amarr Hybrid Tech Decryptor,12,Decryptors - Hybrid,12,m3, Ancient Coordinates Database,23,Sleeper Components,2.30,m3, Caldari Hybrid Tech Decryptor,17,Decryptors - Hybrid,17,m3, Carbon,17,General,34,m3, Cartesian Temporal Coordinator,4,Ancient Salvage,0.04,m3, Central System Controller,2,Ancient Salvage,0.02,m3,
(there will always be these 5 sections per line
I try to do it differently Separate comma and whitespace in Python but I can't get it to work.
@login_required def index(request): if request.method == "POST": form = SellListForm(request.POST) if form.is_valid(): selllist = form.save(commit=False) selllist.user = request.user string = selllist.sell string = [x.strip() for x in string.split(',')] print string return HttpResponseRedirect(reverse('processed')) else: form = SellListForm() return render(request, 'index.html', {'form': form})
returns
[u'<<<SULTS STUFF>>>\t\t\tVoucher\t\t\t0 m3\r\nAmarr Hybrid Tech Decryptor\t12\tDecryptors - Hybrid\t\t\t12 m3\r\nAncient Coordinates Database\t23\tSleeper Components\t\t\t2.30 m3\r\nCaldari Hybrid Tech Decryptor\t17\tDecryptors - Hybrid\t\t\t17 m3\r\nCarbon\t17\tGeneral\t\t\t34 m3\r\nCartesian Temporal Coordinator\t4\tAncient Salvage\t\t\t0.04 m3\r\nCentral System Controller\t2\tAncient Salvage\t\t\t0.02 m3']