Pychecker

2006-06-09 Thread Anthony Greene
Howdy, I had the impression that pychecker caught and reported such
dynamic syntactical errors.

#!/usr/bin/env python


def add(i):
i += 10

status = 3

if 1 == 1:
statuss = 15

add(status)

===

exalted sysfault$ pychecker foo.py 
Processing foo...

Warnings...

None

===

Hence the mispelling of status (statuss), which was done purposely to test
if pychecker will acknowledge and report the error. Do i need to enable
some type of pychecker option in order for it to pick up the error? I know
that it is syntactically correct in python, however it's likely that
'status' is meant. Am i wishing that pychecker will replace a statically
typed language mechanism?

-- 
A wise man knows he knows nothing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pychecker

2006-06-09 Thread Anthony Greene
On Fri, 09 Jun 2006 11:46:59 -0700, Matt Good wrote:

> Anthony Greene wrote:
>> Howdy, I had the impression that pychecker caught and reported such
>> dynamic syntactical errors.
>>
>> #!/usr/bin/env python
>>
>>
>> def add(i):
>> i += 10
>>
>> status = 3
>>
>> if 1 == 1:
>> statuss = 15
>>
>> add(status)
>>
>> ===
>>
>> exalted sysfault$ pychecker foo.py
>> Processing foo...
>>
>> Warnings...
>>
>> None
>>
>> ===
>>
>> Hence the mispelling of status (statuss), which was done purposely to test
>> if pychecker will acknowledge and report the error. Do i need to enable
>> some type of pychecker option in order for it to pick up the error? I know
>> that it is syntactically correct in python, however it's likely that
>> 'status' is meant. Am i wishing that pychecker will replace a statically
>> typed language mechanism?
> 
> That's a functional error, not a syntactical one.  Analyzing the
> spelling of variables for similarity would lead to a lot of incorrect
> warnings since pychecker has no way to tell this apart from intentional
> similar spellings such as:
> 
> values = [1, 2, 3]
> value = values[0]
> 
> However, when the misspelling is made inside a local scope, rather than
> at the module level a warning is reported "test.py:8: Local variable
> (statuss) not used":
> 
> def add(i):
> i += 10
> 
> def test():
> status = 3
> if 1 == 1:
> statuss = 15
> add(status)
> 
> 
> This is why tools like pychecker (or pyflakes, pylint, or even a static
> code compiler) aren't a substitute for unit tests.  They can definitely
> help catch common mistakes, but they can't ensure your code does what
> you intended.

Thanks guys, exactly what was needed.
-- 
A wise man knows he knows nothing.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO conventions

2006-02-01 Thread Anthony Greene
On Wed, 01 Feb 2006 23:40:37 +0100, Daniel Nogradi wrote:

> I'm relatively new to object oriented programming, so get confused
> about its usage once in a while. Suppose there is a class Image that
> has a number of methods, rotate, open, verify, read, close, etc. Then
> to use this class my natural guess would be to have something like
> 
> image = Image( )
> image.read( "myfile.jpg" )
> image.rotate( )
> image.close( )
> 
> But now it turns out that the PIL module uses this as
> 
> image = Image.open( "myfile.jpg" )
> image.verify( )
> image.rotate( )
> image.close( )
> 
> Perhaps the real Image class of PIL doesn't have these methods
> exactly, but doesn't matter, my point is the way it works. Is it
> normal that instead of first creating an instance of a class, it
> starts right away with one its methods? I of course understand that
> the PIL people simply made a choice that their module works this way,
> period, but I'm just wondering if it wouldn't have been more "logical"
> to do it along the way of my first example.
> 
> I guess it's just a matter of convention or how the programmer feels
> like, but there are no conventions of this type? Which would be more
> pythonic? Or I shouldn't worry and it's totally up to the developer?


You should take a look at the PIL source files, open() could surely be a
class which takes a filename as an argument at construction time. If you
run across such code, there is really no need to worry, some things are
conventional and some are a matter of preference. In most cases diving
into the source can help clarify a lot of your speculations, better hope
the code is transparent, i hate reading non-readable code. :)

-- 
A wise man knows he knows nothing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO conventions

2006-02-01 Thread Anthony Greene
On Wed, 01 Feb 2006 23:40:37 +0100, Daniel Nogradi wrote:

> I'm relatively new to object oriented programming, so get confused
> about its usage once in a while. Suppose there is a class Image that
> has a number of methods, rotate, open, verify, read, close, etc. Then
> to use this class my natural guess would be to have something like
> 
> image = Image( )
> image.read( "myfile.jpg" )
> image.rotate( )
> image.close( )
> 
> But now it turns out that the PIL module uses this as
> 
> image = Image.open( "myfile.jpg" )
> image.verify( )
> image.rotate( )
> image.close( )
> 
> Perhaps the real Image class of PIL doesn't have these methods
> exactly, but doesn't matter, my point is the way it works. Is it
> normal that instead of first creating an instance of a class, it
> starts right away with one its methods? I of course understand that
> the PIL people simply made a choice that their module works this way,
> period, but I'm just wondering if it wouldn't have been more "logical"
> to do it along the way of my first example.
> 
> I guess it's just a matter of convention or how the programmer feels
> like, but there are no conventions of this type? Which would be more
> pythonic? Or I shouldn't worry and it's totally up to the developer?

In this case, Image seems to be a python module, with the open function
defined, PIL's Image is not a class.

-- 
A wise man knows he knows nothing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.getmtime() and compare with a date type

2007-09-20 Thread Anthony Greene
[EMAIL PROTECTED] wrote:
> Hi,
> I am new to python and are tryint to write a simple program delete log
> files that are older than 30 days.
>
> So I used os.path.getmtime(filepath) and compare it with a date but it
> does not compile.
>
> threshold_time = datetime.date.today() - datetime.timedelta(days=30)
> mod_time = os.path.getmtime(file_path)
>
> if( mod_time < threshold_time):
>  #delete file
>
> However the interpreter complains at the if line, say "can't comapre
> datetime.date to int
>
> How can I covert one of them to make it work?
>
> Thank you!
>
>   
You are looking for datetime.datetime.fromtimestamp(mod_time)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.getmtime() and compare with a date type

2007-09-20 Thread Anthony Greene
[EMAIL PROTECTED] wrote:
> Hi,
> I am new to python and are tryint to write a simple program delete log
> files that are older than 30 days.
>
> So I used os.path.getmtime(filepath) and compare it with a date but it
> does not compile.
>
> threshold_time = datetime.date.today() - datetime.timedelta(days=30)
> mod_time = os.path.getmtime(file_path)
>
> if( mod_time < threshold_time):
>  #delete file
>
> However the interpreter complains at the if line, say "can't comapre
> datetime.date to int
>
> How can I covert one of them to make it work?
>
> Thank you!
>
>   
You are looking for datetime.datetime.fromtimestamp(mod_time)
-- 
http://mail.python.org/mailman/listinfo/python-list


python application ideas.

2006-04-24 Thread Anthony Greene
Hello, I know this isn't really a python centric question, but I'm seeking
help from my fellow python programmers. I've been learning python for the
past year and a half, and I still haven't written anything substantial nor
have I found an existing project which blows my hair back. Python is my
first language, and I plan on learning lisp within the next week but
before I do so I'd like to write something meaningful, does anyone have
any suggestions? Something they always needed, but never got around to
writing it? Without an imagination you pretty much stagnate your whole
learning process. Thanks in advance.

-- 
A wise man knows he knows nothing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python application ideas.

2006-04-25 Thread Anthony Greene
On Tue, 25 Apr 2006 09:51:42 -0500, Thomas Bartkus wrote:

> "Anthony Greene" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Hello, I know this isn't really a python centric question, but I'm seeking
>> help from my fellow python programmers. I've been learning python for the
>> past year and a half, and I still haven't written anything substantial nor
>> have I found an existing project which blows my hair back. Python is my
>> first language, and I plan on learning lisp within the next week but
>> before I do so I'd like to write something meaningful, does anyone have
>> any suggestions? Something they always needed, but never got around to
>> writing it? Without an imagination you pretty much stagnate your whole
>> learning process. Thanks in advance.
> 
> Just what is it, other than programming, that you have expertise in?
> What kind of problems do you know how to solve?
> 
> > Without an imagination you pretty much stagnate your whole
> > learning process.
> 
> So true!  Unfortunately, no one can provide you with one.
> You have to develop that yourself.
> 
> Tis the conundrum of programming in general.  If all you know how to do is
> write code - then you truly have nothing to do.  What *other* interests do
> you have?  Hobbies? Job Skills?
> What *does* "blow your hair back" ;-)
> 
> That's where your programming ideas need to come from.
> Thomas Bartkus

So true man, I guess I need to truly sit down and determine these things.
I love to do a lot of things, read, hang out, skate, which are a few
amongst other things. I guess my ideas will have to come from real-life
experiences, I'm going to chill out for 2 days this week and just think of
various things which I want or need, but have not found anything which
fulfills that. I'm going to jot everything down, and try to think about
way to implement them programmatically. We'll see how it works out.

-- 
A wise man knows he knows nothing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scatter/gather on sockets?

2006-04-01 Thread Anthony Greene
On Sat, 01 Apr 2006 14:56:02 -0500, Roy Smith wrote:

> I've got a bunch of strings in a list:
> 
> vector = []
> vector.append ("foo")
> vector.append ("bar")
> vector.append ("baz")
> 
> I want to send all of them out a socket in a single send() call, so
> they end up in a single packet (assuming the MTU is large enough).  I
> can do:
> 
> mySocket.send ("".join (vector))
> 
> but that involves creating an intermediate string.  Is there a more
> efficient way, that doesn't involve that extra data copy?

Is sendall() what you're looking for?

-- 
A wise man knows he knows nothing.

-- 
http://mail.python.org/mailman/listinfo/python-list