Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

===========. . def mi(P): f=open(P, 'r') first = f.readline() rest= f.readlines() return first, rest f.close import numpy as np afirst,arest = mi('ccc.txt') #3 bfirst,brest =

image text in transcribed

===========.

.

def mi(P): f=open(P, 'r') first = f.readline() rest= f.readlines() return first, rest

f.close

import numpy as np afirst,arest = mi('ccc.txt') #3 bfirst,brest = mi('ddd.txt')

with open('testfile.txt','w') as testfile: testfile.write(brest) testfile.close()

============

.

ddd.txt (remember 10 numbers per line)

=================================================== first line :} 7.9190559956084232425e-08 4.0014656026579413249e-08 7.9587577896814211040e-08 7.8662419833581675357e-08 0.4063733044143882268e-08 9.5732330998844513040e-08 8.6618234806655863631e-08 2.0072870251849178430e-08 6.7864248806722254548e-08 1.2134776106517812316e-08 4.7565190913441753115e-08 5.1557086343029653458e-08 6.3693801211606923532e-08 7.8897108738118126312e-08 9.4510334836961360301e-08 7.4880836459074272283e-08 4.9268327788150989424e-08 1.8466453757372403026e-08 6.2011855819003971679e-08 2.0783930984602632852e-08 5.6105657006093290136e-08 2.5869788723656166592e-08 3.2336150408719792489e-08 1.3711755095387755690e-08 0.8466139114156927980e-08 8.6552265489125695952e-08 1.6410391288046437544e-08 6.4151550079023113112e-08 9.9077814220256712144e-08 4.8228459783414887112e-08 2.5869788723656166592e-08 3.2336150408719792489e-08 1.3711755095387755690e-08 0.8466139114156927980e-08 8.6552265489125695952e-08 1.6410391288046437544e-08 6.4151550079023113112e-08 9.9077814220256712144e-08 4.8228459783414887112e-08 1.6503915571969716123e-08

python, writing to a textfile. things to copy n paste are below im trying to write brest to a textfile Edit View Insert Cell Kernel Widgets Help! ddd-Notepad g File Edit Format View Help irst 1ine 7.9190559956084232425e-08 4.0014656026579413249e-08 7.9587577896814211040e-08 7.8662419833581 4.7565198913441753115e-08 5.1557886343929653458e-08 6.3693801211606923532e-08 7.8897188738118 5.6105657006093290136e-08 2.5869788723656166592e-08 3.2336150488719792489e-88 1.3711755095387 2.5869 788 723656166592e-08 3.2336150488 719792489e-08 1.3711755895387755698e-98 . 8466139114156 MemoryError: In [21]: import numpy as np afirst, arest..n1('ccc.txt.) bfirst,brest mi ('ddd.txt') #3 with open'testfile.txt',w as testfile: testfile.write (brest) testfile.close) Traceback in module>() 4 5 with open('testfile.txt') as testfile: 6 tfile.write(brest) 7 testfile.close) TypeError: write) argument must be str, not list attempt2 In [28]: import numpy as np afirst , arest mi( 'ccc.txt.) bfirst, brest m1(.ddd.txt.) for i in range(len(brest)): ddd Noteped File Edit Format View Help first line 7.9190559956884232425e-08 4.8014656026579413249e-08 7.9587577896 4.7565190913441753115e-08 5.1557086343829653458e-88 6.3693801211 5.6185657006893298136e-08 2.5869788723656166592e-08 3.2336158408 brest[i] [float(x) for x in brest[i].strip().split,')] with open'testfile.txt', 'w) as testfile: testfile.write(brest) testfile.close() --2.5869788723656166592e-08 3.2336150488719792489e-88 1.3711755095 ValueError Traceback (most recent call last) in () 3 bfirst,brest ni('ddd.txt') 4 for i in range(len(brest)): >5 t] [float (x) for x in brest[i].strip).split(, as testfile: 6 with open('testfile.txt 7 testfile.write(brest) in S brest[i] [float(x) for x in brest[1] . strip(), split(',')] = 6 with open('testfile.txt') as testfile 7 testfile.write(brest) ValueError: could not convert string to float: '7.919055995684232425e-08 4.8014656826579413249e-08 7.9587577896814211840e-08 7.8662419833581675357e-88 e.4063733844143882268e-08 9.5732330998844513048e-08 8.6618234886655863631e-88 2.e072870251849178430e- 08 6.7864248886722254548e-88 1.2134776106517812316e-88 how can i make brest successfully print to a file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions