[Tutor] What these Python user-defined functions do?
Max Jegers
maxjegers at gmail.com
Fri May 20 21:21:06 EDT 2016
Hi,
I started learning Python (v3.5) and was given some code samples to assist
in my studies. There are some things I could not figure out using Python
documentation or other online sources. I have experience with SQL
programming and some procedural programming, but little in terms of OOP.
I try to slice and dice a Python script that exports a shipment from ERP
system to a text file.
Shipment consists of a Header (H, one record) and Details (D, one or more
records).
Script first imports a library with a number of user-defined functions.
Then the script uses functions defined in library to do exporting to a text
file.
Here is the part of the library:
class View:
def __init__(self):
self.handle = None
…
def order(self, n):
return hostviewOrder(handle, self.handle, n)
def put(self, fieldName, value, verify=1):
if verify == True:
verify = 1
elif verify == False:
verify = 0
return hostviewPut(handle, self.handle, fieldName, value,
verify)
def read(self):
return hostviewRead(handle, self.handle)
def browse(self, filter="", ascending=1):
if ascending == True:
ascending = 1
elif ascending == False:
ascending = 0
return hostviewBrowse(handle, self.handle, filter, ascending)
def fetch(self):
return hostviewFetch(handle, self.handle)
Here is a part of the script I am trying to understand:
def ExportShipment():
f = open("c:\\" + me.get("SHN") + ".txt", "w")
h = View("Header", *1*)
d = View("Details", *1*)
h.*order*(1) # SHN
h.*put*("SHN", me.get("SHN"), 1)
h.*read*()
f.write("H," + h.get("LOCATION") + "," + h.get("ADDR1") + "\n")
d.*browse*("SHIUNIQ=" + "{:.0f}".format(h.get("SHIUNIQ")), 1)
while (d.*fetch*() == 0):
f.write("D," + d.get("ITEM") + "," +
"{:.0f}".format(d.get("QTYSHIPPED")) + "\n")
f.close()
Export output looks like:
H,4,1234 Any Road
D,A2,1
D,B1,3
I understand what file operations do. However I can’t get what these
functions do:
*order(), put(), read(), browse(), fetch()*.
Function definitions in the library are of little help for now, as all
functions feature handle and self.handle in their returns; however I cannot
find out what handle and self.handle may mean in this context.
Please let me know if I should provide more info for my question to make
sense.
Thanks a lot!
--
More information about the Tutor
mailing list