Re: sending bytes to parallel port

2006-07-29 Thread Diez B. Roggisch
> *sigh*
> if only pyparallel would install

*sigh* If only you said _what_ failed we could maybe help you make it 
work... :)

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


Re: How to find difference in years between two dates?

2006-07-29 Thread thebjorn
John Machin wrote:
> I don't understand. The examples that I showed went from the last day
> of a month to the last day of another month. [...]

Q1: is ((date-4days)+4days) == date?
Q2: is (((date-4days)+1month)+4days) == date+1month?

Ok, let's use Python'ish syntax (including numbering the days from 0
upwards, and backwards from -1, the last day of the month), you want
the last day of a month plus a month be the last day of the next
month. Simplistically, something like:

   month[-1] + 1 month == (month+1)[-1]   {last-to-last}

but that's obviously not the entire rule you want, unless 4-30 + 1
month == 5-31? So you would also like to have:

   month[i] + 1 month = (month+1)[i] {lock-step}

we'd like yesterday to be a day ago? So for suitable i:

   month[i] - 1 day == month[i-1]  {yesterday-1}
   month[0] - 1 day == (month-1)[-1]   {yesterday-2}

which leads to a natural definition for when tomorrow is:

   month[i] + 1 day == month[i+1]   {tomorrow-1}
   month[-1] + 1 day == (month+1)[0]{tomorrow-2}

So far so good. Now let's count backwards:

   month[-1] - 1 day == month[-2]  
   month[-2] - 1 day == month[-3]  
   month[-3] - 1 day == month[-4]  
   etc.

In other words, if you insist that the last day of the month is a well
defined concept and you want a day ago to be yesterday then month[-4],
the forth-to-last day of the month, is necessarily also well
defined. Having a well defined month[i], I'll apply your rules for
adding a month:

   month[-4] + 1 month == (month+1)[-4]   

but you don't like this, because that means that e.g.:

   april[-4] + 1 month == may[-4]
   april[27] + 1 month == may[28]

which in addition to {lock-step}:

   april[27] + 1 month == may[27]

either gives an inconsistent, ill-formed, or FUZZY system (although
I would call it "regular" ;-)

My approach is simpler since it doesn't define addition, only
subtraction on valid dates, so if I switch to representing dates as
(month, day):

   (a, b) - (c, d) := a - c   iff b < d   {subtract}
 else a - c - 1

{subtract} is irregular but well defined for all valid dates (it will
always give you an answer, and it's always the same answer ;-) :

   (2,29) - (1,31) == 0
   (3,1) - (1,31) == 2

I can add "day addition" and still be ok:

   (m,d) + 1 day := (m,d+1){tomorrow-1}
   (m,-1) + 1 day := (m+1,0)   {tomorrow-2}
   (m,d) - 1 day := (m,d-1)   {yesterday-1}
   (m,0) - 1 day := (m-1,-1)  {yesterday-2}

Now my system is well-formed and consitent, even though it is
irregular, and it will answer yes to Q1 above. I can't see a way of
adding month addition to this and stay consistent without enumerating
special cases for every month, so Q2 can't even be asked in my system.

> > You're entitled to your opinion.
>
> And you to yours :-)

Ok, I've explained why I hold mine... You care to do the same?

-- bjorn

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


Re: sending bytes to parallel port

2006-07-29 Thread Timothy Smith
Diez B. Roggisch wrote:
>> *sigh*
>> if only pyparallel would install
>> 
>
> *sigh* If only you said _what_ failed we could maybe help you make it 
> work... :)
>
> Diez
>   
titan# python setup.py install
running install
running build
running build_py
Traceback (most recent call last):
  File "setup.py", line 19, in ?
package_data = data_files
  File "/usr/local/lib/python2.4/distutils/core.py", line 149, in setup
dist.run_commands()
  File "/usr/local/lib/python2.4/distutils/dist.py", line 946, in
run_commands
self.run_command(cmd)
  File "/usr/local/lib/python2.4/distutils/dist.py", line 966, in
run_command
cmd_obj.run()
  File "/usr/local/lib/python2.4/distutils/command/install.py", line
506, in run
self.run_command('build')
  File "/usr/local/lib/python2.4/distutils/cmd.py", line 333, in run_command
self.distribution.run_command(command)
  File "/usr/local/lib/python2.4/distutils/dist.py", line 966, in
run_command
cmd_obj.run()
  File "/usr/local/lib/python2.4/distutils/command/build.py", line 112,
in run
self.run_command(cmd_name)
  File "/usr/local/lib/python2.4/distutils/cmd.py", line 333, in run_command
self.distribution.run_command(command)
  File "/usr/local/lib/python2.4/distutils/dist.py", line 965, in
run_command
cmd_obj.ensure_finalized()
  File "/usr/local/lib/python2.4/distutils/cmd.py", line 117, in
ensure_finalized
self.finalize_options()
  File "/usr/local/lib/python2.4/distutils/command/build_py.py", line
60, in finalize_options
self.data_files = self.get_data_files()
  File "/usr/local/lib/python2.4/distutils/command/build_py.py", line
120, in get_data_files
filenames = [
  File "/usr/local/lib/python2.4/distutils/command/build_py.py", line
128, in find_data_files
globs = (self.package_data.get('', [])
AttributeError: 'NoneType' object has no attribute 'get'
titan#

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


Re: HERE I BUILT A QUICK MATRIX TOOOK 5 MINS

2006-07-29 Thread H J van Rooyen
"Grant Edwards" <[EMAIL PROTECTED]> wrote:

| On 2006-07-28, Paul McGuire <[EMAIL PROTECTED]> wrote:
| >> ...USING A INFINITE MAGENTIC
| >> FIELD!!!
| >
| > I have a vision of a sweeping magenta fabric rippling through the cosmos.
| >
| > Perhaps a mauvic, cyanic, or even aubergenic field would be more stylish.
|
| depends on what shoes you choose to go with it.
|
| --
| Grant Edwards   grante Yow!  My uncle Murray
|   at   conquered Egypt in 53
|visi.comB.C. And I can prove
|it too!!

I find myself in the unenviable position that I can no longer remember the
colour of magic as expressed in Terry Pratchett's books - was it something like
Octarine?

- Hendrik

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


Re: How to force a thread to stop

2006-07-29 Thread H J van Rooyen
"Paul Rubin"  Writes:



| "H J van Rooyen" <[EMAIL PROTECTED]> writes:
| > *grin* - Yes of course - if the WDT was enabled - its something that
| > I have not seen on PC's yet...
|
| They are available for PC's, as plug-in cards, at least for the ISA
| bus in the old days, and almost certainly for the PCI bus today.

That is cool, I was not aware of this - added to a long running server it will
help to make the system more stable - a hardware solution to hard to find bugs
in Software - (or even stuff like soft errors in hardware - speak to the
Avionics boys about Neutrons) do you know who sells them and what they are
called? -

Sorry if this is getting off topic on this thread... ( in a way it is on topic -
because a reset will stop a thread every time...)

- Hendrik

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


Re: How to force a thread to stop

2006-07-29 Thread H J van Rooyen

"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote:

| On Fri, 28 Jul 2006 08:27:18 +0200, "H J van Rooyen"
| <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
|
| >
| > Dennis - did your OS not have a ticker running?
| >
| That ancient machine, while round-robin, multi-priority,
| pre-emptive, seemed still to only "deliver" signals on deliberate
| blocking calls -- perhaps to prevent potential corruption if the signal
| had been delivered(handled) in the middle of some multi-instruction
| sequence. The OS level would "see" the , and set the signal bit
| in the task header -- but without the blocking I/O (typically), the code
| to activate a registered signal handler would not be invoked. Operation
| was something like: submit I/O request, AND(signal bits, signal mask) --
| invoke handler if non-zero, block for I/O return [or return directly for
| asynchronous I/O request]

- Hah! - so it *could* have responded - it just chose not to - so it was pre
emptive - but hey - what is different between modern OS's and what you are
describing? - it seems to me that there is just a lot of extra memory control,
as well as control over who is allowed to do what - in an effort to make things
more stable - and all this stuff just eats cycles and slows you down... (or
alternatively, makes the hardware more complex and expensive...)

But to get back to the OP's problem - basically the thread has to see some sort
of variable change, or receive a message (by examining something to see if there
is a message there) and then kill itself, or the OS must be told to stop giving
control back to the thread in question - which option will leave all the loose
ends in the thread loose...

So its either: "hey mr nice thread please stop" - or "hey Mr OS - kill that
thread ..." - now from the OS viewpoint - if the application implements some
threading itself - it may not even know that the thread exists - OS threads are
known variously as "Tasks" or "Processes" or "Running Programmes" - so using the
big guns on a thread may not be possible without killing the parent too...

So if you want to use the OS to kill the thread - it has to be a formal OS
thread - something started with a call to the OS, and not something that an
application implements by itself - and I am not familiar enough with Python
threading and dummy threading to pretend to know what is "under the hood" - but
I haven't seen an additional process appearing on my Linux box when I start a
thread - so its either something that Python does on its own without
"registering" the new thread with Linux - or I haven't looked closely enough...

So if somebody else can take over here, we might convince the OP that "hey mr
nice thread" is the way to go, even in the case that the "thread" in question is
an OS Process - after all - there has to be inter - task communication in any
case - so the cleanest solution is to build the kill in right from scratch...

Why do I think of COBOL:

read master_file_record at end go to end_routine

HTH   - Hendrik


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


Re: sending bytes to parallel port

2006-07-29 Thread H J van Rooyen
"Timothy Smith" <[EMAIL PROTECTED]> wrote:


| Grant Edwards wrote:
| > On 2006-07-28, Timothy Smith <[EMAIL PROTECTED]> wrote:
| >
| >
| >> i've been trying to send an 8 byte string to my parallel port
| >> under freebsd. the purpose is it to control a relay board. the
| >> board simply responds to the output byte coming from the port.
| >> eg.  0001 will set pin 1 high and flick the relay open.
| >> todate i've attempted this with merely open() on /dev/ppi0 and
| >> numpy for the byte array, but i just can't seem to get it
| >> working. i know the parallel port works and i know the relay
| >> board works (tested it with it's own windows ultility) so it's
| >> just my crappy programming keeping me from success.
| >>
| >
| > I'm guessing there's an implied request for help there
| > somewhere.  This would be a good start:
| >
| >   http://www.google.com/search?q=python+parallel+port
| >
| > I'd particularly recommend taking a look at the pyparallel
| > module found here:
| >
| >   http://pyserial.sourceforge.net/
| >
| > I've not used pyparallel, but based on my experience with
| > pyserial and some of Chris Liechti's other work, I'd bet
| > dollars to doughnuts it's your best option.
| >
| >
| yes, i did try pyparallel however it will not install on freebsd,
| setup.py errors.
|
| and yes i've done quite a bit of googling, i never expected it to be
| this difficult. i've done work with serial ports before. never parallel but.

What is on the other side of the link? - if its a small 8 bit micro - you may
simply be going too fast...

- Hendrik

|

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


Re: War chest for writing web apps in Python?

2006-07-29 Thread Rob Sinclar
On Saturday 29 July 2006 03:43, Nick Vatamaniuc wrote:
> Aptitude, are you still using that? Just use Synaptic on Ubuntu. The
> problem as I wrote in my post before is that for some IDEs you don't
> just download an executable but because they are written for Linux
> first, on  Windows you have to search and install a lot of helper
> libraries that often takes quite a bit of time.
>
> And why do you want to spend half an hour searching for stuff when you
> can do just spend 1 minute in a nice graphical installer or use apt-get
> install on the command line to  install it.
>
> I am using Ubuntu primarily because it has the .deb system which I
> found to be much better mentained and which deals with dependecies a
> lot better.
>
> Nick V.

Synaptic is using aptitude as back-end (this is serious).
I also find deb system being the best. Managed with aptitude, not apt.
Windows is definitely worth the effort.

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


Re: metaclass : parse all class once before doing anything else ?

2006-07-29 Thread Diez B. Roggisch
Laurent Rahuel schrieb:
> I got a metaclass named Foo


I have the impression that you are not talking about a meta-class, but a 
normal class here.

> Then I got two others classes:
> 
> class Bar(Foo):
> pass
> 
> class Baz(Foo):
> pass
> 
> I know how to add some attrs, methods to Bar and Baz when the module is
> loaded but I need to do something more :
> 
> Before adding anything to these classes, 
> 1 - I need to parse all defined Foo classes
> 2 - "sort" them 
> 3 - parse this sorted list to add attrs and methods.
> 
> This seems to be really to clever for me ;-(
> 
> Any idea ?

Why do you want to do this? It is in that way not possible - python has 
no preprocessing step that would allow this.

I suggest you explain to us what you are after here, and then we might 
come up with a solution.

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


Re: War chest for writing web apps in Python?

2006-07-29 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Rob Sinclar
wrote:

> Synaptic is using aptitude as back-end (this is serious).

Why can I deinstall aptitude without deinstalling synaptic then!?

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


Re: How to force a thread to stop

2006-07-29 Thread Paul Rubin
"H J van Rooyen" <[EMAIL PROTECTED]> writes:
> That is cool, I was not aware of this - added to a long running server it will
> help to make the system more stable - a hardware solution to hard to find bugs
> in Software - (or even stuff like soft errors in hardware - speak to the
> Avionics boys about Neutrons) do you know who sells them and what they are
> called? -

I usually try froogle.com to find stuff like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HERE I BUILT A QUICK MATRIX TOOOK 5 MINS

2006-07-29 Thread Diez B. Roggisch
> I find myself in the unenviable position that I can no longer remember the
> colour of magic as expressed in Terry Pratchett's books - was it something 
> like
> Octarine?

AFAIK yes.

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


Re: War chest for writing web apps in Python?

2006-07-29 Thread Diez B. Roggisch
> Synaptic is using aptitude as back-end (this is serious).

No. It uses apt.

> I also find deb system being the best. Managed with aptitude, not apt.
> Windows is definitely worth the effort.

aptitude as well as synaptic both depend transitive upon debconf, which 
depends on apt.

Use

apt-cache dotty synaptic

to explore the dependency-graph.

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


Re: How to force a thread to stop

2006-07-29 Thread Damjan
> | A common recovery mechanism in embedded systems is a watchdog timer,
> | which is a hardware device that must be poked by the software every
> | so often (e.g. by writing to some register).  If too long an interval
> | goes by without a poke, the WDT hard-resets the cpu.  Normally the
> | software would poke the WDT from its normal periodic timing routine.
> | A loop like you describe would stop the timing routine from running,
> | eventually resulting in a reset.
> 
> *grin* - Yes of course - if the WDT was enabled - its something that I
> have not seen on PC's yet...

The intel 810 chipset (and all after that) has a builtin watchdog timer -
unfortunetally on some motherboards it's disabled (I guess in the BIOS).

How do I know that?
Once I got Linux installed on a new machine and although the install
went without a problem, after the first boot the machine would reboot on
exactly 2 minutes. 
After a bit of poking around I found that hotplug detected the WDT support
and loaded the driver for it (i8xx_tco), and it seems the WDT chip was set
to start ticking right away after the driver poked it. 



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


Re: metaclass : parse all class once before doing anything else ?

2006-07-29 Thread Paddy

Laurent Rahuel wrote:
> Hi,
>
> I have a much to smart problem for my brain.
>
> Here is the deal :
>
> I got a metaclass named Foo
>
> Then I got two others classes:
>
> class Bar(Foo):
> pass
>
> class Baz(Foo):
> pass
>
> I know how to add some attrs, methods to Bar and Baz when the module is
> loaded but I need to do something more :
>
> Before adding anything to these classes,
> 1 - I need to parse all defined Foo classes
> 2 - "sort" them
> 3 - parse this sorted list to add attrs and methods.
>
> This seems to be really to clever for me ;-(
>
> Any idea ?
>
> Regards,
>
> Laurent.

I, like Diez am unsure of why you would need what you have asked for,
but maybe this will help.

You can keep  track of all instances of a class by this kind of thing:

>>> class C1(object):
... inst = []
... def __init__(self):
... self.inst.append(self)
...
>>> i1 = C1()
>>> i2 = C1()
>>> print i1,i2
<__main__.C1 object at 0x0128C970> <__main__.C1 object at 0x0128CA50>
>>> print C1.inst
[<__main__.C1 object at 0x0128C970>, <__main__.C1 object at
0x0128CA50>]
>>>

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


testing for data type

2006-07-29 Thread Jonathan Bowlas








Hi Listers,

 

I have a requirement to test for a data type could someone
tell me if this is possible in python?

 

Basically I have a ZPT in Zope that users can select checkboxes
in a form which pass arguments for a python function, however if there is only
one checkbox selected it is passed as a string whereas more than one checkbox
is passed as a list. Therefore if my function is required to perform an action
based on each argument passed in the list the function works correctly but if
it is passed as a string nothing happens.

 

This is my function:

selecteddeptcodes = context.REQUEST.DEPTCODE

currentstatus = context.REQUEST.STATUS

 

if currentstatus == 'pending':

 for dptcd in selecteddeptcodes:

   context.changetolive(DEPTCODE=dptcd)

if currentstatus == 'old':

 for dptcd in selecteddeptcodes:

   context.changetopending(DEPTCODE=dptcd)

return context.pub_dept_form(context, context.REQUEST,
message='Updated Status')

 

The argument in question is selecteddeptcodes.

 

I tried to make my function conditional based on the length
of the argument passed but if it’s just one checkbox value passed the
length of the argument is 2 (which is the number of chars passed in the string)
and if there are two checkboxes the length of the argument (which is the number
of items in the list) is also 2. So that doesn’t help.

 

Any assistance would be appreciated.

 

Jon






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

Partial Classes - Aspects

2006-07-29 Thread Dr. Peer Griebel
I'm currently writing a small toy application to support symbolic
algebra.  Therefore I implemented some classes Term, Var, Number, Sum,
Product, Power.  These classes are tightly coupled.  So it is not
possible to organize them in distinct files. This would result in
cyclic imports.

To manage the complexity I implemented some sort of aspect oriented
programming (perhaps aspect oriented programming is not quite right in
this context...). That is I implemented a mechanism to dynamically add
methods to existing classes.  This is similar to the thread "Partial
classes" discussed in this list.  Therefore hereby offer some use case
for partial classes.

The aspects I already implemented are amongst others: pretty printing,
differentiation, expansion of terms.  The aspect for expansion looks
like this:


# -*- coding: iso-8859-1 -*-
__aspect__ = "Expand"

class TermExpand:
def expand(self):
return self

class SumExpand:
def expand(self):
...

def expandSum(term, sum):
# some helper function
...

class ProductExpand:
def expand(self):
...

class PowerExpand:
def expand(self):
...



The code to import an aspect into existing classes accepts as a
parameter the name of a module.  The module will be imported.
Afterwards the code iterates over all elements defined in the module.
If it is a (specially named) class all methods will be copied to the
original class.  If it is a (top level) function it will be copied into
the global namespace.  E.g. the method expand of the class TermExpand
will be copyied to the base class Term.

The difficulty with this approach is that the classes' methods and the
functions do operate in the wrong global namespace.  Since these
functions/methods are located in their own module they get their own
namespace.  To correct this I have to use new.function() to create new
methods/functions with the correct namespace (which is the base
module's namespace).

So my questions boil down to this:

* Do you think this is a sound approach to structure my code?
* I don't like the necessity to modify the functions. Is there a
simpler approach? 

Thanks,
  Peer

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


Re: Comma is not always OK in the argument list?!

2006-07-29 Thread Roman Susi
Nick Vatamaniuc wrote:

>True, that is why it behaves the way it does, but which way is the
>correct way? i.e. does the code need updating or the documentation?
>
>  
>
Perhaps, someone can make a bug report... IMHO, docs are wrong.

-Roman

>-Nick V.
>
>[EMAIL PROTECTED] wrote:
>  
>
>>Nick Vatamaniuc wrote:
>>
>>
>>>Roman,
>>>
>>>According to the Python call syntax definition
>>>(http://docs.python.org/ref/calls.html) commas should be allowed, so it
>>>seems like a minor bug.  Here are the  lines in question:
>>>-http://docs.python.org/ref/calls.html---
>>>call ::= primary "(" [argument_list [","]] ")"
>>>argument_list::=positional_arguments ["," keyword_arguments] ["," "*"
>>>expression] ["," "**" expression]
>>> | keyword_arguments ["," "*" expression] ["," "**" expression]
>>>| "*" expression ["," "**" expression]
>>>| "**" expression
>>>--
>>>If you notice in the 'call' definition, no matter what the
>>>'argument_list' is, it can be followed by an optional ',' right before
>>>the closing ')'. Your code is a counterexample to this. Here is a more
>>>exhaustive example:
>>>
>>>  
>>>
>>Actually, in the real BNF it's not allowed:
>>
>>http://svn.python.org/view/python/trunk/Grammar/Grammar?rev=46209&view=markup
>>
>>parameters: '(' [varargslist] ')'
>>varargslist: ((fpdef ['=' test] ',')*
>>  ('*' NAME [',' '**' NAME] | '**' NAME) |
>>  fpdef ['=' test] (',' fpdef ['=' test])* [','])
>>fpdef: NAME | '(' fplist ')'
>>
>>
>
>  
>

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


Re: Need a compelling argument to use Django instead of Rails

2006-07-29 Thread Vincent Delporte
On Sat, 29 Jul 2006 04:07:12 GMT, Tim Roberts <[EMAIL PROTECTED]> wrote:
>Exactly.  The Python interpreter can take a significant fraction of a
>second to start.  For the typical short web request, the overhead can add
>up.
>
>On the other hand, unless you're handling dozens of requests per minute,
>users are unlikely to notice.
>
>You can also keep session state in memory instead of spilling to disk, and
>you can keep database sessions open.

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


Re: War chest for writing web apps in Python?

2006-07-29 Thread Rob Sinclar
> > Synaptic is using aptitude as back-end (this is serious).
>
> Why can I deinstall aptitude without deinstalling synaptic then!?
>
> Ciao,
>   Marc 'BlackJack' Rintsch

Hi,
This is because Aptitude is an independant console application
that is very useful to users working on linux machines without
X server installed.

Synaptic is the interface which leads the underlying application.
Synaptic is often installed with a 
$ aptitude install synaptic

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


Re: War chest for writing web apps in Python?

2006-07-29 Thread gslindstrom
Sybren Stuvel wrote:
> Vincent Delporte enlightened us with:
> > I'm thinking of using Python to build the prototype for a business
> > web appplication.
>
> Why just the prototype?
>

I don't know about Vincent, but I once worked in a "C++" shop where all
other languages were actively discouraged.  I would build my prototypes
in Python to show proof of concept because I could do it quickly.  It
was also nice to show project managers so they could verify it was what
they wanted us to build before we dedicated a full time effort to
development.

I recall once prototype I created in wxWindows; when I showed it to my
boss he exclaimed "That's Python!?".  He was amazed because it looked
just like the windows apps we developed!

Having moved on to another company where we develop in Python
full-time, I hear my former shop now has many Python (and Perl and
Java) programmers.

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


Re: War chest for writing web apps in Python?

2006-07-29 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Rob Sinclar
wrote:

>> > Synaptic is using aptitude as back-end (this is serious).
>>
>> Why can I deinstall aptitude without deinstalling synaptic then!?
>>
>
> This is because Aptitude is an independant console application
> that is very useful to users working on linux machines without
> X server installed.

I know what aptitude is…
 
> Synaptic is the interface which leads the underlying application.

…but I ask why I can deinstall it and still use synaptic if it's using
aptitude as back-end as you seriously claim!?

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

Re: Fastest Way To Loop Through Every Pixel

2006-07-29 Thread Chaos

nikie wrote:
> Chaos wrote:
>
> > As my first attempt to loop through every pixel of an image, I used
> >
> > for thisY in range(0, thisHeight):
> > for thisX in range(0, thisWidth):
> >   #Actions here for Pixel thisX, thisY
> >
> > But it takes 450-1000 milliseconds
> >
> > I want speeds less than 10 milliseconds
>
> Milliseconds don't mean much unless we knew how big your images are and
> what hardware you're using.
>
> Have you considered using NumPy? Assuming you can get the image into a
> numpy array efficiently, the actual algorithm boils down to something
> like this:
>
> grey = r*0.3 + g*0.59 + b*0.11
> index = grey.argmin()
> x,y = index%step, index/step
> v = grey[x,y]
>
> where r,g,b and grey are numpy.ndarray objects; The arithmetic
> operators and the argmin-function are implemented in C, so you can
> expect decent performance. (the 4 lines above take about 80 ms for a
> 1000x1000 image on my PC)
>
> If that's not enough, you might want to use some specially optimized C
> library for this purpose. (I'd suggest Intel's IPP, but there are
> others).

Can you give me an example of geting an image into a numpy array?

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


Re: Fastest Way To Loop Through Every Pixel

2006-07-29 Thread Chaos

nikie wrote:
> Chaos wrote:
>
> > As my first attempt to loop through every pixel of an image, I used
> >
> > for thisY in range(0, thisHeight):
> > for thisX in range(0, thisWidth):
> >   #Actions here for Pixel thisX, thisY
> >
> > But it takes 450-1000 milliseconds
> >
> > I want speeds less than 10 milliseconds
>
> Milliseconds don't mean much unless we knew how big your images are and
> what hardware you're using.
>
> Have you considered using NumPy? Assuming you can get the image into a
> numpy array efficiently, the actual algorithm boils down to something
> like this:
>
> grey = r*0.3 +

 g*0.59 + b*0.11
> index = grey.argmin()
> x,y = index%step, index/step
> v = grey[x,y]
>
> where r,g,b and grey are numpy.ndarray objects; The arithmetic
> operators and the argmin-function are implemented in C, so you can
> expect decent performance. (the 4 lines above take about 80 ms for a
> 1000x1000 image on my PC)
>
> If that's not enough, you might want to use some specially optimized C
> library for this purpose. (I'd suggest Intel's IPP, but there are
> others).

I really do not understand the code. Where did you get the varibales r,
g, b and step and what does v produce?

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


Re: non-blocking PIPE read on Windows

2006-07-29 Thread Antonio Valentino
"placid" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> Hi all,
> 
> I have been looking into non-blocking read (readline) operations on
> PIPES on windows XP and there seems to be no way of doing this. Ive
> read that you could use a Thread to read from the pipe, but if you
> still use readline() wouldnt the Thread block too?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554

> What i need to do is, create a process using subprocess.Popen, where
> the subprocess outputs information on one line (but the info
> continuesly changes and its always on the same line) and read this
> information without blocking, so i can retrieve other data from the
> line i read in then put this in a GUI interface.
> 
> 
> readline() blocks until the newline character is read, but when i use
> read(X) where X is a number of bytes then it doesnt block(expected
> functionality) but i dont know how many bytes the line will be and its
> not constant so i cant use this too.
> 
> Any ideas of solving this problem?
> 
> 
> Cheers

I realized something very similar to what you described in 

http://sourceforge.net/projects/bestgui

- the subprocess2.py module realizes the non blocking I/O
- the outputparser.py module processes the output from the controlled
process and updates the progress-bar, the status-bar and the log
messages in the GUI. Incomplete lines are stored in a buffer and
processed at the next read.

ciao

-- 
Antonio Valentino



-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comma is not always OK in the argument list?!

2006-07-29 Thread Nick Vatamaniuc
Roman,

The way  I see it, it could be either way. In other words if I can
write f(1,2,3) and f(1,2,3,) I should also be able to write
f(1,*[2,3],). It is a really small detail but there sould be some
consistency. Either no extra commas for all kinds of argument types or
extra commas for _all_ of them. It seems though also that if it is
possible to do it with lists, tuples and dictionaries, it should also
be possible to do it with argument lists. In other words if (1,2,3,)
makes sense so should func(1,2,3,) even when written as
func(1,2,*[3],).

Well you are the one who discovered this so you shoud be the one
submitting the bug report! Here is PEP 3 page with the guidelines for
bug reporting:
http://www.python.org/dev/peps/pep-0003/

Just mark it as a very low priority since it is more of a cosmetic bug
than a serious showstopper.

-Nick V


Roman Susi wrote:
> Nick Vatamaniuc wrote:
>
> >True, that is why it behaves the way it does, but which way is the
> >correct way? i.e. does the code need updating or the documentation?
> >
> >
> >
> Perhaps, someone can make a bug report... IMHO, docs are wrong.
>
> -Roman
>
> >-Nick V.
> >
> >[EMAIL PROTECTED] wrote:
> >
> >
> >>Nick Vatamaniuc wrote:
> >>
> >>
> >>>Roman,
> >>>
> >>>According to the Python call syntax definition
> >>>(http://docs.python.org/ref/calls.html) commas should be allowed, so it
> >>>seems like a minor bug.  Here are the  lines in question:
> >>>-http://docs.python.org/ref/calls.html---
> >>>call ::= primary "(" [argument_list [","]] ")"
> >>>argument_list::=positional_arguments ["," keyword_arguments] ["," "*"
> >>>expression] ["," "**" expression]
> >>>   | keyword_arguments ["," "*" expression] ["," "**" expression]
> >>>| "*" expression ["," "**" expression]
> >>>| "**" expression
> >>>--
> >>>If you notice in the 'call' definition, no matter what the
> >>>'argument_list' is, it can be followed by an optional ',' right before
> >>>the closing ')'. Your code is a counterexample to this. Here is a more
> >>>exhaustive example:
> >>>
> >>>
> >>>
> >>Actually, in the real BNF it's not allowed:
> >>
> >>http://svn.python.org/view/python/trunk/Grammar/Grammar?rev=46209&view=markup
> >>
> >>parameters: '(' [varargslist] ')'
> >>varargslist: ((fpdef ['=' test] ',')*
> >>  ('*' NAME [',' '**' NAME] | '**' NAME) |
> >>  fpdef ['=' test] (',' fpdef ['=' test])* [','])
> >>fpdef: NAME | '(' fplist ')'
> >>
> >>
> >
> >  
> >

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


Re: Client/Server Question

2006-07-29 Thread Dennis Benzinger
[EMAIL PROTECTED] wrote:
> Is os.system() going to be deprecated in future ?.I read somewhere.
> [...]

Sometime in the future it will. But that won't happen soon. Read the 
second paragraph of "Backwards Compatibility" in the subprocess PEP 
.


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


system programign

2006-07-29 Thread oqestra
may i use python to read a file and output its content to another file
which is not created yet and i don't want to use ">" to do this in
linux? how do you do ? oqestra.

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


=?utf-8?Q?Re:_ANN:_4_New_ShowMeDo.com_Videos_=28Wing_IDE, _RUR=2DPLE_=282=29, _PataPata=29?=

2006-07-29 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: system programign

2006-07-29 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, oqestra wrote:

> may i use python to read a file and output its content to another file
> which is not created yet and i don't want to use ">" to do this in
> linux?

Read the documentation about `open()`.  Simple example:

in_file = open('old.txt', 'r')
out_file = open('new.txt', 'w')
for line in in_file:
out_file.write(line)
in_file.close()
out_file.close()

how do you do ?

I'm fine, thanks.  ;-)

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


install python on cdrom

2006-07-29 Thread Fabian Braennstroem
Hi,

I look for an easy way to use the newest scipy, pyvtk, matplotlib,
f2py, numpy, paraview/vtk,... on a entreprise redhat machine
without administration rights.
My first thought was to install the whole new python system
on a cdrom/dvd and mounting it, when I need it. Would that
be the easiest way? I would be glad to read some
hints about the way doing it... 

Greetings!
 Fabian

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


Re: Client/Server Question

2006-07-29 Thread bryanjugglercryptographer

[EMAIL PROTECTED] wrote:
> My server.py looks like this
>
> -CODE--
> #!/usr/bin/env python
> import socket
> import sys
> import os
>
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> host = ''
> port = 2000
>
> s.bind((host,port))
> s.listen(1)
> conn, addr = s.accept()
> print 'client is at', addr
>
> while True:
>   data = conn.recv(100)
>   if (data == 'MaxSim'):
>   print 'MaxiSim'
>   os.system('notepad')
>   elif (data == 'Driving Sim'):
>   print 'Driving Sim'
>   os.system('explorer')
>   elif (data == 'SHUTDOWN'):
>   print 'Shutting down...'
>   os.system('shutdown -s')
>   conn.close()
>   break
> ---CODE
> END-
>
> I am running this above program on a windows machine. My client is a
> Linux box. What I want to achieve is that server.py should follows
> instructions till I send a 'SHUTDOWN' command upon which it should shut
> down.
>
> When I run this program and suppose send 'MaxSim' to it, it launches
> notepad.exe fine, but then after that it doesn't accept subsequent
> command.

As others noted, that's because os.system() blocks.
You have more bugs than that.

The recv() might return "MaxiSimDriving Sim". It could return
"MaxiS" on one call, and "im" on the next. If the remote side
closes the connection, recv() will keep returning the empty
string, and your program will be stuck in an infinite loop.

Did you understand Faulkner's suggustion? Anyone who connects to
TCP port 2000 can invoke "shutdown -s" (which I assume shuts down
your host).


-- 
--Bryan

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


Re: Nested function scope problem

2006-07-29 Thread Antoon Pardon
On 2006-07-29, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 28 Jul 2006 17:48:03 GMT, Antoon Pardon <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>> 
>> That is no reason to say that python has no variables. If someone would
>> explain the difference between objects in some other language and
>> objects in python I wouldn't accept the statement: "python has no
>> objects" either.
>>
>   Python objects can exist without a "variable" bound to them...
> Though typically such would soon be garbage collected 

Well C++ objects can exist without a "variable" bound to them.
We just call them memory leaks 

>   Traditional languages are the other way around... If a variable
> exists, it may exist with no object/value (ie, it is uninitialized -- a
> big problem in C).

What do you call traditional? Lisp is about as old as Fortran AFAIK.

> Python names can not exist (and be used) without
> being bound to some object (even None is a defined object). Attempting
> to use a name that has not been bound gives you the "unbound local" type
> problem.

>   Yes, some other languages do define special flag values so that they
> can detect the usage of an uninitialized item... But the variable itself
> exists regardless; you can not detach the object from the variable
> (except by assigning something else to the variable).

I'm not so sure Python is that different. The fact that you get
an UnboundLocalError, instead of a NameError, suggests that in
the first case, the 'variable' already exists but is bound to
a "Not yet Bound" value. Not so long ago I was discussing some
implementation details of CPython and someone then said that
all local variables are entered into the local scope at call
time. This was to prevent the language to find variables
that are shadowed on a more global scope because the local
variable wasn't boud yet.

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


Re: Nested function scope problem

2006-07-29 Thread Antoon Pardon
On 2006-07-28, Gerhard Fiedler <[EMAIL PROTECTED]> wrote:
> On 2006-07-28 15:20:52, Antoon Pardon wrote:
>
>>> Typically, "variable" implies a data storage location that can take on
>>> different values. Emphasis on "location" -- the name is fixed to a
>>> memory location whose contents can be varied.
>> 
>> That is not true. It may be the case in a number of languages but my
>> experience with lisp and smalltalk, though rather limited, says that no
>> such memory location is implied with the word "variable" in those
>> languages and AFAIK they don't have a problem with the word "variable"
>> either. 
>> 
>>> In Python, the closest would be a mutable object.
>
> Maybe this gets somewhere. Consider variable != constant. Python names are
> variables in that what they refer to (what is associated with them through
> a dict) can be changed, through various means (most commonly assignment).
> They are also variables in that what they refer to (usually) can be
> changed. Whether an assignment or some other command changes the reference
> association or the referenced object is one of the confusing issues with
> Python. But that doesn't make a variable less variable... :)

I think the important thing to remember is that the assignment in Python
is a alias maker and not a copy maker. In languages like C, Fortran,
pascal, the assignment makes a copy from what is on the righthand and
stores that in the variable on the lefthand. In languages like Lisp,
Smalltalk and Python, the assignment essentially makes the lefthand
an alias for the righthand.

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


Re: Nested function scope problem

2006-07-29 Thread Antoon Pardon
On 2006-07-29, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 28 Jul 2006 18:20:52 GMT, Antoon Pardon <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>
>> That is not true. It may be the case in a number of languages but
>> my experience with lisp and smalltalk, though rather limited,
>> says that no such memory location is implied with the word "variable"
>> in those languages and AFAIK they don't have a problem with the
>> word "variable" either.
>>
>   I have no smalltalk experience, and my lisp goes back to a cassette
> based version on a TRS-80 Model III...
>
>   Since, at that time at least, everything in lisp was a
> tree-branching linked list I had trouble even considering setq to define
> a "variable" -- it was closer to adding a name to a node of the lists...
> {Yes, that IS a very loose interpretation}
>
>   Does lisp permit one object to have multiple "variables" attached to
> it -- that is, two or more names on one "object" (whatever the node
> contains)...

AFAIK, yes

> And if so, what happens if, say, the "object" had been a
> scalar value "3.14159265436" perhaps and you make an "assignment" to one
> of the names?

About the same as happens in Python. One name will then be attached to
a new "value" and the other names will still be attached to "3.14159265436"

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


Smaple of recursive directory walker

2006-07-29 Thread Traveler
Hello, 

At work I have a directory of about 50 large text files and i need to
search thru them for 10 separate words and print how many were found
in total.

I am new to python so could somebody please show me some sample code
that would help me get this done and i will work from that.

Thanks.

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


Re: sending bytes to parallel port

2006-07-29 Thread Grant Edwards
On 2006-07-29, Timothy Smith <[EMAIL PROTECTED]> wrote:

>> I'd particularly recommend taking a look at the pyparallel
>> module found here:

> yes, i did try pyparallel however it will not install on
> freebsd, setup.py errors.

Ah. I guess freebsd wasn't one of the systems listed on the
pyparallel page -- I should have paid closer attention.

> and yes i've done quite a bit of googling, i never expected it
> to be this difficult. i've done work with serial ports before.
> never parallel but.

Serial ports on PCs are pretty standardized as 16550 UARTs, and
The Unix serial port API was mostly nailed down years ago.

There are at least three different schemes for parallel ports,
and not everybody implements those identically even if they do
claim to be one of the three.  Many motherboard chipsets claim
to do do all three.  On top of that, there doesn't seem to be a
common Unix prallel port API.

-- 
Grant Edwards   grante Yow!  Is this ANYWHERE,
  at   USA?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: War chest for writing web apps in Python?

2006-07-29 Thread SPE - Stani's Python Editor
Nick Vatamaniuc schreef:

> I found Komodo to
> be too slow on my machine, SPE was also slow, was crashing on me and
> had strange gui issues,

I hope you didn't install SPE from the MOTU repositories with synaptic
or apt-get. I use SPE myself daily on Ubuntu and wrote this howto
install SPE on Ubuntu:
http://www.ubuntuforums.org/showthread.php?t=218001&highlight=wxpython

I know that others are running SPE on Ubuntu without problems. The main
point is not to use SPE from the repositories, but from the SPE
website. If the howto is too much just download the -nosetup.zip

Stani
--
http://pythonide.stani.be

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


Re: Nested function scope problem

2006-07-29 Thread Gerhard Fiedler
On 2006-07-29 13:47:37, Antoon Pardon wrote:

> I think the important thing to remember is that the assignment in Python
> is a alias maker and not a copy maker. In languages like C, Fortran,
> pascal, the assignment makes a copy from what is on the righthand and
> stores that in the variable on the lefthand. In languages like Lisp,
> Smalltalk and Python, the assignment essentially makes the lefthand
> an alias for the righthand.

Yes, I think I got it now :) 

It seems that, in essence, Bruno is right in that Python doesn't really
have variables. Everything that seems variable doesn't really change; what
changes is that an element of what seems to change gets rebound. Which in
itself is a rebinding process of a dictionary... I have yet to go there and
see whether anything at all changes :) 

Gerhard

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


Proposal for new option -U extending -u

2006-07-29 Thread James Thiele
Currently -u specifies that stdin, stdout and stderr are all
unbuffered. I propose a that -U make all files unbuffered. It could be
useful for programs that log to files.

Comments solicited.

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


Math package

2006-07-29 Thread diffuser78
I want to write a program which would have a 2 dimensional array of 1
billion by 1 billion. This is for computational purposes and evaluating
a mathematical concept similar to Erdos number.

Which is the best package for such programs (that would be fast
enough). 

Every help is appreciated.

Thanks

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


Re: Smaple of recursive directory walker

2006-07-29 Thread Ant

> At work I have a directory of about 50 large text files and i need to
> search thru them for 10 separate words and print how many were found
> in total.
>
> I am new to python so could somebody please show me some sample code
> that would help me get this done and i will work from that.

Assuming it's primarily the directory walk you need help with,
something like the following should help:

for root, dirs, files in os.walk('~/mydir'):
for file in [f for f in files if f.endswith(".txt")]:
fh = open(file)
for line in fh:
# Search for words.
fh.close()

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


Re: Smaple of recursive directory walker

2006-07-29 Thread Traveler
yes this is great i will work from that but how can i use say a list
to pass 10 words?

mylist = ['word1','word2','word3','word4']



On 29 Jul 2006 12:01:03 -0700, "Ant" <[EMAIL PROTECTED]> wrote:

>
>> At work I have a directory of about 50 large text files and i need to
>> search thru them for 10 separate words and print how many were found
>> in total.
>>
>> I am new to python so could somebody please show me some sample code
>> that would help me get this done and i will work from that.
>
>Assuming it's primarily the directory walk you need help with,
>something like the following should help:
>
>for root, dirs, files in os.walk('~/mydir'):
>for file in [f for f in files if f.endswith(".txt")]:
>fh = open(file)
>for line in fh:
># Search for words.
>fh.close()

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


Re: Math package

2006-07-29 Thread Bas
I think you need one of these:

http://www-03.ibm.com/servers/deepcomputing/bluegene.html

Don't know if it runs python. If that doesn't work try to reformulate
your problem and have a look at

http://scipy.org/

Cheers,
Bas

[EMAIL PROTECTED] wrote:
> I want to write a program which would have a 2 dimensional array of 1
> billion by 1 billion. This is for computational purposes and evaluating
> a mathematical concept similar to Erdos number.
>
> Which is the best package for such programs (that would be fast
> enough). 
> 
> Every help is appreciated.
> 
> Thanks

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


Re: Math package

2006-07-29 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, diffuser78
wrote:

> I want to write a program which would have a 2 dimensional array of 1
> billion by 1 billion. This is for computational purposes and evaluating
> a mathematical concept similar to Erdos number.

Lets say you just want a byte at each cell in that array:

You have: (1 billion)^2 bytes
You want: terabyte
* 100
/ 1e-06

Hope you have enough memory.  ;-)

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


Re: Math package

2006-07-29 Thread bearophileHUGS
[EMAIL PROTECTED]:
> I want to write a program which would have a 2 dimensional array of 1
> billion by 1 billion. This is for computational purposes and evaluating
> a mathematical concept similar to Erdos number.

Maybe you are talking about the edges of a graph with 1e9 nodes. This
structure is surely quite sparse, so you don't need to store the edges
in a matrix, you can manage is as a sparse structure, and maybe you
don't need a Blue Gene.

If you find ways to clean your data, reduce the vertex and arc count,
and if you have a lot of memory, then maybe Boost Graph for Python may
suffice:
http://www.osl.iu.edu/~dgregor/bgl-python/

Bye,
bearophile

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


Re: Proposal for new option -U extending -u

2006-07-29 Thread Fuzzyman

James Thiele wrote:
> Currently -u specifies that stdin, stdout and stderr are all
> unbuffered. I propose a that -U make all files unbuffered. It could be
> useful for programs that log to files.
>
> Comments solicited.

'-U' is already taken (for unicode only strings). Other than that I
have no opinion (don't think I'd use it...).

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Math package

2006-07-29 Thread diffuser78
I will write the problem a little more clearer so that you guys can
recommend me better.

In a graphs of size N ( where, N = 1e9), each node has a degree D=1000.
i.e There are overall (D*N)/2 edges in the graph. This graph needs to
be generated randomly using the program.

Now my task is to find the shortest distance from each node to every
other node. And finally I want to find is the average distance from one
node to another node in the graph. This is an average Erdos number or
equivalently what degree of seperation exists in the graph.

I can start with low values of N and D but my ultimate aim is to
simulate this graph on big values of N and D.

Every help is greatly appreciated.

Thanks


[EMAIL PROTECTED] wrote:
> [EMAIL PROTECTED]:
> > I want to write a program which would have a 2 dimensional array of 1
> > billion by 1 billion. This is for computational purposes and evaluating
> > a mathematical concept similar to Erdos number.
>
> Maybe you are talking about the edges of a graph with 1e9 nodes. This
> structure is surely quite sparse, so you don't need to store the edges
> in a matrix, you can manage is as a sparse structure, and maybe you
> don't need a Blue Gene.
>
> If you find ways to clean your data, reduce the vertex and arc count,
> and if you have a lot of memory, then maybe Boost Graph for Python may
> suffice:
> http://www.osl.iu.edu/~dgregor/bgl-python/
> 
> Bye,
> bearophile

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


Re: Fastest Way To Loop Through Every Pixel

2006-07-29 Thread Ron Adam
Chaos wrote:
> As my first attempt to loop through every pixel of an image, I used
> 
> for thisY in range(0, thisHeight):
> for thisX in range(0, thisWidth):
>   #Actions here for Pixel thisX, thisY
> 
> But it takes 450-1000 milliseconds
> 
> I want speeds less than 10 milliseconds
> 
> I have tried using SWIG, and pypy but they all are unsuccessfull in
> compiling my files.

This probably won't work for you, but it's worth suggesting as it may 
give you other ideas to solve your problem.

If it is a list of lists of pixel objects you can iterate though the 
pixels directly and not use range or xrange at all.  For this to work 
the pixel object needs to be mutable or have an attribute to store it's 
value.  It can't be just an int, in that case you will need to use indexes.



 pixel = [rgb_value]

or

 pixel = [r,g,b]

or

 class Pixel(object):
def __self__(self, rgb_value):
self.value = rgb_value
 pixel = Pixel(rgb_value)

Or some other variation that is mutable.


These may not be suitable and may cause additional overhead elsewhere as 
the image may need to be converted to some other form in order to 
display or save it.



What Actions are you performing on the pixels?

You may be able to increase the speed by creating lookup tables in 
dictionaries and then use the pixel value for the key.


Just a rough example...

action1 = dict()
# fill dict with precomputed pixel key value pairs.
# ...

image = getimage()
for row in image:
   for pixel in row:
  # one of the following or something similar
  pixel[0] = action1[pixel]
  pixel.value = action1[pixel.value]
  pixel[:] = action[pixel]


The pixels need to be objects so they are mutable.  If they aren't, then 
you will need to use index's as you did above.

Precomputing the pixel value tables may use up too much memory or take a 
very long time if your image has a large amount of possible colors.  If 
precomputing the pixels take too long but you are not concerned by the 
memory usage, you may be able to store (pickle) the precomputed tables 
then unpickle it before it is used.

This work best if the number of colors (the depth) is limited.

If these suggestions aren't applicable, then you most likely need to 
look at an image library that uses compiled C (or assembly) code to do 
the brute force work.  It may also be possible to access your platforms 
directX or opengl library routines directly to do it.

Cheers,
Ron












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


Re: simple dbus python problem ... please help

2006-07-29 Thread alisonken1

bob wrote:



> bus = dbus.Bus (dbus.Bus.TYPE_SYSTEM)
> hal_service = bus.get_service ('org.freedesktop.Hal')
> hal_manager = hal_service.get_object ('/org/freedesktop/Hal/Manager',
>   'org.freedesktop.Hal.Manager')
>


It appears that bus.get_service() has been deprecated and deleted.

Not sure about the changes, so anyone else who can help please jump in.

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


Re: Newbie..Needs Help

2006-07-29 Thread Anthra Norell

- Original Message -
From: "Graham Feeley" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Friday, July 28, 2006 5:11 PM
Subject: Re: Newbie..Needs Help


> Thanks Nick for the reply
> Of course my first post was a general posting to see if someone would be
> able to help
> here is the website which holds the data I require
> http://www.aapracingandsports.com.au/racing/raceresultsonly.asp?storydate=27/07/2006&meetings=bdgo
>
> The fields required are as follows
>  NSW Tab
> #  Win  Place
>  2$4.60   $2.40
>  5$2.70
>  1$1.30
>  Quin$23.00
>  Tri  $120.70
> Field names are
> Date   ( not important )
> Track= Bendigo
> RaceNoon web page
> Res1st...2
> Res2nd..5
> Res3rd..1
> Div1..$4.60
> DivPlc...$2.40
> Div2..$2.70
> Div3..$1.30
> DivQuin.$23.00
> DivTrif...$120.70
> As you can see there are a total of 6 meetings involved and I would need to
> put in this parameter ( =bdgo) or (=gosf) these are the meeting tracks
>
> Hope this more enlightening
> Regards
> graham
>

Graham,

Only a few days ago I gave someone a push who had a very similar problem. I 
handed him code ready to run. I am doing it again for
you.
  The site you use is much harder to interpret than the other one was and 
so I took the opportunity to experimentally stretch
the envelope of a new brain child of mine: a stream editor called SE. It is new 
and so I also take the opportunity to demo it.
  One correspondent in the previous exchange was Paul McGuire, the author 
of 'pyparse'. He made a good case for using 'pyparse'
in situations like yours. Unlike a stream editor, a parser reads structure in 
addition to data and can relate the data to its
context.
  Anlayzing the tables I noticed that they are poorly structured: The first 
column contains both data and ids. Some records are
shorter than others, so column ids have to be guessed and hard coded. Missing 
data sometimes is a dash, sometimes nothing. The
inconsistencies seem to be consistent, though, down the eight tables of the 
page. So they can be formalized with some confidence
that they are systematic. If Paul could spend some time on this, I'd be much 
interested to see how he would handle the relative
disorder.
  Another thought: The time one invests in developing a program should not 
exceed the time it can save overall (not talking
about recreational programming). Web pages justify an extra measure of caution, 
because they may change any time and when they do
they impose an unscheduled priority every time the reader stops working and 
requires a revision.

So, here is your program. I write it so you can copy the whole thing to a file. 
Next copy SE from the Cheese Shop. Unzip it and put
both SE.PY and SEL.PY where your Python progams are. Then 'execfile' the code 
in an IDLE window, call 'display_horse_race_data
('Bendigo', '27/07/2006') and see what happens. You'll have to wait ten seconds 
or so.

Regards

Frederic

##

TRACKS = { 'New Zealand' : '',
   'Bendigo' : 'bdgo',
   'Gosford' : 'gosf',
   'Northam' : 'nthm',
   'Port Augusta': 'pta',
   'Townsville'  : 'town',
 }


# This function does it all once all functions are loaded. If nothing shows, the
# page has not data.

def display_horse_race_data (track, date, clip_summary = 100):

   """
  tracks: e.g. 'Bendigo' or 'bdgo'
  date: e.g. '27/07/2006'
  clip_summary: each table has a long summary header.
the argument says hjow much of it to show.
   """

   if track [0].isupper ():
  if TRACKS.has_key (track):
 track = TRACKS [track]
  else:
 print 'No such track %s' % track
 return
   open ()
   header, records = get_horse_race_data (track, date)
   show_records (header, records, clip_summary)



##


import SE, urllib

_is_open = 0

def open ():

   global _is_open

   if not _is_open:   # Skip repeat calls

  global Data_Filter, Null_Data_Marker, Tag_Stripper, Space_Deflator, 
CSV_Maker

  # Making the following Editors is a step-by-step process, adding one 
element at a time and
  # looking at what it does and what should be done next.
  # Get pertinent data segments
  header= ' "~(?i)Today\'s Results - .+?~==*END*OF*HEADER*" '
  race_summary  = ' "~(?i)Race [1-9].*?~==" '
  data_segment  = ' "~(?i)(.|\n)*?~==*END*OF*SEGMENT*" '
  Data_Filter = SE.SE ('  ' + header + race_summary + data_segment)

  # Some data items are empty. Fill them with a dash.
  mark_null_data = ' "~(?i)>\s* \s*~=>-" '
  Null_Data_Marker = SE.SE (mark_null_data + ' " = " ')

  #

Pygame Help

2006-07-29 Thread Blaze Bresko
Hi,

I am trying to make a game using either livewires or pygame. The game
is tetris. Right now I have gotten the program to a point where
everything works (as in user input, score, lines, etc), except I can't
get more than one block to work. Right now I have the user playing a
game where a single block falls at a time instead of one of the seven
different patterns. I was curious how you would program the seperate
images to fall together and not break apart, because pygame and
livewires uses images as collision detection, so therefore you can't
make most of the shapes a single image because they will have
transparent spaces as part of the image, which will make floating
shapes and such.

--Thanks
--Andrew

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


Re: Pygame Help

2006-07-29 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Blaze Bresko
wrote:

> [Tetris] I was curious how you would program the seperate  images to
> fall together and not break apart, because pygame and livewires uses
> images as collision detection, so therefore you can't make most of the
> shapes a single image because they will have transparent spaces as part
> of the image, which will make floating shapes and such.

I wouldn't rely on the graphics library at all but create a "model" of the
game that's completely independent from the graphics.  I think a two
dimensional structure with lists of lists is the simplest solution.

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


Re: Pygame Help

2006-07-29 Thread Lee Harr
> I was curious how you would program the seperate
> images to fall together and not break apart, because pygame and
> livewires uses images as collision detection, so therefore you can't
> make most of the shapes a single image because they will have
> transparent spaces as part of the image, which will make floating
> shapes and such.
>

The way I did it was to compose the shapes out of squares.
The implementation is available in the pygsear-games
distribution. You'd need pygsear also, to play the game.

http://www.nongnu.org/pygsear/

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


Re: Math package

2006-07-29 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> I will write the problem a little more clearer so that you guys can
> recommend me better.
> 
> In a graphs of size N ( where, N = 1e9), each node has a degree D=1000.
> i.e There are overall (D*N)/2 edges in the graph. This graph needs to
> be generated randomly using the program.

You will need to specify your desired random generation algorithm a bit better. 
There are lots of ways to do that, and different choices will affect your 
results substantially. They will also affect your *ability* to get results.

> Now my task is to find the shortest distance from each node to every
> other node. And finally I want to find is the average distance from one
> node to another node in the graph. This is an average Erdos number or
> equivalently what degree of seperation exists in the graph.
> 
> I can start with low values of N and D but my ultimate aim is to
> simulate this graph on big values of N and D.

You probably won't be able to get up to N=1e9 and D=1000. The memory 
requirements are just too large even with a better data structure than an 
adjacency matrix (possibly the worst one you could use for problems this size).

However, for smaller graphs, you will probably want to look at the Boost Graph 
Library, as someone else has already mentioned, and LANL's NetworkX package. It 
was written for the statistical study of large networks (though not as large as 
you want).

   https://networkx.lanl.gov/

If you have a large cluster available, you might be able to parallelize your 
algorithms using the Parallel Boost Graph Library. I don't believe that Python 
bindings are available though. Your ability to solve your problem will also 
depend on the structure of the graph that you generated. Some networks 
parallelize better than others. Look at the "Performance" link on the site 
below.

   http://osl.iu.edu/research/pbgl/

-- 
Robert Kern

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

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


Re: Comma is not always OK in the argument list?!

2006-07-29 Thread Nick Vatamaniuc
Dennis,

You make a good point, that is what I though first. Semantically I
thought a comma after **kw as in ..., **kw,) doesn't make sense because
there is nothing that could follow **kw except the ')'. But then trying
some other cases (see the previous posts for my examples) I noticed
that commas aren't allowed after *pos_args also. For example if ,
*pos_args,) would be an error BUT stuff could follow *pos_args and that
could be **kw as in ..., *pos_args,**kw).

In other words the behavior is not consistent. So it seems that 3
things could happen with this:

1) Not allow commas after **kw only. Allow them in any other case,
because semantically 'stuff' could possibly follow.

2) Don't allow extra commas for all the argument lists. In other words
f(1,2,) or f(a=1,b=2,) would be an error.  But then do we want argument
lists to be consistent with tuples as far as syntax goes?

3) Allow trailing commas after all kinds of arguments in the argument
lists. This is what the documentation describes at the moment. I think
this is more sensible. I understand that argument lists and tuples are
not the same, but it would be nice to have a _syntactic_ consistency,
as opposed to 'a surprise'. As in t=(1,2,3,)  f(1,2,3,)  f(1,*[2,3],)
and f(1,*[2],**{'c':3},) should all be 'OK'.

Perhaps more Python core developers would comment...

Nick Vatamaniuc


Dennis Lee Bieber wrote:
> On 29 Jul 2006 07:26:57 -0700, "Nick Vatamaniuc" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
> > Roman,
> >
> > The way  I see it, it could be either way. In other words if I can
> > write f(1,2,3) and f(1,2,3,) I should also be able to write
> > f(1,*[2,3],). It is a really small detail but there sould be some
> > consistency. Either no extra commas for all kinds of argument types or
>
>   Part of the problem may be that the * notation implies that the
> associated argument is supposed to fill ALL other supplied positional
> arguments -- so what is that empty argument after the , supposed to be
> associated with? A positional argument /after/ all positional arguments?
> --
>   WulfraedDennis Lee Bieber   KD6MOG
>   [EMAIL PROTECTED]   [EMAIL PROTECTED]
>   HTTP://wlfraed.home.netcom.com/
>   (Bestiaria Support Staff:   [EMAIL PROTECTED])
>   HTTP://www.bestiaria.com/

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


Re: War chest for writing web apps in Python?

2006-07-29 Thread Nick Vatamaniuc
Stani,

Thanks. I'll definetly give SPE another try.
You have a great editor with features that others don't have.
I'll try it with the latest wxPython.

I never really thought SPE was the problem, it seemed like a lot of
issues I saw were from wxWidgets...

Nick V.



SPE - Stani's Python Editor wrote:
> Nick Vatamaniuc schreef:
>
> > I found Komodo to
> > be too slow on my machine, SPE was also slow, was crashing on me and
> > had strange gui issues,
>
> I hope you didn't install SPE from the MOTU repositories with synaptic
> or apt-get. I use SPE myself daily on Ubuntu and wrote this howto
> install SPE on Ubuntu:
> http://www.ubuntuforums.org/showthread.php?t=218001&highlight=wxpython
>
> I know that others are running SPE on Ubuntu without problems. The main
> point is not to use SPE from the repositories, but from the SPE
> website. If the howto is too much just download the -nosetup.zip
> 
> Stani
> --
> http://pythonide.stani.be

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


Re: Fastest Way To Loop Through Every Pixel

2006-07-29 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "Chaos" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >
> >
> > myCol = (0.3 * image.GetRed(thisX, thisY)) + (0.59 *
> > image.GetGreen(thisX, thisY)) + (0.11 * image.GetBlue(thisX, thisY))
> > if myCol < darkestCol:
> >darkestCol = myCol
> >possX = thisX
> >possY = thisY
> >
>
> Psyco may be of some help to you, especially if you extract out your myCol
> expression into its own function, something like:
>
> def darkness(img,x,y):
> return  (0.3 * img.GetRed(x,y)) + (0.59 * img.GetGreen(x,y)) + (0.11 *
> img.GetBlue(x,y))
>


Even better than my other suggestions might be to write this function, and
then wrap it in a memoizing decorator
(http://wiki.python.org/moin/PythonDecoratorLibrary#head-11870a08b0fa59a8622
201abfac735ea47ffade5) - surely there must be some repeated colors in your
image.

-- Paul



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


making pseudo random number with spam ad convert text to binary

2006-07-29 Thread bussiere maillist
here is a little project to make a more or less good pseudo random generator by using spam :http://euryale.googlecode.com/it's almost quite finished but i've got a last problem i didn't manage to convert text to binary :
hazard = binascii.a2b_qp(attachment) + binascii.a2b_qp(body) + binascii.a2b_qp(addr) + binascii.a2b_qp(sujet)    print  binascii.b2a_qp(hazard)it still print me ascii charactersregardsBussiere

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

python and JMS

2006-07-29 Thread tksri2000
I am looking to use python to talk to JMS. Can some please point me to
such resources if this is possible.

Sri

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


Re: Proposal for new option -U extending -u

2006-07-29 Thread Carl Banks
James Thiele wrote:
> Currently -u specifies that stdin, stdout and stderr are all
> unbuffered. I propose a that -U make all files unbuffered. It could be
> useful for programs that log to files.
>
> Comments solicited.

Unnecessary.  You can control the buffering of any file object you
create yourself, e.g. open("somefile",buffering=0) to create an
unbuffered file object.  The reason you need a switch for stdin,
stdout, stderr is you don't create those objects yourself.

