IMGCrush 0.4.0 and IMGCrush_GUI 0.4.0 released

2009-11-03 Thread kiithsa...@gmail.com
Announcing IMGCrush 0.4.0 and IMGCrush_GUI 0.4.0 ,
a new release bringing new features and bugfixes,
as well as considerable speedup (even though it's still quite slow)

IMGCrush is an image compressor capable of compressing files to
user specified size or quality using common web image formats
particularly well suited to optimize images for web sites.

IMGCrush_GUI is a simple Tkinter GUI using basic subset of IMGCrush
options.
It should be replaced by a more advanced GTK or Qt GUI in future.

Get IMGCrush and IMGCrush_GUI here: https://launchpad.net/icrush/+download
(IMGCrush_GUI is on the bottom of the page)

New features:
-Recursive directory processing
-Multiprocessing
-GIF bit depths from 1 to 8 support
-JPG grayscale support
-deprecated (and removed some) resizing options

Note that at this moment IMGCrush is still quite slow and
experimental.

More info: https://launchpad.net/icrush
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] stdeb 0.4.2

2009-11-03 Thread Andrew Straw
stdeb produces Debian source packages from Python packages via a new
distutils command, sdist_dsc. Automatic defaults are provided for the
Debian package, but many aspects of the resulting package can be
customized via a configuration file. An additional command, bdist_deb,
creates a Debian binary package, a .deb file.

stdeb: http://github.com/astraw/stdeb

This email announces release 0.4.2.

download: http://pypi.python.org/pypi/stdeb/0.4.2

Release 0.4.2 is a bugfix release fixing a couple issues. The most
significant fix is that if a package specified XS-Python-Version in
stdeb.cfg, the binary package wouldn't install the Python packages.

No backwards incompatible changes were made with this release.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Python-URL! - weekly Python news and links (Nov 3)

2009-11-03 Thread Gabriel Genellina
QOTW:  I consider import * the first error to be fixed ... - Robert
Kern, author of PyFlakes, a potential replacement for Pylint and Pychecker,
on his personal style
http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2


Python 2.6.4 is out; it fixes some small but important bugs in
previous 2.6.3 release:
http://groups.google.com/group/comp.lang.python/t/44f4c166de5e6703/

PEP391: A new way to configure Python logging, using dictionaries:
http://groups.google.com/group/comp.lang.python/t/3fc3138c22a50678/

Why do you use Python?
http://groups.google.com/group/comp.lang.python/t/66ccb10d2da5b740/

Is there any value in forcing one class/function per module? (long thread):
http://groups.google.com/group/comp.lang.python/t/1e0c1e2091539512/

A review of complex solutions to an almost inexistent problem shows
constructive criticism in action:
http://groups.google.com/group/comp.lang.python/t/d218212cabe9670b/

A user module may shadow a standard module of the same name - is it
avoidable?
http://groups.google.com/group/comp.lang.python/t/b31f74b6145c9d94/

copy.deepcopy() is not as deep as its name implies:
http://groups.google.com/group/comp.lang.python/t/d827fd118189fe01/

A long thread about Web development: why to use templates, and why
frameworks actually do help developers:
http://groups.google.com/group/comp.lang.python/t/367025d4d9a2e15d/

Using a module as a place to store application global settings:
http://groups.google.com/group/comp.lang.python/t/23e21edf1b232b32/

A simple list comprehension question leads to discuss mutability,
identity, and Cousin Chuy's Super-Burritos:
http://groups.google.com/group/comp.lang.python/t/17cfd91ece6ed54f/

Combining map, zip and filter into an equivalent list comprehension:
http://groups.google.com/group/comp.lang.python/t/259976305282b0c0?q=map

timeit: make sure you actually measure what you want, and not other code:
http://groups.google.com/group/comp.lang.python/t/7ecae76e11f720ee/

Why do compiled C extensions on Windows use '.pyd' in their name instead
of '.dll'?
http://groups.google.com/group/comp.lang.python/t/c8d93871cc5f31dc/

Pyfora, a web forum about Python, was lauched recently. Will this
fragment the community?
http://groups.google.com/group/comp.lang.python/t/e6e0d99c995da697/

A guy's future book on programming Python doesn't fit standard practice
(a long thread!):
http://groups.google.com/group/comp.lang.python/t/6918784f36d147d2/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet site:
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 


probability sequencing language 1.04 has been released

2009-11-03 Thread edexter
probability sequencing language is a text based piano roll type
programming language for csound. some may refer to it as a pre
processor for csound.

 For version 1.04

 a bug has been fixed alowing floating point numbers for the step
number
 macros are now available loaded from external files.
 frequencies can now have drift where they change on every pass.

 the latest files are always available here

 http://dexrowem.blogspot.com/search?q=probility+sequencing+language
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Open Technology Group, Inc. announces Advanced Python Training

2009-11-03 Thread Chander Ganesan
Morrisville, NC (PRWEB) November 3, 2009 -- Open Technology Group, Inc. 
announces Advanced Python Training.


The Open Technology Group (OTG), a leader in the development and 
delivery of training solutions centered about Open Source technologies, 
released the latest in its set of Open Source Python training courses - 
Advanced Python Programming 
(http://www.otg-nc.com/advanced-python-training). Designed for 
programmers looking to leverage advanced features of Python, or develop 
fast, efficient, and scalable software with Python, this Python course 
covers a wide range of advanced python related topics, including: 
object-oriented python programming; exception handling; python 
generators and decorators; regular expressions; networking with sockets; 
multi-threading, multi-processing, and coordination of operations 
between processes; signal handling; networking with Twisted; XML 
processing; and leveraging the Python unittest module. The Advanced 
Python Programming course is a mix of lecture, demonstration, and 
hands-on exercises. We've taken some of the most popular advanced 
components of Python and integrated them into this course with hands-on 
examples and exercises, said Chander Ganesan, President. The Advanced 
Python Programming course is available for immediate delivery, worldwide.


The new class is available for both public enrollment and customized, 
affordable, on-site delivery to small groups (3 or more students) 
worldwide.


ABOUT OPEN TECHNOLOGY GROUP, INC.

Founded in 2004 and headquartered in Morrisville, NC, the Open 
Technology Group, Inc. (OTG) has established itself as the leading 
provider of training solutions centered about Open Source software and 
solutions. With its comprehensive library of in-house developed 
intellectual property, OTG is able to deliver comprehensive, customized, 
and structured training covering a wide range of software solutions. The 
Open Technology Group offers affordable customized on-site technology 
training worldwide, as well as public-enrollment courses delivered in 
over 10 locations, nationwide. For more information, and a complete 
course catalog, visit us online at http://www.otg-nc.com, or contact us 
at 877-258-8987.

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

   Support the Python Software Foundation:
   http://www.python.org/psf/donations/


Re: list comprehension problem

2009-11-03 Thread Ben Finney
Paul Rudin paul.nos...@rudin.co.uk writes:

 Falcolas garri...@gmail.com writes:

  [s.strip() for s in hosts if s.strip()]

 There's something in me that rebels against seeing the same call
 twice.

Agreed. I'd probably use:

 lines = [foo,,  bar , , baz]
 [s for s in (s.strip() for s in lines) if s]
['foo', 'bar', 'baz']

-- 
 \  “[I]t is impossible for anyone to begin to learn that which he |
  `\thinks he already knows.” —Epictetus, _Discourses_ |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Command parsing... best module to use?

2009-11-03 Thread Collin D
Thanks for the replies. Pyparsing looks just like what I need.

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


Re: self.__dict__ tricks

2009-11-03 Thread Ben Finney
a...@pythoncraft.com (Aahz) writes:

 There are no stupid questions, only stupid people.

The earliest source I know for that aphorism is the fictional teacher
Mister Garrisson, from South Park. Can anyone source it earlier?

-- 
 \“Read not to contradict and confute, nor to believe and take |
  `\  for granted … but to weigh and consider.” —Francis Bacon |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: substituting list comprehensions for map()

2009-11-03 Thread Anh Hai Trinh
 Yes, just about any ‘map()’ operation has a corresponding list
 comprehension. (Does anyone know of a counter-example, a ‘map()’
 operation that doesn't have a correspondingly simple list
 comprehension?)

Try turning this into a list comprehension:

  vectorsum = lambda *args: map(sum, zip(*args))

  vectorsum([1,2], [3,4], [5,6])
-[9, 12]
  vectorsum([1,2], [3,4], [5,6], [7,8])
-[16, 20]

Peace,

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


Re: Sqlite3. Substitution of names in query.

2009-11-03 Thread Lawrence D'Oliveiro
In message mailman.2504.1257216390.2807.python-l...@python.org, Carsten 
Haese wrote:

 With all due respect, but if your experience is exclusive to
 MySQL/MySQLdb, your experience means very little for database
 programming practices in general.

I wonder about the veracity of your claims, because:

 And here are the corresponding results on my laptop:
 $ python -mtimeit -s from querytest import Tester; t=Tester()
 't.with_params()'
 1 loops, best of 3: 20.9 usec per loop
 $ python -mtimeit -s from querytest import Tester; t=Tester()
 't.without_params()'
 1 loops, best of 3: 36.2 usec per loop

Didn't you say previously that there should be a seven orders of magnitude 
difference? What happened to that claim?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Docs Typo

2009-11-03 Thread Ben Finney
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes:

 http://docs.python.org/library/turtle.html -- “ScrolledCavas” should be 
 “ScrolledCanvas”.

Thanks for finding and describing a fault with the Python documentation.
This is not the right place for reporting it, though: this is the Python
user forum, not an appropriate place for reporting faults.

If you would like the issue to be addressed, please report it to the
Python bug tracking system URL:http://bugs.python.org/.

-- 
 \“Program testing can be a very effective way to show the |
  `\presence of bugs, but is hopelessly inadequate for showing |
_o__)  their absence.” —Edsger W. Dijkstra |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Cast into custom type

2009-11-03 Thread Henning Bredel
Hi,

I created a plugin mechanism for my application orientating
at the mechanism described by Martin Alchy in

  http://martyalchin.com/2008/jan/10/simple-plugin-framework/

Now I'd like to call methods like `initialize(parent)' when
the user chooses to use a plugin. As described in the blog
mentioned above, I only have access to the general type called
`PluginMount' (holding all the actual plugin instances).

I tried to define abstract methods in PluginMount type 
raising a `NotImplementedError' but it seems, there is no
late binding (similar to Java), so the right method would be
called. Only the message 

  TypeError: unbound method initialize() must be called 
  with GeoCache instance as first argument (got PluginMount 
  instance instead)

`GeoCache' would be the plugin type. What is strange, is the
fact, that when asking what instances are hold by PluginMount

   [class 'geocacheplugin.GeoCache']

is listed. So it seems, that no late binding is applied when
calling the `initialize(self, parent)' method.

I'm quite new using Python, so this might be a quite basic 
question caused by some misunderstandings in general. Feel
free to point me to appropriate site to solve my problem.

Thanks in advance.

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


Re: Cast into custom type

2009-11-03 Thread Diez B. Roggisch

Henning Bredel schrieb:

Hi,

I created a plugin mechanism for my application orientating
at the mechanism described by Martin Alchy in

  http://martyalchin.com/2008/jan/10/simple-plugin-framework/

Now I'd like to call methods like `initialize(parent)' when
the user chooses to use a plugin. As described in the blog
mentioned above, I only have access to the general type called
`PluginMount' (holding all the actual plugin instances).

I tried to define abstract methods in PluginMount type 
raising a `NotImplementedError' but it seems, there is no

late binding (similar to Java), so the right method would be
called. Only the message 

  TypeError: unbound method initialize() must be called 
  with GeoCache instance as first argument (got PluginMount 
  instance instead)


`GeoCache' would be the plugin type. What is strange, is the
fact, that when asking what instances are hold by PluginMount

   [class 'geocacheplugin.GeoCache']

is listed. So it seems, that no late binding is applied when
calling the `initialize(self, parent)' method.

I'm quite new using Python, so this might be a quite basic 
question caused by some misunderstandings in general. Feel

free to point me to appropriate site to solve my problem.


It seems that GeoCache is not a subclass of PluginMount.

Diez


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


Re: Cast into custom type

2009-11-03 Thread Gabriel Genellina
En Tue, 03 Nov 2009 06:41:37 -0300, Henning Bredel henning.bre...@gmx.de  
escribió:



I created a plugin mechanism for my application orientating
at the mechanism described by Martin Alchy in

  http://martyalchin.com/2008/jan/10/simple-plugin-framework/

Now I'd like to call methods like `initialize(parent)' when
the user chooses to use a plugin. As described in the blog
mentioned above, I only have access to the general type called
`PluginMount' (holding all the actual plugin instances).


According to the article, PluginMount holds a list of all plugin *classes*  
defined, not instances.



I tried to define abstract methods in PluginMount type
raising a `NotImplementedError' but it seems, there is no
late binding (similar to Java), so the right method would be
called. Only the message

  TypeError: unbound method initialize() must be called
  with GeoCache instance as first argument (got PluginMount
  instance instead)


Python uses late binding, even more than Java. A reference like  
obj.foo(...) searches for foo along obj's attributes at runtime.
Please post some code showing your issue, and don't forget to tell us what  
is your expected result, and what you actually get.


--
Gabriel Genellina

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


Re: Pyfora, a place for python

2009-11-03 Thread Lorenzo Gatti
On Nov 1, 8:06 am, Saketh saketh.bhamidip...@gmail.com wrote:
 Hi everyone,

 I am proud to announce the release of Pyfora (http://pyfora.org), an
 online community of Python enthusiasts to supplement comp.lang.python
 and #python. While the site is small right now, please feel free to
 register and post any questions or tips you may have.

I'll feel free to not even bookmark it. I'm sorry, but it is just a
bad idea.

Your forum cannot (and should not) compete either with Python's
official newsgroup, IRC channel and mailing list or with popular, well-
made and well-frequented general programming sites like
stackoverflow.com.

It would be the Internet equivalent of looking for a poker tournament
in a desert valley instead of driving half an hour less and going to
Las Vegas: there are no incentives to choose your forum, except
perhaps for isolationists who value being a big fish in a small pond
over being part of a community.

If you want to claim a small Python-related corner of the web, you
should write a blog: if it is any good, and probably even if it isn't,
it would be linked and read by someone and it would add to collective
knowledge instead of fragmenting it.

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


Re: Cast into custom type

2009-11-03 Thread Steven D'Aprano
On Tue, 03 Nov 2009 09:41:37 +, Henning Bredel wrote:

 Hi,
 
 I created a plugin mechanism for my application orientating at the
 mechanism described by Martin Alchy in
 
   http://martyalchin.com/2008/jan/10/simple-plugin-framework/

Regarding your subject line, Python doesn't have casts. A very small 
number of numeric types are automatically coerced as needed, for 
everything else you need an explicit conversion between objects of one 
type to different objects of another type.


 Now I'd like to call methods like `initialize(parent)' when the user
 chooses to use a plugin. As described in the blog mentioned above, I
 only have access to the general type called `PluginMount' (holding all
 the actual plugin instances).
 
 I tried to define abstract methods in PluginMount type raising a
 `NotImplementedError' but it seems, there is no late binding (similar to
 Java), so the right method would be called. 

You need to give some actual examples of what you are trying to do, and 
what you are expecting to happen. How is initialized() being called?


 Only the message
 
   TypeError: unbound method initialize() must be called with GeoCache
   instance as first argument (got PluginMount instance instead)

Sounds like you are calling initialize on the class instead of on an 
instance. I'm *guessing* that you are doing something like this:

plugin_manager = PluginMount()
# ...
# create plugins, which are registered in the plugin_manager
# ...
# Now initialize them:
for cls in plugin_manager.plugins:
cls.initialize(plugin_Manager)


If my guess is correct, you can fix this two ways:

(1) Change the for-loop to:

for cls in plugin_manager.plugins:
cls().initialize(plugin_Manager)

although it isn't clear to me what you should do with the plugin 
instances after you've created them.

(2) Change the initialize method to a classmethod:

@classmethod
def initialize(cls, parent):
pass



 `GeoCache' would be the plugin type. What is strange, is the fact, that
 when asking what instances are hold by PluginMount
 
[class 'geocacheplugin.GeoCache']
 
 is listed. So it seems, that no late binding is applied when calling the
 `initialize(self, parent)' method.

What do you mean by late binding, and what makes you think it applies (or 
should apply) to calling the initialize method?


 I'm quite new using Python, so this might be a quite basic question
 caused by some misunderstandings in general. Feel free to point me to
 appropriate site to solve my problem.

We have to understand your problem first.



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


Re: PyGDChart2 module

2009-11-03 Thread eb303
On Oct 28, 4:52 pm, eb303 eric.brunel.pragma...@gmail.com wrote:
 Hi all,

 I was looking for a simple chart drawing Python module and as a user
 of the gd library and its Python interface, I was interested in the
 Python interface to the gdchart library (http://www.fred.net/brv/
 chart/). Unfortunately, this module seems to have disappeared: its
 former URL (http://www.nullcube.com/software/pygdchart2.html) gives a
 404 and a Google search did not return any other source. Does anyone
 know where I can find a copy of this module's source code?

 Thanks.

Replying to myself: finally found the source package at
http://ftp.de.debian.org/debian/pool/main/p/pygdchart2/pygdchart2_0.beta1.orig.tar.gz

Seems to work quite well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyfora, a place for python

2009-11-03 Thread M.-A. Lemburg
Kee Nethery wrote:
 I just noticed the tag line a place for Python. Looked it up online
 (http://pyfora.org/) and it will be interesting to see if it can fill
 the void that I experience (no centralized place to post and view user
 submitted sample code) in the existing Python community.

There already is a well-known site for exchanging code snippets:

The ActiveState Cookbook for Python
http://code.activestate.com/recipes/langs/python/

 As for user community fragmentation, I would guess that someone would be
 less likely to create such a site if the user community needs were being
 met by the official sites. There is a place for the existing old school
 interaction forums (the IRC channel, the Usenet groups and mailing
 lists), but there is also a place for archived user submitted comments.
 
 My personal preference would be a link in each sub-paragraph in the
 official documentation to a wiki page devoted to that specific aspect of
 the Python language. A place were users could augment the documentation
 by providing sample code and by expanding out the documentation for
 those of us who don't live and breath Python in our sleep. Real Python
 coders would not click on the user wiki links and all of us newbies
 could communicate with each other. But until a place like that exists,
 perhaps Pyfora will get us part way there.

I'm sure something like that could be added to the official
documentation. Please file a feature request for on the Python
tracker.

We could have a dedicated place on the python.org wiki to host
such snippets and then use sub-pages for the various topics.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 03 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: self.__dict__ tricks

2009-11-03 Thread Simon Brunning
2009/11/1 Steven D'Aprano st...@remove-this-cybersource.com.au:

 The only stupid question is the one you are afraid to ask.

I was once asked, and I quote exactly, are there any fish in the Atlantic sea?

That's pretty stupid. ;-)

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


Re: convert pyc (python 2.4) to py

2009-11-03 Thread Furkan Kuru
There is an online service at http://www.depython.com converting pyc
files to py.
You can give it a try.
It does not have file size limit.

On Wed, Oct 21, 2009 at 8:58 PM, Chris Rebert c...@rebertia.com wrote:
 On Wed, Oct 21, 2009 at 11:35 AM, Peng Yu pengyu...@gmail.com wrote:
 On Tue, Oct 20, 2009 at 4:42 PM, Diez B. Roggisch de...@nospam.web.de 
 wrote:
 Peng Yu schrieb:

 I have a .pyc file generated by python 2.4. My current python is of
 version 2.6. I'm wondering how to generate the corresponding .py file
 from it.

 http://www.crazy-compilers.com/decompyle/

 Is there any free one?

 There's an older version of the software at:
 http://sourceforge.net/projects/decompyle/
 but it's not maintained like the service (just see the last-modified
 date on it) and you'll have to figure out how to use it by yourself.

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




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


Re: About one class/function per module

2009-11-03 Thread Diez B. Roggisch
Peng Yu wrote:

 On Mon, Nov 2, 2009 at 9:39 PM, alex23 wuwe...@gmail.com wrote:
 Peng Yu pengyu...@gmail.com wrote:
 I don't think that this is a problem that can not be overcome. A
 simple solution might be to associate a unique identifier to each
 file, so that even the filename has been changed, the new version and
 the old version can still be identified as actually the same file.

 Or, again, you could work _with_ the tools you're using in the way
 they're meant to be used, rather than re-inventing the whole process
 of version control yourself.
 
 I'm not trying to reinvent a new version control. But due to this
 drawback, I avoid use a version control system. Rather, I compressed
 my source code in a tar file whenever necessary. But if a version
 control system has this capability, I'd love to use it. And I don't
 think that no version control system support this is because of any
 technical difficult but rather because of practical issue (maybe it
 takes a lot efforts to add this feature to an existing version control
 system?).

There are those people who realize if *everything* they encounter needs
adjustment to fit their needs, their needs need adjustment. 

Others fight an uphill battle  bicker about things not being as they want
them.

Don't get me wrong - innovation often comes from scratching ones personal
itch. But you seem to be suffering from a rather bad case of
neurodermatitis.

Diez


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


Re: About one class/function per module

2009-11-03 Thread Ben Finney
Diez B. Roggisch de...@nospam.web.de writes:

 Don't get me wrong - innovation often comes from scratching ones
 personal itch. But you seem to be suffering from a rather bad case of
 neurodermatitis.

+1 QOTW

-- 
 \  “For my birthday I got a humidifier and a de-humidifier. I put |
  `\  them in the same room and let them fight it out.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cast into custom type

2009-11-03 Thread Henning Bredel
Diez, Gabriel, Steven,

thanks for your answers. I'll mainly give response in this posting, so 
I hope not repeating myself.

On Tue, 03 Nov 2009 10:18:29 +, Steven D'Aprano wrote:

 On Tue, 03 Nov 2009 09:41:37 +, Henning Bredel wrote:
 
 Now I'd like to call methods like `initialize(parent)' when the user
 chooses to use a plugin. As described in the blog mentioned above, I
 only have access to the general type called `PluginMount' (holding all
 the actual plugin instances).
 
 I tried to define abstract methods in PluginMount type raising a
 `NotImplementedError' but it seems, there is no late binding (similar
 to Java), so the right method would be called.
 
 You need to give some actual examples of what you are trying to do, and
 what you are expecting to happen. How is initialized() being called?

Example: Assume a framework which offers common functionality for a plugin
or a module a user can choose at the beginning. The framework does not
know the concrete type of the plugin so it is possible to extend it by
implementing a well known interface or abstract class.

The framework reads the plugin directory, loads each module and creates
buttons for each plugin with a callback method for initializing. To use
common functionality of the framework, initialization method takes it as
the parent parameter.

I think this listing makes the most sense to you:

  # initialize all plugins
  self._plugin_modules = _load_plugins() # imp loading here
  LOGGER.debug(ActionProvider.plugins) # print what was loaded
  for plugin in ActionProvider.plugins: # create button for each
  app_button = gtk.Button(plugin.title)
  LOGGER.debug('Title of plugin: %s' % plugin.title)
  app_button.connect(clicked, 
 plugin.initialize(plugin, self), 
 None)
  self.set_canvas(app_button)
  app_button.show()

   TypeError: unbound method initialize() must be called with GeoCache
   instance as first argument (got PluginMount instance instead)
 
 Sounds like you are calling initialize on the class instead of on an
 instance. I'm *guessing* that you are doing something like this:

Oh, I didn't expext PluginMount to hold only classes :/.

When calling `LOGGER.debug('Title of plugin: %s' % plugin.title)' the
global (not class attribute) `title' attribute is printed out though.
Probably some misinterpretation, too ..?!

 (1) Change the for-loop to:
 
 for cls in plugin_manager.plugins:
 cls().initialize(plugin_Manager)

Good guess .. but calling it in that way another error says

  app_button.connect(clicked, plugin().initialize(self), None)
  TypeError: __init__() takes exactly 2 arguments (1 given)

But also

  app_button.connect(clicked, plugin().initialize(plugin, self), None)
  TypeError: __init__() takes exactly 2 arguments (1 given)

That is strange, because neither initialize() nor __init__ of the
plugin is called .. only a logging statement shall print a msg.

I hope it got a bit clearer what I am intended to do.

Thanks for your help.

  Henning

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


import from a string

2009-11-03 Thread iu2
Hi,

Having a file called funcs.py, I would like to read it into a string,
and then import from that string.
That is instead of importing from the fie system, I wonder if it's
possible to eval the text in the string and treat it as a module.

For example

with file('funcs.py') as f: txt = r.read()
string_import(txt, 'funcs')  # is string_import possible?

to have now a module called funcs with the functions defined in
funcs.py.

Thanks

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


Re: Aaaargh! global name 'eggz' is not defined

2009-11-03 Thread Singletoned
On Oct 30, 8:53 am, Bruno Desthuilliers bruno.
42.desthuilli...@websiteburo.invalid wrote:
 Robert Kern a écrit : On 2009-10-29 16:52 PM, Aahz wrote:
 (snip)
  Coincidentally, I tried PyFlakes yesterday and was unimpressed with the
  way it doesn't work with import *.

  I consider import * the first error to be fixed, so it doesn't bother
  me much. :-)

 +1 QOTW

Bruno, do you actually get to decide the QOTW?  Because everytime you `
+1 QOTW` it gets to be the QOTW.

Ed

BTW I was the grateful recipient of your vote the other week.
-- 
http://mail.python.org/mailman/listinfo/python-list


Help resolve a syntax error on 'as' keyword (python 2.5)

2009-11-03 Thread Oltmans
Hi, all. All I'm trying to do is to print the error message using the
following code (copying/pasting from IDLE).

def div(a,b):
print a/b


try:
div(5,0)
except Exception as msg:
print msg

but IDLE says (while highlighting the 'as' keyword)
except Exception as msg:

SyntaxError: invalid syntax

I've searched the internet and I'm not sure what can cause this. Any
help is highly appreciated. I'm using Python 2.5 on Windows XP.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Nov 3)

2009-11-03 Thread Gabriel Genellina
QOTW:  I consider import * the first error to be fixed ... - Robert
Kern, author of PyFlakes, a potential replacement for Pylint and Pychecker,
on his personal style
http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2


Python 2.6.4 is out; it fixes some small but important bugs in
previous 2.6.3 release:
http://groups.google.com/group/comp.lang.python/t/44f4c166de5e6703/

PEP391: A new way to configure Python logging, using dictionaries:
http://groups.google.com/group/comp.lang.python/t/3fc3138c22a50678/

Why do you use Python?
http://groups.google.com/group/comp.lang.python/t/66ccb10d2da5b740/

Is there any value in forcing one class/function per module? (long thread):
http://groups.google.com/group/comp.lang.python/t/1e0c1e2091539512/

A review of complex solutions to an almost inexistent problem shows
constructive criticism in action:
http://groups.google.com/group/comp.lang.python/t/d218212cabe9670b/

A user module may shadow a standard module of the same name - is it
avoidable?
http://groups.google.com/group/comp.lang.python/t/b31f74b6145c9d94/

copy.deepcopy() is not as deep as its name implies:
http://groups.google.com/group/comp.lang.python/t/d827fd118189fe01/

A long thread about Web development: why to use templates, and why
frameworks actually do help developers:
http://groups.google.com/group/comp.lang.python/t/367025d4d9a2e15d/

Using a module as a place to store application global settings:
http://groups.google.com/group/comp.lang.python/t/23e21edf1b232b32/

A simple list comprehension question leads to discuss mutability,
identity, and Cousin Chuy's Super-Burritos:
http://groups.google.com/group/comp.lang.python/t/17cfd91ece6ed54f/

Combining map, zip and filter into an equivalent list comprehension:
http://groups.google.com/group/comp.lang.python/t/259976305282b0c0?q=map

timeit: make sure you actually measure what you want, and not other code:
http://groups.google.com/group/comp.lang.python/t/7ecae76e11f720ee/

Why do compiled C extensions on Windows use '.pyd' in their name instead
of '.dll'?
http://groups.google.com/group/comp.lang.python/t/c8d93871cc5f31dc/

Pyfora, a web forum about Python, was lauched recently. Will this
fragment the community?
http://groups.google.com/group/comp.lang.python/t/e6e0d99c995da697/

A guy's future book on programming Python doesn't fit standard practice
(a long thread!):
http://groups.google.com/group/comp.lang.python/t/6918784f36d147d2/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet site:
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 


Re: Pyfora, a place for python

2009-11-03 Thread Daniel Fetchinson
On 11/3/09, Diez B. Roggisch de...@nospam.web.de wrote:
 Daniel Fetchinson schrieb:
 If you have any suggestions, let me know -- this is a community
 effort!
 Suggestion: Please don't make efforts to fragment the community.
 When a community grows and consequently its needs also grow, how do
 you differentiate natural growth from fragmenting the community?

 Same question in another way: let's suppose Tim Peters sent the exact
 email the OP sent with the exact same website. Would you have
 responded to him the same way?
 Most probably not - but then because Tim certainly would have discussed
 this
 move with peers from the community, if there is a need for this kind of
 forum or not.

 Being from germany, I can say that we *have* this fragmentation, and
 frankly: I don't like it. I prefer my communication via NNTP/ML, and not
 with those visually rather noisy and IMHO suboptimal forums.

 If you prefer NNTP/ML, I'd suggest you pay attention to these channels
 only. BTW, I prefer ML also and I'm very happy with c.l.p. However
 that doesn't mean that I need to be hostile to other forms of
 communication and it doesn't mean that I need to discourage people
 from setting up other channels of communication for those folks who
 prefer them.

 Since when is the mere suggestion that fragmentation will occur and if
 that's a desirable consequence is hostile? The OP is not bound to it,
 and I also don't see the tone used by the two immediate answerers being
 hostile. Paul might have been terse - but hostility looks different IMHO.

I was referring to this comment by Ben:

Suggestion: Please don't make efforts to fragment the community.

This IMHO is hostile, because it presupposes that the mere goal of the
OP is fragmenting the community, which is something negative, i.e. it
contains negative prejudice. What I would have written in Ben's place:

Have you considered the possibility that your website will further
fragment the community?

This wouldn't have been hostile, IMHO.

 The OP *might* come to the conclusion that further fragmenting the
 community isn't within his personal goals either. OTOH, he might also
 simply think that once his forum gained traction, he can switch on the
 google ads, and cash in. Which a forum announced by Tim Peters, run
 under python.org wouldn't I'd say.

 If new channels open up for others it will not make c.l.p any worse.

 It will, if they catch on. As some competent people will move away.

Competent people will only move away if the website is
great/fun/useful/etc. In which case we should welcome it, since
something great/fun/useful/etc is a good thing. If it's not
great/fun/useful/etc competent people will not move away, in which
case c.l.p. will not be any worse as a result of launching the new
website.

 Again, this is the case in the german python scene, and it plain sucks.
 We have a ML, a NG, and a forum. None of them is synchronized in any
 way. We wanted to do this for ML and NG - but the guy responsible for
 the ML can't be reached, or refuses to answer.

Welcome to open source, the world of infinitely many forks, code
variants, MLs, forums, NGs, websites, in other words, welcome to the
bazaar!

Cheers,
Daniel

 If we had only one source, fragmentation wouldn't occur, and the
 competence would be bundled. That I personally prefer MLs and NGs
 doesn't mean that I wouldn't turn to the forum if it was *the* way to
 talk about Python. But as it stands, there are three kind of things, of
 which I'm already subsribed to two - and am annoyed of people posting
 questions in both of them.

 Now, I can't do anything about it in the sense that I can forbid it. But
 questioning the move to create a new form of exchange (especially
 something rather uninspired, in contrast to e.g. stackoverflow) I can.

 If enough people like c.l.p. it will continue to be a good channel, if
 too many too good people switch to an online forum, well, in that case
 c.l.p. will cease to be great, but it won't be because of artificial
 fragmentation by somebody but because the people started to prefer
 online forums (words like free market come to mind :))

 Yes. Or all of them suck equally. Free market again. I'm not against it,
 but asking the OP if he really thinks the value of his forum outweighs
 the risk of making existing fora worse is a valid question. Free speech,
 one other nice free thing out there.

 I generally not register on any online forum and will most probably
 not register on pyfora either. But I know for a fact that many people
 prefer forums over ML and why shouldn't those people be happy with the
 communication platform they like and why shouldn't they be given a
 chance to join the python community if the only reason they stayed
 away was that they didn't like c.l.p. for one reason or another?

 E.g. it
 requires much more effort to get to know what new discussions arose, as
 well as following ongoing ones - because the interface lacks a
 comprehensive overview of that, and features 

Re: Help resolve a syntax error on 'as' keyword (python 2.5)

2009-11-03 Thread Vladimir Ignatov
Hi,

except Exception as variable

is a new python-3 syntax.

You should use except Exception, variable syntax in 2.x series.

Vladimir Ignatov



On Tue, Nov 3, 2009 at 4:06 PM, Oltmans rolf.oltm...@gmail.com wrote:
 Hi, all. All I'm trying to do is to print the error message using the
 following code (copying/pasting from IDLE).

 def div(a,b):
        print a/b


 try:
    div(5,0)
 except Exception as msg:
    print msg

 but IDLE says (while highlighting the 'as' keyword)
 except Exception as msg:

 SyntaxError: invalid syntax

 I've searched the internet and I'm not sure what can cause this. Any
 help is highly appreciated. I'm using Python 2.5 on Windows XP.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sqlite3. Substitution of names in query.

2009-11-03 Thread Carsten Haese
Lawrence D'Oliveiro wrote:
 In message mailman.2504.1257216390.2807.python-l...@python.org, Carsten 
 Haese wrote:
 
 With all due respect, but if your experience is exclusive to
 MySQL/MySQLdb, your experience means very little for database
 programming practices in general.
 
 I wonder about the veracity of your claims, because:

 And here are the corresponding results on my laptop:
 $ python -mtimeit -s from querytest import Tester; t=Tester()
 't.with_params()'
 1 loops, best of 3: 20.9 usec per loop
 $ python -mtimeit -s from querytest import Tester; t=Tester()
 't.without_params()'
 1 loops, best of 3: 36.2 usec per loop
 
 Didn't you say previously that there should be a seven orders of magnitude 
 difference? What happened to that claim?

That claim was an exaggeration I resorted to after you distorted the
concept of choosing the right tool for the job into premature
optimization. It wasn't my initial claim.

The seven orders (which is actually log-10 orders of however often the
same query is executed with different values) is of course only the cost
increase on parsing the query itself, which as you pointed out is
drowned out by other fixed costs associated with performing database
queries. However, you can't dispute the fact that using string
interpolation *is* in general less efficient than parameter binding, and
that was my initial claim.

--
Carsten Haese
http://informixdb.sourceforge.net

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


Re: Help resolve a syntax error on 'as' keyword (python 2.5)

2009-11-03 Thread Xavier Ho
I don't have Python 25 on my computer, but since codepad.org is using Python
2.5.1, I did a quick test:

# input
try:
raise Exception(Mrraa!)
except Exception as msg:
print msg

# output
t.py:3: Warning: 'as' will become a reserved keyword in Python 2.6
  Line 3
except Exception as msg:
  ^
SyntaxError: invalid syntax

#

Well that's interesting. as isn't a keyword yet in Python 2.5.

This works though, and I think it fits the specification in the
documentation.

# input
try:
raise Exception(Mrraa!)
except Exception, msg:  # Notice it's a comma
print msg

# output
Mrraa!

##

Hope that helps,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Nov 3)

2009-11-03 Thread Cameron Laird
QOTW:  I consider import * the first error to be fixed ... -
Robert
Kern, author of PyFlakes, a potential replacement for Pylint and
Pychecker,
on his personal style
http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2


Python 2.6.4 is out; it fixes some small but important bugs in
previous 2.6.3 release:
http://groups.google.com/group/comp.lang.python/t/44f4c166de5e6703/

PEP391: A new way to configure Python logging, using dictionaries:
http://groups.google.com/group/comp.lang.python/t/3fc3138c22a50678/

Why do you use Python?
http://groups.google.com/group/comp.lang.python/t/66ccb10d2da5b740/

Is there any value in forcing one class/function per module? (long
thread):
http://groups.google.com/group/comp.lang.python/t/1e0c1e2091539512/

A review of complex solutions to an almost inexistent problem
shows
constructive criticism in action:
http://groups.google.com/group/comp.lang.python/t/d218212cabe9670b/
A user module may shadow a standard module of the same name - is
it
avoidable?
http://groups.google.com/group/comp.lang.python/t/b31f74b6145c9d94/

copy.deepcopy() is not as deep as its name implies:
http://groups.google.com/group/comp.lang.python/t/d827fd118189fe01/

A long thread about Web development: why to use templates, and why
frameworks actually do help developers:
http://groups.google.com/group/comp.lang.python/t/367025d4d9a2e15d/

Using a module as a place to store application global settings:
http://groups.google.com/group/comp.lang.python/t/23e21edf1b232b32/

A simple list comprehension question leads to discuss mutability,
identity, and Cousin Chuy's Super-Burritos:
http://groups.google.com/group/comp.lang.python/t/17cfd91ece6ed54f/

Combining map, zip and filter into an equivalent list
comprehension:
http://groups.google.com/group/comp.lang.python/t/259976305282b0c0?q=map

timeit: make sure you actually measure what you want, and not
other code:
http://groups.google.com/group/comp.lang.python/t/7ecae76e11f720ee/

Why do compiled C extensions on Windows use '.pyd' in their name
instead
of '.dll'?
http://groups.google.com/group/comp.lang.python/t/c8d93871cc5f31dc/

Pyfora, a web forum about Python, was lauched recently. Will this
fragment the community?
http://groups.google.com/group/comp.lang.python/t/e6e0d99c995da697/

A guy's future book on programming Python doesn't fit standard
practice
(a long thread!):
http://groups.google.com/group/comp.lang.python/t/6918784f36d147d2/



Everything Python-related you want is probably one or two clicks away
in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python
enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet site:
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions.

http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date

Although unmaintained since 2002, the Cetus 

Re: Help resolve a syntax error on 'as' keyword (python 2.5)

2009-11-03 Thread Diez B. Roggisch
Vladimir Ignatov wrote:

 Hi,
 
 except Exception as variable
 
 is a new python-3 syntax.
 
 You should use except Exception, variable syntax in 2.x series.

Not entirely true. This feature has been backported to python2.6 as well.

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


Re: Help resolve a syntax error on 'as' keyword (python 2.5)

2009-11-03 Thread Ben Finney
Oltmans rolf.oltm...@gmail.com writes:

 try:
 div(5,0)
 except Exception as msg:
 print msg

The name ‘msg’ here is misleading. The except syntax does *not* bind the
target to a message object, it binds the target to an exception object.

It would be clearer to write the above code as:

try:
div(5, 0)
except Exception as exc:
print(exc)

since the target ‘exc’ names an exception object, not a message. (The
‘print’ function will *create* a string object from the exception
object, use the string, then discard it.)

 but IDLE says (while highlighting the 'as' keyword)
 except Exception as msg:

 SyntaxError: invalid syntax

 I've searched the internet and I'm not sure what can cause this.

When you get a syntax error, you should check the syntax documentation
for the version of Python you're using.

 Any help is highly appreciated. I'm using Python 2.5 on Windows XP.

The syntax above is for Python 3 only
URL:http://docs.python.org/3.1/reference/compound_stmts.html#try.

In Python 2.5.4, the ‘try … except’ syntax was different
URL:http://www.python.org/doc/2.5.4/ref/try.html, and ‘print’ was not
implemented as a function, but instead as a keyword
URL:http://www.python.org/doc/2.5.4/ref/print.html. Use this form:

try:
div(5, 0)
except Exception, exc:
print exc

-- 
 \   “When I get new information, I change my position. What, sir, |
  `\ do you do with new information?” —John Maynard Keynes |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Handling large datastore search

2009-11-03 Thread Ahmed Barakat
In case I have a  huge datastore (1 entries, each entry has like 6
properties), what is the best way
to handle the search within such a huge datastore, and what if I want to
make a generic search, for example
you write a word and i use it to search within all properties I have for all
entries?

Is the conversion to XML a good solution, or it is not?

sorry for being new to web development, and python.

Thanks in advance.

-- 

Regards,
Ahmed Barakat

http://ahmedbarakat83.blogspot.com/
Even a small step counts
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyfora, a place for python

2009-11-03 Thread Ben Finney
Daniel Fetchinson fetchin...@googlemail.com writes:

 I was referring to this comment by Ben:

 Suggestion: Please don't make efforts to fragment the community.

 This IMHO is hostile, because it presupposes that the mere goal of the
 OP is fragmenting the community

It presupposes nothing of any goal. It describes a predictable result of
the OP's efforts, and requests those efforts to cease.

So I deny the characterisation of that request as hostile.

-- 
 \ “Injustice is relatively easy to bear; what stings is justice.” |
  `\ —Henry L. Mencken |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Handling large datastore search

2009-11-03 Thread Michiel Overtoom

Ahmed Barakat wrote:

In case I have a  huge datastore (1 entries, each entry has like 6 
properties)


Can you show some sample entries?  That way we can get an idea how your 
datastore looks like.


By the way, 1 doesn't sound that much. At work I create python 
programs which do data processing and ofter have this much entries in a 
dictionary, often more.



Is the conversion to XML a good solution, or it is not?


XML is meant to be an exchange format; it is not designed for storage or 
fast retrieval.


Greetings,



--
The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing. - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehension problem

2009-11-03 Thread Scott David Daniels

Terry Reedy wrote:
What immutability has to do with identity is that 'two' immutable 
objects with the same value *may* actually be the same object, 
*depending on the particular version of a particular implementation*.





t1 = (1,2,3) # an immutable object
t2 = (1,2,3) # another immutable object


Whether or not this is 'another' object or the same object is irrelevant 
for all purposes except identity checking. It is completely up to the 
interpreter.



t1 is t2

False


In this case, but it could have been True.


t1 == t2

True


A more telling example:
 t1 = (1, 2) + (3,) # an immutable object
 t2 = (1,) + (2, 3) # another immutable object
 t1 is t2
 False
 t1 is t2
 False

Here you make obvious that (assuming an optimizer that
is not far more aggressive than Python is used to), in
order to make equal immutable values identical, you'd
have to end each operation producing an immutable result
with a search of all appropriately typed values for one
that was equal.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: import bug

2009-11-03 Thread Ask Solem
On Nov 3, 1:52 am, Carl Banks pavlovevide...@gmail.com wrote:
 On Oct 31, 7:12 am, kj no.em...@please.post wrote:





  I'm running into an ugly bug, which, IMHO, is really a bug in the
  design of Python's module import scheme.  Consider the following
  directory structure:

  ham
  |-- __init__.py
  |-- re.py
  `-- spam.py

  ...with the following very simple files:

  % head ham/*.py
  == ham/__init__.py ==

  == ham/re.py ==

  == ham/spam.py ==
  import inspect

  I.e. only ham/spam.py is not empty, and it contains the single line
  import inspect.

  If I now run the innocent-looking ham/spam.py, I get the following
  error:

  % python26 ham/spam.py
  Traceback (most recent call last):
    File ham/spam.py, line 1, in module
      import inspect
    File /usr/local/python-2.6.1/lib/python2.6/inspect.py, line 35, in 
  module
      import string
    File /usr/local/python-2.6.1/lib/python2.6/string.py, line 122, in 
  module
      class Template:
    File /usr/local/python-2.6.1/lib/python2.6/string.py, line 116, in 
  __init__
      'delim' : _re.escape(cls.delimiter),
  AttributeError: 'module' object has no attribute 'escape'

  or, similarly,

  % python3 ham/spam.py
  Traceback (most recent call last):
    File ham/spam.py, line 1, in module
      import inspect
    File /usr/local/python-3.0/lib/python3.0/inspect.py, line 36, in 
  module
      import string
    File /usr/local/python-3.0/lib/python3.0/string.py, line 104, in 
  module
      class Template(metaclass=_TemplateMetaclass):
    File /usr/local/python-3.0/lib/python3.0/string.py, line 98, in __init__
      'delim' : _re.escape(cls.delimiter),
  AttributeError: 'module' object has no attribute 'escape'

  My sin appears to be having the (empty) file ham/re.py.  So Python
  is confusing it with the re module of the standard library, and
  using it when the inspect module tries to import re.

 Python is documented as behaving this way, so this is not a bug.

 It is arguably poor design.  However, Guido van Rossum already ruled
 against using a single package for the standard library, and its not
 likely that special case code to detect accidental name-clashes with
 the standard library is going to be added, since there are legitimate
 reasons to override the standard library.

 So for better or worse, you'll just have to deal with it.

 Carl Banks

Just have to add that you're not just affected by the standard
library.
If you have a module named myapp.django, and someone writes a cool
library called
django that you want to use, you can't use it unless you rename your
local django module.


file myapp/django.py:

from django.utils.functional import curry

ImportError: No module named utils.functional

At least that's what I get, maybe there is some workaround, some way
to say this is an absolute path?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do you use python?

2009-11-03 Thread Jaime Buelta
On 1 nov, 08:54, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:
 On Sat, 31 Oct 2009 06:54:27 -0700 (PDT), Jaime Buelta
 jaime.bue...@gmail.com declaimed the following in
 gmane.comp.python.general:

  shouldn't be heard. Talks a guy that programmed a GUI on Motif using C
  (plain old C) in 2003 and takes almost forever (one year and a half),

         Lucky you...

         I emulated a Ramtek 9300 (think that was the model) graphics engine
 using GKS (for display lists, and ability to turn layers on/off
 without regenerating all the data) on top of plain DECWindows/Xt
 library, with no layout utility. Around 1990 (I date it by the fact
 that, on return from the 7 week two site deployment of the application,
 I decided my old cameras had gotten too burdensome, and bought a Canon
 EOS 10s, 35-105  100-300 lenses, and a photo vest that I could wear
 onto the flights)

         Emulation was needed as the data generation program had to have
 minimal changes -- we replaced the Ramtek library with a package that
 formatted the Ramtek instructions as text strings, sent them via VAX/VMS
 mailboxes to the emulation program... Oh, and the main data generation
 program really was a set of some 50 programs that were invoked in
 random order, each drawing certain data elements onto a single window
 -- so there had to be a common graphics application to maintain the
 window...
 --
         Wulfraed         Dennis Lee Bieber               KD6MOG
         wlfr...@ix.netcom.com   HTTP://wlfraed.home.netcom.com/

Hahahaha, I souposse that I must consider myself EXTREMELY
lucky... ;-)

Anyway, each tool has its time, and we should try to use more-or-less
adequate and available tools of our time...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-11-03 Thread mario ruggier
With respect to to original question regarding web frameworks +
database and Python 3, all the following have been available for
Python 3 since the day Python 3.0 was released:

QP, a Web Framework
http://pypi.python.org/pypi/qp/

Durus, a Python Object Database (the default in qp, for user
sessions, etc)
http://pypi.python.org/pypi/Durus/

Evoque, state-of-the-art templating engine
http://pypi.python.org/pypi/evoque/
(this one is available for py3.0 since a little later, 21-jan-2009)

All the above also runs on python 2.4 (thru to python 3)

For the record, you may see the list of all pypi packages availabe for
Python 3 at:
http://pypi.python.org/pypi?:action=browseshow=allc=533

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


Re: Pyfora, a place for python

2009-11-03 Thread Daniel Fetchinson
 I was referring to this comment by Ben:

 Suggestion: Please don't make efforts to fragment the community.

 This IMHO is hostile, because it presupposes that the mere goal of the
 OP is fragmenting the community

 It presupposes nothing of any goal. It describes a predictable result of
 the OP's efforts, and requests those efforts to cease.

 So I deny the characterisation of that request as hostile.

Probably this thread is going by far too far :) but let's see this again,

If A says to B please don't do X then A assumes that B does X.
Otherwise the request of A doesn't make sense, since it doesn't make
sense to ask somebody not to do something that he/she is not doing.

Agreed?

If no, please explain why you don't agree.

If yes, then I guess we will also agree that if A says to B please
don't make efforts to do X then request of A only makes sense if B
makes an effort to do X.

Agreed?

If no, please explain why.

If yes, great, let's continue! If A says to B please don't make
efforts to fragment the community then this request from A only makes
sense if B makes an effort to fragment the community.

Agreed?

If no, why not?

If yes, we are almost there! In our example the request of A only
makes sense if B is making an effort to fragment the community, in
other words, assuming that A tries to make a meaningful request, A is
assuming that B is making an effort to fragment the community.

Agreed?

If not, why not?

If yes, with the substitution A = Ben and B = OP we get in order for
Ben's request to make sense, Ben has to assume that the OP is making
an effort to fragment the community. This assumption on the part of
Ben, I think, is hostile, since it assumes that the OP is making an
effort to do something not nice. Whether the OP is indeed doing
something not nice, is irrelevant. If the OP does do something not
nice, the hostility is warranted. If the OP is not doing anything not
nice, the hostility is unwarranted. But the fact that Ben was hostile
is a fact :)

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


comparing alternatives to py2exe

2009-11-03 Thread Jonathan Hartley
Hi,

Recently I put together this incomplete comparison chart in an attempt
to choose between the different alternatives to py2exe:

http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdgoutput=html

Columns represent methods of deploying to end-users such that they
don't have to worry about installing Python, packages or other
dependencies. 'Bundle' represents manually bundling an interpreter
with your app. 'Bootstrap' represents a fanciful idea of mine to
include an installer that downloads and installs an interpreter if
necessary. This sounds fiddly, since it would have to install side-by-
side with any existing interpreters of the wrong version, without
breaking anything. Has anyone done this?

The remaining columns represent the projects out there I could find
which would do the bundling for me.

Are there major things I'm missing or misunderstanding?

Perhaps folks on the list would care to rate (+1/-1) rows that they
find important or unimportant, or suggest additional rows that would
be important to them. Maybe an updated and complete version of this
table would help people agree on what's important, and help the
various projects to improve faster.

Best regards,

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


pythonw.exe under Windows-7 (Won't run for one admin user)

2009-11-03 Thread SD_V897
I have a perplexing issue, I have four users set up on a W7 computer. 
The program runs fine for all users except the admin user who needs it 
for school assignments.


It's not a firewall issue as I've added localhost for pythomw.exe as allow.

I've done some data dumps using sysinternals process monitor and the 
working users create a 7.8mb dump file and the file for the broken user 
is only 1.04mb. I can send the zipped data dumps (XML) 384kb if someone 
could have a look.


Python 2.6

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


Re: Pyfora, a place for python

2009-11-03 Thread Diez B. Roggisch
 Since when is the mere suggestion that fragmentation will occur and if
 that's a desirable consequence is hostile? The OP is not bound to it,
 and I also don't see the tone used by the two immediate answerers being
 hostile. Paul might have been terse - but hostility looks different IMHO.
 
 I was referring to this comment by Ben:
 
 Suggestion: Please don't make efforts to fragment the community.
 
 This IMHO is hostile, because it presupposes that the mere goal of the
 OP is fragmenting the community, which is something negative, i.e. it
 contains negative prejudice. What I would have written in Ben's place:
 
 Have you considered the possibility that your website will further
 fragment the community?
 
 This wouldn't have been hostile, IMHO.

Well, this is *deep* into the realms of semantics and dialectics. To an
extend that personal prejudice would change the perception of the sentence.
If everything posted here (and elsewhere) had to be worded so carefully,
we'd hardly discussing anything at all.

 Competent people will only move away if the website is
 great/fun/useful/etc. In which case we should welcome it, since
 something great/fun/useful/etc is a good thing. If it's not
 great/fun/useful/etc competent people will not move away, in which
 case c.l.p. will not be any worse as a result of launching the new
 website.

There is not only the problem of people moving away - but also of them not
even finding *this* place to discuss because they found pyfora first, and
thus the danger of them getting not the good answers they are looking
for. This sometimes already happens, if one of the google ad farms out
there that tries to lure people onto their pages simply reproduces c.l.py
content - and people believe it's a genuine forum - and wonder why they
don't get answers there.

 Welcome to open source, the world of infinitely many forks, code
 variants, MLs, forums, NGs, websites, in other words, welcome to the
 bazaar!

Oh please. If every dissent on the direction of an open-source project (or
commercial one) would lead to forking, we'd end up with a lot of projects
which none of them being competitive and mature. So can we scrap this
straw-man of an argument?

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


Re: comparing alternatives to py2exe

2009-11-03 Thread Maxim Khitrov
On Tue, Nov 3, 2009 at 10:58 AM, Jonathan Hartley tart...@tartley.com wrote:
 Hi,

 Recently I put together this incomplete comparison chart in an attempt
 to choose between the different alternatives to py2exe:

 http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdgoutput=html

 Columns represent methods of deploying to end-users such that they
 don't have to worry about installing Python, packages or other
 dependencies. 'Bundle' represents manually bundling an interpreter
 with your app. 'Bootstrap' represents a fanciful idea of mine to
 include an installer that downloads and installs an interpreter if
 necessary. This sounds fiddly, since it would have to install side-by-
 side with any existing interpreters of the wrong version, without
 breaking anything. Has anyone done this?

Maybe there is a way to use Portable Python for this, but I have no
experience with it.

 The remaining columns represent the projects out there I could find
 which would do the bundling for me.

 Are there major things I'm missing or misunderstanding?

 Perhaps folks on the list would care to rate (+1/-1) rows that they
 find important or unimportant, or suggest additional rows that would
 be important to them. Maybe an updated and complete version of this
 table would help people agree on what's important, and help the
 various projects to improve faster.

 Best regards,

  Jonathan

Good work. Recently I played with cx_freeze and compared it to py2exe,
which I've been using for a while. Here are my findings:

1. I don't think cx_freeze supports single exe. I haven't even been
able to get it to append the generated library.zip file to the
executable using documented options. Other things like .pyd files
always seem to be separate. At the same time, singe executables
generated by py2exe do not always work. I have a program that works
fine on Windows XP, Vista, and 7 if it is built under XP. However, if
I build the exact same program under Windows 7, it no longer works on
Vista or XP. I'm sure it has something to do with SxS or other dll
issues.

2. For output directory structure, you are able to specify where to
put the generated executable and all of its dependencies with both
py2exe and cx_freeze. You cannot do things like put python26.dll in a
separate directory from the executable. Not sure if that is what you
are referring to.

3. py2exe does not support Python 3 (unfortunately).

4. Although cx_freeze does support optimization (-O), it's a bit
broken in that the __debug__ variable is always set to True. In other
words, the code is optimized and things like assert statements are not
executed, but conditional statements that check __debug__ == True are.
I know that py2exe does not have this problem, no experience with
other tools.

5. py2exe is capable of generating smaller executables than cx_freeze
because of the base executable size (18.5 KB vs 1.35 MB). This is
offset by the fact that py2exe saves many more standard library
components to library.zip by default. In a quick test I just ran, both
generated a package of 4.03 MB, but I can remove at least a meg from
py2exe's library.zip. Rather than distribution size, I think it
makes more sense to show overhead above the required components
(exclude minimal library.zip, python dll, and pyd files).

6. cx_freeze is as easy to use as py2exe after looking at the bundled examples.

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


Re: substituting list comprehensions for map()

2009-11-03 Thread Steven D'Aprano
On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote:

 However in this case the procedure by which we derive the value is not
 important or even interesting.  It is much more succinct to think of the
 operation as a value and express it accordingly.  There's no need to
 clutter the mind with extra name bindings and iteration keywords.  They
 won't make our idea any more clear.
 
 dot_product = map(mul, vec1, vec2)
 
 vs
 
 dot_product = [a * b for a, b in zip(vec1, vec2)]
 
 It's very clear, at least to me, what a dot-product is in this case.

Except it's not.

The dot product of two vectors returns a scalar, not another vector:
http://en.wikipedia.org/wiki/Dot_product

So what you want is:

dot_product = sum(map(mul, vec1, vec2))



 Adding in the loop construct and name bindings doesn't enhance my
 understanding of what a dot-product is.  I don't need to see the loop
 construct at all in this case.  A dot product is simply the
 multiplication of each element in a vector sequence.

What you need is to define a function dot-product, and not hijack the 
name for a local value. Then the function's implementation is irrelevant 
to you: it could use a list comp, or could use map, it could use a for-
loop, a while loop, recursion, or black magic:

scalar = dot_product(vec1, vec2)


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


Re: import from a string

2009-11-03 Thread Matt McCredie
iu2 israelu at elbit.co.il writes:

 
 Hi,
 
 Having a file called funcs.py, I would like to read it into a string,
 and then import from that string.
 That is instead of importing from the fie system, I wonder if it's
 possible to eval the text in the string and treat it as a module.
 
 For example
 
 with file('funcs.py') as f: txt = r.read()
 string_import(txt, 'funcs')  # is string_import possible?
 
 to have now a module called funcs with the functions defined in
 funcs.py.

You can do something like this:

import types
import sys

mymodule = types.ModuleType(mymodule, Optional Doc-String)

with file('funcs.py') as f: 
txt = f.read()
exec txt in globals(), mymodule.__dict__
sys.modules['mymodule'] = mymodule


Note that you shouldn't exec untrusted code.
You might also look at the __import__ funciton, which can import by python path.
You might also look at the imp module.

Matt

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


ANN: python-dBase 0.86 Released!

2009-11-03 Thread Ethan Furman

Greetings!

I am happy to announce the latest release of python-dBase (dbf for 
short)!  At this point it supports dBase III and Visual FoxPro 6 dbf files.


It's a bit quicker now since it's using array.array to hold the records 
and not strings, and the API has been standardized.  It also now has 
much better, though still basic, documentation.


It was initially written to ease transition away from vfp files, but we 
use it here everyday for processing both vfp and dBase files.


Drawbacks:
* it is not concurrent
* it does not support vfp auto-increment nor null fields
* entire table is read into memory, so large tables process slowly
* non-initialized logical fields show up as False (? == False)

Advantages:
* entire table is read into memory, so small to medium files process quickly
* memo fields (reading *and* writing) are supported
* :memory: tables can be used to hold result sets from bigger SQL tables 
to ease data access

* custom date, datetime, and time wrappers to support empty date fields
* direct translation from dbf field to python data type

To-Do:
* add an option to not keep all records in memory for large tables
* add codepage support
* add more dbf formats (dBase IV, V, 7 -- any links to these layouts 
would be /greatly/ appreciated!)


This release is available at PyPI -- just search for dbf!

As always, success stories and bug reports desired.

Happy Hacking!

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


Re: Python-URL! - weekly Python news and links (Nov 3)

2009-11-03 Thread Robert Kern

On 2009-11-03 07:29 AM, Cameron Laird wrote:

QOTW:  I consider import * the first error to be fixed ... -
Robert
Kern, author of PyFlakes, a potential replacement for Pylint and
Pychecker,
on his personal style
 http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2


I am not the author of PyFlakes. That distinction belongs to Phil Frost and 
others at Divmod.


--
Robert Kern

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

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


Re: Pyfora, a place for python

2009-11-03 Thread Ethan Furman

Daniel Fetchinson wrote:

I was referring to this comment by Ben:

Suggestion: Please don't make efforts to fragment the community.

This IMHO is hostile, because it presupposes that the mere goal of the
OP is fragmenting the community


It presupposes nothing of any goal. It describes a predictable result of
the OP's efforts, and requests those efforts to cease.

So I deny the characterisation of that request as hostile.




[mass snippitude]


If yes, with the substitution A = Ben and B = OP we get in order for
Ben's request to make sense, Ben has to assume that the OP is making
an effort to fragment the community. This assumption on the part of
Ben, I think, is hostile, since it assumes that the OP is making an
effort to do something not nice. Whether the OP is indeed doing
something not nice, is irrelevant. If the OP does do something not
nice, the hostility is warranted. If the OP is not doing anything not
nice, the hostility is unwarranted. But the fact that Ben was hostile
is a fact :)


You were doing fine until you brought in the hostility.  I must agree 
with Ben that his comment was not hostile.  It was merely a statement. 
Not an exclamation, no name calling, just a plain request rooted in reality.


And that's a fact.  ;-)

Shall we now discuss the nature of the space/time continuum and the 
exact reality of quarks?


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


Re: how to remove the same words in the paragraph

2009-11-03 Thread Peter Otten
kylin wrote:

 I want to remove all the punctuation and no need words form a string
 datasets for experiment.

 I need to remove the word if it appears in the paragraph twice. could
 some give me some clue or some useful function in the python.

 para = uI need to remove the word if it appears in the paragraph 
twice. could
... some give me some clue or some useful function in the python.
... 
 print \n.join(sorted(set(para.translate(dict.fromkeys(map(ord, 
.:,-))).split(
I
appears
clue
could
function
give
if
in
it
me
need
or
paragraph
python
remove
some
the
to
twice
useful
word


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


Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 12:14 pm, Kee Nethery k...@kagi.com wrote:
 On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote:

  En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery k...@kagi.com  
  escribió:

  I've removed all the stuff in my code and tried to distill it down  
  to just what is failing. Hopefully I have not removed something  
  essential.

 Sounds like I did remove something essential.

No, you added something that was not only inessential but caused
trouble.

  et expects bytes as input, not unicode. You're decoding too early  
  (decoding early is good, but not in this case, because et does the  
  work for you). Either feed et.XML with the bytes before decoding, or  
  reencode the received xml text in UTF-8 (since this is the declared  
  encoding).

 Here is the code that hits the URL:
          getResponse1 = urllib2.urlopen(theUrl)
          getResponse2 = getResponse1.read()
          getResponse3 = unicode(getResponse2,'UTF-8')
         theResponseXml = et.XML(getResponse3)

 So are you saying I want to do:
          getResponse1 = urllib2.urlopen(theUrl)
          getResponse4 = getResponse1.read()
         theResponseXml = et.XML(getResponse4)

You got the essence. Note: that in no way implies any approval of your
naming convention :-)

 The reason I am confused is that getResponse2 is classified as an  
 str in the Komodo IDE. I want to make sure I don't lose the non-
 ASCII characters coming from the URL.

str is all about 8-bit bytes. Your data comes from the web in 8-bit
bytes. No problem. Just don't palpate it unnecessarily.

 If I do the second set of code,  
 does elementtree auto convert the str into unicode?

Yes. See the example I gave in my earlier posting:

| ...print c.tag, repr(c.text)
| state u'\ue58d83\ue89189\ue79c8C'

That first u means the type is unicode.

 How do I deal with  
 the XML as unicode when I put it into elementtree as a string?

That's unfortunately rather ambiguous: (1) put past/present? (2)
string unicode/str? (3) what is referent of it?

All text in what et returns is unicode [*] so you read it out as
unicode (see above example) or written as unicode if you want to
change it:

your_element.text = u'a unicode object'

[*] As an optimisation, et stores strings as str objects if they
contain only ASCII bytes (and are thus losslessly convertible to
unicode). In preparation for running your code under Python 3.X, it's
best to ignore this and use unicode constants u'foo' (if you need text
constants at all) even if et would let you get away with 'foo'.

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


Freezing python files into executables

2009-11-03 Thread Girish Venkatasubramanian
Hello,
I have been using freeze.py on 32 bit linux distributions without a
problem. But recently I tried to do the same on RHEL5 x86_64 and ran
into some issues.

1) When I ran the script, I got
Error: needed directory /usr/lib/python2.4/config not found

2) Then I yum install python-devel which installed python-devel.i386
and python-devel.x86_64. Then when I tried freezing, it worked but
make barfed up a bunch of errors during ld like

/usr/bin/ld: warning: i386 architecture of input file
`/usr/lib/python2.4/config/libpython2.4.a(rangeobject.o)' is
incompatible with i386:x86-64 output

and

/usr/lib/python2.4/config/libpython2.4.a(posixmodule.o): In function
`posix_getcwd':
(.text+0x53a1): undefined reference to `PyEval_RestoreThread'

3) I tried uninstalling python-devel.i386 (retaining only the x86_64)
and freeze fails with the same error message as in 1

Any help with this is greatly appreciated.
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: elementtree XML() unicode

2009-11-03 Thread Kee Nethery


On Nov 3, 2009, at 5:27 PM, John Machin wrote:


On Nov 4, 11:01 am, Kee Nethery k...@kagi.com wrote:

Having an issue with elementtree XML() in python 2.6.4.

This code works fine:

  from xml.etree import ElementTree as et
  getResponse = u'''?xml version=1.0 encoding=UTF-8?
customershippingstatebobble/statecityhead/
citystreetcity/street/shipping/customer'''
  theResponseXml = et.XML(getResponse)

This code errors out when it tries to do the et.XML()

  from xml.etree import ElementTree as et
  getResponse = u'''?xml version=1.0 encoding=UTF-8?
customershippingstate\ue58d83\ue89189\ue79c8C/statecity
\ue69f8f\ue5b882/citystreet\ue9ab98\ue58d97\ue58fb03/street/
shipping/customer'''
  theResponseXml = et.XML(getResponse)

In my real code, I'm pulling the getResponse data from a web page  
that

returns as XML and when I display it in the browser you can see the
Japanese characters in the data. I've removed all the stuff in my  
code
and tried to distill it down to just what is failing. Hopefully I  
have

not removed something essential.

Why is this not working and what do I need to do to use Elementtree
with unicode?


On Nov 4, 11:01 am, Kee Nethery k...@kagi.com wrote:

Having an issue with elementtree XML() in python 2.6.4.

This code works fine:

 from xml.etree import ElementTree as et
 getResponse = u'''?xml version=1.0 encoding=UTF-8?
customershippingstatebobble/statecityhead/
citystreetcity/street/shipping/customer'''
 theResponseXml = et.XML(getResponse)

This code errors out when it tries to do the et.XML()

 from xml.etree import ElementTree as et
 getResponse = u'''?xml version=1.0 encoding=UTF-8?
customershippingstate\ue58d83\ue89189\ue79c8C/statecity
\ue69f8f\ue5b882/citystreet\ue9ab98\ue58d97\ue58fb03/street/
shipping/customer'''
 theResponseXml = et.XML(getResponse)

In my real code, I'm pulling the getResponse data from a web page  
that

returns as XML and when I display it in the browser you can see the
Japanese characters in the data. I've removed all the stuff in my  
code
and tried to distill it down to just what is failing. Hopefully I  
have

not removed something essential.

Why is this not working and what do I need to do to use Elementtree
with unicode?


What you need to do is NOT feed it unicode. You feed it a str object
and it gets decoded according to the encoding declaration found in the
first line.


That it uses the encoding declaration found in the first line is the  
nugget of data that is not in the documentation that has stymied me  
for days. Thank you!


The other thing that has been confusing is that I've been using dump  
to view what is in the elementtree instance and the non-ASCII  
characters have been displayed as numbered  
entities (city#26575;#24066;/city) and I know that is not the  
representation I want the data to be in. A co-worker suggested that  
instead of dump that I use et.tostring(theResponseXml,  
encoding='utf-8') and then print that to see the characters. That  
process causes the non-ASCII characters to display as the glyphs I  
know them to be.


If there was a place in the official docs for me to append these  
nuggets of information to the sections for  
xml.etree.ElementTree.XML(text) and  
xml.etree.ElementTree.dump(elem) I would absolutely do so.


Thank you!
Kee Nethery



So take the str object that you get from the web (should
be UTF8-encoded already unless the header is lying), and throw that at
ET ... like this:

| Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit
(Intel)] on win32
| Type help, copyright, credits or license for more
information.
|  from xml.etree import ElementTree as et
|  ucode = u'''?xml version=1.0 encoding=UTF-8?
| ... customershipping
| ... state\ue58d83\ue89189\ue79c8C/state
| ... city\ue69f8f\ue5b882/city
| ... street\ue9ab98\ue58d97\ue58fb03/street
| ... /shipping/customer'''
|  xml= et.XML(ucode)
| Traceback (most recent call last):
|   File stdin, line 1, in module
|   File C:\python26\lib\xml\etree\ElementTree.py, line 963, in XML
| parser.feed(text)
|   File C:\python26\lib\xml\etree\ElementTree.py, line 1245, in
feed
| self._parser.Parse(data, 0)
| UnicodeEncodeError: 'ascii' codec can't encode character u'\ue58d'
in position 69: ordinal not in range(128)
| # as expected
|  strg = ucode.encode('utf8')
| # encoding as utf8 is for DEMO purposes.
| # i.e. use the original web str object, don't convert it to unicode
| # and back to utf8.
|  xml2 = et.XML(strg)
|  xml2.tag
| 'customer'
|  for c in xml2.getchildren():
| ...print c.tag, repr(c.text)
| ...
| shipping '\n'
|  for c in xml2[0].getchildren():
| ...print c.tag, repr(c.text)
| ...
| state u'\ue58d83\ue89189\ue79c8C'
| city u'\ue69f8f\ue5b882'
| street u'\ue9ab98\ue58d97\ue58fb03'
| 

By the way: (1) it usually helps to be more explicit than errors
out, preferably the exact copied/pasted output as shown above; this
is one of the rare cases where the error message 

Re: import from a string

2009-11-03 Thread Gabriel Genellina

En Tue, 03 Nov 2009 17:36:08 -0300, iu2 isra...@elbit.co.il escribió:

On Nov 3, 7:49 pm, Matt McCredie mccre...@gmail.com wrote:

iu2 israelu at elbit.co.il writes:

 Having a file called funcs.py, I would like to read it into a string,
 and then import from that string.
 That is instead of importing from the fie system, I wonder if it's
 possible to eval the text in the string and treat it as a module.



mymodule = types.ModuleType(mymodule, Optional Doc-String)
with file('funcs.py') as f:
txt = f.read()
exec txt in globals(), mymodule.__dict__
sys.modules['mymodule'] = mymodule


Thanks, it seems simpler than I thought.
I don't fully understand , though, the exec statement, how it causes
the string execute in the context of mymodule.


Sometimes you don't even require a module, and this is simpler to  
understand. Suppose you have a string like this:


txt = 
def foo(x):
  print 'x=', x

def bar(x):
  return x + x


you may execute it:

py namespace = {}
py exec txt in namespace

The resulting namespace contains the foo and bar functions, and you may  
call them:


py namespace.keys()
['__builtins__', 'foo', 'bar']
py namespace['foo']('hello')
x= hello

exec just executes the string using the given globals dictionary as its  
global namespace. Whatever is present in the dictionary is visible in the  
executed code as global variables (none in this example). The global names  
that the code creates become entries in the dictionary. (foo and bar;  
__builtins__ is an implementation detail of CPython). You may supply  
separate globals and locals dictionaries.


--
Gabriel Genellina

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


Re: Freezing python files into executables

2009-11-03 Thread Girish Venkatasubramanian
Hey Marc-Andre,
Ummm - I have installed python-devel.x86_64 and checked that the
/usr/lib64/python2.4/ is populated - anything else I can/shuld do to
check/ensure the the devel rpm is installed?
Thanks.

On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg m...@egenix.com wrote:
 Rami Chowdhury wrote:
 On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
 giris...@gmail.com wrote:

 Hello,
 I have been using freeze.py on 32 bit linux distributions without a
 problem. But recently I tried to do the same on RHEL5 x86_64 and ran
 into some issues.

 1) When I ran the script, I got
 Error: needed directory /usr/lib/python2.4/config not found


 I don't know anything about freeze.py but on 64-bit Red Hat distros
 (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-)

 This sounds a lot like a missing Python devel RPM.

 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Nov 03 2009)
 Python/Zope Consulting and Support ...        http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
 

 ::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/

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


Re: Tkinter callback arguments

2009-11-03 Thread Alf P. Steinbach

* Diez B. Roggisch:

Alf P. Steinbach schrieb:

* Diez B. Roggisch:
Your comment about computed makes it more clear what that's all 
about.

Also Bertrand Meyer (Eiffel language creator) had idea like that, he
called it referential transparency. But I think when Python has this
nice property mechanism, why do people change direct data attributes 
into
properties and not the other way around or not at all, I mean using 
only

properties for logical
data attributes  --  e.g. assuring correctness first via read-only
property?


I fail to see where read-only-ness of an attribute is a priori more 
correct

than having modifyable attributes.


No, I didn't mean that it is more correct to have an attribute as 
read-only. I meant that letting a logical data attribute start out as 
a read only property can help to ensure correctness.


Which is the same thing said with other words.


No, it's two different things.

Whether something is correct or not, it can help to ensure correctness.

For a different example of that, a formally incorrect debug thing can help to 
ensure correctness.



For example, consider two rectangle classes R1 and R2, where R2 might 
be a successor to R1, at some point in system evolution replacing R1. 
R1 has logical data members left, top, width and height, and R2 has 
logical data members left, top, right and bottom. With R1 direct 
changes of left and top keeps the rectangle's size (since that size is 
specified by width and height), while with R2 it changes the 
rectangle's size. R1 is implemented with logical data members as 
directly exposed data attributes. Some code in the system deals only 
with R1 objects and for convenience or efficiency or whatever uses 
direct modification instead of set_position method. Due to new 
requirements it instead has to deal with R2 objects, with same 
methods. But due to the direct modification of object state it now 
changes the rectangle sizes, but at first it's not noticed since the 
attempted rectangle position changes are very small. People get upset. 
The bug is fixed. Time has been wasted.


If there is need for mutable rectangles, there is need for mutable 
rectangles. Using properties instead of attributes doesn't help


In the example above using properties would have avoided the problem.

Hence your conclusion is wrong. :-)


- if you 
change semantics of something, code might break.


Yes, but that's totally out of the blue. If you, say, paint your nose bright 
green, then people might stare at it. That has nothing to do do with anything 
discussed here, and so anyone mentioning that as purportedly relevant to 
anything discussed here, would implicitly be saying I don't understand anything 
abour it, and that's effectively what you're saying, sorry.


However, I do understand what got you confused.

Changing the internal representation of a class is not to change the class' 
semantics. It belongs to the class only. Anyone availing himself or herself of 
access to that internal representation is doing something that may or may not 
work in the future and would ideally be doing it at own's risk, but as the 
example above illustrated, they're most often doing it at *other*'s risk.


And so the issue is how to get them to not do it, even when they think that 
nobody will check their code until next version of Lib XYZ comes in a year...


And that's where using properties from the start enters the picture, making it 
less convenient for those tinkerers to use internal representation details.



In Python, attributes 
are part of the public interface as long as you don't explicitly define 
them otherwise.


Not sure what that refers to.


But preliminary assumptions about what could be in some yet unseen 
future is introducing more code with more chances of errors


No not really.


, reducing 
the flexibility at the same time. I still fail to see where that's good.


Yes.

Consider the *nix convention for files, that they're just byte streams. They're 
*restricted* to byte streams. That's darn inflexible, yes?


And totally ungood. :-)  (Note: irony)


Code for what you need code for. It works - in all languages, but 
especially in Python.


Whether that's good advice depends on what you're doing and in what kind of job 
setting you're doing it. For many cases it is, in essence, a very selfish way. 
It gets down to saving time *now* for increased future maintainance times for 
others, which of course is the only rational choice /if/ one is sure to get away 
with it. OK, I'm not antirely serious but it sounds like you're thinking in this 
way, to some degree. But check out any debate on Python vs. Perl, in particular 
about maintainability.



Cheers  hth.,

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


how to remove the punctuation and no need words from paragraphs

2009-11-03 Thread kylin
I want to remove all the punctuation and no need words form a string
datasets for experiment.

I am new to python, please give me some clue and direction to write
this code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Handling large datastore search

2009-11-03 Thread Dave Angel

Ahmed Barakat wrote:

In case I have a  huge datastore (1 entries, each entry has like 6
properties), what is the best way
to handle the search within such a huge datastore, and what if I want to
make a generic search, for example
you write a word and i use it to search within all properties I have for all
entries?

Is the conversion to XML a good solution, or it is not?

sorry for being new to web development, and python.

Thanks in advance.

  
I don't see anything about your query which is specific to web 
development, and there's no need to be apologetic for being new anyway.


One person's huge is another person's pretty large.  I'd say 1 
items is pretty small if you're working on the desktop, as you can 
readily hold all the data in memory.  I edit text files bigger than 
that.   But I'll assume your data really is huge, or will grow to be 
huge, or is an environment which treats it as huge.


When you're parsing large amounts of data, there are always tradeoffs 
between performance and other characteristics, usually size and 
complexity.  If you have lots of data, you're probably best off by using 
a standard code system -- a real database.  The developers of such 
things have decades of experience in making certain things fast, 
reliable, and self-consistent.


But considering only speed here, I have to point out that you have to 
understand databases, and your particular model of database, pretty well 
to really benefit from all the performance tricks in there.  Keeping it 
abstract, you specify what parts of the data you care about fast random 
access to.  If you want fast search access to all of it, your database 
will generally be huge, and very slow to updates.  And the best way to 
avoid that is to pick a database mechanism that best fits your search 
mechanism.   I hate to think how many man-centuries Google has dedicated 
to getting fast random word access to its *enormous* database.  I'm sure 
they did not build on a standard relational model.


If you plan to do it yourself, I'd say the last thing you want to do is 
use XML.  XML may be convenient way to store self-describing data, but 
it's not quick to parse large amounts of it.  Instead, store the raw 
data in text form, with separate index files describing what is where.  
Anything that's indexed will be found rapidly, while anything that isn't 
will require search of the raw data.


There are algorithms for searching raw data that are faster than 
scanning every byte, but a relevant index will almost always be faster.


DaveA

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


Calendar Problem

2009-11-03 Thread Victor Subervi
Hi;
I have the following:

import calendar, datetime

myCal = calendar.calendar(6)
today = datetime.date.today()
day = today.day
mo = today.month
yr = today.year
month = myCal.monthdayscalendar(yr, mo)

The last line throws errors no matter how I try and tweak it. The current
incarnation complains about myCal being a string. What do?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: elementtree XML() unicode

2009-11-03 Thread Gabriel Genellina

En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery k...@kagi.com escribió:


Having an issue with elementtree XML() in python 2.6.4.

This code works fine:

  from xml.etree import ElementTree as et
  getResponse = u'''?xml version=1.0 encoding=UTF-8?  
customershippingstatebobble/statecityhead/ 
citystreetcity/street/shipping/customer'''

  theResponseXml = et.XML(getResponse)

This code errors out when it tries to do the et.XML()

  from xml.etree import ElementTree as et
  getResponse = u'''?xml version=1.0 encoding=UTF-8?  
customershippingstate\ue58d83\ue89189\ue79c8C/statecity 
\ue69f8f\ue5b882/citystreet\ue9ab98\ue58d97\ue58fb03/street/ 
shipping/customer'''

  theResponseXml = et.XML(getResponse)

In my real code, I'm pulling the getResponse data from a web page that  
returns as XML and when I display it in the browser you can see the  
Japanese characters in the data. I've removed all the stuff in my code  
and tried to distill it down to just what is failing. Hopefully I have  
not removed something essential.


Why is this not working and what do I need to do to use Elementtree with  
unicode?


et expects bytes as input, not unicode. You're decoding too early  
(decoding early is good, but not in this case, because et does the work  
for you). Either feed et.XML with the bytes before decoding, or reencode  
the received xml text in UTF-8 (since this is the declared encoding).


--
Gabriel Genellina

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


Re: Cast into custom type

2009-11-03 Thread Gabriel Genellina
En Tue, 03 Nov 2009 09:07:01 -0300, Henning Bredel henning.bre...@gmx.de  
escribió:

On Tue, 03 Nov 2009 10:18:29 +, Steven D'Aprano wrote:



You need to give some actual examples of what you are trying to do, and
what you are expecting to happen. How is initialized() being called?


Example: Assume a framework which offers common functionality for a  
plugin

or a module a user can choose at the beginning. The framework does not
know the concrete type of the plugin so it is possible to extend it by
implementing a well known interface or abstract class.

The framework reads the plugin directory, loads each module and creates
buttons for each plugin with a callback method for initializing. To use
common functionality of the framework, initialization method takes it as
the parent parameter.


Then forget about the code you read in that blog post, doesn't apply to  
your use case.



I think this listing makes the most sense to you:

  # initialize all plugins
  self._plugin_modules = _load_plugins() # imp loading here
  LOGGER.debug(ActionProvider.plugins) # print what was loaded
  for plugin in ActionProvider.plugins: # create button for each
  app_button = gtk.Button(plugin.title)
  LOGGER.debug('Title of plugin: %s' % plugin.title)
  app_button.connect(clicked,
 plugin.initialize(plugin, self),
 None)
  self.set_canvas(app_button)
  app_button.show()


Try something like this:

--- begin plugin.py ---
class Plugin(object):
Every plugin class should have a docstring
def __init__(self, manager):
pass
--- end plugin.py ---

--- begin pluginmgr.py --
import os.path
from glob import glob
from plugin import Plugin

class PluginManager:
def __init__(self, plugin_directory):
self.plugin_directory = plugin_directory
self.plugins = []

def load_all(self):
for fn in glob(os.path.join(self.plugin_directory, '*.py')):
namespace = {}
execfile(fn, namespace)
for name, obj in namespace.items():
if (isinstance(obj, type) and
issubclass(obj, Plugin) and
obj is not Plugin):
# obj is a Plugin subclass
cls = obj
print cls.__name__, fn
print cls.__doc__
print
plugin = cls(self)  # call the constructor
self.plugins.append(plugin)

if __name__ == '__main__':
mgr = PluginManager(r'd:\\temp\\plugins')
mgr.load_all()
print mgr.plugins
--- end pluginmgr.py ---

--- begin one.py in the plugins directory ---
from plugin import Plugin

class MyPlugin(Plugin):
The most wonderful plugin in the world.
This plugin does this, and that,
and also that, too.
It's very nice, I assure you.

class Second(Plugin):
My second plugin. I don't know what
is this for, but it works.
--- end one.py ---

Plugin is the base class; all plugins must inherit from it. PluginMgr  
scans the plugin directory, executes all modules it finds there (be  
careful...), and looks for Plugin subclasses. Then creates an instance of  
each Plugin subclass.


--
Gabriel Genellina

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


how to remove the same words in the paragraph

2009-11-03 Thread kylin
I need to remove the word if it appears in the paragraph twice. could
some give me some clue or some useful function in the python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import from a string

2009-11-03 Thread iu2
On Nov 3, 7:49 pm, Matt McCredie mccre...@gmail.com wrote:
 iu2 israelu at elbit.co.il writes:



  Hi,

  Having a file called funcs.py, I would like to read it into a string,
  and then import from that string.
  That is instead of importing from the fie system, I wonder if it's
  possible to eval the text in the string and treat it as a module.

  For example

  with file('funcs.py') as f: txt = r.read()
  string_import(txt, 'funcs')  # is string_import possible?

  to have now a module called funcs with the functions defined in
  funcs.py.

 You can do something like this:

 import types
 import sys

 mymodule = types.ModuleType(mymodule, Optional Doc-String)

 with file('funcs.py') as f:
     txt = f.read()
 exec txt in globals(), mymodule.__dict__
 sys.modules['mymodule'] = mymodule

 Note that you shouldn't exec untrusted code.
 You might also look at the __import__ funciton, which can import by python 
 path.
 You might also look at the imp module.

 Matt

Thanks, it seems simpler than I thought.
I don't fully understand , though, the exec statement, how it causes
the string execute in the context of mymodule.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyfora, a place for python

2009-11-03 Thread Rhodri James
On Tue, 03 Nov 2009 15:58:30 -, Daniel Fetchinson  
fetchin...@googlemail.com wrote:



If yes, we are almost there! In our example the request of A only
makes sense if B is making an effort to fragment the community, in
other words, assuming that A tries to make a meaningful request, A is
assuming that B is making an effort to fragment the community.


You are assuming here that B is intending his efforts to do X, and
that A believes this to be the case.  That's the assumption where
your chain of logic fails; it is entirely possible that A's statement
is abridging a chain of logic that B hasn't considered, and that A
is making no assumption of any kind concerning B's intent.

Say hello to the Law of Unintended Consequences.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freezing python files into executables

2009-11-03 Thread Rami Chowdhury
On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian  
giris...@gmail.com wrote:



Hello,
I have been using freeze.py on 32 bit linux distributions without a
problem. But recently I tried to do the same on RHEL5 x86_64 and ran
into some issues.

1) When I ran the script, I got
Error: needed directory /usr/lib/python2.4/config not found



I don't know anything about freeze.py but on 64-bit Red Hat distros (RHEL,  
Fedora, etc) it should be /usr/lib64/python2.4/config :-)



--
Rami Chowdhury
Never attribute to malice that which can be attributed to stupidity --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: comparing alternatives to py2exe

2009-11-03 Thread iu2
On Nov 3, 5:58 pm, Jonathan Hartley tart...@tartley.com wrote:
 Hi,

 Recently I put together this incomplete comparison chart in an attempt
 to choose between the different alternatives to py2exe:

 http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdgoutput...

 Columns represent methods of deploying to end-users such that they
 don't have to worry about installing Python, packages or other
 dependencies. 'Bundle' represents manually bundling an interpreter
 with your app. 'Bootstrap' represents a fanciful idea of mine to
 include an installer that downloads and installs an interpreter if
 necessary. This sounds fiddly, since it would have to install side-by-
 side with any existing interpreters of the wrong version, without
 breaking anything. Has anyone done this?

 The remaining columns represent the projects out there I could find
 which would do the bundling for me.

 Are there major things I'm missing or misunderstanding?

 Perhaps folks on the list would care to rate (+1/-1) rows that they
 find important or unimportant, or suggest additional rows that would
 be important to them. Maybe an updated and complete version of this
 table would help people agree on what's important, and help the
 various projects to improve faster.

 Best regards,

   Jonathan

Another thing that I think is of interest is whether the application
support modifying the version and description of the exe (that is, on
Windows, when you right-click on an application and choose
'properties' you view the version number and description of the
application, it is a resource inside the exe). I think py2exe supports
it.
-- 
http://mail.python.org/mailman/listinfo/python-list


elementtree XML() unicode

2009-11-03 Thread Kee Nethery

Having an issue with elementtree XML() in python 2.6.4.

This code works fine:

 from xml.etree import ElementTree as et
 getResponse = u'''?xml version=1.0 encoding=UTF-8?  
customershippingstatebobble/statecityhead/ 
citystreetcity/street/shipping/customer'''

 theResponseXml = et.XML(getResponse)

This code errors out when it tries to do the et.XML()

 from xml.etree import ElementTree as et
 getResponse = u'''?xml version=1.0 encoding=UTF-8?  
customershippingstate\ue58d83\ue89189\ue79c8C/statecity 
\ue69f8f\ue5b882/citystreet\ue9ab98\ue58d97\ue58fb03/street/ 
shipping/customer'''

 theResponseXml = et.XML(getResponse)

In my real code, I'm pulling the getResponse data from a web page that  
returns as XML and when I display it in the browser you can see the  
Japanese characters in the data. I've removed all the stuff in my code  
and tried to distill it down to just what is failing. Hopefully I have  
not removed something essential.


Why is this not working and what do I need to do to use Elementtree  
with unicode?


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


Re: elementtree XML() unicode

2009-11-03 Thread Kee Nethery


On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote:

En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery k...@kagi.com  
escribió:


I've removed all the stuff in my code and tried to distill it down  
to just what is failing. Hopefully I have not removed something  
essential.


Sounds like I did remove something essential.



et expects bytes as input, not unicode. You're decoding too early  
(decoding early is good, but not in this case, because et does the  
work for you). Either feed et.XML with the bytes before decoding, or  
reencode the received xml text in UTF-8 (since this is the declared  
encoding).


Here is the code that hits the URL:
getResponse1 = urllib2.urlopen(theUrl)
getResponse2 = getResponse1.read()
getResponse3 = unicode(getResponse2,'UTF-8')
theResponseXml = et.XML(getResponse3)

So are you saying I want to do:
getResponse1 = urllib2.urlopen(theUrl)
getResponse4 = getResponse1.read()
theResponseXml = et.XML(getResponse4)

The reason I am confused is that getResponse2 is classified as an  
str in the Komodo IDE. I want to make sure I don't lose the non- 
ASCII characters coming from the URL. If I do the second set of code,  
does elementtree auto convert the str into unicode? How do I deal with  
the XML as unicode when I put it into elementtree as a string?


Very confusing. Thanks for the help.

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


Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 1:06 pm, Kee Nethery k...@kagi.com wrote:
 On Nov 3, 2009, at 5:27 PM, John Machin wrote:



  On Nov 4, 11:01 am, Kee Nethery k...@kagi.com wrote:

  Why is this not working and what do I need to do to use Elementtree
  with unicode?

  What you need to do is NOT feed it unicode. You feed it a str object
  and it gets decoded according to the encoding declaration found in the
  first line.

 That it uses the encoding declaration found in the first line is the  
 nugget of data that is not in the documentation that has stymied me  
 for days. Thank you!

And under the don't repeat principle, it shouldn't be in the
Elementtree docs; it's nothing special about ET -- it's part of the
definition of an XML document (which for universal loss-free
transportability naturally must be encoded somehow, and the document
must state what its own encoding is (if it's not the default
(UTF-8))).

 The other thing that has been confusing is that I've been using dump  
 to view what is in the elementtree instance and the non-ASCII  
 characters have been displayed as numbered  
 entities (city#26575;#24066;/city) and I know that is not the  
 representation I want the data to be in. A co-worker suggested that  
 instead of dump that I use et.tostring(theResponseXml,  
 encoding='utf-8') and then print that to see the characters. That  
 process causes the non-ASCII characters to display as the glyphs I  
 know them to be.

 If there was a place in the official docs for me to append these  
 nuggets of information to the sections for  
 xml.etree.ElementTree.XML(text) and  
 xml.etree.ElementTree.dump(elem) I would absolutely do so.

I don't understand ... tostring() is in the same section as dump(),
about two screen-heights away. You want to include the tostring() docs
in the dump() docs? The usual idea is not to get bogged down in the
first function that looks at first glance like it might do what you
want (look at the glyphs) but doesn't (it writes a (transportable)
XML stream) but press on to the next plausible candidate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: self.__dict__ tricks

2009-11-03 Thread Rami Chowdhury
On Tue, 03 Nov 2009 09:59:32 -0800, Ethan Furman et...@stoneleaf.us  
wrote:



Simon Brunning wrote:

2009/11/1 Steven D'Aprano st...@remove-this-cybersource.com.au:


The only stupid question is the one you are afraid to ask.
  I was once asked, and I quote exactly, are there any fish in the  
Atlantic sea?

 That's pretty stupid. ;-)



Are there any fish in the Dead Sea?



Depends on how you define fish, surely ;-)?



--
Rami Chowdhury
Never attribute to malice that which can be attributed to stupidity --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freezing python files into executables

2009-11-03 Thread Rami Chowdhury
On Tue, 03 Nov 2009 11:57:17 -0800, Girish Venkatasubramanian  
giris...@gmail.com wrote:



