can i write a assemly language programs in python

2009-07-09 Thread m.reddy prasad reddy
can any one tell me how to write assembly language programs in python...if
no is there any other way to write the programs in python

Reddi prasad reddy
ph.no:09958083797
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: count

2009-07-09 Thread Paul Rubin
a...@pythoncraft.com (Aahz) writes:
> When dealing with small N, O() can get easily swamped by the constant
> factors.  How often do you deal with more than a hundred fields?

The number of fields in the OP's post was not stated.  Expecting it to
be less than 100 seems like an ill-advised presumption.  If N is
unknown, speed-tuning the case where N is small at the expense of
consuming monstrous amounts of memory when N is large sounds 
somewhere between a premature optimization and a nasty bug.

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


PyGtk Depends on Numeric

2009-07-09 Thread dieter
Get with the times people and port to numpy. :P
Don't you think its about time?

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


Re: ... remove all 0 values

2009-07-09 Thread Daniel Austria
Thanks a lot for your advices,

i decided to use the filter() method to sort out the 0.
i can ´t use the sum() function cause i need the list afterwards 


best,
Dan
-- 
http://mail.python.org/mailman/listinfo/python-list


i need immediate help from u

2009-07-09 Thread m.reddy prasad reddy
i m new this community .;
can any one send me the solution for writing the assembly language programs
in python
my mail ID:redd@gmail.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: i need immediate help from u

2009-07-09 Thread Chris Rebert
On Thu, Jul 9, 2009 at 12:25 AM, m.reddy prasad
reddy wrote:
> i m new this community .;
> can any one send me the solution for writing the assembly language programs
> in python
> my mail ID:redd@gmail.com

Please read http://catb.org/esr/faqs/smart-questions.html

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regex help

2009-07-09 Thread Peter Otten
David wrote:

>  
> 
> Open:
> 
> 5.50
> 
>  
> Mkt Cap:
> 
> 6.92M
> 
>  
> P/E:
> 
> 21.99
> 
> 
> 
> I want to extract the open, mkt cap and P/E values - but apart from
> doing loads of indivdual REs which I think would look messy, I can't
> think of a better and neater looking way. Any ideas?

>>> from BeautifulSoup import BeautifulSoup
>>> bs = BeautifulSoup(""" 
...
... Open:
... 
... 5.50
... 
...  
... Mkt Cap:
... 
... 6.92M
... 
...  
... P/E:
... 
... 21.99
... 
... """)
>>> for key in bs.findAll(attrs={"class": "key"}):
... value = key.findNext(attrs={"class": "val"})
... print key.string.strip(), "-->", value.string.strip()
...
Open: --> 5.50
Mkt Cap: --> 6.92M
P/E: --> 21.99


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


Re: Problem reading file with umlauts

2009-07-09 Thread Claus Hausberger
Thanks a lot. I will try that on the weekend.

Claus

> Claus Hausberger wrote:
> > Thanks a lot. Now I am one step further but I get another strange error:
> > 
> > Traceback (most recent call last):
> >   File "./read.py", line 12, in 
> > of.write(text)
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in
> position 0: ordinal not in range(128)
> > 
> > according to google ufeff has something to do with byte order.
> > 
> > I use an Linux system, maybe this helps to find the error.
> > 
> 'text' contains Unicode, but you're writing it to a file that's not
> opened for Unicode. Either open the output file for Unicode:
> 
>  of = codecs.open("umlaut-out.txt", "w", encoding="latin1")
> 
> or encode the text before writing:
> 
>  text = text.encode("latin1")
> 
> (I'm assuming you want the output file to be in Latin1.)
> 
> > 
> >> Claus Hausberger wrote:
> >>
> >>> I have a text file with is encoding in Latin1 (ISO-8859-1). I can't
> >>> change that as I do not create those files myself. I have to read
> >>> those files and convert the umlauts like ö to stuff like &oumol; as
> >>> the text files should become html files.
> >> umlaut-in.txt:
> >> 
> >> This file is contains data in the unicode
> >> character set and is encoded with utf-8.
> >> Viele Röhre. Macht spaß!  Tsüsch!
> >>
> >>
> >> umlaut-in.txt hexdump:
> >> 
> >> 00: 54 68 69 73 20 66 69 6C  65 20 69 73 20 63 6F 6E This file is
> con
> >> 10: 74 61 69 6E 73 20 64 61  74 61 20 69 6E 20 74 68 tains data in
> th
> >> 20: 65 20 75 6E 69 63 6F 64  65 0D 0A 63 68 61 72 61 e
> unicode..chara
> >> 30: 63 74 65 72 20 73 65 74  20 61 6E 64 20 69 73 20 cter set and
> is
> >> 40: 65 6E 63 6F 64 65 64 20  77 69 74 68 20 75 74 66 encoded with
> utf
> >> 50: 2D 38 2E 0D 0A 56 69 65  6C 65 20 52 C3 B6 68 72 -8...Viele
> R..hr
> >> 60: 65 2E 20 4D 61 63 68 74  20 73 70 61 C3 9F 21 20 e. Macht
> spa..!
> >> 70: 20 54 73 C3 BC 73 63 68  21 0D 0A 00 00 00 00 00 
> Ts..sch!...
> >>
> >>
> >> umlaut.py:
> >> 
> >> # -*- coding: utf-8 -*-
> >> import codecs
> >> text=codecs.open("umlaut-in.txt",encoding="utf-8").read()
> >> text=text.replace(u"ö",u"oe")
> >> text=text.replace(u"ß",u"ss")
> >> text=text.replace(u"ü",u"ue")
> >> of=open("umlaut-out.txt","w")
> >> of.write(text)
> >> of.close()
> >>
> >>
> >> umlaut-out.txt:
> >> 
> >> This file is contains data in the unicode
> >> character set and is encoded with utf-8.
> >> Viele Roehre. Macht spass!  Tsuesch!
> >>
> >>
> >> umlaut-out.txt hexdump:
> >> 
> >> 00: 54 68 69 73 20 66 69 6C  65 20 69 73 20 63 6F 6E This file is
> con
> >> 10: 74 61 69 6E 73 20 64 61  74 61 20 69 6E 20 74 68 tains data in
> th
> >> 20: 65 20 75 6E 69 63 6F 64  65 0D 0D 0A 63 68 61 72 e
> unicode...char
> >> 30: 61 63 74 65 72 20 73 65  74 20 61 6E 64 20 69 73 acter set and
> is
> >> 40: 20 65 6E 63 6F 64 65 64  20 77 69 74 68 20 75 74  encoded with
> ut
> >> 50: 66 2D 38 2E 0D 0D 0A 56  69 65 6C 65 20 52 6F 65 f-8Viele
> Roe
> >> 60: 68 72 65 2E 20 4D 61 63  68 74 20 73 70 61 73 73 hre. Macht
> spass
> >> 70: 21 20 20 54 73 75 65 73  63 68 21 0D 0D 0A 00 00 ! 
> Tsuesch!.
> >>
> >>
> >>
> >>
> >>
> >> -- 
> >> "The ability of the OSS process to collect and harness
> >> the collective IQ of thousands of individuals across
> >> the Internet is simply amazing." - Vinod Valloppillil
> >> http://www.catb.org/~esr/halloween/halloween4.html
> > 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-09 Thread Gabriel Genellina

En Wed, 08 Jul 2009 23:19:25 -0300, kj  escribió:

In  Tim Rowe  
 writes:



2009/7/4 kj :



Precisely. =A0As I've stated elsewhere, this is an internal helper
function, to be called only a few times under very well-specified
conditions. =A0The assert statements checks that these conditions
are as intended. =A0I.e. they are checks against the module writer's
programming errors.



Good for you. I'm convinced that you have used the assertion
appropriately, and the fact that so many here are unable to see that
looks to me like a good case for teaching the right use of assertions.
For what it's worth, I read assertions at the beginning of a procedure
as part of the specification of the procedure, and I use them there in
order to document the procedure. An assertion in that position is for
me a statement to the user of the procedure "it's your responsibility
to make sure that you never call this procedure in such a way as to
violate these conditions". They're part of a contract, as somebody
(maybe you) pointed out.



As somebody who works in the safety-critical domain, it's refreshing
to see somebody teaching students to think about the circumstances in
which a procedure can legitimately be called. The hostility you've
received to that idea is saddening, and indicative of why there's so
much buggy software out there.


Thanks for the encouragement.

When I teach programming, the students are scientists.  For the
stuff they do, correctness of the code trumps everything else.  I
teach them to view assertions as way of translating their assumptions
into code.  And by this I mean not only assumptions about the
correctness of their code (the typical scope of assertions), but
also, more broadly, assumptions about the data that they are dealing
with (which often comes from external sources with abysmal quality
control).


Nobody says you shouldn't check your data. Only that "assert" is not the  
right way to do that. Ok, it's easier to write:


  assert x>0 and y>0 and x0 and y>0 and xbut the assert statement is completely ignored if your script is run with  
the -O option, and then no check is done.
assert should be used only to verify internal correctness only - to detect  
wrong assumptions in the *code* itself. Once you're confident the code is  
OK, you may turn off assertions (and improve program speed). But you must  
*always* validate input data no matter what - so assert is not the right  
tool.


Even worse, never DO anything inside an assertion - it won't be done in  
the optimized version. This method becomes almost empty when assertions  
are removed (not the intended behavior!):


def process_all(self):
for item in self.items:
  assert self.process(item)


My scientific code is jam-packed with assertions.  I can't count
the number of times that one such lowly assertion saved me from a
silent but potentially disastrous bug.  And yes I find it distressing
that so so few programmers in my line of work use assertions at
all.


I'm just saying that some of those assertions probably should be real "if  
... raise" statements instead - not that you remove the checks. You may  
use this short function, if you prefer:


def fassert(condition, message='', exc_type=AssertionError):
  if not condition:
raise exc_type(message)

--
Gabriel Genellina

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


Re: Check file is locked?

2009-07-09 Thread Rajat
On Jul 8, 12:45 pm, Tim Golden  wrote:
> Rajat wrote:
> > On Jul 8, 4:57 am, Lawrence D'Oliveiro  > central.gen.new_zealand> wrote:
> >> In message , Christian
>
> >> Heimes wrote:
> >>> By the way most operating systems don't lock a file when it's opened for
> >>> reading or writing or even executed.
> >> The general conclusion seems to be that mandatory locking is more trouble
> >> than it's worth.
>
> > My OS is a windows XP sp3. All I'm trying to achieve is to close an
> > application ( which could be a notepad, a wordpad or some other text
> > editor) that have opened my file. Once the file is closed I can easily
> > delete that file.
>
> > I guess, if file is opened by one of that application, the file must
> > be locked and so is the reason I cannot delete the file.
>
> I assume that your real requirement is: I can't open/close/delete
> this file; it must be locked by something else; what is that
> something else?
>
> The simplest thing is probably to run sysinternals' handle util:
>
>  http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx
>
> and use the subprocess module to parse the output.
> That will give you the pid, and you can then use, eg, psutil:
>
>  http://code.google.com/p/psutil/
>
> to get the details of the process.
>
> TJG- Hide quoted text -
>
> - Show quoted text -

I've used the Handle.exe and got the following results:

--
notepad.exe pid: 3540 COMP\rajatd
C: File  (RW-)   C:\Documents and Settings\rajatd\Desktop
   10: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   44: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   7C: Section   \BaseNamedObjects\ShimSharedMemory

--
wordpad.exe pid: 2212 COMP\rajatd
   1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   74: Section   \BaseNamedObjects\ShimSharedMemory
   F8: Section   \BaseNamedObjects
\CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
  170: Section   \BaseNamedObjects\RotHintTable
  184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents

I've also parsed this output for the PIDS. But no where in the result
I got to know what file has been associated with a PID.

Does for this I need to use pustil?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter problem

2009-07-09 Thread Peter Otten
Paul Simon wrote:

> "Chris Rebert"  wrote in message
> news:mailman.2863.1247095339.8015.python-l...@python.org...
> On Wed, Jul 8, 2009 at 4:18 PM, Paul Simon wrote:
>> I have the "tkinter" problem and need some assistance to straighten it
>> out.
>> >From the web page "http://wiki.python.org/moin/TkInter"; I tested as in
>> >"step
>> 1" and cannot import "_tkinter." I do not have that file on my computer,
>> but
>> do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
>> directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
>> This python stuff is great, but the documentation frequently
>> feels like it is just a bit out of my grasp. I realize that all of this
>> is free but I understand the instructions on the web page to repair only
>> to the
>> point of confusion. I'm not an expert. How do I modify my python
>> configuration? Is there a file that needs to be edited? Which setup.py
>> file
>> do I use? Make? or python setup.py build and python setup.py install?
>> Thanks. I appreciate your help.
> 
> - How did you install Python?
> - What Linux distro are you using?
> 
> Cheers,
> Chris
> http://blog.rebertia.com
> I"m using Mandriva 2008.1.  I have to tell you honestly that I'm not sure
> exactly how I installed Python.  Originally I had installed 2.5 from RPM
> but 2.6 was not available for my distro (2008.1) in RPM.  I downloaded
> something from python.org and installed.  Not sure if it was tarball or
> zip file.

Zip or tar doesn't matter, you are installing "from source".

Python has to find the necessary include files for tcl/tk. These are in 
separate packages that you have to install before you invoke Python's 
configure script.

I don't know what they are called on your system -- look for tk-dev.rpm, 
tcl-dev.rpm or similar.

You may run into the same problem with other modules like readline.

Peter

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


Re: Problem with list of dicts and copying

2009-07-09 Thread Gabriel Genellina
En Wed, 08 Jul 2009 14:09:43 -0300, Cameron Pulsford  
 escribió:



I'm representing the board as a dictionary, where the keys are
(x, y) positions, and the values are candidates. So my program goes along
picking numbers from the list of candidates and then propagating the
constraints. [...]Basically my boards list should be copies of good  
boards, and when I need to
refresh the current board, I want to pull off a copy of the correct one. 
[...] this isn't happening. I am always modifying the same board.


You have a dictionary whose values are lists, ok? The copy() method  
doesn't make a copy of those lists - only of the dictionary itself. Try  
using the deepcopy function in the copy module:

http://docs.python.org/library/copy.html

--
Gabriel Genellina

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


Re: Check file is locked?

2009-07-09 Thread Tim Golden

Rajat wrote:

I've used the Handle.exe and got the following results:

--
notepad.exe pid: 3540 COMP\rajatd
C: File  (RW-)   C:\Documents and Settings\rajatd\Desktop
   10: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   44: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   7C: Section   \BaseNamedObjects\ShimSharedMemory

--
wordpad.exe pid: 2212 COMP\rajatd
   1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   74: Section   \BaseNamedObjects\ShimSharedMemory
   F8: Section   \BaseNamedObjects
\CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
  170: Section   \BaseNamedObjects\RotHintTable
  184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents

I've also parsed this output for the PIDS. But no where in the result
I got to know what file has been associated with a PID.

Does for this I need to use pustil?



Well unless I'm missing your point considerably, the output tells
you all you need to know: notepad.exe (pid 3540) has some kind
of handle open on the desktop, the common controls DLL and an
area of shared memory. As has been pointed out elsewhere, notepad
doesn't hold the file open which it's editing: it opens it, reads
the contents, and closes it again. 


For demonstration purposes:


import os, sys
import subprocess

f = open (sys.executable)
subprocess.call (["handle", sys.executable])
f.close ()




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


Re: windows command-line

2009-07-09 Thread Gabriel Genellina
En Wed, 08 Jul 2009 14:23:54 -0300, Emile van Sebille   
escribió:

On 7/8/2009 10:07 AM Lucas Junqueira said...


Hi, I'd like to run a simple windows command-line program from within  
my python script and agt all the returt it generates. Is this possible?  
How can I do it?


Depending on python version, look into subprocess, commands or os.pipe  
and related.


commands is Unix only, and os.pipe by itself doesn't solve the problem -  
so we are left with subprocess, and that would be my reccomendation too.


--
Gabriel Genellina

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


Hello

2009-07-09 Thread Tanmoy
Hi ...
I have been trying to set this 2-D array of this sort.

  0 10 20 ... 1000
  1 11 21...

   1000


Here is the code i tried ...

arr=[]
for i in range(0,1010,10):
arr.append([])
for j in range(0,1001,1):
  arr[i].append(i+j)

print arr

I am getting the following error
 list index out of range

Please let me know where am i getting wrong.

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


Re: python3 fail to start

2009-07-09 Thread Mark Dickinson
On Jun 30, 3:43 pm, ts  wrote:
> i just install the python 3.1 dmg onto my mac. when i run python3, it
> fail with :
>
> Fatal Python error: Py_Initialize: can't initialize sys standard
> streamsLookupError: unknown encoding:
> Abort trap
>
> couldnt understand the problem. anyone can help?

Any chance you could give us some feedback about your system?  The
Python devs are working to fix the problem:

http://bugs.python.org/issue6393

but it would be really helpful to know:

- what version of OS X you're using
- what output you get when you type 'locale' at a Terminal prompt
- what the International settings are in your Terminal preferences
  (Terminal preferences -> Settings -> Advanced tab):  what's the
  setting for the character encoding, and do you have the 'Set LANG
  environment variable at startup' checkbox checked?

I managed to reproduce the crash by starting python3 (again
at a Terminal prompt) with:

LANG=UTF-8 python3

So I suspect that your locale settings are part of the problem.
As a temporary workaround, something like

LANG=en_US.UTF-8 python3

might work.  (Substitute whatever language setting is appropriate
for you in place of en_US.)

Thanks!

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


Re: Hello

2009-07-09 Thread MRAB

Tanmoy wrote:
T Hi ...

I have been trying to set this 2-D array of this sort.

  0 10 20 ... 1000
  1 11 21...
  
   1000



Here is the code i tried ...

arr=[]
for i in range(0,1010,10):
arr.append([])
for j in range(0,1001,1):
  arr[i].append(i+j)
 
print arr


I am getting the following error
 list index out of range

Please let me know where am i getting wrong.


The value of 'i' goes 0, 10, ..., etc.

When i==0 you append an empty list to arr, so arr[i] is arr[0]. No
problem.

When i==10 you append another empty list to arr, so arr[i] is arr[10].
Index error because there's no arr[10], only arr[0] and arr[1].
--
http://mail.python.org/mailman/listinfo/python-list


Re: can i write a assemly language programs in python

2009-07-09 Thread Gabriel Genellina
En Thu, 09 Jul 2009 04:17:52 -0300, m.reddy prasad reddy  
 escribió:


can any one tell me how to write assembly language programs in  
python...if

no is there any other way to write the programs in python


You write Python programs using Python, not assembly.

Perhaps if you provide more info on what you want to do, someone can  
suggest a different way...


--
Gabriel Genellina

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


subprocess + python-daemon - bug/problem?

2009-07-09 Thread Andy Clegg
Hi all,

I'm trying to daemonize a python program, and occasionally have it run
subprocesses, however I'm running into a nasty error, as follows:

"File "/users/rsg/ancl/devcocast/devcocast-svn/scripts/DaemonSpawnTes
t.py", line 5, in 
subprocess.Popen('echo 1').wait()
  File "/usr/lib64/python2.5/subprocess.py", line 594, in __init__
errread, errwrite)
  File "/usr/lib64/python2.5/subprocess.py", line 1089, in _execute_ch
ild
os.waitpid(self.pid, 0)
OSError: [Errno 10] No child processes"

The minimal testcase showing this problem is as follows:

"import daemon
import subprocess

daemon.DaemonContext(stderr = open("fakeConsole.txt","w+")).open()
subprocess.Popen('echo 1').wait()"

So there is no threading going on (I've found some bugs relating to
subprocess and threading). I'm using Fedora 10, Python 2.5.2, and
python-daemon 1.4.6 from here http://pypi.python.org/pypi/python-daemon/
.

If anyone can shed some light on the situation, I'd be extremely
grateful!

Yours,

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


older pythons

2009-07-09 Thread superpollo

hi everybody.

i have a certain set of old python scripts and data used by said scripts 
which were written using python 2.3


in particular i used some features which were later modified or 
deprecated by the language newer versions (e.g.: cmp(), print as 
keyword, and such...)


for reasons i find hard to explain briefly, it is unfeasible at the 
moment to modify scripts and data to adapt to the changes


now: i ask if it is possible to have different versions of python 
installed on my system (linux debian) so that i can continue to use 
python 2.3 (as "python" from the shell) but i can also use - say - 
python 3.1 (maybe as "python3.1" from the shell)


if yes: is there a known recommended way to do so?

thanks a lot

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


hoe to build a patched socketmodule.c

2009-07-09 Thread jacopo mondi
Hi all, I need to patch socketmodule.c (the _socket module) in order to
add support to an experimental socket family.

I'm guessing about the patched module build process: does a stand alone
build script using distutils makes sense, or have I to patch
sockmodule.c, eventualy rename it, modify setup.py inside python sources
to let it know about the new module, and then rebuild whole python?
I think the latter makes more sense, because I suppose socketmodule
could not be build stand alone, but need the whole python build system,
in order to have right definition specified by a Makefile generated by
autotools from inside python sources.
Or maybe distutils is able to retreive the whole build system? I don't
think so, because there are no requirement about having python source
tree installed.

If I have to go for the second way, then how could I distribuite the
patched _socket module? I could not use distutils, have I to distribuite
 the already built .so with only a script to install it, and the source
code in another directory?

Thanks a lot
jacopo

PS correct my english please, is the only way I have to improve it!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess + python-daemon - bug/problem?

2009-07-09 Thread Andy Clegg
My apologies, the python code should have been:

"import daemon
import subprocess

daemon.DaemonContext(stderr = open("fakeConsole.txt","w+")).open()
subprocess.Popen(['echo','1']).wait()"

However the error remains the same.

Yours,

Andy

On Jul 9, 10:26 am, Andy  Clegg  wrote:
> Hi all,
>
> I'm trying to daemonize a python program, and occasionally have it run
> subprocesses, however I'm running into a nasty error, as follows:
>
> "File "/users/rsg/ancl/devcocast/devcocast-svn/scripts/DaemonSpawnTes
> t.py", line 5, in 
>     subprocess.Popen('echo 1').wait()
>   File "/usr/lib64/python2.5/subprocess.py", line 594, in __init__
>     errread, errwrite)
>   File "/usr/lib64/python2.5/subprocess.py", line 1089, in _execute_ch
> ild
>     os.waitpid(self.pid, 0)
> OSError: [Errno 10] No child processes"
>
> The minimal testcase showing this problem is as follows:
>
> "import daemon
> import subprocess
>
> daemon.DaemonContext(stderr = open("fakeConsole.txt","w+")).open()
> subprocess.Popen('echo 1').wait()"
>
> So there is no threading going on (I've found some bugs relating to
> subprocess and threading). I'm using Fedora 10, Python 2.5.2, and
> python-daemon 1.4.6 from herehttp://pypi.python.org/pypi/python-daemon/
> .
>
> If anyone can shed some light on the situation, I'd be extremely
> grateful!
>
> Yours,
>
> Andy

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


Re: older pythons

2009-07-09 Thread Adrian Dziubek
The recommended Debian way is update-alternatives. I find it a bit
unintuitive, so I have to read through the documentation every time I
use it, but it should be able link a chosen version of python to /usr/
bin/python. I don't know if it's set up by default, I have only one
version installed.
--
Adrian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check file is locked?

2009-07-09 Thread Rajat
On Jul 9, 1:21 pm, Tim Golden  wrote:
> Rajat wrote:
> > I've used the Handle.exe and got the following results:
>
> > ---­---
> > notepad.exe pid: 3540 COMP\rajatd
> >     C: File  (RW-)   C:\Documents and Settings\rajatd\Desktop
> >    10: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    44: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    7C: Section       \BaseNamedObjects\ShimSharedMemory
>
> > ---­---
> > wordpad.exe pid: 2212 COMP\rajatd
> >    1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    74: Section       \BaseNamedObjects\ShimSharedMemory
> >    F8: Section       \BaseNamedObjects
> > \CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
> >   170: Section       \BaseNamedObjects\RotHintTable
> >   184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents
>
> > I've also parsed this output for the PIDS. But no where in the result
> > I got to know what file has been associated with a PID.
>
> > Does for this I need to use pustil?
>
> Well unless I'm missing your point considerably, the output tells
> you all you need to know: notepad.exe (pid 3540) has some kind
> of handle open on the desktop, the common controls DLL and an
> area of shared memory. As has been pointed out elsewhere, notepad
> doesn't hold the file open which it's editing: it opens it, reads
> the contents, and closes it again.
>
> For demonstration purposes:
>
> 
> import os, sys
> import subprocess
>
> f = open (sys.executable)
> subprocess.call (["handle", sys.executable])
> f.close ()
>
> 
>
> TJG- Hide quoted text -
>
> - Show quoted text -

The Notepad process information is fine here. However, with wordpad
the results are not much differentiating:

--
wordpad.exe pid: 2832 COMP\rajatd
   1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   74: Section   \BaseNamedObjects\ShimSharedMemory
   F8: Section   \BaseNamedObjects
\CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
  170: Section   \BaseNamedObjects\RotHintTable
  184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents
--
wordpad.exe pid: 844 COMP\rajatd
   1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   74: Section   \BaseNamedObjects\ShimSharedMemory
   F8: Section   \BaseNamedObjects
\CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
  170: Section   \BaseNamedObjects\RotHintTable
  184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents

Both the wordpad applications opened 2 totally different files kept at
different locations on the system.

So, on the basis of above results one can not say out of these 2
wordpad apps which is the right one that could be closed. The only
different thing among the two is the PIDs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Psyco 64 bits

2009-07-09 Thread Luis P. Mendes
Hi,

I used Psyco to speed up my Python code.
Due to the great amount of data I have to proccess, I moved my Linux 
system to a 64 bits version with more RAM.

It seems that Psyco cannot be used in such platforms.
Or is there another version of Psyco for 64 bits platform?

I googled and arrived to PyPy.  But I don't know how to use it.
With psyco, I used to include two statements roughly at the beginning of 
the script:
import psyco
psyco.full()

With PyPy, is there a similar way to try to speed up my script?


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


Re: can i write a assemly language programs in python

2009-07-09 Thread Tom Kermode
I wonder if the OP is trying to find out whether python programmes can
be compiled and run as stand alone executables.

(I know assembly and machine code are not the same, but it might be
what they're after.)

On windows you can use http://www.py2exe.org/ to bundle python
programs into stand alone executables. They're not compiled, but your
code and all the modules it relies on are brought together, meaning
you can deliver a single exe than can be run like any other windows
program.

Maybe that helps...

2009/7/9 Gabriel Genellina :
> En Thu, 09 Jul 2009 04:17:52 -0300, m.reddy prasad reddy
>  escribió:
>
>> can any one tell me how to write assembly language programs in python...if
>> no is there any other way to write the programs in python
>
> You write Python programs using Python, not assembly.
>
> Perhaps if you provide more info on what you want to do, someone can suggest
> a different way...
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.kiloday.com
http://www.fourstopspast.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check file is locked?

2009-07-09 Thread Tim Golden

Rajat wrote:

The Notepad process information is fine here. However, with wordpad
the results are not much differentiating:

--
wordpad.exe pid: 2832 COMP\rajatd
   1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   74: Section   \BaseNamedObjects\ShimSharedMemory
   F8: Section   \BaseNamedObjects
\CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
  170: Section   \BaseNamedObjects\RotHintTable
  184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents
--
wordpad.exe pid: 844 COMP\rajatd
   1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
   74: Section   \BaseNamedObjects\ShimSharedMemory
   F8: Section   \BaseNamedObjects
\CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
  170: Section   \BaseNamedObjects\RotHintTable
  184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents

Both the wordpad applications opened 2 totally different files kept at
different locations on the system.

So, on the basis of above results one can not say out of these 2
wordpad apps which is the right one that could be closed. The only
different thing among the two is the PIDs.



Rajat: are you trying to find out which app is holding a file open?

If so -- run handle.exe *for that filename*, as my code does:

handle.exe 

This will only show which apps are holding that file. I suspect
you're running handle.exe on its own which will show everything
which is holding handles on anything.

1) Use wordpad.exe to open c:\temp\blah.txt

2) Run "handle.exe c:\temp\blah.txt"

3) Observe (at least on my Win XP Sp3 machine) that *no* process
has a handle open on c:\temp\blah.txt, including wordpad, which
presumably opens the file, reads it, and closes it again.


The items you're seeing above are system-level handles which
wordpad is holding for reasons of its own, but none of them
is a user filename.

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


Re: Python-list Digest, Vol 70, Issue 123

2009-07-09 Thread Tanmoy
Hello ,
  When i==0 you append an empty list to arr, so arr[i] is arr[0]. No
problem.

When i==10 you append another empty list to arr, so arr[i] is arr[10].
Index error because there's no arr[10], only arr[0] and arr[1].


Thanks for your prompt reply...

How can i pass this problem


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


Re: Python-list Digest, Vol 70, Issue 123

2009-07-09 Thread MRAB

Tanmoy wrote:

Hello ,
  When i==0 you append an empty list to arr, so arr[i] is arr[0]. No
problem.

When i==10 you append another empty list to arr, so arr[i] is arr[10].
Index error because there's no arr[10], only arr[0] and arr[1].
 


Thanks for your prompt reply...

How can i pass this problem


You could try appending to arr[-1] instead.

Better still:

...
row = []
for j in range(0,1001,1):
  row.append(i+j)
arr.append(row)
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: IP Address Function

2009-07-09 Thread Piet van Oostrum
> Fred Atkinson  (FA) wrote:

>FA> On Wed, 08 Jul 2009 12:29:54 +0200, Piet van Oostrum 
>FA> wrote:

>>> Something like:
>>> 
>>> #! /usr/bin/env python
>>> 
>>> import cgi
>>> from os import getenv
>>> 
>>> print "Content-type: text/html"
>>> print
>>> 
>>> ipaddr = (getenv("HTTP_CLIENT_IP") or
>>> getenv("HTTP_X_FORWARDED_FOR") or
>>> getenv("HTTP_X_FORWARDED_FOR") or
>>> getenv("REMOTE_ADDR") or
>>> "UNKNOWN")
>>> 
>>> print ipaddr

>FA> That did it.  

>FA> I wonder why they don't just have a function to return it instead of
>FA> putting you through all of that?  

I see now that I had   getenv("HTTP_X_FORWARDED_FOR") or
duplicated.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: older pythons

2009-07-09 Thread superpollo

Adrian Dziubek wrote:

The recommended Debian way is update-alternatives. I find it a bit
unintuitive, so I have to read through the documentation every time I
use it, but it should be able link a chosen version of python to /usr/
bin/python. I don't know if it's set up by default, I have only one
version installed.
--
Adrian


what i was asking for is about a way to *INSTALL* and mantain different 
python versions, a task i think is not unusal for developers.


thanks anyway for reply

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


Re: Check file is locked?

2009-07-09 Thread Rajat
On Jul 9, 3:21 pm, Tim Golden  wrote:
> Rajat wrote:
> > The Notepad process information is fine here. However, with wordpad
> > the results are not much differentiating:
>
> > ---­---
> > wordpad.exe pid: 2832 COMP\rajatd
> >    1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    74: Section       \BaseNamedObjects\ShimSharedMemory
> >    F8: Section       \BaseNamedObjects
> > \CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
> >   170: Section       \BaseNamedObjects\RotHintTable
> >   184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents
> > ---­---
> > wordpad.exe pid: 844 COMP\rajatd
> >    1C: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    40: File  (RW-)   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
> > Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
> >    74: Section       \BaseNamedObjects\ShimSharedMemory
> >    F8: Section       \BaseNamedObjects
> > \CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653
> >   170: Section       \BaseNamedObjects\RotHintTable
> >   184: File  (RW-)   C:\Documents and Settings\rajatd\My Documents
>
> > Both the wordpad applications opened 2 totally different files kept at
> > different locations on the system.
>
> > So, on the basis of above results one can not say out of these 2
> > wordpad apps which is the right one that could be closed. The only
> > different thing among the two is the PIDs.
>
> Rajat: are you trying to find out which app is holding a file open?
>
> If so -- run handle.exe *for that filename*, as my code does:
>
> handle.exe 
>
> This will only show which apps are holding that file. I suspect
> you're running handle.exe on its own which will show everything
> which is holding handles on anything.
>
> 1) Use wordpad.exe to open c:\temp\blah.txt
>
> 2) Run "handle.exe c:\temp\blah.txt"
>
> 3) Observe (at least on my Win XP Sp3 machine) that *no* process
> has a handle open on c:\temp\blah.txt, including wordpad, which
> presumably opens the file, reads it, and closes it again.
>
> The items you're seeing above are system-level handles which
> wordpad is holding for reasons of its own, but none of them
> is a user filename.
>
> TJG- Hide quoted text -
>
> - Show quoted text -

Thanks Tim for the details. Just further on this, my whole idea is to
close the wordpad / notepad application so that I can delete the file
and the directory where this file resides.

With notepad it is no more a problem. But I'm concerned about the
wordpad now.
-- 
http://mail.python.org/mailman/listinfo/python-list


property using a classmethod

2009-07-09 Thread Emanuele D'Arrigo
Greetings,

today I did something like this:

class MyClass(object):

@classmethod
def myClassMethod(self):
 print "ham"

 myProperty = property(myClassMethod, None, None)

As many of you know this doesn't work and returns a TypeError: the
object passed to the property is not a callable function but a
classmethod object, which isn't callable at all. So, how do I do this?
Ultimately all I want is a non-callable class-level attribute
MyClass.myProperty that gives the result of MyClass.myClassMethod().

Can it be done?

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


Re: count

2009-07-09 Thread Bearophile
Paul Rubin:
> print x, sum(1 for _ in g)

Don't use that, use my function :-) If g has a __len__ you are wasting
time. And sum(1 ...) is (on my PC) slower.


J. Clifford Dyer:
> if __name__ == '__main__':
>     test_func(summer, 1000)
>     test_func(tupler, 1000)
>     test_func(summer, 1)
>     test_func(tupler, 1)

Have you forgotten my function?

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psyco 64 bits

2009-07-09 Thread Bearophile
Luis P. Mendes:
> It seems that Psyco cannot be used in such platforms.
> Or is there another version of Psyco for 64 bits platform?
> I googled and arrived to PyPy.  But I don't know how to use it.

Psyco will be updated, but probably not for 64 bit CPUs. At the moment
PyPy doesn't give you much speed up.
So you can try IronPython, but I don't think it will help. There's
also the Boo language, that's often fast enough.

If your code has few hot spots, then there are many solutions that can
be used. For example Cython, Weave, ShedSkin. Or writing external code
in C/C++/D/Fortran and interfacing with it with a plethora of means,
like ctypes, swig, PIL, Pyd, Boost.Python, Inline, and many other.
Running speed is a big problem in many Python programs, so they have
invented an army of possible solutions.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


python-ldap

2009-07-09 Thread Larry kavanagh

Hi,
I need a PYTHON-LDAP package.

I'm trying to install ploneldap and it tells me I need python-ldap 
package first  .. but I can't find one to match my versions.


I'm using plone 3.2.2, Python 2.4.4 and Zope 2.10.7 on a Win32 environment.

Preferable I'd like an EXE as not too familiar with whole plone 
configuration.


The ones I've tried have all told me I need Python 2.4 installed and it 
can't find in the registry. My plone site tells me I'm python 2.4.4 so 
maybe I just need to configure some environment variables or PATHs or 
something prior to running an install ??


Can anyone help me
Thanks
Larry



Please consider the environment before printing this email.

Examiner Publications (Cork) Ltd
Directors:  G. A. Crosbie (Chairman), Thomas J. Murphy (Chief Executive), A.W. Dinan (Secretary), T.P. Crosbie. 
Registered In Dublin, Ireland. Registered number: 73385. Registered Office: City Quarter, Lapps Quay, Cork.




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


Re: older pythons

2009-07-09 Thread Lie Ryan
superpollo wrote:
> Adrian Dziubek wrote:
>> The recommended Debian way is update-alternatives. I find it a bit
>> unintuitive, so I have to read through the documentation every time I
>> use it, but it should be able link a chosen version of python to /usr/
>> bin/python. I don't know if it's set up by default, I have only one
>> version installed.
>> -- 
>> Adrian
> 
> what i was asking for is about a way to *INSTALL* and mantain different
> python versions, a task i think is not unusal for developers.
> 
> thanks anyway for reply
> 
> bye

Installing several minor versions (e.g. 2.3, 2.4, 2.5, 3.0) in parallel
has always been supported. Just install them and it should work
"automagically".

However changing the system's default /usr/bin/python is NOT
recommended, especially in linux systems that rely heavily on python for
many of the system tools. If you install from source, you need to check
for some settings to ensure the installer does not install the
/usr/bin/python's symlink. If you install from a package manager, they
usually doesn't change the symlink and you'll need to run a separate
program to change the symlinks (e.g. python-updater in Gentoo, which
will also updates all installed python packages to the appropriate
version. Neat.).

The easiest way to make a specific script use a specific version of
python is by changing its hashbang (#!) line:

instead of:
#!/usr/bin/env python

use
#!/usr/bin/env python2.3

or whatever version it should run on.

AFAIK, no major linux distributions have officially ported to python
3.x. This means switching /usr/bin/python to python3.1 will definitely
break your system. As an alternative, you can always explicitly specify
the version number of python you want to use:

$ python2.5
Python 2.5.4 (r254:67916, Jul  5 2009, 04:12:16)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python2.6
Python 2.6.2 (r262:71600, Jul  5 2009, 04:08:11)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python3.0
Python 3.0.1 (r301:69556, Jul  5 2009, 04:03:20)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python3.0 need3.py
happily running with python 3.0
$ python2 need3.py
SillyError: not running with python 3.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Emacs Python-mode. Newbie problem.

2009-07-09 Thread Piet van Oostrum
> Lacrima  (L) wrote:

>L> Thanks for your reply!
>L> My file name is 'trains.py'.
>L> When I do C-h k C-c RET, it shows me help from manual: "C-c RET runs
>L> the command py-execute-import-or-reload
>L>which is an interactive Lisp function in `python-mode'..." and so
>L> on.

>L> And still when I do C-c RET, I receive "(Shell command succeeded with
>L> no output)"

>L> Any more help would be really appreciated, because I am newbie with
>L> Emacs.

I tested it and I can get this message also. It happens when you have no
Python shell running (*Python* buffer). The python code is then executed
by calling the python shell command and catching the output. This output
is displayed in the *Python Output* buffer. It happens also with C-c C-c
and it will give the same message.

There is a difference, however between C-c C-x and C-c RET: The latter
will import your module, and most modules are written such that
importing them doesn't print anything. If you add something like 
print "test" and the end of file, then "test" will appear in the *Python
Output*  buffer.

If your file has the print "hello world" statement it should display in
the *Python Output* buffer. I checked that.

On the other hand, if you have a python shell running you must make sure
(e.g. with the cd command) that its working directory is the directory
where your python file is located, otherwise the import statement will
not find your file. Unless it is somewhere in the python path. Also the
*Python* buffer will not automatically pop up if it is not visible, in
contrast with the *Python Output* buffer.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pydev 1.4.7 Released

2009-07-09 Thread Fabio Zadrozny
Yes.

On Thu, Jul 9, 2009 at 3:32 AM, Morten Nygaard
Aasnes wrote:
> On 2009-07-08, Fabio Zadrozny  wrote:
>> Hi All,
>>
>> Pydev and Pydev Extensions 1.4.7 have been released
>>
>> Details on Pydev Extensions: http://www.fabioz.com/pydev
>> Details on Pydev: http://pydev.sf.net
>> Details on its development: http://pydev.blogspot.com
>
> Nice! Will this work in Eclipse 3.5 as well?
>
> --
> Morten Nygaard Åsnes   http://twitter.com/mortenaa   http://identi.ca/mortenaa
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: older pythons

2009-07-09 Thread superpollo

Lie Ryan wrote:


AFAIK, no major linux distributions have officially ported to python
3.x.


http://packages.debian.org/experimental/python3.1

thanks for help
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-07-09 Thread Helvin
On Jul 9, 6:27 pm, Helvin  wrote:
> On Jul 9, 11:29 am, Robert Kern  wrote:
>
>
>
>
>
> > On 2009-07-08 18:10, Helvin wrote:
>
> > > Thanks for the fast replies! I will look into how to use VTK now.
> > > Where would I find VTK's explicit support for PyQt?
>
> > Wrapping/Python/vtk/qt4/ in the VTK sources.
>
> > > Because I have installed VTK (using its installer) and pyVTK (using
> > > its setup.py file), but how do I actually use it in my code? According
> > > to:http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521...,
> > > I have tried 'import vtk', but python can't find the vtk module.
>
> > Then you have not installed VTK's Python bindings correctly. Note that 
> > pyVTK is
> > just a library for manipulating VTK files. The VTK Python bindings are part 
> > of
> > VTK's distribution itself. Exactly how did you install VTK? Did you compile 
> > it
> > yourself?
>
> > --
> > 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
>
> You mean, when I download VTK, the VTK Python bindings come with it?
> I downloaded VTK from:http://vtk.org/files/release/5.4/
>
> I downloaded pyVTK from:http://pypi.python.org/pypi/PyVTK/0.4.67
> And then installed it by the command 'python setup.py install'
> according to:http://cens.ioc.ee/projects/pyvtk/
> I understand that this command runs the file called 'setup.py' that
> came with the pyVTK download.
>
> Thanks so much for your help! I am very desperate now...
>
> Helvin

I googled: vtk for beginners python.
>From there, I found this: 
>http://www.nabble.com/pls-help-how-to-install-VTK-and-run-td14977428.html
And from there, this: 
http://www-viz.tamu.edu/courses/viza658/08spring/tutorials/WinVTKInstall.html

This last one has very detailed info about how to get started with
VTK. I am now redoing the installing VTK thing. Hope it will work.

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


Re: property using a classmethod

2009-07-09 Thread Bruno Desthuilliers

Emanuele D'Arrigo a écrit :

Greetings,

today I did something like this:

class MyClass(object):

@classmethod
def myClassMethod(self):


 Usually, the first argument of classmethods is named 'cls' 


 print "ham"

 myProperty = property(myClassMethod, None, None)

As many of you know this doesn't work and returns a TypeError: the
object passed to the property is not a callable function but a
classmethod object, which isn't callable at all.  So, how do I do this?
Ultimately all I want is a non-callable class-level attribute
MyClass.myProperty


properties *are* class attributes.


that gives the result of MyClass.myClassMethod().

Can it be done?


You could write your own custom descriptor. Or just use an additional 
level of indirection, ie:


   myProperty = property(lambda self: self.myClassMethod())


but since you already have myClassMethod available, I don't see the 
point. What problem are you trying to solve exactly ?


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


Particle research opens door for new technology

2009-07-09 Thread Rashid Ali Soomro
Big uses for small particles will be explored at the annual Particle
Technology Research Centre Conference at The University of Western
Ontario July 9 and 10.
for more details on http://0nanotechnology0.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: older pythons

2009-07-09 Thread Lie Ryan
superpollo wrote:
> Lie Ryan wrote:
> 
>> AFAIK, no major linux distributions have officially ported to python
>> 3.x.
> 
> http://packages.debian.org/experimental/python3.1
> 
> thanks for help

Note the word "experimental"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-ldap

2009-07-09 Thread Michael Ströder
Larry kavanagh wrote:
> I need a PYTHON-LDAP package.
> 
> I'm trying to install ploneldap and it tells me I need python-ldap
> package first  .. but I can't find one to match my versions.
> 
> I'm using plone 3.2.2, Python 2.4.4 and Zope 2.10.7 on a Win32 environment.

Did you check all the links on this page?

  http://www.python-ldap.org/download.shtml

There's a MSI installer for Python 2.4 on Win32:

http://pypi.python.org/packages/2.4/p/python-ldap/python-ldap-2.3.8.win32-py2.4.exe#md5=35da547711280c18bd4ccd6e637cdf9b

There has been an update of the .egg files recently (also link on the
download page above).

Ciao, Michael.

-- 
Michael Ströder
E-Mail: mich...@stroeder.com
http://www.stroeder.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: unix to Windows technology

2009-07-09 Thread Xah Lee
a fried showed me this today:

http://xahlee.org/funny/Microsoft_eula.html

not sure which site originally reported it.

  Xah
∑ http://xahlee.org/

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


Re: older pythons

2009-07-09 Thread superpollo

Lie Ryan wrote:

superpollo wrote:


Lie Ryan wrote:



AFAIK, no major linux distributions have officially ported to python
3.x.


http://packages.debian.org/experimental/python3.1

thanks for help



Note the word "experimental"


i noticed. isn't experimental official? i thought it was...

thanks for your reply

bye and god bless you
--
http://mail.python.org/mailman/listinfo/python-list


Re: older pythons

2009-07-09 Thread Marco Mariani

superpollo wrote:

what i was asking for is about a way to *INSTALL* and mantain different 
python versions, a task i think is not unusal for developers.


Check out virtualenv, I ask myself how I could work without it.

http://pypi.python.org/pypi/virtualenv

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


Re: property using a classmethod

2009-07-09 Thread Lie Ryan
Emanuele D'Arrigo wrote:
> Greetings,
> 
> today I did something like this:
> 
> class MyClass(object):
> 
> @classmethod
> def myClassMethod(self):
>  print "ham"
> 
>  myProperty = property(myClassMethod, None, None)
> 
> As many of you know this doesn't work and returns a TypeError: the
> object passed to the property is not a callable function but a
> classmethod object, which isn't callable at all.

That code runs fine for me. Although I doubt the behavior is what you
wanted to do.

> So, how do I do this?
> Ultimately all I want is a non-callable class-level attribute
> MyClass.myProperty that gives the result of MyClass.myClassMethod().

This works like what you seem to want (it's ugly):

class MyClass(object):
class _MyClass(object):
@classmethod
def myClassMethod(cls):
return 'ham'
@property
def myProperty(self):
return MyClass._MyClass.myClassMethod()
@classmethod
def myClassMethod(cls):
return MyClass._MyClass.myClassMethod()
@property
def myProperty(self):
return MyClass._MyClass.myClassMethod()

def __call__(self, *args, **kargs):
# this is __init__
return MyClass._MyClass(*args, **kargs)
# note this is NOT a real MyClass instantiation
MyClass = MyClass()

$ python -i ./strangeclass.py
>>> MyClass.myClassMethod()
'ham'
>>> MyClass.myProperty
'ham'
>>> mc = MyClass()
>>> mc.myProperty
'ham'
>>> mc.myClassMethod()
'ham'
-- 
http://mail.python.org/mailman/listinfo/python-list


Hello

2009-07-09 Thread Tanmoy
>
> Hello ,
>  When i==0 you append an empty list to arr, so arr[i] is arr[0]. No
> problem.
>
> When i==10 you append another empty list to arr, so arr[i] is arr[10].
> Index error because there's no arr[10], only arr[0] and arr[1].
>
> Thanks for your prompt reply...
>
> How can i pass this problem
>
>  You could try appending to arr[-1] instead.

Better still:

   ...
   row = []
   for j in range(0,1001,1):
 row.append(i+j)
   arr.append(row)
   ...
I tried both the ways... the only thing is its not coming like 0 10
20...1000 . Its coming like 0,1,2,1000.Any answer to the
problem.
Thanks
Tanmoy Mukherjee
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function local namespace question

2009-07-09 Thread Dave Angel

Paul LaFollette wrote:

Kind people,

Using Python 3.1 under FreeBSD and WinXP.

I've been tearing my hair out trying to solve this myself, but I need
to ask for help.   I want (for obscure reasons) to be able to log
transactions in the namespace(s) of a script.  Specifically I would
like to log creation of identifiers, changes in the binding of
identifiers ("assignment") and lookups.  This turns out to be pretty
easy in the global and local namespaces... I simply subclass dict,
override the appropriate operations to include the logging operations
I want, and then exec the code using my dictionaries as the global and
local namespaces.  All  of this  works just dandy until I try to
extend it to functions.

I cannot figure out any way to get a hook into the local namespace of
a user defined function.  I have tried making a wrapper class that
grabs the function call and then uses exec to invoke
myfunction.__code__ with my own dictionaries.  This runs the (no
argument) function properly (losing the return value, but I can deal
with that) but never accesses the local logging dictionary that I
specify in the exec() call. Perhaps the local namespace of a function
is not a dict at all?

Anyway, is there any way (however clumsy) to do what I want to do?
Thank you for your help.
Paul

---
Paul LaFollette
CIS Department
Temple University
paul.lafollette(at)temple.edu
www.cis.temple.edu/~lafollet

  

Is there a way?  Undoubtedly.

The simplest way that occurs to me is to have a pre-pass that rewrites 
the .pyc files, adding instrumentation to the byte-code.  You could also 
recompile the Python interpreter, with some extra hooks in it.  That 
could get tricky, as you don't want to instrument the code that's doing 
the tracking.  Fnally, you could hook into the byte-code loader, doing 
the changes at that time.


As always, if the code is for commercial use, beware of infringing on 
patents.  I have a few in the 3rd area (though the ownership is with 
other companies;  I was just the inventor.)


DaveA

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


Re: function local namespace question

2009-07-09 Thread Diez B. Roggisch
Dave Angel wrote:

> Paul LaFollette wrote:
>> Kind people,
>>
>> Using Python 3.1 under FreeBSD and WinXP.
>>
>> I've been tearing my hair out trying to solve this myself, but I need
>> to ask for help.   I want (for obscure reasons) to be able to log
>> transactions in the namespace(s) of a script.  Specifically I would
>> like to log creation of identifiers, changes in the binding of
>> identifiers ("assignment") and lookups.  This turns out to be pretty
>> easy in the global and local namespaces... I simply subclass dict,
>> override the appropriate operations to include the logging operations
>> I want, and then exec the code using my dictionaries as the global and
>> local namespaces.  All  of this  works just dandy until I try to
>> extend it to functions.
>>
>> I cannot figure out any way to get a hook into the local namespace of
>> a user defined function.  I have tried making a wrapper class that
>> grabs the function call and then uses exec to invoke
>> myfunction.__code__ with my own dictionaries.  This runs the (no
>> argument) function properly (losing the return value, but I can deal
>> with that) but never accesses the local logging dictionary that I
>> specify in the exec() call. Perhaps the local namespace of a function
>> is not a dict at all?
>>
>> Anyway, is there any way (however clumsy) to do what I want to do?

You might consider using the trace-functionality of python, exposed throug

 sys.settrace

It's very expensive of course to do that.

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


Re: property using a classmethod

2009-07-09 Thread Bruno Desthuilliers

Lie Ryan a écrit :

Emanuele D'Arrigo wrote:

(snip)

Ultimately all I want is a non-callable class-level attribute
MyClass.myProperty that gives the result of MyClass.myClassMethod().


This works like what you seem to want (it's ugly):


Ugly, indeed. And an extreme case of arbitrary overcomplexification too :-/

(snip rube goldberg code)

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


Re: older pythons

2009-07-09 Thread superpollo

Marco Mariani wrote:

superpollo wrote:

what i was asking for is about a way to *INSTALL* and mantain 
different python versions, a task i think is not unusal for developers.



Check out virtualenv, I ask myself how I could work without it.

http://pypi.python.org/pypi/virtualenv



much obliged!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Catching control-C

2009-07-09 Thread Lie Ryan
Michael Mossey wrote:
> On Jul 6, 2:47 pm, Philip Semanchuk  wrote:
>> On Jul 6, 2009, at 5:37 PM, Michael Mossey wrote:
>>
>>> What is required in a python program to make sure it catches a  
>>> control-
>>> c on the command-line? Do some i/o? The OS here is Linux.
>> You can use a try/except to catch a KeyboardInterrupt exception, or  
>> you can trap it using the signal 
>> module:http://docs.python.org/library/signal.html
>>
>> You want to trap SIGINT.
>>
>> HTH
>> Philip
> 
> Thanks to both of you. However, my question is also about whether I
> need to be doing i/o or some similar operation for my program to
> notice in any shape or form that Control-C has been pressed. In the
> past, I've written Python programs that go about their business
> ignoring Ctrl-C. Other programs respond to it immediately by exiting.
> I think the difference is that the latter programs are doing i/o. But
> I want to understand better what the "secret" is to responding to a
> ctrl-C in any shape or form.
> 
> For example, does trapping SIGINT always work, regardless of what my
> process is doing?
> 
> Thanks,
> Mike

Are you asking: "when would the python interpreter process
KeyboardInterrupt?"

In a multi threaded python program (where KeyboardInterrupt doesn't
always work), only the main thread can process KeyboardInterrupt; thus
the main thread must regain control before the interrupt is raised.
Normally, python will context switch (i.e. thread switch) every 100
interpreter "ticks", but when the interpreter received a SIGINT, the
interpreter will try to context switch as fast as it can (every tick) to
allow the main thread to regain control. So the answer is in
multithreaded python program: "when the main thread regains control"

In single threaded python program, the currently running thread is
always the main thread (which can handle KeyboardInterrupt). I believe
SIGINT is checked at every ticks. But SIGINT cannot interrupt atomic
operations (i.e. it cannot interrupt long operations that takes a single
tick).

An example, where python have difficulties processing KeyboardInterrupt:
>>> print 'foo'*1000
...foofoofoo...
because printing a string is an atomic operation

I believe a tick in python is equivalent to a single bytecode, but
please correct me if I'm wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hello

2009-07-09 Thread MRAB

Tanmoy wrote:

Hello ,
 When i==0 you append an empty list to arr, so arr[i] is
arr[0]. No
problem.

When i==10 you append another empty list to arr, so arr[i] is arr[10].
Index error because there's no arr[10], only arr[0] and arr[1].
 
Thanks for your prompt reply...


How can i pass this problem

You could try appending to arr[-1] instead.

Better still:

   ...
   row = []
   for j in range(0,1001,1):
 row.append(i+j)
   arr.append(row)
   ...
I tried both the ways... the only thing is its not coming like 0 10 
20...1000 . Its coming like 0,1,2,1000.Any answer to the 
problem.



Each row should be 1 more than the previous row and each column should
be 10 more than the previous column. Just swap your ranges.
--
http://mail.python.org/mailman/listinfo/python-list


Re: tough-to-explain Python

2009-07-09 Thread Dave Angel

greg wrote:
Dave 
Angel wrote:

By the time I graduated, I had five six-level languages

  ^^^

Are they languages that you have to edit using vi? :-)

Back then I didn't need glasses.  That was of course intended to be  
"six high-level languages"



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


Re: Emacs Python-mode. Newbie problem.

2009-07-09 Thread Lacrima
On Jul 9, 2:31 pm, Piet van Oostrum  wrote:
> > Lacrima  (L) wrote:
> >L> Thanks for your reply!
> >L> My file name is 'trains.py'.
> >L> When I do C-h k C-c RET, it shows me help from manual: "C-c RET runs
> >L> the command py-execute-import-or-reload
> >L>    which is an interactive Lisp function in `python-mode'..." and so
> >L> on.
> >L> And still when I do C-c RET, I receive "(Shell command succeeded with
> >L> no output)"
> >L> Any more help would be really appreciated, because I am newbie with
> >L> Emacs.
>
> I tested it and I can get this message also. It happens when you have no
> Python shell running (*Python* buffer). The python code is then executed
> by calling the python shell command and catching the output. This output
> is displayed in the *Python Output* buffer. It happens also with C-c C-c
> and it will give the same message.
>
> There is a difference, however between C-c C-x and C-c RET: The latter
> will import your module, and most modules are written such that
> importing them doesn't print anything. If you add something like
> print "test" and the end of file, then "test" will appear in the *Python
> Output*  buffer.
>
> If your file has the print "hello world" statement it should display in
> the *Python Output* buffer. I checked that.
>
> On the other hand, if you have a python shell running you must make sure
> (e.g. with the cd command) that its working directory is the directory
> where your python file is located, otherwise the import statement will
> not find your file. Unless it is somewhere in the python path. Also the
> *Python* buffer will not automatically pop up if it is not visible, in
> contrast with the *Python Output* buffer.
> --
> Piet van Oostrum 
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p...@vanoostrum.org

