Re: pypy and ctypes

2013-11-14 Thread Peter Chant

On 11/14/2013 03:13 PM, Neil Cerutti wrote:

On 2013-11-14, Peter Chant  wrote:

Or is it that - if I keep the code as simple as possible, PyPy
is about as fast as you can get?


PyPy profiles your code as it runs and creates, using a
just-in-time compiler, highly optimized versions of frequently
run sections. You don't have to declare types or even think about
it; The scheme will work best with code that runs for a
significant amount of time.



That is the situation I'm in.  If it only ran for a second or two 
there'd be no point in worrying about speed. PyPy gave a massive speed 
up.  I was wonding if I could do a little more.



cython allows you to declare types, and attempts to create more
efficient code *at compile time* using those type declaration.

Which approach will be better depends on how the code runs and
how clever you are at using cython.


If it is marginal then I don't think the effort would be worth while.
I do wonder whether writing some specific functions in C using cffi
would benefit.  It is something I have no experience of.



PyPy isn't designed to speed up programs that run for a few
hundred milliseconds and then complete, though it might sometimes
work for that.



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


pypy and ctypes

2013-11-13 Thread Peter Chant
I'm looking to speed up some python code.  Replacing the python 
interpreter with pypy was impressive.  I noted that use of ctypes (in 
cython?), specifically declaring variables as below, was reported as 
giving a useful result:


cdef float myvar
cdef int i

under cython can provide a useful speed increase even if sections of 
code are not re-written in C.  Does this also work in PyPy?  From 
googling I keep getting pointed at ffi - but that seems to relate more 
to calling c-libraries rather than what I'm trying to do - seeing if 
there are any simple speed ups by declaring variables.


Or is it that - if I keep the code as simple as possible, PyPy is about 
as fast as you can get?


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


Re: Convert QStingList to Python list

2010-11-27 Thread Peter Chant
Peter Otten wrote:

> 
> Try it out yourself in the interactive interpreter. Here's a sample
> session:
> 

Peter,

thanks.  I've got some way to go with python and have only just started 
looking at Qt, your help has been very useful.

Pete

-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert QStingList to Python list

2010-11-27 Thread Peter Chant
The following code generates a QStringList:

fileNames = QFileDialog.getOpenFileNames(None,"Chose raw file",".",)

Printing it:

print "Files selected "+QStringList(fileNames)

Results in:

TypeError: cannot concatenate 'str' and 'QStringList' objects

Any idea how to convert a QStingList into a python list?  pythonQtConv seems 
to come up in google but I've no idea how to import or invoke it.

Thoughts?

Pete


-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking that 2 pdf are identical (md5 a solution?)

2010-07-24 Thread Peter Chant
rlevesque wrote:

> Is there a way to compare 2 pdf files generated at different time but
> identical in every other respect and validate by program that the
> files are identical (for all practical purposes)?

I wonder, do the PDFs have a timestamp within them from when they are 
created?  That would ruin your MD5 plan.

Pete

-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Python, PIL and 16 bit per channel images

2010-01-25 Thread Peter Chant
Does anyone know whether PIL can handle 16 bit per channel RGB images?  
PyPNG site (http://packages.python.org/pypng/ca.html) states PIL uses 8 bits 
per channel internally.

Thanks,

Pete


-- 
http://www.petezilla.co.uk

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


Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Peter Chant
thinke365 wrote:

> 
> such as uniform distribution, Normal distribution or poisson distribution.
> is there any package that can be used to generate such random numbers.
> 

I remeber being told that adding up 12 random numbers in the range 0-1 
(which is what most computer random number genertors at the time chucked 
out) and subtracted 6 gives a pretty good normal distribution.  I think I 
did try it once and it failed, but I must have done something odd.

-- 
http://www.petezilla.co.uk

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


Re: Perl to Python conversion

2009-12-09 Thread Peter Chant
Martin Schöön wrote:

> Hence, are there any Perl to Python converters? So far I
> have only found bridgekeeper which really is (was?) consultancy.
> Apart from that I only find people recommending a manual re-write.
> 
> Any thoughts/recommendations?

Voice of almost no experience.  I once ran a fortran programme through a 
fortran to c converter and when I saw the result I ran away screaming - it 
did not look very human friendly.




-- 
http://www.petezilla.co.uk

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


Re: python simply not scaleable enough for google?

2009-11-11 Thread Peter Chant
Terry Reedy wrote:

> I can imagine a day when code compiled from Python is routinely
> time-competitive with hand-written C.

In my very limited experience it was very informative programming in C for 
PIC microcontrollers and inspecting the assembly code produced.  If I just 
threw together loops and complex if statements the assembly produced was 
very long and impossible to follow whereas if I though carefully about what 
I was doing, tried to parallel what I would have done in assembly I found 
the assembly produced looked a lot like I imagined it would if I were 
programming in assembler directly.  Except that the whole process was 10x 
faster and actually worked.

Pete

-- 
http://www.petezilla.co.uk

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


Re: Simple audio

2009-10-21 Thread Peter Chant
Simon Forman wrote:

> Someone else will probably give you better advice, but have you looked
> at pygame?  IIRC they have a pretty simple audio playback api.

I'm using pygame for something else.  Will it work without the graphics side 
being used? I suppose trying it is the best plan!

Pete

-- 
http://www.petezilla.co.uk

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


Simple audio

2009-10-20 Thread Peter Chant
What are recommendations for simple audio playback?  I want to play back on 
linux (Slackware), which uses alsa.  There seem to be many ways - but some 
are a couple of years old and won't compile, like pymedia, or seem not 
widely used and need pulseaudio (swmixer) which I have not installed.  I 
want to be able to play sounds from a numpy array and would like it to be 
non-blocking so I can play sounds without locking out a pyQt front end.

Whats the current best way?

Pete


-- 
http://www.petezilla.co.uk

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


Re: Setuptools - help!

2009-08-07 Thread Peter Chant
Robert Kern wrote:

> You need to put main.py into the pphoto package.
> 
> $ mkdir pphoto/
> $ mv main.py pphoto/
> $ touch pphoto/__init__.py
> 

Thanks, it worked.  Any ideas how to run the resulting scripts without
installing or running as root?

Pete


-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Setuptools - help!

2009-08-06 Thread Peter Chant
Chaps,

any ideas, I'm floundering - I don't quite get it.  I have the following
files, setup.py and main.py in a directory pphoto:

# more setup.py
from setuptools import setup, find_packages
setup(
name = "Pphoto",
version = "0.1",
packages = find_packages(),

# other arguments here...
entry_points = {'console_scripts': ['foo = pphoto.main:HelloWorld',]}


)

bash-3.1# more main.py


def HelloWorld():
print "Hello World!"

print "Odd world"


>From various websites that should produce a script foo that runs HelloWorld. 
It does produce a script that simply crashes.

bash-3.1# foo
Traceback (most recent call last):
  File "/usr/bin/foo", line 8, in 
load_entry_point('Pphoto==0.1', 'console_scripts', 'foo')()
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 277, in
load_entry_point
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 2098, in
load_entry_point
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 1831, in load
ImportError: No module named pphoto.main
bash-3.1#


Note, doing this as root as it seems not to do anything usefull at all if I
run python setup develop as a user. 

Any ideas?  I must be missing something fundamental?

Pete


-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Building / making an application

2009-08-02 Thread Peter Chant
Diez B. Roggisch wrote:


> You should consider using setuptools. Then you get an egg that people
> can install, and you can define "console_scripts"-entry-points which
> will be installed into /usr/local/bin or similar locations.

Interesting, I think I need to have a play with that.  The cross platform
bit could be useful as well.

Pete

-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Building / making an application

2009-08-02 Thread Peter Chant
Krishnakant wrote:


> Have you considered creating a deb or rpm package for your application?
> Most of the documentation for deb or rpm will talk about make files.
> But even a distutil based python package (with a setup.py) can be made
> into a deb package.
> Then the your requirement will be satisfied at least for most gnu/linux
> based distros.

I'm a slacker, so what I would do would be to make a slack build, the
slackbuild would take the source and build that.  The stage I am at is
the "how to build the source" stage.  Don't really intend to get as far as
distribution specific packages.

What I could do is create a script in the source root directory (that sounds
a bit overblown) that simply concatenates together all the python files in
the right order and perhaps copies the result to /usr/local/bin or /usr/bin
as appropriate.  Is that the right way to go?  It looks like distutils is
appropriate only for modules.  

OTOH it might be appropriate to put the bulk of an application in a module
and have a function calling it the only part of the main script.

Pete

-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Building / making an application

2009-08-02 Thread Peter Chant
What is a good way to do this?  There are instructions on making modules at:

http://docs.python.org/distutils/setupscript.html

however, what do you do if you don't want a module?  I'm thinking of where
I'd like to split the code into several files and have a build / setup
script put it together and install it somewhere such as /usr/local/bin. 
I'm interested in what the standard way of doing this is.

Thanks,

Pete



-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python graphics / imaging library

2009-07-18 Thread Peter Chant
Max Erickson wrote:

> More recent months contain updates to the status of 1.1.7, it is
> headed towards a release. Preliminary tarballs and binaries are
> available on effbot.org:
> 
> http://effbot.org/downloads/#imaging
> http://effbot.org/downloads/#pil

Excellent.  From a very brief look it seems like it will be quite simple to
use.

Pete


-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python graphics / imaging library

2009-07-18 Thread Peter Chant
Peter Chant wrote:


> 
> No, it does not.  However, if PIL was updated last in 2006.  Python in
> 2009
> has gone to version 3.1.  If PIL is compatible with 3.1 then I'm fine. 
> But I don't want to have to stick with Python 2.5 as the rest of the world
> moves on.

BTW, this was not a critisism of PIL or GD, rather what do people generally
use now?

-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python graphics / imaging library

2009-07-18 Thread Peter Chant
Michiel Overtoom wrote:

> Peter Chant wrote:
> 
>> what's the most appropriate (maintained) graphics library to use?  PIL
>> seems to have last been updated in 2006
>> http://www.pythonware.com/products/pil/
>> and GD seems to be even older.  Don't want to go down a dead end.
> 
> Contrary to organic material, software doesn't rot when it gets older.
> 
> PIL is pretty complete for the task it was designed to do, pretty
> debugged during the past years, and pretty much 'finished' -- it doesn't
> need frequent updates anymore.
> 
> Greetings,
> 

No, it does not.  However, if PIL was updated last in 2006.  Python in 2009
has gone to version 3.1.  If PIL is compatible with 3.1 then I'm fine.  But
I don't want to have to stick with Python 2.5 as the rest of the world
moves on.

Pete


-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Python graphics / imaging library

2009-07-18 Thread Peter Chant
Chaps,

what's the most appropriate (maintained) graphics library to use?  PIL seems
to have last been updated in 2006 http://www.pythonware.com/products/pil/
and GD seems to be even older.  Don't want to go down a dead end.

Pete

-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


PyGame font issues

2009-04-27 Thread Peter Chant
Chaps,

I have the following code:

if pygame.font:
font = pygame.font.Font(None, 36)
#font = pygame.font.Font('liberationserif',36)
text = font.render("Esc to quit.", 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)

but I get the error:

Traceback (most recent call last):
  File "g6.py", line 77, in 
font = pygame.font.Font(None, 36)
RuntimeError: default font not found 'freesansbold.ttf'
bash-3.1$  

Now swapping the comments on the font= lines to use liberationserif which
definitely is on my system I get a similar fault.  Any suggestions on a
remidy?

-- 
http://www.petezilla.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie SWMixer / numpy help - AssertionError

2009-02-08 Thread Peter Chant
Robert Kern wrote:

> 
>snd = swmixer.Sound(data=tone_data)
> 
> Well, sort of. You probably need to scale your data and convert it to
> int16 format. It's currently in floating point format.

Done and working, thanks.  As "file" was not needed for file="test.wav" I
assumed the data prefix for data was not essential.

> 
> When asking about why something fails, it helps a lot if you specify
> exactly how it fails and what you expected to happen. Copy-and-paste any
> error messages exactly.

OK

> 
> If you need more help with SWMixer's API, I recommend asking the author.
> It's not in widespread use, so he can probably give you better and faster
> help than we can.
> 
> If you need more help with numpy, specifically, you can ask on the
> numpy-discussion mailing list. numpy *is* in widespread use, but there's a
> higher concentration of helpful numpy users over there.
> 
>http://www.scipy.org/Mailing_Lists
> 

Most useful response, thanks.

Pete

-- 
http://www.petezilla.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Newbie SWMixer / numpy help - AssertionError

2009-02-07 Thread Peter Chant
Hello,

I'm a bit of a python newby.  I want to play and record sound
simultaneously.  SWMixer seems able to do this but the examples use WAV
files.  I'm trying to play a test tone.  Can anyone give me a steer as to
why this fails?

import sys
import swmixer
import numpy


swmixer.init(samplerate=44100, chunksize=1024, stereo=False,
microphone=True)
#snd = swmixer.Sound("test1.wav")
time = 1
freq = 440
time = numpy.linspace(0,1,44100*time)   # 44100 numbers between 0 and 1
tone_data = numpy.sin(time*2*numpy.pi*freq) # A above Middle C
snd = swmixer.Sound(tone_data)

snd.play(loops=-1)

I know this may be in a little at the deep end for someone who has just
started to learn python, but I find I learn a lot faster if I try to do
something that is useful.

Pete


-- 
http://www.petezilla.co.uk
--
http://mail.python.org/mailman/listinfo/python-list