[Tutor] question regarding python exception handling

2005-01-29 Thread Roy
Hello, there:

I am learning about python exception handling. I am reading "Python in
a Nutshell". In the chapter of exception handling, it says: Note that
the try/finally form is distinct from the try/except form: a try
statement cannot have both except and finally clauses, as execution
order might be ambiguous.

I don't understand the reason why except and finally clauses cannot be
together. I know they can be together in java. how does it cause
ambiguous execution order? An example may help me understand.

Thank you very much!

--
Roy

**May I open-source your mind?**
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Naming conventions (was: Should this be a list comprehension or something?

2005-01-29 Thread Liam Clarke
Don't get me wrong, underscores have their place, 
butNotInEveryVariableName.
That_was_only_slightly_less_annoying, however.

I propose a new syntax -

All methods, shall be called Jacques, or a derivative thereof (Jack, Jake etc.)

All variables, Claude.

Oh, and you could use funny little symbols like @_> to clarify the
whole situation

(in other words, Python is always more readable then certain camels.)


On Sat, 29 Jan 2005 09:10:49 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
> iguessthereisnooptionleftexcepttorunwordstogetherwithoutanykindofbreakatall
> 
> thatshouldannoyeveryoneequally
> 
> Kent
> 
> Liam Clarke wrote:
> > Just please_don't_use_underscores.
> >
> > They_make_my_eyes_go_funny_, _and_code_hard_to_read_in_my_opinion.
> >
> > _u_n_d_e_r_s_c_o_r_e_s_ _a_r_e__u_g_l_y_
> >
> > I got out of the habit of using them really fast.
> > Also, __ & _ tend to have special meaning in Python (which is bad
> > enough as it is), so I don't use them for that reason as well.
> >
> >
> > Liam Clarke
> > On Fri, 28 Jan 2005 22:54:08 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
> >
> >>You're my best friend. Everyone else looves camelCase, and I hate it too. It
> >>doesn't make sense. It doesn't fit English.
> >>It doesn't fit Spanish. It doesn't fit any other language AFAIK, so why
> >>should a human (who uses spoken language) to computer interpreter use a
> >>naming convention that doesn't match spoken language? That's my opinion.
> >>
> >>Jacob Schmidt
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] carriage return on windows

2005-01-29 Thread Orri Ganel
Jacob S. wrote:
Thanks Kent and Max!
Wow, I didn't know it did that. I'm too dumb to figure it out on my 
own I guess...
Oh well! I found a cool new thing to play with at least!

Thanks,
Jacob

On Jan 30, 2005, at 02:40, Jacob S. wrote:
I don't think that's what he wants. I think he wants to *overwrite* 
what's in the shell with new output.
For example.

so that the whole line is overwritten. In my experience, this is not 
possible and if anyone can show me how to do it,
I would be grateful.

HTH,
Jacob

It *is* possible, that's exactly what my code does (well, as long as 
you don't run it on Mac OS 9). The carriage return (\r, as opposed to 
the linefeed \n) moves the cursor to the beginning of the *current* 
line.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge 
a perfect, immortal machine?"


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Just a note: This does not work on IDLE, so for those who try this and 
are frustrated when it fails, try it in the dos-box (command prompt).

--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] carriage return on windows

2005-01-29 Thread Jacob S.
Thanks Kent and Max!
Wow, I didn't know it did that. I'm too dumb to figure it out on my own I 
guess...
Oh well! I found a cool new thing to play with at least!

Thanks,
Jacob

On Jan 30, 2005, at 02:40, Jacob S. wrote:
I don't think that's what he wants. I think he wants to *overwrite* 
what's in the shell with new output.
For example.

so that the whole line is overwritten. In my experience, this is not 
possible and if anyone can show me how to do it,
I would be grateful.

HTH,
Jacob
It *is* possible, that's exactly what my code does (well, as long as you 
don't run it on Mac OS 9). The carriage return (\r, as opposed to the 
linefeed \n) moves the cursor to the beginning of the *current* line.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and 
sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"


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


Re: [Tutor] carriage return on windows

2005-01-29 Thread Max Noel
On Jan 30, 2005, at 02:40, Jacob S. wrote:
I don't think that's what he wants. I think he wants to *overwrite* 
what's in the shell with new output.
For example.

so that the whole line is overwritten. In my experience, this is not 
possible and if anyone can show me how to do it,
I would be grateful.

HTH,
Jacob
	It *is* possible, that's exactly what my code does (well, as long as 
you don't run it on Mac OS 9). The carriage return (\r, as opposed to 
the linefeed \n) moves the cursor to the beginning of the *current* 
line.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

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


Re: [Tutor] carriage return on windows

2005-01-29 Thread Kent Johnson
It seems to work fine in Win2k command shell; try this:
 >>> import time
 >>> time.sleep(1)
 >>> for i in range(9):
 ...   print 'i is', i, '\r',
 ...   time.sleep(1)
I get all the output on one line.
Kent
Jacob S. wrote:
I don't think that's what he wants. I think he wants to *overwrite* 
what's in the shell with new output.
For example.

Python 2.4 (#Stuff)
...

Percent complete: 50
becomes...
Python2.4(#Stuff)
...

Percent complete: 51
so that the whole line is overwritten. In my experience, this is not 
possible and if anyone can show me how to do it,
I would be grateful.

HTH,
Jacob

On Jan 30, 2005, at 02:18, R. Alan Monroe wrote:

print "Percent completed:" + str(percent) + "\r"

Print forces a newline.
Try sys.stdout.write instead.
Alan

You can also use the following syntax:
>>> print "Percent completed:", str(percent), "\r",
The trailing comma is NOT a typo, it is intentional. It prevents print 
from appending a newline.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge 
a perfect, immortal machine?"

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

___
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] carriage return on windows

2005-01-29 Thread Jacob S.
I don't think that's what he wants. I think he wants to *overwrite* what's 
in the shell with new output.
For example.

Python 2.4 (#Stuff)
...

Percent complete: 50
becomes...
Python2.4(#Stuff)
...

Percent complete: 51
so that the whole line is overwritten. In my experience, this is not 
possible and if anyone can show me how to do it,
I would be grateful.

HTH,
Jacob

On Jan 30, 2005, at 02:18, R. Alan Monroe wrote:

print "Percent completed:" + str(percent) + "\r"
Print forces a newline.
Try sys.stdout.write instead.
Alan
You can also use the following syntax:
>>> print "Percent completed:", str(percent), "\r",
The trailing comma is NOT a typo, it is intentional. It prevents print 
from appending a newline.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and 
sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

___
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] Naming conventions (was: Should this be alist comprehension or something?

2005-01-29 Thread Jacob S.
I just read your post a heck of alot easier than I read Liam's. ;-)
Jacob Schmidt
iguessthereisnooptionleftexcepttorunwordstogetherwithoutanykindofbreakatall
thatshouldannoyeveryoneequally
Kent
Liam Clarke wrote:
Just please_don't_use_underscores. They_make_my_eyes_go_funny_, 
_and_code_hard_to_read_in_my_opinion.

_u_n_d_e_r_s_c_o_r_e_s_ _a_r_e__u_g_l_y_
I got out of the habit of using them really fast.
Also, __ & _ tend to have special meaning in Python (which is bad
enough as it is), so I don't use them for that reason as well.
Liam Clarke
On Fri, 28 Jan 2005 22:54:08 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
You're my best friend. Everyone else looves camelCase, and I hate it too. 
It
doesn't make sense. It doesn't fit English.
It doesn't fit Spanish. It doesn't fit any other language AFAIK, so why
should a human (who uses spoken language) to computer interpreter use a
naming convention that doesn't match spoken language? That's my opinion.

Jacob Schmidt
___
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] Control flow

2005-01-29 Thread Jacob S.
I noticed that too, Liam.
b = input("Weather is really bad, still go out to jog? [y/n]") # Would 
it kill you to have whitespace in a prompt?
should really be
b = raw_input("Weather is really bad, still go out to jog? [y/n]")
to get the effect he wants.

input() doesn't only take integers, it takes valid python objects. Integers 
are objects, but so are lists, dictionaries, tuples,
actually it takes everything, BUT!!! it trys to return a valid python object 
for input.
So it will take a string--don't quote me on this--if you explicitly put the 
string in quotes.
If you don't put the string in quotes, it instead searches the namespaces 
for that object.
So say the user typed in bad_weather when the interpreter gave that prompt. 
Then, b == "y" evaluates true because bad_weather == "y". Did I explain it 
right? Or am I trying to explain something you already know? I know I get 
frustrated when people try to explain concepts that I already know...

HTH,
Jacob Schmidt
< erk, to the list, to the List!>
if ( bad_weather =='y' ):
  # ask user only if weather is bad.
  b = input ( "Weather is really bad, still go out to jog?[y/n]" )
  if b == 'y':
 go_jogging()
Anyone else notice that he's never gonna go jogging if the weather is bad?
Unless I've got input() wrong, it only takes integers... ?
Regards,
Liam Clarke
--
'There is only one basic human right, and that is to do as you damn well 
please.
And with it comes the only basic human duty, to take the consequences.

--
'There is only one basic human right, and that is to do as you damn well 
please.
And with it comes the only basic human duty, to take the consequences.
___
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] carriage return on windows

2005-01-29 Thread Max Noel
On Jan 30, 2005, at 02:18, R. Alan Monroe wrote:

print "Percent completed:" + str(percent) + "\r"
Print forces a newline.
Try sys.stdout.write instead.
Alan
You can also use the following syntax:
>>> print "Percent completed:", str(percent), "\r",
	The trailing comma is NOT a typo, it is intentional. It prevents print 
from appending a newline.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

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


Re: [Tutor] carriage return on windows

2005-01-29 Thread R. Alan Monroe

> print "Percent completed:" + str(percent) + "\r"

Print forces a newline.
Try sys.stdout.write instead.

Alan

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


[Tutor] carriage return on windows

2005-01-29 Thread Bill Kranec
Hello,
I'm trying to have a loop in a program print a message so I know it's 
status.  Right now I'm using

print "Percent completed:" + str(percent) + "\r"
Which should send me back to the beginning of the line and overwrite it 
with a new line.  But instead I get:

Percent completed: 50
Percent completed: 51
Percent completed: 52
Percent completed: 53
and so on.  Am I using this wrong, and if so, what is the right way to 
implement something like this?

Thanks for any help!
Bill
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] range function

