Get the inputs from Excel and use those inputs in python script

后端 未结 4 1337
予麋鹿
予麋鹿 2021-01-16 14:23

How to get the inputs from excel and use those inputs in python.

4条回答
  •  醉梦人生
    2021-01-16 14:41

    Not sure if this is exactly what you're talking about, but:

    If you have a very simple excel file (i.e. basically just one table filled with string-values, nothing fancy), and all you want to do is basic processing, then I'd suggest just converting it to a csv (comma-seperated value file). This can be done by "saving as..." in excel and selecting csv.

    This is just a file with the same data as the excel, except represented by lines seperated with commas: cell A:1, cell A:2, cell A:3 cell B:1, cell B:2, cell b:3

    This is then very easy to parse using standard python functions (i.e., readlines to get each line of the file, then it's just a list that you can split on ",").

    This if of course only helpful in some situations, like when you get a log from a program and want to quickly run a python script which handles it.

    Note: As was pointed out in the comments, splitting the string on "," is actually not very good, since you run into all sorts of problems. Better to use the csv module (which another answer here teaches how to use).

提交回复
热议问题