Re: [Tutor] pgdb and console output

2010-03-10 Thread Alan Gauld


"pylist1"  wrote


sys.stdout.write(str(i))


Yes that does indeed work like this:

But it leaves formatting issues with leaving the command prompt in the 
middle of the screen. That's not an issue at the moment.


Yes, stdout.write has no formatting if you need spaces or newlines you
have to explicitly provide them. That's why mosty folks use print
combined with a format string to get formatted output.


I found after my initial email your pdf book you had wrote.  ...
  Thanks for writing the book.


You're welcome but the web pages are more up top date than
the pdf file. I only generate the pdf after major updates but the
html files get updates fairly regularly. The zip files get updates
somewhere in between

One last thing is your using "raw_input".  What's the differenct between 
that and "str input"?  If the OS is using UTF-8 and the databse is UTF-8 
should it really matter? So raw_input could mean any type of input?


I don;t know what "str input" refers to but raw_input is the standard
method in Python v2 of reading characters from stdin.  Its called raw
because it reads the raw characters, it does not try to interpret them.
Thus if you know its a number you use int() to convert the string to
an integer value

In Python v3 raw_input has been renamed to input()

See the Talking to the User topic in my tutorial for more detail on the
differences.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Macbook Pro+python programming

2010-03-10 Thread Alan Gauld

"Brett Wunderlich"  wrote


Because I just got a brand new Mac (the one on apple store) and it seems
that the build in Python 2.6.1 from darwin is garbage


Thats unlikely, but the configuration may be faulty.

dual core and each time I open terminal, then type idle and try to use 
IDLE

the screen freezes


What happens if you type

$ python /full/path/to/idle.py

Where /full/path./... is the actualm path to idle.py?
Does that work.


> (something you would never expect with a computer with my

specs) and I must force quit the application to be able to continue


I don;t expect that on my old 600MHz G3 iBook - almost 10 years
old and running Python 2.5 and Idle quite happily!


Python (and idle) on your MacBook Pro should work just fine.
If it does not, you should work on fixing that, as the Mac OS uses
Python for various things in the background, especially for 
installations.


It could well be that Python is working fine and only the idle config is
faulty. It could be as simple as file permissions.
What happens if you use sudo to start idle?

I would suggest using Disk Utility (in the /Applications/Utilities 
folder)

to do a "Verify Disk". If it finds problems, you'll need to boot the
MacBook Pro from your install disk and use Disk Utility to do
a "Repair Disk".


I'd be amazed if that was needed.


If no problems are found then I would start with an Archive and
Install of the operating system.


And I'd definitely keep that as a last resort!
Its much more likely that you need to setup PYTHONPATH or
even PATH, or set permissions differently.

My first check would be that python itself works ok by just typing
python in the Terminal app and checking you get a working >>>
prompt.
If that works try starting IDLE using the full path and explicitly
calling python as described above.
If that works then check your PATH/PYTHONPATH  settings

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Encoding

2010-03-10 Thread Giorgio
2010/3/8 Dave Angel 

>
>>  You still didn't provide the full context.  Are you trying to do store
> binary data, or not?
>

Yes i think ti's binary data. I'm just reading with file.read a JPG image.

Stefan: yes, read that tutorial :)

Giorgio

>
>
>


-- 
--
AnotherNetFellow
Email: anothernetfel...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] WSGI / Apache

2010-03-10 Thread Giorgio
2010/3/8 Benno Lang 

>
>
> WSGI is based on CGI, so I imagine that it's not too difficult to have
> a wrapper that converts between the protocols. I haven't tried
> wsgiref, though.
>

Yes Benno it isn't. It seems that mod_wsgi is the most used alternative.


>
> > Do you have any idea i should use mod_wsgi instead of wsgiref + mod_cgi?
>
> From your application's perspective, if it talks WSGI it shouldn't
> make any difference. But if you're using GAE, what good will it do to
> have a local Apache server anyway?
>

Ok, that was a general question, not GAE related. Someone says that mod_wsgi
is faster than wsgiref + cgi.


>
> Cheers,
> benno
>



-- 
--
AnotherNetFellow
Email: anothernetfel...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Timezone issues with datetime module.

2010-03-10 Thread kushal gupta
Hi,
  I am facing an issue with datetime module with some timezones (especially
day light savings).
Given the date and the timezone, I want to convert it to the UTC date and
time.

Here is the snippet:

import datetime
import mx.DateTime
from dateutil import zoneinfo
def parse_date(date, tzname):
feed_time =  mx.DateTime.strptime(date, '%d-%m-%Y')
feed_datetime = datetime.datetime(*feed_time.timetuple()[:6],
tzinfo=zoneinfo.gettz(tzname))
feed_time = mx.DateTime.DateTime(*feed_datetime.utctimetuple()[:6])

return feed_time

>>>parse_date('28-03-2010', 'Australia/Melbourne')

>>> parse_date('29-03-2010', 'Australia/Melbourne')


which says day light savings ended on 28th March (seeing at the outputs,
there is a difference of 1 hr in time) but it actually ended on April 4th
http://www.timeanddate.com/worldclock/city.html?n=152


for  'America/Anchorage' the same code works fine (DST starts on 14th March
02:00 hours)
http://www.timeanddate.com/worldclock/city.html?n=18

>>> parse_date('14-03-2010', 'America/Anchorage')

>>> parse_date('15-03-2010', 'America/Anchorage')


What am i missing here?

Please help.
Thanks Kushal.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite error messages

2010-03-10 Thread Alan Harris-Reid

Benno Lang wrote:

On 10 March 2010 11:37, Alan Harris-Reid  wrote:
  

Hi there,

I am using the sqlite3 module with Python 3.1, and have some code which goes
something like as follows...

import sqlite3
con = sqlite3.connect('MyDatabase.db')

try:
  execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
("MyValue")')
  con.commit()
except:
  con.rollback()
  If con.execute() fails, nothing is returned, and although the code
correctly executes the rollback next, I have no idea why, and therefore
cannot create a suitable error-handler with meaningful messages.
I notice from the SQLite website that there are error codes, but it looks
like the sqlite3 module is not reporting them.



Do you mean numerical error codes? Which page on the SQLite website
are you referring to? Certainly the exception contains usable data.
Try something like this:

try:
  execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
("MyValue")')
  con.commit()
except Exception as error:
  print("Didn't work:", error)
  con.rollback()

(I didn't create a table, so I get "Didn't work: no such table: MyTable")

HTH,
benno

Hi Benno,  your example is great - just what I needed!

Regarding SQLite error codes, the list I was referring to is at 
www.sqlite.org/c3ref/c_abort.html 
, but it doesn't look complete 
because I have already come-across some IntegrityError messages which 
aren't on the list.


Regards,
Alan




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite error messages

2010-03-10 Thread Alan Harris-Reid

Sander Sweers wrote:

- Original message -
  

I am using the sqlite3 module with Python 3.1, and have some code which
goes something like as follows...

import sqlite3
con = sqlite3.connect('MyDatabase.db')

try:
execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
("MyValue")')
con.commit()
except:



Here you catch all exceptions. Normally you would catch a specific exception like ValueError.  
  

con.rollback()




Do you know finally? It is run after all the exceptions have been handled and 
this is where I would put the rollback.

Greets,
Sander


Hello Sander, thanks for the reply.

"Normally you would catch a specific exception like ValueError."
Agreed, but as I don't know what type the exception is, I would have to 
provide a suitable error message for all exception types (ValueError, 
IntegrityError, etc.).  At this stage catching Exception as errormessage 
is sufficient for my purposes.


"Do you know finally? It is run after all the exceptions have been 
handled and this is where I would put the rollback."
In this case there is no 'finally' section, because if the 'try' section 
doesn't work, then I want the rollback to occur for *all *exceptions. 

Maybe I have misunderstood you, but I always thought that the 'finally' 
section was run even if the 'try' section is successful, in which case I 
would not want a rollback.  (According to the Python documentation 
(section 8.6) "A /finally clause/ is always executed before leaving the 
try  
statement, whether an exception has occurred or not.").


Regards,
Alan



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite error messages

2010-03-10 Thread Sander Sweers
On 10 March 2010 21:02, Alan Harris-Reid  wrote:
> Maybe I have misunderstood you, but I always thought that the 'finally'
> section was run even if the 'try' section is successful, in which case I
> would not want a rollback.

I was thinking something like this.

import sqlite3
con = sqlite3.connect('MyDatabase.db')

execresult = None
try:
execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
("MyValue")')
con.commit()
finally:
if not execresult:
print 'Rollback'
con.rollback()

This way you can have a rollback and still see an exception.

Greets
Sander
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Running a dos program with python

2010-03-10 Thread Armstrong, Richard J.
Hello all,

 

This is my first post to the Tutor@python.org mailing list. I am in the
process of switching from Matlab to Python and there is one task that I
am having a hard time doing and cannot find the answer on the web. I
want to write a script in python that will open up a windows dos
program, send three inputs (file names) into program and then run it. I
know one way to open up the dos program with
os.system(r"c:\shake91.txt") but cannot do the rest.

 

When I run my script

 

import os

os.system(r"c:\shake91.exe")

 

In the IPython(x,y) console I see:

 


--

*

 * SHAKE  --   A COMPUTER PROGRAM FOR EARTHQUAKE RESPONSE  *

 * ANALYSIS OF HORIZONTALLY LAYERED SITES  *

 * by: Per B. Schnabel & John Lysmer -- 1970   *

 * --- *

 * shake85 IBM-PC version of SHAKE *

 * by: S.S. (Willie) Lai, January 1985 *

 * --- *

 * shake88   : New modulus reduction curves for clays added*

 * using results from Sun et al (1988) *

 * by: J. I. Sun & Ramin Golesorkhi*

 * February 26, 1988   *

 * --- *

 * SHAKE90/91: Adjust last iteration; Input now is either  *

 * Gmax or max Vs; up to 13 material types can *

 * be specified by user; up to 50 Layers can   *

 * be specified; object motion can be read in  *

 * from a separate file and can have user  *

 * specified format; Different periods for *

 * response spectral calculations; options *

 * are renumbered; and general cleanup *

 * by: J. I. Sun, I. M. Idriss & P. Dirrim *

 * June 1990 - February 1991   *

 * --- *

 * SHAKE91   : General cleanup and finalization of input/  *

 * output format ... etc   *

 * by: I. M. Idriss*

 * December 1991   *

 ***

   Name of Input File =


--

 

And there is a blinking cursor after Name of Input File. At this point I
can manually enter in the file name (and the two other remaining file
names) and then press enter and the program does run. What I really want
though is to be able to do the whole thing with a python script.

 

Any ideas?

 

Thanks

 

Richie

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a dos program with python

2010-03-10 Thread Wayne Werner
On Wed, Mar 10, 2010 at 3:20 PM, Armstrong, Richard J. <
rarms...@water.ca.gov> wrote:

>  Hello all,
>
>
>
> This is my first post to the Tutor@python.org mailing list. I am in the
> process of switching from Matlab to Python and there is one task that I am
> having a hard time doing and cannot find the answer on the web. I want to
> write a script in python that will open up a windows dos program, send three
> inputs (file names) into program and then run it. I know one way to open up
> the dos program with os.system(r”c:\shake91.txt”) but cannot do the rest.
>

Use the subprocess module:
http://docs.python.org/library/subprocess.html

untested, but should work:

subprocess.Popen([r'c:\shake91.txt', 'param1', 'paramN-1', 'paramN'])

if you want to communicate with the process you can add ,
stdout=subprocess.PIPE, stdin=subprocess.PIPE) to the function call.

Check the docs for more info.
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a dos program with python

2010-03-10 Thread Armstrong, Richard J.
 

 

From: sri...@gmail.com [mailto:sri...@gmail.com] On Behalf Of Wayne
Werner
Sent: Wednesday, March 10, 2010 2:24 PM
To: Armstrong, Richard J.
Cc: tutor@python.org
Subject: Re: [Tutor] Running a dos program with python

 

On Wed, Mar 10, 2010 at 3:20 PM, Armstrong, Richard J.
 wrote:

Hello all,

 

This is my first post to the Tutor@python.org mailing list. I am in the
process of switching from Matlab to Python and there is one task that I
am having a hard time doing and cannot find the answer on the web. I
want to write a script in python that will open up a windows dos
program, send three inputs (file names) into program and then run it. I
know one way to open up the dos program with
os.system(r"c:\shake91.txt") but cannot do the rest.

 

Use the subprocess module:

http://docs.python.org/library/subprocess.html

 

untested, but should work:

 

subprocess.Popen([r'c:\shake91.txt', 'param1', 'paramN-1', 'paramN'])

 

if you want to communicate with the process you can add ,
stdout=subprocess.PIPE, stdin=subprocess.PIPE) to the function call.

 

Check the docs for more info.

HTH,

Wayne

 

Wayne,

 

It kindof works. I wrote 

 

subprocess.Popen([r'c:\shake91.exe', 'FLAC.txt', 'a.txt', 'b.txt'])

 

The dos program pops up and if I hit the enter key three times then it
runs. How can I add these three "enters" into the script? 

 

Thanks,

 

Richie

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difflib comparing string sequnces

2010-03-10 Thread Ricardo Aráoz
Vincent Davis wrote:
> I have never used the difflib or similar and have a few questions.
> I am working with DNA sequences of length 25. I have a list of 230,000
> and need to look for each sequence in the entire genome (toxoplasma
> parasite) I am not sure how large the genome is but more that 230,000
> sequences.
> The are programs that do this and really fast, and they eve do partial
> matches but not quite what I need. So I am looking to build a custom
> solution.
> I need to look for each of my sequences of 25 characters
> example(AGCCTCCCATGATTGAACAGATCAT).
> The genome is formatted as a continuos string
> (CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG.)
>
> I don't care where or how many times on if it exists. This is simple I
> think, str.find(AGCCTCCCATGATTGAACAGATCAT)
>
> But I also what to find a close match defined as only wrong at 1
> location and I what to record the location. I am not sure how do do
> this. The only thing I can think of is using a wildcard and performing
> the search with a wildcard in each position. ie 25 time.
> For example
> AGCCTCCCATGATTGAACAGATCAT
> AGCCTCCCATGATAGAACAGATCAT
> close match with a miss-match at position 13

Untested :

genome = 'CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG'
sequence = 'AGGCTTGCGGAGCCTGAGGGCGGAG'

import fnmatch
for i in range(len(sequence)):
match = '*' + sequence[0:i] + '?' + sequence[i+1:] + '*'
if fnmatch.fnmatch(genome, match)
   print 'It matches'



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difflib comparing string sequnces

2010-03-10 Thread Ricardo Aráoz
Vincent Davis wrote:
> I have never used the difflib or similar and have a few questions.
> I am working with DNA sequences of length 25. I have a list of 230,000
> and need to look for each sequence in the entire genome (toxoplasma
> parasite) I am not sure how large the genome is but more that 230,000
> sequences.
> The are programs that do this and really fast, and they eve do partial
> matches but not quite what I need. So I am looking to build a custom
> solution.
> I need to look for each of my sequences of 25 characters
> example(AGCCTCCCATGATTGAACAGATCAT).
> The genome is formatted as a continuos string
> (CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG.)
>
> I don't care where or how many times on if it exists. This is simple I
> think, str.find(AGCCTCCCATGATTGAACAGATCAT)
>
> But I also what to find a close match defined as only wrong at 1
> location and I what to record the location. I am not sure how do do
> this. The only thing I can think of is using a wildcard and performing
> the search with a wildcard in each position. ie 25 time.
> For example
> AGCCTCCCATGATTGAACAGATCAT
> AGCCTCCCATGATAGAACAGATCAT
> close match with a miss-match at position 13

also :

sequence = 'AGGCTTGCGGAGCCTGAGGGCGGAG'
seqList = ['*' + sequence[0:i] + '?' + sequence[i+1:] + '*' for i in
range(len(sequence))]
import fnmatch

genome = 'CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG'
if any(fnmatch.fnmatch(genome, i) for i in seqList)
print 'It matches'

Which might be better if the sequence is fixed and the genome changes
inside a loop.

HTH



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a dos program with python

2010-03-10 Thread Wayne Werner
On Wed, Mar 10, 2010 at 4:51 PM, Armstrong, Richard J. <
rarms...@water.ca.gov> wrote:

>
>
> The dos program pops up and if I hit the enter key three times then it
> runs. How can I add these three “enters” into the script?
>

I'm not at all sure if this way would work, but you could send the \r\n
through a pipe:

p = subprocess.Popen([file1, file2, file3], stdin=subprocess.PIPE)
p.communicate("\r\n\r\n\r\n") # Three windows line ending sequences.

it also may be possible to add them to the end of the last parameter:
'b.txt\r\n\r\n\r\n'

I don't have much faith that it will work, but you can certainly try!

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a dos program with python

2010-03-10 Thread Randy Raymond
I use wxPython, which allows a statement like:

wx.Execute('c:\shake91.exe "FLAC.txt" "a.txt" "b.txt"')


