I
I
Ivan Melnikov2019-02-13 13:28:51
Python
Ivan Melnikov, 2019-02-13 13:28:51

How to get data from 1C from a python script?

In general, the task is to extract data from 1C using Python.
Platform 1C 8.3, SCP 1.3.
To begin with, I would like to understand how, for example, you can bypass all entries in the Nomenclature Directory and return their values ​​(for example, output to the console).
I establish a COM connection with the 1C base using V83.COMConnector:

#coding=cp1251
import pythoncom
import win32com.client
V83_CONN_STRING = 'File="C:\\Users\\user\\Documents\\InfoBase\\";Usr="Иванов Иван";Pwd="123456";'
pythoncom.CoInitialize()
V83 = win32com.client.Dispatch("V83.COMConnector").Connect(V83_CONN_STRING)

q = '''
Пример запрса???
'''
query = V83.NewObject("Query", q)
selection = query.Execute().Choose()

As I understand it, the q variable must be assigned a string containing a 1C code.
At this point, I'm stumped.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Prog, 2019-02-13
@immelnikoff

q = '''
ВЫБРАТЬ
  Номенклатура.Наименование КАК NAMENOM,
  Номенклатура.Код КАК KODNAME
ИЗ
  Справочник.Номенклатура КАК Номенклатура
'''
query = V83.NewObject("Query", q)
sel = query.Execute().Choose()

while sel.next():
    print(sel.NAMENOM)
    print(sel.KODNAME)

K
Konstantin Nagibovich, 2019-02-13
@nki

as an option
CHOOSE * FROM Directory. Nomenclature

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question