RELEASED Python 2.5.2, release candidate 1

2008-02-15 Thread Martin v. Löwis
On behalf of the Python development team and the Python community, I'm
happy to announce the release of Python 2.5.2 (release candidate 1).

This is the second bugfix release of Python 2.5. Python 2.5 is now in
bugfix-only mode; no new features are being added. According to the
release notes, over 100 bugs and patches have been addressed since
Python 2.5.1, many of them improving the stability of the interpreter,
and improving its portability.

For more information on Python 2.5.2, including download links for
various platforms, release notes, and known issues, please see:

   http://www.python.org/2.5.2/

Highlights of this new release include:

   Bug fixes. According to the release notes, at least 100 have been fixed.

Highlights of the previous major Python release (2.5) are available
from the Python 2.5 page, at

   http://www.python.org/2.5/highlights.html

Enjoy this release,
Martin

Martin v. Loewis
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: SPE 0.8.4.c Python IDE editor

2008-02-15 Thread Stani
As SPE was being developed for more than a year in subversion, I
thought it is time for a release again. This is a major bugfix
release. It ships updated plugins and also some new features,
especially if you use Linux or Blender, for which Witold did a great
job. I would also like to thank in particular the webhost Zindep.com
for their support and patience.

New features:

* new versions of WinPdb debugger, PyChecker, wxGlade  XRCed gui
designer
* clear output pane
* support for wxPython 2.8
* linux support for nautilus, gnome-terminal, konqueror, konsole,
thunar
* improved blender support up to 2.45 (by Witold)

Fixes:

* sidebar sash more tolerant
* show path in title (linux)
* run with filename with spaces
* nicer debug dialog box
* kill process fix
* notebook
* insert signature
* numpad keys (by isolationism)
* find tab with nonexisting files
* add environment to SPE.py (linux)
* better warning for documentation for unsaved files
* better handling of new empty files
* many more...

Installing on Debian(unstable) and Ubuntu Hardy:

sudo apt-get install spe

Installing on all other platforms:

   1. Download either the zip or tar ball from here
   2. Unzip it where you want and do NOT rename the _spe folder
   3. Start SPE from within the _spe folder with python SPE.py

About SPE:
SPE is a python IDE with auto-indentation, auto completion, call tips,
syntax coloring, uml viewer, syntax highlighting, class explorer,
source index, auto todo list, sticky notes, integrated pycrust shell,
python file browser, recent file browser, dragdrop, context help, ...
Special is its blender support with a blender 3d object browser and
its
ability to run interactively inside blender. Spe integrates with XRCed
(gui
designer) and ships with wxGlade (gui designer), PyChecker (source
code doctor), Kiki (regular expression console) and WinPdb (remote,
multi-threaded debugger).

The development of SPE is driven by its donations. Anyone who donates
can ask for an nice pdf version of the manual without ads (74 pages).

For more info go to http://pythonide.stani.be
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[ANN] Release 0.69.1 of Task Coach

2008-02-15 Thread Frank Niessink
Hi,

I'm happy to announce release 0.69.1 of Task Coach. This bug fix
release addresses three bugs introduced in the previous release.

Bugs fixed:

* Exception when closing a task editor dialog. This causes updates of
task states not to be displayed properly. The bug itself does not
cause data loss, but it might trick users into saving an empty task
file over their existing data.
* On Mac OS X, users couldn't enter 'P' and 'M' in text boxes, because
these were mapped to menu items. Reorganized keyboard shortcuts to fix
this.
* The arrow ('→') and infinity symbol ('∞') are not visible on all
computers, so Task Coach is back to using '-' and 'Infinite' again.


What is Task Coach?

Task Coach is a simple task manager that allows for hierarchical
tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is
developed using Python and wxPython. You can download Task Coach from:

http://www.taskcoach.org

In addition to the source distribution, packaged distributions are
available for Windows XP/Vista, Mac OSX, and Linux (Debian and RPM format).

Note that Task Coach is alpha software, meaning that it is wise to back
up your task file regularly, and especially when upgrading to a new release.

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

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


RELEASED: Pymacs 0.23

2008-02-15 Thread François Pinard
Hello to everybody, and Emacs users in the Python community.

Here is Pymacs 0.23!  There has been a while, so I advise current Pymacs
users to switch with caution.  All reported bugs have been squashed, if
we except one about Emacs quit (C-g) not being obeyed gracefully.  A few
suggestions have been postponed, to be pondered later.

The manual is now in reST format, and everything Allout is gone.
Postscript and PDF files are not anymore part of the distribution, you
may find them on the Web site, or use the Makefile if you have needed
tools.  Examples have been moved out of the manual into a new contrib/
subdirectory, which also holds a few new contributions.  The example of
a Python back-end for Emacs Gnus has been deleted.

Python 1.5.2 compatibility has been dropped; use Python 2.2 or better.
The Pymacs manual explains installation procedure, now simplified.  The
pymacs-services script is gone, this should ease installing Pymacs on MS
Windows.  There is also a small, still naive validation suite.

The communication protocol has been revised: more clarity, less magic.
Zombie objects are less dreadful by default.  The API now supports False
and True constants, and Unicode strings (within limits set by Emacs).

Special thanks to those who helped me at creating or testing this release.



Pymacs is a powerful tool which, once started from Emacs, allows
both-way communication between Emacs Lisp and Python.  Pymacs aims
Python as an extension language for Emacs rather than the other way
around, and this asymmetry is reflected in some design choices.  Within
Emacs Lisp code, one may load and use Python modules.  Python functions
may themselves use Emacs services, and handle Emacs Lisp objects kept in
Emacs Lisp space.

The main Pymacs site is `http://pymacs.progiciels-bpi.ca/', and you may
fetch `http://pymacs.progiciels-bpi.ca/archives/Pymacs.tar.gz'.
Report problems and suggestions to `mailto:[EMAIL PROTECTED]'.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


adding values to keys

2008-02-15 Thread Brandon
Hi all,

I'm not sure if I'm calling the right method in a dictionary.  I have:

for k,v in dict.items():
 NT = k,range(alpha,omega)#where alpha and omega are
previously defined as 1 and 4, respectively
 print NT

which gives:
('w', [0,1,2,3])
('x', [0,1,2,3])
('y', [0,1,2,3])
('z', [0,1,2,3])

And now I want a master dictionary like: [{'w': [0],[1],[2],[3]},
{'x': [0]...]

So I try:

MT = {}
MT.fromkeys(NT[0], range(alpha,omega))
print MT

but this only returns:
{}
{}
{}...

Anybody see what I'm doing wrong?  Any advice is much appreciated.

Thanks,

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


Re: dictionary of operators

2008-02-15 Thread A.T.Hofkamp
On 2008-02-14, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,

 In the standard library module operator, it would be nice to have a 
 dictionary
 mapping operators strings with their respective functions. Something like:

   {
 '+': add,
 '-': sub,
 'in': contains,
 'and': and_,
 'or': or_,
 ...
   }

 Does such a dictionary already exist? Is it really a good and useful idea?

How would you handle changes in operator syntax?
- I have 'add' instead of '+'
- I have U+2208 instead of 'in'

I don't think this is generally applicable.


Why don't you attach the function to the +/-/in/... token instead? Then you
don't need the above table at all.


sincerely,
Albert
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a question in python curses modules

2008-02-15 Thread Marc 'BlackJack' Rintsch
On Fri, 15 Feb 2008 11:55:11 +0800, Marco wrote:

 Hi, I wanna write a simple curses program, but somethings confuse
 me, my code here:
 
 #!/usr/bin/python
 
 import os
 import sys
 import time
 import curses
 
 class CursesObject( object ):
 
 def __init__(self):
 
 self.STDSCR = curses.initscr()
 curses.noecho()
 curses.cbreak()
 self.STDSCR.keypad(1)
 
 def __del__(self):
 self.STDSCR.keypad(0)
 curses.nocbreak()
 curses.echo()
 curses.endwin()
 
 c1 = CursesObject()
 time.sleep(1)
 
 
 I donot know what happen, but in __del__ function, curses become None??!!

When the interpreter shuts down it has to remove objects.  Everything you
need in a `__del__()` method must be referenced by that object to be sure
that it is still there and not already garbage collected.  *But* it's not
guaranteed that `__del__()` is called at all!  So if you think this clean
up is necessary to leave a usable console then don't put it into a
`__del__()` method!

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adding values to keys

2008-02-15 Thread Bruno Desthuilliers
Brandon a écrit :
 Hi all,
 
 I'm not sure if I'm calling the right method in a dictionary.  I have:
 
 for k,v in dict.items():

don't use 'dict' as an identifier, this shadows the builtin dict type.

  NT = k,range(alpha,omega)#where alpha and omega are
 previously defined as 1 and 4, respectively
  print NT

If you don't care about the values, you should iterate directly over the 
keys - which is the default for dicts, ie:

for key in somedict:
print k

Also, by convention, ALL_CAPS names denote (pseudo) symbolic constants.

 which gives:
 ('w', [0,1,2,3])
 ('x', [0,1,2,3])
 ('y', [0,1,2,3])
 ('z', [0,1,2,3])

and by that time, NT == ('z', [0,1,2,3])

 And now I want a master dictionary like: [{'w': [0],[1],[2],[3]},
 {'x': [0]...]

This is a list of dicts, each one having a single key pointing to a 
tuple of four one-element lists. Are you *sure* this is *really* what 
you want ?

 So I try:
 
 MT = {}

this creates an empty dict instance...

 MT.fromkeys(NT[0], range(alpha,omega))

this calls the classmethod dict.fromkeys() on the empty dict instance 
created by the previous statement, and discards the dict instance 
created by the call to fromkeys().

Also, since at this stage NT is ('z', [0,1,2,3]), NT[0] is 'z', so the 
dict created by fromkeys (and happily discarded) looked like:

{'z': [0, 1, 2, 3]}


 print MT
 
 but this only returns:
 {}

Indeed. You defined MT as an empty dict, didn't you ?

 {}
 {}...
 
 Anybody see what I'm doing wrong? 

Quite a lot of things actually, but the worst one is probably failing to 
  read the FineManual(tm) !-)

Assuming that you have a dict d, and want to build another dict with d 
keys and range(alpha,omega) for values, here's the solution:


alpha = 0
omega = 4

# arbitrary values, just for the exemple
d = dict(w=1, x=2, y=3, z=4)

master = dict.fromkeys(d, range(alpha, omega))

print master
= {'y': [0, 1, 2, 3], 'x': [0, 1, 2, 3], 'z': [0, 1, 2, 3], 'w': [0, 1, 
2, 3]}

Now note that this will associate each key of master with the *same* 
list instance, so:

master['y'].append(42)
  print master
{'y': [0, 1, 2, 3, 42], 'x': [0, 1, 2, 3, 42], 'z': [0, 1, 2, 3, 42], 
'w': [0, 1, 2, 3, 42]}

which is perhaps not what you want !-)

If you want distinct lists, dict.fromkeys is not the right method. You'd 
better use the default constructor, passing it a sequence of key,value 
tuples, ie:

master = dict((k, range(0,4)) for k in d)
print master
= {'y': [0, 1, 2, 3], 'x': [0, 1, 2, 3], 'z': [0, 1, 2, 3], 'w': [0, 1, 
2, 3]}
master['y'].append(42)
print master
{'y': [0, 1, 2, 3, 42], 'x': [0, 1, 2, 3], 'z': [0, 1, 2, 3], 'w': [0, 
1, 2, 3]}


 Any advice is much appreciated.

Ok:
- read the FineManual(tm)
- learn to use the interactive Python shell
- read the FineManual(tm)
- learn to use the help feature of the interactive Python shell
- read the FineManual(tm)
- read pep08 on naming conventions
- read the FineManual(tm)

!-)

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


Re: adding values to keys

2008-02-15 Thread Bruno Desthuilliers
Dennis Lee Bieber a écrit :
 On Thu, 14 Feb 2008 23:55:21 -0800 (PST), Brandon
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:
(snip)
 MT.fromkeys(NT[0], range(alpha,omega))
 
   Note that NT is a single tuple -- your previous loop throws away the
 prior value and binds a new tuple each time. AND IT IS A TUPLE = ('z',
 [0, 1, 2, 3]), NT[0] is just z -- it does not have keys to use in
 the fromkeys() method.

Note that the first arg to dict.fromkeys doesn't need to have a .keys 
method - you can pass in any iterable, and even a single hashable (in 
which case your ditc will only have one key, of course).

  dict.fromkeys('abc')
{'a': None, 'c': None, 'b': None}
  dict.fromkeys(c for c in 'abc')
{'a': None, 'c': None, 'b': None}
  dict.fromkeys((1,2,3))
{1: None, 2: None, 3: None}
  dict.fromkeys('a')
{'a': None}


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


How to increase the APR cache size?????

2008-02-15 Thread Manikandan R
Hai Friends,
 How can we increase the ARP cache size?
 For storing a single entry how many bytes will it takes?
 What is the default ARP cache size? (Plz mention you are
saying in bytes or in number of entries it can store)

Thank's and Regard's,
R.Manikandan.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: XML pickle

2008-02-15 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
 I cannot tell if the above approach will solve your problem or not.
 
 Well, declare me a persistent object.

Ok, from now on, you are a persistent object. :)


 from lxml import etree
 
 SS= '{urn:schemas-microsoft-com:office:spreadsheet}'
 book= etree.Element( 'Workbook' )
 book.set( 'xmlns', 'urn:schemas-microsoft-com:office:spreadsheet' )
 sheet= etree.SubElement(book, Worksheet)
 sheet.set( SS+ 'Name', 'WSheet1' )
 table= etree.SubElement(sheet, Table)
 row= etree.SubElement(table, Row)
 cell1= etree.SubElement(row, Cell)
 data1= etree.SubElement(cell1, Data )
 data1.set( SS+ 'Type', Number )
 data1.text= '123'
 cell2= etree.SubElement(row, Cell)
 data2= etree.SubElement(cell2, Data )
 data2.set( SS+ 'Type', String )
 data2.text= 'abc'
 out= etree.tostring( book, pretty_print= True, xml_declaration=True )
 print( out )
 open( 'xl.xml', 'w' ).write( out )

http://codespeak.net/lxml/tutorial.html#namespaces
http://codespeak.net/lxml/tutorial.html#the-e-factory
http://codespeak.net/lxml/objectify.html#tree-generation-with-the-e-factory


 Can you use set( '{ss}Type' ) somehow?

What is 'ss' here? A prefix?

What about actually reading the tutorial?

http://codespeak.net/lxml/tutorial.html#namespaces


 And any way to make this look
 closer to the original?

What's the difference you experience?

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


Re: dictionary of operators

2008-02-15 Thread Robert Bossy
A.T.Hofkamp wrote:
 On 2008-02-14, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   
 Hi,

 In the standard library module operator, it would be nice to have a 
 dictionary
 mapping operators strings with their respective functions. Something like:

   {
 '+': add,
 '-': sub,
 'in': contains,
 'and': and_,
 'or': or_,
 ...
   }

 Does such a dictionary already exist? Is it really a good and useful idea?
 

 How would you handle changes in operator syntax?
 - I have 'add' instead of '+'
 - I have U+2208 instead of 'in'
   
Originally I meant only the Python syntax which shouldn't change that 
much. For some operators (arith, comparison) the toy language had the 
same syntax as Python.
Btw,  U+2208 would be a wonderful token... if only it was on standard 
keyboards.

 I don't think this is generally applicable.
   
Thinking about it, I think it is not really applicable. Mainly because 
my examples were exclusively binary operators. What would be for unary 
operators? Or enclosing operators (getitem)?

 Why don't you attach the function to the +/-/in/... token instead? Then you
 don't need the above table at all.
   
Could be. But I prefer settling the semantic parts the furthest possible 
from the lexer. Not that I have strong arguments for that, it's religious.

Anyway, thanks for answering,
RB
-- 
http://mail.python.org/mailman/listinfo/python-list


Assignment saves time?

2008-02-15 Thread rpglover64
In timing my code, which I probably screwed up, I found something
curious:
given that li=range(1000),

the code block (enclosed in braces for clarification)
{
  size=len(li)
  size==1000
}
runs slightly faster than
{
  len(li)==1000
}

I tested this using the timeit module, and though the difference was
small, I would have expected the first code block to do slightly
worse, because it has to assign the length to a variable and then call
the variable (still having to compute the length and having either one
or two additional operations to perform).

I would appreciate it if more knowledgeable coders could
a) point out why I'm wrong and show me how to test it correctly. or
b) explain why this occurs in terminology understandable to someone
who knows next to nothing about the internal workings of python.

I highly appreciate your any response I may receive.  Thank you in
advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


newbie question: converting csv to another dialect

2008-02-15 Thread Albert-jan Roskam
Hi all,

I have a csv file with tab as a delimiter. I want to
convert it into one that is comma delimited. I changed
the regional settings on my computer to US. 

At first I thought I could use the CSV module for
this, by reading the csv file, registering the new
(desired = comma-delimited) dialect, and writing it.

Another option (which may be easier) I tried was:
f = open('d:/temp/myfile.csv', ' rw')
for row in f:
row.replace(\t,,)

Which is a start, but doesn't do the entire job. 
Could somebody help me with this please?

Thanks very much in advance!

Albert-Jan


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

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


Re: How to tell if I'm being run from a shell or a module

2008-02-15 Thread Sion Arrowsmith
Gabriel Genellina [EMAIL PROTECTED] wrote:
a) See if the __main__ module has a __file__ attribute.
b) See if sys.stdin is a real tty

c) See if sys.argv[0] != ''

(Although this works for the command line interactive shell, I've a
suspicion it will fail with IDLE. But I don't have IDLE to hand to
check.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   Frankly I have no feelings towards penguins one way or the other
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: newbie question: converting csv to another dialect

2008-02-15 Thread Chris
On Feb 15, 1:11 pm, Albert-jan Roskam [EMAIL PROTECTED] wrote:
 Hi all,

 I have a csv file with tab as a delimiter. I want to
 convert it into one that is comma delimited. I changed
 the regional settings on my computer to US.

 At first I thought I could use the CSV module for
 this, by reading the csv file, registering the new
 (desired = comma-delimited) dialect, and writing it.

 Another option (which may be easier) I tried was:
 f = open('d:/temp/myfile.csv', ' rw')
 for row in f:
 row.replace(\t,,)

 Which is a start, but doesn't do the entire job.
 Could somebody help me with this please?

 Thanks very much in advance!

 Albert-Jan

   
 
 Be a better friend, newshound, and
 know-it-all with Yahoo! Mobile.  Try it now.  
 http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

easiest way would be to split and then join imo

for line in input_file:
output_file.write(','.join(line.split('\t')) )

If you decide on quote encapsulated comma-delimeted, don't forget to
add additional quotes to the start and end of the line.
Also, if you open the file in OO Calc and you choose to resave it you
can choose the delimiter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assignment saves time?

2008-02-15 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes:

 I tested this using the timeit module, and though the difference was
 small, I would have expected the first code block to do slightly
 worse,

Can you post your entire benchmark, so that we can repeat it?  When I
tried the obvious, I got the expected result:

$ python -m timeit -s 'l=[]' 'len(l)==1000'
100 loops, best of 3: 0.256 usec per loop
$ python -m timeit -s 'l=[]' 'len(l)==1000'
100 loops, best of 3: 0.27 usec per loop

$ python -m timeit -s 'l=[]' 's=len(l); s==1000'
100 loops, best of 3: 0.287 usec per loop
$ python -m timeit -s 'l=[]' 's=len(l); s==1000'
100 loops, best of 3: 0.299 usec per loop
-- 
http://mail.python.org/mailman/listinfo/python-list


Regarding Python.h

2008-02-15 Thread Raj kumar
Hi to all,
I'm new to Python.
I am using python2.4.
I have one application written in c language in which it includes python like

#include Python.h

But when i try to install it, i'm getting an error like
Python.h: No such file or directory
I feel gcc is unable to get the path for Python.h
What should i do to get rid of this problem. If i have to add any path pls give 
me details of how to do that.
Thanks in advance.




  Chat on a cool, new interface. No download required. Go to 
http://in.messenger.yahoo.com/webmessengerpromo.php-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regarding Python.h

2008-02-15 Thread Christian Heimes
Raj kumar wrote:
 Hi to all,
 I'm new to Python.
 I am using python2.4.
 I have one application written in c language in which it includes python like
 
 #include Python.h
 
 But when i try to install it, i'm getting an error like
 Python.h: No such file or directory
 I feel gcc is unable to get the path for Python.h
 What should i do to get rid of this problem. If i have to add any path pls 
 give me details of how to do that.

Most distributions don't install the Python development files. You have
to install a package named python-devel or python2.4-dev.

Christian

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


Re: Is there a way to use .NET DLL from Python

2008-02-15 Thread Luis M. González
On Feb 14, 6:26 pm, Fuzzyman [EMAIL PROTECTED] wrote:
 On Feb 13, 6:58 pm, Luis M. González [EMAIL PROTECTED] wrote:



  On 13 feb, 00:26, Dino Viehland [EMAIL PROTECTED] wrote:

Oh, I know what you mean.
But that was exactly the reason for having a .DLLs folder, isn't it?
When you place an assembly into this folder, you avoid having to write
this boilerplate code, and simply import the assembly as you would
with a normal python module. At least, that´s how it worked in
previous versions...
   No. You have always had to add references to assemblies before being
   able to use the namespaces they contain. You even have to do this with
   C# in Visual Studio.

   This *should* work in bothIronPython1.x and IronPyton 2.0 - the catch 
   though is that it's implemented in the default site.py we ship with.  So 
   if you do the usual thing and use CPython's Lib directory you'll lose 
   this feature w/o copying it over.

  Sorry Dino, I don't understand...
  What does Cpython's Lib have to do with it?

 If you have the CPython standard library in your IRONPYTHONPATH, then
 when IronPython does it's normal 'import site' on startup the CPython
 one will be used instead of the default IronPython one...

 Michael Foordhttp://www.manning.com/foord

I see. Thank you!

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


Re: newbie question: converting csv to another dialect

2008-02-15 Thread Bruno Desthuilliers
Albert-jan Roskam a écrit :
 Hi all,
 
 I have a csv file with tab as a delimiter. I want to
 convert it into one that is comma delimited. I changed
 the regional settings on my computer to US. 
 
 At first I thought I could use the CSV module for
 this, by reading the csv file, registering the new
 (desired = comma-delimited) dialect, and writing it.

That's what I'd do indeed.

 Another option (which may be easier)

Hum... Depends on the effective csv dialect used. So-called csv files 
are not necessarily trivial to handle properly.

 I tried was:
 f = open('d:/temp/myfile.csv', ' rw')
 for row in f:
 row.replace(\t,,)


 Which is a start, but doesn't do the entire job. 

// without proper error handling
source = '/path/to/source.csv'
dest = source + '.new'

fin = open(source, 'r')
fout = open(dest, 'w')

for row in source:
   // let's hope there's no ',' anywhere in source...
   fout.write(row.replace(\t, ,))

fin.close()
fout.close()
os.rename(dest, source)

 Could somebody help me with this please?

yes : forget the above code and use the csv module.

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


Re: Assignment saves time?

2008-02-15 Thread cokofreedom
 $ python -m timeit -s 'l=[]' 'len(l)==1000'
 100 loops, best of 3: 0.256 usec per loop
 $ python -m timeit -s 'l=[]' 'len(l)==1000'
 100 loops, best of 3: 0.27 usec per loop

 $ python -m timeit -s 'l=[]' 's=len(l); s==1000'
 100 loops, best of 3: 0.287 usec per loop
 $ python -m timeit -s 'l=[]' 's=len(l); s==1000'
 100 loops, best of 3: 0.299 usec per loop

More results pretty much agree with yours:

C:\Python25python -m timeit -s 'l=range(1000)' 'len(l)==1000'
1000 loops, best of 3: 0.0235 usec per loop

C:\Python25python -m timeit -s 'l=range(1000)' 'len(l)==1000'
1000 loops, best of 3: 0.0245 usec per loop

C:\Python25python -m timeit -s 'l=range(1000)' 's=len(l)' 's==1000'
1000 loops, best of 3: 0.0383 usec per loop

C:\Python25python -m timeit -s 'l=range(1000)' 's=len(l)' 's==1000'
1000 loops, best of 3: 0.038 usec per loop
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: copying files through Python

2008-02-15 Thread [EMAIL PROTECTED]
On Feb 13, 10:50 pm, Lalit [EMAIL PROTECTED] wrote:

 I need to write a program which would transfer files under one folder
 structure (there are sub folders) to single folder.

troll

find /fromdir -exec mv {} /todir \; -print

/troll

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


Re: Error messages when using the Console Module

2008-02-15 Thread Christian Heimes
peter wrote:
 I am developing code using the effbot Console module, which gives
 control over the Windows terminal settings.  My problem is that while
 this module redirects standard output to a new console window, it
 seems to redirect standard error messages to a black hole.  So when my
 new code fails, I have no error messages to assist in diagnosing the
 problem.  At times I have been reduced to writing new code a line at a
 time!

Windows GUI apps don't have valid standard streams. stdin, stdout and
stderr aren't connected and their fileno is -1. I guess you have to
connect the streams manually when you create a console window. C code
can use freopen() but I don't know how to properly redirect the streams
from Python.

MSDN has probably some docs for you.

Christian

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


Error messages when using the Console Module

2008-02-15 Thread peter
I am developing code using the effbot Console module, which gives
control over the Windows terminal settings.  My problem is that while
this module redirects standard output to a new console window, it
seems to redirect standard error messages to a black hole.  So when my
new code fails, I have no error messages to assist in diagnosing the
problem.  At times I have been reduced to writing new code a line at a
time!

I'm sure there is an easy solution to this problem, but googling has
yet to reveal it.  Can anyone help?

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


Re: copying files through Python

2008-02-15 Thread James Matthews
Basically copying a file is reading a character or string from one file and
writing it to the other.

On Fri, Feb 15, 2008 at 3:06 PM, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:

 On Feb 13, 10:50 pm, Lalit [EMAIL PROTECTED] wrote:

  I need to write a program which would transfer files under one folder
  structure (there are sub folders) to single folder.

 troll

 find /fromdir -exec mv {} /todir \; -print

 /troll

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




-- 
http://search.goldwatches.com/?Search=Movado+Watches
http://www.jewelerslounge.com
http://www.goldwatches.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: RELEASED Python 2.5.2, release candidate 1

2008-02-15 Thread Luis M. González
On 14 feb, 22:39, Paul Rubin http://[EMAIL PROTECTED] wrote:
 I join everyone else in thanking Martin for his work on this whole
 effort.  This wording and naming thing is a trivial subtopic.

Thanks Martin and company for the good job!
By the way, I'm not a native speaker either and I understood perfectly
the meaning of your post.

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


Re: a question in python curses modules

2008-02-15 Thread Sion Arrowsmith
Marc 'BlackJack' Rintsch  [EMAIL PROTECTED] wrote:
When the interpreter shuts down it has to remove objects.  Everything you
need in a `__del__()` method must be referenced by that object to be sure
that it is still there and not already garbage collected.  *But* it's not
guaranteed that `__del__()` is called at all!

This may be true, but it's not really the point here, since clearly
__del__() *is* being called, otherwise how would the OP know that
curses was None in it?

What's relevant is the consequences of the first two sentences. As
the interpreter shuts down, it removes objects *and you don't know
what order it's going to do that in*. So what is happening here is
that first the curses module is being removed (and the name curses
bound to None instead), and then the CursesObject instance is
removed, which causes its __del__ to be called with curses == None.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   Frankly I have no feelings towards penguins one way or the other
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

PYTHON 2.4 PROGRAMMER NEEDED (Direct Client)

2008-02-15 Thread sarosh
Friends ,

I need a Python Developer

Please send resume with rate and contact details to
[EMAIL PROTECTED]




Duration : Long Term

Location: NYC

Interview : Immediately

Rate: open



Experience with:



Required Skills:



Python 2.4 or greater

Twisted Matrix 2.5

Object Oriented Programming

Threaded and Asynchronous Programming

Experience with XML-RPC

Must demonstrate knowledge and use of Design Patterns.



Secondary Skills:

Must have excellent verbal and written skills.

BS or better degree in Computer Science





Thanks  Regards

Sarosh Varghese
Infinity Tech Group
201 621 5802
201 490 5315
201 489 3500
201 489 2039 (fax)
Email - [EMAIL PROTECTED]
www.infigroup.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adding values to keys

2008-02-15 Thread Steve Holden
Dennis Lee Bieber wrote:
 On Thu, 14 Feb 2008 23:55:21 -0800 (PST), Brandon
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:
 
 Hi all,

 I'm not sure if I'm calling the right method in a dictionary.  I have:

 for k,v in dict.items():
 
   Don't call your dictionary dict -- that overloads the builtin
 function...
 
Allow me to pick a nit here: dict is a type, not a function (though as 
you clearly know, it's callable).

  NT = k,range(alpha,omega)#where alpha and omega are
 
   What are you doing with the v... If all you need is the key, then
 don't use the .items() method.
 
 previously defined as 1 and 4, respectively
  print NT

 which gives:
 ('w', [0,1,2,3])
 ('x', [0,1,2,3])
 ('y', [0,1,2,3])
 ('z', [0,1,2,3])

 And now I want a master dictionary like: [{'w': [0],[1],[2],[3]},

Do you want some variation on one of the following?

  dct = {
...   'w': something,
...   'z': something else,
...   'x': doesn't really matter,
...   'y': because the values aren't used
... }
  mylst = [ [k, [[x] for x in range(4)]] for k in dct]
  mylst
[['y', [[0], [1], [2], [3]]], ['x', [[0], [1], [2], [3]]], ['z', [[0], 
[1], [2], [3]]], ['w', [[0], [1], [2], [3
  from pprint import pprint
  pprint(tuple(mylst))
(['y', [[0], [1], [2], [3]]],
  ['x', [[0], [1], [2], [3]]],
  ['z', [[0], [1], [2], [3]]],
  ['w', [[0], [1], [2], [3]]])
  pprint(dict(mylst))
{'w': [[0], [1], [2], [3]],
  'x': [[0], [1], [2], [3]],
  'y': [[0], [1], [2], [3]],
  'z': [[0], [1], [2], [3]]}
 

   That is already impossible to achieve... you've specified four
 1-element lists without packaging them into either a list or tuple of
 their own.
 
 {'x': [0]...]

 So I try:

 MT = {}
 MT.fromkeys(NT[0], range(alpha,omega))
 
   Note that NT is a single tuple -- your previous loop throws away the
 prior value and binds a new tuple each time. AND IT IS A TUPLE = ('z',
 [0, 1, 2, 3]), NT[0] is just z -- it does not have keys to use in
 the fromkeys() method.
 
 print MT

 but this only returns:
 {}
 {}
 {}...

 Anybody see what I'm doing wrong?  Any advice is much appreciated.

Well, one of the things you are doing wring is failing to specify your 
problem fully, but that's pretty normal for people overwhelmed by trying 
to come to terms with early programming tasks: I assume you'll learn 
better in time :-)
 
   Show us code that can be executed -- even if it doesn't produce the
 results you expect -- as the snippets you gave can't be run as is...
 
 
 adict = { x : something,
 ...   y : else,
 ...   z : entirely}
 bdict = adict.fromkeys([y, x], range(3))
 print bdict
 {'y': [0, 1, 2], 'x': [0, 1, 2]}
 
   Note that you don't even need adict for that...
 
 bdict = {}.fromkeys([y, x], range(3))
 print bdict
 {'y': [0, 1, 2], 'x': [0, 1, 2]}
 
 cdict = {}.fromkeys(adict.keys(), Lookie Here!!!)
 print cdict
 {'y': 'Lookie Here!!!', 'x': 'Lookie Here!!!', 'z': 'Lookie Here!!!'}
 
   Do any of the above give any enlightenment?
 
trying-to-help-ly y'rs  - steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Turtle graphics speed(). Seems broken

2008-02-15 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
 I think the speed function may be broken from the turtle graphics
 package
 
 
 from turtle import *
 
 speed('fastest')
 
 forward(50)
 
 
 I have tried all of the different speed settings, but I get no change
 in the turtle's speed does anyone know how to fix this?

Use xturtle? :)

http://ada.rg16.asn-wien.ac.at/~python/xturtle/

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


RELEASED zif.sedna 0.9 beta2

2008-02-15 Thread Jim Washington

zif.sedna provides python access to the very cool XML database, Sedna, 
available at http://modis.ispras.ru/sedna/, under Apache 2.0 license.

It's not about kool-aid or sit-ups.  It's another option for storing, 
modifying, and retrieving hierarchical data.

zif.sedna is available from the Python Package Index.

zif.sedna provides a dbapi-like interface (connections and cursors).

zif.sedna provides a database adapter for Zope(3) and now has preliminary 
instructions for use with pylons.

Sedna is a product of the Sedna Team at the Institute for System 
Programming, Russian Academy of Sciences .

zif.sedna is just an adapter package.

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


Turtle graphics speed(). Seems broken

2008-02-15 Thread Alexander . Oot
I think the speed function may be broken from the turtle graphics
package


from turtle import *

speed('fastest')

forward(50)


I have tried all of the different speed settings, but I get no change
in the turtle's speed does anyone know how to fix this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Pop-up Menu of a Graphics Image?

2008-02-15 Thread W. Watson
Is there a library that contains a pop-up menu class from a mouse click on a 
graphics image?
-- 
  Wayne Watson (Nevada City, CA)

Web Page: speckledwithStars.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pop-up Menu of a Graphics Image?

2008-02-15 Thread Jon Fluffy Saul
On Fri, Feb 15, 2008 at 9:55 AM, W. Watson [EMAIL PROTECTED] wrote:
 Is there a library that contains a pop-up menu class from a mouse click on a
  graphics image?
  --
   Wayne Watson (Nevada City, CA)

 Web Page: speckledwithStars.net
  --
  http://mail.python.org/mailman/listinfo/python-list

What exactly do you mean by library that contains a pop-up menu class from a
mouse click on a graphics image
If I deciphered the sentence correctly, then TKinter, win32 and GTK API's can do
what you want.
Probably others too.

-- 
Push the envelope. Watch it bend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Solve a Debate

2008-02-15 Thread nexes
Alright so me and my friend are having argument.

Ok the problem we had been asked a while back, to do a programming
exercise (in college)
That would tell you how many days there are in a month given a
specific month.

Ok I did my like this (just pseudo):

If month = 1 or 3 or etc 
noDays = 31
Elseif month = 4 or 6 etc 
noDays = 30
Else
noDays = 29
(we didn't have to take into account a leap year)

He declared an array and assigned the number of days in a month to its
own element in an array. Now
I realise that in this example it would not make a difference in terms
of efficiency, but it is my belief that if
there is more data that needed to be assigned(i.e. a couple megs of
data) it would be simpler (and more efficient) to
do a compare rather then assigning all that data to an array, since
you are only going to be using 1 value and the rest
of the data in the array is useless.

What are everyone else's thoughts on this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Accessing Oracle/Access database py2.4

2008-02-15 Thread Ahmed, Shakir
I was used import odbc  to connect oracle or access table before, now I
switched to python 2.4 and is giving me error message. I appreciate any
help on that. 

 

Thanks

sh

 

 

 

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

Re: copying files through Python

2008-02-15 Thread Jeff Schwab
[EMAIL PROTECTED] wrote:
 On Feb 13, 10:50 pm, Lalit [EMAIL PROTECTED] wrote:
 
 I need to write a program which would transfer files under one folder
 structure (there are sub folders) to single folder.
 
 troll
 
 find /fromdir -exec mv {} /todir \; -print
 
 /troll

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


Re: Looking for a Python Program/Tool That Will Add Line Numbers to a txt File

2008-02-15 Thread Steve Holden
W. Watson wrote:
 Thanks. I found this to work:
 
 input_file=open('junkin.txt','r')
 output_file=open('junkout.txt','w')
 for (line_cnt, each_line) in enumerate(input_file):
  output_file.write('%4d '%(line_cnt+1)+each_line)

You can improve this slightly by using string formatting more fully:

 output_file.write(%4d %s % (line_ct+1, each_line))

 output_file.close()
 input_file.close()
 
regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: How do I execute a command from within python and wait on that command?

2008-02-15 Thread Rafael Sachetto
os.system(command)

or

proc = popen2.Popen3(command)
proc.wait()

2008/2/15, black_13 [EMAIL PROTECTED]:
 how do i exec a command (such as xcopy) from with win32 python and
  wait on that command
  to come to completion? and also cleanly terminate the command shell?
  thanks
  black_13

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



-- 
Rafael Sachetto Oliveira

Sir - Simple Image Resizer
http://rsachetto.googlepages.com
-- 
http://mail.python.org/mailman/listinfo/python-list


linux disc space

2008-02-15 Thread DataSmash
I simply want to capture the free disc space in a variable so that I
can compare changes.  I'm aware of a few commands like df -h or du -
k, but I can't figure out how to capture those values as a variable.
I also looked at os.statvfs(), but that output doesn't seem to make
any sense at all to me, knowing the size of the disc.
Thanks for your help!
R.D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to increase the APR cache size?????

2008-02-15 Thread Steve Holden
Manikandan R wrote:
 Hai Friends,
  How can we increase the ARP cache size?

Why do you want to? The answer is operating-system-specific anyway.

  For storing a single entry how many bytes will it takes?

The answer is operating-system-specific. Why is this important to you?

  What is the default ARP cache size? (Plz mention you 
 are saying in bytes or in number of entries it can store)
 
The answer is operating-system-specific.

 Thank's and Regard's,
 R.Manikandan.
 
I fail to see what this has to do with Python. Did I stumble into 
alt.random.questions by mistake?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Solve a Debate

2008-02-15 Thread Tim Chase
 Ok the problem we had been asked a while back, to do a programming
 exercise (in college)
 That would tell you how many days there are in a month given a
 specific month.
 
 Ok I did my like this (just pseudo):
 
 If month = 1 or 3 or etc 
 noDays = 31
 Elseif month = 4 or 6 etc 
 noDays = 30
 Else
 noDays = 29
 (we didn't have to take into account a leap year)
 
 He declared an array and assigned the number of days in a month to its
 own element in an array. Now
 I realise that in this example it would not make a difference in terms
 of efficiency, but it is my belief that if
 there is more data that needed to be assigned(i.e. a couple megs of
 data) it would be simpler (and more efficient) to
 do a compare rather then assigning all that data to an array, since
 you are only going to be using 1 value and the rest
 of the data in the array is useless.
 
 What are everyone else's thoughts on this?

Well, the standard library offers its opinion:

   import calendar
   calendar.mdays
  [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
   month = 2
   calendar.mdays[month]
  28

If you want the actual number of days, taking leap-years into
consideration

   calendar.monthrange(2008,2)[1]
  29
   calendar.monthrange(2007,2)[1]
  28

So the answer is mu...let Python do the work for you :)

-tkc




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


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Grant Edwards
On 2008-02-15, Mark Dickinson [EMAIL PROTECTED] wrote:

 If you're doing such serious number-crunching that you really
 want to handle NANs, you're probably not writing in Python
 anyway.

I disagree completely.  I do a lot of number crunching in
Python where I want IEEE NaN and Inf behavior.  Speed is a
completely orthogonal issue.

 If you're worried about speed, then I agree you probably
 shouldn't be writing in Python.

Even if you are worried about speed, using tools like like
numpy can do some pretty cool stuff.

 But I can imagine there are use-cases for nonstop arithmetic
 with nans and infs where speed isn't the topmost concern.

Frankly, I don't see that speed has anything to do with it at
all.  I use Python for number-crunching because it's easy to
program in.  When people complain about not getting the right
results, replying with if you want something fast, don't use
Python makes no sense.

-- 
Grant Edwards   grante Yow! I put aside my copy
  at   of BOWLING WORLD and
   visi.comthink about GUN CONTROL
   legislation...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Solve a Debate

2008-02-15 Thread Quentin Gallet-Gilles
If the data becomes much bigger, change your way of storing it, not the
code. You don't want to code hundreds of if - elif - else because you have
hundreds of different data, right ? TheDailyWTF is full of horror stories
like this, by the way ;-)
Data growth shouldn't result in modification in logic code.

Also I find that avoiding conditionals is always a win. That's in the spirit
of the pythonic way of removing what would be an if-elif chain (or a switch
statement in another language) by a dict-based dispatch.

Returning to your month exercise... Since code is data, assigning the
numbers of days or comparing the month number in if statements is basically
the same. In the end, you have twelve different values stored in one way or
another in your program and loaded in RAM at execution time.

Therefore, I find the array solution (or whatever storage you wish to use)
better by all counts.

Cheers,
Quentin

On Fri, Feb 15, 2008 at 5:24 PM, nexes [EMAIL PROTECTED] wrote:

 Alright so me and my friend are having argument.

 Ok the problem we had been asked a while back, to do a programming
 exercise (in college)
 That would tell you how many days there are in a month given a
 specific month.

 Ok I did my like this (just pseudo):

 If month = 1 or 3 or etc 
noDays = 31
 Elseif month = 4 or 6 etc 
noDays = 30
 Else
noDays = 29
 (we didn't have to take into account a leap year)

 He declared an array and assigned the number of days in a month to its
 own element in an array. Now
 I realise that in this example it would not make a difference in terms
 of efficiency, but it is my belief that if
 there is more data that needed to be assigned(i.e. a couple megs of
 data) it would be simpler (and more efficient) to
 do a compare rather then assigning all that data to an array, since
 you are only going to be using 1 value and the rest
 of the data in the array is useless.

 What are everyone else's thoughts on this?
 --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: How do I execute a command from within python and wait on that command?

2008-02-15 Thread Matt Nordhoff
Rafael Sachetto wrote:
 os.system(command)
 
 or
 
 proc = popen2.Popen3(command)
 proc.wait()

I don't know about cleanly terminat[ing] the command shell, but you
should use the subprocess module now, not any of the other functions
scattered around.
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating point bug?

2008-02-15 Thread Zentrader
I disagree with this statement
quoteBut that doesn't change the fact that it will expose the same
rounding-errors as floats do - just for different numbers. /quote
The example used has no rounding errors.  For anything less that 28
significant digits it rounds to 1.0.  With floats 1.0/3 yields
0.1-- on my machine.  Also you can compare two
decimal.Decimal() objects for equality.  With floats you have to test
for a difference less than some small value.  BTW, a college professor
who also wrote code for a living made this offhand remark In general
it is best to multiply first and then divide.  Good general advice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a Python Program/Tool That Will Add Line Numbers to a txt File

2008-02-15 Thread [EMAIL PROTECTED]
 See Subject. It's a simple txt file, each line is a Python stmt, but I need
 up to four digits added to each line with a space between the number field
 and the text. Perhaps someone has already done this or there's a source on
 the web for it. I'm not yet into files with Python. A sudden need has burst
 upon me. I'm using Win XP.

I'm not sure why you need the line numbers inserted into the file.
Alot of
editors will display and print line numbers.

My Visual Studio IDE displays file line numbers (it's an option) and
prints
them.  I believe there's a free Express Edition that you can download.

Also, check out http://www.textpad.com/ .  I think you can download an
evaluation copy.

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


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Steve Holden
Mark Dickinson wrote:
 On Feb 14, 11:09 pm, John Nagle [EMAIL PROTECTED] wrote:
  You also need to think about how conditionals interact with
 quiet NANs.  Properly, comparisons like  have three possibilities:
 
 True.  There was a recent change to Decimal to make comparisons (other
 than !=, ==) with NaNs do the right thing:  that is, raise a Python
 exception, unless the Invalid flag is not trapped, in which case they
 return False (and also raise the Invalid flag).  I imagine something
 similar would make sense for floats.
 
 True, False, and raise.  Many implementations don't do that well,
 which means that you lose trichotomy.  == has issues; properly,
 +INF is not equal to itself.
 
 I don't understand:  why would +INF not be equal to itself?  Having
 INF == INF be True seems like something that makes sense both
 mathematically and computationally.
  [...]

There are an uncountable number of infinities, all different.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: XML pickle

2008-02-15 Thread castironpi
On Feb 15, 12:07 pm, [EMAIL PROTECTED] wrote:
 On Feb 15, 11:10 am, [EMAIL PROTECTED] wrote:

Can you use set( '{ss}Type' ) somehow?

   What is 'ss' here? A prefix?

   What about actually reading the tutorial?

  http://codespeak.net/lxml/tutorial.html#namespaces

And any way to make this look
closer to the original?

   What's the difference you experience?

 Something else that crept up is:

 ?xml version='1.0' encoding='ASCII'?
 Workbook xmlns=[hugethingA]
   Worksheet xmlns:ns0=[hugethingA] ns0:name=WSheet1
   /Worksheet
   Styles
     Style xmlns:ns1=[hugethingA] ns1:ID=s21/
   /Styles
 /Workbook

 Which xmlns:ns1 gets redefined because I just didn't figure out how
 get xmlns:ns0 definition into the Workbook tag.  But too bad for me.

In Economics, they call it Economy to Scale- the effect, and the
point, and past it, where the cost to produce N goods on a supply
curve on which 0 goods costs 0 exceeds that on one on which 0 goods
costs more than 0: the opposite of diminishing returns.  Does the
benefit of encapsulating the specifics of the XML file, including the
practice, exceed the cost of it?

For an only slightly more complex result, the encapsulated version is
presented; and the hand-coded, unencapsulated one is left as an
exercise to the reader.

book= Workbook()
sheet= Worksheet( book, 'WSheet1' )
table= Table( sheet )
row= Row( table, index= '2' )
style= Style( book, bold= True )
celli= Cell( row, styleid= style )
datai= Data( celli, 'Number', '123' )
cellj= Cell( row )
dataj= Data( cellj, 'String', 'abc' )

46 lines of infrastructure, moderately packed.  Note that:

etree.XML( etree.tostring( book ) )

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


Re: What's the standard for code docs?

2008-02-15 Thread Torsten Bronger
Hallöchen!

Preston  Landers writes:

 [...]

 I've been using effbot's PythonDoc for a while, but it seems like
 the new standard (if there is one) is docutils and restructured
 text (ReST.)  Is that accurate?

In my opinion this is true.  And with Epydoc being the best tool for
generating documentation from the source code, Epydoc+reST is the
way to go.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML pickle

2008-02-15 Thread castironpi
  Can you use set( '{ss}Type' ) somehow?

 What is 'ss' here? A prefix?

 What about actually reading the tutorial?

 http://codespeak.net/lxml/tutorial.html#namespaces

  And any way to make this look
  closer to the original?

 What's the difference you experience?

Target:
?xml version=1.0?
?mso-application progid=Excel.Sheet?
Workbook
 xmlns=urn:schemas-microsoft-com:office:spreadsheet
 xmlns:ss=urn:schemas-microsoft-com:office:spreadsheet
 Worksheet ss:Name=Sheet1
  Table
   Row
CellData ss:Type=Stringabc/Data/Cell
CellData ss:Type=Number123/Data/Cell
   /Row
  /Table
 /Worksheet
/Workbook

It helped get me the working one, actually-- the tutorial.  'ss' is,
and I don't know the jargon for it, a local variable, or namespace
variable, prefix?, or something. xmlns:ss=urn:schemas-microsoft-
com:office:spreadsheet.  The ElementMaker example is closest, I
think, but it's working, so, ...

I'm more interested in a simplification of the construction code, and
at this point I can get goofy and brainstorm.  Ideas?




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


Re: Accessing Oracle/Access database py2.4

2008-02-15 Thread M.-A. Lemburg
On 2008-02-15 17:06, Ahmed, Shakir wrote:
 I was used import odbc  to connect oracle or access table before, now I
 switched to python 2.4 and is giving me error message. I appreciate any
 help on that. 

The win32 odbc module is very old and no longer maintained.

If you're looking for a reliable ODBC module, please have a
look at our mxODBC package for Python:

http://www.egenix.com/products/python/mxODBC/

Thanks,
-- 
Marc-Andre Lemburg
eGenix.com

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


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


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


Re: QOTW: Re: dream hardware

2008-02-15 Thread Jeff Schwab
[EMAIL PROTECTED] wrote:
 On Feb 14, 10:50 pm, [EMAIL PROTECTED] (Aahz) wrote:
 In article [EMAIL PROTECTED],
 Steven D'Aprano  [EMAIL PROTECTED] wrote:

 On Tue, 12 Feb 2008 10:05:59 -0800, castironpi wrote:
 What is dream hardware for the Python interpreter?
 I'm not sure that the Python interpreter actually does dream, but if it's
 anything like me, it's probably a giant computer the size of a bus, made
 out of broccoli and oven-roasted garlic, that suddenly turns into
 Sylvester Stallone in a tutu just before my program returns its result.
 IHNTA, IJWTSA
 
 IJWTW?  Anyone set up to profile CPython?... or step through?

I give up.  Is there a phrasebook somewhere, or do I need to hire an 
interpreter?

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


returning regex matches as lists

2008-02-15 Thread Jonathan Lukens
I am in the last phase of building a Django app based on something I
wrote in Java a while back.  Right now I am stuck on how to return the
matches of a regular expression as a list *at all*, and in particular
given that the regex has a number of groupings.  The only method I've
seen that returns a list is .findall(string), but then I get back the
groups as tuples, which is sort of a problem.

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


Re: What's the standard for code docs?

2008-02-15 Thread Jeff Schwab
Preston Landers wrote:
 Hey guys and gals.  What are all the cool kids using these days to
 document their code?  My goal is to create in-line documentation of
 each package/module/class/method and create some semi-nice looking (or
 at least usable) packaged documentation from it, in HTML and/or PDF
 format.
 
 I've been using effbot's PythonDoc for a while, but it seems like the
 new standard (if there is one) is docutils and restructured text
 (ReST.)  Is that accurate?
 
 Just from glancing at some samples of ReST the actual format looks
 much easier to work with in plain text in the text editor.
 PythonDoc has not been very popular with my team due to its HTML-ish
 nature and I think ReST will gain more acceptance.  Of course I don't
 want to bother making the jump from PythonDoc to docutils if that
 project is somehow a dead end.

Currently using doxygen.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: linux disc space

2008-02-15 Thread Chris
On Feb 15, 7:10 pm, DataSmash [EMAIL PROTECTED] wrote:
 I simply want to capture the free disc space in a variable so that I
 can compare changes.  I'm aware of a few commands like df -h or du -
 k, but I can't figure out how to capture those values as a variable.
 I also looked at os.statvfs(), but that output doesn't seem to make
 any sense at all to me, knowing the size of the disc.
 Thanks for your help!
 R.D.

import os, statvfs
s = os.statvfs(.)
freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAIL]

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


Re: linux disc space

2008-02-15 Thread DataSmash
On Feb 15, 1:32 pm, Jeff Schwab [EMAIL PROTECTED] wrote:
 Chris wrote:
  On Feb 15, 7:10 pm, DataSmash [EMAIL PROTECTED] wrote:
  I simply want to capture the free disc space in a variable so that I
  can compare changes.  I'm aware of a few commands like df -h or du -
  k, but I can't figure out how to capture those values as a variable.
  I also looked at os.statvfs(), but that output doesn't seem to make
  any sense at all to me, knowing the size of the disc.
  Thanks for your help!
  R.D.

  import os, statvfs
  s = os.statvfs(.)
  freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAIL]

 Is it worth distinguishing free bytes from available bytes?  I've never
 seen them differ, and I'm not sure how they ever would...

  import os
  import statvfs

  def free_bytes(path):
  stats = os.statvfs(path)
  return stats[statvfs.F_BSIZE] * stats[statvfs.F_BFREE]

  def avail_bytes(path):
  stats = os.statvfs(path)
  return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]

  if __name__ == '__main__':
  import sys
  for path in sys.argv[1:]:
  print %s: % path,
  print %dK free, % (free_bytes(path) / 1024),
  print %dK available % (avail_bytes(path) / 1024)


Chris,
Much thanks.  That's just what I need.

Jeff,
Not sure what's taking up the available space, but it's about 12GB
on my system.
Interesting.

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


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Carl Banks
On Feb 14, 11:09 pm, John Nagle [EMAIL PROTECTED] wrote:
  You also need to think about how conditionals interact with
 quiet NANs.  Properly, comparisons like  have three possibilities:
 True, False, and raise.  Many implementations don't do that well,
 which means that you lose trichotomy.  == has issues; properly,
 +INF is not equal to itself.

I'm pretty sure it is.  It certainly is on my machine at the moment:

 float(3e300*3e300) == float(2e300*4e300)
True

Are you confusing INF with NAN, which is specified to be not equal to
itself (and, IIRC, is the only thing specified to be not equal to
itself, such that one way to test for NAN is x!=x).


  For Python, I'd suggest throwing a Python exception on all errors
 recognized by the FPU, except maybe underflow.  If you're doing
 such serious number-crunching that you really want to handle NANs,
 you're probably not writing in Python anyway.

Even if that were entirely true, there are cases where (for example)
you're using Python to glue together numerical routines in C, but you
need to do some preliminary calculations in Python (where there's no
edit/compile/run cycle but there is slicing and array ops), but want
the same floating point behavior.

IEEE conformance is not an unreasonable thing to ask for, and you
should be using something else isn't a good answer to why not?.


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


Re: Pop-up Menu of a Graphics Image?

2008-02-15 Thread W. Watson
I want to allow a user who is looking at a graphic to be able to right-click 
on the graphic to produce a menu of choices.

Does the PIL have something, a class or whatever? What in Tkinter would be 
useful for this purpose? GTK?

Jon Fluffy Saul wrote:
 On Fri, Feb 15, 2008 at 9:55 AM, W. Watson [EMAIL PROTECTED] wrote:
 Is there a library that contains a pop-up menu class from a mouse click on a
  graphics image?
  --
   Wayne Watson (Nevada City, CA)

 Web Page: speckledwithStars.net
  --
  http://mail.python.org/mailman/listinfo/python-list

 What exactly do you mean by library that contains a pop-up menu class from a
 mouse click on a graphics image
 If I deciphered the sentence correctly, then TKinter, win32 and GTK API's can 
 do
 what you want.
 Probably others too.
 

-- 
  Wayne Watson (Nevada City, CA)

Web Page: speckledwithStars.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Jeff Schwab
Steve Holden wrote:
 Mark Dickinson wrote:
 On Feb 14, 11:09 pm, John Nagle [EMAIL PROTECTED] wrote:
  You also need to think about how conditionals interact with
 quiet NANs.  Properly, comparisons like  have three possibilities:

 True.  There was a recent change to Decimal to make comparisons (other
 than !=, ==) with NaNs do the right thing:  that is, raise a Python
 exception, unless the Invalid flag is not trapped, in which case they
 return False (and also raise the Invalid flag).  I imagine something
 similar would make sense for floats.

 True, False, and raise.  Many implementations don't do that well,
 which means that you lose trichotomy.  == has issues; properly,
 +INF is not equal to itself.

 I don't understand:  why would +INF not be equal to itself?  Having
 INF == INF be True seems like something that makes sense both
 mathematically and computationally.
  [...]
 
 There are an uncountable number of infinities, all different.

+ALEPH0?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: linux disc space

2008-02-15 Thread Jeff Schwab
Chris wrote:
 On Feb 15, 7:10 pm, DataSmash [EMAIL PROTECTED] wrote:
 I simply want to capture the free disc space in a variable so that I
 can compare changes.  I'm aware of a few commands like df -h or du -
 k, but I can't figure out how to capture those values as a variable.
 I also looked at os.statvfs(), but that output doesn't seem to make
 any sense at all to me, knowing the size of the disc.
 Thanks for your help!
 R.D.
 
 import os, statvfs
 s = os.statvfs(.)
 freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAIL]

Is it worth distinguishing free bytes from available bytes?  I've never 
seen them differ, and I'm not sure how they ever would...

 import os
 import statvfs

 def free_bytes(path):
 stats = os.statvfs(path)
 return stats[statvfs.F_BSIZE] * stats[statvfs.F_BFREE]

 def avail_bytes(path):
 stats = os.statvfs(path)
 return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]

 if __name__ == '__main__':
 import sys
 for path in sys.argv[1:]:
 print %s: % path,
 print %dK free, % (free_bytes(path) / 1024),
 print %dK available % (avail_bytes(path) / 1024)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mmap and shared memory

2008-02-15 Thread Ryan Smith-Roberts
On Feb 11, 3:41 pm, Matias Surdi [EMAIL PROTECTED] wrote:
 Suppose I've a process P1, which generates itself a lot of data , for
 example 2Mb.
 Then, I've a process P2 which must access P1 shared memory and,
 probably, modify this data.
 To accomplish this, I've been digging around python's mmap module, but I
 can't figure how to use it without files.

 Could anybody explain me how could this be accomplished? An example will
 be very appreciated. Thanks a lot for your help.

A non-portable solution, for modern Linux systems, is to create and
mmap a file in the /dev/shm directory.  This is a more unix-y
solution than the SysV SHM interface mentioned elsewhere in the
thread, since it gives you files you can cat, ls, chown, etc.  Files
created in this directory may hit swap, but don't consume normal disk
space.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML pickle

2008-02-15 Thread castironpi
 In Economics, they call it Economy to Scale- the effect, and the
 point, and past it, where the cost to produce N goods on a supply
 curve on which 0 goods costs 0 exceeds that on one on which 0 goods
 costs more than 0: the opposite of diminishing returns.  Does the
 benefit of encapsulating the specifics of the XML file, including the
 practice, exceed the cost of it?

And for all the management out there, yes.  As soon as possible does
mean as crappy as possible.  Extra is extra.  Assume the sooner the
crappier and the theorem follows.  (Now, corroborate the premise...)

P.S.  Gluttony is American too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: returning regex matches as lists

2008-02-15 Thread Jonathan Lukens
 What would you like to see instead?

I had mostly just expected that there was some method that would
return each entire match as an item on a list.  I have this pattern:

 import re
 corporate_names = 
 re.compile(u'(?u)\\b([А-Я]{2,}\\s+)([][а-яА-Я]+)(\\s*-?[а-яА-Я]+)*([])')
 terms = corporate_names.findall(sourcetext)

Which matches a specific way that Russian company names are
formatted.  I was expecting a method that would return this:

 terms
[u'string one', u'string two', u'string three']

...mostly because I was working it this way in Java and haven't
learned to do things the Python way yet.  At the suggestion from
someone on the list, I just used list() on all the tuples like so:

 detupled_terms = [list(term_tuple) for term_tuple in terms]
 delisted_terms = [''.join(term_list) for term_list in detupled_terms]

which achieves the desired result, but I am not a programmer and so I
would still be interested to know if there is a more elegant way of
doing this.

I appreciate the help.

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

Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 15, 2:35 pm, Steve Holden [EMAIL PROTECTED] wrote:
 There are an uncountable number of infinities, all different.

If you're talking about infinite cardinals or ordinals in set theory,
then yes.  But that hardly seems relevant to using floating-point as a
model for the doubly extended real line, which has exactly two
infinities.

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


Re: linux disc space

2008-02-15 Thread Matthew Woodcraft
In article [EMAIL PROTECTED],
Jeff Schwab  [EMAIL PROTECTED] wrote:
 Available space is how much you can actually access as a non-root user. 
   Apparently (thank you Jean-Paul), space can be reserved for superuser 
 use only; such space is free, but not available.

 I'm not sure how superuser-only space would be reserved in the first 
 place.  I don't see anything relevant in the fdisk man page.

Look at mkfs.whatever-your-filesystem-is

-M-

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


Re: linux disc space

2008-02-15 Thread Jean-Paul Calderone
On Fri, 15 Feb 2008 11:32:09 -0800, Jeff Schwab [EMAIL PROTECTED] wrote:
Chris wrote:
 On Feb 15, 7:10 pm, DataSmash [EMAIL PROTECTED] wrote:
 I simply want to capture the free disc space in a variable so that I
 can compare changes.  I'm aware of a few commands like df -h or du -
 k, but I can't figure out how to capture those values as a variable.
 I also looked at os.statvfs(), but that output doesn't seem to make
 any sense at all to me, knowing the size of the disc.
 Thanks for your help!
 R.D.

 import os, statvfs
 s = os.statvfs(.)
 freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAIL]

Is it worth distinguishing free bytes from available bytes?  I've never
seen them differ, and I'm not sure how they ever would...

 [snip]
 
/: 27723000K free, 15817232K available

It's common for some space to be reserved and only usable by the superuser.

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


Re: Help Parsing an HTML File

2008-02-15 Thread Mike Driscoll
On Feb 15, 3:28 pm, [EMAIL PROTECTED] wrote:
 Hello Python Community,

 It'd be great if someone could provide guidance or sample code for
 accomplishing the following:

 I have a single unicode file that has  descriptions of hundreds of
 objects. The file fairly resembles HTML-EXAMPLE pasted below.

 I need to parse the file in such a way to extract data out of the html
 and to come up with a tab separated file that would look like OUTPUT-
 FILE below.

 Any tips, advice and guidance is greatly appreciated.

 Thanks,

 Egon

 =OUTPUT-FILE=
 /please note that the first line of the file contains column headers/
 --Tab Separated Output File Begin--
 H1  H2  DIV Segment1Segment2Segment3
 RoséH1-1   RoséH2-1   RoséDIV-1  RoséSegmentDIV1-1  
 RoséSegmentDIV2-1
 RoséSegmentDIV3-1
 PinkH1-2PinkH2-2PinkDIV2-2  PinkSegmentDIV1-2   
 No-ValueNo-Value
 BlackH1-3   BlackH2-3   BlackDIV2-3 BlackSegmentDIV1-3  
 No-ValueNo-Value
 YellowH1-4  YellowH2-4  YellowDIV2-4YellowSegmentDIV1-4
 YellowSegmentDIV2-4 No-Value
 --Tab Separated Output File End--

 =HTML-EXAMPLE=
 --HTML Example Begin--
 html

 h1RoséH1-1/h1
 h2RoséH2-1/h2
 divRoséDIV-1/div
 div segment1RoséSegmentDIV1-1/divbr
 div segment2RoséSegmentDIV2-1/divbr
 div segment3RoséSegmentDIV3-1/divbr
 br
 br

 h1PinkH1-2/h1
 h2PinkH2-2/h2
 divPinkDIV2-2/div
 div segment1PinkSegmentDIV1-2/divbr
 br
 comment/comment

 h1BlackH1-3/h1
 h2BlackH2-3/h2
 divBlackDIV2-3/div
 div segment1BlackSegmentDIV1-3/divbr

 h1YellowH1-4/h1
 h2YellowH2-4/h2
 divYellowDIV2-4/div
 div segment1YellowSegmentDIV1-4/divbr
 div segment2YellowSegmentDIV2-4/divbr

 /html
 --HTML Example End--

Pyparsing, ElementTree and lxml are all good candidates as well.
BeautifulSoup takes care of malformed html though.

http://pyparsing.wikispaces.com/
http://effbot.org/zone/element-index.htm
http://codespeak.net/lxml/

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


RE: Solve a Debate

2008-02-15 Thread Reedick, Andrew
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:python-
 [EMAIL PROTECTED] On Behalf Of nexes
 Sent: Friday, February 15, 2008 11:25 AM
 To: python-list@python.org
 Subject: Solve a Debate
 
 Alright so me and my friend are having argument.
 
 Ok the problem we had been asked a while back, to do a programming
 
 He declared an array and assigned the number of days in a month to its
 own element in an array. Now
 I realise that in this example it would not make a difference in terms
 of efficiency, but it is my belief that if
 there is more data that needed to be assigned(i.e. a couple megs of
 data) it would be simpler (and more efficient) to
 do a compare rather then assigning all that data to an array, since
 you are only going to be using 1 value and the rest
 of the data in the array is useless.
 
 What are everyone else's thoughts on this?


Efficient how?  

Looking up the data in a array would probably be faster (look-up tables
normally are.)  

You could make the array efficient by using pointers, gaining both space
and time efficiency.  Mon[1] and mon[3] ... would point to 31.

The array can also just be collection of pointers to the multi-megabyte
objects on disk.  Most languages have modules letting you maintain an
index in memory that points to data on disk.

If the array is static or otherwise only loaded once into memory at
startup, and you have plenty of memory and patience, then who cares if
it is inefficient?  Simple solutions are normally faster to implement.
It's not often that you need to spend three days to save three seconds.

Then there's debug and change efficiency.  An array lookup is simple to
understand and thus less prone to bugs.  It can also be easier to change
a single array element than to change a complicated formula or a cluster
of nested if-then-else statements.



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA625


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


Re: Floating point bug?

2008-02-15 Thread Diez B. Roggisch
Zentrader schrieb:
 That's a misconception. The decimal-module has a different base (10
 instead of 2), and higher precision. But that doesn't change the fact
 that it will expose the same rounding-errors as floats do - just for
 different numbers.

   import decimal as d
   d = d.Decimal
   d(1) / d(3) * d(3)
 Decimal(0.)
 
 Surely you jest.  Your example is exact to 28 digits.  Your attempted
 trick is to use a number that never ends (1/3=0....).  It would
 only convert back to one if you have and infinite number of
 significant digits.  That has nothing to do with the Python decimal
 module (which does what it claims).  It is one of the idiosyncrasies
 of the base 10 number system.  Remember we are working with base 10
 decimals and not fractions.

The point is that all numbering systems with a base + precision will 
have (rational) values they can't exactly represent. Q\R is of course 
out of the question by definition

And the poster I replied to said


This is true.  Fortunately Python does provide a module which allows
you to work with exact floating point quantities.


Which is not more true for decimal as it is for IEEE754 floating points. 
Just for other values.

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


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 14, 11:09 pm, John Nagle [EMAIL PROTECTED] wrote:
  You also need to think about how conditionals interact with
 quiet NANs.  Properly, comparisons like  have three possibilities:

True.  There was a recent change to Decimal to make comparisons (other
than !=, ==) with NaNs do the right thing:  that is, raise a Python
exception, unless the Invalid flag is not trapped, in which case they
return False (and also raise the Invalid flag).  I imagine something
similar would make sense for floats.

 True, False, and raise.  Many implementations don't do that well,
 which means that you lose trichotomy.  == has issues; properly,
 +INF is not equal to itself.

I don't understand:  why would +INF not be equal to itself?  Having
INF == INF be True seems like something that makes sense both
mathematically and computationally.

  If you support quiet NANs, you need the predicates like isnan.

They're on their way!  math.isnan and math.isinf will be in Python
2.6.

 C++ exception using Microsoft's compilers.  But that's not portable.
 x86 has exact exceptions, but most other superscalar machines
 (PowerPC, Alpha, if anybody cares) do not.

Interesting.  What do you mean by 'exact exception'?

  For Python, I'd suggest throwing a Python exception on all errors
 recognized by the FPU, except maybe underflow.

Yes:  I think this should be the default behaviour, at least.  It was
agreed quite a while ago amongst the Python demigods that the IEEE
overflow, invalid and divide-by-zero signals should ideally raise
Python exceptions, while underflow and inexact should be ignored.  The
problem is that that's not what Python does at the moment, and some
people rely on being able to get NaNs and infinities the old ways.

 If you're doing
 such serious number-crunching that you really want to handle NANs,
 you're probably not writing in Python anyway.

If you're worried about speed, then I agree you probably shouldn't be
writing in Python.  But I can imagine there are use-cases for nonstop
arithmetic with nans and infs where speed isn't the topmost concern.

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


Re: Floating point bug?

2008-02-15 Thread Jeff Schwab
Zentrader wrote:
 I disagree with this statement
 quoteBut that doesn't change the fact that it will expose the same
 rounding-errors as floats do - just for different numbers. /quote
 The example used has no rounding errors.

I think we're using the term rounding error to mean different things. 
  If the value 1/3 is represented as a finite sequence of threes divided 
by a power of ten (e.g. 0.), then it is 
actually representing a different value than the original 1/3 
(/1).  This is 
what most of us mean by rounding error.  There are data types than can 
represent rational numbers exactly, such that 1 / 3 * 3 = 1.

 For anything less that 28
 significant digits it rounds to 1.0.

I'm not sure what you mean here.  Do you mean that Decimal can represent 
any sequence of up to 28 decimal digits without any loss in precision? 
No one disputes that.

 With floats 1.0/3 yields
 0.1-- on my machine.

Right, that is != 1/3.  But if the last digit were a 3, the number still 
would not be 1/3, only a different approximation of it.

  Also you can compare two
 decimal.Decimal() objects for equality.  With floats you have to test
 for a difference less than some small value.

A small margin of error (epsilon) is required for both Decimal and 
floats.  Both of these data types have floating points; they just use 
different radixes.  Particular sorts of rounding-errors have become 
acceptable in base-10 arithmetic within certain (mainly financial) 
contexts, so Decimal is preferable for calculations in those contexts. 
For the same reason, a major U.S. stock exchange switched from base-2 to 
base-10 arithmetic a few years ago.  There's nothing inherently more 
accurate about base-10.

 BTW, a college professor
 who also wrote code for a living made this offhand remark In general
 it is best to multiply first and then divide.  Good general advice.

It is best to keep track of how many significant digits remain in 
whatever base is being used.  M before D may help preserve sig. 
digits, but it is not a substitute for knowing how much error each 
calculation introduces.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Mark Dickinson
On Feb 15, 1:38 pm, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2008-02-15, Mark Dickinson [EMAIL PROTECTED] wrote:

  If you're doing such serious number-crunching that you really
  want to handle NANs, you're probably not writing in Python
  anyway.


Some dodgy quoting here: that wasn't me!

 I disagree completely.  I do a lot of number crunching in
 Python where I want IEEE NaN and Inf behavior.  Speed is a
 completely orthogonal issue.


Exactly.

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


Help Parsing an HTML File

2008-02-15 Thread egonslokar
Hello Python Community,

It'd be great if someone could provide guidance or sample code for
accomplishing the following:

I have a single unicode file that has  descriptions of hundreds of
objects. The file fairly resembles HTML-EXAMPLE pasted below.

I need to parse the file in such a way to extract data out of the html
and to come up with a tab separated file that would look like OUTPUT-
FILE below.

Any tips, advice and guidance is greatly appreciated.

Thanks,

Egon




=OUTPUT-FILE=
/please note that the first line of the file contains column headers/
--Tab Separated Output File Begin--
H1  H2  DIV Segment1Segment2Segment3
RoséH1-1RoséH2-1RoséDIV-1   RoséSegmentDIV1-1   
RoséSegmentDIV2-1
RoséSegmentDIV3-1
PinkH1-2PinkH2-2PinkDIV2-2  PinkSegmentDIV1-2   
No-ValueNo-Value
BlackH1-3   BlackH2-3   BlackDIV2-3 BlackSegmentDIV1-3  
No-ValueNo-Value
YellowH1-4  YellowH2-4  YellowDIV2-4YellowSegmentDIV1-4
YellowSegmentDIV2-4 No-Value
--Tab Separated Output File End--



=HTML-EXAMPLE=
--HTML Example Begin--
html

h1RoséH1-1/h1
h2RoséH2-1/h2
divRoséDIV-1/div
div segment1RoséSegmentDIV1-1/divbr
div segment2RoséSegmentDIV2-1/divbr
div segment3RoséSegmentDIV3-1/divbr
br
br

h1PinkH1-2/h1
h2PinkH2-2/h2
divPinkDIV2-2/div
div segment1PinkSegmentDIV1-2/divbr
br
comment/comment

h1BlackH1-3/h1
h2BlackH2-3/h2
divBlackDIV2-3/div
div segment1BlackSegmentDIV1-3/divbr

h1YellowH1-4/h1
h2YellowH2-4/h2
divYellowDIV2-4/div
div segment1YellowSegmentDIV1-4/divbr
div segment2YellowSegmentDIV2-4/divbr

/html
--HTML Example End--
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a question in python curses modules

2008-02-15 Thread Marc 'BlackJack' Rintsch
On Fri, 15 Feb 2008 15:10:12 +, Sion Arrowsmith wrote:

 Marc 'BlackJack' Rintsch  [EMAIL PROTECTED] wrote:
When the interpreter shuts down it has to remove objects.  Everything you
need in a `__del__()` method must be referenced by that object to be sure
that it is still there and not already garbage collected.  *But* it's not
guaranteed that `__del__()` is called at all!
 
 This may be true, but it's not really the point here, since clearly
 __del__() *is* being called, otherwise how would the OP know that
 curses was None in it?

It's not the point the OP asked for directly but just the answer in the
first two sentences might have left the impression it's okay to use
`__del__()` for this kind of clean up if you make sure that `curses` is
bound to the object.  Then it may appear to work for the OP but it's not
guaranteed to work under all circumstances.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QOTW: Re: dream hardware

2008-02-15 Thread castironpi
On Feb 14, 10:50 pm, [EMAIL PROTECTED] (Aahz) wrote:
 In article [EMAIL PROTECTED],
 Steven D'Aprano  [EMAIL PROTECTED] wrote:

 On Tue, 12 Feb 2008 10:05:59 -0800, castironpi wrote:

  What is dream hardware for the Python interpreter?

 I'm not sure that the Python interpreter actually does dream, but if it's
 anything like me, it's probably a giant computer the size of a bus, made
 out of broccoli and oven-roasted garlic, that suddenly turns into
 Sylvester Stallone in a tutu just before my program returns its result.

 IHNTA, IJWTSA

IJWTW?  Anyone set up to profile CPython?... or step through?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating point bug?

2008-02-15 Thread Mark Dickinson
On Feb 15, 3:30 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 The point is that all numbering systems with a base + precision will
 have (rational) values they can't exactly represent. Q\R is of course
 out of the question by definition

This 'Decimal is exact' myth has been appearing often enough that I
wonder whether it's worth devoting a prominent paragraph to in the
docs.

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


How do I execute a command from within python and wait on that command?

2008-02-15 Thread black_13
how do i exec a command (such as xcopy) from with win32 python and
wait on that command
to come to completion? and also cleanly terminate the command shell?
thanks
black_13
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: linux disc space

2008-02-15 Thread Steve Holden
Jeff Schwab wrote:
 I'm not sure how superuser-only space would be reserved in the first 
 place.  I don't see anything relevant in the fdisk man page.

The UFS and ext2 filesystem space allocation routines become very 
inefficient when free space gets too low, so for regular uses the 
filesystem is considered full before that threshold is reached. You can 
adjust the threshold setting (amon others) with tunefs.

Root uid processes can continue to use disk space after that point so 
that various daemon processes don't stop, and so that recovery actions 
can be taken.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Looking for a Python Program/Tool That Will Add Line Numbers to a txt File

2008-02-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 See Subject. It's a simple txt file, each line is a Python stmt, but I need
 up to four digits added to each line with a space between the number field
 and the text. Perhaps someone has already done this or there's a source on
 the web for it. I'm not yet into files with Python. A sudden need has burst
 upon me. I'm using Win XP.
 
 I'm not sure why you need the line numbers inserted into the file.
 Alot of
 editors will display and print line numbers.
 
Perhaps so, but I had to insert line numbers into the code examples in 
Python Web Programming, for example, because I annotated the code 
using the line numbers and I wasn't about to allow the publishers the 
chance to screw them up.

 My Visual Studio IDE displays file line numbers (it's an option) and
 prints
 them.  I believe there's a free Express Edition that you can download.
 
 Also, check out http://www.textpad.com/ .  I think you can download an
 evaluation copy.
 
None of which would have answered by use case. Besides which, maybe the 
OP was just writing a test piece ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Solve a Debate

2008-02-15 Thread Grant Edwards
On 2008-02-15, Ivan Van Laningham [EMAIL PROTECTED] wrote:

 Lookup tables are always significantly faster than a bunch of
 ifs.

Mostly always.  It depends on what you mean by lookup table,
and it depends on how the language implements things.  If you
by lookup table you mean a linearly indexed array, then an
array lookup is O(1), and a series of if/then/elses is O(n).
The indexing operation is going to be faster for all practical
examples I can think of.

If by lookup table you mean an arbitrary mapping (e.g. a
dict in Python), then it depends on the hashing/searching
used to implement the lookup operation. It's possible for small
mappings using some types of keys that a series of compares
could be faster than the hashing operation.

In the general case, if the key being used consists of a lot of
bits, you might have to hash all of the bits before you can
start looking up the result. When doing compares, you can quite
after the first bit doesn't match.  IOW, you might be able to
do a lot of failed key compares in the time it takes to hash
the key.

-- 
Grant Edwards   grante Yow! Can you MAIL a BEAN
  at   CAKE?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML pickle

2008-02-15 Thread castironpi
On Feb 15, 11:10 am, [EMAIL PROTECTED] wrote:
   Can you use set( '{ss}Type' ) somehow?

  What is 'ss' here? A prefix?

  What about actually reading the tutorial?

 http://codespeak.net/lxml/tutorial.html#namespaces

   And any way to make this look
   closer to the original?

  What's the difference you experience?

Something else that crept up is:

?xml version='1.0' encoding='ASCII'?
Workbook xmlns=[hugethingA]
  Worksheet xmlns:ns0=[hugethingA] ns0:name=WSheet1
  /Worksheet
  Styles
Style xmlns:ns1=[hugethingA] ns1:ID=s21/
  /Styles
/Workbook

Which xmlns:ns1 gets redefined because I just didn't figure out how
get xmlns:ns0 definition into the Workbook tag.  But too bad for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


sockets -- basic udp client

2008-02-15 Thread 7stud
My question pertains to this example:

#!/usr/bin/env python

import socket, sys, time

host = sys.argv[1]
textport = sys.argv[2]

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
port = int(textport)
except ValueError:
# That didn't work.  Look it up instread.
port = socket.getservbyname(textport, 'udp')

s.connect((host, port))
print Enter data to transmit: 
data = sys.stdin.readline().strip()
s.sendall(data)
s.shutdown(1)
print Looking for replies; press Ctrl-C or Ctrl-Break to stop.
while 1:
buf = s.recv(2048)
if not len(buf):
break
print Received: %s % buf


As far as I can tell, the if statement:

if not len(buf):
   break

does nothing.  Either recv() is going to read some data or it's going
to block.   My understanding is that udp sockets do not have a
connection, so the server can't close the connection--hich would cause
a blank string to be sent to the client.

So, as far as I can tell, the only way that code would make sense is
if the server were programmed to send a blank string to the client
after it sent data to the client.  Is that correct?
-- 
http://mail.python.org/mailman/listinfo/python-list


What's the standard for code docs?

2008-02-15 Thread Preston Landers
Hey guys and gals.  What are all the cool kids using these days to
document their code?  My goal is to create in-line documentation of
each package/module/class/method and create some semi-nice looking (or
at least usable) packaged documentation from it, in HTML and/or PDF
format.

I've been using effbot's PythonDoc for a while, but it seems like the
new standard (if there is one) is docutils and restructured text
(ReST.)  Is that accurate?

Just from glancing at some samples of ReST the actual format looks
much easier to work with in plain text in the text editor.
PythonDoc has not been very popular with my team due to its HTML-ish
nature and I think ReST will gain more acceptance.  Of course I don't
want to bother making the jump from PythonDoc to docutils if that
project is somehow a dead end.

thanks for any info or advice you can provide.

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


Re: Accessing Oracle/Access database py2.4

2008-02-15 Thread Steve Holden
Ahmed, Shakir wrote:
 I was used import odbc  to connect oracle or access table before, now I 
 switched to python 2.4 and is giving me error message. I appreciate any 
 help on that.
 
So this error message is a secret?

One possibility is that you are trying to use a 2.3 extension module 
with 2.4 - that would give you problems.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Solve a Debate

2008-02-15 Thread Ivan Van Laningham
Hi All--
Lookup tables are always significantly faster than a bunch of ifs.

Metta,
Ivan

On Fri, Feb 15, 2008 at 10:10 AM, Tim Chase
[EMAIL PROTECTED] wrote:
  Ok the problem we had been asked a while back, to do a programming
   exercise (in college)
   That would tell you how many days there are in a month given a
   specific month.
  
   Ok I did my like this (just pseudo):
  
   If month = 1 or 3 or etc 
   noDays = 31
   Elseif month = 4 or 6 etc 
   noDays = 30
   Else
   noDays = 29
   (we didn't have to take into account a leap year)
  
   He declared an array and assigned the number of days in a month to its
   own element in an array. Now
   I realise that in this example it would not make a difference in terms
   of efficiency, but it is my belief that if
   there is more data that needed to be assigned(i.e. a couple megs of
   data) it would be simpler (and more efficient) to
   do a compare rather then assigning all that data to an array, since
   you are only going to be using 1 value and the rest
   of the data in the array is useless.
  
   What are everyone else's thoughts on this?

  Well, the standard library offers its opinion:

import calendar
calendar.mdays
   [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month = 2
calendar.mdays[month]
   28

  If you want the actual number of days, taking leap-years into
  consideration

calendar.monthrange(2008,2)[1]
   29
calendar.monthrange(2007,2)[1]
   28

  So the answer is mu...let Python do the work for you :)

  -tkc






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




-- 
Ivan Van Laningham
God N Locomotive Works
http://www.pauahtun.org/
http://www.python.org/workshops/1998-11/proceedings/papers/laningham/laningham.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


scary thought for consideration

2008-02-15 Thread Blubaugh, David A.
To All,


I am wondering as far as the integration of MyHDL with Python 2.5, if
there might be any potential version incompatibility issues?  What I
mean is will MyHDL not operate correctly, if it is executed with a
Python 2.5 version not a Python 2.4? I will be testing to see if this
possibility is indeed true over the weekend.  


Thanks,

David Blubaugh

This e-mail transmission contains information that is confidential and may be 
privileged.   It is intended only for the addressee(s) named above. If you 
receive this e-mail in error, please do not read, copy or disseminate it in any 
manner. If you are not the intended recipient, any disclosure, copying, 
distribution or use of the contents of this information is prohibited. Please 
reply to the message immediately by informing the sender that the message was 
misdirected. After replying, please erase it from your computer system. Your 
assistance in correcting this error is appreciated.


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

Re: linux disc space

2008-02-15 Thread Jeff Schwab
Christian Heimes wrote:
 Jeff Schwab wrote:
 I'm not sure how superuser-only space would be reserved in the first 
 place.  I don't see anything relevant in the fdisk man page.
 
 man mkfs
 
 :)

Thank you.

Looks like the feature is only supported by particular file systems.  I 
don't see anything at mkfs(8), but I do (for example) see the -m flag at 
mke2fs(8).

What I've done in the past is to make the boot partition big enough for 
emergency, super-user system administration.  In the default boot 
configuration, I just don't mount /boot.  When the other partitions get 
filled up by some runaway process (which happens with surprising (to me) 
frequency), I mount the boot partition so I have some breathing room.  I 
guess the formally reserved blocks in the filesystem are meant to serve 
the same purpose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Grant Edwards
On 2008-02-15, Mark Dickinson [EMAIL PROTECTED] wrote:
 On Feb 15, 1:38 pm, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2008-02-15, Mark Dickinson [EMAIL PROTECTED] wrote:

  If you're doing such serious number-crunching that you really
  want to handle NANs, you're probably not writing in Python
  anyway.

 Some dodgy quoting here: that wasn't me!

Yup.  That's indicated by the xtra level of .  Sorry if that
mislead anybody -- I accidentally deleted the nested attribute
line when I was trimming things.

 I disagree completely.  I do a lot of number crunching in
 Python where I want IEEE NaN and Inf behavior.  Speed is a
 completely orthogonal issue.

 Exactly.

-- 
Grant Edwards   grante Yow! I know how to do
  at   SPECIAL EFFECTS!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML pickle

2008-02-15 Thread castironpi
On Feb 15, 2:58 pm, [EMAIL PROTECTED] wrote:
  In Economics, they call it Economy to Scale- the effect, and the
  point, and past it, where the cost to produce N goods on a supply
  curve on which 0 goods costs 0 exceeds that on one on which 0 goods
  costs more than 0: the opposite of diminishing returns.  Does the
  benefit of encapsulating the specifics of the XML file, including the
  practice, exceed the cost of it?

 And for all the management out there, yes.  As soon as possible does
 mean as crappy as possible.  Extra is extra.  Assume the sooner the
 crappier and the theorem follows.  (Now, corroborate the premise...)

The sooner the crappier or the parties waste time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assignment saves time?

2008-02-15 Thread rpglover64
I ran it in an interactive python shell, which might have made a
difference.

import timeit
time1=timeit.Timer('s=len(li); s==1000', 'li=range(1000)')
time2=timeit.Timer('len(li)==1000', 'li=range(1000)')
store=min(time1.repeat(5))
call=min(time2.repeat(5))
store=min(min(time1.repeat(5)),store)
call=min(min(time2.repeat(5)),call)
store
  0.25531911849975586
call
  0.25700902938842773

The difference is small enough to be insignificant, but I am curious
how it's possible and why it happened.  It's more likely a reflection
of how I timed it than anything else, isn't it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assignment saves time?

2008-02-15 Thread rpglover64
I ran it in an interactive python shell, which might have made a
difference.

import timeit
time1=timeit.Timer('s=len(li); s==1000', 'li=range(1000)')
time2=timeit.Timer('len(li)==1000', 'li=range(1000)')
store=min(time1.repeat(5))
call=min(time2.repeat(5))
store=min(min(time1.repeat(5)),store)
call=min(min(time2.repeat(5)),call)
store
  0.25531911849975586
call
  0.25700902938842773

The difference is small enough to be insignificant, but I am curious
how it's possible and why it happened.  It's more likely a reflection
of how I timed it than anything else, isn't it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email Directly from python

2008-02-15 Thread Daniel Folkes
You could always just set up a gmail account and use that SMTP.  Thats
what I do.  Then all you have to do is google search for gmail smtp
python and get some easy code.

You can even send attatchments really easy.

-Daniel Folkes

brad wrote:
 I'd like to send email directly from within python without having to
 rely on an external smtp server. You know, something like the good, old
 Unix...

 echo My_message | mail -s Subject [EMAIL PROTECTED]

 Can Python do something similar in a portable fashion without a smtp
 server installed on the machine?

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


Re: Looking for a Python Program/Tool That Will Add Line Numbers to a txt File

2008-02-15 Thread Jeff Schwab
W. Watson wrote:
 See Subject. It's a simple txt file, each line is a Python stmt, but I 
 need up to four digits added to each line with a space between the 
 number field and the text. Perhaps someone has already done this or 
 there's a source on the web for it. I'm not yet into files with Python. 
 A sudden need has burst upon me. I'm using Win XP.

i = 0
for line in sys.stdin:
 i += 1
 print i, line,

Or if you want consistent alignment:

i = 0
for line in sys.stdin:
 i += 1
 print %4s % i, line,


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


Re: linux disc space

2008-02-15 Thread Christian Heimes
Jeff Schwab wrote:
 I'm not sure how superuser-only space would be reserved in the first 
 place.  I don't see anything relevant in the fdisk man page.

man mkfs

:)

Christian

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


Re: linux disc space

2008-02-15 Thread Jeff Schwab
DataSmash wrote:
 On Feb 15, 1:32 pm, Jeff Schwab [EMAIL PROTECTED] wrote:
 Chris wrote:
 On Feb 15, 7:10 pm, DataSmash [EMAIL PROTECTED] wrote:
 I simply want to capture the free disc space in a variable so that I
 can compare changes.  I'm aware of a few commands like df -h or du -
 k, but I can't figure out how to capture those values as a variable.
 I also looked at os.statvfs(), but that output doesn't seem to make
 any sense at all to me, knowing the size of the disc.
 Thanks for your help!
 R.D.
 import os, statvfs
 s = os.statvfs(.)
 freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAIL]
 Is it worth distinguishing free bytes from available bytes?  I've never
 seen them differ, and I'm not sure how they ever would...

  import os
  import statvfs

  def free_bytes(path):
  stats = os.statvfs(path)
  return stats[statvfs.F_BSIZE] * stats[statvfs.F_BFREE]

  def avail_bytes(path):
  stats = os.statvfs(path)
  return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]

  if __name__ == '__main__':
  import sys
  for path in sys.argv[1:]:
  print %s: % path,
  print %dK free, % (free_bytes(path) / 1024),
  print %dK available % (avail_bytes(path) / 1024)
 
 
 Chris,
 Much thanks.  That's just what I need.
 
 Jeff,
 Not sure what's taking up the available space, but it's about 12GB
 on my system.
 Interesting.

Available space is how much you can actually access as a non-root user. 
  Apparently (thank you Jean-Paul), space can be reserved for superuser 
use only; such space is free, but not available.

I'm not sure how superuser-only space would be reserved in the first 
place.  I don't see anything relevant in the fdisk man page.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scary thought for consideration

2008-02-15 Thread Guilherme Polo
2008/2/15, Blubaugh, David A. [EMAIL PROTECTED]:



 To All,


 I am wondering as far as the integration of MyHDL with Python 2.5, if there
 might be any potential version incompatibility issues?  What I mean is will
 MyHDL not operate correctly, if it is executed with a Python 2.5 version not
 a Python 2.4? I will be testing to see if this possibility is indeed true
 over the weekend.


That depends on how custom your project is. Take Zope for example, a
lot of effort is being done to make it run under python 2.5.

Having a good test suite ready would be a good way to determine if it
runs correctly under python 2.5.


 Thanks,

 David Blubaugh

 This e-mail transmission contains information that is confidential and may
 be privileged.   It is intended only for the addressee(s) named above. If
 you receive this e-mail in error, please do not read, copy or disseminate it
 in any manner. If you are not the intended recipient, any disclosure,
 copying, distribution or use of the contents of this information is
 prohibited. Please reply to the message immediately by informing the sender
 that the message was misdirected. After replying, please erase it from your
 computer system. Your assistance in correcting this error is appreciated.

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



-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn off ZeroDivisionError?

2008-02-15 Thread Grant Edwards
On 2008-02-15, Carl Banks [EMAIL PROTECTED] wrote:

 For Python, I'd suggest throwing a Python exception on all
 errors recognized by the FPU, except maybe underflow.  If
 you're doing such serious number-crunching that you really
 want to handle NANs, you're probably not writing in Python
 anyway.

 Even if that were entirely true, there are cases where (for
 example) you're using Python to glue together numerical
 routines in C, but you need to do some preliminary
 calculations in Python (where there's no edit/compile/run
 cycle but there is slicing and array ops), but want the same
 floating point behavior.

Or when you're verifying/testing algorithms implemented on
another platform that follows the IEEE standard.

Or when propagating quiet NaNs and Infinities is by far the
simplest way to do what needs to be done.  Being able to feed
NaN values into a set of calculations and have outputs
dependant on invalid inputs turn out to be NaNs is just _so_
much simpler than either

 1) Having a complete set of boolean logic code in parallel to
the calculations that keeps track of what's valid and
what's not.

 2) Writing a floating point class with some sort of valid
flag that travels along with the values.

 IEEE conformance is not an unreasonable thing to ask for,

Especially when the hardware already provides it (or at least
provides something close enough to satisfy most of us who
whinge about such things).

 and you should be using something else isn't a good answer
 to why not?.

even for Usenet. ;)

-- 
Grant Edwards   grante Yow! A shapely CATHOLIC
  at   SCHOOLGIRL is FIDGETING
   visi.cominside my costume..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Looking for a Python Program/Tool That Will Add Line Numbers to a txt File

2008-02-15 Thread Steve Holden
I'll see your IBM 650 and raise you a Univac 418 with a FastRand drum.

regards
  Steve

W. Watson wrote:
 Good grief! You go a long way back. Want to try for an IBM 650 with a drum 
 memory?
 
 Gabriel Genellina wrote:
 En Thu, 14 Feb 2008 04:54:56 -0200, W. Watson [EMAIL PROTECTED] 
 escribió:

 See Subject. It's a simple txt file, each line is a Python stmt, but I 
 need
 up to four digits added to each line with a space between the number 
 field
 and the text. Perhaps someone has already done this or there's a 
 source on
 the web for it. I'm not yet into files with Python. A sudden need has 
 burst
 upon me. I'm using Win XP.
 This command should suffice - but you must first find a working CP/M 
 system to use it:

 CPIP [N] NEW.PY=OLD.PY

 (Sorry - just a a nostalgic flash!)

 


-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


  1   2   >