Author Topic: For Andy, Python work  (Read 304 times)

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8315
    • View Profile
For Andy, Python work
« on: July 05, 2020, 22:18:12 pm »
Andy, (or for that matter anyone else who might know the solution),

I'm making progress using Python as a post-build-processor language, but not quite.

I can execute such a script from either the command prompt (using python) or from a Windows command (using pythonw), and it runs fine, using the input file and creating an output file properly.

But when I attempt to execute it as a PBP, I get the following errors, and NO output (in fact, except for a delay I added to see that it had run, you'd think it hadn't run -- but it has):

External command c:\python27\pythonw c:\python27\Pythontest1.py -i CBinput -o CBoutput
close failed in the object destructor
sys.excepthook is missing
lost sys stderr

Obviously, there's something missing in my execution or closing of Python that isn't a problem when using wscript to call a .vbs script.

Since we're fairly soon going to lose .VBS, I thought it would be a good idea to implement another 'scripted' language.

Any help will be appreciated.

Yours,
Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6073
    • View Profile
    • Cambam V1.0 French Doc
Re: For Andy, Python work
« Reply #1 on: July 05, 2020, 23:04:38 pm »
Hello

Quote
Since we're fairly soon going to lose .VBS, I thought it would be a good idea to implement another 'scripted' language.

Why ? If I well understand VBS will only disappears for Browser, but is still usable in stand alone application ... it's the script language in Excel or Word, and ... it's also used in Mach3 for all M codes.

... and why do you not use an .exe done with VB .net or C#  ??? that works without problem ... and you don't need to learn Python ..
 
++
David
« Last Edit: July 05, 2020, 23:15:08 pm by dh42 »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8315
    • View Profile
Re: For Andy, Python work
« Reply #2 on: July 05, 2020, 23:46:53 pm »
David,
In reverse:
I'm learning Python to give me another 'tool in the box'.  I hope to make it work properly for the PBP in order to give others that tool, also.

So far as creating an exe, yeah, I can do that; I have done, here.  But it's many extra steps and extra time, compared to a scripted language.

VBS and other scripting languages are extremely effective at saving time.  Time is my enemy, and anything I can do to save some is a task worthwhile.

Finally, don't trust Microsoft to not eliminate VBS one day, even from the command-line.  They've threatened to do so, already.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6073
    • View Profile
    • Cambam V1.0 French Doc
Re: For Andy, Python work
« Reply #3 on: July 05, 2020, 23:59:48 pm »
Quote
I'm learning Python to give me another 'tool in the box'.

Yes, but you are a young man with lots of future plans ! , for me the next language to learn is Latin to be able to read my tombstone  ;D

++
David


Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8315
    • View Profile
Re: For Andy, Python work
« Reply #4 on: July 06, 2020, 00:53:39 am »
Et tu, David?

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6073
    • View Profile
    • Cambam V1.0 French Doc
Re: For Andy, Python work
« Reply #5 on: July 06, 2020, 01:01:14 am »
sorry, not understand the question ...

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8315
    • View Profile
Re: For Andy, Python work
« Reply #6 on: July 06, 2020, 01:18:57 am »
Latin:  "And you, David?"  (meaning, "you also"?)

I also feel the effects of age (being 71).

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6073
    • View Profile
    • Cambam V1.0 French Doc
Re: For Andy, Python work
« Reply #7 on: July 06, 2020, 01:31:41 am »
Ah OK, sorry (bed time for me I think  ::) )

And you ? = Et toi ?

you also ? = Toi aussi ?

56 years and 8 months for me ; you beat me ;)

++
David

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 2960
    • View Profile
Re: For Andy, Python work
« Reply #8 on: July 06, 2020, 10:35:06 am »
I also feel the effects of age (being 71).
**************************

This must be an 'old fart' place  ;D, at end of this month I be 71 as well.  :D :D
My 2ยข

Win 10 64 bit, CB [1.0} rc 1 64 bit, Mach3, ESS, G540

Offline kvom

  • CNC Jedi
  • *****
  • Posts: 1578
    • View Profile
Re: For Andy, Python work
« Reply #9 on: July 06, 2020, 12:39:36 pm »
I haven't needed to modify g-code myself, but if I did need it I'd just use grep.

Regular expressions are easier to learn than a programming language IMO.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8315
    • View Profile
Re: For Andy, Python work
« Reply #10 on: July 06, 2020, 16:42:29 pm »
I know grep well, having done tons of Unix programming during my career.

I examined the task, and for the (so far) two things I need to do, grep wouldn't even come close to serving the task.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline Dragonfly

  • CNC Jedi
  • *****
  • Posts: 2342
    • View Profile
Re: For Andy, Python work
« Reply #11 on: July 06, 2020, 18:05:56 pm »
I have a very humble experience with Python. Only enough to realize it's huge (with all modules and libraries for different applications) and the level and abstraction and philosophy it's been built around is difficult to comprehend for a person who has used strong typed languages. Sometimes, looking at examples in forums I look with awe how some experienced programmers do with a couple of lines things that I'd do in a many lines code block. :)
But on the other hand it has very strong built-in functionality for analyzing and processing plain text. Or a text stream. I've used some of it in my projects.
Therefore very good for post-build processing of G-code.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8315
    • View Profile
Re: For Andy, Python work
« Reply #12 on: July 06, 2020, 18:24:23 pm »
Yep, and my Python script works fine 'stand-alone'.  I just cannot get it to execute when called as a post-build-processor.

I'm hoping Andy will know the answer, or at least how he might address it.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"