From: Armstrong, Richard J. 
Sent: Wednesday, March 10, 2010 4:51 PM
To: Wayne Werner 
Cc: tutor@python.org 
Subject: Re: [Tutor] Running a dos program with python


 

 

From: sri...@gmail.com [mailto:sri...@gmail.com] On Behalf Of Wayne Werner
Sent: Wednesday, March 10, 2010 2:24 PM
To: Armstrong, Richard J.
Cc: tutor@python.org
Subject: Re: [Tutor] Running a dos program with python

 

On Wed, Mar 10, 2010 at 3:20 PM, Armstrong, Richard J.  
wrote:

Hello all,

 

This is my first post to the Tutor@python.org mailing list. I am in the process 
of switching from Matlab to Python and there is one task that I am having a 
hard time doing and cannot find the answer on the web. I want to write a script 
in python that will open up a windows dos program, send three inputs (file 
names) into program and then run it. I know one way to open up the dos program 
with os.system(r"c:\shake91.txt") but cannot do the rest.

 

Use the subprocess module:

http://docs.python.org/library/subprocess.html

 

untested, but should work:

 

subprocess.Popen([r'c:\shake91.txt', 'param1', 'paramN-1', 'paramN'])

 

if you want to communicate with the process you can add , 
stdout=subprocess.PIPE, stdin=subprocess.PIPE) to the function call.

 

Check the docs for more info.

HTH,

Wayne

 

Wayne,

 

It kindof works. I wrote 

 

subprocess.Popen([r'c:\shake91.exe', 'FLAC.txt', 'a.txt', 'b.txt'])

 

The dos program pops up and if I hit the enter key three times then it runs. 
How can I add these three "enters" into the script? 

 

Thanks,

 

Richie






___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a dos program with python

2010-03-10 Thread Armstrong, Richard J.
 

 

From: sri...@gmail.com [mailto:sri...@gmail.com] On Behalf Of Wayne
Werner
Sent: Wednesday, March 10, 2010 3:00 PM
To: Armstrong, Richard J.
Cc: tutor@python.org
Subject: Re: [Tutor] Running a dos program with python

 

On Wed, Mar 10, 2010 at 4:51 PM, Armstrong, Richard J.
 wrote:

 

The dos program pops up and if I hit the enter key three times then it
runs. How can I add these three "enters" into the script?

 

I'm not at all sure if this way would work, but you could send the \r\n
through a pipe:

 

p = subprocess.Popen([file1, file2, file3], stdin=subprocess.PIPE)

p.communicate("\r\n\r\n\r\n") # Three windows line ending sequences.

 

it also may be possible to add them to the end of the last parameter:

'b.txt\r\n\r\n\r\n'

 

I don't have much faith that it will work, but you can certainly try!

 

HTH,

Wayne

 

Wayne thank you so much!

 

This worked beautifully:

 

import subprocess

 

p = subprocess.Popen([r'c:\shake91.exe', 'FLAC.txt', 'a.txt', 'b.txt'],
stdin=subprocess.PIPE)

p.communicate("\r\n\r\n\r\n") # Three windows line ending sequences.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a dos program with python

2010-03-10 Thread Armstrong, Richard J.
Thanks Randy, maybe I should check out wxPython.

 

From: tutor-bounces+rarmstro=water.ca@python.org
[mailto:tutor-bounces+rarmstro=water.ca@python.org] On Behalf Of
Randy Raymond
Sent: Wednesday, March 10, 2010 3:06 PM
To: Tutor Python
Subject: Re: [Tutor] Running a dos program with python

 

I use wxPython, which allows a statement like:

 

wx.Execute('c:\shake91.exe "FLAC.txt" "a.txt" "b.txt"')

 

From: Armstrong, Richard J.   

Sent: Wednesday, March 10, 2010 4:51 PM

To: Wayne Werner   

Cc: tutor@python.org 

Subject: Re: [Tutor] Running a dos program with python

 

 

 

From: sri...@gmail.com [mailto:sri...@gmail.com] On Behalf Of Wayne
Werner
Sent: Wednesday, March 10, 2010 2:24 PM
To: Armstrong, Richard J.
Cc: tutor@python.org
Subject: Re: [Tutor] Running a dos program with python

 

On Wed, Mar 10, 2010 at 3:20 PM, Armstrong, Richard J.
 wrote:

Hello all,

 

This is my first post to the Tutor@python.org mailing list. I am in the
process of switching from Matlab to Python and there is one task that I
am having a hard time doing and cannot find the answer on the web. I
want to write a script in python that will open up a windows dos
program, send three inputs (file names) into program and then run it. I
know one way to open up the dos program with
os.system(r"c:\shake91.txt") but cannot do the rest.

 

Use the subprocess module:

http://docs.python.org/library/subprocess.html

 

untested, but should work:

 

subprocess.Popen([r'c:\shake91.txt', 'param1', 'paramN-1', 'paramN'])

 

if you want to communicate with the process you can add ,
stdout=subprocess.PIPE, stdin=subprocess.PIPE) to the function call.

 

Check the docs for more info.

HTH,

Wayne

 

Wayne,

 

It kindof works. I wrote 

 

subprocess.Popen([r'c:\shake91.exe', 'FLAC.txt', 'a.txt', 'b.txt'])

 

The dos program pops up and if I hit the enter key three times then it
runs. How can I add these three "enters" into the script? 

 

Thanks,

 

Richie

  _  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a dos program with python

2010-03-10 Thread Martin Walsh
Armstrong, Richard J. wrote:
> Hello all,
> 
> This is my first post to the Tutor@python.org 
> mailing list. I am in the process of switching from Matlab to Python and
> there is one task that I am having a hard time doing and cannot find the
> answer on the web. I want to write a script in python that will open up
> a windows dos program, send three inputs (file names) into program and
> then run it. I know one way to open up the dos program with
> os.system(r”c:\shake91.txt”) but cannot do the rest.
> 
> Use the subprocess module:
> 
> http://docs.python.org/library/subprocess.html
> 
> untested, but should work:
> subprocess.Popen([r'c:\shake91.txt', 'param1', 'paramN-1', 'paramN'])
> 
> if you want to communicate with the process you can add ,
> stdout=subprocess.PIPE, stdin=subprocess.PIPE) to the function call.
> 
> Check the docs for more info.
> 
> HTH,
> 
> Wayne
>>
>>
> Wayne,
> 
> It kindof works. I wrote
> subprocess.Popen([r'c:\shake91.exe', 'FLAC.txt', 'a.txt', 'b.txt'])
> 
> The dos program pops up and if I hit the enter key three times then it
> runs. How can I add these three “enters” into the script?

Then perhaps something more like this (untested) ...

from subprocess import Popen, PIPE
proc = Popen([r'c:\shake91.exe'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate('FLAC.txt\na.txt\nb.txt\n')

If that doesn't work you may need something like 'expect' for windows
(or, pexpect and cygwin).

HTH,
Marty


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difflib comparing string sequnces

2010-03-10 Thread Vincent Davis
@Ricardo Aráoz
Thanks for your response, Before I saw your response I had posted the
question on stack overflow. See link below. I like your solution better than
the re solution posted.
It looks like this task may take longer than I think. The .re solution I
guess might take more than 10 days. The search string in 80million digits
long. But Obviously I can stop once I find a match and then just move on the
the next sequence.
You might what to post this answer on stackoverflow. I like the more
interactive form of a mailing list but there seems to be a very p\broad
audience on stackoverflow.

Thanks again,
http://stackoverflow.com/questions/2420412/search-for-string-allowing-for-one-mismatches-in-any-location-of-the-string-pyth

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog  |
LinkedIn


2010/3/10 Ricardo Aráoz 

>  Vincent Davis wrote:
>
> I have never used the difflib or similar and have a few questions.
> I am working with DNA sequences of length 25. I have a list of 230,000 and
> need to look for each sequence in the entire genome (toxoplasma parasite) I
> am not sure how large the genome is but more that 230,000 sequences.
> The are programs that do this and really fast, and they eve do partial
> matches but not quite what I need. So I am looking to build a custom
> solution.
> I need to look for each of my sequences of 25 characters example(
> AGCCTCCCATGATTGAACAGATCAT).
> The genome is formatted as a continuos string
> (CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG.)
>
>  I don't care where or how many times on if it exists. This is simple I
> think, str.find(AGCCTCCCATGATTGAACAGATCAT)
>
>  But I also what to find a close match defined as only wrong at 1 location
> and I what to record the location. I am not sure how do do this. The only
> thing I can think of is using a wildcard and performing the search with a
> wildcard in each position. ie 25 time.
> For example
> AGCCTCCCATGATTGAACAGATCAT
> AGCCTCCCATGATAGAACAGATCAT
> close match with a miss-match at position 13
>
>
> also :
>
> sequence = 'AGGCTTGCGGAGCCTGAGGGCGGAG'
> seqList = ['*' + sequence[0:i] + '?' + sequence[i+1:] + '*' for i in
> range(len(sequence))]
> import fnmatch
>
> genome = 'CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG'
> if any(fnmatch.fnmatch(genome, i) for i in seqList)
> print 'It matches'
>
> Which might be better if the sequence is fixed and the genome changes
> inside a loop.
>
> HTH
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Feedparser and Google News feeds

2010-03-10 Thread David Kim
I have been working through some of the examples in the Programming
Collective Intelligence book by Toby Segaran. I highly recommend it, btw.

Anyway, some of the exercises use feedparser to pull in RSS/Atom feeds from
different sources (before doing more interesting things). The algorithm
stuff I pretty much follow, but one thing is driving me CRAZY: I can't seem
to pull more than 10 items from a google news feed. For example, I'd like to
pull 1000 google news items (using some search term, let's say
'lightsabers'). The associated atom feed url, however, only holds ten items.
And its hard to do some of the clustering analysis with only ten items!

Anyway, I imagine this must be a straightforward thing and I'm being a
moron, but I don't know where else to ask this question (none of my friends
are web-savvy programmers). I did see some posts about an n=100 term one can
add to the url (the limit seems to be 100 items), but it only seems to
effect the webpage view and not the feed. I've also tried subscribing to the
feed in Google Reader and making the feed public, but I seem to be running
into the same problem. Is this a feedparser thing or a google thing?

The url I'm using is
http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&as_scoring=r&as_maxm=3&q=health+information+exchange&as_qdr=a&as_drrb=q&as_mind=8&as_minm=2&cf=all&as_maxd=100&output=rss

Can anyone help me? I'm tearing my hair out and want to choke my computer.
It's probably not relevant, but I'm running Snow Leopard and Python 2.6
(actually EPD 6.1).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timezone issues with datetime module.

2010-03-10 Thread DK
kushal gupta  gmail.com> writes:

> 
> Hi,  I am facing an issue with datetime module with some timezones 

You may want to check out the pytz library at http://pytz.sourceforge.net/ for
easier timezone manipulation.




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Feedparser and google news/google reader

2010-03-10 Thread David Kim
I have been working through some of the examples in the Programming
Collective Intelligence book by Toby Segaran. I highly recommend it, btw.

Anyway, one of the simple exercises required is using feedparser to pull in
RSS/Atom feeds from different sources (before doing more interesting
things). The algorithm stuff I pretty much follow, but one thing is driving
me CRAZY. I can't seem to pull more than 10 items from a google news feed.
For example, I'd like to pull 1000 google news items (using some search
term, let's say 'lightsabers'). The associated atom feed url, however, only
holds ten items. And its hard to do some of the clustering exercises with
only ten items!

Anyway, I imagine this must be a straightforward thing and I'm being a
moron, but I don't know where else to ask this question. I did see some
posts about an n=100 term one can add to the url (the limit seems to be 100
items), but it only seems to effect the webpage view and not the feed. I've
also tried subscribing to the feed in Google Reader and making the feed
public, but I seem to be running into the same problem. Is this a feedparser
thing or a google thing?

The url I'm using is
http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&as_scoring=r&as_maxm=3&q=health+information+exchange&as_qdr=a&as_drrb=q&as_mind=8&as_minm=2&cf=all&as_maxd=100&output=rss

Can anyone help me? I'm tearing my hair out and want to choke my computer.
It's probably not relevant, but I'm running Snow Leopard and Python 2.6
(actually EPD 6.1).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Feedparser and google news/google reader

2010-03-10 Thread Alan Gauld

"David Kim"  wrote

me CRAZY. I can't seem to pull more than 10 items from a google news 
feed.

For example, I'd like to pull 1000 google news items (using some search
term, let's say 'lightsabers'). The associated atom feed url, however, 
only

holds ten items. And its hard to do some of the clustering exercises with
only ten items!


I have no idea if this is relevantt and without code I suspect we will all
be guessing blindly but...

Have you checked Google's terms of use? I know they make it hard to
screen scrape their search engine so they may have similar limits on
their feeds. Just a thought.

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor