Re: searching and storing large quantities of xml!

2010-01-16 Thread Stefan Behnel
dads, 16.01.2010 19:10:
> I work in as 1st line support and python is one of my hobbies. We get
> quite a few requests for xml from our website and its a long strung
> out process. So I thought I'd try and create a system that deals with
> it for fun.
> 
> I've been tidying up the archived xml and have been thinking what's
> the best way to approach this issue as it took a long time to deal
> with big quantities of xml. If you have 5/6 years worth of 26000+
> 5-20k xml files per year. The archived stuff is zipped but what is
> better, 26000 files in one big zip file, 26000 files in one big zip
> file but in folders for months and days, or zip files in zip files!

As Paul suggested, that doesn't sound like a lot of data at all.

Personally, I guess I'd keep separate folders of .gz files, but that also
depends on platform characteristics (e.g. I/O performance and file system).
If you already have them archived in .zip files, that's fine also. Your
files are fairly small, so combined .zip archival will likely yield better
space efficiency.


> I created an app in wxpython to search the unzipped xml files by the
> modified date and just open them up and just using the something like
> l.find('>%s<' % fiveDigitNumber) != -1: is this quicker than parsing
> the xml?

Sounds like all you need is an index. Look at the various dbm database
modules that come with Python. They are basically persistent dictionaries.
To achieve the above, all you have to do is parse the XML files once (use
cElementTree's iterparse() for that, as Steve suggested) and store a path
(i.e. zip file name and archive entry name) for each 'modified date' that
you find in the file. When your app then needs to access data for a
specific modification date, you can look up the file path in the dbm and
parse it directly from the open zip file.

That's a simple solution, at least. Depending on your expected load and
additional feature set, e.g. full text indexing, a more complex database
setup (potentially even copying all data into the DB) may still be worth
going for.

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


Re: r"string" vs R"string

2010-01-16 Thread Terry Reedy

On 1/17/2010 1:55 AM, Brendan Miller wrote:

Is there any difference whatsoever between a raw string beginning with
the captical R or one with the lower case r e.g. r"string" vs
R"string"?


No. Nor is there and difference between the strings created with raw 
literals and cooked literals.



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


Re: r"string" vs R"string

2010-01-16 Thread Ben Finney
Brendan Miller  writes:

> Is there any difference whatsoever between a raw string beginning with
> the captical R or one with the lower case r e.g. r"string" vs
> R"string"?

For answering questions like this, the Python language reference is your
friend:

String literals may optionally be prefixed with a letter 'r' or 'R';
such strings are called raw strings and use different rules for
interpreting backslash escape sequences.


http://docs.python.org/reference/lexical_analysis.html#string-literals>.

No mention is made of any distinction made between ‘r’ or ‘R’ in this
context.

-- 
 \   “Give a man a fish, and you'll feed him for a day; give him a |
  `\religion, and he'll starve to death while praying for a fish.” |
_o__)   —Anonymous |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


r"string" vs R"string

2010-01-16 Thread Brendan Miller
Is there any difference whatsoever between a raw string beginning with
the captical R or one with the lower case r e.g. r"string" vs
R"string"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad

2010-01-16 Thread Ben Finney
Grant Edwards  writes:

> FF still works with a lot of things.  Most ASCII printers still
> honor it, as do pagers and programs like a2ps.  I still use it
> in ASCII text files...

Yes. It's especially useful for making large sectional structure in a
text file — for example, program source code — that can then be easily
navigated “by page” with a text editor like Emacs or Vim.

Since it's a standard white space character by definition, it can go
anywhere that white space can go; and yet it acts to signal structure
within the file.

-- 
 \  “There's a certain part of the contented majority who love |
  `\anybody who is worth a billion dollars.” —John Kenneth |
_o__)Galbraith, 1992-05-23 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad

2010-01-16 Thread Grant Edwards
On 2010-01-16, Nobody  wrote:
> On Fri, 15 Jan 2010 10:42:43 -0800, W. eWatson wrote:
>
>> I thought I'd put a page break, chr(12), character in a txt file I wrote 
>> to skip to the top of the page. It doesn't work. Comments?
>
> The 1970's are over, and neither Notepad nor your printer attempts to
> maintain compatibility with a Teletype model 37.

FF still works with a lot of things.  Most ASCII printers still
honor it, as do pagers and programs like a2ps.  I still use it
in ASCII text files...

-- 
Grant


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


Re: Is python not good enough?

2010-01-16 Thread Terry Reedy

On 1/16/2010 10:08 PM, David Cournapeau wrote:


Compilation with global type inference may be a good way to speed up
python, but it is not the only way. Your claim about lookups does seem
to contradict how the various efficient implementations of dynamic
languages work. For example, the V8 engine deal with dynamic
attributes without static analysis:

http://code.google.com/apis/v8/design.html


Reading that, I notice a couple of things.

1. Like Psycho, V8 trades space for time. Given that space is now 
expanding more than time is shrinking, this is more sensible in general 
than it was a decade ago. Given Javascript programs are usually small 
and work with small objects, this is even more sensible for Javascript 
than for some Python programs.


2. It compiles to object code rather than byte code. If the only target 
is standard 32/64 bit Intel/AMD processors, this is quite sensible. Does 
V8 have, for instance, Cray versions?


Guido wants the reference version to be runnable on everything with a C 
compiler and maintainable and upgradeable by volunteers who are not 
assembler experts (which I believe are getting more rare).


tjr

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


Re: Unicode and dictionaries

2010-01-16 Thread Carl Banks
On Jan 16, 7:06 pm, Ben Finney  wrote:
> Carl Banks  writes:
> > On Jan 16, 3:56 pm, Ben Finney  wrote:
> > > gizli  writes:
> > > > >>> test_dict = {u'öğe':1}
> > > > >>> u'öğe' in test_dict.keys()
> > > > True
> > > > >>> 'öğe' in test_dict.keys()
> > > > True
>
> > > I would call this a bug. The two objects are different, so the latter
> > > expression should return ‘False’.
>
> > Except the two objects are not different if default encoding is utf-8.
>
> They are different, because a Unicode object is *not* encoded in any
> character encoding, whereas the byte string object is.

Of course they're different, it's not relevant to this situation.
What matters is if they compare equal, which is the only criteria for
whether an object is found in a list.  x in s is true if there is some
object m in s for which m == x.

If the default encoding and the terminal encoding are both UTF-8 (or
both latin-9), then u'öğe' == 'öğe'.  This behavior is documented (PEP
100) and therefore not a bug.  Relevant lines:

"Unicode objects should compare equal to other objects after these
other objects have been coerced to Unicode.  For strings this means
that they are interpreted as Unicode string using the ."



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


Re: Is python not good enough?

2010-01-16 Thread Paul Rubin
David Cournapeau  writes:

> And certainly, one of the big reason for
> the python success is easy interface with C. Maybe interfacing with C
> is the real reason for holding back python implementations ?

The CPython/C API is not terrible but it's not all that easy to use.
For example, it's very easy to make reference counting errors.  Other
language FFI's that I've used avoid that problem to some extent.  It's
true that CPython has quite a few existing C modules that would require
rework if the API were to change incompatibly.  But I think a different
(better) API wouldn't stop people from writing new modules.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confusing, desparate MySQLdb problems...

2010-01-16 Thread Ned Deily
In article 
<5bc2641f-44fc-4324-b299-400ccbc79...@p8g2000yqb.googlegroups.com>,
 stopchuckingstuff  wrote:
[...]
> This just gets even more confusing!
> 
> I used a shebang line:
> 
> #!/Library/Frameworks/Python.framework/Versions/2.6/bin/python
> 
> which i got from which python in terminal, and now i get this error
> when trying to import MySQLdb:
> 
> : No module named pkg_resources
> 
> How!? I don't get that error when using that same version of python in
> IDLE...
> 
> What's going on?!

Sounds like setuptools is not being found on sys.path.  And, judging 
from your earlier post, it appears that sys.path when running under 
Apache includes /Library/WebServer/.python-eggs.  Perhaps you need to 
ensure setuptools is installed there.  That wouldn't normally be on the 
python's sys.path when running from the terminal.

But I realized after my last response that I should have asked how you 
were using Python with Apache: presumably with mod_wsgi or, possibly, 
mod_python.  In either case, the configurations are more complex and 
something I have little experience with so I should probably point you 
elsewhere.  For mod_wsgi, Graham Dumpleton offers exemplary thorough 
documentation here:

http://code.google.com/p/modwsgi/
http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX 
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp

Good luck.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Unicode and dictionaries

2010-01-16 Thread Ben Finney
Carl Banks  writes:

> On Jan 16, 3:56 pm, Ben Finney  wrote:
> > gizli  writes:
> > > >>> test_dict = {u'öğe':1}
> > > >>> u'öğe' in test_dict.keys()
> > > True
> > > >>> 'öğe' in test_dict.keys()
> > > True
> >
> > I would call this a bug. The two objects are different, so the latter
> > expression should return ‘False’.
>
> Except the two objects are not different if default encoding is utf-8.

They are different, because a Unicode object is *not* encoded in any
character encoding, whereas the byte string object is.

The source code shows a Unicode *literal* represented in some encoding;
but, just like the source code sequence ‘1.0’ results in an
floating-point object, the source code sequence ‘u'öğe'’ results in a
Unicode object. Neither the floating-point object nor the Unicode object
have a character encoding, even though their representations in source
code did have one.

The Effbot explains it http://effbot.org/zone/unicode-objects.htm>
in more detail.

-- 
 \   “[W]hoever is able to make you absurd is able to make you |
  `\unjust.” —Voltaire |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python not good enough?

2010-01-16 Thread David Cournapeau
On Sun, Jan 17, 2010 at 11:43 AM, John Nagle  wrote:
> David Cournapeau wrote:
>>
>> On Sun, Jan 17, 2010 at 4:17 AM, John Nagle  wrote:
>>>
>>> Nobody wrote:

 On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:

>   Actually, no.  It's quite possible to make a Python implementation
> that
> runs fast.  It's just that CPython, a naive interpreter, is too
> primitive
> to do it.  I was really hoping that Google would put somebody good at
> compilers in charge of Python and bring it up to production speed.
>
>   Look at Shed Skin, a hard-code compiler for Python

 A hard-code compiler for the subset of Python which can easily be
 compiled.

 Shed Skin has so many restrictions that it isn't really accurate to
 describe the language which it supports as "Python".

 Hardly any real-world Python code can be compiled with Shed Skin. Some
 of
 it could be changed without too much effort, although most of that is
 the
 kind of code which wouldn't look any different if it was implemented in
 C++ or Java.

 The monomorphism restriction is likely to be particularly onerous: the
 type of a variable must be known at compile time; instances of
 subclasses
 are allowed, but you can only call methods which are defined in the
 compile-time class.

 If you're writing code which makes extensive use of Python's dynamicity,
 making it work with Shed Skin would require as much effort as re-writing
 it in e.g. Java, and would largely defeat the point of using Python in
 the
 first place.

 http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html

 If you want a language to have comparable performance to C++ or Java,
 you
 have to allow some things to be fixed at compile-time. There's a reason
 why C++ and Java support both virtual and non-virtual ("final") methods.
>>>
>>>   My point is that Python is a good language held back by a bad
>>> implementation.  Python has gotten further with a declaration-free syntax
>>> than any other language.  BASIC and JavaScript started out
>>> declaration-free,
>>> and declarations had to be retrofitted.  Python has survived without
>>> them.
>>> (Yes, there are hokey extensions like Psyco declarations and
>>> "decorators",
>>> but both are marginal concepts.)
>>
>> There are efficient implementations of dynamic programming languages
>> which do not rely on declaration (if by declaration you mean typing
>> declaration), even when available:
>>
>> http://strongtalk.googlecode.com/svn/web%20site/history.html
>>
>> See also:
>>
>> http://www.avibryant.com/2008/05/those-who-misre.html
>
>   Yes, that's my point.

Compilation with global type inference may be a good way to speed up
python, but it is not the only way. Your claim about lookups does seem
to contradict how the various efficient implementations of dynamic
languages work. For example, the V8 engine deal with dynamic
attributes without static analysis:

http://code.google.com/apis/v8/design.html

So JIT may be limited, but I don't think it applies to the examples
you have given. Maybe static analysis ala stalin is needed for very
fast execution.

I don't claim any knowledge on those technologies, but my impression
is that other forces held back a fast python implementation, in
particular compatibility with C extensions. For example, I know no
fast implementation of dynamic languages which do not rely on garbage
collection: if this is indeed true, it may mean that retrofitting a gc
everywhere is needed, but doing so without breaking C extensions is
hard (if at all possible ?). And certainly, one of the big reason for
the python success is easy interface with C. Maybe interfacing with C
is the real reason for holding back python implementations ?

cheers,

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


Re: Confusing, desparate MySQLdb problems...

2010-01-16 Thread stopchuckingstuff
On Jan 17, 1:54 am, Ned Deily  wrote:
> In article
> <8647768b-944c-4025-8389-768a9cae5...@u41g2000yqe.googlegroups.com>,
>
>
>
>
>
>  stopchuckingstuff  wrote:
> > On Jan 17, 12:14 am, Ned Deily  wrote:
> > > In article
> > > <0ba7faf8-f816-4100-ba5b-b138d3008...@c3g2000yqd.googlegroups.com>,
> > >  stopchuckingstuff  wrote:
> > > > I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
> > > > running on my system in IDLE and in terminal, however encounter
> > > > continual problems when running it through Apache.
> > > > When trying to import the module, it gives me this error:
> > > > : /Library/WebServer/.python-eggs/
> > > > MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
> > > > appropriate 64-bit architecture (see "man python" for running in 32-
> > > > bit mode) [...]
> > > Most likely possibility: you've installed another Python on 10.6,
> > > probably from python.org, which only runs in 32-bit mode while Apache is
> > > using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
> > > mode. [...]
> > Thanks very much - I think this must be the problem (which python
> > produces some long path to Python 2.6). Ideally, I'd like to change
> > Apache's path to python as I had such problems installing MySQLdb -
> > would you have any idea how to do it?
> [...]
> > Sorry for the repeat posts, but would it be to do with the first line
> > of all my scripts - #!/usr/bin/env python?
>
> /usr/bin/env python will cause the first command named python in the
> process's execution path ($PATH) to be used.  Apache is probably not
> running under your user name and does not have the PATH modification in
> your .bash_profile to stick that long path to the python.org Python 2.6
> bin directory at the front of $PATH.   Rather than changing Apache's
> startup, the easier solution would probably be to modify your scripts to
> point at the desired python.  By default, the python.org installers put
> a link to that python in /usr/local/bin so it may be easier to use a
> shebang line like:
>
> #!/usr/local/bin/python
> or
> #!/usr/local/bin/python2.6
>
> --
>  Ned Deily,
>  n...@acm.org

What's even worse, is that importing pkg_resources works fine in
terminal, and the sys.paths in each are the same!?!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confusing, desparate MySQLdb problems...

2010-01-16 Thread stopchuckingstuff
On Jan 17, 1:54 am, Ned Deily  wrote:
> In article
> <8647768b-944c-4025-8389-768a9cae5...@u41g2000yqe.googlegroups.com>,
>
>
>
>
>
>  stopchuckingstuff  wrote:
> > On Jan 17, 12:14 am, Ned Deily  wrote:
> > > In article
> > > <0ba7faf8-f816-4100-ba5b-b138d3008...@c3g2000yqd.googlegroups.com>,
> > >  stopchuckingstuff  wrote:
> > > > I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
> > > > running on my system in IDLE and in terminal, however encounter
> > > > continual problems when running it through Apache.
> > > > When trying to import the module, it gives me this error:
> > > > : /Library/WebServer/.python-eggs/
> > > > MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
> > > > appropriate 64-bit architecture (see "man python" for running in 32-
> > > > bit mode) [...]
> > > Most likely possibility: you've installed another Python on 10.6,
> > > probably from python.org, which only runs in 32-bit mode while Apache is
> > > using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
> > > mode. [...]
> > Thanks very much - I think this must be the problem (which python
> > produces some long path to Python 2.6). Ideally, I'd like to change
> > Apache's path to python as I had such problems installing MySQLdb -
> > would you have any idea how to do it?
> [...]
> > Sorry for the repeat posts, but would it be to do with the first line
> > of all my scripts - #!/usr/bin/env python?
>
> /usr/bin/env python will cause the first command named python in the
> process's execution path ($PATH) to be used.  Apache is probably not
> running under your user name and does not have the PATH modification in
> your .bash_profile to stick that long path to the python.org Python 2.6
> bin directory at the front of $PATH.   Rather than changing Apache's
> startup, the easier solution would probably be to modify your scripts to
> point at the desired python.  By default, the python.org installers put
> a link to that python in /usr/local/bin so it may be easier to use a
> shebang line like:
>
> #!/usr/local/bin/python
> or
> #!/usr/local/bin/python2.6
>
> --
>  Ned Deily,
>  n...@acm.org

This just gets even more confusing!

I used a shebang line:

#!/Library/Frameworks/Python.framework/Versions/2.6/bin/python

which i got from which python in terminal, and now i get this error
when trying to import MySQLdb:

: No module named pkg_resources

How!? I don't get that error when using that same version of python in
IDLE...

What's going on?!

Many thanks for your ongoing assistance!
Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode and dictionaries

2010-01-16 Thread Carl Banks
On Jan 16, 5:38 pm, Carl Banks  wrote:
> On Jan 16, 3:58 pm, Steven D'Aprano  cybersource.com.au> wrote:
> > On Sat, 16 Jan 2010 15:35:05 -0800, gizli wrote:
> > > Hi all,
>
> > > I am using Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41). I ran
> > > into this issue yesterday and wanted  to check to see if this is a
> > > python bug. It seems that there is an inconsistency between lists and
> > > dictionaries in the way that unicode objects are handled. Take a look at
> > > the following example:
>
> >  test_dict = {u'öğe':1}
> >  u'öğe' in test_dict.keys()
> > > True
> >  'öğe' in test_dict.keys()
> > > True
>
> > I can't reproduce your result, at least not in 2.6.1:
>
> > >>> test_dict = {u'öğe':1}
> > >>> u'öğe' in test_dict.keys()
> > True
> > >>> 'öğe' in test_dict.keys()
>
> > __main__:1: UnicodeWarning: Unicode equal comparison failed to convert
> > both arguments to Unicode - interpreting them as being unequal
> > False
>
> The OP changed his default encoding.  I was able to confirm the
> behavior after setting the default encoding to latin-1.
>
> This is most definitely a bug in Python.

I've thought it over and I'm not so sure it's a bug now, but it is
highly questionable.  Here is more detailed explanation.  The
following script shows why; my terminal is UTF-8.


Python 2.5.4 (r254:67916, Nov 19 2009, 19:46:21)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> reload(sys) # get sys.setdefaultencoding back

>>> sys.setdefaultencoding('utf-8')
>>> u'öğe' == 'öğe'
True
>>> test_dict = {u'öğe':1}
>>> test_dict['öğe']
Traceback (most recent call last):
  File "", line 1, in 
KeyError: '\xc3\xb6\xc4\x9fe'


So the source encoding is UTF-8, and you see I've set the default
encoding to UTF-8.  You'll notice that u'öğe' and 'öğe' compare equal,
this is entirely correct.  Given that UTF-8 is the source encoding,
the string 'öğe' will be read as a byte-string with the UTF-8 encoding
of those Unicode characters.  And, given that UTF-8 is also the
default encoding, the string will be re-encoded using UTF-8, and so
will be equal to the Unicode stirng.

Given that the two are equal, the correct behavior for dicts would be
to use the two as the same key.  However, it doesn't.  In fact the two
objects don't even have the same hash code:

>>> hash(u'öğe')
1671320785
>>> hash('öğe')
-813744964

This ought to be a bug; objects that compare equal and are hashable
must have the same hash code.  However, given that it is crucially
important to be as fast as possible when calculating that hash code of
ASCII strings, I could imagine that this is deliberate.  (And if it is
it should be documented so; I looked briefly but did not see it.)

I can imagine another buggy possibility as well.  test_dict['öğe'] = 2
will add a new key to the above example, but it could overwrite the
key if there's a hash collision, because the objects compare equal.

All in all, it's a mighty mess.  The best advice is to avoid it
altogether and leave the default encoding alone.

Thankfully Python 3 does away with all this nonsense.


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


Re: BaseHTTPServer get_request not called till first request

2010-01-16 Thread yousay
On Jan 13, 1:38 am, Adam Tauno Williams 
wrote:
> Looking at  and
>  as examples I've attempted
> to create a BaseHTTPServer class that times-out accept() ever X seconds
> to check some other work.  This seems to work well, but only once the
> HTTPServer object has received its first request.  Up until the first
> request get_request() is not invoked and not timeout occurs.
>
> class HTTPServer(BaseHTTPServer.HTTPServer):
>
>     def server_bind(self):
>         BaseHTTPServer.HTTPServer.server_bind(self)
>         self.socket.settimeout(1)
>         self._shutdown = False
>
>     def get_request(self):
>         while not self._shutdown:
>             try:
>                 print ' HTTP worker {0} waiting.'.format(self.pid)
>                 self.log.debug('Waiting for connection...')
>                 s, a = self.socket.accept()
>                 s.settimeout(None)
>                 return (s, a)
>             except socket.timeout:
>                 /// do other work ///
>         return None, None
>
> The "HTTP worker" message is not seen until the server has taken a
> request, then it seems to dutifully do the timeout.
>
> --
> OpenGroupware developer: awill...@whitemice.org
> 
> OpenGroupare & Cyrus IMAPd documenation @
> 

your class Name is the same to the superClass,may be have influence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python not good enough?

2010-01-16 Thread John Nagle

David Cournapeau wrote:

On Sun, Jan 17, 2010 at 4:17 AM, John Nagle  wrote:

Nobody wrote:

On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:


   Actually, no.  It's quite possible to make a Python implementation
that
runs fast.  It's just that CPython, a naive interpreter, is too primitive
to do it.  I was really hoping that Google would put somebody good at
compilers in charge of Python and bring it up to production speed.

   Look at Shed Skin, a hard-code compiler for Python

A hard-code compiler for the subset of Python which can easily be
compiled.

Shed Skin has so many restrictions that it isn't really accurate to
describe the language which it supports as "Python".

Hardly any real-world Python code can be compiled with Shed Skin. Some of
it could be changed without too much effort, although most of that is the
kind of code which wouldn't look any different if it was implemented in
C++ or Java.

The monomorphism restriction is likely to be particularly onerous: the
type of a variable must be known at compile time; instances of subclasses
are allowed, but you can only call methods which are defined in the
compile-time class.

If you're writing code which makes extensive use of Python's dynamicity,
making it work with Shed Skin would require as much effort as re-writing
it in e.g. Java, and would largely defeat the point of using Python in the
first place.

http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html

If you want a language to have comparable performance to C++ or Java, you
have to allow some things to be fixed at compile-time. There's a reason
why C++ and Java support both virtual and non-virtual ("final") methods.

   My point is that Python is a good language held back by a bad
implementation.  Python has gotten further with a declaration-free syntax
than any other language.  BASIC and JavaScript started out declaration-free,
and declarations had to be retrofitted.  Python has survived without them.
(Yes, there are hokey extensions like Psyco declarations and "decorators",
but both are marginal concepts.)


There are efficient implementations of dynamic programming languages
which do not rely on declaration (if by declaration you mean typing
declaration), even when available:

http://strongtalk.googlecode.com/svn/web%20site/history.html

See also:

http://www.avibryant.com/2008/05/those-who-misre.html


   Yes, that's my point.

   Psyco was a good first step.  The big win with Psyco is that it
generally can recognize when a variable is an integer or floating
point number, and generate hard code for that.  It doesn't do much
for the rest of the language.  Psyco is really a kind of JIT compiler.
Those are useful, but in some ways limited.

   To go beyond that, global analysis is needed.  A big bottleneck
in Python is that too much time is spent doing dictionary lookups
for things that could be bound at compile time.  So the next big
win is figuring out which classes definitely don't have any hidden
dynamism.  A global check is needed to see if any external code
messes with the attributes of a class or its functions from outside
the function.  Most of the time, this is the case.  Once that's
been done, the class's module can be analyzed for optimization.

   If the class doesn't use "setattr", etc. to add attributes to
itself, then the class can be "slotted", with a C++ like structure for
the class members and functions.

   Global analysis also has to determine the class hierarchy; what inherits
from what.  It may be necessary to implement "object" as an abstract class
with a huge number of virtual functions, so that "duck typing" will work.
That's a space cost, but not a time cost.

   Caller/callee type inference is useful to determine the potential types
of parameters.  Often, analysis of all the calls to a function will determine
the types of many of the paraeters.  Then, those parameters can be hard-typed
at compile time.

   You can go this far without the restrictions Shed Skin imposes, such as
the restriction that lists must be homogeneous.   If you do impose that
restriction, array processing becomes much faster.  Type inference for
array elements is hard when arrays are computed from other arrays, so
that's a huge simplification.

   Yes, you can't use "eval" to get at existing variables. But in Python,
you don't really need to.

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


Re: Unicode and dictionaries

2010-01-16 Thread Carl Banks
On Jan 16, 3:56 pm, Ben Finney  wrote:
> gizli  writes:
> > >>> test_dict = {u'öğe':1}
> > >>> u'öğe' in test_dict.keys()
> > True
> > >>> 'öğe' in test_dict.keys()
> > True
>
> I would call this a bug. The two objects are different, so the latter
> expression should return ‘False’.

Except the two objects are not different if default encoding is utf-8.

(Whether it's a good idea to change the default encoding is another
question, but Python is clearly documented as behaving this way.  When
comparing a byte string and a Unicode string, the byte string will be
decoded according to the default encoding.)


> FYI, ‘foo in bar.keys()’ is easier to spell as ‘foo in bar’.

I believe the OP's point was to show that dicts behave differently
than lists here ("in" works for lists, doesn't work for dicts).


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


Re: Confusing, desparate MySQLdb problems...

2010-01-16 Thread Ned Deily
In article 
<8647768b-944c-4025-8389-768a9cae5...@u41g2000yqe.googlegroups.com>,
 stopchuckingstuff  wrote:
> On Jan 17, 12:14 am, Ned Deily  wrote:
> > In article
> > <0ba7faf8-f816-4100-ba5b-b138d3008...@c3g2000yqd.googlegroups.com>,
> >  stopchuckingstuff  wrote:
> > > I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
> > > running on my system in IDLE and in terminal, however encounter
> > > continual problems when running it through Apache.
> > > When trying to import the module, it gives me this error:
> > > : /Library/WebServer/.python-eggs/
> > > MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
> > > appropriate 64-bit architecture (see "man python" for running in 32-
> > > bit mode) [...]
> > Most likely possibility: you've installed another Python on 10.6,
> > probably from python.org, which only runs in 32-bit mode while Apache is
> > using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
> > mode. [...]
> Thanks very much - I think this must be the problem (which python
> produces some long path to Python 2.6). Ideally, I'd like to change
> Apache's path to python as I had such problems installing MySQLdb -
> would you have any idea how to do it?
[...]
> Sorry for the repeat posts, but would it be to do with the first line
> of all my scripts - #!/usr/bin/env python?

/usr/bin/env python will cause the first command named python in the 
process's execution path ($PATH) to be used.  Apache is probably not 
running under your user name and does not have the PATH modification in 
your .bash_profile to stick that long path to the python.org Python 2.6 
bin directory at the front of $PATH.   Rather than changing Apache's 
startup, the easier solution would probably be to modify your scripts to 
point at the desired python.  By default, the python.org installers put 
a link to that python in /usr/local/bin so it may be easier to use a 
shebang line like:

#!/usr/local/bin/python 
or
#!/usr/local/bin/python2.6

-- 
 Ned Deily,
 n...@acm.org

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


Re: Unicode and dictionaries

2010-01-16 Thread Carl Banks
On Jan 16, 3:58 pm, Steven D'Aprano  wrote:
> On Sat, 16 Jan 2010 15:35:05 -0800, gizli wrote:
> > Hi all,
>
> > I am using Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41). I ran
> > into this issue yesterday and wanted  to check to see if this is a
> > python bug. It seems that there is an inconsistency between lists and
> > dictionaries in the way that unicode objects are handled. Take a look at
> > the following example:
>
>  test_dict = {u'öğe':1}
>  u'öğe' in test_dict.keys()
> > True
>  'öğe' in test_dict.keys()
> > True
>
> I can't reproduce your result, at least not in 2.6.1:
>
> >>> test_dict = {u'öğe':1}
> >>> u'öğe' in test_dict.keys()
> True
> >>> 'öğe' in test_dict.keys()
>
> __main__:1: UnicodeWarning: Unicode equal comparison failed to convert
> both arguments to Unicode - interpreting them as being unequal
> False


The OP changed his default encoding.  I was able to confirm the
behavior after setting the default encoding to latin-1.

This is most definitely a bug in Python.


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


Re: dict's as dict's key.

2010-01-16 Thread Ethan Furman

Lie Ryan wrote:

On 01/14/10 05:33, Albert van der Horst wrote:


(I encountered this before. A dictionary is a natural for a
boardgame position, i.e. chess. Now we want to look up chess
positions.)



or use collections.namedtuple


Which is great until you want to make a move.  ;)

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


Re: Confusing, desparate MySQLdb problems...

2010-01-16 Thread stopchuckingstuff
On Jan 17, 12:14 am, Ned Deily  wrote:
> In article
> <0ba7faf8-f816-4100-ba5b-b138d3008...@c3g2000yqd.googlegroups.com>,
>
>
>
>
>
>  stopchuckingstuff  wrote:
> > I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
> > running on my system in IDLE and in terminal, however encounter
> > continual problems when running it through Apache.
>
> > When trying to import the module, it gives me this error:
>
> > : /Library/WebServer/.python-eggs/
> > MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
> > appropriate 64-bit architecture (see "man python" for running in 32-
> > bit mode)
>
> > Which I  just don't understand, as it works perfectly in IDLE?!
>
> > I am running Snow Leopard in 64bit mode, but I don't see how this
> > could be the problem when I have already run the module successfully.
>
> Most likely possibility: you've installed another Python on 10.6,
> probably from python.org, which only runs in 32-bit mode while Apache is
> using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
> mode.  From the terminal, do:
>
> which python
>
> If it's not /usr/bin/python, you're using another Python in the
> terminal.  You'll need to install a 64-bit version of the MySQLdb and
> the MySQL client libraries for the Apple-supplied Python or modify the
> Apache setup to either force 32-bit mode for the Apple-supplied Python
> or use the other Python (from /usr/local/bin/python2.6 or wherever).
>
> --
>  Ned Deily,
>  ...@acm.org

Sorry for the repeat posts, but would it be to do with the first line
of all my scripts - #!/usr/bin/env python?

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


Re: Confusing, desparate MySQLdb problems...

2010-01-16 Thread stopchuckingstuff
On Jan 17, 12:14 am, Ned Deily  wrote:
> In article
> <0ba7faf8-f816-4100-ba5b-b138d3008...@c3g2000yqd.googlegroups.com>,
>
>
>
>
>
>  stopchuckingstuff  wrote:
> > I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
> > running on my system in IDLE and in terminal, however encounter
> > continual problems when running it through Apache.
>
> > When trying to import the module, it gives me this error:
>
> > : /Library/WebServer/.python-eggs/
> > MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
> > appropriate 64-bit architecture (see "man python" for running in 32-
> > bit mode)
>
> > Which I  just don't understand, as it works perfectly in IDLE?!
>
> > I am running Snow Leopard in 64bit mode, but I don't see how this
> > could be the problem when I have already run the module successfully.
>
> Most likely possibility: you've installed another Python on 10.6,
> probably from python.org, which only runs in 32-bit mode while Apache is
> using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
> mode.  From the terminal, do:
>
> which python
>
> If it's not /usr/bin/python, you're using another Python in the
> terminal.  You'll need to install a 64-bit version of the MySQLdb and
> the MySQL client libraries for the Apple-supplied Python or modify the
> Apache setup to either force 32-bit mode for the Apple-supplied Python
> or use the other Python (from /usr/local/bin/python2.6 or wherever).
>
> --
>  Ned Deily,
>  ...@acm.org

Thanks very much - I think this must be the problem (which python
produces some long path to Python 2.6). Ideally, I'd like to change
Apache's path to python as I had such problems installing MySQLdb -
would you have any idea how to do it?

Thanks again for you help
Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: searching and storing large quantities of xml!

2010-01-16 Thread Paul Rubin
dads  writes:
> I've been tidying up the archived xml and have been thinking what's
> the best way to approach this issue as it took a long time to deal
> with big quantities of xml. If you have 5/6 years worth of 26000+
> 5-20k xml files per year. The archived stuff is zipped but what is
> better, 26000 files in one big zip file, 26000 files in one big zip
> file but in folders for months and days, or zip files in zip files!

If I'm reading that properly, you have 5-6 years worth of files, 26000
files per year, 5-20k bytes per file?  At 10k bytes/file that's about
1.3GB which isn't all that much data by today's standards.

> Generally the requests are less than 3 months old so that got me into
> thinking should I create a script that finds all the file names and
> corresponding web number of old xml and bungs them into a db table one
> for each year and another script that after everyday archives the xml
> and after 3months zip it up, bungs info into table etc. Sorry for the
> ramble I just want other peoples opinions on the matter. =)

Extract all the files and put them into some kind of indexed database or
search engine.  I've used solr (http://lucene.apache.org/solr) for this
purpose and while it has limitations, it's fairly easy to set up and use
for basic purposes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python not good enough?

2010-01-16 Thread David Cournapeau
On Sun, Jan 17, 2010 at 4:17 AM, John Nagle  wrote:
> Nobody wrote:
>>
>> On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:
>>
>>>    Actually, no.  It's quite possible to make a Python implementation
>>> that
>>> runs fast.  It's just that CPython, a naive interpreter, is too primitive
>>> to do it.  I was really hoping that Google would put somebody good at
>>> compilers in charge of Python and bring it up to production speed.
>>>
>>>    Look at Shed Skin, a hard-code compiler for Python
>>
>> A hard-code compiler for the subset of Python which can easily be
>> compiled.
>>
>> Shed Skin has so many restrictions that it isn't really accurate to
>> describe the language which it supports as "Python".
>>
>> Hardly any real-world Python code can be compiled with Shed Skin. Some of
>> it could be changed without too much effort, although most of that is the
>> kind of code which wouldn't look any different if it was implemented in
>> C++ or Java.
>>
>> The monomorphism restriction is likely to be particularly onerous: the
>> type of a variable must be known at compile time; instances of subclasses
>> are allowed, but you can only call methods which are defined in the
>> compile-time class.
>>
>> If you're writing code which makes extensive use of Python's dynamicity,
>> making it work with Shed Skin would require as much effort as re-writing
>> it in e.g. Java, and would largely defeat the point of using Python in the
>> first place.
>>
>> http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html
>>
>> If you want a language to have comparable performance to C++ or Java, you
>> have to allow some things to be fixed at compile-time. There's a reason
>> why C++ and Java support both virtual and non-virtual ("final") methods.
>
>    My point is that Python is a good language held back by a bad
> implementation.  Python has gotten further with a declaration-free syntax
> than any other language.  BASIC and JavaScript started out declaration-free,
> and declarations had to be retrofitted.  Python has survived without them.
> (Yes, there are hokey extensions like Psyco declarations and "decorators",
> but both are marginal concepts.)

There are efficient implementations of dynamic programming languages
which do not rely on declaration (if by declaration you mean typing
declaration), even when available:

http://strongtalk.googlecode.com/svn/web%20site/history.html

See also:

http://www.avibryant.com/2008/05/those-who-misre.html

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


Re: Confusing, desparate MySQLdb problems...

2010-01-16 Thread Ned Deily
In article 
<0ba7faf8-f816-4100-ba5b-b138d3008...@c3g2000yqd.googlegroups.com>,
 stopchuckingstuff  wrote:

> I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
> running on my system in IDLE and in terminal, however encounter
> continual problems when running it through Apache.
> 
> When trying to import the module, it gives me this error:
> 
> : /Library/WebServer/.python-eggs/
> MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
> appropriate 64-bit architecture (see "man python" for running in 32-
> bit mode)
> 
> Which I  just don't understand, as it works perfectly in IDLE?!
> 
> I am running Snow Leopard in 64bit mode, but I don't see how this
> could be the problem when I have already run the module successfully.

Most likely possibility: you've installed another Python on 10.6, 
probably from python.org, which only runs in 32-bit mode while Apache is 
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit 
mode.  From the terminal, do:

which python

If it's not /usr/bin/python, you're using another Python in the 
terminal.  You'll need to install a 64-bit version of the MySQLdb and 
the MySQL client libraries for the Apple-supplied Python or modify the 
Apache setup to either force 32-bit mode for the Apple-supplied Python 
or use the other Python (from /usr/local/bin/python2.6 or wherever).

-- 
 Ned Deily,
 n...@acm.org

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


Re: chr(12) Form Feed in Notepad

2010-01-16 Thread bartc


"Steve Holden"  wrote in message 
news:mailman.1007.1263682208.28905.python-l...@python.org...

bartc wrote:


"Nobody"  wrote in message
news:pan.2010.01.16.04.24.18.437...@nowhere.com...

On Fri, 15 Jan 2010 10:42:43 -0800, W. eWatson wrote:

I thought I'd put a page break, chr(12), character in a txt file I 
wrote

to skip to the top of the page. It doesn't work. Comments?


The 1970's are over, and neither Notepad nor your printer attempts to
maintain compatibility with a Teletype model 37.


Odd that TXT files under Windows still use the same 13 (carriage
return), 10 (linefeed) and 9 (tab) codes that used to work on my ASR 33.
So why not code 12 (formfeed)?


Because the KSR/ASR33 devices were designed for continuous output in
things like torn-tape and torn-paper messaging systems (where I believe
Cable and Wireless made a lot of  money once upon a time). There was no
point paginating the copy, and to do so would have been wasteful.


My point was these other control codes from over 30 years ago are still in 
use today, so why not also make use of chr(12)?


--
Bartc 


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


Re: Unicode and dictionaries

2010-01-16 Thread Steven D'Aprano
On Sat, 16 Jan 2010 15:35:05 -0800, gizli wrote:

> Hi all,
> 
> I am using Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41). I ran
> into this issue yesterday and wanted  to check to see if this is a
> python bug. It seems that there is an inconsistency between lists and
> dictionaries in the way that unicode objects are handled. Take a look at
> the following example:
> 
 test_dict = {u'öğe':1}
 u'öğe' in test_dict.keys()
> True
 'öğe' in test_dict.keys()
> True


I can't reproduce your result, at least not in 2.6.1:

>>> test_dict = {u'öğe':1}
>>> u'öğe' in test_dict.keys()
True
>>> 'öğe' in test_dict.keys()
__main__:1: UnicodeWarning: Unicode equal comparison failed to convert 
both arguments to Unicode - interpreting them as being unequal
False



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


Re: A simple-to-use sound file writer

2010-01-16 Thread Alf P. Steinbach

* Steve Holden:

Alf P. Steinbach wrote:

* Steve Holden:

Alf P. Steinbach wrote:

* Grant Edwards:

On 2010-01-15, Steve Holden  wrote:


I will, however, observe that your definition of a square wave is
what I
would have to call a "'square' wave" (and would prefer to call a
"pulse
train"), as I envisage a square wave as a waveform having a 50% duty
cycle, as in

 ___ ___
|   |   |   |
|   |   |   |
|   |   |   |
+---+---+---+---+ and so on ad infinitum, (though I might allow you
|   |   |   |  to adjust the position
|   |   |   |  of y=0 if you want)
|___|   |___|

That is a square wave.


as opposed to your

 _
| |
| |
  __| |__   __
 | |
 | |
 |_|

That isn't.

Arguing to the contrary is just being Humpty Dumpty...

Neither I nor Steve has called that latter wave a square wave.

Steve, quoted above, has written that I defined a square wave that way.
I have not. So Steve's statement is a misrepresentation (I described it
as a sum of two square waves, which it is), whatever the reason for that
misrepresentation.





[snip]

So here you have an interesting example of a
piece of code that is pathological in Python2. All you have to change is
to add

  from __future__ import __division__

and bingo! It's a multi-language program. But try seeing what 2to3 says
about your Python3 code :)

I will forgive you the omission of the ".0" because I too would assume
that it would be slower.


I did not make any such assumption, no. The *1 just lingered from some testing.


[snip]

and so on, but I still get silence from the Quicktime player.


I don't know, sorry.

It might be that [simple_sound] also needs the "from __future__" treatment.

But anyway, with 2.x compatible code you can now see that the sample values 
produced are correct (just print them, or graph them).



Cheers & hth.,

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


Re: remote evaluation of Python code typed in html webpage frame

2010-01-16 Thread André
On Jan 15, 11:47 am, dmitrey  wrote:
> Thank you for the link, but I meant what is appropriate soft to be
> installed on my server to do things like that.
> Also, for my purposes it's better to have some text with possibility
> of reexecuting after some minor code changes than python interpreter
> command prompt.
> Regards, D.
>

You could install crunchy (http://code.google.com/p/crunchy) on your
server and embed an editor in a page that is displayed.

If you have Python code executed on your server ... it is a huge
security risk, but it's your choice.  For your purpose, you likely
would have to disable the authentication feature of Crunchy.

André

> On 15 янв, 16:41, "Diez B. Roggisch"  wrote:
>
> > Am 15.01.10 15:16, schrieb dmitrey:
>
> > > hi all,
> > > what's the simplest way to create a webpage with a frame for Python
> > > code to be typed in (as a plain text, or, better, as a highlighted
> > > text or something like scite or any other easy python IDE, capable of
> > > automatic indentations), and then pressing a button to evaluate it
> > > using a remote server?
>
> > > Thank you in advance, D.
>
> >http://try-python.mired.org/
>
> > Diez
>
>

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


Unicode and dictionaries

2010-01-16 Thread gizli
Hi all,

I am using Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41). I
ran into this issue yesterday and wanted  to check to see if this is a
python bug. It seems that there is an inconsistency between lists and
dictionaries in the way that unicode objects are handled. Take a look
at the following example:

>>> test_dict = {u'öğe':1}
>>> u'öğe' in test_dict.keys()
True
>>> 'öğe' in test_dict.keys()
True
>>> test_dict[u'öğe']
1
>>> test_dict['öğe']
Traceback (most recent call last):
  File "", line 1, in 
KeyError: '\xc3\xb6\xc4\x9fe'
>>>

Is this a bug? has_key functionality of the dictionary works as
expected:

>>> test_dict.has_key(u'öğe')
True
>>> test_dict.has_key('öğe')
False
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Alf P. Steinbach

* Gertjan Klein:

Alf P. Steinbach wrote:


* Gertjan Klein:

Alf P. Steinbach wrote:

Thinking about it some more, perhaps that way I can't get at return
codes a python script might provide. I haven't used those, but they may
be useful at some point.

Return codes work OK no matter what.


Ok, I won't have to worry about that then. ;-)

But it's a hassle for the user to connect up standard input, standard output and 
standard error for a GUI subsystem process.


Good point. Two executables it is. But out of curiousity, what happens
when a user pipes something into a GUI subsystem executable?


The same as with a console program, I guess.

Indeed piping is one way to connect up the output.

Disclaimer: I can't recall ever actually trying to pipe input to a GUI subsystem 
exe. However, piping output, while not common, at least I've done that! :-)



Perhaps do this in JScript or VBScript (languages bundled with Windows)? There 
may be less startup overhead than with Python. But I haven't checked.


Won't these create a DOS window, always?


No. They're run via the Windows Script Host interface. WSH has two runner 
programs: cscript (console) and wscript (GUI). So you get a console window (it's 
tehnically not DOS although the icon was MS-DOS until and including Windows NT 
4.0) if you run a [.js] or [.vbs] file via cscript, and not via wscript.


wscript is the default.

But you can change that association, or create new associations, via the Windows 
'assoc' and 'ftype' commands (note that after some XP update 'ftype' is no 
longer able to delete associations, it must then be done directly in registry).




Or can they run windowless as well?


Yes, see above.



If so, that might be an option worth exploring as well.




Cheers & hth.,

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


Re: searching and storing large quantities of xml!

2010-01-16 Thread Steve Holden
dads wrote:
> I work in as 1st line support and python is one of my hobbies. We get
> quite a few requests for xml from our website and its a long strung
> out process. So I thought I'd try and create a system that deals with
> it for fun.
> 
> I've been tidying up the archived xml and have been thinking what's
> the best way to approach this issue as it took a long time to deal
> with big quantities of xml. If you have 5/6 years worth of 26000+
> 5-20k xml files per year. The archived stuff is zipped but what is
> better, 26000 files in one big zip file, 26000 files in one big zip
> file but in folders for months and days, or zip files in zip files!
> 
> I created an app in wxpython to search the unzipped xml files by the
> modified date and just open them up and just using the something like
> l.find('>%s<' % fiveDigitNumber) != -1: is this quicker than parsing
> the xml?
> 
> Generally the requests are less than 3 months old so that got me into
> thinking should I create a script that finds all the file names and
> corresponding web number of old xml and bungs them into a db table one
> for each year and another script that after everyday archives the xml
> and after 3months zip it up, bungs info into table etc. Sorry for the
> ramble I just want other peoples opinions on the matter. =)

The first question I'd ask is what library you are using for the XML
processing. If you aren't using cElementTree it would definitely be
worth checking to see if it improves your processing speed. You can test
with ElementTree if you want, but cElementTree is an extension module,
and therefore much faster.

Fredrik Lundh wrote it so it's pretty solid stuff (he was one of the
minds behind the RE engine).

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python not good enough?

2010-01-16 Thread Steve Holden
John Nagle wrote:
> Nobody wrote:
>> On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:
>>
>>> Actually, no.  It's quite possible to make a Python
>>> implementation that
>>> runs fast.  It's just that CPython, a naive interpreter, is too
>>> primitive
>>> to do it.  I was really hoping that Google would put somebody good at
>>> compilers in charge of Python and bring it up to production speed.
>>>
>>> Look at Shed Skin, a hard-code compiler for Python
>>
>> A hard-code compiler for the subset of Python which can easily be
>> compiled.
>>
>> Shed Skin has so many restrictions that it isn't really accurate to
>> describe the language which it supports as "Python".
>>
>> Hardly any real-world Python code can be compiled with Shed Skin. Some of
>> it could be changed without too much effort, although most of that is the
>> kind of code which wouldn't look any different if it was implemented in
>> C++ or Java.
>>
>> The monomorphism restriction is likely to be particularly onerous: the
>> type of a variable must be known at compile time; instances of subclasses
>> are allowed, but you can only call methods which are defined in the
>> compile-time class.
>>
>> If you're writing code which makes extensive use of Python's dynamicity,
>> making it work with Shed Skin would require as much effort as re-writing
>> it in e.g. Java, and would largely defeat the point of using Python in
>> the
>> first place.
>>
>> http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html
>>
>> If you want a language to have comparable performance to C++ or Java, you
>> have to allow some things to be fixed at compile-time. There's a reason
>> why C++ and Java support both virtual and non-virtual ("final") methods.
> 
> My point is that Python is a good language held back by a bad
> implementation.  Python has gotten further with a declaration-free syntax
> than any other language.  BASIC and JavaScript started out
> declaration-free,
> and declarations had to be retrofitted.  Python has survived without them.
> (Yes, there are hokey extensions like Psyco declarations and "decorators",
> but both are marginal concepts.)
> 
> The key to hard-compiling Python is that you have to compile the
> whole program, not individual modules.  You can't tell how an individual
> module will be used until you've seen its callers.  If the compiler
> looks at the whole program at once, type inference has a good chance of
> disambiguating most type issues.
> 
> If you can see the whole program at once, most dynamism can be
> detected.
> What's really needed is to detect the most common case, where objects don't
> have unexpected dynamism and can be implemented as hard structures.
> 
> John Nagle
> 
Of course, Guido has left the path to declarations open through the use
of function argument annotation. If you wanted to write programs that
reasoned about Python programs to optimize them, annotations could come
in very useful.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: A simple-to-use sound file writer

2010-01-16 Thread Steve Holden
Alf P. Steinbach wrote:
> * Steve Holden:
>> Alf P. Steinbach wrote:
>>> * Grant Edwards:
 On 2010-01-15, Steve Holden  wrote:

> I will, however, observe that your definition of a square wave is
> what I
> would have to call a "'square' wave" (and would prefer to call a
> "pulse
> train"), as I envisage a square wave as a waveform having a 50% duty
> cycle, as in
>
>  ___ ___
> |   |   |   |
> |   |   |   |
> |   |   |   |
> +---+---+---+---+ and so on ad infinitum, (though I might allow you
> |   |   |   |  to adjust the position
> |   |   |   |  of y=0 if you want)
> |___|   |___|
 That is a square wave.

> as opposed to your
>
>  _
> | |
> | |
>   __| |__   __
>  | |
>  | |
>  |_|
 That isn't.

 Arguing to the contrary is just being Humpty Dumpty...
>>> Neither I nor Steve has called that latter wave a square wave.
>>>
>>> Steve, quoted above, has written that I defined a square wave that way.
>>> I have not. So Steve's statement is a misrepresentation (I described it
>>> as a sum of two square waves, which it is), whatever the reason for that
>>> misrepresentation.
>>>
>>>
> Or, best of all, you could show me how to synthesize any
> waveform by adding square waves with a 50% duty cycle.  Then I
> *will* be impressed.
 Isn't that what he claimed?  He said that his algorithm for
 summing square waves demonstrated the converse of the ability
 to construct a periodic function (like a square wave) from a
 sine-cosine summation.
>>> Not by itself, no: it just synthesizes a sine.
>>>
>>> For the more general case read e.g. the PS in my reply to your earlier
>>> (single) article in this thread.
>>>
>>> For information about what the algorithm does, what you refer to as a
>>> "claim" (but note that a Python implementation has been posted to this
>>> thread, and that it works, and that besides the algorithm is trivial so
>>> that "claim" is a rather meaningless word here), read the article that
>>> you then responded to.
>>>
>> Though for what it's worth I wasn't impressed by the results of running
>> the posted program, since it yielded an AIFF file of mostly zeroes that
>> produced no audible sound.
>>
>> $ od -bc sinewave.aiff
>> 000 106 117 122 115 000 002 261 076 101 111 106 106 103 117 115 115
>>   F   O   R   M  \0 002 261   >   A   I   F   F   C   O   M   M
>> 020 000 000 000 022 000 001 000 001 130 210 000 020 100 016 254 104
>>  \0  \0  \0 022  \0 001  \0 001   X 210  \0 020   @ 016 254   D
>> 040 000 000 000 000 000 000 123 123 116 104 000 002 261 030 000 000
>>  \0  \0  \0  \0  \0  \0   S   S   N   D  \0 002 261 030  \0  \0
>> 060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
>>  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
>> *
>> 0530500 000 000 000 000 000 000
>>  \0  \0  \0  \0  \0  \0
>> 0530506
>>
>> Any idea what I did wrong?
> 
> That sounds like something I did wrong, not like something you did wrong:
> 
> It sounds like a  ...  BUG!  ... in my simple_writer code. :-)
> 
> Or, that's perhaps not funny, but it occurred to me that it might, to
> some at least, appear to be sort of incongruous in the context of the
> earlier thread. Heh.
> 
> Checking first 20 sample values generated:
> 
> 
> if True:
> f   = 440
> sample_rate = 44100
> total_time  = 2
> n_samples   = sample_rate*total_time
> 
> writer = simple_sound.Writer( "sinewave.aiff" )
> for i in range( n_samples ):
> t = 1*i/sample_rate
> sample = sample_squares( f, t )
> if i < 20: print( sample )# Check 'em
> writer.write( sample )
> writer.close()
> 
> 
> 
> -0.0314107590781
> -0.0314107590781
> -0.0941083133185
> -0.15643446504
> -0.218143241397
> -0.278991106039
> -0.338737920245
> -0.397147890635
> -0.45399049974
> -0.50904141575
> -0.562083377852
> -0.612907053653
> -0.661311865324
> -0.707106781187
> -0.75011106963
> -0.790155012376
> -0.827080574275
> -0.860742027004
> -0.891006524188
> -0.917754625684
> 
> 
> Checking generated file:
> 
> 
> $ od -bc sinewave.aiff | head
> 000 106 117 122 115 000 001 130 266 101 111 106 106 103 117 115 115
>   F   O   R   M  \0 001   X 266   A   I   F   F   C   O   M   M
> 020 000 000 000 022 000 001 000 000 254 104 000 020 100 016 254 104
>  \0  \0  \0 022  \0 001  \0  \0 254   D  \0 020   @ 016 254   D
> 040 000 000 000 000 000 000 123 123 116 104 000 001 130 220 000 000
>  \0  \0  \0  \0  \0  \0   S   S   N   D  \0 001   X 220  \0  \0
> 060 000 000 000 000 000 000 373 373 373 373 363 364 353 372 344 024
>  \0  \0  \0  \0  \0  \0 373 373 373 373 363 364 353 372 344 024
> 1

Re: chr(12) Form Feed in Notepad

2010-01-16 Thread Steve Holden
bartc wrote:
> 
> "Nobody"  wrote in message
> news:pan.2010.01.16.04.24.18.437...@nowhere.com...
>> On Fri, 15 Jan 2010 10:42:43 -0800, W. eWatson wrote:
>>
>>> I thought I'd put a page break, chr(12), character in a txt file I wrote
>>> to skip to the top of the page. It doesn't work. Comments?
>>
>> The 1970's are over, and neither Notepad nor your printer attempts to
>> maintain compatibility with a Teletype model 37.
> 
> Odd that TXT files under Windows still use the same 13 (carriage
> return), 10 (linefeed) and 9 (tab) codes that used to work on my ASR 33.
> So why not code 12 (formfeed)?
> 
Because the KSR/ASR33 devices were designed for continuous output in
things like torn-tape and torn-paper messaging systems (where I believe
Cable and Wireless made a lot of  money once upon a time). There was no
point paginating the copy, and to do so would have been wasteful. An
operator would just hit CRLF a few times (in fact a good operator would
only return the carriage once at the start, and then just hit the
requisite number of line feeds.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-16 Thread Steve Holden
Lie Ryan wrote:
> On 01/17/10 02:37, W. eWatson wrote:
>> D'Arcy J.M. Cain wrote:
>>> On Fri, 15 Jan 2010 20:17:35 -0800
>>> "W. eWatson"  wrote:
 Could be, but I have no way of easily knowing. In any case, I was
 trying to write a simple report that could be printed with titles at
 the top of each page. If there's another "common" format that I can
 write in to produce the file, that's fine. It may be this is so
 difficult to be impossible. Long, long ago this was no problem. :-)
>>> Why not generate a PostScript or PDF file in the first place?  Check
>>> out reportlab.
>>>
>> New Courier and NotePad produces a good looking result.
>>
>> I'm trying to keep this effort to a minimum. I don't think tracking down
>> how to write PP code PDF code is worth for this effort.
> 
> How about creating a new print job for each discontinuous page? AFAIK,
> modern printer spooler don't continue printing between separate jobs? A
> bit of hackery, but guaranteed to work unless you're using roll paper.
> 
Or unless you are printing to a production mailing system, and don't
want job headers printed or interspersed jobs.

>> In another related effort that I might get involved in, it would be good
>> to be able to produce graphical data as from MatPlotLib and be able to
>> print that to a printer directly from a Python program.
> 
A client of mine just built a web site where output from queries could
be HTML, PDF (Piza and ReportLab) or CSV (just written out). It's not
that hard (though the code isn't open sourced I may be able to get them
to document an outline of the process, or let me (in my copious spare time).

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-16 Thread Tim Chase

John Yeung wrote:

In another response, Tim Chase suggested creating an RTF file instead
of plain text.  I think this is your best bet if your goal is to get
page breaks with the least amount of additional effort.

The package he's probably referring to is PyRTF.  I took a quick look
at it and in my opinion it's overkill for your purposes.


Yes, John is correct -- it was PyRTF that I tinkered with (which 
can be overkill if all you want to do is what John describes). 
I'm not well versed in RTF, and he demonstrates:



I am too lazy to have actually read any documentation on RTF, but it's
freely available on the Web should you need to reference i


even in his laziness, he helpfully provided a quick guide on how 
to hand-create simple documents without the addition of a 
full-blown RTF toolkit like PyRTF.


-tkc


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


Confusing, desparate MySQLdb problems...

2010-01-16 Thread stopchuckingstuff
I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
running on my system in IDLE and in terminal, however encounter
continual problems when running it through Apache.

When trying to import the module, it gives me this error:

: /Library/WebServer/.python-eggs/
MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
appropriate 64-bit architecture (see "man python" for running in 32-
bit mode)

Which I  just don't understand, as it works perfectly in IDLE?!

I am running Snow Leopard in 64bit mode, but I don't see how this
could be the problem when I have already run the module successfully.

Please help!

Thanks very much,
Sam
stopchuckingst...@me.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Duncan Booth
Mike  wrote:

>> That seems overkill. This does pretty much the same thing:
>>
>>         @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF
>>         import sys
>>         print sys.version
>>         # raise RuntimeError # uncomment to trigger the 'pause'
>>
> 
> Indeed! Must be as close to a "Windows shebang line" as you can get.
> 
> In actual use, if/when I want a pause, I typically make a call
> raw_input() or msvcrt.getch()

Right, but that doesn't help if you have an uncaught exception. Personally 
I run scripts from a command window so I don't care whether they pause or 
not, but since your example had a pause I thought I'd throw one in too.

> 
>> EOF is a special label which may be used to exist a CMD file without
>> having to explicitly define it.
> 
> Did not know that; something new for my toolbox!
> 
s/exist/exit/

There's a surprising amount you can do in a windows cmd or bat file, it's 
just that the syntax is so archane.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad

2010-01-16 Thread bartc


"Nobody"  wrote in message 
news:pan.2010.01.16.04.24.18.437...@nowhere.com...

On Fri, 15 Jan 2010 10:42:43 -0800, W. eWatson wrote:


I thought I'd put a page break, chr(12), character in a txt file I wrote
to skip to the top of the page. It doesn't work. Comments?


The 1970's are over, and neither Notepad nor your printer attempts to
maintain compatibility with a Teletype model 37.


Odd that TXT files under Windows still use the same 13 (carriage return), 10 
(linefeed) and 9 (tab) codes that used to work on my ASR 33. So why not code 
12 (formfeed)?


--
Bartc 


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


Re: Long integers and ways around xrange

2010-01-16 Thread Martin Manns
On 16 Jan 2010 20:25:44 GMT
Steven D'Aprano  wrote:

> On Sat, 16 Jan 2010 20:04:09 +0100, Martin Manns wrote:
> >> islice(count(start, step), (stop-start+step-1)//step).
> > 
> > However, count only accepts one parameter, so that this solution
> > does not work. Furthermore, islice only accepts positive values for
> > step.
> 
> This should be reported as a documentation bug.

I added a bug report [issue7721].

Thanks for the code review.

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


Re: I really need webbrowser.open('file://') to open a web browser

2010-01-16 Thread Paul Boddie
On 15 Jan, 21:14, Timur Tabi  wrote:
> After reading several web pages and mailing list threads, I've learned
> that the webbrowser module does not really support opening local
> files, even if I use a file:// URL designator.  In most cases,
> webbrowser.open() will indeed open the default web browser, but with
> Python 2.6 on my Fedora 10 system, it opens a text editor instead.  On
> Python 2.5, it opens the default web browser.

The webbrowser module seems to have changed. For example, in the
Python 2.5 standard library, it uses gconftool to query the GNOME
registry and get the preferred browser, whereas in the Python 2.6
standard library, it appears to use gnome-open instead (but only in a
GNOME environment). For KDE, there's a KDE-specific usage of kfmclient
in the 2.6 library. See here for more:

http://svn.python.org/view/python/tags/r254/Lib/webbrowser.py?revision=67917&view=markup
http://svn.python.org/view/python/tags/r264/Lib/webbrowser.py?revision=75707&view=markup

> This is a problem because my Python script creates a local HTML file
> and I want it displayed on the web browser.

Generally, the desktop-specific tools should know that a browser is
the appropriate application for an HTML file, and testing with both
xdg-open, gnome-open and "kfmclient openURL" seems to open browsers on
HTML files (using file:///...) for me (using KDE, Kubuntu 8.04). Of
course, this depends on the settings in use on your desktop, but it
should be noted that using "kfmclient exec" could have the effect you
describe.

> So is there any way to force webbrowser.open() to always use an actual
> web browser?

Not that I'm aware of. Sadly, standardisation of applications and
services - having a command which can open a particular class of
application (such as "e-mail reader", "Web browser") - seems to be
absent from the free desktop arena, although I do recall there being a
preferred applications dialogue in KDE, at least. Maybe this
information is exposed somehow, and maybe I'll incorporate such stuff
into the desktop package eventually:

http://pypi.python.org/pypi/desktop

Note that the desktop package concerns itself precisely with opening
files in text editors if that's how the user has configured their
desktop, whereas the webbrowser module should really only use a Web
browser, obviously.

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


Re: Long integers and ways around xrange

2010-01-16 Thread Steven D'Aprano
On Sat, 16 Jan 2010 20:04:09 +0100, Martin Manns wrote:

> Hi
> 
> As stated in the manual, xrange raises an OverflowError for long integer
> parameters. Looking for a xrange like generator for long integers, I
> found this in the manual
> (http://docs.python.org/library/functions.html):
> 
>> CPython implementation detail: xrange() is intended to be simple and
>> fast. Implementations may impose restrictions to achieve this. The C
>> implementation of Python restricts all arguments to native C longs
>> (“short” Python integers), and also requires that the number of
>> elements fit in a native C long. If a larger range is needed, an
>> alternate version can be crafted using the itertools module:
>> islice(count(start, step), (stop-start+step-1)//step).
> 
> However, count only accepts one parameter, so that this solution does
> not work. Furthermore, islice only accepts positive values for step.

This should be reported as a documentation bug.



> I came up with a solution that I have pasted below.
> 
> Is there a standard long integer replacement for xrange? 

Not really. There are many ways of implementing it, and it really depends 
on what you care most about: speed, memory consumption, simplicity, 
economy of code, or something else. Chances are that only memory 
consumption is critical for any real application.

This is probably the simplest you can get:

def myxrange(start, end, step):
n = start
while n < end:
yield n
n += step

Adding error checking, useful defaults, and support for negative step 
values is left as a exercise *wink*


> Do you have ideas for improving the code?

Only quibbles.

E.g. you set the module encoding to utf-8, but don't use any non-ASCII 
characters.

In the lambda in scount, you use x for an argument which is an int not a 
float. I would use i rather than x to make that clear.

As I said, quibbles.



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


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Mike
> That seems overkill. This does pretty much the same thing:
>
>         @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF
>         import sys
>         print sys.version
>         # raise RuntimeError # uncomment to trigger the 'pause'
>

Indeed! Must be as close to a "Windows shebang line" as you can get.

In actual use, if/when I want a pause, I typically make a call
raw_input() or msvcrt.getch()

> EOF is a special label which may be used to exist a CMD file without having
> to explicitly define it.

Did not know that; something new for my toolbox!

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-16 Thread John Yeung
On Jan 15, 7:40 pm, "W. eWatson"  wrote:
> I am writing a txt file. It's up to the user to print
> it using Notepad or some other tool.

In another response, Tim Chase suggested creating an RTF file instead
of plain text.  I think this is your best bet if your goal is to get
page breaks with the least amount of additional effort.

The package he's probably referring to is PyRTF.  I took a quick look
at it and in my opinion it's overkill for your purposes.  Since RTF is
actually just a markup language, and the only features of it that you
absolutely need are (1) a way to ensure a fixed-width font is used and
(2) a way to insert page breaks, it's probably quickest and simplest
to just throw the markup into the document yourself (well, with
Python) and naming the result with the .rtf suffix instead of .txt.

So, how do you find out what markup to use?  Open WordPad, select the
font you want, type a bit of text, save the file as RTF (this should
be the default), and open up the file in Notepad.  At the top will be
a bunch of setup codes, including the font selection.  Make your
Python program put that whole spiel (including a trailing space or
newline, to separate your text from the last RTF tag) at the top of
your output.  There will be one unmatched curly brace, which you
should close at the end of the document.  On my computer, it looks
like this:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fmodern
\fprq1\fcharset0 Courier New;}}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\f0\fs20

That takes care of the font (and other stuff, but you are interested
in the font).  The only other things you need to do are put
r'\par' (the end-paragraph tag) at the end of each line and r'\page'
at the end of each page.  Again, remember to make sure these tags
don't collide with your actual text.  (I'd use '\\par\n' in place of
'\n' and '\\page\n' in place of chr(12).)  Finally, make sure to end
with a closing curly brace as previously mentioned.

The RTF solution is probably more robust than embedding chr(12) and
telling the user to use WordPad, especially since I saw someone report
on another forum that chr(12) doesn't always work even in WordPad (it
might be dependent on the version of WordPad, or the printer, or
whatever).

I am too lazy to have actually read any documentation on RTF, but it's
freely available on the Web should you need to reference it.

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


Long integers and ways around xrange

2010-01-16 Thread Martin Manns
Hi

As stated in the manual, xrange raises an OverflowError for 
long integer parameters. Looking for a xrange like generator 
for long integers, I found this in the manual 
(http://docs.python.org/library/functions.html):

> CPython implementation detail: xrange() is intended to be simple and
> fast. Implementations may impose restrictions to achieve this. The C
> implementation of Python restricts all arguments to native C longs
> (“short” Python integers), and also requires that the number of
> elements fit in a native C long. If a larger range is needed, an
> alternate version can be crafted using the itertools module:
> islice(count(start, step), (stop-start+step-1)//step).

However, count only accepts one parameter, so that this solution does
not work. Furthermore, islice only accepts positive values for step.

I came up with a solution that I have pasted below. 

Is there a standard long integer replacement for xrange? 
Do you have ideas for improving the code?

Best Regards

Martin


File irange.py:


#! /usr/bin/env python
# -*- coding: utf-8 -*-

from itertools import count, imap, islice

def scount(n=0, step=1):
"""Count that supports a step attribute"""

return imap(lambda x: x * step + n, count())

def irange(start, stop=None, step=1):
"""Range for long integers

Usage: irange([start], stop, [step])

Parameters
--
start: Integer, defaults to 0
stop: Integer
step: Integer, defaults to 1

Note on long integers
-

Each of the three parameters can be long integers.
If stop < start: start(stop-start+step-1) // step) must be a short integer.
If stop > start: start(stop-start+step+1) // step) must be a short integer.

"""

if start is None:
raise TypeError, "range() integer argument expected, got NoneType"

if stop is None:
stop = start
start = 0

if step is None:
step = 1

if step > 0:
if stop < start:
return (_ for _ in [])
return islice(scount(start, step), (stop-start+step-1) // step)

elif step < 0:
if stop > start:
return (_ for _ in [])
return islice(scount(start, step), (stop-start+step+1) // step)

else:
raise ValueError, "irange() step argument must not be zero"






File test_irange.py


#! /usr/bin/env python
# -*- coding: utf-8 -*-

from irange import scount, irange 

# Unit test for irange.py (py.test)

class TestIrange(object):
'Unit test for MainGridBase'
__module__ = __name__

def setup_method(self, method):
pass

def test_irange(self):
test_values = [ \
 [2],
 [1],
 [-23],
 (0, 1), 
 (0, 2),
 (0, 1),
 (1, 2),
 (100, 1000),
 (4, 0),
 (4, -1),
 (2**65-512, 2**65),
 (-1, 1),
 (-100, 0),
 (0, 1, 1),
 (0, 2, 1),
 (0, 10, 1),
 (0, 100, 1),
 (0, -1, 1),
 (0, 2, 2),
 (0, 10, 3),
 (0, 100, 4),
 (0, 1000, 60),
 (0, 2**65, 2**60),
 (1, 0, -1),
 (10, 0, -1),
 (12312, 0, -1),
 (2**65, 0, -2**61),
 (1, 0, -2),
 (10, 0, -3),
 (12312, 0, -4),
 (2**65, 0, -2**60),
 (2**67, 0, -2**67+1000),
 (-10, 2, 1),
 (-2, 10, 1),
 (3, 100, 1),
 (1000-1000, 1000, 1),
 (2**65, 2**66, 2**63),
 (-120, 2**65, 2**63),
 (1, -2334234, -1),
 (1, 10, 100),
 (10, 1, 100),
 (1, 10, -100),
 (1, 2, 2**65),
 (1, -2, 2**65),
]

for val in test_values:
assert list(irange(*val)) == range(*val)

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


Re: Is python not good enough?

2010-01-16 Thread John Nagle

Nobody wrote:

On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:


Actually, no.  It's quite possible to make a Python implementation that
runs fast.  It's just that CPython, a naive interpreter, is too primitive
to do it.  I was really hoping that Google would put somebody good at
compilers in charge of Python and bring it up to production speed.

Look at Shed Skin, a hard-code compiler for Python


A hard-code compiler for the subset of Python which can easily be compiled.

Shed Skin has so many restrictions that it isn't really accurate to
describe the language which it supports as "Python".

Hardly any real-world Python code can be compiled with Shed Skin. Some of
it could be changed without too much effort, although most of that is the
kind of code which wouldn't look any different if it was implemented in
C++ or Java.

The monomorphism restriction is likely to be particularly onerous: the
type of a variable must be known at compile time; instances of subclasses
are allowed, but you can only call methods which are defined in the
compile-time class.

If you're writing code which makes extensive use of Python's dynamicity,
making it work with Shed Skin would require as much effort as re-writing
it in e.g. Java, and would largely defeat the point of using Python in the
first place.

http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html

If you want a language to have comparable performance to C++ or Java, you
have to allow some things to be fixed at compile-time. There's a reason
why C++ and Java support both virtual and non-virtual ("final") methods.


My point is that Python is a good language held back by a bad
implementation.  Python has gotten further with a declaration-free syntax
than any other language.  BASIC and JavaScript started out declaration-free,
and declarations had to be retrofitted.  Python has survived without them.
(Yes, there are hokey extensions like Psyco declarations and "decorators",
but both are marginal concepts.)

The key to hard-compiling Python is that you have to compile the
whole program, not individual modules.  You can't tell how an individual
module will be used until you've seen its callers.  If the compiler
looks at the whole program at once, type inference has a good chance of
disambiguating most type issues.

If you can see the whole program at once, most dynamism can be detected.
What's really needed is to detect the most common case, where objects don't
have unexpected dynamism and can be implemented as hard structures.

John Nagle

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


Re: Inheriting methods but over-riding docstrings

2010-01-16 Thread Gerard Flanagan

Steven D'Aprano wrote:
I have a series of subclasses that inherit methods from a base class, but 
I'd like them to have their own individual docstrings. The obvious 
solution (other than copy-and-paste) is this:



class Base(object):
colour = "Blue"
def parrot(self):
"""docstring for Base"""
return "Norwegian %s" % self.colour


class SubClass(Base):
colour = "Red"
def parrot(self):
"""docstring for Subclass"""
return super(Subclass, self).parrot()


but that adds an awful lot of boilerplate to my subclasses. Are there any 
other good solutions to this problem?






If I've understood, one idea is:

--
def type_factory(colour):

class Base(object):

def parrot(self):
"""Norwegian %s"""
return 1
parrot.__doc__ %= colour

return Base

class Base(object):

def __new__(cls, *args, **kw):
return type_factory(cls.colour)(*args, **kw)


class A(Base):
colour = "Blue"

class B(Base):
colour = "Red"

a = A()
b = B()

print inspect.getdoc(a.parrot)
Norwegian Blue
print inspect.getdoc(b.parrot)
Norwegian Red
--

In the more general case, (ie. where you don't know that there is a 
method called parrot and an attribute called colour), I imagine you 
could do the same thing but at the metaclass level.


HTH

G.F.

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


searching and storing large quantities of xml!

2010-01-16 Thread dads
I work in as 1st line support and python is one of my hobbies. We get
quite a few requests for xml from our website and its a long strung
out process. So I thought I'd try and create a system that deals with
it for fun.

I've been tidying up the archived xml and have been thinking what's
the best way to approach this issue as it took a long time to deal
with big quantities of xml. If you have 5/6 years worth of 26000+
5-20k xml files per year. The archived stuff is zipped but what is
better, 26000 files in one big zip file, 26000 files in one big zip
file but in folders for months and days, or zip files in zip files!

I created an app in wxpython to search the unzipped xml files by the
modified date and just open them up and just using the something like
l.find('>%s<' % fiveDigitNumber) != -1: is this quicker than parsing
the xml?

Generally the requests are less than 3 months old so that got me into
thinking should I create a script that finds all the file names and
corresponding web number of old xml and bungs them into a db table one
for each year and another script that after everyday archives the xml
and after 3months zip it up, bungs info into table etc. Sorry for the
ramble I just want other peoples opinions on the matter. =)
-- 
http://mail.python.org/mailman/listinfo/python-list


Inheriting methods but over-riding docstrings

2010-01-16 Thread Steven D'Aprano
I have a series of subclasses that inherit methods from a base class, but 
I'd like them to have their own individual docstrings. The obvious 
solution (other than copy-and-paste) is this:


class Base(object):
colour = "Blue"
def parrot(self):
"""docstring for Base"""
return "Norwegian %s" % self.colour


class SubClass(Base):
colour = "Red"
def parrot(self):
"""docstring for Subclass"""
return super(Subclass, self).parrot()


but that adds an awful lot of boilerplate to my subclasses. Are there any 
other good solutions to this problem?



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


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Duncan Booth
Mike  wrote:

> t does not; Windows associates applications with file extensions.
> However, I have used something like this to get something like the
> Unix shebang behavior:
> 
> @echo off
> rem = """ ver26.bat: Python 2.6
> C:\Python26\python -x %~f0 %*
> goto END
> rem """
> # ver26.py wrapped in ver26.bat to mimic Unix #! behavior
> 
> import sys
> print sys.version
> 
> rem = """
>:END
> pause
> rem """
> 

That seems overkill. This does pretty much the same thing:

@(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF
import sys
print sys.version
# raise RuntimeError # uncomment to trigger the 'pause'

EOF is a special label which may be used to exist a CMD file without having 
to explicitly define it. As I wrote it above the pause is executed only if 
the script exists with a non-zero status.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Mike
> On unix you would start the file with a "hashbang" e.g.
>
> #!/usr/bin/python3
>
> Fraid I don't know if that works on XP though.
>
> Roger.

It does not; Windows associates applications with file extensions.
However, I have used something like this to get something like the
Unix shebang behavior:

@echo off
rem = """ ver26.bat: Python 2.6
C:\Python26\python -x %~f0 %*
goto END
rem """
# ver26.py wrapped in ver26.bat to mimic Unix #! behavior

import sys
print sys.version

rem = """
:END
pause
rem """

@echo off
rem = """ ver31.bat: Python 3.1
D:\Python31\python -x %~f0 %*
goto END
rem """
# ver31.py wrapped in ver31.bat to mimic Unix #! behavior

import sys
print(sys.version)

rem = """
:END
pause
rem """

I cannot remember where I first saw this, and don't think I have ever
seen it since.  It seems like a bit of a hack, but I use it from time
to time when I cannot rely on Windows file associations. Perl has
a much cleaner way to accomplish the same thing for Windows (see the
pl2bat.bat script that ships with
Perl Windows distributions).

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


Re: I really need webbrowser.open('file://') to open a web browser

2010-01-16 Thread Jon Clements
On Jan 16, 5:08 pm, Jonathan Temple  wrote:
> On Jan 15, 8:14 pm, Timur Tabi  wrote:
>
>
>
> > After reading several web pages and mailing list threads, I've learned
> > that the webbrowser module does not really support opening local
> > files, even if I use a file:// URL designator.  In most cases,
> > webbrowser.open() will indeed open the default web browser, but with
> > Python 2.6 on my Fedora 10 system, it opens a text editor instead.  On
> > Python 2.5, it opens the default web browser.
>
> > This is a problem because my Python script creates a local HTML file
> > and I want it displayed on the web browser.
>
> > So is there any way to force webbrowser.open() to always use an actual
> > web browser?
>
> > --
> > Timur Tabi
> > Linux kernel developer at Freescale
>
> Might not be useful, but trying open_new_tab() on...
>
> Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
> [GCC 4.3.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import webbrowser as wb
> >>> x = wb.get()
> >>> x.basename
>
> 'gnome-open'
>
> When attempting to use open_new_tab(), I get:
>
> file:///home/jon/blahblah.html - opens in Firefox
> file:///home/jon/blahblah.txt  - opens in gedit
>
> Jon.

Err, I'd just like to mention that "Jonathan Temple" did not post that
message: He was checking his Google Mail on my machine, and when I
went to send my post, it got a little confused.

Cheers,

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


Re: I really need webbrowser.open('file://') to open a web browser

2010-01-16 Thread Jonathan Temple
On Jan 15, 8:14 pm, Timur Tabi  wrote:
> After reading several web pages and mailing list threads, I've learned
> that the webbrowser module does not really support opening local
> files, even if I use a file:// URL designator.  In most cases,
> webbrowser.open() will indeed open the default web browser, but with
> Python 2.6 on my Fedora 10 system, it opens a text editor instead.  On
> Python 2.5, it opens the default web browser.
>
> This is a problem because my Python script creates a local HTML file
> and I want it displayed on the web browser.
>
> So is there any way to force webbrowser.open() to always use an actual
> web browser?
>
> --
> Timur Tabi
> Linux kernel developer at Freescale

Might not be useful, but trying open_new_tab() on...

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser as wb
>>> x = wb.get()
>>> x.basename
'gnome-open'

When attempting to use open_new_tab(), I get:

file:///home/jon/blahblah.html - opens in Firefox
file:///home/jon/blahblah.txt  - opens in gedit

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


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Gertjan Klein
Alf P. Steinbach wrote:

>* Gertjan Klein:
>> Alf P. Steinbach wrote:
>> 
>> Thinking about it some more, perhaps that way I can't get at return
>> codes a python script might provide. I haven't used those, but they may
>> be useful at some point.
>
>Return codes work OK no matter what.

Ok, I won't have to worry about that then. ;-)

>But it's a hassle for the user to connect up standard input, standard output 
>and 
>standard error for a GUI subsystem process.

Good point. Two executables it is. But out of curiousity, what happens
when a user pipes something into a GUI subsystem executable?

>Perhaps do this in JScript or VBScript (languages bundled with Windows)? There 
>may be less startup overhead than with Python. But I haven't checked.

Won't these create a DOS window, always? Or can they run windowless as
well? If so, that might be an option worth exploring as well.

Gertjan.

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


Re: remote evaluation of Python code typed in html webpage frame

2010-01-16 Thread r0g
Anand Vaidya wrote:
> On Jan 16, 12:26 am, r0g  wrote:
 Diez
>> The Web2py framework works a bit like that, although it's not quite as
>> simplistic as what you describe. May be worth a look though.
>>
>> Roger.
> 
> 
> Hi r0g,
> 
> web2py is a web-app framework (very similar to django, pylons etc) and
> it does not execute user form-submitted python code. It executes
> applications written and stored on the server-side only.
> 
> You are probably referring to some other project???
> 
> Regards
> Anand


Actually no I AM referring to web2py, the framework. I count it as
relevant because it has a web interface with built in code editor. That
would allow to OP to create a server where permitted users could enter
code which is then executed on that server, which is what he asked for.
Clearly there's much more to web2py than the above but in lieu of more
information from the OP it's a fair answer.

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-16 Thread Lie Ryan
On 01/17/10 02:37, W. eWatson wrote:
> D'Arcy J.M. Cain wrote:
>> On Fri, 15 Jan 2010 20:17:35 -0800
>> "W. eWatson"  wrote:
>>> Could be, but I have no way of easily knowing. In any case, I was
>>> trying to write a simple report that could be printed with titles at
>>> the top of each page. If there's another "common" format that I can
>>> write in to produce the file, that's fine. It may be this is so
>>> difficult to be impossible. Long, long ago this was no problem. :-)
>>
>> Why not generate a PostScript or PDF file in the first place?  Check
>> out reportlab.
>>
> 
> New Courier and NotePad produces a good looking result.
> 
> I'm trying to keep this effort to a minimum. I don't think tracking down
> how to write PP code PDF code is worth for this effort.

How about creating a new print job for each discontinuous page? AFAIK,
modern printer spooler don't continue printing between separate jobs? A
bit of hackery, but guaranteed to work unless you're using roll paper.

> In another related effort that I might get involved in, it would be good
> to be able to produce graphical data as from MatPlotLib and be able to
> print that to a printer directly from a Python program.

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-16 Thread Tim Chase

W. eWatson wrote:

I am writing a txt file. It's up to the user to print it using
Notepad or some other tool.  I have no idea how to send it
directly to the printer, but I really don't want to furnish
that capability in the program. From Google, The Graphics
Device Interface (GDI).


If you're writing it to a text file and assuming that Notepad is 
smart enough to properly handle form-feeds, I'm sorry, you'll be 
disappointed...this says more about the brain-deadness of Notepad 
than your optimism :-)


If you have a configurable destination, you might be able to do 
something within your Python app like


  if 'win' in sys.platform.lower():
default_dest = "lpt1:"
  else:
default_dest = "/dev/lp0"
  dest = config.get("printer", default_dest)
  f = file(dest, 'wb')
  f.write(my_output_with_ff)
  # optionally
  # f.write(chr(12))
  # to eject the last page
  f.close()

Otherwise, you'd have to write to something a default Windows 
application would know how to handle with embedded 
form-feeds/page-breaks (i.e., not Notepad as the default .txt 
handler).  My first thought would be to export it as RTF (there 
was a good python RTF library I tinkered with one afternoon -- 
it's a quick google away) which should allow embedding 
page-breaks, and even give you a fair bit of additional control 
over other aspects like fonts and styles.


-tkc


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


Re: Is it possible to print different levels to different streams using the logging module?

2010-01-16 Thread Peter Otten
Dotan Barak wrote:

> Hi.
> 
> I would like to use the logging module and print the following levels to
> the mentioned streams:
> 
> CRITICAL-> stderr
> ERROR -> stderr
> WARNING   -> stderr
> INFO -> stdout
> DEBUG -> stdout
> 
> I would like that every message will be printed only once, and for the
> stream that i choose.
> (I failed to find a "maximum level" for the handlers in the logging
> module).

I believe you have to write a custom filter:

import logging
import sys

from logging import NOTSET

class LevelFilter:
def __init__(self, min=NOTSET, max=NOTSET):
self.min = min
self.max = max
def filter(self, record):
if self.min != NOTSET and record.levelno < self.min:
return False
if self.max != NOTSET and record.levelno > self.max:
return False
return True

out = logging.StreamHandler(sys.stdout)
format_out = logging.Formatter("[via stdout] %(levelname)s: %(message)s")
out.setFormatter(format_out)
out.addFilter(LevelFilter(max=logging.INFO))

err = logging.StreamHandler(sys.stderr)
format_err = logging.Formatter("[via stderr] %(levelname)s: %(message)s")
err.setFormatter(format_err)
err.setLevel(logging.WARNING)

logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(out)
logger.addHandler(err)

logger.info("foo")
logger.warn("bar")

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-16 Thread W. eWatson

D'Arcy J.M. Cain wrote:

On Fri, 15 Jan 2010 20:17:35 -0800
"W. eWatson"  wrote:
Could be, but I have no way of easily knowing. In any case, I was trying 
to write a simple report that could be printed with titles at the top of 
each page. If there's another "common" format that I can write in to 
produce the file, that's fine. It may be this is so difficult to be 
impossible. Long, long ago this was no problem. :-)


Why not generate a PostScript or PDF file in the first place?  Check
out reportlab.



New Courier and NotePad produces a good looking result.

I'm trying to keep this effort to a minimum. I don't think tracking down 
how to write PP code PDF code is worth for this effort.


In another related effort that I might get involved in, it would be good 
to be able to produce graphical data as from MatPlotLib and be able to 
print that to a printer directly from a Python program.

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


Re: Using invalid.com email addresses

2010-01-16 Thread D'Arcy J.M. Cain
On Fri, 15 Jan 2010 23:04:57 -0800
Stephen Hansen  wrote:
> It may or may not be in violation of the RFCs, but the modern reality of the
> internet makes certain "rules" of the RFC's meaningless.

They aren't meaningless.  They also aren't "rules", a term that I did
not use.  The Internet is an anarchy that works on voluntary
cooperation.  The RFCs are simply a codification of best practices.  If
someone doesn't want to be part of the community they should simply
leave.  It's not like anyone is forcing them to participate.

> Spam is a major issue for some people; and some people do not want their
> email address to be trivially harvested, and usenet exposes that address

So non-trivial harvesting is OK?  If you are on the Net you will be
found.  If this is a real problem for you (generic "you", not Stephen)
then get a throwaway account and hide behind it.

Spam is an issue but it is pretty easy to deal with on the personal
level.  Between RBLs, Spamassassin and Bayesian filtering I hardly ever
see a spam these days.

> very easy. You will frequently see people mutate their address, sometimes
> they'll do so in such a way that if you look at it you'll know that if you
> remove parts you will get a real address-- these people allow for personal

Slightly better than using @invalid.com but these people aren't hiding
very well.  Spammers probably get most of those already.  All they do
is make it inconvenient for legitimate correspondents.

> direct communication. Others don't really want to receive any email at all
> based on their newsgroup posting, and want all of your messages to go to the
> group instead-- they generally provide an email address which is utterly
> meaningless.

Or worse as is the case with @invalid.com.

> It may or may not violate certain RFC's, but there's nothing rude about it.
> Its people trying to engage a community and yet hold some measure of control
> over how they engage that community. They have every right, IMHO, regardless
> of what an RFC may say.

That's right.  And I have every right to filter out those people who
don't want to be part of the community that I want to be part of.

> People who may use an invalid.com address simply don't want to be contacted
> individually and directly. Why is that rude? They post to a public forum,

They asked a question and directed answers to someone who was not
involved in the conversation.  How is that not rude.  It caused an
email to be sent to a domain that was not involved in the
conversation, required them to process the message, send back a
response (because they do follow the RFCs) require my system to
process the bounce and finally for me to deal with the message
telling me that the address I thought that I was sending to doesn't
exist.  Convenient for the person asking the question, inconvenient
for everyone else.  

> and they simply want to communicate solely in that public forum. They have

Then they should use a forum, not Usenet or a mailing list.

> no moral obligation to provide a means for personal or direct communication,
> in my mind at least. To me, demanding a real address from people in the
> usenet medium which has nothing even vaguely like privacy protection is

I won't even get into my opinions on gatewaying between Usenet groups
and mailing lists.  :-)

> rude. If someone chooses to provide it, great. If not, just as fine. One is
> obligated only to share with us what they wish, and all power to them in
> whatever capacity they wish to share.

And I have no obligation to share with anyone who doesn't want to
follow the RFCs.  That's why I blacklisted @invalid.com.  My choice.

That's the last on this subject from me here since it is off topic.  If
you want to discuss privately you better have a real address.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing var names

2010-01-16 Thread Victor Subervi
On Fri, Jan 15, 2010 at 3:47 PM, Phlip  wrote:

> Victor Subervi wrote:
>
> > Should I re-write it in classes before testing units? Right now it's
> > very monolithic.
>
> The "Unit" in unit tests is a misnomer. It refers to an old QA concept, for
> high-end projects, that the failure of any test should implicate only one
> unit.
>
> We only need "developer tests". They help, when we change the code, to
> avoid excessive debugging. And to test a given method you must be able to
> access it, so tests force your code to be decoupled. But a test may call as
> many functions as it needs, regardless what "unit" they live in.
>
> If you don't have tests yet, then sometimes a rewrite is indicated (and
> sometimes it's very easy and will produce _very_ clear code!). But in most
> cases like yours the best advice is to write your next feature using "test
> driven development". Write the test first, get it to fail, then change the
> code as little as possible to get it to pass. Repeat until done,
> occasionally refactoring.
>
> If old code now works, just leave it alone. Until it needs a new feature,
> and then wham! it has tests.
>

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


Is it possible to print different levels to different streams using the logging module?

2010-01-16 Thread Dotan Barak

Hi.

I would like to use the logging module and print the following levels to 
the mentioned streams:


CRITICAL-> stderr
ERROR -> stderr
WARNING   -> stderr
INFO -> stdout
DEBUG -> stdout

I would like that every message will be printed only once, and for the 
stream that i choose.

(I failed to find a "maximum level" for the handlers in the logging module).


Thanks in advanced
Dotan Barak
--
http://mail.python.org/mailman/listinfo/python-list


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Alf P. Steinbach

* Gertjan Klein:

Alf P. Steinbach wrote:


* Gertjan Klein:

What I've been thinking about is to write a single [Windows] executable that
gets associated with .py and .pyw (instead of python.exe itself).

Well, you need two: one for console subsystem, and one for GUI subsystem.


Why? I'd have imagined writing something for the GUI subsystem (without
actually creating a GUI, just to prevent a DOS box popping up), creating
the proper commandline, with either python.exe or pythonw.exe, and
launching that as a separate process. (I have no idea whether this would
actually work though -- I'm just thinking out loud at this stage.)

Thinking about it some more, perhaps that way I can't get at return
codes a python script might provide. I haven't used those, but they may
be useful at some point.


Return codes work OK no matter what.

But it's a hassle for the user to connect up standard input, standard output and 
standard error for a GUI subsystem process.


That's mainly why the distinction between [.py] and [.pyw] is there in Windows: 
the former is associated with console subsystem interpreter ensuring that the 
standard streams are connected up automatically, the latter is associated with 
GUI subsystem interpreter ensuring no automatic console window.




If it's OK with C++, I just sat down and wrote this.


Thanks for that. I won't be using it though; I don't know C++ at all,
and the source looks like complete gobbledygook to me. I wouldn't know
where to begin to change anything in it. ;-)


Ah, well.

Perhaps do this in JScript or VBScript (languages bundled with Windows)? There 
may be less startup overhead than with Python. But I haven't checked.




Cheers,

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


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Gertjan Klein
Alf P. Steinbach wrote:

>* Gertjan Klein:
>> 
>> What I've been thinking about is to write a single [Windows] executable that
>> gets associated with .py and .pyw (instead of python.exe itself).
>
>Well, you need two: one for console subsystem, and one for GUI subsystem.

Why? I'd have imagined writing something for the GUI subsystem (without
actually creating a GUI, just to prevent a DOS box popping up), creating
the proper commandline, with either python.exe or pythonw.exe, and
launching that as a separate process. (I have no idea whether this would
actually work though -- I'm just thinking out loud at this stage.)

Thinking about it some more, perhaps that way I can't get at return
codes a python script might provide. I haven't used those, but they may
be useful at some point.

>If it's OK with C++, I just sat down and wrote this.

Thanks for that. I won't be using it though; I don't know C++ at all,
and the source looks like complete gobbledygook to me. I wouldn't know
where to begin to change anything in it. ;-)

Gertjan.

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


Re: A simple-to-use sound file writer

2010-01-16 Thread Alf P. Steinbach

* Alf P. Steinbach:

* Steve Holden:



Though for what it's worth I wasn't impressed by the results of running
the posted program, since it yielded an AIFF file of mostly zeroes that
produced no audible sound.

$ od -bc sinewave.aiff
000 106 117 122 115 000 002 261 076 101 111 106 106 103 117 115 115
  F   O   R   M  \0 002 261   >   A   I   F   F   C   O   M   M
020 000 000 000 022 000 001 000 001 130 210 000 020 100 016 254 104
 \0  \0  \0 022  \0 001  \0 001   X 210  \0 020   @ 016 254   D
040 000 000 000 000 000 000 123 123 116 104 000 002 261 030 000 000
 \0  \0  \0  \0  \0  \0   S   S   N   D  \0 002 261 030  \0  \0
060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
 \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0530500 000 000 000 000 000 000
 \0  \0  \0  \0  \0  \0
0530506

Any idea what I did wrong?



[snip]



Hm, I'm inclined to think that you used Python 2.x instead of my 3.1.1!

I no longer have Python 2.x installed, I think, so no time to test that 
now.


But would that be the case?

If so, perhaps changing "t = 1*i/sample_rate" to "t = 
(1.0*i)/sample_rate" will help?


I fixed up two more divisions. Not sure if this is 2.x-compatible, but perhaps:




# Python 3.1.1  --  *probably* works also with 2.x?
# Generating a sine wave as a sum of square waves of various amplitudes & 
phases.
import simple_sound


# Step 1"Divide a full cycle of the sine wave into n intervals."
n = 100


# Step 2-- Just an explanation of the rest


# Step 3"In the first half of the cycle, for each bar create that bar as
#   a square wave of frequency f, amplitude half the bar's height, and 
phase
#   starting at the bar's left, plus same square wave with negative sign
#   (inverted amplitude) and phase starting at the bar's right."

square_waves = []
for i in range( n//2 ):
middle_of_interval = (i + 0.5)/n
amp = simple_sound.sample_sine( 1, middle_of_interval ) / 2.0
def first_square_wave( t, i = i, amp = amp ):
phase = 1.0*i/n
return amp*simple_sound.sample_square( 1.0, t - phase )
def second_square_wave( t, i = i, amp = amp ):
phase = 1.0*(i + 1)/n
return -amp*simple_sound.sample_square( 1.0, t - phase )
square_waves.append( first_square_wave )
square_waves.append( second_square_wave )


# Step  4   "Sum all the square waves from step 3."

def sample_squares( f, t ):
samples = []
o_time = f*t
for func in square_waves:
sq_sample = func( o_time )
samples.append( sq_sample )
return sum( samples )


# Finally, generate this is in an [.aiff] file:
if True:
f   = 440
sample_rate = 44100
total_time  = 2
n_samples   = sample_rate*total_time

writer = simple_sound.Writer( "sinewave.aiff" )
for i in range( n_samples ):
t = 1.0*i/sample_rate
sample = sample_squares( f, t )
writer.write( sample )
writer.close()



Cheers & hth.,

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


Re: A simple-to-use sound file writer

2010-01-16 Thread Alf P. Steinbach

* Steve Holden:

Alf P. Steinbach wrote:

* Grant Edwards:

On 2010-01-15, Steve Holden  wrote:


I will, however, observe that your definition of a square wave is what I
would have to call a "'square' wave" (and would prefer to call a "pulse
train"), as I envisage a square wave as a waveform having a 50% duty
cycle, as in

 ___ ___
|   |   |   |
|   |   |   |
|   |   |   |
+---+---+---+---+ and so on ad infinitum, (though I might allow you
|   |   |   |  to adjust the position
|   |   |   |  of y=0 if you want)
|___|   |___|

That is a square wave.


as opposed to your

 _
| |
| |
  __| |__   __
 | |
 | |
 |_|

That isn't.

Arguing to the contrary is just being Humpty Dumpty...

Neither I nor Steve has called that latter wave a square wave.

Steve, quoted above, has written that I defined a square wave that way.
I have not. So Steve's statement is a misrepresentation (I described it
as a sum of two square waves, which it is), whatever the reason for that
misrepresentation.



Or, best of all, you could show me how to synthesize any
waveform by adding square waves with a 50% duty cycle.  Then I
*will* be impressed.

Isn't that what he claimed?  He said that his algorithm for
summing square waves demonstrated the converse of the ability
to construct a periodic function (like a square wave) from a
sine-cosine summation.

Not by itself, no: it just synthesizes a sine.

For the more general case read e.g. the PS in my reply to your earlier
(single) article in this thread.

For information about what the algorithm does, what you refer to as a
"claim" (but note that a Python implementation has been posted to this
thread, and that it works, and that besides the algorithm is trivial so
that "claim" is a rather meaningless word here), read the article that
you then responded to.


Though for what it's worth I wasn't impressed by the results of running
the posted program, since it yielded an AIFF file of mostly zeroes that
produced no audible sound.

$ od -bc sinewave.aiff
000 106 117 122 115 000 002 261 076 101 111 106 106 103 117 115 115
  F   O   R   M  \0 002 261   >   A   I   F   F   C   O   M   M
020 000 000 000 022 000 001 000 001 130 210 000 020 100 016 254 104
 \0  \0  \0 022  \0 001  \0 001   X 210  \0 020   @ 016 254   D
040 000 000 000 000 000 000 123 123 116 104 000 002 261 030 000 000
 \0  \0  \0  \0  \0  \0   S   S   N   D  \0 002 261 030  \0  \0
060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
 \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0530500 000 000 000 000 000 000
 \0  \0  \0  \0  \0  \0
0530506

Any idea what I did wrong?


That sounds like something I did wrong, not like something you did wrong:

It sounds like a  ...  BUG!  ... in my simple_writer code. :-)

Or, that's perhaps not funny, but it occurred to me that it might, to some at 
least, appear to be sort of incongruous in the context of the earlier thread. Heh.


Checking first 20 sample values generated:


if True:
f   = 440
sample_rate = 44100
total_time  = 2
n_samples   = sample_rate*total_time

writer = simple_sound.Writer( "sinewave.aiff" )
for i in range( n_samples ):
t = 1*i/sample_rate
sample = sample_squares( f, t )
if i < 20: print( sample )# Check 'em
writer.write( sample )
writer.close()



-0.0314107590781
-0.0314107590781
-0.0941083133185
-0.15643446504
-0.218143241397
-0.278991106039
-0.338737920245
-0.397147890635
-0.45399049974
-0.50904141575
-0.562083377852
-0.612907053653
-0.661311865324
-0.707106781187
-0.75011106963
-0.790155012376
-0.827080574275
-0.860742027004
-0.891006524188
-0.917754625684


Checking generated file:


$ od -bc sinewave.aiff | head
000 106 117 122 115 000 001 130 266 101 111 106 106 103 117 115 115
  F   O   R   M  \0 001   X 266   A   I   F   F   C   O   M   M
020 000 000 000 022 000 001 000 000 254 104 000 020 100 016 254 104
 \0  \0  \0 022  \0 001  \0  \0 254   D  \0 020   @ 016 254   D
040 000 000 000 000 000 000 123 123 116 104 000 001 130 220 000 000
 \0  \0  \0  \0  \0  \0   S   S   N   D  \0 001   X 220  \0  \0
060 000 000 000 000 000 000 373 373 373 373 363 364 353 372 344 024
 \0  \0  \0  \0  \0  \0 373 373 373 373 363 364 353 372 344 024
100 334 112 324 245 315 053 305 344 276 330 270 016 261 215 253 133
334   J 324 245 315   + 305 344 276 330 270 016 261 215 253   [



Hm, I'm inclined to think that you used Python 2.x instead of my 3.1.1!

I no longer have Python 2.x installed, I think, so no time to test that now.

But would that be the case?

If so, perhaps changing "t = 1*i/sample_rate" to "t = (1.0*i)/sample_rate" will 
help?



Cheers,

- Alf
--
http://mail.python.org/mailman/listinfo/python-lis

Re: A simple-to-use sound file writer

2010-01-16 Thread Steve Holden
Alf P. Steinbach wrote:
> * Grant Edwards:
>> On 2010-01-15, Steve Holden  wrote:
>>
>>> I will, however, observe that your definition of a square wave is what I
>>> would have to call a "'square' wave" (and would prefer to call a "pulse
>>> train"), as I envisage a square wave as a waveform having a 50% duty
>>> cycle, as in
>>>
>>>  ___ ___
>>> |   |   |   |
>>> |   |   |   |
>>> |   |   |   |
>>> +---+---+---+---+ and so on ad infinitum, (though I might allow you
>>> |   |   |   |  to adjust the position
>>> |   |   |   |  of y=0 if you want)
>>> |___|   |___|
>>
>> That is a square wave.
>>
>>> as opposed to your
>>>
>>>  _
>>> | |
>>> | |
>>>   __| |__   __
>>>  | |
>>>  | |
>>>  |_|
>>
>> That isn't.
>>
>> Arguing to the contrary is just being Humpty Dumpty...
> 
> Neither I nor Steve has called that latter wave a square wave.
> 
> Steve, quoted above, has written that I defined a square wave that way.
> I have not. So Steve's statement is a misrepresentation (I described it
> as a sum of two square waves, which it is), whatever the reason for that
> misrepresentation.
> 
> 
>>> Or, best of all, you could show me how to synthesize any
>>> waveform by adding square waves with a 50% duty cycle.  Then I
>>> *will* be impressed.
>>
>> Isn't that what he claimed?  He said that his algorithm for
>> summing square waves demonstrated the converse of the ability
>> to construct a periodic function (like a square wave) from a
>> sine-cosine summation.
> 
> Not by itself, no: it just synthesizes a sine.
> 
> For the more general case read e.g. the PS in my reply to your earlier
> (single) article in this thread.
> 
> For information about what the algorithm does, what you refer to as a
> "claim" (but note that a Python implementation has been posted to this
> thread, and that it works, and that besides the algorithm is trivial so
> that "claim" is a rather meaningless word here), read the article that
> you then responded to.
> 
Though for what it's worth I wasn't impressed by the results of running
the posted program, since it yielded an AIFF file of mostly zeroes that
produced no audible sound.

$ od -bc sinewave.aiff
000 106 117 122 115 000 002 261 076 101 111 106 106 103 117 115 115
  F   O   R   M  \0 002 261   >   A   I   F   F   C   O   M   M
020 000 000 000 022 000 001 000 001 130 210 000 020 100 016 254 104
 \0  \0  \0 022  \0 001  \0 001   X 210  \0 020   @ 016 254   D
040 000 000 000 000 000 000 123 123 116 104 000 002 261 030 000 000
 \0  \0  \0  \0  \0  \0   S   S   N   D  \0 002 261 030  \0  \0
060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
 \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0530500 000 000 000 000 000 000
 \0  \0  \0  \0  \0  \0
0530506

Any idea what I did wrong?

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Using invalid.com email addresses

2010-01-16 Thread Steve Holden
Lie Ryan wrote:
> On 01/16/10 19:56, Ben Finney wrote:
>> Paul Rubin  writes:
>>
>>> I'd think whoever registered that domain would have known what they
>>> were getting into when they registered it. Same with "example.com" and
>>> so forth.
>> Which doesn't make it any more appropriate to act as though you have
>> free rein in a domain registered to someone else.
>>
>> Especially so as there are domains reserved by RFC 2606 that are *known*
>> never to be registered by anyone, and that *are* free for such use.
>>
> 
> I would be more inclined to think that whoever registered it, actually
> does so he can get those misdirected emails; my suspicion was confirmed
> after seeing this on http://www.invalid.com:
> 
> ===
> Hi everybody,
> 
> Thank you for all the e-mails you sent to us! I promise to read them as
> soon as I can, but please be patient - today there are 292,988 unread
> messages in our invalid.com inboxes and I'm all alone at the office.
> 
> Maybe you want to buy my domain name and get a couple of thousand
> e-mails every month? It's a lot of fun, but I guess you too would feel a
> bit exhausted after a while :)
> 
> Take care!
> 
> Elsa W.
> 
> e...@invalid.com
> ===
> 
> Seeing that, I cannot bring myself to think it's impolite to use it as
> /dev/null service (it's still impolite to your reader though). I'm a bit
> suspicious of their real motives though, who knows if it's owned by spam
> email address collector.
> 
> example.com, though, seems to be registered to IANA (Internet Assigned
> Numbers Authority).

As usual, there are people who know what they are doing, people who know
they don't know what they're doing, and people who don't know they don't
know what they're doing.

This is teh Intarwebs. Live with it or leave.

regards
 Steve
(who can't believe he just typed "the" as a typo for "teh")
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Integrate JpegEnhancer in PSPX on XP

2010-01-16 Thread Heinrich Wolf

Hi all,

I've read somewhere that any suitable program - exe file -
could be run by a script in Paint Shop Pro on Windows XP/SP3.
JpegEnhancer from www.vicman.net/jpegenhancer/ is a well known
stand alone app. requiring to juggle an image between PSP and
JpegEnhancer via HD - a extremely undesirable situation for very
many reasons.

If my assumption holds true, JpegEnhancer would rather behave
just as an ordinary PSP python script, taking hold of the bitmap
in RAM, doing its job and leaving the result in PSP smartly for 
further processing as required - including PSP' undo and redo.

I had a look at http://docs.python.org/library/subprocess.html,
but that's over my head by far.

Is there a friendly person here in this Python domain, willing to 
supply a little know how for me and others to further our 
addiction to photography?


Very many thanks in advance and kind regards - flowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Alf P. Steinbach

* Gertjan Klein:


What I've been thinking about is to write a single [Windows] executable that
gets associated with .py and .pyw (instead of python.exe itself).


Well, you need two: one for console subsystem, and one for GUI subsystem.

Happily you can use the same source code. :-)



This
executable would parse the #! line to look for a specific python
version, or use a configured default if none found (or a parsing error
occurs). It would then invoke the appropriate python version (with
whatever arguments, if any, are supplied).

As far as I can see, this allows both typing the script name and
arguments (i.e., without python31 before it) from a command prompt, and
doubleclicking on a .py or .pyw file from windows explorer. In both
cases, the proper python executable would be used to run the script.

What's been holding me back so far is that probably needs to be written
in C, to prevent the Python runtime's startup overhead. I haven't
written any significant amount of C code in years, if not decades, so
that seems like a daunting task to me at the moment. ;-)


If it's OK with C++, I just sat down and wrote this.

It's not especially well tested (or almost not at all), and it's limited.

It handles or is meant to handle Unicode script file paths, but the path to the 
Python interpreter, specified in a "#!" comment in the script's first line, must 
be single byte per character. And if that path contains spaces must be quoted.




// Note: in order to handle Unicode paths needs to use Windows API command line.
//
// If this code works then it was written (but not tested) by Alf P. Steinbach.
// Otherwise it's someone impersonating me.

#include// std::wstring
#include// std::vector
#include
#include
#include

#undef  STRICT
#undef  NOMINMAX
#undef  UNICODE
#define STRICT
#define NOMINMAX
#define UNICODE
#include // CommandLineToArgvW, GetCommandLine

using namespace std;


//-- Various things ordinarily from libraries...

bool throwX( char const s[] ) { throw std::runtime_error( s ); }

typedef ptrdiff_t   Size;

template< typename Container >
Size n_elements( Container const& c ) { return c.size(); }

// The C++98 standard library doesn't offer Unicode filename functionality.
// Using library extension that works with GNU g++ and Microsoft Visual C++.
class TextFileReader
{
private:
FILE*   f;
TextFileReader( TextFileReader const& );// No copy constructor.
TextFileReader& operator=( TextFileReader const& ); // No assignment.

public:
TextFileReader( wstring const& path )
: f( _wfopen( path.c_str(), L"r" ) )
{
(f != 0) || throwX( "Unable to open file for reading" );
}

~TextFileReader() { fclose( f ); }

wstring line()
{
wstring s;
for( ;; )
{
int const c = fgetc( f );
if( c == EOF || c == L'\n' ) { break; }
s.push_back( wchar_t( c ) );
}
return s;
}
};

wstring substring( wstring const& s, Size const i, Size const n = -1 )
{
wstring::size_type constcount   = (n == -1? wstring::npos : n);
return (i >= n_elements( s )? L"" : s.substr( i, count ));
}

//-- Main

typedef wstring String;
typedef vector  StringVector;


StringVector cmdArguments()
{
struct Args
{
wchar_t**   p;
int n;

Args()
{
p = CommandLineToArgvW( GetCommandLine(), &n );
(p != 0) || throwX( "Unable to obtain command line arguments" );
}

~Args() {  GlobalFree( p ); }
};

Args const  args;
return StringVector( args.p, args.p + args.n );
}

int run( wstring const& prog_path, wstring const& args )
{
wstring cmd_line= prog_path + L" " + args;

cmd_line.c_str();
PROCESS_INFORMATION process_info= {};
STARTUPINFO startup_info= { sizeof( startup_info ) };
bool const ok   = !!CreateProcess(
0,  // application name
&cmd_line[0],   // command line
0,  // process security attributes
0,  // thread security attributes
TRUE,   // inherit handles
0,  // creation flags
0,  // environment, 0 => inherit parent process env.
0,  // current directory
&startup_info,
&process_info
);
(ok)
|| throwX( "Unable to run the interpreter" );


bool const  wait_ok =
(WaitForSingleObject( process_info.hProcess, INFINITE ) != WAIT_FAILED);

DWORD   exit_code   = EXIT_FAILURE;
GetExitCodeProcess( process_info.hProcess, &exit_code );
CloseHandle( process_info.hProcess );
CloseHandle( process_info.hThread );

(wait_ok) || throwX( "Waiting for the program to end failed" );
return exit_code;
}

int cppMain()
{
StringVector const  args= cmdArgume

Re: remote evaluation of Python code typed in html webpage frame

2010-01-16 Thread Anand Vaidya
On Jan 16, 12:26 am, r0g  wrote:
> >> Diez
>
> The Web2py framework works a bit like that, although it's not quite as
> simplistic as what you describe. May be worth a look though.
>
> Roger.


Hi r0g,

web2py is a web-app framework (very similar to django, pylons etc) and
it does not execute user form-submitted python code. It executes
applications written and stored on the server-side only.

You are probably referring to some other project???

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


Re: Using invalid.com email addresses

2010-01-16 Thread Lie Ryan
On 01/16/10 19:56, Ben Finney wrote:
> Paul Rubin  writes:
> 
>> I'd think whoever registered that domain would have known what they
>> were getting into when they registered it. Same with "example.com" and
>> so forth.
> 
> Which doesn't make it any more appropriate to act as though you have
> free rein in a domain registered to someone else.
> 
> Especially so as there are domains reserved by RFC 2606 that are *known*
> never to be registered by anyone, and that *are* free for such use.
> 

I would be more inclined to think that whoever registered it, actually
does so he can get those misdirected emails; my suspicion was confirmed
after seeing this on http://www.invalid.com:

===
Hi everybody,

Thank you for all the e-mails you sent to us! I promise to read them as
soon as I can, but please be patient - today there are 292,988 unread
messages in our invalid.com inboxes and I'm all alone at the office.

Maybe you want to buy my domain name and get a couple of thousand
e-mails every month? It's a lot of fun, but I guess you too would feel a
bit exhausted after a while :)

Take care!

Elsa W.

e...@invalid.com
===

Seeing that, I cannot bring myself to think it's impolite to use it as
/dev/null service (it's still impolite to your reader though). I'm a bit
suspicious of their real motives though, who knows if it's owned by spam
email address collector.

example.com, though, seems to be registered to IANA (Internet Assigned
Numbers Authority).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using invalid.com email addresses

2010-01-16 Thread Ben Finney
Ben Finney  writes:

> Paul Rubin  writes:
>
> > I'd think whoever registered that domain would have known what they
> > were getting into when they registered it. Same with "example.com" and
> > so forth.
>
> Which doesn't make it any more appropriate to act as though you have
> free rein in a domain registered to someone else.

Lest this be misread: The “you”, above, is intended in its non-specific
sense, not directed at a particular person. I should perhaps have said
“act as though one has free rein” etc.

I especially don't mean Paul here, since he is using a domain from
RFC 2606 which therefore is known to never be treading on anyone's toes.

-- 
 \   “Remember: every member of your ‘target audience’ also owns a |
  `\   broadcasting station. These ‘targets’ can shoot back.” —Michael |
_o__)   Rathbun to advertisers, news.admin.net-abuse.email |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using invalid.com email addresses

2010-01-16 Thread Ben Finney
Paul Rubin  writes:

> I'd think whoever registered that domain would have known what they
> were getting into when they registered it. Same with "example.com" and
> so forth.

Which doesn't make it any more appropriate to act as though you have
free rein in a domain registered to someone else.

Especially so as there are domains reserved by RFC 2606 that are *known*
never to be registered by anyone, and that *are* free for such use.

-- 
 \   “I bought some batteries, but they weren't included; so I had |
  `\to buy them again.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setattr() oddness

2010-01-16 Thread Lie Ryan
On 01/16/10 10:10, Sean DiZazzo wrote:
> Interesting.  I can understand the "would take time" argument, but I
> don't see any legitimate use case for an attribute only accessible via
> getattr().  Well, at least not a pythonic use case.

mostly for people (ab)using attributes instead of dictionary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using invalid.com email addresses

2010-01-16 Thread Paul Rubin
Ben Finney  writes:
>> Does anyone else think that that behaviour is just rude, not to
>> mention in violation of the RFCs?
>
> Yes, it violates RFCs. It also ignores the fact that the domain is
> currently registered until 2010-08-03, and is therefore not available
> for anyone else's use, unless they happen to have an arrangement for its
> use with the registrant.

I'd think whoever registered that domain would have known what they were
getting into when they registered it.  Same with "example.com" and so forth.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: maintain 2 versions of python on my computer

2010-01-16 Thread Gertjan Klein
Gabriel Genellina wrote:

>En Thu, 14 Jan 2010 08:21:28 -0300, luis  escribió:
>
>> Is there any way to indicate the version of the python interpreter
>> must use a script?
>
>See http://www.effbot.org/zone/exemaker.htm
>It uses the #! line to determine which version to load, resembling the  
>Unix way.
>(I've written a variant of the same idea but isn't ready yet)

I'd be interested to see what you've come up with, if you care to share.
I've been thinking about something like this as well. Exemaker, for me,
is the wrong solution, because it requires making an .exe file for every
script you want to run this way.

What I've been thinking about is to write a single executable that gets
associated with .py and .pyw (instead of python.exe itself). This
executable would parse the #! line to look for a specific python
version, or use a configured default if none found (or a parsing error
occurs). It would then invoke the appropriate python version (with
whatever arguments, if any, are supplied).

As far as I can see, this allows both typing the script name and
arguments (i.e., without python31 before it) from a command prompt, and
doubleclicking on a .py or .pyw file from windows explorer. In both
cases, the proper python executable would be used to run the script.

What's been holding me back so far is that probably needs to be written
in C, to prevent the Python runtime's startup overhead. I haven't
written any significant amount of C code in years, if not decades, so
that seems like a daunting task to me at the moment. ;-)

Gertjan.

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