Carl Banks

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


Re: Newbie..Needs Help

2006-07-29 Thread Graham Feeley
Well Well Well, Anthra you are a clever person, Are
nt you
I nearly fell over when i read your post.
Would it help if we used another web site to gather data
As you stated the tables are not all that well structured.
well I will give thisone  a go first and if there is anything I can do for 
you just ask and I will try my best.
I really appreciate what you have done.
Of course I will try to follow your code to see if any will fall on 
meLOL
Regards
Graham

"Anthra Norell" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> - Original Message -
> From: "Graham Feeley" <[EMAIL PROTECTED]>
> Newsgroups: comp.lang.python
> To: 
> Sent: Friday, July 28, 2006 5:11 PM
> Subject: Re: Newbie..Needs Help
>
>
>> Thanks Nick for the reply
>> Of course my first post was a general posting to see if someone would be
>> able to help
>> here is the website which holds the data I require
>> http://www.aapracingandsports.com.au/racing/raceresultsonly.asp?storydate=27/07/2006&meetings=bdgo
>>
>> The fields required are as follows
>>  NSW Tab
>> #  Win  Place
>>  2$4.60   $2.40
>>  5$2.70
>>  1$1.30
>>  Quin$23.00
>>  Tri  $120.70
>> Field names are
>> Date   ( not important )
>> Track= Bendigo
>> RaceNoon web page
>> Res1st...2
>> Res2nd..5
>> Res3rd..1
>> Div1..$4.60
>> DivPlc...$2.40
>> Div2..$2.70
>> Div3..$1.30
>> DivQuin.$23.00
>> DivTrif...$120.70
>> As you can see there are a total of 6 meetings involved and I would need 
>> to
>> put in this parameter ( =bdgo) or (=gosf) these are the meeting tracks
>>
>> Hope this more enlightening
>> Regards
>> graham
>>
>
> Graham,
>
> Only a few days ago I gave someone a push who had a very similar problem. 
> I handed him code ready to run. I am doing it again for
> you.
>  The site you use is much harder to interpret than the other one was 
> and so I took the opportunity to experimentally stretch
> the envelope of a new brain child of mine: a stream editor called SE. It 
> is new and so I also take the opportunity to demo it.
>  One correspondent in the previous exchange was Paul McGuire, the 
> author of 'pyparse'. He made a good case for using 'pyparse'
> in situations like yours. Unlike a stream editor, a parser reads structure 
> in addition to data and can relate the data to its
> context.
>  Anlayzing the tables I noticed that they are poorly structured: The 
> first column contains both data and ids. Some records are
> shorter than others, so column ids have to be guessed and hard coded. 
> Missing data sometimes is a dash, sometimes nothing. The
> inconsistencies seem to be consistent, though, down the eight tables of 
> the page. So they can be formalized with some confidence
> that they are systematic. If Paul could spend some time on this, I'd be 
> much interested to see how he would handle the relative
> disorder.
>  Another thought: The time one invests in developing a program should 
> not exceed the time it can save overall (not talking
> about recreational programming). Web pages justify an extra measure of 
> caution, because they may change any time and when they do
> they impose an unscheduled priority every time the reader stops working 
> and requires a revision.
>
> So, here is your program. I write it so you can copy the whole thing to a 
> file. Next copy SE from the Cheese Shop. Unzip it and put
> both SE.PY and SEL.PY where your Python progams are. Then 'execfile' the 
> code in an IDLE window, call 'display_horse_race_data
> ('Bendigo', '27/07/2006') and see what happens. You'll have to wait ten 
> seconds or so.
>
> Regards
>
> Frederic
>
> ##
>
> TRACKS = { 'New Zealand' : '',
>   'Bendigo' : 'bdgo',
>   'Gosford' : 'gosf',
>   'Northam' : 'nthm',
>   'Port Augusta': 'pta',
>   'Townsville'  : 'town',
> }
>
>
> # This function does it all once all functions are loaded. If nothing 
> shows, the
> # page has not data.
>
> def display_horse_race_data (track, date, clip_summary = 100):
>
>   """
>  tracks: e.g. 'Bendigo' or 'bdgo'
>  date: e.g. '27/07/2006'
>  clip_summary: each table has a long summary header.
>the argument says hjow much of it to show.
>   """
>
>   if track [0].isupper ():
>  if TRACKS.has_key (track):
> track = TRACKS [track]
>  else:
> print 'No such track %s' % track
> return
>   open ()
>   header, records = get_horse_race_data (track, date)
>   show_records (header, records, clip_summary)
>
>
>
> ##
>
>
> import SE, urllib
>
> _is_open = 0
>
> def open ():
>
>   global _is_open
>
>   if not _is_open:   # Skip rep

PIL on MacOS

2006-07-29 Thread kernel1983
I was trying to build PIL and pygame from the source on the MacOS.

But when I typed 'sudo python setup.py install',
it gives error msg :

gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd
-fno-common -dynamic -DNDEBUG -g -DHAVE_LIBZ -DWORDS_BIGENDIAN
-I/System/Library/Frameworks/Tcl.framework/Headers
-I/System/Library/Frameworks/Tk.framework/Headers
-I/usr/local/include/freetype2 -IlibImaging
-I/Library/Frameworks/Python.framework/Versions/2.4/include
-I/usr/local/include -I/usr/include
-I/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4
-c _imaging.c -o build/temp.macosx-10.4-fat-2.4/_imaging.o
gcc: cannot specify -o with -c or -S and multiple compilations
error: command 'gcc' failed with exit status 1

Is there any one who did this before?how can i solve it?
Thanks

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