2005-01-29 Thread Danny Yoo


On Sat, 29 Jan 2005, Srinivas Iyyer wrote:

> I have bunch of coordinates for various vectors.
>
> small vecs:
>
> name  cord. Xcord. Y   Sector no.
> smvec175  1001aa
> smvec225  50 1aa
> smvec3135 1551ab
>
> large vecs:zone
> Lvec1 10  50  1aa  ut
> Lvec1 60  110 1aa  cd
> Lvec1 130 180 1ab  cd
>
> Now I am checking if small vecs are falling in which
> large vecs.


Hi Srivivas,


Some of the problem statement is confusing me slightly, since there's more
infomation here than just "vector" information.

Is it accurate to say that the essential part of the data is something
like this?

###
small_vecs = [ ("smvec1", 75, 100, "1aa"),
   ("smvec2", 25, 50, "1aa"),
   ("smvec3", 135, 155, "1ab") ]

large_vecs = [ ("Lvec1", 10, 50, "1aa", "ut"),
   ("Lvec1", 60, 110, "1aa", "cd"),
   ("Lvec1", 130, 180, "1ab", "cd") ]
###


Or do you really just care about a portion of the data?

###
small_vecs = [ ("smvec1", 75, 100),
   ("smvec2", 25, 50,),
   ("smvec3", 135, 155) ]

large_vecs = [ ("Lvec1", 10, 50),
   ("Lvec1", 60, 110),
   ("Lvec1", 130, 180) ]
###

I'm just trying to digest what part of the program we're trying to solve.
*grin*


Rather than work on text files directly as part of the algorithm, it might
be easier to split the problem into two pieces:

Part 1.  A function that takes the text file and turns it into a data
structure of Python tuples, lists, and numbers.

Part 2.  A function to do the matching against those data structures.

The reason this breakup might be useful is because you can test out the
vector-matching part of the program (Part 2) independently of the
file-reading-parsing part (Part 1).

And parsing files is sometimes really messy, and we often want to keep
that messiness localized in one place.  As a concrete example, we probably
need to do something like:

cols = line.split('\t')
(x, y) = (int(cols[1]), int(cols[2]))

where we have to sprinkle in some string-to-int stuff.




> The other way by taking tuples:
>
> for line in smallvecs:
>  cols = line.split('\t')
>  smvec_tup = zip(cols[1],cols[2])

zip() is probably not the best tool here.  We can just write out the tuple
directly, like this:

smvec_tup = (cols[1], cols[2])


zip() is meant for something else: here's an example:

###
>>> languages = ["Python", "Perl", "Java", "Ocaml", "C"]
>>> prefixes = ["py", "pl", "java", "ml", "c"]
>>> languages_and_prefixes = zip(languages, prefixes)
>>>
>>> print languages_and_prefixes
[('Python', 'py'), ('Perl', 'pl'), ('Java', 'java'), ('Ocaml', 'ml'),
 ('C', 'c')]
###

So zip() is more of a bulk-tuple constructing function: it's not really
meant to be used for making just a single tuple.  It takes in lists of
things, and pairs them up.


Please feel free to ask more questions about this.  Best of wishes to you!

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


[Tutor] range function

2005-01-29 Thread Srinivas Iyyer
Hi:

I have bunch of coordinates for various vectors. 

example:

small vecs:

name  cord. Xcord. Y   Sector no.
smvec175  1001aa
smvec225  50 1aa
smvec3135 1551ab

large vecs:zone
Lvec1 10  50  1aa  ut
Lvec1 60  110 1aa  cd
Lvec1 130 180 1ab  cd

Now I am checking if small vecs are falling in which
large vecs.

I initially tried by taking sm X and sm Y coordinates
into two variables smX smY and similarly LX and LY and
checking:
if smX >=lX and smY <= LY:
  print line in large vect +'\t' + line in
small vec. 

Unfortunately this failed. because LX and LY are not
matched together. 

The other way by taking tuples:

for line in smallvecs:
 cols = line.split('\t')
 smvec_tup = zip(cols[1],cols[2])
 for line2 in largevec:
  cols  = line2.split('\t')
  lvec_tup = zip(cols[1]+'\t'+cols[2])
## from here I have no clue, :-( ###
   if smvec_tup is in rane(lvec_tup):
  print line+'\t'+line2

ultimately I want to say:
smvec1   smX   smYLX  LYLvec1cd

My question here is that is there any way that i can
ask python to check a tuple is falls in the range of
other tuple. 

Also, members could u suggest more pythonian ways to
deal with this kind of problem.

thank you in advance

Srini



__ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: Fwd: [Tutor] Control flow

2005-01-29 Thread Orri Ganel
Kent Johnson wrote:
Bob Gailer wrote:
At 04:43 AM 1/29/2005, Liam Clarke wrote:
< erk, to the list, to the List!>
if ( bad_weather =='y' ):
   # ask user only if weather is bad.
   b = input ( "Weather is really bad, still go out to jog?[y/n]" )
   if b == 'y':
  go_jogging()
Anyone else notice that he's never gonna go jogging if the weather 
is bad?
Unless I've got input() wrong, it only takes integers... ?

 From the docs:
input( [prompt])
Equivalent to eval(raw_input(prompt)).

So, it takes more than just integers, but it won't work the way the OP 
expects:
 >>> print input('Type something: ')
Type something: 'spam ' * 4
spam spam spam spam
 >>> print input('Type something: ')
Type something: y
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 0, in ?
NameError: name 'y' is not defined
-  because eval('y') looks for a variable named y

 >>> print input('Type something: ')
Type something: 'y'
y
It works with the quotes - it is evaluating a string literal
raw_input() would work better.
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Or you could just define a variable y and a variable n which equal "y" 
and "n", respectively. Using raw_input() is probably easier though.

--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: Fwd: [Tutor] Control flow

2005-01-29 Thread Kent Johnson
Bob Gailer wrote:
At 04:43 AM 1/29/2005, Liam Clarke wrote:
< erk, to the list, to the List!>
if ( bad_weather =='y' ):
   # ask user only if weather is bad.
   b = input ( "Weather is really bad, still go out to jog?[y/n]" )
   if b == 'y':
  go_jogging()
Anyone else notice that he's never gonna go jogging if the weather is bad?
Unless I've got input() wrong, it only takes integers... ?

 From the docs:
input( [prompt])
Equivalent to eval(raw_input(prompt)).
So, it takes more than just integers, but it won't work the way the OP 
expects:
 >>> print input('Type something: ')
Type something: 'spam ' * 4
spam spam spam spam
 >>> print input('Type something: ')
Type something: y
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 0, in ?
NameError: name 'y' is not defined
-  because eval('y') looks for a variable named y
 >>> print input('Type something: ')
Type something: 'y'
y
It works with the quotes - it is evaluating a string literal
raw_input() would work better.
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: Fwd: [Tutor] Control flow

2005-01-29 Thread Bob Gailer


At 04:43 AM 1/29/2005, Liam Clarke wrote:
< erk, to the list, to the
List!>
if ( bad_weather =='y' ):
   # ask user only if weather is bad.
   b = input ( "Weather is really bad, still go out to
jog?[y/n]" )
   if b == 'y':
  go_jogging()
Anyone else notice that he's never gonna go jogging if the weather is
bad?
Unless I've got input() wrong, it only takes integers...
?
 From the docs:
input( [prompt])
Equivalent to eval(raw_input(prompt)). 

Bob Gailer
mailto:[EMAIL PROTECTED]
303 442 2625 home
720 938 2625 cell

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


Re: [Tutor] Naming conventions (was: Should this be a list comprehension or something?

2005-01-29 Thread Kent Johnson
iguessthereisnooptionleftexcepttorunwordstogetherwithoutanykindofbreakatall
thatshouldannoyeveryoneequally
Kent
Liam Clarke wrote:
Just please_don't_use_underscores. 

They_make_my_eyes_go_funny_, _and_code_hard_to_read_in_my_opinion.
_u_n_d_e_r_s_c_o_r_e_s_ _a_r_e__u_g_l_y_
I got out of the habit of using them really fast.
Also, __ & _ tend to have special meaning in Python (which is bad
enough as it is), so I don't use them for that reason as well.
Liam Clarke
On Fri, 28 Jan 2005 22:54:08 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
You're my best friend. Everyone else looves camelCase, and I hate it too. It
doesn't make sense. It doesn't fit English.
It doesn't fit Spanish. It doesn't fit any other language AFAIK, so why
should a human (who uses spoken language) to computer interpreter use a
naming convention that doesn't match spoken language? That's my opinion.
Jacob Schmidt
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Diffing two files.

2005-01-29 Thread Kent Johnson
OK, that is clear. diffutils is probably overkill. A simple loop to accumulate the lines of interest 
should work. Here is some untested (!) code that may do what you want :-)

def getCommonPart(filePath):
  ''' Get a list containing all the lines of a file that fall between the start 
and end lines.
  The returned list does not include the actual start and end lines.
  If start is not found, returns None.
  If end is not found, returns the lines after start.
  '''
  start = '-Beginning flag\n'
  end = '-Ending flag\n'
  common = None  # This will be the list of lines, also a flag of whether start 
has been seen
  for line in open(filePath):
if common is None and line == start:
  common = []
elif line == end:
  break
else:
  common.append(line)
  return common
# Now it's easy to compare the two files:
lines1 = getCommonPart(file1)
lines2 = getCommonPart(file2)
if lines1 != lines2:
  # Do what you need to do in case of a mismatch...
  # If you want details of the differences then you might want to use difflib 
here
Kent
Ertl, John wrote:
Kent
What I need to do is find what should be common and see if it really is.  I
have two output files...The output files will have a bunch of systems stuff
then the text of interest and then a bunch more systems stuff.  The systems
stuff may be different for each file but the text of interest will always
have a fixed line in front of it and behind it.  

The idea is to get the text of interest (using the known beginning and
ending flags in the text) from each file and then check to make sure the
text of interest is the same in both files. 

I have not done much text stuff so this is new territory for me.  I will
take a look at difflib.
Thanks again
John Ertl
Simplified example of a text files.
Sldfsdf
Sdfsdfsf
Sdfsdfsdfwefs
Sdcfasdsgerg
Vsadgfasgdbgdfgsdf
-Beginning flag
This
Text
Should be
The
Same in the other file.
-Ending flag
Sdfsdfsdfsd
Sdfsdfsdfasd
Sdfsadfsdf
Sdfsadfasdf
Sdfsdfasd
Sdfasdf
s
-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED]
Sent: Friday, January 28, 2005 15:23
Cc: Tutor@python.org
Subject: Re: [Tutor] Diffing two files.
You don't really say what you are trying to accomplish. Do you want to
identify the common text, or
find the pieces that differ?
If the common text is always the same and you know it ahead of time, you can
just search the lines
of each file to find it.
If you need to identify the common part, difflib might be useful. There is
an example on this page
of finding matching blocks of two sequences:
http://docs.python.org/lib/sequencematcher-examples.html
In your case the sequences will be lists of lines rather than strings (which
are sequences of
characters)
Kent
Ertl, John wrote:
All,
I have two text files that should contain a section of text that is the
same.  Luckily the section of text has a defined beginning and end.  It
looks like the most straightforward thing would be to read the targeted
text
from each file (only 50 lines or so) into lists and then compare the
lists.
I would think I could use sets to find a unique list (hopefully there
would
not be anything)...or I could do line by line comparison.  Any advise on
what is the better method.  Should I avoid the list comparison
approach...is
there a built in way of comparing entire files instead of dealing
explicitly
with the lines?
Thanks,
John Ertl
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
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] Naming conventions (was: Should this be a list comprehension or something?

2005-01-29 Thread Liam Clarke
Just please_don't_use_underscores. 

They_make_my_eyes_go_funny_, _and_code_hard_to_read_in_my_opinion.

_u_n_d_e_r_s_c_o_r_e_s_ _a_r_e__u_g_l_y_

I got out of the habit of using them really fast.
Also, __ & _ tend to have special meaning in Python (which is bad
enough as it is), so I don't use them for that reason as well.


Liam Clarke
On Fri, 28 Jan 2005 22:54:08 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
> You're my best friend. Everyone else looves camelCase, and I hate it too. It
> doesn't make sense. It doesn't fit English.
> It doesn't fit Spanish. It doesn't fit any other language AFAIK, so why
> should a human (who uses spoken language) to computer interpreter use a
> naming convention that doesn't match spoken language? That's my opinion.
> 
> Jacob Schmidt
> 
> 
> > On Wed, 26 Jan 2005, Sean Perry wrote:
> >
> >> And now, for the pedant in me. I would recommend against naming
> >> functions with initial capital letters. In many languages, this implies
> >> a new type (like your Water class). so CombineWater should be
> >> combineWater.
> >
> > I hate hate hate hate hate camelcase and will never use it.  In my book,
> > if the name has *any* capitals in it, the first letter is capitalized,
> > too.  Anything else is unaesthetic.
> >
> > To me, when I have names that are composed of multiple words (say, "rice
> > quantity"), I have two approaches: distinguishing the words by case
> > (RiceQuantity) or separating by underscores (rice_quantity).
> >
> > I never confuse classes/instances and methods, because I use noun phrases
> > for classes and instances (HeatedWater, VerifiedInput) and verb phrases
> > for the methods (CombineWater, CookRice).  I suppose I could get
> > confusion, for example, when the combination either a noun phrase or
> > verb phrase (SoundOut: is that a name describing the Sound that's being
> > put Out, or is it a method that's is tentatively Sounding Out somthing?)
> > but so far that hasn't been an issue for me.
> >
> > Of course in my case, I write code only for myself, so I have the luxury
> > of not worrying about what Joe in the next cubicle is doing, and what Jane
> > will do when she's trying to read Bob's and my code together.  So I have
> > the luxury of turning my nose up at camelCase.
> >
> > I should add that, the one time I made changes to someone else's Python
> > code for release (a minor patch to nntplib.py), I used the same case
> > conventions already in place in the module.
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Fwd: [Tutor] Control flow

2005-01-29 Thread Liam Clarke
< erk, to the list, to the List!>

if ( bad_weather =='y' ):
   # ask user only if weather is bad.
   b = input ( "Weather is really bad, still go out to jog?[y/n]" )
   if b == 'y':
  go_jogging()

Anyone else notice that he's never gonna go jogging if the weather is bad?
Unless I've got input() wrong, it only takes integers... ?

Regards,

Liam Clarke

--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Should this be a list comprehension or something?

2005-01-29 Thread Brian van den Broek
Alan Gauld said unto the world upon 2005-01-28 16:28:
So you've been looking at Eiffel then?
:-)
I don't get this joke, but it sounds like the basis for it 
would be interesting.  Can you explain?

Bertrand Meyer, the inventor of Eiffel uses rich text to display
code in his books. The commercial Eiffel IDE that his company 
ISE sells used to display the code the same way. Thus different 
fonts were used for comments, keywords etc as well as the 
usual syntax colouring. I note that the freeware version of the 
tool seems to be more conventional in approach!

Alan G.
[Alan posted the Eiffel reference in response to my 'suggestion' we 
switch to MS Word format for writing code.]

Thanks for explaining that, Alan. I'd heard of Eiffel, but that was as 
far as that went. (I was just going for maximally silly with the Word 
suggestion.)

I am a bit surprised by your description and links. I like scite a 
lot, but the first time I fired it up and saw my code in a 
non-monospace font, I just about recoiled in horror. Once I figured 
out how to switch that, I felt much better, as my lack of previous 
programming experience meant I didn't have a recoil in horror over 
Python's use of whitespace. I'd felt left out ;-)

Best to all,
Brian vdB
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor