Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A couple things you might find interesting:</p> <ul> <li><p>The built in <a href="http://docs.python.org/2/library/os.html" rel="nofollow noreferrer"><code>os</code> module</a> has some nice functions for doing filesystem stuff:</p> <ul> <li><p>Using the <code>os.path</code> module you don't have to worry about platform-dependant syntax or backslashes when dealing with paths.</p></li> <li><p>You can use <code>os.remove</code> to delete a file.</p></li> </ul></li> <li><p>Because you're using Excel, I'm guessing you're on Windows: consider using 'wb' instead of 'w' when writing to a file because <a href="https://stackoverflow.com/questions/2665866/what-is-the-wb-mean-in-this-code-using-python">Windows deals with EOL characters differently than Unix.</a></p></li> <li><p><code>"0.Df"%number</code> can be used to format the floating point 'number with D decimal places.</p></li> </ul> <p>Your code with these changes added in:</p> <pre><code>import os import time import pythoncom from win32com.client import Dispatch #create file myDir = input('Where do you want to write the file?') myPath = os.path.join(myDir, 'pydatafile') size_MB = int(input('What sized file do you want to test with? (MB): ')) size_B = size_MB * 1024 * 1024 # create string to write to_write = "\x00" * size_B #start timer start = time.clock() f = open(myPath, 'wb') f.write(to_write) f.close() #how much time it took elapsed = time.clock() - start print "It took %0.3f"%elapsed, "seconds to write the", size_MB, "MB file at a rate of %0.3f"%(size_MB/elapsed), "Mbps." #record results on Excel xl = Dispatch('Excel.Application') xl.visible= 0 wb = xl.Workbooks.Add(r'C:\Users\ryansinfield\Desktop\Book1.xlsm') ws = wb.Worksheets(1) #loop until empty cell is found in column col = 1 row = 1 empty = False while not empty: val = ws.Cells(row,col).value print("Looking for next available cell to write to...") if val == None: print("Writing result to cell") ws.Cells(row,col).value = Mbps empty = True row += 1 xl.Run('Save') xl.Quit() pythoncom.CoUninitialize() # Remove the file at the end os.remove(myPath) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload