Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (M_D, AndrewAMD, Quad, Ayumi), 806 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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