I need to use a semaphore simulator Sync.py that is written in Pythone and new program (also written in Pythone) is added as parameter.

There is problem with classical syntax of If statement, I do not know how to write there else branch as well as more than one command in if branch. Moreover I must write the command straightforward into one line

if (counter == 1): counter += 1

, it doesn’t work in a new line.

I downloaded the simulator from
http://www.greenteapress.com/thinkpython/swampy/install.html
and for running:

python Sync.py mycode.py

I have already tried lots of brackets and functions, I’ve tried to find a problem directly in Sync.py, but I have not had success. I wrote a mail directly to the authors, but they didn’t answer.

Thank you
laccko

did you get an exception that mentioned something about indentation because in python you have to have the executable code under the if statement. you don't need the brackets as well
try this:

if counter == 1:
    counter += 1

When I run the code directly in python there is no problem.
But I need to run it with the sync.py simulator and then the error is occurred (SyntaxError: unexpected EOF while parsing).

Probably there is mistake inside the simulator (I do not know where), but funny is that with single command it works.

I probably found where the problem (but not the solution) is.

Sync.py acts as an interpreter and there is line:

code = compile(source, '<user-provided code>', 'exec')

for interpreting a line from source code.
But just one line!

Any idea for solution?

If you can call/execute external programs, then you can put each routine in a function in a separate file with the appropriate return value. Otherwise, you could do something like the following to eliminate the else statements, and hopefully the program is not large.

a = 1
if a > 0 : print "a is positive"
if a <= 0: print "a is not positive"

test_a = False
b = 0
if a > 0 and b > 0:    test_a = True
if test_a:    print "condition is True"
if not test_a:     print "condition is False"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.