Re: how to get a value from CSV specific cell (A7) thanks

2018-09-02 Thread Peter Otten
[email protected] wrote:

> how to get a value from CSV specific cell (A7) thanks

$ cat csv_sheet.py   
#!/usr/bin/python3
import re
import csv
import string

LOOKUP = {c: i for i, c in enumerate(string.ascii_uppercase, 1)}

def a2i(s):
"""
>>> a2i("A")
0
>>> a2i("Z")
25
>>> a2i("AA")
26
>>> a2i("AZ")
51
>>> a2i("BA")
52
"""
sigma = 0
for c in s:
sigma *= len(LOOKUP)
sigma += LOOKUP[c]
return sigma - 1

def offset(s):
m = re.match("([A-Z]+)([0-9]+)", s.upper())
if m is None:
raise ValueError
col, row = m.groups()
return a2i(col), int(row) - 1

if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("file")
parser.add_argument("cells", metavar="cell", nargs="+")
args = parser.parse_args()

with open(args.file) as f:
rows = list(csv.reader(f))
for cell in args.cells:
x, y = offset(cell)
print(rows[y][x])
$ cat tmp.csv
1,2,3,4,5,6,7,8,9
10,20,30,40,50,60,70,80,90
100,200,300,400,500,600,700,800,900
1000,2000,3000,4000,5000,6000,7000,8000,9000
1,2,3,4,5,6,7,8,9
10,20,30,40,50,60,70,80,90
100,200,300,400,500,600,700,800,900
$ ./csv_sheet.py tmp.csv a7 b2 c3
100
20
300
$ python3 -m doctest csv_sheet.py  # otherwise untested


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to get a value from CSV specific cell (A7) thanks

2018-09-02 Thread alon . najman
On Saturday, September 1, 2018 at 9:19:29 PM UTC+3, [email protected] wrote:
> how to get a value from CSV specific cell (A7) thanks

thanks all !
-- 
https://mail.python.org/mailman/listinfo/python-list


Can't drop files on python scripts in a fresh installation of Windows 10 and Python 3.7

2018-09-02 Thread Random832
Python itself runs fine, but when I try to drop a file on a script it just 
doesn't work.

If I try to regsvr32 the shell extension, it says: The module 
"c:\windows\pyshellext.amd64.dll" failed to load.

There was no indication of any problem until this. Apparently it is linked 
against "VCRUNTIME140.dll", not (or in addition to? peview shows both) the 
universal CRT.

Installing the Visual C++ 2015 redistributable resolved it, but there was no 
instruction for this.
-- 
https://mail.python.org/mailman/listinfo/python-list