Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, howardR), 472 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Python bridge - wrong output sample #477461
06/30/19 09:35
06/30/19 09:35
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline OP
Senior Member
Grat  Offline OP
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
Hi,

I trying the python sample:
Code

   if(!pyStart(0,1)) {
    printf("Error - Python won't start!");
    return;
  }


  var Vec[5] = { 0,1,2,3,4 };
  pySet("PyVec",Vec,5);
  pyX("for i in range(5): PyVec[i] *= 10\n");
  pyVec("PyVec",Vec,5);

  int i;
  printf("\nReturned: ");
  for(i=0; i<5; i++) printf("%.0f ",Vec[i]);

// test a function
  
  pyX("def PySum(V):\n Sum = 0.0\n for X in V:\n Sum += X\n return Sum\n\n");
  pyX("Result = PySum(PyVec)");
  printf("\nSum: %.0f",pyVar("Result"));


output the Sum is -1, but correct is 100

Re: Python bridge - wrong output sample [Re: Grat] #477463
06/30/19 10:29
06/30/19 10:29
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Maybe not var but int?

Re: Python bridge - wrong output sample [Re: Grat] #477465
06/30/19 15:29
06/30/19 15:29
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline OP
Senior Member
Grat  Offline OP
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
no, becouse is:
Code
...
Sum = 0.0
....


this working (return 100):
Code
pyX("Sum=0");
pyX("for X in PyVec: Sum += X");


this code also work:
Code
  pyX("def PySum(V):\n\tSum=0\n\tfor X in V:\n\t\tSum =Sum+ X\n\treturn( Sum)\n\n");
  pyX("Sum=PySum(PyVec)");
  printf("\nSum: %f",pyVar("Sum"));


so, is a better use \t not space,

Last edited by Grat; 06/30/19 15:44.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1