Re: Python 2.6 and Sqlite3 - Slow

2012-08-27 Thread Bryan
bruceg113 wrote:
> I selected sqlite for the following reasons:
>
> 1) Ships with Python.
> 2) Familiar with Python.
> 3) The Sqlite description athttp://www.sqlite.org/whentouse.htmlappears to 
> meet my requirements:
>     Very low volume and concurrency, small datasets, simple to use.

All good reasons, but a database file on a network drive is
contraindication for SQLite. A Google site-specific search
for "network" on www.sqlite.org, finds such warnings as:

"We have received reports of implementations of both Windows network
filesystems and NFS in which locking was subtly broken. We can not
verify these reports, but as locking is difficult to get right on a
network filesystem we have no reason to doubt them. You are advised to
avoid using SQLite on a network filesystem in the first place, since
performance will be slow."

That said, I don't know where your 17 seconds is going.

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


Re: Python 2.6 and Sqlite3 - Slow

2012-08-27 Thread Bryan
bruceg113 wrote:
> Thank you for your reply.
> Are you saying having a sqlite database file on a
> shared LOCAL network drive is problematic?

Yes, mostly, I think I am saying that.

A "LOCAL network drive" is network drive, and is not a
local drive, local as the network may be. We read and
write such a drive over a network protocol, in this
case a Microsoft protocol and implementation in the
SMB/CIFS family.

Where are your 17 seconds going? Hard to tell. Is
your experience of astonishing filesystem slothfulness
rare? Not so much.

We could probably diagnose the problem in a few weeks.
We'd use some open-source tools, WireShark among them,
plus some Microsoft tools for which we might have to
pay, plus the SQLite3 project's C library. With that
investment I'd bet we could diagnose, but not cure.

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


Re: tornado.web ioloop add_timeout eats CPU

2012-09-03 Thread Bryan
Laszlo Nagy wrote:
[...]
> And here is my problem. If I point 5 browsers to the server, then I get
> 2% CPU load (Intel i5 2.8GHz on amd64 Linux). But why? Most of the time,
> the server should be sleeping. cProfile tells this:
>
> ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>  10.0000.000  845.146  845.146 :1()
>1135775  832.2830.001  832.2830.001 {method 'poll' of
> 'select.epoll' objects}
>
> I have copied out the two relevant rows only. As you can see, total
> runtime was 845 seconds, and 832 seconds were spent in "epoll".
> Apparently, CPU load goes up linearly as I connect more clients. It
> means that 50 connected clients would do 20% CPU load. Which is
> ridiculous, because they don't do anything but wait for messages to be
> processed. Something terribly wrong, but I cannot figure out what?

What's wrong is the 1,135,775 calls to "method 'poll' of
'select.epoll' objects".
With five browsers waiting for messages over 845 seconds, that works
out to each  waiting browser inducing 269 epolls per second.

Almost equally important is what the problem is *not*. The problem is
*not* spending the vast majority of time in epoll; that's *good* news.
The problem is *not* that CPU load goes up linearly as we connect more
clients. This is an efficiency problem, not a scaling problem.

So what's the fix? I'm not a Tornado user; I don't have a patch.
Obviously Laszlo's polling strategy is not performing, and the
solution is to adopt the event-driven approach that epoll and Tornado
do well.

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


Re: sockets,threads and interupts

2012-09-05 Thread Bryan
loial wrote:
> I have threaded python script that uses sockets to monitor network ports.
>
> I want to ensure that the socket is closed cleanly in all circumstances. This 
> includes if the script is killed or interupted in some other way.
>
> As I understand it signal only works in the main thread, so how can I trap 
> interupts in my threaded class and always ensure I close the socket?

You may have various threads waiting in blocking calls, and I don't
think there's a good way to alert them. Closing sockets that other
threads may be waiting on is "probably unwise" according to Linux man
page on close(2).

Do you really need to worry about it? If your process is being
forcibly terminated you probably cannot do anything better than the OS
will do by default.

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


Re: simple client data base

2012-09-06 Thread Bryan
Mark R Rivet wrote:
> Hello all, I am learning to program in python. I have a need to make a
> program that can store, retrieve, add, and delete client data such as
> name, address, social, telephone number and similar information. This
> would be a small client database for my wife who has a home accounting
> business.

Among programming languages Python is exceptionally easy to learn, and
rocks for the kind of app you describe, but your goal is not
realistic. Simple is better than complex, but what you can build at
this point is far from what a professional accountant with her own
business needs from a client database manager.

> I have been reading about lists, tuples, and dictionary data
> structures in python and I am confused as to which would be more
> appropriate for a simple database.

Those are good classes to read about, and I dare say that most
Pythoneers at some time faced confusion as to which were most
appropriate for the problem at hand. You'd need of all them and more,
a whole freak'in bunch more, to build a professional quality contact
manager app.

> I know that python has real database capabilities but I'm not there
> yet and would like to proceed with as simple a structure as possible.
>
> Can anyone give me some idea's or tell me which structure would be
> best to use?
>
> Maybe its a combination of structures? I need some help.

comp.lang.python tries to be friendly and helpful, and to that end
responders have read and answered your question as directly as
possible. There's good stuff available for Python.

Mark, there is absolutely no chance, no how, no way, that your stated
plan is a good idea. Fine CRM apps are available for free; excellent
ones for a few dollars. You're reading about lists, tuples, and
dictionary data? Great, but other home accounting businesses have
their client databases automatically synced with their smart-phones
and their time-charging and their invoicing.

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


Re: simple client data base

2012-09-09 Thread Bryan
Mark R Rivet wrote:
> Well I have to say that this is most discouraging.

Sorry to to be a drag, but the thread needed a bit a realism.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Asynchronous Python

2012-09-09 Thread Bryan
Dustin J. Mitchell wrote:
> After seeing David Mertz's talk at PyCon 2012, "Coroutines, event
> loops, and the history of Python generators" [1], I got thinking again
> about Python's expressive power for asynchronous programming.

I lament the confusion of generators and coroutines. Generators are no
substitute for threads; they're a substitute for temporary memory-
wasting lists and for those extraneous classes that just implement
another class's __iter__.

[big snip]
> As I get to work on the PEP, I'd like to hear any initial reactions to the 
> idea.

Be warned that I'm frequently chastised for negativity...
Your motivating examples motivate me in the opposite direction.
Computing Fibonacci numbers with a generator? The problem with your
first support app is that threads don't scale?

I'm happy with the direction Python has chosen: real, platform-
provided threads. There are some fine projects taking other courses,
but most of the standard stuff is sequential code with some notion of
thread-safety. In this area Python has benefited for free as the
popular platforms have steadily improved.

Properly exploiting event-drive would be a bigger change than you
propose. Python tends to polymorphize I/O via "file like" objects,
who's requirements have traditionally been under-specified and have
never included event-driven behavior. Also, while Python is proudly
cross-platform, Microsoft Windows has the edge on asynchronous
facilities but Python treats Windows like a Unix wanna-be.

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


Re: Beginner Q: What does the double underscore __ mean?

2012-09-09 Thread Bryan
StarPilgrim wrote:
> Brand new to python. I was wondering what the __ underscore means?
> For example, there is a line of code:
>
> __name__=='__main__'
>
> and I don't know what the double underscore is used for.

Ah, tricky. That's not just double underscore; it's double ended
double underscore. Double ended double underscore means that it
invokes special behavior in the Python language. It means fair
warning. Look this up.

Never name your own variables with double ended double underscore. The
one exception is if you are proposing a change to the Python language
and seeking the blessing of our BDFL. Such names are reserved for the
Python language.

Leading double underscore without trailing double underscore means
that the programmer knows and loves some other object-oriented
language, and this other language has a notion of trying to enforce
that this member variable is "private", and Python is meeting him half
way. The programmer of the class advises you not to manipulate this
member variable directly and Python has bowed to convention and done
some name mangling. It's often useful, usually naive, fundamentally
insecure, and tangential to the zen Python.

A lesser known Python convention is the double ended single
underscore. Whether it even rates as convention might be arguable, but
it's there in the critical _fields_ member of the Structure and Union
base classes in the standard ctypes module. It means special within
the particular class. To the Python language it's just another name,
but the authors of the class have coded it to look up that name and do
something interesting with the associated value.

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


Re: Standard Asynchronous Python

2012-09-15 Thread Bryan
Dustin J. Mitchell wrote:
> Thanks for the second round of responses.  I think this gives me some
> focus - concentrate on the API, talk to the framework developers, and
> start redrafting the PEP sooner rather than later.

That's mostly what you came in with, but talking to the framework
developers is unarguably a good idea. So what frameworks?

There is one great framework for asynchronous Python and that's
Twisted. I'm not a Twisted guy... well not in the sense at issue here.
I can tell you why Twisted is "massive": no workable alternative. An
event-driven framework cannot simply call methods in a mainstream
Python library because they often block for I/O. The good and gifted
developers of Twisted have risen to the challenge by re-writing
important libraries around their deferreds which they regard as
beautiful.

Our fellow scripting language programmers in the young node.js
community work in a system that is event-driven from the ground up.
They had the advantage of no important blocking sequential libraries
to re-write. As a programming language JavaScript is grossly inferior
to Python, yet the node.js guys have put out some useful code and
impressive benchmarks with their bad-ass rock-star tech.
https://www.youtube.com/watch?v=bzkRVzciAZg

The obvious exemplars among Python frameworks are web frameworks.
Developers of the most popular Python web framework, Django, famously
stated their goal of making making web programming "stupidly easy".
That registered with me. Django did spectacularly well, then Web2py
did even better on that particular criterion. There are several-to-
many other excellent Python web frameworks, and there's a clear
consensus among the major players on how to handle simultaneous
requests: threads.

Dustin, I hope you carry on with your plan. I request, please, report
back here what you find. As law professor James Duane said in pre-
introduction of police officer George Bruch, "I'm sure [you'll] have a
lot to teach all of us, including myself."

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


PyWart fixed mostly, was: Re: Python Gotcha's?

2013-01-22 Thread Bryan
On Apr 14 2012, 2:47 pm I wrote:
> Miki Tebeka wrote:
> > If you have an interesting/common "Gotcha" (warts/dark corners ...) please 
> > share.
>
> Python 3(K) likes to use the same '.py' file extension as its
> incompatible predecessors, and in some/many/most *nix implementations,
> it likes to install in the same place. Python 3 is an improvement upon
> Python 2, but Python went from, "sure... Python just works," to,
> "well... that depends... which Python?"

My "gotcha" is addressed by PEP 394, "The 'python' Command on Unix-
Like Systems", and PEP 397, "A Python launcher for Windows". They
alleviate much of that pain and suffering of running both Python 2.x
and 3.x.

On *nix systems, if a Python 2 interpreter is available it should be
runnable as "python2". If Python 3 is available, it should runnable as
"python3". The modern Python shebang line is "#!/usr/bin/env python3".
[PEP 394]

On Microsoft Windows, the latest and greatest Python installation,
3.3, no longer usurps the ".py" extension for its own version-specific
interpreter. It associates ".py" with a multi-version launcher, called
"py", that makes a reasonable attempt to do the right thing py-version-
wise. The modern shebang line will help even on MS-Windows. [PEP 397]

There's room for improvement. The launcher invocation, "py", should
work on Unix. And everywhere it runs it should respect shebang lines
that name itself. The modern shebang line ought to be "#!/usr/bin/env
py -3" (but it's not yet so don't use it).

The other big idea in supporting multiple Pythons is virtual
environments. Python 3.3 has PEP 405, virtual environments in the
core. Unfortunately the aforementioned PEP 397 windows launcher, also
in Python 3.3, ignores an active virtual environment. Be warned.


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


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-18 Thread Bryan
SherjilOzair wrote:
> Has it been considered to add shell features
> to python, such that it can be used as a
> default shell, as a replacement for bash, etc.

I think yes, but rather than become a shell, Python makes easy
programming a shell that can execute Python code. The tendency has
been to excel as a scripting language, and prefer to add extra
features to the standard library.

To start, look at the built-in functions eval() and (raw_)input; and
the library modules: subprocess, os and os.path, glob and re, shutil,
and code.

> I'm sure everyone would agree that doing this
> would make the terminal very powerful.

'Cept of course that they already are.

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


Re: multithreading

2012-04-07 Thread Bryan
Kiuhnm wrote:
> I'm about to write my first module and I don't know how I should handle
> multithreading/-processing.
> I'm not doing multi-threading inside my module. I'm just trying to make
> it thread-safe so that users *can* do multi-threading.

There are a couple conventions to follow. Trying to anticipate the
threading needs of users and then locking everything for the worst
case is a bad idea.

So what are the conventions? Unless documented otherwise, classes
don't guarantee that each instance can be used by more then one
thread. Most of the classes in Python's standard library are not one-
instance-multiple-threads safe. An important documented exception is
queue.queue.

Classes should be safe for instance-per-thread multi-threading, unless
documented otherwise. Likewise, functions should be thread safe under
the assumption that their arguments are not shared between threads,
which brings us to your example:

> For instance, let's say I want to make this code thread-safe:
>
> --->
> myDict = {}
>
> def f(name, val):
>      if name not in myDict:
>          myDict[name] = val
>      return myDict[name]
> <---

First, don't re-code Python's built-ins. The example is a job for
dict.setdefault(). Language built-ins are already thread-safe (at
least in CPython), though not meant as thread synchronization
primitives.

Second, the example suggests no obvious reason for the single global
variabel. It could be a class for which users can make any number of
instances.

Third, there are cases where you want a single global. Most of the
time I'd recommend warning users about threading assumptions.

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


Re: multithreading

2012-04-07 Thread Bryan
Kiuhnm wrote:
> My question is this: can I use 'threading' without interfering with the
> program which will import my module?

Yes. The things to avoid are described at the bottom of:
http://docs.python.org/library/threading.html

On platforms without threads, 'import threading' will fail. There's a
standard library module dummy_threading which offers fake versions of
the facilities in threading. It suggests:

try:
import threading as _threading
except ImportError:
import dummy_threading as _threading


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


Re: multithreading

2012-04-08 Thread Bryan
Kiuhnm wrote:
> I have a decorator which takes an optional argument that tells me
> whether I should use locks.
> Maybe I could import 'threading' only if needed. If the user wants to
> use locks I'll assume that 'threading' is available on his/her system.

Use of dummy_threading might be cleaner. It has things with the same
names as the locks in real threading, and that you can create and call
just like locks, but they don't actually do anything.

> By the way, should I avoid to 'import threading' more than once?

No; threading imports like any other competent module. The tricky part
doesn't start until you actually use its facilities.

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


Re: Python Gotcha's?

2012-04-14 Thread Bryan
Miki Tebeka wrote:
> If you have an interesting/common "Gotcha" (warts/dark corners ...) please 
> share.

Python 3(K) likes to use the same '.py' file extension as its
incompatible predecessors, and in some/many/most *nix implementations,
it likes to install in the same place. Python 3 is an improvement upon
Python 2, but Python went from, "sure... Python just works," to,
"well... that depends... which Python?"

I missed the 1 to 2 transition. I'm not exactly a Python newbie, but
Python 1.5.2 was dead an buried by the time I met the snake^H^H^H^H^H
group of daffy English k-ni-ghits.

We knew that there was no painless path from where we were to where we
saw to be better, and the Python community and our BDFL made many wise
decisions toward the Python 3 transition. This particular matter, we
botched. I am too late in speaking up, so I'm as much blame as anyone.
Something to keep in mind for Python 4.

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


Re: Python Gotcha's?

2012-04-15 Thread Bryan
Steven D'Aprano wrote:
> Bryan wrote:
> > Python 3(K) likes to use the same '.py' file extension as its
> > incompatible predecessors,
>
> And so it should.

We disagree. Not surprising in a "gotcha's" thread.

> > and in some/many/most *nix implementations,
> > it likes to install in the same place.
>
> I won't speak for Unixes, but that is certainly not the case with Linux.
> Each Python version gets its own location:

Yes, that was just silly of me to write that. All I want is a new
general convention for the most-likely-to-work invocation that won't
break with the change: "#!/usr/bin/env python" for Python 2 versus,
for example, "#!/usr/bin/env python3". Of course that's not an issue
of where python is installed, just a recommended naming convention.

> I don't intent to be rude, but anyone who isn't a complete newbie to
> programming but is surprised to the point of "gotcha" by version
> compatibilities simply hasn't been paying attention.

My perspective is simply different from yours. I'm not the one who
installs python on most of the boxes where I work or play. There's
little consistency, so I love conventions that usually work. I'd like
to advocate for Python 3, but the default install on Windows
commandeers the '.py' extension and breaks stuff that currently works.

Here's a discussion of the issue from late 2008. Amusingly, one of the
arguments for not changing the file extension was that Python 2 would
be gone in a few years.
http://www.velocityreviews.com/forums/t647251-running-python-2-and-python-3-on-the-same-machine.html

-Bryan

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


Whither paramiko?

2012-04-15 Thread Bryan
Paramiko is a Python library for SSH (Secure Shell). Over about the
last year, I've grown dependent upon it. Its home page is still easy
to search up, but the links to its mailing list and repository don't
work.

Paramiko depends on PyCrypto, and not so long ago that dependency was
the stated reason why paramiko did not yet play with Python 3. Even
more recently, PyCrypto has gone green on the Python 3 Wall of Shame.

Anyone know recent news on the status of paramiko?

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


Re: Python Gotcha's?

2012-04-15 Thread Bryan
Steven wrote:
> Yes, but I have reasons for disagreeing, which you trimmed out of your
> response. If you have reasons for thinking that a separate file extension
> for Python 3 is a good idea, you are keeping it to yourself.

On Windows the file extension determines what executable opens the
file. Running both Python 2 and Python 3 on Windows is painful where
it doesn't need to be. I'd like to encourage my users to check out
Python 3, but installing it on Windows will take over the '.py'
extension and break stuff that currently works.

Incidentally, I'm not actually advocating for '.py3'. I'm advocating
for '.py4'.

> Python and C are different languages. Python 2 and Python 3 are not, they
> are the same language with only a few minor dialect differences.

You could think of it as the same file extension in a different
dialect, but really the works/broken distinction is more important
than language/dialect.

> There is a practical argument against separate file extensions: which
> extension do you use for code intended to run with both Python 2 and 3?

The file extension default should work with the the recommended
transition method, which is not dual-major-version code. Admittedly,
support for such code has improved.

> We didn't need a new file extension for the transition between Python 2.5
> (string exceptions are legal) and Python 2.6 (string exceptions cause a
> SyntaxError exception). Nor did we need a new file extension for the
> transition between Python 2.1 (nested functions behaved one way) and
> Python 2.2 (nested functions behaved a different way). We certainly
> didn't have a new file extension when the bastion or gopher modules were
> removed from the standard library, backwards-incompatible changes if I've
> ever seen one.

Python's management of backwards compatibility for minor version has
worked pretty well, at least for me. Major version simply do not
attempt backward compatibility.

Your experience seems to be quite different from mine. I don't recall
a minor version upgrade ever giving me significant trouble with my own
code. The issue has been the external libraries upon which I depend,
and they've tended to catch up quickly, unlike what we're seeing with
Python 3.

> If there's a good argument in favour of separate file extensions for
> Python 2 and Python 3 (one which doesn't also apply to, say, Python 2.5
> and 2.6, or 3.1 and 3.2) I'm afraid I don't know it.

Because it would allow Windows user to play with Python 3 alongside
Python 2, while waiting for external libraries to catch up. Of course
they can, as I am, but the gotchas are really annoying. With minor
versions its not a big deal if most users simply wait to do an
upgrade.

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


Re: Python Gotcha's?

2012-04-15 Thread Bryan
Steven D'Aprano wrote:
> And how is that different from any other two versions of Python?

Python 3.0, also known as “Python 3000” or “Py3K”, is the first ever
*intentionally backwards incompatible* Python release. --GVR

> Unless both versions include the same libraries (either standard modules
> or third party), and your code is written to use only the lowest common
> denominator functionality, you will have problems regardless of which
> versions they are.

*My* code is not what's holding me back. I *like* moving my code to
Python 3. What's holding me back is library availability, and from
various readings on the transition to 3, I gather that's what holding
many, perhaps most, users back.

The need to keep using 2.x should not stop users from installing and
starting to muck with 3.0. That's much more painful than it has to be
because they both use the same file extension.

--
--Bryan


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


Re: Framework for a beginner

2012-04-17 Thread Bryan
biofob wrote:
> I am new to python and only have read the Byte of Python ebook, but want to 
> move to the web. I am tired of being a CMS tweaker and after I tried python, 
> ruby and php, the python language makes more sense (if that makes any "sense" 
> for the real programmers). I heard a lot of good things about Django, 
> Pyramid, etc, but I dont want to pick the most used or the one with the most 
> magic. Instead I was thinking about one that could "teach" me python along 
> the way. My plan is to rebuild my portfolio using python and a framework and 
> also benefit my python learning along the way.

Warning: I'm a mere dabbler in web frameworks.

If by rebuilding your portfolio you mean to position yourself for a
job, then popularity counts a lot. As measured by job openings, Django
is king. It's a fine framework and reasonably Pythonic. The Django
community is large and sophisticated and helpful They have there own
app download system, which I haven't used but is supposed to work
really well. Django has emphasized backwards compatibility with the
down-side that, last I heard, there was no plan to move to Python 3.

Your disinterest in "magic" plays against Web2Py. Were the goal to go
from squat to professional quality web site quickly and easily, Web2Py
would be it.

Web2Py does a load of complex and interesting stuff behind the scenes.
Among web frameworks, it rocks like none other at teaching and using
web best-practices, at the cost of hiding or skirting core Python
practices. Professor Massimo DiPierro fist built Web2Py for his own
particular problem: teaching web programming in one semester. Without
it, his students spent so much time on the tools that his course could
not cover the essential topics.

Turbo-Gears has a lot going for it, largely by adoption. It demands
more elbow-grease than Django or Web2Py, but the extra effort has
benefits beyond the framework. In particular, Turbo-Gears has adopted
SQLAlchemy, which is significantly more demanding and vastly more
powerful than the purpose-built automatic table-generators of Django
and Web2Py.

Then there are the less than full-stack frameworks and libraries. But
this post is probably too long already.

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


Re: Framework for a beginner

2012-04-17 Thread Bryan
Roy Smith wrote:
> Bryan wrote:
> > Django has emphasized backwards compatibility with the
> > down-side that, last I heard, there was no plan to move to Python 3.
>
> Hardly.  Seehttps://www.djangoproject.com/weblog/2012/mar/13/py3k/

Ah, I'm behind the times again. Thanks, that's good news.

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


Re: Framework for a beginner

2012-04-20 Thread Bryan
Gerd Niemetz wrote:
> Take a look at http://www.web2py.com, a powerful and easy to learn python 
> framework, and the community at 
> https://groups.google.com/forum/?fromgroups#!forum/web2py is also very helpful
>

Web2py rocks. It does by default better than many, probably most,
professional web programmers do for their living. A prominent
commercial publication extolled ranked it: best-open-source-
application-development-software of the last year.
http://www.infoworld.com/d/open-source-software/bossie-awards-2011-the-best-open-source-application-development-software-171759-0¤t=10&last=1#slideshowTop

Hope that URL works. Users of web2py generally produce shorter,
simpler, more elegant URL's. I have my reservations about whether
web2py is the best answer for the O.P. here, and on that I stand by my
previous reporting.

At risk of making the same mistake twice in one short thread: Last I
heard -- please correct me if I'm wrong -- Web2py had no plan for to
move to Python 3.


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


number of python users

2005-09-26 Thread Bryan
is there a rough estimate somewhere that shows currently how many python 1.5 vs 
2.2 vs 2.3 vs 2.4 users there are?  have a majority moved to 2.4? or are they 
still using 2.3? etc...

thanks,

bryan

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


Re: number of python users

2005-09-26 Thread Bryan
Fredrik Lundh wrote:
> Bryan wrote:
> 
>>is there a rough estimate somewhere that shows currently how many python 1.5 
>>vs
>>2.2 vs 2.3 vs 2.4 users there are?  have a majority moved to 2.4? or are they
>>still using 2.3? etc...
> 
> 
> Here are current PIL download statistics (last 10 days):
> 
> 75.6% /downloads/PIL-1.1.5.win32-py2.4.exe
> 18.0% /downloads/PIL-1.1.5.win32-py2.3.exe
>  2.2%  /downloads/PIL-1.1.5.win32-py2.2.exe
>  4.2%  /downloads/PIL-1.1.5.win32-py2.1.exe
> 
> Note that these are fresh downloads for Windows, not users.  People
> who run other systems, or are happy with their existing installation,
> isn't included (so older versions are probably more common than they
> appear).
> 
> (fwiw, I still have users on 1.5.2 for most of my libraries.  usually huge
> Unix systems that nobody wants to break just because they can...)
> 
> 
> 
> 
> 

just for fun, i looked at the top linux distros at distrowatch and looked at 
what version of python the latest released version is shipping with out of the 
box:

1. ubuntu hoary - python 2.4.1
2. mandriva 2005 - python 2.4
3. suse 9.3 - python 2.4
4. fedora core 4 - python 2.4.1
5. mepis 3.3.1 - python 2.3.5
6. knoppix 4.0.2  - python 2.3.5
7. debian sarge - python 2.3.5
8. gentoo 2005.1 - python 2.3.5
9. slackware 10.2 - python 2.4.1
10.kubuntu hoary - python 2.4.1
11. freebsd 5.4 - python 2.4
12. xandros 3.0 - python 2.3.4
13. pclinuxos 0.91 - python 2.3.4


bryan

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


bizarro world (was Re: Python Doc Problem Example: sort() (reprise))

2005-10-11 Thread Bryan
Xah Lee wrote:
> Addendum, 200510
> 
> Here's further example of Python's extreme low quality of
> documentation. In particular, what follows focuses on the bad writing
> skill aspect, and comments on some language design and quality issues
> of Python.
> 
>>From the Official Python documentation of the sort() method, at:
> http://python.org/doc/2.4.2/lib/typesseq-mutable.html, Quote:
> 
> «The sort() method takes optional arguments for controlling the
> comparisons.»
> 
> It should be “optional parameter” not “optional argument”.
> Their difference is that “parameter” indicates the variable, while
> “argument” indicates the actual value.
> 
> «... for controlling the comparisons.»
> 
> This is a bad writing caused by lack of understanding. No, it doesn't
> “control the comparison”. The proper way to say it is that “the
> comparison function specifies an order”.
> 
> «The sort() and reverse() methods modify the list in place for economy
> of space when sorting or reversing a large list. To remind you that
> they operate by side effect, they don't return the sorted or reversed
> list. »
> 
> This is a example of tech-geeking drivel. The sort() and reverse()
> methods are just the way they are. Their design and behavior are really
> not for some economy or remind programers of something. The Python doc
> is bulked with these irrelevant drivels. These littered inanities
> dragged down the whole quality and effectiveness of the doc implicitly.
> 
> «Changed in version 2.4: Support for key and reverse was added.»
> 
> «In general, the key and reverse conversion processes are much faster
> than specifying an equivalent cmp function. This is because cmp is
> called multiple times for each list element while key and reverse touch
> each element only once.»
> 
> When sorting something, one needs to specify a order. The easiest way
> is to simply list all the elements as a sequence. That way, their order
> is clearly laid out. However, this is in general not feasible and
> impractical. Therefore, we devised a mathematically condensed way to
> specify the order, by defining a function f(x,y) that can take any two
> elements and tell us which one comes first. This, is the gist of
> sorting a list in any programing language.
> 
> The ordering function, being a mathematically condensed way of
> specifying the order, has some constraints. For example, the function
> should not tell us x < y and y < x. (For a complete list of these
> constraints, see http://xahlee.org/perl-python/sort_list.html )
> 
> With this ordering function, it is all sort needed to sort a list.
> Anything more is interface complexity.
> 
> The optional parameters “key” and “reverse” in Python's sort
> method is a interface complexity. What happened here is that a compiler
> optimization problem is evaded by moving it into the language syntax
> for programers to worry about. If the programer does not use the
> “key” syntax when sorting a large matrix (provided that he knew in
> advance of the list to be sorted or the ordering function), then he is
> penalized by a severe inefficiency by a order of magnitude of execution
> time.
> 
> This situation, of moving compiler problems to the syntax surface is
> common in imperative languages.
> 
> «Changed in version 2.3: Support for None as an equivalent to omitting
> cmp was added.»
> 
> This is a epitome of catering towards morons. “myList.sort()” is
> perfect but Pythoners had to add “myList.sort(None)” interface
> complexity just because idiots need it.
> 
> The motivation here is simple: a explicit “None” gives coding
> monkeys a direct sensory input of the fact that “there is no
> comparison function”. This is like the double negative in black
> English “I ain't no gonna do it!”. Logically, “None” is not
> even correct and leads to bad thinking. What really should be stated in
> the doc, is that “the default ordering function to sort() is the
> ‘cmp’ function.”.
> 
> «Starting with Python 2.3, the sort() method is guaranteed to be
> stable. A sort is stable if it guarantees not to change the relative
> order of elements that compare equal -- this is helpful for sorting in
> multiple passes (for example, sort by department, then by salary
> grade).»
> 
> One is quite surprised to read this. For about a decade of a language's
> existence, its sort functionality is not smart enough to preserve
> order?? A sort that preserves original order isn't something difficult
> to implement. What we have here is sloppiness and poor quality common
> in OpenSource projects.
> 
> Also note the extreme low quality of the writing. It employes the
> jargon “stable sort” then proceed to explain what it is, and the
> latch on of “multiple passes” and the mysterious “by department,
> by salary”.
> 
> Here's a suggested rewrite: “Since Python 2.3, the result of sort()
> no longer rearrange elements where the comparison function returns
> 0.”
> ---
> This post is archived at:
> http://xahlee.org/perl-python/python_doc_

Re: bizarro world (was Re: Python Doc Problem Example: sort() (reprise))

2005-10-11 Thread Bryan
mr. xah... would you be willing to give a lecture at pycon 2006?  i'm sure you 
would draw a huge crowd and a lot of people would like to meet you in person...

thanks.

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


Re: tuple versus list

2005-10-16 Thread Bryan
[EMAIL PROTECTED] wrote:
> In this particular case, it seems that (width,height) looks nicer. But
> I think otherwise, list constuct is easier to read, even though it is
> supposed to be slower.
> 
> With list you can :
> [a] + [ x for x in something ]
> 
> With tuple it looks like this :
> (a,) + tuple(x for x in something)
> 
> I think the list looks cleaner. And since you cannot concat tuple with
> list, I think unless it looks obvious and natural(as in your case), use
> list.
> 


i always use the structure analogy.  if you view (width, height) as a 
structure, 
use a tuple.  if you view it a sequence, use a list.  in this example, i view 
it 
as a stucture, so i would use (width, height) as a tuple.

bryan

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


Re: tuple versus list

2005-10-17 Thread Bryan

>>
>>i always use the structure analogy.  if you view (width, height) as a 
>>structure, 
>>use a tuple.  if you view it a sequence, use a list.  in this example, i view 
>>it 
>>as a stucture, so i would use (width, height) as a tuple.
> 
> 
> Right, but there's an unfortunate ambiguity in the term "sequence",
> since in Python it is defined to include tuple.  I gather you meant
> more in the abstract sense of a data collection whose interesting
> properties are of a sequential nature, as opposed to the way we are
> typically more interested in positional access to a tuple.  Maybe
> a more computer literate reader will have a better word for this,
> that doesn't collide with Python terminology.  My semi-formal
> operational definition is "a is similar to a[x:y], where
> x is not 0 or y is not -1, and `similar' means `could be a legal
> value in the same context.'"
> 
>Donn Cave, [EMAIL PROTECTED]


yes, you are correct.  i shouldn't have used the word "sequence" which is a 
python term.   maybe structure vs. array.  in any case, i think the *wrong* 
answer that is often given to this question is along the lines of if it's read 
only, make it a tuple. if it's read write, make it a list. a great trivial 
example is a point.  a point is a structure (x, y).  if you have many points 
then you have a list of structures: [(x, y), (x1, y1), (x2, y2), ...].  to me, 
it doesn't matter if you want to modify a point.  if you do then create a new 
one, but don't make it a list just to make it modifiable.

bryan

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


Re: Python vs Ruby

2005-10-19 Thread Bryan
Amol Vaidya wrote:
> Hi. I am interested in learning a new programming language, and have been 
> debating whether to learn Ruby or Python. How do these compare and contrast 
> with one another, and what advantages does one language provide over the 
> other? I would like to consider as many opinions as I can on this matter 
> before I start studying either language in depth. Any help/comments are 
> greatly appreciated. Thanks in advance for your help. 
> 
> 

why don't you do what i did?  download ruby and spend a day or two reading 
"programming ruby" from www.ruby-lang.org/en.  the download python and spend a 
day or two reading the python tuturial from www.python.org.  they are very 
similar languages and it's going to come down to your personal perference.  for 
me personally, ruby did not fit in my brain and python did.  i used the "how 
many times did i have to flip back to a previous page in the manual/tutorial 
and 
reread a section" test.  with ruby, once i got about one third of the way 
through the manual, i had to constantly reread previous sections.  with python, 
not once did i need to reread a previous section.  therefore, python was the 
obvious choice for me.


bryan

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


Re: Python vs Ruby

2005-10-19 Thread Bryan
Dave Cook wrote:
> On 2005-10-20, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
> 
>>Languages are very similar but Python has more cale avaliable. Much
>>more.
> 
> 
> Cale?  You mean Python has more ruffage?
> 
> Dave Cook


i think you mean "kale" not "cale".  nothing like a hot bowl of tofu kale soup 
while reading the recipes in the "python cookbook".

bryan

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


python -m pdb questions

2005-10-21 Thread Bryan
So I am new to the whole python thing, be nice.

So I do a b /foo/foo.py :10

(if I do a foo.py:10 it says not in sys.path)

Then a continue... my breakpoint isn't hit.

but if I am in main.py and do a b /foo/main.py:10 I hit the breakpoint.

also I can't get b fooMethod to ever take, always get not in sys.path

What am I missing?  Or is pdb fubar?

Suse93 btw.

thanks,

Bryan 


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


Re: Python vs Ruby

2005-10-21 Thread Bryan
Ed Jensen wrote:
> Sion Arrowsmith <[EMAIL PROTECTED]> wrote:
> 
>>I have here a library (it's the client side of a client-server
>>interface including a pile of class definitions) which has
>>implementations in pure C++, Java and Python, taking about 3000,
>>3500 and 1500 loc respectively. And there's an associated module
>>(with no C++ implementation) that I remember being particular
>>"impressed" while writing it to find being 3 times as long in Java
>>as Python despite (a) extensive (and pretty much common) Javadoc/
>>docstrings and (b) implementing in the Python version a feature
>>present in the standard Java library (scheduling a thread to run
>>at specified intervals and time out). Strip the Javadoc/docstrings
>>out and it's about at that 5:1 ratio.
> 
> 
> This claim seems pretty dubious to me.

i would not say sion's ratio of 5:1 is dubious.  for what it's worth, i've 
written i pretty complex program in jython over the last year.  jython compiles 
to java source code and the number of generated java lines to the jython lines 
is 4:1.

bryan

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


Re: Python as Guido Intended

2005-11-25 Thread Bryan

> But suppose someone came up with a Python compiler.  It
> would compile any Python program but there would be no
> speed benefit unless you carefully wrote the code to not use
> many of Python's dynamic features, so that either by type
> inferencing or programmer supplied static declarations, the
> compiler could generate efficient native machine code
> that executes at near C speeds.
> Obviously this would require changes (mostly additions?)
> to the Python language, though these changes would still
> allow today's style dynamic code to be written and run
> (though just as slow as today's runs).
> The payout would be that things written as C-extensions
> today, would be writable in (a restricted form of) Python.
> Would the Python orthodoxy favor such a development?
> Or would that be turning Python into a screwdriver?
> 
>

i agree with you... pyrex should be part of the python distribution :)

bryan

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


Re: what would you like to see in a 2nd edition Nutshell?

2005-01-01 Thread Bryan
Nick Coghlan wrote:
JoeG wrote:
wxPython takes on more of the native platform's interface.  I say seems
to because I haven't actually written any code with it.

While Tkinter is the GUI toolkit shipped *with* Python, then that's the 
correct toolkit for Alex to cover in PiaN. Mentioning other toolkits 
(and providing references for additional information, including books if 
they're available) seems like the most reasonable alternative.

Now, if we could just switch to wxPython and Boa Constructor for Py3K. . .
Cheers,
Nick.
Sorry Kurt!
i would prefer PiaN not to cover any gui toolkits, and instead use that space 
for more core funcionality.

thanks,
bryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyCon Preliminary Program Announced!

2005-01-20 Thread Bryan
can anyone tell me how the talks work?  there are between 9 and 12 talks for 
each time slot.  do all talks start at the same time? or are there just four 
talks at a time and the columns show what talks are in a given room?  is it easy 
to go to the talks you want?

thanks,
bryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: The next Xah-lee post contest

2005-01-30 Thread Bryan
Eric Pederson wrote:
From: Arthur <[EMAIL PROTECTED]>

Not sure how Xah got himself into all this.  

One can easily see that Java programmers are geeks who secretly wanted to make the 
football team and are now trying to conform, ignoring their language's critical lack of 
Prolog syntax.  Python coders, similarly, do not recognize that they may be violating 
several open source patents each time they write: "class(Object):", and both 
languages may become unusable when the Government changes the inheritance tax.
Rather than throw stones or make fun, all but the closet Republicans should 
examine how poor Xah came to such a state of misunderstanding IPv8, and try to 
help him.
From Aahz tag line we have a clue:
"19. A language that doesn't affect the way you think about programming,is 
not worth knowing."  --Alan Perlis
Further understanding will require research.  Was it Perl that did this to Mr. Lee's 
brain, or perhaps it was trying to ascertain the web services "standard"?  Was 
it a massive PHP program that simply grew beyond comprehendability and blew all normal 
circuits?  Or perhaps an attempt to jump straight from Fortran 77 into Ruby?
Perhaps we will never know the cause, but surely when the ill come to us we 
must prescribe something.
Ah, perhaps if he will join us in a song we will all be OK:
Python Choir:
Lee's a lumberjack, and he's OK,
He codes all night and he posts all day.
XL:
I cut down trees, I eat my lunch,
I go to the lavatory.
On Wednesdays I go shopping,
And have buttered scones for tea.
Python Choir:
Lee cuts down trees, He eats his lunch,
He goes to the lavatory.
On Wednesdays he goes shopping,
And have buttered scones for tea.
Lees a lumberjack, and he's OK,
He codes all night and he posts all day.
XL:
I cut down trees, I skip and jump,
I like to press wild flowers.
I put on women's clothing,
And hang around in bars.
Python Choir:
Lee cuts down trees, he skips and jumps,
He likes to press wild flowers.
He puts on women's clothing
And hangs around In bars???
Well.  At least I feel better.  For now.

/Eric - sentenced to re-learn and write an application in Perl 5.0
What will that do to my mind?
http://www.songzilla.blogspot.com
:::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::
oh great... now you just legend-ized him on this group forever :(
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding exception handling

2005-01-30 Thread Bryan
Dan Perl wrote:
"Aggelos I. Orfanakos" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Thanks. This should now be OK:
#try:
#try:
#s = ... # socket opens
#
## various code ...
#except socket.error, x:
## exception handling
#finally:
#s.close() # socket closes

Why the nested try's?  If I understand your intention correctly this should 
do the same thing:

try:
 s = ... # socket opens
 # various code ...
except socket.error, x:
 # exception handling
s.close() # socket closes
You would need the try-finally statement only if you expect it to handle 
other exceptions than socket.error or if the socket.error is re-raised in 
the "except" clause.  Otherwise, the try-finally statement is redundant 
because no socket.error are getting out of the try-except statement.

Dan 


i always use the try/finally statement with resources, but in a slightly 
different way than the above two examples:

s = ... # socket opens
try:
# various code ...
finally:
s.close()
or, if i want to handle the socket.error if s gets successfully bound,
s = ... # socket opens
try:
try:
# various code
except socket.error e:
# exception handling
finally:
s.close()
i disagree with the statement:
"You would need the try-finally statement only if you expect it to handle other 
exceptions than socket.error or if the socket.error is re-raised in the "except" 
clause.  Otherwise, the try-finally statement is redundant because no 
socket.error are getting out of the try-except statement."

IMO, that is not the reason for the try/finally statement and it is not 
redundant.  the try/finally statement guarantees the resource is closed and the 
try/finally statement only gets executed if and only if the opening of the 
resource doesn't raise an exception.  it has nothing to do with exception handling.

in the previous 2 examples s = ... was placed inside the try/finally, but if an 
exception occures and s doesn't get bound to an object, then s.close() in both 
examples will raise a NameError on s.

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


Re: Regarding exception handling

2005-01-30 Thread Bryan
Dan Perl wrote:
"Bryan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

IMO, that is not the reason for the try/finally statement and it is not 
redundant.  the try/finally statement guarantees the resource is closed 
and the try/finally statement only gets executed if and only if the 
opening of the resource doesn't raise an exception.  it has nothing to do 
with exception handling.

But IMO, try-finally is meant to be used only if the block in the try clause 
may raise exceptions.  Here is an example that shows what I meant:
s = ... # socket opens
try:
a = 1
finally:
s.close()

works perfectly the same as:
s = ... # socket opens
a = 1
s.close()
the above is not the same. make the a = ... raise an exception and you'll see 
the difference.

s = ... #
a = 1/0
s.close()
as you can see, s.close() will never be called.  also, in this example, i 
intentionally didn't put the extra try/except around the try/finally statement. 
   usually i let an exception caused by s = ... to bubble up to some level that 
knows how to handle that error.  we are talking about a resource here and in my 
experience, these low level functions (below the UI or management layer) don't 
know how to or shouldn't handle resources that can't be opened.

bryan
The try-finally statement does not "handle" the exception, but it makes 
sense only if exceptions are possible.  There is no point in enclosing "a = 
1" in any kind of try statement.

According to a following posting from Angelos he did expect some other 
exceptions than socket.error and hence the nested try's.  To my defence 
though, I put in a disclaimer for that case in my initial posting.


in the previous 2 examples s = ... was placed inside the try/finally, but 
if an exception occures and s doesn't get bound to an object, then 
s.close() in both examples will raise a NameError on s.

That is a very good point.  I missed it.
Dan 


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


Re: Regarding exception handling

2005-01-30 Thread Bryan
Fredrik Lundh wrote:
"Bryan" wrote

the above is not the same. make the a = ... raise an exception and you'll see 
the difference.
s = ... #
a = 1/0
s.close()
as you can see, s.close() will never be called.  also, in this example, i intentionally didn't put 
the extra try/except around the try/finally statement.

file handles and sockets are closed when the objects are garbage collected.
under CPython, they're usually closed when they go out of scope.
using try/finally on files and sockets are usually overkill.
 


i was trying to be generic and use the term resource.  i know you are correct 
about file handles and sockets. there are other resources that don't behave so 
nicely.  i'm currently using a third party module that will crash python (the 
entire interpreter GPF's) if you don't explicitly close the resource before your 
python script exits.  other times, depending on a variable to go out of scope to 
 have a resource automically close itself is not practical.  or sometimes you 
want a resource to be closed, but still hold on to the reference.   so, i don't 
feel as strongly as you do that try/finally on even files and socks are 
overkill.  of course on small scripts, i don't use try/finally or close() either :)

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


Re: Where are list methods documented?

2005-02-01 Thread Bryan
Skip Montanaro wrote:
Grant> where are the methods of basic types documented?  

The other day I suggested the most valuable doc page to bookmark is the
global module index.  Here's a demonstration.  Start at:
http://www.python.org/dev/doc/devel/modindex.html
Click "__builtin__", which takes you to
http://www.python.org/dev/doc/devel/lib/module-builtin.html
Click the "2" in "See Chapter 2", which takes you to
http://www.python.org/dev/doc/devel/lib/builtin.html#builtin
Scroll down to section 2.3.6 and choose your sequence poison.
I use the dev docs instead of the latest release docs because I generally
run from CVS on my system, however in this case it has the added advantage
that the link on the __builtin__ page is more useful.
Skip


wow, that's pretty obscure.  i barely even saw the link to chapter 2.  i always 
the modules index page open and i always wished there was an explicit link to 
lists, tuples, dict, set, etc.  maybe these explicit links could be at the top 
of the __builtins__ page.

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


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread Bryan
Torsten Bronger wrote:
> 
> Besides, wxPython prepares for being included
> into the standard distribution.
> 

wow, i've never heard this said so explicitly.  is there a reference link 
backing up this statement?  i really really hope this is true.  i'm very much 
in 
favor to see wx included in the standard distrubution.

bryan

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


os._exit vs. sys.exit

2005-07-28 Thread Bryan
Quick question:

Why does os._exit called from a Python Timer kill the whole process while 
sys.exit does not?  On Suse.

Bryan 


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


Re: os._exit vs. sys.exit

2005-07-29 Thread Bryan

"Peter Hansen" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Andrew Dalke wrote:
>> sys.exit() is identical to "raise SystemExit()".  It raises a Python
>> exception which may be caught at a higher level in the program stack.
>
> And which *is* caught at the highest levels of threading.Thread objects 
> (which Timer is based on).  Exceptions raised (and caught or not) in a 
> Thread do not have any effect on the main thread, and thus don't affect 
> the interpreter as a whole.
>
> -Peter

Thanks for the clarifications.  One more question, can I catch this 
exception in my main thread and then do another sys.exit() to kill the whole 
process?

Apparently sys.exit() allows the program to clean up resources and exit 
gracefully, while os._exit() is rather abrupt.

Bryan 


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


Re: Python Light Revisted?

2005-08-22 Thread Bryan

> Someone recently produced a distribution capable of running from a CD 
> and designed to make it easy to use Python on machines where it wasn't 
> actually installed. That might be a useful starting point too, but I 
> can't find the right incantation to get Google to bring it up.
> 
> regards
>   Steve

steve,

are you thinking about moveable python?

http://www.voidspace.org.uk/python/movpy/

bryan

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


Re: C#3.0 and lambdas

2005-09-19 Thread Bryan
Diez B. Roggisch wrote:
>>meanwhile, over in python-dev land:
>>
>>"Is anyone truly attached to nested tuple function parameters; 'def
>>fxn((a,b)): print a,b'?  /.../
>>
>>Would anyone really throw a huge fit if they went away?  I am willing
>>to write a PEP for their removal in 2.6 with a deprecation in 2.5 if
>>people are up for it."
> 
> 
> I am - I think that feature is sort of an orthogonality which should be 
> preserved. No doubt its not one of the most important ones - but if I 
> can write
> 
> a, (b ,c) = 1, (2,3)
> 
> I'd like to write
> 
> def foo(a, (b,c)):
> ...
> 
> foo(1, (2,3))
> 
> too.
> 
> Diez

exactly... consistency is the most important thing here.  i use this style all 
the time.  i will be very disappointed to find this removed from python. i'm +1 
for keeping it.

bryan

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


Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Bryan
Christos TZOTZIOY Georgiou wrote:
On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers <[EMAIL PROTECTED]>
might have written:
[snip: snacktime posts code to count bits]

Seems to work, is there a better way to do this?

[Dan]
for c in range( 128 ):
  even_odd = 0
  print '%3d' % c,
  while c:
  c &= c - 1
  even_odd = not even_odd
  print int( even_odd )

Just for the sake of people who haven't messed with bit manipulation in C or
assembly, the effect of
c &= c - 1
is to reset the rightmost (less significant) '1' bit of a number (ie change it
to '0').
i tried c &= c - 1 but i'm not getting the least significant or rightmost bit 
reset to zero.  am i misunderstanding something?

>>> 2 & 1  # 2 = 0x10; reset right most would be 0x10
0
>>> 10 & 9 # 10 = 0x1010; reset right most would be 0x1010
8
bryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Bryan
Duncan Booth wrote:
Bryan wrote:

is to reset the rightmost (less significant) '1' bit of a number (ie
change it to '0').
i tried c &= c - 1 but i'm not getting the least significant or
rightmost bit reset to zero.  am i misunderstanding something?

2 & 1  # 2 = 0x10; reset right most would be 0x10
0
10 & 9 # 10 = 0x1010; reset right most would be 0x1010
8

The difference between the original "reset the rightmost '1' bit", and your 
interpretation: "reset the rightmost bit" is the "'1'".

The rightmost bit that is set is reset. So 0x10 -> 0, and 0x1010 -> 0x1000.
If you want to extract the least significant set bit from a number 'x' you 
can use (x&-x):


x = 0xab4
while x:
print hex(x&-x), hex(x)
x ^= (x&-x)

0x4 0xab4
0x10 0xab0
0x20 0xaa0
0x80 0xa80
0x200 0xa00
0x800 0x800
(but don't try this if x is negative: it works but never terminates).
thanks duncan... you're right, i did intrepret this as "reset the rightmost bit" 
instead of "reset the rightmost '1' bit".  and i must have read what christos 
wrote 100 times!!!

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


Re: [perl-python] generic equivalence partition

2005-02-24 Thread Bryan
Xah Lee wrote:
another functional exercise with lists.
Here's the perl documentation. I'll post a perl and the translated
python version in 48 hours.
=pod
parti(aList, equalFunc)
given a list aList of n elements, we want to return a list that is a
range of numbers from 1 to n, partition by the predicate function of
equivalence equalFunc. (a predicate function is a function that
takes two arguments, and returns either True or False.)
Note: a mathematical aspect: there are certain mathematical constraints
on the a function that checks equivalence. That is to say, if a==b,
then b==a. If a==b and b==c, then a==c. And, a==a. If a equivalence
function does not satisfy these, it is inconsistent and basically give
meaningless result.
example:
parti([['x','x','x','1'],
['x','x','x','2'],
['x','x','x','2'],
['x','x','x','2'],
['x','x','x','3'],
['x','x','x','4'],
['x','x','x','5'],
['x','x','x','5']], sub {$_[0]->[3] == $_[1]->[3]} )
returns
 [[1],['2','3','4'],['5'],['6'],['7','8']];
=cut
In the example given, the input list's elements are lists of 4
elements, and the equivalence function is one that returns True if the
last item are the same.
Note that this is a generic function. The input can be a list whose
elements are of any type. What "parti" does is to return a partitioned
range of numbers, that tells us which input element are equivalent to
which, according to the predicate given. For example, in the given
example, it tells us that the 2nd, 3rd, 4th elements are equivalent.
And they are equivalent measured by the predicate function given, which
basically tests if their last item are the same integer. (note that if
we want to view the result as indexes, then it is 1-based index. i.e.
counting starts at 1.)
PS if you didn't realize yet, nested lists/dictionaries in perl is a
complete pain in the ass.
PS note that the code "sub {$_[0]->[3] == $_[1]->[3]}" is what's called
the lambda form, in Perl.
 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html
this is the first thing that came to my mind.  i'm sure there are more clever 
ways to do this.

elements = [['x', 'x', 'x', '1'],
['x', 'x', 'x', '2'],
['x', 'x', 'x', '2'],
['x', 'x', 'x', '2'],
['x', 'x', 'x', '3'],
['x', 'x', 'x', '4'],
['x', 'x', 'x', '5'],
['x', 'x', 'x', '5']]
pos = {}
for i, element in enumerate(elements):
pos.setdefault(element[-1], []).append(i+1)
p = pos.values()
p.sort()
[[1], [2, 3, 4], [5], [6], [7, 8]]
bryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: code for Computer Language Shootout

2005-03-18 Thread Bryan

import sys
import string
def show(seq, table=string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy',
 'TGVHCDM\nKNSYAAWBRTGVHCDMKNSYAAWBR')):
 seq = seq.translate(table)[::-1]
 for i in range(0, len(seq), 60):
 print seq[i:i+60]
couldn't you change the above for loop to:
print wraptext.fill(seq, 60)

bryan

def main():
 seq = []
 for line in sys.stdin:
 if line[0] in ';>':
 show(''.join(seq))
 print line,
 del seq[:]
 else:
 seq.append(line[:-1])
 show(''.join(seq))
main()

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


determine os language

2005-03-19 Thread Bryan
is there a way to determine the operating system's language?  i can't seem to 
find a method that returns the value.

thanks,
bryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: determine os language

2005-03-19 Thread Bryan
Bryan wrote:
is there a way to determine the operating system's language?  i can't 
seem to find a method that returns the value.

thanks,
bryan
found it myself, thanks...
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1252')
>>>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Versioning Libraries

2004-12-02 Thread Bryan
Peter Hansen wrote:
Randall Smith wrote:
As Python changes and old code still needs to work properly, I wonder 
if there is a standard way to note which version of the Python 
interpreter code is intended to work with.  I know that an executable 
may begin with #!/usr/bin/python2.3 or something similar, but what 
about libraries and such?  Would it be a good idea for the software I 
write to check for the version of the interpreter?

Python is exceptionally backwards compatible, so generally
code from an older version will run unchanged on newer
Pythons.
There is a simple way of encoding a version of the interpreter,
but the real question is why would you want to do that.  If
you really think it's necessary, just import sys and check the
value of sys.version_info.  Lots of code which wants to require
a *minimum* version of Python (a far more common use case than
checking for a *maximum*) contains code like this:
import sys
if sys.hex_version[:3] < (2, 3, 3):
sys.exit('Requires Python 2.3.3 or later to run!')
-Peter
i think you meant something this:
>>> import sys
>>> sys.version_info[:3]
(2, 4, 0)
>>> sys.version_info[:3] >= (2, 3, 3)
True
>>> sys.hex_version
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'module' object has no attribute 'hex_version'
bryan
--
http://mail.python.org/mailman/listinfo/python-list


deferred decorator

2004-12-07 Thread Bryan
i was intrigued with a recently posted cookbook recipe which implements deferred 
results with decorators:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/355651
the problem i see with this recipe is that the author only tested his code by 
printing the values which causes __getattr__ to be called with '__str__' and 
work correctly.  but, if you were to remove the print statements and just do a v 
+ v, __getattr__ won't get called as he expected and the join will never happen. 
  i think by making __coerce__ as smart as __getattr__ this recipe would work. 
 can someone validate that i'm correct in what i'm saying?

i'm also curious if it's possible to write this recipe using the new class style 
for the Deffered class.it appears you can nolonger delegate all attributes 
including special methods to the contained object by using the __getattr__ or 
the new __getattribute__ methods.  does anyone know how to port this recipe to 
the new class style?

thanks,
bryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: deferred decorator

2004-12-08 Thread Bryan
Nick Coghlan wrote:
Bryan wrote:
i'm also curious if it's possible to write this recipe using the new 
class style for the Deffered class.it appears you can nolonger 
delegate all attributes including special methods to the contained 
object by using the __getattr__ or the new __getattribute__ methods.  
does anyone know how to port this recipe to the new class style?

Override __getattribute__. I don't know why you think it doesn't let you 
override all attribute accesses, as that's exactly what it is for.

Cheers,
Nick.
here's an example. __getattribute__ gets called for x but not for the special 
method __add__.  and the __str__ method was found in the base class object which 
printed the memory location, but didn't call __getattribute__.  so 
__getattribute__ cannot be used to capture special methods and delegate them to 
an encapsulated object.   this is why i'm asking what the technique using new 
classes would be for this recipe.

>>> class Foo(object):
... def __getattribute__(self, name):
... raise AttributeError('__getattribute__ is called')
...
>>> f = Foo()
>>> f.x()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 3, in __getattribute__
AttributeError: __getattribute__ is called
>>> f + f
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unsupported operand type(s) for +: 'Foo' and 'Foo'
>>> str(f)
'<__main__.Foo object at 0x0118AD10>'
--
http://mail.python.org/mailman/listinfo/python-list


collaborative text editor

2005-03-28 Thread Bryan
at pycon, several mac users were using a collaborative text editor where each 
user's text background color was a different color as they edited the same 
document at the same time while they took notes during the lectures.  does 
anyone know the name of that program?  it was one of the coolest things i've 
ever seen :)

thanks,
bryan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming Language for Systems Administrator

2005-04-13 Thread Bryan
pythonUser_07 wrote:
Python is great, but having much "admin" type experience, I've found
python to be less than Ideal when dealing with system calls and
standard Input Ouput.
For example, I've written complex tools that use perforce, I've taken
advantage of both regular IO and the perforce marshalled IO.  Under
heavy load, some of the threads in my scripts experience IO hang (Linux
and WIndows) (solaris and BSD were fine).  I did not get the same
behavior with Perl.
Having said that I still do 99% of my utilities in python.  Just be
aware.
i've written some complex tools around perforce too, but i use the perforce 
python module and get an order of magnitude better performance than when i use 
popen to execute the same command (if that is what you are referring to  by 
"regular IO and marshalled IO".  my app doesn't use threads, so i can't speak to 
that, but i've never experienced an IO hang related to perforce.

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


Re: socketserver question

2012-01-08 Thread Bryan
K Richard Pixley wrote:
[...]
> The doc says server.shutdown(), but if I call self.server.shutdown()
> from within handler.handle(), I seem to get a deadlock, which is exactly
> what I'd expect in a single threaded system with no way to "signal" the
> server.server_forever() loop which is several frames up the stack.

Well, it's documented behavior, but not what I would have expected.
Seems to go out of its way to deadlock. Stopping the main loop from
inside a request is perfectly reasonable thing to want to do, and
single-threaded GUI's do it all the time.

It's not an up-the-stack problem. shutdown() sets a flag that will
cause the loop not to repeat, but then calls wait() for an event that
won't be signaled until the loop exits, breaking the single-threaded
case. It's bad design.

Given the library class is as it is, one solution (untested) is to
relax being single-threader for just a bit.

import thread
    thread.start_new_thread(server.shutdown, ())

--
--Bryan

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


Re: Hash stability

2012-01-15 Thread Bryan
Chris Angelico wrote:
> Suggestion: Create a subclass of dict, the SecureDict or something,
> which could either perturb the hashes or even use a proper
> cryptographic hash function; normal dictionaries can continue to use
> the current algorithm. The description in Objects/dictnotes.txt
> suggests that it's still well worth keeping the current system for
> programmer-controlled dictionaries, and only change user-controlled
> ones (such as POST data etc).

I have to disagree; that's not how the world works, at least not
anymore. Competent, skilled, dedicated programmers have over and over
again failed to appreciate the importance and the difficulty of
maintaining proper function in an adversarial environment. The tactic
of ignoring security issues unless and until they are proven
problematic stands utterly discredited.

> It would then be up to the individual framework and module authors to
> make use of this, but it would not impose any cost on the myriad other
> uses of dictionaries - there's no point adding extra load to every
> name lookup just because of a security issue in an extremely narrow
> situation. It would also mean that code relying on hash(str) stability
> wouldn't be broken.

That seemingly "extremely narrow situation" turns out to be wide as
Montana. Maybe Siberia. Does your program take input? Does it accept a
format that could possibly be downloaded from a malicious site on the
Internet? Does your market include users who occasionally make
mistakes? If not, enjoy your utter irrelevance. If so,
congratulations: you write Internet software.

Varying the hash function is just the first step. Plausible attacks
dynamically infer how to induce degenerate behavior. Replacing the
dictionary hash function with a "proper cryptographic hash function"
is a naive non-solution; all things considered it's somewhat worse
than useless. An old and interesting and relevant exercise is to
implement a dictionary with O(1) insert, look-up, and delete in the
average non-adversarial case; and O(lg n) insert, look-up, and delete
in the worse case.

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


Implementing Tuples with Named Items

2006-01-09 Thread Bryan
in the python cookbook 2nd edition, section 6.7 (page 250-251), there a problem 
for implementing tuples with named items.  i'm having trouble understanding how 
one of commands work and hope someone here can explain what exactly is going 
on. 
  without copying all the code here, here is the gist of the problem:

from operator import itemgetter

class supertup(tuple):
 def __new__(cls, *args):
 return tuple.__new__(cls, args)

setattr(supertup, 'x', property(itemgetter(0)))

 >>> t = supertup(2, 4, 6)
 >>> t.x
 >>> 2


i understand what itemgetter does,

 >>> i = itemgetter(0)
 >>> i((2, 3, 4))
 >>> 2
 >>> i((4, 8, 12))
 >>> 4

i understand what property does, and i understand what setattr does.  i tested 
this problem myself and it works, but i can't understand how t.x evaluates to 2 
in this case.  how does itemgetter (and property) know what tuple to use?  in 
my 
  itemgetter sample, the tuple is passed to itemgetter so it's obvious to see 
what's going on.  but in the supertup example, it isn't obvious to me.


thanks,

bryan

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


wxHtmlHelpController

2006-07-12 Thread Bryan
is it possible to get the list of search results from the search box from 
wxPython's wxHtmlHelpControl without it displaying GUI?  i don't see an obvious 
way to do this.

thanks,

bryan

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


Re: wxHtmlHelpController

2006-07-12 Thread Bryan
Bryan wrote:
> is it possible to get the list of search results from the search box from 
> wxPython's wxHtmlHelpControl without it displaying GUI?  i don't see an 
> obvious 
> way to do this.
> 
> thanks,
> 
> bryan
> 

i meant wxPython's wxHtmlHelpController

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


Re: newbie graphing recommendations ?

2006-07-15 Thread Bryan
[EMAIL PROTECTED] wrote:
> Adam wrote:
>> Where should a py newbie start to do some 2D graphs on screen ?
>> PythonGraphApi,
>> Gato, looks interesting
>> pygraphlib,
>> matplotlib,
>> is there a best native Python place to start ?
> 
> The only good and simple way I have found so far to do some free
> graphics with Python in a Window is using PyGame. (You can also use
> TKinter, but it's slower).
> MatPlotLib is very good to graph functions, datasets, etc. and to save
> them to an image file.
> There are other good libs if/when you want 3D graphics.
> 
> Bye,
> bearophile
> 

do you think that pygame would be a good alternative to matplotlib to create 
some graphs such simple bar and line graphs?  i want to animate them as new 
data 
comes comes in.  i would also like to have the bars and graphs have nice 
shading 
if possible to give it a really attractive look.  also, do you know if a pygame 
windows can be embedded in a wxPython app?

thanks,

bryan

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


Re: Any pyChart experts lend a hand?

2006-07-17 Thread Bryan
[EMAIL PROTECTED] wrote:
> Code
> 
> from pychart import *
> import sys
> theme.get_options()
> 
> theme.use_color = True
> theme.output_format="png"
> theme.output_file="C:\Comp\graphic\pic1.png"
> theme.reinitialize()
> 
> data = [("foo", 10),("bar", 20), ("baz", 30), ("ao", 40)]
> 
> ar = area.T(size=(300,300), legend=legend.T(),
> x_grid_style = None, y_grid_style = None)
> 
> plot = pie_plot.T(data=data, arc_offsets=[0,10,0,10],
>   shadow = (2, -2, fill_style.gray50),
>   label_offset = 25,
>   arrow_style = arrow.a3)
> ar.add_plot(plot)
> ar.draw()
> 

i've been playing with pychart for exactly 5 minutes just before i read your 
post, so i doubt that makes me an expert, but i did your code to work by 
changing your code to this:


from pychart import *
import sys
theme.get_options()

theme.use_color = True

can = canvas.init('pic1.png')

data = [("foo", 10),("bar", 20), ("baz", 30), ("ao", 40)]

ar = area.T(size=(300,300), legend=legend.T(),
 x_grid_style = None, y_grid_style = None)

plot = pie_plot.T(data=data, arc_offsets=[0,10,0,10],
   shadow = (2, -2, fill_style.gray50),
   label_offset = 25,
   arrow_style = arrow.a3)
ar.add_plot(plot)
ar.draw()



bryan

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


PyThreadState_Swap(NULL)

2006-08-18 Thread Bryan
hi,

i've written a program that uses python c api code that lives in a 
shared library that is loaded by a custom apache module (mod_xxx).  this 
python c api code all works correctly under our test server and under 
apache but only if mod_python isn't loaded.  when apache loads 
mod_python as shown in the http.conf snippet below, 
PyThreadState_Swap(NULL) in mod_xxx returns NULL.  when the snippet of 
code in http.conf is commented out, it works again.  what do i have to 
do to have mod_xxx code work correctly when apache loads mod_python?


failure case when apache loads mod_python:
 Py_Initialize() succeeded
 PyThreadState_Swap(NULL) failed


sucess case when apache doesn't load mod_python:
 Py_Initialize() succeeded
 PyThreadState_Swap(NULL) succeeded


thanks,

bryan


--- mod_xxx ---

Py_Initialize();
if (Py_IsInitialized()) {
 log("Py_Initialize() succeeded");
}
else {
 log("Py_Initialize() failed");
}

PyEval_InitThreads();
g_py_main_interpreter = PyThreadState_Swap(NULL);
PyThreadState_Swap(g_py_main_interpreter);
PyEval_ReleaseLock();
if (g_py_main_interpreter) {
 log("PyThreadState_Swap(NULL) succeeded");
}
else {
 log("PyThreadState_Swap(NULL) failed");
}



 apache's http.conf 

LoadModule python_module   "../apache/bin/mod_python.so"

Listen 4119

 
 SetHandlermod_python
 PythonHandler mod_python.publisher
 PythonDebug   Off
 


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


Re: PyThreadState_Swap(NULL)

2006-08-19 Thread Bryan
Jack Diederich wrote:
> On Fri, Aug 18, 2006 at 02:21:40PM -0700, Bryan wrote:
>> i've written a program that uses python c api code that lives in a 
>> shared library that is loaded by a custom apache module (mod_xxx).  this 
>> python c api code all works correctly under our test server and under 
>> apache but only if mod_python isn't loaded.  when apache loads 
>> mod_python as shown in the http.conf snippet below, 
>> PyThreadState_Swap(NULL) in mod_xxx returns NULL.  when the snippet of 
>> code in http.conf is commented out, it works again.  what do i have to 
>> do to have mod_xxx code work correctly when apache loads mod_python?
>>
>>
>> failure case when apache loads mod_python:
>>  Py_Initialize() succeeded
>>  PyThreadState_Swap(NULL) failed
>>
>>
>> sucess case when apache doesn't load mod_python:
>>  Py_Initialize() succeeded
>>  PyThreadState_Swap(NULL) succeeded
>>
> 
> Running multiple python interpreters in the same process isn't supported.
> It works OK for most things but some low-level guts are shared between
> interpreters so it is possible to run into trouble.
> 
> You aren't running multiple interpreters in the same process.  You and
> mod_python both think you are in charge and end up nuking each other's 
> states. Py_Initialize() resets the global state and shouldn't be called 
> more than once.  You can create more than one sub-interpreter (check out
> the mod_python source for how, the source is small and readable).
> 
> The best thing to do would be to load your module last and conitionally
> call Py_Initialize() if someone else hasn't already.
> 
> -Jack


thanks for replying jack. i tested what you suggested.

i put our module after mod_python, commented out Py_Initialize(), and 
Py_IsInitialized() returned True, but PyThreadState_Swap() failed.

i put our module before mod_python, called Py_Initialize(), and 
Py_IsInitialized() returned True, but PyThreadState_Swap() failed.

i removed mod_python and our module succeeded.

i even tested combinations of calling and PyEval_InitThreads() but didn't work 
either.


bryan

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


Re: PyThreadState_Swap(NULL)

2006-08-20 Thread Bryan
let me try to ask the question again in a simpler more generic way.  i thought 
that the following lines of code, could not fail even if another library in the 
same process initialized the python interpreter first.


if (!Py_IsInitialized()) {
 Py_Initialize();
}

PyEval_InitThreads();
interpreter = PyThreadState_Swap(NULL);


what could another library do to make this fail?  and is there anything i can 
do 
to make this work in all situations?

thanks,

bryan

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


callback cashing python

2006-10-18 Thread Bryan
hi,

i have a multithreaded c server that calls process_method in a different 
c thread per each call.  process_method calls a python function bar in 
module foo.  function bar calls back into c.  i've removed all the type 
error handling and simplified the code to hopefully show a minimum 
amount of code.  when only one request is hitting the server at a time 
this works correctly even at fast speeds.  but as soon as a second 
request is made concurrently, the python24.dll will crash and 
session.callback() in the python code never returns.  i've tried 
wrapping the callback code in PyGILState_Ensure(), PyEval_SaveThread() 
without success.

does anyone know what i have to do to the c callback to prevent python 
from crashing?

thanks,

bryan


static void process_method(session *session)
{
 PyObject  *py_obj_session = NULL;
 PyObject  *py_mod_foo = NULL;
 PyObject  *py_call_bar= NULL;
 PyThreadState *py_interp  = NULL;

 py_interp = get_py_interpreter(session);
 PyEval_AcquireLock();
 PyThreadState_Swap(py_interp);
 py_obj_session = get_py_session(session);

 py_mod_foo = PyImport_ImportModule("foo");
 py_call_bar = PyObject_GetAttrString(py_mod_foo, "bar");
 PyObject_CallFunctionObjArgs(py_call_bar, py_obj_session, NULL);

 Py_XDECREF(py_call_bar);
 Py_XDECREF(py_mod_foo);
 Py_XDECREF(py_obj_session);

 PyThreadState_Swap(NULL);
 PyEval_ReleaseLock();
}


# module bar

def bar(session):
 session.callback()



/* session.callback() /*
static PyObject* callback(PyObject *self, PyObject *args)
{
 Py_INCREF(Py_None);
 return Py_None;
}

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


Re: callback crashing python

2006-10-19 Thread Bryan
Bryan wrote:
> hi,
> 
> i have a multithreaded c server that calls process_method in a different 
> c thread per each call.  process_method calls a python function bar in 
> module foo.  function bar calls back into c.  i've removed all the type 
> error handling and simplified the code to hopefully show a minimum 
> amount of code.  when only one request is hitting the server at a time 
> this works correctly even at fast speeds.  but as soon as a second 
> request is made concurrently, the python24.dll will crash and 
> session.callback() in the python code never returns.  i've tried 
> wrapping the callback code in PyGILState_Ensure(), PyEval_SaveThread() 
> without success.
> 
> does anyone know what i have to do to the c callback to prevent python 
> from crashing?
> 
> thanks,
> 
> bryan
> 
> 
> static void process_method(session *session)
> {
>  PyObject  *py_obj_session = NULL;
>  PyObject  *py_mod_foo = NULL;
>  PyObject  *py_call_bar= NULL;
>  PyThreadState *py_interp  = NULL;
> 
>  py_interp = get_py_interpreter(session);
>  PyEval_AcquireLock();
>  PyThreadState_Swap(py_interp);
>  py_obj_session = get_py_session(session);
> 
>  py_mod_foo = PyImport_ImportModule("foo");
>  py_call_bar = PyObject_GetAttrString(py_mod_foo, "bar");
>  PyObject_CallFunctionObjArgs(py_call_bar, py_obj_session, NULL);
> 
>  Py_XDECREF(py_call_bar);
>  Py_XDECREF(py_mod_foo);
>  Py_XDECREF(py_obj_session);
> 
>  PyThreadState_Swap(NULL);
>  PyEval_ReleaseLock();
> }
> 
> 
> # module bar
> 
> def bar(session):
>  session.callback()
> 
> 
> 
> /* session.callback() /*
> static PyObject* callback(PyObject *self, PyObject *args)
> {
>  Py_INCREF(Py_None);
>  return Py_None;
> }
> 

update... it's still crashing even without the callback.


function bar is now changed to something like this:

def bar(session):
 return 1

i'm calling this c method process_method concurrently in two process 
where each process is sending requests at a rate of approximately 100 
per second.  each request is processed on the server side in it's own c 
thread.  when the crash happens, it appears that the python code 
successfully completes.  in other words, it never crashes in the middle 
of function bar.  is PyEval_AquireLock, PyThreadState_Swap thread safe 
across c threads?


thanks,

bryan




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


python thread state

2006-10-23 Thread Bryan
hi,

i'm trying to write a multithreaded embedded python application and i'm
having some trouble.  i found this article "embedding python in
multi-threaded c/c++ applications" in the python journal
(http://www.linuxjournal.com/article/3641) but there still seems to be a
step missing for me.

each time a function in my c module is called, it's called on a different c
thread.  i would then like to call a function in an embedded python script.
from my understanding of the article, you can associate a python script
with a c thread by calling PyThreadState_New as in this code:

// save main thread state
PyThreadState * mainThreadState = NULL;
mainThreadState = PyThreadState_Get();
PyEval_ReleaseLock();

// setup for each thread
PyEval_AcquireLock();
PyInterpreterState * mainInterpreterState = mainThreadState->interp
PyThreadState * myThreadState = PyThreadState_New(mainInterpreterState);
PyEval_ReleaseLock();

//execute python code
PyEval_AcquireLock();
PyThreadState_Swap(myThreadState);
# execute python code
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();


unfortunately, this doesn't work for me because each time i get called to
execute python code, i'm in a new c thread and PyThreadState_Swap seems to
want to be executed in the same c thread that PyThreadState_New was
executed in.  if this isn't the case, please let know.  

i then called PyThreadState_New each time i wanted to call a python function
in the script, but PyThreadState_New wipes out, or rather gives you a new
global dictionary, because i lost all my global variables.  the article
assumes you have one c thread per python thread state, but i want multiple
c threads per python thread state. Is there a c api function that will
associate a c thread without resetting the global dictionary?

thank you,

bryan

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


Re: how is python not the same as java?

2006-11-11 Thread Bryan
Jorge Vargas wrote:


> 
> the pyc files are just a "catching" system for the common python
> developer, as for the java developer the .class files are executable
> code. In python noone runs the pyc files, the interpreter takes care
> of this for you.
> 

this is an incorrect statement.  we (the company i work for) only ship the
pyc files, and our customers _only_ run the pyc files.  and our embedded
python contains no .py files.  from our perspective,  java .class files and
python .pyc files are treated exactly the same.  and there is very little
difference between jar files containing .class files and zip files
containing .pyc files.


bryan

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


Re: Open Source Charting Tool

2006-06-05 Thread Bryan
Harry George wrote:
> See pygdchart
> http://www.nullcube.com/software/pygdchart.html
> 

this looks pretty nice.  i don't see in the docs if and how it can be 
integrated 
with other gui toolkits such wxpython. :(

bryan

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


language-x-isms

2006-06-07 Thread Bryan
does anyone know if there is a collection somewhere of common python mistakes 
or 
inefficiencies or unpythonic code that java developers make when first starting 
out writing python code? if not, maybe we could start a thread on this.

for example, i've noticed several java developers i know write python code like 
this:

foo_list = [...]
for i in range(len(foo_list)):
print '%d %s' % (i, foo_list[i])


of course, one way to do this would be to use enumerate:

for i, foo in enumerate(foo_list):
 print '%d %s' % (i, foo)


i'm guessing there is a lot of these language-x-isms that people on this list 
have seen. i think it would be helpful to both the new java-to-python developer 
and python developers in general to be aware of these.

just an idea.
feel free to discuss any language-x-isms, not necessarily just java-isms.

bryan

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


numeric/numpy/numarray

2006-06-12 Thread Bryan
hi,

what is the difference among numeric, numpy and numarray?  i'm going to start 
using matplotlib soon and i'm not sure which one i should use.


this page says, "Numarray is a re-implementation of an older Python array 
module 
called Numeric"
http://www.stsci.edu/resources/software_hardware/numarray

this page says, "NumPy derives from the old Numeric code base and can be used 
as 
a replacement for Numeric."
http://numeric.scipy.org/

i looked at the matplotlib examples today and if i remember correctly, the 
examples didn't use numarray.

so i'm a bit confused.

thanks,

bryan

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


Re: numeric/numpy/numarray

2006-06-13 Thread Bryan
Simon Percivall wrote:
> Bryan wrote:
>> hi,
>>
>> what is the difference among numeric, numpy and numarray?  i'm going to start
>> using matplotlib soon and i'm not sure which one i should use.
>>
>>
>> this page says, "Numarray is a re-implementation of an older Python array 
>> module
>> called Numeric"
>> http://www.stsci.edu/resources/software_hardware/numarray
>>
>> this page says, "NumPy derives from the old Numeric code base and can be 
>> used as
>> a replacement for Numeric."
>> http://numeric.scipy.org/
>>
>> i looked at the matplotlib examples today and if i remember correctly, the
>> examples didn't use numarray.
>>
>> so i'm a bit confused.
>>
>> thanks,
>>
>> bryan
> 
> Look again at numeric.scipy.org, and this time: read the whole page,
> especially the section called "Older Array Packages".
> 

at the end of that page, it says:

"Numarray is another implementation of an arrayobject for Python written after 
Numeric and before NumPy. Sponsors of numarray have indicated they will be 
moving to NumPy as soon as is feasible for them so that eventually numarray 
will 
be phased out."


on the python wiki
"NumArray is the current reimplementation of NumPy."
http://wiki.python.org/moin/NumArray

so, was Numarray written *before* NumPY, or was it a reimplementation of NumPy 
which implies it came *after* NumPy?  it seems clear that Numeric is the old 
one 
and i read is not being worked on anymore.  so that leaves Numarray and numpy. 
which of these two should i use?

thanks,

bryan



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


Re: numeric/numpy/numarray

2006-06-13 Thread Bryan
Ben Sizer wrote:
> Bryan wrote:
> 
>> at the end of that page, it says:
>>
>> "Numarray is another implementation of an arrayobject for Python written 
>> after
>> Numeric and before NumPy. Sponsors of numarray have indicated they will be
>> moving to NumPy as soon as is feasible for them so that eventually numarray 
>> will
>> be phased out."
>>
>>
>> on the python wiki
>> "NumArray is the current reimplementation of NumPy."
>> http://wiki.python.org/moin/NumArray
>>
>> so, was Numarray written *before* NumPY, or was it a reimplementation of 
>> NumPy
>> which implies it came *after* NumPy?  it seems clear that Numeric is the old 
>> one
>> and i read is not being worked on anymore.  so that leaves Numarray and 
>> numpy.
>> which of these two should i use?
> 
> Bryan,
> 
> NumPy is the name of both an old package and a new package. I believe
> that NumArray came after the first incarnation, but that the new
> incarnation of NumPy is the most recent, and is probably the one you
> want.
> 

thanks ben,

i'll use NumPy then.  just wish it was clear and obvious which one to use so i 
wouldn't have had to ask this question here.

bryan

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


Re: language design question

2006-07-09 Thread Bryan
Steven Bethard wrote:

> The advantage of a functional form over a method shows up when you write 
> a function that works on a variety of different types. Below are 
> implementations of "list()", "sorted()" and "join()" that work on any 
> iterable and only need to be defined once::
> 
>  def list(iterable):
>  result = []
>  for item in iterable:
>  result.append(item)
>  return result
> 
>  def sorted(iterable):
>  result = list(iterable)
>  result.sort()
>  return result
> 
>  def join(iterable):
>  # this is more efficient in C, where the string's buffer can be
>  # pre-allocated before iterating through the loop.
>  result = ''
>  for item in iterable:
>  result += item
>  return result
> 
> Now, by providing these as functions, I only have to write them once, 
> and they work on *any* iterable, including some container object that 
> you invent tomorrow.
> 
> If everything were methods, when you invented your container object 
> tomorrow, you'd have to reimplement these methods on your class. (Or 
> we'd have to introduce a Container class to provide them, and everyone 
> would have to inherit from that if they wanted to define a container.)
> 

could you get the same result by putting these methods in base class object 
that 
everything subclasses?  then you wouldn't have to reimplement these methods on 
your class either, right?  i'm not arguing for one method or the other.  just 
curious about the difference.

bryan

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


Re: language design question

2006-07-10 Thread Bryan
Fredrik Lundh wrote:
> Bryan wrote:
> 
>> could you get the same result by putting these methods in base
>  > class object that everything subclasses?
> 
> and how do you make sure that everything subclasses this base class ?
> 
> 
> 

in this hypothetical case, i was assuming len() would be put in object and 
every 
class subclasses object implicitly or explicitly (ie, new style classes only). 
if it was done that way, would len(obj) == obj.len() in all cases?


bryn


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


Re: language design question

2006-07-11 Thread Bryan
Fredrik Lundh wrote:
> "Bryan" wrote:
> 
>>> and how do you make sure that everything subclasses this base class ?
>> in this hypothetical case, i was assuming len() would be put in object and 
>> every
>> class subclasses object implicitly or explicitly (ie, new style classes 
>> only).
>> if it was done that way, would len(obj) == obj.len() in all cases?
> 
> why should *everything* be forced to have a length ?
> 
>  
> 

good point.  you're right, everything should not have to be forced to have a 
length.  i thought ruby did something like putting length functionality in 
their 
highest level base class.  then subclasses would either inherit it or could 
modify it in their own class.  my coworker who knows ruby complains about 
python's len(obj) too.  so i assumed ruby implements this in their equivalent 
base object class.  i just briefly searched the ruby docs, but i can't seem to 
find it.  if it is done this way in ruby, then i wonder what happens what 
obj.length would return for objects that you would not normally associate as 
having a length, such as what steve holden mentioned 1.length.



bryan

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


downloading eggs

2006-09-10 Thread Bryan
i'm trying to just download the turbogears eggs without installing it.  i've 
read the turbogear install instructions and the easy_install help.


from the easy_install web site:

If you have another machine of the same operating system and library versions 
(or if the packages aren't platform-specific), you can create the directory of 
eggs using a command like this:

easy_install -zmaxd somedir SomePackage



i tried this:


C:\python\turbogears>easy_install -zmaxd TurboGears TurboGears
Processing TurboGears
error: Couldn't find a setup script in TurboGears


C:\python\turbogears>easy_install -zmaxd . TurboGears
Processing TurboGears
error: Couldn't find a setup script in TurboGears



on the turbogears mailing list, someone posted this:

You could even do "easy_install -zmaxd TurboGears" at home to just
download the files and then bring in the files on a usb key and then
"easy_install -f . TurboGears" from the usb drive.


i tried this:

C:\python\turbogears>easy_install -zmaxd TurboGears
error: No urls, filenames, or requirements specified (see --help)


i copied the ez_setup.py file from turbogears and tried the commands against 
that script but it didn't work.  i'm using setuptools-0.6c2 if that is helpful 
to anyone.


thanks,

bryan



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


Re: stock quotes

2006-09-13 Thread Bryan
Donlingerfelt wrote:
> I would like to download stock quotes from the web, store them, do
> calculations and sort the results.  However I am fairly new and don't have a
> clue how to parse the results of a web page download.   I can get to the
> site, but do not know how to request the certain data  need.  Does anyone
> know how to do this?  I would really appreciate it.  Thanks.
> 
> 

i recently wrote a moinmoin macro which i believe does exactly what you want. 
even though you aren't writing a moinmoin macro, all the stuff you need is here.

usage: [[stock(amzn,goog,yhoo)]]

note that the string 'amzn,goog,yahoo' is passed in as the symbols variable and 
is placed as-is onto the url.  you will receive one .csv file from yahoo with 
*all* the ticker info for all symbols you requested... very cool :)  then for 
each row in the csv file, i pull out each column (data) and set a red or green 
color based on whether the stock is up or down for the day as well as providing 
a link to the yahoo finance site (finance.google.com in my latest version) when 
that symbol is clicked.  and finally return an html table with the data.

i hope this helps you.  i apologize in advance if this code doesn't come 
through 
the newsgroup formatted properly.



import urllib
import csv
def execute(macro, symbols):
 color = 'black'
 try:
 reader = 
csv.reader(urllib.urlopen('http://finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv&e=.csv'
 
% symbols))
 data = []
 for symbol, trade, date, time, change, opened, hi, low, volume in 
reader:
 num = float(change)
 if num > 0:
 color = 'green'
 elif num < 0:
 color = 'red'
 percent = 100 * float(change) / (float(trade) - float(change))
 data.append('http://finance.yahoo.com/q?s=%s";>%s%s (%s / 
%.2f%%)' % (symbol, symbol, color, trade, change, percent))
     return '%s' % ''.join(data)
 except:
 return '%s: Stock information unavailable' % symbols



bryan

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


Re: xmlrpc with Basic Auth

2006-09-15 Thread Bryan
Milos Prudek wrote:
> I need to use XML-RPC call with Basic Authorization in HTTP headers. I found 
> xmlrpclibBasicAuth.py, and it can be used as follows:
> 
> from xmlrpclibBasicAuth import Server
> s=Server("http://www.example.com/rpc.php","user","pwd";)
> print s.system.listMethods()
> 
> Is this possible in plain xmlrpclib, without xmlrpclibBasicAuth.py? 
> 
> I found the Transport class in xmlrpclib, and it has a method 
> "get_host_info", 
> which parses "user:pwd" out of "user:[EMAIL PROTECTED]". But when I tried to 
> instantiate Server, it threw error "unsupported XML-RPC protocol". Here is a 
> snippet:
> 
> from xmlrpclib import Server
> s=Server("user:[EMAIL PROTECTED]://www.example.com/rpc.php")
> ...
> File "/usr/local/lib/python2.3/xmlrpclib.py", line 1293, in __init__
> raise IOError, "unsupported XML-RPC protocol"
> IOError: unsupported XML-RPC protocol
> 
> I know that I am using it incorrectly. Does the basic authentication support 
> in xmlrpclib mean something else than I take it for?
> 


i'm currently using xmlrpclib with basic auth and i use it like this:


from xmlrpclib import Server
s=Server("http://user:[EMAIL PROTECTED]/rpc.php")


bryan

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


saving an exception

2006-10-02 Thread Bryan
hi,

i would like to save an exception and reraise it at a later time.


something similar to this:

exception = None
def foo():
    try:
        1/0 
    except Exception, e:
        exception = e

if exception: raise exception


i have a need to do this because in my example foo is a callback from c code
which was originally called from python and i can't modify the c code. 
with the above code, i'm able to successfully raise the exception, but the
line number of the exception is at the place of the explicit raise instead
of the where the exception originally occurred.  is there anyway to fix
this?


thanks,

bryan

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

buildbot

2006-11-29 Thread Bryan
does anyone know if processes defined around buildbot would be similar to
the one used by the mozilla seamonkey project which uses tinderbox?  this
link shows an example of an entire checkin cycle using tinderbox and it's
quite detailed and gives a very good picture of what using the product
would be like.

http://www.mozilla.org/hacking/working-with-seamonkey.html

i know python is currently using buildbot...  are there any differences or
simplifications in the processes using buildbot?

thanks,

bryan



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


alternate language

2006-12-10 Thread Bryan
what is a good alternate language to learn? i just want something to expand
my mind and hopefully reduce or delay any chance of alzheimer's. i would
especially like to hear from those of you who learned python _before_ these
languages.

haskell, erlang, ocaml, mozart/oz, rebel, etc.

i don't require any of these features, but extra browny points for any of
the following:

interactive interpreter
batteries included
can integrate with c
compiles to native code
can use a gui toolkit such as wx
doesn't take 60 hour weeks over years to master


thanks,

bryan




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


Re: Who is www.python.org for? (was Re: New Python.org website ?)

2006-01-22 Thread Bryan
Aahz wrote:

> The idea is that we make www.python.org even more minimal than the
> current beta.python.org; it becomes a portal similar in simplicity to
> google.com (with a bit more explanation).  It would lead off to
> subdomains such as business.python.org, tech.python.org, help.python.org,
> and so on.  That would make it easy for people to bookmark a specific
> section that was appropriate for their needs.
> 

+1  IMO, this is the best suggestion i've heard yet.  it seems like such a 
simple, clean, minimalist yet fully functional solution. and it seems to 
elegantly solve the suits vs developer issue.  for those who like fancy images 
on the home page, you could now have an image that clearly links to each 
subdomain.  you could even have a search on the home page that searches all the 
python subdomains.

bryan

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


Re: Which IDE is recommended?

2005-05-02 Thread Bryan
dcrespo wrote:
>>But I personally recommend DrPython. (Not only, I'm a member of the
>>project).
> 
> 
> I saw this message and downloaded DrPython. It's very good: I like the
> class/functions browser while I'm coding... but I can't find the
> autocompletion feature you talk, and I think this feature is very
> important. Where it is?
> 
> Daniel
> 

i saw this message too and i've been using it for the last couple days, but i 
don't see the class/functions browser you are talking about.  where is it???

thanks,

bryan

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


Re: New Python regex Doc

2005-05-05 Thread Bryan
Xah Lee wrote:

> Extra point: If the Python command line interface is actually a robust
> application, like so-called IDE e.g. Mathematica front-end, then things
> are very different. In reality, the Python command line interface is a
> fucking toy whose max use is as a simplest calculator and double as a
> chanting novelty for standard coding morons. In practice it isn't even
> suitable as a trial'n'error pad for real-world programing.
> 

i disagree with this 110%.  i write python and jython code everyday at my 
company and the python interpreter (or command line interface) is always 
running 
on my computer whether it's from the command prompt, idle, pythonwin, pyshell, 
etc..  using the interpreter while you are coding is an invaluable tool and 
actually helps speed up software development which is opposite of what was 
stated by xah lee.  it allows complete freedom to experiment reducing the 
amount 
of bugs that are in the real product.  it's also useful to use the pywin 
modules 
and experiment with the win32 api interactively, or use the jython interpreter 
and experiment with some java api without any compilation step.  i have never 
found these interpreters to be anything but very robust and *IT IS SUITABLE* as 
trial'n'error pad for real-world programming.  the above comment can possible 
only be made by someone who doesn't actually use it for real world programming.


bryan

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


How to reset sys.exec_prefix?

2007-08-08 Thread Bryan
Somehow on my linux box I scrood things up and I lost my python path info.

If I check sys.exec_prefix or sys.prefix it shows '/usr/local/', where 
it should show '/usr/'.

Is there a config file somewhere that I can change to fix this, or do I 
need to do a rebuild/reinstall?  Hope not.

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


Re: How to reset sys.exec_prefix?

2007-08-08 Thread Bryan
Bryan wrote:
> Somehow on my linux box I scrood things up and I lost my python path info.
> 
> If I check sys.exec_prefix or sys.prefix it shows '/usr/local/', where 
> it should show '/usr/'.
> 
> Is there a config file somewhere that I can change to fix this, or do I 
> need to do a rebuild/reinstall?  Hope not.
> 
> Thanks,
> B

Actually to clarify a bit here's what I see:

 >>> sys.prefix
'/usr/local'
 >>> sys.path
['', '/usr/local/lib/python25.zip', '/usr/local/lib/python2.5', 
'/usr/local/lib/python2.5/plat-linux2', 
'/usr/local/lib/python2.5/lib-tk', 
'/usr/local/lib/python2.5/lib-dynload', 
'/usr/local/lib/python2.5/site-packages', 
'/usr/local/lib/python2.5/site-packages/PIL']

I am thinking that the prefix is prepended to all the paths.

All my stuff lives in 'usr/lib/python2.5', so I was hoping by just 
changing my prefix it would set the rest of the paths accordingly.

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


Simple python iteration question

2007-08-14 Thread Bryan
Hi,

I just started with python, and have a for loop question

In c++ (or a number of other languages) I can do this:

for (int i=0, j=0; i < i_len, j< j_len; ++i, ++j) {}

If I have this in python:
l = ['a', 'b', 'c']

I want to get the value and also an iterator:
for i,v in len(l), l:
print v
print i

Or something like this without declaring the iterator outside my loop...

How do I do this?
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python strings

2006-05-03 Thread Bryan
Gerhard Häring wrote:
> Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
> [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> s = "\x000"
>>>> s[0] == chr(0)
> True
> 
> - -- Gerhard

this works too :)

 >>> s = '\x001'
 >>> s[0] == chr(0)
True
 >>> s = '\x00abc'
 >>> s[0] == chr(0)
True


i think it would be more clear not to use 3 digits for this example since \x 
only uses the next two numbers, not 3.

 >>> s = '\x00'
 >>> s[0] == chr(0)
True


bryan

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


Re: stripping unwanted chars from string

2006-05-03 Thread Bryan

>  >>> keepchars = set(alphabet + alphabet.upper() + '1234567890-.')

or

 >>> keepchars = set(string.letters + string.digits + '-.')

bryan

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


lines of code per functional point

2006-05-09 Thread Bryan
in document, which is titled, "Java and programmer productivity", there is a 
table on page 4 which shows LOC/FP for several languages.  unfortunately, 
python 
is the only language "dashed out" and has no value.  i'm unable to google and 
find a source that shows this value for python, but i did find other sites that 
show java and c++ at 53 LOC/FP which is the same as this document.  is it safe 
to assume that python's value would be similar to perl's value of 21 ?

http://www.abo.fi/~kaisa/FN.pdf

thanks,

bryan

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


matplotlib

2006-05-11 Thread Bryan
does anyone know if matplotlib is robust enough to use in a commercial 
application?  are there any existing commercial or popular open source programs 
that use it?

thanks,

bryan

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


Re: Tabs versus Spaces in Source Code

2006-05-14 Thread Bryan
Xah Lee wrote:
> Tabs versus Spaces in Source Code
> 
> Xah Lee, 2006-05-13
> 
> In coding a computer program, there's often the choices of tabs or
> spaces for code indentation. There is a large amount of confusion about
> which is better. It has become what's known as “religious war” —
> a heated fight over trivia. In this essay, i like to explain what is
> the situation behind it, and which is proper.
> 
> Simply put, tabs is proper, and spaces are improper. Why? This may seem
> ridiculously simple given the de facto ball of confusion: the semantics
> of tabs is what indenting is about, while, using spaces to align code
> is a hack.
> 

i agree, tabs is proper and i always use the tab key to indent... it puts in 4 
spaces.

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

groupby

2006-05-22 Thread Bryan
can some explain why in the 2nd example, m doesn't print the list [1, 1, 1] 
which i had expected?


 >>> for k, g in groupby([1, 1, 1, 2, 2, 3]):
... print k, list(g)
...
1 [1, 1, 1]
2 [2, 2]
3 [3]


 >>> m = list(groupby([1, 1, 1, 2, 2, 3]))
 >>> m
[(1, ), (2, ), (3, )]
 >>> list(m[0][1])
[]
 >>>


thanks,

bryan

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


Re: groupby

2006-05-22 Thread Bryan
George Sakkis wrote:
> Bryan wrote:
> 
>> can some explain why in the 2nd example, m doesn't print the list [1, 1, 1]
>> which i had expected?
>>
>>
>>  >>> for k, g in groupby([1, 1, 1, 2, 2, 3]):
>> ... print k, list(g)
>> ...
>> 1 [1, 1, 1]
>> 2 [2, 2]
>> 3 [3]
>>
>>
>>  >>> m = list(groupby([1, 1, 1, 2, 2, 3]))
>>  >>> m
>> [(1, ), (2, > object
>> at 0x00AAC5A0>), (3, )]
>>  >>> list(m[0][1])
>> []
>>  >>>
>>
>>
>> thanks,
>>
>> bryan
> 
> I've tripped on this more than once, but it's in the docs
> (http://docs.python.org/lib/itertools-functions.html):
> 
> "The returned group is itself an iterator that shares the underlying
> iterable with groupby(). Because the source is shared, when the groupby
> object is advanced, the previous group is no longer visible. So, if
> that data is needed later, it should be stored as a list"
> 
> George
> 

i read that description in the docs so many times before i posted here. now 
that 
i read it about 10 more times, i finally get it.  there's just something about 
the wording that kept tripping me up, but i can't explain why :)

thanks,

bryan

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


Re: graphs and charts

2006-05-24 Thread Bryan
Terry Hancock wrote:
> Yaron Butterfield wrote:
>>  What's the best way to on-the-fly graphs and charts using Python? Or
>>  is Python not really the best way to do this?
> 
> I quite enjoyed using Biggles for this:
> 
> http://biggles.sf.net
> 
> There are many different choices, though.
> 
> Cheers,
> Terry
> 

Terry Hancock wrote:
 > Yaron Butterfield wrote:
 >>  What's the best way to on-the-fly graphs and charts using Python? Or
 >>  is Python not really the best way to do this?
 >
 > I quite enjoyed using Biggles for this:
 >
 > http://biggles.sf.net
 >
 > There are many different choices, though.
 >
 > Cheers,
 > Terry
 >

hi terry,

this is the first time i've heard of biggles.  it looks really nice and simple 
to use?  and i especially like your use of gradients in example 9.  does 
biggles 
integrate well wxPython?  if so, do you have an example of how to add it to a 
wxPython panel?

thanks,

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


Upgrading standard library module

2009-02-13 Thread Bryan
I have a Python v2.5.2 server running and I found some undesirable
behavior in the xmlrpclib module that is included with that version of
Python.  The xmlrpclib version that is included with Python 2.6
changes the behavior for the better.  I nervous about upgrading my
Python install to 2.6 on this server because I remember reading in the
docs of a library I use that it targets the 2.5 branch.  What is the
best way to only upgrade the xmlrpclib in my 2.5 install?

Also, have you all had problems with libraries not specifying which
Python version they target?  I can't find a requirements for the
formencode library.  It is kind of scary upgrading my Python server
install without being sure all my libraries will work.  Experiences??

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


Re: Upgrading standard library module

2009-02-13 Thread Bryan
On Feb 13, 1:52 pm, Jason Scheirer  wrote:
> On Feb 13, 12:42 pm, Bryan  wrote:
>
> > I have a Python v2.5.2 server running and I found some undesirable
> > behavior in the xmlrpclib module that is included with that version of
> > Python.  The xmlrpclib version that is included with Python 2.6
> > changes the behavior for the better.  I nervous about upgrading my
> > Python install to 2.6 on this server because I remember reading in the
> > docs of a library I use that it targets the 2.5 branch.  What is the
> > best way to only upgrade the xmlrpclib in my 2.5 install?
>
> > Also, have you all had problems with libraries not specifying which
> > Python version they target?  I can't find a requirements for the
> > formencode library.  It is kind of scary upgrading my Python server
> > install without being sure all my libraries will work.  Experiences??
>
> > Bryan
>
> Python has always been pretty backwards-compatible and has a nice
> roadmap for upgrades (with new languages features living in __future__
> for a version or so before they're in the main version). With the
> exception of 2.X->3, you can usually assume that any pure-Python
> modules written for 2.x will work in 2.(x+1), and assuming they don't
> issue any warnings, also in 2.(x+2).
>
> What behavior, exactly, do you not like in xmlrpclib? Diffing the 2.5
> and 2.6, only significant differences I see are checks for True/False
> as builtins left over from pre-2.4 and some datetime handling.

The xmlrpclib in my 2.5.2 install does not allow the marshaling of my
custom objects.  It checks the type of my object, and if it isn't in a
hard-coded list of types, then a "Cannot marshal object of 
type" exception message shows up.  The version in my Windows 2.6
install has a fall back case where if the type is not in the hard-
coded list, it simply calls Object.__dict__ to get a graph of the
object's values that can be marshaled into xmlrpc.

I am using xmlrpc through Pylons.  As a workaround, instead of
returning my custom objects in my xmlrpc server functions, I return
MyObject.__dict__

I also did not see anything in the revision log in the source file
about this change.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   >