Re: how you know you're a programming nerd

2006-04-08 Thread Ron Adam
John Salerno wrote:
> Ron Adam wrote:
>> When you are working on your programming project on Friday night 
>> instead of going out.
> 
> Ok, you win. :)
> 
> Oh wait, it's Friday night and I'm typing this message...dang it!


Yep,  Hah Hah...  No wait,  I'm here too.   ;-)

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


Re: output formatting for user-defined types

2006-04-08 Thread Steven D'Aprano
On Fri, 07 Apr 2006 21:18:23 -0700, Russ wrote:

>> dist = 4 * ft
>> print >> out, dist/ft
>>> 4
> 
>>> Note, however, that this requires the user to explicity ask for the
>>> conversion.
> 
>>How is this any more explicit and any less safe than:
> 
>>dist = 4 * ft
>>print float(dist)
> 
> Because the former specifies the actual units and the latter does not.
> If the base units were not feet, then the latter would not return the
> value in feet (which happens to be 4 here). It would return the value
> in whatever the base unit for length happened to be. So the former
> works even if the base unit is changed, but the latter does not.

So what you are saying is, if I enter a unit in feet, you automatically
change that unit to some base unit (say, metres if you use SI) behind my
back. So, assuming SI units as the base, if I say:

print 2*ft + 1*ft

you're going to give me an answer of 0.9144 metres, instead of the
expected 3ft. Surely if I'm entering my values in a particular unit, I
would like to see the answers in that same unit, unless I explicitly ask
for it to be converted?


> Secondly, allowing unconditional conversion to float allows any unit to
> be passed to trig functions. But any unit other than (dimensionless)
> radians passed to a trig function is an error. I explaned that already,
> but apparently you missed it.

I didn't miss that at all.

sin(45*ft) 

is still an error.

sin(45) 

shouldn't be, even if that 45 came from float(45*ft). What do you care
where the value comes from? I'm sure you allow sin(float('45')) without
complaining that trig functions don't operate on strings.


>>But in any case, I suspect you do automatically convert units. What do you
>>do in this case:
> 
>>x = 45*ft
>>y = 16*m
>>z = x+y
> 
>>Do you raise an error?
> 
> Nope. Works just fine. You obviously didn't look at the user guide.
> What happens is that any length unit is automatically converted to the
> chosen base unit for length, so everything is consistent.

So, despite your going on about the evils of automatic conversions behind
the user's back, you do go ahead and do automatic conversions behind the
user's back. 

Slight inconsistency, don't you think?


>>All you are doing is making a rod for your own back, to no advantage.
> 
> Wrong again.

Hey, it isn't *me* battling to find a way to easily print my instance
objects. 



-- 
Steven.

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


Re: "The World's Most Maintainable Programming Language"

2006-04-08 Thread Christos Georgiou
On Fri, 07 Apr 2006 11:11:14 +0200, rumours say that Azolex
<[EMAIL PROTECTED]> might have written:

>>   At-least Pythetic isn't a word (yet).
>> 
>
>:))) "now that's quite pythetic !"

Well, "pythetic" could become a synonym to "un-pythonic".
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: minidom + wxPython woes

2006-04-08 Thread Fredrik Lundh
Frank Millman wrote:

> This sounds similar to a problem I reported a few months ago. This is
> the link.
>
http://groups.google.com/group/comp.lang.python/browse_frm/thread/6fc1097d26083e43/5fbdf493f3c38942?q=&rnum=1&hl=en#5fbdf493f3c38942
>
> In my case, it turned out to be a bug in the pyexpat module - it is
> known about, but for some reason difficult to fix, so it is still
> there.

no, it's not a bug in the pyexpat module -- the problem is that
wxPython uses it's own incompatible version of the expat library,
and loads it in a way that causes problems for any library that's
tries to use its own statically linked version.

see MvL's comments in the sourceforge tracker for more info.





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


Re: calculating system clock resolution

2006-04-08 Thread Steven D'Aprano
On Fri, 07 Apr 2006 16:39:40 -0700, jUrner wrote:

> Maybe it was not too clear what I was trying to point out.
> 
> I have to calculate the time time.time() requires to return the next
> tick of the clock.
> Should be about 0.01ms but this may differ from os to os.

I suspect that Python isn't quite fast enough to give an accurate measure
for this, but I could be wrong.

You can try this:

def calc_time_res():
now = time.time
start = now()
x = start
while start == x:
x = now()
print x - start

Trying it, I get a fairly small number:




>>> calc_time_res()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 2, in calc_time_res
NameError: global name 'time' is not defined
>>> import time
>>>
>>> calc_time_res()
2.50339508057e-05
>>> calc_time_res()
2.59876251221e-05
>>> calc_time_res()
2.59876251221e-05
>>> calc_time_res()
2.59876251221e-05
>>> calc_time_res()
2.40802764893e-05









> 
> BTW (I'm new to linux) cat  /proc/cpuinfo is nice but I have 2457.60
> bogomips.
> Is this something i should be concerned about? I mean is this
> contageous or something ;-)

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


Re: GUI Treeview

2006-04-08 Thread Christos Georgiou
On Fri, 7 Apr 2006 22:52:06 +0200, rumours say that "Arne"
<[EMAIL PROTECTED]> might have written:


>"Peter Hansen" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
>news:[EMAIL PROTECTED]

>> Arne wrote:
>>> Hello !
>>>
>>> I am looking for a widget with the following properties:
>>> - showing the tree file structure/ directory structure
>>> - next to each file should be a checkbox
>>> - the tree should only show certain files (i. e. only for the looked in 
>>> user)

>> For which GUI framework?  (e.g. Tkinter, wxPython, etc...)

>If possible for the Tkinter frameworkt.

There's a TreeWidget.py module in idlelib, which you can modify to your
needs.  There's also the Tix.Tree widget, if you have Tix installed (and you
probably do if you run a recent Python on your Windows box), which also is
very powerful.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to install python modules on linux

2006-04-08 Thread Fabian Braennstroem
Hi to all,

thanks for your ideas! I just figured out a different way
using archlinux 'pacman' (package management tool like apt).
As a former archlinux user I am more used to adjust those
PKDBUILDs (kind of ebuilds under archlinux) than adjusting
debian packages. The downside is that apt does not know
anything about those installed packages (just like with
easyinstall and checkinstall). I am not sure, if is the best
way, but the installation of numpy and scipy almost worked ;-)

Starting numpy gives me:
  import numpy
  import linalg -> failed: /usr/lib/3dnow/libf77blas.so.2: undefined symbol: 
e_wsfe

Which looks pretty odd for me!?

Greetings!
 Fabian

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


Re: calculating system clock resolution

2006-04-08 Thread Steven D'Aprano
Ah, drat -- hit the wrong key and sent the last post before I had finished
writing it... the following is what I *intended* to send.

On Fri, 07 Apr 2006 16:39:40 -0700, jUrner wrote:

> Maybe it was not too clear what I was trying to point out.
> 
> I have to calculate the time time.time() requires to return the next
> tick of the clock.
> Should be about 0.01ms but this may differ from os to os.

I suspect that Python isn't quite fast enough to give an accurate measure
for this, but I could be wrong.

You can try this:

def calc_time_res():
now = time.time
start = now()
x = start
while start == x:
x = now()
print x - start

Trying it, I get a fairly small number:

>>> calc_time_res()
1.50203704834e-05
>>> calc_time_res()
1.50203704834e-05
>>> calc_time_res()
1.50203704834e-05

This is Python 2.3 running under Fedora Core 2 Linux.


-- 
Steven.

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


Re: Appending Elements in Element Tree

2006-04-08 Thread Ron Adam
Ron Adam wrote:
> 
> In my program I have a lot of statements that append elements, but 
> sometimes I don't want to append the element so it requres an if 
> statement to check it, and that requires assigning the returned element 
> from a function to a name or calling the funtion twice.
> 
> e = ET.Element('name')
> e.append(get_subelement(obj))   # but raises an exception on None
> 
> 
> 
> This works, but I have a lot of appends.
> 
> sube = get_element(obj)
> if sube is None:
> e.append(sube)
> 
> 
> 
> Now if Elements worked more like lists I could extend an element.
> 
> alist = []
> alist.extend([])# returns orginal list
> 
> 
> 
> With strings.
> 
> s = ''
> s += ''  # returns original string (or copy)
> 
> 
> So is there an identity operation with Element Tree elements that I can 
> use to avoid putting a lot of if and or try statements around appending 
> elements?
> 
> 
> 
> I could wrap the append and do it this way...
> 
>def eappend(e1, e2):
>   if e2 is None: return e1
>   e1.append(e2)
>   return e1
> 
> Then do...
> 
>e = eappend(e, get_element(obj))   # Append if not None.
> 
> 
> But maybe there's a better way?



The following worked in cases where I needed to append a list of items.

def extend(e1, elist):
 for e in elist:
 e1.append(e)
 return e1


Although I still need to return the list as elements aren't mutable.

 element = extend(element, elist)

It would be nice if this was built in so I could do...  Hint hint.  :-)

 element.extend(elist)

Where elist is a list of elements or an element with a number of sub 
elements.


I still need to special case individual appends or put the returned item 
in a list so I use the extend() function on the returned element.

I guess I need to look at the Element Tree source code.

Cheers,
Ron









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


Re: How to change the docs - a case study

2006-04-08 Thread Fredrik Lundh
Kent Johnson wrote:

> >> Here is an example. This morning I noticed a minor discrepancy in the
> >> docs for the 'rot13' encoding. I posted a bug to SourceForge at 10:05
> >> GMT. At 10:59 someone commented that maybe the code was broken rather
> >> than the docs. At 11:18 another poster responded that the code should
> >> stay the same. At 11:25, less than two hours after my original report, a
> >> fixed was checked in.
> >
> > how many manhours did this take, in total ?  did you clock your own efforts 
> > ?
>
> It took a few minutes of my time. Maybe a minute to verify that there
> was no similar bug report, a few minutes to write up my findings and
> submit them. I don't know how much time the other posters spent but the
> total clock time from OP to fix was 1 hour 20 minutes so that gives you
> an upper bound.

now that the developer documentation has been updated, have you verified
that the fix is correct ?   if you have, how long did it take (in clock time) 
be-
fore you got around to do that ?

> the 2.4.3 doc is still broken:
>
> http://docs.python.org/lib/standard-encodings.html

for the record, it's still broken.  and there's no sign that there's a known
bug on that page.

I've written a little more about this here:

http://pytut.infogami.com/blog/43fm





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


Re: unicode wrap unicode object?

2006-04-08 Thread ygao
sorry,my poor english.
I got a solution  from others.
I must use utf-8 for chinese.


>>> import sys
>>> reload(sys)
>>> sys.setdefaultencoding("utf-8")
>>> s='\xe9\xab\x98' #this uff-8 string
>>> ss=U'\xe9\xab\x98'
>>> ss1=ss.encode('unicode_escape').decode('string_escape')
>>> s1=s.decode('unicode_escape')
>>> s1==ss
True
>>> ss1==s
True
>>>

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


Re: calculating system clock resolution

2006-04-08 Thread Ron Adam
Steven D'Aprano wrote:
> On Fri, 07 Apr 2006 16:39:40 -0700, jUrner wrote:
> 
>> Maybe it was not too clear what I was trying to point out.
>>
>> I have to calculate the time time.time() requires to return the next
>> tick of the clock.
>> Should be about 0.01ms but this may differ from os to os.
> 
> I suspect that Python isn't quite fast enough to give an accurate measure
> for this, but I could be wrong.

 import time

 calc_time_res()
> 2.50339508057e-05
 calc_time_res()
> 2.59876251221e-05
 calc_time_res()
> 2.59876251221e-05
 calc_time_res()
> 2.59876251221e-05
 calc_time_res()
> 2.40802764893e-05

Trying this on my win xp gives the following.


0.0150001049042# time.time()

2.23492091872e-006 # time.clock()

2.7936511484e-006
1.9580388e-006 #<- lowest value for time.clock()
1.9580388e-006
1.9580388e-006
3.35238137808e-006
1.9580388e-006
1.9580388e-006
1.9580388e-006
2.23492091872e-006

But I think this is going to vary from system to system as well as what 
os is used.  And it may be effected by other tasks as well so checking 
multiple times is probably needed.


def calc_time_res():
 now = time.time
 start = now()
 x = start
 while start == x:
 x = now()
 print x - start

def calc_time_res2():
 now = time.clock
 start = now()
 x = start
 while start == x:
 x = now()
 print x - start

def calc_time_res3():
 now = time.clock
 r = range(10)
 times = [now() for x in r]
 start = times[0]
 for x in times[1:]:
 print x-start
 start = x

calc_time_res()
print
calc_time_res2()
print
calc_time_res3()



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


Re: output formatting for user-defined types

2006-04-08 Thread Russ
>So what you are saying is, if I enter a unit in feet, you automatically
>change that unit to some base unit (say, metres if you use SI) behind my
>back. So, assuming SI units as the base, if I say:

>print 2*ft + 1*ft

>you're going to give me an answer of 0.9144 metres, instead of the
>expected 3ft. Surely if I'm entering my values in a particular unit, I
>would like to see the answers in that same unit, unless I explicitly ask
>for it to be converted?

Actually, that was my initial thinking exactly, and it is exactly what
my first version actually did. I learned through experience, however,
that that approach makes adding differrent units of the same type
(e.g., feet and meters) substantially more complicated than it is using
my current approach,  so I abandoned it.

The disadvantage is that, as you point out, you can add feet to feet
and get meters. There are two answers to this problem. First, if you
expect to use feet consistently, you can easily make it your base unit.
Secondly, you can always convert the output to feet:

x = 2 * m
print format(x,ft)

That may seem inconvenient, but there are actually a couple of
significant advantages here that makes this form preferable to simply
"print x". One advantage is that if you "disable" units for efficiency,
your output can (and will) still show the units of feet. Otherwise you
lose the unit information completely. The other advantage is that you
can change your base unit and your program will still produce the same
result.

>sin(45*ft)

>is still an error.

>sin(45)

>shouldn't be, even if that 45 came from float(45*ft). What do you care
>where the value comes from? I'm sure you allow sin(float('45')) without
>complaining that trig functions don't operate on strings.

Either you don't understand how the "__float__" function works or you
don't understand basic physics. If the float function converts 45 * ft
to simply 45, then sin(45*ft) will be automatically converted to
sin(45). That is most definitely *not* what you want.

>So, despite your going on about the evils of automatic conversions behind
>the user's back, you do go ahead and do automatic conversions behind the
>user's back.

>Slight inconsistency, don't you think?

Let's try this one more time. Automatic conversion is fine as long as
the conversion is dimensionally correct. Automatically converting from
feet to a dimensionless number is *not* dimensionally correct. This
isn't rocket science.

>Hey, it isn't *me* battling to find a way to easily print my instance
>objects.

Actually, I have already developed an excellent workaround for that
problem.

By the way, I doubt you are impressing anyone here. Are you sure you
want to continue with this?

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


Re: unicode wrap unicode object?

2006-04-08 Thread ygao
sorry,my poor english.
I got a solution  from others.
I must use utf-8 for chinese.
>>> import sys
>>> reload(sys)
>>> sys.setdefaultencoding("utf-8")
>>> s='\xe9\xab\x98' #this uff-8 string
>>> ss=U'\xe9\xab\x98'
>>> ss1=ss.encode('unicode_escape').decode('string_escape')
>>> s1=s.decode('unicode_escape')
>>> s1==ss 
True 
>>> ss1==s 
True

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


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread malv
Looks pretty good, except for your difficult to read examples.
Don't use black backrounds with green characters.
A plain white background with black text would be a major improvement.

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


Re: unicode wrap unicode object?

2006-04-08 Thread Fredrik Lundh
"ygao" wrpte_

> I must use utf-8 for chinese.

yeah, but you shouldn't store it in a *Unicode* string.  Unicode strings
are designed to hold things that you've already decoded (that is, your
chinese text), not the raw UTF-8 bytes.

if you store the UTF-8 in an ordinary 8-bit string instead, you can use
the unicode constructor to convert things properly:

b = "... some utf-8 data ..."

# turn it into a unicode string
u = unicode(b, "utf-8")

# ... do something with it ...

# turn it back into a utf-8 string
s = u.encode("utf-8")

# or use some other encoding
s = u.encode("big5")

e.g.

>>> b = '\xe9\xab\x98'
>>> u = unicode(b, "utf-8")
>>> u.encode("utf-8")
'\xe9\xab\x98'
>>> u.encode("big5")
'\xb0\xaa'





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


Re: unicode wrap unicode object?

2006-04-08 Thread ygao
thanks for your advice.

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


How can I reduce the number of queries to my PostgreSQL database?

2006-04-08 Thread SR
As a starter project for learning Python/PostgreSQL, I am building a
Books database that stores information on the books on my bookshelf.

Say I have three tables.

Table "books" contains rows for book_id, title, subtitle, ISBN.

Table "authors" contains rows for author_id, author surname, author
first names, biographical notes.

Table "bookauthors" contains two rows: book_id, author_id.

The bookauthors table links the books and authors tables.

Scenario: I have a python script which creates web page listing all
books in the database, and all authors for each book. My python script
does essentially three things:

1.  retrieve a list of all book_ids and book_titles.

2.  for each book_id, query the bookauthors table and retrieve all
author names for that book_id.

3.  display it all out as an html table on a web page.

The script works fine, if a little slow. I think that's because if I
have 50 books in my database, my script performs 51 database queries (1
for all book names; then 1 for each book). A colleague of mine
suggested that I could get away with two queries, 1 to read the book
ids and titles, and 1 to read the bookauthors table to pull in *all*
relations, and then do all the work in Python.

I think I know where he's coming from, but I don't know where to begin.
Any clues? Is there a specific name for this technique?

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


Re: unicode wrap unicode object?

2006-04-08 Thread Martin v. Löwis
ygao wrote:
> I must use utf-8 for chinese.

Sure. But please don't do that:

 import sys
 reload(sys)
 sys.setdefaultencoding("utf-8")

As Fredrik says, you should really avoid changing the
default encoding.

 s='\xe9\xab\x98' #this uff-8 string
 ss=U'\xe9\xab\x98'
 ss1=ss.encode('unicode_escape').decode('string_escape')
 s1=s.decode('unicode_escape')
 s1==ss 
> True 
 ss1==s 
> True

Ok. But how about that:

py> s='\xe9\xab\x98'
py> ss=u'\u9ad8'
py> s1=s.decode('utf-8')
py> s1==ss
True

Here, ss is a single character, which uses 3 bytes in UTF-8.
In your example, ss has three characters, which are not Chinese,
but European.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: freeze.py builds, but binary doesn't even run locally (shared GTK problem?)

2006-04-08 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
> from _gtk import *
> 
> ImportError: No module named _gtk

If you look at the freeze output, you'll notice that _gtk is
not linked into your application: It is a shared library (.so),
so it can't be frozen.

Instead, the resulting binary will look for _gtk.so on sys.path.
Try copying _gtk.so into the directory where the binary is,
or set PYTHONPATH before running the binary.

If you want to freeze _gtk into the application, you need it as
a static library.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I reduce the number of queries to my PostgreSQL database?

2006-04-08 Thread Frank Millman

SR wrote:
> As a starter project for learning Python/PostgreSQL, I am building a
> Books database that stores information on the books on my bookshelf.
>
> Say I have three tables.
>
> Table "books" contains rows for book_id, title, subtitle, ISBN.
>
> Table "authors" contains rows for author_id, author surname, author
> first names, biographical notes.
>
> Table "bookauthors" contains two rows: book_id, author_id.
>
> The bookauthors table links the books and authors tables.
>
> Scenario: I have a python script which creates web page listing all
> books in the database, and all authors for each book. My python script
> does essentially three things:
>
> 1.  retrieve a list of all book_ids and book_titles.
>
> 2.  for each book_id, query the bookauthors table and retrieve all
> author names for that book_id.
>
> 3.  display it all out as an html table on a web page.
>
> The script works fine, if a little slow. I think that's because if I
> have 50 books in my database, my script performs 51 database queries (1
> for all book names; then 1 for each book). A colleague of mine
> suggested that I could get away with two queries, 1 to read the book
> ids and titles, and 1 to read the bookauthors table to pull in *all*
> relations, and then do all the work in Python.
>
> I think I know where he's coming from, but I don't know where to begin.
> Any clues? Is there a specific name for this technique?

The specific name you are looking for is to 'join' tables. There will
be many references and tutorials available, but I suggest you start
with the PostgreSQL tutorial, which is part of the documentation
supplied with PostgreSQL.

Here is a link to the 'join' command in the online manual.

http://www.postgresql.org/docs/8.1/interactive/tutorial-join.html

HTH

Frank Millman

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


Documentation for Tkinter/Tix

2006-04-08 Thread Arne
Hello!

Where can I find a documentation for Tkinter/Tix. I already have the 
standard documentation ditributed with Python.
Especially I am looking for documentation about the options for some tix 
widgets like Dirlist (How can I link it to a certain directory, etc.)

Thanks!
Arne 


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


ftp putting information in a variable

2006-04-08 Thread Arne


Hello!I am looking for a way to put ftp returns in a variable.My OS is XP and I want to get the owner of a file. So I have to connect to ftp. But I am stacked with how I can receive this information and put it in a variable.Thanks! ArneHere is a intend of doing thisfrom ftplib import FTP
ftp = FTP('ftp.cwi.nl')   # connect to host, default port
ftp.login()   # user anonymous, passwd anonymous
 ftp.retrlines('LIST') # list directory contents.

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

Re: DO NOT USE JAVA BECAUSE IT IS NOT OPEN SOURCE

2006-04-08 Thread geletine
Nobody has mentioned that c was proprietary until richard stallman
wrote gcc in 1987, c is a great for system programming. Just because
something is originally proprietary does not mean its technically
rubbish, there are plenty of merits in java escially for new
programmers or anyone who wants to get a program going very quickly.
Gcj at the moment can do most tasks apart from swing gui, i believe Awt
is well supported.

To further my position, without the proprietary(it was licenced on a
liberal account at the time) UNIX created in bell labs, they would
possibly not be linux.

Miguel de Icaza started implemening mono as he too saw technical
advantages  in .net, he is freeing the language in my opinion.

Technology is just as important as polictics, hopefully i am well
understood

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


scipy/numpy inverse cumulative normal

2006-04-08 Thread bartsimpson8882002
I was wondering if scipy/numpy has the inverse cumulative normal 
function, ie the function f in this expression

f(scipy.stats.norm.cdf(1.2)) = 1.2

or more generally, a function f which fits the criteria

f(scipy.stats.norm.cdf(x)) = x

There is a distribution called invnorm, but I am not sure of how to use 
it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calculating system clock resolution

2006-04-08 Thread jUrner
def calc_time_res():
now = time.time
start = now()
x = start
while start == x:
x = now()
print x, start  # <--
print x - start

print calc_time_res()
>> 1.50203704834e-05

Something is going wrong here.
If you look at the function ,time.time() returns time in microseconds
(most oses and so
does mine).
So the calculation goes, lets say 1.23 - 1.24
How can the result be something like 1.50203704834e-05 ?
I would expect 0.01.

Next is, the first print statement prints out x and start equal up to
the fraction.

Is it Python giggeling?
Maybe it's python throwing the rounded float at us but internally
keeps calculating with the float returned by the os.
Maybe I'm wrong.

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


Re: calculating system clock resolution

2006-04-08 Thread Steven D'Aprano
On Sat, 08 Apr 2006 04:16:20 -0700, jUrner wrote:

> def calc_time_res():
> now = time.time
> start = now()
> x = start
> while start == x:
> x = now()
> print x, start  # <--
> print x - start
> 
> print calc_time_res()
>>> 1.50203704834e-05
> 
> Something is going wrong here.
> If you look at the function ,time.time() returns time in microseconds
> (most oses and so does mine).

>From help(time.time):

time() -> floating point number
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.

Seconds, not microseconds.


> So the calculation goes, lets say 1.23 - 1.24

How can the time *after* the while loop be less than the time *before* the
while loop?

> How can the result be something like 1.50203704834e-05 ?

Have you looked at the output of time.time()?

>>> time.time()
1144496209.3221531

Of course, Python only prints a certain number of digits; to see the full
amount, use string formatting:

>>> '%40.30f' % time.time()
'1144496642.9059870243072509765625'


This brings me to an even simpler method of getting the resolution of
time.time(), without the overhead of a while loop:

>>> abs(time.time() - time.time())
1.0013580322265625e-05

which is approximately 0.01ms, just as you expected.



-- 
Steven.

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


Compleated Begginers Guide. Now What?

2006-04-08 Thread Jay
I have compleated the beginers guide to python
http://www.freenetpages.co.uk/hp/alan.gauld/.
then i found the Toolkit Tkinter and started on that. its graight and
av made lots of apps to help me with litle things but i have a big
problem. the CLASS method.

when i seperate things up into classes i carnt get one class to tell
the other class somthing. it just opens another coppy of the class. i
am confused.

oh and i carnt fathem out how to run to loops at the same time. EG .
Ball Blaster i wanted to permenetly run the ball with a loop well my
main loop ran the bat.

can sumone point me to the right studeing material.

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


Re: calculating system clock resolution

2006-04-08 Thread Peter Hansen
Steven D'Aprano wrote:
> This brings me to an even simpler method of getting the resolution of
> time.time(), without the overhead of a while loop:
> 
abs(time.time() - time.time())
> 
> 1.0013580322265625e-05
> which is approximately 0.01ms, just as you expected.

This doesn't necessarily work, at least on Windows, where the 
time.time() resolution is much worse than the time it takes to execute a 
couple of calls to time.time().  Most of the time the values returned by 
two consecutive time.time() calls are identical, differing only if the 
timer just happens to tick between the two.  (On my machine a simple 
while loop that performs the above calculation until it produces a 
non-zero value has to run on average over 1 times.)

-Peter

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


Re: calculating system clock resolution

2006-04-08 Thread Tim Peters
[jUrner]
>> def calc_time_res():
>> now = time.time
>> start = now()
>> x = start
>> while start == x:
>> x = now()
>> print x, start  # <--
>> print x - start
>>
>> print calc_time_res()
>> 1.50203704834e-05
>>
>> Something is going wrong here.
>> If you look at the function ,time.time() returns time in microseconds
>> (most oses and so does mine).

Don't confuse resolution with precision (or make up other words you
like better ;-)):  just because some quantity is given with N bits
doesn't mean it's _accurate_ to N bits.See below for a more
extreme example.

[Steven D'Aprano]
> ...
> This brings me to an even simpler method of getting the resolution of
> time.time(), without the overhead of a while loop:
>
> >>> abs(time.time() - time.time())
> 1.0013580322265625e-05
>
> which is approximately 0.01ms, just as you expected.

Caution:  the most likely outcome on Windows for that line is 0.0. 
That's because the clock mechanism underlying time.time() on Windows
only updates at a frequency of 18.2 Hz (older systems) or 64 Hz (newer
systems).  IOW, time.time() only "changes" 18.2 to 64 times per second
on Windows, and two consecutive calls are consequently likely to
return exactly the same result.

In contrast, time.clock() on Windows typically updates more than a
million times per second.
-- 
http://mail.python.org/mailman/listinfo/python-list


download for official Python logo artwork?

2006-04-08 Thread has
Anyone know where I can find source artwork, preferably vector-based,
for python.org's new 'ying-yang' snake icon? I think it's hiding.
Thanks.

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


Re: Characters contain themselves?

2006-04-08 Thread Kent Johnson
WENDUM Denis 47.76.11 (agent) wrote:
> While testing recursive algoritms dealing with generic lists I stumbled 
> on infinite loops which were triggered by the fact that (at least for my 
> version of Pyton) characters contain themselves.See session:

Strings are sequences and this is a problem for recursive functions that 
process nested lists. You do need to test for stringiness somehow. IIRC 
the usual solutions are

- explicit test for string: isinstance(xx, basestring)

- explicit test for list: isinstance(xx, list) - this fails for 
user-defined sequences that don't subclass list

- test for __iter__ attribute. IIUC this relies on an implementation 
detail that strings don't define __iter__:

In [6]: hasattr('aa', '__iter__')
Out[6]: False

In [7]: hasattr([], '__iter__')
Out[7]: True

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


Re: minidom + wxPython woes

2006-04-08 Thread Frank Millman

Fredrik Lundh wrote:
> Frank Millman wrote:
>
> > This sounds similar to a problem I reported a few months ago. This is
> > the link.
> >
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/6fc1097d26083e43/5fbdf493f3c38942?q=&rnum=1&hl=en#5fbdf493f3c38942
> >
> > In my case, it turned out to be a bug in the pyexpat module - it is
> > known about, but for some reason difficult to fix, so it is still
> > there.
>
> no, it's not a bug in the pyexpat module -- the problem is that
> wxPython uses it's own incompatible version of the expat library,
> and loads it in a way that causes problems for any library that's
> tries to use its own statically linked version.
>
> see MvL's comments in the sourceforge tracker for more info.
>
> 

I had a look at the sourceforge tracker. I did not understand much of
it - rather too technical for me. There are two points worth noting.

Firstly, it seems from various posts to the tracker item that the same
problem has been reported with pygtk, Qt, and VTK.

Secondly, in tracker item 1295808 (which, according to the notes, is
actually the same bug), there is talk of submitting a patch in 2.5 to
address the issue.

It seems to me (FWIW - as I said, I do not really understand much of
what I read) that it may not technically be a bug in pyexpat, but there
is a real issue there, and the decision has been taken to make a change
to pyexpat so that the problem will not arise in the future.

Frank

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


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread Bruno Desthuilliers
malv a écrit :
> Looks pretty good, except for your difficult to read examples.
> Don't use black backrounds with green characters.
> A plain white background with black text would be a major improvement.
> 
May I suggest a system like Trac-Wiki, that knows how to display Python 
code with syntax-hilighting and line-numbering ?-) (Not sure but IIRC, 
MoinMoin as the same feature).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread James
On the calculator page you describe the difference between 3.0 / 2 and
3 / 2, but an absolute beginner probably wouldn't know about the
difference between integers and floats, or even what the two terms
meant. If you don't know much about computers then the fact that they
are separate types would probably be surprising...

James

On 7 Apr 2006 12:45:48 -0700, Clodoaldo Pinto <[EMAIL PROTECTED]> wrote:
> I'm starting a programming tutorial for absolute beginners using Python
> and I would like your opinions.
>
> http://programming-crash-course.com
>
> Regards, Clodoaldo Pinto
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread Bruno Desthuilliers
Clodoaldo Pinto a écrit :
> bill pursell wrote:
> 
(snip)
>>2) In the section on installing, you begin with:
>>"Python is an interpreted, interactive, object-oriented programming
>>language.".  The complete novice sees those words and expects
>>them to be explained, but there is no definition given.  I would
>>recommend simplifying that sentence, or explaining the terms.
> 
> Ok, i will think about something, or just delete it.

FWIW, being "interpreted" is not a feature of a language but of a given 
implementation of a language - and actually, the reference 
implementation (CPython) is byte-compiled, not interpreted. As for 
interactivity, it comes from a program (the Python shell) that ships 
with the reference implementation - not from the laguage itself.

This leaves us with "Python is an object-oriented programming language", 
which is not 100% accurate since Python - even if strongly OO - also 
supports the procedural and functional paradigms !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: very strange problem in 2.4

2006-04-08 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> The Problem (very basic, but strange):
> 
> I have a list holding a population of objects, each object has 5 vars
> and appropriate funtions to get or modify the vars. 

Which are probably not necessary:
http://dirtsimple.org/2004/12/python-is-not-java.html

(in short: Python as a mechanism named "properties" that allow you to 
"gateway" attribute access thru hiddens getter and setter).

> When objects in
> the list have identical vars (like all = 5 for var "a" and all = 10 for
> var "b" across all vars and objects) and i change
> 
> self.mylist[i].change_var_a(5)
> 
> to a new value, in this case var "a" in object i to 5, now all vars of
> type "a" in all objects in my list are changed to 5 instead of just var
> "a" in object mylist[i], which is my goal.

(snip)
> 
> What is python doing? Am I missing something? Any ideas at all would be
> wonderful?
> 

It would have helped if you had posted your code. Anyway, at least two 
things could lead to the behaviour you describe:

1/ you have class attributes instead of instance attributes, ie:

class MyClass(object):
   # this attribute belongs to the class
   class_attrib = 42

   def __init__(self, instance_attrib):
 # this attribute belongs to the instance
 self.instance_attrib = instance_attrib

2/ you in fact have in your list multiple references to the same instance.

My 2 cents
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython and SuSE 10.0

2006-04-08 Thread Steve
Jorge Godoy wrote:

> Steve <[EMAIL PROTECTED]> writes:
> 
>> I was wondering if there is a wxPython RPM for SuSE 10.0
>> available. I
>> Googled for it with no luck, but I'm hopeful that there is one out
>> there.
> 
> There are RPMs within SuSE's DVD / CDs, IIRC.  Anyway, you can get
> it with Apt, smart and even YaST.
> 

I was unable to find it on the CD,s, I'm using Open SuSE. I did
finally locate it and get it downloaded. Thanks for the reply.

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


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread Neal Becker
Maybe find a spell checker?

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


Re: How can I reduce the number of queries to my PostgreSQL database?

2006-04-08 Thread Martin Christensen
> "SR" ==   <[EMAIL PROTECTED]> writes:
SR> Scenario: I have a python script which creates web page listing
SR> all books in the database, and all authors for each book. My
SR> python script does essentially three things:

SR> 1. retrieve a list of all book_ids and book_titles.

SR> 2. for each book_id, query the bookauthors table and retrieve all
SR> author names for that book_id.

SR> 3. display it all out as an html table on a web page.

That's one query, if you're willing to make it advanced enough,
although you need to make an aggregate to enable PostgreSQL to
concatenate and comma separate author names. However, this aggregate
will typically need more than one database function. Such an aggregate
could be as follows:

CREATE OR REPLACE FUNCTION author_agg_sfunc(TEXT, authors.name%TYPE)
RETURNS TEXT AS '
SELECT $1 || '', '' || $2;
' LANGUAGE sql;

CREATE OR REPLACE FUNCTION author_agg_ffunc(TEXT)
RETURNS TEXT AS '
SELECT trim(trailing '', '' from $1);
' LANGUAGE sql;

CREATE AGGREGATE author_agg (
  basetype  = VARCHAR(100),
  sfunc = author_agg_sfunc,
  stype = TEXT,
  finalfunc = author_agg_ffunc,
  initcond  = ''
);

Then you could use it as follows:

SELECT author_agg(authors.name),
   foo,
   bar
  FROM authors, writes, books
 WHERE authors.id = writes.author_id
   AND writes.book_id = books.id
 GROUP BY foo, bar;

This is the solution that I would use after working nearly a decade
with databases. It is neither simple nor obvious to the novice, but
it's the Right Way To Do It. For a learning exercise, this is way over
the top, but I thought you might benefit from seeing that - so long as
you only need information that would reasonably fit in one table on a
web page or the equivalent - one query is always enough. Or perhaps
that should be One Query Is Always Enough. :-) Learn at your own pace,
though, but you might want to keep this in mind for future reference.

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


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread Martin Christensen
> "Jay" == Jay  <[EMAIL PROTECTED]> writes:

Jay> when i seperate things up into classes i carnt get one class to
Jay> tell the other class somthing. it just opens another coppy of the
Jay> class. i am confused.

I'm sorry, it's very difficult to understand what you mean. You'll
have to be a lot more precise, and it would probably help if you
posted code examples and tell us what you expect from the code you're
making.

Jay> oh and i carnt fathem out how to run to loops at the same time.
Jay> EG . Ball Blaster i wanted to permenetly run the ball with a loop
Jay> well my main loop ran the bat.

Erm... it _could_ sound as if you're looking for multi-threading, i.e.
running several things at the same time. This, however, is pretty
difficult, especially for a beginner. Maybe you should try to
structure your program differently so that you only need one thread of
execution. Then you can proceed to multi-threading when you have more
experience.

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


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread Jay
Verry true but no help at all

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


Re: Screen placement based on screen resolution

2006-04-08 Thread Pat
Thanks a lot for you response.
S
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Pat" <[EMAIL PROTECTED]> wrote:
>
>> I am trying to place a dialog in the center of the screen based on a 
>> users
>> screen resolution.  I can get the width and height of the screen, but I 
>> can't
>> seem to use the following:
>>
>> root.geometry('WxH+X+Y')
>>
>> It appears the values for X and Y need to be integers and not a variable
>> like width/2-40
>
> Python doesn't look in string literals for things that might look
> like expressions, but if you have the values, *creating* a string
> with the right contents is pretty easy.  see the tutorial for the
> basics:
>
>http://docs.python.org/tut/node9.html
>
> if you have all the values in variables, this expression sets the
> geometry in one step:
>
>root.geometry("%dx%d%+d%+d" % (width, height, xoffset, yoffset))
>
> also see
>
>http://effbot.org/tkinterbook/wm.htm#Tkinter.Wm.geometry-method
>
> which includes code that parses a geometry string.
>
> 
>
>
> 


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


Re: download for official Python logo artwork?

2006-04-08 Thread Brian Quinlan
has wrote:
> Anyone know where I can find source artwork, preferably vector-based,
> for python.org's new 'ying-yang' snake icon? I think it's hiding.
> Thanks.
> 
I don't know how office it is, but you can get the artwork here:
http://tinyurl.com/n4rge

Cheers,
Brian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread Jay
Verry true but no help at all

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


Working with decimal points

2006-04-08 Thread Byte
How come:

sum = 1/4
print sum

returns 0? 1/4=0.25, not 0. How do I fix this?

 -- /usr/bin/byte

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


Re: kinterbas and Python

2006-04-08 Thread David Rushby
[EMAIL PROTECTED] wrote:
> My error code is :
>
> concorrency level error
> use kinterbas.init(concurrency_level=?) to set the concurrency level
> legally...

That's not the actual error message.  The actual error message is:
"""
The concurrency level cannot be changed once it has been set.  Use
kinterbasdb.init(concurrency_level=?) to set the concurrency level
legally.
"""

So, it seems that you're either trying to call kinterbasdb.init
multiple times, or you're performing an operation that calls
kinterbasdb.init implicitly, and later you're trying to call
kinterbasdb.init explicitly.

Either remove the kinterbasdb.init call entirely, or move it to a place
where it is called before you perform any database operations, and
won't be called again.

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


Where python looks for path

2006-04-08 Thread Philippe Martin
Hi,

I am currently packaging python and a few libraries: PyWin32, PySerial, PIL,
wxPython, HTML generator, numarray for U3 distribution.

Basically that means that the complete system initially in $path1\host will
be moved dynamically to $path2\at execution.


To take PIL as an example, I notice when I launch Idle in a "relative"
manner: I am in $path1\host that $path1\host\Lib\site-packages\PIL is in
the sys.path before I do anything.

I notice that there is a PIL.pch file in site-packages: 

Q1) is that read by python ?


On the other hand, even after appending all I can think of in sys.path, I
still get an error (cannot find module) trying to load win32com.client: it
fails in the win32api import in win32com.client.

pywin32.pch is there.

I think all the .dlls are there also, so I'm a bit confused.

Q2) what should I be looking for ?


Also, I seemed to notice in the past that modules (my own) not listed in any
__init__.py where found under Linux but not Windows for which I had to
upgrade my __init__.py.


Q3: is that true ?


Regards,

Philippe




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


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread Jay
Thank you Martin Christensen and i am sorry for not explaning well. i
will tack that advice

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


Re: Working with decimal points

2006-04-08 Thread [EMAIL PROTECTED]
Byte wrote:
> How come:
>
> sum = 1/4
> print sum
>
> returns 0? 1/4=0.25, not 0. How do I fix this?

Make sure there is at least one float in your equation. In your example
Python is doing interger math for you and returing the floor. You need
to give it a hint that you would like to do floating point math.

>>> sum = 1.0/4
>>> print sum
0.25
>>> sum = 1/4.0
>>> print sum
0.25
>>>

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


recognize a drive as removable media (e.g. compact flash, sd card or usb drive)

2006-04-08 Thread Mike Joyce
I am trying to write a portable script that will find removable media, 
such as compact flash, sd card, usb, etc. drive and then upload files 
from the media. I want this to be portable so that I can write and 
maintain one program for both Linux and Windows. Each platform uses 
different functions so even if I could find two platform dependent 
functions that would be fine. Basically, I would like to avoid checking 
fixed disks if possible.
If anyone know of a good way to do this please let me know. Thanks in 
advance for any help.
-Mike Joyce
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working with decimal points

2006-04-08 Thread Byte
That dosnt work either:

sum = 0.1+1/4
print sum

Just returns 0.1

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


Re: Working with decimal points

2006-04-08 Thread Fredrik Lundh
"Byte" wrote:

> How come:
>
> sum = 1/4
> print sum
>
> returns 0?

because 1 and 4 are integer objects, so 1/4 is an integer division, which
rounds down to the nearest integer.

> 1/4=0.25, not 0. How do I fix this?

use floating point numbers:

1.0/4.0 = 0.25

or convert one of the numbers to a float:

float(1)/4 = 0.25





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


Re: Working with decimal points

2006-04-08 Thread Peter Hansen
Byte wrote:
> That dosnt work either:
> 
> sum = 0.1+1/4
> print sum
> 
> Just returns 0.1

That's because the 1/4 is executed first, and the problem mentioned 
still applies (i.e. you get a 0, then add it to 0.1).

The best fix for you might be simply to place this line at the start 
(before all other code) of your module:

from __future__ import division

That will change the way simple division works to give you the results 
you expected.  See the online docs for more background on this.

-Peter

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


jpype and zxJDBC

2006-04-08 Thread benchline
I would love to be able to use jdbc drivers using the python db 2.0 api
and cpython.

Has anyone used jpype and zxJDBC (distributed with jython) together?  I
am trying and what I have tried does not yet work.   If I figure
anything out that works I will post it here.

Thanks

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


Re: Working with decimal points

2006-04-08 Thread Byte
Fredrik Lundh's way works: thank a million!

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


Re: Where python looks for path

2006-04-08 Thread Philippe Martin
PS: I forgot to say that on the win32api import I get a "DLL load failed"

Philippe


Philippe Martin wrote:

> Hi,
> 
> I am currently packaging python and a few libraries: PyWin32, PySerial,
> PIL, wxPython, HTML generator, numarray for U3 distribution.
> 
> Basically that means that the complete system initially in $path1\host
> will be moved dynamically to $path2\at execution.
> 
> 
> To take PIL as an example, I notice when I launch Idle in a "relative"
> manner: I am in $path1\host that $path1\host\Lib\site-packages\PIL is in
> the sys.path before I do anything.
> 
> I notice that there is a PIL.pch file in site-packages:
> 
> Q1) is that read by python ?
> 
> 
> On the other hand, even after appending all I can think of in sys.path, I
> still get an error (cannot find module) trying to load win32com.client: it
> fails in the win32api import in win32com.client.
> 
> pywin32.pch is there.
> 
> I think all the .dlls are there also, so I'm a bit confused.
> 
> Q2) what should I be looking for ?
> 
> 
> Also, I seemed to notice in the past that modules (my own) not listed in
> any __init__.py where found under Linux but not Windows for which I had to
> upgrade my __init__.py.
> 
> 
> Q3: is that true ?
> 
> 
> Regards,
> 
> Philippe

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


Re: download for official Python logo artwork?

2006-04-08 Thread has
That'll do nicely. Thanks.

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


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread Clodoaldo Pinto
Bruno Desthuilliers wrote:
> Clodoaldo Pinto a écrit :
> > bill pursell wrote:
> >
> (snip)
> >>2) In the section on installing, you begin with:
> >>"Python is an interpreted, interactive, object-oriented programming
> >>language.".  The complete novice sees those words and expects
> >>them to be explained, but there is no definition given.  I would
> >>recommend simplifying that sentence, or explaining the terms.
> >
> > Ok, i will think about something, or just delete it.
>
> FWIW, being "interpreted" is not a feature of a language but of a given
> implementation of a language - and actually, the reference
> implementation (CPython) is byte-compiled, not interpreted. As for
> interactivity, it comes from a program (the Python shell) that ships
> with the reference implementation - not from the laguage itself.
>
That Python definition was taken literally from the old site's "about"
page. The new "about" page is better for the purposes of this course:

"Python is a remarkably powerful dynamic programming language that is
used in a wide variety of application domains. Python is often compared
to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing
features include:..."

Or the first page definition:

"Python® is a dynamic object-oriented programming language that can be
used for many kinds of software development. It offers strong support
for integration with other languages and tools, comes with extensive
standard libraries, and can be learned in a few days. Many Python
programmers report substantial productivity gains and feel the language
encourages the development of higher quality, more maintainable code."

I'm leaning towards the first page one from which i would take this
part out:

"is a dynamic object-oriented programming language"

That would leave this simple text:

"Python® can be used for many kinds of software development. It offers
strong support for integration with other languages and tools, comes
with extensive standard libraries, and can be learned in a few days.
Many Python programmers report substantial productivity gains and feel
the language encourages the development of higher quality, more
maintainable code."

Regards, Clodoaldo

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


Re: Working with decimal points

2006-04-08 Thread Steven D'Aprano
On Sat, 08 Apr 2006 08:21:06 -0700, Byte wrote:

> How come:
> 
> sum = 1/4
> print sum
> 
> returns 0? 1/4=0.25, not 0. How do I fix this?

By default, / does integer division, not floating point. In integer
division, 1/4 is 0, exactly as calculated. 

(How many fours go into one? Zero fours go into one, with one remainder.)

There are two ways to change this:

(1) Convert at least one of the numbers to a float first:

>>> 1.0/4
0.25
>>> 1/float(4)
0.25

but be careful, this one doesn't do what you want:

>>> float(1/4)
0.0


(2) Run the following command at the start of your program or in your
interactive session:

>>> from __future__ import division

Now division will behave as you expect:

>>> 1/4
0.25

and you can use // for integer division.

Now that you can do floating point division, I peer into my crystal
ball and predict your next question: why is Python so inaccurate?

>>> 1/10
0.10001

Answer: it isn't. You've discovered a mathematical limitation that 1/10
cannot be written exactly in any fixed number of binary places, just like
1/3 cannot be written exactly in any fixed number of decimal places.

See also:

http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate

http://docs.python.org/tut/node16.html


Hope this helps.


-- 
Steven.

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


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread Clodoaldo Pinto
James wrote:
> On the calculator page you describe the difference between 3.0 / 2 and
> 3 / 2, but an absolute beginner probably wouldn't know about the
> difference between integers and floats, or even what the two terms
> meant. If you don't know much about computers then the fact that they
> are separate types would probably be surprising...
>
This point is not easy to aproach. The fact is that it is necessary
that the beginner knows that there is a differerence between 3 / 2 and
3.0 / 2.

I don't want him to now about types, at least not at that stage. I used
the term "integer" for the lack of a better one and I didn't mention
"float". Any suggestions?

Regards, Clodoaldo.

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


Re: calculating system clock resolution

2006-04-08 Thread jUrner
Starts getting confusing...

on linux I get
print time.time()
>> xxx.23

Is it mentioned somewhere that print truncates floats ?
Thats new to me. Kinda surprising that is.

print '%.30' % time.time()
>> xxx.23456678990...
I knew it must have been hiding somewhere

On windows I'd expect a resolution of round around 15ms. Thats why I
fell for the trap assuming linux is operating on about the same.
Anyway.
As far as I can see there is no nice way except for the brute force
loop
to calculate this resolution. This was giving me head sratches and
thats
why the loop in the initial post was so shamelessly empty. I was
thinking
about the poor dudes running an os with a resolution of about 1 second.
I was hoping for s.o. releasing an ace from his sleeve. Well, there
seems
to be no way to know except knowing.

Or like Sege Orlov put it
>> I think the number of samples to take depends on resolution ;-)

Crappy oses that is. Time for them to get standardized.

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


Re: debug CGI with complex forms

2006-04-08 Thread R. Bernstein
"Sullivan WxPyQtKinter" <[EMAIL PROTECTED]> writes:

> When the form in one HTML is very complex with a lot of fields(input,
> button,radio,checkbox etc.), setting the environment is quite
> burdernsome, so I usually change the stdout and stderr of the submit
> processing script to a file object to see the output directly from that
> file. This just can do, but still inconvinient.
> Anyone has more suggestions?

The extended Python debugger (http://bashdb.sourceforge.net/pydb) has
the ability to give POSIX-style line tracing, and to change the debugger
stdout/stderr to a file you direct it. For example,
   pydb --trace --output=/tmp/dbg.log --error=/tmp/error.log my-cgi

Rather than trace the entire CGI, if there is a specific portion that
you want traced that can be done too by changing the CGI. Create a
files called "/tmp/trace-on" and "/tm/trace-off". "/tmp/trace-on" might
contain this:

  # Issue debugger commands to set debugger output to 
  # go to a file, turn on line tracing, and continue
  set logging file /tmp/dbg.log
  # uncomment the following line if you want to wipe out old dbg.log
  # set logging overwrite on
  set logging redirect on
  set logging on
  set linetrace on
  continue

and /tmp/trace-off:

  # Issue debugger commands to turn off line tracing and continue
  set linetrace off
  continue

In your CGI (in the above command-line example the CGI was called
"my-cgi") add:

   import pydb   # needs to be done only once
   ...
   pydb.set_trace("/tmp/trace-on")
   # This and subsequent lines will be traced
   ...
   pydb.set_trace("/tmp/trace-off")

Of course modify the file names in the examples above, my-cgi,
/tmp/dbg.log /tmp/trace-on, /tmp/trace-off as appropriate.

I notice that line tracing at present doesn't show the text of traced
lines just the position (file name, line number, and possibly
function/method name). I will probably change this pretty soon in CVS
though.

Finally, I don't know if any of this will help, but I guess if it
doesn't it would be interesting to understand how it fails. 

(If my past experience in c.l.p holds here, if nothing else, my having
posted this will at least motivate someone else to give other
method(s). ;-)




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


Re: calculating system clock resolution

2006-04-08 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> Is it mentioned somewhere that print truncates floats ?

'print' prints str(time()). On the interactive prompt, you see
repr(time()). float.__str__ truncates. I don't know where it's
documented, but this is the reason why you see the truncation.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread James
Perhaps use the phrase "whole number" there and mention that in
programming they're called integers. Having a glossary with
definitions for things like integer, float etc etc. would be good if
when you talked about integers it linked to the glossary. And
similarly use "decimals" for floats? Less sure about that one though.
But anyway you don't need to go into the whole type thing, just
mention that Python distinguishes between doing maths with whole
numbers and decimals.

On 8 Apr 2006 09:02:22 -0700, Clodoaldo Pinto <[EMAIL PROTECTED]> wrote:
> I don't want him to now about types, at least not at that stage. I used
> the term "integer" for the lack of a better one and I didn't mention
> "float". Any suggestions?
>
> Regards, Clodoaldo.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documentation for Tkinter/Tix

2006-04-08 Thread [EMAIL PROTECTED]
wesley's core python programming (i m havin the old one) has a good
chaper on Tkinter.

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


Re: advice on this little script

2006-04-08 Thread R. Bernstein
"BartlebyScrivener" <[EMAIL PROTECTED]> writes:

> There are several of these writing quotes, all good in their own way,

And from Hamlet: brevity is the soul of wit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where python looks for path

2006-04-08 Thread Philippe Martin
Hi,

I had to move the dlls from pywin32_system32 to where python.exe is.

PS: if someone has a great desire to have another library included in the
package, let me know.

Regards,

Philippe



Philippe Martin wrote:

> Hi,
> 
> I am currently packaging python and a few libraries: PyWin32, PySerial,
> PIL, wxPython, HTML generator, numarray for U3 distribution.
> 
> Basically that means that the complete system initially in $path1\host
> will be moved dynamically to $path2\at execution.
> 
> 
> To take PIL as an example, I notice when I launch Idle in a "relative"
> manner: I am in $path1\host that $path1\host\Lib\site-packages\PIL is in
> the sys.path before I do anything.
> 
> I notice that there is a PIL.pch file in site-packages:
> 
> Q1) is that read by python ?
> 
> 
> On the other hand, even after appending all I can think of in sys.path, I
> still get an error (cannot find module) trying to load win32com.client: it
> fails in the win32api import in win32com.client.
> 
> pywin32.pch is there.
> 
> I think all the .dlls are there also, so I'm a bit confused.
> 
> Q2) what should I be looking for ?
> 
> 
> Also, I seemed to notice in the past that modules (my own) not listed in
> any __init__.py where found under Linux but not Windows for which I had to
> upgrade my __init__.py.
> 
> 
> Q3: is that true ?
> 
> 
> Regards,
> 
> Philippe

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


Re: Working with decimal points

2006-04-08 Thread [EMAIL PROTECTED]

Byte wrote:
> That dosnt work either:
>
> sum = 0.1+1/4
> print sum
>
> Just returns 0.1

You get precedence right? Your equation does not evaluate from left to
right. 1/4 happens first, and since there are no floats you get 0.

in that equation you basically are doing this:

sum = 1/4
print sum
0

sum = 0.1 + sum
print sum
0.1

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


Re: Working with decimal points

2006-04-08 Thread Fredrik Lundh
"Byte" wrote:

> That dosnt work either:
>
> sum = 0.1+1/4
> print sum
>
> Just returns 0.1

division has higher precedence than addition, so 1/4 is calculated first,
and the result is then added to 0.1.

and as I've already explained, 1/4 is an integer division, so the result
is rounded down to the the nearest integer (0).  in other words, your
expression boils down to

0.1 + 0

which is 0.1 [1].

the precedence order is explained here:

http://docs.python.org/ref/summary.html



1) or at least a close approximation of it; see
http://docs.python.org/tut/node16.html



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


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread John Salerno
Clodoaldo Pinto wrote:

> "Python is a remarkably powerful dynamic programming language that is
> used in a wide variety of application domains. Python is often compared
> to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing
> features include:..."

I'd be careful with that definition for newbies though. There's nothing 
more frustrating (as a newbie myself) when Python (or anything else) is 
compared to something as a way to explain it, yet I have no idea what 
the other things are either! A programming newbie won't know about, and 
maybe won't even have heard of, those other languages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recognize a drive as removable media (e.g. compact flash, sd card or usb drive)

2006-04-08 Thread Larry Bates
Mike Joyce wrote:
> I am trying to write a portable script that will find removable
> media, such as compact flash, sd card, usb, etc. drive and then upload
> files from the media. I want this to be portable so that I can write and
> maintain one program for both Linux and Windows. Each platform uses
> different functions so even if I could find two platform dependent
> functions that would be fine. Basically, I would like to avoid checking
> fixed disks if possible.
> If anyone know of a good way to do this please let me know. Thanks
> in advance for any help.
> -Mike Joyce

Take a look at the code located at the top of the os.py module.  It
goes through a series of tests to determine which OS it is running
on.  You should be able to use something like that to create branches
in your code to handle Windows/Linux separately.  As far as determining
removable drives in Windows/Linux I'm afraid I can't help on that.

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


Do I Need This?

2006-04-08 Thread sdavies6
I have no idea how this got onto my month old HP computer; I must have 
downloaded something which uses it.  It seems I have a folder and subfolders 
equaling about 29 MB, called PYTHON 22.  The subfolders are "DLLs," "Lib," 
"libs," "Scripts," and, "td." I am not a programmer, so I'm wondering if I 
can safely remove this. 


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


Re: minidom + wxPython woes

2006-04-08 Thread Paul Boddie
Frank Millman wrote:
> Fredrik Lundh wrote:
> >
> > no, it's not a bug in the pyexpat module -- the problem is that
> > wxPython uses it's own incompatible version of the expat library,
> > and loads it in a way that causes problems for any library that's
> > tries to use its own statically linked version.

[...]

> Firstly, it seems from various posts to the tracker item that the same
> problem has been reported with pygtk, Qt, and VTK.

There used to be issues with Expat, PyXML and mod_python which may be
vaguely related to this, mostly because there was some usage of Expat
within some Apache component which conflicted with PyXML's Expat
configuration. In the end, I just dropped PyXML and started using other
libraries not affected by such issues, and I'm not totally sure that
anyone really resolved the problem definitively (although this was
possibly four or five years ago, so a lot can have happened since).

Paul

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


Re: Do I Need This?

2006-04-08 Thread Paul Boddie
sdavies6 wrote:
> I have no idea how this got onto my month old HP computer; I must have
> downloaded something which uses it.  It seems I have a folder and subfolders
> equaling about 29 MB, called PYTHON 22.  The subfolders are "DLLs," "Lib,"
> "libs," "Scripts," and, "td." I am not a programmer, so I'm wondering if I
> can safely remove this.

See this page for some advice:

http://www.python.org/doc/faq/installed/

Paul

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


Re: Do I Need This?

2006-04-08 Thread Terry Reedy

"sdavies6" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I have no idea how this got onto my month old HP computer; I must have 
>downloaded something which uses it.  It seems I have a folder and 
>subfolders equaling about 29 MB, called PYTHON 22.  The subfolders are 
>"DLLs," "Lib," "libs," "Scripts," and, "td." I am not a programmer, so I'm 
>wondering if I can safely remove this.

Loaded by HP to run their Python scripts.  You need if and only if you run 
at least one of them either directly or indirectly.  Since I considered the 
preloading a bonus, I never tried renaming the directly to find out.  There 
may be a page at python.com that explains more.

tjr




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


Re: best way to install python modules on linux

2006-04-08 Thread Robert Kern
Fabian Braennstroem wrote:
> Hi to all,
> 
> thanks for your ideas! I just figured out a different way
> using archlinux 'pacman' (package management tool like apt).
> As a former archlinux user I am more used to adjust those
> PKDBUILDs (kind of ebuilds under archlinux) than adjusting
> debian packages. The downside is that apt does not know
> anything about those installed packages (just like with
> easyinstall and checkinstall). I am not sure, if is the best
> way, but the installation of numpy and scipy almost worked ;-)
> 
> Starting numpy gives me:
>   import numpy
>   import linalg -> failed: /usr/lib/3dnow/libf77blas.so.2: undefined symbol: 
> e_wsfe
> 
> Which looks pretty odd for me!?

It looks like you are missing linking to the g2c library. If you could post your
build log to [EMAIL PROTECTED], we'll be glad to help you out.

-- 
Robert Kern
[EMAIL PROTECTED]

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


How to determine if a line of python code is a continuation of the line above it

2006-04-08 Thread Sandra-24
I'm not sure how complex this is, I've been brainstorming a little, and
I've come up with:

If the previous line ended with a comma or a \ (before an optional
comment)

That's easy to cover with a regex

But that doesn't cover everything, because this is legal:

l = [
 1,
 2,
 3
 ]

and with dictionaries and tuples as well.

Not sure how I would check for that programmatically yet.

Is there any others I'm missing?

Thanks,
-Sandra

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


Re: scipy/numpy inverse cumulative normal

2006-04-08 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> I was wondering if scipy/numpy has the inverse cumulative normal 
> function, ie the function f in this expression
> 
> f(scipy.stats.norm.cdf(1.2)) = 1.2
> 
> or more generally, a function f which fits the criteria
> 
> f(scipy.stats.norm.cdf(x)) = x

Look in the file where all of the distributions are defined,
Lib/stats/distributions.py . You will find that each distribution object also
has a method call .ppf(), the Percent Point Function, the inverse of the CDF.

In [1]: from scipy.stats import norm

In [2]: norm.ppf(norm.cdf(1.2))
Out[2]: array(1.2004)

> There is a distribution called invnorm, but I am not sure of how to use
> it.

invnorm is another probability distribution entirely. Don't bother with it.

-- 
Robert Kern
[EMAIL PROTECTED]

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread Duncan Smith
James wrote:
> Perhaps use the phrase "whole number" there and mention that in
> programming they're called integers. Having a glossary with
> definitions for things like integer, float etc etc. would be good if
> when you talked about integers it linked to the glossary. And
> similarly use "decimals" for floats? Less sure about that one though.
> But anyway you don't need to go into the whole type thing, just
> mention that Python distinguishes between doing maths with whole
> numbers and decimals.
> 

In general they are integers, and "integer" is not a Python type, so I
don't see a problem with the term.  The problem I saw was that there was
no explanation for the returned value.  Using the term "decimal" is
probably a bad idea, given Python decimals.  But I'm not sure you need
to come up with a suitable term until you actually get round to
explaining types (at which point the problem disappears).

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


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread Clodoaldo Pinto
John Salerno wrote:
> Clodoaldo Pinto wrote:
>
> > "Python is a remarkably powerful dynamic programming language that is
> > used in a wide variety of application domains. Python is often compared
> > to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing
> > features include:..."
>
> I'd be careful with that definition for newbies though. There's nothing
> more frustrating (as a newbie myself) when Python (or anything else) is
> compared to something as a way to explain it, yet I have no idea what
> the other things are either! A programming newbie won't know about, and
> maybe won't even have heard of, those other languages.

Good point. I used the Python site front page definition without the
object oriented thing.

Regars, Clodoaldo

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


Re: recognize a drive as removable media (e.g. compact flash, sd card or usb drive)

2006-04-08 Thread Tim Golden
Mike Joyce wrote:
> I am trying to write a portable script that will find removable media,
> such as compact flash, sd card, usb, etc. drive and then upload files
> from the media. I want this to be portable so that I can write and
> maintain one program for both Linux and Windows. Each platform uses
> different functions so even if I could find two platform dependent
> functions that would be fine. Basically, I would like to avoid checking
> fixed disks if possible.
>   If anyone know of a good way to do this please let me know. Thanks in
> advance for any help.

Under Windows, you can probably use WMI for this, depending on
exactly what it is you're trying to do. If I read you right, you want
to
scan all devices, determine the removable ones, and then read stuff
off them.

If that's right, then something like this might do the trick on Windows
(untestedish - picks up my floppy and USB stick):


import wmi
c = wmi.WMI ()
removable_disks = c.Win32_LogicalDisk (DriveType=2)
# if you want CDROM as well, repeat with DriveType=5


This will give you a list of WMI objects, each corresponding
to a removable disk. You can access the drive letter via the
objects' .Name attributes, and do an os.walk or whatever on
them.


import os
for disk in removable_disks:
  for dirpath, dirnames, filenames in os.walk (disk.Name + "\\"):
print dirpath # and do whatever else you want


TJG

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


Insertion (sql) bug in Py2.4 pySQLite 2.2

2006-04-08 Thread DurumDara
Hi !

I have this code in my program. Before this I use APSW, but that 
project's connection object doesn't have close method...

... crs.execute(*'''create table files
(*f_id integer not null primary key, f_name varchar(255), f_size long, 
f_attr integer, f_crtime varchar(20), f_mdtime varchar(20), f_hash long 
)*''') ...
crs=connection.cursor()
crs.execute('insert into files 
(f_crtime,f_mdtime,f_attr,f_id,f_hash,f_size,f_name) 
values(?,?,?,?,?,?,?)',('1','1',1,1,1,1,'a')) ... *

So: I create a table in the first, and later I want to push some 
elements to it. Before this example code I use special method to create 
insert sql with tuple of values. But everytime it have been failed with 
this message: SQL error or inaccessible database. Then I simplified the 
code with hand maded SQL. And then I got same error message. The 
database file removed and rebuilded with every execution.

When I tired by this error, I returned to APSW, and then I don't got 
error messages.

What is the problem in this package ? 
http://initd.org/pub/software/pysqlite/releases/2.2/2.2.0/pysqlite-2.2.0.win32-py2.4.exe
 
With Py2.3 I use pysqlite package in my CD organizer program, and then I 
does not exp. same problems.

Please help me: dd

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


Re: How to determine if a line of python code is a continuation of the line above it

2006-04-08 Thread Dan Sommers
On 8 Apr 2006 11:24:04 -0700,
"Sandra-24" <[EMAIL PROTECTED]> wrote:

> I'm not sure how complex this is, I've been brainstorming a little, and
> I've come up with:

["This" meaning how to determine if a line of python code is a
continuation of the line above it.]

> If the previous line ended with a comma or a \ (before an optional
> comment)

A line ending with a comma does *not* indicate a single statement spread
out over two lines:

a = 1,
print a,
a = [ ]

None of those lines is a continuation of the line above it.

> That's easy to cover with a regex

> But that doesn't cover everything ...

I think you'll end up having to parse the code in its entirety to do
this correctly.  Consider triple quoted strings and multiple uses of
parenthesis, both of which can be nested arbitrarily, including inside
each other, and arbitrarily nested delimeters are beyond the ability of
regexen.

Is this merely an academic exercise, or is there a larger purpose for
wanting this information?

Regards,
Dan

-- 
Dan Sommers

"I wish people would die in alphabetical order." -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread James
If you're serious about this being a real introduction for someone who
knows nothing, then you might want to start off by explaining what a
programming language is (and why there are more than one) and then
what a standard library is - perhaps explain it in terms of a large
set of tools you can use straight away?

James

On 8 Apr 2006 11:53:34 -0700, Clodoaldo Pinto <[EMAIL PROTECTED]> wrote:
> John Salerno wrote:
> > Clodoaldo Pinto wrote:
> >
> > > "Python is a remarkably powerful dynamic programming language that is
> > > used in a wide variety of application domains. Python is often compared
> > > to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing
> > > features include:..."
> >
> > I'd be careful with that definition for newbies though. There's nothing
> > more frustrating (as a newbie myself) when Python (or anything else) is
> > compared to something as a way to explain it, yet I have no idea what
> > the other things are either! A programming newbie won't know about, and
> > maybe won't even have heard of, those other languages.
>
> Good point. I used the Python site front page definition without the
> object oriented thing.
>
> Regars, Clodoaldo
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming Tutorial for absolute beginners

2006-04-08 Thread Clodoaldo Pinto
Duncan Smith wrote:
> James wrote:
> > Perhaps use the phrase "whole number" there and mention that in
> > programming they're called integers. Having a glossary with
> > definitions for things like integer, float etc etc. would be good if
> > when you talked about integers it linked to the glossary. And
> > similarly use "decimals" for floats? Less sure about that one though.
> > But anyway you don't need to go into the whole type thing, just
> > mention that Python distinguishes between doing maths with whole
> > numbers and decimals.
> >
>
> In general they are integers, and "integer" is not a Python type, so I
> don't see a problem with the term.  The problem I saw was that there was
> no explanation for the returned value.

How would I explain that 3 / 2 is 1 without entering the type realm?
What if I say that if one don't use the point the interpreter will also
not use it? Would i be laying? Isn't it better to just let it go? I
think the typical non programmer newbie just don't care two much about
reasons as long as there is a clear rule. No point in the question then
no point in the answer.

>  Using the term "decimal" is
> probably a bad idea, given Python decimals.  But I'm not sure you need
> to come up with a suitable term until you actually get round to
> explaining types (at which point the problem disappears).
>

As I think float is scaring I changed it in the program comments where
it appeared for decimal. I don't worry about precision as much as I
worry about fluidity. I don't want anyone stoping to consult a
dictionary or a glossary.

Now the integer versus whole. As a non native english speaker I don't
know what sounds less mathematical and more natural. I changed integer
to whole following the previous suggestion but I really don't know.

Regards, Clodoaldo

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


Receiving emails with attachments

2006-04-08 Thread tomer . ha
Hi there,

I'm new to Python, but know other scripting and programming languages.
I
want to develop a script which will receive emails with attachments
from my POP3 account, perform certain actions on it and email it back
to someone else.

However, I'm not familiar with any Python library which does it. Could
you a guide me to a relevant library which can handle emails?

I haven't decided yet what scripting language I will use, so a nice
module for Python will probably make me choose it over Perl. :)

Thanks in advance. :)

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


how relevant is C today?

2006-04-08 Thread John Salerno
Because of my 'novice-ness' in programming, I had always thought that C 
was replaced by C++ and wasn't really used anymore today. I know that's 
not the case at all now, but I'm still curious how much C is used 
anymore in programming today, and what purpose it serves. Is it used for 
actual application programming, or is its use more for something like 
extending Python? Would it help for a newbie to learn C for any reason?
-- 
http://mail.python.org/mailman/listinfo/python-list


programming puzzles?

2006-04-08 Thread John Salerno
Similar to the Python Challenge, does anyone know of any other websites 
or books that have programming puzzles to solve? I found a book called 
"Puzzles for Hackers", but it seems like it might be a little advanced 
for me, and I've also read that it focuses too much on encryption and 
security issues and doesn't really have coding problems, exactly. But 
something like that book would be fun to have.
-- 
http://mail.python.org/mailman/listinfo/python-list


How's python's web scraping capabilities (vs LWP) ...

2006-04-08 Thread ArKane
Hello all,

I've been hacking away at perl for a few months now, mainly using the
LWP module, used for web scraping. Amoung its capabilities include
support for HTTPS and proxies, authentication, cookies (including the
ability to automatically import Internet Explorer cookies), etc.

It seems to me, however, that trying to write more sophisticated apps
using GUIs with perl is somewhat akin to pulling teeth, so I've been
looking at python, but was wondering if there was an LWP equivalent
for python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine if a line of python code is a continuation of the line above it

2006-04-08 Thread Sandra-24
No it's not an academic excercise, but your right, the situation is
more complex than I originally thought. I've got a minor bug in my
template code, but it'd cause more trouble to fix than to leave in for
the moment.

Thanks for your input!
-Sandra

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


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread Mirco Wahab
Jay wrote:

 > I have compleated the beginers guide to python
 > http://www.freenetpages.co.uk/hp/alan.gauld/.
 > then i found the Toolkit Tkinter and started on that. its graight and
 > av made lots of apps to help me with litle things but i have a big
 > problem. the CLASS method.

Ledds viddy, my droog - you tried to rabbit
hard but diddnt get your horrorshow? So you
start platching here?

 > when i seperate things up into classes i carnt get one class to tell
 > the other class somthing. it just opens another coppy of the class. i
 > am confused.

Malchick, you cracked your veshchs to classes, which is
not that gloopy. So rabbit on them and add class methods
that sloosh on beeing called and do the proper veshchs
to the gulliwuts of their classes.

 > oh and i carnt fathem out how to run to loops at the same time. EG .
 > Ball Blaster i wanted to permenetly run the ball with a loop well my
 > main loop ran the bat.
 > can sumone point me to the right studeing material.

All TK-lewdies here will creech 'callback' at you sth. So
prod your working TK app by rabbit out a 'callback domy',
just filly around with this
http://effbot.org/zone/wck-2.htm#handling-user-events
or that
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/464635

Tolchock it,

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


Re: Receiving emails with attachments

2006-04-08 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote:

> Hi there,
>
> I'm new to Python, but know other scripting and programming languages.
> I
> want to develop a script which will receive emails with attachments
> from my POP3 account, perform certain actions on it and email it back
> to someone else.
>
> However, I'm not familiar with any Python library which does it. Could
> you a guide me to a relevant library which can handle emails?
>
> I haven't decided yet what scripting language I will use, so a nice
> module for Python will probably make me choose it over Perl. :)
>
> Thanks in advance. :)

poplib module:

http://docs.python.org/lib/pop3-example.html

some example code that I wrote when I was starting Python:

http://gflanagan.net/site/python/pagliacci/PopClient.html

( YMMV with this - it works for me but the emails I handle with it are
mostly from a single company and attachments are only ever MS Word or
MS Excel )

I don't know about sending mails.

Gerard

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


Re: Python-list Digest, Vol 31, Issue 119

2006-04-08 Thread Jay Parlar

On Apr 8, 2006, at 1:40 PM, [EMAIL PROTECTED] wrote:

>
> Hi there,
>
> I'm new to Python, but know other scripting and programming languages.
> I
> want to develop a script which will receive emails with attachments
> from my POP3 account, perform certain actions on it and email it back
> to someone else.
>
> However, I'm not familiar with any Python library which does it. Could
> you a guide me to a relevant library which can handle emails?
>
> I haven't decided yet what scripting language I will use, so a nice
> module for Python will probably make me choose it over Perl. :)
>
> Thanks in advance. :)


Well, there's always the 'email' module, part of the standard library:

http://docs.python.org/lib/module-email.html

Jay P.

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


Re: how relevant is C today?

2006-04-08 Thread Martin v. Löwis
John Salerno wrote:
> Because of my 'novice-ness' in programming, I had always thought that C
> was replaced by C++ and wasn't really used anymore today. I know that's
> not the case at all now, but I'm still curious how much C is used
> anymore in programming today, and what purpose it serves. Is it used for
> actual application programming, or is its use more for something like
> extending Python? Would it help for a newbie to learn C for any reason?

My impression is that C++ hasn't managed to replace C, and that it isn't
used that much for new projects; of course, there is tons of existing
C++ code.

I think John Ousterhout's distinction of System programming vs.
Scripting languages isn't that bad, after all. C is used heavily
for System programming, and will not be replaced there for a foreseeable
future: operating systems, programming languages, web servers, database
servers, etc. OTOH, application programming is done in Java, Python,
C#, Ruby, ... C++ is used both for system programming and applications.

As for *learning* the languages: never learn a language without a
specific inducement. If you know you are going to write a Python
extension, an Apache module, or a Linux kernel module in the
near future, start learning C today. If you don't know what you
want to use it for, learning it might be a waste of time, as
you won't know what to look for if you don't have a specific project
in mind.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how relevant is C today?

2006-04-08 Thread Mirco Wahab
Hi John

> Because of my 'novice-ness' in programming, I had always thought that C 
> was replaced by C++ and wasn't really used anymore today. I know that's 
> not the case at all now, but I'm still curious how much C is used 
> anymore in programming today, and what purpose it serves. 

There is a whole spectrum of 'mixing' between features of
C ans C++ used today in the industry and thats o.k. if it
just works. You cal write plain C in a C++ environment,
mix some C++ features to your otherwise plain C and
so on - as you like.

You can't compare C/C++'industrial use w/Python's in todays
Software production - there is no match.

A recent 580+ people survey (O'Reilly) brought up the following:
http://www.onlamp.com/pub/a/onlamp/2005/12/02/onlamp_survey_results.html?page=2

"The Dice" (find tech jobs) has offerings
(last 7 days, U.S. + unrestricted) for:
   *SQL 14,322
   C/C++11,968
   Java 10,143
   ...
   Perl  3,332
   PHP 730
  *Python* 503
   Fortran 119
   Ruby108
   open*gl  66

That is what the industry looks for.
You understand the ratios?

> ... Is it used for 
> actual application programming, or is its use more for something like 
> extending Python? Would it help for a newbie to learn C for any reason?

It is used for almost everything, from
- Programming the Python Language itself,
- Programming the Perl Language itself,
- Programming the PHP language and others,
to
- complete Applications, as you said.

It *is* somehow 'wordy' (especially C), but
don't underestimate its power in the hands
of a master ;-)

There is a huge amount of highly
functional libraries for almost
everything too.

Regards,

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


Re: Insertion (sql) bug in Py2.4 pySQLite 2.2

2006-04-08 Thread Peter Hansen
DurumDara wrote:
> So: I create a table in the first, and later I want to push some 
> elements to it. Before this example code I use special method to create 
> insert sql with tuple of values. But everytime it have been failed with 
> this message: SQL error or inaccessible database. Then I simplified the 
> code with hand maded SQL. And then I got same error message. The 
> database file removed and rebuilded with every execution.
> 
> When I tired by this error, I returned to APSW, and then I don't got 
> error messages.

*What* error messages?  Please always post the *complete* traceback, cut 
and pasted directly from your console window without editing, so that we 
don't have to guess what is wrong.

If possible, you should also take the time to reduce your code down to 
the smallest program which still causes the undesirable behaviour, and 
if it's only ten or twenty lines of code you should post that here along 
with the traceback.

-Peter

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


Re: Compleated Begginers Guide. Now What?

2006-04-08 Thread James Stroud
Mirco Wahab wrote:
> Jay wrote:
> Malchick, you cracked your veshchs to classes, which is
> not that gloopy. So rabbit on them and add class methods
> that sloosh on beeing called and do the proper veshchs
> to the gulliwuts of their classes.

Brillig!


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: programming puzzles?

2006-04-08 Thread [EMAIL PROTECTED]
John Salerno wrote:
> Similar to the Python Challenge, does anyone know of any other websites
> or books that have programming puzzles to solve? I found a book called
> "Puzzles for Hackers", but it seems like it might be a little advanced
> for me, and I've also read that it focuses too much on encryption and
> security issues and doesn't really have coding problems, exactly. But
> something like that book would be fun to have.

Personally, I am an avid reader of rec.puzzles. Not because
I like doing stupid puzzles per se, but I look at them from the
viewpoint "how would I write a program to solve this?"
Even simple word problems sometimes involves more trouble than
the puzzle is worth, but it teaches you how to write algorithms to
generate permutations, combinations, partitions, etc. that can be
handy for other applications. And it's one thing to generate letter
patterns, determining if they are English words is something else,
which can teach you about database and such.

Many puzzle purists bristle at this attitude, but I do this for
myself, not for them.

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


Re: how relevant is C today?

2006-04-08 Thread Daniel Nogradi
> "The Dice" (find tech jobs) has offerings
> (last 7 days, U.S. + unrestricted) for:
>*SQL 14,322
>C/C++11,968
>Java 10,143
>...
>Perl  3,332
>PHP 730
>   *Python* 503
>Fortran 119
>Ruby108
>open*gl  66

Can anyone shed some light on the secret of Java? How is it that they
are so high on this list?
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >