Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Martin Walsh

Hi Nathan,

Nathan McBride wrote:
 Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
 work with mysqldump piping to gzip 
 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc...

from http://pexpect.sourceforge.net/pexpect.html

Remember that Pexpect does NOT interpret shell meta characters such as
redirect, pipe, or wild cards (, |, or *). This is a common mistake.
If you want to run a command and pipe it through another command then
you must also start a shell. For example::

child = pexpect.spawn('/bin/bash -c ls -l | grep LOG  log_list.txt')
child.expect(pexpect.EOF)


HTH,
Marty

 -Original Message-
 From: Jeff Younker [EMAIL PROTECTED]
 Sent: Sunday, March 16, 2008 6:59 PM
 To: Nathan McBride [EMAIL PROTECTED]
 Cc: tutor@python.org
 Subject: Re: [Tutor] how to get response from os.system()
 
 
 Would you mind perhaps show an example running an interactive  
 command like su and show how to send input to the commands waiting  
 propmts?
 
 If you're doing that then you *really* want to be using the pexpect
 module.
 
 cmd = pexpect.spawn('su - SOMEINTERACTIVECOMMAND')
 cmd.expect('# ')   # the prompt
 cmd.sendline('A COMMAND')
 cmd.expect('# ')   # wait for the prompt again
 output = cmd.before  # the stuff before the prompt
 cmd.sendline('exit')
 cmd.close()
 
 
 - Jeff Younker - [EMAIL PROTECTED] -
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my first project: a multiplication trainer

2008-03-17 Thread Guba
Dear Chris, list,

cheers for the great help: very valuable indeed.

Chris Fuller wrote:
##
for proxyq in choices:
   q = questions[proxyq]
   answer = raw_input('%dx%d = ' % tuple(q))

   if int(answer) == q[0]*q[1]:
  print 'correct'
   else:
  print 'incorrect'
  false_answers.append(q)
##

I was unable to find information on tuple(). (The Python help function
was rather conservative in its output, Google not helpful).
What exactly is the use of tuple(q) here, and why does not a simple q
instead of tuple(q) do? The latter would have been my intuitive
expectation...

The other thing I have on my mind is this: how could I have the program
ask the math questions not horizontally but vertically? An example:

 4
x7
=

instead of

4x7=

Thank you all,

Guba

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh [EMAIL PROTECTED]
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
 Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
 work with mysqldump piping to gzip 
 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my first project: a multiplication trainer

2008-03-17 Thread Chris Fuller

You should try some of the Python tutorials out there.  There's a difference 
between tuples and lists, and the parameter list passed to the string 
formatting operator must be a tuple.  String formatting will also solve your 
second problem.

Also, the library reference is your friend.  I particularly like the Beazley 
book, if you want something in hardcopy, but one of the less terse and more 
introductory O'Rielly books might suit you better.

Here's a partial list of (mostly) tutorial resources that I've compiled:

http://wiki.python.org/moin/BeginnersGuide
http://www.uselesspython.com/gettingstarted.html
http://www.freenetpages.co.uk/hp/alan.gauld/
http://www.secnetix.de/olli/Python/
http://pythonology.org/

Cheers
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh [EMAIL PROTECTED]
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
 Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
 work with mysqldump piping to gzip 
 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python, wxpython and postgresql

2008-03-17 Thread Bill Mais
I'm a newbie to python and would like to build a database app with 
wxpython and postgresql.  Aside from Dabo, I have not found any 
tutorials that cover reading and writing to a database.  Is it so easy 
that examples are not needed or so impossible that no one can do it.  
Can someone point me in the right direction. 

I've got more specific questions but figured this would be a good place 
to start.

Thanks,
Bill
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python, wxpython and postgresql

2008-03-17 Thread Luke Paireepinart
Bill Mais wrote:
 I'm a newbie to python and would like to build a database app with 
 wxpython and postgresql.  Aside from Dabo, I have not found any 
 tutorials that cover reading and writing to a database.  Is it so easy 
 that examples are not needed or so impossible that no one can do it.  
   
It's neither.  There are plenty of examples, but it is fairly easy to do.
Ask Google:
http://www.google.com/search?hl=enq=python+postgresql+tutorialbtnG=Google+Search
Try the first two results from About.com.
If you have an issue with a particular tutorial, we can help you with 
that as well.
 Can someone point me in the right direction. 
   
It's always helpful to do a bit of googling before you ask.  You don't 
want people assuming you're just being lazy ;)
 I've got more specific questions but figured this would be a good place 
 to start.
   
Sure, ask away.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh [EMAIL PROTECTED]
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
 Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
 work with mysqldump piping to gzip 
 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh [EMAIL PROTECTED]
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
 Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
 work with mysqldump piping to gzip 
 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Luke Paireepinart
Nathan McBride wrote:
 That's a great tip I'll have to save than.
Nathan,
I'm not sure why you sent this three times, but we've gotten it, if 
you're worried about it.
Thanks,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python, wxpython and postgresql

2008-03-17 Thread Eric Walstad
Hey Bill,

Bill Mais wrote:
 I'm a newbie to python and would like to build a database app with 
 wxpython and postgresql.

I would suggest you first write the basic app to work from the command
line.  It's easy to debug that way and enables you to focus on the
critical features of your app without wasting much, if any, of your
time.  Once you are able to do the basics from the command line it is
generally easy to wrap it in wxPython.

As Luke said, there are a lot of examples out there on how to read/write
to a postgresql db.  At some point, probably after you try a code
example or two, you may find the DB API pep helpful:
http://www.python.org/dev/peps/pep-0249/
It defines the interface the db adapters (psycopg, for example) are
supposed to provide you.

We are happy to help when you have specific questions, too.

Best,

Eric.

other keyword pointers include:
optparse (makes handling command line options a breeze)
raw_input (get user input from the command line)
psycopg2 (postgresql database adapter)
doctest (document your code with runnable tests)



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python, wxpython and postgresql

2008-03-17 Thread Bill Mais
Hey, I thought programming was all about the shortcuts ;-)

I'm sorry to not be clear.  I've done several excellent python + 
postgresql tutorials, but the one I have not found is wxPython + 
postgresql (or any database).

Specifically, how would you take your sql results and set the values of 
your wxTextCtrls and wxListCtrls?  For example if the sql select 
statement returns 20 fields the function would find the wxPython 
controls with the same name and set their values.

And how would you build a sql statement with only the wxPython controls 
that have been modified by the user?  So if only the address field was 
modified the sql would be: UPDATE table1 SET address = '123 Easy Street' 
WHERE rec_id = 1

Thanks again,
Bill
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python, wxpython and postgresql

2008-03-17 Thread Chris Fuller
Unless you have a specific reason for choosing postgresql (an excellent 
database, just not the easiest), such as having an existing 
installation, desiring networked access, or nice features such as type 
safety, you might want to consider SQLite instead. Also, if you stick to 
the DB-API spec, you will have a fairly easy time of switching databases 
later, should you wish to.

http://www.python.org/peps/pep-0249.html

Cheers

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python, wxpython and postgresql

2008-03-17 Thread Chris Fuller
There are at least a couple of python interfaces to postgresql, but psycopg 
follows the DB-API spec.  You shouldn't have to use the postgresql engine 
directly.

http://www.initd.org/pub/software/psycopg/

The cool bit is that the examples you see that follow DB-API will apply to 
postgresql, except for the initial connection part.

Cheers
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Foothill College Spring Courses

2008-03-17 Thread Elaine
Spring quarter classes start Monday, 7 April, at
Foothill College.
These two may be of interest to you:

1) Introduction to Python Programming - 5 units
Prerequisite: Any programming language experience
CIS 68K - Monday evenings at Middlefield campus in
Palo Alto

2) Application Software Development with Ajax - 5
units
Prerequisite: Knowledge  of HTML and JavaScript 
COIN 71 - Tuesday evenings at Middlefield campus in
Palo Alto

If you are interested in taking a class, please
register as soon as possible by going to:
http://www.foothill.fhda.edu/reg/index.php
If not enough students sign up, a class may be
cancelled.

If you have any questions, please contact the
instructor, Elaine Haight, at
[EMAIL PROTECTED]




  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Should config file parser be in module's __init__.py

2008-03-17 Thread Shrutarshi Basu
I'm working on a module consisting of a number of scripts that handle
communications over a serial connection. I would like someway for the
user to be able to specify which serial port to be used based on a
config file in the same directory as the user's program. Should I
place the parsing system in the module's init.py, considering that the
port will actually be accessed by a different python script in the
same module? How could I then let the other scripts access the port
information obtained by the parser?
Thanks,
Shrutarshi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor