Re: ANN: PyQt v4.1 Released

2006-11-09 Thread Tool69
Shame on me, I forgot to import the lexers.

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-09 Thread robert
robert wrote:

> --
> 0040101F   mov eax,3B9ACA00h
> 13: for (i = 0; i < count; ++i) {
> 14: __asm lock inc x;
> 00401024   lock incdword ptr [_x (00408a00)]
> 15: sum += x;
> 0040102B   mov edx,dword ptr [_x (00408a00)]
> 00401031   add esi,edx
> 00401033   dec eax
> 00401034   jne main+24h (00401024)
> 16: }
> ---
> 
> results on a UP PIII :
> 
> INC version:
> clocks: 7520
> secs:   7
> 
> LOCK INC version:
> clocks: 36632
> secs:   36
> 
> 
> Its probably not much...

The Intels I checked, have all about this factor of ~5 in that simple example.

AMDs were typically faster. less than ~3. 


-robert

PS: 
the asm for x86 linux/gcc:
---

#include 
#include 
#include 

volatile int x=0;
clock_t c0,c1;
time_t t0,t1;

int main (int argc, char **argv) {
  int sum = 0, i, count = 1;
  t0=time(&t0);
  c0=clock();
  for (i = 0; i < count; ++i) {
  asm ("incl %0;" : "=m"(x)  );
  sum += x;
  }
  c1=clock();
  t1=time(&t1);
//  printf("%d\n", sum);
  printf("clocks: %d\n", c1-c0);
  printf("secs:   %d\n", t1-t0);
  return sum;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib.urlopen: Errno socket error

2006-11-09 Thread frifri007

[EMAIL PROTECTED] a écrit :

> Hi,
>
> I'm just trying to read from a webpage with urllib but I'm getting
> IOErrors. This is my code:
>
> import urllib
> sock = urllib.urlopen("http://www.google.com/";)
>
> and this is the error:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> sock = urllib.urlopen("http://www.google.com/";)
>   File "C:\Python25\lib\urllib.py", line 82, in urlopen
> return opener.open(url)
>   File "C:\Python25\lib\urllib.py", line 190, in open
> return getattr(self, name)(url)
>   File "C:\Python25\lib\urllib.py", line 325, in open_http
> h.endheaders()
>   File "C:\Python25\lib\httplib.py", line 856, in endheaders
> self._send_output()
>   File "C:\Python25\lib\httplib.py", line 728, in _send_output
> self.send(msg)
>   File "C:\Python25\lib\httplib.py", line 695, in send
> self.connect()
>   File "C:\Python25\lib\httplib.py", line 679, in connect
> raise socket.error, msg
> IOError: [Errno socket error] (10060, 'Operation timed out')
>
> I'm behind my company's firewall. Would that cause a problem? If it
> does, How do I get around it?


See the documentation for urllib.urlopen:

"""
In a Windows environment, if no proxy environment variables are set,
proxy settings are obtained from the registry's Internet Settings
section.
"""
Remove Proxy configuration under IE and try again
(don't use Ie anymore ;0)

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

Re: Multithreaded C API Python questions

2006-11-09 Thread Hendrik van Rooyen
"Svein Seldal" <"svein at seldal dot com">wrote:
8<---
> I am dependent upon the ability to have to threads executing in python
> land at the same time. How can this be done?

call time.sleep(0.001) in each, as well as the main thread, to politely give the
rest a chance

Fiddle with the sleep times in your setup to get the best performance - and
don't be misled into thinking that faster is better - its not always true -
there comes a point where the overhead of swapping  a thread consumes the total
resource of the process, and no work gets done.

- HTH

- Hendrik

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


Re: substring search without using built in utils

2006-11-09 Thread Hendrik van Rooyen
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote:
8<--

> Given a source list, find the offset of a target sub-list within the
> source list, in other words, find for lists.
>
> i.e. search(source, target) returns n if source[n:n+len(target)] == target
> for any sequence type.
>
> Yes, I know I'm changing the constraints of the problem. Now for a real
> challenge, change the search from a one-dimensional data structure to two.
>
> (The solution is left as an exercise for the class.)

do you mean like a cross word puzzle - find for fit both across and down, and
possibly reversed too, in both dimensions? - sounds like a lot of nested loops
to me...

- Hendrik



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


Re: how is python not the same as java?

2006-11-09 Thread John Henry

gavino wrote:
> both are interpreted oo langauges..


I remember the days when I got all excited about Java (many many moons
ago when Java first came out).  I brought a whole truckload of books on
it, even spent 5 days attending a seminar on the subject.   To my great
disappointment, I never got very far with it.   Not being a
"professional programmer" by training, I found it very difficult to go
very far with Java.   Everything was so "un-natural" for me.  So, I
felt back to my little C-corner.

Last year, I got a chance to attend a 5 day class on Python.   Hated it
- for the first 5 minutes (what the , they are using white space
for what)  but from that pont on, never look back.

Not considering myself an advance Python programmer.   Don't matter, I
am very proficient with it.   It allows me to get things done - in a
whole lot less time then I have to do otherwise.

Learning new things about it everyday, finding new and usefull open
source packages for it everyday.

My Java books?  They hit the trash dump long ago

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


Re: Printing to file, how do I do it efficiently?

2006-11-09 Thread Robert Kern
Cameron Walsh wrote:
> Hi all,
> 
> I have a numpy.array of 89x512x512 uint8's, set up with code like this:

numpy questions are best asked on the numpy list, not here.

  http://www.scipy.org/Mailing_Lists

> data=numpy.array([],dtype="uint8")
> data.resize((89,512,512))

You might want to look at using numpy.empty() here, instead.

> # Data filled in about 4 seconds from 89 image slices
> 
> 
> 
> I first tried writing this data to a binary raw format (for use in a
> program called Drishti) as follows:
> 
> # The slow bit:
> volumeFile=file("/tmp/test.raw","wb")
> for z in xrange(Z):
> for y in xrange(Y):
> for x in xrange(X):
> volumeFile.write("%c" %(data[z,y,x]))
> volumeFile.close()
> 
> That took about 39 seconds.
> 
> My second attempt was as follows:
> volumeFile = open("/tmp/test2.raw","wb")
> data.resize((X*Y*Z)) # Flatten the array
> for i in data:
> volumeFile.write("%c" %i)
> data.resize((Z,Y,X))
> volumeFile.close()
> 
> This took 32 seconds.  (For those of you unfamiliar with numpy, the
> data.resize() operations take negligible amounts of time, all it does is
> allow the data to be accessed differently.)

No, if the total size is different, it will also copy the array. Use .reshape()
if you want to simply alter the shape, not the total number of elements.

> I'm guessing that the slow part is the fact that I am converting the
> data to character format and writing it one character at a time.  What
> is a better way of doing this, or where should I look to find a better way?

data.tostring()

-- 
Robert Kern

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

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


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread John Henry
Upon closer look, the walkthrough did say:

***
from PythonCard import model

Change that so it says:

from PythonCard import dialog, model

Save the code.
***

So, it works.



John Henry wrote:
> Bill Maxwell wrote:
> > On 8 Nov 2006 11:49:07 -0800, "John Henry" <[EMAIL PROTECTED]>
> > wrote:
> >
> > >
> > >John Salerno wrote:
> > >> Dan Lenski wrote:
> > >>
> > >> > So, is there another toolkit I should be looking at?
> > >>
> > >> I highly recommend wxPython. It's very mature, full-featured, and
> > >> portable, and fairly easy to learn as well. I can't really compare it to
> > >> other toolkits (not having used any of them, except Tkinter), but it's
> > >> definitely one of the most popular and well-supported ones out there.
> > >>
> > >> http://www.wxpython.org/
> > >
> > >I highly recommend that you try PythonCard (which sits on top of
> > >wxPython).  You can get productive very very quickly.  Take a look at:
> > >
> > >http://pythoncard.sourceforge.net/walkthrough1.html
> >
> >
> > I took a brief look at PythonCard almost a year ago and got discouraged
> > by what I found, so I stopped looking at it.  I've inserted my notes
> > from back then, below.  Does anybody know if these things have been
> > fixed in the latest release?
> >
> > Bill
> >
> >
> > =
> > My notes from Fri Dec-23-2005:
> >
> > This is a list of gripes I have while trying to learn about PythonCard.
> > I'm trying to investigate various GUI builders for Python, and
> > PythonCard looks promising, but a lot of things are getting in the way.
> >
> > I installed yesterday, using this installer:
> > PythonCard-0.8.1.FIXED.win32.exe
> >
> > A)  The very first example in the tutorial is wrong!
> >
> > On this page:  http://pythoncard.sourceforge.net/documentation.html
> > When you follow this link to try something for the very first time:
> >
> > Getting Started in PythonCard by Dan Shafer:
> > http://pythoncard.sourceforge.net/walkthrough1.html
> >
> > You quickly see that the minimal.py example doesn't even contain
> > this line, even though the tutorial refers to it:
> >
>
> I am not sure which one you are referring to but in the
> PythonCard\samples\minimal, you will find a minimal.py that says:
>
> #!/usr/bin/python
>
> """
> __version__ = "$Revision: 1.8 $"
> __date__ = "$Date: 2005/12/17 15:20:02 $"
> """
>
> from PythonCard import model
>
>
> class Minimal(model.Background):
> def on_menuFileAbout_select(self, event):
> pass
>
> if __name__ == '__main__':
> app = model.Application(Minimal)
> app.MainLoop()
>
>
>
> > def on_menuFileAbout_select(self, event):
> >
> > And, of course, if you replace the word "pass" with this, as
> > instructed:
> >
> > result = dialog.alertDialog(self, 'It works!', 'Showing Off')
> >
> > it won't run, because the existing "pass" line isn't inside a def
> > inside of a class.
> >
>
> No, it didn't work because the author forgot to mention that you have
> to do a:
>
> from PythonCard import model, dialog
>
> instead of just:
>
> from PythonCard import model
>
> I just tried it and it works.
>
> >
> > B)  Is the Notebook widget really supported?
> >
> > In the installed file "changelog.txt" (gets installed as part of
> > PythonCard installation), it says:
> >
> > "added Notebook component, PageBackground, and testNotebook
> > sample"
> >
> > But, the testNotebook sample is nowhere to be found.
> >
>
> I haven't come across a need to use Notebook and so I can not say for
> sure.  Looking at notebook.py, it appears to be just a simple wrapper
> on top of the wxWindow notebook.  I would encourage you to post a
> message to the mailing list and ask there.
>
>
> > I looked lots of places, including the main SourceForge web site,
> > and on the wiki, here:
> >
> > http://wiki.wxpython.org/index.cgi/PythonCard
> >
> > Both the main website and the wiki seem way out of date, and the
> > latest dates I could find on both of them are sometime in 2004.
> >
>
> Yes, sometime around 2004, the website updating stopped.   Fortunately,
> development didn't.  There are quite a number of new things since then:
> new resource editor (now call layout Editor, standalone exe creator,
> and so forth).  I even learn that a new sizer handler is in the work.
>
> Not saying that there are 10 programmers working 7/24 on it.  It *is*
> an Open Source project nevertheless.   Nobody gets paid for doing it.
>  But there are development work going on.
>
>
> > Finally, by following the mailing list archive link on the main
> > website, I managed to find a reference to the notebook component on the
> > ASPN site, where some guy named Brian wonders about the same thing as
> > me, concerning the availability of the notebook component:
> >
> > http://aspn.activesta

Re: How to choose the right GUI toolkit ?

2006-11-09 Thread John Henry
Bill Maxwell wrote:
> On 8 Nov 2006 11:49:07 -0800, "John Henry" <[EMAIL PROTECTED]>
> wrote:
>
> >
> >John Salerno wrote:
> >> Dan Lenski wrote:
> >>
> >> > So, is there another toolkit I should be looking at?
> >>
> >> I highly recommend wxPython. It's very mature, full-featured, and
> >> portable, and fairly easy to learn as well. I can't really compare it to
> >> other toolkits (not having used any of them, except Tkinter), but it's
> >> definitely one of the most popular and well-supported ones out there.
> >>
> >> http://www.wxpython.org/
> >
> >I highly recommend that you try PythonCard (which sits on top of
> >wxPython).  You can get productive very very quickly.  Take a look at:
> >
> >http://pythoncard.sourceforge.net/walkthrough1.html
>
>
> I took a brief look at PythonCard almost a year ago and got discouraged
> by what I found, so I stopped looking at it.  I've inserted my notes
> from back then, below.  Does anybody know if these things have been
> fixed in the latest release?
>
> Bill
>
>
> =
> My notes from Fri Dec-23-2005:
>
> This is a list of gripes I have while trying to learn about PythonCard.
> I'm trying to investigate various GUI builders for Python, and
> PythonCard looks promising, but a lot of things are getting in the way.
>
> I installed yesterday, using this installer:
> PythonCard-0.8.1.FIXED.win32.exe
>
> A)  The very first example in the tutorial is wrong!
>
>   On this page:  http://pythoncard.sourceforge.net/documentation.html
>   When you follow this link to try something for the very first time:
>
>   Getting Started in PythonCard by Dan Shafer:
>   http://pythoncard.sourceforge.net/walkthrough1.html
>
>   You quickly see that the minimal.py example doesn't even contain
> this line, even though the tutorial refers to it:
>

I am not sure which one you are referring to but in the
PythonCard\samples\minimal, you will find a minimal.py that says:

#!/usr/bin/python

"""
__version__ = "$Revision: 1.8 $"
__date__ = "$Date: 2005/12/17 15:20:02 $"
"""

from PythonCard import model


class Minimal(model.Background):
def on_menuFileAbout_select(self, event):
pass

if __name__ == '__main__':
app = model.Application(Minimal)
app.MainLoop()



>   def on_menuFileAbout_select(self, event):
>
>   And, of course, if you replace the word "pass" with this, as
> instructed:
>
>   result = dialog.alertDialog(self, 'It works!', 'Showing Off')
>
>   it won't run, because the existing "pass" line isn't inside a def
> inside of a class.
>

No, it didn't work because the author forgot to mention that you have
to do a:

from PythonCard import model, dialog

instead of just:

from PythonCard import model

I just tried it and it works.

>
> B)  Is the Notebook widget really supported?
>
>   In the installed file "changelog.txt" (gets installed as part of
> PythonCard installation), it says:
>
>   "added Notebook component, PageBackground, and testNotebook
>   sample"
>
>   But, the testNotebook sample is nowhere to be found.
>

I haven't come across a need to use Notebook and so I can not say for
sure.  Looking at notebook.py, it appears to be just a simple wrapper
on top of the wxWindow notebook.  I would encourage you to post a
message to the mailing list and ask there.


>   I looked lots of places, including the main SourceForge web site,
> and on the wiki, here:
>
>   http://wiki.wxpython.org/index.cgi/PythonCard
>
>   Both the main website and the wiki seem way out of date, and the
> latest dates I could find on both of them are sometime in 2004.
>

Yes, sometime around 2004, the website updating stopped.   Fortunately,
development didn't.  There are quite a number of new things since then:
new resource editor (now call layout Editor, standalone exe creator,
and so forth).  I even learn that a new sizer handler is in the work.

Not saying that there are 10 programmers working 7/24 on it.  It *is*
an Open Source project nevertheless.   Nobody gets paid for doing it.
 But there are development work going on.


>   Finally, by following the mailing list archive link on the main
> website, I managed to find a reference to the notebook component on the
> ASPN site, where some guy named Brian wonders about the same thing as
> me, concerning the availability of the notebook component:
>
>   http://aspn.activestate.com/ASPN/Mail/Message/pythoncard/2536825
>
>   and, that message led me here:
>
>   http://article.gmane.org/gmane.comp.python.pythoncard/1060
>
>   where Kevin Altis admits that he forgot to include it in the 0.8.1
> release!  At least he provides a way to download it separately.  But,
> gheesh, this is pretty poor for a new user.  I was interested in using
> the notebook component right away, because I looked at the wxGlade
> tutorial bef

Re: how is python not the same as java?

2006-11-09 Thread George Sakkis
how are BMWs not the same with Yugos ?

both have four wheels and burn gasoline.

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


Printing to file, how do I do it efficiently?

2006-11-09 Thread Cameron Walsh
Hi all,

I have a numpy.array of 89x512x512 uint8's, set up with code like this:


data=numpy.array([],dtype="uint8")
data.resize((89,512,512))
# Data filled in about 4 seconds from 89 image slices



I first tried writing this data to a binary raw format (for use in a
program called Drishti) as follows:

# The slow bit:
volumeFile=file("/tmp/test.raw","wb")
for z in xrange(Z):
for y in xrange(Y):
for x in xrange(X):
volumeFile.write("%c" %(data[z,y,x]))
volumeFile.close()

That took about 39 seconds.

My second attempt was as follows:
volumeFile = open("/tmp/test2.raw","wb")
data.resize((X*Y*Z)) # Flatten the array
for i in data:
volumeFile.write("%c" %i)
data.resize((Z,Y,X))
volumeFile.close()

This took 32 seconds.  (For those of you unfamiliar with numpy, the
data.resize() operations take negligible amounts of time, all it does is
allow the data to be accessed differently.)

I'm guessing that the slow part is the fact that I am converting the
data to character format and writing it one character at a time.  What
is a better way of doing this, or where should I look to find a better way?


Thanks,

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


Re: how is python not the same as java?

2006-11-09 Thread Ray

[EMAIL PROTECTED] wrote:

> Jython exists.

And Pava (or Pyava) doesn't, you mean?

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


Re: Searching for a module to generate GUI events

2006-11-09 Thread Stephan Kuhagen
utabintarbo wrote:

> http://pywinauto.pbwiki.com/ for Win32

Thanks for the hint, looks usable. But it seems, there's nothing for X11 and
MacOSX. I didn't thought, that the problem would be so unusual...

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


Re: how is python not the same as java?

2006-11-09 Thread p . lavarre
Jython exists.

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


to Doctest as SystemExit is to Python

2006-11-09 Thread p . lavarre
> From: http://docs.python.org/lib/doctest-soapbox.html ...
> Regression testing is best confined to dedicated objects or files ...

Can I somehow tell doctest that it's time to quit?

I ask because not all doctest examples are created equal.  Some
failures are catastrophic, making all subsequent failures at least
uninteresting, and maybe painfully slow.  Other failures are
negligible, making the print of any subsequent failure valuable.

So sys.exit() doesn't do what I mean: it raises SystemExit, but doctest
redefines the SystemExit exception to mean print a traceback, rather
than meaning to exit quietly after a noisily catastrophic failure,
exiting almost as if the doctest had passed.

And doctest.REPORT_ONLY_FIRST_FAILURE doesn't do what I mean: it prints
only the first failure, always, never the valuable subsequent failures.

Can doctest somehow be persuaded to do the right thing?  That is, to
exit after a catastrophic failure, but not after a negligible failure,
and not after an independent failure?

In the last Python I shipped, to get the effect of exit after
catastrophe, I actually faked a run of doctest:

print 'Expected:'
print "'...'"
print 'Got:'
print "" + repr(result)
print '***Test Failed***'
sys.exit(-1)

Surely that's wrong?  Somehow not idiomatic Python?

Surely I can somehow tell doctest that my code has just realised,
sorry, it is time to quit?

Thanks in advance, Pat LaVarre

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


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Bill Maxwell
On 8 Nov 2006 11:49:07 -0800, "John Henry" <[EMAIL PROTECTED]>
wrote:

>
>John Salerno wrote:
>> Dan Lenski wrote:
>>
>> > So, is there another toolkit I should be looking at?
>>
>> I highly recommend wxPython. It's very mature, full-featured, and
>> portable, and fairly easy to learn as well. I can't really compare it to
>> other toolkits (not having used any of them, except Tkinter), but it's
>> definitely one of the most popular and well-supported ones out there.
>>
>> http://www.wxpython.org/
>
>I highly recommend that you try PythonCard (which sits on top of
>wxPython).  You can get productive very very quickly.  Take a look at:
>
>http://pythoncard.sourceforge.net/walkthrough1.html


I took a brief look at PythonCard almost a year ago and got discouraged
by what I found, so I stopped looking at it.  I've inserted my notes
from back then, below.  Does anybody know if these things have been
fixed in the latest release?

Bill


=
My notes from Fri Dec-23-2005:

This is a list of gripes I have while trying to learn about PythonCard.
I'm trying to investigate various GUI builders for Python, and
PythonCard looks promising, but a lot of things are getting in the way.

I installed yesterday, using this installer:
PythonCard-0.8.1.FIXED.win32.exe

A)  The very first example in the tutorial is wrong!  

On this page:  http://pythoncard.sourceforge.net/documentation.html
When you follow this link to try something for the very first time:

Getting Started in PythonCard by Dan Shafer: 
http://pythoncard.sourceforge.net/walkthrough1.html

You quickly see that the minimal.py example doesn't even contain
this line, even though the tutorial refers to it:

def on_menuFileAbout_select(self, event):

And, of course, if you replace the word "pass" with this, as
instructed:

result = dialog.alertDialog(self, 'It works!', 'Showing Off')

it won't run, because the existing "pass" line isn't inside a def
inside of a class.


B)  Is the Notebook widget really supported?

In the installed file "changelog.txt" (gets installed as part of
PythonCard installation), it says:

"added Notebook component, PageBackground, and testNotebook
sample"

But, the testNotebook sample is nowhere to be found.

I looked lots of places, including the main SourceForge web site,
and on the wiki, here:

http://wiki.wxpython.org/index.cgi/PythonCard

Both the main website and the wiki seem way out of date, and the
latest dates I could find on both of them are sometime in 2004.

Finally, by following the mailing list archive link on the main
website, I managed to find a reference to the notebook component on the
ASPN site, where some guy named Brian wonders about the same thing as
me, concerning the availability of the notebook component:

http://aspn.activestate.com/ASPN/Mail/Message/pythoncard/2536825

and, that message led me here:

http://article.gmane.org/gmane.comp.python.pythoncard/1060

where Kevin Altis admits that he forgot to include it in the 0.8.1
release!  At least he provides a way to download it separately.  But,
gheesh, this is pretty poor for a new user.  I was interested in using
the notebook component right away, because I looked at the wxGlade
tutorial before looking at PythonPage, and they use the notebook
component in their example (and I decided I really want to use the
component).

To add insult to injury, after you download the zip file with the
testNotebook stuff, the readme file says this:

"Until we have a Notebook integrated into some of the other
samples or tools this will serve as a basic test app, but I don't expect
to include it in releases."

C)  Are the websites being maintained?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how is python not the same as java?

2006-11-09 Thread Ben Finney
Steve Holden <[EMAIL PROTECTED]> writes:

> Java is horrible, Oython is not.

Is that the predecessor to Python, the one that could only be
expressed in vowel noises?

-- 
 \"Beware of and eschew pompous prolixity."  -- Charles A. |
  `\ Beardsley |
_o__)  |
Ben Finney

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


Re: how is python not the same as java?

2006-11-09 Thread Tim Chase
> Java is horrible, Oython is not.

Oython...the new scripting language from down under...just a wee 
bit south of the island of Java...

g'day-mate'ly yers...

-tkc





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


Re: Having problems with urlparser concatenation

2006-11-09 Thread i80and
Thank you!  Fixed my problem perfectly!
Gabriel Genellina wrote:
> At Thursday 9/11/2006 20:23, i80and wrote:
>
> >I'm working on a basic web spider, and I'm having problems with the
> >urlparser.
> >[...]
> > SpliceStart = Website.find('', SpliceStart))
> >
> > ParsedURL =
> >urlparse((Website[SpliceStart+9:(SpliceEnd+1)]))
> > robotparser.set_url(ParsedURL.hostname + '/' +
> >'robots.txt')
> >-
> >Traceback (most recent call last):
> >   File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
> >line 120, in 
> > FindLinks(Website)
> >   File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
> >line 84, in FindLinks
> > robotparser.read()
> >   File "C:\Program Files\Python25\lib\robotparser.py", line 61, in read
> > f = opener.open(self.url)
> >   File "C:\Program Files\Python25\lib\urllib.py", line 190, in open
> > return getattr(self, name)(url)
> >   File "C:\Program Files\Python25\lib\urllib.py", line 451, in
> >open_file
> > return self.open_local_file(url)
> >   File "C:\Program Files\Python25\lib\urllib.py", line 465, in
> >open_local_file
> > raise IOError(e.errno, e.strerror, e.filename)
> >IOError: [Errno 2] The system cannot find the path specified:
> >'en.wikipedia.org\\robots.txt'
> >
> >Note the last line 'en.wikipedia.org\\robots.txt'.  I want
> >'en.wikipedia.org/robots.txt'!  What am I doing wrong?
>
> No, you don't want 'en.wikipedia.org/robots.txt'; you want
> 'http://en.wikipedia.org/robots.txt'
> urllib treats the former as a file: request, here the \\ in the
> normalized path.
> You are parsing the link and then building a new URI using ONLY the
> hostname part; that's wrong. Use urljoin(ParsedURL, '/robots.txt') instead.
>
> You may try Beautiful Soup for a better HTML parsing.
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

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


Re: pack a three byte int

2006-11-09 Thread Gabriel Genellina

At Friday 10/11/2006 00:08, [EMAIL PROTECTED] wrote:


> > >>> import binascii
> > >>> cdb = binascii.unhexlify('%02X%06X%02X%02X' % (0x08, 
0x12345, 0x80, 0))

> > >>> binascii.hexlify(cdb)
> >'080123458000'
>
> The only problem I can see is that this code is endianness-dependent;
> the suggested versions using pack(">...") not. But this may not be of
> concern to you.

Thanks for cautioning us.  I suspect we agree:

i) pack('>...') can't say three byte int.
ii) binascii.hexlify evals bytes in the order printed.
iii) %X prints the bytes of an int in big-endian order.
iv) struct.unpack '>' of struct.pack '<' flips the bytes of an int
v) struct.unpack '<' of struct.pack '>' flips the bytes of an int
vi) [::-1] flips a string of bytes.


Yes to all.


In practice, all my lil-endian structs live by the C/Python-struct-pack
law requiring the byte size of a field to be a power of two, so I can
use Python-struct-pack to express them concisely.  Only my big-endian
structs are old enough to violate that recently (since ~1972)
popularised convention, so only those do I construct with
binascii.unhexlify.


So you would have no problems. I stand corrected: the code above will 
always generate big-endian numbers.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how is python not the same as java?

2006-11-09 Thread Steve Holden
gavino wrote:
> both are interpreted oo langauges..
> 
Java is horrible, Oython is not.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Excel file read/write?

2006-11-09 Thread John Machin

Podi wrote:

>
> >
> > 2. OpenOffice.org has a built-in Python -- 2.n where n is a small
> > number :-( and almost impenetrable documentation -- Sybren Stuvel has
> > published some examples: http://www.stuvel.eu/ooo-python
> > but my guess is that all the users of the OOo interface could fit in a
> > taxi.
>
> Hmmm..., I have 2.4.2 and would not like to down grade myself.

It is a separate installation of Python, somewhere in the OOo directory
hierarchy. You would have to "down grade" yourself only when working
with OOo. In any case the documentation and the size of the user base
are showstoppers IMHO.

Cheers,
John

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


Re: how is python not the same as java?

2006-11-09 Thread Paddy

gavino wrote:

> both are interpreted oo langauges..

One can curl; the other, one can suck!

(Its early, I'm sure this will not be as funny at more decent hours).

Gavino, I suggest you take a very small problem, something like
computing pascals triangle for example, and write implementations in
both languages yourself.

- Paddy.

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


Re: pack a three byte int

2006-11-09 Thread p . lavarre
> > ... Python can say six-nybble hex:
> >
> > >>> import binascii
> > >>> cdb = binascii.unhexlify('%02X%06X%02X%02X' % (0x08, 0x12345, 0x80, 0))
> > >>> binascii.hexlify(cdb)
> >'080123458000'
>
> The only problem I can see is that this code is endianness-dependent;
> the suggested versions using pack(">...") not. But this may not be of
> concern to you.

Thanks for cautioning us.  I suspect we agree:

i) pack('>...') can't say three byte int.
ii) binascii.hexlify evals bytes in the order printed.
iii) %X prints the bytes of an int in big-endian order.
iv) struct.unpack '>' of struct.pack '<' flips the bytes of an int
v) struct.unpack '<' of struct.pack '>' flips the bytes of an int
vi) [::-1] flips a string of bytes.

In practice, all my lil-endian structs live by the C/Python-struct-pack
law requiring the byte size of a field to be a power of two, so I can
use Python-struct-pack to express them concisely.  Only my big-endian
structs are old enough to violate that recently (since ~1972)
popularised convention, so only those do I construct with
binascii.unhexlify.

Often I wrap a big-endian struct in a lil-endian struct, but I'm ok
calling hexlify to make the big-endian struct and then catenating it
into the lil-endian struct, e.g., in the following cdb is big-endian
inside cbwBytes:

cbwBytes = struct.pack('http://mail.python.org/mailman/listinfo/python-list


Re: urllib en https

2006-11-09 Thread Podi

> > As I recall, ActiveState doesn't distribute the SSL package that the
> > python.org package contains. But... It is possible to copy the SSL
> > related files from a python.org package into the ActiveState
> > installation.
>

Are there any instructions on doing this? My Python installation from
cygwin seems to have SSL but not the ActiveState. However, I really
like the ActiveState PythonWin UI.

I would be much appreciated if anyone can provide pointer to get the
SSL in AS Python to work.

Thanks in advance.
P

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


Registrations are open for tutorials at OSDC 2006

2006-11-09 Thread Richard Jones
Time is running out to register for tutorials at the Open Source
Developers' Conference 2006 tutorial program:

http://www.osdc.com.au/registration/index.html

The tutorials run on the 5th December, followed by the technical program on
the 6th - 8th December.  Most tutorials include printed reference material.
Our tutorial program is included below:

Room 1 Room 2

 9:00am Cascading Style Sheets Open Source Python GIS Hacks
12:30pm Lunch  Lunch
 1:30pm Test Web Apps with PerlDrupal Tutorial
 3:00pm  Afternoon tea  Afternoon tea
 3:30pm Intro to Perl Template::ToolkitLarge Scale Web Apps

A morning tea break will occur roughly half way through the the 9am -
12:30pm tutorials.

For more information on what each tutorial covers, please visit:

http://www.osdc.com.au/papers/tutorials.html

Prices and information on how to register can be found at:

http://www.osdc.com.au/registration/index.html

You can help us make this conference be the best developers' conference
this year just by turning up and participating!  We look forward to sharing
this great conference with you.

If your business would like to benefit from exposure to many of Australia's
best open source developers then perhaps you should consider sponsorship.
We have a wide range of sponsorship options, to find out more information
please visit: http://www.osdc.com.au/sponsors/index.html

Richard Jones
OSDC Program Chair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how is python not the same as java?

2006-11-09 Thread John Machin

Jorge Vargas wrote:
> On 9 Nov 2006 16:44:40 -0800, gavino <[EMAIL PROTECTED]> wrote:
> > both are interpreted oo langauges..
> >
> that is not correct java is compiled and the VM interprets the code

... and what do you think is in those pesky little .pyc files you may
have noticed lying around on your hard disk?

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


Re: Excel file read/write?

2006-11-09 Thread Podi
Thanks for the reply.

>
> Most folk would seem to be using pyExcelerator rather than pyXLWriter.
> It is much more up to date, it just hasn't been worked on for a year,

I will give it a shot.

> 1. Python COM interface (part of
> http://sourceforge.net/projects/pywin32/) with lots of users (and hence
> readily available help in this newsgroup), examples, etc -- but
> requires (a) Windows OS (b) Microsoft Excel

I am not into COM as it is kind of anti-intuitive, at least to me.

>
> 2. OpenOffice.org has a built-in Python -- 2.n where n is a small
> number :-( and almost impenetrable documentation -- Sybren Stuvel has
> published some examples: http://www.stuvel.eu/ooo-python
> but my guess is that all the users of the OOo interface could fit in a
> taxi.

Hmmm..., I have 2.4.2 and would not like to down grade myself.

>
> 3. Gnumeric is rumoured to have a similar scripting facility.

Well, I would like to stick with the MS crowd, at least for the moment.

Cheers!
P

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


Re: comparing Unicode and string

2006-11-09 Thread John Machin

Neil Cerutti wrote:
> On 2006-10-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > here is something that surprises me.
> >
> >   #coding: iso-8859-1
>
> I think that's supposed to be:
>
> # -*- coding: iso-8859-1 -*-
>

Not quite. As PEP 263 says:

"""
More precisely, the first or second line must match the regular
expression "coding[:=]\s*([-\w.]+)". 
"""

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


Re: pack a three byte int

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 22:24, [EMAIL PROTECTED] wrote:


Perhaps Python can't concisely say three-byte int ...

But Python can say six-nybble hex:

>>> import binascii
>>> cdb = binascii.unhexlify('%02X%06X%02X%02X' % (0x08, 0x12345, 0x80, 0))
>>> binascii.hexlify(cdb)
'080123458000'


The only problem I can see is that this code is endianness-dependent; 
the suggested versions using pack(">...") not. But this may not be of 
concern to you.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Excel file read/write?

2006-11-09 Thread John Machin

Podi wrote:
> As far as I know, there is pyXLWriter for writing and xlrd for reading.

Most folk would seem to be using pyExcelerator rather than pyXLWriter.
It is much more up to date, it just hasn't been worked on for a year,
whereas pyXLWriter is obsolete (doesn't write latest Excel file format)
and is deliberately/officially in Norwegian Blue Parrot emulation mode.

> Is there such thing so that one can open an Excel file into memory and
> read/update any sheet/cell on the fly. One analogy to this is the
> ConfigParser module.

There is no pure Python platform-independent facility that requires no
other software to be installed. Your choices are:

1. Python COM interface (part of
http://sourceforge.net/projects/pywin32/) with lots of users (and hence
readily available help in this newsgroup), examples, etc -- but
requires (a) Windows OS (b) Microsoft Excel

2. OpenOffice.org has a built-in Python -- 2.n where n is a small
number :-( and almost impenetrable documentation -- Sybren Stuvel has
published some examples: http://www.stuvel.eu/ooo-python
but my guess is that all the users of the OOo interface could fit in a
taxi.

3. Gnumeric is rumoured to have a similar scripting facility.

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


Re: how is python not the same as java?

2006-11-09 Thread Jorge Vargas
On 9 Nov 2006 16:44:40 -0800, gavino <[EMAIL PROTECTED]> wrote:
> both are interpreted oo langauges..
>
that is not correct java is compiled and the VM interprets the code
from the programmers point  of view java is a compiled languaje.

python is dynamic typed java is static
python allows functional programming as well as procedural, java doesn't
java is OO in the API, python is OO everywhere.

tons of other things
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question to split

2006-11-09 Thread Tiefeng Wu
Matthias Winterland wrote:
> Hi,
>
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a 
> single split-call?
>
> Thx,
> Matthias

Sorry, I didn't notice there are spaces between 5 6 7 :{P
here is new code:
>>> a = "1,2,3,4,5 6 7,3,4"
>>> l = [int(n) for n in a.replace(' ',',').split(',')]
>>> l
[1, 2, 3, 4, 5, 6, 7, 3, 4]
>>>

wutiefeng
2006-11-10



___ 
抢注雅虎免费邮箱-3.5G容量,20M附件! 
http://cn.mail.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Simple question to split

2006-11-09 Thread Tiefeng Wu
Matthias Winterland wrote:
> Hi,
>
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a 
> single split-call?
>
> Thx,
> Matthias

Maybe like this:

>>> a = "1,2,3,4,5,6,7,3,4"
>>> l = [int(n) for n in a.split(',')]
>>> l
[1, 2, 3, 4, 5, 6, 7, 3, 4]
>>>



___ 
雅虎免费邮箱-3.5G容量,20M附件 
http://cn.mail.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pack a three byte int

2006-11-09 Thread John Machin

[EMAIL PROTECTED] wrote:
> Speaking as the OP, perhaps I should mention:
>
> > > [-3:] to [1:] is a minor cosmetic improvement
>
> To my eye, that's Not an improvement.
>
> '\x08' '\x01\x23\x45' '\x80' '\0' is the correct pack of (0x08,
> 0x12345, 0x80, 0) because '\x01\x23\x45' are the significant low three
> bytes of a big-endian x12345, thus [-3:].
>
> The [1:] fact that we can keep the 3 significant bytes by tossing
> exactly 1 byte away after rounding the bit length of that digital
> number up to the nearest power of two which happens to be 4 = 3 + 1 is
> merely incidental - not of central significance.

I said *cosmetic* improvement and also said "obscures the underlying"
need-to-know that 4 - 3 == 1 (which I didn't contemplate needing 2
paragraphs of laborious explanation).

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


Re: pack a three byte int

2006-11-09 Thread John Machin

[EMAIL PROTECTED] wrote:


>
> Pack ' these things.
>
> The people who wrote this stuff forty years ago were thinking of bit
> fields - here bit lengths of 8 then 3 then 21 then 8 then 8 bits -
> cheating only when the bit boundaries happened to hit byte boundaries.
>
> Yes, as you describe in this example, I could cheat when the boundaries
> happen to hit H or I boundaries as well, but then I'm still left coping
> with the cases where the fields split on byte boundaries that are not H
> or I boundaries, such as the example:
>
> Am I helping?

Yes, you have *finally* said unambiguously what your problem really is
-- field lengths not a multiple of 8 bits. I suggest that you start a
new thread, write it out logically and ask for assistance. You should
get some sensible answers. I will apologise in advance for not
participating; I'm exhausted.

Cheers,
John

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


Re: Tkinter check box behaviour - Windows / Linux discrepancy

2006-11-09 Thread jim-on-linux
Peter,
You already have an answer to you question but if 
you want to fancy up your program you could 
replace;


   
self.chkTest.bind('',
self.chkTest_click)
>
with
>
self.chkTest.bind('',self.chkTest_click0)

or some other acceptable key from the keyboard
>


def chkTest_click0(self,event):
self.chkTest_click()


def chkTest_click(self):
 # read check box state and display
   appropriate text 
   if self.intTest.get()==0:
 self.lblTest.config(text='Check box
 cleared') 
   else:
 self.lblTest.config(text='Check box
 set')



jim-on-linux
http://www.inqvista.com



On Thursday 09 November 2006 18:28, peter wrote:
> I've come across a weird difference between the
> behaviour of the Tkinter checkbox in Windows
> and Linux.  The issue became apparent in some
> code I wrote to display an image in a fixed
> size canvas widget. If a checkbox was set then
> the image should be shrunk as necessary to fit
> the canvas while if cleared it should appear
> full size with scrollbars if necessary.
>
> The code worked fine under Linux (where it was
> developed).  But under Windows, the first click
> in the checkbox did nothing, then subsequent
> clicks adjusted the size according to the
> PREVIOUS, not the current, checkbox state.
>
> I've isolated the problem in the code below,
> which shows a single checkbox and a label to
> describe its state. It works ok under Linux,
> but in Windows it is always one click behind.
>
> Any ideas?  I am using
>Linux: Fedora Core 3, Python 2.3.4
>Windows: Windows NT, Python 2.3.4
>
> Peter
>
> ===
>= import Tkinter as tk
>
>
>
> class App:
>
> def __init__(self,frmMain):
>
> """
> Demonstrate difference in Windows /
> Linux handling of check box
>
> Text in lblTest should track check box
> state """
>
> # Set up form
>
> self.intTest=tk.IntVar()
>
>
> self.chkTest=tk.Checkbutton(frmMain,text='Click
> me!',variable=self.intTest)
>
>
> self.chkTest.grid(row=0,column=0,padx=5,pady=5,
>sticky=tk.W)
>
>
> self.chkTest.bind('',self.chkT
>est_click)
>
>
>
>
> self.lblTest=tk.Label(frmMain,text='Dummy')
>
>
> self.lblTest.grid(row=1,column=0,padx=5,pady=5,
>sticky=tk.W)
>
>
> self.chkTest_click() # so as to
> initialise text
>
> def chkTest_click(self,event=None):
> # read check box state and display
> appropriate text if self.intTest.get()==0:
> self.lblTest.config(text='Check box
> cleared') else:
> self.lblTest.config(text='Check box
> set')
>
>
>
>
> if __name__=='__main__':
>
> frmMain=tk.Tk()
>
> app=App(frmMain)
>
> frmMain.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pack a three byte int

2006-11-09 Thread p . lavarre
Perhaps Python can't concisely say three-byte int ...

But Python can say six-nybble hex:

>>> import binascii
>>> cdb = binascii.unhexlify('%02X%06X%02X%02X' % (0x08, 0x12345, 0x80, 0))
>>> binascii.hexlify(cdb)
'080123458000'
>>>

Thanks again for patiently helping me find this.  A shortcut is:

http://docs.python.org/lib/genindex.html
search: hex

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


Re: object data member dumper?

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 22:16, tom arnall wrote:


> I'd suggest you instead consider a mixin object that will add recursive
> data dump functionality to any such classes you require.

have googled a fair amount on 'mixin' but still stumped on it.


Try again using "mixin class"


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pack a three byte int

2006-11-09 Thread John Machin

[EMAIL PROTECTED] wrote:
> > "struct" == "Python struct module"
> >
> > Struct module has (concise) codes B, H, I, Q for unsigned integers of
> > lengths 1, 2, 4, 8, but does *not* have a code for 3-byte integers.
>
> I thought that's what the manual meant, but I was unsure, thank you.

If it doesn't have a code for 3-byte integers in the table of codes, it
doesn't have one. What's to be unsure about??

>
> > > > 1. Not as concisely as a one-byte struct code
> >
> > Looks like you ignored the first word in the sentence ("Not").
>
> I agree I have no confident idea of what your English meant.

"Not" is rather unambiguous.

>
> I guess you're hinting at the solution you think I should find obvious,
> without volunteering what that is.

I did volunteer what it is -- try reading the message again. You may
need to use the PageDown key :-)

>
> Yes?  If so, then:

No, not at all. Stop guessing. I ask again: have you read the solution
that I gave???
Here it is again:

"""
You could try throwing the superfluous bits away before packing instead
of after:

| >>> from struct import pack
| >>> skip = 0x123456; count = 0x80
| >>> hi, lo = divmod(skip, 0x1)
| >>> cdb = pack(">BBHBB", 0x08, hi, lo, count, 0)
| >>> ' '.join(["%02X" % ord(x) for x in cdb])
| '08 12 34 56 80 00'


>
> I guess for you "a one-byte struct code" is a 'B' provided as a "format
> character" of the fmt parameter of the struct.pack function.
>
> Yes?

Yes -- but I thought we were already over that.


> if so, then:

This does not follow.

>
> You recommend shattering the three byte int:

Yes, but not like that. See above.

>
> skip = 0x012345 ; count = 0x80
> struct.pack('>6B', 0x08, skip >> 0x10, skip >> 8, skip, count, 0)
>
> Except you know that chokes over:
>
> DeprecationWarning: 'B' format requires 0 <= number <= 255

That is not "choking" -- that is barfing; it is telling you that you
have done something silly.

>
> So actually you recommend:
>
> def lossypack(fmt, *args):
> return struct.pack(fmt, *[(arg & 0xFF) for arg in args])
> skip = 0x012345 ; count = 0x80
> lossypack('>6B', 0x08, skip >> 0x10, skip >> 8, skip, count, 0)
>
> Yes?

No, never, not in a pink fit.

>
> > > I guess you're asking me ...
> > > to show more plainly that indeed I am trying
> > > to make sense of every word of every answer

You guess wrongly.

> 
> Am I helping?

No.

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


Re: object data member dumper?

2006-11-09 Thread tom arnall
Steve Holden wrote:

> tom arnall wrote:
>> Steve Holden wrote:
>> 
>> 
>>>Bruno Desthuilliers wrote:
>>>
tom arnall a écrit :


>does anyone know of a utility to do a recursive dump of object data
>members?
>


What are "object data members" ? (hint: in Python, everything is an
object - even functions and methods).

What is your real use case ?
>>>
>>>Basically it sounds like the OP wants to see the attribute values for an
>>>object (and those objects' attribute values, ...). Presumably the
>>>recursive descent could be stopped at the built-in types.
>> 
>> 
>> Yes, exactly. But what is 'OP'?
>> 
> "original poster" (you)
>> 
>>>I'm not familiar with any such thing.
>> 
>> 
>> I'm amazed that there is no way to easily look at the fundamental data
>> structures of a python program. I'm new to python - is there something I
>> don't know about the territory in this regard?
>> 
> Well, new enough to be unaware that Python normally doesn't need such
> drastic measures for debugging. When you are building complex data
> structures such a form of output could get big really quickly. I've
> never come across anything like it in any other language that I have used.

never come across the complexity of data structures or across an object
displayer?

> 
> The most that's usually required is a __repr__() method that dumps the
> values of necessary data attributes.

what about __dict__?


>> 
>>>The code of the standard library's
>>>pprint module might be a good place to start
>> 
>> 
>> I played around with this but it seems more targetted to looking at
>> python objects as opposed to user-defined.
>> 
> It is, but it could be used as a basis for something more to your liking.
>> 
>>>(and the suggested
>>>functionality might make a nice addition if we could work out exactly
>>>what the requirement was).
>> 
>> 
>> I would be glad if people would comment on my example as a step in this
>> direction.
>> 
> I'd suggest you instead consider a mixin object that will add recursive
> data dump functionality to any such classes you require.

have googled a fair amount on 'mixin' but still stumped on it.




-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: pack a three byte int

2006-11-09 Thread p . lavarre
Speaking as the OP, perhaps I should mention:

> > [-3:] to [1:] is a minor cosmetic improvement

To my eye, that's Not an improvement.

'\x08' '\x01\x23\x45' '\x80' '\0' is the correct pack of (0x08,
0x12345, 0x80, 0) because '\x01\x23\x45' are the significant low three
bytes of a big-endian x12345, thus [-3:].

The [1:] fact that we can keep the 3 significant bytes by tossing
exactly 1 byte away after rounding the bit length of that digital
number up to the nearest power of two which happens to be 4 = 3 + 1 is
merely incidental - not of central significance.

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


Re: pack a three byte int

2006-11-09 Thread p . lavarre
> > when talking the 1960's lingo
> > ...
> > X12Inquiry = 0x12
> > xxs = [0] * 6
> > xxs[0] = X12Inquiry
> > xxs[4] = allocationLength
> > rq = ''.join([chr(xx) for xx in xxs])
>
> It looks wrong (and a few other adjectives),

Ah, we agree, thank you for saying.

> Looks like little-endian 4-byte integer
> followed by 2-byte integer ... what's wrong with struct.pack(" X12Inquiry, allocationLength) 

Pack ' > skip = 0x123456; count = 0x80
> > hi, lo = divmod(skip, 0x1)
>
> Does it do what you asked (one pack call instead of three)

One pack call, not three, yes.

Shatters the 3 byte int into 1 and 2 bytes by divmod of (0x + 1),
yes.

> > I guess you're asking me ...
> > to show more plainly that indeed I am trying
> > to make sense of every word of every answer 

Am I helping?

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


Re: comparing Unicode and string

2006-11-09 Thread [EMAIL PROTECTED]
Marc 'BlackJack' Rintsch wrote:
> Why?  Python strings are *byte strings* and bytes have values in the range
> 0..255.  Why would you restrict them to ASCII only?

Because getting an exception when comparing a string with a unicode
string is irritating.

But I don't insist on my PEP. The example just shows just another
pitfall with Unicode and why I'll advise to any beginner: Never write
text constants that contain non-ascii chars as simple strings, always
make them Unicode strings by prepending the "u".

Luc

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


Re: pack a three byte int

2006-11-09 Thread p . lavarre
> "struct" == "Python struct module"
>
> Struct module has (concise) codes B, H, I, Q for unsigned integers of
> lengths 1, 2, 4, 8, but does *not* have a code for 3-byte integers.

I thought that's what the manual meant, but I was unsure, thank you.

> > > 1. Not as concisely as a one-byte struct code
>
> Looks like you ignored the first word in the sentence ("Not").

I agree I have no confident idea of what your English meant.

I guess you're hinting at the solution you think I should find obvious,
without volunteering what that is.

Yes?  If so, then:

I guess for you "a one-byte struct code" is a 'B' provided as a "format
character" of the fmt parameter of the struct.pack function.

Yes?  if so, then:

You recommend shattering the three byte int:

skip = 0x012345 ; count = 0x80
struct.pack('>6B', 0x08, skip >> 0x10, skip >> 8, skip, count, 0)

Except you know that chokes over:

DeprecationWarning: 'B' format requires 0 <= number <= 255

So actually you recommend:

def lossypack(fmt, *args):
return struct.pack(fmt, *[(arg & 0xFF) for arg in args])
skip = 0x012345 ; count = 0x80
lossypack('>6B', 0x08, skip >> 0x10, skip >> 8, skip, count, 0)

Yes?

> > I guess you're asking me ...
> > to show more plainly that indeed I am trying
> > to make sense of every word of every answer

Am I helping?

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


Re: pack a three byte int

2006-11-09 Thread p . lavarre
> Help, what did you mean by the question?

How does Python express the idea:

i) Produce the six bytes '\x08' '\x01\x23\x45' '\x80' '\0' at run-time
when given the tuple (0x08, 0x12345, 0x80, 0).

ii) Produce the six bytes '\x12' '\0\0\0' '\x24' '\0' when given the
tuple (0x12, 0, 0x24, 0).

iii) And so on.

So far, everything I write is ugly.  Help?

> Looks like you ignored ...

I guess you're asking me to leave the mystery of my question alone long
enough to show more plainly that indeed I am trying to make sense of
every word of every answer.

I guess I should do that in separate replies, cc'ed back into this same
thread.  Please stay tuned.

Thanks in advance, Pat LaVarre

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


Re: how is python not the same as java?

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 21:44, gavino wrote:


both are interpreted oo langauges..


I'd use Google to find thousands of references...


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

how is python not the same as java?

2006-11-09 Thread gavino
both are interpreted oo langauges..

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


Excel file read/write?

2006-11-09 Thread Podi
As far as I know, there is pyXLWriter for writing and xlrd for reading.
Is there such thing so that one can open an Excel file into memory and
read/update any sheet/cell on the fly. One analogy to this is the
ConfigParser module.

Any info would be much appreciated.

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


Re: urlretrieve get file name

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 20:52, Sven wrote:


Thanks for your help, but I'm a guy with no luck. :-) I can't get the
file name from response header...


Try using a browser and "Save as..."; if it suggests a file name, it 
*must* be in the headers - so look again carefully.
If it does not suggests a filen ame, the server is not providing one 
(there is no obligation to do so).



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter check box behaviour - Windows / Linux discrepancy

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 20:28, peter wrote:


I've come across a weird difference between the behaviour of the
Tkinter checkbox in Windows and Linux.  The issue became apparent in
some code I wrote to display an image in a fixed size canvas widget. If
a checkbox was set then the image should be shrunk as necessary to fit
the canvas while if cleared it should appear full size with scrollbars
if necessary.

The code worked fine under Linux (where it was developed).  But under
Windows, the first click in the checkbox did nothing, then subsequent
clicks adjusted the size according to the PREVIOUS, not the current,
checkbox state.

I've isolated the problem in the code below, which shows a single
checkbox and a label to describe its state. It works ok under Linux,
but in Windows it is always one click behind.




self.chkTest=tk.Checkbutton(frmMain,text='Click
me!',variable=self.intTest)

self.chkTest.bind('',self.chkTest_click)


Your code works fine in Linux just by accident. The action of button 
widgets must be associated to "command"; as you see, when the mouse 
button is released, the associated variable might not have been updated.

Remove that bind call, and use:

self.chkTest=tk.Checkbutton(frmMain,text='Click 
me!',variable=self.intTest, command=chkTest_click)


(Should work fine on every platform - I've just tested on Windows)
The command is fired after the mouse up event, and *only* if the 
previous mouse down was over the same widget. Your code doesn't work 
either if the user presses SPACE to toggle the button state; using 
"command" works fine in this case too.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Py3K idea: why not drop the colon?

2006-11-09 Thread Dan Lenski
Ben Finney wrote:
> > I think the colon could be omitted from every type of compound
> > statement: 'if', 'for', 'def', 'class', whatever. Am I missing
> > anything?
>
> A use case. What problem is being solved by introducing this
> inconsistency?

I agree completely.  And as a recent convert to Python, I have to say
that I *like* the colons.  I found the whitespace-and-colon thing
really irritating... for about 2 hours.

The colon makes it easier to eyeball where a block statement begins in
the absence of braces around the block, it allows one-line if
statements (which I use a lot), and it means that even the stupidest,
simplest editor can figure out where auto-indentation is needed, namely
following any line that ends with a colon (except in a triple-quoted, I
guess).

Contrast that with Perl, where in years of professional and hobby use I
have not found a single editor that gets indentation right more than
about 90% of the time.  The syntax is too darn complicated.  With
Python, figuring out where to auto-indent is trivial.  Works for me.

Dan

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


Re: Py3K idea: why not drop the colon?

2006-11-09 Thread Ben Finney
Please don't hide your new thread as a reply to an existing, unrelated
message. Start a new message if your message isn't actually a reply.

Michael Hobbs <[EMAIL PROTECTED]> writes:

> Can anyone find a flaw with this change in syntax?
>
> Instead of dividing a compound statement with a colon, why not
> divide it on a newline? For example, the colon could be dropped from
> this statement:
> if self.hungry:
> self.eat()
> to
> if self.hungry
> self.eat()

But it can't be dropped from this statement:

if self.hungry: self.eat()

> The colon that divides the statement therefore seems redundant. The
> colon could continue to be used for single-line statements:
> if self.hungry: self.eat()

Why have two different syntaxes for the same statement?

> I think the colon could be omitted from every type of compound
> statement: 'if', 'for', 'def', 'class', whatever. Am I missing
> anything?

A use case. What problem is being solved by introducing this
inconsistency?

-- 
 \  "The shortest distance between two points is under |
  `\   construction."  -- Noelie Alito |
_o__)  |
Ben Finney

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


Re: urlretrieve get file name

2006-11-09 Thread Sven
Hello Gabriel,

Thanks for your help, but I'm a guy with no luck. :-) I can't get the
file name from response header...

On Nov 10, 12:39 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> At Thursday 9/11/2006 19:11, Sven wrote:
>
> >I'm wrestling with the urlretrieve function in the urllib module. I
> >want to download a file from a web server and save it locally with the
> >same name. The problem is the URL - it's on the form
> >http://www.page.com/?download=12345. It doesn't reveal the file name.
> >Some hints to point me in the right direction are greatly appreciated.The 
> >file name *may* come in the Content-Disposition header (ex:
> Content-Disposition: attachment; filename="budget.xls")
> Use urlopen to obtain a file-like object; its info() method gives you
> those headers.
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> ¡Abrí tu cuenta ya! -http://correo.yahoo.com.ar

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


Re: Having problems with urlparser concatenation

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 20:23, i80and wrote:


I'm working on a basic web spider, and I'm having problems with the
urlparser.
[...]
SpliceStart = Website.find('', SpliceStart))

ParsedURL =
urlparse((Website[SpliceStart+9:(SpliceEnd+1)]))
robotparser.set_url(ParsedURL.hostname + '/' +
'robots.txt')
-
Traceback (most recent call last):
  File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 120, in 
FindLinks(Website)
  File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 84, in FindLinks
robotparser.read()
  File "C:\Program Files\Python25\lib\robotparser.py", line 61, in read
f = opener.open(self.url)
  File "C:\Program Files\Python25\lib\urllib.py", line 190, in open
return getattr(self, name)(url)
  File "C:\Program Files\Python25\lib\urllib.py", line 451, in
open_file
return self.open_local_file(url)
  File "C:\Program Files\Python25\lib\urllib.py", line 465, in
open_local_file
raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified:
'en.wikipedia.org\\robots.txt'

Note the last line 'en.wikipedia.org\\robots.txt'.  I want
'en.wikipedia.org/robots.txt'!  What am I doing wrong?


No, you don't want 'en.wikipedia.org/robots.txt'; you want 
'http://en.wikipedia.org/robots.txt'
urllib treats the former as a file: request, here the \\ in the 
normalized path.
You are parsing the link and then building a new URI using ONLY the 
hostname part; that's wrong. Use urljoin(ParsedURL, '/robots.txt') instead.


You may try Beautiful Soup for a better HTML parsing.

--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pack a three byte int

2006-11-09 Thread John Machin
[EMAIL PROTECTED] wrote:
> > Not as concisely as a one-byte struct code
>
> Help, what do you mean?

Help, what did you mean by the question?

"struct" == "Python struct module"

Struct module has (concise) codes B, H, I, Q for unsigned integers of
lengths 1, 2, 4, 8, but does *not* have a code for 3-byte integers.

>
> > you presumably... read... the manual ...
>
> Did I reread the wrong parts?  I see I could define a ctypes.Structure
> since 2.5, but that would be neither concise, nor since 2.3.

Looks like you ignored the first word in the sentence ("Not").

>
> > when 24-bit machines become ... popular
>
> Indeed the struct's defined recently, ~1980, were contorted to make
> them easy to say in C, which makes them easy to say in Python, e.g.:
>
> X28Read10 = 0x28
> cdb = struct.pack('>BBIBHB', X28Read10, 0, skip, 0, count, 0)
>
> But when talking the 1960's lingo I find I am actually resorting to
> horrors like:
>
> X12Inquiry = 0x12
> xxs = [0] * 6
> xxs[0] = X12Inquiry
> xxs[4] = allocationLength
> rq = ''.join([chr(xx) for xx in xxs])
>
> Surely this is wrong?  A failure on my part to think in Python?

It looks wrong (and a few other adjectives), irrespective of what
problem it is trying to solve. Looks like little-endian 4-byte integer
followed by 2-byte integer ... what's wrong with struct.pack("http://mail.python.org/mailman/listinfo/python-list


Re: pack a three byte int

2006-11-09 Thread p . lavarre
> > > cdb0 = '\x08' '\x01\x23\x45' '\x80' '\0'
> >
> > cdb = ''
> > cdb += struct.pack('>B', 0x08)
> > cdb += struct.pack('>I', skip)[-3:]
> > cdb += struct.pack('>BB', count, 0)
>
> The change from [-3:] to [1:] is a minor cosmetic improvement,

Ouch, [1:] works while sizeof I is 4, yes, but that's not what I meant,
more generally.

Something else I tried that doesn't work is:

skip = 0x12345 ; count = 0x80
struct.pack('>8b3b21b8b8b', 0x08, 0, skip, count, 0)

That doesn't work, because in Python struct b means signed char, not
bit; and a struct repeat count adds fields, rather than making a field
wider.

But do you see what I mean?  The fields of this struct have 8, 3, 21,
8, and 8 bits.  The "skip" field has 21 bits, the "count" field has 8
bits, I'd like to vary both of those.

> why do you want to do that to concise working code???

cdb0 = '\x08' '\x01\x23\x45' '\x80' '\0'
works, but it's not parameterised.  Writing out the hex literal always
packs the same x12345 and x80 values into those 21 and 8 bit fields.

I see I can concisely print and eval the big-endian hex:

X08Read6 = 0x08
skip = 0x12345 ; count = 0x80
hex = '%02X' % X08Read6 + ('%06X' % skip) + ('%02X' % count) + '00'
''.join([chr(int(hex[ix:ix+2],0x10)) for ix in range(0,len(hex),2)])

But that's ugly too.  Maybe least ugly so far, if I bury the
join-chr-int-for-range-len-2 in a def.

Is there no less ugly way to say pack bits, rather than pack bytes, in
Python?

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


Re: Having problems with urlparser concatenation

2006-11-09 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, i80and wrote:

> return self.open_local_file(url)
>   File "C:\Program Files\Python25\lib\urllib.py", line 465, in
> open_local_file
> raise IOError(e.errno, e.strerror, e.filename)
> IOError: [Errno 2] The system cannot find the path specified:
> 'en.wikipedia.org\\robots.txt'
> 
> Note the last line 'en.wikipedia.org\\robots.txt'.  I want
> 'en.wikipedia.org/robots.txt'!  What am I doing wrong?

You don't have that file on you local computer.  :-)

If you look at the messages above you'll see there's a function
`open_local_file()` involved.  This function is chosen by `urllib` because
your path looks like a local file, i.e. it lacks the protocol information.
You don't want 'en.wikipedia.org/robots.txt', you want
'http://en.wikipedia.org/robots.txt'!

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


Re: urlretrieve get file name

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 19:11, Sven wrote:


I'm wrestling with the urlretrieve function in the urllib module. I
want to download a file from a web server and save it locally with the
same name. The problem is the URL - it's on the form
http://www.page.com/?download=12345. It doesn't reveal the file name.
Some hints to point me in the right direction are greatly appreciated.


The file name *may* come in the Content-Disposition header (ex: 
Content-Disposition: attachment; filename="budget.xls")
Use urlopen to obtain a file-like object; its info() method gives you 
those headers.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how to create a multicolor "font-string" in pygame??

2006-11-09 Thread Diez B. Roggisch
Diez B. Roggisch schrieb:
> [EMAIL PROTECTED] schrieb:
>> Hi! I need to manipulate multicolor strings, i.e. strings with a color
>> associated with each letter.
>> Any suggestions?
> 
> There is no support for multi-color strings as such in pygame. If you 
> use a fixed-width font, things are easy. Just create the strings one 
> after another using spaces as prefix. E.g.
> 
> back = (0,0,0)
> font = pygame.font.Font(font_fn, size)
> images = []
> for i, c in enumerate("colored string"):
> s = " " * i + c
> color = color_for_index(i)
> s_image = font.render(s, True, color, back)
> images.append(s_image)

Don't drink and code... *sigh*

Of course you can just create an equally dimensioned image for each 
character and each color (cached or not, however you like it), and just 
blit these one after another, offsetting them with the character width.

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


Tkinter check box behaviour - Windows / Linux discrepancy

2006-11-09 Thread peter
I've come across a weird difference between the behaviour of the
Tkinter checkbox in Windows and Linux.  The issue became apparent in
some code I wrote to display an image in a fixed size canvas widget. If
a checkbox was set then the image should be shrunk as necessary to fit
the canvas while if cleared it should appear full size with scrollbars
if necessary.

The code worked fine under Linux (where it was developed).  But under
Windows, the first click in the checkbox did nothing, then subsequent
clicks adjusted the size according to the PREVIOUS, not the current,
checkbox state.

I've isolated the problem in the code below, which shows a single
checkbox and a label to describe its state. It works ok under Linux,
but in Windows it is always one click behind.

Any ideas?  I am using
   Linux: Fedora Core 3, Python 2.3.4
   Windows: Windows NT, Python 2.3.4

Peter


import Tkinter as tk



class App:

def __init__(self,frmMain):

"""
Demonstrate difference in Windows / Linux handling of check box

Text in lblTest should track check box state
"""

# Set up form

self.intTest=tk.IntVar()

self.chkTest=tk.Checkbutton(frmMain,text='Click
me!',variable=self.intTest)

self.chkTest.grid(row=0,column=0,padx=5,pady=5,sticky=tk.W)

self.chkTest.bind('',self.chkTest_click)



self.lblTest=tk.Label(frmMain,text='Dummy')

self.lblTest.grid(row=1,column=0,padx=5,pady=5,sticky=tk.W)


self.chkTest_click() # so as to initialise text

def chkTest_click(self,event=None):
# read check box state and display appropriate text
if self.intTest.get()==0:
self.lblTest.config(text='Check box cleared')
else:
self.lblTest.config(text='Check box set')




if __name__=='__main__':

frmMain=tk.Tk()

app=App(frmMain)

frmMain.mainloop()

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


Having problems with urlparser concatenation

2006-11-09 Thread i80and
I'm working on a basic web spider, and I'm having problems with the
urlparser.
This is the effected function:
--
def FindLinks(Website):
WebsiteLen = len(Website)+1
CurrentLink = ''
i = 0
SpliceStart = 0
SpliceEnd = 0

LinksString = ""
LinkQueue = open('C:/LinkQueue.txt', 'a')

while (i < WebsiteLen) and (i != -1):

#Debugging info
#print '-'
#print 'Length = ' + str(WebsiteLen)
#print 'SpliceStart = ' + str(SpliceStart)
#print 'SpliceEnd = ' + str(SpliceEnd)
#print 'i = ' + str(i)

SpliceStart = Website.find('', SpliceStart))

ParsedURL =
urlparse((Website[SpliceStart+9:(SpliceEnd+1)]))
robotparser.set_url(ParsedURL.hostname + '/' +
'robots.txt')
robotparser.read()
if (robotparser.can_fetch("*",
(Website[SpliceStart+9:(SpliceEnd+1)])) == False):
i = i - 1
else:
LinksString = LinksString + "\n" +
(Website[SpliceStart+9:(SpliceEnd+1)])
LinksString = LinksString[:(len(LinksString) - 1)]
#print 'found ' + LinksString
i = SpliceEnd

LinkQueue.write(LinksString)
LinkQueue.close()
--
Sorry if it's uncommented.  When I run my program, I get this error:
-
Traceback (most recent call last):
  File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 120, in 
FindLinks(Website)
  File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 84, in FindLinks
robotparser.read()
  File "C:\Program Files\Python25\lib\robotparser.py", line 61, in read
f = opener.open(self.url)
  File "C:\Program Files\Python25\lib\urllib.py", line 190, in open
return getattr(self, name)(url)
  File "C:\Program Files\Python25\lib\urllib.py", line 451, in
open_file
return self.open_local_file(url)
  File "C:\Program Files\Python25\lib\urllib.py", line 465, in
open_local_file
raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified:
'en.wikipedia.org\\robots.txt'

Note the last line 'en.wikipedia.org\\robots.txt'.  I want
'en.wikipedia.org/robots.txt'!  What am I doing wrong?

If this has been answered before, please just give me a link to the
proper thread.  If you need more contextual code, I can post more.

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


Re: pack a three byte int

2006-11-09 Thread p . lavarre
> Not as concisely as a one-byte struct code

Help, what do you mean?

> you presumably... read... the manual ...

Did I reread the wrong parts?  I see I could define a ctypes.Structure
since 2.5, but that would be neither concise, nor since 2.3.

> when 24-bit machines become ... popular

Indeed the struct's defined recently, ~1980, were contorted to make
them easy to say in C, which makes them easy to say in Python, e.g.:

X28Read10 = 0x28
cdb = struct.pack('>BBIBHB', X28Read10, 0, skip, 0, count, 0)

But when talking the 1960's lingo I find I am actually resorting to
horrors like:

X12Inquiry = 0x12
xxs = [0] * 6
xxs[0] = X12Inquiry
xxs[4] = allocationLength
rq = ''.join([chr(xx) for xx in xxs])

Surely this is wrong?  A failure on my part to think in Python?

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


Re: Simple question to split

2006-11-09 Thread John Machin
Matthias Winterland wrote:
> Hi,
>
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a
> single split-call?
>

Using str method split, no -- as documented [hint!], it provides only a
single separator argument.

Using re.split function, yes -- as documented [hint!], it allows a
pattern as a separator.

The required pattern is simply expressed as "space or comma":

| import re
| >>> re.split('[, ]', '1,2,3,4,5 6 7,3,4')
| ['1', '2', '3', '4', '5', '6', '7', '3', '4']
| >>> [int(x) for x in re.split('[, ]', '1,2,3,4,5 6 7,3,4')]
| [1, 2, 3, 4, 5, 6, 7, 3, 4]

Cheers,
John

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


Re: Simple question to split

2006-11-09 Thread faulkner
def splits(seq, cs):
if not cs: return seq
elif isinstance(seq, str): return splits(seq.split(cs[0]), cs[1:])
else: return splits(sum([elem.split(cs[0]) for elem in seq], []),
cs[1:])

or
a = re.split('(\ |\,)', a)
a.remove(' ')
a.remove(',')

Matthias Winterland wrote:
> Hi,
>
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a
> single split-call?
> 
> Thx,
> Matthias

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


Re: Simple question to split

2006-11-09 Thread Georg Brandl
Diez B. Roggisch schrieb:
> Diez B. Roggisch schrieb:
>> Matthias Winterland schrieb:
>>> Hi,
>>>
>>> I have a simple question. When I read in a string like:
>>> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a 
>>> single split-call?
>> 
>> Nope. But you could replace the commas with spaces, and then split.
> 
> Or use re.split

And not forget to map it through int() afterwards.

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


Re: Simple question to split

2006-11-09 Thread Diez B. Roggisch
Diez B. Roggisch schrieb:
> Matthias Winterland schrieb:
>> Hi,
>>
>> I have a simple question. When I read in a string like:
>> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a 
>> single split-call?
> 
> Nope. But you could replace the commas with spaces, and then split.

Or use re.split

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


Re: Simple question to split

2006-11-09 Thread Diez B. Roggisch
Matthias Winterland schrieb:
> Hi,
> 
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a 
> single split-call?

Nope. But you could replace the commas with spaces, and then split.

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


Re: Simple question to split

2006-11-09 Thread Dan Lenski
Yep, use regular expressions!  For example, use the regular expression
r',|\s+' to split on either (a) any amount of whitespace or (b) a
single comma.  Try this:

import re
a='1,2,3,4,5 6 7,3,4'
print re.split(r',|\s+*', a)

Matthias Winterland wrote:
> Hi,
>
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a
> single split-call?
> 
> Thx,
> Matthias

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


Re: Simple question to split

2006-11-09 Thread Robert Kern
Matthias Winterland wrote:
> Hi,
> 
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a 
> single split-call?

You can't get what you want with a single method call. You can do it with a
single call to .split() if you preprocess the string first:

  a.replace(',', ' ').split()

-- 
Robert Kern

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

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


Re: how to create a multicolor "font-string" in pygame??

2006-11-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hi! I need to manipulate multicolor strings, i.e. strings with a color
> associated with each letter.
> Any suggestions?

There is no support for multi-color strings as such in pygame. If you 
use a fixed-width font, things are easy. Just create the strings one 
after another using spaces as prefix. E.g.

back = (0,0,0)
font = pygame.font.Font(font_fn, size)
images = []
for i, c in enumerate("colored string"):
 s = " " * i + c
 color = color_for_index(i)
 s_image = font.render(s, True, color, back)
 images.append(s_image)


Then blit the images onto each other.

If you don't use fixed widht fonts, things get more complicated. Then 
you should calculate the size of the prefix to a certain characer, and 
store that together with the image:

text = "colored string"
back = (0,0,0)
font = pygame.font.Font(font_fn, size)
images = []
for i, c in enumerate(text):
 s = " " * i + c
 color = color_for_index(i)
 prefix_offest = font.size(text[:i])
 s_image = font.render(s, True, color, back)
 images.append((prefix_offset, s_image))

Then you have to combine the images according to the prefix offset.

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


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Dan Lenski
One other thing I'm wondering: how exactly does Tkinter work?  Is the
whole Tk toolkit bound up as library of low-level C code, or does
Tkinter sit on top of a Tcl interpreter?

If the latter, that might explain why it is frustratingly slow on
Cygwin... since Cygwin is not very good at starting up new processes in
a timely manner.

Dan

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-09 Thread Robin Becker
Andrew MacIntyre wrote:
> Robin Becker wrote:
> 
>> I think it uses sysv semaphores and although freeBSD 6 has them 
>> perhaps there's something I need to do to allow them to work.
> 
> IIRC, you need to explicitly configure loading the kernel module, or
> compile the kernel with the necessary option in the config file.
> 
I tried loading the module, but it seems already to be in the kernel. 
Probably some sysctl stuff to do.

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


Simple question to split

2006-11-09 Thread Matthias Winterland
Hi,

I have a simple question. When I read in a string like:
a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a 
single split-call?

Thx,
Matthias
-- 
http://mail.python.org/mailman/listinfo/python-list


SPE bug?

2006-11-09 Thread timmy
i can't paste from SPE into an xterm window. is this problem with SPE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to create a multicolor "font-string" in pygame??

2006-11-09 Thread Jorge Godoy
[EMAIL PROTECTED] writes:

> Hi! I need to manipulate multicolor strings, i.e. strings with a color
> associated with each letter.
> Any suggestions?

If you're on Unix / Linux the curses module might help.

-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py3K idea: why not drop the colon?

2006-11-09 Thread Robert Kern
Tim Chase wrote:
> A few arbitrary warts per-dictum of BDFL are fine though...it 
> still looks much cleaner compared to PHP & Perl ;-)

Well, it's neither arbitrary nor simply the preference of the BFDL. The ABC
project actually did empirical experiments with programmers to find that code
comprehension improved by adding the colon.

Here's a post from Uncle Timmy mentioning it:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/525480d0caa61b7f/8d568e684d653003?lnk=st&q=group%3Acomp.lang.python+ABC+colon+experiment&rnum=2#8d568e684d653003

Unfortunately, my Google-fu has not located an actual paper. It might be in here
somewhere:

http://homepages.cwi.nl/~steven/abc/publications.html

-- 
Robert Kern

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

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


urlretrieve get file name

2006-11-09 Thread Sven
Hi guys and gals,

I'm wrestling with the urlretrieve function in the urllib module. I
want to download a file from a web server and save it locally with the
same name. The problem is the URL - it's on the form
http://www.page.com/?download=12345. It doesn't reveal the file name.
Some hints to point me in the right direction are greatly appreciated.

Sven

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


Re: ANN: PyQt v4.1 Released

2006-11-09 Thread Tool69
Sorry,
I just tried with other lexers, but I'm having some errors (names not
defined errors) with those ones :
1.lexer = QsciLexerRuby()
2.lexer = QsciLexerTeX()
Are they implemented ?

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-09 Thread Andrew MacIntyre
Robin Becker wrote:

> I think it uses sysv semaphores and although freeBSD 6 has them perhaps 
> there's 
> something I need to do to allow them to work.

IIRC, you need to explicitly configure loading the kernel module, or
compile the kernel with the necessary option in the config file.

-- 
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread John Henry


Steve Holden wrote:

> >
> You may find that it starts out fine, but becomes less satisfactory as
> the sophistication of your interfaces increases. Then the problem will
> be that migration to another platform demands a substantial rewrite of
> your application (I have done this for a fairly small app).
>

It all depends on what you need.  You can always "drop down" to calling
wxPython.

> I don't think PythonCard gets much maintenance nowadays.
>

Funny you mention that.  I started that discussion on the PythonCard
list only yesterday.

While it's true that the web pages hasn't been updated to follow up
with the developments, I am delighted to learn that there has been
quite a bit of work going on.

Again, it all depends on what your needs are.  If you need to become
productive in a hurry,  and you are not exactly chasing after the
latest widget, my recommendation is to go with PythonCard.


> regards
>   Steve
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb   http://holdenweb.blogspot.com
> Recent Ramblings http://del.icio.us/steve.holden

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


Re: Py3K idea: why not drop the colon?

2006-11-09 Thread Bjoern Schliessmann
Michael Hobbs wrote:

> That is, assume that the expression ends at the colon, not at the
> newline. That would make this type of statement possible:
> if color == red or
>   color == blue or
>   color == green:
> return 'primary'
> Right now, such a statement would have to be spelled thus:
> if color == red or \
>   color == blue or \
>   color == green:
> return 'primary'
> or
> if (color == red or
>   color == blue or
>   color == green):
> return 'primary'

What about

if color == red or blue or green:
return 'primary'

:)

Really, I think it'd be more mess to let the if statement's end only
depend on ":". I think there could arise situations that are messy
to debug. If I need multiple lines I prefer the parentheses.

Regards,


Björn

-- 
BOFH excuse #295:

The Token fell out of the ring. Call us when you find it.

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


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Bjoern Schliessmann
Dan Lenski wrote:

> for my next project.  I too would avoid Qt, not because of the GPL
> but simply because I don't use KDE under Linux and because Qt is
> not well supported under Cygwin or on native Windows. 

Why not?

BTW, big projects such as the Opera browser use Qt. Also in Windows.

Regards,


Björn

-- 
BOFH excuse #381:

Robotic tape changer mistook operator's tie for a backup tape.

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


Re: ANN: PyQt v4.1 Released

2006-11-09 Thread Tool69
Thanks David,
your sample works nicely !

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


how to create a multicolor "font-string" in pygame??

2006-11-09 Thread Iacopo . Marmo
Hi! I need to manipulate multicolor strings, i.e. strings with a color
associated with each letter.
Any suggestions?

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


Re: Vim/Python Help

2006-11-09 Thread Scott Smith
Thank you!

Python Rocks!

"Tim Chase" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> I am just getting into python and am trying to learn how to use the 
>> python.vim script.  I really like the fact that it autoindents for me 
>> while inserting defs etc, but how do I move my cursor to back to outer 
>> block (say at the end of a def) to continue with writing next def while 
>> still in insert mode?  Right now I have to get out of insert mode to do 
>> thisvery annoying!
>
> If I understand what you're wanting, it sounds like you want an exdent 
> sort of command.
>
> Vim provides two variants within insert mode:
>
> 1) just plain control+D will exdent one 'shiftwidth'
>
> 2) typing a zero followed by a control+D will exdent you to the far left 
> margin
>
> You can read more in the help at
>
> :help i_CTRL-D
> :help i_0_CTRL-D
> :help i_^_CTRL-D
>
> (that last variant is more helpful for C/C++ coding than for Python, but 
> it's nice to know it's there)
>
> For future reference regarding vim related questions, I highly recommend 
> the vim mailing list, which you can find at www.vim.org which is almost 
> pure content (very high S/N ratio) and gives the python ML a run for its 
> money in terms of fast & accurate responses.
>
> -tkc
>
>
>
>
> 


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


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Dan Lenski
Wojciech Mula wrote:
> Nick Craig-Wood wrote:
> >>  It's very mature, full-featured, and portable, and fairly easy to
> >>  learn as well.
> >
> > ...with native look and feel on each platform unlike GTK / TK
>
> AFAIK Tk 8 uses platform's native widgets.
>
> w.

Tk 8.4 appears to use native Win32 widgets under Cygwin and native
WinXP.  But it definitely doesn't use GTK widgets under Ubuntu with
Gnome desktop.  Is there a way to get it to do so?

Dan

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


Re: [OT] Py3K idea: why not drop the colon?

2006-11-09 Thread [EMAIL PROTECTED]
Steve Holden wrote:
> Paul Boddie wrote:
> > Steve Holden wrote:
> >> Paul Boddie wrote:
> >>> http://www.python.org/doc/faq/general/#why-are-colons-required-for-the-if-while-def-class-statements
> >>>
> >> I suppose it would be even better if that hyperlink actually took you to
> >>   section 1.4.27 rather than 1.4.14 ...
> >
> > I'd suggest a browser upgrade: even the old version of Konqueror I'm
> > using here manages to scroll to the right place. And it isn't a Web
> > site maintenance problem, either, although I did have my suspicions.
> >
> YTes, IE copes with it but Firefox doesn't. Having heard a number of
> complaints about Firefox 2 I'm tempted to stick with 1.5.0.8 just a
> little longer.

FWIW, Firefox 2.0 and 1.5.0.7 both work properly on this link (as does
Epiphany 1.2.10).  Linux 2.6-based system.

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


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Steve Holden
Dan Lenski wrote:
> John Henry wrote:
>> I assume you meant that the example programs looks LabView-like GUIs?
>> PythonCard itself has nothing in common with LabView.   It's more like
>> HyperCard.
> 
> That's right, I'm saying the GUIs *produced* by PythonCard look like
> those produced by LabView.  Believe me, if the PythonCard programming
> style had anything to do with LabView, I'd avoid it like the plague =)
> 
> In any case, I think I'm gonna give PythonCard a shot before trying
> full-fledged wxPython.  It looks ideal for my needs.
> 
You may find that it starts out fine, but becomes less satisfactory as 
the sophistication of your interfaces increases. Then the problem will 
be that migration to another platform demands a substantial rewrite of 
your application (I have done this for a fairly small app).

I don't think PythonCard gets much maintenance nowadays.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Py3K idea: why not drop the colon?

2006-11-09 Thread Tim Chase
>>> Anyway, the FAQ answer seems to be a weak argument to me.
>> I agree. I was expecting something more technical to justify
>> the colon, not just that it looks better.
> 
> I think it is outstanding that the colon's justification is
> asthetic rather than technical (though I too had expected to see
> a technical excuse for it).

Though by such justifications based on asthetics, the interpreter 
should also enforce that class-names begin with capital letters, 
that camel-case is eschewed in favor of underscore_separation. 
And perhaps enforce a 79-column character limit on text.  Perhaps 
also put a cap on the number of punctuation characters on a given 
line as well to prevent the code from looking too much like 
Perl... ;*)

A few arbitrary warts per-dictum of BDFL are fine though...it 
still looks much cleaner compared to PHP & Perl ;-)

Shaving-with-Occam's-disposable-razor'ly yers...

-tkc




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


Re: Python memory usage

2006-11-09 Thread Klaas

placid wrote:

> Actually i am executing that code snippet and creating BeautifulSoup
> objects in the range()  (now xrange() ) code block.

Right; I was referring specifically to abominations like
range(100), not looping over an incrementing integer.

-Mike

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-09 Thread robert
Paul Boddie wrote:
> robert wrote:
>> Shane Hathaway wrote:
>>> of multiple cores.  I think Python only needs a nice way to share a
>>> relatively small set of objects using shared memory.  POSH goes in that
>>> direction, but I don't think it's simple enough yet.
>>>
>>> http://poshmodule.sourceforge.net/
>> interesting, a solution possibly a little faster than pickling - but maybe 
>> only in selected
>> situations. Made already experiments with pickling through shared memory.
> 
> What did you discover in your experiments? I'd certainly suspect that
> pickling is going to add an unacceptable degree of overhead in the kind
> of application you're attempting to write (using a shared data
> structure with random access properties), and I'll admit that I haven't
> really had to deal with that kind of situation when using my own
> pickle-based parallelisation solutions (which involve communicating
> processes).
> 
>> With "x = posh.share(x)" an object tree will be (deep-)copied to shared mem 
>> ( as far as
>> objects fullfil some conditions 
>> http://poshmodule.sourceforge.net/posh/html/node6.html: is
>> this true for numpy arrays?)
> 
> My impression is that POSH isn't maintained any more and that work was
> needed to make it portable, as you have observed. Some discussions did
> occur on one of the Python development mailing lists about the
> possibility of using shared memory together with serialisation
> representations faster than pickles (which also don't need to be
> managed as live objects by Python), and I think that this could be an
> acceptable alternative.
> 
>> Every object to be inserted in the hot tunnel object tree has to be copied 
>> that same style.
>> Thus ~pickling, but somewhat easier to use.
> 
> If my understanding of "hot tunnel object tree" is correct, you're
> really wanting fast access involving mutual exclusion to some shared
> data structure. At this point it becomes worth considering some kind of
> distributed object technology (or even a database technology) where you
> have to initialise the data structure and then communicate with an
> object (or database) to perform operations on it, all for reasons I'll
> explain shortly.
> 
> In your ideal situation, you say that you'd have the data structure in
> the same address space as a number of threads, and each thread would be
> able to perform some algorithm on the data structure, but the pattern
> of accessing the structure isn't an insignificant concern even where
> you can assume that the overheads are generally low: reading and
> writing things might be fast in the same address space, but if the
> nature of access involves lots of locking, you'll incur quite a penalty
> anyway. In other words, if each read or write to the structure involves
> acquiring a lock for that operation in isolation, this could
> significantly diminish performance, whereas if you can guarantee that
> the granularity of locking is more coarse than having to occur upon
> each read or write access - that there exist some high-level operations
> that require consistency within the data structure - then reasonable
> performance might be maintained.
> 
> However, if the pattern of concurrent access is restricted to coarse
> operations, where some entity has exclusive access to a potentially
> large dataset, and where the overhead of the communication of inputs
> and outputs to and from that entity is low in comparison to the cost of
> performing such coarse operations, and where such operations are
> themselves performed infrequently, then such a pattern coincides with
> classic database or distributed object scenario. In other words, you
> implement the operations acting on the data structure in a distributed
> object (or as a database query or operation) and then invoke such
> operations from separate processes.
> 
> I hope this makes some sense. Generally, demands for high concurrent
> performance using threads often ignore other important properties such
> as reliability and scalability. Certainly, threads have an important
> place - classically, this involved maintaining responsiveness in
> graphical user interfaces - but even then, the background threads were
> often detached and not competing for the same resources as the
> foreground threads servicing the event loop. The only kinds of
> situation I can think of right now which might benefit from uninhibited
> random access to shared data structures might be things like
> simulations or large-scale multi-user games, where an appropriate data
> architecture cannot be decided in advance, but even then there are
> approaches which attempt to mitigate the seemingly unpredictable nature
> of access to shared data.

Some thoughts may make reason, when one wants to trick the single GIL a little. 
But the length of the text tells us again to possibly get at least refcounting 
thread safe (within access restrictions) - or get rid of refcount - or do it an 
go the full path towards a GIL free Python.

Beside

Re: Py3K idea: why not drop the colon?

2006-11-09 Thread Neil Cerutti
On 2006-11-09, John Salerno <[EMAIL PROTECTED]> wrote:
> Michael Hobbs wrote:
>> Anyway, the FAQ answer seems to be a weak argument to me.
>
> I agree. I was expecting something more technical to justify
> the colon, not just that it looks better.

I think it is outstanding that the colon's justification is
asthetic rather than technical (though I too had expected to see
a technical excuse for it).

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


Re: cross connecting

2006-11-09 Thread Gabriel Genellina

At Thursday 9/11/2006 17:17, km wrote:


I have a c executable in machine A which cannot execute on B.
I am on machine B and i need python program to connect to A via 
telnet  and run the program with arguments passed from program on 
B  and at the end fetch back  results to machine B.
i would like to know , which set of modules are suitable for this 
sort of a work ?


Using rsh (linux) or psexec (windows; www.sysinternals.com) you can 
execute *any* program remotely (of course certain security constraints apply).
From the python point of view, you're executing a command and 
capturing its output; use the subprocess module.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: UnboundLocalError

2006-11-09 Thread Rob Williscroft
Terry Reedy wrote in
news:[EMAIL PROTECTED] in
comp.lang.python: 

>> def main():
>>number = number()
> 
> Within a function, a given name can be either global or local, but not
> both.
> Here you are expecting the compiler to interpret the first occurance
> of 'number' as local and the second as global.  Humans can often
> resolve such ambiguities correctly, but not necessarily always.  So
> this is too much to ask of a program and hence it is not allowed.
> 

".. asked too much of the programme", sounds like a BOFH excuse to 
me ;-).

Seriously I'd bet (if I were a gambling man) that this is by design,
not either of "too much work for the interpreter" or "nobody's 
submitted a patch".

IOW: Why should the intepreter do more work just so the user 
can find new and interesting ways to shoot them selves in the foot.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lists of lists and tuples, and finding things within them

2006-11-09 Thread attn . steven . kuo
Daniel Nogradi wrote:
> > I have a program that keeps some of its data in a list of tuples.
> > Sometimes, I want to be able to find that data out of the list.  Here is
> > the list in question:
> >
> > [('password01', 'unk'), ('host', 'dragonstone.org'), ('port', '1234'),
> > ('character01', 'Thessalus')]
> >
> > For a regular list, I could do something like x.index('host') and find
> > the index of it, but I don't know how to do this for a tuple where the
> > data item isn't known in advance.  For example, I want to get the "host"
> > entry from the list above; but I can only retrieve it if I know what it
> > contains (e.g., x.index(('host', 'dragonstone.org'))).
> >
> > Is there a better way to do this than a construct similar the following?
> >
> > for key, value in x:
> > if key == 'host':
> > print value
> >
>
> If I were you I would use a dictionary for such a thing:
>

(snipped)


The sequence of tuples may have repeated "keys"; if
that's the case, then you may use a filter/iterator instead.
Using a dictionary would otherwise cause you to lose
"values":

import itertools

mytuple = (('foo', 'bar'), ('foo', 'foobar'), ('baz', 'qux'))

it = itertools.ifilter(lambda t : t[0] == 'foo', mytuple)
 
for t in it:
print t


-- 
Hope this helps,
Steven

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


cross connecting

2006-11-09 Thread km
HI all,

I have a c executable in machine A which cannot execute on B.
I am on machine B and i need python program to connect to A via
telnet  and run the program with arguments passed from program on
B  and at the end fetch back  results to machine B.
i would like to know , which set of modules are suitable for this sort of a work ? 

regards,
KM
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Dan Lenski
John Henry wrote:
> I assume you meant that the example programs looks LabView-like GUIs?
> PythonCard itself has nothing in common with LabView.   It's more like
> HyperCard.

That's right, I'm saying the GUIs *produced* by PythonCard look like
those produced by LabView.  Believe me, if the PythonCard programming
style had anything to do with LabView, I'd avoid it like the plague =)

In any case, I think I'm gonna give PythonCard a shot before trying
full-fledged wxPython.  It looks ideal for my needs.

Dan

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


Re: Py3K idea: why not drop the colon?

2006-11-09 Thread John Salerno
Michael Hobbs wrote:

> Anyway, the FAQ answer seems to be a 
> weak argument to me.

I agree. I was expecting something more technical to justify the colon, 
not just that it looks better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread John Henry

Dan Lenski wrote:
>
> John H.: thanks for pointing out pythoncard.  This looks like it might
> be an excellent substitute for LabView-like GUIs, which all my
> coworkers like.  I personally refuse to read or write LabView code, on
> the grounds that its syntax causes severe brain damage and is
> completely unportable.  But that's a flame for another thread, so to
> speak...
>
> Thanks,
> Dan

I assume you meant that the example programs looks LabView-like GUIs?
PythonCard itself has nothing in common with LabView.   It's more like
HyperCard.

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


  1   2   3   >