Re: RE Module Performance

2013-07-25 Thread Jeremy Sanders
[email protected] wrote:

> Short example. Writing an editor with something like the
> FSR is simply impossible (properly).

http://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Representations.html#Text-Representations

"To conserve memory, Emacs does not hold fixed-length 22-bit numbers that are 
codepoints of text characters within buffers and strings. Rather, Emacs uses a 
variable-length internal representation of characters, that stores each 
character as a sequence of 1 to 5 8-bit bytes, depending on the magnitude of 
its codepoint[1]. For example, any ASCII character takes up only 1 byte, a 
Latin-1 character takes up 2 bytes, etc. We call this representation of text 
multibyte.

...

[1] This internal representation is based on one of the encodings defined by 
the Unicode Standard, called UTF-8, for representing any Unicode codepoint, but 
Emacs extends UTF-8 to represent the additional codepoints it uses for raw 8-
bit bytes and characters not unified with Unicode.

"

Jeremy


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


Re: interactive plots

2011-07-06 Thread Jeremy Sanders
Mihai Badoiu wrote:

> How do I do interactive plots in python?  Say I have to plot f(x) and g(x)
> and I want in the plot to be able to click on f and make it disappear. 
> Any python library that does this?

You could try veusz, which is a python module and plotting program combined. 
You can also embed it in a PyQt program.

Jeremy


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


Re: Classes derived from dict and eval

2005-09-22 Thread Jeremy Sanders
On Tue, 20 Sep 2005 13:59:50 -0700, Robert Kern wrote:

> globals needs to be a real dictionary. The implementation uses the C
> API, it doesn't use the overridden __getitem__. The locals argument,
> apparently can be some other kind of mapping.

It seems that on Python 2.3 then neither globals or locals accessing by
eval calls the __getitem__ member of the dicts.

Jeremy

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


Wrapping classes

2005-09-22 Thread Jeremy Sanders
Is it possible to implement some sort of "lazy" creation of objects only
when the object is used, but behaving in the same way as the object?

For instance:

class Foo:
  def __init__(self, val):
"""This is really slow."""
self.num = val

# this doesn't call Foo.__init__ yet
a = lazyclass(Foo, 6)

# Foo is only initalised here
print a.num

What I really want to do is make an object which looks like a numarray,
but only computes its contents the first time it is used.

Thanks

Jeremy


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


Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
Peter Hansen wrote:
 
> Almost anything is possible in Python, though whether the underlying
> design idea is sound is a completely different question.  (Translation:
> try the following pseudo-code, but I have my suspicions about whether
> what you're doing is a good idea. :-) )

What I'd like to do precisely is to be able to evaluate an expression like
"a+2*b" (using eval) where a and b are objects which behave like numarray
arrays, but whose values aren't computed until their used.

I need to compute the values when used because the arrays could depend on
each other, and the easiest way to get the evaluation order correct is to
only evaluate them when they're used.

An alternative way is to do some string processing to replace a with
computearray("a") in the expression or something horrible like that.

Thanks

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
Diez B. Roggisch wrote:

> It works - in python 2.4!! I tried subclassing dict, but my
> __getitem__-method wasn't called - most probably because it's a C-type,
> but I don't know for sure. Maybe someone can elaborate on that?

Yes - I tried that (see thread below). Unfortunately it needs Python 2.4,
and I can't rely on my users having that.

Traceback (most recent call last):
  File "test.py", line 15, in ?
print eval("10 * a + b", globals(), l)
TypeError: eval() argument 3 must be dict, not Foo

If you subclass dict it doesn't call the __getitem__ method.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
bruno modulix wrote:

> Could it work with a UserDict subclass ?

Unfortunately not:

Traceback (most recent call last):
  File "test.py", line 17, in ?
print eval("10 * a + b", globals(), l)
TypeError: eval() argument 3 must be dict, not instance

Thanks

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
Colin J. Williams wrote:

> Could you not have functions a and b each of which returns a NumArray
> instance?
> 
> Your expression would then be something like a(..)+2*b(..).

The user enters the expression (yes - I'm aware of the possible security
issues), as it is a scientific application. I don't think they'd like to
put () after each variable name.

I could always munge the expression after the user enters it, of course.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Veusz 0.8 released

2005-10-21 Thread Jeremy Sanders
Veusz 0.8
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/
 
Veusz is Copyright (C) 2003-2005 Jeremy Sanders <[EMAIL PROTECTED]>
Licenced under the GPL (version 2 or greater)
 
Veusz is a scientific plotting package written in Python (currently
100% Python). It uses PyQt for display and user-interfaces, and
numarray for handling the numeric data. Veusz is designed to produce
publication-ready Postscript output.
 
Veusz provides a GUI, command line and scripting interface (based on
Python) to its plotting facilities. The plots are built using an
object-based system to provide a consistent interface.
 
Changes from 0.7:
 Please refer to ChangeLog for all the changes.
 Highlights include:
  * Datasets can be linked together with expressions
  * SVG export
  * Edit/Copy/Cut support of widgets
  * Pan image with mouse
  * Click on graph to change settings
  * Lots of UI improvements
 
Features of package:
 * X-Y plots (with errorbars)
 * Images (with colour mappings)
 * Stepped plots (for histograms)
 * Line plots
 * Function plots
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS output
 * Simple data importing
 * Scripting interface
 * Save/Load plots
 * Dataset manipulation
 * Embed Veusz within other programs
 
To be done:
 * Contour plots
 * UI improvements
 * Import filters (for qdp and other plotting packages, fits, csv)
 
Requirements:
 Python (probably 2.3 or greater required)
   http://www.python.org/
 Qt (free edition)
   http://www.trolltech.com/products/qt/
 PyQt (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numarray
   http://www.stsci.edu/resources/software_hardware/numarray
 Microsoft Core Fonts (recommended)
   http://corefonts.sourceforge.net/
 PyFITS (optional)
   http://www.stsci.edu/resources/software_hardware/pyfits
 
For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).
 
If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at
 
https://gna.org/mail/?group=veusz
 
to discuss new features or if you'd like to contribute code. The
newest code can always be found in CVS.

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


Re: Scanning a file

2005-10-28 Thread Jeremy Sanders
Gerhard Häring wrote:

> [EMAIL PROTECTED] wrote:
>> I want to scan a file byte for byte [...]
>> while True:
>> ch = inputFile.read(1)
>> [...] But it is very slow. What is the fastest way to do this? Using some
>> native call? Using a buffer? Using whatever?
> 
> Read in blocks, not byte for byte. I had good experiences with block
> sizes like 4096 or 8192.

It's difficult to handle overlaps. The four byte sequence may occur at the
end of one block and beginning of the next. You'd need to check for these
special cases.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyFLTK - an underrated gem for GUI projects

2005-11-08 Thread Jeremy Sanders
aum wrote:

> But for smaller gui programs not needing the power of wx, I find I get
> the job done much more quickly and effortlessly with PyFLTK.

Interesting. I've found PyQt very easy to use too. I wonder how they compare
(providing you can GPL your app, of course).

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pylab and pyserial plot in real time

2005-11-08 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> Does anyone know of a module designed for ploting real time data thats
> more appropriate for the above mentioned task than pylab??

You could have a look at my plotting package, Veusz, which can be embedded
in other apps. You can update the data in real time, as the windowing runs
in a separate thread.

The main problem is that I have only really tested it on Unix, but I have
reports that it "mostly" works in Windows (I'm looking into supporting this
soon).

http://home.gna.org/veusz/

Alternatively matplotlib may be another solution.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using python for writing models: How to run models in restricted python mode?

2005-11-09 Thread Jeremy Sanders
vinjvinj wrote:
 
> 2. restrict the amount of memory a module uses as well. For instance
> how can I restrict a user from doing a = range(100) or similar
> tasks so that my whole compute farm does not come down.

The safest way to do this in unix is to run the model in a separate process,
and use ulimit (or the resource module) to limit the memory usage.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using python for writing models: How to run models in restricted python mode?

2005-11-10 Thread Jeremy Sanders
vinjvinj wrote:

> Unfortunately this in not an options since all the processes share
> objects in memory which are about 1gig for each node. Having a copy of
> this in each user process is just not an options. I think I'm going to
> use RestrictedPython from zope3 svn which should take care of 70-80 %
> of the problem.

I wonder whether it is possible to fork() the program, restricting the
memory usuage for the forked program. In most unix variants, forked
programs share memory until that memory is written to. Of course this may
not be useful if there's data going back and forth all the time.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to extract columns like awk $1 $5

2005-01-07 Thread Jeremy Sanders
On Fri, 07 Jan 2005 12:15:48 -0500, Anand S Bisen wrote:

> Is there a simple way to extract words speerated by a space in python 
> the way i do it in awk '{print $4 $5}' . I am sure there should be some 
> but i dont know it.

mystr = '1 2 3 4 5 6'
parts = mystr.split()
print parts[3:5]

Jeremy

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


Re: simultaneous multiple requests to very simple database

2005-01-19 Thread Jeremy Sanders
On Tue, 18 Jan 2005 11:26:46 -0500, Eric S. Johansson wrote:

> So the solutions that come to mind are some form of dictionary in shared
> memory with locking semaphore scoreboard or a multithreaded process
> containing a single database (Python native dictionary, metakit, gdbm??)
> and have all of my processes speak to it using xmlrpc which leaves me
> with the question of how to make a multithreaded server using stock
> xmlrpc.

Another solution might be to store the records as files in a directory,
and use file locking to control access to the files (careful over NFS!).

You might also consider berkeley db, which is a simple database to add to
an application, (and which I believe supports locks), but I must admit I'm
not a fan of the library.

I assume that the bottleneck is processing the records, otherwise this all
seems a bit academic.

Jeremy

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


Re: Python with no significant whitespace

2005-01-26 Thread Jeremy Sanders
On Wed, 26 Jan 2005 11:31:18 +0800, mep wrote:

> Hi,all
> Is there anybody trying to release a modification version to current
> python source code with no significant whitespace, say replacing whitespace
> by {}
> like C or java. I do *NOT* mean whitespace is good or bad, just
> want to know.

It probably would be easy to convert source in the form using brackets to
indented form on the fly, and use exec to interpret the converted form.

You need to do something like convert  { to

:
 foo

Of course this isn't a good idea.

Jeremy


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


webbrowser.py

2005-02-02 Thread Jeremy Sanders
It occurs to me that webbrowser could be more intelligent on Linux/Unix
systems. Both Gnome and KDE have default web browsers, so one could use
their settings to choose the appropriate browser.

I haven't been able to find a freedesktop common standard for web browser,
however.

Firefox now sets itself as a "default browser" on startup, so python could
also look for a similar setting.

webbrowser could identify whether it was running under KDE/Gnome (maybe
scan the processes?), identify the correct desktop's browser (or just use
Gnome, maybe), and start that web browser.

Comments?

Jeremy

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


Re: Python choice of database

2005-06-21 Thread Jeremy Sanders
On Mon, 20 Jun 2005 23:42:21 -0800, EP wrote:

> until my records (text - maybe 50KB average) unexpectedly blossomed into
> the 10,000-1,000,000 ranges.  If I or someone else (who innocently doesn't
> know better) opens up one of the directories with ~150,000 files in it,
> the machine's personality gets a little ugly (it seems buggy but is just
> very busy; no crashing).  Under 10,000 files per directory seems to work
> just fine, though.

Yes. Programs like "squid" use subdirectories to avoid this problem. If
your key is a surname, then you can just use the first letter to divide
the names up, for instance, or part of the hash value.

Many Linux FSs can cope with lots of files, but it doesn't hurt to try to
avoid this.

Jeremy

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


Re: User interfaces in console (dialog like)

2005-06-23 Thread Jeremy Sanders
Negroup wrote:

> Do you guys know an alternative that fits my needings without moving
> from Python?

Turbo Vision in dos used to be really good. There's a python binding to the
free version here:

http://tvision.sourceforge.net/

(I haven't tried it)

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary to tuple

2005-06-28 Thread Jeremy Sanders
Erik Max Francis wrote:

> But it doesn't return a tuple of them.  Which is what the tuple call
> there does.

Yes, but I think he meant:

t = tuple(d.items())

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Store multiple dictionaries in a file

2005-06-30 Thread Jeremy Sanders
Philipp H. Mohr wrote:

> I would like to store multiple dictionaries in a file, if possible one per
> line. My code currently produces a new dictionary every iteration and
> passes it on to another peace of code. In order to be able to re-run some
> experiments at a later date I would like to store every dictionary in the
> same file.
> I looked at pickel, but that seems to require a whole file for each
> dictionary.

If you're not worried about security, you could write the repr() of each
dict to the file and get the values back by using the eval() function.
repr() writes onto one line.

If you're storing types without repr() representations this will not work.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sort files by date

2005-07-12 Thread Jeremy Sanders
fargo wrote:

> I'm looking for some way to sort files by date.

you could do something like:

l = [(os.stat(i).st_mtime, i) for i in glob.glob('*')]
l.sort()
files = [i[1] for i in l]

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: breaking out of nested loop

2005-07-12 Thread Jeremy Sanders
rbt wrote:

> What is the appropriate way to break out of this while loop if the for
> loop finds a match?

queue discussion why Python doesn't have a "break N" statement...

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Veusz 0.7 - a scientific plotting package

2005-07-24 Thread Jeremy Sanders
Veusz 0.7
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/
 
Veusz is a scientific plotting package written in Python (currently
100% Python). It uses PyQt for display and user-interfaces, and
numarray for handling the numeric data. Veusz is designed to produce
publication-ready Postscript output.
 
Veusz provides a GUI, command line and scripting interface (based on
Python) to its plotting facilities. The plots are built using an
object-based system to provide a consistent interface.
 
Changes from 0.6:
 Please refer to ChangeLog for all the changes.
 Highlights include:
  * 2D image support
  * FITS file data import (1D + 2D) with PyFITS module
  * Support for line separated blocks of data when importing
  * Reversed axes supported
  * Key length option
  * Linked dataset reload UI
  * Plot functions over specific range
  * Several UI improvements
 
Features of package:
 * X-Y plots (with errorbars)
 * Images (with colour mappings)
 * Stepped plots (for histograms)
 * Line plots
 * Function plots
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS output
 * Simple data importing
 * Scripting interface
 * Save/Load plots
 * Dataset manipulation
 * Embed Veusz within other programs
 
To be done:
 * Contour plots
 * UI improvements
 * Import filters (for qdp and other plotting packages, fits, csv)
 
Requirements:
 Python (probably 2.3 or greater required)
   http://www.python.org/
 Qt (free edition)
   http://www.trolltech.com/products/qt/
 PyQt (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numarray
   http://www.stsci.edu/resources/software_hardware/numarray
 Microsoft Core Fonts (recommended)
   http://corefonts.sourceforge.net/
 PyFITS (optional)
   http://www.stsci.edu/resources/software_hardware/pyfits
 
For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).
 
Cheers
 
Jeremy
 

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


Re: Psyco & Linux

2005-08-12 Thread Jeremy Sanders
Fausto Arinos Barbuto wrote:

> The specifics of my system are:
> 
> Athlon AMD-64 3300+
> SuSE 9.3 Professional (64-bit)
> Python 2.4
> gcc/g++ 3.3.5

Ummm... I thought psyco only supported 32 bit systems. I haven't seen
anything else to suggest otherwise. See

http://psyco.sourceforge.net/psycoguide/req.html

Maybe you could recompile your python in 32 bit mode. You may find that
native 64 bit python is faster than 32 bit psyco however!

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round() wrong in Python 2.4?

2005-09-13 Thread Jeremy Sanders
Nils Grimsmo wrote:

> Why did round() change in Python 2.4?

It the usual floating point representation problem. 0.0225 cannot be
represented exactly:

xpc20:~> python
Python 2.3.4 (#1, Mar 14 2005, 16:47:22)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.0225
0.022499

See
http://www.python.org/doc/current/tut/node13.html#SECTION001380

If you need exact maths, then you're better off using integers or decimal
arithmetic.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round() wrong in Python 2.4?

2005-09-14 Thread Jeremy Sanders
Robert Kern wrote:

> That's not what he's asking about. He's asking why his Python 2.3 rounds
> 0.0225 *up* to 0.023 while his Python 2.4 rounds *down* to 0.022. It's
> the change in behavior that he's concerned with and isn't just the usual
> floating point problem.

You can't rely on either being true, given the nature of the inexact
representation of the number, and the fact that python ignores quite a lot
of the IEEE stuff. Different optimisations (particularly with the 80 bit
floating point registers in x86), will lead to different represenations.
Any code which relies on a particular behaviour is broken.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Classes derived from dict and eval

2005-09-20 Thread Jeremy Sanders
Hi -

I'm trying to subclass a dict which is used as the globals environment of
an eval expression. For instance:

class Foo(dict):
def __init__(self):
self.update(globals())
self['val'] = 42
 
def __getitem__(self, item):
# this doesn't get called from the eval statement
print "*", item
return dict.__getitem__(self, item)

a = Foo()

print a['val']
print eval('val*2+6', a)

The first print statements also prints "* val", but __getitem__ is never
called by the evaluation in the eval statement.

Is this a bug? Does anyone have an idea for a workaround? I'm using
Python 2.3.3.

Thanks

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


Re: supress creation of .pyc files

2005-02-16 Thread Jeremy Sanders
On Wed, 16 Feb 2005 14:53:22 +0100, Thomas Guettler wrote:

> The imported file is a config file, not a script.

You could use execfile() to read the file, and not import.

Jeremy

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


Splitting strings - by iterators?

2005-02-25 Thread Jeremy Sanders
I have a large string containing lines of text separated by '\n'. I'm
currently using text.splitlines(True) to break the text into lines, and
I'm iterating over the resulting list.

This is very slow (when using 40 lines!). Other than dumping the
string to a file, and reading it back using the file iterator, is there a
way to quickly iterate over the lines?

I tried using newpos=text.find('\n', pos), and returning the chopped text
text[pos:newpos+1], but this is much slower than splitlines.

Any ideas?

Thanks

Jeremy

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


Re: Splitting strings - by iterators?

2005-02-25 Thread Jeremy Sanders
On Fri, 25 Feb 2005 17:14:24 +0100, Diez B. Roggisch wrote:

> Maybe [c]StringIO can be of help. I don't know if it's iterator is lazy. But
> at least it has one, so you can try and see if it improves performance :)

Excellent! I somehow missed that module. StringIO speeds up the iteration
by a factor of 20!

Thanks

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


Re: Splitting strings - by iterators?

2005-02-25 Thread Jeremy Sanders
On Fri, 25 Feb 2005 10:57:59 -0600, Larry Bates wrote:

> How did you get the string in memory in the first place?

They're actually from a generated python script, acting as a saved file
format, something like:

interpret("""
lots of lines
""")
another_command()

Obviously this isn't the most efficient format, but it's nice to
encapsulate the data and the script into one file.

Jeremy

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


Re: Sorting in huge files

2004-12-08 Thread Jeremy Sanders
On Tue, 07 Dec 2004 12:27:33 -0800, Paul wrote:

> I have a large database of 15GB, consisting of 10^8 entries of
> approximately 100 bytes each. I devised a relatively simple key map on
> my database, and I would like to order the database with respect to the
> key.

You won't be able to load this into memory on a 32-bit machine, even with
loads of swap. Maybe you could do this on x86-64 with lots of swap (or
loadsa memory), or other 64-bit hardware. It will be _really_ slow,
however.

Otherwise you could do an on-disk sort (not too hard with fixed-length
records), but this will require some coding. You'll probably need to do
some reading to work out which sorting algorithm accesses the data less
randomly. I think the key phrase is an "external sort" rather than an
"interal sort".

It's probably easiest to load it into the thing into a database (like
PostgreSQL), to do the work for you.

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


High level SNMP

2004-12-09 Thread Jeremy Sanders
Hi -

I'd like to write a program which basically does a few snmpgets. I haven't
been able to find a python package which gives you a nice high-level and
simple way of doing this (like PHP has). Everything appears to be
extremely low level. All I need is SNMPv1.

Does anyone know of a simple python package for doing this? I'd rather
have something written in pure python, so that it is easily cross-platform.

Jeremy

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


Re: High level SNMP

2004-12-09 Thread Jeremy Sanders
On Thu, 09 Dec 2004 15:34:14 +0200, Petri Laakso wrote:

>> have you tested twistedsnmp?
> http://twistedsnmp.sourceforge.net/

I looked at it, but it needs Twisted compiled and installed, which is a
pain.

The old versions of PySNMP (version 2.XX), seem to be a lot simpler to
use than later ones, so I might do that. That's if I can work out how to
convert the random string it produces to a floating point number. Somehow
it manages to gain 3 bytes over a float...

Jeremy

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


Re: Help beautify ugly heuristic code

2004-12-09 Thread Jeremy Sanders
On Wed, 08 Dec 2004 18:38:14 -0500, Stuart D. Gathman wrote:

>> Here are the last 20 (which my subjective judgement says are correct):
> 
> 65.112.76.15usfshlxmx01.myreg.net 201.128.108.41 
[snip]
> 80.143.79.97p508F4F61.dip0.t-ipconnect.de DYN

Looks like you could do something like look for a part of the dns name
which is over a certain length with a high fraction of numbers and
punctuation characters.

Of course, you could build up a probability tree of the chance of a
character being followed by another character in a dynamic name and a
static name.

This might work well, as many are sequences of numbers (high chance of
number followed by number), and mixed characters and numbers, which are
unusual in normal dns names.

Jeremy

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


ANN: Veusz 0.5 - a scientific plotting package

2005-04-17 Thread Jeremy Sanders
Veusz 0.5
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/

Veusz is Copyright (C) 2003-2005 Jeremy Sanders <[EMAIL PROTECTED]>
Licenced under the GPL (version 2 or greater)

Veusz is a scientific plotting package written in Python (currently
100% Python). It uses PyQt for display and user-interfaces, and
numarray for handling the numeric data. Veusz is designed to produce
publication-ready Postscript output.

Veusz provides a GUI, command line and scripting interface (based on
Python) to its plotting facilities. The plots are built using an
object-based system to provide a consistent interface.

Changes from 0.4:
 Installation:
  * distutils used to install the package. RPMS available.
 Plotting:
  * Different error bar styles (diamond, curve...)
  * "Matched" axes, with the same scale on each
  * Data can be linked from external files instead of embedded in
document
  * Filled regions under/over functions or xy plots
  * Improved function clipping near edge of plot
  * Default values can be set for settings, which are remembered
between sessions (e.g. blue points for xy3).
  * Rotated text labels
  * Improved fitting, giving results from chi2, etc..
 UI:
  * Can move around widgets and delete them
  * Exception dump dialog to send bug reports
  * Improved import dialog help
  * Propagate settings between widgets
  * Window positions are saved between sessions 
 Reading data:
  * Better error handling when reading data
 + Numerous bug fixes

Features of package:
 * X-Y plots (with errorbars)
 * Stepped plots (for histograms)
 * Line plots
 * Function plots
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS output
 * Simple data importing
 * Scripting interface
 * Save/Load plots

To be done:
 * Contour plots
 * Images
 * UI improvements
 * Import filters (for qdp and other plotting packages, fits, csv)
 * Data manipulation
 * Python embedding interface (for embedding Veusz in other programs).
   [some of the external interface is complete]

Requirements:
 Python (probably 2.3 or greater required)
   http://www.python.org/
 Qt (free edition)
   http://www.trolltech.com/products/qt/  
 PyQt (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numarray
   http://www.stsci.edu/resources/software_hardware/numarray
 Microsoft Core Fonts (recommended)
   http://corefonts.sourceforge.net/

For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).

If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at

https://gna.org/mail/?group=veusz

to discuss new features or if you'd like to contribute code. The
newest code can always be found in CVS.

Cheers

Jeremy

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


Re: ANN: Veusz 0.5 - a scientific plotting package

2005-04-18 Thread Jeremy Sanders
On Mon, 18 Apr 2005 00:55:17 -0700, hemanth wrote:

> Why not matplotlib? Of late, it has seemed to have picked up a lot of
> attention. I would prefer that the different plotting packages developers
> join hands and implement missing features into a single plotting package
> and make this a part of Python standard library. In contrast to the
> various web frameworks we now have in Python, it is preferable to have
> atleast one plotting package as a standard Python package.

I made a reply on this subject to the SciPy mailing list:
 http://www.scipy.org/mailinglists/mailman?fn=scipy-user/2005-April/004312.html

Basically my main issue was the baroque object structure that matplotlib
used (it may have got better then), and its speed (which has).

The difficulty of writing a plotting package is the user interface, and so
I don't think I'm wasting much effort by having my own plotting routines.
I've done 90% of what's needed there. Basically, I'll be happy when
contouring and images are added.

The advantage of Veusz is the nice object-based system of building up a
plot.

I have a version of veusz which used matplotlib as a backend, but I
abandoned that several months ago.

Jeremy

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


Re: ANN: Veusz 0.5 - a scientific plotting package

2005-04-19 Thread Jeremy Sanders
On Mon, 18 Apr 2005 13:40:09 -0700, jdh2358 wrote:

> I'll start by saying that I for one won't criticize you for rolling you
> own plotting package rather than join forces with an existing project.
> I've been accused of the same, on more than one occasion :-)  But I'm also
> aware of the problem that this creates -- the tyranny of choice. python is
> so fun to code in that many developers are looking for a reason to find an
> existant package inadequate so they have an excuse to write their own
> replacement.  Hence we have a proliferation of web-app frameworks,
> plotting packages, array objects and so on.  There is a lot of duplicated
> effort in many arenas and it would be nice to collaborate more.

True. It's sad that it's just more fun to go off and write something
yourself, but it is fun :-)  I'm afraid I'm not very good with using other
people's codebases.

> I read over your scipy list of problems that you found in matplotlib --
> some were helpful and some, as you note, have been long fixed.  One
> critique you might flesh out for me is the notion that matplotlib's object
> model is baroque -- most of the developers feel the object model is fairly
> solid.  You weren't by chance, trying to use the procedural pylab (aka
> matlab) interface, were you, since pylab itself is just a wrapper of the
> OO matplotlib API?  One area in the object model that we plan to change is
> to make high level plot objects (scatter, error, histogram) etc, proper
> objects, ala gnuplot.  Right now they are methods that generate primitive
> objects (lines, rectangles, text, etc).

I thought I was using the object interface. It seemed strange to me that
methods of the axes were used to plot data, draw legends, and so on... It
seemed to make much more sense to have these as objects themselves. The
main problem is that there's no object you can alter to change their
appearance.

I quite like the object system I've developed, where the external
interface is completely based on building the object hierarchy and setting
properties of the objects (plus there is a "functional" interface, but
this is only used rarely for active operations, like fitting data).

I wanted an interface where I could twiddle a bit, and change the axis
from log to linear, or vertical to horizontal... I wasn't sure which
variables in the matplotlib source I could touch and get away with in
future releases :-)

> Another area you identify as a problem with matplotlib is the need to
> regenerate the entire graph when one property is changed.  This is true in
> one way and false in another.  matplotlib does have a proper object model
> -- eg, you can selectively change the facecolor of a marker w/o
> regenerating the graph scene.  But the *drawing* hierarchy (as opposed to
> the object hierarchy) needs some work .  Once you have changed a property,
> the entire graph is redrawn.  This is a known limitation and will change
> in the not-too-distant-future.  One advantage of working in mainstream in
> open source software is the network effect.  With 10 some-odd developers
> including institutions such as the U of C, STScI, JPL and NOAA, bugs and
> limitations of matplotlib tend to be fixed within minutes, days, weeks or
> months.

It looked to me that you could change some properties (like line style)
after creating the graph, but other things were hard to change (marker
style?). Therefore I deleted the graph and rebuilt it from scratch each
time. The way you modify a property is different from how you set it when
building a graph, and so it was difficult to create a transparent
interface.

> Your package looks very nice.  It specifically addresses two limitations
> in matplotlib that we would like to address -- a GUI interface for
> creating figures and a way to save the figure at any point as a high level
> description (rather than an image).  I do wish you had publicly voiced the
> problems you ran into along the way; I just searched the archives and saw
> only one post from you on the users list which I answered 28 minutes later
> with
> 
> http://sourceforge.net/mailarchive/message.php?msg_id=10124206
>
> after which I never heard from you again.  Such response times are fairly
> typical on the list, but if you don't report the bugs and follow up on the
> suggested fixes, we can't fix them.

Sorry - much of my work was done when I didn't have a very good internet
connection, and so it was hard for me to collaborate over bugs. I took the
easy option of expanding the small codebase I already have (which I knew
pretty well!), over debugging someone else's code.

> Anyway, nice work on veusz.  Are you committed to the GPL license?
> matplotlib uses a more permissive license (PSF compatible) mainly to
> encourage contributions from the commercial sector.  As you suggest, it is
> still possible for someone to take the work you've done on the GUI
> frontend and expose matplotlib as a backend based on your prior
> experiments.  The NASA Jet Propulsion Laboroa

Re: squeeze out some performance

2013-12-06 Thread Jeremy Sanders
Robert Voigtländer wrote:

> I try to squeeze out some performance of the code pasted on the link
> below. http://pastebin.com/gMnqprST
> 
> The code will be used to continuously analyze sonar sensor data. I set
> this up to calculate all coordinates in a sonar cone without heavy use of
> trigonometry (assuming that this way is faster in the end).
> 
> I optimized as much as I could. Maybe one of you has another bright idea
> to squeeze out a bit more?

This sort of code is probably harder to make faster in pure python. You 
could try profiling it to see where the hot spots are. Perhaps the choice of 
arrays or sets might have some speed impact.

One idea would be to use something like cython to compile your python code 
to an extension module, with some hints to the types of the various values.

I would go down the geometry route. If you can restate your problem in terms 
of geometry, it might be possible to replace all that code with a few numpy 
array operations.

e.g. for finding pixels in a circle of radius 50
import numpy as np
radiussqd = np.fromfunction(lambda y,x: (y-50)**2+(x-50)**2, (100,100) )
all_y, all_x = np.indices((100,100))
yvals = all_y[radiussqd < 50**2]

Jeremy


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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-16 Thread Jeremy Sanders
Michael Torrie wrote:

> I think PyQt is slowly being pushed aside in favor of PySide, which is
> more license-friendly for use in closed or open projects.  I would
> recommend using PySide unless PyQt is a requirement for your project.

That's not the impression I get from the PySide mailing lists. Work seems 
slow now everyone is a volunteer. For example, Qt 5 is not yet supported 
(there's no effort towards this according to the mailing list) and bugs seem 
to take a long time to be fixed. PyQt support is much better, even when I'm 
using it for a free project.

Jeremy



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


Re: Python, C++ interaction

2014-12-04 Thread Jeremy Sanders
Michael Kreim wrote:

> What are you using to wrap C++ classes for Python?

I'm using SIP, as it fits nicely with my PyQt user interface. 
http://www.riverbankcomputing.com/software/sip/intro

It's a pretty flexible and fast way of wrapping C++ and C.

If you want to pass numpy arrays and such, it requires a bit more work, 
however.

Jeremy


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


Re: checking if two things do not equal None

2014-03-31 Thread Jeremy Sanders
[email protected] wrote:

> if (a, b) != (None, None):
> or
> if a != None != b:
> 
> Preference? Pros? Cons? Alternatives?

I couldn't see anyone else give this, but I like

if None not in (a, b):
 pass

Jeremy


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


Re: semicolon at end of python's statements

2013-09-05 Thread Jeremy Sanders
Chris Angelico wrote:

> Because s/he thought it made for better code, or as a joke? Usually I
> see this sort of thing as the latter...

http://oldhome.schmorp.de/marc/bournegol.html
http://utcc.utoronto.ca/~cks/space/blog/programming/BourneGol

Jeremy


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


Re: Multiple scripts versus single multi-threaded script

2013-10-04 Thread Jeremy Sanders
Roy Smith wrote:

> Threads are lighter-weight.  That means it's faster to start a new
> thread (compared to starting a new process), and a thread consumes fewer
> system resources than a process.  If you have lots of short-lived tasks
> to run, this can be significant.  If each task will run for a long time
> and do a lot of computation, the cost of startup becomes less of an
> issue because it's amortized over the longer run time.

This might be true on Windows, but I think on Linux process overheads are 
pretty similar to threads, e.g.
http://stackoverflow.com/questions/807506/threads-vs-processes-in-linux

Combined with the lack of a GIL-conflict, processes can be pretty efficient.

Jeremy


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


Re: Python Random vs. Cython C Rand for Dice Rolls

2015-06-08 Thread Jeremy Sanders
C.D. Reimer wrote:

> Is there something in the Cython code that I need to change and/or find
> a better C random number generator?

This may not be helpful, but numpy is pretty helpful for this sort of thing:

import numpy
import numpy.random

a=numpy.random.randint(1,6,5000)
b=numpy.random.randint(1,6,5000)

numpy.bincount(a+b-1)

array([  0, 1999229, 4000369, 5999372, 7999232, 9998769, 8003430,
   5998538, 4001160, 101])

This takes a few seconds on my system.

Jeremy


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


Re: A new module for performing tail-call elimination

2015-07-16 Thread Jeremy Sanders
Robin Becker wrote:

> I believe the classic answer is Ackermann's function
> 
> http://demonstrations.wolfram.com/RecursionInTheAckermannFunction/
> 
> which is said to be not "primitive recursive" ie cannot be unwound into
> loops; not sure whether that implies it has to be recursively defined or
> can perhaps be broken down some other way. For more eye-glazing

But am I right in thinking that TCO doesn't work for Ackermann's function, 
at least not as it's written down in the above page?

J.


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


Re: Optimizing if statement check over a numpy value

2015-07-23 Thread Jeremy Sanders
Heli Nix wrote:

> Is there any way that I can optimize this if statement.

Array processing is much faster in numpy. Maybe this is close to what you 
want

import numpy as N
# input data
vals = N.array([42, 1, 5, 3.14, 53, 1, 12, 11, 1])
# list of items to exclude
exclude = [1]
# convert to a boolean array
exclbool = N.zeros(vals.shape, dtype=bool)
exclbool[exclude] = True
# do replacement
ones = vals==1.0
# Note: ~ is numpy.logical_not
vals[ones & (~exclbool)] = 1e-20

I think you'll have to convert your HDF array into a numpy array first, 
using numpy.array().

Jeremy


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


ANN: Veusz 0.9, a scientific plotting package

2006-01-20 Thread Jeremy Sanders
Veusz 0.9
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/

Veusz is Copyright (C) 2003-2006 Jeremy Sanders <[EMAIL PROTECTED]>
Licenced under the GPL (version 2 or greater)

Veusz is a scientific plotting package written in Python. It uses PyQt
for display and user-interfaces, and numarray for handling the numeric
data. Veusz is designed to produce publication-ready Postscript
output.

Veusz provides a GUI, command line and scripting interface (based on
Python) to its plotting facilities. The plots are built using an
object-based system to provide a consistent interface.

Changes from 0.8:
 Please refer to ChangeLog for all the changes.
 Highlights include:
  * Contour support (thanks to the code of the matplotlib guys!)
  * Undo/redo
  * Rubber band axis zooming
  * More flexible data importing

Features of package:
 * X-Y plots (with errorbars)
 * Contour plots
 * Images (with colour mappings)
 * Stepped plots (for histograms)
 * Line plots
 * Function plots
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS output
 * Simple data importing
 * Scripting interface
 * Save/Load plots
 * Dataset manipulation
 * Embed Veusz within other programs

To be done:
 * UI improvements
 * Import filters (for qdp and other plotting packages, fits, csv)

Requirements:
 Python (probably 2.3 or greater required)
   http://www.python.org/
 Qt (free edition)
   http://www.trolltech.com/products/qt/  
 PyQt 3 (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numarray
   http://www.stsci.edu/resources/software_hardware/numarray
 Microsoft Core Fonts (recommended)
   http://corefonts.sourceforge.net/
 PyFITS (optional)
   http://www.stsci.edu/resources/software_hardware/pyfits

For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).

If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at

https://gna.org/mail/?group=veusz

Cheers

Jeremy

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


Re: How to have application-wide global objects

2006-07-13 Thread Jeremy Sanders
Fredrik Lundh wrote:

> "Sanjay" wrote:
> 
>> Trying hard, I am not even being able to figure out how to create an
>> object in one module and refer the same in another one. "import"
>> created a new object, as I tried.
> 
> "import" doesn't create new objects, so that's not very likely.  can you
> post some code so we don't have to guess what you've tried and not ?

It does if you mess around with sys.path between doing two imports of the
same thing (at least I found out the hard way on Python 2.4). I'm not sure
this is considered a bug or a "don't do that then" problem.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to have application-wide global objects

2006-07-14 Thread Jeremy Sanders
Fredrik Lundh wrote:
 
> if you got some other result, you didn't just import the same thing
> twice...

I think you may be incorrect, or I have misinterpreted you.

Try this:

** In test.py 
import sys

import foo.bar

print foo.bar.myvar
foo.bar.myvar = 42
print foo.bar.myvar

sys.path.insert(0, 'foo')
import bar

print bar.myvar

** In foo/__init__.py 
# this is blank

** In foo/bar.py *
myvar = 10


If you run test.py, then you get the output
10
42
10

When I would have expected 10, 42, 42. The bar module gets imported twice,
once as foo.bar and secondly as bar. The value of 42 in myvar does not get
retained, as there are two copies of the module imported.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to have application-wide global objects

2006-07-14 Thread Jeremy Sanders
Fredrik Lundh wrote:

> no, the "bar.py" *file* gets loaded twice, first as the "foo.bar"
> module, and then as the "bar" module.

True and I agree with your email, but suppose there is bar1.py and bar2.py
in foo, then they can refer to each other by importing bar2 and bar1,
respectively. These module objects will be the same modules that test.py
would get by importing foo.bar1 and foo.bar2.

By analogy you might expect the path munging example to work, but the
details are in the nitty-gritty of how python importing works. The import
docs say something like "Details of the module searching and loading
process are implementation and platform specific". The results can be a
little suprising! It would be include a check so that you could get a
warning with debugging switched on.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyqt scrollview layout

2006-07-21 Thread Jeremy Sanders
Felix Steffenhagen wrote:

> I have a problem with updating contents in a qscrollview.
> I've implementented two widgets (PremiseInput and PremiseList).
> You can find the source code under
> http://www.informatik.uni-freiburg.de/~steffenh/premiseinput.{html|py} and
> http://www.informatik.uni-freiburg.de/~steffenh/premiselist.{html|py}

You should ask on the PyQt mailing list - you're much more likely to get an
answer.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested function scope problem

2006-07-27 Thread Jeremy Sanders
Gerhard Fiedler wrote:

> Going back to the original question... What would be the most
> common/useful way to access variables from the outer function for writing
> from within the inner function?

I've done something like this (which doesn't look very nice)

def myfunc():

   tok = ['']

   def inner():
   tok[0] += 'hi'
   ...
   tok[0] = 'foo'

   inner()
   print tok[0]

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Small Troll on notation of variables over time

2006-08-21 Thread Jeremy Sanders
Hendrik van Rooyen wrote:

> What do you guys think?

You could get something similar using an object, such as

class Hist(object):

def __init__(self):
self.vals = [None]

def __call__(self, index=-1):
return self.vals[index]

def set(self, val):
self.vals.append(val)

a = Hist()

a.set(5)
print a()

a.set('hi there')
print a()
print a(-2)

Which prints
5
hi there
5

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Python and STL efficiency

2006-08-21 Thread Jeremy Sanders
Licheng Fang wrote:

> I was using VC++.net and IDLE, respectively. I had expected C++ to be
> way faster. However, while the python code gave the result almost
> instantly, the C++ code took several seconds to run! Can somebody
> explain this to me? Or is there something wrong with my code?

It must be the debugging, the compiler or a poor STL implementation. With
gcc 4 it runs instantly on my computer (using -O2), even with 10x the
number of values.

If the problem is that C++ has to make lots of new strings, as other posters
have suggested, then you could do something like

const string foo = "What do you know?";

for (long int i=0; i<1 ; ++i){
   a.push_back(foo);
   ...
}

as many C++ implementations use reference counting for identical strings.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-22 Thread Jeremy Sanders
Mc Osten wrote:

> Here some results (I know that the fpoint optimizations are useless...
> it's is my "prebuilt" full optimization macro :) ):

Interesting. The opimisation makes no difference to the speed of the C++ one
for me. I just get

xpc17:~> g++4 -O2 test2.cpp
xpc17:~> ./a.out
What do you know?
chicken crosses road
fool
so long...
What do you know?
chicken crosses road
fool
so long...
Elapsed 2.11
Elapsed 1.11

(This is with an Althon 64 4600+ running Linux).

Unfortunately the Python on this computer doesn't have set as it is too old,
so I can't compare it.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 123 introduction

2006-10-30 Thread Jeremy Sanders
Here is a brief simple introduction to Python I wrote for a computing course
for graduate astronomers. It assumes some programming experience. Although
it is not a complete guide, I believe this could be a useful document for
other groups to learn Python, so I'm making it available for others to
download, and modify for their own needs (some of the content is site
specific).

HTML version:
 http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123/
Postscript LaTeX output:
 http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123.ps
PDF LaTeX output:
 http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123.pdf
LaTeX source:
 http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123.tex

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 123 introduction

2006-10-30 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> This is great! A excellent tutorial for somone who has prior experience
> in programming and is starting out in python. My friend keeps wanting
> me to teach him python, I think this would be the perfect link for him.

I'm glad you think it is useful. It needs a bit of cleaning up as it assumes
things such as python being in /usr/local/bin... I may try to improve this
later.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 123 introduction

2006-10-30 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> I'm not trying to minimize Jeremy's efforts in any way, but how is his
> tutorial a significant improvement over the original
> (http://www.python.org/doc/current/tut/)?

It's not intended as a replacement, but what I wanted to do was write a
quick 2 hour course for people to work through. It overlaps quite a bit
with the tutorial, but I tried to minimise any detail.

I just publicised it in case anybody wanted something similar.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plot pkg - Multiple Y axes?

2006-11-07 Thread Jeremy Sanders
monkeyboy wrote:

> I'm searching for a plotting package that will allow multiple y axes of
> different scales. For example I'd like to overlay 4 or 5 time series
> with each series having a separate axis. Does anyone know of such a
> package?

My package veusz allows that... 

http://home.gna.org/veusz/

You can have any number of y-axes, see

http://home.gna.org/veusz/screenshots/screenshot1.png

The PyQt4 version is coming along nicely too...

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Jeremy Sanders
Dan Lenski wrote:

> Nick and John S., thank you for the tip on wxPython!  I'll look into it
> for my next project.  I too would avoid Qt, not because of the GPL but
> simply because I don't use KDE under Linux and because Qt is not well
> supported under Cygwin or on native Windows.  I too like to learn from
> actual printed books, so I'll check this one out.  O'Reilly should do a
> book on Python GUI stuff!

PyQt is well supported under native Windows. Qt-4 is now GPLd for Windows
too. I'd highly recommend it.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to choose the right GUI toolkit ?

2006-11-10 Thread Jeremy Sanders
Dan Lenski wrote:

> My apologies!  I'm glad to be corrected on this.  There are Cygwin
> packages for Qt as well, but I have heard about enough bugs to think I
> should avoid Qt.  I have used enough Gtk apps that run flawlessly under
> Windows to have my hopes that it works well.

You normally use PyQt/Qt on Windows without Cygwin. There are very few bugs
and lots of professional companies base their products on Qt Windows.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programmatically finding "significant" data points

2006-11-14 Thread Jeremy Sanders
erikcw wrote:

> I have a collection of ordered numerical data in a list.  The numbers
> when plotted on a line chart make a low-high-low-high-high-low (random)
> pattern.  I need an algorithm to extract the "significant" high and low
> points from this data.
> 
...
> 
> How do I sort through this data and pull out these points of
> significance?

Get a book on statistics. One idea is as follows. If you expect the points
to be centred around a single value, you can calculate the median or mean
of the points, calculate their standard deviation (aka spread), and remove
points which are more than N-times the standard deviation from the median.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Mutual interdependency problem

2006-06-07 Thread Jeremy Sanders
I'm getting problems with modules with interdependencies when using the
import form "import foo.bar as bar".

Here are a set of files which replicate the problem

::
importproblem/__init__.py
::
# This is blank

::
importproblem/dir1/__init__.py
::
from bar import *

::
importproblem/dir1/bar.py
::
import importproblem.dir2 as foo
def hello():
print "Hello world"

::
importproblem/dir2/__init__.py
::
from foo import *

::
importproblem/dir2/test.py
::
import importproblem.dir1.bar as bar
def hello():
print "Hello world"

::
importproblem/dir2/foo.py
::
import importproblem.dir1 as dir1
def hello():
print "Hello world"

If you now do
>>> import importproblem.dir1
Traceback (most recent call last):
  File "", line 1, in ?
  File "importproblem/dir1/__init__.py", line 1, in ?
from bar import *
  File "importproblem/dir1/bar.py", line 1, in ?
import importproblem.dir2 as foo
  File "importproblem/dir2/__init__.py", line 1, in ?
from foo import *
  File "importproblem/dir2/foo.py", line 1, in ?
import importproblem.dir1 as dir1
AttributeError: 'module' object has no attribute 'dir1'

[GCC 4.1.0 20060210 (Red Hat 4.1.0-0.24)]

If you remove the "as dir1" from the import line in dir2/foo.py then this
works. Can this be explained or fixed?

Maybe the "from foo import *" style in __init__.py is a bad idea, but it
allows you to expose a flat namespace without having to put all the code
into one file. Then naturally you need mutual interdependencies, and then
it breaks! I can work around it by removing the "as XXX" parts on the
import statement, but it gets annoying having to specify the full path.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


import hook

2006-06-11 Thread Jeremy Sanders
Hi - Is it possible to override the import process so that if in my program
I do

import foo.bar

Python will look for bar in a directory which isn't called foo?

I want my module/program to be able to be run without being installed in
site-packages, so by doing "import foo.bar", it should start looking for
bar in the current directory which could be called "foo-0.43".

I've tried overriding __import__, chopping out "foo." from package names,
but that tends to break. I've also tried overriding imp.find_module() but
Python never appears to use my version.

Any ideas?

Thanks

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import hook

2006-06-18 Thread Jeremy Sanders
Thomas Heller wrote:

> There are also other ways.  You could extend __path__ of foo, and the
> pkgutil module might also be useful.

The __path__ trick worked nicely, thanks. Here is the code in case anyone is
interested

# Allow veusz to be run even if not installed into PYTHONPATH
try:
import veusz
except ImportError:
# load in the veusz module, but change its path to
# the veusz directory, and insert it into sys.modules
import __init__ as veusz
thisdir = os.path.dirname( os.path.abspath(__file__) )
veusz.__path__ = [thisdir]
veusz.__name__ = 'veusz'
sys.modules['veusz'] = veusz

This is part of the main program. If it can't import it (i.e. it is not
installed), it imports the __init__ module, renames it, and corrects its
path, then sticks it into the list of imported modules.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ntp in python

2006-08-29 Thread Jeremy Sanders
Janto Dreijer wrote:

> I want to measure the packet delivery delays over various network
> links. For this I need to synchronise the times of the sender and
> receiver, either against NTP or eachother.

Couldn't you just use NTP itself to get the delivery delay? You can read the
delay out from the ntpdc console using dmpeers, or lopeers in ntpq. You
could have two peers either side of the link and measure the delay from
NTP.

You may also be able to query remote ntp servers to get their delays to
their peers.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ntp in python

2006-08-30 Thread Jeremy Sanders
Janto Dreijer wrote:

> Maybe I'd be better off writing my own implementation that synchronises
> the two pc clocks. Any hints? :-)

I think you might read up on how ntp synchronises clocks (their website is
very thorough), and use their algorithm. It is supposed to be very robust
algorithm. I saw something about ntp on the twisted mailing list, so you
could ask there.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Force sleep to ignore interrupts

2006-09-14 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> It works as I want when used in the main application thread.
> That is, when you hit Ctr + C, it stops running.  However, if
> the class that subclasses it, also subclasses Thread, it breaks
> in that hitting Ctrl + C interrupts the call to sleep which puts
> the event loop out of sync with real time.

Maybe you could install a signal handler to ignore ctrl+c, when required

import signal
signal.signal(signal.SIGINT, signal.SIG_IGN)


-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to save a running program and reload next time ?

2006-09-21 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> I have a program which will continue to run for several days. When it is
> running, I can't do anything except waiting because it takes over most
> of the CUP time.
> 
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?

For Linux (and other Unix like OSs), there are several "checkpointing"
libraries available which allow programs to be saved to disk, and restarted
later.

If the other suggestions people have given to you (STOPping and CONTinuing
processes), or sleep statements, or saving state, don't work investigate
these.

e.g. http://www.cs.wisc.edu/~zandy/ckpt/

These programs have limitations on what can be restored (e.g. threads,
shared memory, network connections...). I don't know which ones work with
python.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: naming objects from string

2006-09-21 Thread Jeremy Sanders
manstey wrote:

> so they might provide a list of names, like 'bob','john','pete', with 3
> structures per name, such as 'apple','orange','red' and I need 9 tuples
> in my code to store their data:
> 
> bob_apple=()
> bob_orange=()
> ..
> pete_red=()

I really think you should be using dictionaries here. You don't want to be
messing around creating random variables in the local or global namespace.

For instance

myvals = {}
myvals['bob'] = {}
myvals['pete'] = {}
...
myvals['bob']['apple'] = (1,2,3,4)
myvals['bob']['orange'] = (2,3,4)
myvals['pete']['red'] = (4,5,6,7)

and so on

>>> myvals
{'pete': {'red': (4, 5, 6, 7)}, 'bob': {'orange': (2, 3, 4), 'apple': (1, 2,
3,4)}}

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing 2d array in an ascci file

2006-09-28 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> I want to write an 2d array in an ascii file using numpy. There's the -
> tofile / fromfile - function but it doesn't work with nd array.

Is this good enough?

x = numpy.zeros( (10, 10) )
f = open('out.txt', 'w')
print >>f, str(x).replace('[',' ').replace(']', ' ')
f.close()


Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to handle large lists?

2006-10-03 Thread Jeremy Sanders
Chaz Ginger wrote:

> What would sets do for me over lists?

It's faster to tell whether something is in a set or dict than in a list
(for some minimum size).

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to handle large lists?

2006-10-03 Thread Jeremy Sanders
Jeremy Sanders wrote:

> Chaz Ginger wrote:
> 
>> What would sets do for me over lists?
> 
> It's faster to tell whether something is in a set or dict than in a list
> (for some minimum size).

As a footnote, this program

import random
num = 10

a = set( range(num) )
for i in range(10):
x = random.randint(0, num-1) in a

completes in less than a second, whereas

import random
num = 10

a = range(num)
for i in range(10):
x = random.randint(0, num-1) in a

takes a long time on my computer.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt app in seperate thread

2006-11-23 Thread Jeremy Sanders
anders wrote:

> OK I see that now. Thanks for pointing that out. So basically, I can't
> do what I want at all. That's a bit of a pain. Is there no way of
> tricking Qt into thinking I'm running it in the main thread?

I have an app which runs Qt in a separate thread and allows the user to send
it python commands from the main thread. Have a look at this code to see
how it works:

http://svn.gna.org/viewcvs/veusz/branches/qt4/embed.py?rev=530&view=markup

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to read the directory which the actively running python file islocated in?

2006-12-01 Thread Jeremy Sanders
Michael Malinowski wrote:

> Nevermind, I got it using the sys.argv[0]

That doesn't always work, as on unix the path isn't prepended onto
sys.argv[0] necessarily.

import os.path
...
os.path.dirname(os.path.abspath(__file__))

may be better.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGTK

2006-02-09 Thread Jeremy Sanders
Huy wrote:

> What I am curious to know is whether anyone has come across any
> noteworthy gui development platforms.  Cross compatibility is not a
> must, but a bonus.  Good documentation and clarity is essential for me.
>  Also, I imagine I can use modules for image manipulation in tandem
> with the GUI interface?  Any comments or speculations are looked
> forward to.  Just thought I'd see if there's anything out there the
> community knows I may not be currently aware of.

PyQt is very easy to use and Qt is well documented, see
http://www.riverbankcomputing.co.uk/pyqt/

The main issue is whether the licence of your code is compatible with the
GPL licensing of Qt and PyQt. If not you will need a commercial license.

I've used it in combination with numarray for image manipulation (however
NumPy is probably better than numarray now). I suppose it depends on what
sort of image manipulation you need.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.

What not

for x in list:
  if x == O:
break
  storage.append(x)

??

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Poisson Distribution (for a newbie)

2006-02-16 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> I want to mimic such kind of distribution using poison traffic ( a bell
> shaped curve). I looked into wikipedia and some other tutorials but I
> wasn't sure how many parameter does the above kind of distribution
> would require.

I've used numarray's poisson distribution generator, which was very useful.
There may well be something similar in NumPy/Numeric/SciPy.

e.g.

from numarray.random_array import poisson

for i in xrange(100):
 print poisson(10)

Where 10 is the mean.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ls files --> list packer

2006-02-24 Thread Jeremy Sanders
I V wrote:

> snd_filelist = [f for f in os.listdir('/snd/Public/') if
> f.endswith('.aiff')]

Or even

from glob import glob

snd_filelist = glob('/snd/Public/*.aiff')

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-02-28 Thread Jeremy Sanders
Fabian Steiner wrote:

> Unfortunately I don't know how to realize this, since also some images
> and different boxes should be printed out. As the whole application is
> based on QT, QPrinter might be used, but I couldn't find any examples
> how to use it.

QPrinter is easy to use. You just draw to the page the same way as you talk
to the screen with a QPainter.

prnt = qt.QPrinter()
# you can also vary options like colour, doc name, dpi here

# display dialog box to user (you can actually leave this out)
if prnt.setup():
 painter = qt.QPainter()
 painter.begin(printer)
 # do stuff to draw to painter
 painter.end(printer)
 # do this between each page
 printer.newPage()

 # ... more pages can be printed to a painter

It's very easy to do. If you want to handle multiple pages and so on,
there's a bit of work to do to interface to the dialog to get the
user-selected page range, etc.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-03-02 Thread Jeremy Sanders
David Boddie wrote:

> That's where QPrintDialog comes in:
> 
>   http://doc.trolltech.com/4.1/qprintdialog.html
> 
> It's also secretly available in Qt 3 via the QPrinter.setup() method:
> 
>   printer = QPrinter()
>   printer.setup()
>   # Now, paint onto the printer as usual.

No - that was in my example. The work I was refering to was taking the
user's input to the dialog and writing the pages to the device in the right
order (I don't think this is done automatically).

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Veusz 0.6 - a scientific plotting package

2005-05-19 Thread Jeremy Sanders
Veusz 0.6
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/

Veusz is Copyright (C) 2003-2005 Jeremy Sanders <[EMAIL PROTECTED]>
Licenced under the GPL (version 2 or greater)

Veusz is a scientific plotting package written in Python (currently
100% Python). It uses PyQt for display and user-interfaces, and
numarray for handling the numeric data. Veusz is designed to produce
publication-ready Postscript output.

Veusz provides a GUI, command line and scripting interface (based on
Python) to its plotting facilities. The plots are built using an
object-based system to provide a consistent interface.

Changes from 0.5:
 Please refer to ChangeLog for all the changes.
 Highlights include:
  * Major UI enhancements - much faster to control now, more dialogs
  * Veusz can be embedded within other non-PyQt Python programs. Its plots
can be updated at any time from the embedding program using the
command line interface.
  * Dialogs for manipulating datasets using expressions, and direct editing
  * Multiple documents can be opened simultaneously
  * Lots of bug fixes (e.g. log axes improvement, rotation of labels)
  * Unicode support in plots

Features of package:
 * X-Y plots (with errorbars)
 * Stepped plots (for histograms)
 * Line plots
 * Function plots
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS output
 * Simple data importing
 * Scripting interface
 * Save/Load plots
 * Dataset manipulation
 * Embed Veusz within other programs

To be done:
 * Contour plots
 * Images
 * UI improvements
 * Import filters (for qdp and other plotting packages, fits, csv)

Requirements:
 Python (probably 2.3 or greater required)
   http://www.python.org/
 Qt (free edition)
   http://www.trolltech.com/products/qt/  
 PyQt (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numarray
   http://www.stsci.edu/resources/software_hardware/numarray
 Microsoft Core Fonts (recommended)
   http://corefonts.sourceforge.net/

For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).

If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at

https://gna.org/mail/?group=veusz

to discuss new features or if you'd like to contribute code. The
newest code can always be found in CVS.

If non GPL projects are interested in using Veusz code, please contact
me. I am happy to consider relicencing code for other free projects,
if I am legally allowed to do so.

Cheers

Jeremy

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


Re: __init__() not called automatically

2005-05-26 Thread Jeremy Sanders
On Wed, 25 May 2005 21:31:57 -0700, Sriek wrote:

> Similarly, why do we have to explicitly use the 'self' keyword everytime?

I didn't like that when starting Python. Now when I look back at C++ code,
I find it very hard to work out which variables and methods and members,
and which are not, unless the author used a clear naming convention.

Jeremy

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


Re: Subprocess and time-out

2005-06-16 Thread Jeremy Sanders
On Thu, 16 Jun 2005 18:36:52 +0200, Gilles Lenfant wrote:

> Grabbing the various docs of Python, I didn't find how to do this :
> 
> I Use popen2 to run wvware that transforms lots of M$ word docs to plain
> text. Sometimes wvware runs in a deadlock and I can't control this from
>   Python app.
> 
> I need to stop wvware processing after 30 seconds (considered deadlocked)
> and to process the next file.
> 
> Unfortunately, I didn't find any pythonic stuff to control the time spent
> runnning subprocesses (and kill'em if needed) launched with popen.
> 
> An hint is welcome. Many thanks by advance.

Is this Unix? If you're using the Popen3/Popen4 objects from popen2
module, you could take the pid of the popened process, and fork your
program. In the forked child process you could wait for an interval, then
do os.wait with W_NOHANG to see whether the process has stopped, and if
not kill it with os.kill.

Jeremy

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


Re: Multiple instances of a python program

2005-06-17 Thread Jeremy Sanders
On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote:

> If you have a python script and you want that 75 copies of the script be
> run simultaneously how will you do it? Is there anyway to do so without
> running 75 copies of the python interpreter simultaneously?

If you're running on Linux (and other Unixes perhaps), you could use the
os.fork() function to create independent child processes from a single
python process. I believe Linux forked processes share memory until a
section of memory is written to (copy on write functionality).

If most of python is in a shared library, then this probably won't make
much difference.

Jeremy

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


Re: Matrix Multiplication

2007-06-18 Thread Jeremy Sanders
sturlamolden wrote:

> Use numpy: www.scipy.org
> 
> NumPy has a matrix type that overloads the * operator.

Just a tiny followup, which may be important unless you carefully read the
documentation. The "*" operator doesn't do matrix multiplication for normal
numpy arrays - you do need to use its special matrix type to get this. You
can use the dot function to get matrix multiplication with its normal
arrays.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Matrix Multiplication

2007-06-19 Thread Jeremy Sanders
sturlamolden wrote:

> That's what I wrote: "NumPy has a matrix type." It is called called
> numpy.matrix.
> 
> I did not suggest using the array type numpy.array.
> 
> Reading carefully is indeed important...

I know what you wrote and you are strictly correct. I was just clarifying it
for a reader who may not have instantly realised that there were multiple
array types in numpy (I didn't for a while), and could have wasted many
hours and been discouraged.

Explaining clearly is indeed important.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stripping the first byte from a binary file

2007-07-10 Thread Jeremy Sanders
rvr wrote:

> Would someone mind showing me how to strip the first byte from a
> binary file? For some reason I can't figure this out from the binary
> file editing examples I've read. Thanks.

Do you mean something like this?

f = open('test.dat', 'rb')
f.read(1)  # read 1st byte and ignore it
rest = f.read()  # read rest

or

data = f.read()
data = data[1:] # skip 1st byte

?

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: questions about functions inside a function

2007-07-16 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> What I want is, the value of i should be bounded to the anonymous
> function. And the output should like this:
...
> How to achieve this?

This doesn't answer your question (others have), but another (perhaps
clearer) way to do such things is something like

class MyFunc(object):
  """A function object."""
  def __init__(self, val):
 self.val = val

  def __call__(self):
 """Return value squared"""
 return self.val**2

a = []
for i in range(4):
  a.append(MyFunc(i))

for f in a:
  f()


Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner: Formatting text output (PyQt4)

2007-04-19 Thread Jeremy Sanders
Glen wrote:

> What seems to be happening is that the font that pyqt is using is not
> fixed width, so I did this:
> qTxtFormat = QTextCharFormat()
> qTxtFormat.setFontFixedPitch(True)
> ui.textEdit.setCurrentCharFormat(qTxtFormat)

Does something like ui.textEdit.setCurrentFont(QFont('fixed')) work? It
seems to work for me if you use plain text.

Tabs or html/rich text formatting should be a better way to get the layout
(or just use a table).

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Screen Scraper

2007-04-24 Thread Jeremy Sanders
Michael Bentley wrote:
> Possibly the easiest thing will be to read from firefox' cache.
> Otherwise I think your only real options are to either build a proxy
> or sniff the wire...

Maybe another way would be to write a firefox addon/plugin. I believe python
is now supported...

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Veusz-0.99.0 - a scientific plotting package

2007-05-24 Thread Jeremy Sanders
I am pleased to announce a new beta of a largely rewritten Veusz plotting
package. This now uses Qt4 and numpy, adding support for Windows. Windows
and Linux binaries are provided. For details see below:


Veusz 0.99.0 (new Qt4/numpy beta)

Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/

Veusz is Copyright (C) 2003-2007 Jeremy Sanders <[EMAIL PROTECTED]>
Licenced under the GPL (version 2 or greater).

Veusz is a scientific plotting package written in Python, using PyQt4
for display and user-interfaces, and numpy for handling the numeric
data. Veusz is designed to produce publication-ready Postscript/PDF
output. The user interface aims to be simple, consistent and powerful.

Veusz provides a GUI, command line, embedding and scripting interface
(based on Python) to its plotting facilities. It also allows for
manipulation and editing of datasets.

Changes from 0.10:
 This is the first release of a much rewritten version of Veusz
 It has been updated to run under Qt4 and numpy, and now supports Windows
 The user interface is also signficantly easier to use

 Other useful features include:
  * Colorbars for images (better color scaling for images too)
  * Grids of graphs with different sized subgraphs
  * Much better import dialog 
  * Antialiased screen output
  * Native PNG and PDF export
  * Separate formatting/properties dialog
  * Handling of INF/NaN in input data
  * Transparency of graphs (not for EPS output)
 Plus many more useful changes (see ChangeLog)

Features of package:
 * X-Y plots (with errorbars)
 * Line and function plots
 * Contour plots
 * Images (with colour mappings and colorbars)
 * Stepped plots (for histograms)
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS/PDF/PNG export
 * Scripting interface
 * Dataset creation/manipulation
 * Embed Veusz within other programs
 * Text, CSV and FITS importing

Requirements:
 Python (2.3 or greater required)
   http://www.python.org/
 Qt >= 4.1 (free edition)
   http://www.trolltech.com/products/qt/  
 PyQt >= 4.1 (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numpy >= 1.0
   http://numpy.scipy.org/
 Microsoft Core Fonts (recommended for nice output)
   http://corefonts.sourceforge.net/
 PyFITS >= 1.1rc3 (optional for FITS import)
   http://www.stsci.edu/resources/software_hardware/pyfits

For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).

Issues:
 * This is a new beta, so there are likely to be a number of bugs, even
   though it has been used by a couple of people for some time.
 * Can be very slow to plot large datasets if antialiasing is enabled.
   Right click on graph and disable antialias to speed up output.
 * Some older versions of Qt (<4.2.2) can produce very large postscript
   output and random crashes. This may not be completely resolved
   (especially on windows).
 * The embedding interface appears to crash on exiting.

If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at

https://gna.org/mail/?group=veusz

to discuss new features or if you'd like to contribute code. The
latest code can always be found in the SVN repository.

Jeremy Sanders

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


Re: Smoother Lines in Turtle Graphics

2007-08-10 Thread Jeremy Sanders
Ant wrote:

> Python: Batteries and Turtles included!

I didn't know that! It looks like turtle is based on Tk, which doesn't have
antialiasing yet (see http://wiki.tcl.tk/10101 ), so it can't really be
made nice and smooth (unless you could somehow use tkzinc/tkpath to draw
with).

I suppose turtle wouldn't be that hard to reimplement it to use Qt/Gtk
instead.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best GUI library for vector drawing program

2007-08-17 Thread Jeremy Sanders
chewie54 wrote:

> What would be the best cross-platform GUI library to use for a vector
> based CAD program ( something like Visio on Windows )   WxWidgets,
> Tk,   PyQt,  Java Swing,  Java SWT,   I need the capibility to
> draw and edit in a window that looks like a page of paper so WYSIWYG
> is very important,  and I need to save the drawings in vector based
> file formats like PS, EPS,  SVG, as well as image formats like jpg,
> png, and gif.  Also, the images need to be high resolution so that
> they can be pasted into various other programs in Windows OS,  and
> Linux OS,  and the Mac OS.

PyQt/Qt4 is capable of that (SVG export was added in Qt4.3).

I have a graph drawing application based around it (Veusz).

If you base everything around QPainter, you'll be able to write to any of
those output formats (including eps and pdf), and bitmaps. Antialiasing is
optional for bitmap formats.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best GUI library for vector drawing program

2007-08-17 Thread Jeremy Sanders
chewie54 wrote:

> I looked at your application, Veusz (it looks very nice),  and I see
> you have binary distrubitions
> for each os.  Is is difficult to build these binaries for each
> system.  Could
> you tell me how that is done?

I use pyinstaller to make the binaries (see the veusz_pyinst.spec file), and
NSIS to make a Windows installer from the Windows binary (see veusz.nsi).

The Linux binary, unfortunately, isn't 100% compatible, as I've found trying
to run on 64 bit systems. I assume it's some sort of glibc mismatch. Making
the linux binaries on an old distribution helps the compatibility (I use
centos 3 in a virtual environment).

jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Co-developers wanted: document markup language

2007-08-24 Thread Jeremy Sanders
Torsten Bronger wrote:

> Some LaTeX users in Aachen thought about a general-use markup
> language this spring.  I wrote some code and a rough project
> description, however, we could need some help.
> 
> If you are interested, visit the provisional project page at
> http://latex-bronger.sourceforge.net/gummi/

Sounds a good idea - LaTeX has so many historical hangovers. How many people
on earth can actually write a LaTeX style file?

I'm not sure about writing LaTeX output, however, due to the crude nasty
ways it handles fonts and so on. How are you going to get enough controls
for users over what they always complain about: fonts, page breaking, and
positioning of figures? Maybe it's an okay first step however.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Co-developers wanted: document markup language

2007-08-25 Thread Jeremy Sanders
Torsten Bronger wrote:

> I don't know exactly what you mean but the answer is probably no.
> For example, I want the author to state the title, keywords, etc of
> his document, however, he should not state that he wants the title
> printed centred and 4cm from the top of the page.
> 
> The latter is defined in the "theme" which will be given as a set of
> ordinary LaTeX commands (for the LaTeX backend).

Isn't the problem that making such a theme will be very hard?

One of the annoying things about LaTeX is lack of control over positioning
(e.g. floats, page breaks...). The one thing most LaTeX users moan about is
trying to get their document to fit into an n page limit (e.g. for a
proposal). Maybe the theme could have some options to control spacing,
however, like some sort of CSS.

I think the one thing that would improve LaTeX is orthogonality in its
commands (e.g. why no 8pt option for the document, why the crazy \small,
\LARGE, etc commands?), and fixing the font system to be based around
modern fonts. Finally making bibtex part of the core and making it easy to
use would be great.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >