Re: module confusion

2007-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Robert
Kern wrote:

> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote:
>> 
>>> What does type(os.path) return when you try it?
>> 
>> It returns the type of the value contained in that variable, of course:
>> 
>> >>> import os
>> >>> os.path = 3
>> >>> type(os.path)
>> 
>> 
>> See, it's just a variable, like any other.
> 
> Okay. No one is contending that the "os.path" name can't be reassigned
> to a different object or that the "os.path" name is somehow different from
> any other name in Python. It's not wrong to say that "os is a module"
> either, even though you can obviously reassign that name to another
> object, too.

It is not the _name_ that is being reassigned, it is the _variable_ that the
name is bound to. All names in Python are bound to variables at all times.

> What I meant when I said "os.path is a bit of a weird case" is that, by
> default, the object referred to by the name "os.path" (assuming you've
> imported the standard library's os module) is another module and that os
> itself is a module, not a package like logging is. This is somewhat odd,
> because most modules aren't exposed that way. They are either in their own
> file and accessed by importing them directly, or they are inside a
> package.

That is also true of the module pointed to by os.path. Like any other
non-built-in module, it lives in its own file.

It also helps to keep clear the difference between a "module" and a "module
object". A "module" is the contents of a Python source file, while
a "module object" is a type of in-memory Python object. An "import"
statement generates the latter from the former. See
. Admittedly, other parts of the
Python docs do not keep the distinction clear, but the section on "Modules"
in that page does just about do so.

You can't have modules within modules. But there's no reason an attribute of
one module object can't point to another module object. Notice I say "point
to" rather than "contain". There is no sense in which any Python object
can "contain" any other.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module confusion

2007-10-05 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit :
> In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote:
> 
>> What does type(os.path) return when you try it?
> 
> It returns the type of the value contained in that variable, of course:

Certainly not. You're confusing Python with C. In Python, 'variables' 
are *not* labels for memory locations containing values. Period

> >>> import os
> >>> os.path = 3
> >>> type(os.path)
> 
> 
> See, it's just a variable, like any other.

This is bad faith.

 >>> import os
 >>> type(os.path)


See, this is a name bound to an object, like any other.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Real time plot

2007-10-05 Thread Lawson Hanson
Nicholas Bastin wrote:
> On 10/4/07, Jean-Francois Canac <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED]
>>> I would draw dots on a suitably sized Tkinter canvas, after drawing a
>>> schematic
>>> of the race track (laborious).
>>>
>>> 20 per second will be no problem, provided the machine is half decent.
>>>
>>> What is the speed at which the com port runs?
>>>
>>> - Hendrik
>>>
>> The com port run at 19.2 kb/s.
>> My pb is more the real time aspect: to see the plot changing in real time
>> than the com aspect as the installation is already running with programs in
>> c++.
>> The PC on which it is running is good enought
>> For me the interest is to migrate all taht on python to be able to make fast
>> changes when it is of interest
> 
> The success of this will have more to do with design than programming
> language.  Any GUI toolkit which allows partial screen updates can be
> made to update at least as fast as your screen refresh rate, even in
> python.
> 
> --
> Nick

If you are using Tkinter (probably a very good choice), just remember
 to make periodic (i.e., once per I/O processing loop) calls to:

 Tkinter.update_idletasks()

which will update the display window, etc.

Regards,

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


Re: Mysql class works like php

2007-10-05 Thread Bruno Desthuilliers
Andrey a écrit :
> Hi
> 
> just a quick question about using MySQL module... are there any api / class 
> available to give a higher level in working with Mysql in python?
> such as
> db.fetch_array(),
> db.fetch_rows(),
> db.query(),
> for eachrow in db.fetch_array():
> 

You really find this "higher level" than Python's db-api ???

> just as easy as PHP?

D'oh :(


// PHP:
// suppose we have a valid $connection
$q = mysql_query("select * from yaddayadda", $connection)
if (is_resource($q)) {
   while($row = mysql_fetc_row($q)) {
 do_something_with($row);
   }
   mysql_free($q);
}
else {
   // handle the error here
}

# python:
# suppose we have a valid connection
cursor = connection.cursor() # can specify the kind of cursor here
try:
   cursor.execute("select * from yaddayadda")
except MysqlError, e:
   # handle error here
else:
   for row in cursor:
 do_something_with(row)

# not strictly necessary, you can reuse the same
# cursor for another query
cursor.close()


As far as I'm concerned, I fail to see how PHP is "higher level" or 
"easier" here.


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


Re: module confusion

2007-10-05 Thread Hendrik van Rooyen
"Steve Holden" <[EMAIL PROTECTED]> wrote:

> Hendrik van Rooyen wrote:
> > "Steve Holden"  wrote:
> >
> >> religious issues for me. It's more like "This problem has a cross head,
> >> so I'll need a Philips screwdriver".
> >
> > As long as it is not a Pozidrive, that is a commendable attitude.
> >
> I said cross head, not Pozidriv (tm). But then I have been nown to use a
> Manchester screwdriver[1] on occasion.

Philistine!

But in a way, it is more honest than the Free State method of tightening a bolt-

You tighten enthusiastically until it strips, then go a quarter turn back to
undo
the damage.

BTW, in case you have been wondering - a Free State Micrometer is a
plumber's adjustable pipe wrench.

- Hendrik

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


Re: Program with wx in Linux and Windows

2007-10-05 Thread Hendrik van Rooyen
"marcpp"  wrote:


> Hi I've developed a program (WXpython GUI). In Linux the GUI is correct 
> (various distributions), but in Windows all appears disordered.
> Any recomendations?

You are not going to like this recommendation.

Use Tkinter instead - seems to work nicely cross platform for me.

- Hendrik

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


Re: Real time plot

2007-10-05 Thread Hendrik van Rooyen
 "Jean-Francois Canac"  wrote:

"Hendrik van Rooyen"  a écrit dans le message de news:

>>
>> I would draw dots on a suitably sized Tkinter canvas, after drawing a
>> schematic
>> of the race track (laborious).
>>
>> 20 per second will be no problem, provided the machine is half decent.
>>
>> What is the speed at which the com port runs?
>>
>> - Hendrik
>>
>The com port run at 19.2 kb/s.
>My pb is more the real time aspect: to see the plot changing in real time
>than the com aspect as the installation is already running with programs in
>c++.
>The PC on which it is running is good enought
>For me the interest is to migrate all taht on python to be able to make fast
>changes when it is of interest

Doing the plotting should not be a problem - the interesting bits will be
to associate the data with the plot, so that you can click to "drill down"
to see the speed, etc.

Or maybe you should do two things at once - show the position of the car
on the track, and a running graph of the variables of interest.

In a sense, plotting on a canvas is a fairly simple co ordinate transformation
problem.

HTH - Hendrik
- Hendrik




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


Re: Is there a nicer way to do this?

2007-10-05 Thread Bruno Desthuilliers
Stefan Arentz a écrit :
> Is there a better way to do the following?
> 
> attributes = ['foo', 'bar']
> 
> attributeNames = {}
> n = 1
> for attribute in attributes:
>attributeNames["AttributeName.%d" % n] = attribute
>n = n + 1
> 
> It works, but I am wondering if there is a more pythonic way to
> do this.

There is:

attributeNames = dict(
 ("AttributeName.%d" % n, attr) \
 for n, attr in enumerate(attributes)
   )

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


"SyntaxError: Non-ASCII character '\xc2'...", was Re: Is there a nicer way to do this?

2007-10-05 Thread Peter Otten
Victor B. Gonzalez wrote:

> anyhow, I keep getting "SyntaxError: Non-ASCII character '\xc2'..." on line 
> 5. 
> anyone know what this is? 

I too had that problem with KNode. Leading space consists of NO-BREAK SPACE
(unichr(160)) which translates to '\xc2\xa0' in UTF-8. As I don't see this
problem here (using pan) I suspect it may be specific to KMail/KNode.

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


a good website for making money online

2007-10-05 Thread panguohua
www.space666.com



more information for making money

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


Re: module confusion

2007-10-05 Thread Marc 'BlackJack' Rintsch
On Fri, 05 Oct 2007 19:51:05 +1300, Lawrence D'Oliveiro wrote:

> It is not the _name_ that is being reassigned, it is the _variable_ that
> the name is bound to. All names in Python are bound to variables at all
> times.

I think this is the source of the confusion.  Most people don't seem
to share your definition of `variable` above.

To me a `variable` is made of a name, a memory address, a data type, and
a value.  In languages like C the address and type are attached to the
name while in Python both are attached to the value.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross platform way of finding number of processors on a machine?

2007-10-05 Thread Tim Golden
Nicholas Bastin wrote:
> On 10/4/07, John <[EMAIL PROTECTED]> wrote:
>> Is there a way to find the number of processors on a machine (on linux/
>> windows/macos/cygwin) using python code (using the same code/cross
>> platform code)?
> 
> There's no single call that will give you the same info on every
> platform, but you can obviously write this yourself and switch based
> on os.uname()[0] in most cases.

Second that point about not getting one cross-platform
answer. Under Windows, WMI is often the way to go for
these things:

   http://msdn2.microsoft.com/en-us/library/aa394373.aspx

but, as Nicholas noted:

   """
   Windows Server 2003, Windows XP, and Windows 2000:
 This property is not available.
   """

since it's presumably not available in anything earlier either,
that leaves you with Vista or the early-adopter editions of the
next Windows Server product.

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


Please Help me

2007-10-05 Thread Jean-Francois Canac
I am very new in Python and I would like to write an application which takes
records from a COM port (or from a file to replay) and draw a real time
Plot.

 

But I am confused I have looked at Matplotlib, and a little at hippodraw, I
have seen that there are many plot interfaces . But I really don’t know
which I should take for producing plot with data coming from a steam



Please could you help?

 

Many thanks

Jean-François 

 

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

Re: Convert on uppercase unaccentent unicode character

2007-10-05 Thread Ricardo Aráoz
Wildemar Wildenburger wrote:
> Steve Holden wrote:
>> Malheureusement, I see that absence of accented capitals is a modern 
>> phenomenon that is regarded as an impediment to the language mostly 
>> stemming from laziness of individual authors and inadequacy of low-end 
>> typesetting software. I hadn't realised I was so up-to-date ;-)
>>
>> So I will have to stop propagating this misinformation.
>>
> 
> Thats really weird, because I was taught in school that caps are not to 
> be accented. In school! Big Brother is an idiot.
> 
> I'm equally ammused by the part of JBJ's link where it says that a 
> missing acccent "fait hésiter sur la prononciation". Yeah, AS IF written 
> French had anything to do with the way it is pronounced. Not that I 
> don't like french, mind you. Everywhere outside action movies its pretty 
> cool.
> 
> /W

Then you never saw Taxi. Or some of Depardieu's ones. Or Les
adventuriers (sp?) (that's a rally old one), or I comme Icarus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: racism kontrol (OT)

2007-10-05 Thread Hendrik van Rooyen
 "Wildemar Wildenburger"  wrote:


> Hendrik van Rooyen wrote:
> >  "Wildemar Wildenburger"  wrote:
> > 
> >> (By the way: Accusing a German of racism is almost too easy an insult. 
> >> Not that I had taken any, just saying.)
> > 
> > I always thought that it would be insulting to a German if you accused
> > him or her of not being a racist...
> > 
> Very funny, Herr Dutsh-Mann. 

Afrikaans, not Dutch.

>>Dude, hailing from South Africa with a 
> Dutch name, I'd be careful with the word racist. That of course being 
> based on the fact that in South Africa the term never had relevance and 
> thus meaning. Hence I understand that you probably have as much 
> understanding of the term "racism", as we have of "a welcome Jew". Or, 
> for that matter, a "a Dutchman that is pleasant to listen to". Burn! ;)

I really must apologise for my accent - but then I was once mistaken
for a Scot by an Englishwoman in Hong Kong. But you know, it is
like being ugly - its not so bad for the perpetrator, it really bothers 
other people more.

Is there an equivalent of Godwin's law with "Hitler" being replaced
by "Apartheid" ? - there should be, in my opinion.  In that respect
Germany and South Africa are similar  - They both have murky
pasts.

> Sidenote: Its funny that everybody calls the Dutch "Dutch" (when 
> speaking English), which pretty much is the word "deutsch", which, guess 
> what, means "German" (cf. Pennsylvania Dutch). That has always baffled 
> me --- do Dutch people refer to themselves as "Dutch" when speaking 
> dutch? The term for "Dutch" is "Nederlands" or "Hollands", isn't it?

Yes to both  - with the "Ne" pronounced similar to English "neigh'...

One of these days I will try to learn to speak the language of my ancestors.

- Hendrik

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


Python + Shoutpy + Twisted Locks

2007-10-05 Thread exhuma.twn
Unfortunately I don't have the code at hand on this box, but maybe
someone can give me a nudge in the right direction.

Some background: Last year I began to write a jukebox system that
provided a Telnet-like interface. I wrote this using "socket". Later
along the path I discovered Twisted, and due to various other
problems, a re-write made sense. So I decided to use Twisted. The only
thing I adapted was the class providing the telnet interface. In the
background I use a few other threads. One for metadata-scanning, one
for assuring continuous playback (periodic checks the player status
and appends songs if necessary) and in the case the shoutcast backend
is activated, there is also a built-in player thread.

I remember having it running already, but I don't remember if it was
before I started to use Twisted or after.

Well, I beleive the problem lies withing the last named thread. This
one uses shoutpy to stream data to the shoutcast server. What I found
is that "libshout" is blocking, which should be fine as the whole
thing runs in it's separate thread. But the application hangs
nevertheless while streaming. This effectively blocks out the other
thread that checks the player status, which then fails to append new
songs to the queue. So only one song is played when streaming.

I saw that there is another package called "python-shout". But neither
that nor "shoutpy" have any comprehensive documentation which might
tell me anything about the libshout blocking problem. The
documentation of libshout revealed a "non-blocking" mode, but even
though I made the necessary adjustments to the code, I still had the
same problem.

The other threads in my application run fine and don't block the rest
of the app. So I guess, that the main problem is that blocking occurs
"outside" the python world and "inside" the libshout world. Maybe the
combination of all this with Twisted is an unlucky marriage but I
would be disappointed to be told: "Nope, won't be possible"

Maybe Twisted's deferreds to the rescue? I don't know... I'm still
quite green with Twisted ;)

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


Re: Cross platform way of finding number of processors on a machine?

2007-10-05 Thread Kay Schluehr
On 5 Okt., 09:58, Tim Golden <[EMAIL PROTECTED]> wrote:
> Nicholas Bastin wrote:
> > On 10/4/07, John <[EMAIL PROTECTED]> wrote:
> >> Is there a way to find the number of processors on a machine (on linux/
> >> windows/macos/cygwin) using python code (using the same code/cross
> >> platform code)?
>
> > There's no single call that will give you the same info on every
> > platform, but you can obviously write this yourself and switch based
> > on os.uname()[0] in most cases.
>
> Second that point about not getting one cross-platform
> answer. Under Windows, WMI is often the way to go for
> these things:
>
>http://msdn2.microsoft.com/en-us/library/aa394373.aspx
>
> but, as Nicholas noted:
>
>"""
>Windows Server 2003, Windows XP, and Windows 2000:
>  This property is not available.
>"""
>
> since it's presumably not available in anything earlier either,
> that leaves you with Vista or the early-adopter editions of the
> next Windows Server product.
>
> TJG

Remarkable. I've a two years old Windows XP dual core notebook and
when I'm asking Python I get the correct answer:

>>> import os
>>> os.environ['NUMBER_OF_PROCESSORS']
2

However this feature might not be guaranteed by Microsoft for
arbitrary computers using their OS?

Kay

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


Re: Adding behaviour for managing "task" dependencies

2007-10-05 Thread David
>
> Any thoughts would be most appreciated, though I would like to stress
> that I don't think Python should support the syntax I'm proposing I'd
> just like to know if I can extend a copy of it to do that.
>

You can use syntax like this:

class MyJob1(Job):
depends(MyJob2)
depends(MyJob3)

Or with quotes (if MyJob2 and MyJob3 could be declared later):

class MyJob1(Job):
depends('MyJob2')
depends('MyJob3')

(where 'depends' is a DSL-like construct. See Elixir
(elixir.ematia.de) for an example of how to implement DSL statements
like "depends". Check their implementation of the "belongs_to"
statement.

You could also extend your "depends" dsl statement to allow more than
one dep at a time, eg:

class MyJob1(Job):
depends('MyJob2', 'MyJob3')

Whatever approach you use, you should also look into implementing
"topological sort" logic. This lets you resolve programatically which
order the inter-dependent tasks should be handled in to satisfy their
dependencies.

You may find this module interesting in this regard:

http://pypi.python.org/pypi/topsort

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


Where's the Starship's crew?

2007-10-05 Thread Dick Moores


I didn't check on all of them, but the only one I found was Mark 
Hammond .

Dick Moores

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


Re: Cross platform way of finding number of processors on a machine?

2007-10-05 Thread Tim Golden
[Tim Golden]
>>"""
>>Windows Server 2003, Windows XP, and Windows 2000:
>>  This property is not available.
>>"""
>>
>> since it's presumably not available in anything earlier either,
>> that leaves you with Vista or the early-adopter editions of the
>> next Windows Server product.

Kay Schluehr wrote:

> Remarkable. I've a two years old Windows XP dual core notebook and
> when I'm asking Python I get the correct answer:
> 
 import os
 os.environ['NUMBER_OF_PROCESSORS']
> 2
> 
> However this feature might not be guaranteed by Microsoft for
> arbitrary computers using their OS?

Ahem. I was referring (and not very clearly, now I look
back at my post) to a particular property within the
WMI class, not to the general concept of counting
processors.

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


Re: open(.xls file, 'w') so that hyperlinks appear

2007-10-05 Thread Michael Bentley




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

Re: tkinter question

2007-10-05 Thread Eric Brunel
On Fri, 05 Oct 2007 05:16:14 +0200, goldtech <[EMAIL PROTECTED]>  
wrote:

> This works OK. But I notice that if I enlarge the window after the
> script has run, the white listbox only gets "so" big while the grey
> background enlarges.
>
> Is there a way to have it all white when I enlarge a window - like
> what normally happens?
>
>
>
> from Tkinter import *
> root = Tk()
> root.title("Dirty Words")
> scrollbar = Scrollbar(root)
> scrollbar.pack(side=RIGHT, fill=Y)
> listbox = Listbox(root, bg='white', font = "Courier 16", width=60)
> listbox.pack()

=> listbox.pack(fill=BOTH, expand=1)

> i='123456789abcdefghijklmnopqrstuvwxyz'
> for x in range(10):
> listbox.insert(END, i)
> listbox.config(yscrollcommand=scrollbar.set)
> scrollbar.config(command=listbox.yview)
> mainloop()

BTW, even for something that simple, using the grid geometry manager may  
be easier... It is at least easier to explain: don't ask me what the  
expand=1 option means, I never understood it... I just add or remove it  
when the pack doesn't do what I want. The sticky option with grid is  
easier to handle.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Real time plot

2007-10-05 Thread Jean-Francois Canac

"Lawson Hanson" <[EMAIL PROTECTED]> a écrit dans le message de 
news: [EMAIL PROTECTED]
> Nicholas Bastin wrote:
>> On 10/4/07, Jean-Francois Canac <[EMAIL PROTECTED]> wrote:
>>> [EMAIL PROTECTED]
 I would draw dots on a suitably sized Tkinter canvas, after drawing a
 schematic
 of the race track (laborious).

 20 per second will be no problem, provided the machine is half decent.

 What is the speed at which the com port runs?

 - Hendrik

>>> The com port run at 19.2 kb/s.
>>> My pb is more the real time aspect: to see the plot changing in real 
>>> time
>>> than the com aspect as the installation is already running with programs 
>>> in
>>> c++.
>>> The PC on which it is running is good enought
>>> For me the interest is to migrate all taht on python to be able to make 
>>> fast
>>> changes when it is of interest
>>
>> The success of this will have more to do with design than programming
>> language.  Any GUI toolkit which allows partial screen updates can be
>> made to update at least as fast as your screen refresh rate, even in
>> python.
>>
>> --
>> Nick
>
> If you are using Tkinter (probably a very good choice), just remember
> to make periodic (i.e., once per I/O processing loop) calls to:
>
> Tkinter.update_idletasks()
>
> which will update the display window, etc.
>
> Regards,
>
> Lawson
>
Finally I tried this coding and it works
#==
import time
import pylab

pylab.ion()

lat,long,vit = pylab.load(r"c:\pytst\test1.txt",usecols=(1,2,3), 
unpack=True)
lat_min=pylab.amin(lat)
lat_max=pylab.amax(lat)
long_min=pylab.amin(long)
long_max=pylab.amax(long)

print "start"


timefig = pylab.figure(1)
timesub = pylab.subplot(111)
x=[]
y=[]


lines = pylab.plot(x,y)
print lat_min,lat_max,long_min,long_max

for i in range(len(lat)):
 x.append(long[i])
 y.append(lat[i])
 lines[0].set_data(x,y)
 timesub.set_xlim(long_min,long_max)
 timesub.set_ylim(lat_min,lat_max)
 pylab.draw()

#
The kind of data I have in the text file are just below
Now I have two problems, I think my coding is not very clean as when I try 
yo close or manipulate the windows it generates an error
secondly I think it is a bit slow. I would much prefer something quicker and 
to be able to adapt the speed dynamically with a sleep instruction or 
something as that

09:25:08.50 46.863930 3.161866 56.9 Km/h
09:45:07.75 46.863907 3.161786 11.5 Km/h
09:45:08.0 46.863914 3.161794 12.4 Km/h
09:45:08.25 46.863918 3.161804 13.4 Km/h
09:45:08.50 46.863922 3.161814 14.5 Km/h
09:45:08.75 46.863930 3.161825 15.4 Km/h
09:45:09.0 46.863934 3.161837 16.1 Km/h
09:45:09.25 46.863941 3.161848 16.6 Km/h
09:45:09.50 46.863945 3.161861 17.1 Km/h
09:45:09.75 46.863953 3.161874 17.3 Km/h


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

where can I get a space supporting cgi written in python

2007-10-05 Thread [EMAIL PROTECTED]
I'm studying python and very interested in cgi written in python, but
i can't find a free host suporting it.who can tell where can i sign up
for a free python host?
I just wanna have a try, the space dont have to be very large, 20M or
50M is OK
thanks!

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


Re: Where's the Starship's crew?

2007-10-05 Thread exhuma.twn
On Oct 5, 10:31 am, Dick Moores <[EMAIL PROTECTED]> wrote:
> 
>
> I didn't check on all of them, but the only one I found was Mark
> Hammond .
>
> Dick Moores

Doing 6 random clicks, revealed:

http://starship.python.net/crew/hooft/

all the others are dead links. I realised this fact as well some time
ago already. I thought the page itself was still "in development" and
did not find a single one page. These two obviously eluded me ;)

Strange to see that the situation did not yet improve. But then again,
we all probably know how much of a hassle it is to keep 10 different
web-pages with personal info's up-to-date. I suppose that the starship
crew all have som homes elsewhere and don't find the time to update
yet another page. I myself don't even bother anymore at all. I have
about 2 hours of free time per day (given that I like to sleep a
lot!). What makes things worse, the network at work is completely cut
off from the rest of the world for security reasons. I am happy that I
at least can access usenet by using google-groups *sigh*.

An interesting task might be to find the homes of the starship crew,
and post them here? Maybe? If lucky, the right person picks this up
and updates the crew-quarter labels of the starship. Or would
"Turbolift Buttons" be a better analogy for hyperlinks? Args.
Supposing, that these turbolifts *do* have buttons. How retro! ;)

I'm babbling again... sorry for this long winded post.

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


Strange generator problem

2007-10-05 Thread Joost Cassee
Hello all,


I bumped into an unexpected problem using generators. Consider this code:

def test(s):
return _test([], [], s)
def _test(s1, s2, s):
if s:
s1.append(s.pop())
for x in _test(s1, s2, s):
yield x
s2.append(s1.pop())
for x in _test(s1, s2, s):
yield x
s.append(s2.pop())
else:
yield s1, s2

The test function is supposed be a generator returning all combinations
of dividing the elements of the input list into two distinct lists
(order of elements unimportant). (This post is not about the quality of
the solution. :-) )

Consider now the result of using the generator in a for-loop and in the
list function (same result for list comprehension):

>>> for x in test(range(3)):
...  print x
...
([2, 1, 0], [])
([2, 1], [0])
([2, 0], [1])
([2], [1, 0])
([1, 0], [2])
([1], [2, 0])
([0], [2, 1])
([], [2, 1, 0])
>>>
>>> list(test(range(3)))
[([], []), ([], []), ([], []), ([], []), ([], []), ([], []), ([], []),
([], [])]

The following (simpler) generator works as expected:

>>> def test2(s):
... for x in s:
... yield x
...
>>> list(test2(range(3)))
[0, 1, 2]

Can anyone explain the difference? The python version is 2.5.1.


Regards,

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


Re: unit testing

2007-10-05 Thread Craig Howard

On Oct 4, 2007, at 3:02 PM, brad wrote:

> Does anyone else feel that unittesting is too much work? Not in  
> general,
> just the official unittest module for small to medium sized projects?
>
> It seems easier to write some quick methods that are used when needed
> rather than building a program with integrated unittesting. I see the
> value of it (the official unittest that is)... especially when  
> there's a
> lot of source code. But this...
>
> if len(x) != y:
> sys.exit('...')
>
> is a hell of a lot easier and quicker that subclassing  
> unittest.TestCase
> on small projects :)
>
> Do others do their own "informal" unit testing?
>
> Just curious,
>
> Brad
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Brad:

If the program is more than 100 lines or is a critical system, I  
write a unit test. I hate asking myself, "Did I break something?"  
every time I decide to refactor a small section of code. For  
instance, I wrote an alarm system in Python for a water treatment  
plant. If the chlorine, pH, or turbidity are out of spec, an email  
message is sent to the plant operator's pager. Because of the nature  
of the alarm system, extensive field testing was out of the question.  
Unit testing was the only way to ensure it worked without disrupting  
the plant operation.

Craig

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


Re: Strange generator problem

2007-10-05 Thread Paul Hankin
On Oct 5, 10:23 am, Joost Cassee <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I bumped into an unexpected problem using generators. Consider this code:
>
> def test(s):
> return _test([], [], s)
> def _test(s1, s2, s):
> if s:
> s1.append(s.pop())
> for x in _test(s1, s2, s):
> yield x
> s2.append(s1.pop())
> for x in _test(s1, s2, s):
> yield x
> s.append(s2.pop())
> else:
> yield s1, s2

Lists aren't copied when they're yielded, so you're returning the same
lists (with different elements) each time. Your final list looks like
[(s1, s2), (s1, s2), ...] and as it happens, s1 and s2 are both [] by
the end.

You can fix it by copying the lists manually before yielding them, or
using a better sub-list algorithm :)

--
Paul Hankin

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


Re: Duplicate content filter..

2007-10-05 Thread Michael
Markov chains maybe? You could probably create a pretty fast db of sorts for
checking on word to page relationships and word to word relationships. Or
else a normal db could probably do it pretty fast. Break the page into words
and remove common words (*prepositions, etc)* and keep a database of
word:page pairs. Simply go through the words on the new page and check for
other pages with the same words. If any other page scores to high then there
you go. I'd probably go with the simple chains as it's a lot lighter
solution and could probably be made to be pretty quick.

On 10/3/07, Abandoned <[EMAIL PROTECTED]> wrote:
>
> Hi..
> I'm working a search engine project now. And i have a problem. My
> problem is Duplicate Contents..
> I can find the percentage of similarity between two pages but i have a
> 5 millions index and i search 5 million page contents  to find one
> duplicate :(
>
> I want to a idea for how can i find duplicate pages quickly and fast ?
>
> Please help me, i'm sorry my bad english.
> King regards..
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Command-line does work when scheduled

2007-10-05 Thread Martin P. Hellwig
Jim wrote:
> On Sep 30, 6:16 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>> On Sun, 30 Sep 2007 07:42:56 -0700, Jim <[EMAIL PROTECTED]>
>> declaimed the following in comp.lang.python:
>>
>>> What else could be wrong?
>>> Thanks,
>> Possibly those associations are only defined for your login account,
>> and not active for the "account" that the task scheduler is running
>> under?
>> --
>> WulfraedDennis Lee Bieber   KD6MOG
>> [EMAIL PROTECTED] [EMAIL PROTECTED]
>> HTTP://wlfraed.home.netcom.com/
>> (Bestiaria Support Staff:   [EMAIL PROTECTED])
>> HTTP://www.bestiaria.com/
> 
> As far as know, since I'm the major user of my PC it runs under my
> account (computer administrator).   It even asked for the password for
> my account when I added this scheduled task.
> Any further ideas?
> Thanks,
> Jim
> 

It could be the scheduler might execute the job as the local system 
account (which isn't that by default and I doubt that this is the 
problem). If your configuration are not globally they won't be picked up 
by that account. Meaning you should set the environment variables not on 
user level but system level.

However I have observed some weird issues with scheduler too in the 
past, especially when the job is executed while the job owner is not 
logged on, apparently the full users profile is not available then.
But that behavior seems to differ on the various windows incarnations 
and the color of the moon.

I solved my problem by running the scheduling program not in scheduler 
but in cron, but I doubt that is applicable for you :-)

This post doesn't really help much but perhaps it gives some insights on 
the problem.

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


Re: WebBased Vector 2D Graphics

2007-10-05 Thread Bjoern Schliessmann
 [EMAIL PROTECTED] wrote:

> Is there any way this web programming can be done in python. 

Sure. Minimalistic approaches include using CGI
(http://docs.python.org/lib/module-cgi.html)
or using Apache with mod_python directly. There are also web
frameworks for Python, but I don't know much about them.

> As mentioned previously, I have never done any web based
> development so don't really know what I'm talking about when
> trying to understand how I can go from this Python program output
> to producing some graphical output on a web page.

The above approaches allow you to directly print to the web page.
I'm not sure how you could display constant progress there. Perhaps
much simpler with mod_python than with CGI. 
 
Regards,


Björn

-- 
BOFH excuse #369:

Virus transmitted from computer to sysadmins.

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


Re: Cross platform way of finding number of processors on a machine?

2007-10-05 Thread Nick Craig-Wood
Nicholas Bastin <[EMAIL PROTECTED]> wrote:
>  On 10/4/07, John <[EMAIL PROTECTED]> wrote:
> >
> > Is there a way to find the number of processors on a machine (on linux/
> > windows/macos/cygwin) using python code (using the same code/cross
> > platform code)?
> 
>  There's no single call that will give you the same info on every
>  platform, but you can obviously write this yourself and switch based
>  on os.uname()[0] in most cases.
> 
>  For Darwin, you can just use the subprocess module to call 'sysctl
>  hw.logicalcpu'.  I'm not sure if there's a more direct way in python
>  to use sysctl.  (hw.logicalcpu_max is what the hardware maximally
>  supports, but someone may have started their machine with OF blocking
>  some of the processors and you should probably respect that decision)
> 
>  For Linux you can read /proc/cpuinfo and parse that information.  Be
>  somewhat careful with this, however, if your processors support HT,
>  they will show as 2, and that may or may not be what you want.  You
>  can deterministically parse this information out if you know which
>  processor families are truly multi-core, and which are HT.

On any unix/posix system (OSX and linux should both qualify) you can use

  >>> import os
  >>> os.sysconf('SC_NPROCESSORS_ONLN')
  2
  >>>

(From my Core 2 Duo laptop running linux)

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit testing

2007-10-05 Thread Kay Schluehr
On Oct 4, 9:39 pm, Paul Rubin  wrote:

> Yeah, unittest is sort of a Java-ism.

However legend tells the story of Kent Beck and Erich Gamma sitting
together in a plane to ( or from ) New York and porting a unittest
framework from SmallTalk to Java. This extreme programming session was
the origin of JUnit.

It doesn't mean of course that XUnit is not a Javaism - it's just one
I like.

Kay

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


Re: unit testing

2007-10-05 Thread Kay Schluehr
On Oct 3, 2:37 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Paul Rubin a écrit :
>
> > brad <[EMAIL PROTECTED]> writes:
>
> >>Does anyone else feel that unittesting is too much work? Not in
> >>general, just the official unittest module for small to medium sized
> >>projects?
>
> > Yeah, unittest is sort of a Java-ism.  You might try the newer doctest
> > module instead.
>
> Or py.test or nose, which are both more complete than doctest and more
> pythonics than the unittest module.

But you need to distribute testframeworks, when you just want to
distribute tests.

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

Re: migrating to packages

2007-10-05 Thread Bruno Desthuilliers
Gerardo Herzig a écrit :
> Carl Bank a écrit :
>>
>> Add these lines in __init__.py:
>>
>> from MYCLASSES.A import A
>> from MYCLASSES.B import B
>>  
>>
> Ummm, that works indeed, but forces me to import all (more than A and B) 
> classes, rigth?

Why so ?

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


Re: WebBased Vector 2D Graphics

2007-10-05 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

> Hi there
> 
> I currently have a Python program outputing to the command line,
> durations of 'completed Steps' and 'data items' in relation to time
> i.e.
> 
> 
> --jfh
>   -kl//kl started after jfh finished
> % Ds  //new data arrived at this point in time
> ---pl (1)  //Details error with finsihed Step
>*kl  // This step is now outputed but
> due to error with pl is cancelled (no duration)
> 
> I am new to doing any web based development and don't have a clue
> where to start! I just wondered what is the best way to output this
> program to a web page graphically.
> 
> I want to be able to represent these durations "-" as rectangles
> and as the program runs the page will refresh every 10 seconds, thus
> the boxes will expand with time until they have finished. New data
> will also be represented in boxes with a different colour. I believe
> some kind of script will have to be run which constantly updates the
> html page after x seconds which then causes the web page to refresh
> with the updated data.
> 
> Is there any way this web programming can be done in python. Or
> perhaps I can use soemthing such as ajax?
> 
> As mentioned previously, I have never done any web based development
> so don't really know what I'm talking about when trying to understand
> how I can go from this Python program output to producing some
> graphical output on a web page.

You certainly need to get on speed with webdevelopment. Otherwise you will
fail miserably.

There are several options here:

 - rendering a server-side image, deliver that embedded in a html-page

 - render using html tags like DIV and the like, which allow for positioned
colored rectangles and text, in pixel coordinates

 - canvas tag, to render 2D-drawing-commands

 - embedded SVG

All that can be enriched with AJAX to have that fancy
realtime-update-thingy.

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


Re: Boolean parser..

2007-10-05 Thread Abandoned
On 4 Ekim, 22:29, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> I try a boolean parser in python since 1 weak.. But i can't do this
> because this is very complicated :(
> Do you know any blooean parser script in python or how do i write a
> boolean parser ?
> example query: ((google or yahoo) or (live msn)) not web
> I'm sorry my bad english.
> King Regards..

This is a example written in perl "
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=350&lngWId=6";
but i don't find any python example

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


Re: novice list

2007-10-05 Thread Dustan
On Oct 5, 6:01 am, István <[EMAIL PROTECTED]> wrote:
> Could somebody suggest me a novice Python list, please?
> Thanks, Istvan

You're there.

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

Re: Where's the Starship's crew?

2007-10-05 Thread Thomas Heller
Dick Moores schrieb:
> 
> 
> I didn't check on all of them, but the only one I found was Mark 
> Hammond .
> 
> Dick Moores
> 

There are more.  Think of it as a game you have to solve.

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


Re: Python "implements " equivalent?

2007-10-05 Thread Sion Arrowsmith
Grant Edwards  <[EMAIL PROTECTED]> wrote:
>   try:
>   myobj.feature1()
>   except AttributeError:
>   print "object doesn't implement feature1"
>
>isn't correct, since an unhandled AttributeError generated by
>the feature1 method will print "object doesn't implement
>feature1".

I'd be tempted to argue that it *was* correct, since the object
doesn't implement a feature1 which can be used. (This is the cue
for someone to talk about making sure that myobj's class has
been thoroughly unit tested.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: tkinter question

2007-10-05 Thread Michal Bozon
On Thu, 04 Oct 2007 20:16:14 -0700, goldtech wrote:

> This works OK. But I notice that if I enlarge the window after the
> script has run, the white listbox only gets "so" big while the grey
> background enlarges.
> 
> Is there a way to have it all white when I enlarge a window - like
> what normally happens?
> 
> 
> 
> from Tkinter import *
> root = Tk()
> root.title("Dirty Words")
> scrollbar = Scrollbar(root)
> scrollbar.pack(side=RIGHT, fill=Y)
> listbox = Listbox(root, bg='white', font = "Courier 16", width=60)
> listbox.pack()
> i='123456789abcdefghijklmnopqrstuvwxyz'
> for x in range(10):
> listbox.insert(END, i)
> listbox.config(yscrollcommand=scrollbar.set)
> scrollbar.config(command=listbox.yview)
> mainloop()

try to change listbox.pack() to listbox.pack(expand=True, fill=BOTH)
.. is it that you want ?

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


Re: module confusion

2007-10-05 Thread Steven D'Aprano
On Fri, 05 Oct 2007 00:12:33 -0500, Robert Kern wrote:

> This is somewhat odd, because most modules aren't exposed that way. They
> are either in their own file and accessed by importing them directly, or
> they are inside a package.

Any time you say:

import parrot


in one of your modules, you export parrot to anything that imports your 
module. (Unless you take specific steps to prevent it, for instance with 
del parrot.)


Just to pick some random examples:

>>> import ConfigParser, base64, fileinput
>>> ConfigParser.re

>>> base64.struct

>>> base64.binascii

>>> fileinput.sys

>>> fileinput.os



It's quite common.


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


Re: tkinter question

2007-10-05 Thread Kevin Walzer
Eric Brunel wrote:

> 
> BTW, even for something that simple, using the grid geometry manager may 
> be easier... It is at least easier to explain: don't ask me what the 
> expand=1 option means, I never understood it... I just add or remove it 
> when the pack doesn't do what I want. The sticky option with grid is 
> easier to handle.
> 

"expand = 1" ==  "expand=TRUE"--that means the widget resizes itself 
when the window is re-sized.


-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and SSL

2007-10-05 Thread [EMAIL PROTECTED]
On Oct 5, 2:50 am, John Nagle <[EMAIL PROTECTED]> wrote:
> Johny wrote:
> > Martin and John,
> > Thank you both for your replies
> >  Must I  have OpenSSL imported in my Python program?
> > So far I have been using only SSL  support.
> > Built-in SSL support works OK if I connect from my Python program
> > directly to SSL server ( but not via proxy).
> > L.
>
>  SSL isn't SUPPOSED to work through proxies.  That's the whole point of
> SSL - to prevent somebody in the middle from tapping into the connection.
> Look up "man in the middle attack".

I'm afraid this is complete rubbish - using a proxy with SSL is fine.
The only
issue is that the built in python SSL support doesn't work with
proxies. There
are a number of ways of adding support though eg.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456195
One thing to note is that python's built in SSL support does not
validate the
server certicate and is therefore vulnerable to MITM attacks
irrespective
of whether a proxy is in use or not. If you want real security then
you need
to use something like PyOpenSSL or M2Crypto and a certificate store
with your
root CAs.

Rich.

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


Re: novice list

2007-10-05 Thread Steve Holden
István wrote:
> Could somebody suggest me a novice Python list, please?
> Thanks, Istvan
> 
[EMAIL PROTECTED] is known to be noob-friendly. See

   http://mail.python.org/mailman/listinfo/tutor

for more details.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: Boolean parser..

2007-10-05 Thread Abandoned
http://pyparsing.wikispaces.com/space/showimage/searchparser.py this
is searchparser but i can't understant to use this.
Can anybody explain this how to use ?

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


Re: Python "implements " equivalent?

2007-10-05 Thread David
> I'm a seasoned Java programmer and quite a big fan of interfaces...
> i.e. The idea that if I make a number of distinct classes that
> implement interface X, I can pass them all as parameters to functions
> or whatnot that require an X object.
>
> Is there something similar in Python?
>

Python will probably be getting Abstract Base Classes at some point.

http://www.python.org/dev/peps/pep-3119/

For ABC in current versions of Python, see the "Can you implement
abstract classes in Python in 0 lines of code? Or 4?" question on this
page: http://norvig.com/python-iaq.html

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


WebBased Vector 2D Graphics

2007-10-05 Thread cjt22
Hi there

I currently have a Python program outputing to the command line,
durations of 'completed Steps' and 'data items' in relation to time
i.e.


--jfh
  -kl//kl started after jfh finished
% Ds  //new data arrived at this point in time
---pl (1)  //Details error with finsihed Step
   *kl  // This step is now outputed but
due to error with pl is cancelled (no duration)

I am new to doing any web based development and don't have a clue
where to start! I just wondered what is the best way to output this
program to a web page graphically.

I want to be able to represent these durations "-" as rectangles
and as the program runs the page will refresh every 10 seconds, thus
the boxes will expand with time until they have finished. New data
will also be represented in boxes with a different colour. I believe
some kind of script will have to be run which constantly updates the
html page after x seconds which then causes the web page to refresh
with the updated data.

Is there any way this web programming can be done in python. Or
perhaps I can use soemthing such as ajax?

As mentioned previously, I have never done any web based development
so don't really know what I'm talking about when trying to understand
how I can go from this Python program output to producing some
graphical output on a web page.

Any help would be much appreciated
Chris

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


Re: Strange generator problem

2007-10-05 Thread Joost Cassee
On 05/10/2007 11:34, Paul Hankin wrote:

> Lists aren't copied when they're yielded,

Duh! Thanks for your sharp eye.

-- 
Joost Cassee
http://joost.cassee.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter question

2007-10-05 Thread Eric Brunel
On Fri, 05 Oct 2007 14:10:57 +0200, Kevin Walzer <[EMAIL PROTECTED]>  
wrote:
> "expand = 1" ==  "expand=TRUE"--that means the widget resizes itself  
> when the window is re-sized.

That's the theory... But what does fill=BOTH means then? And why does  
expand=1 (or TRUE, or True) is only needed in some cases and not others?  
And I'm quite sure that sometimes, I use expand=1 and it does exactly what  
I don't want, and removing it gives the behaviour I want. I've been doing  
tk/Tkinter stuff for quite a few years now, and I still haven't understood  
exactly when I should use this option... Quite counter-intuitive, IMHO.

But then, since I almost never use pack for this kind of layout, I guess  
it's not really important...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where can I get a space supporting cgi written in python

2007-10-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> I'm studying python and very interested in cgi written in python, but
> i can't find a free host suporting it.who can tell where can i sign up
> for a free python host?
> I just wanna have a try, the space dont have to be very large, 20M or
> 50M is OK

FWIW, you don't *need* a web hosting for *trying* Python CGI - just
install Apache (or any other web server supporting CGI) on your machine.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: WebBased Vector 2D Graphics

2007-10-05 Thread cjt22
On Oct 5, 11:43 am, Bjoern Schliessmann  wrote:
>  [EMAIL PROTECTED] wrote:
> > Is there any way this web programming can be done in python.
>
> Sure. Minimalistic approaches include using CGI
> (http://docs.python.org/lib/module-cgi.html)
> or using Apache with mod_python directly. There are also web
> frameworks for Python, but I don't know much about them.
>
> > As mentioned previously, I have never done any web based
> > development so don't really know what I'm talking about when
> > trying to understand how I can go from this Python program output
> > to producing some graphical output on a web page.
>
> The above approaches allow you to directly print to the web page.
> I'm not sure how you could display constant progress there. Perhaps
> much simpler with mod_python than with CGI.
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #369:
>
> Virus transmitted from computer to sysadmins.

Thanks Bjorn

> The above approaches allow you to directly print to the web page.

Would this mean I wouldn't be able to have any fancy graphics outputed
such as the rectangles I mentioned before with different filled in
colours?

Cheers
Chris

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

Re: unit testing

2007-10-05 Thread Kay Schluehr
On 4 Okt., 22:49, Jeffrey Froman <[EMAIL PROTECTED]> wrote:
> Chris Mellon wrote:
> > Doctest is commonly given as the alternative to people who feel this
> > way. Personally, I find that anything worth testing is worth having a
> > test directory and independent unit tests for.
>
> I like keeping my tests separate as well, and doctest does allow this, using
> doctest.testfile(). That is, despite the name, doctests do not necessarily
> need to appear in docstrings :-)
>
> Jeffrey

And they are definitely no unit tests. Instread they are diffs on
lexical content of an executed session protocol of arbitrary size
( which might be customized using a mini language ). So they are
sensitive to all kinds of ambient changes being irrelevant for the
*functional unit* to be tested.

I wish all people good luck porting their doctests to Python 3.0.

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


Re: module confusion

2007-10-05 Thread Steven D'Aprano
On Fri, 05 Oct 2007 19:51:05 +1300, Lawrence D'Oliveiro wrote:

> There is no sense in which any Python object can "contain" any other.

>>> L = [1, 2, 3]
>>> 2 in L
True
>>> L.__contains__(3)
True



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


novice list

2007-10-05 Thread István
Could somebody suggest me a novice Python list, please?
Thanks, Istvan

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


Re: module confusion

2007-10-05 Thread Steve Holden
Steven D'Aprano wrote:
> On Fri, 05 Oct 2007 00:12:33 -0500, Robert Kern wrote:
> 
>> This is somewhat odd, because most modules aren't exposed that way. They
>> are either in their own file and accessed by importing them directly, or
>> they are inside a package.
> 
> Any time you say:
> 
> import parrot
> 
> 
> in one of your modules, you export parrot to anything that 

subsequently

>  imports your 
> module. (Unless you take specific steps to prevent it, for instance with 
> del parrot.)

or the creation of an __all__ containing an exclusive list of names for 
export.
> 
> 
> Just to pick some random examples:
> 
 import ConfigParser, base64, fileinput
 ConfigParser.re
> 
 base64.struct
> 
 base64.binascii
> 
 fileinput.sys
> 
 fileinput.os
> 
> 
> 
> It's quite common.
> 
> 
OK, I am sort of getting used to the idea that you guys are going to 
beat this one to death with a stick, and will still be tossing emails 
back and forth to each other while the rest of us are admiring the heat 
death of the universe.

So please try and avoid writing anything that will be misconstrued by 
newless cloobs unfortunate enough to reach this thread as a result of a 
search for meaningful information on Python imports.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: tkinter question

2007-10-05 Thread goldtech

>
> try to change listbox.pack() to listbox.pack(expand=True, fill=BOTH)
> .. is it that you want ?

Yes.

>
>  -mykhal

Worked with TRUE all uppercase.

Exactly what I needed. Thank you.

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


Re: WebBased Vector 2D Graphics

2007-10-05 Thread Robin Becker
Diez B. Roggisch wrote:
>  [EMAIL PROTECTED] wrote:
> 
...
> 
> You certainly need to get on speed with webdevelopment. Otherwise you will
> fail miserably.
> 
> There are several options here:
> 
>  - rendering a server-side image, deliver that embedded in a html-page
> 
>  - render using html tags like DIV and the like, which allow for positioned
> colored rectangles and text, in pixel coordinates
> 
>  - canvas tag, to render 2D-drawing-commands
> 
>  - embedded SVG
> 
> All that can be enriched with AJAX to have that fancy
> realtime-update-thingy.
> 
> Diez

simple rectangles are pretty easy though. I did a progress bar here
http://www.jessikat.plus.com/pbar.html with a bit of javascript.

The other side of the information usually involves ajax call backs to determine 
how much of the job has been done etc etc. I seem to remember doing that for a 
project a while back. As I recall we had a cgi script that did

action "start" start off a long running job that detached itself from the web 
server so the response could be made short

action "query" find out from an output file how much of the job has been done.

A javascript timeout periodically performed the query request and used the 
response to update the ticker.
-- 
Robin Becker

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


Python Magazine: Issue 1 Free!

2007-10-05 Thread Steve Holden
I've just been told by the editors at Python Magazine that the first 
issue is out. It's all-electronic so anyone can download and read it. 
Let them know what you think:

   http://www.pythonmagazine.com/c/issue/2007/10

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: module confusion

2007-10-05 Thread Neil Cerutti
On 2007-10-05, Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:
> In message <[EMAIL PROTECTED]>, Neil Cerutti wrote:
>
>> On 2007-10-03, Lawrence D'Oliveiro <[EMAIL PROTECTED]>
>> wrote:
>>> In Python, all names _are_ variables. They are not "bound" to
>>> objects. The value of os.path is a pointer. It's implemented
>>> as a pointer, it has all the semantics of a pointer.
>> 
>> No. A pointer is also an iterator.
>> 
>> void duplicate(char *d, const char *s)
>> {
>>   while (*d++ = *s++)
>> ;
>> }
>
> So if you can't do pointer arithmetic, then it's not a pointer?
> Trying this:
>
> void duplicate(void *d, const void *s)
> {
>   while (*d++ = *s++)
> ;
> }
>
> I get:
>
> test.c: In function 'duplicate':
> test.c:3: warning: dereferencing 'void *' pointer
> test.c:3: warning: dereferencing 'void *' pointer
> test.c:3: error: invalid use of void expression
>
> So you can't do arithmetic or iterate with a void * pointer.

...or dereference.

> Does that mean it's not really a pointer?

That's an interesting taxonimical conundrum. If a pointer were
defined by it's semantics, then yes, a void pointer wouldn't be a
pointer. But pointers are defined not by behavior, but by an
ANSI/ISO standard. The term "pointer to void" makes sense if you
think of it as a pointer in an altered, intermediate state.

I suppose you might score a Pyrrhic victory by claiming that
Python identifiers are pointers that don't behave like pointers.
But you claimed the opposite.

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


Re: Boolean parser..

2007-10-05 Thread David
On 10/4/07, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> I try a boolean parser in python since 1 weak.. But i can't do this
> because this is very complicated :(
> Do you know any blooean parser script in python or how do i write a
> boolean parser ?
> example query: ((google or yahoo) or (live msn)) not web
> I'm sorry my bad english.
> King Regards..
>
> --

http://mail.python.org/pipermail/python-list/2006-August/399804.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Adrian Cherry
Steve Holden <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> I've just been told by the editors at Python Magazine that
> the first issue is out. It's all-electronic so anyone can
> download and read it. Let them know what you think:
> 
>http://www.pythonmagazine.com/c/issue/2007/10
> 
> regards
>   Steve

Thanks for that, initial impression looks good, I peruse it later 
when the boss isn't watching. Unfortunately there seems to be a 
few horror pictures crept in on page 4!.

One initial comment is the end of the magazine. It just seems to 
stop abruptly. No back page commentry, cartoon or teaser for the 
next issue.

Regards

Adrian




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


Re: migrating to packages

2007-10-05 Thread Gerardo Herzig
Bruno Desthuilliers wrote:

>Gerardo Herzig a écrit :
>  
>
>>Carl Bank a écrit :
>>
>>
>>>Add these lines in __init__.py:
>>>
>>>from MYCLASSES.A import A
>>>from MYCLASSES.B import B
>>> 
>>>
>>>  
>>>
>>Ummm, that works indeed, but forces me to import all (more than A and B) 
>>classes, rigth?
>>
>>
>
>Why so ?
>
>  
>
If the original MYCLASSES.py has 5 different classes ,say A,B,C,D,E , 
each one has to be imported (as A and B) in order to be used for the 
client code. The thing is, there are more than 5 classes, and looks like 
a lot of unnecesary work to me, since a particular program can use 1,2, 
or 3 classes at the timeThats why im watching the way to override 
the `import statement'...

Damn client code!!!

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


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Paul McGuire
On Oct 5, 7:52 am, "Adrian Cherry" <[EMAIL PROTECTED]> wrote:
> Steve Holden <[EMAIL PROTECTED]> wrote innews:[EMAIL PROTECTED]:
>
> > I've just been told by the editors at Python Magazine that
> > the first issue is out. It's all-electronic so anyone can
> > download and read it. Let them know what you think:
>
> >http://www.pythonmagazine.com/c/issue/2007/10
>
> > regards
> >   Steve
>
> Thanks for that, initial impression looks good, I peruse it later
> when the boss isn't watching. Unfortunately there seems to be a
> few horror pictures crept in on page 4!.
>
> One initial comment is the end of the magazine. It just seems to
> stop abruptly. No back page commentry, cartoon or teaser for the
> next issue.
>
> Regards
>
> Adrian

I thought Steve Holden's Random Hits column was the "back page
commentry".  Maybe this column needs to start on the last page, and
continue on the previous one, so that it qualifies as truly "back
page".

Nice launch, good luck PyMag!

-- Paul

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


Re: Where's the Starship's crew?

2007-10-05 Thread Dick Moores
At 04:54 AM 10/5/2007, Thomas Heller wrote:
>Dick Moores schrieb:
> > 
> >
> > I didn't check on all of them, but the only one I found was Mark
> > Hammond .
> >
> > Dick Moores
> >
>
>There are more. Think of it as a game you have to solve.

Yeah, a mind numbing game!

http://starship.python.net/crew/ewalstad/ Eric Walstad
http://starship.python.net/crew/piers/ Piers Lauder
http://starship.python.net/crew/jae/ --> http://zhar.net/  John Eikenberry
http://starship.python.net/crew/mwh/
http://starship.python.net/crew/manus/ Manus Hand
http://starship.python.net/crew/bhoel/ Berthold Höllmann
http://starship.python.net/crew/marduk/ ("Server Error")
http://starship.python.net/crew/schorsch/
http://starship.python.net/crew/dni/ David Niergarth
http://starship.python.net/crew/jcooley/ James Cooley
http://starship.python.net/crew/sdrees/ Stefan Drees
http://starship.python.net/crew/jwt/ Jim Tittsler
http://starship.python.net/crew/theller/ Thomas Heller
http://starship.python.net/crew/gherman/ Dinu Gherman
http://starship.python.net/crew/mhammond/ Mark Hammond
http://starship.python.net/crew/atuining/
http://starship.python.net/crew/hooft/ Rob W.W. Hooft
http://starship.python.net/crew/lemburg/ --> http://www.egenix.com/
http://starship.python.net/crew/goodger/ David Goodger
http://starship.python.net/crew/mmuller/ Mike Muller
http://starship.python.net/crew/skippy/ same as 
http://starship.python.net/crew/mhammond/ Mark Hammond

BTW How could I have done this with Python script?

Dick Moores

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


Re: tkinter question

2007-10-05 Thread Kevin Walzer
Eric Brunel wrote:
> On Fri, 05 Oct 2007 14:10:57 +0200, Kevin Walzer <[EMAIL PROTECTED]> 
> wrote:
>> "expand = 1" ==  "expand=TRUE"--that means the widget resizes itself 
>> when the window is re-sized.
> 
> That's the theory... But what does fill=BOTH means then? And why does 
> expand=1 (or TRUE, or True) is only needed in some cases and not others? 
> And I'm quite sure that sometimes, I use expand=1 and it does exactly 
> what I don't want, and removing it gives the behaviour I want. I've been 
> doing tk/Tkinter stuff for quite a few years now, and I still haven't 
> understood exactly when I should use this option... Quite 
> counter-intuitive, IMHO.
> 
> But then, since I almost never use pack for this kind of layout, I guess 
> it's not really important...

"Fill" refers to the dimension/space that is filled when you expand the 
widget (assuming "expand" is set to true). "fill=x" means the widget 
will expand horizontally (along the x axis). "fill=y" means that the 
widget will expand vertically (along the y axis). "fill=both" means the 
widget will expand in both direction.

Frederick Lundh has a good introduction to the packer here: 
http://effbot.org/tkinterbook/pack.htm

I find "pack" to be more flexible than "grid," so I prefer it for 
complex layouts. "grid" is better for simple layouts.

HTH,
Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: migrating to packages

2007-10-05 Thread Hrvoje Niksic
Gerardo Herzig <[EMAIL PROTECTED]> writes:

> If the original MYCLASSES.py has 5 different classes ,say A,B,C,D,E
> , each one has to be imported (as A and B) in order to be used for
> the client code. The thing is, there are more than 5 classes, and
> looks like a lot of unnecesary work to me, since a particular
> program can use 1,2, or 3 classes at the timeThats why im
> watching the way to override the `import statement'...
>
> Damn client code!!!

You can create both a package and a compatibility module.  The package
would be broken into modules for modularity, while the compatibility
module would import what old code needs from the package, like this:

# old.py:
from new.submodule1 import A, B
from new.submodule2 import C, D
...

Now, old code can keep using "from old import A" and such, while new
code would import new.submodule1, new.submodule2, etc., as necessary.

Old code is no worse off because, although it uses the compatibility
module that just imports everything, that is in essence what the
previous module did as well.  On the other hand, new code can make use
of the modularity and reduce load times by only importing what it
really needs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit testing

2007-10-05 Thread byte8bits
On Oct 5, 5:38 am, Craig Howard <[EMAIL PROTECTED]> wrote:
> Brad:
>
> If the program is more than 100 lines or is a critical system, I
> write a unit test. I hate asking myself, "Did I break something?"
> every time I decide to refactor a small section of code. For
> instance, I wrote an alarm system in Python for a water treatment
> plant. If the chlorine, pH, or turbidity are out of spec, an email
> message is sent to the plant operator's pager. Because of the nature
> of the alarm system, extensive field testing was out of the question.
> Unit testing was the only way to ensure it worked without disrupting
> the plant operation.
>
> Craig

Thanks to all for the opinions. Just to clarify, I have nothing
against testing. I like doing it. I catch a lot of bugs! I dislike the
formality of the unittest module. It's unyielding. It makes testing
difficult unless your code is written with testing in mind from the
start.

I maintain old code... code written a long time ago, before unittest
was popular. Getting unittest to work on that is difficult at best. So
we do informal testing ourselfs. The end result is the same... bugs
are squashed before the code is placed into production. Many times, we
find bugs as soon as we write a test!

Thanks again for the advice.

Brad


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


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Adrian Cherry
Paul McGuire <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> I thought Steve Holden's Random Hits column was the "back
> page commentry".

after re-reading it then yes I can see your point, I suppose I 
was just hoping for some pythonesque humour to close the show!

Regards

Adrian

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


Re: Program with wx in Linux and Windows

2007-10-05 Thread Grant Edwards
On 2007-10-04, marcpp <[EMAIL PROTECTED]> wrote:

> Hi I've developed a program (WXpython GUI). In Linux the GUI is correct 
> (various distributions), but in Windows all appears disordered.
> Any recomendations?

I've been using wxPython for cross platofrm stuff on Linux and
Windows for 5+ years now for at least a dozen programs. I never
had any problems like the one you describe (though "appears
disordered" isn't much of a problem description).  I write/test
on Linux, and the programs pretty much "just work" on Windows.

I would guess your code is wrong it a way that happens to be
tolerated better under Linux than Windows for some reason.  If
you can come up with a minimal example program that
demonstrates the problem, the people on the wxPython mailing
list will almost certainly be able to tell you what you've done
wrong.

-- 
Grant Edwards   grante Yow! Spreading peanut
  at   butter reminds me of
   visi.comopera!!  I wonder why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Version 0.3.7 of the config module has been released

2007-10-05 Thread Vinay Sajip
Version 0.3.7 of the Python config module has been released.

What Does It Do?

The config module allows you to implement a hierarchical configuration
scheme with support for mappings and sequences, cross-references
between one part of the configuration and another, the ability to
flexibly access real Python objects, facilities for configurations to
include and cross-reference one another, simple expression evaluation
and the ability to change, save, cascade and merge configurations. You
can easily integrate with command line options using optparse.

This module has been developed on python 2.3 but should work on
version 2.2 or greater. A test suite using unittest is included in the
distribution.

A very simple configuration file (simple.cfg):

# starts here
message: Hello, world!
#ends here

a very simple program to use it:

from config import Config

cfg = Config(file('simple.cfg'))
print cfg.message

results in:

Hello, world!

Configuration files are key-value pairs, but the values can be
containers that contain further values.

A simple example - with the example configuration file:

messages:
[
  {
stream : `sys.stderr`
message: 'Welcome'
name: 'Harry'
  }
  {
stream : `sys.stdout`
message: 'Welkom'
name: 'Ruud'
  }
  {
stream : $messages[0].stream
message: 'Bienvenue'
name: Yves
  }
]

a program to read the configuration would be:

from config import Config

f = file('simple.cfg')
cfg = Config(f)
for m in cfg.messages:
s = '%s, %s' % (m.message, m.name)
try:
print >> m.stream, s
except IOError, e:
print e

which, when run, would yield the console output:

Welcome, Harry
Welkom, Ruud
Bienvenue, Yves

The above example just scratches the surface. There's more information
about this module available at

http://www.red-dove.com/python_config.html

Comprehensive API documentation is available at

http://www.red-dove.com/config/index.html

As always, your feedback is most welcome (especially bug reports,
patches and suggestions for improvement). Enjoy!

Cheers

Vinay Sajip
Red Dove Consultants Ltd.

Changes since the last release posted on comp.lang.python[.announce]:
=
Added Mapping.__delitem__ (patch by John Drummond).
Mapping.__getattribute__ no longer returns "" when asked
for "__class__" - doing so causes pickle to crash
(reported by Jamila Gunawardena).
Allow negative numbers (reported by Gary Schoep; had
already been fixed but not yet released).

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


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Grant Edwards
On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote:

> I've just been told by the editors at Python Magazine that the first 
> issue is out.

The first issue is issue number 10?

That's a bit silly.

-- 
Grant Edwards   grante Yow! I can't decide which
  at   WRONG TURN to make first!!
   visi.comI wonder if BOB GUCCIONE
   has these problems!
-- 
http://mail.python.org/mailman/listinfo/python-list


supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

2007-10-05 Thread timw.google
Hi

I want to write a python script that runs rsync on a given directory
and host. I build the command line string, but when I try to run
subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
os.system(cmd), I get prompted for my login password. I expected this,
but when I try to give my password, it's echoed back to the terminal
and the special characters in the password is (I think) getting
interpreted by the shell (zsh)

I can't ssh w/o supplying a password. That's the way the security is
set up here.

How do I use python to do this, or do I just have to write a zsh
script?

Thanks.

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


Re: remove list elements..

2007-10-05 Thread chris . monsanto
On Oct 5, 10:27 am, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> I have a problem..
> list1=[11, 223, 334, 4223...] 1 million element
> list2=[22,223,4223,2355...] 500.000 element
>
> I want to difference list1 to list2 but order very importent..
>
> My result must be:
> list3=[11,334,...]
>
> I do this use FOR easly but the speed very imported for me. I want to
> the fastest method please help me.
>
> I'm sorry my bad english.
>
> King regards..

Research the "set" data type. :)

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


Re: novice list

2007-10-05 Thread Paul Rudin
István <[EMAIL PROTECTED]> writes:

> Could somebody suggest me a novice Python list, please?

Here you go:

['novice']


(Sorry, couldn't resist.)

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

remove list elements..

2007-10-05 Thread Abandoned
Hi..
I have a problem..
list1=[11, 223, 334, 4223...] 1 million element
list2=[22,223,4223,2355...] 500.000 element

I want to difference list1 to list2 but order very importent..

My result must be:
list3=[11,334,...]

I do this use FOR easly but the speed very imported for me. I want to
the fastest method please help me.

I'm sorry my bad english.

King regards..

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


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Steve Holden
Grant Edwards wrote:
> On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote:
> 
>> I've just been told by the editors at Python Magazine that the first 
>> issue is out.
> 
> The first issue is issue number 10?
> 
> That's a bit silly.
> 
It's the October edition. They obviously decided to make sure the month 
numbering was consistent across the volumes.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Brian Jones
On 10/5/07, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
> On Oct 5, 9:44 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
> > On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote:
> >
> > > I've just been told by the editors at Python Magazine that the first
> > > issue is out.
> >
> > The first issue is issue number 10?
> >
> > That's a bit silly.
> >
> > --
> > Grant Edwards   grante Yow! I can't decide
> which
> >   at   WRONG TURN to make
> first!!
> >visi.comI wonder if BOB
> GUCCIONE
> >has these problems!
>
> Probably Issue 10 as in "issued in October, being the 10th month", so
> this is more of an id than it is a sequential index number.  Just like
> a social security number of 123-45-6789 does not mean you are the
> 123,456,789th human born since the beginning of the SS system.
>
> But I grant that Issue number does have some connotation of sequence
> to it, and if the next issue is something like 2 or 8, or really
> anything other than 11, now THAT would be silly.  And I'm sure that in
> the future, when people are trying to amass the complete set of Python
> Magazines, they'll wonder why those issues 1-9 of the first volume are
> so hard to come by.
>
> But I suspect that, come January, we will see the release of Vol 2,
> Issue 1.  Just an artifact of having the first issue come out in some
> month other than January.
>
> -- Paul
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

It's "Volume 1, Issue 10". A volume is a year. When January '08 is released,
it will be "Volume 2, Issue 1".

Keep the feedback coming!
brian.

-- 
Brian K. Jones
Python Magazine  http://www.pythonmagazine.com
My Blog  http://m0j0.wordpress.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: remove list elements..

2007-10-05 Thread J. Clifford Dyer
On Fri, Oct 05, 2007 at 07:27:39AM -0700, Abandoned wrote regarding remove list 
elements..:
> 
> Hi..
> I have a problem..
> list1=[11, 223, 334, 4223...] 1 million element
> list2=[22,223,4223,2355...] 500.000 element
> 
> I want to difference list1 to list2 but order very importent..
> 
> My result must be:
> list3=[11,334,...]
> 
> I do this use FOR easly but the speed very imported for me. I want to
> the fastest method please help me.
> 
> I'm sorry my bad english.
> 
> King regards..
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

If you're using a recent python, you can create a set from list2, and preserve 
order with list1 like so:

set2 = set(list2)
list3 = [ x for x in list1 if x not in set2 ]

That will speed up your access to list2 (for 500,000 scans) at the low cost of 
reading through the whole thing once.

You say order is very important, but if your order is known to be strictly 
increasing (as it appears from your sample code), you can speed up further by 
doing:

set1 = set(list1)
set2 = set(list2)
list3 = sorted(set1 - set2)


Though to tell the truth, I'm not sure this actually would be faster, since you 
access each element of list1 just once in the list comprehension version.  And 
I can't be bothered to try it out with timeit.

Cheers,
Cliff

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


Re: unit testing

2007-10-05 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
> On Oct 5, 5:38 am, Craig Howard <[EMAIL PROTECTED]> wrote:
>> Brad:
>>
>> If the program is more than 100 lines or is a critical system, I
>> write a unit test. I hate asking myself, "Did I break something?"
>> every time I decide to refactor a small section of code. For
>> instance, I wrote an alarm system in Python for a water treatment
>> plant. If the chlorine, pH, or turbidity are out of spec, an email
>> message is sent to the plant operator's pager. Because of the nature
>> of the alarm system, extensive field testing was out of the question.
>> Unit testing was the only way to ensure it worked without disrupting
>> the plant operation.
> 
> Thanks to all for the opinions. Just to clarify, I have nothing
> against testing. I like doing it. I catch a lot of bugs! I dislike the
> formality of the unittest module. It's unyielding. It makes testing
> difficult unless your code is written with testing in mind from the
> start.

There's been talk in the past about trying to bring some of the features 
of py.test to the unittest module.  However, I think there hasn't been 
anyone with enough free time to start tackling this problem.

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


Re: Where's the Starship's crew?

2007-10-05 Thread Aahz
In article <[EMAIL PROTECTED]>,
Dick Moores  <[EMAIL PROTECTED]> wrote:
>
>
>
>I didn't check on all of them, but the only one I found was Mark 
>Hammond .

This is the unfortunate remnant of a system hack; many people who used
to have active Starship accounts never bothered bringing them back after
Starship was cleaned up.  Starship was recently moved to another machine
and we're having discussions about the future.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Paul McGuire
On Oct 5, 9:44 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> > I've just been told by the editors at Python Magazine that the first
> > issue is out.
>
> The first issue is issue number 10?
>
> That's a bit silly.
>
> --
> Grant Edwards   grante Yow! I can't decide which
>   at   WRONG TURN to make first!!
>visi.comI wonder if BOB GUCCIONE
>has these problems!

Probably Issue 10 as in "issued in October, being the 10th month", so
this is more of an id than it is a sequential index number.  Just like
a social security number of 123-45-6789 does not mean you are the
123,456,789th human born since the beginning of the SS system.

But I grant that Issue number does have some connotation of sequence
to it, and if the next issue is something like 2 or 8, or really
anything other than 11, now THAT would be silly.  And I'm sure that in
the future, when people are trying to amass the complete set of Python
Magazines, they'll wonder why those issues 1-9 of the first volume are
so hard to come by.

But I suspect that, come January, we will see the release of Vol 2,
Issue 1.  Just an artifact of having the first issue come out in some
month other than January.

-- Paul

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


Re: Boolean parser..

2007-10-05 Thread Paul McGuire
On Oct 4, 3:00 pm, [EMAIL PROTECTED] wrote:
> On Oct 5, 7:29 am, Abandoned <[EMAIL PROTECTED]> wrote:
>
> > Hi..
> > I try a boolean parser in python since 1 weak.. But i can't do this
> > because this is very complicated :(
> > Do you know any blooean parser script in python or how do i write a
> > boolean parser ?
> > example query: ((google or yahoo) or (live msn)) not web
> > I'm sorry my bad english.
> > King Regards..
>
> Try the pyparsing module (google it)
> They have several examples.

The pyparsing wiki has this online example:
http://pyparsing.wikispaces.com/space/showimage/searchparser.py.

-- Paul

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


Re: remove list elements..

2007-10-05 Thread Carsten Haese
On Fri, 2007-10-05 at 07:27 -0700, Abandoned wrote:
> Hi..
> I have a problem..
> list1=[11, 223, 334, 4223...] 1 million element
> list2=[22,223,4223,2355...] 500.000 element
> 
> I want to difference list1 to list2 but order very importent..
> 
> My result must be:
> list3=[11,334,...]
> 
> I do this use FOR easly but the speed very imported for me. I want to
> the fastest method please help me.

If you can write this as a for/append loop, then you can easily rewrite
it into a list comprehension:

 = []
for  in :
  if :
 .append()

becomes

 = [ for  in  if ]

Now all you need to do is fill in the blanks.

As a hint for what exactly to fill in for blank4, remember (or be
advised) that Python has sets.

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: remove list elements..

2007-10-05 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes:

> I do this use FOR easly but the speed very imported for me. I want
> to the fastest method please help me.

Can you post the code snippet that was too slow for you?  Are the
lists sorted?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean parser..

2007-10-05 Thread Paul McGuire
On Oct 5, 7:00 am, Abandoned <[EMAIL PROTECTED]> wrote:
> http://pyparsing.wikispaces.com/space/showimage/searchparser.pythis
> is searchparser but i can't understant to use this.
> Can anybody explain this how to use ?

The code demonstrates a testing example, named TestParser, which
inherits from SearchQueryParser.  As mentioned in the docstrings at
the top, to use this code, import the module and define your own class
to inherit from SearchQueryParser.  Then override the Get... methods,
as is done in TestParser.  Each Get method returns a set, and all sets
are then ANDed and ORed according to the input search string.

Here's a simple example, a database of fruit-based products.  To keep
things simple, each product will come from a single fruit, and the
name of the fruit will be at the beginning of the product's name, for
instance "grape juice" is made from the fruit named "grape".

from searchparser import SearchQueryParser

products = [ "grape juice", "grape jelly", "orange juice", "orange
jujubees",
"strawberry jam", "prune juice", "prune butter", "orange
marmalade",
"grapefruit juice" ]

class FruitSearchParser(SearchQueryParser):
def GetWord(self, word):
return set( p for p in products if p.startswith(word + " ") )

def GetWordWildcard(self, word):
return set( p for p in products if p.startswith(word[:-1]) )

def GetQuotes(self, search_string, tmp_result):
result = Set()
# I have no idea how to use this feature...
return result

def GetNot(self, not_set):
return set( products ) - not_set


parser = FruitSearchParser()

tests = """\
grape or orange
grape*
not(grape*)
prune and grape""".splitlines()

for t in tests:
print t.strip()
print parser.Parse(t)
print


Prints:

grape or orange
set(['orange juice', 'grape juice', 'orange marmalade', 'orange
jujubees', 'grape jelly'])

grape*
set(['grapefruit juice', 'grape juice', 'grape jelly'])

not(grape*)
set(['orange jujubees', 'orange juice', 'prune butter', 'orange
marmalade', 'strawberry jam', 'prune juice'])

prune and grape
set([])



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


Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

2007-10-05 Thread timw.google
On Oct 5, 10:33 am, "timw.google" <[EMAIL PROTECTED]> wrote:
> Hi
>
> I want to write a python script that runs rsync on a given directory
> and host. I build the command line string, but when I try to run
> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
> os.system(cmd), I get prompted for my login password. I expected this,
> but when I try to give my password, it's echoed back to the terminal
> and the special characters in the password is (I think) getting
> interpreted by the shell (zsh)
>
> I can't ssh w/o supplying a password. That's the way the security is
> set up here.
>
> How do I use python to do this, or do I just have to write a zsh
> script?
>
> Thanks.

I wrote a zsh script to do what I wanted, but I'd still like to know
how to do it in Python.

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


Re: novice list

2007-10-05 Thread chris . monsanto
On Oct 5, 10:22 am, Paul Rudin <[EMAIL PROTECTED]> wrote:
> István <[EMAIL PROTECTED]> writes:
> > Could somebody suggest me a novice Python list, please?
>
> Here you go:
>
> ['novice']
>
> (Sorry, couldn't resist.)

No no... I think he meant a "simple" list. Like, you know, a list
novices can handle.

I suggest the empty list []!

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

Re: remove list elements..

2007-10-05 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Oct 5, 10:27 am, Abandoned <[EMAIL PROTECTED]> wrote:
>> Hi..
>> I have a problem..
>> list1=[11, 223, 334, 4223...] 1 million element
>> list2=[22,223,4223,2355...] 500.000 element
>>
>> I want to difference list1 to list2 but order very importent..
>>
>> My result must be:
>> list3=[11,334,...]
>>
>> I do this use FOR easly but the speed very imported for me. I want to
>> the fastest method please help me.
>>
>> I'm sorry my bad english.
>>
>> King regards..
> 
> Research the "set" data type. :)
> 
Probably not a very helpful suggestion given that ordering is stated to 
be very important.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: unit testing

2007-10-05 Thread Roy Smith
[EMAIL PROTECTED] wrote:
> Thanks to all for the opinions. Just to clarify, I have nothing
> against testing. I like doing it. I catch a lot of bugs! I dislike the
> formality of the unittest module. It's unyielding. It makes testing
> difficult unless your code is written with testing in mind from the
> start.

There is some advantage in forcing you to write code with testing in mind.  
It often works out that the same things which make code easy to test (clean 
interfaces, little cross-class dependency, etc), also make the code easy to 
maintain and modify later.

Compared to some other testing frameworks I've used, unittest is pretty 
lightweight.  That's not to say that for small projects, even the small 
amount of baggage it brings with it may feel heavy.
-- 
http://mail.python.org/mailman/listinfo/python-list


picture filter

2007-10-05 Thread [EMAIL PROTECTED]
hii my friends
ı want to a filter for porn picture
if you know , please help me :S:S
how  do ı separate porn form not porn
I don't want my web site porn;)
(my english bad I hope understant it. very very thans )

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


Re: unit testing

2007-10-05 Thread Kay Schluehr
On Oct 5, 4:12 pm, [EMAIL PROTECTED] wrote:
> On Oct 5, 5:38 am, Craig Howard <[EMAIL PROTECTED]> wrote:
>
> > Brad:
>
> > If the program is more than 100 lines or is a critical system, I
> > write a unit test. I hate asking myself, "Did I break something?"
> > every time I decide to refactor a small section of code. For
> > instance, I wrote an alarm system in Python for a water treatment
> > plant. If the chlorine, pH, or turbidity are out of spec, an email
> > message is sent to the plant operator's pager. Because of the nature
> > of the alarm system, extensive field testing was out of the question.
> > Unit testing was the only way to ensure it worked without disrupting
> > the plant operation.
>
> > Craig
>
> Thanks to all for the opinions. Just to clarify, I have nothing
> against testing. I like doing it. I catch a lot of bugs! I dislike the
> formality of the unittest module. It's unyielding. It makes testing
> difficult unless your code is written with testing in mind from the
> start.
>
> I maintain old code... code written a long time ago, before unittest
> was popular. Getting unittest to work on that is difficult at best. So
> we do informal testing ourselfs. The end result is the same... bugs
> are squashed before the code is placed into production. Many times, we
> find bugs as soon as we write a test!
>
> Thanks again for the advice.
>
> Brad

Just one recommendation. I don't know your project and remote
diagnostics is usually more funny than usefull, but there is a body of
literature about dealing with legacy code, for example:

http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052

Of course Micheal Feathers talks constantly about putting systems
under test, exposing code for testability and lots more that goes
beyond code & fix.

Here is some article of the same author:

http://www.objectmentor.com/resources/articles/WorkingEffectivelyWithLegacyCode.pdf

Kay

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


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread J. Clifford Dyer
On Fri, Oct 05, 2007 at 04:11:07PM -, Grant Edwards wrote regarding Re: 
Python Magazine: Issue 1 Free!:
> 
> On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote:
> >>
> >>> I've just been told by the editors at Python Magazine that the
> >>> first issue is out.
> >> 
> >> The first issue is issue number 10?
> >> 
> >> That's a bit silly.
> >
> > It's the October edition. They obviously decided to make sure
> > the month numbering was consistent across the volumes.
> 
> I presumed that was the reasoning. It just seems
> counter-intuitive (and sort of un-Pythonic) to start numbering
> a sequence of objects at 10. ;)
> 

Well, it's also unpythonic to start numbering a sequence at 1, but it's clearly 
the right thing to do in this case.

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


Re: Python Magazine: Issue 1 Free!

2007-10-05 Thread Grant Edwards
On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote:
>>
>>> I've just been told by the editors at Python Magazine that the
>>> first issue is out.
>> 
>> The first issue is issue number 10?
>> 
>> That's a bit silly.
>
> It's the October edition. They obviously decided to make sure
> the month numbering was consistent across the volumes.

I presumed that was the reasoning. It just seems
counter-intuitive (and sort of un-Pythonic) to start numbering
a sequence of objects at 10. ;)

-- 
Grant Edwards   grante Yow! Hmmm ... a CRIPPLED
  at   ACCOUNTANT with a FALAFEL
   visi.comsandwich is HIT by a
   TROLLEY-CAR ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module confusion

2007-10-05 Thread Steve Holden
Steven D'Aprano wrote:
> On Fri, 05 Oct 2007 07:37:34 -0400, Steve Holden wrote:
> 
>> Steven D'Aprano wrote:
>>> On Fri, 05 Oct 2007 00:12:33 -0500, Robert Kern wrote:
>>>
 This is somewhat odd, because most modules aren't exposed that way.
 They are either in their own file and accessed by importing them
 directly, or they are inside a package.
>>> Any time you say:
>>>
>>> import parrot
>>>
>>>
>>> in one of your modules, you export parrot to anything that
>> subsequently
> 
> Well obviously you have to write the module before people import it. I 
> didn't really think "you must obey the laws of time and space" needed to 
> be explained.
> 
But a module needn't be fully executed before it's imported.
> 
>>> imports your
>>> module. (Unless you take specific steps to prevent it, for instance
>>> with del parrot.)
>> or the creation of an __all__ containing an exclusive list of names for
>> export.
> 
> No.
> 
> __all__ only effects names imported with "from module import *", it has 
> no effect on "import module".
> 
> What was that again about avoiding "writing anything that will be 
> misconstrued by newless cloobs unfortunate enough to reach this thread as 
> a result of a search for meaningful information on Python imports"?
> 
> 
> 
Well, precisely.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: module confusion

2007-10-05 Thread Steven D'Aprano
On Fri, 05 Oct 2007 07:37:34 -0400, Steve Holden wrote:

> Steven D'Aprano wrote:
>> On Fri, 05 Oct 2007 00:12:33 -0500, Robert Kern wrote:
>> 
>>> This is somewhat odd, because most modules aren't exposed that way.
>>> They are either in their own file and accessed by importing them
>>> directly, or they are inside a package.
>> 
>> Any time you say:
>> 
>> import parrot
>> 
>> 
>> in one of your modules, you export parrot to anything that
> 
> subsequently

Well obviously you have to write the module before people import it. I 
didn't really think "you must obey the laws of time and space" needed to 
be explained.


>> imports your
>> module. (Unless you take specific steps to prevent it, for instance
>> with del parrot.)
> 
> or the creation of an __all__ containing an exclusive list of names for
> export.

No.

__all__ only effects names imported with "from module import *", it has 
no effect on "import module".

What was that again about avoiding "writing anything that will be 
misconstrued by newless cloobs unfortunate enough to reach this thread as 
a result of a search for meaningful information on Python imports"?



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


Re: remove list elements..

2007-10-05 Thread Marc 'BlackJack' Rintsch
On Fri, 05 Oct 2007 11:45:07 -0400, Steve Holden wrote:

> [EMAIL PROTECTED] wrote:
>> On Oct 5, 10:27 am, Abandoned <[EMAIL PROTECTED]> wrote:
>>> Hi..
>>> I have a problem..
>>> list1=[11, 223, 334, 4223...] 1 million element
>>> list2=[22,223,4223,2355...] 500.000 element
>>>
>>> I want to difference list1 to list2 but order very importent..
>>>
>>> My result must be:
>>> list3=[11,334,...]
>>>
>>> I do this use FOR easly but the speed very imported for me. I want to
>>> the fastest method please help me.
>> 
>> Research the "set" data type. :)
>> 
> Probably not a very helpful suggestion given that ordering is stated to 
> be very important.

A `set()` can be part of such a solution.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "SyntaxError: Non-ASCII character '\xc2'...", was Re: Is there a nicer way to do this?

2007-10-05 Thread Victor B. Gonzalez
On Friday 05 October 2007 3:33:43 am Peter Otten wrote:
> Victor B. Gonzalez wrote:
> > anyhow, I keep getting "SyntaxError: Non-ASCII character '\xc2'..." on
> > line 5. anyone know what this is?
>
> I too had that problem with KNode. Leading space consists of NO-BREAK SPACE
> (unichr(160)) which translates to '\xc2\xa0' in UTF-8. As I don't see this
> problem here (using pan) I suspect it may be specific to KMail/KNode.
>
> Peter

You're right, thank you for pointing that out. I am bad with almost anything 
like \this but stripping off the leading whitespace solved the issue. thank 
you for the heads up!

-- 
Best Regards
Victor B. Gonzalez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

2007-10-05 Thread Stargaming
On Fri, 05 Oct 2007 08:37:05 -0700, timw.google wrote:

> On Oct 5, 10:33 am, "timw.google" <[EMAIL PROTECTED]> wrote:
>> Hi
>>
>> I want to write a python script that runs rsync on a given directory
>> and host. I build the command line string, but when I try to run
>> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
>> os.system(cmd), I get prompted for my login password. I expected this,
>> but when I try to give my password, it's echoed back to the terminal
>> and the special characters in the password is (I think) getting
>> interpreted by the shell (zsh)
>>
>> I can't ssh w/o supplying a password. That's the way the security is
>> set up here.
>>
>> How do I use python to do this, or do I just have to write a zsh
>> script?
>>
>> Thanks.
> 
> I wrote a zsh script to do what I wanted, but I'd still like to know how
> to do it in Python.

`subprocess.Popen` has a keyword argument called `stdin` -- what takes 
the password, I guess. Assigning `subprocess.PIPE` to it and using 
`Popen.communicate` should do the trick. 

Check the documentation at http://docs.python.org/lib/module-
subprocess.html for details.

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


Re: picture filter

2007-10-05 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> hii my friends
> ı want to a filter for porn picture
> if you know , please help me :S:S
> how  do ı separate porn form not porn
> I don't want my web site porn;)
> (my english bad I hope understant it. very very thans )

If anybody know how to do that, he or she would immediatly become 
incredibly rich, selling this magic filter to concerned parents as well 
as eager porn enthusiasts, to help them filter away the noise or dirt, 
from their respective viewpoints that is of course...

So - you're out of luck buddy. Nobody will be able to help you.


Diez

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


  1   2   >