Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Execute Python code in QM
#9
Thank you for your reply, maybe I didn’t describe it clearly.

1. I installed python3.7 and pywin32 on my computer. I found that pywin32 is installed in the \Lib\site-packages\ folder of python. I tested the python script test file in QM, it can run successfully, then I Generated exe file with QM

2. I have another computer. I don't want to install python3.7 and pywin32. I want to copy the python installation folder installed on the first computer directly to the same folder as exe. Is there any way to run the exe file?

I think that Python sets the environment variable when it is installed. This is the key to success.

How to modify the Python script code in QM, set environment variables, and run exe file directly on any computer? This is very convenient, portable and easy to use.

My English is not good, I used Google Translate  Big Grin

The following code can't run successfully  Huh


Function py_test
Code:
Copy      Help
out
PythonExec ""


#ret

def Script():
,i = int(raw_input('Net profit:'))
,arr = [1000000,600000,400000,200000,100000,0]
,rat = [0.01,0.015,0.03,0.05,0.075,0.1]
,r = 0
,for idx in range(0,6):
,,if i>arr[idx]:
,,,r+=(i-arr[idx])*rat[idx]
,,,print (i-arr[idx])*rat[idx]
,,,i=arr[idx]
,print r


# ---------------------------------------------------------------------------------
# Put your Python script in the Script() function. Don't need to change other code.

import sys
import ctypes
import os
import win32gui

class PrintRedirector(object):
,def __init__(self):
,,self.hwndQM=win32gui.FindWindow("QM_Editor", None)
,
,def write(self, message):
,,if(message=='\n'): return
,,ctypes.windll.user32.SendMessageW(self.hwndQM, 12, -1, message)

sys.stdout = PrintRedirector()
try: Script()
finally: sys.stdout = sys.__stdout__


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)