Re: Why custom objects take so much memory?

2007-12-19 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Tue, 18 Dec 2007 21:13:14 +0100, Hrvoje Niksic wrote:
>
>> Each object takes 36 bytes itself: 4 bytes refcount + 4 bytes type ptr +
>> 4 bytes dict ptr + 4 bytes weakptr + 12 bytes gc overhead.  That's not
>> counting malloc overhead, which should be low since objects aren't
>> malloced individually.  Each object requires a dict, which consumes
>> additional 52 bytes of memory (40 bytes for the dict struct plus 12 for
>> gc).  That's 88 bytes per object, not counting malloc overhead.
>
> And let's not forget that if you're running on a 64-bit system, you
> can double the size of every pointer.

And of Py_ssize_t's, longs, ints with padding (placed between two
pointers).  Also note the price of 8-byte struct alignment.

> Is there a canonical list of how much memory Python objects take up?
> Or a canonical algorithm?
>
> Or failing either of those, a good heuristic?

For built-in types, you need to look at the code of each individual
object.  For user types, you can approximate by calculations such as
the above.

>> Then there's string allocation: your average string is 6 chars
>> long; add to that one additional char for the terminating zero.
>
> Are you sure about that? If Python strings are zero terminated, how
> does Python deal with this?
>
 'a\0string'[1]
> '\x00'

Python strings are zero-terminated so the pointer to string's data can
be passed to the various C APIs (this is standard practice, C++
strings do it too.)  Python doesn't rely on zero termination to
calculate string length.  So len('a\0string') will do the right thing,
but the string will internally store 'a\0string\0'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why only an msi-installer for windows ?

2007-12-19 Thread Stef Mientki
Gabriel Genellina wrote:
> On 18 dic, 15:54, Stef Mientki <[EMAIL PROTECTED]> wrote:
> 
>> having a lot of trouble installing 2.5 (without affecting my stable 2.4),
>> I wonder why there's only a msi installer for windows users ?
> 
> What's your problem? I have five versions installed (2.1, 2.3, 2.4,
> 2.5 and svn) and they coexist peacefully. Just make sure when
> installing 2.5: a) use a different directory (obviously!) b) don't
> associate .py extension with this new version.

So how do you prevent that the windows registry is changed,
if you're using an msi installer ?
Or do you use another install technique ?.
Or do you don't mind that the registry is changed by an installation ?

> Regarding the standard library, Python tries to locate it based on
> where the executable (python.exe) resides, so this should not be a
> problem. Better if you don't set a PYTHONPATH environment variable
> (usually there is no need to do that; if required, you can extend the
> search path using .pth files instead)
Yes I've to study that once.
As a REAL windows user,
I know nothing about registry, environment variables, associating files etc,
Bill is always doing that for me !! ;-)

cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


How does setup.py work?

2007-12-19 Thread dxm
I am a new comer to python.
I am wondering how setup.py works.
For example, I have a directory like this:
/
   setup.py
   mymodule.c

where setup.py is:

from distutils.core import setup, Extension

mod = Extension('mymodule', sources = ['mymodule.c'])

setup (name = 'Package',
   version = '1.0',
   description = 'This is a demo package',
   ext_modules = [mod])

The correct way to install the newly created extension module is to
type
python setup.py install instead of executing those statements in
python shell, isn't it ?
My question is how additional arguments like 'build', 'install' are
passed into python and how
can I install it from interactively from python shell

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


Need help with "with-statement-compatible" object

2007-12-19 Thread Dmitry Teslenko
Hello!
I've made some class that can be used with "with statement". It looks this way:

class chdir_to_file( object ):
...
def __enter__(self):
...

def __exit__(self, type, val, tb):
...
def get_chdir_to_file(file_path):
return chdir_to_file(file_path)
...

Snippet with object instantiation looks like this:
for s in sys.argv[1:]:
c = chdir_to_file( s )
with c:
print 'Current directory is %s' % os.path.realpath( 
os.curdir )

That works fine. I want to enable it to be used in more elegant way:
for s in ... :
with get_chdir_to_file( s ) as c:
   c.do_something()

But python complains c is of NoneType and has no "do_something()". Am
I missing something?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to generate pdf file from an html page??

2007-12-19 Thread Stefan Behnel

abhishek wrote:
> sh: a2ps: not found

This should make you think. Sounds like a good reason to install a2ps...

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


Re: Changing intobject to use int rather than long

2007-12-19 Thread Christian Heimes
Terry Reedy wrote:
> Good idea.  I think people who moved to 64 bits to get 64 bits would be 
> upset if they did not ;-).

Windows X64 users still get 32bit ints. The long datatype is 32bit even
on the 64bit version of Windows.

Christian

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


Re: import X between submodules in a package

2007-12-19 Thread Bruno Desthuilliers
Donn Ingle a écrit :
> Hi, I'm sure this is a FAQ, but I have just not found clarity on the
> web/docs.
> 
> (using monospaced type to show the tree)
> trunk:$ tree
> .
> fp
> |-- fontypython
> |   |-- __init__.py
> |   |-- cli.py
> |   |-- config.py
> 
> (I start it all with ./fp)
> 
> fp says:
> import cli
> 
> cli.py says:
> import os
> import config
> 
> config.py says:
> print os.environ['HOME']
> 
> I get a NameError in config.py
> 
> If I add 'import os' to config.py all is well.
> 
> So, I guess I am confused about the 'scope' of what gets imported where. I
> am thinking that if one module (py file) does *import os* something and
> *then* imports another module - the second module should have access to os
> too?

Definitively no. This would make the second module dependent on the 
context in which it is used, which would be a VeryBadThing(tm). Each 
Python module is it's own _distinct_ namespace, and only depend on the 
name  it explicitely imports or defines. FWIW, it's the whole point of 
*modules* (by opposition to 'includes' à la PHP).

>  I imagine myself "standing" inside cli.py at this point and saying "well I
> can see os, and I'm bringing config *into* this space, so they should be
> able to see os too."

I can tell you from experience (with languages that work that way, cf 
above) that this usually leads to the worst possible mess, even if 
you're being careful.

> How do I structure things so that I don't have endless repetitions of import
> in every py file within my package directory?

Having explicits imports in each module is good wrt/ readability. Now if 
you have a huge common set of imports in each and every submodule of a 
package, you can of course factor them out in a distinct submodule and 
just do a 'from myimports import *' at the top of the others submodules...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clearing text on canvas

2007-12-19 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> i am doing  validation of contents of a folder  and need to show the
> ok/error messages on a canvas
> 
> resultdisplay =Canvas(...)
> errmessage="error!"
> okmessage="dir validation ok!"
> 
> if dirvalidate is False:

if ... is False: ...

is bad style. Just

if dirvalidate: ...

reads better and is less likely to cause subtle errors.

> resultdisplay.create_text(1,50,anchor=W,text=errmessage,width=175)
> 
> else:
> self.resultdisplay.create_text(1,50,anchor=W,text=okmessage,width=175)
> 
> 
> my problem is that if validation succeeds or fails the text created on
> canvas is displayed over the previous created text
> I need to clear the previous text from the canvas before creating new
> text
> can someone help?

You create the text once but keep its handle for further changes.

handle = canvas.create_text(...)

You can change it later with

canvas.itemconfigure(handle, ...)

Here's a short self-contained example:

import Tkinter as tk

root = tk.Tk()
canvas = tk.Canvas(root, width=100, height=100)
canvas.pack()

text_id = canvas.create_text(50, 50, width=100)

ok = False
def change_text():
global ok
ok = not ok
if ok:
text = "ok"
else:
text = "error"

canvas.itemconfigure(text_id, text=text)

button = tk.Button(root, text="change text", command=change_text)
button.pack()

root.mainloop()

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


Re: operator module isSequenceType with builtin set produces False

2007-12-19 Thread MarkE
On 19 Dec, 05:24, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Tue, 18 Dec 2007 09:15:12 -0300, English, Mark <[EMAIL PROTECTED]>
> escribió:
>
>
>
>  try: set
>  except NameError: from sets import Set as set
>  class myset_fails(set): pass
>  class myset_works(set):
>  def __getitem__(self): pass
>  s = set()
>  fails = myset_fails()
>  works = myset_works()
>  import operator
>  operator.isSequenceType(s) #Not what I expected
> > False
>  operator.isSequenceType(fails) #Not what I expected either
> > False
>  operator.isSequenceType(works) #A hint at what isSequenceType does ?
> > True
>
> > Are sets not sequences ? I didn't think the isSequenceDisclaimer gave
> > false negatives.
>
> No, sets aren't sequences, as they have no order. Same as dicts, which
> aren't sequences either.


Oops. I was under the misapprehension that they were sequences in that
they were sequential but of unknown ordering
 e.g. for x in set([someobject, someotherobject, ...]) always iterates
in the same order

Anywho, now I know. Thanks.

Is there a short Pythonic way to determine whether an object is
iterable (iteratable ??) that I haven't thought of (getattr(obj,
'__iter__') ?). Would operator.isIterable() be at all a useful
addition ?

(And what did I do wrong when I posted my original post that I can't
see it in groups.google)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How does setup.py work?

2007-12-19 Thread Matias Surdi
dxm escribió:
> I am a new comer to python.
> I am wondering how setup.py works.
> For example, I have a directory like this:
> /
>setup.py
>mymodule.c
> 
> where setup.py is:
> 
> from distutils.core import setup, Extension
> 
> mod = Extension('mymodule', sources = ['mymodule.c'])
> 
> setup (name = 'Package',
>version = '1.0',
>description = 'This is a demo package',
>ext_modules = [mod])
> 
> The correct way to install the newly created extension module is to
> type
> python setup.py install instead of executing those statements in
> python shell, isn't it ?
> My question is how additional arguments like 'build', 'install' are
> passed into python and how
> can I install it from interactively from python shell
> 


Here you can read the documentation of "setuptools" , the package from 
where setup.py comes.

http://peak.telecommunity.com/DevCenter/setuptools

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


Re: How does setup.py work?

2007-12-19 Thread Robert Kern
dxm wrote:
> I am a new comer to python.
> I am wondering how setup.py works.
> For example, I have a directory like this:
> /
>setup.py
>mymodule.c
> 
> where setup.py is:
> 
> from distutils.core import setup, Extension
> 
> mod = Extension('mymodule', sources = ['mymodule.c'])
> 
> setup (name = 'Package',
>version = '1.0',
>description = 'This is a demo package',
>ext_modules = [mod])
> 
> The correct way to install the newly created extension module is to
> type
> python setup.py install instead of executing those statements in
> python shell, isn't it ?

Yes.

> My question is how additional arguments like 'build', 'install' are
> passed into python

Command-line arguments are passed into Python as the list sys.argv. Try running
the following script to explore this:

 sys_argv.py 
#!/usr/bin/env python
import sys
print sys.argv
#

[~]$ python sys_argv.py
['sys_argv.py']
[~]$ python sys_argv.py build
['sys_argv.py', 'build']
[~]$ python sys_argv.py build_ext --inplace install
['sys_argv.py', 'build_ext', '--inplace', 'install']

http://docs.python.org/lib/module-sys.html

Code inside setup() parses this list to determine what actions the user wants it
to take.

> and how
> can I install it from interactively from python shell

Generally speaking, you don't. distutils was not really designed for this use
case. There is no easy way to do this.

-- 
Robert Kern

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

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


Re: Need help with "with-statement-compatible" object

2007-12-19 Thread Peter Otten
Dmitry Teslenko wrote:

> Hello!
> I've made some class that can be used with "with statement". It looks this 
> way:
> 
> class chdir_to_file( object ):
> ...
>   def __enter__(self):
> ...
> 
>   def __exit__(self, type, val, tb):
> ...
> def get_chdir_to_file(file_path):
>   return chdir_to_file(file_path)
> ...
> 
> Snippet with object instantiation looks like this:
>   for s in sys.argv[1:]:
>   c = chdir_to_file( s )
>   with c:
>   print 'Current directory is %s' % os.path.realpath( 
> os.curdir )
> 
> That works fine. I want to enable it to be used in more elegant way:
> for s in ... :
> with get_chdir_to_file( s ) as c:
>c.do_something()
> 
> But python complains c is of NoneType and has no "do_something()". Am
> I missing something?

Does the chdir_to_file class have a do_something() method? If so,
changing chdir_to_file.__enter__() to 

def __enter__(self):
# ...
return self

should help.

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


Re: How does setup.py work?

2007-12-19 Thread Robert Kern
Matias Surdi wrote:

> Here you can read the documentation of "setuptools" , the package from 
> where setup.py comes.
> 
> http://peak.telecommunity.com/DevCenter/setuptools

No, setup.py files are standard distutils. setuptools is a 3rd-party package
that extends distutils.

  http://docs.python.org/dist/dist.html

-- 
Robert Kern

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

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


how to get string printed by PyErr_Print( )?

2007-12-19 Thread grbgooglefan
PythonC API function PyErr_Print( ) prints an error string onto stderr
if PyErr_Occurred() is true.
I don't want to print this to stderr because my Python+C code is
running daemon mode & won't have terminal / stderr.
So, I want to retrieve the string which PyErr_Print( ) will print.
E.g., PyErr_Print() printed following string when I tried to call
setTuple with one extra argument
Traceback (most recent call last):
  File "", line 2, in isTacticSafe
IndexError: tuple assignment index out of range

How do I get this error message in a local char* & use it for further
error handling?

Also, is there any way to get an error number associated for these
error conditions using some getError function on the object returned
by PyErr_Occurred()?

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


Re: how to get string printed by PyErr_Print( )?

2007-12-19 Thread Robert Kern
grbgooglefan wrote:
> PythonC API function PyErr_Print( ) prints an error string onto stderr
> if PyErr_Occurred() is true.
> I don't want to print this to stderr because my Python+C code is
> running daemon mode & won't have terminal / stderr.
> So, I want to retrieve the string which PyErr_Print( ) will print.
> E.g., PyErr_Print() printed following string when I tried to call
> setTuple with one extra argument
> Traceback (most recent call last):
>   File "", line 2, in isTacticSafe
> IndexError: tuple assignment index out of range
> 
> How do I get this error message in a local char* & use it for further
> error handling?
> 
> Also, is there any way to get an error number associated for these
> error conditions using some getError function on the object returned
> by PyErr_Occurred()?

PyErr_Print() will import the sys module and try to use whatever file-like
object is sys.stderr. Replace this with a StringIO or an open file object just
like you would for output from the Python level.

-- 
Robert Kern

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

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


Re: Windows XP unicode and escape sequences

2007-12-19 Thread Martin v. Löwis
> This brings up another question.  If I run some Python code that
> starts off with 'os.system('cp869')' so it will change to the correct
> code page, then when it starts printing the Greek characters it
> breaks.  But run the same Python code again and it works fine.  Is
> there another way to do this so I can change over to the 869 code
> page and continue on with the Greek letters printing correctly?

You'll have to call SetConsoleOutputCP (see MSDN). Python does not
directly expose that, so you'll have to use ctypes or PythonWin to
call it.

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


Re: operator module isSequenceType with builtin set produces False

2007-12-19 Thread MarkE
On 19 Dec, 10:03, MarkE <[EMAIL PROTECTED]> wrote:
> > No, sets aren't sequences, as they have no order. Same as dicts, which
> > aren't sequences either.
>
> Oops. I was under the misapprehension that they were sequences
I realise now that this is even explicitly documented:
http://docs.python.org/lib/typesseq.html
"There are six sequence types: strings, Unicode strings, lists,
tuples, buffers, and xrange objects."

> Is there a short Pythonic way to determine whether an object is
> iterable (iteratable ??) that I haven't thought of (getattr(obj,
> '__iter__') ?). Would operator.isIterable() be at all a useful
> addition ?
And here I probably meant container (although the url says sequence
when the article meant container, bit like me):
http://docs.python.org/ref/sequence-types.html
"Containers usually are sequences (such as lists or tuples) or
mappings (like dictionaries), but can represent other containers as
well"

So same question, but perhaps "isContainer()" rather than
"isIterable()"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static linking of python and pyqt

2007-12-19 Thread Martin v. Löwis
> I'm trying to link python statically with qt and pyqt. I've tried this in 
> several ways but never succeeded. At the moment the final make runs without 
> errors but I get import errors when accessing pyqt.
> How can I solve this problem?

You'll need to include QtCore into Modules/config.c, preferably by
adding it to Modules/Setup.local.

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


Re: how to get string printed by PyErr_Print( )?

2007-12-19 Thread Christian Heimes
grbgooglefan wrote:
> PythonC API function PyErr_Print( ) prints an error string onto stderr
> if PyErr_Occurred() is true.
> I don't want to print this to stderr because my Python+C code is
> running daemon mode & won't have terminal / stderr.
> So, I want to retrieve the string which PyErr_Print( ) will print.
> E.g., PyErr_Print() printed following string when I tried to call
> setTuple with one extra argument
> Traceback (most recent call last):
>   File "", line 2, in isTacticSafe
> IndexError: tuple assignment index out of range

I suggest a different approach. A daemon must have a stdin, stdout and
stderr connected to a terminal. You can use freopen() to redirect stderr
and stdout to a log file and fclose() to close stdin.

http://www.gnu.org/software/libc/manual/html_mono/libc.html#Opening-Streams

Christian

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


Re: Python decompiler

2007-12-19 Thread Martin v. Löwis
> I'm searching a maneuverable python bytecode decompiler. There is one
> named 'decompyle', but it doesn't support Python2.5 and too hard to
> use. And the 'depython'(http://www.depython.net/) is good enough
> except it cannot process file more than 5kb.
> 
> Is there some else available?

I don't think so. For a Python novice, I'd firmly advise against trying
to decompile Python byte code.

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


Re: import X between submodules in a package

2007-12-19 Thread Chris
On Dec 19, 9:24 am, Donn Ingle <[EMAIL PROTECTED]> wrote:
> So, I guess I am confused about the 'scope' of what gets imported where. I
> am thinking that if one module (py file) does *import os* something and
> *then* imports another module - the second module should have access to os
> too?
>  I imagine myself "standing" inside cli.py at this point and saying "well I
> can see os, and I'm bringing config *into* this space, so they should be
> able to see os too."

Each module has its own namespace.  Why config throws an error is
because even though you imported 'os' in the cli module you are
calling an os function from a different module.  You can however put
them all together in a different manner if this helps:

#fp.py
import cli

#cli.py
import os

#config.py
import cli
print cli.os.environ['HOME']

if you wish to use the os module loaded by the cli module
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why only an msi-installer for windows ?

2007-12-19 Thread Martin v. Löwis
>>> having a lot of trouble installing 2.5 (without affecting my stable
>>> 2.4),
>>> I wonder why there's only a msi installer for windows users ?
>>
>> What's your problem? I have five versions installed (2.1, 2.3, 2.4,
>> 2.5 and svn) and they coexist peacefully. Just make sure when
>> installing 2.5: a) use a different directory (obviously!) b) don't
>> associate .py extension with this new version.
> 
> So how do you prevent that the windows registry is changed,
> if you're using an msi installer ?

Just unselect "Register Extensions" ("Make this Python installation
the default Python installation") when installing the MSI file, if
you don't want .py be associated with this installation.

> Or do you use another install technique ?.
> Or do you don't mind that the registry is changed by an installation ?

It's indeed no problem whatsoever to modify the registry. Different
Python versions use different registry keys, so they don't conflict.

> Yes I've to study that once.
> As a REAL windows user,
> I know nothing about registry, environment variables, associating files
> etc,
> Bill is always doing that for me !! ;-)

And so is Python. Just install the MSI file, and don't worry.

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


Re: Best way to protect my new commercial software.

2007-12-19 Thread Piet van Oostrum
> Steven D'Aprano <[EMAIL PROTECTED]> (SD) wrote:

>SD> It means that there is a serious problem of "orphan works", where rare
>SD> and valuable films from the 1920s and earlier are rapidly decaying
>SD> into an unusable powder because nobody dares copy them lest the
>SD> unknown copyright owners descend like vultures and sue you for
>SD> copyright infringement *after* you've done the hard work of restoring
>SD> our cultural heritage.

Our (Dutch) copyright law has a specific exemption for this particular
case for libraries, museums and archives.
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


pass 3D Matrix from matlab to C mex- file

2007-12-19 Thread baavour
help please

how can i pass 3d matrix from matlab to c

using mex file

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


Re: pydoc - how to generate documentation for an entire package?

2007-12-19 Thread kirillrd
On Nov 20, 4:28 pm, Jens <[EMAIL PROTECTED]> wrote:
> On 20 Nov., 08:19, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> > On Mon, 19 Nov 2007 10:50:28 -0800, Jens wrote:
> > > Generating documentation form code is a nice thing, but this pydoc.py
> > > is driving me insane - isn't there are better way?
>
> > Epydoc!?
>
> > Ciao,
> > Marc 'BlackJack' Rintsch
>
> Thanks! Epydoc looks promising - shame about the user interface
> though :-(

There is also happydoc , much less features , but still nice :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static linking of python and pyqt

2007-12-19 Thread Markus Dahlbokum
> > I'm trying to link python statically with qt and pyqt. I've tried this in
> > several ways but never succeeded. At the moment the final make runs
> > without errors but I get import errors when accessing pyqt.
> > How can I solve this problem?
>
> You'll need to include QtCore into Modules/config.c, preferably by
> adding it to Modules/Setup.local.
>
> HTH,
> Martin

I tried this in combination with the QtCore libs from pyqt. But there seems to 
be a conflict between the pyqt package and the linked libs. Therefore I tried 
to link only qt statically and import pyqt dynamically. But in the 
Setup.local you need to specify a module:

 

I just want the qt libs linked to the interpreter without accessing them by a 
module. I tried the configure option '--with-libs='lib ...''. The make did 
fine but the executable is too small and the qt symbols are not known by it.
How can I just link qt statically?

Thank you.

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


Re: pass 3D Matrix from matlab to C mex- file

2007-12-19 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> help please
> 
> how can i pass 3d matrix from matlab to c
> 
> using mex file

This is a mailing list for the Python programming language. Please ask your
question on the appropriate Matlab mailing list.

-- 
Robert Kern

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

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


Re: Newbie observations

2007-12-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> Warning! Complaints coming.
> 
> The good news is that 10-days of part-time Python coding has convinced
> me that I picked the right language. Now, observations.
> 
> First, it is absolutely horrible being a newbie. I'd forgot how bad it
> was. In addition to making a fool of yourself in public,

As my grand-dad used to say, better to make a fool of yourself once by 
asking a possibly dumb question than to remain one by not asking it !-)

> you have to
> look up everything. I wanted to find a substring in a string. OK,
> Python's a serious computer language, so you know it's got a function
> to do this. But where? 

Could it be in the string object itself ?-) Remember that Python is 
mostly an OO language, so the first thing to do is usually to inspect 
the type or read it's help in the Python shell.


> Look it up in the function reference. OK,
> where's the function reference? A line of code that you'd type in a
> second is a ten-minute search. Thank God for google.

FWIW, I'm certainly not a PHP newbie (wrote tens of thousands of PHP 
code those last years) and I *still* have to lookup the doc for most 
functions exact spelling and signature. This is a problem I usually 
don't have with Python, thanks to it's mostly consistent API and the 
Python shell.

> Second, would anyone mind if we tossed the semi-colon (which this
> newbie is forever forgetting)? I think the language is parsable
> without it.

It is, indeed. But keeping the semi-colon is a design decision, and a 
good one IMHO.

Given your argument, we should remove the instruction terminator (';') 
from C/C++/Java etc, because that's what newbies are forever forgetting 
- at least that's what I've been forgetting for a couple monthes when 
starting with C and Java !-)

More seriously, that's something you should get used too quite quickly, 
specially if your code editor does a good job at indenting Python code 
(because then it should not indent if you forget this semi-colon).

> Third, could our classes be a little more selfless? Or a lot more
> selfless? 



> The Stroustrup's idea of having the compiler, not the
> programmer, worry about the self pointer was an excellent decision.

It's IMVHO one of the worst design flaws of C++. FWIW, in languages that 
  support implicit self (or this or whatever it's named), I always use 
the explicit one - which I find way better than prefixing member 
variables with "m_".

But anyway, what you suggest is obviously something that'll never happen 
in Python. I won't explain *once again* why the explicit self in both 
the signature and the function's body is a GoodThing(tm), but you can 
google this ng for a couple previous explanations on that topic. Anyway, 
once you'll have a good enough knowledge of Python's object model, 
you'll understand by yourself - you may want to lookup the doc for what 
Python 'methods' really are and how the whole thing works.

> What was van Rossum thinking?

That readability counts, and that uniformity is a good thing.

Not to be harsh, but don't you think that 10-days experience is a bit 
short to discuss a language design ? There are lot of things in Python 
that newcomers usually dislike or find weird at first. Most of these 
points make sens when you finally gain enough experience with and 
knowledge of the language and suddenly all things fall in places, you 
see the big picture and these "weird things" make sens.

Not to say that Python is wart-free of course, but MVHO is that you need 
much more than ten days experience with a language to be able to make 
the difference between effective warts and sound -even if unusual- 
design decisions. Now of course, once you fully understand them, you're 
totally free to still dislike these design choices !-)

My 2 cents.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with "with-statement-compatible" object

2007-12-19 Thread Dmitry Teslenko
On Dec 19, 2007 12:14 PM, Peter Otten <[EMAIL PROTECTED]> wrote:
> def __enter__(self):
> # ...
> return self
>
> should help.

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


Re: why only an msi-installer for windows ?

2007-12-19 Thread Stef Mientki
Martin v. Löwis wrote:
 having a lot of trouble installing 2.5 (without affecting my stable
 2.4),
 I wonder why there's only a msi installer for windows users ?
>>> What's your problem? I have five versions installed (2.1, 2.3, 2.4,
>>> 2.5 and svn) and they coexist peacefully. Just make sure when
>>> installing 2.5: a) use a different directory (obviously!) b) don't
>>> associate .py extension with this new version.
>> So how do you prevent that the windows registry is changed,
>> if you're using an msi installer ?
> 
> Just unselect "Register Extensions" ("Make this Python installation
> the default Python installation") when installing the MSI file, if
> you don't want .py be associated with this installation.
Thanks I missed that setting.
Never seen before that this tree was used to prevent register changes.
A beautiful example of bad GUI ;-)

cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static linking of python and pyqt

2007-12-19 Thread Martin v. Löwis
> I just want the qt libs linked to the interpreter without accessing them by a 
> module. I tried the configure option '--with-libs='lib ...''. The make did 
> fine but the executable is too small and the qt symbols are not known by it.
> How can I just link qt statically?

Why do you want to do this? If qt isn't actually *used* in Python (as
you don't include the pyqt modules), what effect do you expect from
such linking?

I think it linked just fine - it just didn't include any symbols,
because none were needed. That is the correct, expected behavior.
It all worked fine.

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


Re: Newbie observations

2007-12-19 Thread MartinRinehart
> My 2 cents.

Eurozone? That would be 3 cents US.

I meant colon, not semi-colon. I did the tutorial. I did objects 3
times.

In Java, the agreed convention is to use lowerAndUpper naming for
member variables.  (See 
http://www.MartinRinehart.com/articles/code-conventions.html#5_1
.)

10 days is not enough. But I don't have any more clarity in my Python
classes than I did in Java. Just more "self"s.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why custom objects take so much memory?

2007-12-19 Thread jsanshef
Thank you all for your useful comments and suggestions!! They're a
great starting point to redesign my script completely ;)


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


Re: Newbie observations

2007-12-19 Thread Marco Mariani
[EMAIL PROTECTED] wrote:

> 10 days is not enough. But I don't have any more clarity in my Python
> classes than I did in Java.

You do when you start using classes the python way, and do things that 
are not even thinkable in java or any static language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie observations

2007-12-19 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

>> My 2 cents.
> 
> Eurozone? That would be 3 cents US.
> 
> I meant colon, not semi-colon. I did the tutorial. I did objects 3
> times.
> 
> In Java, the agreed convention is to use lowerAndUpper naming for
> member variables.  (See
> http://www.MartinRinehart.com/articles/code-conventions.html#5_1 .)
> 
> 10 days is not enough. But I don't have any more clarity in my Python
> classes than I did in Java. Just more "self"s.

Believe me: I do java for a living, but I'm hoping to change that ASAP to go
with python (and the occasional C) - because my expressiveness in Python is
so much larger than with Java. Mixins, higher-order functions, Metaclasses,
decorators, properties, multiline strings, local functions in Java? No,
sir!

The thing is: self won't go away. Others have tried it - and didn't succeed.
Try and adapt. If you can't, you won't get happy with python - because its
not going to change.

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


Re: Newbie observations

2007-12-19 Thread Peter Otten
MartinRinehart wrote:

> 10 days is not enough. But I don't have any more clarity in my Python
> classes than I did in Java. Just more "self"s.

Watch your classes evolve over the next weeks. They will get smaller,
with less state and fewer methods with less code. Occasionally you will use
a function or generator instead of a class, an inlined expression where
you used to write a custom function. You'll ditch code as you
discover that the standard library already provides a more general
way to achieve what you wanted.

If you don't share the experience sketched above you are likely moving in
the wrong direction.

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


Need help with a regular expression

2007-12-19 Thread Sharun
Python newbie here. I am not clear about how the matching is taking
place when I do the following

>str5 = 'aaa bbb\r\n ccc ddd\r\n eee fff'
>re5=re.compile('aaa.*(ddd|fff)',re.S);
>re5.search(str5).group(0)
'aaa bbb\r\n ccc ddd\r\n eee fff'

>re5.search(str5).group(1)
'fff'

I am trying to find the substring starting with 'aaa', and ending with
ddd OR fff. If ddd is found shouldnt the search stop? Shouldn't
re5.search(str5).group(0) return 'aaa bbb\r\n ccc ddd' ?

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


Re: Need help with a regular expression

2007-12-19 Thread marek . rocki
On 19 Gru, 13:08, Sharun <[EMAIL PROTECTED]> wrote:
> I am trying to find the substring starting with 'aaa', and ending with
> ddd OR fff. If ddd is found shouldnt the search stop? Shouldn't
> re5.search(str5).group(0) return 'aaa bbb\r\n ccc ddd' ?

The documentation for the re module (http://docs.python.org/lib/re-
syntax.html), tells you that the "*", "+", and "?" qualifiers are all
greedy; they match as much text as possible. What you are looking for
are the qualifiers "*?", "+?", "??". Your regex pattern might look
like this: "aaa.*?(ddd|fff)".

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


error with wxPython2.8-win32-unicode-2.8.7.1-py25.exe

2007-12-19 Thread Emmanuel
I recently upgraded wxpython (and python) on XP using wxPython2.8-
win32-unicode-2.8.7.1-py25.exe

Now when I run

from wxPython.wx import *

It crashes :

-> import _wx
 ...

from _misc import *

...

--> 456 wxDateTime_GetNumberOfDaysinYear =
wx._misc.DateTime_GetNumberOfDaysinYear

...

AtributeError: 'module' object has no atribute
'DateTime_GetNumberOfDaysinYear'

Is it a known problem or is there something wrong only on my side?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static linking of python and pyqt

2007-12-19 Thread Markus Dahlbokum
> > I just want the qt libs linked to the interpreter without accessing them
> > by a module. I tried the configure option '--with-libs='lib ...''. The
> > make did fine but the executable is too small and the qt symbols are not
> > known by it. How can I just link qt statically?
>
> Why do you want to do this? If qt isn't actually *used* in Python (as
> you don't include the pyqt modules), what effect do you expect from
> such linking?
>
> I think it linked just fine - it just didn't include any symbols,
> because none were needed. That is the correct, expected behavior.
> It all worked fine.
>
> Regards,
> Martin

I need an environment that can be delivered to our customers without 
installing python, qt and pyqt. We want to provide the complete package.
In order to do so I need to link at least python and qt. How can this be done?

Of course a complete package with python, qt and pyqt would be the best 
solution but there seem to be even more complications that way. If you can 
help me with this I would be very grateful.

Thank you in advance.
Markus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lotus nsf to mbox

2007-12-19 Thread Michael Ströder
Adam Lanier wrote:
>> Brian Munroe schrieb am 12/15/2007 07:10 PM:
>>>
>>> If you really need to do it from Linux and are lucky enough to be
>>> running the IIOP task on your Domino server, then you could possibly
>>> use CORBA.
> 
> You could always enable the IMAP interface on the Domino machine and use
> imaplib to retrieve the mail via IMAP.

Be prepared to hit a lot of bugs in Domino implementations of IIOP and 
IMAP depending on the Domino version deployed...

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import X between submodules in a package

2007-12-19 Thread Donn Ingle
Chris wrote:
> print cli.os.environ['HOME']
I was really confused by your reply until I saw the cli.os part. Okay, I see
what you mean.

\d

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


Re: import X between submodules in a package

2007-12-19 Thread Donn Ingle
> would be a VeryBadThing(tm). 
:)

> Having explicits imports in each module is good wrt/ readability. 
Okay, I can accept that. I worry that it's opening the module file over and
over again - or does it open it once and kind of re-point to it when it
hits a second import of the same thing?

> package, you can of course factor them out in a distinct submodule and
> just do a 'from myimports import *' at the top of the others submodules...
Good point.

\d

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


Re: Need help with a regular expression

2007-12-19 Thread Paddy
On Dec 19, 12:08 pm, Sharun <[EMAIL PROTECTED]> wrote:
> Python newbie here. I am not clear about how the matching is taking
> place when I do the following
>
> >str5 = 'aaa bbb\r\n ccc ddd\r\n eee fff'
> >re5=re.compile('aaa.*(ddd|fff)',re.S);
> >re5.search(str5).group(0)
>
> 'aaa bbb\r\n ccc ddd\r\n eee fff'
>
> >re5.search(str5).group(1)
>
> 'fff'
>
> I am trying to find the substring starting with 'aaa', and ending with
> ddd OR fff. If ddd is found shouldnt the search stop? Shouldn't
> re5.search(str5).group(0) return 'aaa bbb\r\n ccc ddd' ?
>
> Thanks

Have an RE problem in Python?

Get Kodos! (http://kodos.sourceforge.net/)

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


Re: Newbie observations

2007-12-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
>> My 2 cents.
> 
> Eurozone? That would be 3 cents US.
> 
> I meant colon, not semi-colon. I did the tutorial. I did objects 3
> times.

That's not where you'll learn the inners of Python's object model. You 
may want to browse this thread for some hints:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/7943ab9f93854eb6

> In Java, the agreed convention is to use lowerAndUpper naming for
> member variables.  (See 
> http://www.MartinRinehart.com/articles/code-conventions.html#5_1
> .)

It's also the convention used for local variables, so unless you do 
explicitely use the 'this' reference, it's not clear whether a name is a 
local variable or a member variable - you have to check the function's 
code for local variables declarations, then eventually the class 
definition, then the parent's class etc.

> 
> 10 days is not enough. But I don't have any more clarity in my Python
> classes than I did in Java.   Just more "self"s.

The "more self's" already gives you more clarity, even if you don't 
realize it yet. Now 10 days is not also not enough to switch from Java 
thinking to idiomatic Python. C/C++/Java programmer discovering Python 
is a well-known pattern here - I even suspect it to be the most common 
case !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with a regular expression

2007-12-19 Thread Sharun
Thanks Marek!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import X between submodules in a package

2007-12-19 Thread Bruno Desthuilliers
Donn Ingle a écrit :
>> would be a VeryBadThing(tm). 
> :)
> 
>> Having explicits imports in each module is good wrt/ readability. 
> Okay, I can accept that. I worry that it's opening the module file over and
> over again 

Hopefully not ! "import" is not "include".

> - or does it open it once and kind of re-point to it when it
> hits a second import of the same thing?

You guess. When fisrt imported, the module's source is executed, a 
module object is created and stored in sys.modules, and the needed names 
are inserted into the importing module's namespace. Next times the 
module is "served" directly from sys.modules.

> 
>> package, you can of course factor them out in a distinct submodule and
>> just do a 'from myimports import *' at the top of the others submodules...
> Good point.

Note that while it's perfectly legal, that's a pattern I'd try to avoid 
unless I have a very good reason to use it.


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


Re: Distinguishing attributes and methods

2007-12-19 Thread Boris Borcic
MonkeeSage wrote:
> what am I missing?

To my eyes, when you write:

 >I think it muddies the water to say that a.a() and a.a are the same
 >thing--obviously they are not. In the common case, the first is a
 >method, and the second is a variable.

What you are most obviously missing is what's shown by

b=a.a
b()

IOW I am tempted to make the prediction that you never use bound methods as 
values :)

Cheers, BB

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


Re: pass 3D Matrix from matlab to C mex- file

2007-12-19 Thread Brian Blais


On Dec 19, 2007, at Dec 19:5:07 AM, [EMAIL PROTECTED] wrote:


help please

how can i pass 3d matrix from matlab to c

using mex file

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



wrong mailing list, you might want to try the matlab news group. but,  
to answer your question, mex files all have the same syntax:


void mexFunction(
 int nlhs,/* number of expected outputs */
 mxArray *plhs[], /* mxArray pointer array returning  
outputs */

 int nrhs,/* number of inputs */
 const mxArray *prhs[]  /* mxArray pointer array for  
inputs */

 )


no matter what type of array you pass.  you then need to get the data  
pointer, the sizes for the arrays, etc... like:



mydata  = mxGetPr(prhs[0]);
dims=mxGetDimensions(prhs[0]);
ndims=mxGetNumberOfDimensions(prhs[0]);


check out the mex documentation.

Or, you can use Python with numpy for matrices, and use Pyrex for the  
c-extensions and make your life a *lot* easier.




bb




--
Brian Blais
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais


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

HTML unit .

2007-12-19 Thread Amal
Is there something like HTML unit for python. I don't want to use jython and
use the existing Java based HTML unit.

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

Re: Static linking of python and pyqt

2007-12-19 Thread Diez B. Roggisch
Markus Dahlbokum wrote:

>> > I just want the qt libs linked to the interpreter without accessing
>> > them by a module. I tried the configure option '--with-libs='lib ...''.
>> > The make did fine but the executable is too small and the qt symbols
>> > are not known by it. How can I just link qt statically?
>>
>> Why do you want to do this? If qt isn't actually *used* in Python (as
>> you don't include the pyqt modules), what effect do you expect from
>> such linking?
>>
>> I think it linked just fine - it just didn't include any symbols,
>> because none were needed. That is the correct, expected behavior.
>> It all worked fine.
>>
>> Regards,
>> Martin
> 
> I need an environment that can be delivered to our customers without
> installing python, qt and pyqt. We want to provide the complete package.
> In order to do so I need to link at least python and qt. How can this be
> done?
> 
> Of course a complete package with python, qt and pyqt would be the best
> solution but there seem to be even more complications that way. If you can
> help me with this I would be very grateful.

I don't think you will succeed in that attempt. Statically linking means
statically refering, as martin says. I'm not an expert, but as qt refers to
PyQt (via sip-bindings) but the latter one isn't explicitly refered to by
the python-interpreter itself, you won't get the linking right.

I've got the agfeo Tk-suite client running on my system - it's a windows +
linux qt-based app. And it ships completely with a version of qt, locally
installed into it's program-dir. An approach that is even more common in
OSX and Windows. So you might consider using that instead.

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


Re: error with wxPython2.8-win32-unicode-2.8.7.1-py25.exe

2007-12-19 Thread Enrico
"Emmanuel" <[EMAIL PROTECTED]> ha scritto nel messaggio
news:[EMAIL PROTECTED]
> I recently upgraded wxpython (and python) on XP using wxPython2.8-
> win32-unicode-2.8.7.1-py25.exe
>
> Now when I run
>
> from wxPython.wx import *
>
> It crashes :

On my win2k with 2.8.4.0 I got:

>>> from wxPython.wx import *

Warning (from warnings module):
  File "__main__", line 1
DeprecationWarning: The wxPython compatibility package is no longer
automatically generated or actively maintained.  Please switch to the wx
package as soon as possible.

I suggest you to try
>>> from wx import *
or better
>>> import wx
(I don't think that importing everything is a good choice)

Enrico


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


3D plotting with python 2.5 on win32

2007-12-19 Thread anton
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.

I know  matplotlib.

There is MayaVi from enthon but you need to use their python (2.4.3),
all other stuff need picking sources etc.

IVuPy-0.1 seems to be abandonware, and there are no binaries.

I don't get qwtplot3d-0.2.7 to compile on my pc, it seems you need the
commercial
qt 4.33 (with opensource qt 4.3.3 I doesnt work).


Actually there is a big list on python org of 3D software, but I need
only plotting facility (like Matlab for example), and some/most of
the listed projects seem not be up to date (still based on python 2.4,
like PyOpenGL where you get binaries only for python 2.4,
seems to be abandonware too, sigh).

Thanks for a hint :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error with wxPython2.8-win32-unicode-2.8.7.1-py25.exe

2007-12-19 Thread Emmanuel
I switched back to wxPython2.6 and with wxPython2.6-win32-
unicode-2.6.4.0-py25.exe
this problem mentionned eariler does not occur.
-- 
http://mail.python.org/mailman/listinfo/python-list


sending a rip1 request via python

2007-12-19 Thread scripteaze
ok, im new to this sort of coding so excuse me if im not exactly sure
as to what i need to pull this off.

I need to be able to send a rip1 request to my rip1 enabled device.,
so i need python to send :

01 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
10

which is an RIP1 request and then have it respond back to me. im not
to worried about the returned format, but is there anyway to do this
in just a few lines of python?

i was looking at this page for ideas:

http://www.larsen-b.com/Article/206.html

its just one of the few google responses for : sending packets with
python.

any responses welcome, thanks :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to generate pdf file from an html page??

2007-12-19 Thread Terry Jones
> "Grant" == Grant Edwards <[EMAIL PROTECTED]> writes:
Grant> On 2007-12-19, abhishek <[EMAIL PROTECTED]> wrote:
>>> > Hi everyone, I am trying to generate a PDF printable format file from
>>> > an html page. Is there a way to do this using python. If yes then
>>> > which library and functions are required and if no then reasons why it
>>> > cant be done.
>>> 
>>> Here's one way:
>>> 
>>> --html2pdf.py-
>>> #!/usr/bin/python
>>> import os,sys
>>> 
>>> inputFilename,outputFilename = sys.argv[1:3]
>>> 
>>> os.system("w3m -dump %s | a2ps -B --borders=no | ps2pdf - %s" % 
>>> (inputFilename,outputFilename))

Note that this is highly insecure. outputFilename could be passed e.g., as

  /tmp/file.pdf; rm -fr /home/abhishek

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


Re: How to generate pdf file from an html page??

2007-12-19 Thread Ismail Dönmez
Wednesday 19 December 2007 17:40:17 tarihinde Terry Jones şunları yazmıştı:
> > "Grant" == Grant Edwards <[EMAIL PROTECTED]> writes:
>
> Grant> On 2007-12-19, abhishek <[EMAIL PROTECTED]> wrote:
> >>> > Hi everyone, I am trying to generate a PDF printable format file from
> >>> > an html page. Is there a way to do this using python. If yes then
> >>> > which library and functions are required and if no then reasons why
> >>> > it cant be done.
> >>>
> >>> Here's one way:
> >>>
> >>> --html2pdf.py--
> >>>--- #!/usr/bin/python
> >>> import os,sys
> >>>
> >>> inputFilename,outputFilename = sys.argv[1:3]
> >>>
> >>> os.system("w3m -dump %s | a2ps -B --borders=no | ps2pdf - %s" %
> >>> (inputFilename,outputFilename))
>
> Note that this is highly insecure. outputFilename could be passed e.g., as
>
>   /tmp/file.pdf; rm -fr /home/abhishek

And the solution is to use subprocess [0] instead of os.system()

[0] http://docs.python.org/lib/module-subprocess.html

Regards,
ismail

-- 
Never learn by your mistakes, if you do you may never dare to try again.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: New+old-style multiple inheritance

2007-12-19 Thread George Sakkis
On Dec 18, 3:16 pm, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Dec 18, 10:08 am, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > We are trying to monkey-patch a third-party library that mixes new and
> > old-style classes with multiple inheritance.
>
> New library?  Geez, if people are dumb enough to do this, are you sure
> you want your application to depend on their library?
>
> Sometimes you have to work with code that's not up to your standards,
> but come on.

Doing the armchair code reviewer without context is easy but my guess
would be that the old style library classes were written long before
the new style ones (perhaps even before the latter were introduced)
and/or written independently by different developers/groups, without
any plan to mix the two in the future. Also remember that up to 2.4
even the standard exception classes were old-style so it's not safe to
assume that you only have new style classes to worry about when the
very standard library includes lots of legacy code.

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


Re: How to generate pdf file from an html page??

2007-12-19 Thread Grant Edwards
On 2007-12-19, abhishek <[EMAIL PROTECTED]> wrote:

>> > Hi everyone, I am trying to generate a PDF printable format file from
>> > an html page. Is there a way to do this using python. If yes then
>> > which library and functions are required and if no then reasons why it
>> > cant be done.
>>
>> Here's one way:
>>
>> --html2pdf.py-
>> #!/usr/bin/python
>> import os,sys
>>
>> inputFilename,outputFilename = sys.argv[1:3]
>>
>> os.system("w3m -dump %s | a2ps -B --borders=no | ps2pdf - %s" % 
>> (inputFilename,outputFilename))
>> --

> hi grant have tried the command it resulted in the following errors
>
> sh: a2ps: not found

You'll need to install a2ps.  It's available as a standard
package for all the distros I've ever used.

> ESP Ghostscript 815.04:  Could not open the file /home/samba/users/
> Abhishek/newTemplate.pdf .
>  Unable to open the initial device, quitting.
> 256

Either your ghostscript installation is broken, or you've tried
to use an output path/file that's not writable.  I suspect the
latter.

-- 
Grant Edwards   grante Yow! Is it 1974?  What's
  at   for SUPPER?  Can I spend
   visi.commy COLLEGE FUND in one
   wild afternoon??
-- 
http://mail.python.org/mailman/listinfo/python-list


Preprocessing of input for the interactive interpreter?

2007-12-19 Thread Stefan Salewski
Hello,

I just start learning Python (ordered "Dive into Python" a week ago).

In the past I have used the Python interactive interpreter for some
calculations instead of Linux command line tools like "bc" or "calc".

I wonder if it is possible to do a pre-processing of command strings in
the interactive interpreter. (Not that I really need it, and currently my
Python skills are far away to manage this hack. But I am curious -- did
some Google search yesterday, but did not find an answer. Yes, an extended
interpreter called IPython exists -- this one seems to have this
functionality, and I may use this one later.)

It is possible to convert input in this form (input hook?):

My custom input format:

>>> b := 10a + 0,1

Format send to interpreter after preprocessing:

>>> b = 10*a + 0.1


Best regards

Stefan Salewski

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


Re: container.___le___ can use only <=?

2007-12-19 Thread Neil Cerutti
On 2007-12-15, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Dec 15, 9:05 am, [EMAIL PROTECTED] wrote:
>> My reasoning is (I hope) that the container ought to support
>> every comparison operation supported by the contained objects.
>> This can be ensured by being careful in the implementation.
>
> I see what you're asking now.  Yep, probably a bad idea to use
> that shortcut.

I put together a test suite, and discovered that the built-in
list assumes that all contained object support __eq__, i.e., it
may call __eq__ while performing some other comparison, e.g.,
__gt__. This is contrary to the rule I was contemplating for
sequence comparisons in this thread.

>>> class Evil:
...   def __init__(self, i):
... self.i = i
...   def __eq__(self, o):
... raise RuntimeError
...   def __gt__(self, o):
... if isinstance(o, Evil):
...   return self.i > o.i
... return NotImplemented
...
>>> [Evil(1)] > [Evil(0)]
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 5, in __eq__
RuntimeError

This prompted inspection of listobject.c. After trying some
short-cuts for __ne__ and __eq__, list_richcompare iterates
through both lists until the first non-equal elements are found,
and then performs the correct comparison, or simply returns,
depending on if the lists were the same length.

Otherwise, the built-in list rich comparison follows the advice
posted in this thread, i.e., it uses only the comparison
operation being implemented to compare contained objects.

When implementing a mutable sequence in Python, the rule of thumb
seems to be "do as lists do," so as of the Python's current
implementation, there's a small limit on the perversity level of
the rich comparison operations of types contained in lists.

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


Re: Allowing Arbitrary Indentation in Python

2007-12-19 Thread gDog
Hi, Sam-

I'm not wanting to start a flame war, either, but may I ask why does
your friend want to do that?  I'm always intrigued by the folks who
object to the indentation rules in Python, even though I've always
tried to keep consistent indentation in all the languages I've used
(and I've been at this since the 1980's).  Even my Perl coding friends
tend to insist on indents being aligned.  I'm just curious, that's
all.

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


Re: How to generate pdf file from an html page??

2007-12-19 Thread Grant Edwards
On 2007-12-19, Terry Jones <[EMAIL PROTECTED]> wrote:
>> "Grant" == Grant Edwards <[EMAIL PROTECTED]> writes:
>Grant> On 2007-12-19, abhishek <[EMAIL PROTECTED]> wrote:
 > Hi everyone, I am trying to generate a PDF printable format file from
 > an html page. Is there a way to do this using python. If yes then
 > which library and functions are required and if no then reasons why it
 > cant be done.
 
 Here's one way:
 
 --html2pdf.py-
 #!/usr/bin/python
 import os,sys
 
 inputFilename,outputFilename = sys.argv[1:3]
 
 os.system("w3m -dump %s | a2ps -B --borders=no | ps2pdf - %s" % 
 (inputFilename,outputFilename))
>
> Note that this is highly insecure. outputFilename could be passed e.g., as
>
>   /tmp/file.pdf; rm -fr /home/abhishek

Here's a half-assed solution:

inputFilename = inputFilename.replace("'","")
outputFilename = outputFilename.replace("'","")

os.system("w3m -dump '%s' | a2ps -B --borders=no | ps2pdf - '%s'" % 
(inputFilename,outputFilename))

As somebody else suggested, building the pipeline "by hand"
using the subprocess module is the most bullet-proof method.

-- 
Grant Edwards   grante Yow! I brought my BOWLING
  at   BALL -- and some DRUGS!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending a rip1 request via python

2007-12-19 Thread Dirk Loss
scripteaze wrote:
> I need to be able to send a rip1 request to my rip1 enabled device.,
> so i need python to send :
> 01 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> 10

Use Scapy:

from scapy import *
myrip = RIP()/RIPEntry(metric=16)
ans, unans = sr(IP(dst="192.168.1.1")/UDP(sport=520)/myrip)

http://www.secdev.org/projects/scapy/

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


Re: Allowing Arbitrary Indentation in Python

2007-12-19 Thread Sam
On Dec 19, 11:09 am, gDog <[EMAIL PROTECTED]> wrote:
> Hi, Sam-
>
> I'm not wanting to start a flame war, either, but may I ask why does
> your friend want to do that?  I'm always intrigued by the folks who
> object to the indentation rules in Python, even though I've always
> tried to keep consistent indentation in all the languages I've used
> (and I've been at this since the 1980's).  Even my Perl coding friends
> tend to insist on indents being aligned.  I'm just curious, that's
> all.
>
> Thanks,
> --greg

His comments on the subject are in the LiveJournal comment I linked to
in my original post.  I think it's mostly an idiosyncratic thing; he's
used to laying out GUI elements in a hierarchy using tabs (in some
language that allows arbitrary tabs) and now that he's experimenting
with the (new?) Python API for the same toolkit, he wishes he could
use the same coding style.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another newbie design question

2007-12-19 Thread MartinRinehart
This morning block comments disappeared from the Decaf design. Maybe
later today they'll be instantiated in the tokenizer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Allowing Arbitrary Indentation in Python

2007-12-19 Thread Chris Mellon
On Dec 19, 2007 10:46 AM, Sam <[EMAIL PROTECTED]> wrote:
> On Dec 19, 11:09 am, gDog <[EMAIL PROTECTED]> wrote:
> > Hi, Sam-
> >
> > I'm not wanting to start a flame war, either, but may I ask why does
> > your friend want to do that?  I'm always intrigued by the folks who
> > object to the indentation rules in Python, even though I've always
> > tried to keep consistent indentation in all the languages I've used
> > (and I've been at this since the 1980's).  Even my Perl coding friends
> > tend to insist on indents being aligned.  I'm just curious, that's
> > all.
> >
> > Thanks,
> > --greg
>
> His comments on the subject are in the LiveJournal comment I linked to
> in my original post.  I think it's mostly an idiosyncratic thing; he's
> used to laying out GUI elements in a hierarchy using tabs (in some
> language that allows arbitrary tabs) and now that he's experimenting
> with the (new?) Python API for the same toolkit, he wishes he could
> use the same coding style.
>


It's interesting that the solutions "move away from the terrible
abomination of a GUI toolkit" and "write Python wrappers that don't
cause actual physical pain" never occur to him. He's got a lot of
years invested in this layout so I understand the hesitance to move
away from it, but seriously - this is a really terrible way to do GUI
layout. The context manager solution is probably the best way to
maintain something close to the style he's used to.

All those setParent calls! *shiver*. I notice he retreats to the
"well, *I* can read it, so it's not unreadable" defense, which of
course applies to anything (I know people who can read x86 assembly
directly from hex dumps) without really addressing the merits of a
particular case.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New+old-style multiple inheritance

2007-12-19 Thread Carl Banks
On Dec 19, 10:55 am, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Dec 18, 3:16 pm, Carl Banks <[EMAIL PROTECTED]> wrote:
>
> > On Dec 18, 10:08 am, "[EMAIL PROTECTED]"
>
> > <[EMAIL PROTECTED]> wrote:
> > > We are trying to monkey-patch a third-party library that mixes new and
> > > old-style classes with multiple inheritance.
>
> > New library?  Geez, if people are dumb enough to do this, are you sure
> > you want your application to depend on their library?
>
> > Sometimes you have to work with code that's not up to your standards,
> > but come on.
>
> Doing the armchair code reviewer without context is easy but my guess
> would be that the old style library classes were written long before
> the new style ones (perhaps even before the latter were introduced)
> and/or written independently by different developers/groups, without
> any plan to mix the two in the future. Also remember that up to 2.4
> even the standard exception classes were old-style so it's not safe to
> assume that you only have new style classes to worry about when the
> very standard library includes lots of legacy code.


It's not the use of old-style classes, or even old-style and new-style
in the same package.  It's multiple inheritance combining old- and new-
style classes that's so wrong here.  They should have converted the
old-style to new when they decided to derive from both types (it's not
like that's terribly difficult).


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


How to in Python

2007-12-19 Thread MartinRinehart
I've got a pointer to a position in a line of code that contains
either a digit or a period (decimal point). I've got this comment:

Numbers are one of these:
integers:
digit+
0xhex_digit+
decimals:
digit+.digit*[E['+'|'-']digit+]
.digit+[E['+'|'-']digit+]
digit+[.digit*]%
.digit+%

Common metacode: '*' = 0 or more, '+' = 1 or more, [] = optional, | =
or, ...

Now I need to instantiate the comment. How would an experienced Python
coder proceed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Where best to put local modules?

2007-12-19 Thread tinnews
I'm just beginning to create some python modules for my own use and
I'm wondering where to put them.  Initially I have put them in
$HOME/bin and I have set PYTHONPATH to point to them there.  It all
seems to be OK but I was wondering if I might be storing up problems
for the future by putting python modules in with my odds and sods of
shell scripts etc. (and with my python 'main' scripts).

Would I be better off putting the modules somewhere else, e.g.
somewhere like $HOME/lib/python?


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


Re: Preprocessing of input for the interactive interpreter?

2007-12-19 Thread Larry Bates
Stefan Salewski wrote:
> Hello,
> 
> I just start learning Python (ordered "Dive into Python" a week ago).
> 
> In the past I have used the Python interactive interpreter for some
> calculations instead of Linux command line tools like "bc" or "calc".
> 
> I wonder if it is possible to do a pre-processing of command strings in
> the interactive interpreter. (Not that I really need it, and currently my
> Python skills are far away to manage this hack. But I am curious -- did
> some Google search yesterday, but did not find an answer. Yes, an extended
> interpreter called IPython exists -- this one seems to have this
> functionality, and I may use this one later.)
> 
> It is possible to convert input in this form (input hook?):
> 
> My custom input format:
> 
 b := 10a + 0,1
> 
> Format send to interpreter after preprocessing:
> 
 b = 10*a + 0.1
> 
> 
> Best regards
> 
> Stefan Salewski
> 

I'm no expert, but I'll bet that pyparsing module will be the answer to your 
question.

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


Re: 3D plotting with python 2.5 on win32

2007-12-19 Thread markacy
On 19 Gru, 15:15, 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.
>
> I know  matplotlib.
>
> There is MayaVi from enthon but you need to use their python (2.4.3),
> all other stuff need picking sources etc.
>
> IVuPy-0.1 seems to be abandonware, and there are no binaries.
>
> I don't get qwtplot3d-0.2.7 to compile on my pc, it seems you need the
> commercial
> qt 4.33 (with opensource qt 4.3.3 I doesnt work).
>
> Actually there is a big list on python org of 3D software, but I need
> only plotting facility (like Matlab for example), and some/most of
> the listed projects seem not be up to date (still based on python 2.4,
> like PyOpenGL where you get binaries only for python 2.4,
> seems to be abandonware too, sigh).
>
> Thanks for a hint :-)

Hi anton,

   Have you take a look at vpython? Here's their website:
http://www.vpython.org/
And here is an simple example of how to use it:
http://linuxgazette.net/144/john.html

Hope this helps :-)

Cheers,

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


Re: No tab completion if sys.stdout is redirected

2007-12-19 Thread Dirk Loss
Bjoern Schliessmann wrote:
> readline module applies its autocompletion functions to (and only
> to) sys.stdout.

I see. Then I guess I'll have to avoid redirecting sys.stdout and
come up with some kind of workaround instead.
Nevertheless, thanks for the info.

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


Re: 3D plotting with python 2.5 on win32

2007-12-19 Thread Jason
On Dec 19, 7: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.
>
> I know  matplotlib.
>
> There is MayaVi from enthon but you need to use their python (2.4.3),
> all other stuff need picking sources etc.
>
> IVuPy-0.1 seems to be abandonware, and there are no binaries.
>
> I don't get qwtplot3d-0.2.7 to compile on my pc, it seems you need the
> commercial
> qt 4.33 (with opensource qt 4.3.3 I doesnt work).
>
> Actually there is a big list on python org of 3D software, but I need
> only plotting facility (like Matlab for example), and some/most of
> the listed projects seem not be up to date (still based on python 2.4,
> like PyOpenGL where you get binaries only for python 2.4,
> seems to be abandonware too, sigh).
>
> Thanks for a hint :-)

PyOpenGL isn't abandonware.  Python 2.5 comes with the ctypes module
[1], so there isn't any need for a binary wrapper module anymore.

Under 2.5, all pure "wrapper" binary modules are unnecessary.  They
can work cross-platform from pure Python, calling directly into the C
function code.  Trust me, this is an excellent improvement.

PyOpenGL probably too low-level for what you want, but it isn't dead
yet.  (It's just pining for the symbol table.)

  --Jason

[1] http://docs.python.org/lib/module-ctypes.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New+old-style multiple inheritance

2007-12-19 Thread George Sakkis
On Dec 19, 12:01 pm, Carl Banks <[EMAIL PROTECTED]> wrote:

>  They should have converted the
> old-style to new when they decided to derive from both types (it's not
> like that's terribly difficult).

Unless perhaps the old-style class is part of an stdlib or 3rd party
(or rather 4th party since "they" are the 3rd party here ;-)) module.
Even if it's technically possible and the change doesn't break other
things, I'd rather not have to maintain a patched version of the
stdlib.

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


Re: Another newbie design question

2007-12-19 Thread Paul McGuire
On Dec 19, 10:48 am, [EMAIL PROTECTED] wrote:
> This morning block comments disappeared from the Decaf design. Maybe
> later today they'll be instantiated in the tokenizer.

Out of the idlest of curiousity, does this language have a BNF, or
some other form of grammar definition?

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


Re: Another newbie design question

2007-12-19 Thread Neil Cerutti
On 2007-12-19, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Dec 19, 10:48 am, [EMAIL PROTECTED] wrote:
>> This morning block comments disappeared from the Decaf design.
>> Maybe later today they'll be instantiated in the tokenizer.
>
> Out of the idlest of curiousity, does this language have a BNF,
> or some other form of grammar definition?

Might I suggest: laughs evilly, rubbing hands together?

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


Re: import X between submodules in a package

2007-12-19 Thread Donn Ingle
> You guess. When fisrt imported, the module's source is executed, a
> module object is created and stored in sys.modules, and the needed names
> are inserted into the importing module's namespace. Next times the
> module is "served" directly from sys.modules.

Peachy, thanks.

\d

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



Re: error with wxPython2.8-win32-unicode-2.8.7.1-py25.exe

2007-12-19 Thread kyosohma
On Dec 19, 5:26 am, Emmanuel <[EMAIL PROTECTED]> wrote:
> I recently upgraded wxpython (and python) on XP using wxPython2.8-
> win32-unicode-2.8.7.1-py25.exe
>
> Now when I run
>
> from wxPython.wx import *
>
> It crashes :
>
> -> import _wx
>  ...
>
> from _misc import *
>
> ...
>
> --> 456 wxDateTime_GetNumberOfDaysinYear =
> wx._misc.DateTime_GetNumberOfDaysinYear
>
> ...
>
> AtributeError: 'module' object has no atribute
> 'DateTime_GetNumberOfDaysinYear'
>
> Is it a known problem or is there something wrong only on my side?

The newer versions of wx are not supposed to be imported in this way:

from wx import *

The current correct way is to just import wx. I am not sure when this
was started, but it was more than a year ago.

Most of the time, from package import * is NOT recommended as it can
unintended consequences, such as poisoning the namespace. For example,
if you did this with a package that contained an object called "foo"
and you did this:

foo = 2

Then you just reassigned the foo that was imported.

HTH

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


Re: Where best to put local modules?

2007-12-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> I'm just beginning to create some python modules for my own use and
> I'm wondering where to put them.  Initially I have put them in
> $HOME/bin and I have set PYTHONPATH to point to them there.  It all
> seems to be OK but I was wondering if I might be storing up problems
> for the future by putting python modules in with my odds and sods of
> shell scripts etc. (and with my python 'main' scripts).
> 
> Would I be better off putting the modules somewhere else, e.g.
> somewhere like $HOME/lib/python?
> 

If you're on a shared system and don't have admin access, this last 
solution is probably the best - "pure" modules have nothing to do in a 
bin/ directory indeed. Now if it's your own computer, why not just put 
them in /path/to/python/libs/site-packages ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import X between submodules in a package

2007-12-19 Thread Gabriel Genellina
En Wed, 19 Dec 2007 07:02:00 -0300, Chris <[EMAIL PROTECTED]> escribió:

> #fp.py
> import cli
>
> #cli.py
> import os
>
> #config.py
> import cli
> print cli.os.environ['HOME']
>
> if you wish to use the os module loaded by the cli module

En Wed, 19 Dec 2007 09:42:31 -0300, Donn Ingle <[EMAIL PROTECTED]>  
escribió:

> Chris wrote:
>> print cli.os.environ['HOME']
> I was really confused by your reply until I saw the cli.os part. Okay, I  
> see
> what you mean.

Note that altough this is perfectly legal, I would *not* recommend doing  
it unless you have a compelling reason to do so (like providing a single  
public namespace for a package, for example).
Some people choose to remove spurious names, to keep the namespace clean  
if that's important for other usage:

# config.py
import os, sys
startup_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
del os, sys
background_color = "white"
...

# main.py
import config
for key, value in vars(config).iteritems():
   print '%s=%r' % (key, value)

-- 
Gabriel Genellina

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


Re: operator module isSequenceType with builtin set produces False

2007-12-19 Thread Gabriel Genellina
En Wed, 19 Dec 2007 06:28:03 -0300, MarkE <[EMAIL PROTECTED]>  
escribi�:

>> Is there a short Pythonic way to determine whether an object is
>> iterable (iteratable ??) that I haven't thought of (getattr(obj,
>> '__iter__') ?). Would operator.isIterable() be at all a useful
>> addition ?

Yes, I think the only way is to try iter(obj) and see if it succeeds  
(that's basically the same as what you do with getattr, but actually  
creates the iterator and checks that it's of the right type).

> And here I probably meant container (although the url says sequence
> when the article meant container, bit like me):
> http://docs.python.org/ref/sequence-types.html
> "Containers usually are sequences (such as lists or tuples) or
> mappings (like dictionaries), but can represent other containers as
> well"
>
> So same question, but perhaps "isContainer()" rather than
> "isIterable()"

"container" is too generic. Perhaps you can look if it has a __len__  
attribute. But anyone could implement a linked list (the common interfase  
don't fit well with those sequence/mapping methods) and would be hard to  
deduce whether it is a container or not without further knowledge about it.

-- 
Gabriel Genellina

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

Re: Static linking of python and pyqt

2007-12-19 Thread Martin v. Löwis
> I need an environment that can be delivered to our customers without 
> installing python, qt and pyqt. We want to provide the complete package.
> In order to do so I need to link at least python and qt. How can this be done?

You should link all extension modules into the Python executable,
through Setup.local

> Of course a complete package with python, qt and pyqt would be the best 
> solution but there seem to be even more complications that way. If you can 
> help me with this I would be very grateful.

Not sure. You didn't explain what the precise problem is, so it's
difficult to help in correcting it.

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


Re: Where best to put local modules?

2007-12-19 Thread Gabriel Genellina
En Wed, 19 Dec 2007 14:02:20 -0300, <[EMAIL PROTECTED]> escribi�:

> I'm just beginning to create some python modules for my own use and
> I'm wondering where to put them.  Initially I have put them in
> $HOME/bin and I have set PYTHONPATH to point to them there.  It all
> seems to be OK but I was wondering if I might be storing up problems
> for the future by putting python modules in with my odds and sods of
> shell scripts etc. (and with my python 'main' scripts).
>
> Would I be better off putting the modules somewhere else, e.g.
> somewhere like $HOME/lib/python?

Try lib/pythonX.X/site-packages, which is already on sys.path so you don't  
have to set PYTHONPATH

-- 
Gabriel Genellina

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

Re: How to in Python

2007-12-19 Thread Gabriel Genellina
En Wed, 19 Dec 2007 14:02:00 -0300, <[EMAIL PROTECTED]> escribi�:

> I've got a pointer to a position in a line of code that contains
> either a digit or a period (decimal point). I've got this comment:
>
> Numbers are one of these:
> integers:
> digit+
> 0xhex_digit+
> decimals:
> digit+.digit*[E['+'|'-']digit+]
> .digit+[E['+'|'-']digit+]
> digit+[.digit*]%
> .digit+%
>
> Common metacode: '*' = 0 or more, '+' = 1 or more, [] = optional, | =
> or, ...
>
> Now I need to instantiate the comment. How would an experienced Python
> coder proceed?

Do you have to validate input based on that grammar? That is, do you want  
a function like this?

def is_valid_number(input):
   if 
  return True
   return False

Or, do you want to consume characters starting from your pointer, stopping  
when an invalid character appears?

This looks like one of those few cases where "Use a regular expression"  
may be a good answer. If you like a more Pythonic approach, try using  
Pyparsing 

-- 
Gabriel Genellina

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

help displaying pdf thru client/server

2007-12-19 Thread PaulS
Connecting to a Linux server from XP pc using a telnet program, I run a 
report and convert it to a pdf document(using Reportlab) which I need to 
display.  The pdf is on the Linux server. Ideas how to display to the pc 
would be appreciated. thanks, paul 


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


Re: help displaying pdf thru client/server

2007-12-19 Thread Larry Bates
PaulS wrote:
> Connecting to a Linux server from XP pc using a telnet program, I run a 
> report and convert it to a pdf document(using Reportlab) which I need to 
> display.  The pdf is on the Linux server. Ideas how to display to the pc 
> would be appreciated. thanks, paul 
> 
> 
You will need webserver running (Apache?) on Linux server that shows a page 
that 
has a link to the pdf file that you created.

Alternatively you can use SimpleHTTPServer module or Twisted to make a more 
stripped down webserver but it is probably easier just to use Apache.

You didn't say if the Linux server was local or not.  If local, you could use 
SAMBA to create a SMB share and have the XP PC get to it that way.  There are 
other ways, but these should get you started.

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


Re: help displaying pdf thru client/server

2007-12-19 Thread kyosohma
On Dec 19, 1:41 pm, "PaulS" <[EMAIL PROTECTED]> wrote:
> Connecting to a Linux server from XP pc using a telnet program, I run a
> report and convert it to a pdf document(using Reportlab) which I need to
> display.  The pdf is on the Linux server. Ideas how to display to the pc
> would be appreciated. thanks, paul

Some ideas, none tested:

1) Use Python to download the document and from the Windows box, do an
os.startfile(path)
2) Use a Python web framework (such as Turbogears, Pylons or Django)
to display the pdf in the browser if acrobat is installed
3) If the pdf is only accessible from a machine on your local network,
than you can do #1 without downloading it if you have samba running.
I've opened PDFs on our Debian boxes like this:
os.startfile(r'\\server\path\to\pdf')

HTH

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


Re: help displaying pdf thru client/server

2007-12-19 Thread Jean-Paul Calderone
On Wed, 19 Dec 2007 13:50:10 -0600, Larry Bates <[EMAIL PROTECTED]> wrote:
>PaulS wrote:
>> Connecting to a Linux server from XP pc using a telnet program, I run a
>> report and convert it to a pdf document(using Reportlab) which I need to
>> display.  The pdf is on the Linux server. Ideas how to display to the pc
>> would be appreciated. thanks, paul
>>
>>
>You will need webserver running (Apache?) on Linux server that shows a page 
>that
>has a link to the pdf file that you created.
>
>Alternatively you can use SimpleHTTPServer module or Twisted to make a more
>stripped down webserver but it is probably easier just to use Apache.

Serving static files with Twisted is pretty easy:

twistd web --port abcd --path /foo/bar

I don't think any way you can set up Apache is easier than that. ;)

>
>You didn't say if the Linux server was local or not.  If local, you could use
>SAMBA to create a SMB share and have the XP PC get to it that way.  There are
>other ways, but these should get you started.
>
>-Larry

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


Re: Does fileinput.input() read STDIN all at once?

2007-12-19 Thread Adam Funk
On 2007-12-18, Jonathan Gardner wrote:

>> As a test, I tried this:
>>
>>for line in fileinput.input():
>>   print '**', line
>>
>> and found that it would print nothing until I hit Ctl-D, then print
>> all the lines, then wait for another Ctl-D, and so on (until I pressed
>> Ctl-D twice in succession to end the loop).

> There is probably a 1024 byte buffer. Try filling it up and see if you
> get something before you hit CTRL-D.

Thanks; I'm looking into the buffering question.


> It sounds like you want to write some kind of interactive program for
> the terminal. Do yourself a favor and use curses or go with a full-
> blown GUI.

No, I'm really interested in reading the input from files!

This just came up because I was trying to test the program by giving
it no filename arguments and typing sample input.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another newbie design question

2007-12-19 Thread John Machin
On Dec 20, 5:00 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Dec 19, 10:48 am, [EMAIL PROTECTED] wrote:
>
> > This morning block comments disappeared from the Decaf design. Maybe
> > later today they'll be instantiated in the tokenizer.
>
> Out of the idlest of curiousity, does this language have a BNF, or
> some other form of grammar definition?
>
> -- Paul

+1 Rhetorical Question OTW

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


Re: Changing intobject to use int rather than long

2007-12-19 Thread Terry Reedy

"Christian Heimes" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Terry Reedy wrote:
| > Good idea.  I think people who moved to 64 bits to get 64 bits would be
| > upset if they did not ;-).
|
| Windows X64 users still get 32bit ints. The long datatype is 32bit even
| on the 64bit version of Windows.

Yes, anyone expecting to get 64 bit ints from Windows would be upset.  And 
those who are getting 64 bit ints from real 64 bit OSes would be upset if 
the OPs suggestion were implemented. 



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


dbus bindings under Windows

2007-12-19 Thread Yann Leboulanger
Are there any python dbus bindings under windows ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to in Python

2007-12-19 Thread John Machin
On Dec 20, 4:02 am, [EMAIL PROTECTED] wrote:
> I've got a pointer to a position in a line of code that contains
> either a digit or a period (decimal point). I've got this comment:
>
> Numbers are one of these:
> integers:
> digit+
> 0xhex_digit+
> decimals:
> digit+.digit*[E['+'|'-']digit+]
> .digit+[E['+'|'-']digit+]
> digit+[.digit*]%
> .digit+%
>
> Common metacode: '*' = 0 or more, '+' = 1 or more, [] = optional, | =
> or, ...
>
> Now I need to instantiate the comment. How would an experienced Python
> coder proceed?

Use a proper lexer written by somebody who knows what they are doing,
as has already been recommended to you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: operator module isSequenceType with builtin set produces False

2007-12-19 Thread Terry Reedy

"MarkE" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|| > Is there a short Pythonic way to determine whether an object is
| > iterable (iteratable ??)

Welcome to Python and its neat concept of iterables and iterators.
An iterable is an object that has an __iter__ method that returns an 
iterator.
An iterator is an object that has an __iter__ method that returns itself
and a next method that either returns another item or raises StopIteration.
(I omit an older alternative that will disappear in 3.0.  Ignore it.)
(Also, in 3.0, next methods will become __next__ methods.)
So iterators are also, intentionally, iterables.
So functions can take arguments that are either by beginning with
   it = iter(iterable)
without worrying about whether the iterable already is an iterator.
As Gabriel said, assume that an object returned by iter is an iterable.
Writing an __iter__ method that does not return such would be either a bug 
or a nasty trick.

I usually would not bother wrapping iter in a try: block.
Just iterate with 'it' and if it is not an iterator, you will find out.

| And here I probably meant container (although the url says sequence
| when the article meant container, bit like me):
| http://docs.python.org/ref/sequence-types.html
| "Containers usually are sequences (such as lists or tuples) or
| mappings (like dictionaries), but can represent other containers as
| well"

I think 'collection' is a better word that 'container' since 'container' 
implies an exclusivity (which is false) that 'collection' does not, at 
least not necessarily.

| So same question, but perhaps "isContainer()" rather than
| "isIterable()"

Python 3 will have Abstract Base Classes that will better defined some of 
these concepts.  So if class authors bother to inherit from them when 
appropriate, isinstance(obj, Sequence) or isinstance(obj, Number), for 
instance, will tell you.

Terry Jan Reedy



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


integer subclass range behavior

2007-12-19 Thread [EMAIL PROTECTED]
I was wondering what would happen, so I tried this out for the heck of
it with:
Python 3.0a2 (py3k:59572M, Dec 19 2007, 15:54:07) [MSC v.1500 32 bit
(Intel)] on win32

class a(int):
  def __new__(cls,number):
return int.__new__(cls,number)

for x in range(0,a(5)):
  print(x)


Which resulted in a:

Traceback (most recent call last):
  File "", line 1, in 
  File "a.py", line 5, in 
for x in range(0,a(5)):
SystemError: ..\Objects\longobject.c:400: bad argument to internal
function
[41030 refs]


It looks like the rangeobject performs a FitsInLong test on each of
the parameters to range, which uses the function
_PyLong_FitsInLong(PyObject *vv) within longobject.c.  In tern, this
performs a typecheck:  #define PyLong_CheckExact(op) (Py_TYPE(op) ==
&PyLong_Type) that fails.


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


Is there a simple way to parse this string ?

2007-12-19 Thread Stef Mientki
hello,

I need to translate the following string
a = '(0, 0, 0, 255), (192, 192, 192, 255), True, 8'

into the following list or tuple
b = [(0, 0, 0, 255), (192, 192, 192, 255), True, 8 ]

Is there a simple way to to this.
(Not needed now, but might need it in the future: even deeper nested 
lists, represented by a string.)

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


In an inherited class, "embedded" classes is referenced?

2007-12-19 Thread Christian Joergensen
Hello

I stumpled upon this "feature" during my work tonight, and found it 
a bit confusing:

>>> class A(object):
... class C: 
... foobar = 42
... 
>>> class B(A): pass
... 
>>> A.C   

>>> B.C

>>> B.C.foobar = 60
>>> A.C.foobar  
60  

When I inherit B from A, I would expect that A.C and B.C would be two
different classes? But apparently not.

Can anyone give me an explanation? Or a better workaround than 
something along the line of:

>>> B.C = type("C", (object,), {'foobar': 60})

Instead of:

>>> B.C.foobar = 60

Thanks,

-- 
Christian Joergensen | Linux, programming or web consultancy
http://www.razor.dk  | Visit us at: http://www.gmta.info
-- 
http://mail.python.org/mailman/listinfo/python-list


class memebers

2007-12-19 Thread N L
How do I list the members of a class? Meaning, how do I know what are the 
functions a particular class has, if i do not want to manually browse through 
the class?
N




  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Is there a simple way to parse this string ?

2007-12-19 Thread James Newton
>I need to translate the following string
>a = '(0, 0, 0, 255), (192, 192, 192, 255), True, 8'
>
>into the following list or tuple
>b = [(0, 0, 0, 255), (192, 192, 192, 255), True, 8 ]

>Is there a simple way to to this.
>Stef Mientki


>>> a = '(0, 0, 0, 255), (192, 192, 192, 255), True, 8'
>>> b = eval(a)
>>> b
((0, 0, 0, 255), (192, 192, 192, 255), True, 8)
>>> c = list(eval(a))
>>> c
[(0, 0, 0, 255), (192, 192, 192, 255), True, 8]
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >