Re: [Tutor] IDLE/phythonWin -- Who's On First? (Abbott and Costello)

2009-02-11 Thread Alan Gauld


"Wayne Watson"  wrote


Signature.htmlMy program in IDLE bombed with:
==
Exception in Tkinter callback
Traceback (most recent call last):
   dialog = OperationalSettingsDialog( self.master, set_loc_dict )
   tkSimpleDialog.Dialog.__init__(self, parent)
   self.wait_visibility() # window needs to be visible for the grab



But runs fine in pythonWin performing the same entry operation.


Lets eliminate some variables by avoiding any IDEs.

Does it work OK when run from a DOS console?
Or if you just double click the file in Windows explorer?

If it does that means its some kind of interaction between the program
and IDLE. This is not unusual since IDLE is itself a Tkinter program
and although recent versions are much better behaved with Tkinter
it can still cause some strangeness.

If you still get an error running outside the IDE then we can analyze
it more closely. For that we will need the code, at least the function
that calls the dialog. And if its a subclass the dialog class too.

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


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


Re: [Tutor] IDLE

2009-02-11 Thread Alan Gauld


"WM."  wrote

Allen G.asked me how I made IDLE work. I did nothing on purpose. One 
can open Python into the IDLE window or into the program window.


I assume you mean the editor window?

Yes that will produce proper indentation, it is only the shell window 
that

is broken because the >>> prompt produces an offset in the first line.

changed from the program window to the IDLE window. IDLE now works 
exactly right.


Except you don't evaluate the expressions as you type them which
is what tbe shell window does... You need to run the program.

As a bonus my DOS-idle window which used to produce error messages 
now works like a Trojan, also.


I don't know what you mean by the dos-idle window?

Alan G. 



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


Re: [Tutor] IDLE/phythonWin -- Who's On First? (Abbott and Costello)

2009-02-11 Thread Wayne Watson
Title: Signature.html




I ran it w/o using either IDLE/pyWin, and it worked without any
messages, as shown by the console window. Isn't this the same as using
the console? 

Outside of the two, my guess is that some subtle was made to the code,
accidentally, and one tolerates it and the other doesn't. I'm going to
do a WinMerge compare between the current py and a slightly older one. 

Alan Gauld wrote:

"Wayne Watson"  wrote
  
  
  Signature.htmlMy program in IDLE bombed with:

==

Exception in Tkinter callback

Traceback (most recent call last):

   dialog = OperationalSettingsDialog( self.master, set_loc_dict )

   tkSimpleDialog.Dialog.__init__(self, parent)

   self.wait_visibility() # window needs to be visible for the grab

  
  
  But runs fine in pythonWin performing the
same entry operation.

  
  
Lets eliminate some variables by avoiding any IDEs.
  
  
Does it work OK when run from a DOS console?
  
Or if you just double click the file in Windows explorer?
  
  
If it does that means its some kind of interaction between the program
  
and IDLE. This is not unusual since IDLE is itself a Tkinter program
  
and although recent versions are much better behaved with Tkinter
  
it can still cause some strangeness.
  
  
If you still get an error running outside the IDE then we can analyze
  
it more closely. For that we will need the code, at least the function
  
that calls the dialog. And if its a subclass the dialog class too.
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)



The Richard Feynman Problem-Solving
Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.



Web Page: 



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


Re: [Tutor] IDLE/phythonWin -- Who's On First? (Abbott and Costello)

2009-02-11 Thread Wayne Watson
Title: Signature.html




Using WinMerge, I found a difference between the two that shouldn't
have been, but it didn't solve the problem.

dialog.rateVar.get() versus dialog.rateVar.get

There was another like it with get(), but it wouldn't have been
executed in my test run. 

I suspect something else like that lurks in the code.

Wayne Watson wrote:

  
I ran it w/o using either IDLE/pyWin, and it worked without any
messages, as shown by the console window. Isn't this the same as using
the console? 
  
Outside of the two, my guess is that some subtle was made to the code,
accidentally, and one tolerates it and the other doesn't. I'm going to
do a WinMerge compare between the current py and a slightly older one. 
  
Alan Gauld wrote:
  
"Wayne Watson" 
wrote 

Signature.htmlMy program in IDLE bombed
with: 
== 
Exception in Tkinter callback 
Traceback (most recent call last): 
   dialog = OperationalSettingsDialog( self.master, set_loc_dict ) 
   tkSimpleDialog.Dialog.__init__(self, parent) 
   self.wait_visibility() # window needs to be visible for the grab 


But runs fine in pythonWin performing the
same entry operation. 


Lets eliminate some variables by avoiding any IDEs. 

Does it work OK when run from a DOS console? 
Or if you just double click the file in Windows explorer? 

If it does that means its some kind of interaction between the program 
and IDLE. This is not unusual since IDLE is itself a Tkinter program 
and although recent versions are much better behaved with Tkinter 
it can still cause some strangeness. 

If you still get an error running outside the IDE then we can analyze 
it more closely. For that we will need the code, at least the function 
that calls the dialog. And if its a subclass the dialog class too. 

  
  
  -- 
  
  
 Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

  
  
  The Richard Feynman
Problem-Solving
Algorithm:
    (1) write down the problem;
    (2) think very hard;
    (3) write down the answer.
  
  
  
Web Page: 
  
  

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


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)



The Richard Feynman Problem-Solving
Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.



Web Page: 



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


Re: [Tutor] Picking up citations

2009-02-11 Thread Kent Johnson
On Tue, Feb 10, 2009 at 5:54 PM, Kent Johnson  wrote:
> Another attempt attached, it recognizes the n. separator and gets the last 
> item.

And here is the actual attachment.

Kent
# Parser for legal citations, PLY version
# This version doesn't parse the names

from ply import lex, yacc

debug = 0

text = """Indemnified Capital Investments, S.A. v. R.J. O'Brien & Assoc., Inc., 12 F.3d 1406, 1409 (7th Cir.1993).
Hunt v. Washington Apple Advertising Commn., 432 U.S. 333, 343, 97 S.Ct. 2434, 2441, 53 L.Ed.2d 383 (1977)
Smith v. Wisconsin Dept. of Agriculture, 23 F.3d 1134, 1141 (7th Cir.1994)
 
see also Warth v. Seldin, 422 U.S. 490, 499 n. 10, 95 S.Ct. 2197, 2205 n. 10, 45 L.Ed.2d 343 (1975)

Idaho Conservation League v. Mumma, 956 F.2d 1508, 1517-18 (9th Cir.1992)
NFMA, NEPA, or MUSYA. Sierra Club v. Marita, 843 F.Supp. 1526 (E.D.Wis.1994) ("Nicolet ").
Page 500 Carter v. Jury Commission of Greene County, 396 U.S. 320, 90 S.Ct. 518, 24 L.Ed.2d 549 (1970); 
Lathe Turner v. Fouche, 396 U.S. 346, 90 S.Ct. 532, 24 L.Ed.2d 567 (1970); 
White v. Crook, 251 F.Supp. 401 (DCMD Ala.1966). 

Moreover, the Court has also recognized that the exclusion of a discernible class from jury service 
injures not only those defendants who belong to the excluded class, 
but other defendants as well, in that it destroys the possibility 
that the jury will reflect a representative cross section of the community. 

In John Doggone Williams v. Florida, 399 U.S. 78, 90 S.Ct. 1893, 234, 26 L.Ed.2d 446 (1970)"""

# Lexical tokens

tokens = (
   'NUMBER',
   'MIXED',
   'N',
   'YEAR',
)

literals = ",()-"

# Regular expression rules for simple tokens
t_NUMBER = r'\d+'
t_MIXED = r'[A-Za-z][A-Za-z.0-9\']+'  # References and names after the first work
t_YEAR = r'\([^)]+\)'   # Note: "year" can contain multiple words and non-numeric

# A string containing ignored characters (spaces and tabs)
t_ignore  = ' \t\r\n'

def t_N(t):
r'n\.'
return t

# Error handling rule
def t_error(t):
t.lexer.skip(1)

# Build the lexer
lexer = lex.lex()

def test_lexer(data):
lexer.input(data)

# Tokenize
while True:
tok = lexer.token()
if not tok: break  # No more input
print tok

# Parser productions

def p_Page(p):
'''page : NUMBER
  | NUMBER '-' NUMBER
  | NUMBER N NUMBER'''
if len(p) == 2:
p[0] = p[1]
elif p[2] == 'n.':
p[0] = '%s n. %s' % (p[1], p[3])
else:
p[0] = p[1] + p[2] + p[3]

def p_Reference(p):
'''reference : NUMBER MIXED page'''
p[0] = '%s %s %s' % (p[1], p[2], p[3])

def p_Reference_List(p):
'''reference_list : reference
  | reference_list ',' page
  | reference_list ',' reference
  | reference_list ',' page ',' reference'''

