<HTML>
<BODY>
<br>

<br>

Hi looking for help with what should be a fairly simple Python problem, relating to VB inter-operability.<br>

Got a great response from a fellow named Matt at help@python.org, pointed me in some good directions - some areas, concerns still foggy on, the below thread is included.... any feedback on this simple dilemma<br>

would be very appreciated.<br>

<br>

Thanks,<br>

<br>

D<br>

<br>

thread follows below;<br>

<br>

------------------------------------<br>

 <br>

To:     help@python.org    <br>

Subject:        Problem with Python math functions and VB          <br>

Date:   3/30/2006 9:39:28 PM       <br>

 Download Message Display Headers Printer Friendly                       <br>

            Previous | Next <br>

<br>

Wondering if you might either know how to solve the following.<br>

<br>

I've a background in Visual Basic, and am using an old version, 4.0, it compiles to a smaller executable which I prefer. I find myself in an odd situation, needing a very simple yet powerful capability of Python for a VB app<br>

Im working on.<br>

<br>

Simply, a large 300 digit number is divided by a smaller number ranging from 1 to 3 digits. I.e;<br>

<br>

This large 300 digit number is generated as a string from the VB app, and I want to input this somehow<br>

from the VB app directly to Python for simple math operations.<br>

<br>

Where; x = 300 digit number, y = divisor ( say '37')<br>

<br>

<br>

x / 37<br>

<br>

I want to divide x by y but I want the remainder of this division to at least 3 or 4 decimal places, so my Python script at the command line;<br>

<br>

x %y /y. = z<br>

<br>

So now I want to take the resultant, the full number plus its remainder, and I want to round this number up<br>

to the next highest number and divide it by the same constant;<br>

<br>

z rounded up to next highest number (never the lowest)<br>

<br>

so<br>

<br>

z /y = z Long<br>

<br>

Remove the 'L' at the end, round up the last digit of z = Z<br>

<br>

Then;<br>

<br>

Z %y /y. = a<br>

<br>

Then I want the last five digits of z (not Z) and a truncated at the end, so the last digit before<br>

the decimal point and the four digits past the decimal point printed to a text file.<br>

<br>

I want to be able to open the text file with the VB app and use this data as inputs.<br>

==========<br>

<br>

Ok, so here is my dilemma, I know VERY litle about Python and a fair bit about VB.<br>

<br>

Ideally, I'd love to be able to simply have some extremely small executable that just accepts inputs<br>

does the calculations above and then spits out the outputs. If it were possible to write some<br>

simple lines of math code in Python and then compile these scripts in Python to a Windows<br>

compatible executable,that would be fantastic.<br>

<br>

If I could simply have my VB app, 'call' the name of the tiny Python executable, and then the Python executable<br>

just automatically looked for a named text file (created by the VB app) and extracted the 300 digit number from this, then performed the calcs, then spit this data out as a new text file name it created, which I could then use the VB app to open and read from, THAT would be ideal.<br>

<br>

However, I don't know if Python can compile scripts to an exe? If it can how could I find out how to do this?<br>

<br>

If it doesn't, how could I get VB to directly pass commands to the Python command line and then automatically<br>

extract the outputs? Shelling out from VB to Python would be tough to the command line I think, since the Python command line uses the 'Edit / Mark, Paste' approach to inserting, copy inputs, outputs and this would be virtually untenable, as far as I can tell to automate in a VB shell out routine.<br>

<br>

So basically, how the heck can I access Pythons ability to perform simple calculations on very large numbers, easily, from within VB 4.0 ? There must be a way, it seems like such a simple think to do, especially since the actual math operations are so simple, straight forward, and would never change.....<br>

<br>

Any ideas?<br>

<br>

<br>

<br>

------<br>

Matthew,  thanks for your response. <br>

<br>

<-----Original Message-----> <br>

>From: Matthew Dixon Cowles<br>

>Sent: 3/31/2006 9:41:18 AM<br>

>To: durango@mail2world.com<br>

>Cc: help@python.org<br>

>Subject: Re: [Python-Help] Problem with Python math functions and VB<br>

<br>

>I'm sure that there's a way to do that, but I'm not familiar with <br>

>Visual Basic and I don't know what inter-process communication <br>

>facilities it offers. <br>

<br>

Is there a person or group you might direct me to that has worked with this <br>

inter-process communication between VB and Python?<br>

<br>

>I don't think that Python is going to be able to do that for you out <br>

>of the box. Hundreds of digits of floating-point precision is a lot. <br>

<br>

Could you explain that a bit more, sorry Im not sure what you mean<br>

by 'out of the box' ?  If I run the Python command line screen in windows<br>

and manually type out a very large number, say 180 digits; where 'X' = very large number;<br>

<br>

X %37 /37.<br>

<br>

returns what Im after, value wise.....  but of course I don't want to do this manually each time<br>

for every dividend.<br>

<br>

>You might find that one of the Python modules that let you use an <br>

>extended-precision library would do what you want. GMPY is one: <br>

<br>

>http://gmpy.sourceforge.net/ <br>

<br>

Hey, thats interesting, wonder if these modules can be operated on with VB.....<br>

<br>

>> So now I want to take the resultant, the full number plus its <br>

>> remainder, and I want to round this number up <br>

>> to the next highest number and divide it by the same constant; <br>

><br>

>That's easy enough. <br>

><br>

>> I want to be able to open the text file with the VB app and use this <br>

>> data as inputs. <br>

><br>

>Python can write to a file without any trouble, so it that form of <br>

>inter-process communication suits you, you shouldn't have much <br>

>trouble. I assume that Visual Basic has an easy way to start a <br>

>program and supply it with arguments, so you could have your Python <br>

>program get its inputs from sys.argv. <br>

<br>

What is sys.argv ? Thats really good news.  In fact, all I really need for the moment is<br>

a python executable that;<br>

<br>

================<br>

PYTHON ALGORITHM ABSTRACT<br>

<br>

a) opens a text file<br>

b) reads a string from the file, which is a very large number<br>

c) performs simple arithmetic operations;<br>

<br>

        X %37 /37. = y (four digit remainder after decimal point)<br>

        X /37 = w (quotient as long, the resulting output is stored as a variable, the 'L' suffix tagged on the end of this resultant then gets removed.<br>

                then the last digit in the quotient resultant string is increased in value by one, rounded upwards = 'Z'<br>

<br>

        then <br>

<br>

        Z %37 /37. = a<br>

<br>

        then, y and a are printed to a text file with hard returns between them.  Thats it, thats all I need to do.<br>

===================<br>

>Alas, it's not going to be extremely small. There isn't a compiler <br>

>from Python to machine code. Py2exe will bundle a Python program, <br>

>with everything that it needs to run, into a single executable <br>

>archive. But the archive isn't small. Py2exe is at: <br>

><br>

>http://www.py2exe.org/ <br>

<br>

the most important thing is the functionality, I'll sacrifice size if I have to.  My guess is this should work based on your comments, because<br>

perhaps all I really have to do is have VB dump out the value of the Very large number, `180 to 300 digits or so', to a text file, which then<br>

becomes the input data for the Python executable, and then if I simply call the name of the Python executable from VB as an instance,<br>

then the Python App runs, spits out the data as a new text file, then the VB app goes and opens the new text file and reads in the values,<br>

and voila!  There it is.  I'm pretty sure I can call the Python app from VB....... the alternative to all this would be to try and feed Python scripts<br>

directly to Python from VB, which I have NO idea how to do or where to begin.... and am guessing would be much more messy...<br>

<br>

I haven't programmed in Python, how would the "PYTHON ALGORITHM ABSTRACT" I describe above look like, code wise? <br>

Is this fairly easy for you to describe?<br>

<br>

>It may be that Python isn't the best solution for you here. Are there <br>

>extended-precision libraries for Visual Basic? <br>

<br>

Alas, none that I know of that are reliable and not incredibly expensive, been looking for years, plus Im hooped because I have to work <br>

with VB 4.0 instead of 6 +, guh.... <br>

<br>

>Regards, <br>

>Matt <br>

<br>

Matt..... good name, why do I always seem to get along with Matts, you people keep popping up in my life and its always a blast!<br>

<br>

Best regards,<br>

<br>

D
</BODY></HTML>


<span id=m2wTl><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Get the FREE email that has everyone talking at <a href=http://www.mail2world.com target=new>http://www.mail2world.com</a><br>  <font color=#999999>Unlimited Email Storage – POP3 – Calendar – SMS – Translator – Much More!</font></font></span>