Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Peter Wang
On Jan 27, 3:16 pm, Reckoner recko...@gmail.com wrote:
 I'm not sure this is possible, but I would like to have
 a list of  objects

 A=[a,b,c,d,...,z]

 where,  in the midst of a lot of processing I might do something like,

 A[0].do_something_which_changes_the_properties()

 which alter the properties of the object 'a'.

 The trick is that I would like A to be mysteriously aware that
 something about the  object 'a' has changed so that when I revisit A,
 I will know that the other items in the list need to be refreshed to
 reflect the changes in A as a result of changing 'a'.

 Even better would be to automatically percolate the subsequent changes
 that resulted from altering 'a' for the rest of the items in the list.
 Naturally, all of these items are related in some parent-child
 fashion.

 that might be a lot to ask, however.

 Any advice appreciated.

You should really look at Enthought's Traits package.  It does exactly
what you are asking for, and much, much more.  See:

http://code.enthought.com/projects/traits/documentation.php
http://code.enthought.com/projects/traits/examples.php

Using Traits, you could do the following:

from enthought.traits.api import *
class Child(HasTraits):
state = Enum(happy, sad, bawling)

class Parent(HasTraits):
child = Instance(Child)

@on_trait_change('child.state')
def handler(self):
print new child state:, self.child.state

bob_jr = Child()
bob = Parent(child = bob_jr)

bob_jr.state = sad
# This would result in bob.handler() being called

(Disclosure: I work at Enthought and have been using Traits heavily
for the last 4+ years.)

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


[issue4515] Formatting error in What's New in Python 3.0

2008-12-03 Thread Peter Wang

New submission from Peter Wang [EMAIL PROTECTED]:

In the section Removed Syntax, there is some ReST markup that leaked
through into the output:

The only acceptable syntax for relative imports is from .``[*module*]
:keyword:`import` *name*; :keyword:`import` forms not starting with ``.
are always interpreted as absolute imports. (PEP 0328)

--
assignee: georg.brandl
components: Documentation
messages: 76865
nosy: georg.brandl, pwang
severity: normal
status: open
title: Formatting error in What's New in Python 3.0
versions: Python 3.0

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4515
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4516] Another formatting error in What's New in Python 3.0

2008-12-03 Thread Peter Wang

New submission from Peter Wang [EMAIL PROTECTED]:

In the Library Changes section, the next to last bullet point about
string.letters has leaked through some ReST markup into the final
output: :data:string.letters`

--
assignee: georg.brandl
components: Documentation
messages: 76866
nosy: georg.brandl, pwang
severity: normal
status: open
title: Another formatting error in What's New in Python 3.0
versions: Python 3.0

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Documenation for yum and rpmUtils modules

2008-11-13 Thread Peter Wang
Hi All,

I'm new to Python. I troubleshoot a yum install error. so i'm studying yum 
and rmpUtils module and try to understand how yum works. Do you know where 
can I find the documenation for yum and rpmUtils module?

Thanks,
Peter


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


Can i use this script as a python evaluator?

2008-10-20 Thread Peter Wang

code
#! /bin/sh
python -c import sys;exec(sys.stdin)
/code

Emacs has a function `shell-command-on-region', which takes region as
input for the evaluator (script above), and output its result. I have
tried and found it works, is there any problems for this, or any other
better solution for it? Thanks.


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


Re: Can i use this script as a python evaluator?

2008-10-20 Thread Peter Wang
Bruno Desthuilliers [EMAIL PROTECTED] writes:

 Peter Wang a �crit :
 code
 #! /bin/sh
 python -c import sys;exec(sys.stdin)
 /code

 Emacs has a function `shell-command-on-region', which takes region as
 input for the evaluator (script above), and output its result. I have
 tried and found it works, is there any problems for this, or any other
 better solution for it? Thanks.

 If your problem is to eval a region of a python buffer and output the
 result to another buffer, then python-mode.el (the one that comes with
 Python, not the python.el bundled with recent emacs versions) already
 know how to do so.
Yes, I want eval a region, but likely not a python buffer, for example, 
in a *w3m* buffer.

 Else please explain what you're trying to do ?
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Can i use this script as a python evaluator?

2008-10-20 Thread Peter Wang
Nathan Seese [EMAIL PROTECTED] writes:

 #! /bin/sh
 python -c import sys;exec(sys.stdin)

 I know this isn't your question, but I think you could write that more 
 cleanly with:

 #!/usr/bin/python
 import sys
 exec(sys.stdin)
thanks.
What's the difference between this and mine? 

I think what i need actually is a python function like
`file_get_contents' in php:)
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: automatically insert text in ms-word properties

