Python, VB math simple problem

2006-03-31 Thread Mr X






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

Got a great response from a fellow named Matt at [EMAIL PROTECTED], pointed me in some good directions - some areas, concerns still foggy on, the below thread is included any feedback on this simple dilemma

would be very appreciated.



Thanks,



D



thread follows below;





 

To: 	[EMAIL PROTECTED]	   

Subject: 	Problem with Python math functions and VB	   

Date: 	3/30/2006 9:39:28 PM	   

 Download Message Display Headers Printer Friendly 			 

Previous | Next 



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



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

Im working on.



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



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

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



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





x / 37



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;



x %y /y. = z



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

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



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



so



z /y = z Long



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



Then;



Z %y /y. = a



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

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



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

==



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



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

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

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

compatible executable,that would be fantastic.



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

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.



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?



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

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.



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.



Any ideas?







--

Matthew,  thanks for your response. 



<-Original Message-> 

>From: Matthew Dixon Cowles

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

>To: [EMAIL PROTECTED]

>Cc: [EMAIL PROTECTED]

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



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

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

>facilities it offers. 



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

inter-process communication between VB and Python?



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

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



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

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

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



X %37 /37.



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

for every dividend.



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

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



>http://gmpy.sourceforge.net/ 


Python, VB math simple problem

2006-03-31 Thread Mr X






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

Got a great response from a fellow named Matt at [EMAIL PROTECTED], pointed me in some good directions - some areas, concerns still foggy on, the below thread is included any feedback on this simple dilemma

would be very appreciated.



Thanks,



D



thread follows below;





 

To: 	[EMAIL PROTECTED]	   

Subject: 	Problem with Python math functions and VB	   

Date: 	3/30/2006 9:39:28 PM	   

 Download Message Display Headers Printer Friendly 			 

Previous | Next 



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



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

Im working on.



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



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

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



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





x / 37



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;



x %y /y. = z



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

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



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



so



z /y = z Long



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



Then;



Z %y /y. = a



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

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



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

==



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



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

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

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

compatible executable,that would be fantastic.



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

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.



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?



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

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.



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.



Any ideas?







--

Matthew,  thanks for your response. 



<-Original Message-> 

>From: Matthew Dixon Cowles

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

>To: [EMAIL PROTECTED]

>Cc: [EMAIL PROTECTED]

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



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

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

>facilities it offers. 



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

inter-process communication between VB and Python?



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

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



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

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

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



X %37 /37.



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

for every dividend.



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

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



>http://gmpy.sourceforge.net/