Re: failed to install PIL in fedora core 6

2007-02-24 Thread Michele Petrazzo
Frank Potter wrote:
> I use "python setup.py install" to install PIL in fedora with python 
> 2.4, But I got these errors:

<-cut some errors->

> error: Python.h: No such file or directory In file included from
> libImaging/Imaging.h:14, from _imaging.c:78:

So you don't have the python-dev package.

> What should I do if I want to successfully have pil installed?

Try to search into the Fedora repos for the PIL (or python-imaging). If
not, install the python-dev and compile!

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


Re: Rational numbers

2007-02-24 Thread Toby A Inkster
aleaxit wrote:

> If anybody who has easy access to Microsoft's MSVC++.NET (and is willing
> to try building GMP 4.2 with/for it), or a PPC Mac with XCode installed
> (possibly with MacOSX 10.3...)

I'm writing this message on a MacOS 10.3.9 box with Xcode 1.5 (gcc 3.3)
installed. If you tell me how, I'd be happy to compile it for you.

Contact me through the feedback form on the site below.

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert to binary and convert back to strings

2007-02-24 Thread Hendrik van Rooyen
 "Paul Rubin"  wrote:

> "Hendrik van Rooyen" <[EMAIL PROTECTED]> writes:
> > s = 'some string that needs a bcc appended'
> > ar = array.array('B',s)
> > bcc = 0
> > for x in ar[:]:
> > bcc ^= x
> > ar.append(bcc)
> > s=ar.tostring()
> 
> Untested:
> 
> import operator
> s = 'some string that needs a bcc appended'
> ar = array.array('B',s)
> s += chr(reduce(operator.xor, ar))
> 

Yikes! - someday soon I am going to read the docs on
what reduce does...

Won't this be slow because of the double function call on each char?

- Hendrik

 

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


Re: Convert to binary and convert back to strings

2007-02-24 Thread Paul Rubin
"Hendrik van Rooyen" <[EMAIL PROTECTED]> writes:
> > s += chr(reduce(operator.xor, ar))
> Yikes! - someday soon I am going to read the docs on what reduce does...

Reduce just intersperses an operator over a sequence.  For example,
  reduce(operator.add, (a,b,c,d,e)) 
is a+b+c+d+e.  

> Won't this be slow because of the double function call on each char?

I think there's the same number of func calls, one xor per char.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV(???)

2007-02-24 Thread David C.Ullrich
On Fri, 23 Feb 2007 11:43:24 + (UTC), Philipp Pagel
<[EMAIL PROTECTED]> wrote:

>David C. Ullrich <[EMAIL PROTECTED]> wrote:
>> Is there a csvlib out there somewhere?
>
>How about csv in the standard library?
>
>> (Um: Believe it or not I'm _still_ using
>> python 1.5.7.
>
>I have no idea if csv was part of the standard library backin those
>days...

Nope.

>But even if not: either upgrade to something less outdated 

Thanks. Actually, for reasons I could explain if you really
wanted to know, going to 2.x would actually cost me some
money. Since I'm not getting paid for this...

>or see if you
>can get todays csv to work with the oldtimer.
>
>cu
>   Philipp




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


Re: CSV(???)

2007-02-24 Thread David C.Ullrich
On 23 Feb 2007 11:51:57 GMT, nmp <[EMAIL PROTECTED]> wrote:

>Op Fri, 23 Feb 2007 11:45:54 +, schreef nmp:
>
>> Op Fri, 23 Feb 2007 05:11:26 -0600, schreef David C. Ullrich:
>> 
>>> Is there a csvlib out there somewhere?
>> 
>> Hey, cool! I am just beginning with Python but I may already be able to
>> help you ;)
>
>Oops I missed the bit where you said you were using that very old Python
>version...

No problem. Actually if there were a csv.py in my version I would
have found it before posting, but you didn't know that.




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


Re: CSV(???)

2007-02-24 Thread David C.Ullrich
On 23 Feb 2007 19:13:10 +0100, Neil Cerutti <[EMAIL PROTECTED]> wrote:

>On 2007-02-23, David C  Ullrich <[EMAIL PROTECTED]> wrote:
>> Is there a csvlib out there somewhere?
>>
>> And/or does anyone see any problems with
>> the code below?
>>
>> [...]
>>
>> (Um: Believe it or not I'm _still_ using python 1.5.7. So
>> comments about iterators, list comprehensions, string methods,
>> etc are irrelevent. Comments about errors in the algorithm
>> would be great. Thanks.)
>
>Two member functions of indexedstring are not used: next and
>lookahead. __len__ and __getitem__ appear to serve no real
>purpose.

Hey, thanks! I didn't realize that using an object with
methods that were never called could cause an algorithm
to fail... shows how much I know.

(Seriously, all I really wanted to know was whether anyone
noticed something I overlooked, so that 
parsecsvline(csvline(fields)) might under some condition
not come out the same as fields...)

>> def parsecsvline(csvline):
>>   """Inverts csvline(). Assumes csvline is valid, ie
>>   is something as returned by csvline(); output undefined
>>   if csvline is in invalid format"""
>>
>>   s = indexedstring(csvline)
>>   res = []
>>
>>   while not s.eos():
>>res.append(s.getfield())
>>
>>   return res
>
>You'll be happy to know that iterators and list comprehensions
>will make your code better after you upgrade. ;-)

Uh, thanks again. You're right, knowing that makes me so happy
I could just burst.

>In the meantime, I think your (relative lack of) error handling
>is OK. GIGO, as they say (garbage in, garbage out).

_I_ don't think it's ok.

But (i) the code I posted was not supposed to be the final
version! It was a preliminary version, posted hoping that
someone would notice any errors in the _algorithm_ that
existed. (ii) in the intended application parsecsvline
will only be applied to the output of csvline, so if
the former is indeed a left inverse of the latter there
should be no error unless something else has already
gone wrong elsewhere. Not that that makes it ok...



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


Re: Finding non ascii characters in a set of files

2007-02-24 Thread Toby A Inkster
bg_ie wrote:

> What I'd like to do is scan a directory and list all the
> files in it that contain a non ascii character.

Not quite sure what your intention is. If you're planning a one-time scan
of a directory for non-ASCII characters in files, so that you can manually
fix those files up, then this Perl one-liner will do the trick. At the
command line, type:

perl -ne 'print "$ARGV:$.\n" if /[\x80-\xFF]/;' *

This will print out a list of files that contain non-ASCII characters, and
the line numbers which those characters appear on. Note this also
operates on binary files like images, etc, so you may want to be more
specific with the wildcard. e.g.:

perl -ne 'print "$ARGV:$.\n" if /[\x80-\xFF]/;' *.py *.txt *.*htm*

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question: Install Tkinter with Python2.5

2007-02-24 Thread TK
Hi,

> I see that Tcl/Tk detection has been moved in the Python source
> distribution (since the "good old days" when I last had to deal with
> this kind of thing) from the configure machinery to the setup.py
> program. However, a few things worth checking include (1) whether you
> not only have the Tcl/Tk libraries but also the Tcl/Tk headers/
> includes and (2) whether they're installed in standard places or
> somewhere else.
> 
> Look for things like libtcl8.4.so, libtk8.4.so as well as tcl.h and
> tk.h. If appropriate, check your distribution's packages and make sure
> you have the developer packages (eg. tcl8.4-dev, tk8.4-dev) installed.


It's not so simple ... . Thanx fpor help.

o-o

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


Re: CSV(???)

2007-02-24 Thread David C.Ullrich
On 23 Feb 2007 07:31:35 -0800, "John Machin" <[EMAIL PROTECTED]>
wrote:

>On Feb 23, 10:11 pm, David C. Ullrich <[EMAIL PROTECTED]>
>wrote:
>> Is there a csvlib out there somewhere?
>
>I can make available the following which should be capable of running
>on 1.5.2 -- unless they've suffered bitrot :-)
>
>(a) a csv.py which does simple line-at-a-time hard-coded-delimiter-etc
>pack and unpack i.e. very similar to your functionality *except* that
>it doesn't handle newline embedded in a field. You may in any case be
>interested to see a different way of writing this sort of thing: my
>unpack does extensive error checking; it uses a finite state machine
>so unexpected input in any state is automatically an error.

Actually a finite-state machine was the first thing I thought of.
Then while I was thinking about what states would be needed, etc,
it ocurred to me that I could get something working _now_ by
just noticing that (assuming valid input) a quoted field
would be terminated by '",' or '"[eos]'.

A finite-state machine seems like the "right" way to do it,
but there are plenty of other parts of the project where
doing it right is much more important - yes, in my experience
doing it "right" saves time in the long run, but that
finite-state machine would have taken more time 
_yesterday_.

>(b) an extension module (i.e. written in C) with the same API. The
>python version (a) imports and uses (b) if it exists.
>
>(c) an extension module which parameterises everything including the
>ability to handle embedded newlines.
>
>The two extension modules have never been compiled & tested on other
>than Windows but they both should IIRC be compilable with both gcc
>(MinGW) and the free Borland 5.5 compiler -- in other words vanilla C
>which should compile OK on Linux etc.
>
>If you are interested in any of the above, just e-mail me.

Keen.

>>
>> And/or does anyone see any problems with
>> the code below?
>>
>> What csvline does is straightforward: fields
>> is a list of strings. csvline(fields) returns
>> the strings concatenated into one string
>> separated by commas. Except that if a field
>> contains a comma or a double quote then the
>> double quote is escaped to a pair of double
>> quotes and the field is enclosed in double
>> quotes.
>>
>> The part that seems somewhat hideous is
>> parsecsvline. The intention is that
>> parsecsvline(csvline(fields)) should be
>> the same as fields. Haven't attempted
>> to deal with parsecsvline(data) where
>> data is in an invalid format - in the
>> intended application data will always
>> be something that was returned by
>> csvline.
>
>"Always"? Famous last words :-)

Heh. 

Otoh, having read about all the existing variations
in csv files, I don't think I'd attempt to write
something that parses csv provided from an
external source.

>> It seems right after some
>> testing... also seems blechitudinous.
>
>I agree that it's bletchworthy, but only mildly so. If it'll make you
>feel better, I can send you as a yardstick csv pack and unpack written
>in awk -- that's definitely *not* a thing of beauty and a joy
>forever :-)
>
>I presume that you don't write csvline() output to a file, using
>newline as a record terminator and then try to read them back and pull
>them apart with parsecsvline() -- such a tactic would of course blow
>up on the first embedded newline. 

Indeed. Thanks - this is exactly the sort of problem I was hoping
people would point out (although in fact this one is irrelevant,
since I already realized this). In fact the fields will not
contain linefeeds (the data is coming from 
on an html form, which means that unless someone's _trying_
to cause trouble a linefeed is impossible, right? Regardless,
incoming data is filtered. Fields containing newlines are
quoted just to make the thing usable in other situations - I
wouldn't use parsecsvline without being very careful, but there's
no reason csvline shouldn't have general applicability.) And in 
any case, no, I don't intend to be parsing multi-record csv files.

Although come to think of it one could modify the above
to do that without too much trouble, at least assuming
valid input - end-of-field followed by linefeed must
be end-of-record, right?

>So as a matter of curiosity, where/
>how are you storing multiple csvline() outputs?

Since you ask: the project is to allow alumni to
store contact information on a web site, and then
let office staff access the information for various
purposes. So each almunus' data is stored as a
csvline in an anydbm "database" - when someone in
the office requests the information it's dumped
into a csv file, the idea being that the office
staff opens that in Excel or whatever.

(Why not simply provide a suitable interface
to the data instead of just giving them the
csv file? So they can use the data in ways I
haven't anticipated. Why not give them access
to a real database? They know how to use Excel.

I do think I'll provide a few access thingies
in addition to the csv file, for ex

Re: Newbie in the deep - some PyGTK questions

2007-02-24 Thread Dieter Verfaillie
Hi,

On Fri, 2007-02-23 at 11:36 +, nmp wrote:
> First "problem": when I insert the glade file in my application the way
> some tutorials have shown me:
> 
> self.wTree = gtk.glade.XML("autostart.glade", "mainWindow")
> 
> ... Python is consistently giving me this warning:
> 
> /home//Projecten/autostart/autostart.py:18: GtkWarning:
> gtk_widget_grab_default: assertion `GTK_WIDGET_CAN_DEFAULT (widget)'
> failed
> self.wTree = gtk.glade.XML("autostart.glade", "mainWindow")

I think you've set the "Has default" property to Yes on some
widget, but you forgot to set the "Can default" property
to Yes on that same widget.
In short, you created a default widget that can't be the default and
gtk happily complains about that. Check your glade file to fix it.

> Now I want the user of my program to be able to just double click a row or
> hit Enter to flip the boolean, so FALSE becomes TRUE and vice versa.

See the answer to your third "problem" :)

> The third "problem" (for now...) is really just a cosmetic thing. The
> representation of the boolean in the list is fine for me, but in time I
> would like to make it prettier by replacing it with a graphical checkbox.
> Does anyone have an example of this that I can use?

Use a CellRendererToggle. There's a tutorial on the pygtk website:
http://pygtk.org/pygtk2tutorial/sec-CellRenderers.html (scroll all the
way down that page to "Figure 14.6. Editable and Activatable Cells")

> Thank you for your patience. I can already see how all this is going to
> keep me busy for weeks and it will be fun ;)

You'll probably get faster/better answers to you pygtk questions on the
pygtk mailing list: http://www.daa.com.au/mailman/listinfo/pygtk

Have fun,
Dieter

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


Re: Performance project for the SigEx Foundry

2007-02-24 Thread pablo
On Feb 22, 8:40 pm, [EMAIL PROTECTED] wrote:
> On Feb 21, 1:15 pm, [EMAIL PROTECTED] wrote:
>
> > have been testing performances of different scripting languages
> > fordatabase access, text processing and client application data
> > transfer. So far, I am getting better performance from PHP, but I
> > don't have any hard data to back it up compared to others.
>
> > This is a large project for theSigExFoundryand it involves hundreds
> > of servers. I am looking for articles/studies/benchmarks on the
> > subject.
>
> > Thank you,
>
> > Pablo
> > Server Side Developer
> > Student for theSigExFoundry,
> > bySigExVentures
>
> Hi Pablo,
>
> It's a good question. You want to really understand what you are doing
> this benchmark for. In my opinion, you should go for the language that
> fits your needs and focus on performance optimization for that
> language. I would be more inclined to go with PHP, but that's a
> personal choice. I'm sure you can search performance for these
> languages and come up with lots of ressources on the web.
>
> Pierre-Marie Durand

Pierre-Marie,

Thanks for the feedback. You are right, for now, I am sticking to PHP,
but I would like to read more about this subject. Bearophile's link is
a good start. Thanks,

Pablo
Server Side Developer
Student for the SigEx Foundry,
SigEx Ventures

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


arf

2007-02-24 Thread John Doe



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


Endianness conversion

2007-02-24 Thread Toby
As part of a program I'm writing, I need to save to disk big amounts of
data (hundreds of MB, in 8kB chunks) swapping every couple of bytes.  

I obviously cannot do it in a Python loop.

Is there a function I could use in the standard library, or do I have to
write my own C extension?


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


INSTALL ODDITIES

2007-02-24 Thread Schnizalfritz
When I built python 2.5 for linux I did the normal:
configure
make
make install

Everything went fine til the "make install" part. It dies with no
error.
just says "install failed" after this:


Compiling /usr/local/lib/python2.5/zipfile.py

That part built fine but the next part failed.
So what I did being the industrious fellow that I am I did:

make -n install > out

Took the out file and did:

sh out

That installed python without failure.

Now if I do "make install" everything works fine.

Weird eh?

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


Re: Endianness conversion

2007-02-24 Thread Dan Sommers
On Sat, 24 Feb 2007 15:39:53 +, Toby wrote:

> As part of a program I'm writing, I need to save to disk big amounts of
> data (hundreds of MB, in 8kB chunks) swapping every couple of bytes.  
> 
> I obviously cannot do it in a Python loop.
> 
> Is there a function I could use in the standard library, or do I have to
> write my own C extension?

You could try the struct module.  If your input comes in fixed sized
chunks, just call struct.unpack and struct.pack once per chunk.

HTH,
Dan

-- 
Dan Sommers

Atoms are not things. -- Werner Heisenberg.

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


Recreating a char array from a pointer

2007-02-24 Thread buffinator
I have an application that has to send a string as a pointer to memory, 
and then another one that has to retriece it and fetch the string. 
Converting the string to an array and sending the pointer was easy

import array
a=array.array("c","mytextgoeshere")
my_pointer = a.buffer_info()[0]


But then I tried to get the data back... and I just can't find out how. 
I ended up writing a C module for this that works fine in linux, but 
this application is meant for windows and I just can't get C-modules to 
compiler there correctly since I suck at windows.

The relevant code from the module is

static PyObject *
pointrtostr_casttostr(PyObject *self, PyObject *args)
{
 char *mystr;
 long int p;

 if (!PyArg_ParseTuple(args, "l", &p))
   return NULL;

 mystr = (char*)p;
 return Py_BuildValue("s", mystr);
}

My question is... can I do the above code in python without involving C 
since it is quite a big hassle to have to go through the module building 
in windows? :/

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


*** CANADIAN ANTI-TERROR LAW HAS BEEN STRUCK DOWN BY ITS HONORABLE SUPREME COURT UNANIMOUSLY ***

2007-02-24 Thread stj911
Canada anti-terror law is struck down
>From the Associated Press
February 24, 2007

OTTAWA - Canada's Supreme Court on Friday unanimously declared it
unconstitutional to detain foreign terrorism suspects indefinitely
while the courts review their deportation orders.

Five Arab Muslim men have been held for years under the "security
certificate" program, which the Justice Department has said is a key
tool in the fight against global terrorism and essential to Canada's
security.

The court found that the system violated the Charter of Rights and
Freedoms, Canada's bill of rights. However, it suspended its ruling
for a year to give Parliament time to rewrite the part of the
Immigration and Refugee Protection Act that covers the certificate
process.

The security certificates were challenged by three men from Morocco,
Syria and Algeria - all alleged by the Canadian Security Intelligence
Service to have ties to terrorist networks.

The men have spent years in jail while fighting deportation orders.

They risk being labeled terrorists and sent back to their native
countries, where they say they could face torture.

The court said the treatment of the suspects was a violation of their
rights.

"The overarching principle of fundamental justice that applies here is
this: Before the state can detain people for significant periods of
time, it must accord them a fair judicial process," Chief Justice
Beverley McLachlin wrote in a ruling for all nine justices.

"The secrecy required by the scheme denies the person named in a
certificate the opportunity to know the case put against him or her,
and hence to challenge the government's case," she said.

The challenged law allows sensitive intelligence to be heard behind
closed doors by a federal judge, with only sketchy summaries given to
defense attorneys.

The court said the men and their lawyers should have a right to
respond to the evidence used against them by intelligence agents.

Stockwell Day, the minister of public safety, noted that because the
ruling does not take effect for a year, the certificates would remain
in place. He said the government would address the court's ruling "in
a timely and decisive fashion."

Two of the men are out on bail and remain under house arrest. Three
others are being held in a federal facility in Ontario.

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


Re: Recreating a char array from a pointer

2007-02-24 Thread Thomas Heller
buffinator schrieb:
> I have an application that has to send a string as a pointer to memory, 
> and then another one that has to retriece it and fetch the string. 
> Converting the string to an array and sending the pointer was easy
> 
> import array
> a=array.array("c","mytextgoeshere")
> my_pointer = a.buffer_info()[0]
> 
> 
> But then I tried to get the data back... and I just can't find out how. 
> I ended up writing a C module for this that works fine in linux, but 
> this application is meant for windows and I just can't get C-modules to 
> compiler there correctly since I suck at windows.
> 
> The relevant code from the module is
> 
> static PyObject *
> pointrtostr_casttostr(PyObject *self, PyObject *args)
> {
>  char *mystr;
>  long int p;
> 
>  if (!PyArg_ParseTuple(args, "l", &p))
>return NULL;
> 
>  mystr = (char*)p;
>  return Py_BuildValue("s", mystr);
> }
> 
> My question is... can I do the above code in python without involving C 
> since it is quite a big hassle to have to go through the module building 
> in windows? :/

You can use the ctypes package for this.  It is in the standard library in 
Python 2.5,
for older versions it is a separate download.

Thomas

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


Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-24 Thread Toby
Charles D Hixson wrote:
> What I basically want is a kind of class that has both class and 
> instance level dict variables, such that descendant classes 
> automatically create their own class and instance level dict variables.  
> The idea is that if a member of this hierarchy looks up something in 
> it's local dict, and doesn't find it, it then looks in the class dict, 
> and if not there it looks in its ancestral dict's.  This is rather like 
> what Python does at compile time, but I want to do it at run time.

I don't understand, Python already does it at runtime:

class A:
  A_class_var = 1

class B(A):
  B_class_var = 2
  def __init__(self):
self.B_inst_var = 3

>>> b.A_class_var
1
>>> b.B_class_var
2
>>> b.B_inst_var
3
>>> A.another = 4
>>> b.another
4

Can you post a ">>>"-script of what you would like your classes to do?


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


Re: Recreating a char array from a pointer

2007-02-24 Thread buffinator
Oh, nice
Im running 2.4 but im gonna download it and give it a try then

Thanks!

Thomas Heller wrote:
> buffinator schrieb:
>> I have an application that has to send a string as a pointer to memory, 
>> and then another one that has to retriece it and fetch the string. 
>> Converting the string to an array and sending the pointer was easy
>>
>> import array
>> a=array.array("c","mytextgoeshere")
>> my_pointer = a.buffer_info()[0]
>>
>>
>> But then I tried to get the data back... and I just can't find out how. 
>> I ended up writing a C module for this that works fine in linux, but 
>> this application is meant for windows and I just can't get C-modules to 
>> compiler there correctly since I suck at windows.
>>
>> The relevant code from the module is
>>
>> static PyObject *
>> pointrtostr_casttostr(PyObject *self, PyObject *args)
>> {
>>  char *mystr;
>>  long int p;
>>
>>  if (!PyArg_ParseTuple(args, "l", &p))
>>return NULL;
>>
>>  mystr = (char*)p;
>>  return Py_BuildValue("s", mystr);
>> }
>>
>> My question is... can I do the above code in python without involving C 
>> since it is quite a big hassle to have to go through the module building 
>> in windows? :/
> 
> You can use the ctypes package for this.  It is in the standard library in 
> Python 2.5,
> for older versions it is a separate download.
> 
> Thomas
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Idea about thread safe issue with python

2007-02-24 Thread mralokkp
On Feb 16, 11:37 pm, Bjoern Schliessmann  wrote:
> mralokkp wrote:
> > I need help guys. I have a code running properly and execute again
> > after a certain time.
> > In Simple words [incomplete and useless code line] is not solving
> > my purpose. Would any body like to help.
>
> Please be so kind and read this paragraph:
>
> http://www.catb.org/~esr/faqs/smart-questions.html#explicit
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #331:
>
> those damn raccoons!

I am newbie here at your system.I was not aware of the system policies
you follows guys.
Any way The problem is sort out.Thanks for the reply.
Regards
Alok

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


Re: Endianness conversion

2007-02-24 Thread Toby
Dan Sommers wrote:
> You could try the struct module.  If your input comes in fixed sized
> chunks, just call struct.unpack and struct.pack once per chunk.

Thanks, but it was a bit awkward to use for big chunks.

I ended up writing my own byteswapper in Pyrex:


def swapbytes(data):
  "Swap every two bytes of a even-sized python string, in place"
  cdef int i
  cdef char t, *p
  p = data
  for i from 0 <= i < len(data) / 2:
t = p[0]
p[0] = p[1]
p[1] = t
p = p + 2


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


Re: Endianness conversion

2007-02-24 Thread Daniel Harding
On Feb 24, 9:39 am, Toby <[EMAIL PROTECTED]> wrote:
> As part of a program I'm writing, I need to save to disk big amounts of
> data (hundreds of MB, in 8kB chunks) swapping every couple of bytes.
>
> I obviously cannot do it in a Python loop.
>
> Is there a function I could use in the standard library, or do I have to
> write my own C extension?

Try the using the array module.  array objects provide a byteswap
method which reverses endianness.

-Daniel

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


Jobs: Lisp and Python programmers (Los Angeles)

2007-02-24 Thread Tech HR
http://www.smartcharter.com/jobs.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Required for Choosing Programming Language

2007-02-24 Thread Thomas Bartkus
On Mon, 19 Feb 2007 08:03:43 -0800, Andy Dingley wrote:


> GUI-based" is fairly unimportant as it's just how you build your
> programs, not what they do afterwards

Most user apps. require 95% of coding effort to provide a usable user
interface and 5% effort on the algorithmic meat.  The "afterwards" you
allude to. So why do we still endure so much programming effort on the
unimportant part?

Because elegent algorithms require bullet proof and intuitive user
interfaces or people won't use or buy your software.


> GUI programs are less important now than they were a few years ago,
> owing to the huge importance of the web and HTML.

Now with html the programming load rises to about 99.8% effort for the
user interface and 0.2% on the algorithmic core. All that coding
effort wasted on a user interface that looks and works like crap.

The top poster is quite correct to ask for a system like VB6 that banishes
the problem of user interface coding to the trivial role it deserves.
Why should a programmer waste even so much as 10% of his effort to throw
together a standard interface with ordinary textboxes, labels, and option
buttons?  Over and over again?

Thomas Bartkus

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


Re: Endianness conversion

2007-02-24 Thread Toby
Daniel Harding wrote:
> Try the using the array module.  array objects provide a byteswap
> method which reverses endianness.

Thanks!


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


[ANN] argparse 0.6 - Command-line parsing library

2007-02-24 Thread Steven Bethard
Announcing argparse 0.6
---

argparse home:
  http://argparse.python-hosting.com/

argparse single module download:
  http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw

argparse bundled downloads at PyPI:
  http://www.python.org/pypi/argparse/

About this release
==

This release adds support for argument groups, and fixes a bug in the
display of required options. Also, the source distribution of this
release should now include the tests.

Note that the 'outfile' type is still deprecated and will likely be
removed in the next release. Please update your code to use the new
FileType factory.

New in this release
===

* Required options are no longer displayed with brackets (so that they
no longer look optional).

* The source distribution includes ``test_argparse.py``, argparse's
test suite.

* Arguments can now be grouped into user-defined sections instead of
the default "positional arguments" and "optional arguments" sections::

>>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
>>> xgroup = parser.add_argument_group('')
>>> xgroup.add_argument('-x', help='x help')
>>> ygroup = parser.add_argument_group('')
>>> ygroup.add_argument('y', help='y help')
>>> parser.print_help()
usage: PROG [-x X] y

:
  -x X  x help

:
  y y help

About argparse
==

The argparse module is an optparse-inspired command line parser that
improves on optparse by:

* handling both optional and positional arguments
* supporting parsers that dispatch to sub-parsers
* producing more informative usage messages
* supporting actions that consume any number of command-line args
* allowing types and actions to be specified with simple callables
instead of hacking class attributes like STORE_ACTIONS or
CHECK_METHODS

as well as including a number of other more minor improvements on the
optparse API. To whet your appetite, here's a simple program that sums
its command-line arguments and writes them to a file::

   parser = argparse.ArgumentParser()
   parser.add_argument('integers', nargs='+', type=int)
   parser.add_argument('--log', default=sys.stdout,
   type=argparse.FileType('w'))
   args = parser.parse_args()
   args.log.write('%s\n' % sum(args.integers))
   args.log.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


newbie needs help building Python 2.5 for Fedora Core 6

2007-02-24 Thread bobmon
Hello, and please be gentle...

I'm trying to build Python 2.5 on my Fedora Core 6 installation.  I
think I've resolved most of my problems, but "make test" reports an
error for test_socket.py, shown below.

I suppose my FC6 installation is missing something, but I have no idea
what.  Any ideas, directions, pointers would be most appreciated.



==
 ERROR: testSockName (__main__.GeneralModuleTests)
 
--
 Traceback (most recent call last):
   File "./Lib/test/test_socket.py", line 456, in testSockName
 my_ip_addr = socket.gethostbyname(socket.gethostname())
 gaierror: (-2, 'Name or service not known')

 
--
 Ran 66 tests in 35.478s

 FAILED (errors=1)
 Traceback (most recent call last):
   File "./Lib/test/test_socket.py", line 962, in 
 test_main()
   File "./Lib/test/test_socket.py", line 958, in test_main
 test_support.run_unittest(*tests)
   File "/home/Installer/Python/Python-2.5/Lib/test/test_support.py",
line 441, in run_uni
 ttest
 run_suite(suite, testclass)
   File "/home/Installer/Python/Python-2.5/Lib/test/test_support.py",
line 426, in run_sui
 te
 raise TestFailed(err)
 test.test_support.TestFailed: Traceback (most recent call last):
   File "./Lib/test/test_socket.py", line 456, in testSockName
 my_ip_addr = socket.gethostbyname(socket.gethostname())
 gaierror: (-2, 'Name or service not known')

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


Re: newbie needs help building Python 2.5 for Fedora Core 6

2007-02-24 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "bobmon" <[EMAIL PROTECTED]> wrote:

> Hello, and please be gentle...
> 
> I'm trying to build Python 2.5 on my Fedora Core 6 installation.  I
> think I've resolved most of my problems, but "make test" reports an
> error for test_socket.py, shown below.
> 
> I suppose my FC6 installation is missing something, but I have no idea
> what.  Any ideas, directions, pointers would be most appreciated.
> 
> 
> 
> ==
>  ERROR: testSockName (__main__.GeneralModuleTests)
>  
> --
>  Traceback (most recent call last):
>File "./Lib/test/test_socket.py", line 456, in testSockName
>  my_ip_addr = socket.gethostbyname(socket.gethostname())
>  gaierror: (-2, 'Name or service not known')
> 
>  
> --
>  Ran 66 tests in 35.478s
> 
>  FAILED (errors=1)
>  Traceback (most recent call last):
>File "./Lib/test/test_socket.py", line 962, in 
>  test_main()
>File "./Lib/test/test_socket.py", line 958, in test_main
>  test_support.run_unittest(*tests)
>File "/home/Installer/Python/Python-2.5/Lib/test/test_support.py",
> line 441, in run_uni
>  ttest
>  run_suite(suite, testclass)
>File "/home/Installer/Python/Python-2.5/Lib/test/test_support.py",
> line 426, in run_sui
>  te
>  raise TestFailed(err)
>  test.test_support.TestFailed: Traceback (most recent call last):
>File "./Lib/test/test_socket.py", line 456, in testSockName
>  my_ip_addr = socket.gethostbyname(socket.gethostname())
>  gaierror: (-2, 'Name or service not known')

OK, so this fails:

my_ip_addr = socket.gethostbyname(socket.gethostname())

Try it from the python command line.  This is what happens when I try it 
on FC6 w/ Python 2.5 (retyped, tho):

>>> import socket
>>> socket.gethostname()
'localhost.localdomain'
>>> socket.gethostbyname(_)
'127.0.0.1'
>>>

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question: Install Tkinter with Python2.5

2007-02-24 Thread bobmon
> how can I install Tkinter with Python2.5? I can install Python2.5
> (tarball) in the usual way but there is no Tkinter? What's wrong?

I'm trying to build Python 2.5 under FC6,  and had similar problems
(plus others).  I had to do "yum install"  'tcl-devel.i386' and 'tk-
devel.i386' to get the tcl portion to work.  HTH.


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


Re: newbie needs help building Python 2.5 for Fedora Core 6

2007-02-24 Thread bobmon
WOW.  I'm gobsmacked...

On Feb 24, 6:13 pm, Tony Nelson
<[EMAIL PROTECTED]> wrote:
>
> Try it from the python command line.  This is what happens when I try it


Okay, that was interesting...

Apparently there's a subtlety of /etc/hosts that affects this!
Originally it had this line:
127.0.0.1localhostlocalhost.localdomainfoobar
and I get this result for my machine ("foobar.foodomain.com"):
>>>
>>> import socket
>>> socket.gethostname()
'foobar.foodomain.com'
>>> socket.gethostbyname(_)
Traceback (most recent call last):
  File "", line 1, in 
socket.gaierror: (-2, 'Name or service not known')
>>>
>>>
>>> socket.gethostbyname('localhost')
'127.0.0.1'
>>> socket.gethostbyname('localhost.localdomain')
'127.0.0.1'
>>>

Whe I change /etc/hosts to this:
127.0.0.1foobarfoobar.foodomain.net
localhost.localdomain   localhost
Python is happy and I get;
>>>
>>> import socket
>>> socket.gethostname()
'foobar.foodomain.net'
>>> socket.gethostbyname(_)
'127.0.0.1'
>>>


So, problem "fixed" although I have no real understanding of what was
wrong or what's right now.
Only that "gethostbyname()" seems to be really sensitive to the format
of the /etc/hosts file.

Thank you, Tony Nelson.
-Bob Montante, -bob,mon.

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


Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-24 Thread Charles D Hixson
Toby wrote:
> Charles D Hixson wrote:
>   
>> What I basically want is a kind of class that has both class and 
>> instance level dict variables, such that descendant classes 
>> automatically create their own class and instance level dict variables.  
>> The idea is that if a member of this hierarchy looks up something in 
>> it's local dict, and doesn't find it, it then looks in the class dict, 
>> and if not there it looks in its ancestral dict's.  This is rather like 
>> what Python does at compile time, but I want to do it at run time.
>> 
>
> I don't understand, Python already does it at runtime:
>
> class A:
>   A_class_var = 1
>
> class B(A):
>   B_class_var = 2
>   def __init__(self):
> self.B_inst_var = 3
>
>   
 b.A_class_var
 
> 1
>   
 b.B_class_var
 
> 2
>   
 b.B_inst_var
 
> 3
>   
 A.another = 4
 b.another
 
> 4
>
> Can you post a ">>>"-script of what you would like your classes to do?
>
>
> Toby
>   
Sorry, the "script" hasn't been written.  But Python apparently *won't* 
(automatically) do what I want, which is create a class whose 
sub-classes automatically have unique class variables of a determined 
form such that I can do a hierarchical search through them.  (I could 
plausibly handle this for the instance case but "class variables are 
static", so it looks like I can't do it for class variables in a 
straightforward manner.  This looks like it's going to demand a factory 
method, or some alternate approach.  (Not sure yet which I'll choose.)

What I'm looking for is a reasonable way to implement what Marvin Minsky 
calls Panologies.  These are "objects" (my term) with sufficient local 
intelligence to try alternative models of a situation until they find 
one that's appropriate.  E.g., is this being operated on as a physical 
transaction or a social transaction.  (Yes, it is physically happening, 
and it's taking place in physical space, but different models yield 
different analyses of what's happening.  Which is appropriate for the 
situation currently being evaluated?)

Well, I'm not trying to handle all that, merely to create a simple model 
of what a panology *IS*.  So each Panology object will need a list of 
delegatees to handle the operations, and a list of indexes to assist it 
in evaluating which delegatee to use.  If it doesn't find it locally, it 
will need to search through the situational context and these should be 
maintained at both the class and instance levels by it's ancestors.  The 
base class should have a method that manages the searching, and the 
finding of delegatees (models) based around the indexing keys.

This will take a bit of work, but if I can manage it, it should be 
rather interesting.  It could also be used to test some of Minsky's 
ideas...or not, because what I'm thinking of it different from exactly 
what he's proposing.

E.g., after I figure out how to build the basic structure, I'm going to 
need to figure out how to determine the appropriate model.  This may be 
a harder problem.

P.S.:  What I really expect is that by the time I get this solved, 
somebody else will already have a solution.  (It's happened before.  I 
had the "idea" of an "intelligent spam filter" before spambayes was 
built...but I was much too slow at the implementation.  MUCH!  (I spend 
too much time dreaming and not enough time programming.)

P.P.S.:  This isn't all loss.  I'm expecting that eventually I'll start 
running into performance problems, and at that point it would be 
necessary to start translating into a native-compiler language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What happened to SPE?

2007-02-24 Thread SPE - Stani's Python Editor
On Feb 3, 2:18 am, Jaroslaw Zabiello <[EMAIL PROTECTED]>
wrote:
> Dnia 11 Jan 2007 17:02:49 +0100, Neil Cerutti napisa³(a):
>
> >SPElost its web host, and last I heard is looking for a new
> > home. For now you can get it here:
>
> >  http://sourceforge.net/projects/spe/
>
> That is old addres. Never ishttp://developer.berlios.de/projects/python/
>
> --
> Jaroslaw Zabiellohttp://blog.zabiello.com

SPE will restart. Follow it on http://pythonide.stani.be

Stani

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


ANN: xlrd 0.6.1a4 is now available

2007-02-24 Thread John Machin
An alpha release (a4) of version 0.6.1 of xlrd is now available from
http://www.lexicon.net/sjmachin/xlrd.htm and from the Cheeseshop
(http://cheeseshop.python.org/pypi/xlrd).

What is xlrd? It's a small (download approx 0.1 Mb) pure-Python
library for extracting information  from Microsoft Excel (tm) files,
anywhere Python 2.1 or later will run -- no need for Excel itself, nor
COM, nor even Windows. Further info: follow the links on the home
page.

This release incorporates the functionality of 0.6.0 which was not
released
independently for various reasons including the need to push ahead
with the
0.6.1 functionality.

New in 0.6.0: facility to access named cell ranges and named
constants (Excel UI: Insert/Name/Define).

New in 0.6.1: extracts formatting information for cells (font, "number
format", background, border, alignment and protection) and rows/
columns (height/width etc). To save memory and time for those who
don't need it, this information is extracted only if formatting_info=1
is supplied to the open_workbook() function. The cell records BLANK
and MULBLANKS which contain no data, only formatting information, will
continue to be ignored in the default (no formatting info) case.

There have been several changes made to handle anomalous files
(written by
3rd party software) which Excel will open without complaint, but
failed
with xlrd, usually because an assertion fails or xlrd deliberately
raises an exception. Refer to HISTORY.html for details. These have
been changed to accept the anomaly either silently or with a NOTE
message  or a WARNING message, as appropriate.

Many thanks are due to Simplistix Ltd
(http://www.simplistix.co.uk). for funding the new functionality in
0.6.1.

BTW, Feedback: general discussion on the python-excel newsgroup (sign
up at http://groups.google.com.au/group/python-excel?lnk=li&hl=en) or
mailto: [EMAIL PROTECTED] preferably with [xlrd] in the message
subject.

Cheers,
John

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


Referencing Items in a List of Tuples

2007-02-24 Thread rshepard
  While working with lists of tuples is probably very common, none of my
five Python books or a Google search tell me how to refer to specific items
in each tuple. I find references to sorting a list of tuples, but not
extracting tuples based on their content.

  In my case, I have a list of 9 tuples. Each tuple has 30 items. The first
two items are 3-character strings, the remaining 28 itmes are floats.

  I want to create a new list from each tuple. But, I want the selection of
tuples, and their assignment to the new list, to be based on the values of
the first two items in each tuple.

  If I try, for example, writing:

for item in mainlist:
if mainlist[item][0] == 'eco' and mainlist[item][1] == 'con':
  ec.Append(mainlist[item][2:])

python doesn't like a non-numeric index.

  I would really appreciate a pointer so I can learn how to manipulate lists
of tuples by referencing specific items in each tuple (string or float).

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


Re: Referencing Items in a List of Tuples

2007-02-24 Thread Rune Strand
On Feb 25, 3:01 am, [EMAIL PROTECTED] wrote:
>   In my case, I have a list of 9 tuples. Each tuple has 30 items. The first
> two items are 3-character strings, the remaining 28 itmes are floats.
>
>   I want to create a new list from each tuple. But, I want the selection of
> tuples, and their assignment to the new list, to be based on the values of
> the first two items in each tuple.
>
>   If I try, for example, writing:
>
> for item in mainlist:
> if mainlist[item][0] == 'eco' and mainlist[item][1] == 'con':
>   ec.Append(mainlist[item][2:])
>
> python doesn't like a non-numeric index.
>

try this instead:
for item in mainlist:
 if item[0] == 'eco' and item[1] == 'con':
   ec.append(item[2:])

if you want numeric adressing, try:
for i in range(len(mainlist)):
   if mainlist[i][0] == 'eco'  etc.





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


Re: Referencing Items in a List of Tuples

2007-02-24 Thread John Machin
On Feb 25, 1:01 pm, [EMAIL PROTECTED] wrote:
>   While working with lists of tuples is probably very common, none of my
> five Python books or a Google search tell me how to refer to specific items
> in each tuple. I find references to sorting a list of tuples, but not
> extracting tuples based on their content.
>
>   In my case, I have a list of 9 tuples. Each tuple has 30 items. The first
> two items are 3-character strings, the remaining 28 itmes are floats.
>
>   I want to create a new list from each tuple. But, I want the selection of
> tuples, and their assignment to the new list, to be based on the values of
> the first two items in each tuple.
>
>   If I try, for example, writing:
>
> for item in mainlist:

item is one of your 30-element tuples, ...


> if mainlist[item][0] == 'eco' and mainlist[item][1] == 'con':

so do this:

if item[0] == 'eco' and item[1] == 'con':

>   ec.Append(mainlist[item][2:])

and

 ec.append(item[2:]) # note append, not Append

>
> python doesn't like a non-numeric index.

If nothing. Python doesn't like a non-numeric index, quite
irrespective of what you do :-)


>   I would really appreciate a pointer

Sorry, only nasty languages have pointers :-)

> so I can learn how to manipulate lists
> of tuples by referencing specific items in each tuple (string or float).

HTH,
John

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


Re: Referencing Items in a List of Tuples

2007-02-24 Thread Paul Rubin
"Rune Strand" <[EMAIL PROTECTED]> writes:
> if you want numeric adressing, try:
> for i in range(len(mainlist)):
>if mainlist[i][0] == 'eco'  etc.

Preferable:

for i,m in enumerate(mainlist):
   if m[0] == 'eco' etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


convert python scripts to exe file

2007-02-24 Thread Eric CHAO
I know py2exe can make an exe file. But python runtime dll is still
there. How can I combine the dll file into the exe, just make one
file?

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


Re: Endianness conversion

2007-02-24 Thread Gabriel Genellina
En Sat, 24 Feb 2007 14:27:12 -0300, Toby <[EMAIL PROTECTED]> escribió:

> I ended up writing my own byteswapper in Pyrex:

You can use the byteswap method of arrays:

>>> import array
>>> a = array.array('H', 'ABcd56')
>>> a.tostring()
'ABcd56'
>>> a.byteswap()
>>> a.tostring()
'BAdc65'

-- 
Gabriel Genellina

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


Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-24 Thread Gabriel Genellina
En Sat, 24 Feb 2007 21:29:13 -0300, Charles D Hixson  
<[EMAIL PROTECTED]> escribió:

> Sorry, the "script" hasn't been written.  But Python apparently *won't*
> (automatically) do what I want, which is create a class whose
> sub-classes automatically have unique class variables of a determined
> form such that I can do a hierarchical search through them.  (I could
> plausibly handle this for the instance case but "class variables are
> static", so it looks like I can't do it for class variables in a
> straightforward manner.  This looks like it's going to demand a factory
> method, or some alternate approach.  (Not sure yet which I'll choose.)

"Class variables are static" until you assign to them a new value, then  
become instance (normal) attributes.

class A:
   x = 1

a = A()
a.x # prints 1
a.x = 100
a.x # prints 100
A.x # still 1
b = A()
b.x # still 1

> What I'm looking for is a reasonable way to implement what Marvin Minsky
> calls Panologies.  These are "objects" (my term) with sufficient local
> intelligence to try alternative models of a situation until they find
> one that's appropriate.  E.g., is this being operated on as a physical
> transaction or a social transaction.  (Yes, it is physically happening,
> and it's taking place in physical space, but different models yield
> different analyses of what's happening.  Which is appropriate for the
> situation currently being evaluated?)

You may be interested on Acquisition, a concept from Zope2. Objects not  
only have behavior by nature (inheritance) but nurture (acquisition).  
*Where* an object is contained (or, *how* you reach to it), determines its  
behavior as well as *what* it is.

> P.P.S.:  This isn't all loss.  I'm expecting that eventually I'll start
> running into performance problems, and at that point it would be
> necessary to start translating into a native-compiler language.

Your design seems to be too dynamic to be feasible on a more static  
language.

-- 
Gabriel Genellina

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


Re: convert python scripts to exe file

2007-02-24 Thread Gabriel Genellina
En Sun, 25 Feb 2007 00:29:53 -0300, Eric CHAO <[EMAIL PROTECTED]>  
escribió:

> I know py2exe can make an exe file. But python runtime dll is still
> there. How can I combine the dll file into the exe, just make one
> file?

May I ask why? If you want to distribute your app on a single file, there  
are many installers available that will package that for you (try  
InnoSetup).

-- 
Gabriel Genellina

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


Are weak refs slower than strong refs?

2007-02-24 Thread John Nagle
   Are weak refs slower than strong refs?  I've been considering making the
"parent" links in BeautifulSoup into weak refs, so the trees will release
immediately when they're no longer needed.  In general, all links back
towards the root of a tree should be weak refs; this breaks the loops
that give reference counting trouble.

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