1
I’m trying to establish the way to read a table of excel for xlrd.
But I get an answer saying that the C: cannot be used. How to correctly define the path of the files to be used?
import xlrd
workbook = xlrd.open_workbook("C:\\Users\rdmsouza\Documents\python\programas\dados.xls")
workbook = xlrd.open_workbook("C:\\Users\rdmsouza\Documents\python\programas\dados.xls", on_demand = True)
sheet.cell(0,0).value
Oserror Traceback (Most recent call last) in () 1 import xlrd ----> 2 Workbook = xlrd.open_workbook("C: Users rdmsouza Documents python.xls data programs") 3 Workbook = xlrd.open_workbook("C: Users rdmsouza Documents python.xls data programs", on_demand = True) 4 sheet.Cell(0,0). value
C: Users rdmsouza Appdata Local Continuum Anaconda3 lib site-Packages xlrd__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows) 393 Peek = file_contents[:peeksz] 394 The following shall apply: --> 395 with open(filename, "Rb") as f: 396 Peek = f.read(peeksz) 397 if Peek == b"PK x03 X04": # a ZIP file
Error: [Errno 22] Invalid argument: 'C: Users rdmsouza Documents python programs.xls data'
Or, you can use the "/" forward as well - Python the interplay as a directory separator, even in Windows, precisely because of the duplicity of the inverted "".
– jsbueno
@jsbueno True, but the problem is when vc depends on external variables that you have no control over, so you have to know the detail of the scape to necessarily make the conversion.
– Sidon
There are no "external variables" in this case - the "" only 'an escape character if it is in a string typed inside the Python source code. If someone types ma "" in an "input" entry, or if a "" is read from a text file, or from a database, it will always be a separate character, which acts as a separator. Experiment: do
print(input())
and type a single "" or some of the escape combinations like n, t, etc...– jsbueno
Ok, I don’t have time and I don’t care to search now (even because my world is currently exclusively Linux), but... YES! in some contexts one can have HUGE problems (and I’ve had them). It’s no coincidence that there are libs to deal with this
– Sidon
But... I wanted to make a test, if not I went with configurations based on yaml files (python 2 something), but not.... I don’t think so! I won’t enter windows just for this. :-)
– Sidon
What I wrote is correct - is that YAML files can use Escaping with exactly the same syntax as Python - see: http://symfony.com/doc/current/components/yaml/yaml_format.html
– jsbueno
Yes, and what I wrote is correct, I said "external variables", ie if you distribute an app that depends on a file
yaml
of which you have no direct participation, that is, built in the production environment by another professional team, you are dealing with a external variable, capisce? :-)– Sidon