[Tutor] getopts question

2007-03-29 Thread Greg Perry
Hello List Members,

I am working on a simple program and would like to know the best way to 
approach this.  Using getops I am parsing the argv array to grab command line 
options; from the command line the user can specify either a filename or a 
directory (but not both).  Is there an eloquent way with getopts to do an 
either/or scenario without resorting to multiple tests to see which variable is 
set using if then statements?

Thanks in advance


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


[Tutor] hashlib weirdness

2007-03-30 Thread Greg Perry
Here's one that has me stumped.

I am writing a forensic analysis tool that takes either a file or a directory 
as input, then calculates a hash digest based on the contents of each file.

I have created an instance of the hashlib class:

m = hashlib.md5()

I then load in a file in binary mode:

f = open("c:\python25\python.exe", "rb")

According to the docs, the hashlib update function will update the hash object 
with the string arg.  So:

m.update(f.read())
m.hexdigest()

The md5 hash is not correct for the file.

However, this works:

f.seek(0)
hashlib.md5(f.read()).hexdigest()

Why the difference I wonder?

Thanks in advance.


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


Re: [Tutor] getopts question

2007-03-30 Thread Greg Perry
Yeah I figured that.  I am trying to find a way to have the program detect if 
the user input is a file or directory, which is easy enough with os.path.  
However, os.path makes no distinction between a regular file and a mask, eg 
filename.txt or *.txt.  I guess I'll have to have a second set of tests to see 
if the filename contains any wildcards..?

-Original Message-
From: Kent Johnson

>I'm not really sure what you are looking for here. If you use two options, you 
>will have to test to see which option is set. You could use one option, then 
>you will have to test to see if the value is a file or a directory.
>
>Kent



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


[Tutor] os.path.isfile and isdir

2007-03-30 Thread Greg Perry
It looks like both os.path.isfile and os.path.isdir evaluate to False for a 
wildcard, so that makes it a bit easier to deal with a mask.

Thanks to everyone for the suggestions.


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


[Tutor] Communication between classes

2007-04-01 Thread Greg Perry
Hi again,

I am still in the process of learning OOP concepts and reasons why classes 
should be used instead of functions etc.

One thing that is not apparent to me is the best way for classes to communicate 
with each other.  For example, I have created an Args class that sets a variety 
of internal variables (__filename, __outputdir etc) by parsing the argv array 
from th command line.  What would be the preferred mechanism for returning or 
passing along those variables to another class?  Maybe by a function method 
that returns all of those variables?



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


Re: [Tutor] Communication between classes

2007-04-01 Thread Greg Perry
That makes sense, thank you for the detailed explanation Andrei.  For this 
simple project I am working on, it looks like the most direct route would be to 
use functions and only develop classes for the portions of the program that can 
be reused.

Is it safe to say that classes are only useful for instances where reuse is a 
key consideration?  From my very limited perspective, it seems that classes are 
in most cases overkill for simple tasks (such as reading the command line then 
calculating a hash/checksum to verify integrity).

Thanks again for your very descriptive answer.

-Original Message-
From: Andrei

Hi Greg,
>
>Greg Perry wrote:
> I am still in the process of learning OOP concepts and 
> > reasons why classes should be used instead of functions etc.
> 
> One thing that is not apparent to me is the best way for 
> > classes to communicate with each other.  For example,
>
>Good question. Unfortunately there's no general rule that you can apply 
>and end up with an undisputably perfect solution.
>
>Classes should communicate on a need-to-know basis. Take for example a 
>RSS feed reader application. You may have a class representing a feed 
>and a class representing a post. The feed will know what posts it 
>contains, but the post probably won't know what feed it comes from. The 
>interface would display a list of feeds (without knowing their 
>contents), a list of posts within a feed (this needs to know both feed 
>and feed contents) and the contents of a single post (knows only about 
>an individual post).
>
> > I have created an Args class that sets a variety of internal
> > variables (__filename, __outputdir etc) by parsing the argv
>
>Be careful with classes that simply act as a container for what are in 
>fact global variables. A class should do one thing only (of course what 
>you accept as 'one thing' is open for debate) and encapsulate all that's 
>necessary for that particular thing. Make sure you're not 
>overcomplicating your solution by making classes where they're not 
>really necessary.
>
> > array from th command line.  What would be the preferred
> > mechanism for returning or passing along those variables
>
>In some cases only some parts of the information contained in class A 
>are relevant to class B - you should pass only that particular 
>information, e.g. in the constructor or by setting a property of B. In 
>your example, if you have a Reader class that is interested in the 
>filename, you would not pass the whole Args object to it - only the 
>filename, like this:
>
> myreader = Reader(Args.FileName)
>
> > to another class?  Maybe by a function method that returns
> > all of those variables?
>
>Use properties if you need getter/setter methods or simple attributes 
>otherwise. In your case, I would not make __filename etc. 'private' 
>(that's what the double underscore suggests), then write a getter method 
>for it - just call it FileName and be done with it. Python idiom here is 
>more flexible than other languages.
>
>-- 
>Yours,
>
>Andrei
>
>=
>Mail address in header catches spam. Real contact info:
>''.join([''.join(s) for s in zip(
>"[EMAIL PROTECTED] pmfe!Pes ontuei ulcpss  edtels,s hr' one oC.",
>"rjc5wndon.Sa-re laed o s npbi ot.Ira h it oteesn edt C")])
>
>___
>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] hashlib weirdness

2007-04-02 Thread Greg Perry
Thanks Terry, others have pointed out the same thing.  The stock Python 2.5 
interpreter functions properly; my issue seems to be with the IDE I am using, 
that is where I've been able to nail down the problem so far.

-Original Message-
From: Terry Carroll

On 30 Mar 2007, Greg Perry wrote:
>
>> Here's one that has me stumped.
> 
> I am writing a forensic analysis tool that takes either a file or a
> directory as input, then calculates a hash digest based on the contents
> of each file.
> 
> I have created an instance of the hashlib class:
> 
> m = hashlib.md5()
> 
> I then load in a file in binary mode:
> 
> f = open("c:\python25\python.exe", "rb")
> 
> According to the docs, the hashlib update function will update the hash
> object with the string arg.  So:
> 
> m.update(f.read())
> m.hexdigest()
> 
> The md5 hash is not correct for the file.
>
>Odd.  It's correct for me:
>
>In Python:
>
>>>> import hashlib
>>> m = hashlib.md5()
>>> f = open("c:\python25\python.exe", "rb")
>>> m.update(f.read())
>>> m.hexdigest()
>'7e7c8ae25d268636a3794f16c0c21d7c'
>
>Now, check against the md5 as calculated by the md5sum utility:
>
>>md5sum c:\Python25\python.exe
>\7e7c8ae25d268636a3794f16c0c21d7c *c:\\Python25\\python.exe
>
>
>> f.seek(0)
> hashlib.md5(f.read()).hexdigest()
>
>No difference here:
>
>>>> f.close()
>>> f = open("c:\python25\python.exe", "rb")
>>> hashlib.md5(f.read()).hexdigest()
>'7e7c8ae25d268636a3794f16c0c21d7c'
>
>___
>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] Movies from jpg files

2007-04-07 Thread Greg Perry
Maybe PyMedia is what you are looking for:  http://www.pymedia.org

It's a Python library based on FFmpeg, which is a program that can encode and 
decode many different video streams.  FFmpeg can also create an mpeg from a 
collection of jpeg images, read section 1.2 of the FFmpeg FAQ which 
demonstrates making a mpeg from a sequence of jpeg images:

http://ffmpeg.mplayerhq.hu/faq.html

Subject: [Tutor] Movies from jpg files
To: tutor@python.org

Dear All,
>
>I have found a fine Axis 2100 webcamera on my shelf, that was out of 
>usage,
>It uploads jpg images every minutes to an ftp server now.
>I would like to build up a movie from the pictures for easier review.
>I don't know which movie format can be built up easier,
>.jpeg, quicktime .mov, .wmv, .avi or anything else.
>It would be fine to use a format that has compression advantage compared 
>the raw
>volume of jpg files. It could be possible as the camera placed statically 
>so the images
>are very similar. 
>
>May you recommend me which format could be used ?
>May you recommend anything to build them easy ?
>
>
>Yours sincerely,
>__
>János Juhász
>
>___
>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] Movies from jpg files

2007-04-08 Thread Greg Perry
Indeed ;)

>Python is Cool :)



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


Re: [Tutor] please help me

2007-04-13 Thread Greg Perry
Let no good deed go unpunished!

-Original Message-
From: Daniel Yoo
Date: Friday, Apr 13, 2007 8:24 pm
Subject: Re: [Tutor] please help me

> If this is homework, please tell your teacher I helped - I need the 
> extra credit.
>
>Please avoid giving homework answers like this.  Rather than actually help 
>the person, it can do harm, because it encourages a lazy attitude toward 
>solving problems.



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor