Re: BaseHTTPServer and Apache

2007-04-14 Thread Ron Garret
In article <[EMAIL PROTECTED]>,
 "Luis M. González" <[EMAIL PROTECTED]> wrote:

> On Apr 13, 8:44 pm, Ron Garret <[EMAIL PROTECTED]> wrote:
> > In article <[EMAIL PROTECTED]>,
> >  Ron Garret <[EMAIL PROTECTED]> wrote:
> >
> > > Does
> > > anyone know of a straightforward way to get Apache to "forward" requests
> > > to a given path to another HTTP server running on a different port?
> >
> > Never mind, I think I figured it out.  Apparently what I need is the
> > ProxyPassReverse directive.
> >
> > I'd still be interested in hearing about people's experience using
> > BaseHTTPServer for real applications.
> >
> > Thanks,
> > rg
> 
> 
> Some python web frameworks use the aproach you described by means of
> mod_rewrite.
> For example, Karrigell and Cherrypy (although they offer also other
> ways of deployment).
> This page in Karrigell's docs show how: 
> http://karrigell.sourceforge.net/en/apache.htm

Thanks for that pointer.  Using the 502 handler to start the server is a 
nifty trick.

So I've got all that working now.  Next question: how do I set things up 
so that I can communicate to my server through a unix domain socket 
instead of a TCP socket?  (The reason I want to do this is that I'm 
running multiple copies of this server so that multiple engineers can do 
development each in their own sandbox, and assigning each of them their 
own port number is a configuration nightmare.)

I got as far as rewriting the server code to use a unix socket, but then 
I got stuck.

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

Re: nonstandard XML character entities?

2007-04-14 Thread Martin v. Löwis
> I'm new to xml mongering so forgive me if there's an obvious
> well-known answer to this.  It's not real obvious from the library
> documentation I've looked at so far.  Basically I have to munch of a
> bunch of xml files which contain character entities like ú 
> which are apparently nonstandard.

If they contain such things, and do not contain a document type
definition, they are not well-formed XML files (i.e. can't be
called "XML" in a meaningful sense).

It would have been helpful if you had given an example of such
a document.

> Basically I want to know if there's a way to supply the regular parser
> (preferably xml.etree but I guess I can switch to another one if
> necessary) with some kind of entity table, and/or if the info is
> supposed to be found in the DTD or someplace like that.  Right now I'm
> ignoring the DTD and simply figuring out the doc structure by
> eyeballing the xml files, maybe not a perfectly approved method but
> it seems to be what most people do.

If there is a document type declaration in the document, the best
way is to parse it in a mode where the parser downloads the DTD
when parsing it, and resolves the entity references itself.

In SAX, you can put an EntityResolver into the parser, and then
return a file-like object from resolveEntity. This can be used
to avoid the network download; the document type declaration
would still have to be present.

Alternatively, you can implement a skippedEntity callback in
the SAX content handler.

In ElementTree, the XMLTreeBuilder has an attribute entity
which is a dictionary used to map entity names in entity references
to their definitions. Whether you can make the parser download
the DTD itself, I don't know.

Regards,
Martin

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


Re: Lists and Tuples and Much More

2007-04-14 Thread Hendrik van Rooyen


 "7stud" <[EMAIL PROTECTED]> wrote:

> ..  But using a tuple as a
> key in a dictionary is probably something you will never do.

Yikes!  I do this all the time...

Think of an address in any one town.
It has a Street, and a number 
(could be more complex, like a sub number for an apartment 
in a block, but lets ignore that for now)

so:
addy = ("First Avenue", 10)
Residents = {addy:"Frank Everyman",..}

To make a thing where you can look up who lives at a place...
(this is simplistic of course, for illustrative purposes - few people
live completely alone. - it should be at least a list, or possibly a dict 
by surname...)

I find that when I do this, I almost invariably also create the
inverse dict:

Addresses = {"Frank Everyman":addy,.}

So that you can get at stuff from all directions.  If you keep it
up you have a home made relational database if you are not careful...

But if you limit it to one thing and its inverse, its quite useful, and it
would be nice to have one "doubledict" that can be accessed as speedily
from either end...

Sort of an internally linked list of mixed hashed immutables, where: 

doubledict["Frank Everyman"] yields addy, and
doubledict[addy] yields "Frank Everyman"

It would have direct applicability in things like the label table in
an assembler, for debugging and so on.

- Hendrik

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


Re: tuples, index method, Python's design

2007-04-14 Thread Martin v. Löwis
> The use case has already been discussed.  Removing the pointless
> inconsistency between lists and tuples means you can stop having to
> remember it, so you can free up brain cells for implementing useful
> things.  That increases your programming productivity.

So to increase consistency, the .index method should be removed
from lists, as well, IMO. If you find yourself doing a linear
search, something is wrong.

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


Re: How to get a forum for your free site?

2007-04-14 Thread Ann
On 4月14日, 下午2时49分, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> Normaly I would consider this way way off topic but I did notice that
> you offer unlimited space so I suppose it could be usefull for those
> of us that distribute software..  what else do I get some of the add
> space??  If you are after killer apps you should consider allowing
> combination of other boards between websites...  (I had a provider
> that went down in the .com bust that did that)

Don't be doubtful of our space .We can sure to provide you unlimited
free space forever. If you need add your space ,we could support
too.If you have the intention, you can leave the link, or contact with
me ,my MSN : [EMAIL PROTECTED] .
thank you.

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

Re: How to get a forum for your free site?

2007-04-14 Thread ann
On 4月14日, 下午3时39分, "Ann" <[EMAIL PROTECTED]> wrote:
> On 4月14日, 下午2时49分, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > Normaly I would consider this way way off topic but I did notice that
> > you offer unlimited space so I suppose it could be usefull for those
> > of us that distribute software..  what else do I get some of the add
> > space??  If you are after killer apps you should consider allowing
> > combination of other boards between websites...  (I had a provider
> > that went down in the .com bust that did that)
>
> Don't be doubtful of our space .We can sure to provide you unlimited
> free space forever. If you need add your space ,we could support
> too.If you have the intention, you can leave the link, or contact with
> me ,my MSN : [EMAIL PROTECTED] .
> thank you.

 What's your account on our forum ? So we could contact you
convenience.

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

Stdout

2007-04-14 Thread gbastian
Dear Users,

I am trying to recover through the python function
popen3 the stdout,in,err of a launched process.

I would like also to recover the stdout which you can
get only through the command:   command1 >& filename

Do you know how I can access to that stdout by python?

Thanks

GIacomo

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


Re: tuples, index method, Python's design

2007-04-14 Thread Steven D'Aprano
On Sat, 14 Apr 2007 08:19:36 +0200, Hendrik van Rooyen wrote:

> This is the point where the whole thing falls apart in my head and 
> I get real confused - I can't find a reason why, list or tuple, the first
> item can't be something, the second something else, etc...

It's not that they _can't_ be, but that the two sequence types were
designed for different uses:

Here are some tuples of statistics about people:

fred = (35, 66, 212)  # age, height, weight
george = (42, 75, 316)

They are tuples because each one is like a Pascal record or a C struct.

It isn't likely that you'll be in a position where you know that Fred's
age, height or weight is 66, but you don't know which one and so need
fred.index() to find out. Hence, tuples weren't designed to have an index
method.

Here are some lists of statistics about people:

ages = [35, 42, 26, 17, 18]
heights = [66, 75, 70, 61, 59]
weights = [212, 316, 295, 247, 251]
# notice that the first column is fred, the second column is george, etc.

They are mutable lists rather than immutable tuples because you don't know
ahead of time how many data items you need to store.

Now, it is likely that you'll want to know which column(s) have an age of
26, so lists were designed to have an index method.

Now, that's the sort of things tuples and lists were designed for. If you
want to use them for something else, you're free to.



-- 
Steven.

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


Re: Append data to a list within a dict

2007-04-14 Thread Hendrik van Rooyen
 "Tina I"  wrote:


> Hello group,
> 
> Say I have the following dictionary:
> 
> ListDict = {
> 'one' : ['oneone' , 'onetwo' , 'onethree'],
> 'two' : ['twoone' , 'twotwo', 'twothree'],
> 'three' : ['threeone' , 'threetwo', threethree']}
> 
> Now I want to append 'twofour' to the list of the 'two' key but I can't 
> figure out how to that?
> Some pointers would be greatly appreciated.
> 

Just do it:

ListDict['two'].append('twofour')

This works because ListDict['two'] is a list...

- Hendrik

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


Re: reading from sys.stdin

2007-04-14 Thread 7stud
On Apr 13, 6:20 am, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> 7stud wrote:
> > On Apr 13, 3:13 am, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> >> 7stud wrote:
> >>> I assume all input is buffered by default, so I'm not sure how it
> >>> explains things to say that input from sys.stdin is buffered.
> >> The difference with sys.stdin is that it has indeterminate length until
> >> you signal EOF. I believe you'd get the same problem reading from, say,
> >> a named pipe.
>
> > Couldn't you say the same thing about a file you are iterating over?
>
> Only if the file has indeterminate length. Regular files have a length.
>
>  This should be f = iter(raw_input,"") and this will end in a EOFError
>  and stop on blank line. So you need a wrapper
> >>> Why a wrapper?
> >> Because without a wrapper you'll get EOFError, while the file iterator
> >> would ordinarily give you StopIteration.
>
> > Did you run my example?  Did you get an error?  I don't get an error.
>
> Yes I did. I did get an error.
>
>  >>> lst = []
>  >>> f = iter(raw_input, "")
>  >>> for line in f:
> ... lst.append(line)
> ...
> abc
> def
> Traceback (most recent call last):
>File "", line 1, in 
> EOFError
> --
> Michael Hoffman

But if you hit return on a blank line, there is no error.  In other
words, will stop on a blank line and not return EOFError.

Anyway, it seems everyone is saying that when you iterate over a file,
the whole file is first read into memory.  Therefore iterating over
sys.stdin is consistent: you have to type Ctrl+D to signal EOF before
the iteration can start.  Is that about right?

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


Re: tuples, index method, Python's design

2007-04-14 Thread Hendrik van Rooyen
"Martin v. Löwis" <[EMAIL PROTECTED]> wrote:


>
> So to increase consistency, the .index method should be removed
> from lists, as well, IMO. If you find yourself doing a linear
> search, something is wrong.
>
I agree.
You should at the very least make it a binary search.
To do that you have to sort the list.
Much more efficient.

; - )

Please Sir, can I have the DoubleDict I asked for elsewhere in this thread?

- Hendrik

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Ali
On 14 Apr, 05:48, "Jack" <[EMAIL PROTECTED]> wrote:
> That's a good one. I got to find out what's special with Emacs :)

The users.

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


Re: Python and XML?

2007-04-14 Thread Stefan Behnel
Leonard J. Reder wrote:
> What is the best way to process a Relax NG Schema and auto generate XML
> Python parser/generator code?
> Any suggestions?

Not sure what you mean with "XML Python parser/generator code", but regarding
RNG, you should definitely give lxml a try. It may already be what you were
looking for anyway.

http://codespeak.net/lxml

Have fun,
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Double backslash in filepaths ?

2007-04-14 Thread Stef Mientki
It looks like sometimes a single backslash is replaced by a double backslash,
but sometimes it's not ???
See the error message below,
the first backslash is somewhere (not explicitly in my code) replaced,
but the second is not ???
Is it in general better to use double backslash in filepaths ?

thanks,
Stef Mientki


 >>> Write_Signal_File_Ext (IOO, fSamp, 'D:\data_to_test\test_global.pd')
Traceback (most recent call last):
 File "", line 21, in ?
 File "D:\data_to_test\Signal_WorkBench.py", line 118, in 
Write_Signal_File_Ext
 DataFile.Write_Data (Data)
 File "D:\data_to_test\Signal_WorkBench.py", line 95, in Write_Data
 self.Write_Header(Nchan)
 File "D:\data_to_test\Signal_WorkBench.py", line 83, in Write_Header
 self.datafile = open(self.filename,'wb')
IOError: [Errno 2] No such file or directory: 'D:\\data_to_test\test_global.pd'
-- 
http://mail.python.org/mailman/listinfo/python-list


Willa Ford Angelina Joli Paris Hilton

2007-04-14 Thread A - J
Willa   Ford Angelina  Joli Paris Hilton 


www.alphasearch.GR-- 
http://mail.python.org/mailman/listinfo/python-list

list comparison help?

2007-04-14 Thread Dropkick Punt
Hi. I have a list of common prefixes:

>>> prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r", "you", "u"]

And I have a string, that I split() into a list.

>>> sentence = "what the blazes is this"
>>> sentence = sentence.split()

Now I want to strip the sentence of all words in the prefix list. 

I tried this method:

>>> for x in prefixes:
...   if sentence.index(x):
... del sentence[sentence.index(x)]


This raises, the error: 

Traceback (most recent call last):
  File "", line 3, in ?
ValueError: list.index(x): x not in list

This puzzles me, because if x isn't in the list, the subroutine shouldn't 
attempt to delete it
from the list, so I'm not sure why it's complaining.

Can anybody explain this to me, &/or show me a better way to do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list comparison help?

2007-04-14 Thread Wojciech Muła
Dropkick Punt wrote:
 prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r", "you", 
 "u"]
> 
> And I have a string, that I split() into a list.
> 
 sentence = "what the blazes is this"
 sentence = sentence.split()
> 
> Now I want to strip the sentence of all words in the prefix list. 
> 
> I tried this method:
> 
 for x in prefixes:
> ... if sentence.index(x):
> ... del sentence[sentence.index(x)]
> 
> 
> This raises, the error: 
> 
> Traceback (most recent call last):
>   File "", line 3, in ?
> ValueError: list.index(x): x not in list
> 
> This puzzles me, because if x isn't in the list, the subroutine shouldn't 
> attempt to delete it
> from the list, so I'm not sure why it's complaining.

list.index raised ValueError, see error message.

> Can anybody explain this to me, &/or show me a better way to do it?

prefixes = set(prefixes)
sentence = [word for word in sentence.split() if word not in prefixes]

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


Re: Double backslash in filepaths ?

2007-04-14 Thread Michael Bentley

On Apr 14, 2007, at 4:26 AM, Stef Mientki wrote:

> It looks like sometimes a single backslash is replaced by a double  
> backslash,
> but sometimes it's not ???
> See the error message below,
> the first backslash is somewhere (not explicitly in my code) replaced,
> but the second is not ???
> Is it in general better to use double backslash in filepaths ?
>
> thanks,
> Stef Mientki
>
>
 Write_Signal_File_Ext (IOO, fSamp, 'D:\data_to_test 
 \test_global.pd')
> Traceback (most recent call last):
>  File "", line 21, in ?
>  File "D:\data_to_test\Signal_WorkBench.py", line 118, in  
> Write_Signal_File_Ext
>  DataFile.Write_Data (Data)
>  File "D:\data_to_test\Signal_WorkBench.py", line 95, in  
> Write_Data
>  self.Write_Header(Nchan)
>  File "D:\data_to_test\Signal_WorkBench.py", line 83, in  
> Write_Header
>  self.datafile = open(self.filename,'wb')
> IOError: [Errno 2] No such file or directory: 'D:\\data_to_test 
> \test_global.pd'

If I remember correctly, you don't really have to use backslashes at  
all.  I think that's just a holdover from when DOS filesystems first  
became hierarchical -- and they had already used the sensible  
directory delimiter '/' as a command line switch character.  So I  
think you can just substitute forward slashes and forget that double- 
backslash madness.

But that's not really answering your question, is it?

What you're looking for is called 'escape characters'. The single  
backslash combines with the 't' to become a TAB character.  The  
double backslashes combine to become '\'.  So:

 >>> print 'D:\\data_to_test\test_global.pd'
D:\data_to_test est_global.pd

hth,
Michael

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


Re: "HTTP error -1" from urllib2

2007-04-14 Thread John J. Lee
John Nagle <[EMAIL PROTECTED]> writes:

> I'm getting a wierd error from urllib2 when opening certain
> URLs.  The code works for most sites, but not all of them.
> Here's the traceback:
[...]
> InfoException: Problem with page "http://www.fourmilab.ch": HTTP error -1 - ..
> 
> This fails identically using Python 2.4 on a Windows desktop and on Python 2.5
> on a Linux server.
> 
> The site being accessed reads fine in a browser.  It's not a redirect,
> and it doesn't insist on cookies.
> 
> See "http://mail.python.org/pipermail/python-list/2005-March/314301.html";
> for another problem involving "HTTP error -1".

Can you create an example (preferably small) that fails?  Feel free to
email it to me if it includes something you don't want to post.

Simply fetching the URL you mention with urllib2.urlopen() works for
me, so I guess something extra is needed to reproduce the bug:

import urllib2
r = urllib2.urlopen("http://www.fourmilab.ch";)
print r.read()


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


Re: Emergence of Grok

2007-04-14 Thread Anton Vredegoor
Paul McGuire wrote:

> I just stumbled upon a great-looking project, to make Zope3 more
> approachable to mere mortals such as myself.  Echoing the ROR mantra
> of "convention over configuration", the Grok project (http://
> grok.zope.org/)  aims to stand on the shoulders of Zope3, while
> providing the ease of development of ROR (for instance, no more ZCML).
> 
> Philipp von Weitershausen has a set of slides at
> http://philikon.de/files/grok-bbq-sprint.pdf, and the Grok project
> page links to a number of tutorials.
> 
> Am I the last person to hear about this?

No, not anymore since I learned about it later than you :-)

However I can assure you this won't work. I'll tell you why.

I'm a reasonably experienced python programmer and eager and interested 
to explore new -to me- paradigms, especially when there seems to be a 
possibility for making some money. I was lucky to find some programming 
job where I could learn zope and plone and make some money at the same 
time. I noticed that somewhere between pure python and zope there is a 
division where one cannot cross except by *paying* someone some money in 
order to learn how things work. When I told my employer at the time 
about this -he was totally *not* a programmer- the response was like, 
hey, but his other guy learned about it in one month etc, etc, or he 
just pointed at some plone programming colleagues who 'kicked ass'. Upon 
inspection of the 'ass kicking' colleagues' code I noticed that they had 
only a very rudimentary knowledge of python, or even didn't know much 
about programming altogether.

There is no way around paying money because however 'intuitive' the code 
seems to be to the developers it is just not possible to read their 
sourcecode and understand what they are doing. This is a result of 
rapidly changing conventions that make it impossible to reproduce or 
adapt working code to one's specific likings. So the code examples are 
just one offs, working only for this specific case. Any adaptation will 
break the code, forcing one to contact -and pay- the developers, who are 
probably already working on some more advanced version.

As result we see the emergence of 'more easy' solutions -like plone- 
which try to hide the complexities of zope for the end user but end up 
becoming even harder to 'grok' because the zope developers are racing 
ahead and don't bother to explain things unless they get paid. And why 
shouldn't they because they have to make a living too, don't they? Well 
I've got to make a living too and being forced to continually follow 
them around unable to pay for education and as a consequence not able to 
reproduce their code is just not financially feasible. Sorry, but this 
stuff is only 'grokkable' for the early adopters, however good ones' 
general python skills are.

The problem gets even worse because by now -in order to make any money 
programming zope at all- one has to learn the zillion different ways 
_plone_ makes things 'easier' (it's not like there is a clean slate when 
one starts to work at a zope/plone programming site). The plone 
community is generally despised by the zope community because they are 
even more programming for money and not for universal enlightenment. I 
even suspect some plone programmers of hiding essential information from 
colleagues because that make *them* the experts, it's either that or 
maybe they just don't know themselves why things work the way they do 
and can't answer questions. OK, lets give them the benefit of doubt.

While such deviousness generally cannot be assumed for the zope 
developers - try and ask questions on zope versus plone forums and 
notice the difference in attitude to persons asking for information- 
there is still a large difference in the way the zope community and the 
general python community 'think' about documentation. One can get close 
to understanding but in order to make it work there is no way around 
paying someone. I just know because I am good with python, I can read 
code and I know when things are not explained adequately. Essentially 
all this stuff is a pyramid scheme, only profitable for the well 
connected and/or the early adopters.

That doesn't mean that I haven't met a lot of enthusiastic and helpful 
zope developers and programmers, it's just that they don't understand or 
don't want to understand that money can be a show stopper for people 
wanting to learn about zope.

A.

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


Python Feature Request: Explicit variable declarations

2007-04-14 Thread samjnaa
Hello. Please tell me whether this feature request is sane (and not
done before) for python so it can be posted to the python-dev mailing
list. I should say first that I am not a professional programmer with
too much technical knowledge.

I would like to have something like the "option explicit" statement in
Visual Basic which turns on C-like checking for declaration of
variables. This is highly helpful for people who are coming from C/C+
+, for people who are learning programming using Python, and even
professionals, since this helps prevent typo errors like:

sunlognitude = sunlongitude + 180.0

where the user has inadvertantly typed "g" before "n" and will later
wonder why his application is not working as expected.

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


Re: list comparison help?

2007-04-14 Thread 7stud
On Apr 14, 3:36 am, "Dropkick Punt" <[EMAIL PROTECTED]> wrote:
> Hi. I have a list of common prefixes:
>
> >>> prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r", "you", 
> >>> "u"]
>
> And I have a string, that I split() into a list.
>
> >>> sentence = "what the blazes is this"
> >>> sentence = sentence.split()
>
> Now I want to strip the sentence of all words in the prefix list.
>
> I tried this method:
>
> >>> for x in prefixes:
>
> ...   if sentence.index(x):
> ... del sentence[sentence.index(x)]
>
> This raises, the error:
>
> Traceback (most recent call last):
>   File "", line 3, in ?
> ValueError: list.index(x): x not in list
>
> This puzzles me, because if x isn't in the list, the subroutine shouldn't 
> attempt to delete it
> from the list, so I'm not sure why it's complaining.
>
> Can anybody explain this to me, &/or show me a better way to do it?

Add some print statements to help you figure out what is going on:

for x in prefixes:
print x
a = sentence.index(x)
print "index: " + str(a)
if a:
del sentence[sentence.index(x)]

The problem is: to evaluate the if statement, python executes
sentence.index(x) and the return value of that is examined to see if
it is True or False.  However sentence.index(x) throws an exception
when the word x is not found in sentence, and therefore your program
terminates before the if statement ever completes its evaluation.

So you need to use something in your if condition that won't throw an
exeception, i.e. something that returns only true or false, like:

for prefix in prefixes:
while prefix in sentence:   #remove only removes the first
occurrence
   sentence.remove(prefix)


Here is a better way:

prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r",
"you", "u"]
sentence = "what the blazes is the da this da this the"
sentence = sentence.split()

result = [word for word in sentence if word not in prefixes]
print result


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


Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread samjnaa
This is like the previous one. Please check for sanity and approve for
posting at python-dev.

I would like to have something like "option base" in Visual Basic.
IIRC it used to allow me to choose whether 0 or 1 should be used as
the base of member indices of arrays. In Python, the same can be used
with strings, lists, tuples etc.

This would mean:
foo = "foo"
=> foo[1] == 'f'

foo = ['foo', 'bar', 'spam' ]
=> foo[1] == 'foo'

foo = ('spam', 'eggs')
=> foo[1] == 'spam'

For convenience it should also affect the range function so that:

range(3) = [1, 2, 3]

because this is often used where arrays would be used in VB.

Finally, when the programmer does not specify his choice of base at
the beginning of the program, the current behaviour of using 0 as base
should continue so that there is no problem with backward
compatibility.

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


Python Feature Request: (?) Group all file-directory-related stdlib functions in one place

2007-04-14 Thread samjnaa
Please check for sanity and approve for posting at python-dev.

Currently file-directory-related functionality in the Python standard
library is scattered among various modules such as shutil, os,
dircache etc. So I request that the functions be gathered and
consolidated at one place. Some may need renaming to avoid conflicts
or for clarification.

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


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread Paddy
On Apr 14, 11:21 am, [EMAIL PROTECTED] wrote:
> Hello. Please tell me whether this feature request is sane (and not
> done before) for python so it can be posted to the python-dev mailing
> list. I should say first that I am not a professional programmer with
> too much technical knowledge.
>
> I would like to have something like the "option explicit" statement in
> Visual Basic which turns on C-like checking for declaration of
> variables. This is highly helpful for people who are coming from C/C+
> +, for people who are learning programming using Python, and even
> professionals, since this helps prevent typo errors like:
>
> sunlognitude = sunlongitude + 180.0
>
> where the user has inadvertantly typed "g" before "n" and will later
> wonder why his application is not working as expected.

Please read this:
http://www.python.org/doc/faq/programming.html#is-there-a-tool-to-help-find-bugs-or-perform-static-analysis

PyChecker and Pylint might help you.

- Paddy.

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


Re: Double backslash in filepaths ?

2007-04-14 Thread John J. Lee
Stef Mientki <[EMAIL PROTECTED]> writes:

> It looks like sometimes a single backslash is replaced by a double backslash,
> but sometimes it's not ???
> See the error message below,
> the first backslash is somewhere (not explicitly in my code) replaced,
> but the second is not ???
> Is it in general better to use double backslash in filepaths ?
[...]
> IOError: [Errno 2] No such file or directory: 
> 'D:\\data_to_test\test_global.pd'

'\t' is the tab character.  '\d' is not a valid escape sequence, so
the backslash there survives intact.  repr() normalises the string on
output, so the (single!) backslash in '\d' is displayed, as always in
the repr of strings, as '\\'.

You should either use this:

'D:\\data_to_test\\test_global.pd'


Or this:

r'D:\data_to_test\test_global.pd'

See also:

http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-backslash


Or even this, which will work unless you're using crufty software that
doesn't like slash path separators (cmd.exe being one of those pieces
of software):

'D:/data_to_test/test_global.pd'


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


problem with qthread and signal/slot

2007-04-14 Thread Pradnyesh Sawant
Hello,
i've written a small pyqt code which increments a counter in the backend,
and prints it on the frontend. However, i'm passing a dummy string var
along with it in the signal/slot mechanism. The problem is that from
the 2nd call onwards, the string gets printed, but NOT in the 1st
call. (eg, in the foll code i get:- 1, (2, 'a'), (3, 'a'), ...)
The code is:-
**
import time
import sys
from PyQt4 import QtGui, QtCore

class Counter(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
self.cntr = 0
def run(self):
while True:
self.cntr += 1
self.emit(QtCore.SIGNAL("showCntr"), (self.cntr, "a"))
time.sleep(1)
if self.cntr == 10: break
class Gui(QtGui.QDialog):
def __init__(self, parent = None):
QtGui.QDialog.__init__(self, parent)
frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel

self.lCntr = QtGui.QLabel()
self.lCntr.setFrameStyle(frameStyle)
loGrd = QtGui.QGridLayout()
loGrd.addWidget(self.lCntr, 0, 0)
self.setLayout(loGrd)
self.setWindowTitle(self.tr("Counter"))
def showCntr(self, val):
print val
self.lCntr.setText(str(val))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
dialog = Gui()
cntr = Counter()
cntr.start()
QtCore.QObject.connect(cntr, QtCore.SIGNAL("showCntr"),
dialog.showCntr, QtCore.Qt.QueuedConnection)
sys.exit(dialog.exec_())
**
Also, this is my 1st ever prog with signals/slots across threads; and
am a newbie to python and pyqt. So please be considerate and kind
enough to point out mistakes/better approaches with the above code.

Thanks a lot!
-- 
warm regards,
Pradnyesh Sawant
--
Be yourself, everyone else is taken. --Anon
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread samjnaa
Please check for sanity and approve for posting at python-dev.

In Visual Basic there is the keyword "with" which allows an object-
name to be declared as governing the following statements. For
example:

with quitCommandButton
 .enabled = true
 .default = true
end with

This is syntactic sugar for:

quitCommandButton.enabled=true
quitCommandButton.default=true

This can be very useful especially in GUI programming when we have to
type the same object name in line-after-line. I personally found
having to type the word "self" umpteen times inside classes very
irritating. Such a beautiful language is Python, she should have this
good feature from VB too.

Now I hear that the word "with" is being discussed for a different
purpose in Py 3 as a result of a PEP and I don't want to conflict with
that. So I propose the word "using" as a replacement. This also is
similar to the C++ "using" keyword which exposes the members of a
namespace to access without specifying the namespace scope for each
reference. For example after giving "using namespace std;" I can
change all references to "std::cout" to "cout", which is similar to
what I am proposing for Python now.

Some thoughts about how this "using" statement should behave. The word
using should be followed by an object name and a colon indicating the
start of a block. The object named after "using" must determine the
context (or whatever the technical word is) of the of the statements
in that block.

self.setFixedSize(200, 120)
self.quit = QtGui.QPushButton("Quit", self)
self.quit.setGeometry(62, 40, 75, 30)
self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
QtCore.SLOT("quit()"))

to be rewritten as:

using self:
__setFixedSize(200,120)
__quit = QtGui.QPushButton("Quit", self)
__using quit:
setGeometry(62, 40, 75, 30)
setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
__connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
QtCore.SLOT("quit()"))

[I don't know whether usenet will retain my indenting, so I changed
the tabs to underscores.]

This context governing may need to be limited to the first applicable
member - so that in the above example "self" governs setFixedSize,
quit, quit and connect only in each sentence and quit (self.quit)
governs setGeometry and setFont only. (Point is that the parser should
not search for self.QtGui, self.self or self.QtCore in sentences 3 and
7, and self.quit.QtGui in sentence 6.)

Due to my absence of professional experience, my request may be
somewhat unpolished technical-wise, but I believe that this is a very
useful feature for Python and hence request the technically-
knowledgeable to reformat it as necessary. Thank you.

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


Re: list comparison help?

2007-04-14 Thread bearophileHUGS
7stud:

> prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r",
> "you", "u"]
> sentence = "what the blazes is the da this da this the"
> sentence = sentence.split()
> result = [word for word in sentence if word not in prefixes]
> print result

If prefixes becomes long enough (let's say > 20) then it's faster to
use a set:

nowords = [ "the", "this", "that", "da", "d", "is", "are", "r", "you",
"u"]
prefixes = set(nowords)

Bye,
bearophile

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Paddy
On Apr 13, 7:20 pm, "Jack" <[EMAIL PROTECTED]> wrote:
> I wonder what everybody uses for Python editor/IDE on Linux?
> I use PyScripter on Windows, which is very good. Not sure if
> there's something handy like that on Linux. I need to do some
> development work on Linux and the distro I am using is Xubuntu.

When the Linux distros wanted an editor, they did not choose Emacs or
emaacs vi mode.
They chose vim.

Emacs users:
 Margaret Thatcher,
 Nixon,
 The Joker.
 Max Wall.

Vim users:
 Nelson Mandella,
 Ghandi,
 Isambard Kingdom Brunel,
 Batman.
 The Silver Surfer.
 Edison.
 Max Planck

Notepad user:
 G.W. Bush.

See, it's clear!

- Paddy ;-)

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


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread James Stroud
[EMAIL PROTECTED] wrote:
> Hello. Please tell me whether this feature request is sane (and not
> done before) for python so it can be posted to the python-dev mailing
> list. I should say first that I am not a professional programmer with
> too much technical knowledge.
> 
> I would like to have something like the "option explicit" statement in
> Visual Basic which turns on C-like checking for declaration of
> variables. This is highly helpful for people who are coming from C/C+
> +, for people who are learning programming using Python, and even
> professionals, since this helps prevent typo errors like:
> 
> sunlognitude = sunlongitude + 180.0
> 
> where the user has inadvertantly typed "g" before "n" and will later
> wonder why his application is not working as expected.
> 

I have no formal training in programming and thus have had to shake off 
all of the worst habits afflicting amateurs on my path to the modest 
proficiency I enjoy now. So let me assure you that this is something I 
can honestly say is just about the least of your worries and 
consequently has no place clogging up a language like python.

But, if you have masochistic tendencies and want a lot of overhead in 
your programming, you can always bind yourself mercilessly to classes:


class C(object):
   declared = ['bob', 'carol', 'ted', 'alice']
   def __setattr__(self, anattr, aval):
 if anattr not in C.declared:
   raise TypeError, "Just can't hook you up, bro."
 else:
   self.__dict__[anattr] = aval


E.g.:

py> class C(object):
...   declared = ['bob', 'carol', 'ted', 'alice']
...   def __setattr__(self, anattr, aval):
... if anattr not in C.declared:
...   raise TypeError, "Just can't hook you up, bro."
... else:
...   self.__dict__[anattr] = aval
...
py> c = C()
py> c.bob = 42
py> c.bob
42
py> c.x = 69
Traceback (most recent call last):
   File "", line 1, in 
   File "", line 5, in __setattr__
TypeError: Just can't hook you up, bro.


Extending this ugliness to type-checking is left as an exercise for the 
reader. Using metaclasses for such nonsense is left as an exercise for 
metaclass maniacs.

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


Re: Python Feature Request: (?) Group all file-directory-related stdlib functions in one place

2007-04-14 Thread bearophileHUGS
> Currently file-directory-related functionality in the Python standard
> library is scattered among various modules such as shutil, os,
> dircache etc. So I request that the functions be gathered and
> consolidated at one place. Some may need renaming to avoid conflicts
> or for clarification.

I think similar consolidations of the STD lib are positive, they are
scheduled for Python V.3.0-3.1:
http://www.python.org/dev/peps/pep-3001/
http://www.python.org/dev/peps/pep-3108/
If you submit this to python-dev I suggest you to work as much as
possible: finding a good organization, writing justifications all for
all the changes etc. You can also remember that lot of people are
using some nonstandard modules, like the path one, that may be fit for
the STD library, once cleaned up a bit, so you have to take into
accout that too.

Bye,
bearophile

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


Re: list comparison help?

2007-04-14 Thread mik3l3374
On Apr 14, 5:36 pm, "Dropkick Punt" <[EMAIL PROTECTED]> wrote:
> Hi. I have a list of common prefixes:
>
> >>> prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r", "you", 
> >>> "u"]
>
> And I have a string, that I split() into a list.
>
> >>> sentence = "what the blazes is this"
> >>> sentence = sentence.split()
>
> Now I want to strip the sentence of all words in the prefix list.
>
> I tried this method:
>
> >>> for x in prefixes:
>
> ...   if sentence.index(x):
> ... del sentence[sentence.index(x)]
>
> This raises, the error:
>
> Traceback (most recent call last):
>   File "", line 3, in ?
> ValueError: list.index(x): x not in list
>
> This puzzles me, because if x isn't in the list, the subroutine shouldn't 
> attempt to delete it
> from the list, so I'm not sure why it's complaining.
>
> Can anybody explain this to me, &/or show me a better way to do it?

>>> prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r", "you", "u"]
>>> sentence = "what the blazes is this"
>>> sentence = sentence.split()
>>> sentence
['what', 'the', 'blazes', 'is', 'this']
>>> set(sentence).difference(prefixes)
set(['what', 'blazes'])

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


Re: XML/encoding/prolog/python hell...

2007-04-14 Thread Stefan Behnel
fscked schrieb:
> I am a beginning pythoner and I am having a terrible time trying to
> figure out how to do something that (it would seeme to me) should be
> fairly simple.
> 
> I have a CSV file of unknown encoding and I need to parse that file to
> get the fields <--- DONE
> I need to create an xml document that has the proper prolog and
> namespace information in it. <--- NOT DONE
> I need it to be encoded properly<--- Looks right in IE, not right in
> any other app.

UTF-8 encoding is the default. No need for a prologue here.

ET 1.3 will have an xml_declaration keyword argument for write() that will
allow you to write the declaration even if unnecessary. lxml already has it
now (and is ET compatible, so your code should just straight work).

http://codespeak.net/lxml


> I should say that I have googled my butt off, tried ElementTree,
> CSV2XML, and various other things and cannot get any of them to work.
> 
> A sample of the output I am looking for is as follows:
> 
> 
> 
>pl_h="No Data" name="Lounge" address="here" phone="555-"
> country="US" city="LA"/>
>pl_h="No Data" name="MyHouse" address="there" phone="555-5556"
> country="US" city="New York"/>
> 

This should help you to get namespaces working:

http://effbot.org/zone/element.htm#xml-namespaces

Hope it helps,
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> Hello. Please tell me whether this feature request is sane (and not
> done before) for python so it can be posted to the python-dev mailing
> list. I should say first that I am not a professional programmer with
> too much technical knowledge.

I believe it has been requested before, but I'm too lazy now to search
for prior discussion. The request is sane, but is also incomplete: there
is no syntax suggested for the actual declarations of local variables,
and no discussion whether this is meant to apply to local variables
only, or also to global variables and object attributes.

I think there is a fairly low chance that such a request will be
considered. It's a big change (implementation-wise, and
documentation-wise), and likely controversial. So one would have
to write a PEP first (see PEP 1 for details).

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


Re: XML/encoding/prolog/python hell...

2007-04-14 Thread Stefan Behnel
with lxml (although untested):

fscked wrote:
> import os,sys
> import csv

from lxml.etree import Element, SubElement, ElementTree, tostring

> root = Element("{Boxes}boxes")
> myfile = open('ClientsXMLUpdate.csv')
> csvreader = csv.reader(myfile)
> 
> for row in csvreader:
> mainbox = SubElement(root, "{Boxes}box")
> r2 = csv.reader(myfile)
> b = r2.next()
> mainbox.put("city", b[10])
[...]

ElementTree(root).write('test.xml', "UTF-8", xml_declaration=True,
pretty_print=True)

Hope it helps,
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Double backslash in filepaths ?

2007-04-14 Thread Stef Mientki
John J. Lee wrote:
> Stef Mientki <[EMAIL PROTECTED]> writes:
> 
>> It looks like sometimes a single backslash is replaced by a double backslash,
>> but sometimes it's not ???
>> See the error message below,
>> the first backslash is somewhere (not explicitly in my code) replaced,
>> but the second is not ???
>> Is it in general better to use double backslash in filepaths ?
> [...]
>> IOError: [Errno 2] No such file or directory: 
>> 'D:\\data_to_test\test_global.pd'
> 
> '\t' is the tab character.  '\d' is not a valid escape sequence, so
> the backslash there survives intact.  repr() normalises the string on
> output, so the (single!) backslash in '\d' is displayed, as always in
> the repr of strings, as '\\'.
> 
> You should either use this:
> 
> 'D:\\data_to_test\\test_global.pd'
> 
> 
> Or this:
> 
> r'D:\data_to_test\test_global.pd'
> 
> See also:
> 
> http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-backslash
> 
> 
> Or even this, which will work unless you're using crufty software that
> doesn't like slash path separators (cmd.exe being one of those pieces
> of software):
> 
> 'D:/data_to_test/test_global.pd'
> 
> 
> John

thanks John and Michael,
this is a very helpful explanation.

cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> This is like the previous one. Please check for sanity and approve for
> posting at python-dev.

This one is not sane. It's not possible to change the indexing of
objects on a per-module basis, as objects may cross module boundaries.

Suppose you have this code:

option base
import sys
print sys.path[1]

So should the be 0-based (because path is in module sys), or should
it be one-based (because the access occurs in a module that uses
1-indexing)?

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


Re: Python Feature Request: (?) Group all file-directory-related stdlib functions in one place

2007-04-14 Thread Martin v. Löwis
> Currently file-directory-related functionality in the Python standard
> library is scattered among various modules such as shutil, os,
> dircache etc. So I request that the functions be gathered and
> consolidated at one place. Some may need renaming to avoid conflicts
> or for clarification.
> 

Please see PEP 355.

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread James Stroud
[EMAIL PROTECTED] wrote:
> Please check for sanity and approve for posting at python-dev.
> 
> In Visual Basic there is the keyword "with" which allows an object-
> name to be declared as governing the following statements. For
> example:
> 
> with quitCommandButton
>  .enabled = true
>  .default = true
> end with
> 
> This is syntactic sugar for:
> 
> quitCommandButton.enabled=true
> quitCommandButton.default=true
> 
> This can be very useful especially in GUI programming when we have to
> type the same object name in line-after-line. I personally found
> having to type the word "self" umpteen times inside classes very
> irritating. Such a beautiful language is Python, she should have this
> good feature from VB too.
> 
> Now I hear that the word "with" is being discussed for a different
> purpose in Py 3 as a result of a PEP and I don't want to conflict with
> that. So I propose the word "using" as a replacement. This also is
> similar to the C++ "using" keyword which exposes the members of a
> namespace to access without specifying the namespace scope for each
> reference. For example after giving "using namespace std;" I can
> change all references to "std::cout" to "cout", which is similar to
> what I am proposing for Python now.
> 
> Some thoughts about how this "using" statement should behave. The word
> using should be followed by an object name and a colon indicating the
> start of a block. The object named after "using" must determine the
> context (or whatever the technical word is) of the of the statements
> in that block.
> 
> self.setFixedSize(200, 120)
> self.quit = QtGui.QPushButton("Quit", self)
> self.quit.setGeometry(62, 40, 75, 30)
> self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
> self.connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
> QtCore.SLOT("quit()"))
> 
> to be rewritten as:
> 
> using self:
> __setFixedSize(200,120)
> __quit = QtGui.QPushButton("Quit", self)
> __using quit:
> setGeometry(62, 40, 75, 30)
> setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
> __connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
> QtCore.SLOT("quit()"))
> 
> [I don't know whether usenet will retain my indenting, so I changed
> the tabs to underscores.]
> 
> This context governing may need to be limited to the first applicable
> member - so that in the above example "self" governs setFixedSize,
> quit, quit and connect only in each sentence and quit (self.quit)
> governs setGeometry and setFont only. (Point is that the parser should
> not search for self.QtGui, self.self or self.QtCore in sentences 3 and
> 7, and self.quit.QtGui in sentence 6.)
> 
> Due to my absence of professional experience, my request may be
> somewhat unpolished technical-wise, but I believe that this is a very
> useful feature for Python and hence request the technically-
> knowledgeable to reformat it as necessary. Thank you.
> 

I like this one for some reason. Just the "using self" would save hella 
typing in a lot of classes. I would favor a convention with leading dots 
to disambiguate from other variables. This wouldn't conflict with, say, 
floats, because variable names can't begin with a number.

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


Re: ulimit on open sockets ?

2007-04-14 Thread Maxim Veksler
On 4/13/07, Alex Martelli <[EMAIL PROTECTED]> wrote:
>
> On Apr 12, 2007, at 1:17 PM, Maxim Veksler wrote:
> ...
> > Now, someone I work with suggested a simple work around "Pass the list
> > objects in groups of 1024 each time to the select.select structure". I
> > think it's acceptable and good advice, the thing is I don't know how
> > to implement this "the python way" (that is - with out it being ugly).
>
> I don't understand how you're going to make it work (I see no select
> calls in your code and I don't understand how you'd get one in there
> by polling), but I'm going to just explain how to get slices of 1024
> items at a time from a long list.
>

Thank you. I'm attaching the full code so far for reference, sadly it
still doesn't work. It seems that select.select gets it's count of
fd's not from the amount passed to it by the sub_list but from the
kernel (or whatever) count for the process; The main issue here is
that it seems I won't be able to use select for the simple
non-blocking process and am forced to check poll to see if that helps.

The error I'm getting is still the same:

# ulimit -n
50
# python listener_sockets_range.py
Traceback (most recent call last):
  File "listener_sockets_range.py", line 22, in ?
ready_to_read, ready_to_write, in_error =
select.select(select_cap_sockets, [], [], 0)
ValueError: filedescriptor out of range in select()


"""
#!/usr/bin/env python

import socket, select

def get_non_blocking_socket(port_number):
print port_number

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
s.bind(('0.0.0.0', port_number))
s.listen(1)
return s

def slice_by_fd_limit(longlist, N=1024):
for i in xrange(0, len(longlist), N):
yield longlist[i:i+N]

all_sockets = map(get_non_blocking_socket, xrange(1, 2))

while 1:
for select_cap_sockets in slice_by_fd_limit(all_sockets):
ready_to_read, ready_to_write, in_error =
select.select(select_cap_sockets, [], [], 0)
for nb_active_socket in all_sockets:
if nb_active_socket in ready_to_read:
conn, addr = nb_active_socket.accept()
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
"""

-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading from sys.stdin

2007-04-14 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, 7stud wrote:

> Anyway, it seems everyone is saying that when you iterate over a file, the
> whole file is first read into memory.  Therefore iterating over sys.stdin
> is consistent: you have to type Ctrl+D to signal EOF before the iteration
> can start.  Is that about right?

Not the whole file is read but a block of it.  If you type in enough to
fill the buffer the iteration can start without an EOF on `sys.stdin`.

See the second example in <[EMAIL PROTECTED]> which
demonstrates that not the whole file is read at once by the iterator.

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread jamadagni
> I like this one for some reason. Just the "using self" would save hella
> typing in a lot of classes. I would favor a convention with leading dots
> to disambiguate from other variables. This wouldn't conflict with, say,
> floats, because variable names can't begin with a number.

Excellent. Now we don't have to worry about the "first applicable
instance" etc. Any member that begins with a dot will have the context
governer auto-prefixed by the parser. This means that nested using
statements should be like follows:

using self:
__using .quit:

with the dot preceding quit also. Excellent!

But you have said "variable names can't begin with a number". The
point this, they shouldn't be able to begin with a *dot*. We are not
worried about numbers here, right?

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread James Stroud
jamadagni wrote:
>> I like this one for some reason. Just the "using self" would save hella
>> typing in a lot of classes. I would favor a convention with leading dots
>> to disambiguate from other variables. This wouldn't conflict with, say,
>> floats, because variable names can't begin with a number.
> 
> Excellent. Now we don't have to worry about the "first applicable
> instance" etc. Any member that begins with a dot will have the context
> governer auto-prefixed by the parser. This means that nested using
> statements should be like follows:
> 
> using self:
> __using .quit:

Under what circumstances would this not mean "using self.quit"? I think 
one  must be refreshingly imaginative to infer that I was proposing that 
we add "." to variable names in general. The idea would be that it 
specifies to which names the using statement applies.

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


Re: Portably generating infinity and NaN

2007-04-14 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> % python
> Python 2.6a0 (trunk:54264M, Mar 10 2007, 15:19:48) 
> [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
> Type "help", "copyright", "credits" or "license" for more
> information. 
> >>> import struct
> >>> struct.pack("f", float("Inf"))
> '\x7f\x80\x00\x00'
> >>> struct.pack("f", float("NaN"))
> '\x7f\xc0\x00\x00'
> 
> (Note the absence of a demonstration on Windows.)  Can't the above be
> blessed as the One True Way and wormed around in floatmodule.c for
> those platforms where float'ing "NaN" or "Inf" doesn't currently work?

How about doing the same in reverse to generate the values on Windows? It 
should be pretty portable, otherwise the struct module doesn't work as 
advertised:

>>> NaN, Inf = struct.unpack("!2f",  '\x7f\xc0\x00\x00\x7f\x80\x00\x00')
>>> NaN,Inf
(1.#QNAN, 1.#INF)

This also means you can choose which NaN you generate, although given 
that it compares unequal with itself it probably doesn't matter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread James Stroud
jamadagni wrote:
>> I like this one for some reason. Just the "using self" would save hella
>> typing in a lot of classes. I would favor a convention with leading dots
>> to disambiguate from other variables. This wouldn't conflict with, say,
>> floats, because variable names can't begin with a number.
> 
> Excellent. Now we don't have to worry about the "first applicable
> instance" etc. Any member that begins with a dot will have the context
> governer auto-prefixed by the parser. This means that nested using
> statements should be like follows:
> 
> using self:
> __using .quit:
> 
> with the dot preceding quit also. Excellent!
> 
> But you have said "variable names can't begin with a number". The
> point this, they shouldn't be able to begin with a *dot*. We are not
> worried about numbers here, right?
> 

On third or fourth read, I think you are not being sarcastic and 
rhetorical--sorry for my misunderstanding you--I think fatigue is 
affecting the little voices in my head. I'm just saying that a preceding 
dot is not otherwise used in the language except for perhaps floats.

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread Duncan Booth
James Stroud <[EMAIL PROTECTED]> wrote:
> I like this one for some reason. Just the "using self" would save
> hella typing in a lot of classes. I would favor a convention with
> leading dots to disambiguate from other variables. This wouldn't
> conflict with, say, floats, because variable names can't begin with a
> number. 

I can't see how it is going to save you any typing over what you can
already do. 

The suggested example:

 self.setFixedSize(200, 120)
 self.quit = QtGui.QPushButton("Quit", self)
 self.quit.setGeometry(62, 40, 75, 30)
 self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
 self.connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
 QtCore.SLOT("quit()"))

(259 characters including newlines but not leading indents).

would become:

 using self:
 .setFixedSize(200,120)
 .quit = QtGui.QPushButton("Quit", self)
 using quit:
 .setGeometry(62, 40, 75, 30)
 .setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
 .connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp, 
QtCore.SLOT("quit()"))

(251 characters including newlines but not leading indents).

If you are going to reference self.quit a lot of times then it makes
sense to also assign it to a local variable and then you already get 
even fewer characters (239):

self.setFixedSize(200, 120)
q = self.quit = QtGui.QPushButton("Quit", self)
q.setGeometry(62, 40, 75, 30)
f = QtGui.QFont
q.setFont(f("Times", 18, f.Bold))
self.connect(q, QtCore.SIGNAL("clicked()"), QtGui.qApp, QtCore.SLOT("quit()"))

Assigning 's=self' would save even more typing, but there are limits 
to how unreadable you want it.

Using local variables also means you don't have any ambiguity and can 
use a variety of such shorthands interchangeably (e.g. q and f above).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

> In Visual Basic there is the keyword "with" which allows an
> object- name to be declared as governing the following statements.
> For example:
> 
> with quitCommandButton
>  .enabled = true
>  .default = true
> end with
> 
> This is syntactic sugar for:
> 
> quitCommandButton.enabled=true
> quitCommandButton.default=true

Personally, I'd never use it. In more complex modules, when you are
looking for, e. g., self.myVar and anotherObject.myVar,
this "using" statement decreases readability and maintainability
(in full text searching). IMHO.

Regards,


Björn

-- 
BOFH excuse #406:

Bad cafeteria food landed all the sysadmins in the hospital.

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


Re: wxPython, mac, wx.HSCROLL not working

2007-04-14 Thread Bjoern Schliessmann
7stud wrote:

> Huh?  Are you saying you found a solution?

Yes, the solution to 

| Where is that list?  

Regards,


Björn

-- 
BOFH excuse #382:

Someone was smoking in the computer room and set off the halon
systems.

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


visit http://www.real-article.com/computer/index.php

2007-04-14 Thread chuancs
The www.real-article.com website provides a ton of information about
computer. In addition, you will find extensive information on leading
computer to help you on your way to success.

Please have a look at our computer articles, products, resources, and
additional information located throughout www.real-article.com.

We strive to provide only quality articles, so if there is a specific
topic related to computer that you would like us to cover, please
contact us at any time.

visit http://www.real-article.com/computer/index.php

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


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread nikolas pontikos
[EMAIL PROTECTED] wrote:
> Hello. Please tell me whether this feature request is sane (and not
> done before) for python so it can be posted to the python-dev mailing
> list. I should say first that I am not a professional programmer with
> too much technical knowledge.
> 
> I would like to have something like the "option explicit" statement in
> Visual Basic which turns on C-like checking for declaration of
> variables. This is highly helpful for people who are coming from C/C+
> +, for people who are learning programming using Python, and even
> professionals, since this helps prevent typo errors like:
> 
> sunlognitude = sunlongitude + 180.0
> 
> where the user has inadvertantly typed "g" before "n" and will later
> wonder why his application is not working as expected.
> 

Just as a side-note, if you used a+=1 instead of a=a+1 then you wouldn't 
have this problem.
Languages like Perl and VB need a strict mode because they will 
auto-vivify variable for you.  I.e. they will bring variables to life 
with defined or undefined values if you use them in a l-value (left hand 
side of an assignment) without having declared them prior.  If you do 
that in Python you get an exception.

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


Re: Stdout

2007-04-14 Thread Dustan
On Apr 14, 2:49 am, [EMAIL PROTECTED] wrote:
> Dear Users,
>
> I am trying to recover through the python function
> popen3 the stdout,in,err of a launched process.
>
> I would like also to recover the stdout which you can
> get only through the command:   command1 >& filename
>
> Do you know how I can access to that stdout by python?

I'm not sure if I understand your entire post, but in python, you get
access to stdout through the sys module:

>>> print 'hello, world!'
hello, world!
>>> import sys
>>> sys.stdout.write('hello, world!')
hello, world!
>>>

> Thanks
>
> GIacomo


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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread jamadagni
On Apr 14, 5:06 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:

> I can't see how it is going to save you any typing over what you can
> already do.
>
> The suggested example:

The suggested example is only a small case. I realize that the main
usage would be when there are a lot of repetitive usages when the five
characters "using", the space and the colon at the end would be worth
the full typing.

> (259 characters including newlines but not leading indents).
> would become:
> (251 characters including newlines but not leading indents).

So there *is* gain even in this small case. It's a matter of avoiding
the bore and potential scope for typos in repetitive typing.

> If you are going to reference self.quit a lot of times then it makes
> sense to also assign it to a local variable and then you already get
> even fewer characters (239):

But you realize readability decreases considerably.

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread jamadagni
> Personally, I'd never use it.

You are free to avoid using it of course. :)

> In more complex modules, when you are
> looking for, e. g., self.myVar and anotherObject.myVar,
> this "using" statement decreases readability and maintainability
> (in full text searching). IMHO.

Why? Just search for self and you turn up using self. Just scan down
(the block) and you get myVar. Similarly for anotherObject.myVar.

Of course, you lose the possibility of just searching for self.myVar
-- something lost, something gained, IMHO.

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


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread jamadagni
> Languages like Perl and VB need a strict mode because they will
> auto-vivify variable for you.  I.e. they will bring variables to life
> with defined or undefined values if you use them in a l-value (left hand
> side of an assignment) without having declared them prior.  If you do
> that in Python you get an exception.

I don't comprehend. I can just type a = 5 in a new Python session and
I get no exception. Python currently does not require variables to be
declared before they are used on the LHS.

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


Re: reading from sys.stdin

2007-04-14 Thread Steve Holden
7stud wrote:
> On Apr 13, 6:20 am, Michael Hoffman <[EMAIL PROTECTED]> wrote:
[...]
> 
> But if you hit return on a blank line, there is no error.  In other
> words, will stop on a blank line and not return EOFError.
> 
> Anyway, it seems everyone is saying that when you iterate over a file,
> the whole file is first read into memory.  Therefore iterating over
> sys.stdin is consistent: you have to type Ctrl+D to signal EOF before
> the iteration can start.  Is that about right?
> 
No. The file content is usually buffered, but the buffering doesn't 
necessarily include the whole content of the file.

If you are iterating over the file the correct way to access the next 
line is to call the file's  .next() method, as I indicated before.

If you are reading lines the appropriate way is to use readline().

And, as you have already seen an error message telling you, mixing the 
two types is unlikely to give you usable results.

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

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread jamadagni
On Apr 14, 4:01 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> This one is not sane. It's not possible to change the indexing of
> objects on a per-module basis, as objects may cross module boundaries.

I do not request for this to be changed per-module. Once I say
something like:

from __future__ import indices_start_at_one

afterwards I would expect *any* index from *any* module to start at 1.
To my understanding, Python is going to parse the content of modules
only as and when they are called. So Python is basically reading the
content of those modules when the flag of indices_start_at_one is
active, and hence I would expect it to start counting at 1.

I can envisage, stemming from your comments, that this can lead to
trouble when a module being accessed has hard-coded indices. It would
not be fair of me to expect all module writers to declare the base
option at the head of each file, though it would be good practice. So
the solution is to allow the programmer to choose to limit this tag
locally or activate it globally.

option base 1 local
option base 1 global

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, jamadagni
wrote:

> On Apr 14, 4:01 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> 
>> This one is not sane. It's not possible to change the indexing of
>> objects on a per-module basis, as objects may cross module boundaries.
> 
> I do not request for this to be changed per-module. Once I say
> something like:
> 
> from __future__ import indices_start_at_one
> 
> afterwards I would expect *any* index from *any* module to start at 1.
> To my understanding, Python is going to parse the content of modules
> only as and when they are called.

Modules are parsed when they are imported.  And some modules are already
imported before your module is imported because they are built-in or
loaded to be able to import your module in the first place.  And what
about modules that are written in C?

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

Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread BJörn Lindqvist
Your idea isn't new and has already been discussed lots of time
before. It was once planned to be implemented in py3k, but no longer
is.

One of the problems is that with a "using" statement, you always have
to decide whether your code repeats some prefix enough times to use a
"using" statement. Should you write:

self.quit.action = self.bar
self.quit.name = "End it"

or should it be:

using self.quit:
.action = self.bar
.name = "End it"

? Not having to bother with petty things like that is an advantage.
Javascript has with-statements that are equivalent to your
using-statements but from what I've seen most programmers avoid them.
They don't increase readability one bit.

You already can emulate the using statement like this:

def using(obj, **kw):
for key, val in kw.items():
setattr(obj, key, val)

using(self.quit,
action = self.bar,
name = "End it")

But I have never seen anyone do that, which I think, is a sign that
nobody wants the feature.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nonstandard XML character entities?

2007-04-14 Thread Chuck Rhode
Martin v. Löwis wrote this on Sat, 14 Apr 2007 09:10:44 +0200.  My
reply is below.

> Paul Rubin:

>> I'm new to xml mongering so forgive me if there's an obvious
>> well-known answer to this.  It's not real obvious from the library
>> documentation I've looked at so far.  Basically I have to munch of
>> a bunch of xml files which contain character entities like ú
>> which are apparently nonstandard.

-snip-

> In ElementTree, the XMLTreeBuilder has an attribute entity which is
> a dictionary used to map entity names in entity references to their
> definitions. Whether you can make the parser download the DTD
> itself, I don't know.

What he said

Try this on your piano:

: import xml.etree.ElementTree  # or elementtree.ElementTree prior to 2.5
: ElementTree = xml.etree.ElementTree
: import htmlentitydefs


: class XmlFile(ElementTree.ElementTree):

  
: def __init__(self, file=None, tag='global', **extra):
: ElementTree.ElementTree.__init__(self)
: parser = ElementTree.XMLTreeBuilder(
: target=ElementTree.TreeBuilder(Element))
: parser.entity = htmlentitydefs.entitydefs
: self.parse(source=file, parser=parser)
: return


It looks goofy as can be, but it works for me.

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 32° — Wind Calm
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread jamadagni
> Modules are parsed when they are imported.  And some modules are already
> imported before your module is imported because they are built-in or
> loaded to be able to import your module in the first place.  And what
> about modules that are written in C?

OK fine. It is clear that this feature must be implemented if at all
only on a per-module basis. So can we have votes for per-module
implementation of this feature?

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


Re: nonstandard XML character entities?

2007-04-14 Thread Chuck Rhode
Chuck Rhode wrote this on Sat, 14 Apr 2007 09:04:45 -0500.  My reply is
below.

Fixed text wrap:

> import xml.etree.ElementTree  # or elementtree.ElementTree prior to 2.5
> ElementTree = xml.etree.ElementTree
> import htmlentitydefs


> class XmlFile(ElementTree.ElementTree):

> def __init__(self, file=None, tag='global', **extra):
> ElementTree.ElementTree.__init__(self) 
> parser = ElementTree.XMLTreeBuilder(
> target=ElementTree.TreeBuilder(Element))
> parser.entity = htmlentitydefs.entitydefs
> self.parse(source=file, parser=parser) 
> return


-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 32° — Wind Calm
-- 
http://mail.python.org/mailman/listinfo/python-list

Option Explicit

2007-04-14 Thread Clement
Is there any command like Option Explicit[In visual basic].

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread jamadagni
> You already can emulate the using statement like this:

You can emulate only assignments like this. How would you emulate
function calls, like the ones in my example?

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


Re: Option Explicit

2007-04-14 Thread jamadagni
On Apr 14, 7:20 pm, "Clement" <[EMAIL PROTECTED]> wrote:
> Is there any command like Option Explicit[In visual basic].

We have been discussing that over the past few hours. Please see the
thread:

"Python Feature Request: Explicit Variable Declarations".

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


Making a tree out of a 2 column list

2007-04-14 Thread Sebastian Bassi
I have a two column list like:

2,131
6,335
7,6
8,9
10,131
131,99
5,10

And I want to store it in a tree-like structure.
So if I request 131, it should return all the child of 131, like 2, 10
and 5 (since 5 is child of 10).
If I request 335, it should return: 6 and 7.
If I request 9, it should return 8.
I guess I could use tuples or dictionaries to do it, but I can't figure out how.

Best,
SB.


-- 
Sebastián Bassi
Diplomado Ciencia y Tecnología.
Club de la razón (www.clubdelarazon.org)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread Army1987
"jamadagni" <[EMAIL PROTECTED]> ha scritto nel messaggio 
news:[EMAIL PROTECTED]
>> Languages like Perl and VB need a strict mode because they will
>> auto-vivify variable for you.  I.e. they will bring variables to life
>> with defined or undefined values if you use them in a l-value (left hand
>> side of an assignment) without having declared them prior.  If you do
>> that in Python you get an exception.
>
> I don't comprehend. I can just type a = 5 in a new Python session and
> I get no exception. Python currently does not require variables to be
> declared before they are used on the LHS.

I think (s)he meant right hand. 


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


Simple integer comparison problem

2007-04-14 Thread tom
Hi!
I ran in problem with simple exercise. I'm trying to get program to 
return grade when given points but no matter what, I always get F.

def grader():
 print "Insert points: "
 points = raw_input('> ')
 int(points)

 if points > 89 and points <= 100:
 return "A"
 elif points > 89 and points <= 89:
 return "B"
 elif points > 69 and points <= 79:
 return "C"
 elif points > 59 and points <= 69:
 return "D"
 else:
 return "F"

grade = grader()
print grade
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple integer comparison problem

2007-04-14 Thread Jakub Stolarski
On Apr 14, 5:19 pm, [EMAIL PROTECTED] wrote:
> Hi!
> I ran in problem with simple exercise. I'm trying to get program to
> return grade when given points but no matter what, I always get F.
>
> def grader():
>  print "Insert points: "
>  points = raw_input('> ')
>  int(points)
>
>  if points > 89 and points <= 100:
>  return "A"
>  elif points > 89 and points <= 89:
>  return "B"
>  elif points > 69 and points <= 79:
>  return "C"
>  elif points > 59 and points <= 69:
>  return "D"
>  else:
>  return "F"
>
> grade = grader()
> print grade

You should write:
points = int(points)

int returns value, not change in place.

If I can suggest you can use simpler if-statement:
if 89 < points <= 100:

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


Re: Simple integer comparison problem

2007-04-14 Thread Dan Bishop
On Apr 14, 10:19 am, [EMAIL PROTECTED] wrote:
> Hi!
> I ran in problem with simple exercise. I'm trying to get program to
> return grade when given points but no matter what, I always get F.
>
> def grader():
>  print "Insert points: "
>  points = raw_input('> ')
>  int(points)
>
>  if points > 89 and points <= 100:
>  return "A"
>  elif points > 89 and points <= 89:
>  return "B"
>  elif points > 69 and points <= 79:
>  return "C"
>  elif points > 59 and points <= 69:
>  return "D"
>  else:
>  return "F"
>
> grade = grader()
> print grade

You have a typo in the first "elif": "points > 89 and points <= 89" is
never true, so you'll get an "F" instead of a "B".

BTW, Python lets you write things like "80 <= points < 90".

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Steve Holden
jamadagni wrote:
>> Modules are parsed when they are imported.  And some modules are already
>> imported before your module is imported because they are built-in or
>> loaded to be able to import your module in the first place.  And what
>> about modules that are written in C?
> 
> OK fine. It is clear that this feature must be implemented if at all
> only on a per-module basis. So can we have votes for per-module
> implementation of this feature?
> 
Like votes would make a difference. Please just accept that this is not 
a sensible suggestion and leave it at that.

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

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread ici
On Apr 14, 1:27 pm, [EMAIL PROTECTED] wrote:
...
> This would mean:
> foo = "foo"
> => foo[1] == 'f'
>

class Str1(str):
def __getitem__(self,i):
return str.__getitem__(self,i-1)

s1 = Str1("foo")
print s1[1]

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Mel Wilson
jamadagni wrote:
> OK fine. It is clear that this feature must be implemented if at all
> only on a per-module basis. So can we have votes for per-module
> implementation of this feature?

The only way that can work is if the API to the module doesn't expose 
ANY sequence indices.  It would be a great pain to have to remember 
which of the modules you've imported expect base 0 and which expect 
base 1. (There's a Monty Python sketch: a station full of police 
officers who only understand you if you speak 
slowly/quickly/high-pitched/low-pitched/etc. depending on the 
individual officer.)

The scheme could work if the module was carefully programmed to show 
and accept only application-relevant values that nobody would expect 
to have an alternative base -- quantities of things, arbitrary code 
numbers, and the like.

Mel.

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


Re: how to strip the domain name in python?

2007-04-14 Thread Marko . Cain . 23
On Apr 14, 12:02 am, Michael Bentley <[EMAIL PROTECTED]>
wrote:
> On Apr 13, 2007, at 11:49 PM, [EMAIL PROTECTED] wrote:
>
>
>
> > Hi,
>
> > I have a list of url names like this, and I am trying to strip out the
> > domain name using the following code:
>
> >http://www.cnn.com
> >www.yahoo.com
> >http://www.ebay.co.uk
>
> > pattern = re.compile("http:(.*)\.(.*)", re.S)
> > match = re.findall(pattern, line)
>
> > if (match):
> > s1, s2 = match[0]
>
> > print s2
>
> > but none of the site matched, can you please tell me what am i
> > missing?
>
> change re.compile("http:(.*)\.(.*)", re.S) to re.compile("http:\/
> \/(.*)\.(.*)", re.S)

Thanks. I try this:

but when the 'line' is http://www.cnn.com, I get 's2' com,
but i want 'cnn.com' (everything after the first '.'), how can I do
that?

pattern = re.compile("http:\/\/(.*)\.(.*)", re.S)


match = re.findall(pattern, line)

if (match):

s1, s2 = match[0]

print s2

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


Re: ulimit on open sockets ?

2007-04-14 Thread Alex Martelli
Maxim Veksler <[EMAIL PROTECTED]> wrote:
   ...
> Thank you. I'm attaching the full code so far for reference, sadly it
> still doesn't work. It seems that select.select gets it's count of
> fd's not from the amount passed to it by the sub_list but from the
> kernel (or whatever) count for the process; The main issue here is

It's not a problem of COUNT of FD's, i.e., how many you're passing to
select; the problem is the value of the _highest_ number you can pass.
It's an API-level limitation, not an issue with Python per se: the
select API takes a "bit vector" of N bits, representing a set of FDs in
that way, and N is fixed at kernel-compilation time (normally to 1024).

The poll system call does not have this particular limitation, which is
why select.poll may be better for you.

Moreover, your code has other performance problems:


> while 1:
> for select_cap_sockets in slice_by_fd_limit(all_sockets):
> ready_to_read, ready_to_write, in_error =
> select.select(select_cap_sockets, [], [], 0)
> for nb_active_socket in all_sockets:
> if nb_active_socket in ready_to_read:

A small issue is with the last two lines -- instead of looping directly
on the small "ready-to-read" list, you're looping on the large
all_sockets one and looking each up in the small list -- that's just
throwing performance out of the window, and adding complexity, for no
benefit whatsoever.

The big issue is that you are "ceaselessly polling".  If no socket is
ready to read, you force select to return immediately anyway, and
basically call select at once afterwards.  You churn on the CPU without
surcease, using 100% of it, hogging it for this "busy wait", possibly to
the point of crowding out the kernel from some of the CPU time it needs
to do useful work in the TCP-IP stack.  Busy-wait is a bad thing...
never call select with a timeout of 0 in a tight loop. This
recommendation also applies to the polling-object that you can build
with select.poll, and any other situation where you're waiting for
another thread or process to deliver some data -- ideally you should
wait in a blocking way, if that's unfeasible at least make sure you're
letting some time pass between such calls, by using small but non-0
timeout (or even by inserting calls to time.sleep if that's what it
takes).

The risk of such "antipatterns" is a good reason why it would be better
to use a well-designed, well-coded, well-debugged existing framework,
such as Twisted, rather than roll your own, btw.  With twisted, you can
choose among many appropriate implementations of "reactor" (the key
design pattern for async prorgramming) and activate the one that is most
suitable for your needs (including, e.g., one based on epoll, which
gives better performance than poll on suitable operating systems).

If you're adamant on "rolling your own", though, you can find a Python
epoll module at  (it's
said to be in alpha status, though; I believe there are other such
modules around, but pyepoll seems to be the only one on Cheese Shop).


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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread Mel Wilson
[EMAIL PROTECTED] wrote:
> In Visual Basic there is the keyword "with" which allows an object-
> name to be declared as governing the following statements. For
> example:
> 
> with quitCommandButton
>  .enabled = true
>  .default = true
> end with
> 
> This is syntactic sugar for:
> 
> quitCommandButton.enabled=true
> quitCommandButton.default=true
> 
> This can be very useful especially in GUI programming when we have to
> type the same object name in line-after-line. 

q = quitCommandButton
q.enabled = true
q.default = true



Mel.

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Paulo da Silva
Jack escreveu:
> I wonder what everybody uses for Python editor/IDE on Linux?
> I use PyScripter on Windows, which is very good. Not sure if
> there's something handy like that on Linux. I need to do some
> development work on Linux and the distro I am using is Xubuntu. 
> 
> 
eric3 is nice and simple.

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


Re: compiling modules with VS 2008 for python 2.4 prepared with Visual Studio 2003

2007-04-14 Thread alf
Martin v. Löwis wrote:
>>well, instructions were clear enough for me. What is hard to get why it
>>could not use free M$ compiler which is presumably produces compatible
>>objects and libraries.
> 
> 
> This presumption is incorrect. The compiler does *not* create compatible
> objects and libraries. It links with msvcr8.dll, whereas Python is
> linked with mscvr71.dll; Microsoft does not support mixing CRTs.
> 

complier is just a compiler. perhaps final linking could be somehow 
tweaked to include msvcrt71 instad of 80.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple integer comparison problem

2007-04-14 Thread tom
Thanks for help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pydoc Rewrite Discussion at doc-sig list.

2007-04-14 Thread Colin J. Williams
Ron Adam wrote:
> If anyone is interested in participating in discussing the details of the 
> PyDoc rewrite/refactoring I've been working on, a discussion is being 
> started on the doc-sig list.
> 
>   [EMAIL PROTECTED]
> 
> The goal of this discussion will be to get it to a final finished form so a 
> patch can be submitted and a final discussion can take place on the 
> python-dev list at a later date.
> 
> Thanks and Regards,
>Ron Adam
> 
Are there features which exist or planned for Pydoc and which are not 
available with epydoc?

Colin W.

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


Re: Making a tree out of a 2 column list

2007-04-14 Thread [EMAIL PROTECTED]
On Apr 14, 9:37�am, "Sebastian Bassi" <[EMAIL PROTECTED]>
wrote:
> I have a two column list like:
>
> 2,131
> 6,335
> 7,6
> 8,9
> 10,131
> 131,99
> 5,10
>
> And I want to store it in a tree-like structure.
> So if I request 131, it should return all the child of 131, like 2, 10
> and 5 (since 5 is child of 10).
> If I request 335, it should return: 6 and 7.
> If I request 9, it should return 8.
> I guess I could use tuples or dictionaries to do it, but I can't figure out 
> how.

There are probably better ways.

def tree_path(key,tree,indent):
print '\t'*indent,key
if tree.has_key(key):
for m in tree[key]:
tree_path(m,tree,indent+1)
return

print 'original data'
print

source = [(2,131),(6,335),(7,6),(8,9),(10,131),(131,99),(5,10)]

tree = {}
for s in source:
if tree.has_key(s[1]):
tree[s[1]].append(s[0])
else:
tree[s[1]] = [s[0]]

for t in tree:
print '%3d ' % (t),tree[t]

print
print
tree_path(99,tree,0)

print
print 'extended data'
print

source_extend = [(666,2),(777,2),(888,2)]

for s in source_extend:
if tree.has_key(s[1]):
tree[s[1]].append(s[0])
else:
tree[s[1]] = [s[0]]

for t in tree:
print '%3d ' % (t),tree[t]

print
print
tree_path(99,tree,0)

##original data
##
## 99  [131]
##  6  [7]
##  9  [8]
## 10  [5]
##335  [6]
##131  [2, 10]
##
##
## 99
##131
##2
##10
##5
##
##extended data
##
##  2  [666, 777, 888]
## 99  [131]
##  6  [7]
##  9  [8]
## 10  [5]
##335  [6]
##131  [2, 10]
##
##
## 99
##131
##2
##666
##777
##888
##10
##5


>
> Best,
> SB.
>
> --
> Sebasti�n Bassi
> Diplomado Ciencia y Tecnolog�a.
> Club de la raz�n (www.clubdelarazon.org)


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

Re: vocab question

2007-04-14 Thread Colin J. Williams
James Stroud wrote:
> Alan G Isaac wrote:
>> Pardon the vocab question;
>> I'm not a computer science type.
>> According to the Reference Manual,
>> a class defintion has the structure::
>>
>> classdef  ::=  "class" classname [inheritance] ":" suite
>>
>> What is the entire part before the suite called?
>> (Just pointing to a reference is fine & helpful,
>> as long as its not an entire course on BNF.)
>>
>> Thanks,
>> Alan Isaac
+1
> 
> Signature?

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread Duncan Booth
"BJörn Lindqvist" <[EMAIL PROTECTED]> wrote:

> ? Not having to bother with petty things like that is an advantage.
> Javascript has with-statements that are equivalent to your
> using-statements but from what I've seen most programmers avoid them.
> They don't increase readability one bit.

That is at least partly because Javascript with statements are badly 
broken. Consider the following code:

function setit(a) {
   with (a) { x = 1; };
   return a;
}
var x;
delete x;
alert(setit({'x':0}).x);
alert(setit({'y':0}).x);
alert(x);


If 'a' has a property 'x' setit updates the property, otherwise it searches 
out the scope chain until it finds an object with an 'x' property and 
finally creates one on the global object if there isn't one.

So the output in this case is the sequence '1', 'undefined', '1'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread Duncan Booth
"jamadagni" <[EMAIL PROTECTED]> wrote:

>> If you are going to reference self.quit a lot of times then it makes
>> sense to also assign it to a local variable and then you already get
>> even fewer characters (239):
> 
> But you realize readability decreases considerably.
> 
Not as much as it would with your 'using' statement. Using a local alias 
for an expression lets you use appropriate mnemonic abbreviations 
for multiple expressions with. Nested 'using' statements means you have to 
look back through the code to try to work out which is in scope at each 
level.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple integer comparison problem

2007-04-14 Thread Bart Willems
> if points > 89 and points <= 100:
> return "A"
> elif points > 89 and points <= 89:
> return "B"
> elif points > 69 and points <= 79:
> return "C"
> elif points > 59 and points <= 69:
> return "D"
> else:
> return "F"

The previous posters already pointed out your int problem. However, the 
if-statement can be written with a lot less clutter:

if points > 100:
 return "Illegal score"
elif points > 89:
 return "A"
elif points > 79:
 return "B"
elif points > 69:
 return "C"
elif points > 59:
 return "D"
else:
 return "F"

I have a feeling that there's a Python-solution that is shorter yet 
better readable, I just can't figure it out yet...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making a tree out of a 2 column list

2007-04-14 Thread [EMAIL PROTECTED]
Hope this helps

# list of pairs [child,parent]
list=[[2,131],[6,335],[7,6],[8,9],[10,131],[131,99],[5,10]]

# list with loop
#list=[[2,131],[6,335],[7,6],[8,9],[10,131],[131,99],[5,10],[3,10],
[131,3]]

# put the pairs in a dictionary, for easy retrieval
d={}
for c,p in list:
# must be able to hold multiple values for each key
if not(d.has_key(p)):
d[p]=[c]
else:
d[p].append(c)


# function to retrieve children using recursion. max_depth to ensure
termination
def retrieve_recursive(key,result=[],max_depth=10):
if d.has_key(key) and max_depth>0:
for i in d[key]:
result.append(i)
retrieve_recursive(i,result,max_depth-1)
return result

print retrieve_recursive(131)

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Kevin Walzer
Jack wrote:
> I wonder what everybody uses for Python editor/IDE on Linux?
> I use PyScripter on Windows, which is very good. Not sure if
> there's something handy like that on Linux. I need to do some
> development work on Linux and the distro I am using is Xubuntu. 
> 
> 

Why not IDLE?

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Dotan Cohen
On 14/04/07, Kevin Walzer <[EMAIL PROTECTED]> wrote:
> Jack wrote:
> > I wonder what everybody uses for Python editor/IDE on Linux?
> > I use PyScripter on Windows, which is very good. Not sure if
> > there's something handy like that on Linux. I need to do some
> > development work on Linux and the distro I am using is Xubuntu.
> >
> >
>
> Why not IDLE?

Because idle means no progress. Better use VI[M].

Dotan Cohen

http://technology-sleuth.com/technical_answer/what_is_a_cellphone.html
http://lyricslist.com/lyrics/artist_albums/345/metallica.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiling modules with VS 2008 for python 2.4 prepared with Visual Studio 2003

2007-04-14 Thread Martin v. Löwis
> complier is just a compiler. perhaps final linking could be somehow
> tweaked to include msvcrt71 instad of 80.

Not easily. VS 2005 is not just a complier, it is also a rinkel,
and ships with improt librareis. The import library for msvcrt.lib
it ships with automatically links with msvcr8.dll.

You either would have to create a import library for mscvr71.dll
by hand, or you have to copy one from VS 2003 (breaking its license).

Regards,
Martin

P.S. Why does the subject say "VS 2008", anyway? That product has
not been released yet, and Microsoft is still hoping that it will
be called VS 2007.
-- 
http://mail.python.org/mailman/listinfo/python-list


WOLFOWITZ AND HIS IRANIAN PROSTITUTE SALARY OF $190k/yr Re: Test Tube Zealots: The American Chemical Society Terminates the Membership of Chemists from Iran

2007-04-14 Thread lemnitzer
"I now direct you to agree to a proposal which includes the following
terms and conditions," Wolfowitz instructed. "You should accept
immediately her offer to be detailed to an outside institution of her
choosing, while retaining bank salary and benefits."

The Wolfowitz memo went on say that Riza should receive a promotion,
draw a salary of 180,000 dollars (£90,000) and get annual pay
increases of 8%.

Before the job change, Riza was believed to be getting paid close to
133,000 dollars (£67,000). After the transfer, she received 193,590
dollars (£97,000), according to the Government Accountability Project,
a watchdog group.

Riza remains on the World Bank's payroll though she left the State
Department job last year and now works for Foundation for the Future,
an international organisation that gets some money from the
department.

On Apr 7, 9:33 am, [EMAIL PROTECTED] wrote:
> http://counterpunch.org/rahni04072007.html
>
> Test Tube Zealots: The American Chemical Society Terminates the
> Membership of Chemists from Iran
>
> By DAVID N. RAHNI
>
> The American Chemical Society (ACS) has once again led the way, with
> its "zealot" interpretation of "embargo" by the Department of
> Treasury's Office of Foreign Asset Control, by terminating the
> membership of its long-standing members in Iran, many of whom are post
> Ph.D. Alumni of American Universities. Several years ago, the ACS
> undertook a similar unprecedented action, under the same law. Then, it
> unilaterally stopped accepting scholarly and research manuscripts from
> Iranian scientists for its three dozen periodicals in the publication
> division. However, later, under embarrassing pressure from the
> American scientific community and its membership, the ACS retracted
> its decision and agreed to take it up instead with the federal
> government. Paradoxically and notwithstanding rhetoric, such ill-
> conceived measures are against the current U.S. Administration policy
> of promoting people-to-people contact as enunciated by the Assistant
> Secretary of State Nicholas Burns at the March 29 hearing of the
> Senate Foreign Relations Committee.
>
> Yudhijit Bhattacharjee, in Science Magazine, reported that the ACS
> Assistant General Counsel, David Smorodin when "re-reading the embargo
> rules, made the recommendation to terminate Iranian membership(Science
> Magazine, Vol. 315, 30 March 2007). One can not help but speculate
> whether or not such decision is truly serving the interests of member-
> based ACS or enforcing the laws to the limit as he has served as a
> U.S. Assistant District Attorney before joining the ACS. Nonetheless,
> despite the abrupt termination of individual membership of Iranian
> chemical scientists with no due process, the ACS has stated that while
> they [Iranians] can continue to purchase journals and other "non-
> sensitive products at full-rate, the ACS might apply for a special
> license from the Treasury Department to reinstate their memberships.
> This has in the meantime deprived American chemists to learn about the
> scholarly contributions of their Iranian peers.
>
> It should be noted that as in the past, the American Physical Society
> (APS), in contrast, stated, "We have NO plan to do anything similar,
> and continue to serve our members in Iran." Judy Franz, a director at
> the APS further stated that, "We would resist having to obtain a
> license to the extent we can."
>
> When interviewed by Science Magazine, the official publication of the
> American Association for the Advancement of Science (AAAS), David
> Rahni an Iranian-American chemistry professor in New York stated, "I,
> like most ACS members and peers in the scientific community, strongly
> question the ACS motive on this issue, and expect ACS,s leadership to
> refrain from allowing politics to taint the high stature the
> Organization has achieved." Rahni further stated that this has
> personally concerned him gravely since he has served the ACS with
> distinctions in the past thirty years, as typified by his positions as
> the chair of the ACS New York, the chair of the Middle Atlantic
> Regional Meeting, and the chair of Nichols Medal. 90% of the ACS
> projects, publications and activities are run by a huge cadre of
> volunteer professionals who, with no expectations, give their time,
> energy, money and intellects and talents to the advancement of the
> chemical sciences worldwide. It is painfully ironic to many,
> especially the ACS American members to witness the politicization of
> their disciplines through the ACS as they continue to register their
> grave concerns with the ACS lucratively remunerated executive
> directors. As a chemistry professor with having given fifty years of
> his life to the ACS and the profession so eloquently put it, "Never
> mind the Iranians as one may not give a darn about them and their
> plights, what, I am bewildered to speculate the ulterior motives of
> the ACS paid "professional leadership is to embarrass us a

ctypes and pointers

2007-04-14 Thread Diez B. Roggisch
Hi,

I'm working under mac os x with the OpenCV-library that I load via ctypes.

 From a ObjectiveC-methodcall I get an integer, that "really" is a 
pointer to an IplImage-structure.

I've got a function that takes such a pointer. But I don't find a way to 
pass it to that very function.

These are the relevant parts of my code:

 cvImage = self._f.cvImage()
 print "Address of IplImage: %x" % cvImage
 cvImage = c_void_p(cvImage)
 print cvImage
 cvImage2 = macopencv.cvCloneImage(cvImage)

The output is

2007-04-14 19:22:53.910 SequenceGrabberTest[5320] Returning IplImage at 
Address of IplImage: e860c60
e860c60
c_void_p(243666016)
2007-04-14 19:22:53.915 SequenceGrabberTest[5320] Exception raised 
during posting of notification.  Ignored.  exception: 
exceptions.ValueError: depythonifying 'pointer', got 'int'


The first line is actually from the ObjectivC-method, a log-statement.

As one can see, the pointer is passed back as integer.

But then I'm stuck.

Any suggestions would be appreciated!

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Aahz
In article <[EMAIL PROTECTED]>,
Michael Bentley  <[EMAIL PROTECTED]> wrote:
>
>>>
>>> Everybody uses vim.
>>>
>> Except for real programmers...
>
>Who instead use emacs ;-)

"Emacs makes a good OS, but a lousy editor."
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

Help a hearing-impaired person: http://rule6.info/hearing.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple integer comparison problem

2007-04-14 Thread Anton Vredegoor
Bart Willems wrote:

> I have a feeling that there's a Python-solution that is shorter yet 
> better readable, I just can't figure it out yet...

Shorter (and faster for big lists): Yes. More readable: I don't know, I 
guess that depends on ones familiarity with the procedure.

import bisect

def grader(score):
 c = bisect.bisect([60,70,80,90],score)
 return 'FDCBA'[c]

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Jorge Godoy
[EMAIL PROTECTED] (Aahz) writes:

> In article <[EMAIL PROTECTED]>,
> Michael Bentley  <[EMAIL PROTECTED]> wrote:
>>

 Everybody uses vim.

>>> Except for real programmers...
>>
>>Who instead use emacs ;-)
>
> "Emacs makes a good OS, but a lousy editor."

Yep.  Emacs comes with a lot of those funny phrases.  It is so good that
it even helps people using other editors to have some fun. ;-)

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


Re: Python editor/IDE on Linux?

2007-04-14 Thread Carl K
Jack wrote:
> I wonder what everybody uses for Python editor/IDE on Linux?
> I use PyScripter on Windows, which is very good. Not sure if
> there's something handy like that on Linux. I need to do some
> development work on Linux and the distro I am using is Xubuntu. 
> 
> 

I use spe - it is in universe.

Has some rough edges, but in general I like it enough to recommend it.

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


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread BJörn Lindqvist
On 14 Apr 2007 07:24:32 -0700, jamadagni <[EMAIL PROTECTED]> wrote:
> > You already can emulate the using statement like this:
>
> You can emulate only assignments like this. How would you emulate
> function calls, like the ones in my example?

You can't, of course. But using the with statement:

using self.q:
.doit()

becomes:

with self.quit as q:
q.doit()

:)

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-14 Thread Rhamphoryncus
On Apr 13, 11:05 pm, Paul Rubin  wrote:
> "Rhamphoryncus" <[EMAIL PROTECTED]> writes:
> > >   i = s.index(e) => s[i] = e
> > > Then this algorithm is no longer guaranteed to work with strings.
> > It never worked correctly on unicode strings anyway (which becomes the
> > canonical string in python 3.0).
>
> What?!   Are you sure?  That sounds broken to me.

Nope, it's pretty fundamental to working with text, unicode only being
an extreme example: there's a wide number of ways to break down a
chunk of text, making the odds of "e" being any particular one fairly
low.  Python's unicode type only makes this slightly worse, not
promising any particular one is available.

For example, if you had an algorithm designed for ascii that gathered
statistics on how common each "character" is, you'd want to redesign
it to use either grapheme clusters or scalar values, then improve it
to merge duplicate characters.  You'd need to roll your own iterator
though, Python doesn't provide a method that's specifically grapheme
clusters or scalar values (and if I'm wrong I'd love to hear it!).

--
Adam Olsen, aka Rhamphoryncus

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


Minimal Linux system to run Python

2007-04-14 Thread Chaz Ginger
I have a need for the minimal Linux system to run Python. Basically I
want the system to boot up and instead of starting up Init/etc. I would
love it to run python (and a python script I have written).

Before embarking on doing it myself I was wondering if anyone knew of
just such a system?

Peace,
Chaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread BJörn Lindqvist
On 4/14/07, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
> On 14 Apr 2007 07:24:32 -0700, jamadagni <[EMAIL PROTECTED]> wrote:
> > > You already can emulate the using statement like this:
> >
> > You can emulate only assignments like this. How would you emulate
> > function calls, like the ones in my example?
>
> You can't, of course. But using the with statement:
>
> using self.q:
> .doit()
>
> becomes:
>
> with self.quit as q:
> q.doit()

Er.. I guess there are some details you need to work out for that. But
in principle, it works fine.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread nikolas pontikos
Army1987 wrote:
> "jamadagni" <[EMAIL PROTECTED]> ha scritto nel messaggio 
> news:[EMAIL PROTECTED]
>>> Languages like Perl and VB need a strict mode because they will
>>> auto-vivify variable for you.  I.e. they will bring variables to life
>>> with defined or undefined values if you use them in a l-value (left hand
>>> side of an assignment) without having declared them prior.  If you do
>>> that in Python you get an exception.
>> I don't comprehend. I can just type a = 5 in a new Python session and
>> I get no exception. Python currently does not require variables to be
>> declared before they are used on the LHS.
> 
> I think (s)he meant right hand. 
> 
> 

Yes I did sorry about that.  If an assignment had hands then I would 
have been right ;).
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >