Precision for equality of two floats?

2005-11-28 Thread Anton81
Hi!

When I do simple calculation with float values, they are rarely exactly
equal even if they should be. What is the threshold and how can I change
it?

e.g. "if f1==f2:" will always mean "if abs(f1-f2)<1e-6:"

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


Extracting documentation for user relevant functions only?

2005-11-28 Thread Anton81
Hi,

I've written a python script and added short docstrings. Now I'd like to
create a short overview of commands the user can use. However I don't want
the internal stuff that I also commented. Is there a way to create a fancy
documentation (e.g. pydoc) of certain functions only?

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


Escape sequences (colour) and padding with "%8s"%

2006-08-09 Thread Anton81
Hi all!

I used escape sequences to produce colour output, but a construct like

print "%8s" % str_with_escape

doesn't do the right thing. I suppose the padding counts the escape
characters, too.

What could be a solution?

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


Re: Escape sequences (colour) and padding with "%8s"%

2006-08-10 Thread Anton81
For example:

print '%8s' % '\x1b[34mTEST\x1b[0m'

doesn't not indent 'TEST' whereas

print '%8s' % TEST'

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


Re: Escape sequences (colour) and padding with "%8s"%

2006-08-10 Thread Anton81
> If you insist on building the codes yourself instead of using the
> standard curses library...
> 
> print '\x1b[34m%8s\x1b[0m' % 'TEST'

Will the curses library help? The problem is I need the colour coded in my
string and the "print pattern" is static.

What's the quickest way to solve this without having special print routines,
that handle "colour string objects"?

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


self=pickle.load(file)? (Object loads itself)

2006-08-12 Thread Anton81
Hi!

it seems that

class Obj:
def __init__(self):
f=file("obj.dat")
self=pickle.load(f)
...

doesn't work. Can an object load itself with pickle from a file somehow?
What's an easy solution?

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


__div__ not recognized automatically

2006-11-02 Thread Anton81
Hello!

I wrote a class

class NumX:
  ...
  def __add__(self,other):
...
  def __div__(self,other):
if not isinstance(other,NumX): other=NumX(other)
...

Somewhere else I use

a=(b+c)/2

where all variables are of NumX Type. When I execute the program it
complains that it can't find an operator "/" for "instance" and "integer".
However if I use pdb the same command works when started on the prompt. Also
the manual execution

a=(b+c).__div__(2)

works. Any suggestions what goes wrong?

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


Re: __div__ not recognized automatically

2006-11-07 Thread Anton81
> If you have the
> 
> from __future__ import division
> 
> statement, you need to override __truediv__(), not __div__()

That worked after I also added
from __future__ import division
to all other modules I created.

Is it possible that there appears an inconsistency if the division is
imported in only some of the modules?

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


Weird import problem

2008-05-04 Thread Anton81
I have a directory structure like

NS/dir1/file1.py
NS/dir2/file2.py

if in the python shell I type

import NS.dir1.file1

it works, however typing

import NS.dir2.file2

fails with

ImportError: No module named dir2.file2

Any ideas what could go wrong?
Directory permissions seem to be OK.

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


Re: Weird import problem

2008-05-05 Thread Anton81
>> NS/dir1/file1.py
>> NS/dir2/file2.py
> This *must* be wrong or at least not the full directory listing - please
> read
It is the directory structure in one of the python paths.

> Missing __init__.py in the dir2?
Oh right. I forgot about this. Thank you!
--
http://mail.python.org/mailman/listinfo/python-list


Inter-module globals

2006-03-09 Thread Anton81
Hi,

I want to use globals that are immediately visible in all modules. My
attempts to use "global" haven't worked. Suggestions?

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


Connecting to gnuplot with Popen?

2006-03-30 Thread Anton81
Hi,

it seems to be a FAQ, but I still haven't found a solution. I want to
control gnuplot with a python program. The following at least gives me the
gnuplot output:

subp=Popen("gnuplot",stdin=None,stderr=PIPE,stdout=PIPE)
...
subp.stderr.readline()

even though I'm not sure how to check if no more lines can be read with
readline() so that it doesn't block.
But after the script has finished, the console doesn't show me the
characters I type.

However, as soon as I try:

subp=Popen("gnuplot",stdin=PIPE,stderr=PIPE,stdout=PIPE)
...
subp.stderr.readline()

the program hangs.

What's wrong?

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


Re: Connecting to gnuplot with Popen?

2006-03-31 Thread Anton81
> Hi Anton,
> 
> here is a little snippet using os.popen:

Unfortunately I'm having more problem getting the output from Gnuplot, which
I'd like to examine for error messages and settings of options.

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


Re: Float precision and float equality

2009-12-06 Thread Anton81
I do some linear algebra and whenever the prefactor of a vector turns
out to be zero, I want to remove it.

I'd like to keep the system comfortable. So basically I should write a
new class for numbers that has it's own __eq__ operator?
Is there an existing module for that?

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