if len(p) == 2:
p[0] = [p[1]]   # single reference
elif len(p) == 4:
if p.slice[3].type == 'reference':
p[0] = p[1] + [p[3]]   # append new reference
else:
p[1][-1] += ', %s' % p[3]   # append page number
p[0] = p[1]
else:
# page number and reference
p[1][-1] += ', %s' % p[3]   # append page number
p[0] = p[1] + [p[5]]   # append new reference


def p_Citation(p):
'''citation : reference_list YEAR error
| reference_list YEAR'''
for reference in p[1]:
print '%s %s' % (reference, p[2])
print

def p_Citations(p):
'''citations : citation
 | citations citation'''
pass


def p_error(p):
pass

start = 'citations'


# Build the parser
parser = yacc.yacc()


if __name__ == '__main__':
parser.parse(text, debug=debug)

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


Re: [Tutor] Simple PassGen

2009-02-11 Thread Lie Ryan
On Wed, Feb 11, 2009 at 2:26 AM,  wrote:

>
> > Are you sure it isn't python 3.x you're playing with? The reason why
> simple print function "works" in python 2.x is because of a syntactical
> coincidence, it is still a 100% statement.
>
> Yes, I'm sure :) I restarted IDLE and pasted my session output below:



You didn't tell that you imported __future__'s print_function! I thought I
was having a hallucination or something... seeing that behavior in python2.6
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple PassGen

2009-02-11 Thread python
Lie,
The import from __future__ print_function happens automatically
in our environment and I took this for granted.
Sorry about the confusion :)
Regards,
Malcolm

- Original message -
From: "Lie Ryan" 
To: pyt...@bdurham.com
Cc: tutor@python.org
Date: Wed, 11 Feb 2009 23:16:11 +1100
Subject: Re: [Tutor] Simple PassGen

On Wed, Feb 11, 2009 at 2:26 AM, <[1]pyt...@bdurham.com> wrote:

  > Are you sure it isn't python 3.x you're playing with? The
  reason why simple print function "works" in python 2.x is
  because of a syntactical
  coincidence, it is still a 100% statement.
  Yes, I'm sure :) I restarted IDLE and pasted my session output
  below:


You didn't tell that you imported __future__'s print_function! I
thought I was having a hallucination or something... seeing that
behavior in python2.6

References

1. mailto:pyt...@bdurham.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Extracting information from an EXCEL/Matlab file to use in Python

2009-02-11 Thread Andres Sanchez
Fellows,

I am trying to extract information from a spreadsheet to use it in Python. For 
instance, say I have the number 5.6 in cell A1 of Sheet1 in the file 
example.xls . Could anyone of you ladies and gentleman let me know what 
commands I need to type in Pyhton to open the file that contains the 
spreadsheet, localize cell A1, and finally save the value in that cell, e.g. 
5.6, as a variable in Python?

Thank you for your help!!

Andres


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


Re: [Tutor] Extracting information from an EXCEL/Matlab file to use in Python

2009-02-11 Thread Shantanoo Mahajan (शंत नू महा जन)

On 12-Feb-09, at 1:31 AM, Andres Sanchez wrote:


Fellows,

I am trying to extract information from a spreadsheet to use it in  
Python. For instance, say I have the number 5.6 in cell A1 of Sheet1  
in the file example.xls . Could anyone of you ladies and gentleman  
let me know what commands I need to type in Pyhton to open the file  
that contains the spreadsheet, localize cell A1, and finally save  
the value in that cell, e.g. 5.6, as a variable in Python?


Thank you for your help!!

Andres


For reading .xls: http://pypi.python.org/pypi/xlrd/0.5.2
For writing .xls: http://sourceforge.net/projects/pyxlwriter/

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


Re: [Tutor] Extracting information from an EXCEL/Matlab file to use in Python

2009-02-11 Thread wesley chun
On Wed, Feb 11, 2009 at 12:16 PM, "Shantanoo Mahajan (शंतनू महाजन)"
 wrote:
> On 12-Feb-09, at 1:31 AM, Andres Sanchez wrote:
>
>> I am trying to extract information from a spreadsheet to use it in Python.
>
> For reading .xls: http://pypi.python.org/pypi/xlrd/0.5.2
> For writing .xls: http://sourceforge.net/projects/pyxlwriter/


pyXLWriter -- http://pypi.python.org/pypi/pyXLWriter

...stopped active development back in Aug 2004. it was "replaced" by...

pyExcelerator -- http://pypi.python.org/pypi/pyExcelerator

...which has also stopped development (last release was Aug 2005). now
ppl use...

 xlwt -- http://pypi.python.org/pypi/xlwt

... which appears to be actively maintained and developed.

xlrd and xlrt do not require a win32 box, i.e., you can use *ix/MacOS
to read/write .xls files. if you are an active win32 developer, you
may wish to consider Python's Extensions for Windows to
control/manipulate Excel directly -- http://pywin32.sf.net -- FWIW,
there is some info on how to do this in Chapter 23 of "Core Python
Programming".

hope this helps!
-wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Extracting information from an EXCEL/Matlab file to use in Python

2009-02-11 Thread wesley chun
>>> I am trying to extract information from a spreadsheet to use it in Python.
>> For reading .xls: http://pypi.python.org/pypi/xlrd/0.5.2


i forgot to mention that xlrd is on version 0.6.1 now:
http://pypi.python.org/pypi/xlrd

-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Python Web Development with Django", Addison Wesley, (c) 2009
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to foreach over a dynamic number of levels

2009-02-11 Thread Isaac Eiland-Hall
I'm probably trying to go about this the wrong way - so I'm asking more for
what direction to head in, at least.

 

The group I'm working with has a python program (the Model Framework) that
runs data through a number of models. For each possible step, there are
multiple possible models. Each run also is for a single date.

 

So the ini for Model Framework might be something like this:

 

step1 = step1model-a

step2 = step2model-a

step3 =  step3model-b

step4 = step4model-a

 

(so for any given step, one or more models exist. For a Model Framework run,
you choose one model for any given step you choose to run)

 

The program I'm working on will drive the framework and run it multiple
times. For example, to run a range of dates; but also, to run a range of
models - so you might want to run models a-h on days Jan1-Jan30 - that would
be 8 times 30 = 240 runs.

 

The program I'm working on needs to be Framework-agnostic. That is, I know
that the framework's ini file consists of a number of key and value pairs,
but my program has no concept of what these values *do*, or which ones
*exist*. The end-user will basically take a Framework ini file, and change
some values from strings to lists, for example:

 

step1=["step1model-a","step1model-b","step1model-c"]

 

My program will parse that, and know that it must iterate three times
because of that line alone.

 

So I do not know in advance how many keys I will have, nor how many of them
will be arrays vs. strings, although my initial thought is that I can treat
strings like single-member arrays - I don't care if I foreach a single time
- execution time on that order of magnitude is irrelevant.

 

I'm really not sure how in the world to accomplish this.

 

The best method I can think of would involve somehow iterating through and
generating code to exec, but frankly I don't even have that as a complete
working solution. The other thought would be a function that called itself,
but that is also very very ugly.

 

I come from PHP, where you have variable variables. I think that would help
me a lot here - I could at least dynamically nest my arrays, and call my
arrays using variable vars.

 

I'm definitely a pretty new programmer. I don't mind reading - but I've
spent about 6 hours today googling for terms like "dynamic nesting" and
found a lot of interesting stuff - but no clear direction to head in.

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


[Tutor] How to foreach over a dynamic number of levels

2009-02-11 Thread Isaac Eiland-Hall
I'm probably trying to go about this the wrong way - so I'm asking more for
what direction to head in, at least.

 

The group I'm working with has a python program (the Model Framework) that
runs data through a number of models. For each possible step, there are
multiple possible models. Each run also is for a single date.

 

So the ini for Model Framework might be something like this:

 

step1 = step1model-a

step2 = step2model-a

step3 =  step3model-b

step4 = step4model-a

 

(so for any given step, one or more models exist. For a Model Framework run,
you choose one model for any given step you choose to run)

 

The program I'm working on will drive the framework and run it multiple
times. For example, to run a range of dates; but also, to run a range of
models - so you might want to run models a-h on days Jan1-Jan30 - that would
be 8 times 30 = 240 runs.

 

The program I'm working on needs to be Framework-agnostic. That is, I know
that the framework's ini file consists of a number of key and value pairs,
but my program has no concept of what these values *do*, or which ones
*exist*. The end-user will basically take a Framework ini file, and change
some values from strings to lists, for example:

 

step1=["step1model-a","step1model-b","step1model-c"]

 

My program will parse that, and know that it must iterate three times
because of that line alone.

 

So I do not know in advance how many keys I will have, nor how many of them
will be arrays vs. strings, although my initial thought is that I can treat
strings like single-member arrays - I don't care if I foreach a single time
- execution time on that order of magnitude is irrelevant.

 

I'm really not sure how in the world to accomplish this.

 

