Re: Performance: sets vs dicts.

2010-08-31 Thread Arnaud Delobelle
Paul Rubin  writes:

> a...@pythoncraft.com (Aahz) writes:
>> Possibly; IMO, people should not need to run timeit to determine basic
>> algorithmic speed for standard Python datatypes.
>
> Indeed.  Alex Stepanov (designer of C++ Standard Template Library) was
> emphatic that algorithm complexity assertions should be part of the
> interface of any STL function:
>
>  http://www.sgi.com/tech/stl/drdobbs-interview.html
>
> He also said it should be part of the "unwritten contract" between the
> module and its user, but I don't understand why he said "unwritten",
> since in the C++ STL the complexity statements are part of the written
> spec.

The spec is written, not the contract :)

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


Re: Functions continuing to ru after returning something?

2010-08-31 Thread Maxwell Hansen

On 08/30/2010 05:05 PM, Bradley Hintze wrote:

I may be having a brain fart, but is it at all possible to have a
function first return a value then continue its calculation. Like this
simple example:

my_var = 5
def my_function():
 return my_var
 my_var +=1

This obviously won't work as written but is there a cleaver way around this.



return stops execution of any code remaining in the function, but just 
out of curiosity, why do you need to do this?

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


Re: Problem checking an existing browser cookie

2010-08-31 Thread Nik the Greek
On 30 Αύγ, 20:48, Rami Chowdhury 
wrote:
> On Mon, Aug 30, 2010 at 23:36, Nik the Greek  
> wrote:
>
>
>
>
>
>
>
>
>
> > # initialize cookie
> > cookie = SimpleCookie()
> > cookie.load( os.environ.get('HTTP_COOKIE', '') )
> > visitor = cookie.get('visitor')
>
> > This statement
>
> > if (visitor.value != 'nikos') and re.search( r'(msn|yandex|13448|
> > spider|crawl)', host ) is None:
>
> > produces the following error:
>
> >  /home/webville/public_html/cgi-bin/counter.py
> >   93 # do not increment the counter if a Cookie is set to the
> > visitors browser already
> >   94 #
> > === 
> > ==
> >   95 if (visitor.value != 'nikos') and re.search( r'(msn|yandex|13448|
> > spider|crawl)', host ) is None:
> >   96
> >   97         print visitor
> > visitor = None, visitor.value undefined, re =  > lib64/python2.4/re.pyc'>, re.search = , host =
> > '178-128-217.dynamic.cyta.gr', builtin None = None
>
> > Why visitor.value is undefined?
>
> Because, as the traceback tells you, visitor is None. As you said, the
> cookie is not recognized. Try inserting the following line at the top
> of your script:
>
> print "Content-type:text/html\r\n\r\n", os.environ.get('HTTP_COOKIE',
> 'NO COOKIE DATA')
>
> That should give you the value of the cookie, which might help you
> debug why it is not being loaded.
>
> --
> Rami Chowdhury
> "Never assume malice when stupidity will suffice." -- Hanlon's Razor
> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

Unfortunately it produces an Internal Server Error :(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functions continuing to ru after returning something?

2010-08-31 Thread Peter Otten
Bradley Hintze wrote:

> I may be having a brain fart, but is it at all possible to have a
> function first return a value then continue its calculation. Like this
> simple example:
> 
> my_var = 5
> def my_function():
> return my_var
> my_var +=1
> 
> This obviously won't work as written but is there a cleaver way around
> this.

>>> n = 1
>>> def f():
... global n
... try:
... return n
... finally:
... n += 1
...
>>> f()
1
>>> f()
2
>>> f()
3

However, I would prefer the generator as Aidan has shown because it doesn't 
rely on a global variable.

Peter

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


Re: Problem checking an existing browser cookie

2010-08-31 Thread Nik the Greek
On 30 Αύγ, 20:50, MRAB  wrote:
> On 30/08/2010 18:16, Nik the Greek wrote:
>
>
>
>
>
>
>
>
>
> > On 30 Αύγ, 19:41, MRAB  wrote:
> >> On 30/08/2010 04:33, Nik the Greek wrote:
>
> >>> On 30 Αύγ, 06:12, MRAB    wrote:
>
>  This part:
>
>         ( not mycookie or mycookie.value != 'nikos' )
>
>  is false but this part:
>
>         re.search( r'(msn|yandex|13448|spider|crawl)', host ) is None
>
>  is true because host doesn't contain any of those substrings.
>
> >>> So, the if code does executed because one of the condition is true?
>
> >>> How should i write it?
>
> >>> I cannot think clearly on this at all.
>
> >>> I just wan to tell it to get executed  ONLY IF
>
> >>> the cookie values is not 'nikos'
>
> >>> or ( don't knwo if i have to use and or 'or' here)
>
> >>> host does not contain any of the substrings.
>
> >>> What am i doign wrong?!
>
> >> It might be clearer if you reverse the condition and say:
>
> >>       me_visiting = ...
> >>       if not me_visiting:
> >>           ...
>
> > I don't understand what are you trying to say
>
> > Please provide a full example.
>
> > You mean i should try it like this?
>
> > unless ( visitor and visitor.value == 'nikos' ) or re.search( r'(msn|
> > yandex|13448|spider|crawl)', host ) not None:
>
> > But isnt it the same thing like the if?
>
> My point is that the logic might be clearer to you if you think first
> about how you know when you _are_ the visitor.

Well my idea was to set a cookie on my browser with the name visitor
and a value of "nikos" and then check each time that cooki. if value
is "nikos" then dont count!

I could also pass an extra url string like http://webville.gr?show=nikos
and check that but i dont like the idea very much of giving an extra
string each time i want to visit my webpage.
So form the 2 solution mentioned the 1st one is better but cant come
into action for some reason.

Aprt form those too solution i cant think of anyhting else that would
identify me and filter me out of the actual guest of my website.

I'm all ears if you can think of something else.

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


Re: Functions continuing to ru after returning something?

2010-08-31 Thread Bruno Desthuilliers

Peter Otten a écrit :


n = 1
def f():

... global n
... try:
... return n
... finally:
... n += 1
...


The same without a global:

def f(_n=[0]):
try:
return _n[0]
finally:
_n[0] += 1


But yeps, using a generator would be better.
--
http://mail.python.org/mailman/listinfo/python-list


sendmail error

2010-08-31 Thread sandric ionut


Hello:

I have a script for sending email from python (it is attached bellow). When I 
am 
launching the script I get the error:
TypeError: cannot concatenate 'str' and 'type' objects if I use sys.argv[1], 
but 
if I input from the begging an email address like "em...@email.com", the script 
is working OK

What could be the problem?

Thank you,

Ionut

import
mesaj = email.MIMEMultipart.MIMEMultipart()
fromEmail = sys.argv[
toEmail = os, sys, smtplib, email1]"toEmail"mesaj[
mesaj[
mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[
atasament = r"Date"] = 
email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP = 
email.MIMEBase.MIMEBase(
atasamentP.set_payload(open(atasament,
email.Encoders.encode_base64(atasamentP)
atasamentP.add_header(
mesaj.attach(atasamentP)
mesaj.attach(email.MIMEText.MIMEText(
smtpObj = 
smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attachement;
 filename="%s"'% os.path.basename(atasament))"Email transmis la data: ", 
email.Utils.formatdate(localtime=False)))"192.168.1.2")try
smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string())
smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+ 
smtplib.SMTPException


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


Re: Functions continuing to ru after returning something?

2010-08-31 Thread Paul Rubin
Bradley Hintze  writes:
> my_var = 5
> def my_function():
> return my_var
> my_var +=1

def my_function():
  temp = my_var
  my_var += 1
  return temp
-- 
http://mail.python.org/mailman/listinfo/python-list


Can't find elements using ElementTree find method

2010-08-31 Thread Brendan Simon (eTRIX)
 I am trying to use ElementTree (with Python 2.7) and can't seem to find
elements at the top level.  The find() and findall() methods seem to
find elements within the top level, but not if it the elements are at
the top level.

How do I find top level elements ??
Here is my code.

import xml.etree.ElementTree as ET

xml = '''\


  
Fred
Australia
  

'''

root = ET.fromstring( xml )

### This pattern is not found :(
comps = root.find( './/components' )

### These patterns are found ok :)
comp = root.find( './/component' )
name = root.find( './/name' )

print 'comps =', comps
print 'comp =', comp
print 'name =', name


Thanks, Brendan.

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


Re: Can't find elements using ElementTree find method

2010-08-31 Thread Nitin Pawar
Try using 
getroot()

I think your root is components so its searching in root

On Tue, Aug 31, 2010 at 2:19 PM, Brendan Simon (eTRIX) <
brendan.si...@etrix.com.au> wrote:

>  I am trying to use ElementTree (with Python 2.7) and can't seem to find
> elements at the top level.  The find() and findall() methods seem to find
> elements within the top level, but not if it the elements are at the top
> level.
>
> How do I find top level elements ??
> Here is my code.
>
> import xml.etree.ElementTree as ET
>
> xml = '''\
> 
> 
>   
> Fred
> Australia
>   
> 
> '''
>
> root = ET.fromstring( xml )
>
> ### This pattern is not found :(
> comps = root.find( './/components' )
>
> ### These patterns are found ok :)
> comp = root.find( './/component' )
> name = root.find( './/name' )
>
> print 'comps =', comps
> print 'comp =', comp
> print 'name =', name
>
>
> Thanks, Brendan.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Can't find elements using ElementTree find method

2010-08-31 Thread Stefan Behnel

Brendan Simon (eTRIX), 31.08.2010 10:49:

  I am trying to use ElementTree (with Python 2.7) and can't seem to find
elements at the top level.  The find() and findall() methods seem to
find elements within the top level, but not if it the elements are at
the top level.

How do I find top level elements ??
Here is my code.

 import xml.etree.ElementTree as ET

 xml = '''\
 
 
   
 Fred
 Australia
   
 
 '''

 root = ET.fromstring( xml )

 ### This pattern is not found :(
 comps = root.find( './/components' )


"." matches the current element, so the path expression looks for all 
"components" nodes *below* the current element.


You can either wrap the root in an ElementTree and search globally (i.e. 
without the leading "."), or you can test the root node yourself.


Stefan

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


Re: PyGeo

2010-08-31 Thread Thomas Jollans
On Tuesday 31 August 2010, it occurred to L to exclaim:
> Traceback (most recent call last):
>File
> "/usr/lib/python2.6/dist-packages/pygeo/examples/real/dandelinspheres2.py",
> line 2, in 
>  from pygeo.base.abstract_elements_real import _Sphere, _Point
>File "/usr/lib/python2.6/dist-packages/pygeo/__init__.py", line 3, in
> 
>  from pygeo.vpyframe import display
>File "/usr/lib/python2.6/dist-packages/pygeo/vpyframe.py", line 38,
> in 
>  class display( visual.ui.display):
> AttributeError: 'module' object has no attribute 'ui'

THAT's the information I was waiting for. So, it looks like everything is 
working together, except that the visual module appears to have changed 
somewhat since PyGeo was written. Importing "visual" within PyGeo appears to 
have worked, but "visual.ui" doesn't exist. 

After having a brief look at the documentation, I found no mention of a "ui" 
object, but there appears to be visual.display -- so, if you wanted to port 
the package to the latest VPython, that would be a place to start: replace 
"visual.ui.display" with "visual.display", and try again. And the fix the next 
problem, and so on, until it works, when you can send a patch to the old 
maintainer.
http://www.vpython.org/webdoc/visual/index.html

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


Re: Can't find elements using ElementTree find method

2010-08-31 Thread Brendan Simon (eTRIX)
 I can't use getroot() when using fromstring() -- as fromstring()
returns an Element, not an ElementTree object.

Yes, my root is the 'components' element, but find() seems to insist on
searching for sub-elements.

Ideally, I would like root.find('components') or
root.find('./components') to find the components element at the top-level.

I'd also like to be able to do root.find('./components/component') or
root.find('./components/component/name') and so on.

I guess I just have to check that root.tag == 'components' first, then
search for './component', './component/name' and so on.  It's a bit
ugly, but heaps better than using minidom :)

Cheers, Brendan.


On 31/08/10 6:57 PM, Nitin Pawar wrote:
> Try using getroot()
>
> I think your root is components so its searching in root 
>
> On Tue, Aug 31, 2010 at 2:19 PM, Brendan Simon (eTRIX)
> mailto:brendan.si...@etrix.com.au>> wrote:
>
> I am trying to use ElementTree (with Python 2.7) and can't seem to
> find elements at the top level.  The find() and findall() methods
> seem to find elements within the top level, but not if it the
> elements are at the top level.
>
> How do I find top level elements ??
> Here is my code.
>
> import xml.etree.ElementTree as ET
>
> xml = '''\
> 
> 
>   
> Fred
> Australia
>   
> 
> '''
>
> root = ET.fromstring( xml )
>
> ### This pattern is not found :(
> comps = root.find( './/components' )
>
> ### These patterns are found ok :)
> comp = root.find( './/component' )
> name = root.find( './/name' )
>
> print 'comps =', comps
> print 'comp =', comp
> print 'name =', name
>
>
> Thanks, Brendan.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
>
> -- 
> Nitin Pawar
>

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


Re: sendmail error

2010-08-31 Thread Dave Angel

sandric ionut wrote:

Hello:

I have a script for sending email from python (it is attached bellow). When I am 
launching the script I get the error:
TypeError: cannot concatenate 'str' and 'type' objects if I use sys.argv[1], but 
if I input from the begging an email address like "em...@email.com", the script 
is working OK


What could be the problem?

Thank you,

Ionut

import
mesaj = email.MIMEMultipart.MIMEMultipart()
fromEmail = sys.argv[
toEmail = os, sys, smtplib, email1]"toEmail"mesaj[
mesaj[
mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[
atasament = r"Date"] = 
email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP = 
email.MIMEBase.MIMEBase(

atasamentP.set_payload(open(atasament,
email.Encoders.encode_base64(atasamentP)
atasamentP.add_header(
mesaj.attach(atasamentP)
mesaj.attach(email.MIMEText.MIMEText(
smtpObj = 
smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attachement;
 filename="%s"'% os.path.basename(atasament))"Email transmis la data: ", 
email.Utils.formatdate(localtime=False)))"192.168.1.2")try

smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string())
smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+ 
smtplib.SMTPException



  
Three things:   When quoting code, do it exactly, and without wordwrap 
in your mail program.  There are so many typos in that code sample that 
it's useless, presumably because you didn't use copy/paste.


When quoting an error message, get it all.  Since you omit the 
stacktrace part, we can't tell what line might be giving you that error.


Once you've noticed which line, just examine the types of each of the 
elements you're combining.  If you're using the + operator, and the left 
operand is a string, then the right one must also be string.  Figure out 
why it's not and you have your own answer.


DaveA

  
  

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


Re: Performance: sets vs dicts.

2010-08-31 Thread Jerry Hill
On Mon, Aug 30, 2010 at 7:42 PM, Aahz  wrote:
> Possibly; IMO, people should not need to run timeit to determine basic
> algorithmic speed for standard Python datatypes.

http://wiki.python.org/moin/TimeComplexity takes a stab at it.  IIRC,
last time this came up, there was some resistance to making promises
about time complexity in the official docs, since that would make
those numbers part of the language, and thus binding on other
implementations.

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


Re: PyGeo

2010-08-31 Thread Giacomo Boffi
L  writes:

> also the PyGeo readme text mentions Numerical python (I think it
> means Numeric, but I also have NumPy installed)

afaict, Numerical python is numpy --- if you look at pygeo home page,
the reference to Numerical python is a link to numpy home page

on the contrary, there is no "import numpy" in all the sources of
pygeo, and a couples or so of "import Numeric", so that the situation
is unclear

aiuole/../PyGeo-1.0a1 $ find build| grep py$ | xargs grep -n import'.*'numpy
aiuole/../PyGeo-1.0a1 $ find build| grep py$ | xargs grep -n import'.*'Numeric
build/lib.linux-i686-2.6/pygeo/base/pygeomath.py:1:import Numeric as N
build/lib.linux-i686-2.6/pygeo/base/wiresphere.py:2:import Numeric
aiuole/../PyGeo-1.0a1 $ 

to complicate matters, it is not possible to install python-numeric
using the apt system on debian unstable

i don't know if it is possible to build numeric against the default
python (2.6) on my system, further i don't know if it is worthwhile
because, at a first sight, it looks like pygeo does not use advanced
features of numeric, and replacing numeric with numpy should be very
easy

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


Fw: sendmail error

2010-08-31 Thread sandric ionut




- Forwarded Message 
From: sandric ionut 
To: Dave Angel 
Sent: Tue, August 31, 2010 3:56:40 PM
Subject: Re: sendmail error








From: Dave Angel 
To: sandric ionut 
Cc: Python List 
Sent: Tue, August 31, 2010 2:49:29 PM
Subject: Re: sendmail error


The code was COPY and PASTE -> presume wrong

   When quoting an error message, get it all.  Since you omit the stacktrace 
part, we can't tell what line might be giving you that error

That is all the error code!!!

    Once you've noticed which line, just examine the types of each of the 
elements you're combining.  If you're using the + operator, and the left 
operand 
is a string, then the right one must also be string.  Figure out why it's not 
and you have your own answer

Do you really think that I didn't do it? What a... response. This + or , is 
really USELESS. Please don't bother to send useless replays
This is the line where I get the error: smtpObj.sendmail(fromEmail, toEmail, 
mesaj.as_string())

I.S.

DaveA

>       
sandric ionut wrote:
> Hello:
> 
> I have a script for sending email from python (it is attached bellow). When I 
>am launching the script I get the error:
> TypeError: cannot concatenate 'str' and 'type' objects if I use sys.argv[1], 
>but if I input from the begging an email address like "em...@email.com", the 
>script is working OK
> 
> What could be the problem?
> 
> Thank you,
> 
> Ionut
> 
> import
> mesaj = email.MIMEMultipart.MIMEMultipart()
> fromEmail = sys.argv[
> toEmail = os, sys, smtplib, email1]"toEmail"mesaj[
> mesaj[
> mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[
> atasament = r"Date"] = 
>email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP = 
>email.MIMEBase.MIMEBase(
> atasamentP.set_payload(open(atasament,
> email.Encoders.encode_base64(atasamentP)
> atasamentP.add_header(
> mesaj.attach(atasamentP)
> mesaj.attach(email.MIMEText.MIMEText(
> smtpObj = 
>smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attachement;
>
>  filename="%s"'% os.path.basename(atasament))"Email transmis la data: ", 
>email.Utils.formatdate(localtime=False)))"192.168.1.2")try
> smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string())
> smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+ 
>smtplib.SMTPException
> 
> 
>  
  Three things:  When quoting code, do it exactly, and without wordwrap in your 
mail program.  There are so many typos in that code sample that it's 
useless, presumably because you didn't use copy/paste



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


Re: Fw: sendmail error

2010-08-31 Thread Alexander Kapps

sandric ionut wrote:
  Three things:  When quoting code, do it exactly, and without wordwrap 
in your mail program.  There are so many typos in that code sample that 
it's useless, presumably because you didn't use copy/paste
 
The code was COPY and PASTE -> presume wrong


   When quoting an error message, get it all.  Since you omit the 
stacktrace part, we can't tell what line might be giving you that error
 
That is all the error code!!!


Once you've noticed which line, just examine the types of each of 
the elements you're combining.  If you're using the + operator, and the 
left operand is a string, then the right one must also be string.  
Figure out why it's not and you have your own answer
 
Do you really think that I didn't do it? What a... response. This + or , 
is really USELESS. Please don't bother to send useless replays
This is the line where I get the error: smtpObj.sendmail(fromEmail, 
toEmail, mesaj.as_string())



Indeed, what a response. But from you. Do you always attack people 
who tried to help you?


Dave Angel, gave you a very useful hint on how to debug such errors. 
 In particular, he asked you to paste the *full* traceback.


And if your mail/news client messes up the code so heavily, it's 
probably time to move to a better client.


And the mention of + is not useless. If you would have tried a 
little harder, you would probably find, that concatenating a string 
and an exception object, gives exactly the error you got.




So, the problem is probably here:

print "eroare: " + smtplib.SMTPException

Instead you want something like:

except smtplib.SMTPException, msg
print "eroare: " + msg


If you are sure, that's not the line which gave the error, again, 
post the *full* traceback.


Next time, show a little more civility and follow the advices you 
got. "Help us, to help you." is the word.


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


Re: sendmail error

2010-08-31 Thread Thomas Jollans
On Tuesday 31 August 2010, it occurred to sandric ionut to exclaim:
> Hello:
> 
> I have a script for sending email from python (it is attached bellow). When
> I am launching the script I get the error:
> TypeError: cannot concatenate 'str' and 'type' objects if I use
> sys.argv[1], but if I input from the begging an email address like
> "em...@email.com", the script is working OK
> 
> What could be the problem?
> 
> Thank you,
> 
> Ionut
> 
> import
> mesaj = email.MIMEMultipart.MIMEMultipart()
> fromEmail = sys.argv[
> toEmail = os, sys, smtplib, email1]"toEmail"mesaj[
> mesaj[
> mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[
> atasament = r"Date"] =
> email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP =
> email.MIMEBase.MIMEBase(
> atasamentP.set_payload(open(atasament,
> email.Encoders.encode_base64(atasamentP)
> atasamentP.add_header(
> mesaj.attach(atasamentP)
> mesaj.attach(email.MIMEText.MIMEText(
> smtpObj =
> smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attach
> ement; filename="%s"'% os.path.basename(atasament))"Email transmis la data:
> ", email.Utils.formatdate(localtime=False)))"192.168.1.2")try
> smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string())
> smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+
> smtplib.SMTPException

I struggle to imagine what one might do to a piece of code to garble it this 
badly. If this was actually the script you're trying to run, then it would 
have blown up in your face with a angry SyntaxError, not the helpful TypeError 
you quoted. As far as I can see, you never actually use sys.argv[1], so this 
can't be the right code.

To paraphrase what you failed to spell correctly in your other message, please 
don't bother sending useless inquiries to this list. If you want to get a 
useful reply, please:

 - Quote the code correctly. Before sending, check that it actually makes
   sense. The above is quite simply nothing like Python.

 - Quote the entire stack trace and error message. You might have looked at it
   already, but we haven't. This information is not useless!

Also, when replying:

  - Quote properly. While top posting is discouraged, the most important bit
is to clearly distinguish quoted material from new material. Make it
possible from the structure of the message you're sending which parts you
wrote and which parts you're just quoting.

  - Keep your reply on-list.

 - Thomas

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


Re: Performance: sets vs dicts.

2010-08-31 Thread Aahz
In article ,
Jerry Hill   wrote:
>On Mon, Aug 30, 2010 at 7:42 PM, Aahz  wrote:
>>
>> Possibly; IMO, people should not need to run timeit to determine basic
>> algorithmic speed for standard Python datatypes.
>
>http://wiki.python.org/moin/TimeComplexity takes a stab at it.  IIRC,
>last time this came up, there was some resistance to making promises
>about time complexity in the official docs, since that would make
>those numbers part of the language, and thus binding on other
>implementations.

I'm thoroughly aware of that page and updated it yesterday to make it
easier to find.  ;-)

However, I think there are some rock-bottom basic guarantees we can make
regardless of implementation.  Does anyone seriously think that an
implementation would be accepted that had anything other than O(1) for
index access into tuples and lists?  Dicts that were not O(1) for access
with non-pathological hashing?  That we would accept sets having O()
performance worse than dicts?

I suggest that we should agree on these guarantees and document them in
the core.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...if I were on life-support, I'd rather have it run by a Gameboy than a
Windows box."  --Cliff Wells
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance: sets vs dicts.

2010-08-31 Thread Stefan Behnel

Jerry Hill, 31.08.2010 14:24:

On Mon, Aug 30, 2010 at 7:42 PM, Aahz wrote:

Possibly; IMO, people should not need to run timeit to determine basic
algorithmic speed for standard Python datatypes.


http://wiki.python.org/moin/TimeComplexity takes a stab at it.  IIRC,
last time this came up, there was some resistance to making promises
about time complexity in the official docs, since that would make
those numbers part of the language, and thus binding on other
implementations.


The docs start getting clearer about what's language specification and 
what's implementation specific to CPython, so that would just add another 
couple of CPython-only bits to what's there already. Although I do consider 
facts like list indexing being O(1) pretty much at the 
language-rather-than-implementation level. Most Python code simply expects 
that and it would degrade a lot of code if that ever changed in whatever 
implementation.


Stefan

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


Re: Performance: sets vs dicts.

2010-08-31 Thread Ian

 On 31/08/2010 15:09, Aahz wrote:

I suggest that we should agree on these guarantees and document them in
the core.

I suspect that documenting them will be the easy part ;)


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


Re: Performance: sets vs dicts.

2010-08-31 Thread Jerry Hill
On Tue, Aug 31, 2010 at 10:09 AM, Aahz  wrote:
> I suggest that we should agree on these guarantees and document them in
> the core.

I can't get to the online python-dev archives from work (stupid
filter!) so I can't give you a link to the archives, but the original
thread that resulted in the creation of that wiki page was started on
March 9th, 2008 and was titled "Complexity documentation request".

At the time, opposition to formally documenting this seemed pretty
widespread, including from yourself and Guido.  You've obviously
changed your mind on the subject, so maybe it's something that would
be worth revisiting, assuming someone wants to write the doc change.

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


Stackless Python and EVE Online

2010-08-31 Thread Roman Sokolyuk
Hi,

I am new to Python and I wanted to understand something...

The EVE Online Client is build using Stackless Python

So when I install the client on my machine, how doe sit get run if I do not
have Python installed?

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


Re: Stackless Python and EVE Online

2010-08-31 Thread Thomas Jollans
On Tuesday 31 August 2010, it occurred to Roman Sokolyuk to exclaim:
> Hi,
> 
> I am new to Python and I wanted to understand something...
> 
> The EVE Online Client is build using Stackless Python
> 
> So when I install the client on my machine, how doe sit get run if I do not
> have Python installed?

If this program uses Stackless, and you do not have Stackless installed 
system-wide, then the program includes Stackless. This is probably not a bad 
idea, since the likelihood of Stackless Python being installed is realtively 
small.

Stackless Python is not the same as Python -- as far as I know, it adds some 
new features not found in the actual Python language to the "PyPy" 
implementation of the language. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Saving (unusual) linux filenames

2010-08-31 Thread AmFreak

Hi,

i have a script that reads and writes linux paths in a file. I save the  
path (as unicode) with 2 other variables. I save them seperated by "," and  
the "packets" by newlines. So my file looks like this:

path1, var1A, var1B
path2, var2A, var2B
path3, var3A, var3B


this works for "normal" paths but as soon as i have a path that does  
include a "," it breaks. The problem now is that (afaik) linux allows  
every char (aside from "/" and null) to be used in filenames. The only  
solution i can think of is using null as a seperator, but there have to a  
cleaner version ?


Thanks for any help

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


Re: Stackless Python and EVE Online

2010-08-31 Thread Benjamin Kaplan
On Tuesday, August 31, 2010, Roman Sokolyuk  wrote:
> Hi,
>
> I am new to Python and I wanted to understand something...
> The EVE Online Client is build using Stackless Python
> So when I install the client on my machine, how doe sit get run if I do not 
> have Python installed?
>
We call it "freezing" the program. There are several tools that do
this with py2exe being the most popular. These tools create an
executable that includes a bundled python interpreter along with all
the scripts and modules needed to run the program.
> Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving (unusual) linux filenames

2010-08-31 Thread Grant Edwards
On 2010-08-31, amfr...@web.de  wrote:
> Hi,
>
> i have a script that reads and writes linux paths in a file. I save the  
> path (as unicode) with 2 other variables. I save them seperated by "," and  
> the "packets" by newlines. So my file looks like this:
> path1, var1A, var1B
> path2, var2A, var2B
> path3, var3A, var3B
> 
>
> this works for "normal" paths but as soon as i have a path that does  
> include a "," it breaks. The problem now is that (afaik) linux allows  
> every char (aside from "/" and null) to be used in filenames. The only  
> solution i can think of is using null as a seperator, but there have to a  
> cleaner version ?

The normal thing to do is to escape the delimiter when it appears in
data.  There are lots of plenty of escaping standards to choose from,
and some of them (e.g. the one used for URLs) are already present
in various bits of Python's standard library.

-- 
Grant Edwards   grant.b.edwardsYow! ... the HIGHWAY is
  at   made out of LIME JELLO and
  gmail.commy HONDA is a barbequeued
   OYSTER!  Yum!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGeo

2010-08-31 Thread Robert Kern

On 8/31/10 7:21 AM, Giacomo Boffi wrote:

L  writes:


also the PyGeo readme text mentions Numerical python (I think it
means Numeric, but I also have NumPy installed)


afaict, Numerical python is numpy --- if you look at pygeo home page,
the reference to Numerical python is a link to numpy home page

on the contrary, there is no "import numpy" in all the sources of
pygeo, and a couples or so of "import Numeric", so that the situation
is unclear


numpy supercedes the older Numeric package. However, "numpy" used to be a 
colloquial name for Numeric, too.


--
Robert Kern

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

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


Find closest matching string based on collection of strings in list/dict/set

2010-08-31 Thread python
I'm parsing a simple, domain specific scripting language that has
commands like the following: *page, *title, *text, *footer, etc.
There are about 100 of these '*' commands. When we see a command
that we don't recognize, I would like to find the closest match
possible (from a list of all legal commands) and include this
suggestion in our diagnostic output.

I'm not sure what you would call the type of algorithm I'm
looking for: closest matching string or auto-correct?

Any suggestions on algorithms or python libraries that would help
me do what I'm looking for?

Here's my short-list of ideas based on my research so far:
- Soundex
- Lawrence Philips' Metaphone Algorithm (from aspell?)
- Edit Distance Algorithm
- Levenstein Word Distance

Any suggestions, comments on the above techniques, or ideas on a
simpler algorithm for finding close string matches based on a
list, dict, or set of possible strings?

Thank you,
Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving (unusual) linux filenames

2010-08-31 Thread MRAB

On 31/08/2010 15:49, amfr...@web.de wrote:

Hi,

i have a script that reads and writes linux paths in a file. I save the
path (as unicode) with 2 other variables. I save them seperated by ","
and the "packets" by newlines. So my file looks like this:
path1, var1A, var1B
path2, var2A, var2B
path3, var3A, var3B


this works for "normal" paths but as soon as i have a path that does
include a "," it breaks. The problem now is that (afaik) linux allows
every char (aside from "/" and null) to be used in filenames. The only
solution i can think of is using null as a seperator, but there have to
a cleaner version ?


You could use a tab character '\t' instead.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optimising literals away

2010-08-31 Thread Aleksey
On Aug 30, 10:38 pm, Tobias Weber  wrote:
> Hi,
> whenever I type an "object literal" I'm unsure what optimisation will do
> to it.
>
> def m(arg):
>   if arg & set([1,2,3]):
>     return 4
>
> Is the set created every time the method is called? What about a
> frozenset? Or tuple vs list? After how many calls per second does it pay
> to save it at the module level? Would anybody else find this ugly?
>
> Also I never profiled the regular expression cache...
>
> --
>   Tobias Weber

I test time creation of any types ang get next result:

dictionary = 393 000 * 10
frozenset = 267 000 * 10
list = 519 000 * 10
set = 268 000 * 10
tuple = 5 935 500 * 10
global assign = 5 882 700 * 10

All results multiple by 10 becouse i do 10 creations in one loop and
count loops per second.

As you see create global variable is more faster (20 times) then
create list and from it create set! Assigments is ~ 5 882 000*10,>>>
set creation is 268 000*10

My test system is Ubuntu 10.04, Dell Inspiron 1525, Core2Duo, T8300,
2Gb , Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3].
I make tests with XPyLIB.timetest module. (XPyLIB hosted at
sourceforge - http://sourceforge.net/apps/trac/xpylib/wiki/CookBook/TimeTest)

Assign global (pre declared by "global") function is next (N - is a
times of repeating):

gset = set((1,2,3))
def t_set_assign_global(ntimes = N, funcloop=u'funcloop',
excludecall=u'excludecall'):
"""Set assigment from global : global=(1,2,3); loop a = global 10
times in while.

@UID@ e710b888-bacd-4248-9ff7-1f7a348e1c8f
@author@ Mazhugin Aleksey
@score_common@ 1
"""
a = 0
global gset
while ntimes > 0:
a = gset
a = gset
a = gset
a = gset
a = gset
a = gset
a = gset
a = gset
a = gset
a = gset
ntimes -= 1



Set function is next:

def t_set_create(ntimes = N, funcloop=u'funcloop',
excludecall=u'excludecall'):
"""Set creation : t=(1,2,3); loop a = set(t) 10 times in while.

@UID@ a021a756-f9a5-44ec-b9e6-e5532b56c09f
@author@ Mazhugin Aleksey
@score_common@ 1
"""
a = 0
t = (1,2,3)
while ntimes > 0:
a = set(t)
a = set(t)
a = set(t)
a = set(t)
a = set(t)
a = set(t)
a = set(t)
a = set(t)
a = set(t)
a = set(t)
ntimes -= 1



Also i test regular expression compiled pattern vs non-compiled:

compiled = 343 000*2
not compiled = 164 000*2

Functions is next:

patt5 = u'*.tmp,*.pyc,*.pyo,*.bak,*.log'
path1 = u'/home/user/project/src/file.ext'
path2 = u'/home/user/project/logs/debug.log'

def t_rematch(ntimes=10, funcloop=u'funcloop',
excludecall='excludecall'):
"""
Compiled.

@UID@ 665f4014-9c11-4668-baae-e49230027bd4
@author@ Mazhugin Aleksey
@score_common@ 1
"""
ci = patt5.replace(u'\\',u'').replace(u'|',u'\
\|').replace(u'.',u'\\.').replace(u'*',u'.*'). \
replace(u'?',u'.?').replace(u'$',u'\\$').replace(u'^',u'\
\^').replace(u'{',u'\\{'). \
replace(u'(',u'\\(').replace(u'[',u'\\[').replace(u'+',u'\\
+').split(u',')
repat = u'|'.join([u'('+i+u'$)' for i in ci])
rec = re.compile(repat)
r = 0
while ntimes:
r = rec.match(path1) is not None
r = rec.match(path2) is not None
ntimes -= 1

def t_rematch_string(ntimes=10, funcloop=u'funcloop',
excludecall='excludecall'):
"""
Not compiled.

@UID@ 80fa1ca3-5d51-4f6e-8ac2-4ccafe4c1160
@author@ Mazhugin Aleksey
@score_common@ 1
"""
ci = patt5.replace(u'\\',u'').replace(u'|',u'\
\|').replace(u'.',u'\\.').replace(u'*',u'.*'). \
replace(u'?',u'.?').replace(u'$',u'\\$').replace(u'^',u'\
\^').replace(u'{',u'\\{'). \
replace(u'(',u'\\(').replace(u'[',u'\\[').replace(u'+',u'\\
+').split(u',')
repat = u'|'.join([u'('+i+u'$)' for i in ci])
#rec = re.compile(repat)
r = 0
while ntimes:
r = re.match(repat, path1) is not None
r = re.match(repat, path2) is not None
ntimes -= 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving (unusual) linux filenames

2010-08-31 Thread Jeremy Sanders
amfr...@web.de wrote:

> i have a script that reads and writes linux paths in a file. I save the
> path (as unicode) with 2 other variables. I save them seperated by "," and
> the "packets" by newlines. So my file looks like this:
> path1, var1A, var1B
> path2, var2A, var2B
> path3, var3A, var3B

If you're generating the file and it is safe to do so (you're not getting 
the data from the internet), you could use repr((path1, v1, v2)) to save the 
line to the file and eval to interpret back the tuple.

Alternatively you could use // as a separator, making sure that you replace 
multiple slashes in the path which a single slash (which are equivalent).

Jeremy


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


Re: Saving (unusual) linux filenames

2010-08-31 Thread Grant Edwards
On 2010-08-31, MRAB  wrote:
> On 31/08/2010 15:49, amfr...@web.de wrote:
>> Hi,
>>
>> i have a script that reads and writes linux paths in a file. I save the
>> path (as unicode) with 2 other variables. I save them seperated by ","
>> and the "packets" by newlines. So my file looks like this:
>> path1, var1A, var1B
>> path2, var2A, var2B
>> path3, var3A, var3B
>> 
>>
>> this works for "normal" paths but as soon as i have a path that does
>> include a "," it breaks. The problem now is that (afaik) linux allows
>> every char (aside from "/" and null) to be used in filenames. The only
>> solution i can think of is using null as a seperator, but there have to
>> a cleaner version ?
>
> You could use a tab character '\t' instead.

That just breaks with a different set of filenames.

-- 
Grant Edwards   grant.b.edwardsYow! !  Everybody out of
  at   the GENETIC POOL!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving (unusual) linux filenames

2010-08-31 Thread MRAB

On 31/08/2010 17:58, Grant Edwards wrote:

On 2010-08-31, MRAB  wrote:

On 31/08/2010 15:49, amfr...@web.de wrote:

Hi,

i have a script that reads and writes linux paths in a file. I save the
path (as unicode) with 2 other variables. I save them seperated by ","
and the "packets" by newlines. So my file looks like this:
path1, var1A, var1B
path2, var2A, var2B
path3, var3A, var3B


this works for "normal" paths but as soon as i have a path that does
include a "," it breaks. The problem now is that (afaik) linux allows
every char (aside from "/" and null) to be used in filenames. The only
solution i can think of is using null as a seperator, but there have to
a cleaner version ?


You could use a tab character '\t' instead.


That just breaks with a different set of filenames.


How many filenames contain control characters? Surely that's a bad idea.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sendmail error

2010-08-31 Thread sandric ionut

This is the only message that I will send to this list regarding my question:

1. I have copied and paste my code from Eclipe PyDev and I have used web 
interface for yahoo email to send the email. I don't know why the message 
arrived like that. I consider that the message from Dave was rude and just a 
replay considering the structure of the script would have been enough
2. Regarding the useless of the question: I consider that you two are also 
rude! 
There are some many more "useless" questions than my question on this forum!

Do not bother to replay to this email because I would not receive the message. 
Your  replays were enough to make me unsubscribe from the list

I.S.







From: Thomas Jollans 
To: python-list@python.org
Sent: Tue, August 31, 2010 4:46:58 PM
Subject: Re: sendmail error

On Tuesday 31 August 2010, it occurred to sandric ionut to exclaim:
> Hello:
> 
> I have a script for sending email from python (it is attached bellow). When
> I am launching the script I get the error:
> TypeError: cannot concatenate 'str' and 'type' objects if I use
> sys.argv[1], but if I input from the begging an email address like
> "em...@email.com", the script is working OK
> 
> What could be the problem?
> 
> Thank you,
> 
> Ionut
> 
> import
> mesaj = email.MIMEMultipart.MIMEMultipart()
> fromEmail = sys.argv[
> toEmail = os, sys, smtplib, email1]"toEmail"mesaj[
> mesaj[
> mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[
> atasament = r"Date"] =
> email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP =
> email.MIMEBase.MIMEBase(
> atasamentP.set_payload(open(atasament,
> email.Encoders.encode_base64(atasamentP)
> atasamentP.add_header(
> mesaj.attach(atasamentP)
> mesaj.attach(email.MIMEText.MIMEText(
> smtpObj =
> smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attach
> ement; filename="%s"'% os.path.basename(atasament))"Email transmis la data:
> ", email.Utils.formatdate(localtime=False)))"192.168.1.2")try
> smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string())
> smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+
> smtplib.SMTPException

I struggle to imagine what one might do to a piece of code to garble it this 
badly. If this was actually the script you're trying to run, then it would 
have blown up in your face with a angry SyntaxError, not the helpful TypeError 
you quoted. As far as I can see, you never actually use sys.argv[1], so this 
can't be the right code.

To paraphrase what you failed to spell correctly in your other message, please 
don't bother sending useless inquiries to this list. If you want to get a 
useful reply, please:

- Quote the code correctly. Before sending, check that it actually makes
   sense. The above is quite simply nothing like Python.

- Quote the entire stack trace and error message. You might have looked at it
   already, but we haven't. This information is not useless!

Also, when replying:

  - Quote properly. While top posting is discouraged, the most important bit
is to clearly distinguish quoted material from new material. Make it
possible from the structure of the message you're sending which parts you
wrote and which parts you're just quoting.

  - Keep your reply on-list.

- Thomas

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



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


Re: Fw: sendmail error

2010-08-31 Thread Chris Withers

Alexander Kapps wrote:

Instead you want something like:

except smtplib.SMTPException, msg
print "eroare: " + msg


Err, that's still concatenating a string and an exception object.

What *would* work is:

except smtplib.SMTPException, msg
 print "eroare: " + str(msg)

...not that it's particularly good coding style, what with hiding the 
traceback and all...


cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: sendmail error

2010-08-31 Thread Chris Withers

Thomas Jollans wrote:
I struggle to imagine what one might do to a piece of code to garble it this 
badly.


You viewed the text/plain part of his message, the text/html part showed 
the code almost correctly, complete with pasted-from-IDE colour 
formatting ;-)


Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fw: sendmail error

2010-08-31 Thread Alexander Kapps

Chris Withers wrote:

Alexander Kapps wrote:

Instead you want something like:

except smtplib.SMTPException, msg
print "eroare: " + msg


Err, that's still concatenating a string and an exception object.


OUCH! What a stupid error. Thanks for correction. :-)


What *would* work is:

except smtplib.SMTPException, msg
 print "eroare: " + str(msg)

...not that it's particularly good coding style, what with hiding the 
traceback and all...


Full Ack.


cheers,

Chris



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


Re: Saving (unusual) linux filenames

2010-08-31 Thread Albert Hopkins
On Tue, 2010-08-31 at 16:49 +0200, amfr...@web.de wrote:
> i have a script that reads and writes linux paths in a file. I save
> the  
> path (as unicode) with 2 other variables. I save them seperated by ","
> and  
> the "packets" by newlines. So my file looks like this:
> path1, var1A, var1B
> path2, var2A, var2B
> path3, var3A, var3B
> 
> 
> this works for "normal" paths but as soon as i have a path that does  
> include a "," it breaks. The problem now is that (afaik) linux
> allows  
> every char (aside from "/" and null) to be used in filenames. The
> only  
> solution i can think of is using null as a seperator, but there have
> to a  
> cleaner version ? 

Why is your impression that the null character is "dirty"?

E.g. that's how find|xargs etc. usually work.

Another alternative would be if you gaurantee that your varn's don't
have commas then put the path last.  But that doesn't account for
filenames containing newlines.

Another alternative would be to wrap with some kind of serialization
library. But really, what's so dirty about null?

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


Re: Saving (unusual) linux filenames

2010-08-31 Thread Nobody
On Tue, 31 Aug 2010 18:13:44 +0100, MRAB wrote:

 this works for "normal" paths but as soon as i have a path that does
 include a "," it breaks. The problem now is that (afaik) linux allows
 every char (aside from "/" and null) to be used in filenames. The only
 solution i can think of is using null as a seperator, but there have to
 a cleaner version ?
>>>
>>> You could use a tab character '\t' instead.
>>
>> That just breaks with a different set of filenames.
>>
> How many filenames contain control characters? Surely that's a bad idea.

It may be a bad idea, but it's permitted by the OS. If you're writing a
general-purpose tool, having it flake out whenever it encounters an
"unusual" filename is also a bad idea.

FWIW, my usual solution is URL-encoding (i.e. replacing any "awkward"
character by a "%" followed by two hex digits representing the byte's
value). It has the advantage that you can extend the set of bytes which
need encoding as needed without having to change the code (e.g. you can
provide a command-line argument or configuration file setting which
specifies which bytes need to be encoded).

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


Re: sendmail error

2010-08-31 Thread Thomas Jollans
On Tuesday 31 August 2010, it occurred to sandric ionut to exclaim:
> This is the only message that I will send to this list regarding my
> question:
> 
> 1. I have copied and paste my code from Eclipe PyDev and I have used web
> interface for yahoo email to send the email.

I will try never to use Yahoo! mail then.

> I don't know why the message
> arrived like that. I consider that the message from Dave was rude and just
> a replay considering the structure of the script would have been enough 2.
> Regarding the useless of the question: I consider that you two are also
> rude! There are some many more "useless" questions than my question on
> this forum!
> 
> Do not bother to replay to this email because I would not receive the
> message. Your  replays were enough to make me unsubscribe from the list

Charming. Replay indeed.

> 
> 
> 
> 
> From: Thomas Jollans 
> To: python-list@python.org
> Sent: Tue, August 31, 2010 4:46:58 PM
> Subject: Re: sendmail error
> 
> On Tuesday 31 August 2010, it occurred to sandric ionut to exclaim:
> > Hello:
> > 
> > I have a script for sending email from python (it is attached bellow).
> > When I am launching the script I get the error:
> > TypeError: cannot concatenate 'str' and 'type' objects if I use
> > sys.argv[1], but if I input from the begging an email address like
> > "em...@email.com", the script is working OK
> > 
> > What could be the problem?
> > 
> > Thank you,
> > 
> > Ionut
> > 
> > import
> > mesaj = email.MIMEMultipart.MIMEMultipart()
> > fromEmail = sys.argv[
> > toEmail = os, sys, smtplib, email1]"toEmail"mesaj[
> > mesaj[
> > mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[
> > atasament = r"Date"] =
> > email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP =
> > email.MIMEBase.MIMEBase(
> > atasamentP.set_payload(open(atasament,
> > email.Encoders.encode_base64(atasamentP)
> > atasamentP.add_header(
> > mesaj.attach(atasamentP)
> > mesaj.attach(email.MIMEText.MIMEText(
> > smtpObj =
> > smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','atta
> > ch ement; filename="%s"'% os.path.basename(atasament))"Email transmis la
> > data: ", email.Utils.formatdate(localtime=False)))"192.168.1.2")try
> > smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string())
> > smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+
> > smtplib.SMTPException
> 
> I struggle to imagine what one might do to a piece of code to garble it
> this badly. If this was actually the script you're trying to run, then it
> would have blown up in your face with a angry SyntaxError, not the helpful
> TypeError you quoted. As far as I can see, you never actually use
> sys.argv[1], so this can't be the right code.
> 
> To paraphrase what you failed to spell correctly in your other message,
> please don't bother sending useless inquiries to this list. If you want to
> get a useful reply, please:
> 
> - Quote the code correctly. Before sending, check that it actually makes
>sense. The above is quite simply nothing like Python.
> 
> - Quote the entire stack trace and error message. You might have looked at
> it already, but we haven't. This information is not useless!
> 
> Also, when replying:
> 
>   - Quote properly. While top posting is discouraged, the most important
> bit is to clearly distinguish quoted material from new material. Make it
> possible from the structure of the message you're sending which parts you
> wrote and which parts you're just quoting.
> 
>   - Keep your reply on-list.
> 
> - Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving (unusual) linux filenames

2010-08-31 Thread Grant Edwards
On 2010-08-31, MRAB  wrote:
> On 31/08/2010 17:58, Grant Edwards wrote:
>> On 2010-08-31, MRAB  wrote:
>>> On 31/08/2010 15:49, amfr...@web.de wrote:
 Hi,

 i have a script that reads and writes linux paths in a file. I save the
 path (as unicode) with 2 other variables. I save them seperated by ","
 and the "packets" by newlines. So my file looks like this:
 path1, var1A, var1B
 path2, var2A, var2B
 path3, var3A, var3B
 

 this works for "normal" paths but as soon as i have a path that does
 include a "," it breaks. The problem now is that (afaik) linux allows
 every char (aside from "/" and null) to be used in filenames. The only
 solution i can think of is using null as a seperator, but there have to
 a cleaner version ?
>>>
>>> You could use a tab character '\t' instead.
>>
>> That just breaks with a different set of filenames.
>>
> How many filenames contain control characters?

How many filenames contain ","?  Not many, but the OP wants his
program to be bulletproof.  Can't fault him for that.

If I had a nickle for every Unix program or shell-script that failed
when a filename had a space it it

> Surely that's a bad idea.

Of course it's a bad idea.  That doesn't stop people from doing it.

-- 
Grant Edwards   grant.b.edwardsYow! !  Now I understand
  at   advanced MICROBIOLOGY and
  gmail.comth' new TAX REFORM laws!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving (unusual) linux filenames

2010-08-31 Thread MRAB

On 31/08/2010 19:33, Nobody wrote:

On Tue, 31 Aug 2010 18:13:44 +0100, MRAB wrote:


this works for "normal" paths but as soon as i have a path that does
include a "," it breaks. The problem now is that (afaik) linux allows
every char (aside from "/" and null) to be used in filenames. The only
solution i can think of is using null as a seperator, but there have to
a cleaner version ?


You could use a tab character '\t' instead.


That just breaks with a different set of filenames.


How many filenames contain control characters? Surely that's a bad idea.


It may be a bad idea, but it's permitted by the OS.

[snip]
So are viruses. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Dumb Stupid Question About List and String

2010-08-31 Thread Alban Nona
Hi all,

Im stuck on this problem:
I have a function which return me a list of string (basically the result
looks like: ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
In other hand, I have another list full of that kind of entries:
["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]

I would like to do something like this:

myFirstList = ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
mySecondList =
["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]

for n in myFirstList:
if n in mySecondList:
mySecondList.remove(n)

In fact, what I want to do it to remove entries with the secondlist which
content the entries of the first one. But it seems to not work like this.
Someone can help me please ? did I miss something ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimising literals away

2010-08-31 Thread John Nagle

On 8/30/2010 8:38 AM, Tobias Weber wrote:

Hi,
whenever I type an "object literal" I'm unsure what optimisation will do
to it.


   CPython is a "naive interpreter".  It has almost no optimization.
It doesn't even really comprehend "constants".
This is an implementation problem, not a language problem.

   Shed Skin has serious optimization but limits the language.
PyPy has been trying for years, but it still barely works.
Iron Python seems to be nearing end of life, as Microsoft
phases it out.  Unladen Swallow seems to be in trouble; it's
been almost a year since the last "quarterly release".

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


Re: Saving (unusual) linux filenames

2010-08-31 Thread Arnaud Delobelle
amfr...@web.de writes:

> Hi,
>
> i have a script that reads and writes linux paths in a file. I save
> the path (as unicode) with 2 other variables. I save them seperated by
> "," and  the "packets" by newlines. So my file looks like this:
> path1, var1A, var1B
> path2, var2A, var2B
> path3, var3A, var3B
> 
>
> this works for "normal" paths but as soon as i have a path that does
> include a "," it breaks. The problem now is that (afaik) linux allows
> every char (aside from "/" and null) to be used in filenames. The only
> solution i can think of is using null as a seperator, but there have
> to a  cleaner version ?
>
> Thanks for any help
>
> Biene_Maja

A simple solution would be to save each line of data using JSON with the json
module:

>>> import json
>>> 
>>> 
>>> path = "x,y,z"
>>> varA = 12
>>> varB = "abc"
>>> line = json.dumps([path, varA, varB])
>>> print line
["x,y,z", 12, "abc"]
>>> loadpathA, loadvarA, loadvarB = json.loads(line)
>>> print loadpathA
x,y,z
>>> print loadvarA
12
>>> print loadvarB
abc

HTH

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


Re: Dumb Stupid Question About List and String

2010-08-31 Thread Alban Nona
Ok, here a solution:

myFirstList = ["FN067_098_MEN", "FN067_098_JIN", "FN067_098_BG"]

mySecondList =
["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]

for n in myFirstList:

 var = str(n)

 for n in mySecondList:

 if var in n:

  mySecondList.remove(n)

print mySecondList


:)


2010/8/31 Alban Nona 

> Hi all,
>
> Im stuck on this problem:
> I have a function which return me a list of string (basically the result
> looks like: ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
> In other hand, I have another list full of that kind of entries:
>
> ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]
>
> I would like to do something like this:
>
> myFirstList = ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
> mySecondList =
> ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]
>
> for n in myFirstList:
> if n in mySecondList:
> mySecondList.remove(n)
>
> In fact, what I want to do it to remove entries with the secondlist which
> content the entries of the first one. But it seems to not work like this.
> Someone can help me please ? did I miss something ?
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb Stupid Question About List and String

2010-08-31 Thread MRAB

On 31/08/2010 19:57, Alban Nona wrote:

Hi all,

Im stuck on this problem:
I have a function which return me a list of string (basically the result
looks like: ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
In other hand, I have another list full of that kind of entries:
["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]

I would like to do something like this:

myFirstList = ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
mySecondList =
["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]

for n in myFirstList:
 if n in mySecondList:
 mySecondList.remove(n)

In fact, what I want to do it to remove entries with the secondlist
which content the entries of the first one. But it seems to not work
like this.
Someone can help me please ? did I miss something ?


Your code is asking whether, for example, "FN067_098_MEN" is in
mySecondList. It isn't. mySecondList contains
"FN067_098_MEN_Hair_PUZ_v001.0001.exr", but that's not the same as
"FN067_098_MEN".

If I understand you correctly, you want to remove entries from
mySecondList which have an entry of myFirstList as a substring.

Here's one solution:

result_list = []
for second in mySecondList:
if not any(first in second for first in myFirstList):
result_list.append(second)

mySecondList = result_list
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb Stupid Question About List and String

2010-08-31 Thread Chris Rebert
On Tue, Aug 31, 2010 at 12:20 PM, Alban Nona  wrote:
> Ok, here a solution:

> for n in myFirstList:
>  var = str(n)

n is already a string, so the previous line doesn't do anything useful.

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


Re: Optimising literals away

2010-08-31 Thread Stefan Behnel

John Nagle, 31.08.2010 21:03:

On 8/30/2010 8:38 AM, Tobias Weber wrote:

whenever I type an "object literal" I'm unsure what optimisation will do
to it.


CPython is a "naive interpreter". It has almost no optimization.
It doesn't even really comprehend "constants".
This is an implementation problem, not a language problem.

Shed Skin has serious optimization but limits the language.
PyPy has been trying for years, but it still barely works.
Iron Python seems to be nearing end of life, as Microsoft
phases it out. Unladen Swallow seems to be in trouble; it's
been almost a year since the last "quarterly release".


To continue the list, Cython also has a couple of optimisations for 
literals. It caches simple immutable constants, applies numeric constant 
folding and it's obviously a lot faster in packing tuples and lists than 
CPython as it avoids the interpreter loop. It also optimises away the 
literal sequences in "in" tests such as


if x in (1,2,3):
...

which, in the best case of integer literals, even compile down into C 
switch statements.


Stefan

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


Re: Dumb Stupid Question About List and String

2010-08-31 Thread MRAB

On 31/08/2010 20:20, Alban Nona wrote:

Ok, here a solution:

myFirstList = ["FN067_098_MEN", "FN067_098_JIN", "FN067_098_BG"]

mySecondList =
["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]

for n in myFirstList:
  var = str(n)


Why str(n)?

Also, it would be clearer if you used different variables for the
different loops.


  for n in mySecondList:
  if var in n:
   mySecondList.remove(n)


You shouldn't change the length of a list over which you're iterating. 
Python will step along the list one entry at a time and won't notice 
when you remove an entry, so the next one will be skipped. For example:


>>> letters = ["a", "b", "c", "d", "e"]
>>> for i in letters:
... if i == "b" or i == "c":
... letters.remove(i)
...
>>> print letters
['a', 'c', 'd', 'e']

It removed "b" and then moved on to the next entry, which is "d"
because "b" has been removed and all the following entries have moved
down one place. It never sees "c".



print mySecondList


[snip]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb Stupid Question About List and String

2010-08-31 Thread Shashwat Anand
On Wed, Sep 1, 2010 at 12:27 AM, Alban Nona  wrote:

> Hi all,
>
> Im stuck on this problem:
> I have a function which return me a list of string (basically the result
> looks like: ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
> In other hand, I have another list full of that kind of entries:
>
> ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]
>
> I would like to do something like this:
>
> myFirstList = ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"]
> mySecondList =
> ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]
>
> for n in myFirstList:
> if n in mySecondList:
> mySecondList.remove(n)
>
> In fact, what I want to do it to remove entries with the secondlist which
> content the entries of the first one. But it seems to not work like this.
> Someone can help me please ? did I miss something ?
>

You can try this if you don't care about the order.

>>> myFirstList = ["FN067_098_MEN", "FN067_098_JIN", "FN067_098_BG"]
>>> mySecondList =
["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]
>>> list(set(mySecondList).difference(myFirstList))
['FN067_098_MEN_Jin_MVE_v001.0001.exr',
'FN067_098_MEN_Hair_PUZ_v001.0001.exr', 'FR043_010_GEN_NRM_v001.0001.exr',
'FN067_098_JIN_Hair_SPC_v001.0001.exr']

Another example to make this clear.
>>> a = range(10)
>>> b = range(5,15)
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> b
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
>>> list(set(b).difference(a))
[10, 11, 12, 13, 14]


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


Re: Find closest matching string based on collection of strings in list/dict/set

2010-08-31 Thread Shashwat Anand
On Tue, Aug 31, 2010 at 9:12 PM,  wrote:

> I'm parsing a simple, domain specific scripting language that has commands
> like the following: *page, *title, *text, *footer, etc. There are about 100
> of these '*' commands. When we see a command that we don't recognize, I
> would like to find the closest match possible (from a list of all legal
> commands) and include this suggestion in our diagnostic output.
>
> I'm not sure what you would call the type of algorithm I'm looking for:
> closest matching string or auto-correct?
>
> Any suggestions on algorithms or python libraries that would help me do
> what I'm looking for?
>
> Here's my short-list of ideas based on my research so far:
> - Soundex
> - Lawrence Philips' Metaphone Algorithm (from aspell?)
> - Edit Distance Algorithm
> - Levenstein Word Distance
>
> Any suggestions, comments on the above techniques, or ideas on a simpler
> algorithm for finding close string matches based on a list, dict, or set of
> possible strings?
>

You are looking possibly for autocompletion/spell correction algorithm. You
can write a HMM based Pos Tagger.


> Thank you,
> Malcolm
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: How to convert (unicode) text to image?

2010-08-31 Thread Terry Reedy

On 8/31/2010 12:47 AM, ru...@yahoo.com wrote:


I have participated in 71 doc improvement issues on the tracker. Most of
those I either initiated or provided suggestions. How many have you
helped with?


Certainly not 71.  But there is, for example, 
http://bugs.python.org/issue1397474
Please note the date on it.


Ugh. Some doc issues get resolved in hours. That didn't. I built on your 
proposed change and properly assigned the issue, so it is more likely to 
get attention. Please comment there on my revision.


--
Terry Jan Reedy

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


Re: Optimising literals away

2010-08-31 Thread Terry Reedy

On 8/31/2010 12:33 PM, Aleksey wrote:

On Aug 30, 10:38 pm, Tobias Weber  wrote:

Hi,
whenever I type an "object literal" I'm unsure what optimisation will do
to it.


Optimizations are generally implentation dependent. CPython currently 
creates numbers, strings, and tuple literals just once. Mutable literals 
must be created each time as they may be bound and saved.



def m(arg):
   if arg&  set([1,2,3]):


set() is a function call, not a literal. When m is called, who knows 
what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, 
which is much faster as it avoids creating and deleting a list. On my 
machine, .35 versus .88 usec. Even then, it must be calculated each time 
because sets are mutable and could be returned to the calling code.



 return 4

Is the set created every time the method is called? What about a
frozenset? Or tuple vs list? After how many calls per second does it pay
to save it at the module level? Would anybody else find this ugly?


Defining module level constants is considered good practice in some 
circles, especially if is something you might want to change. That is 
what function definitions are (as long as the name is not redefined. 
This is different from having lots of module level variables.


To see what CPython does, you can use the dis module.

--
Terry Jan Reedy

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


Python libs on Windows ME

2010-08-31 Thread hexusne...@gmail.com
I'm not guessing that this is a problem on Windows 98, but on Windows
ME modules in /Lib don't seem to load.  Examples include site.py and
os.py which are both located in the top level Lib directory.  The same
thing happens with Python 2.3, 2.4, and 2.5.  I can't get IDLE to load
and the Python interpreter always complains that it can't load the
"site" module even if Python is run from the same directory as the
module (note: this does not happen if a module is loaded from the
current working directory while in the interpreter).

I would use another os like Linux or Windows 2000, but this particular
computer can't even seem to handle even the most minimal graphical
Linux distributions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python as Scripting Language in IIS

2010-08-31 Thread hexusne...@gmail.com
On Aug 30, 6:55 pm, naugiedoggie  wrote:
> Hello,
>
> Windows 2003, 64-bit, standard edition server with IIS 6.0.  I
> followed the MS instruction sheets on setting up CGI application with
> Python as scripting engine.  I'm just getting 404 for the test script,
> whereas an html file in the same virtual directory is properly
> displayed.
>
> Here:
>
> Creating Applications in IIS 6.0 (IIS 
> 6.0)http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Librar...
>
> Setting Application Mappings in IIS 6.0 (IIS 
> 6.0)http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Librar...
>
> I mapped the exe thus:  c:\Python26\python.exe -u "%s %s"
> to extension `py' for all verbs and checked the `script engine' box.
>
> There are no errors in the script itself, i ran it from the command
> line to be sure.  Further, I enabled ASP and tried using python as the
> scripting language.  That generates this error:
>
> 
> Active Server Pages error 'ASP 0129'
> Unknown scripting language
> /cgi/index.asp, line 1
> The scripting language 'Python' is not found on the server.
> 
>
> I can't find any good references for dealing with this, either.
>
> I've dicked around with this for so long, now I don't know which way
> is up, anymore.
>
> Any thoughts on where I might be going wrong, much appreciated.
>
> Thanks.
>
> mp

I had the same problem with Python 2.5 and IIS on Windows XP.  I
wonder if using ActivePython would make any difference?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Helper app for intranet site

2010-08-31 Thread kevinlcarlson
On Aug 30, 4:13 pm, Lawrence D'Oliveiro  wrote:
> In message
> <61894f54-90ff-4e0e-9c81-860b6e9cd...@p12g2000prn.googlegroups.com>,
>
>
>
> kevinlcarlson wrote:
> > On Aug 29, 8:46 pm, Lawrence D'Oliveiro 
> > wrote:
>
> >> In message
> >> <45e0772c-24a8-4cbb-a4fc-74a1b6c25...@n19g2000prf.googlegroups.com>,
> >> kevinlcarlson wrote:
>
> >>> I'm exploring the possibility of developing a helper app for an
> >>> existing internal company website.  Basically, it would automatically
> >>> scan the current page contents, including prepopulated forms, and
> >>> provide context-related business rule comments to the user, via a stay-
> >>> on-top wxPython panel.
>
> >> Seems like a roundabout way of doing it. Can’t you integrate into the
> >> server code which is generating the page contents, instead of trying to
> >> reverse- engineer those contents?
>
> > Absolutely - that would be the best way to accomplish this.
> > Unfortunately, our group has no access to the web server and the
> > developers have this functionality scheduled about a year into the
> > future, but we need it ASAP.  Also, our group would like to be in
> > control of the code and business rule contents, rather than wait for
> > updates from the busy web team...
>
> Conway’s Law: any piece of software reflects the organizational structure
> that produced it.

Hard to disagree with that sentiment - I've come across a fair amount
of disorganized software in my day... ;)
In any case, I'll try the WinGuiAuto approach and see how that
works...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb Stupid Question About List and String

2010-08-31 Thread Alban Nona
Well, I have a lot to learn :)

Thank you very much both of you ! it seems to work now :p

2010/8/31 MRAB 

> On 31/08/2010 20:20, Alban Nona wrote:
>
>> Ok, here a solution:
>>
>> myFirstList = ["FN067_098_MEN", "FN067_098_JIN", "FN067_098_BG"]
>>
>> mySecondList =
>>
>> ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]
>>
>> for n in myFirstList:
>>  var = str(n)
>>
>
> Why str(n)?
>
> Also, it would be clearer if you used different variables for the
> different loops.
>
>
>   for n in mySecondList:
>>  if var in n:
>>   mySecondList.remove(n)
>>
>
> You shouldn't change the length of a list over which you're iterating.
> Python will step along the list one entry at a time and won't notice when
> you remove an entry, so the next one will be skipped. For example:
>
> >>> letters = ["a", "b", "c", "d", "e"]
> >>> for i in letters:
> ... if i == "b" or i == "c":
> ... letters.remove(i)
> ...
> >>> print letters
> ['a', 'c', 'd', 'e']
>
> It removed "b" and then moved on to the next entry, which is "d"
> because "b" has been removed and all the following entries have moved
> down one place. It never sees "c".
>
>
>> print mySecondList
>>
>>  [snip]
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find closest matching string based on collection of strings in list/dict/set

2010-08-31 Thread Joel Goldstick

pyt...@bdurham.com wrote:

I'm parsing a simple, domain specific scripting language that has
commands like the following: *page, *title, *text, *footer, etc.
There are about 100 of these '*' commands. When we see a command
that we don't recognize, I would like to find the closest match
possible (from a list of all legal commands) and include this
suggestion in our diagnostic output.

I'm not sure what you would call the type of algorithm I'm
looking for: closest matching string or auto-correct?

Any suggestions on algorithms or python libraries that would help
me do what I'm looking for?

Here's my short-list of ideas based on my research so far:
- Soundex
- Lawrence Philips' Metaphone Algorithm (from aspell?)
- Edit Distance Algorithm
- Levenstein Word Distance

Any suggestions, comments on the above techniques, or ideas on a
simpler algorithm for finding close string matches based on a
list, dict, or set of possible strings?

Thank you,
Malcolm



Have you looked at difflib?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python libs on Windows ME

2010-08-31 Thread Thomas Jollans
On Tuesday 31 August 2010, it occurred to hexusne...@gmail.com to exclaim:
> I'm not guessing that this is a problem on Windows 98, but on Windows
> ME modules in /Lib don't seem to load.  Examples include site.py and
> os.py which are both located in the top level Lib directory.  The same
> thing happens with Python 2.3, 2.4, and 2.5.  I can't get IDLE to load
> and the Python interpreter always complains that it can't load the
> "site" module even if Python is run from the same directory as the
> module (note: this does not happen if a module is loaded from the
> current working directory while in the interpreter).

What is sys.path set to ?

python.exe -c "import sys; print(sys.path)"

It sounds like the stdlib directory is not on sys.path. Couldn't say why 
though...

> 
> I would use another os like Linux or Windows 2000, but this particular
> computer can't even seem to handle even the most minimal graphical
> Linux distributions.

Really? I'm sure you can get Linux on there somehow. It might not be trivial, 
but it should definitely be possible. Out of interest: what distros did you 
try?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functions continuing to ru after returning something?

2010-08-31 Thread Stefan Schwarzer
Hi,

On 2010-08-31 02:05, Bradley Hintze wrote:
> I may be having a brain fart, but is it at all possible to have a
> function first return a value then continue its calculation. Like this
> simple example:
> 
> my_var = 5
> def my_function():
> return my_var
> my_var +=1
> 
> This obviously won't work as written but is there a cleaver way around this.

At least in CPython 2.6.5 the above code results in

Traceback (most recent call last):
  File "test.py", line 7, in 
my_function()
  File "test.py", line 3, in my_function
return my_var
UnboundLocalError: local variable 'my_var' referenced before assignment

as soon as the function is called.

If you want to have the global my_var modified, you need
a "global my_var" statement in the function body.

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


Re: Find closest matching string based on collection of strings in list/dict/set

2010-08-31 Thread Arnaud Delobelle
Joel Goldstick  writes:

> pyt...@bdurham.com wrote:
>> I'm parsing a simple, domain specific scripting language that has
>> commands like the following: *page, *title, *text, *footer, etc.
>> There are about 100 of these '*' commands. When we see a command
>> that we don't recognize, I would like to find the closest match
>> possible (from a list of all legal commands) and include this
>> suggestion in our diagnostic output.
>>
>> I'm not sure what you would call the type of algorithm I'm
>> looking for: closest matching string or auto-correct?
>>
>> Any suggestions on algorithms or python libraries that would help
>> me do what I'm looking for?
>>
>> Here's my short-list of ideas based on my research so far:
>> - Soundex
>> - Lawrence Philips' Metaphone Algorithm (from aspell?)
>> - Edit Distance Algorithm
>> - Levenstein Word Distance
>>
>> Any suggestions, comments on the above techniques, or ideas on a
>> simpler algorithm for finding close string matches based on a
>> list, dict, or set of possible strings?
>>
>> Thank you,
>> Malcolm
>>
>>
> Have you looked at difflib?

You only have a few words to compare with, so why not try this
naive solution?

>>> commands = ["page", "text", "footer", "header", "title"]
>>> def closest(u):
...return min(commands, key=lambda v: len(set(u) ^ set(v)))
... 
>>> closest("paige")
'page'
>>> closest("heeder")
'header'
>>> closest("tilte")
'title'

-- 
Arnaud

PS: oddly, I didn't see the OP (reading newsgroup).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find closest matching string based on collection of strings in list/dict/set

2010-08-31 Thread Shashwat Anand
On Wed, Sep 1, 2010 at 2:31 AM, Joel Goldstick <
joel.goldst...@columbuswebmakers.com> wrote:

> pyt...@bdurham.com wrote:
>
>> I'm parsing a simple, domain specific scripting language that has
>> commands like the following: *page, *title, *text, *footer, etc.
>> There are about 100 of these '*' commands. When we see a command
>> that we don't recognize, I would like to find the closest match
>> possible (from a list of all legal commands) and include this
>> suggestion in our diagnostic output.
>>
>> I'm not sure what you would call the type of algorithm I'm
>> looking for: closest matching string or auto-correct?
>>
>> Any suggestions on algorithms or python libraries that would help
>> me do what I'm looking for?
>>
>> Here's my short-list of ideas based on my research so far:
>> - Soundex
>> - Lawrence Philips' Metaphone Algorithm (from aspell?)
>> - Edit Distance Algorithm
>> - Levenstein Word Distance
>>
>> Any suggestions, comments on the above techniques, or ideas on a
>> simpler algorithm for finding close string matches based on a
>> list, dict, or set of possible strings?
>>
>> Thank you,
>> Malcolm
>>
>>
>>  Have you looked at difflib?
>

On a side note, you can read this awesome article by Peter Norvig.
http://norvig.com/spell-correct.html


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



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


Re: Python libs on Windows ME

2010-08-31 Thread Alexander Kapps

Thomas Jollans wrote:


I would use another os like Linux or Windows 2000, but this particular
computer can't even seem to handle even the most minimal graphical
Linux distributions.


Really? I'm sure you can get Linux on there somehow. It might not be trivial, 
but it should definitely be possible. Out of interest: what distros did you 
try?


In my experiences, getting /some/ Linux on a usual, say, post-1995 
PC is almost trivial, even with GUI. It's just a matter of choosing 
the right distro (and desktop environment).


If the OP would post the exact hardware specs, I'm almost sure, that 
we can find a distro that works without much hassle.

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


Re: Saving (unusual) linux filenames

2010-08-31 Thread Stefan Schwarzer
Hi Grant,

On 2010-08-31 20:49, Grant Edwards wrote:
> How many filenames contain ","?

CVS repository files end with ,v . However, just let's agree
that nobody uses CVS anymore. :-)

> Not many, but the OP wants his
> program to be bulletproof.  Can't fault him for that.

What about using the csv (not CVS) module?

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


Re: Saving (unusual) linux filenames

2010-08-31 Thread AmFreak

Thanks for all the nice answers!


The normal thing to do is to escape the delimiter when it appears in
data.  There are lots of plenty of escaping standards to choose from,
and some of them (e.g. the one used for URLs) are already present
in various bits of Python's standard library.


The CSV module has something like that, but im using unicode and it  
doesn't work with that.





Why is your impression that the null character is "dirty"?
E.g. that's how find|xargs etc. usually work.
Another alternative would be if you gaurantee that your varn's don't
have commas then put the path last.  But that doesn't account for
filenames containing newlines.
Another alternative would be to wrap with some kind of serialization
library. But really, what's so dirty about null?


I think i just prefer a little formated file instead of one lng row :)




A simple solution would be to save each line of data using JSON with the  
json

module:



import json
  path = "x,y,z"
varA = 12
varB = "abc"
line = json.dumps([path, varA, varB])
print line

["x,y,z", 12, "abc"]

loadpathA, loadvarA, loadvarB = json.loads(line)
print loadpathA

x,y,z

print loadvarA

12

print loadvarB

abc

Thanks, just tried it - so simple, but seems to work like a charm. Really  
aprecciated :D.

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


Re: Stackless Python and EVE Online

2010-08-31 Thread Krister Svanlund
On Tue, Aug 31, 2010 at 5:10 PM, Benjamin Kaplan
 wrote:
> On Tuesday, August 31, 2010, Roman Sokolyuk  wrote:
>> Hi,
>>
>> I am new to Python and I wanted to understand something...
>> The EVE Online Client is build using Stackless Python
>> So when I install the client on my machine, how doe sit get run if I do not 
>> have Python installed?
>>
> We call it "freezing" the program. There are several tools that do
> this with py2exe being the most popular. These tools create an
> executable that includes a bundled python interpreter along with all
> the scripts and modules needed to run the program.
>> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I'm not sure but I do believe it is mainly the servers that are
written in stackless...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stackless Python and EVE Online

2010-08-31 Thread Benjamin Kaplan
On Tue, Aug 31, 2010 at 5:45 PM, Krister Svanlund
 wrote:
> On Tue, Aug 31, 2010 at 5:10 PM, Benjamin Kaplan
>  wrote:
>> On Tuesday, August 31, 2010, Roman Sokolyuk  wrote:
>>> Hi,
>>>
>>> I am new to Python and I wanted to understand something...
>>> The EVE Online Client is build using Stackless Python
>>> So when I install the client on my machine, how doe sit get run if I do not 
>>> have Python installed?
>>>
>> We call it "freezing" the program. There are several tools that do
>> this with py2exe being the most popular. These tools create an
>> executable that includes a bundled python interpreter along with all
>> the scripts and modules needed to run the program.
>>> Thanks.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> I'm not sure but I do believe it is mainly the servers that are
> written in stackless...
>

You'd have a hard time scripting the game with Python if only the
server used it.
http://wiki.eveonline.com/en/wiki/How_is_the_game_logic_implemented_in_EVE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimising literals away

2010-08-31 Thread MRAB

On 31/08/2010 21:18, Terry Reedy wrote:

On 8/31/2010 12:33 PM, Aleksey wrote:

On Aug 30, 10:38 pm, Tobias Weber wrote:

Hi,
whenever I type an "object literal" I'm unsure what optimisation will do
to it.


Optimizations are generally implentation dependent. CPython currently
creates numbers, strings, and tuple literals just once. Mutable literals
must be created each time as they may be bound and saved.


def m(arg):
if arg& set([1,2,3]):


set() is a function call, not a literal. When m is called, who knows
what 'set' will be bound to? In Py3, at least, you could write {1,2,3},
which is much faster as it avoids creating and deleting a list. On my
machine, .35 versus .88 usec. Even then, it must be calculated each time
because sets are mutable and could be returned to the calling code.


There's still the possibility of some optimisation. If the resulting
set is never stored anywhere (bound to a name, for example) then it
could be created once. When the expression is evaluated there could be
a check so see whether 'set' is bound to the built-in class, and, if it
is, then just use the pre-created set.


return 4

Is the set created every time the method is called? What about a
frozenset? Or tuple vs list? After how many calls per second does it pay
to save it at the module level? Would anybody else find this ugly?


Defining module level constants is considered good practice in some
circles, especially if is something you might want to change. That is
what function definitions are (as long as the name is not redefined.
This is different from having lots of module level variables.

To see what CPython does, you can use the dis module.


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


Re: Dumb Stupid Question About List and String

2010-08-31 Thread Alban Nona
Just Another Question on this one, Im trying to create that kind of thing in
code now:

#GENERE ET INCREMENT LE NOM DES ELEMENTS

val = 0

list = ["0", "1", "2", "3"]

listEl = []

for n in list:

 val = val + 1

 next = "00" +str(val)

 elem = "ELM"+next

 listEl.append(elem)



#INCREMENT LE NOM DES ELEMENTS AVEC LE NOM DES PASSES

listPass = ["DIF","SPC", "RFL", "SSS", "REFR", "ALB", "AMB", "NRM", "MVE",
"DPF", "SDW", "MAT", "WPP"]

listElem = []

for first in listEl:

 for second in listPass:

 listElem.append(first+"_"+second)


print listElem

print listEl

What I would like to do is:

if 'ELM001' Contained in one of the entries of listElem, create a new list
with only 'ELM001' Elements (eg: newList=['ELM001_DIF', 'ELM001_SPC',
'ELM001_RFL', 'ELM001_SSS', 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB',
'ELM001_NRM', 'ELM001_MVE', 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT',
'ELM001_WPP']

Damn Im so lost with this tables and loop, Im always trying to
understand in which way I should do it :/
Any Ideas please ?


2010/8/31 Alban Nona 

> Well, I have a lot to learn :)
>
> Thank you very much both of you ! it seems to work now :p
>
> 2010/8/31 MRAB 
>
>> On 31/08/2010 20:20, Alban Nona wrote:
>>
>>  Ok, here a solution:
>>>
>>> myFirstList = ["FN067_098_MEN", "FN067_098_JIN", "FN067_098_BG"]
>>>
>>> mySecondList =
>>>
>>> ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"]
>>>
>>> for n in myFirstList:
>>>  var = str(n)
>>>
>>
>> Why str(n)?
>>
>> Also, it would be clearer if you used different variables for the
>> different loops.
>>
>>
>>   for n in mySecondList:
>>>  if var in n:
>>>   mySecondList.remove(n)
>>>
>>
>> You shouldn't change the length of a list over which you're iterating.
>> Python will step along the list one entry at a time and won't notice when
>> you remove an entry, so the next one will be skipped. For example:
>>
>> >>> letters = ["a", "b", "c", "d", "e"]
>> >>> for i in letters:
>> ... if i == "b" or i == "c":
>> ... letters.remove(i)
>> ...
>> >>> print letters
>> ['a', 'c', 'd', 'e']
>>
>> It removed "b" and then moved on to the next entry, which is "d"
>> because "b" has been removed and all the following entries have moved
>> down one place. It never sees "c".
>>
>>
>>> print mySecondList
>>>
>>>  [snip]
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python libs on Windows ME

2010-08-31 Thread hexusne...@gmail.com
On Aug 31, 2:04 pm, Thomas Jollans  wrote:
> On Tuesday 31 August 2010, it occurred to hexusne...@gmail.com to exclaim:
>
> > I'm not guessing that this is a problem on Windows 98, but on Windows
> > ME modules in /Lib don't seem to load.  Examples include site.py and
> > os.py which are both located in the top level Lib directory.  The same
> > thing happens with Python 2.3, 2.4, and 2.5.  I can't get IDLE to load
> > and the Python interpreter always complains that it can't load the
> > "site" module even if Python is run from the same directory as the
> > module (note: this does not happen if a module is loaded from the
> > current working directory while in the interpreter).
>
> What is sys.path set to ?
>
> python.exe -c "import sys; print(sys.path)"
>
> It sounds like the stdlib directory is not on sys.path. Couldn't say why
> though...
>
>
>
> > I would use another os like Linux or Windows 2000, but this particular
> > computer can't even seem to handle even the most minimal graphical
> > Linux distributions.
>
> Really? I'm sure you can get Linux on there somehow. It might not be trivial,
> but it should definitely be possible. Out of interest: what distros did you
> try?

I think Puppy Linux might work, but I'd need GTK for wxPython, and I
assume that means version 2 of GTK which I'm not sure comes with Puppy
Linux and I've experienced problems in the past compiling GTK with './
configure && make' and so on.

Yeah, for some reason, the sys.path variable was set with 'python'
instead of 'Python25'.  Funny how I never had that problem on Windows
XP.  Renaming the directory or appending to sys.path fixes that
problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimising literals away

2010-08-31 Thread Cameron Simpson
On 31Aug2010 22:53, MRAB  wrote:
[...]
| >>>def m(arg):
| >>>if arg& set([1,2,3]):
| >
| >set() is a function call, not a literal. When m is called, who knows
| >what 'set' will be bound to? In Py3, at least, you could write {1,2,3},
| >which is much faster as it avoids creating and deleting a list. On my
| >machine, .35 versus .88 usec. Even then, it must be calculated each time
| >because sets are mutable and could be returned to the calling code.
| >
| There's still the possibility of some optimisation. If the resulting
| set is never stored anywhere (bound to a name, for example) then it
| could be created once. When the expression is evaluated there could be
| a check so see whether 'set' is bound to the built-in class, and, if it
| is, then just use the pre-created set.

Wouldn't you need to repeat that check every time, otherwise "set" may
no longer be the builtin?
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

>From sci.physics:
t...@mailzone.com:
  The only problem is, how do you send a message from Earth to Mars
  instantly?  Does anyone have any ideas about where we can start?
John Baez http://mail.python.org/mailman/listinfo/python-list


Re: Dumb Stupid Question About List and String

2010-08-31 Thread MRAB

On 31/08/2010 22:57, Alban Nona wrote:

Just Another Question on this one, Im trying to create that kind of
thing in code now:

#GENERE ET INCREMENT LE NOM DES ELEMENTS

val = 0

list = ["0", "1", "2", "3"]

listEl = []

for n in list:

  val = val + 1

  next = "00" +str(val)

  elem = "ELM"+next

  listEl.append(elem)



#INCREMENT LE NOM DES ELEMENTS AVEC LE NOM DES PASSES

listPass = ["DIF","SPC", "RFL", "SSS", "REFR", "ALB", "AMB", "NRM",
"MVE", "DPF", "SDW", "MAT", "WPP"]

listElem = []

for first in listEl:

  for second in listPass:

  listElem.append(first+"_"+second)


print listElem

print listEl


What I would like to do is:

if 'ELM001' Contained in one of the entries of listElem, create a new
list with only 'ELM001' Elements (eg: newList=['ELM001_DIF',
'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', 'ELM001_REFR', 'ELM001_ALB',
'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', 'ELM001_DPF', 'ELM001_SDW',
'ELM001_MAT', 'ELM001_WPP']

Damn Im so lost with this tables and loop, Im always trying to
understand in which way I should do it :/
Any Ideas please ?


How about:

newList = []
for elem in listElem:
if 'ELM001' in elem:
newList.append(elem)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb Stupid Question About List and String

2010-08-31 Thread Xavier Ho
On 1 September 2010 07:57, Alban Nona  wrote:

> listPass = ["DIF","SPC", "RFL", "SSS", "REFR", "ALB", "AMB", "NRM", "MVE",
> "DPF", "SDW", "MAT", "WPP"]
>

Out of curiosity, could you briefly mention what "SDW" and "WPP" passes are?
I've worked out the rest, and these two are riddling my brain.

(On topic: If you want only the elements starting with ELM001, or whatever,
use a if condition like what MRAB posted.)

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


Re: Optimising literals away

2010-08-31 Thread MRAB

On 31/08/2010 23:11, Cameron Simpson wrote:

On 31Aug2010 22:53, MRAB  wrote:
[...]
|>>>def m(arg):
|>>>if arg&  set([1,2,3]):
|>
|>set() is a function call, not a literal. When m is called, who knows
|>what 'set' will be bound to? In Py3, at least, you could write {1,2,3},
|>which is much faster as it avoids creating and deleting a list. On my
|>machine, .35 versus .88 usec. Even then, it must be calculated each time
|>because sets are mutable and could be returned to the calling code.
|>
| There's still the possibility of some optimisation. If the resulting
| set is never stored anywhere (bound to a name, for example) then it
| could be created once. When the expression is evaluated there could be
| a check so see whether 'set' is bound to the built-in class, and, if it
| is, then just use the pre-created set.

Wouldn't you need to repeat that check every time, otherwise "set" may
no longer be the builtin?


Isn't that what I said?

My point is that if you have a set of constants which is created and
then discarded you can cache it and reuse it next time. You check every
time whether 'set' is bound to the set class.
--
http://mail.python.org/mailman/listinfo/python-list


Ed Lambda: Functional programming meetup in Edinburgh

2010-08-31 Thread Ollie Saunders
Hi guys,

I'm running a meetup for functional programming in Edinburgh. The
first one will be on the 13th of September at Malone's Irish Bar (14
Forrest Road) and will continue every 2nd monday of each month. For
the first meetup I think we'll just be having a chat and getting to
know each other but I hope to be able to expand it to talks and coding
dojos once we have some regular numbers.

For more details: http://meetup.com/ed-lambda/
And we're on Twitter: http://twitter.com/ed_lambda
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance: sets vs dicts.

2010-08-31 Thread Terry Reedy

On 8/31/2010 10:09 AM, Aahz wrote:

In article,
Jerry Hill  wrote:

On Mon, Aug 30, 2010 at 7:42 PM, Aahz  wrote:


Possibly; IMO, people should not need to run timeit to determine basic
algorithmic speed for standard Python datatypes.


http://wiki.python.org/moin/TimeComplexity takes a stab at it.  IIRC,
last time this came up, there was some resistance to making promises
about time complexity in the official docs, since that would make
those numbers part of the language, and thus binding on other
implementations.


I'm thoroughly aware of that page and updated it yesterday to make it
easier to find.  ;-)

However, I think there are some rock-bottom basic guarantees we can make
regardless of implementation.  Does anyone seriously think that an
implementation would be accepted that had anything other than O(1) for
index access into tuples and lists?


Does anyone seriously think that an implementation should be rejected as 
an implementation if it intellegently did seq[n] lookups in log2(n)/31 
time units for all n (as humans would do), instead of stupidly taking 1 
time unit for all n < 2**31 and rejecting all larger values (as 32-bit 
CPython does)?


>  Dicts that were not O(1) for access with non-pathological hashing?

You would actually be unhappy if small dicts ran even faster than they 
do now (while large dicts ran the same)? Not me!



I suggest that we should agree on these guarantees and document them in
the core.


I disagree for several reasons.

1. It would a category mistake. Python is an abstract algorithm 
language. The concept of speed is not applicable. I happen to think it 
one of the best, which is why I once dubbed it 'executable pseudocode', 
to compare it to similar but inferior, non-executable algorithm 
languages too often used still today. To human readers, as readers, 
speed of CPython or anything else is not relevant.


2. A Python interpreter is an abstract algorithm. Algorithms can be 
characterized by operation counts, but not by physical universe time.


3. Algorithms, including Python interpreters, can be embodied in 
anything that can compute, including humans, VonNeuman machines of 
various types, and possible future non-VonNeuman machines. To limit 
'python interpreter' to current vonNeuman machines would be short 
sighted. Human interpretation of Python code (and other specifications) 
is part of development, testing, and debugging.


4. Guarantee? Who will pay what to who if what is not performed ;-?. The 
Python license intentionally disclaims any guarantee of performance. If 
you are using 'guarantee' metaphorically, perhaps try another word.


5. Accepted? If you want to claim that an interpreter that is useless 
for your purposes is not really an interpreter, you are free to, I 
suppose. Asking the PSF to impose your view on me would, to me, violate 
its diversity policy.


6. O-notation was developed for characterizing the asymptotic (large-N) 
behavior of abstract algorithms in terms of abstract operation counts. 
Left out are differences between operations, lower order terms, 
multiplicative constants, how large N must be to get large-N behavior, 
and what happens for smaller N. These and other factors make the 
translation of O(f(n)) into real time extremely mushy or even wrong.


I already suggested that O(1) lookup is a symption of simple-minded 
arithmetic stupidity, of doing unnecessary work when adding small 
numbers. When it is a result doing most additions slower than necessary, 
it is a bad thing, not a good thing, and a bad criteria for an 
acceptable algorithm and acceptable interpreter. Similarly, books say 
that O(n*logn) sorting is  'better' that O(n**2) sorting. However, Tim 
Peters verified that the opposite is true for real times for small n, 
and hence the current list.sort smartly uses a fast O(n**2) algorithm 
for small lists (len < 64) and small runs in larger lists. Rejecting 
list.sort for this reason would be stupid.


--
Terry Jan Reedy

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


msg.attach multiple attachments and passing vars to html

2010-08-31 Thread aurfalien

Hi,

Few questions as I've been at this for dayz.

Can I do multiple attachments in order via msg.attach as so;

part1 = MIMEText(html, 'html')
msg.attach(part1)
part2 = MIMEText(text, 'plain')
msg.attach(part2)
part3 = MIMEText(html, 'html')
msg.attach(part3)

I desire to attach part1, part2 and part3 in that order.

Also, is it somehow possible to pas python vars to html?

My goal to to have an email that says something like;

Welcome to ACME.

A few LINKS to get you started.

Your user name is USRNM and your password is PASS

Where USRNM and PASS are python vars but the rest is an html based  
email.


LINKS is an actual hyperlink, hence the desire to do html based emails.

Thanks in advance,

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


Re: Stackless Python and EVE Online

2010-08-31 Thread Terry Reedy

On 8/31/2010 11:10 AM, Benjamin Kaplan wrote:

On Tuesday, August 31, 2010, Roman Sokolyuk  wrote:

Hi,

I am new to Python and I wanted to understand something...
The EVE Online Client is build using Stackless Python
So when I install the client on my machine, how doe sit get run if I do not 
have Python installed?


We call it "freezing" the program. There are several tools that do
this with py2exe being the most popular. These tools create an
executable that includes a bundled python interpreter along with all
the scripts and modules needed to run the program.


Bundling Python with an app adds a few megabytes, depending on how many 
modules are included. For a 10K script, that is a big nuisance. For a 
100M+ app, it is trivial.


While I have not yet tried Eve, both for lack of a good enough machine 
and fear of having my life sucked away, it has been a positive for 
Python. Beyond the publicity, Eve is a pretty good stress test, and they 
have contributed a few bug reports and patches back to the core.


--
Terry Jan Reedy

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


Re: Python libs on Windows ME

2010-08-31 Thread Alexander Kapps

hexusne...@gmail.com wrote:

On Aug 31, 2:04 pm, Thomas Jollans  wrote:

On Tuesday 31 August 2010, it occurred to hexusne...@gmail.com to exclaim:


I'm not guessing that this is a problem on Windows 98, but on Windows
ME modules in /Lib don't seem to load.  Examples include site.py and
os.py which are both located in the top level Lib directory.  The same
thing happens with Python 2.3, 2.4, and 2.5.  I can't get IDLE to load
and the Python interpreter always complains that it can't load the
"site" module even if Python is run from the same directory as the
module (note: this does not happen if a module is loaded from the
current working directory while in the interpreter).

What is sys.path set to ?

python.exe -c "import sys; print(sys.path)"

It sounds like the stdlib directory is not on sys.path. Couldn't say why
though...




I would use another os like Linux or Windows 2000, but this particular
computer can't even seem to handle even the most minimal graphical
Linux distributions.

Really? I'm sure you can get Linux on there somehow. It might not be trivial,
but it should definitely be possible. Out of interest: what distros did you
try?


I think Puppy Linux might work, but I'd need GTK for wxPython, and I
assume that means version 2 of GTK which I'm not sure comes with Puppy
Linux and I've experienced problems in the past compiling GTK with './
configure && make' and so on.


Well, just try. AFAIK, Puppy has GTK2 (actually, it would surprise 
me if not)

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


Re: Saving (unusual) linux filenames

2010-08-31 Thread Alan Meyer

On 8/31/2010 2:33 PM, Nobody wrote:

...

FWIW, my usual solution is URL-encoding (i.e. replacing any "awkward"
character by a "%" followed by two hex digits representing the byte's
value). It has the advantage that you can extend the set of bytes which
need encoding as needed without having to change the code (e.g. you can
provide a command-line argument or configuration file setting which
specifies which bytes need to be encoded).


I like that one.

A similar solution is to use an escape character, e.g., backslash, e.g., 
"This is a backslash\\ and this is a comma\,."


However, because the comma won't appear at all in the URL-encoded 
version, it has the virtue of still allowing you to split on commas.


You must of course also URL encode the '%' as %25, e.g.,
"Here is a comma (%2C) and this (%2C) is a percent sign."

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


Re: Saving (unusual) linux filenames

2010-08-31 Thread Nobody
On Tue, 31 Aug 2010 18:49:33 +, Grant Edwards wrote:

>> How many filenames contain control characters?
> 
> How many filenames contain ","?  Not many,

Unless you only ever deal with "Unix folk", it's not /that/ uncommon to
encounter filenames which are essentially complete sentences, punctuation
included.

FWIW, I've found that a significant proportion of "why can't I burn this
file to a CD" queries are because the Joliet extension to ISO-9660 "only"
allows 64 characters in a filename.

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


Re: msg.attach multiple attachments and passing vars to html

2010-08-31 Thread MRAB

On 01/09/2010 00:24, aurfal...@gmail.com wrote:

Hi,

Few questions as I've been at this for dayz.

Can I do multiple attachments in order via msg.attach as so;

part1 = MIMEText(html, 'html')
msg.attach(part1)
part2 = MIMEText(text, 'plain')
msg.attach(part2)
part3 = MIMEText(html, 'html')
msg.attach(part3)

I desire to attach part1, part2 and part3 in that order.


This might help:

http://snippets.dzone.com/posts/show/2038


Also, is it somehow possible to pas python vars to html?

My goal to to have an email that says something like;

Welcome to ACME.

A few LINKS to get you started.

Your user name is USRNM and your password is PASS

Where USRNM and PASS are python vars but the rest is an html based email.

LINKS is an actual hyperlink, hence the desire to do html based emails.


Create a template HTML with placeholders and then the individual HTML
by replacing the placeholders with the values, something like:

template_html = "Your user name is %USRNM% and your password is 
%PASS%."

   ...
   user_html = template_html.replace("%USRNM%", 
username).replace("%PASS%", password)


That's the general idea.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Queue cleanup

2010-08-31 Thread Lawrence D'Oliveiro
In message <7xtymbzixt@ruckus.brouhaha.com>, Paul Rubin wrote:

> It's pretty well established by now that GC doesn't have any significant
> speed penalty compared with manual allocation.  It does consume more
> memory, which is acceptable a lot of the time.  It certainly leads to
> more reliable programs.

And yet Java code, for example, doesn’t have a reputation for greater 
reliability compared to, say code written in Ada or C++, or even C. What is 
the Java runtime written in? C. Why not use Java, if there is no speed 
penalty in doing so?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: msg.attach multiple attachments and passing vars to html

2010-08-31 Thread Chris Rebert
On Tue, Aug 31, 2010 at 5:44 PM, MRAB  wrote:
> On 01/09/2010 00:24, aurfal...@gmail.com wrote:

>> Also, is it somehow possible to pas python vars to html?
>>
>> My goal to to have an email that says something like;
>>
>> Welcome to ACME.
>> A few LINKS to get you started.
>> Your user name is USRNM and your password is PASS
>>
>> Where USRNM and PASS are python vars but the rest is an html based email.
>> LINKS is an actual hyperlink, hence the desire to do html based emails.
>>
> Create a template HTML with placeholders and then the individual HTML
> by replacing the placeholders with the values, something like:
>
>    template_html = "Your user name is %USRNM% and your password is %PASS%."
>   ...
>   user_html = template_html.replace("%USRNM%", username).replace("%PASS%",
> password)
>
> That's the general idea.

In the general case though, one needs to be sure to properly escape
the inserted text:

from cgi import escape
user_html = template_html.replace("%USRNM%",
escape(username)).replace("%PASS%", escape(password))

Also, string formatting would probably be safer than .replace() in the
unlikely but not impossible event that user input and the magic
placeholder names overlap.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ride tab editor 2.03 has been released

2010-08-31 Thread eric_dex...@msn.com
ride tab editor 2.03 has been  released.  ride tab editor features
customizable instruments and an editable tool menu (alpha help would
be nice).  also included are some scripts showing how you can use the
output files in csound.  The 2 series is an expansion of ride guitar
tab editor that managed to get over 2000 downloads.

http://dexrowem.blogspot.com/search?q=ride+tab+editor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Queue cleanup

2010-08-31 Thread Lawrence D'Oliveiro
In message <7x39tz42fd@ruckus.brouhaha.com>, Paul Rubin wrote:

> Dennis Lee Bieber  writes:
>
>> Heap marking, OTOH, tends to run at indeterminate times, which could
>> have an impact if one needs predictable response timings
> 
> Reference counting has the same problem.  If you drop the last reference
> to a complex structure, it could take quite a long time to free all the
> components.

One difference is the interaction with caching behaviour. When a reference-
counted object is freed, the odds are that happens fairly soon after the 
last access, so the object will still be in the CPU cache, and access will 
be fast.

Whereas garbage collection will happen at some indeterminate time long after 
the last access to the object, when it very likely will no longer be in the 
cache, and have to be brought back in just to be freed, quite likely bumping 
out something else that the running program needs to access.

This is one reason why garbage collection is still considered an expensive 
technique. Computing power has improved by something like five orders of 
magnitude over the last half-century, making possible all kinds of 
productivity-enhancing techniques that were once considered expensive to 
become commonplace: high-level languages, dynamic memory allocation, stacks, 
hardware floating-point, memory protection and so on.

But alone of all of these, garbage collection still remains just as costly 
to implement as ever. That should tell you something about how poorly it 
matches the characteristics of modern computing hardware.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Queue cleanup

2010-08-31 Thread Lawrence D'Oliveiro
In message <7xmxs4uzjl@ruckus.brouhaha.com>, Paul Rubin wrote:

> Gregory Ewing  writes:
>
>> I'd be disappointed if CPython ditched refcounting and
>> then became unsuitable for real-time games as a result.
> 
> Refcounting is susceptable to the same pauses for reasons already
> discussed.

Doesn’t seem to happen in the real world, though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimising literals away

2010-08-31 Thread Cameron Simpson
On 31Aug2010 23:38, MRAB  wrote:
| On 31/08/2010 23:11, Cameron Simpson wrote:
| >On 31Aug2010 22:53, MRAB  wrote:
| >| There's still the possibility of some optimisation. If the resulting
| >| set is never stored anywhere (bound to a name, for example) then it
| >| could be created once. When the expression is evaluated there could be
| >| a check so see whether 'set' is bound to the built-in class, and, if it
| >| is, then just use the pre-created set.
| >
| >Wouldn't you need to repeat that check every time, otherwise "set" may
| >no longer be the builtin?
| 
| Isn't that what I said?

Yes. It's not what my brain decided to read to me.

| My point is that if you have a set of constants which is created and
| then discarded you can cache it and reuse it next time. You check every
| time whether 'set' is bound to the set class.

Ok then. I was thinking, for some reason, a JIT-like behaviour that
didn't just reuse the previously made set but replaced the set([1,2,3])
itself, thus omitting the test you mentioned:-(

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

It's hard to make a man understand something when his livelihood depends
on him not understanding it. - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


comp.lang.python

2010-08-31 Thread roshini begum
www.127760.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Structured programming with optionParser

2010-08-31 Thread NickC
On Mon, 30 Aug 2010 21:19:08 -0700, Michele Simionato wrote:

> Perhaps, I should give an example of using plac.

> 
> For more (including managing options, which I have not shown here) you
> should check the full documentation of plac. I have just uploaded
> release 0.7.2, which is required for this example to work.

Many thanks, very useful.



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


Re: Dumb Stupid Question About List and String

2010-08-31 Thread Alban Nona
@MRAB, thank you, but what if there are like 40 entries like 'Elem00x' ? is
there a way to do it automaticaly ?

@Xavier: ShaDoW, WorldPositionPoint (which is the same thing as
WordPointCloud passe) :)

Anyway, thank you !

2010/8/31 Xavier Ho 

> On 1 September 2010 07:57, Alban Nona  wrote:
>
>> listPass = ["DIF","SPC", "RFL", "SSS", "REFR", "ALB", "AMB", "NRM", "MVE",
>> "DPF", "SDW", "MAT", "WPP"]
>>
>
> Out of curiosity, could you briefly mention what "SDW" and "WPP" passes
> are? I've worked out the rest, and these two are riddling my brain.
>
> (On topic: If you want only the elements starting with ELM001, or whatever,
> use a if condition like what MRAB posted.)
>
> Cheers,
> Xav
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb Stupid Question About List and String

2010-08-31 Thread MRAB

On 01/09/2010 03:00, Alban Nona wrote:

@MRAB, thank you, but what if there are like 40 entries like 'Elem00x' ?
is there a way to do it automaticaly ?


If you can do it for 'Elem001', I'm sure you could write some code to
produce a list of 'Elem001', 'Elem002', etc, and check whether any are
substrings, just as was done for 'Elem001'.


@Xavier: ShaDoW, WorldPositionPoint (which is the same thing as
WordPointCloud passe) :)

Anyway, thank you !


[snip]
Do you want separate lists for 'Elem001', 'Elem002', etc, or all in the
same list?
--
http://mail.python.org/mailman/listinfo/python-list


[Pickle]dirty problem 3 lines

2010-08-31 Thread bussiere bussiere
i know it's dirty, i know i should use json but i want to know, it's
quiet late here :
import pickle
dump = """b'\x80\x03]q\x00(K\x00K\x01e.'"""
print(pickle.loads(dump))

how can i get back my object from this string ?
the string is :  b'\x80\x03]q\x00(K\x00K\x01e.'
and i'am using python3
help will be appreciated i'am chewing on this for a long time now.
Regards
B.
fan of dresden files
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Pickle]dirty problem 3 lines

2010-08-31 Thread MRAB

On 01/09/2010 03:33, bussiere bussiere wrote:

i know it's dirty, i know i should use json but i want to know, it's
quiet late here :
import pickle
dump = """b'\x80\x03]q\x00(K\x00K\x01e.'"""
print(pickle.loads(dump))

how can i get back my object from this string ?
the string is :  b'\x80\x03]q\x00(K\x00K\x01e.'
and i'am using python3
help will be appreciated i'am chewing on this for a long time now.


Well, pickle.loads(b'\x80\x03]q\x00(K\x00K\x01e.') works.

That, of course, is not the same as """b'\x80\x03]q\x00(K\x00K\x01e.'""".

Do you mean r"""b'\x80\x03]q\x00(K\x00K\x01e.'"""?

(It's also late here, well, actually, so late it's early... Time to
sleep. :-))
--
http://mail.python.org/mailman/listinfo/python-list


Fwd: Dumb Stupid Question About List and String

2010-08-31 Thread Alban Nona
In fact, the First list (wich contain "Elm001, Elm002, Elm003) will be
generated automatically from files that I have in a directory, that's why I
cant write the same code for Elm002, 003, etc... Because Ill not know how
many Elm there will be.


2010/8/31 MRAB 

> On 01/09/2010 03:00, Alban Nona wrote:
>
>  @MRAB, thank you, but what if there are like 40 entries like 'Elem00x' ?
>> is there a way to do it automaticaly ?
>>
>>  If you can do it for 'Elem001', I'm sure you could write some code to
> produce a list of 'Elem001', 'Elem002', etc, and check whether any are
> substrings, just as was done for 'Elem001'.
>
>
>  @Xavier: ShaDoW, WorldPositionPoint (which is the same thing as
>> WordPointCloud passe) :)
>>
>> Anyway, thank you !
>>
>>  [snip]
> Do you want separate lists for 'Elem001', 'Elem002', etc, or all in the
> same list?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: triangle python user's group?

2010-08-31 Thread Tim Arnold
"Albert Hopkins"  wrote in message 
news:mailman.219.1283200967.29448.python-l...@python.org...
> On Mon, 2010-08-30 at 12:38 -0700, Tim Arnold wrote:
>> Hi,
>> Is there a python users group in the Research Triangle Park area
>> (North Carolina, USA)?
>
> Google "triangle python user's group"
>


thanks for the pointer
--Tim


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


Re: Source code for itertools

2010-08-31 Thread Tim Roberts
vsoler  wrote:

>On 31 ago, 04:42, Paul Rubin  wrote:
>> vsoler  writes:
>> > I was expecting an itertools.py file, but I don't see it in your list.
>> >> ./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c
>>
>> looks promising.  Lots of stdlib modules are written in C for speed or
>> access to system facilities.
>
>Lawrence, Paul,
>
>You seem to be running a utility I am not familiar with. Perhaps this
>is because I am using Windows, and most likely you are not.
>
>How could I have found the answer in a windows environment?

Did you take the time to understand what he did?  It's not that hard to
figure out.  He fetched the Python source code, unpacked it, then search
for filenames that contained the string "itertools."

The equivalent in Windows, after unpacking the source archive, would have
been:
dir /s *itertools*
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >