I need to read a text file stored on a USB stick. PyUSB is what I need to search the USB device, but I don't understand how can I access the file after the device is mounted (on Linux and on Windows).
An idea please?
Just use the absolute path of the file (e.g. C:\text.txt).
To loop through the lines of a text file, use
for line in open("C:\text.txt", "rU"):
#do stuff
open(r"C:\text.txt"...) or open("C:\\text.txt"...) - although '/' on Windows still works...In Ubuntu the pendrive was under /media so I used:
import os
from os.path import join, getsize
for root, dirs, files in os.walk('/media'):
print root, "consumes",
print sum(getsize(join(root, name)) for name in files),
print "bytes in", len(files), "non-directory files"
from http://docs.python.org/library/os.html#os.walk
in windows you will have to try with different drive letters maybe?
No need for PyUSB.