I checked and ls /usr/lib64/python2.4/config/ returns
config.c config.c.in install-sh libpython2.4.a Makefile makesetup
python.o Setup Setup.config Setup.local

so I am guessing the python-devel installation went off OK, from what  
you say.


I looked at the freeze.py code and I see your point. But for tweaking,
I would need to know what modules should get included from lib64
instead of lib and hardcode them 
Maybe tinkering around with the makefile which is produced by freeze
is a better way to go?

But since I need to freeze this python code by today, can you suggest
any other tool to do this?



I believe /usr/lib64 on a 64-bit RHEL will contain everything you need ;  
can you try just changing the directory freeze.py looks at to 'lib64', and  
see if the freeze works?




On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg m...@egenix.com wrote:

Girish Venkatasubramanian wrote:

Hey Marc-Andre,
Ummm - I have installed python-devel.x86_64 and checked that the
/usr/lib64/python2.4/ is populated - anything else I can/shuld do to
check/ensure the the devel rpm is installed?


If you have the config/ sub-dir in there, things should be
fine.

However, it's possible that you need to tweek the freeze.py
script a little, since RedHat chose to split the Python
installation on x64 in two parts and they may have missed
patching freeze.py as well:

The platform independent parts are in /usr/lib, whereas the
platform dependent parts are in /usr/lib64.

Python normally doesn't support this. It only has a
prefix and an exec_prefix, but those only allow to do
things like prefix=/usr and exec_prefix=/usr64, not
changing the lib/ part in /usr/lib/.


Thanks.

On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg m...@egenix.com wrote:

Rami Chowdhury wrote:

On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
giris...@gmail.com wrote:


Hello,
I have been using freeze.py on 32 bit linux distributions without a
problem. But recently I tried to do the same on RHEL5 x86_64 and ran
into some issues.

1) When I ran the script, I got
Error: needed directory /usr/lib/python2.4/config not found



I don't know anything about freeze.py but on 64-bit Red Hat distros
(RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-)


This sounds a lot like a missing Python devel RPM.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 03  
2009)
Python/Zope Consulting and Support ...        
 http://www.egenix.com/
mxODBC.Zope.Database.Adapter ...              
http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...        
 http://python.egenix.com/



::: Try our new mxODBC.Connect Python Database Interface for free !  




  eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
   D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
          Registered at Amtsgericht Duesseldorf: HRB 46611
              http://www.egenix.com/company/contact/



--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 03 2009)

Python/Zope Consulting and Support ...        http://www.egenix.com/
mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/



::: Try our new mxODBC.Connect Python Database Interface for free ! 


  eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
   D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
          Registered at Amtsgericht Duesseldorf: HRB 46611
              http://www.egenix.com/company/contact/





--
Rami Chowdhury
Never attribute to malice that which can be attributed to stupidity --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: self.__dict__ tricks

2009-11-03 Thread Steven D'Aprano
On Tue, 03 Nov 2009 11:26:49 +, Simon Brunning wrote:

 2009/11/1 Steven D'Aprano st...@remove-this-cybersource.com.au:

 The only stupid question is the one you are afraid to ask.
 
 I was once asked, and I quote exactly, are there any fish in the
 Atlantic sea?
 
 That's pretty stupid. ;-)

Once in the distant past, there were no fish in what would become the 
Atlantic Ocean (not sea); and some day in the future there won't be any 
fish either. At the rate we're going that day may not be that far away: 
fish are being over-fished all over the world, jellyfish are blooming, 
and there are areas of the Namibian continental where the dominant 
species have flipped from fish to jellyfish:

http://www.scienceinafrica.co.za/2009/september/jellyfish.htm
http://www.sciencedaily.com/releases/2006/07/060711091411.htm
http://www.sciencedaily.com/releases/2009/06/090609092057.htm


So, no, not a stupid question at all.



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


Re: elementtree XML() unicode

2009-11-03 Thread Gabriel Genellina

En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery k...@kagi.com escribió:

If there was a place in the official docs for me to append these nuggets  
of information to the sections for xml.etree.ElementTree.XML(text) and  
xml.etree.ElementTree.dump(elem) I would absolutely do so.


http://bugs.python.org/ applies to documentation too.

--
Gabriel Genellina

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


Re: how to remove the same words in the paragraph

2009-11-03 Thread Andre Engels
On Tue, Nov 3, 2009 at 11:13 PM, kylin huili.s...@gmail.com wrote:
 I need to remove the word if it appears in the paragraph twice. could
 some give me some clue or some useful function in the python.

Well, it depends a bit on what you call 'the same word' (In the
paragraph Fly fly, fly! does the word fly occur 0, 1, 2 or 3
times?), but the split() function seems a logical choice to use
whatever the answer to that question.


-- 
André Engels, andreeng...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonw.exe under Windows-7 (Won't run for one admin user)

2009-11-03 Thread Rhodri James

On Tue, 03 Nov 2009 16:00:16 -, SD_V897 sd_v...@nosuchmail.com wrote:

I have a perplexing issue, I have four users set up on a W7 computer.  
The program runs fine for all users except the admin user who needs it  
for school assignments.


A little more information, please.  How does it not work for the admin
user?  Is there a traceback?  What do you get if you try to invoke it
from a command line?

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: chr / ord

2009-11-03 Thread Sean McIlroy

thanks. that did the trick. in case anyone else is in the same boat as
myself, here are the relevant correspondences:

string - [int] bytes - [int]
---
--

lambda string: [ord(x) for x in string]   list
lambda ints: ''.join([chr(x) for x in ints])  bytes

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


Re: how to remove the same words in the paragraph

2009-11-03 Thread Tim Chase

kylin wrote:

I need to remove the word if it appears in the paragraph twice. could
some give me some clue or some useful function in the python.


Sounds like homework.  To fail your class, use this one:

 p = one two three four five six seven three four eight
 s = set()
 print ' '.join(w for w in p.split() if not (w in s or s.add(w)))
one two three four five six seven eight

which is absolutely horrible because it mutates the set within 
the list comprehension.  The passable solution would use a 
for-loop to iterate over each word in the paragraph, emitting it 
if it hadn't already been seen.  Maintain those words in set, so 
your words know how not to be seen. (Mr. Nesbitt, would you 
please stand up?)


This also assumes your paragraph consists only of words and 
whitespace.  But since you posted your previous homework-sounding 
question on stripping out non-word/whitespace characters, you'll 
want to look into using a regexp like [\w\s] to clean up the 
cruft in the paragraph.  Neither solution above preserves non 
white-space/word characters, for which I'd recommend using a 
re.sub() with a callback.  Such a callback class might look 
something like


 class Dedupe:
... def __init__(self):
... self.s = set()
... def __call__(self, m):
... w = m.group(0)
... if w in self.s: return ''
... self.s.add(w)
... return w
...
 r.sub(Dedupe(), p)

where I leave the definition of r to the student.  Also beware 
of case-differences for which you might have to normalize.


You'll also want to use more descriptive variable names than my 
one-letter tokens.


-tkc




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


Re: Freezing python files into executables

2009-11-03 Thread Girish Venkatasubramanian
Will try that.

Meanwhile I went ahead and used cx_freeze and that seems to work OK.

Thanks for your help Rami and Marc-Andre.

On Tue, Nov 3, 2009 at 12:31 PM, Rami Chowdhury
rami.chowdh...@gmail.com wrote:
 On Tue, 03 Nov 2009 11:57:17 -0800, Girish Venkatasubramanian
 giris...@gmail.com wrote:

 I checked and ls /usr/lib64/python2.4/config/ returns
 config.c config.c.in install-sh libpython2.4.a Makefile makesetup
 python.o Setup Setup.config Setup.local

 so I am guessing the python-devel installation went off OK, from what you
 say.

 I looked at the freeze.py code and I see your point. But for tweaking,
 I would need to know what modules should get included from lib64
 instead of lib and hardcode them 
 Maybe tinkering around with the makefile which is produced by freeze
 is a better way to go?

 But since I need to freeze this python code by today, can you suggest
 any other tool to do this?


 I believe /usr/lib64 on a 64-bit RHEL will contain everything you need ; can
 you try just changing the directory freeze.py looks at to 'lib64', and see
 if the freeze works?


 On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg m...@egenix.com wrote:

 Girish Venkatasubramanian wrote:

 Hey Marc-Andre,
 Ummm - I have installed python-devel.x86_64 and checked that the
 /usr/lib64/python2.4/ is populated - anything else I can/shuld do to
 check/ensure the the devel rpm is installed?

 If you have the config/ sub-dir in there, things should be
 fine.

 However, it's possible that you need to tweek the freeze.py
 script a little, since RedHat chose to split the Python
 installation on x64 in two parts and they may have missed
 patching freeze.py as well:

 The platform independent parts are in /usr/lib, whereas the
 platform dependent parts are in /usr/lib64.

 Python normally doesn't support this. It only has a
 prefix and an exec_prefix, but those only allow to do
 things like prefix=/usr and exec_prefix=/usr64, not
 changing the lib/ part in /usr/lib/.

 Thanks.

 On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg m...@egenix.com wrote:

 Rami Chowdhury wrote:

 On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
 giris...@gmail.com wrote:

 Hello,
 I have been using freeze.py on 32 bit linux distributions without a
 problem. But recently I tried to do the same on RHEL5 x86_64 and ran
 into some issues.

 1) When I ran the script, I got
 Error: needed directory /usr/lib/python2.4/config not found


 I don't know anything about freeze.py but on 64-bit Red Hat distros
 (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-)

 This sounds a lot like a missing Python devel RPM.

 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Nov 03
 2009)

 Python/Zope Consulting and Support ...        http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/


 

 ::: Try our new mxODBC.Connect Python Database Interface for free !
 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Nov 03 2009)

 Python/Zope Consulting and Support ...        http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

 

 ::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/




 --
 Rami Chowdhury
 Never attribute to malice that which can be attributed to stupidity --
 Hanlon's Razor
 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

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


fastPATX Panther for your speedy web browsing needs!

2009-11-03 Thread patx
fastPATX Panther is now out! It beats Firefox on startup and is very
lightweight you have to try it!

Download here: http://bitbucket.org/patx/fastpatx/fastpatx-panther.py

-- 
patx, python gui and web, http://patx.me
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 11:01 am, Kee Nethery k...@kagi.com wrote:
 Having an issue with elementtree XML() in python 2.6.4.

 This code works fine:

       from xml.etree import ElementTree as et
       getResponse = u'''?xml version=1.0 encoding=UTF-8?  
 customershippingstatebobble/statecityhead/
 citystreetcity/street/shipping/customer'''
       theResponseXml = et.XML(getResponse)

 This code errors out when it tries to do the et.XML()

       from xml.etree import ElementTree as et
       getResponse = u'''?xml version=1.0 encoding=UTF-8?  
 customershippingstate\ue58d83\ue89189\ue79c8C/statecity
 \ue69f8f\ue5b882/citystreet\ue9ab98\ue58d97\ue58fb03/street/
 shipping/customer'''
       theResponseXml = et.XML(getResponse)

 In my real code, I'm pulling the getResponse data from a web page that  
 returns as XML and when I display it in the browser you can see the  
 Japanese characters in the data. I've removed all the stuff in my code  
 and tried to distill it down to just what is failing. Hopefully I have  
 not removed something essential.

 Why is this not working and what do I need to do to use Elementtree  
 with unicode?

On Nov 4, 11:01 am, Kee Nethery k...@kagi.com wrote:
 Having an issue with elementtree XML() in python 2.6.4.

 This code works fine:

   from xml.etree import ElementTree as et
   getResponse = u'''?xml version=1.0 encoding=UTF-8?
 customershippingstatebobble/statecityhead/
 citystreetcity/street/shipping/customer'''
   theResponseXml = et.XML(getResponse)

 This code errors out when it tries to do the et.XML()

   from xml.etree import ElementTree as et
   getResponse = u'''?xml version=1.0 encoding=UTF-8?
 customershippingstate\ue58d83\ue89189\ue79c8C/statecity
 \ue69f8f\ue5b882/citystreet\ue9ab98\ue58d97\ue58fb03/street/
 shipping/customer'''
   theResponseXml = et.XML(getResponse)

 In my real code, I'm pulling the getResponse data from a web page that
 returns as XML and when I display it in the browser you can see the
 Japanese characters in the data. I've removed all the stuff in my code
 and tried to distill it down to just what is failing. Hopefully I have
 not removed something essential.

 Why is this not working and what do I need to do to use Elementtree
 with unicode?

What you need to do is NOT feed it unicode. You feed it a str object
and it gets decoded according to the encoding declaration found in the
first line. So take the str object that you get from the web (should
be UTF8-encoded already unless the header is lying), and throw that at
ET ... like this:

| Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit
(Intel)] on win32
| Type help, copyright, credits or license for more
information.
|  from xml.etree import ElementTree as et
|  ucode = u'''?xml version=1.0 encoding=UTF-8?
| ... customershipping
| ... state\ue58d83\ue89189\ue79c8C/state
| ... city\ue69f8f\ue5b882/city
| ... street\ue9ab98\ue58d97\ue58fb03/street
| ... /shipping/customer'''
|  xml= et.XML(ucode)
| Traceback (most recent call last):
|   File stdin, line 1, in module
|   File C:\python26\lib\xml\etree\ElementTree.py, line 963, in XML
| parser.feed(text)
|   File C:\python26\lib\xml\etree\ElementTree.py, line 1245, in
feed
| self._parser.Parse(data, 0)
| UnicodeEncodeError: 'ascii' codec can't encode character u'\ue58d'
in position 69: ordinal not in range(128)
| # as expected
|  strg = ucode.encode('utf8')
| # encoding as utf8 is for DEMO purposes.
| # i.e. use the original web str object, don't convert it to unicode
| # and back to utf8.
|  xml2 = et.XML(strg)
|  xml2.tag
| 'customer'
|  for c in xml2.getchildren():
| ...print c.tag, repr(c.text)
| ...
| shipping '\n'
|  for c in xml2[0].getchildren():
| ...print c.tag, repr(c.text)
| ...
| state u'\ue58d83\ue89189\ue79c8C'
| city u'\ue69f8f\ue5b882'
| street u'\ue9ab98\ue58d97\ue58fb03'
| 

By the way: (1) it usually helps to be more explicit than errors
out, preferably the exact copied/pasted output as shown above; this
is one of the rare cases where the error message is predictable (2)
PLEASE don't start a new topic in a reply in somebody else's thread.

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


Re: Freezing python files into executables

2009-11-03 Thread M.-A. Lemburg
Girish Venkatasubramanian wrote:
 Hey Marc-Andre,
 Ummm - I have installed python-devel.x86_64 and checked that the
 /usr/lib64/python2.4/ is populated - anything else I can/shuld do to
 check/ensure the the devel rpm is installed?

If you have the config/ sub-dir in there, things should be
fine.

However, it's possible that you need to tweek the freeze.py
script a little, since RedHat chose to split the Python
installation on x64 in two parts and they may have missed
patching freeze.py as well:

The platform independent parts are in /usr/lib, whereas the
platform dependent parts are in /usr/lib64.

Python normally doesn't support this. It only has a
prefix and an exec_prefix, but those only allow to do
things like prefix=/usr and exec_prefix=/usr64, not
changing the lib/ part in /usr/lib/.

 Thanks.
 
 On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg m...@egenix.com wrote:
 Rami Chowdhury wrote:
 On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
 giris...@gmail.com wrote:

 Hello,
 I have been using freeze.py on 32 bit linux distributions without a
 problem. But recently I tried to do the same on RHEL5 x86_64 and ran
 into some issues.

 1) When I ran the script, I got
 Error: needed directory /usr/lib/python2.4/config not found


 I don't know anything about freeze.py but on 64-bit Red Hat distros
 (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-)

 This sounds a lot like a missing Python devel RPM.

 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Nov 03 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
 

 ::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/


-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 03 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help resolve a syntax error on 'as' keyword (python 2.5)

2009-11-03 Thread Gabriel Genellina
En Tue, 03 Nov 2009 10:06:24 -0300, Oltmans rolf.oltm...@gmail.com  
escribió:



Hi, all. All I'm trying to do is to print the error message using the
following code (copying/pasting from IDLE).

try:
div(5,0)
except Exception as msg:
print msg

SyntaxError: invalid syntax

I'm using Python 2.5 on Windows XP.


Other people already told you what the problem is.
I suggest reading a book/tutorial written for the *same* Python version  
you're using (2.x; it doesn't matter 2.6, 2.5, 2.4...).
Once you know the basics of the language, you may look at the differences  
in the What's new? document for Python 3.0 - but right now, they will  
just confuse you.


--
Gabriel Genellina

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


Re: comparing alternatives to py2exe

2009-11-03 Thread Maxim Khitrov
On Tue, Nov 3, 2009 at 3:50 PM, iu2 isra...@elbit.co.il wrote:
 On Nov 3, 5:58 pm, Jonathan Hartley tart...@tartley.com wrote:
 Hi,

 Recently I put together this incomplete comparison chart in an attempt
 to choose between the different alternatives to py2exe:

 http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdgoutput...

 Columns represent methods of deploying to end-users such that they
 don't have to worry about installing Python, packages or other
 dependencies. 'Bundle' represents manually bundling an interpreter
 with your app. 'Bootstrap' represents a fanciful idea of mine to
 include an installer that downloads and installs an interpreter if
 necessary. This sounds fiddly, since it would have to install side-by-
 side with any existing interpreters of the wrong version, without
 breaking anything. Has anyone done this?

 The remaining columns represent the projects out there I could find
 which would do the bundling for me.

 Are there major things I'm missing or misunderstanding?

 Perhaps folks on the list would care to rate (+1/-1) rows that they
 find important or unimportant, or suggest additional rows that would
 be important to them. Maybe an updated and complete version of this
 table would help people agree on what's important, and help the
 various projects to improve faster.

 Best regards,

   Jonathan

 Another thing that I think is of interest is whether the application
 support modifying the version and description of the exe (that is, on
 Windows, when you right-click on an application and choose
 'properties' you view the version number and description of the
 application, it is a resource inside the exe). I think py2exe supports
 it.

py2exe supports this, cx_freeze doesn't.

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


Re: Freezing python files into executables

2009-11-03 Thread Mike Driscoll
On Nov 3, 3:23 pm, Girish Venkatasubramanian giris...@gmail.com
wrote:
 Will try that.

 Meanwhile I went ahead and used cx_freeze and that seems to work OK.

 Thanks for your help Rami and Marc-Andre.


Something that you might want to try in the future is GUI2Exe, which
allows you to play with a whole slew of freezing modules:

http://code.google.com/p/gui2exe/

I've been using it to make executables on Windows through it's py2exe
implementation.

---
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Freezing python files into executables

2009-11-03 Thread Girish Venkatasubramanian
I checked and ls /usr/lib64/python2.4/config/ returns
config.c config.c.in install-sh libpython2.4.a Makefile makesetup
python.o Setup Setup.config Setup.local

so I am guessing the python-devel installation went off OK, from what you say.

I looked at the freeze.py code and I see your point. But for tweaking,
I would need to know what modules should get included from lib64
instead of lib and hardcode them 
Maybe tinkering around with the makefile which is produced by freeze
is a better way to go?

But since I need to freeze this python code by today, can you suggest
any other tool to do this?

Thanks.

On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg m...@egenix.com wrote:
 Girish Venkatasubramanian wrote:
 Hey Marc-Andre,
 Ummm - I have installed python-devel.x86_64 and checked that the
 /usr/lib64/python2.4/ is populated - anything else I can/shuld do to
 check/ensure the the devel rpm is installed?

 If you have the config/ sub-dir in there, things should be
 fine.

 However, it's possible that you need to tweek the freeze.py
 script a little, since RedHat chose to split the Python
 installation on x64 in two parts and they may have missed
 patching freeze.py as well:

 The platform independent parts are in /usr/lib, whereas the
 platform dependent parts are in /usr/lib64.

 Python normally doesn't support this. It only has a
 prefix and an exec_prefix, but those only allow to do
 things like prefix=/usr and exec_prefix=/usr64, not
 changing the lib/ part in /usr/lib/.

 Thanks.

 On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg m...@egenix.com wrote:
 Rami Chowdhury wrote:
 On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
 giris...@gmail.com wrote:

 Hello,
 I have been using freeze.py on 32 bit linux distributions without a
 problem. But recently I tried to do the same on RHEL5 x86_64 and ran
 into some issues.

 1) When I ran the script, I got
 Error: needed directory /usr/lib/python2.4/config not found


 I don't know anything about freeze.py but on 64-bit Red Hat distros
 (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-)

 This sounds a lot like a missing Python devel RPM.

 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Nov 03 2009)
 Python/Zope Consulting and Support ...        http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
 

 ::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Nov 03 2009)
 Python/Zope Consulting and Support ...        http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
 

 ::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/

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


Re: Can I run a python program from within emacs?

2009-11-03 Thread Jean
On Nov 1, 10:15 am, rustom rustompm...@gmail.com wrote:
 On Nov 1, 7:20 pm, Robinson wanderingaen...@comcast.net wrote:

  I have also just started with both Aquamacs and Python so I ask for  
  your patience as well.
  When I evaluate the buffer (C-c C-C) I don't see any response or  
  output from my python program. Should another buffer open  
  automatically? Should a terminal window open?
  thanks for your patience.
  Rugbeia Floreat Ubique

   On Mar 20, 3:09 pm, jmDesktop needin4mat... at gmail.com wrote:
Hi, I'm trying to learn Python.  I usingAquamacan emac
implementation with mac os x.  I have a program.  If I go to the
command prompt and type pythong myprog.py, it works.  Can the  
   program
be run from within the editor or is that not how development is  
   done?

 There are two python modes -- python.el and python-mode.el
 Default with emacs is python.el, what comes from/with python is python-
 mode.el (needs a download and a couple of lines of setup 
 seehttp://www.emacswiki.org/emacs/PythonMode). I recommend python-mode.

 The key-bindings are different --C-c ! to start interpreter followed
 by C-c C-c to exec a file.

Perfect! Many thanks...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: self.__dict__ tricks

2009-11-03 Thread Ethan Furman

Simon Brunning wrote:

2009/11/1 Steven D'Aprano st...@remove-this-cybersource.com.au:


The only stupid question is the one you are afraid to ask.



I was once asked, and I quote exactly, are there any fish in the Atlantic sea?

That's pretty stupid. ;-)



Are there any fish in the Dead Sea?

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


Re: Calendar Problem

2009-11-03 Thread Dave Angel



MichaB Klich wrote:

Dnia wtorek 03 listopada 2009 o 20:50:10 Victor Subervi napisał(a):
  

Hi;
I have the following:

import calendar, datetime

myCal =alendar.calendar(6)
today =atetime.date.today()
day =oday.day
mo =oday.month
yr =oday.year
month =yCal.monthdayscalendar(yr, mo)

The last line throws errors no matter how I try and tweak it. The current
incarnation complains about myCal being a string. What do?
TIA,
Victor




You should use

myCal =calendar.Calendar(6)

This creates calendar.Calendar object.

  

Right. But I wanted to tell the OP what to do with an error like this.


You should post the actual error traceback, and tell us what version of 
Python you're using:


Traceback (most recent call last):
File M:\Programming\Python\sources\dummy\stuff2.py, line 15, in module
month = myCal.monthdayscalendar(yr, mo)
AttributeError: 'str' object has no attribute 'monthdayscalendar'


Now, since it says that myCal is a 'str' object, the next thing you 
should do is look at the value. I get an actual printable calendar for a 
year. So clearly, it's not the Calendar object you were looking for. So 
you need to change from the calendar() function to the Calendar() 
constructor.


DaveA

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


continuous return?

2009-11-03 Thread Someone Something
I'm trying to write something related to IRC. The thing is, I have one
thread receiving and another sending. But, how can I keep the caller of the
recv() function informed about what was last received so that it can all be
printed out. But, I no idea how I can accomplish this. I was thinking about
getting one variable that was constantly updated with the latest line that
was recved and that the variable would be  a member of the class so other
functions/classes can access it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Freezing python files into executables

2009-11-03 Thread M.-A. Lemburg
Rami Chowdhury wrote:
 On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
 giris...@gmail.com wrote:
 
 Hello,
 I have been using freeze.py on 32 bit linux distributions without a
 problem. But recently I tried to do the same on RHEL5 x86_64 and ran
 into some issues.

 1) When I ran the script, I got
 Error: needed directory /usr/lib/python2.4/config not found

 
 I don't know anything about freeze.py but on 64-bit Red Hat distros
 (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-)

This sounds a lot like a missing Python devel RPM.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 03 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comparing alternatives to py2exe

2009-11-03 Thread Ryan Kelly

 Recently I put together this incomplete comparison chart in an attempt
 to choose between the different alternatives to py2exe:
 
 http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdgoutput=html
 
 ...snip...

 Are there major things I'm missing or misunderstanding?

A quick note - although I haven't tried it out, the latest version of
bbfreeze claims to support OSX.


  Ryan

-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import bug

2009-11-03 Thread Gabriel Genellina
En Tue, 03 Nov 2009 12:29:10 -0300, Ask Solem askso...@gmail.com  
escribió:



If you have a module named myapp.django, and someone writes a cool
library called
django that you want to use, you can't use it unless you rename your
local django module.


file myapp/django.py:

from django.utils.functional import curry

ImportError: No module named utils.functional

At least that's what I get, maybe there is some workaround, some way
to say this is an absolute path?


Yes, that's exactly the way to solve it. Either move on to Python 3, or  
use:

from __future__ import absolute_import

When absolute imports are in effect, and assuming your code is inside a  
package, then neither import re nor from django.utils.functional import  
curry are affected by your own module names, because those statements  
imply an absolute import (absolute means that the module is searched  
along sys.path).
The only way to import a local file re.py is using from .re import  
something; the leading dot means it's a relative import (relative means  
that the module is searched in a single directory: the current package  
directory and its parents, depending on how many dots are specified)


--
Gabriel Genellina

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


Re: Freezing python files into executables

2009-11-03 Thread Girish Venkatasubramanian
Hi Rami,
Thanks for pointing this out. I did see that point - but apart from
installing python-devel (which has created and populated
/usr/lib64/python2.4/...) I am not sure what I should do - is there
some setting in python where I can ask it to look at lib64 instead of
lib?
Thanks.

On Tue, Nov 3, 2009 at 11:21 AM, Rami Chowdhury
rami.chowdh...@gmail.com wrote:
 On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian
 giris...@gmail.com wrote:

 Hello,
 I have been using freeze.py on 32 bit linux distributions without a
 problem. But recently I tried to do the same on RHEL5 x86_64 and ran
 into some issues.

 1) When I ran the script, I got
 Error: needed directory /usr/lib/python2.4/config not found


 I don't know anything about freeze.py but on 64-bit Red Hat distros (RHEL,
 Fedora, etc) it should be /usr/lib64/python2.4/config :-)


 --
 Rami Chowdhury
 Never attribute to malice that which can be attributed to stupidity --
 Hanlon's Razor
 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

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


Re: continuous return?

2009-11-03 Thread Gabriel Genellina
En Wed, 04 Nov 2009 00:20:05 -0300, Someone Something  
fordhai...@gmail.com escribió:



I'm trying to write something related to IRC. The thing is, I have one
thread receiving and another sending. But, how can I keep the caller of  
the
recv() function informed about what was last received so that it can all  
be
printed out. But, I no idea how I can accomplish this. I was thinking  
about
getting one variable that was constantly updated with the latest line  
that

was recved and that the variable would be  a member of the class so other
functions/classes can access it


I don't completely understand your scenario, but since you say you have  
several threads, a common way to communicate between them is to use a  
Queue object. Let the receiver thread put() lines into the queue, and the  
processing thread get() them and do some work.


--
Gabriel Genellina

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


unittest setup

2009-11-03 Thread Jonathan Haddad
Maybe I'm doing something wrong here, definitely not the most experienced
unit tester.

I've got a class, in the constructor it loads a CSV file from disc.  I'd
like only 1 instance of the class to be instantiated.  However, when running
multiple unit tests, multiple instances of the class are created.  What's
the best way for me to avoid this?  It takes about a few seconds to load the
CSV file.
-- 
Jonathan Haddad
http://www.rustyrazorblade.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: elementtree XML() unicode

2009-11-03 Thread Kee Nethery


On Nov 3, 2009, at 7:06 PM, Gabriel Genellina wrote:

En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery k...@kagi.com  
escribió:


If there was a place in the official docs for me to append these  
nuggets of information to the sections for  
xml.etree.ElementTree.XML(text) and  
xml.etree.ElementTree.dump(elem) I would absolutely do so.


http://bugs.python.org/ applies to documentation too.


I've submitted documentation bugs in the past and no action was taken  
on them, the bugs were closed. I'm guessing that information that  
everyone knows not being in the documentation is not a bug. It's my  
fault I'm a newbie and I accept that. Thanks to you two for helping me  
get past this block.


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


Re: unittest setup

2009-11-03 Thread Gabriel Genellina
En Wed, 04 Nov 2009 01:02:24 -0300, Jonathan Haddad j...@jonhaddad.com  
escribió:



I've got a class, in the constructor it loads a CSV file from disc.  I'd
like only 1 instance of the class to be instantiated.  However, when  
running

multiple unit tests, multiple instances of the class are created.  What's
the best way for me to avoid this?  It takes about a few seconds to load  
the

CSV file.


Use a factory function:

_instance = None
def createFoo(parameters):
  if _instance is None:
_instance = Foo(parameters)
  return _instance

and replace all occurrences of Foo(parameters) with createFoo(parameters).  
For new-style classes, you may override the __new__ method instead.


Perhaps I didn't understand your problem correctly because this is  
unrelated to unit testing...


--
Gabriel Genellina

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


Re: substituting list comprehensions for map()

2009-11-03 Thread Robert Kern

Steven D'Aprano wrote:

On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote:



Adding in the loop construct and name bindings doesn't enhance my
understanding of what a dot-product is.  I don't need to see the loop
construct at all in this case.  A dot product is simply the
multiplication of each element in a vector sequence.


What you need is to define a function dot-product, and not hijack the 
name for a local value. Then the function's implementation is irrelevant 
to you: it could use a list comp, or could use map, it could use a for-

loop, a while loop, recursion, or black magic:

scalar = dot_product(vec1, vec2)


Or use the appropriate libraries:

from numpy import dot

scalar = dot(vec1, vec2)

--
Robert Kern

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

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


  1   2   >