Re: Python and games

2005-08-14 Thread Eric Lavigne
>Like XML, scripting was extremely useful as both a mod tool and an
>internal development tool.  If you don't have any need to expose code
>and algorithms in a simple and safe way to others, you can argue that
>providing a scripting language is not worth the effort.  However, if you
>do have that need, as we did, scripting is a no brainer, and it makes
>complete sense to use a powerful, documented, cross-platform standard
>such as Python.

The Torque Game Engine at www.garagegames.com is written in C++ and
comes with a customized scripting language, torquescript, with a c-like
syntax. Despite that, some game developers decided to add Python as
another scripting layer on top of torquescript. The modified version of
Torque is called PyTorque. I never tried PyTorque, but looking back on
my time with torquescript this sounds like a very good idea.
Torquescript was fine for convenient access to Torque features, but it
never felt as flexible as a general-purpose language like Python. I
expect that the Torque development team could have saved themselves a
lot of trouble by using Python as an extension language to begin with.

-- 
http://mail.python.org/mailman/listinfo/python-list


last line chopped from input file

2005-08-20 Thread Eric Lavigne
Here is a shell command (MS-DOS):
  debug\curve-fit output.txt

And here is a Python script that *should* do the same thing (and almost
does):

  import os

  inputfilename = 'input.txt'
  outputfilename = 'output.txt'

  inputfile = open(inputfilename,'r')
  outputfile = open(outputfilename,'w')
  inputstream,outputstream = os.popen2("debug\\curve-fit")
  inputstream.write(inputfile.read())
  inputfile.close()
  inputstream.close()
  outputfile.write(outputstream.read())
  outputstream.close()
  outputfile.close()

In the shell command, my curve-fit program processes the entire input
file. In the Python script, my curve-fit program processes all except
for the last line. Adding an extra newline to the end of my input file
fixes this problem. What did I do wrong that led to this small
difference?

On a side note, I am very new to Python so I would appreciate any
comments on style, or suggestions for simpler ways to write something
like this (seems overkill for matching one line of shell), or more
portable ways to write it (requires '\\' on windows but '/' on linux).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: last line chopped from input file

2005-08-21 Thread Eric Lavigne
>A shorter python program would be:
>
>   os.command("debug\\curve-fit output.txt")

I tried this program:
  import os
  os.command("debug\\curve-fit output.txt")

My error message is:
  AttributeError: 'module' object has no attribute 'command'

I also could not find os.command in the help files. My Python version
is 2.4 (latest is 2.4.1, just a bug-fix release).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: last line chopped from input file

2005-08-21 Thread Eric Lavigne

> >   import os
> >   os.command("debug\\curve-fit output.txt")
> >
>
> I imagine thats was a typo for:
>
> >>> os.system("debug\\curve-fit output.txt")
> 
> Alan

That fixes it. Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interface with C

2005-09-14 Thread Eric Lavigne

> When this button is hit, it will send a code of 0 to the C
> program.
>
> ./mcp | python gui.py

Your pipe is backwards. Try this:
python gui.py | ./mcp

When your gui.py notices that a button got hit, it can just print the
number 0 (followed by a newline character) to standard output. This
becomes the input to ./mcp, which responds by sending a ping.

Of course, this only works if gui.py does not need to see the output of
./mcp

> Is there a way to do this with Python, to be able
> to read the output of the mcp program, and to
> send data to it, as if it were just a person at the
> computer converting?

Ouch, so you need two way interaction. Are you sure about this? Will
your gui program need to change its behavior based on the output of
mcp? If so, then the simple interface offered by pipes is no longer an
option. You will need to call mcp from within your script. To see how
this sort of thing is done, study the following short script:

# mimics the following shell command:
# debug\curve-fit output.txt

  import os

  inputfilename = 'input.txt'
  outputfilename = 'output.txt'

  inputfile = open(inputfilename,'r')
  outputfile = open(outputfilename,'w')
  inputstream,outputstream = os.popen2("debug\\curve-fit")
  inputstream.write(inputfile.read())
  inputfile.close()
  inputstream.close()
  outputfile.write(outputstream.read())
  outputstream.close() 
  outputfile.close()

-- 
http://mail.python.org/mailman/listinfo/python-list