2008-10-07 Thread Peter Wang
gita ziabari [EMAIL PROTECTED] writes:

 All,

 I wanna use python to automatically insert text in ms-word properties.
 Anyone could help me?
Why not use VBA for that work? 

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

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


Re: Fast 2D Raster Rendering with GUI

2008-03-18 Thread Peter Wang
On Mar 18, 6:51 pm, Ivan Illarionov [EMAIL PROTECTED] wrote:
  That's another new step for me. Any ideas where to start?

 http://docs.python.org/ext/simpleExample.html

 And look into the source of existing extensions. PIL and PyCairo are
 the best in your situation.

You shouldn't be afraid of doing raster graphics in Python; you'll
just need to be familiar with Numpy.  You can easily compose layers,
mask out operations to only happen on one channel, etc., and code it
all up in Python while getting C-level speed.  The gotcha, if you use
PIL, is that you're going to have to use tostring() and fromstring()
to get the array data back and forth between numpy and PIL.  An
alternative is to use openGL, as others have suggested, and blit into
a texture.  If you use pyglet, for instance, you can use Andrew
Straw's pygarrayimage module to convert a numpy array directly into a
texture.

I wouldn't recommend Cairo for doing pixel-level ops, since it is a
vector graphics library.


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


Re: Any fancy grep utility replacements out there?

2008-03-18 Thread Peter Wang
On Mar 18, 5:16 pm, Robert Kern [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  So I need to recursively grep a bunch of gzipped files.  This can't be
  easily done with grep, rgrep or zgrep.  (I'm sure given the right
  pipeline including using the find command it could be donebut
  seems like a hassle).

  So I figured I'd find a fancy next generation grep tool.  Thirty
  minutes of searching later I find a bunch in Perl, and even one in
  Ruby.  But I can't find anything that interesting or up to date for
  Python.  Does anyone know of something?

 I have a grep-like utility I call grin. I wrote it mostly to recursively 
 grep
 SVN source trees while ignoring the garbage under the .svn/ directories and 
 more
 or less do exactly what I need most frequently without configuration. It could
 easily be extended to open gzip files with GzipFile.

https://svn.enthought.com/svn/sandbox/grin/trunk/

 Let me know if you have any requests.

And don't forget: Colorized output! :)


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


Re: graphing/plotting with python and interface builder

2008-02-22 Thread Peter Wang
On Feb 22, 10:08 pm, Jacob Davis [EMAIL PROTECTED] wrote:
 Hi.

 I am developing for mac and using Xcode and Interface Builder 3.0.  I
 can make a simple application, but I am having a hard time trying to
 figure out a good way to create a graph orplotfor a class project.

 Does anybody have any tips on where to get started, or on how to do
 this?

 I have searched far for several days now, but I don't know if I am on
 the right track.  Any help is much appreciated.

 Thanks,
 Jake


Jake, are you using any python-specific GUI libraries like wxPython,
Qt, or Tk?  The Chaco plotting toolkit (http://code.enthought.com/
chaco)  supports several different mechanisms for rendering on OS X;
the default is to render via Quartz, but this requires wx or Qt.  I am
also currently working on a (somewhat experimental) pure OpenGL
backend, which doesn't require wxPython or Qt, just an active OpenGL
context.

Do you want to generate a fairly static plot, or do you want the user
to be able to interact with it in some way?


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


Re: jpype with JFreeChart, anyone interested to help?

2008-01-15 Thread Peter Wang
On Jan 14, 8:25 pm, oyster [EMAIL PROTECTED] wrote:
 Thanx
 However I knew Chaco and matplotlib, and I use matplotlib during my
 school days. And as I have pointed out, they are for plot, but not
 chart. If you don't know the difference between plot and chart, you
 can have a look at athttp://www.jfree.org/jfreechart,http://www.rmchart.com
 Yes, it is true we can use plot lib to draw chart, but that is tedious.

What are the chart types that are missing?  Or do you find that the
handling of categorical data is generally lacking?

Charting and plotting are quite related, and I think you might get
better traction trying to add the exact chart and axis types that you
need to an existing package rather than starting yet another plotting
package for Python. :)


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


Re: jpype with JFreeChart, anyone interested to help?

2008-01-14 Thread Peter Wang
On Jan 14, 6:51 am, oyster [EMAIL PROTECTED] wrote:
 As you may know, there is no beautiful and free chart(notplot, you
 can find the examples 
 athttp://www.jfree.org/jfreechart,http://www.rmchart.com) module for python 
 than runs on
 windows/linux/mac osx.

Actually, may I humbly suggest two:

Chaco: http://code.enthought.com/chaco/gallery/index.shtml

matplotlib: http://matplotlib.sourceforge.net/


-Peter

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


Re: 3D plotting with python 2.5 on win32

2007-12-20 Thread Peter Wang
On Dec 19, 8:15 am, anton [EMAIL PROTECTED] wrote:
 Hi,

 I would like to know if some of you knows a
  - working
  - actual
  - out of the box (for me: binaries available)
 Package/Lib to do 3D plotting out of the box.
 There is MayaVi from enthon but you need to use their python (2.4.3),
 all other stuff need picking sources etc.

Hi Anton,

You actually don't need to use the enthon installer (and definitely
not the 2.4.3-based one) in order to get MayaVi.  You will need to
have setuptools installed.  Then, you should run:

easy_install -f http://code.enthought.com/enstaller/eggs/windows/xp
VTK enthought.mayavi[nonets]

It's important to include [nonets] so that you will get scipy and
numpy as well.

Here are some links for getting started with MayaVI:
Mayavi Cookbook: http://scipy.org/Cookbook/MayaVi
MLab: http://www.scipy.org/Cookbook/MayaVi/mlab

From your posts it sounds like you really want to use something like
MLab.


On a side note, we are almost done putting together an updated one-
click installer of python + packages for scientific computing.  This
will be based on Python 2.5, will include most of what was included in
the 2.4.3-based installer, and will be available for multiple
platforms.


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


Re: Basic animation in Python - how to

2007-12-08 Thread Peter Wang
On Dec 8, 6:37 am, http://members.lycos.co.uk/dariusjack/;
[EMAIL PROTECTED] wrote:
 I need to draw a shaded rectangle and have flashing (gif animated)
 points on it
 so not to refresh all objects a rectangle, but points, changing their
 colors, attributes.
 Please refer me to some basic Python code for animation like that .

 Darius

What kind of graphical environment and operating system do you want to
do this on?  Is there a particular UI toolkit you have in mind?  Or do
you want to output an animated gif or small movie file?


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


Re: (Modular-)Application Framework / Rich-Client-Platform in Python

2007-05-18 Thread Peter Wang
On May 18, 10:15 am, Wildemar Wildenburger [EMAIL PROTECTED]
wrote:
 stefaan wrote:
  To make it short again:http://code.enthought.com/ets/

 Nice, seems very interesting. Bit of a bitch to set up, as it appears
 from scanning the site, but that might be it.

Actually, just this week, we completed a major SVN reorganization and
from this point forward, all of the libraries in ETS will be released
as eggs.  In fact, eggs have been available for a long time for python
2.4, and now we have them for python 2.5 as well.

The Eclipse in python you're looking for is actually called
Envisage, and it is part of ETS: 
https://svn.enthought.com/enthought/wiki/Envisage

The Dev Guide has some tutorials etc.: 
https://svn.enthought.com/enthought/wiki/EnvisageDevGuide

Note that Envisage != ETS.  ETS is the term for the whole bundle of
various Enthought libraries, including Traits, Chaco, Pyface, etc.
Envisage does require some of these others (notably Traits and
Pyface), but they are all available as eggs.

 Now for the everlasting circle of evaluating, feature-wanting,
 to-write-myself-deciding, failing, for-the-next-big-idea-waiting,
 asking, evaluationg, ...

Chime in on the mailing list if you have any questions.  It's pretty
active and many people on it have lots of experience with Envisage.


-Peter

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


Re: (Modular-)Application Framework / Rich-Client-Platform in Python

2007-05-18 Thread Peter Wang
On May 18, 1:10 pm, Wildemar Wildenburger [EMAIL PROTECTED]
wrote:
 I'm not sure, but you guys seem a bit Windows-centric. I have yet to
 find out if the egg-approach actually works for Linux (and Mac, though I
 don't use it) as well.

It does.  We have several linux and mac-based developers here.  (I'm
on a mac most of the time.)  I am currently running most of the ETS
libraries from eggs.  It's certainly true that the large, monolithic
Enthought Python Edition that was offered in the past was only
available for windows, but that's gone now and has been replaced with
the egg-based distribution.

 I've seen some mentioning of binary dependencies,
 which makes me frown a bit. We'll just see.

The Traits package has a small C extension that builds on all
platforms that I've seen.  Most of the other binary dependencies are
for graphical things like the plotting library.  If you just plan to
use Envisage, you won't need those.

 Yeah, I've been reading through that for the past couple of hours, seems
 pretty sweet and reasonably simple.
 I can see your reorg, by the way: The example .py files are not where
 they're advertised to be. Better be quick with that, even solid software
 with buggy documentation is buggy software ... ;)

I'll file a ticket for that. :)


-Peter

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


Re: Python crash after using weave inline

2007-04-18 Thread Peter Wang
Soren,

For future reference, you might want to direct weave-related questions
to the [EMAIL PROTECTED] mailing list.

 def cartPolFast(xlen, ylen, x_c, y_c):

 res = zeros((xlen,ylen))

 code = 
 {
 int xlen, ylen, x_c, y_c;

This line is unnecessary, because weave exposes those variables inside
the local scope of your code.  This also makes the braces at the top
and bottom of the code block unnecessary.

 for( x = 0; x == xlen; x++)
for( y = 0; y == ylen; y++)
 rel_x = x-x_c;
 rel_y = y_c-y;

 res(x,y) = rel_y*rel_y;
 }

Two things:
1. You need to put curly braces around the three lines of the inner
loop.
2. You need to change x == xlen and y == ylen to x  xlen and y
 ylen.

I made these modifications to your code and it runs fine on my machine
(macbook pro, OS 10.4, scipy 0.5.2.dev2314).


-peter

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


Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-06 Thread Peter Wang
On Mar 5, 12:31 am, Adam Atlas [EMAIL PROTECTED] wrote:
 Right now I'm just testing and polishing up the code... in the
 meantime, any comments?

How does this work with compiled extension modules?

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


Re: Compiling extension with Visual C++ Toolkit Compiler - MSVCR80.dll

2007-01-29 Thread Peter Wang
On Jan 29, 2:47 pm, [EMAIL PROTECTED] wrote:
 The library seems to build correctly (producing Polygon.py and
 cPolygon.pyd), but when I import it I get the following message from
 python.exe: This application has failed to start because MSVCR80.dll
 was not found. I thought that this might be due to Python trying to
 link against  the .dll from Microsoft Visual C++ Express 2005, also
 installed on my PC, instead of MSVCR71.dll. So I've removed MS Visual C
 ++ Express 2005, and any trace of it from my environment variables,
 but that doesn't seem to change anything.

Alex,  I'm not familiar with the particular problem you're seeing, but 
did you try building the polygon library using the gcc that's included 
with the Enthought distribution?

python setup.py build_clib build_ext --inplace --compiler=mingw32


-Peter

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


Re: How a script can know if it has been called with the -i command line option?

2006-12-22 Thread Peter Wang

Michele Simionato wrote:
 The subject says it all, I would like a script to act differently when
 called as
 $ python script.py and when called as $ python -i script.py. I looked
 at the sys module
 but I don't see a way to retrieve the command line flags, where should
 I look?

I realize this is quite a hack, but the entire command line is
preserved in the process's entry in the OS's  process table.  if you do
ps -ax you will see that the interpreter was invoked with -i.  I
didn't test this under windows, but it works on Mac and Linux.

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


Re: Decorator for Enforcing Argument Types

2006-12-22 Thread Peter Wang
Bruno Desthuilliers wrote:
 my humble opinion
 Python is dynamic, and fighting against the language is IMHO a really
 bad idea. The only places where theres a real need for this kind of
 stuff are when dealing with the outside world (IOW : inputs and
 outputs). And then packages like formencode can do much more than mere
 type-checking
 /my humble opinion

I don't think proper use of type checking is fighting against the
language.  The goal of any language is to enable programmers to
express their intent in a form that executes correctly.

Python is extremely expressive but there is a trade-off with
correctness - you can easily say something that you don't mean.  Unit
testing is sometimes sufficient, but it can never span the infinite
space of potential errors.  Type-checking method signatures guarantees
a certain amount of low-level correctness, and most type-checking
mechanisms also serve as documentation aids.

I think that with a sufficiently sophisticated type checking syntax,
one can get the best of both worlds.  If the type checker understood
interfaces (like PyProtocols) and its syntax had the flexibility to
indicate sets of allowed arguments and aggregates of allowed
types/interfaces, it would cover the majority of cases without limiting
expressive power.

I understand that we're all adults, but it's still nice to have the
computer tell us when we're being childish. :)


-peter

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


Re: Python component model

2006-10-17 Thread Peter Wang
Ilias Lazaridis wrote:
 Peter  Wang wrote:
  Ilias Lazaridis wrote:
   what about persistency?
 
  Um... what about it?

 
 As far as I can see, there's no persistency binding available.

 Is one planned?
 
 http://groups.google.com/group/comp.lang.python/msg/dbdaedc68eee653a

This thread was just some name-calling between you and Robert Kern, but
didn't really provide any details.

I guess I'm too dumb to understand the question... Does pickle not work
for you?  What is a persistency binding?

-peter

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


Re: Enthought python - Traits

2006-10-12 Thread Peter Wang
Ash wrote:
 Hello everyone !

 I am trying to find some sort of a cookbook or more examples for using
 Enthought Traits to build GUI's. I tried to follow the documentations
 present at the enthought site, but couldnt get too far - especially on
 how to handle a control event ?

The traits manual is in the lib/site-packages/enthought/traits/doc
directory, named Traits2_UM.doc/.pdf.  The traits UI manual/user guide
is also in there.  However, what is not so obvious is that there is
also an excellent, massive set of powerpoint slides (121 pages) that
Dave Morrill put together that talks about the architecture of Traits
UI, and how to build GUIs using it.  (Er, how to build them *well*,
i.e. adhering to the M-V-C pattern and maximizing code reuse.)  Those
slides are in traits_ui.ppt.

 say i have a list control that create using the following two lines:

 class Project(HasTraits):
   coordinate_system=Enum('Cartesian','Cylindrical')

 I added the following line to get the option selected by the user:

 def _coordinate_system_changed(self,old,new):
 print 'System changed from %s to %s ' %(old,new)

 but it does not return what the user select. It should return either 0
 or 1 based on the two choices, but i can't seem to find a way to trap
 that.

The way that this works is that _coordinate_system_changed() gets
called with the old value and the new value of self.coordinate_system.
Thus, it doesn't return anything; your method is a handler method
that gets called when the value of a particular trait gets changed.

Why do you say it should return 0 or 1?  Do you mean that you want to
get the index into the list of enumeration choices?  The Enum trait
type is not quite like C in this regard.  In C/C++, enums are really
ints; in traits, enums are lists of values of possibly mixed type.

 I am relatively new to this GUI programming in Python and really could
 use some tips/hints.

No problem, hope the above helped.  You might want to email your
questions to [EMAIL PROTECTED] (and subscribe to it!).  That
is the primary mailing list for several enthought libraries (including
traits) and you'll get very speedy, in-depth answers to your questions
there.


-Peter

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


Re: Python component model

2006-10-12 Thread Peter Wang
Edward Diener wrote:
 It looks as if traits is an attempt to create a property in the
 component terminology which I originally specified. I will take a look
 at it.

Traits is frighteningly similar to the requirements that you laid out
in your post (the example for Skip), including delegates!  I would like
to point out, however, that traits is a *general* component framework
for python that facilitates implementing the observer pattern and a
higher level of introspection.  It can be used to build applications
that have no visual interfaces at all, but wish to benefit from the
reactive programming style that componentized, event-based
programming encourages.  (induces?)

Traits UI, which Robert only alluded to, is actually very much the sort
of RAD environment you have described.  It builds upon the component
model, and uses introspection to automagically create nice widgets for
your model, but adds mechanisms for specifying controllers, customizing
behavior, and generically composing complicated forms from simpler
ones.  There is even a visual builder tool for it called VET that
closely resembles Delphi/C++ Builder.  (The VET itself is, of course,
written using Traits UI.)

Envisage, the plugin application framework, can use the traits
component models and the TraitsUI interfaces to roll out very dynamic
applications, whose underlying models are all live components that can
be scripted, twiddled with from an embedded Python shell, etc.

 Already subscribed. Thanks !

Please contribute ideas or ask conceptual questions!

Oh, and disclaimer: I also work at enthought. :)


-peter

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


Re: Python component model

2006-10-12 Thread Peter Wang
Edward,

This isn't in response to any specific one of the 100+ posts on this
thread, but I justed wanted to encourage you to continue your
investigation into Python component models and maybe looking for some
common ground between them.  Frequently the individual developers are
too heads-down on working on their own things to do a broad survey, so
I think this would be very useful indeed.

I wouldn't have felt it necessary to post this except for the large
number of posts along the lines of foo.dict is introspective enough
for me!.  I think you might have an easier time evangelizing the
principle of component-oriented programming (or event-based, or
reactive, or whatever) if you separated it from the notions of RAD UI
development.  There is a very large difference between writing
components and writing objects, and it seems that most people arguing
python doesn't need components don't see this distinction.

For me, it's the difference between writing live objects and dead
objects.  Live objects not only encapsulate implementations of an
interface with some state, but they also encapsulate handling of
events, i.e. responses to changes in their environment.  Dead objects
have methods but there has to be a function somewhere that knows which
dead object to call with what parameters at exactly the right time.
(The only mechanism for managing this complexity is to create ever more
functions at ever higher levels of abstraction, or to have a
proliferation of nebulously-defined manager objects.)  IMHO once you
cross this chasm and are able to model your problem domain with live
objects that go off and automatically respond to the runtime
environment and Do the Right Thing, it's very hard to go back to a dead
object mindset.  I can understand, however, that until one makes this
leap, it might seem like an academic and useless distinction.


-peter

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


Re: Python component model

2006-10-12 Thread Peter Wang
Ilias Lazaridis wrote:
 looks interesting.

Thanks!

 what about persistency?

Um... what about it?

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


Re: Python doc problems example: gzip module

2005-09-01 Thread Peter Wang
 Constructor for the GzipFile class, which simulates most of the methods
 of a file object, with the exception of the readinto() and truncate()

 yeah, blab blab blab. what the fuck are you talking about? So, how to
 use it?

um... presumably you type zippedfile = GzipFile(...) and depending on
whether you are creating a new file, or extracting an existing
GzipFile.  the documentation says:

 The new class instance is based on fileobj, which can be a regular file, a
 StringIO object, or any other object which simulates a file. It defaults to
 None, in which case filename is opened to provide a file object.

so i guess in your case you would want to do zippedfile =
GzipFile(myfile.gz).

 When fileobj is not None, the filename argument is only used to be
 included in the gzip file header, which may includes the original
 filename of the uncompressed file. It defaults to the filename of
 fileobj, if discernible; otherwise, it defaults to the empty string,
 and in this case the original filename is not included in the header.

 what the fuck??

when you gzip -d myfile.gz, the resultant output name might not be
myfile.  The uncompressed name can be stored in the gzip header, and
so if you provide both a fileobj argument and a filename argument to
the GzipFile constructor, it will use fileobj for the data stream and
just place filename into the header (as opposed to opening the file
filename).

 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb',
 depending on whether the file will be read or written. The default is
 the mode of fileobj if discernible; otherwise, the default is 'rb'. If
 not given, the 'b' flag will be added to the mode to ensure the file is
 opened in binary mode for cross-platform portability.

 discernible? so, what the fuck are exactly these modes? can't you
 describe them concretely?

these are the same modes that are used in just about every single
programming language when it comes to opening files.  these modes are
described in the Python tutorial and in the core Python documentation
about files and file I/O.  It should not be surprising, therefore, that
GzipFile, which simulates most of the methods of a file object,
should have the same semantics when it comes to file modes.

it is actually quite shocking to me that someone with 10 years of
computing experience would not know what rb and rb mean in the
context of opening files in a programming language.

 Calling a GzipFile object's close() method does not close fileobj,
 since you might wish to append more material after the compressed data.
 This also allows you to pass a StringIO object opened for writing as
 fileobj, and retrieve the resulting memory buffer using the StringIO
 object's getvalue() method.

 huh? append more material? pass a StringIO? and memory buffer?

you see, not everyone who uses GzipFile will be decompressing files.
sometimes they will be *compressing* file data.  in this case, it's
very possible that they want to compress data going over a network
stream, or embed some gzipped into the middle of their own file format.
 GzipFile doesn't make any assumptions about what the user is going to
do with the gzipped data or the file object that the Gzip module is
writing into/reading from.

 Motherfucking 90% of programers using this module really just want to
 compress or decompress a file.

I disagree.  I think a whopping (non-motherfucking) 100% of programmers
using this module want to compress or decompress file data.  If someone
just wants to decompress a file, wouldn't they just do:

import os
os.system(gzip -d filename.gz)

The GzipFile module is meant to be used by folks who want to gzip or
gunzip file data in a programmatic function.  It's not meant to be a
drop-in, shell-scripting replacement for the gzip command.

-peter

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