Thank you for really useful and detailed explanation. Now I can test
my code using Emacs.
But I think it works for me in a little bit different way.
My file contains only the print 'hello world'.
If I have no python shell running, then:
a) C-c RET opens *Python Output* buffer without any output and with
'Shell command succeeded with no output' message at the bottom
b) C-c C-c opens *Python Output* with appropriate 'hello world'
message.

Then I run python shell with C-c ! command. And:
a) C-c RET opens *Python* buffer and prints 'hello world' in the
python shell
b) C-c C-c gives the same result.

With regards, Max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i write a assemly language programs in python

2009-07-09 Thread Dave Angel

m.reddy prasad reddy wrote:

can any one tell me how to write assembly language programs in python...if
no is there any other way to write the programs in python

Reddi prasad reddy
ph.no:09958083797

  
Assembly language is a different programming language than Python.  You 
can use both in the same process, much in the same way you can use C or 
C++ with Python.  In fact, some of the system DLL's are written (partly) 
in assembler, though mostly in C or C++.


You'll need to tell us what your real goal is.  Are you a python 
programmer trying to optimize some loop?  Are you taking a course in 
assembler, and hope that somehow Python will help?  Do you have Python 
installed on your system?  What system is it?


As far as I know, Python has no "inline assembler" mode, as C does.   So 
anything written in assembler would be in a separate DLL, not mixed in 
your .py files.  It's not hard to mix assembly files with C or C++ files 
(or Pascal, or dozens of other compiled languages), and link them into a 
single DLL.  But Python's access to that DLL will be done through a 
module like ctypes, or SWIG.



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


gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Nick
I've seen a lot of posts on this problem, but none seems to help.
Here is the code:
/code

file = open(prefix1)
text = file.readlines()
len = len(text)
fields = text[1].split()
num_rows = int(fields[1])
num_cols = int(fields[2])

U1_matrix = []

print fields
print repr(fields)
print len(fields)

for line in text[2: num_rows+2]:
fields = line.split()
#print "fields", fields, line
for i in range(len(fields)):
fields[i] = float(fields[i])
U1_matrix.append(fields)

/*code

prefix is a space/line delimited ascii file that represents a 2D
matrix.  i'm trying to read in 2 matrices from different files, strip
away the header stuff and then take the dot product of the 2
matrices.  any help is much appreciated.

thanks,
nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tough-to-explain Python

2009-07-09 Thread Benjamin Kaplan
On Thu, Jul 9, 2009 at 1:05 AM, Simon Forman wrote:
> Everyone gets so caught up in programming via languages that
> you get, well, people trying to teach "Computer Programming" as if it
> were only necessary to grok a language, rather than grokking /symbol
> manipulation/ itself.
>
>

+1 QOTW.

I'm a CS major and this is exactly what I see happening in the intro
to CS courses. In class, the "Intro to Programming" students are
showed how to write Java code. Then they try their homework and are
completely lost because they were never taught how to think like a
programmer so they don't understand how to approach the question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Blocking XMPP API?

2009-07-09 Thread Gabriel Rossetti

Hello everyone,

I am looking for blocking XMPP API. I'm wanting to make a webservice 
that uses XMPP, but all the XMPP libs I find are non-blocking (i.e. w/ 
callbacks). I'd like to be able to do something like :


cl = Client("t...@domain.com/res01", "password",)
msg = "any ideas? Using Java I have Smack which can either get msgs sync or 
async, but I found nothing that can do this in Python.


Thanks,
Gabriel

--
Arimaz SA
Ingénieur en Informatique
Av. du 24 Janvier 11
Ateliers de la Ville de Renens, Atelier 5
1020 Renens, Switzerland
www.arimaz.com
www.mydeskfriend.com
Mob: +41-(0)79-539-0069
Tel: +41-(0)21-566-7343

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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Lutz Horn
Hi,

Nick schrieb:
> I've seen a lot of posts on this problem, but none seems to help.

Could you please post a sample input file and the exact error message?

Thanks
Lutz
-- 
Strike Out ⇒ http://www.fourmilab.ch/documents/strikeout
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: older pythons

2009-07-09 Thread Benjamin Kaplan
On Thu, Jul 9, 2009 at 8:10 AM, Lie Ryan wrote:
> superpollo wrote:
>> Lie Ryan wrote:
>>
>>> AFAIK, no major linux distributions have officially ported to python
>>> 3.x.
>>
>> http://packages.debian.org/experimental/python3.1
>>
>> thanks for help
>
> Note the word "experimental"

Assuming that Debian does the same thing as Ubuntu (which is highly
likely), Python3.1 won't install itself as the default. Too many
system features depend on Python 2.x.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Friðrik Már Jónsson

Look at:

  len = len(text)

You're overriding `len` (a built-in method), with an integer  
(`len(text)`).  You then call:


  for i in range(len(fields)):

But `len` is no longer a callable, but merely an integer.

Regards,
Friðrik Már

P.S. While this is a fairly obvious problem it's usually a good idea  
to post working code and a traceback when requesting help.

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


Re: Check file is locked?

2009-07-09 Thread Gabriel Genellina
En Thu, 09 Jul 2009 07:53:29 -0300, Rajat   
escribió:



Thanks Tim for the details. Just further on this, my whole idea is to
close the wordpad / notepad application so that I can delete the file
and the directory where this file resides.

With notepad it is no more a problem. But I'm concerned about the
wordpad now.


I don't see Wordpad keeping the file open either.
If you can't remove the file, use "handle.exe filename.txt" to discover  
which process is holding it open, as Tim already explained.


--
Gabriel Genellina

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


Re: Hello

2009-07-09 Thread Dave Angel
You could pick a much better title.  And apparently you started a new 
thread with this one.  When responding to an existing message, you ought 
to reply-all to the existing message, rather than starting a new thread.


Tanmoy wrote:

Hello ,
 When i==0 you append an empty list to arr, so arr[i] is arr[0]. No
problem.

When i==10 you append another empty list to arr, so arr[i] is arr[10].
Index error because there's no arr[10], only arr[0] and arr[1].

Thanks for your prompt reply...

How can i pass this problem

 You could try appending to arr[-1] instead.



Better still:

   ...
   row = []
   for j in range(0,1001,1):
 row.append(i+j)
   arr.append(row)
   ...
I tried both the ways... the only thing is its not coming like 0 10
20...1000 . Its coming like 0,1,2,1000.Any answer to the
problem.
Thanks
Tanmoy Mukherjee

  
If you want the row to count by 10's you have to build it that way.  You 
have the arguments to the ranges backwards.  Try:



arr=[]
for i in range(1001):
  row = []
  for j in range(0,1010,10):
row.append(i+j)
  arr.append(row)

Coincidentally, once you reverse them, the original problem would go 
away.  But this is better anyway, as it makes it clear what's 
happening.  You are building 1001 rows, each containing non-contiguous 
numbers.


DaveA

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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Richard Brodie

"Nick"  wrote in message 
news:e54c4461-c0b7-42fb-8542-cefd7bf5f...@h18g2000yqj.googlegroups.com...

> file = open(prefix1)
> text = file.readlines()
> len = len(text)

You have redefined two built-in functions "file" and "len" in the first three 
lines.
This is usually considered poor practice. Stick to meaningless variable names,
it's safer (only joking).

TypeError: 'int' object is not callable". This means that something you thought
was a function is in fact an integer. It's helpful to post/look at the line 
number of
the error; "how is this line failing", is much easier to answer than
"how is my program failing".

print len(fields)

Here len is an integer, because you redefined it in line 3. I'm guessing this 
is the
problem. 


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


Re: a little wsgi framework

2009-07-09 Thread timmyt
On Jul 7, 5:19 am, Bruno Desthuilliers  wrote:
> timmyt a écrit :
>
> > i'm interested in getting opinions on a smallwsgiframework i
> > assembled from webob, sqlalchemy, genshi, and various code fragments i
> > found on the inter-tubes
>
> > here is the interesting glue - any comments / suggestions would be
> > much appreciated
>
> 
> Well... My first comment would be about the usefulness of yet another
> Python web framework, but let's not worry about this...
> 
>
> > --
> > thewsgiapp
> > --
> > def application(environ, start_response):
> >     path = environ.get('PATH_INFO', '').lstrip('/')
>
> >     for regex, callback in urls:
> >         match = re.search(regex, path)
>
> I don't know where these "urls" come from. But anyway : if they live in
> some sort of long-running process, you may want to precompile them.
>
> >         if match:
> >             environ['myapp.url_args'] = match.groups()
> >             request = webob.Request(environ)
>
> >             try:
> >                 return callback(request, start_response)
> >             except Exception, ex:
>
> How are redirect etc handled ?
>
> >                 start_response('500 Internal Server Error', [('Content-
> > Type', 'text/plain')])
> >                 return [traceback.format_exc()]
>
> A configuration option controlling the display of the traceback would be
> fine - I surely don't want the traceback being displayed to anyone when
>   the app goes into production.
>
> Also, logging the error and traceback might be useful.
>
> >     start_response('404 Not Found', [('Content-Type', 'text/plain')])
> >     return ["Couldn't find the URL specified."]
>
> And in both cases, having the ability to use "custom" 500 and 404 pages
> might be nice too.
>
>
>
> > --
> > the controller decorator
> > --
> > def web_decorator(filename, method='html'):
>
> >     def decorator(target):
>
> May I suggest some renaming here ?
>
> filename => path (or 'template_path' ?)
> method   => content_type
> target   => controller or function or callback or
>
> >         def wrapper(request, start_response):
>
> >             #genshi TemplateLoader
> >             template = loader.load(filename)
>
> >             global config
>
> Probably not thread-safe
>
> >             try:
> >                 return_dict = target(request, start_response)
> >                 return_string = template.generate(**return_dict).render
> > (method)
>
> Renaming again:
> return_dict => context
> return_string => data or text or ???
>
> >                 config['database.Session'].commit()
> >             except:
> >                 config['database.Session'].rollback()
> >                 raise
> >             finally:
> >                 config['database.Session'].remove()
>
> This doesn't leave much control on transactions... Sometimes you want to
> handle it manually one way or another.
>
> >             #TODO: alter 'Content-Type' per method being passed
> >             start_response('200 OK', [('Content-Type', 'text/html')])
> >             return [return_string]
>
> Ok, so here again, I don't understand how redirects can work. Also, if
> you do use start_response here, I don't get why you still pass it to the
> callback function.
>
> >         return wrapper
>
> >     return decorator
>
> slightly OT, but preserving infos on the decorated function might help
> too (introspection, debugging etc).
>
> My 2 cents...

thank you gentlemen

i'm now looking for Redirect exceptions as well, and returning the
appropriate response code (stole this idea from turbogears)

i like doing the response codes and exceptions myself which is why i'm
not using the webob response - i think it's more explicit and
straightforward

the conditional display of errors goes without say - that will be
trivial to add

the 'global config' line was an error - config is a module level
variable set before the application definition

i assume as long as i don't write to the config variable within the
application it is thread-safe - is that correct

the underlying assumption is the wsgi application setup does not have
to be thread safe - this is only run once per process






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


Problem with two instances of PySerial

2009-07-09 Thread Shine Jose
Hello friends,I am developing an application to read data from serial port
and display it on the screen using GUI developed in pyQT. For this I have
instantiated the GUI as well as pySerial objects in the main thread. I have
provided a button 'Read' which when clicked by the user reads from the
serial port using read() method of pySerial. However, for debugging purposes
I also want to poll the serial port continuously for arrival of data and
display on screen. I achieve this by creating a separate worker thread to
poll the serial port for arrival of data and then updating the required
widget in main thread of program. For polling the serial port, I create a
separate instance of pySerial object. However, I am unable to read any data
in the worker thread. Can the reason for this be 2 instances of pySerial
objects being connected to serial port. The reason I had this doubt was
because Serial.Connect() in the worker thread did not throw any exception &
isOpen() method returns true.
I request you to help me in figuring out the problem.

-- 
Regards,
Shine Jose
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Nick
On Jul 9, 10:02 am, "Richard Brodie"  wrote:
> "Nick"  wrote in message
>
> news:e54c4461-c0b7-42fb-8542-cefd7bf5f...@h18g2000yqj.googlegroups.com...
>
> > file = open(prefix1)
> > text = file.readlines()
> > len = len(text)
>
> You have redefined two built-in functions "file" and "len" in the first three 
> lines.
> This is usually considered poor practice. Stick to meaningless variable names,
> it's safer (only joking).
>
> TypeError: 'int' object is not callable". This means that something you 
> thought
> was a function is in fact an integer. It's helpful to post/look at the line 
> number of
> the error; "how is this line failing", is much easier to answer than
> "how is my program failing".
>
> print len(fields)
>
> Here len is an integer, because you redefined it in line 3. I'm guessing this 
> is the
> problem.

thanks for spotting the obvious errors, its my 2nd day programming
python in about 3 years.
fridrick, code should be workable with the exception of the
errors...thats the whole program

Thanks again for all the help problem fixed
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Bruno Desthuilliers

Nick a écrit :

I've seen a lot of posts on this problem, but none seems to help.
Here is the code:
/code

file = open(prefix1)


shadows the builtin 'file' type.



text = file.readlines()
len = len(text)


shadows the builtin 'len' function.


fields = text[1].split()
num_rows = int(fields[1])
num_cols = int(fields[2])

U1_matrix = []

print fields
print repr(fields)
print len(fields)


And here's your problem - 'len' is now bound to the result of the 
previous call to len(text).


Hint : Python's functions, classes and modules are objects too, and 
don't live in a distinct namespace. So _don't_ use builtin's types / 
functions / etc names as identifiers.


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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Dave Angel

Nick wrote:

I've seen a lot of posts on this problem, but none seems to help.
Here is the code:
/code

file = open(prefix1)
text = file.readlines()
len = len(text)
fields = text[1].split()
num_rows = int(fields[1])
num_cols = int(fields[2])

U1_matrix = []

print fields
print repr(fields)
print len(fields)

for line in text[2: num_rows+2]:
fields = line.split()
#print "fields", fields, line
for i in range(len(fields)):
fields[i] = float(fields[i])
U1_matrix.append(fields)

/*code

prefix is a space/line delimited ascii file that represents a 2D
matrix.  i'm trying to read in 2 matrices from different files, strip
away the header stuff and then take the dot product of the 2
matrices.  any help is much appreciated.

thanks,
nick

  
You have at least two problems with that code, one of which is causing 
your symptom.


Both 'file' and 'len' are defined in the standard library, and shouldn't 
be redefined in your code.  And your problem is that after you redefined 
'len', you then tried to use it in its original meaning.



Rename those two and you'll get further.

And it would have saved lots of time for lots of people if you included 
sample data and the actual error message, marking where in your code it 
occurs.  Once you know it's complaining about the len() call, it's not 
too hard to figure out that the problem was you rebound the len 
attribute from a function to an integer.


Traceback (most recent call last):
 File "M:\Programming\Python\sources\dummy\echo2.py", line 21, in 
   print len(fields)
TypeError: 'int' object is not callable


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


Re: count

2009-07-09 Thread J. Cliff Dyer
Bearophile wins!  (This only times the loop itself.  It doesn't check
for __len__)

summer:5
0:00:00.51
bearophile:5
0:00:00.09
summer:50
0:00:00.30
bearophile:50
0:00:00.13
summer:500
0:00:00.77
bearophile:500
0:00:00.53
summer:5000
0:00:00.000575
bearophile:5000
0:00:00.000473
summer:5
0:00:00.005583
bearophile:5
0:00:00.004625
summer:50
0:00:00.055834
bearophile:50
0:00:00.046137
summer:500
0:00:00.426734
bearophile:500
0:00:00.349573
summer:5000
0:00:04.180920
bearophile:5000
0:00:03.652311
summer:5
0:00:42.647885
bearophile: 5
0:00:35.190550

On Thu, 2009-07-09 at 04:04 -0700, Bearophile wrote:
> Paul Rubin:
> > print x, sum(1 for _ in g)
> 
> Don't use that, use my function :-) If g has a __len__ you are wasting
> time. And sum(1 ...) is (on my PC) slower.
> 
> 
> J. Clifford Dyer:
> > if __name__ == '__main__':
> > test_func(summer, 1000)
> > test_func(tupler, 1000)
> > test_func(summer, 1)
> > test_func(tupler, 1)
> 
> Have you forgotten my function?
> 
> Bye,
> bearophile

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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Friðrik Már Jónsson

Previously, I wrote:
P.S. While this is a fairly obvious problem it's usually a good  
idea to post working code and a traceback when requesting help.


Nick wrote:

thanks for spotting the obvious errors, its my 2nd day programming
python in about 3 years.


I'm sorry, my saying it was obvious may have come off a little  
arrogant. My clumsily delivered point was that because it was a small  
snippet of code it didn't take much time to run through for someone  
who codes daily with Python. What you did there was a perfectly  
ordinary thing to do until experience teaches you how Python does  
things. :)



fridrick, code should be workable with the exception of the
errors...thats the whole program


You're right, I failed to say it explicitely but I was referring to  
the input file.  In some cases, albeit not this one, problems can  
exist in parsing gotchas.


Regards,
Friðrik Már
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-07-09 Thread Robert Kern

On 2009-07-09 01:27, Helvin wrote:

On Jul 9, 11:29 am, Robert Kern  wrote:

On 2009-07-08 18:10, Helvin wrote:


Thanks for the fast replies! I will look into how to use VTK now.
Where would I find VTK's explicit support for PyQt?

Wrapping/Python/vtk/qt4/ in the VTK sources.


Because I have installed VTK (using its installer) and pyVTK (using
its setup.py file), but how do I actually use it in my code? According
to:http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521...,
I have tried 'import vtk', but python can't find the vtk module.

Then you have not installed VTK's Python bindings correctly. Note that pyVTK is
just a library for manipulating VTK files. The VTK Python bindings are part of
VTK's distribution itself. Exactly how did you install VTK? Did you compile it
yourself?


You mean, when I download VTK, the VTK Python bindings come with it?
I downloaded VTK from:http://vtk.org/files/release/5.4/


Exactly which file did you download? I don't think the vtk-5.4.x-win32.exe 
installers have the Python bindings. You will need to build VTK from sources.


--
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: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Nick
no problem, i understand, i haven't coded anything in literally 2
years, but it was a simple and pretty obvious mistake.  thanks for all
your help,

nick


On Jul 9, 11:30 am, Friðrik Már Jónsson  wrote:
> Previously, I wrote:
> >> P.S. While this is a fairly obvious problem it's usually a good
> >> idea to post working code and a traceback when requesting help.
> Nick wrote:
> > thanks for spotting the obvious errors, its my 2nd day programming
> > python in about 3 years.
>
> I'm sorry, my saying it was obvious may have come off a little
> arrogant. My clumsily delivered point was that because it was a small
> snippet of code it didn't take much time to run through for someone
> who codes daily with Python. What you did there was a perfectly
> ordinary thing to do until experience teaches you how Python does
> things. :)
>
> > fridrick, code should be workable with the exception of the
> > errors...thats the whole program
>
> You're right, I failed to say it explicitely but I was referring to
> the input file.  In some cases, albeit not this one, problems can
> exist in parsing gotchas.
>
> Regards,
> Friðrik Már

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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Tom Kermode
Hi,

   Do you know a good way to avoid running into this problem?  It
makes sense to suggest not calling variables the same names as
built-in functions, but that's hard for a new python programmer who
doesn't already know what all the built-in functions are. Over time a
programmer will learn which names to avoid, but it's a bit of a
pitfall early on.

Cheers,
Tom



2009/7/9 Richard Brodie :
>
> "Nick"  wrote in message
> news:e54c4461-c0b7-42fb-8542-cefd7bf5f...@h18g2000yqj.googlegroups.com...
>
>> file = open(prefix1)
>> text = file.readlines()
>> len = len(text)
>
> You have redefined two built-in functions "file" and "len" in the first three 
> lines.
> This is usually considered poor practice. Stick to meaningless variable names,
> it's safer (only joking).
>
> TypeError: 'int' object is not callable". This means that something you 
> thought
> was a function is in fact an integer. It's helpful to post/look at the line 
> number of
> the error; "how is this line failing", is much easier to answer than
> "how is my program failing".
>
> print len(fields)
>
> Here len is an integer, because you redefined it in line 3. I'm guessing this 
> is the
> problem.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.kiloday.com
http://www.fourstopspast.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter problem

2009-07-09 Thread Paul Simon

"Peter Otten" <__pete...@web.de> wrote in message 
news:h3481q$d95$0...@news.t-online.com...
> Paul Simon wrote:
>
>> "Chris Rebert"  wrote in message
>> news:mailman.2863.1247095339.8015.python-l...@python.org...
>> On Wed, Jul 8, 2009 at 4:18 PM, Paul Simon wrote:
>>> I have the "tkinter" problem and need some assistance to straighten it
>>> out.
>>> >From the web page "http://wiki.python.org/moin/TkInter"; I tested as in
>>> >"step
>>> 1" and cannot import "_tkinter." I do not have that file on my computer,
>>> but
>>> do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
>>> directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
>>> This python stuff is great, but the documentation frequently
>>> feels like it is just a bit out of my grasp. I realize that all of this
>>> is free but I understand the instructions on the web page to repair only
>>> to the
>>> point of confusion. I'm not an expert. How do I modify my python
>>> configuration? Is there a file that needs to be edited? Which setup.py
>>> file
>>> do I use? Make? or python setup.py build and python setup.py install?
>>> Thanks. I appreciate your help.
>>
>> - How did you install Python?
>> - What Linux distro are you using?
>>
>> Cheers,
>> Chris
>> http://blog.rebertia.com
>> I"m using Mandriva 2008.1.  I have to tell you honestly that I'm not sure
>> exactly how I installed Python.  Originally I had installed 2.5 from RPM
>> but 2.6 was not available for my distro (2008.1) in RPM.  I downloaded
>> something from python.org and installed.  Not sure if it was tarball or
>> zip file.
>
> Zip or tar doesn't matter, you are installing "from source".
>
> Python has to find the necessary include files for tcl/tk. These are in
> separate packages that you have to install before you invoke Python's
> configure script.
>
> I don't know what they are called on your system -- look for tk-dev.rpm,
> tcl-dev.rpm or similar.
>
> You may run into the same problem with other modules like readline.
>
> Peter
>

Thank you Peter.  I understand what you are saying but don't know how to do 
it.  Although I installed from source, I followed a "cookbook" recipe. 
Could you tell me what files to execute, where they might be, and file 
arguments?  I'm just ignorant, not stupid. ;-).

Paul 


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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Richard Brodie

"Tom Kermode"  wrote in message 
news:mailman.2903.1247155607.8015.python-l...@python.org...

> Do you know a good way to avoid running into this problem?  It
> makes sense to suggest not calling variables the same names as
> built-in functions, but that's hard for a new python programmer who
> doesn't already know what all the built-in functions are.

No, but not redefining the ones you actually use is a good start.
Learning to understand the traceback is the more important lesson,
IMHO. It takes a while to tune into what error messages are trying
to tell you; even when you stop making newbie mistakes, you're
going to have to deal with runtime errors from time to time. 


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


send keys to focused window

2009-07-09 Thread Broken
Hi,
I am new to Python, and I'm miserably failing to send specific keys to 
(say) notepad.

Here is the scenario:
I have notepad open.
My python script is running in the background.
When I press ALT+a I want to intercept the keys and send "ä"(ASCII code: 
ALT+0228) instead.

OS: Windows 7
Libraries used: pyHook, SendKeys, pyWin32

Here is my code:

###
# -*- coding: cp1252 -*-
import pythoncom, pyHook
from SendKeys import SendKeys

def OnKeyboardEvent(event):
if event.Alt == 32: #alt pressed
if event.Ascii == 97:   #a pressed
SendKeys("ä")
return False #don't pass to other handlers

# return True to pass the event to other handlers
return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()

###

It's largely copied from the pyhook example.
My problem is, I need to somehow disable ALT while sonding the key.

Please help :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Running a script to build docs from setup.py

2009-07-09 Thread Tony Houghton
I want to write a setup.py script, using distutils, for a python library
called ROX-Lib2 (package name "rox"). The library includes a script to
build HTML documentation from the pydoc strings. I'd like to run that
script from setup.py but I don't know the best way to do that. I've
looked through the manual but I can't find any hooks in distutils for
generating files at install time other than extension modules and .pyc
files. Should I just run the script from somewhere in my setup.py before
calling distutils' setup function?

-- 
TH * http://www.realh.co.uk

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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Friðrik Már Jónsson

Tom Kermode wrote:

Do you know a good way to avoid running into this problem?  It
makes sense to suggest not calling variables the same names as
built-in functions, but that's hard for a new python programmer who
doesn't already know what all the built-in functions are.


One way is using a code checker like PyChecker[1]. This neat software  
for finding bugs will check for lots of other pitfalls too, but you  
can filter it down to what you need if you're only interested in this  
one.


I don't use an IDE, but this would seem like something for an IDE[2]  
to support if you're into that kind of magic.


Regards,
Friðrik Már

[1] http://pychecker.sourceforge.net/
[2] http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter problem

2009-07-09 Thread Peter Otten
Paul Simon wrote:

> 
> "Peter Otten" <__pete...@web.de> wrote in message
> news:h3481q$d95$0...@news.t-online.com...
>> Paul Simon wrote:
>>
>>> "Chris Rebert"  wrote in message
>>> news:mailman.2863.1247095339.8015.python-l...@python.org...
>>> On Wed, Jul 8, 2009 at 4:18 PM, Paul Simon wrote:
 I have the "tkinter" problem and need some assistance to straighten it
 out.
 >From the web page "http://wiki.python.org/moin/TkInter"; I tested as in
 >"step
 1" and cannot import "_tkinter." I do not have that file on my
 computer, but
 do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
 directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
 This python stuff is great, but the documentation frequently
 feels like it is just a bit out of my grasp. I realize that all of this
 is free but I understand the instructions on the web page to repair
 only to the
 point of confusion. I'm not an expert. How do I modify my python
 configuration? Is there a file that needs to be edited? Which setup.py
 file
 do I use? Make? or python setup.py build and python setup.py install?
 Thanks. I appreciate your help.
>>>
>>> - How did you install Python?
>>> - What Linux distro are you using?
>>>
>>> Cheers,
>>> Chris
>>> http://blog.rebertia.com
>>> I"m using Mandriva 2008.1.  I have to tell you honestly that I'm not
>>> sure
>>> exactly how I installed Python.  Originally I had installed 2.5 from RPM
>>> but 2.6 was not available for my distro (2008.1) in RPM.  I downloaded
>>> something from python.org and installed.  Not sure if it was tarball or
>>> zip file.
>>
>> Zip or tar doesn't matter, you are installing "from source".
>>
>> Python has to find the necessary include files for tcl/tk. These are in
>> separate packages that you have to install before you invoke Python's
>> configure script.
>>
>> I don't know what they are called on your system -- look for tk-dev.rpm,
>> tcl-dev.rpm or similar.
>>
>> You may run into the same problem with other modules like readline.
>>
>> Peter
>>
> 
> Thank you Peter.  I understand what you are saying but don't know how to
> do
> it.  Although I installed from source, I followed a "cookbook" recipe.
> Could you tell me what files to execute, where they might be, and file
> arguments?  I'm just ignorant, not stupid. ;-).
> 
> Paul

Once you have the necessary development packages for tcl/tk just go into the 
directory where you unzipped the source and

./configure
make
sudo make altinstall

Unfortunately I don't know the names of these packages nor how to install 
them, and Google didn't turn up anything useful.

If you don't get any additional answers here you may try a Mandriva forum 
since this is not a question that requires python knowlegde.

Peter

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


Examples of Python driven Microsoft UI Automation wanted

2009-07-09 Thread TheSeeker
Hi,

I am embarking on teaching myself Microsoft UI Automation using Python
as the scripting language.

I have asked some questions in the IronPython users group, but have
yet to get a response, so I thought I would broaden the audience by
asking here.

Specifically, I have a WinForms application I will be wanting to
automate. Does anyone have some Python examples of driving Microsoft
UI Automation they could share with me to get me started? The
structure of the UI automation classes etc. seem quite convoluted, and
I am having difficulty getting my brain wrapped around it.

Alternatives to Microsoft's UI Automation are welcome too, but I have
tried using winguiauto and watsup (along with AutoIt), and there seems
to be severe limitations when using these tools with WinForm
applications.

Thanks in advance,
Duane
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Opening a SQLite database in readonly mode

2009-07-09 Thread Joshua Kugler
Joshua Kugler wrote:
> Sorry about that...since pysqlite and APSW are both discusses on the
> pysqlite list, I had made an incorrect assumption. Oops.

"are both discusses?"  Yeef, I must have been out of it.  Discussed, thank
you. :)

j

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


Re: tough-to-explain Python

2009-07-09 Thread Steven D'Aprano
On Wed, 08 Jul 2009 22:05:57 -0700, Simon Forman wrote:

> The core abstractions of [mechanical] computation are just not that
> complicated.  You can teach them to anybody in about a half an hour,
> drunk. I have.

That's *easy*. Anyone can teach the most complicated and abstract 
principles of any topic at all drunk. What's hard is doing it sober.

http://stackoverflow.com/questions/63668/confessions-of-your-worst-wtf-
moment-what-not-to-do/350267#350267

or http://tinyurl.com/lur784


You'll excuse my skepticism about all these claims about how anyone can 
program, how easy it is to teach the fundamentals of Turing Machines and 
functional programming to anybody at all. Prove it. Where are your peer-
reviewed studies demonstrating such successes on randomly chosen people, 
not self-selected motivated, higher-than-average intelligence students?

In the real world, human beings are prone to serious cognitive biases and 
errors. Our brains are buggy. Take any list of reasoning fallacies, and 
you'll find the majority of people have difficulty avoid them. The first 
struggle is to get them to even accept that they *are* fallacies, but 
even once they have intellectually accepted it, getting them to live up 
to that knowledge in practice is much, much harder.

In fact I'd go further and say that *every single person*, no matter how 
intelligent and well-educated, will fall for cognitive biases and 
fallacious reasoning on a regular basis.

http://en.wikipedia.org/wiki/Cognitive_bias
http://en.wikipedia.org/wiki/Fallacy




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


Re: Examples of Python driven Microsoft UI Automation wanted

2009-07-09 Thread Tim Harig
On 2009-07-09, TheSeeker  wrote:
> Specifically, I have a WinForms application I will be wanting to
> automate. Does anyone have some Python examples of driving Microsoft
> UI Automation they could share with me to get me started? The
> structure of the UI automation classes etc. seem quite convoluted, and
> I am having difficulty getting my brain wrapped around it.

If you find a way to work through the UI using the keyboard (tabs, etc);
then, you can send it keyboard commands using WScript.WshShell.SendKeys():

http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cleaning up after failing to contructing objects

2009-07-09 Thread Lie Ryan
brasse wrote:
> Hello!
> I have been thinking about how write exception safe constructors in
> Python. By exception safe I mean a constructor that does not leak
> resources when an exception is raised within it. The following is an
> example of one possible way to do it:

First, your automatic cleaning Bar() silently pass an unitialized Bar()
into the calling code. When a code fails, it should fail as loud as
possible. Bar() should raises an Exception and the calling code should
turn into something like:

try:
bar = Bar()
except Exception, e:
print 'bar failed to construct'

And about the cleaning up, how about:

class CleanWrap(object):
def __init__(self, cls, cleanup):
self.cls = cls
self.cleanup = cleanup
def __call__(self, *args, **kargs):
try:
return self.cls(*args, **kargs)
except:
self.cleanup()
raise

class Bar(object):
def __init__(self):
CleanWrappedFoo = CleanWrap(Foo, self.close)
self.a = CleanWrappedFoo('a')
self.b = CleanWrappedFoo('b', fail=True)
def close(self):
if hasattr(self, 'a'):
self.a.close()
if hasattr(self, 'b'):
self.b.close()

try:
bar = Bar()
except Exception, e:
print 'Bar() failed to construct'

==
My next attempt is pretty neat, using a totally different approach, see
the docstring for details:

class Foo1(object):
def __init__(self, name, fail=False):
self.name = name
cls_name = self.__class__.__name__
if not fail:
print '%s.__init__(%s)' % (cls_name, self.name)
else:
print '%s.__init__(%s), FAIL' % (cls_name, self.name)
raise Exception()

def close(self):
print '%s.close(%s)' % (self.__class__.__name__, self.name)

class Foo2(object):
def __init__(self, name, fail=False):
self.name = name
cls_name = self.__class__.__name__
if not fail:
print '%s.__init__(%s)' % (cls_name, self.name)
else:
print '%s.__init__(%s), FAIL' % (cls_name, self.name)
raise Exception()

def close(self):
print '%s.close(%s)' % (self.__class__.__name__, self.name)


class CleanList(object):
''' Each CleanList() instance is rigged so that if exceptions happen
in the same CleanList() instance's wrapped class, all objects
created from the wrapped classes in the same CleanList()
instance will be cleaned (see "Usage" for much better
explanation).

Usage:
>>> cleaner = CleanList()
>>> othercleaner = CleanList()
>>> F = cleaner(F, F.close)
>>> G = cleaner(G, G.close)
>>> H = othercleaner(H, H.close)
>>> a = F()
>>> b = F()
>>> c = G()
>>> d = H()
>>> cleaner.cleanall()

cleaner.cleanall() will clean a, b, and c but not d
exceptions in (F|G|H).__init__ will trigger
cleaner.cleanall()

Can be subclassed if you want to override the conditions
that determines the triggering of cleanups
'''
def wrap(self, cls):
''' Wrapper factory that customizes Wrapper's subclass
'''
class Wrapper(cls):
''' Wraps the class' __init__ with cleanup guard.
Subclasses cls to simulate cls as close as possible
'''

# change __class__ to make printing prettier
# e.g. Foo1.__init__ instead of Wrapper.__init__
# probably should be removed
# I'm not sure of the side effects of changing __class__
__class__ = cls

def __init__(self_in, *args, **kargs):
try:
sup = super(Wrapper, self_in)
ret = sup.__init__(*args, **kargs)
except:
self.cleanall()
raise
else:
self.add_to_list(cls, self_in)
return ret
return Wrapper

def __init__(self):
self.cleaners = {}

def __call__(self, cls, cleanup):
''' wraps the class constructor '''
# cleanup, []:
# cleanup is the function called to clean
# [] is the object list for that `cleanup` function
# may not be the best data structure, but it works...
self.cleaners[cls] = cleanup, []
return self.wrap(cls)

def cleanall(self):
''' clean all objects '''
for cleaner, insts in self.cleaners.values():
for inst in insts:
cleaner(inst)

def add_to_list(self, cls, inst):
''' add objects to the cleanup list '''
self.cleaners[cls][1].append(inst)

class Bar(object):
def __init__(self):
clist = CleanList()
otherclist = CleanList()
CleanFoo1 = clist(Foo1, Foo1.close)
CleanFoo2 = clist(Foo2, Foo2.close)
OtherCleanFoo1 = otherclist(Foo1,

Concatenating images (numpy arrays), but they look like HSV images

2009-07-09 Thread Sebastian Schabe

Hello everybody,

I want to concatenate 2 numpy array which in fact are RGB images:

def concat_images(im1,im2):
  rows1 = im1.shape[0]
  rows2 = im2.shape[0]

  if rows1 < rows2:
im1 = concatenate((im1,zeros((rows2-rows1,im1.shape[1],3), int)), 
axis=0)

  elif rows1 > rows2:
im2 = concatenate((im2,zeros((rows1-rows2,im2.shape[1],3), int)), 
axis=0)


  return concatenate((im1,im2), axis=1)

It's all working fine, except that the images when showing with pylab 
are somewhat interpreted as HSV images as it looks. The function zeros() 
must be responsible for that circumstance, because when the arrays have 
the same shape and are concatenated they appear as horizontally 
concatenated images as I expected.


Can someone help me with that?

Thanks a lot,
Basti
--
http://mail.python.org/mailman/listinfo/python-list


Re: property using a classmethod

2009-07-09 Thread Scott David Daniels

Emanuele D'Arrigo wrote:

class MyClass(object):
@classmethod
def myClassMethod(self):
 print "ham"
 myProperty = property(myClassMethod, None, None)

... doesn't work and returns a TypeError:  So, how do I do this?
Ultimately all I want is a non-callable class-level attribute
MyClass.myProperty that gives the result of MyClass.myClassMethod().


properties affect instances, and classes are instances of types.
What you want is a new metaclass:

class MyType(type):
@property
def demo(class_):
return class_.a + 3

class MyClass(object):
__metaclass__ = MyType
a = 5

print MyClass.a, MyClass.demo

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: property using a classmethod

2009-07-09 Thread Lie Ryan
Bruno Desthuilliers wrote:
> Lie Ryan a écrit :
>> Emanuele D'Arrigo wrote:
> (snip)
>>> Ultimately all I want is a non-callable class-level attribute
>>> MyClass.myProperty that gives the result of MyClass.myClassMethod().
>>
>> This works like what you seem to want (it's ugly):
> 
> Ugly, indeed. And an extreme case of arbitrary overcomplexification too :-/
> 
> (snip rube goldberg code)
> 

Can't think of anything simpler than that without meddling with
descriptor. I'm not even sure descriptor can help here as it seems
descriptor needs an instance? (I've just skimmed it, so I may be wrong)

The ugliness of the code hints to two possible reasons:
- there should be a better way
- if there isn't an easier way, then something is wrong the class' design
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Examples of Python driven Microsoft UI Automation wanted

2009-07-09 Thread DuaneKaufman
On Jul 9, 12:18 pm, Tim Harig  wrote:
> On 2009-07-09, TheSeeker  wrote:
>
> > Specifically, I have a WinForms application I will be wanting to
> > automate. Does anyone have some Python examples of driving Microsoft
> > UI Automation they could share with me to get me started? The
> > structure of the UI automation classes etc. seem quite convoluted, and
> > I am having difficulty getting my brain wrapped around it.
>
> If you find a way to work through the UI using the keyboard (tabs, etc);
> then, you can send it keyboard commands using WScript.WshShell.SendKeys():
>
> http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx

Thanks for the link.

Unfortunately, I need to be able to find out the contents of a few
text-boxes as well,
so SendKeys isn't all I need.

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


Re: can i write a assemly language programs in python

2009-07-09 Thread Terry Reedy

Dave Angel wrote:

m.reddy prasad reddy wrote:
can any one tell me how to write assembly language programs in 
python...if

no is there any other way to write the programs in python

Reddi prasad reddy
ph.no:09958083797

  
Assembly language is a different programming language than Python.  You 
can use both in the same process, much in the same way you can use C or 
C++ with Python.  In fact, some of the system DLL's are written (partly) 
in assembler, though mostly in C or C++.


It is possible that he meant how to write assembly *with* python.
Or how to translate python to assembly.

As it turns out, CPython translates Python to byte code and has a dis 
(assembly) module that produces very nice assembly code ;-)

So that is one answer to his question.


You'll need to tell us what your real goal is.


Definitely.

tjr

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


Re: gett error message: "TypeError: 'int' object is not callable"

2009-07-09 Thread Rhodri James

On Thu, 09 Jul 2009 17:06:45 +0100, Tom Kermode  wrote:


Hi,

   Do you know a good way to avoid running into this problem?  It
makes sense to suggest not calling variables the same names as
built-in functions, but that's hard for a new python programmer who
doesn't already know what all the built-in functions are. Over time a
programmer will learn which names to avoid, but it's a bit of a
pitfall early on.


It's only really a pitfall if you try to use the built-in after you've
redefined it.  That's the thing to keep an eye open for.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: older pythons

2009-07-09 Thread Lie Ryan
superpollo wrote:
> Lie Ryan wrote:
>> superpollo wrote:
>>
>>> Lie Ryan wrote:
>>>
>>>
 AFAIK, no major linux distributions have officially ported to python
 3.x.
>>>
>>> http://packages.debian.org/experimental/python3.1
>>>
>> Note the word "experimental"
> 
> i noticed. isn't experimental official? i thought it was...

Official as in "official release"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Emacs Python-mode. Newbie problem.

2009-07-09 Thread Piet van Oostrum
> Lacrima  (L) wrote:

>L> Thank you for really useful and detailed explanation. Now I can test
>L> my code using Emacs.
>L> But I think it works for me in a little bit different way.
>L> My file contains only the print 'hello world'.
>L> If I have no python shell running, then:
>L> a) C-c RET opens *Python Output* buffer without any output and with
>L> 'Shell command succeeded with no output' message at the bottom
>L> b) C-c C-c opens *Python Output* with appropriate 'hello world'
>L> message.

>L> Then I run python shell with C-c ! command. And:
>L> a) C-c RET opens *Python* buffer and prints 'hello world' in the
>L> python shell
>L> b) C-c C-c gives the same result.

Which version of python-mode.el do you have? (Variable py-version)
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter problem

2009-07-09 Thread Terry Reedy

Paul Simon wrote:
"Peter Otten" <__pete...@web.de> wrote in message 
news:h3481q$d95$0...@news.t-online.com...

Paul Simon wrote:




I"m using Mandriva 2008.1.  I have to tell you honestly that I'm not sure
exactly how I installed Python.  Originally I had installed 2.5 from RPM
but 2.6 was not available for my distro (2008.1) in RPM.  I downloaded
something from python.org and installed.  Not sure if it was tarball or
zip file.

Zip or tar doesn't matter, you are installing "from source".

Python has to find the necessary include files for tcl/tk. These are in
separate packages that you have to install before you invoke Python's
configure script.

I don't know what they are called on your system -- look for tk-dev.rpm,
tcl-dev.rpm or similar.

You may run into the same problem with other modules like readline.

Peter



Thank you Peter.  I understand what you are saying but don't know how to do 
it.  Although I installed from source, I followed a "cookbook" recipe. 
Could you tell me what files to execute, where they might be, and file 
arguments?  I'm just ignorant, not stupid. ;-).


Is there a Mandriva list where you can ask such distribution-specific 
questions?


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


Colour of output text

2009-07-09 Thread Alex Rosslyn
Hi,

I would like to learn a way of changing the colour of a particular
part of the output text. I've tried the following:

import os
os.system("color 17")
print "This should be white on blue"

But that command changes the colour of ALL the text and the whole
background. What i'm trying to do is simple: Change a single part (A
letter, a word, a phrase) of the output text.

Is there a way of doing this?

Thanks in advance,

~~A.Rosslyn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Examples of Python driven Microsoft UI Automation wanted

2009-07-09 Thread Tim Harig
On 2009-07-09, DuaneKaufman  wrote:
> On Jul 9, 12:18 pm, Tim Harig  wrote:
>> On 2009-07-09, TheSeeker  wrote:
>> > Specifically, I have a WinForms application I will be wanting to
>> > automate. Does anyone have some Python examples of driving Microsoft
>> > UI Automation they could share with me to get me started? The
>> > structure of the UI automation classes etc. seem quite convoluted, and
>> > I am having difficulty getting my brain wrapped around it.
>> If you find a way to work through the UI using the keyboard (tabs, etc);
>> then, you can send it keyboard commands using WScript.WshShell.SendKeys():
>> http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
> Unfortunately, I need to be able to find out the contents of a few
> text-boxes as well,
> so SendKeys isn't all I need.

Then you will need some way to import your application as an object so that
you can gain access to the methods and properties directly.  Using
IronPython you should be able to access anyting in the GAC.  If you
register your UI componets then you should be able to access them.  If not,
or using cpython, you might be able to do something like:

http://msdn.microsoft.com/en-us/library/fh1h056h(VS.71).aspx

to get a mashalled COM object.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >