[Tutor] Where to start with Unit Testing

2010-08-01 Thread Huy Ton That
Hi all,

Do any of you have any feedback, strategies and best practices related to
unit testing within Python. This is a relatively new topic for me. I was
thinking of starting with reading the documentation associate with the
unittest module.

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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Mark Lawrence

On 01/08/2010 08:30, Huy Ton That wrote:

Hi all,

Do any of you have any feedback, strategies and best practices related to
unit testing within Python. This is a relatively new topic for me. I was
thinking of starting with reading the documentation associate with the
unittest module.

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


The documentation is a good starting point.  Then see the excellent:-
http://diveintopython.org/unit_testing/index.html.
Also look at the actual Python test code in the Lib\test\ directory.
Depending on the code that you're wanting to test you might also want to 
google for mock+objects, but this can wait until you've got your feet 
under the table.


HTH.

Mark Lawrence.


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


Re: [Tutor] problem with simple script

2010-08-01 Thread Richard D. Moores
(This repeats an earlier post of mine, and gives the correct link to
the script I wrote about: . In
a subsequent post I reported that I had gotten rid of the flag in a
further revision:  This link is
correct. I apologize for the confusion. --Dick)

On Wed, Jul 28, 2010 at 08:35, Richard D. Moores  wrote:

> Now I'll dig into all the help I received. I see an *args in Steven's
> detailed reply. That'll take some reviewing to understand.

Here's my slight revision of Steven's script (see my note, lines 9-14)
-- revised only because I wanted it to handle the case where the user
(me) entered the interval bounds in the wrong order, e.g., 10, 5
instead of 5, 10.  I've also added a way ('r') for the user to choose
to get another random number in the same interval without having to
reenter the bounds: . Then I
needed a way ('c') to choose to change the bounds after 'r' had been
used. I used a flag (lines 42, 53, 55) to accomplish these additions.
Was there a better way? Should I have written a couple of extra
functions instead of using the flag? Are flags unpythonic?

I've learned a lot from his script, and hope to learn more -- I'm
still grappling with the  *args  of line 46.

What I've learned so far:
1. To separate the front end (for the user) from the back end. See his
note on line 3.
2. The use of maxsplit with str.split(). Line 29.
3. Using the return of a function to call another function. Line 38.
4. In main(), he assigns the prompt to a variable _before_ the while
loop (line 41), so the assignment is done only once, rather than each
time through the loop. Not a biggie in this script, but a good thing
to learn, I think.

So thanks, Steven!

Now, on to *args!

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


Re: [Tutor] Writing scripts and apps for Internet consumption

2010-08-01 Thread Timo

On 01-08-10 00:40, Eric Hamiter wrote:
On Sat, Jul 31, 2010 at 4:48 PM, bob gailer > wrote:



Please post that code, and the URL you use to invoke it.


test.py: this works on my laptop but not on the server

http://pastebin.com/ChjUzLRU

Just a wild guess, but maybe it is failing on the following line:

with open("grocery_list.txt") as grocery_list:

The with statement was introduced in Python 2.5, and if I look at my own 
webhost, they are still with Python 2.4.
Make a script that prints the Python version (with sys.version_info or 
sys.version for example) or ask your webhost.


You can also put this on top of your script, so it shows you a nice 
Python traceback instead of an error:

import cgitb
cgitb.enable()


Cheers,
Timo




test-working.py: this works on both laptop & server

http://pastebin.com/iLNTrGdW

both available for execution here:

http://erichamiter.com/xkred27/


Do you import cgi?


Yes.


There is a companion module (cgitb) that captures exceptions and
returns the traceback to the web browser.


I tried that as well. I'm sure I'm missing something fundamental here, 
but that's kind of obvious since I posted I don't know what I'm doing 
in the first place! :)


Thanks,

Eric


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


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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Mac Ryan
On Sun, 2010-08-01 at 03:30 -0400, Huy Ton That wrote:
> Hi all, 
>
> Do any of you have any feedback, strategies and best practices related
> to unit testing within Python. This is a relatively new topic for me.
> I was thinking of starting with reading the documentation associate
> with the unittest module.

My answer falls in the category "feedback" (I was also going to mention
the diveintopython page, but somebody else has done that already!), so
you should be aware what follows is highly subjective...

JUST THINK... IN PYTHON!
   IMO, unit testing is really easy to pick up. It really does not
amount to much more than taking note (in python) of what you are
thinking when you are coding.
   If you are anything like me, when you code you keep on formulating
"rules" in your head, in the line of "when everything works as expected,
if the methods iterates four times, then this method must return X" or
"when everything works as expected, if a user enter a value over 212
then the script must throw this exception", etc...
   * the "when everything works as expected" translates in "this test
pass when..."
   * the "if X" translates in your test case (i.e. the scenario you are
testing for)
  * the "then Y" translates in "the outcome of my test case must be Y"

TESTING IS VALUABLE IN THE LONG RUN
   At times, designing and coding a test is a time-consuming activity,
and if the code is particularly straightforward you might be tempted to
skip the unit testing altogether. In my experience - however - unit
testing is never as useful on the spot as it is three months from now,
when you will have/want/choose to modify a little bit of your old code,
and all of a sudden everything will break. In the latter scenario, your
test suite will be an invaluable asset.

FUNCTIONAL PROGRAMMING WINS
   The most difficult thing in writing a test, is replicating the state
of the environment needed for the test to happen. This is especially
(but not uniquely) true for DB-driven applications, when you might wish
to perform test on methods that interact with the DB. In that case you
have to create a test DB, populate it with ~credible data, etc...
   The most "functional" (as in functional programming, i.e.
machine-state independent) is your code, the easiest is to write a test.
Example: if you need to check a method that validate the postal code of
an address based on the name of the city, it is easier to test a method
that is invoked with "validate_postal_code(code, city)" rather than one
that is invoked with "validate_postal_address(user)" and that will have
to retrieve the full address of a user from a DB, and extract the city
and postal address from it.

MVC WINS
   I never test UI's. I know it is bad... but it is simply too
time-consuming for me (I'll be very glad if somebody reading this will
show me how one can make it snappier!). This means - at least for me -
that writing tests become extremely easier for me if I keep separated
the presentation layer from all the rest of the stuff.

EVERY BUG IS A TEST YET NOT WRITTEN
   A program that passes all its tests is not necessarily a bug-free
program. But once you find a new bug, try to make a point of writing a
new test that check for that particular scenario in which said bug is
happening.

TEST-DRIVEN IS BETTER
   What I find useful (although not always applicable) is to start my
programming session by writing the tests before I write the code to be
tested. This somehow reconnect to my previously articulated "just
think... in python!" point: you are however *already doing a list of
rules* in your head, before writing code, so you could well write it
down directly in code. All you need is to create a mock method/function
in your code with the same signature you are using in your test. For
example. You could write tests in the form:

assertEqual(better_square_root(9), 3)
assertRaises(ValueError, better_square_root, -4)

and then write in your module:

def my_better_square_root(number):
pass

all your tests will of course initially fail, but then you will keep on
working on the code of my_better_square_root until all your tests pass.

Well, these are just my two ¢... As stated in the beginning: highly
subjective, so keep your mind open for other (possibly opposite)
opinions too! :)

HTH,
Mac.

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


[Tutor] Help with Import Error problems

2010-08-01 Thread Roy Khristopher Bayot
Hi. Good day.

I am having an import error problem. Last week, I was following this site:
http://sites.google.com/site/spatialpython/processing-aster-with-python-numpy-and-gdal.
I
was able to make the python script run on the terminal. But this week, it
was throwing some error.

This was the traceback:

Traceback (most recent call last):
  File "aster_convert.py", line 2, in 
from osgeo import gdal
  File "/usr/lib/python2.6/dist-packages/osgeo/__init__.py", line 21, in

_gdal = swig_import_helper()
  File "/usr/lib/python2.6/dist-packages/osgeo/__init__.py", line 17, in
swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: /usr/lib/libspatialite.so.2: undefined symbol: GEOSSimplify

I tried google-ing for the ImportError but the results dont make sense. It
was working last week. I might have installed something that "broke" it but
I dont know how to trace it back.

Could I ask for some pointers on how to fix this?

Thank you.

Roy

P.S. I dont know if this is the right list to post this. If it isnt, I'm
sorry for the inconvenience. Kindly direct me to the right one.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Import Error problems

2010-08-01 Thread Evert Rol
> Hi. Good day. 
> 
> I am having an import error problem. Last week, I was following this site: 
> http://sites.google.com/site/spatialpython/processing-aster-with-python-numpy-and-gdal.
>  I was able to make the python script run on the terminal. But this week, it 
> was throwing some error. 
> 
> This was the traceback:
> 
> Traceback (most recent call last):
>   File "aster_convert.py", line 2, in 
> from osgeo import gdal
>   File "/usr/lib/python2.6/dist-packages/osgeo/__init__.py", line 21, in 
> 
> _gdal = swig_import_helper()
>   File "/usr/lib/python2.6/dist-packages/osgeo/__init__.py", line 17, in 
> swig_import_helper
> _mod = imp.load_module('_gdal', fp, pathname, description)
> ImportError: /usr/lib/libspatialite.so.2: undefined symbol: GEOSSimplify
> 
> I tried google-ing for the ImportError but the results dont make sense. It 
> was working last week. I might have installed something that "broke" it but I 
> dont know how to trace it back.
> 
> Could I ask for some pointers on how to fix this? 

I have absolutely no experience with the libraries you're using, but the error 
tells you that libspatialite is expected to have the symbol GEOSSimplify (could 
be a function or a class definition, for example), which isn't found.
The first Google hit for libspatialite results in 
http://www.gaia-gis.it/spatialite/how_to_build_libspatialite.html , which 
mentions two required dependencies: PROJ.4 and GEOS. Probably the latter 
provides GEOSSimplify.
So, you've either uninstalled the GEOS library, your LD_ LIBRARY_PATH settings 
settings aren't what they were a week ago, or you've reinstalled libspatialite, 
but this time with the no-geos option.

For a quick check, try the following from the command line:
$> ldd /usr/lib/libspatialite.so.2

and see if it has any missing dependencies. If there's any missing (you can 
also post the output here if you'd like), see if you can that dependency 
somewhere on your system (the 'locate' command can help, or just good-old 
'find'). If it's missing from libspatialite but you can find that library 
somewhere on your system (that would probably be the GEOS library then), it's 
your LD_LIBRARY_PATH that's likely different.

Also, what linux distro are you using? Maybe you've been using the package 
manager overzealously, causing some essential packages to be modified or 
removed?

And how did you install libspatialite; or for that matter, osgeo?


> 
> Thank you.
> 
> Roy
> 
> P.S. I dont know if this is the right list to post this. If it isnt, I'm 
> sorry for the inconvenience. Kindly direct me to the right one.  

If libspatialite or osgeo has a mailing list, you could (also) try that one. 
While this error shows up in Python, it's more likely a generic 
installation/system settings problems. Which are often tricky to find the 
correct mailing list for, actually, as long as it's not clear what's the 
underlying cause.


Good luck, and let us know what you find.

  Evert

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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread python
Mac,

> My answer falls in the category "feedback" ...

I'm not the OP, but I wanted to let you know that I really enjoyed your
feedback - excellent writeup!

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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Che M



> Do any of you have any feedback, strategies and best practices 
> related to unit testing within Python. This is a relatively new topic 
> for me. I was thinking of starting with reading the documentation 
> associate with the unittest module.

The idea of unit testing/test driven development has remained 
foreign to me throughout my time trying to learn Python--by choice.  
I want to make desktop GUI applications and I don't use MVC, so 
the idea of writing tests strikes me as far more work--and a major 
delayer of getting to an application that actually does something--
than simply using the software myself and noting problems.  It 
sounds like TDD is probably the most proper way to go about things, 
but, in the interest of getting something out of Python to warrant the
time I've put into it, I favor a "good enough" approach for now.




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


[Tutor] web-based python?

2010-08-01 Thread Alex Hall
Hi all,
I have an IPowerWeb.com server, which claims to support Python. How
would I use this? For example, to start, how would I print html code
to the screen, or manage input from a form? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web-based python?

2010-08-01 Thread Hugo Arts
On Sun, Aug 1, 2010 at 7:07 PM, Alex Hall  wrote:
> Hi all,
> I have an IPowerWeb.com server, which claims to support Python. How
> would I use this? For example, to start, how would I print html code
> to the screen, or manage input from a form? Thanks.
>

There is a myriad of python web development frameworks. Here's a link
with a ton of info:

http://wiki.python.org/moin/WebFrameworks

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


Re: [Tutor] Help with Import Error problems

2010-08-01 Thread Roy Khristopher Bayot
Evert,

I got it back working. But it was with some stroke of luck. And I dont know
the explanation.

I installed the latest source of GEOS (as suggested by someone from the gdal
channel). Then i tried the script. It gave me a different import error.

ImportError: libgeos-3.3.0.so: cannot open shared object file: No such file
or directory

I uninstalled the thing. And then tried the script again and it worked. :| I
answered some of your questions below. Again, thanks.

Roy

On Sun, Aug 1, 2010 at 10:39 PM, Evert Rol  wrote:

> > Hi. Good day.
> >
> > I am having an import error problem. Last week, I was following this
> site:
> http://sites.google.com/site/spatialpython/processing-aster-with-python-numpy-and-gdal.
> I was able to make the python script run on the terminal. But this week, it
> was throwing some error.
> >
> > This was the traceback:
> >
> > Traceback (most recent call last):
> >   File "aster_convert.py", line 2, in 
> > from osgeo import gdal
> >   File "/usr/lib/python2.6/dist-packages/osgeo/__init__.py", line 21, in
> 
> > _gdal = swig_import_helper()
> >   File "/usr/lib/python2.6/dist-packages/osgeo/__init__.py", line 17, in
> swig_import_helper
> > _mod = imp.load_module('_gdal', fp, pathname, description)
> > ImportError: /usr/lib/libspatialite.so.2: undefined symbol: GEOSSimplify
> >
> > I tried google-ing for the ImportError but the results dont make sense.
> It was working last week. I might have installed something that "broke" it
> but I dont know how to trace it back.
> >
> > Could I ask for some pointers on how to fix this?
>
> I have absolutely no experience with the libraries you're using, but the
> error tells you that libspatialite is expected to have the symbol
> GEOSSimplify (could be a function or a class definition, for example), which
> isn't found.
> The first Google hit for libspatialite results in
> http://www.gaia-gis.it/spatialite/how_to_build_libspatialite.html , which
> mentions two required dependencies: PROJ.4 and GEOS. Probably the latter
> provides GEOSSimplify.
> So, you've either uninstalled the GEOS library, your LD_ LIBRARY_PATH
> settings settings aren't what they were a week ago, or you've reinstalled
> libspatialite, but this time with the no-geos option.
>
> For a quick check, try the following from the command line:
> $> ldd /usr/lib/libspatialite.so.2
>

The command line returns the following lines:

linux-vdso.so.1 =>  (0x7fff6edff000)
 libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x7f793015c000)
libgeos_c.so.1 => /usr/local/lib/libgeos_c.so.1 (0x7f792ff4f000)
 libgeos-3.2.2.so => /usr/lib/libgeos-3.2.2.so (0x7f792fbe8000)
 libproj.so.0 => /usr/lib/libproj.so.0 (0x7f792f9a6000)
libm.so.6 => /lib/libm.so.6 (0x7f792f723000)
 libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f792f40e000)
libpthread.so.0 => /lib/libpthread.so.0 (0x7f792f1f1000)
 libdl.so.2 => /lib/libdl.so.2 (0x7f792efed000)
libc.so.6 => /lib/libc.so.6 (0x7f792ec69000)
 libgeos.so.2 => /usr/local/lib/libgeos.so.2 (0x7f792e964000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x7f792e74d000)
 /lib64/ld-linux-x86-64.so.2 (0x7f7930688000)

I dont know what to make of it.

and see if it has any missing dependencies. If there's any missing (you can
> also post the output here if you'd like), see if you can that dependency
> somewhere on your system (the 'locate' command can help, or just good-old
> 'find'). If it's missing from libspatialite but you can find that library
> somewhere on your system (that would probably be the GEOS library then),
> it's your LD_LIBRARY_PATH that's likely different.
>
> Also, what linux distro are you using? Maybe you've been using the package
> manager overzealously, causing some essential packages to be modified or
> removed?
>
>
I'm on Ubuntu 10.04 (64 bit). I think it was from installing different
GIS-related software (not all of which could be installed from the package
manager).


> And how did you install libspatialite; or for that matter, osgeo?
>

I didnt install them both explicitly. I think it's a dependency from GRASS.


>
>
> >
> > Thank you.
> >
> > Roy
> >
> > P.S. I dont know if this is the right list to post this. If it isnt, I'm
> sorry for the inconvenience. Kindly direct me to the right one.
>
> If libspatialite or osgeo has a mailing list, you could (also) try that
> one. While this error shows up in Python, it's more likely a generic
> installation/system settings problems. Which are often tricky to find the
> correct mailing list for, actually, as long as it's not clear what's the
> underlying cause.
>
>
> Good luck, and let us know what you find.
>
>  Evert
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web-based python?

2010-08-01 Thread python
Alex,

> I have an IPowerWeb.com server, which claims to support Python

Many hosting providers claim to support Python. The best hosting service
I've found for Python is webfaction.com. Originally this hosting
provider specialized in just Python hosting and this enthusiasm for
Python and hands-on Python skills are still part of their culture.

Highly recommended.

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


Re: [Tutor] web-based python?

2010-08-01 Thread Alex Hall
On 8/1/10, Hugo Arts  wrote:
> On Sun, Aug 1, 2010 at 7:07 PM, Alex Hall  wrote:
>> Hi all,
>> I have an IPowerWeb.com server, which claims to support Python. How
>> would I use this? For example, to start, how would I print html code
>> to the screen, or manage input from a form? Thanks.
>>
>
> There is a myriad of python web development frameworks. Here's a link
> with a ton of info:
>
> http://wiki.python.org/moin/WebFrameworks
I had looked into Django before. What is confusing me is that it
sounds like it is meant to be run on the server directly. I do not
have direct access to my server, I just rent space on it and can
login. Maybe I am missing something, but how would I get Django onto
my server if I do not have the physical box available to me?
>
> Hugo
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web-based python?

2010-08-01 Thread Hugo Arts
On Sun, Aug 1, 2010 at 7:46 PM, Alex Hall  wrote:
>
> I had looked into Django before. What is confusing me is that it
> sounds like it is meant to be run on the server directly. I do not
> have direct access to my server, I just rent space on it and can
> login. Maybe I am missing something, but how would I get Django onto
> my server if I do not have the physical box available to me?

ssh access is usually enough. Log in and check if you can run python
for starters. If all you have is ftp access, you'll need to ask your
host for a clarification on how you can get python to work on their
servers.

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


Re: [Tutor] web-based python?

2010-08-01 Thread bob gailer

On 8/1/2010 1:07 PM, Alex Hall wrote:

Hi all,
I have an IPowerWeb.com server, which claims to support Python. How
would I use this? For example, to start, how would I print html code
to the screen, or manage input from a form? Thanks.

   

Another participant just raised a similar question!

Unfortunately IPowerWeb.com does not "provide support for custom code or 
custom scripts. We assume that if a customer wants to use Perl, CGI, 
PHP, Python, ASP or any other scripting language, he/she has the 
necessary programming skills to manage his/her scripts."


A starting place is the following script - let's call it "test.py". 
Upload it then invoke it. Try http://url-to-your-site/test.py


#!/usr/bin/python
print "Content-type: text/html"
print
print ""
print "Hello World from Python"
print ""
print "Standard Hello World from a Python CGI Script"
print "

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Help with Import Error problems

2010-08-01 Thread Evert Rol
> I got it back working. But it was with some stroke of luck. And I dont know 
> the explanation.
> 
> I installed the latest source of GEOS (as suggested by someone from the gdal 
> channel). Then i tried the script. It gave me a different import error. 
> 
> ImportError: libgeos-3.3.0.so: cannot open shared object file: No such file 
> or directory
> 
> I uninstalled the thing. And then tried the script again and it worked. :| I 
> answered some of your questions below. Again, thanks.

Sounds like a library mess-up. System thing, definitely not a Python thing. 
Installing the latest source was a bit of an odd suggestion, if you got things 
working earlier.
But it's good it's working now. Just be careful that it doesn't come back to 
bite you when you install more things.

Few other things below, after the break:




> For a quick check, try the following from the command line:
> $> ldd /usr/lib/libspatialite.so.2
> 
> The command line returns the following lines:
> 
>   linux-vdso.so.1 =>  (0x7fff6edff000)
>   libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x7f793015c000)
>   libgeos_c.so.1 => /usr/local/lib/libgeos_c.so.1 (0x7f792ff4f000)
>   libgeos-3.2.2.so => /usr/lib/libgeos-3.2.2.so (0x7f792fbe8000)
>   libproj.so.0 => /usr/lib/libproj.so.0 (0x7f792f9a6000)
>   libm.so.6 => /lib/libm.so.6 (0x7f792f723000)
>   libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f792f40e000)
>   libpthread.so.0 => /lib/libpthread.so.0 (0x7f792f1f1000)
>   libdl.so.2 => /lib/libdl.so.2 (0x7f792efed000)
>   libc.so.6 => /lib/libc.so.6 (0x7f792ec69000)
>   libgeos.so.2 => /usr/local/lib/libgeos.so.2 (0x7f792e964000)
>   libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x7f792e74d000)
>   /lib64/ld-linux-x86-64.so.2 (0x7f7930688000)
>  
> I dont know what to make of it.

It's the pointers to the libgeos libraries that are interesting.
Which shows that one libgeos lives in /usr/lib, while the other one can be 
found in /usr/local/lib. And libgeos_c also lives in /usr/local/lib.
So it still feels a bit messy, having similarly named libraries in two 
different system directories, and you may run into some compatibility issues 
later on, in just a few specific functions or classes. May, because I've never 
used this software. 
You should scan through /usr/local/lib for more libgeos* libraries. If you find 
libgeos-3.2.2.so there as well, then probably that should actually be the 
preferred one (although then libspatialite.so.2 should also be in 
/usr/local/lib). Anyway, don't change it if it's working.
See also below.

> and see if it has any missing dependencies. If there's any missing (you can 
> also post the output here if you'd like), see if you can that dependency 
> somewhere on your system (the 'locate' command can help, or just good-old 
> 'find'). If it's missing from libspatialite but you can find that library 
> somewhere on your system (that would probably be the GEOS library then), it's 
> your LD_LIBRARY_PATH that's likely different.
> 
> Also, what linux distro are you using? Maybe you've been using the package 
> manager overzealously, causing some essential packages to be modified or 
> removed?
> 
> 
> I'm on Ubuntu 10.04 (64 bit). I think it was from installing different 
> GIS-related software (not all of which could be installed from the package 
> manager).

So perhaps some stuff automatically installed in /usr/lib (that could be 
software installed through the package manager), and then you used the usual 
./configure; make; make install (or python setup.py install; or whatever), 
which most likely (hopefully, actually) would install things in /usr/local/lib. 
And somewhere along the way, a library got removed or replaced by a different 
version library, and things stopped working. 
What exactly happened is hard to tell, depending on how exactly you installed 
everything, and in which order.

I hope this keeps working for you. Probably the folks on the gdal channel or 
related mailing lists could otherwise help you; but perhaps then tell them you 
have the geos & related libraries spread across /usr/lib and /usr/local/lib.

Cheers,

  Evert

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


Re: [Tutor] Help with Import Error problems

2010-08-01 Thread Roy Khristopher Bayot
Evert,

Thank you very much. I do hope it goes on working.  :D

Roy

On Mon, Aug 2, 2010 at 2:09 AM, Evert Rol  wrote:

> > I got it back working. But it was with some stroke of luck. And I dont
> know the explanation.
> >
> > I installed the latest source of GEOS (as suggested by someone from the
> gdal channel). Then i tried the script. It gave me a different import error.
> >
> > ImportError: libgeos-3.3.0.so: cannot open shared object file: No such
> file or directory
> >
> > I uninstalled the thing. And then tried the script again and it worked.
> :| I answered some of your questions below. Again, thanks.
>
> Sounds like a library mess-up. System thing, definitely not a Python thing.
> Installing the latest source was a bit of an odd suggestion, if you got
> things working earlier.
> But it's good it's working now. Just be careful that it doesn't come back
> to bite you when you install more things.
>
> Few other things below, after the break:
>
> 
>
>
> > For a quick check, try the following from the command line:
> > $> ldd /usr/lib/libspatialite.so.2
> >
> > The command line returns the following lines:
> >
> >   linux-vdso.so.1 =>  (0x7fff6edff000)
> >   libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x7f793015c000)
> >   libgeos_c.so.1 => /usr/local/lib/libgeos_c.so.1
> (0x7f792ff4f000)
> >   libgeos-3.2.2.so => /usr/lib/libgeos-3.2.2.so (0x7f792fbe8000)
> >   libproj.so.0 => /usr/lib/libproj.so.0 (0x7f792f9a6000)
> >   libm.so.6 => /lib/libm.so.6 (0x7f792f723000)
> >   libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f792f40e000)
> >   libpthread.so.0 => /lib/libpthread.so.0 (0x7f792f1f1000)
> >   libdl.so.2 => /lib/libdl.so.2 (0x7f792efed000)
> >   libc.so.6 => /lib/libc.so.6 (0x7f792ec69000)
> >   libgeos.so.2 => /usr/local/lib/libgeos.so.2 (0x7f792e964000)
> >   libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x7f792e74d000)
> >   /lib64/ld-linux-x86-64.so.2 (0x7f7930688000)
> >
> > I dont know what to make of it.
>
> It's the pointers to the libgeos libraries that are interesting.
> Which shows that one libgeos lives in /usr/lib, while the other one can be
> found in /usr/local/lib. And libgeos_c also lives in /usr/local/lib.
> So it still feels a bit messy, having similarly named libraries in two
> different system directories, and you may run into some compatibility issues
> later on, in just a few specific functions or classes. May, because I've
> never used this software.
> You should scan through /usr/local/lib for more libgeos* libraries. If you
> find libgeos-3.2.2.so there as well, then probably that should actually be
> the preferred one (although then libspatialite.so.2 should also be in
> /usr/local/lib). Anyway, don't change it if it's working.
> See also below.
>
> > and see if it has any missing dependencies. If there's any missing (you
> can also post the output here if you'd like), see if you can that dependency
> somewhere on your system (the 'locate' command can help, or just good-old
> 'find'). If it's missing from libspatialite but you can find that library
> somewhere on your system (that would probably be the GEOS library then),
> it's your LD_LIBRARY_PATH that's likely different.
> >
> > Also, what linux distro are you using? Maybe you've been using the
> package manager overzealously, causing some essential packages to be
> modified or removed?
> >
> >
> > I'm on Ubuntu 10.04 (64 bit). I think it was from installing different
> GIS-related software (not all of which could be installed from the package
> manager).
>
> So perhaps some stuff automatically installed in /usr/lib (that could be
> software installed through the package manager), and then you used the usual
> ./configure; make; make install (or python setup.py install; or whatever),
> which most likely (hopefully, actually) would install things in
> /usr/local/lib.
> And somewhere along the way, a library got removed or replaced by a
> different version library, and things stopped working.
> What exactly happened is hard to tell, depending on how exactly you
> installed everything, and in which order.
>
> I hope this keeps working for you. Probably the folks on the gdal channel
> or related mailing lists could otherwise help you; but perhaps then tell
> them you have the geos & related libraries spread across /usr/lib and
> /usr/local/lib.
>
> Cheers,
>
>  Evert
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web-based python?

2010-08-01 Thread Alex Hall
On 8/1/10, bob gailer  wrote:
> On 8/1/2010 1:07 PM, Alex Hall wrote:
>> Hi all,
>> I have an IPowerWeb.com server, which claims to support Python. How
>> would I use this? For example, to start, how would I print html code
>> to the screen, or manage input from a form? Thanks.
> Another participant just raised a similar question!
>
> Unfortunately IPowerWeb.com does not "provide support for custom code or
> custom scripts. We assume that if a customer wants to use Perl, CGI,
> PHP, Python, ASP or any other scripting language, he/she has the
> necessary programming skills to manage his/her scripts."
Sure, but django would be quite helpful. I want to do more than just
print, the point is to be able to handle form input, resize/position
images, all that. Still, it is good to not have to go through the
hastle of getting a straight answer from an iPowerWeb tech support
person. Last time I asked them about my htaccess file they deleted it!
>
> A starting place is the following script - let's call it "test.py".
> Upload it then invoke it. Try http://url-to-your-site/test.py
>
> #!/usr/bin/python
Is this line necessary? I ask because, on Windows, it is ignored, and
I do not know the path to the server's Python interpreter even if it
is required.
> print "Content-type: text/html"
> print
> print ""
> print "Hello World from Python"
> print ""
> print "Standard Hello World from a Python CGI Script"
> print "
Thanks. I assume all built-in functions will work. Would I be able to
upload and use packages?
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
 is a work in progress. If I
could get the script to tell whether or not the pickle files already
existed, I could radically revise it (yeah, functions and all :) ). So
how to find if a file exists?

Vista, Python 3.1

Thanks,

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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread python
Richard,

Look at the os.path.isfile function.

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


Re: [Tutor] web-based python?

2010-08-01 Thread Hugo Arts
On Sun, Aug 1, 2010 at 8:28 PM, Alex Hall  wrote:
>
> Sure, but django would be quite helpful. I want to do more than just
> print, the point is to be able to handle form input, resize/position
> images, all that. Still, it is good to not have to go through the
> hastle of getting a straight answer from an iPowerWeb tech support
> person. Last time I asked them about my htaccess file they deleted it!

IIRC Some frameworks can work through CGI. Not django, I believe, at
least not officially. But it's worth googling around, there might be
some custom solutions.

> Is this line necessary? I ask because, on Windows, it is ignored, and
> I do not know the path to the server's Python interpreter even if it
> is required.

including it can never hurt. Linux systems sometimes need it. If you
replace /usr/bin/python with /usr/bin/env python, env will find the
python interpreter for you (assuming env is set up).

> Thanks. I assume all built-in functions will work. Would I be able to
> upload and use packages?

Sure, just put them in your path and you're good to go. Maybe put a
.htaccess so that it can't be accessed through http.

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


Re: [Tutor] web-based python?

2010-08-01 Thread Che M



> > There is a myriad of python web development frameworks. Here's a link
> > with a ton of info:
> >
> > http://wiki.python.org/moin/WebFrameworks
> I had looked into Django before. What is confusing me is that it
> sounds like it is meant to be run on the server directly. I do not
> have direct access to my server, I just rent space on it and can
> login. Maybe I am missing something, but how would I get Django onto
> my server if I do not have the physical box available to me?

For a long time I have hoped for a "Python web apps for absolute beginners"
tutorial that doesn't assume any knowledge.  For a beginner, it is not even
clear what a "web frameworks" is let alone which one he/she should start
with or if it is even needed.  I just checked Alan Gauld's Learning to Program
and was disappointed to see the section on writing web apps hasn't been
done yet, since all the other tutorial material is so good (I understand that
it is a lot of work to write these, though, and greatly appreciate all you have
already done).

Brainstorming what a good soup-to-nuts tutorial for Python web apps 
might include...

- What the the various kinds of web apps one can make are and (very) roughly 
  how much work each entails.  In other words, there is a difference between
  writing an online newspaper vs. a web based GUI app.
- Whether it matters if you develop on Windows, Linux, or Mac.
- The easiest possible "Hello, World!" (just text) in a web browser.
- How much of other languages (XHTML, CSS, Javascript, etc.) you need to know.
- What you need to understand about servers and how to communicate with them.
- How you can get more than just text on a web app, that is, widgets, and
  therefore what are currently the options for that (learning javascript and 
whatever
  widget toolkits are out there for that; qooxdoo; Pyjamas; others).
- Whether you could use Pyjamas to make your code work as both a web app
  and a desktop app.
- How you can develop your web app on your own computer and when you
  need to test it actually on the web.
- What to consider when choosing a way to host your app online.
- How to get your Python code onto that server, as well as whatever other
  code (like Django) there too. (Alex's question)
- Why starting with a MVC pattern may be the best way to go for a web app.
- What you need to consider to make your web app work the same on most browsers.
- Scalability issues, speed issues, Security issues, cost issues; etc.
- What databases to use and why
- Issues concerning whether your app can be used by iPhones and other smart 
phones.
- Opening your code to contribution; monetizing your service
- Probably lots of other stuff I don't even know about.

I understand much of this is about web apps generally and is not germane
only to Python, but it would be good if a Python tutorial at least pointed 
toward
this information, since for many beginners, the entry portal to anything is 
through
Python.  To just refer someone to Django when they don't know the first thing 
about
web apps is, I think, off-putting.

Che


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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 11:33,   wrote:
> Richard,
>
> Look at the os.path.isfile function.
>
> Malcolm

Thanks, Malcolm. That makes a tremendous difference.

If anyone's curious, they see what use I've made of
os.path.isfile(path): 

Dick


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


[Tutor] sys.exit help

2010-08-01 Thread Jason MacFiggen
I was wondering how can I change sys.exit so if you use command line to run
the program. it prompts a message asking if the user wants to exit instead
of automatically just exiting?

import random
import sys
my_hp = 50
mo_hp = 50
menu1 = """
Menu Selections:
1 - Attack
2 - Defend
3 - Help
4 - Exit
"""
print menu1
while True:
my_dmg = random.randrange(1, 20)
mo_dmg = random.randrange(1, 20)

choice = input ("\nEnter your selection. ")
choice = float(choice)
print
if choice == 1:
mo_hp = mo_hp - my_dmg
if mo_hp <= 0:
print "Iris is at 0 Hit Points!\nYOU HAVE SLAIN IRIS!"
sys.exit(0)
elif mo_hp > 0:
print
"-"
print "Iris is at %s Hit Points\nYou did %s damage\n" %
(mo_hp, my_dmg)
my_hp = my_hp - mo_dmg
if my_hp <= 0:
print "Your Hit Points are 0!\nYOU HAVE BEEN SLAIN BY Iris!"
sys.exit(0)
elif my_hp > 0:
print name,"was attacked by Iris for %s damage!\nMy Hit
Points are %s" % (mo_dmg, my_hp)
print
"-"
else:
print menu1


elif choice == 2:
mo_hp = mo_hp - my_dmg / 2
if mo_hp <= 0:
print "The Lich King is at 0 Hit Points!\nYOU HAVE SLAIN
IRIS!"
sys.exit(0)
elif mo_hp > 0:
print
"-"
print "The Lich King is at %s Hit Points\nYou did %s
damage\n" % (mo_hp, my_dmg)
my_hp = my_hp - mo_dmg / 2
if my_hp <= 0:
print "Your Hit Points are 0!\nYOU HAVE BEEN SLAIN BY IRIS!"
sys.exit(0)
elif my_hp > 0:
print name,"was attacked by the Iris for %s damage!\nMy Hit
Points are %s" % (mo_dmg, my_hp)
print
"-"
else:
print menu1

elif choice == 3:
print """
-
Attack = Attack for 100% of damage.
Defending = Attack for 50% of damage and endure 50% of damage.
-
"""
elif choice == 4:
sys.exit(0)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sys.exit help

2010-08-01 Thread Hugo Arts
On Sun, Aug 1, 2010 at 10:26 PM, Jason MacFiggen  wrote:
> I was wondering how can I change sys.exit so if you use command line to run
> the program. it prompts a message asking if the user wants to exit instead
> of automatically just exiting?

You can't change sys.exit, but you can build something yourself. You
have raw_input to ask the user something, and an if statement to make
a decision based on that input. You should be able to figure something
out.

One other point: if you just want to exit, you don't have to call
sys.exit really, you can just let the script end naturally (break out
of the while loop and it'll end by itself). sys.exit is only really
useful if you want a special exit status.

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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Steven D'Aprano
On Mon, 2 Aug 2010 04:29:39 am Richard D. Moores wrote:
>  is a work in progress. If I
> could get the script to tell whether or not the pickle files already
> existed, I could radically revise it (yeah, functions and all :) ).
> So how to find if a file exists?

The lazy way is with the os.file.exists() function:

if os.file.exists(filename):
f = open(filename)


Of course, the lazy way usually ends up needing more work to fix the 
bugs it introduces. This is 2010, you're running under a multi-process 
operating system where a hundred other programs are sharing time with 
you, possibly even a multi-user system with other people reading and 
writing files. So the above is wrong, because there's no guarantee that 
just because the file exists when you call os.file.exists it will still 
be there a millisecond later when you call open. So the right way is to 
ignore os.file.exists and just open the file, catching errors:

try:
f = open(filename)
except IOError:
do_something_when_the_file_isnt_there()
else:
do_something_with_file(f)




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


Re: [Tutor] sys.exit help

2010-08-01 Thread Evert Rol
> I was wondering how can I change sys.exit so if you use command line to run 
> the program. it prompts a message asking if the user wants to exit instead of 
> automatically just exiting?

Just write a wrapper exit() function around sys.exit that does that.
You don't want to change the sys.exit function to behave differently; it's 
purpose is simply to exit the program with a return value.



> import random
> import sys
> my_hp = 50
> mo_hp = 50
> menu1 = """
> Menu Selections: 
> 1 - Attack
> 2 - Defend
> 3 - Help
> 4 - Exit
> """
> print menu1
> while True:
> my_dmg = random.randrange(1, 20)
> mo_dmg = random.randrange(1, 20)
> 
> choice = input ("\nEnter your selection. ")
> choice = float(choice)
> print
> if choice == 1:
> mo_hp = mo_hp - my_dmg
> if mo_hp <= 0:
> print "Iris is at 0 Hit Points!\nYOU HAVE SLAIN IRIS!"
> sys.exit(0)
> elif mo_hp > 0:
> print 
> "-"
> print "Iris is at %s Hit Points\nYou did %s damage\n" % 
> (mo_hp, my_dmg)
> my_hp = my_hp - mo_dmg
> if my_hp <= 0:
> print "Your Hit Points are 0!\nYOU HAVE BEEN SLAIN BY Iris!"
> sys.exit(0)
> elif my_hp > 0:
> print name,"was attacked by Iris for %s damage!\nMy Hit 
> Points are %s" % (mo_dmg, my_hp)
> print 
> "-"
> else:
> print menu1
> 
> 
> elif choice == 2:
> mo_hp = mo_hp - my_dmg / 2
> if mo_hp <= 0:
> print "The Lich King is at 0 Hit Points!\nYOU HAVE SLAIN 
> IRIS!"
> sys.exit(0)
> elif mo_hp > 0:
> print 
> "-"
> print "The Lich King is at %s Hit Points\nYou did %s 
> damage\n" % (mo_hp, my_dmg)
> my_hp = my_hp - mo_dmg / 2
> if my_hp <= 0:
> print "Your Hit Points are 0!\nYOU HAVE BEEN SLAIN BY IRIS!"
> sys.exit(0)
> elif my_hp > 0:
> print name,"was attacked by the Iris for %s damage!\nMy Hit 
> Points are %s" % (mo_dmg, my_hp)
> print 
> "-"
> else:
> print menu1
> 
> elif choice == 3:
> print """
> -
> Attack = Attack for 100% of damage.
> Defending = Attack for 50% of damage and endure 50% of damage.
> -
> """
> elif choice == 4:
> sys.exit(0)
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] sys.exit help

2010-08-01 Thread Steven D'Aprano
On Mon, 2 Aug 2010 06:26:24 am Jason MacFiggen wrote:
> I was wondering how can I change sys.exit so if you use command line
> to run the program. it prompts a message asking if the user wants to
> exit instead of automatically just exiting?

Don't do that. Leave sys.exit alone, write your own quit() function that 
asks the user and then calls sys.exit if they say yes.


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


Re: [Tutor] Tutor Digest, Vol 78, Issue 8

2010-08-01 Thread Daniel Sarmiento
> Date: Sun, 1 Aug 2010 12:28:49 -0700
> From: "Richard D. Moores" 
> To: pyt...@bdurham.com
> Cc: tutor@python.org
> Subject: Re: [Tutor] How to get script to detect whether a file
>exists?
> Message-ID:
>
> Content-Type: text/plain; charset=UTF-8
>
> On Sun, Aug 1, 2010 at 11:33,   wrote:
> > Richard,
> >
> > Look at the os.path.isfile function.
> >
> > Malcolm
>
> Thanks, Malcolm. That makes a tremendous difference.
>
> If anyone's curious, they see what use I've made of
> os.path.isfile(path): 
>
> Dick
>
>
> >
>
>
> --
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 78, Issue 8
> 
>

I don't know if I am right, but I remember reading it is better to try to
open the files and see if an exception is raised than checking if the files
exist.  In that way one can avoid TOCTTOU bugs (
http://en.wikipedia.org/wiki/Time-of-check-to-time-of-use )

Without knowing what your code does, I think it will be something like:

try:
F_unused = open(path1, 'rb')
F_used = open(path2, 'rb')
except IOError:
print("no")
.
else:
unused_ints = pickle.load(F_unused)
..

HTH

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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Daniel Sarmiento
> Date: Sun, 1 Aug 2010 12:28:49 -0700
> From: "Richard D. Moores" 
> To: pyt...@bdurham.com
> Cc: tutor@python.org
> Subject: Re: [Tutor] How to get script to detect whether a file
>exists?
> Message-ID:
>
> Content-Type: text/plain; charset=UTF-8
>
> On Sun, Aug 1, 2010 at 11:33,   wrote:
> > Richard,
> >
> > Look at the os.path.isfile function.
> >
> > Malcolm
>
> Thanks, Malcolm. That makes a tremendous difference.
>
> If anyone's curious, they see what use I've made of
> os.path.isfile(path): 
>
> Dick
>
>
> >
>
>
> --
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
I don't know if I am right, but I remember reading it is better to try to
open the files and see if an exception is raised than checking if the files
exist.  In that way one can avoid TOCTTOU bugs (
http://en.wikipedia.org/wiki/Time-of-check-to-time-of-use )

Without knowing what your code does, I think it will be something like:

try:
F_unused = open(path1, 'rb')
F_used = open(path2, 'rb')
except IOError:
print("no")
.
else:
unused_ints = pickle.load(F_unused)
..

HTH

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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 13:37, Steven D'Aprano  wrote:
> On Mon, 2 Aug 2010 04:29:39 am Richard D. Moores wrote:
>>  is a work in progress. If I
>> could get the script to tell whether or not the pickle files already
>> existed, I could radically revise it (yeah, functions and all :) ).
>> So how to find if a file exists?
>
> The lazy way is with the os.file.exists() function:
>
> if os.file.exists(filename):
>    f = open(filename)
>
>
> Of course, the lazy way usually ends up needing more work to fix the
> bugs it introduces. This is 2010, you're running under a multi-process
> operating system where a hundred other programs are sharing time with
> you, possibly even a multi-user system with other people reading and
> writing files. So the above is wrong, because there's no guarantee that
> just because the file exists when you call os.file.exists it will still
> be there a millisecond later when you call open. So the right way is to
> ignore os.file.exists and just open the file, catching errors:
>
> try:
>    f = open(filename)
> except IOError:
>    do_something_when_the_file_isnt_there()
> else:
>    do_something_with_file(f)

OK, but there are actually 2 files that need to be checked. If either
one or both are missing I need to create/recreate both. How do I do
that your way? I've forgotten the little I knew about catching errors.
My lazy way has it now as
"if not (os.path.isfile(path1) and os.path.isfile(path2)):"

Thanks,

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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 15:00, Richard D. Moores  wrote:
> On Sun, Aug 1, 2010 at 14:44, Daniel Sarmiento  wrote:
>>

>> Without knowing what your code does, I think it will be something like:
>>
>> try:
>>     F_unused = open(path1, 'rb')
>>     F_used = open(path2, 'rb')
>> except IOError:
>>     print("no")
>>     .
>> else:
>>     unused_ints = pickle.load(F_unused)

OK. Did that. And it works: .
Now what? Am I done? Or should I break it up into a bunch of
functions, each one doing just one thing?

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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Hugo Arts
On Mon, Aug 2, 2010 at 12:53 AM, Richard D. Moores  wrote:
> On Sun, Aug 1, 2010 at 15:00, Richard D. Moores  wrote:
>> On Sun, Aug 1, 2010 at 14:44, Daniel Sarmiento  wrote:
>>>
>
>>> Without knowing what your code does, I think it will be something like:
>>>
>>> try:
>>>     F_unused = open(path1, 'rb')
>>>     F_used = open(path2, 'rb')
>>> except IOError:
>>>     print("no")
>>>     .
>>> else:
>>>     unused_ints = pickle.load(F_unused)
>
> OK. Did that. And it works: .
> Now what? Am I done? Or should I break it up into a bunch of
> functions, each one doing just one thing?
>

For a script this short, you could probably get away with just leaving
it here. However, I mean that in a "if you're really lazy, I suppose
you could" way. It will become easier to understand if you break it
up, and that is good for your future sanity. So it's not required, but
it definitely can't hurt, and if this script gets any larger you will
be glad you broke it up.

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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 12:18 PM, Che M  wrote:
>
>
>> Do any of you have any feedback, strategies and best practices
>> related to unit testing within Python. This is a relatively new topic
>> for me. I was thinking of starting with reading the documentation
>> associate with the unittest module.
>
> The idea of unit testing/test driven development has remained
> foreign to me throughout my time trying to learn Python--by choice.
> I want to make desktop GUI applications and I don't use MVC, so
> the idea of writing tests strikes me as far more work--and a major
> delayer of getting to an application that actually does something--
> than simply using the software myself and noting problems.  It
> sounds like TDD is probably the most proper way to go about things,
> but, in the interest of getting something out of Python to warrant the
> time I've put into it, I favor a "good enough" approach for now.

Writers just call this a rough draft. Perfection is in the revisions
that come after a little thought.

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


Re: [Tutor] web-based python?

2010-08-01 Thread Eric Hamiter
On Sun, Aug 1, 2010 at 1:56 PM, Che M  wrote:

> For a long time I have hoped for a "Python web apps for absolute beginners"
> tutorial that doesn't assume any knowledge.  For a beginner, it is not even
> clear what a "web frameworks" is let alone which one he/she should start
> with or if it is even needed.
>
> I understand much of this is about web apps generally and is not germane
> only to Python, but it would be good if a Python tutorial at least pointed
> toward
> this information, since for many beginners, the entry portal to anything is
> through
> Python.  To just refer someone to Django when they don't know the first
> thing about
> web apps is, I think, off-putting.
>
> Che
>
> Che, my sentinments exactly. I'm looking for something similar.

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


Re: [Tutor] web-based python?

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 7:38 PM, Eric Hamiter  wrote:
> On Sun, Aug 1, 2010 at 1:56 PM, Che M  wrote:
>>
>> For a long time I have hoped for a "Python web apps for absolute
>> beginners"
>> tutorial that doesn't assume any knowledge.  For a beginner, it is not
>> even
>> clear what a "web frameworks" is let alone which one he/she should start
>> with or if it is even needed.
>>
>> I understand much of this is about web apps generally and is not germane
>> only to Python, but it would be good if a Python tutorial at least pointed
>> toward
>> this information, since for many beginners, the entry portal to anything
>> is through
>> Python.  To just refer someone to Django when they don't know the first
>> thing about
>> web apps is, I think, off-putting.

I think just using the term web app instead of interactive website is
confusing, unless by web app(and this is the way I might, incorrectly,
use the term) you mean a desktop app that works only with an internet
connection, and communication with a nonlocal server.


>>
>> Che
>>
> Che, my sentinments exactly. I'm looking for something similar.
>
> Eric
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web-based python?

2010-08-01 Thread Alan Gauld


"Che M"  wrote
For a long time I have hoped for a "Python web apps for absolute 
beginners"
  I just checked Alan Gauld's Learning to Program and was 
disappointed

to see the section on writing web apps hasn't been done yet,


I started on the client side topic but then Python 3 came out and I've
been diverted rewriting everything for that. I'm hoping to get the v3 
tutorial

up to the same place as the v2 one by the end of the year - then maybe
I'll get round to finishing the web programming section.

However I will only be covering basic CGI scripting, I don't intend to 
attemp

any of the Frameworks. Mainly becauase moast of them have perfectly
good tutorials already once you understand the bare bones of CGI.

- What the the various kinds of web apps one can make are and (very) 
roughly
  how much work each entails.  In other words, there is a difference 
between

  writing an online newspaper vs. a web based GUI app.


Actually web apps are all pretty similar. They consist of three basic 
parts

(maybe 4):
1) A mechanism for mapping a URL to a Python function or method.
2) A mechanism for generating HTML with embedded data values
3) A data storage mechanism
4) Some client code for a more dynamic feel

What they look like is just down to HTML creativity. But they all 
start

out as an HTML web page with some kind of form that captures data.
When you submit the form yyou send some data to the server which
interprets it and generates a new HTML page back again. There might
be some flash graphics or some Javascript doing clever display stuff
to make tings more dynamic, but basically all web apps work by
capturing some data and sending it to a server which generates a
new page in response.

In fact designing a web app is a lot like designing an old fashioned
mainframe terminal application. They also worked on a page view basis
albeit a 24linex80character display page...


- Whether it matters if you develop on Windows, Linux, or Mac.


The whole point of the web is that it doersn'ty care. You can write 
platform
specific web code - especially on Microsoft platforms - but all that 
does

is limits your audience. There is no good reason to do it.


- The easiest possible "Hello, World!" (just text) in a web browser.


Hello, World!

That's it as a one liner.

If you want it as a CGI program in Python its only slightly longer
and the CGI documentation shows you how...

- How much of other languages (XHTML, CSS, Javascript, etc.) you 
need to know.


That all depends on how fancy you want the presentation to be.
For professional standard you will definitely need all 3.
For basic stuff HTML is all you really need.

- What you need to understand about servers and how to communicate 
with them.


Not a lot if you use a Framework, but debugging problems is easier
if you understand whats actually happening.

- How you can get more than just text on a web app, that is, 
widgets, and
  therefore what are currently the options for that (learning 
javascript and whatever

  widget toolkits are out there for that; qooxdoo; Pyjamas; others).


This is where it gets very complicated. There are lots of different 
ways of
doing widgets (in out company we have a "standard" that defines 4 
levels,
or kinds, of widget you can build and still be complant with the 
company

architecture! The simplest is an IFrame fragment)


- Whether you could use Pyjamas to make your code work
as both a web app and a desktop app.


I've heard of pyjamas but not used it. The .NET framework has a 
similar
concept but in my experience the results are usually not very good 
GUIs
and not very good web apps... Its better to design for one or the 
other

and do a good job for that one.


- How you can develop your web app on your own computer and when you
  need to test it actually on the web.


Thats usually just a case of running a web server on your PC.
There are many to choose from and Python even offers a couple in the
standard library.


- What to consider when choosing a way to host your app online.
- How to get your Python code onto that server, as well as whatever 
other

  code (like Django) there too. (Alex's question)


ftp is the usual way.

- Why starting with a MVC pattern may be the best way to go for a 
web app.


MVC is usually the best pattern for any UI centric app, whether 
desktop,

client/server or web. It maximises reuse and clarifies the logic.


- What you need to consider to make your web app work the same
on most browsers.


Stick to established standards and remember that by its nature the web
does not give you fine control. So design the GUI in the knowledge 
that
different browsers will do different things with it and that is their 
right - and
that of your user. Then realise that this will invariably compromise 
the

user experienve. So you then decide whether maximum reach or maximum
user satisfaction is most important to you.

- Scalability issues, speed issues, Security issues, cost issues; 
etc.


Pretty much

Re: [Tutor] sys.exit help

2010-08-01 Thread Alan Gauld


"Jason MacFiggen"  wrote

I was wondering how can I change sys.exit so if you use command line 
to run
the program. it prompts a message asking if the user wants to exit 
instead

of automatically just exiting?


Don't just use sys.exit use a try/except SystemExit...

import sys
try:

...sys.exit()
... except SystemExit:
...print 'caught exit'
...raise
...
caught exit

However thats usually the wrong way to do it.
Better to have your program exit naturally and have the control logic 
in

the code control when it finishes.

HTH,


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


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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 16:01, Hugo Arts  wrote:
> On Mon, Aug 2, 2010 at 12:53 AM, Richard D. Moores  wrote:
>> On Sun, Aug 1, 2010 at 15:00, Richard D. Moores  wrote:
>>> On Sun, Aug 1, 2010 at 14:44, Daniel Sarmiento  
>>> wrote:

>>
 Without knowing what your code does, I think it will be something like:

 try:
     F_unused = open(path1, 'rb')
     F_used = open(path2, 'rb')
 except IOError:
     print("no")
     .
 else:
     unused_ints = pickle.load(F_unused)
>>
>> OK. Did that. And it works: .
>> Now what? Am I done? Or should I break it up into a bunch of
>> functions, each one doing just one thing?
>>
>
> For a script this short, you could probably get away with just leaving
> it here. However, I mean that in a "if you're really lazy, I suppose
> you could" way. It will become easier to understand if you break it
> up, and that is good for your future sanity. So it's not required, but
> it definitely can't hurt, and if this script gets any larger you will
> be glad you broke it up.

Well, I'd like to try. Could you give me, say, an outline of what
might be a good way? Actually, before I changed to the error catching,
I tried to break it up into a bunch of small functions. But they got
all tangled up with some functions returning the calling of others,
that I couldn't get them straightened out. Also, some were required to
have such a long string of arguments I couldn't get them all on one
line.

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


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Hugo Arts
On Mon, Aug 2, 2010 at 2:26 AM, Richard D. Moores  wrote:
>
> Well, I'd like to try. Could you give me, say, an outline of what
> might be a good way? Actually, before I changed to the error catching,
> I tried to break it up into a bunch of small functions. But they got
> all tangled up with some functions returning the calling of others,
> that I couldn't get them straightened out. Also, some were required to
> have such a long string of arguments I couldn't get them all on one
> line.
>

For starters, the code recreating both your files is almost exactly
the same, so you can easily turn that into one function and call it
twice. I see two necessary arguments, the path and the data you're
dumping in. See if you can work that one out.

The file saving code at the end is another one that can be easily made
into one function and called twice. If you get those two pieces done
you should be in good shape.

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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Che M



> > The idea of unit testing/test driven development has remained
> > foreign to me throughout my time trying to learn Python--by choice.
> > I want to make desktop GUI applications and I don't use MVC, so
> > the idea of writing tests strikes me as far more work--and a major
> > delayer of getting to an application that actually does something--
> > than simply using the software myself and noting problems.  It
> > sounds like TDD is probably the most proper way to go about things,
> > but, in the interest of getting something out of Python to warrant the
> > time I've put into it, I favor a "good enough" approach for now.
> 
> Writers just call this a rough draft. Perfection is in the revisions
> that come after a little thought.

Well, I don't see what I'm doing as a rough draft, as I am attempting
to hone it to "perfection" (that is, a working app)--just without unit testing.

A different analogy comes to my mind; I once saw two different sets of
people analyze data.  One did it "by hand":  visually inspecting thousands
of signals herself and typing Y or N to accept or reject each signal.  The
other did it with an automated system that accepted or rejected signals 
based on fuzzy logic.  In an important interpretation, the automated system 
was far better, and yet the first scientist was done with her analysis and
accepted for publication before the second team even had the bugs worked 
out of the automated system!  Yes, I think the slow-but-more-proper team
did the more correct thing, but there is something to be said for "good
enough", too (it works for evolution, for example).



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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 9:11 PM, Che M  wrote:
>
>
>> > The idea of unit testing/test driven development has remained
>> > foreign to me throughout my time trying to learn Python--by choice.
>> > I want to make desktop GUI applications and I don't use MVC, so
>> > the idea of writing tests strikes me as far more work--and a major
>> > delayer of getting to an application that actually does something--
>> > than simply using the software myself and noting problems.  It
>> > sounds like TDD is probably the most proper way to go about things,
>> > but, in the interest of getting something out of Python to warrant the
>> > time I've put into it, I favor a "good enough" approach for now.
>>
>> Writers just call this a rough draft. Perfection is in the revisions
>> that come after a little thought.
>
> Well, I don't see what I'm doing as a rough draft, as I am attempting
> to hone it to "perfection" (that is, a working app)--just without unit
> testing.

Every time you try to perfect is a revision of your initial 'written'
algorithm. From concept forward is your revisions. Notice that svn and
cvs are called revisions. How quickly is a different story. To you,
your writing and rewriting, but each rewrite is a revision of the
initial concept. And as far as i can tell, if you want to be the unit
test yourself, it's fine, but unit testing might be inappropriate for
something like this. But basically unit testing would be a script that
inputs the possible combinations of requests to the original script,
which should be tested like chefs do soups-intermittently as you
design it. So the tests are really what you put or type as input given
directly to the script , right?.



>
> A different analogy comes to my mind; I once saw two different sets of
> people analyze data.  One did it "by hand":  visually inspecting thousands
> of signals herself and typing Y or N to accept or reject each signal.  The
> other did it with an automated system that accepted or rejected signals
> based on fuzzy logic.

This depends on your need for control, do you need to manually accept,
or can you just detect the signal, and let the program proceedl. Do
you want the local nuclear plant to have their system throw an error,
without a human response?

In an important interpretation, the automated system
> was far better, and yet the first scientist was done with her analysis and
> accepted for publication before the second team even had the bugs worked
> out of the automated system!

Like you state below, the automated system used, evolved from manually
designed systems, so automation is the easy way, but sometimes not the
best, depending on the circumstance and priority level of the
information being received.

Yes, I think the slow-but-more-proper team
> did the more correct thing, but there is something to be said for "good
> enough", too (it works for evolution, for example).


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


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 9:31 PM, David Hutto  wrote:
> On Sun, Aug 1, 2010 at 9:11 PM, Che M  wrote:
>>
>>
>>> > The idea of unit testing/test driven development has remained
>>> > foreign to me throughout my time trying to learn Python--by choice.
>>> > I want to make desktop GUI applications and I don't use MVC, so
>>> > the idea of writing tests strikes me as far more work--and a major
>>> > delayer of getting to an application that actually does something--
>>> > than simply using the software myself and noting problems.  It
>>> > sounds like TDD is probably the most proper way to go about things,
>>> > but, in the interest of getting something out of Python to warrant the
>>> > time I've put into it, I favor a "good enough" approach for now.
>>>
>>> Writers just call this a rough draft. Perfection is in the revisions
>>> that come after a little thought.
>>
>> Well, I don't see what I'm doing as a rough draft, as I am attempting
>> to hone it to "perfection" (that is, a working app)--just without unit
>> testing.
>
> Every time you try to perfect is a revision of your initial 'written'
> algorithm. From concept forward is your revisions. Notice that svn and
> cvs are called revisions. How quickly is a different story. To you,
> your writing and rewriting, but each rewrite is a revision of the
> initial concept. And as far as i can tell, if you want to be the unit
> test yourself, it's fine, but unit testing might be inappropriate for
> something like this. But basically unit testing would be a script that
> inputs the possible combinations of requests to the original script,
> which should be tested like chefs do soups-intermittently as you
> design it. So the tests are really what you put or type as input given
> directly to the script , right?.
>
>
>
>>
>> A different analogy comes to my mind; I once saw two different sets of
>> people analyze data.  One did it "by hand":  visually inspecting thousands
>> of signals herself and typing Y or N to accept or reject each signal.  The
>> other did it with an automated system that accepted or rejected signals
>> based on fuzzy logic.
>
> This depends on your need for control, do you need to manually accept,
> or can you just detect the signal, and let the program proceedl. Do
> you want the local nuclear plant to have their system throw an error,
> without a human response?
>
> In an important interpretation, the automated system
>> was far better, and yet the first scientist was done with her analysis and
>> accepted for publication before the second team even had the bugs worked
>> out of the automated system!
>
> Like you state below, the automated system used, evolved from manually
> designed systems, so automation is the easy way, but sometimes not the
> best, depending on the circumstance and priority level of the
> information being received.
>
> Yes, I think the slow-but-more-proper team
>> did the more correct thing, but there is something to be said for "good
>> enough", too (it works for evolution, for example).
>
>
>>
>>
>>
>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>

Disclaimer: I have no clue what unit testing is, nor have I had to use it yet.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 9:39 PM, David Hutto  wrote:
> On Sun, Aug 1, 2010 at 9:31 PM, David Hutto  wrote:
>> On Sun, Aug 1, 2010 at 9:11 PM, Che M  wrote:
>>>
>>>
 > The idea of unit testing/test driven development has remained
 > foreign to me throughout my time trying to learn Python--by choice.
 > I want to make desktop GUI applications and I don't use MVC, so
 > the idea of writing tests strikes me as far more work--and a major
 > delayer of getting to an application that actually does something--
 > than simply using the software myself and noting problems.  It
 > sounds like TDD is probably the most proper way to go about things,
 > but, in the interest of getting something out of Python to warrant the
 > time I've put into it, I favor a "good enough" approach for now.

 Writers just call this a rough draft. Perfection is in the revisions
 that come after a little thought.
>>>
>>> Well, I don't see what I'm doing as a rough draft, as I am attempting
>>> to hone it to "perfection" (that is, a working app)--just without unit
>>> testing.
>>
>> Every time you try to perfect is a revision of your initial 'written'
>> algorithm. From concept forward is your revisions. Notice that svn and
>> cvs are called revisions. How quickly is a different story. To you,
>> your writing and rewriting, but each rewrite is a revision of the
>> initial concept. And as far as i can tell, if you want to be the unit
>> test yourself, it's fine, but unit testing might be inappropriate for
>> something like this. But basically unit testing would be a script that
>> inputs the possible combinations of requests to the original script,
>> which should be tested like chefs do soups-intermittently as you
>> design it. So the tests are really what you put or type as input given
>> directly to the script , right?.
>>
>>
>>
>>>
>>> A different analogy comes to my mind; I once saw two different sets of
>>> people analyze data.  One did it "by hand":  visually inspecting thousands
>>> of signals herself and typing Y or N to accept or reject each signal.  The
>>> other did it with an automated system that accepted or rejected signals
>>> based on fuzzy logic.
>>
>> This depends on your need for control, do you need to manually accept,
>> or can you just detect the signal, and let the program proceedl. Do
>> you want the local nuclear plant to have their system throw an error,
>> without a human response?
>>
>> In an important interpretation, the automated system
>>> was far better, and yet the first scientist was done with her analysis and
>>> accepted for publication before the second team even had the bugs worked
>>> out of the automated system!
>>
>> Like you state below, the automated system used, evolved from manually
>> designed systems, so automation is the easy way, but sometimes not the
>> best, depending on the circumstance and priority level of the
>> information being received.
>>
>> Yes, I think the slow-but-more-proper team
>>> did the more correct thing, but there is something to be said for "good
>>> enough", too (it works for evolution, for example).
>>
>>
>>>
>>>
>>>
>>>
>>> ___
>>> Tutor maillist  -  tu...@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>
> Disclaimer: I have no clue what unit testing is, nor have I had to use it yet.
>

But it would be a series of function instances from a module, right?
Not to butt in on the OP.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Huy Ton That
All these responses are incredible, I will go through them on my venture to
bring unit testing under my belt.

I have never done formal unit testing in my programming career, I've just
gone through way of general debugging and utilizing version control such as
Mercurial.

On Sun, Aug 1, 2010 at 9:42 PM, David Hutto  wrote:

> On Sun, Aug 1, 2010 at 9:39 PM, David Hutto  wrote:
> > On Sun, Aug 1, 2010 at 9:31 PM, David Hutto 
> wrote:
> >> On Sun, Aug 1, 2010 at 9:11 PM, Che M  wrote:
> >>>
> >>>
>  > The idea of unit testing/test driven development has remained
>  > foreign to me throughout my time trying to learn Python--by choice.
>  > I want to make desktop GUI applications and I don't use MVC, so
>  > the idea of writing tests strikes me as far more work--and a major
>  > delayer of getting to an application that actually does something--
>  > than simply using the software myself and noting problems.  It
>  > sounds like TDD is probably the most proper way to go about things,
>  > but, in the interest of getting something out of Python to warrant
> the
>  > time I've put into it, I favor a "good enough" approach for now.
> 
>  Writers just call this a rough draft. Perfection is in the revisions
>  that come after a little thought.
> >>>
> >>> Well, I don't see what I'm doing as a rough draft, as I am attempting
> >>> to hone it to "perfection" (that is, a working app)--just without unit
> >>> testing.
> >>
> >> Every time you try to perfect is a revision of your initial 'written'
> >> algorithm. From concept forward is your revisions. Notice that svn and
> >> cvs are called revisions. How quickly is a different story. To you,
> >> your writing and rewriting, but each rewrite is a revision of the
> >> initial concept. And as far as i can tell, if you want to be the unit
> >> test yourself, it's fine, but unit testing might be inappropriate for
> >> something like this. But basically unit testing would be a script that
> >> inputs the possible combinations of requests to the original script,
> >> which should be tested like chefs do soups-intermittently as you
> >> design it. So the tests are really what you put or type as input given
> >> directly to the script , right?.
> >>
> >>
> >>
> >>>
> >>> A different analogy comes to my mind; I once saw two different sets of
> >>> people analyze data.  One did it "by hand":  visually inspecting
> thousands
> >>> of signals herself and typing Y or N to accept or reject each signal.
> The
> >>> other did it with an automated system that accepted or rejected signals
> >>> based on fuzzy logic.
> >>
> >> This depends on your need for control, do you need to manually accept,
> >> or can you just detect the signal, and let the program proceedl. Do
> >> you want the local nuclear plant to have their system throw an error,
> >> without a human response?
> >>
> >> In an important interpretation, the automated system
> >>> was far better, and yet the first scientist was done with her analysis
> and
> >>> accepted for publication before the second team even had the bugs
> worked
> >>> out of the automated system!
> >>
> >> Like you state below, the automated system used, evolved from manually
> >> designed systems, so automation is the easy way, but sometimes not the
> >> best, depending on the circumstance and priority level of the
> >> information being received.
> >>
> >> Yes, I think the slow-but-more-proper team
> >>> did the more correct thing, but there is something to be said for "good
> >>> enough", too (it works for evolution, for example).
> >>
> >>
> >>>
> >>>
> >>>
> >>>
> >>> ___
> >>> Tutor maillist  -  Tutor@python.org
> >>> To unsubscribe or change subscription options:
> >>> http://mail.python.org/mailman/listinfo/tutor
> >>>
> >>>
> >>
> >
> > Disclaimer: I have no clue what unit testing is, nor have I had to use it
> yet.
> >
>
> But it would be a series of function instances from a module, right?
> Not to butt in on the OP.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread Mac Ryan
> A different analogy comes to my mind; I once saw two different sets of
> people analyze data.  One did it "by hand":  visually inspecting
> thousands
> of signals herself and typing Y or N to accept or reject each signal.
> The
> other did it with an automated system that accepted or rejected
> signals 
> based on fuzzy logic.  In an important interpretation, the automated
> system 
> was far better, and yet the first scientist was done with her analysis
> and
> accepted for publication before the second team even had the bugs
> worked 
> out of the automated system!  Yes, I think the slow-but-more-proper
> team
> did the more correct thing, but there is something to be said for
> "good
> enough", too (it works for evolution, for example).

Che, from the analogies you made, it looks like you might not have very
clear what Unit Testing is for.

True, UT is a way to automate tests that otherwise you should do
manually (as per your analogy), but the test you automate with UT are
not a "one off" thing (as it is processing the data needed to publish a
paper): depending on the coding philosophy you follow, you might run UT
as often as every couple of hours of coding (as it is in certain agile
programming techniques).

UT is there to give you a tool to prevent regression *when/if you modify
or refactor your code* (which is the norm if you are a professional
programmer), and its advantages grow exponentially with the increase of
complexity of the code and the increase of number of developers working
on the project (it is very easy to break someone's else code... there is
a reason for which "blame" - http://blame.sourceforge.net/ - is called
that way!).

If you are an hobbyist programmer busy on a simple one-off small app,
you may skip UT altogether, manually inspect the behaviour of your
program, and never regret it. 

But if you are writing an e-commerce application that will organise
transaction for millions of euros of revenue monthly, UT is probably the
very first code you will want to commit to your repo.

Mac.

PS: I did not comment on the analogy with evolution, because did not get
the parallelism you were trying to draw. Care to explain?


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