The best method I can think of would involve somehow iterating through and
generating code to exec, but frankly I don't even have that as a complete
working solution. The other thought would be a function that called itself,
but that is also very very ugly.

 

I come from PHP, where you have variable variables. I think that would help
me a lot here - I could at least dynamically nest my arrays, and call my
arrays using variable vars.

 

I'm definitely a pretty new programmer. I don't mind reading - but I've
spent about 6 hours today googling for terms like "dynamic nesting" and
found a lot of interesting stuff - but no clear direction to head in.

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


[Tutor] Program to report if file was modified today

2009-02-11 Thread David

Hi Everyone and thanks for the list and your help.
In my adventure in learning Python (never programed before) I am 
attempting to findout if a file has been modified today given a search 
path. It is working somewhat. Here it is;


#!/usr/bin/python
import sys
import os
import time

def Mod():
"""Find files modified today, given a file path."""
latest = 0
dir = os.path.dirname(sys.argv[1])
for fname in os.listdir(dir):
if fname.endswith('.py'):
modtime = os.stat(os.path.join(dir, fname)).st_mtime
if modtime > latest:
latest = modtime
out = time.strftime('%Y-%m-%d', time.localtime(latest))
my_list = [fname, out]
print fname
now = time.strftime('%Y-%m-%d', time.localtime())
if my_list[-1] == now:
print "This file has changed today."
print "*"*30
else:
print "This file did not change"

results;
./py_lastmod_date.py /home/david/

py_pyparse_end.py
This file did not change
**
cologne_time.py
This file did not change
**
py_find_word_prefix.py
This file did not change
**
py_round_by_five.py
This file did not change
**
graphics.py
This file did not change
**
py_countdown_generator.py
This file did not change
**
py_compare_time.py
This file has changed today.
**
py_lastmod_date.py
This file has changed today.
**

OK here are my questions.
Is there an easier way of doing this?
Why does it only return 8 results, I have a ton of .py files in /home/david
Why do both the if and else get printed?
How do I do this without all the if statments?
I don't understand the if modtime > latest part, is this to loop over 
the files and put the oldest last? I found that part in another program 
and my program does not work without it.

Thank you,
-david


--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu

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


Re: [Tutor] How to foreach over a dynamic number of levels

2009-02-11 Thread Kent Johnson
On Wed, Feb 11, 2009 at 6:20 PM, Isaac Eiland-Hall  wrote:

> The group I'm working with has a python program (the Model Framework) that
> runs data through a number of models. For each possible step, there are
> multiple possible models. Each run also is for a single date.
>
> So the ini for Model Framework might be something like this:
>
> step1 = step1model-a
>
> step2 = step2model-a
>
> step3 =  step3model-b
>
> step4 = step4model-a

> The program I'm working on will drive the framework and run it multiple
> times. For example, to run a range of dates; but also, to run a range of
> models – so you might want to run models a-h on days Jan1-Jan30 – that would
> be 8 times 30 = 240 runs.
>
>  The end-user will basically take a Framework ini file, and change
> some values from strings to lists, for example:
>
> step1=["step1model-a","step1model-b","step1model-c"]
>
>
>
> My program will parse that, and know that it must iterate three times
> because of that line alone…
>
>
>
> So I do not know in advance how many keys I will have, nor how many of them
> will be arrays vs. strings, although my initial thought is that I can treat
> strings like single-member arrays – I don't care if I foreach a single time
> – execution time on that order of magnitude is irrelevant…
>
>
>
> I'm really not sure how in the world to accomplish this…
>
>
>
> The best method I can think of would involve somehow iterating through and
> generating code to exec, but frankly I don't even have that as a complete
> working solution… The other thought would be a function that called itself,
> but that is also very very ugly…

It's much easier than that. You haven't asked about reading the ini
file or running the model, so I'll leave that for another time.

Let's assume you have the steps read in to variables like this:
step1=["step1model-a","step1model-b","step1model-c"]
step2 = "step2model-a"
step3 =  ["step3model-a", "step3model-b"]

Make a list containing all the steps:
steps = [step1, step2, step3]

Now you need to convert all steps to lists. This loop builds a new
list from the original step list, wrapping any bare strings in lists:

step_lists = []
for step in steps:
if isinstance(step, basestring):
step = [step]
step_lists.append(step)

Now what you want is the Cartesian product of all the lists. Python
has a function (new in Python 2.6) in the itertools library module
that will do this:

from itertools import product
for model_set in product(*step_lists):
print model_set

(The * in the argument list means, take the elements of step_list and
use them as the arguments to product())

The output is
('step1model-a', 'step2model-a', 'step3model-a')
('step1model-a', 'step2model-a', 'step3model-b')
('step1model-b', 'step2model-a', 'step3model-a')
('step1model-b', 'step2model-a', 'step3model-b')
('step1model-c', 'step2model-a', 'step3model-a')
('step1model-c', 'step2model-a', 'step3model-b')

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


Re: [Tutor] Program to report if file was modified today

2009-02-11 Thread bob gailer

David wrote:

Hi Everyone and thanks for the list and your help.
In my adventure in learning Python (never programed before) I am 
attempting to findout if a file has been modified today given a search 
path. It is working somewhat. Here it is;


#!/usr/bin/python
import sys
import os
import time

def Mod():
"""Find files modified today, given a file path."""
latest = 0
dir = os.path.dirname(sys.argv[1])
for fname in os.listdir(dir):
if fname.endswith('.py'):
modtime = os.stat(os.path.join(dir, fname)).st_mtime
if modtime > latest:
latest = modtime
out = time.strftime('%Y-%m-%d', time.localtime(latest))
my_list = [fname, out]
print fname
now = time.strftime('%Y-%m-%d', time.localtime())
if my_list[-1] == now:
print "This file has changed today."
print "*"*30
else:
print "This file did not change"



1) That can't be the entire program, as there is no call to Mod()!
2) Convention says function names start with lower case. Save initial 
caps for class names.

3) Get rid of latest - that is why you are not getting all the files.
4) Use glob.glob() so you can specify *.py
5) It is not necessary to convert times to strings. You can get midnight 
today from int(time.localtime())

6) Move calculation of now outside the loop, as it does not change.
7) my_list is not necessary.
8) revised (untested) code:


#!/usr/bin/python
import sys
import os
import time
import glob

def mod():
   """Find files modified today, given a file path."""
   dir = os.path.dirname(sys.argv[1])
   start_of_today = int(time.localtime())
   for fname in glob.glob(dir + '/*.py'):
   modtime = os.stat(os.path.join(dir, fname)).st_mtime
   print fname
   if modtime >= start_of_today:
   print "This file has changed today."
   print "*"*30
   else:
   print "This file did not change"
mod()



results;
./py_lastmod_date.py /home/david/

py_pyparse_end.py
This file did not change
**
cologne_time.py
This file did not change
**
py_find_word_prefix.py
This file did not change
**
py_round_by_five.py
This file did not change
**
graphics.py
This file did not change
**
py_countdown_generator.py
This file did not change
**
py_compare_time.py
This file has changed today.
**
py_lastmod_date.py
This file has changed today.
**

OK here are my questions.
Is there an easier way of doing this?
Why does it only return 8 results, I have a ton of .py files in 
/home/david

Why do both the if and else get printed?
How do I do this without all the if statments?
I don't understand the if modtime > latest part, is this to loop over 
the files and put the oldest last? I found that part in another 
program and my program does not work without it.

Thank you,
-david





--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program to report if file was modified today

2009-02-11 Thread Kent Johnson
On Wed, Feb 11, 2009 at 8:46 PM, bob gailer  wrote:

> 5) It is not necessary to convert times to strings. You can get midnight
> today from int(time.localtime())

??
In [1]: import time

In [2]: time.localtime()
Out[2]: time.struct_time(tm_year=2009, tm_mon=2, tm_mday=11,
tm_hour=21, tm_min=20, tm_sec=11, tm_wday=2, tm_yday=42, tm_isdst=0)

In [4]: int(time.localtime())
TypeError: int() argument must be a string or a number, not 'time.struct_time'

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


Re: [Tutor] Program to report if file was modified today

2009-02-11 Thread David

bob gailer wrote:


1) That can't be the entire program, as there is no call to Mod()!

Yep, it was lost in my copy paste
2) Convention says function names start with lower case. Save initial 
caps for class names.

Thanks for the reminder, I had forgotten :)

3) Get rid of latest - that is why you are not getting all the files.

For some reason when I take that out it reports all file have been modified.

4) Use glob.glob() so you can specify *.py
5) It is not necessary to convert times to strings. You can get midnight 
today from int(time.localtime())

OK

6) Move calculation of now outside the loop, as it does not change.

Good Point, makes since now.

7) my_list is not necessary.
Ok, my reason was to make sure the file and date remained together but 
It works fine without it.

8) revised (untested) code:

I get this error with the int(time.localtime())
 start_of_today = int(time.localtime())
TypeError: int() argument must be a string or a number, not 
'time.struct_time'


Thanks Bob,
I really only want it to report when a file has been modified so this 
seems to work, next I will work on putting glob.glob working plus any 
other suggestions.


#!/usr/bin/python
import sys
import os
import time

def mod():
"""Find files modified today, given a file path."""
latest = 0
now = time.strftime('%Y-%m-%d', time.localtime())
dir = os.path.dirname(sys.argv[1])
for fname in os.listdir(dir):
if fname.endswith('.py'):
modtime = os.stat(os.path.join(dir, fname)).st_mtime
if modtime > latest:
latest = modtime
out = time.strftime('%Y-%m-%d', time.localtime(latest))
if out == now:
print fname, "has changed today. "
else:
pass
mod()

results;
david [09:25 PM] opteron ~ $ ./py_lastmod_date.py /home/david/
py_compare_time.py has changed today.
py_lastmod_date.py has changed today.

-david

--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu

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


[Tutor] Keeping Dictonary Entries Ordered

2009-02-11 Thread Wayne Watson
Title: Signature.html




I have a dictionary that looks like:

config_names = {"start_time : '18:00:00', 'gray_scale' : True, "long":
120.00}

If I iterate over it, the entries will appear in any order, as opposed
to what I see above. However, in the config file, I'd like to keep them
in the order above. That I want to write the config file in order.
Perhaps, I need a list like c_names = ["start_time", "gray_scale",
"long"] to get the keys out in the order I need? Maybe there's another
way?
-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)



The Richard Feynman Problem-Solving
Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.



Web Page: 



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


Re: [Tutor] [tutor] IDLE

2009-02-11 Thread WM.

At one time I could not run a skit in IDLE nor with the command line.
IDLE gave error messages because (Alan G. says) of the 3 chevrons.
The command opened into a wee square & issued only error messages.
Then the command line opened into a 4x7 box and worked perfectly.
IDLE also now works perfectly, whether I open into IDLE or edit window.
Below is a copy/paste:

IDLE 2.6
>>> i = 9
>>> while i > 2:
print i
i -= 1


9
8
7
6
5
4
3
>>>

just so, with no adjustments
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-11 Thread Eric Dorsey
>>> config_names = {'start_time': '18:00:00', 'gray_scale': True, 'long':
120.0}

>>> config_names
{'start_time': '18:00:00', 'gray_scale': True, 'long': 120.0}
>>> for i, x in config_names.items():
... print i, x
...
start_time 18:00:00
gray_scale True
long 120.0
>>>

On Wed, Feb 11, 2009 at 7:48 PM, Wayne Watson
wrote:

>  I have a dictionary that looks like:
>
> config_names = {"start_time : '18:00:00', 'gray_scale' : True, "long":
> 120.00}
>
> If I iterate over it, the entries will appear in any order, as opposed to
> what I see above. However, in the config file, I'd like to keep them in the
> order above. That I want to write the config file in order. Perhaps, I need
> a list like c_names = ["start_time", "gray_scale", "long"] to get the keys
> out in the order I need? Maybe there's another way?
> --
>
>Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
>  (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
>
>  *The Richard Feynman Problem-Solving Algorithm:*
> *  (1) write down the problem;*
> *  (2) think very hard;*
> *  (3) write down the answer.***
>  **
>
> **Web Page: 
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program to report if file was modified today

2009-02-11 Thread bob gailer

David wrote:

I get this error with the int(time.localtime())
 start_of_today = int(time.localtime())
TypeError: int() argument must be a string or a number, not 
'time.struct_time'


Should have been start_of_today = int(time.time())

--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-11 Thread Wayne Watson




Looks good. Thanks.

Eric Dorsey wrote:

  
  
  >>> config_names = {'start_time': '18:00:00',
'gray_scale': True, 'long': 120.0}
  
  
  >>> config_names
  {'start_time': '18:00:00', 'gray_scale': True, 'long': 120.0}
  >>> for i, x in config_names.items():
  ...     print i, x
  ...
  start_time 18:00:00
  gray_scale True
  long 120.0
  >>>
  
  
  
  On Wed, Feb 11, 2009 at 7:48 PM, Wayne
Watson 
wrote:
  
I have a dictionary that
looks like:

config_names = {"start_time : '18:00:00', 'gray_scale' : True, "long":
120.00}

If I iterate over it, the entries will appear in any order, as opposed
to what I see above. However, in the config file, I'd like to keep them
in the order above. That I want to write the config file in order.
Perhaps, I need a list like c_names = ["start_time", "gray_scale",
"long"] to get the keys out in the order I need? Maybe there's another
way?
-- 
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)



The Richard Feynman
Problem-Solving
Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.


Web Page: 



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

  
  
  


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)



The Richard Feynman Problem-Solving
Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.



Web Page: 



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


Re: [Tutor] Python & MySQL... Define port.

2009-02-11 Thread wormwood_3
Hello,

You can specify the port of the instance you want to connect to simply by 
passing "port=NUM" in MySQLdb.connect(). Here is a formulation I have found 
generally useful:

import MySQLdb

def run_mysql(query, db, user, passwd, port=3306, 
socket="/var/run/mysqld/mysqld.sock", host="localhost"):
"""Runs query passed with connection info passed, returns results."""
try:
db = MySQLdb.connect(user=user, passwd=passwd, db=db, port=port, 
unix_socket=socket, host=host)
except MySQLdb.Error, e:
raise e
cursor = db.cursor()
cursor.execute(query)
data = cursor.fetchall()
db.close()
return data


This sets common defaults, but you can of course pass in whatever you want when 
you call it. 

You might also want to check out the MySQLdb docs: 
http://mysql-python.sourceforge.net/MySQLdb.html. It contains a number of 
examples.

___
Samuel Huckins


Homepage - http://samuelhuckins.com
Tech blog - http://dancingpenguinsoflight.com/
Photos - http://www.flickr.com/photos/samuelhuckins/
AIM - samushack | Gtalk - samushack | Skype - shuckins





From: Network Administrator 
To: tutor@python.org
Sent: Monday, February 9, 2009 1:29:21 PM
Subject: [Tutor] Python & MySQL... Define port.

Hello everybody!


I want to use Python to query a given MySQL database. However, this database is 
running on port 3308, instead the traditional 3306.

I read that (example):

MySQLdb.connect(host="dbserv', db='inv', user='smith')

can be used to query a given database; however, it didn't work in my particular 
case. This is my code:

connection = MySQLdb.connect (db = "netlogin", user="netadmin", pass = "r4nas", 
port="3308")

I appreciate if you give me assistance in the proper sintax of the last 
mentioned instruction.

Regards,



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


Re: [Tutor] IDLE/phythonWin -- Who's On First? (Abbott and Costello)

2009-02-11 Thread Wayne Watson




This appears to be an old problem.
.
However, the question remains. What to do about it? reboot? I killed
about a dozen pythonwin.exe task, but to no avail. 

Wayne Watson wrote:

  
Using WinMerge, I found a difference between the two that shouldn't
have been, but it didn't solve the problem.
  
dialog.rateVar.get() versus dialog.rateVar.get
  
There was another like it with get(), but it wouldn't have been
executed in my test run. 
  
I suspect something else like that lurks in the code.
  
Wayne Watson wrote:
  

I ran it w/o using either IDLE/pyWin, and it worked without any
messages, as shown by the console window. Isn't this the same as using
the console? 

Outside of the two, my guess is that some subtle was made to the code,
accidentally, and one tolerates it and the other doesn't. I'm going to
do a WinMerge compare between the current py and a slightly older one. 

Alan Gauld wrote:

"Wayne Watson" 
wrote 
  
  Signature.htmlMy program in IDLE bombed
with: 
== 
Exception in Tkinter callback 
Traceback (most recent call last): 
   dialog = OperationalSettingsDialog( self.master, set_loc_dict ) 
   tkSimpleDialog.Dialog.__init__(self, parent) 
   self.wait_visibility() # window needs to be visible for the grab 
  
  
  But runs fine in pythonWin performing the
same entry operation. 
  
  
Lets eliminate some variables by avoiding any IDEs. 
  
Does it work OK when run from a DOS console? 
Or if you just double click the file in Windows explorer? 
  
If it does that means its some kind of interaction between the program 
and IDLE. This is not unusual since IDLE is itself a Tkinter program 
and although recent versions are much better behaved with Tkinter 
it can still cause some strangeness. 
  
If you still get an error running outside the IDE then we can analyze 
it more closely. For that we will need the code, at least the function 
that calls the dialog. And if its a subclass the dialog class too. 
  


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

  

The Richard Feynman
Problem-Solving
Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.



Web Page: 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  
  
  
  -- 
  
  Signature.html
 Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

  
  
  The Richard Feynman
Problem-Solving
Algorithm:
    (1) write down the problem;
    (2) think very hard;
    (3) write down the answer.
  
  
  
Web Page: 
  
  

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


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)



The Richard Feynman Problem-Solving
Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.



Web Page: 



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