LANG, locale, unicode, setup.py and Debian packaging

2008-01-12 Thread Donn Ingle
Hello,
 I hope someone can illuminate this situation for me.

Here's the nutshell:

1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale.

2. If this returns "C" or anything without 'utf8' in it, then things start
to go downhill:
 2a. The app assumes unicode objects internally. i.e. Whenever there is
a "string  like this" in a var it's supposed to be unicode. Whenever
something comes into the app (from a filename, a file's contents, the
command-line) it's assumed to be a byte-string that I decode("utf8") on
before placing it into my objects etc.
 2b. Because of 2a and if the locale is not 'utf8 aware' (i.e. "C") I start
getting all the old 'ascii' unicode decode errors. This happens at every
string operation, at every print command and is almost impossible to fix.

3. I made the decision to check the locale and stop the app if the return
from getlocale is (None,None). 

4. My setup.py (distutils) also tests locale (because it then loads gettext
to give localized information to the user during setup).

5. Because it's doing a raise SystemExit if the locale is (None,None) which
happens if LANG is set to "C", the setup.py stops.

6. Someone is helping me to package the app for Debian/Ubuntu. During the
bizarre amount of Voodoo they invoke to do that, the setup.py is being run
and it is breaking out because their LANG is set to "C"

7. I have determined, as best I can, that Python relies on LANG being set to
a proper string like en_ZA.utf8 (xx_YY.encoding) and anything else will
start Python with the default encoding of 'ascii' thus throwing the entire
app into a medieval dustbin as far as i18n goes.

8. Since I can't control the LANG of the user's system, and I am relying on
it containing 'utf8' in the locale results.. well I seem to be in a
catch-22 here. 

Does anyone have some ideas? Is there a universal "proper" locale that we
could set a system to *before* the Debian build stuff starts? What would
that be - en_US.utf8?

Any words of wisdom would help.
\d

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


Re: How to POST call and retrieve result page

2008-01-12 Thread suyash jape
Hi

/search.php fills the text box values. But /search.php has two form action
elements

1) 
AND
2) 

I  did GET and POST to both results.php  page , which gives *'String could
not be parsed as XML'*  exception.
Should data passed be in some XML format  or normal query ?

POST on blast_results.php also does not work.

I guess i am not able to identify the variable names to be
passed.For/search.php i found the
variables.But couldnt in the other forms.

Thanks for your help..
Suyash




On Jan 11, 2008 10:27 PM, Mike Meyer <[EMAIL PROTECTED]> wrote:

> On Fri, 11 Jan 2008 14:44:19 +0530 "suyash jape" <[EMAIL PROTECTED]>
> wrote:
>
> > Hi all
> > i want to access a web page through python script, fillup the necessary
> > fields,
> > and press submit button (which does POST call) and retrieve the result
> page
> > and retrieve some values from it.
> >
> > Here is the script i have written till now.
> >
> > >import urllib2
> > > # create array of name/value pairs
> > > self.params = urllib.urlencode({'seqname': 'BioSequence', 'sequence':
> > 'ATACATTATCCAAACATAGCATGGCTT'})
> > >
> > > # send http-post
> > > request = urllib.urlopen("http://www.hydrazome.metazome.net/search.php
> ",
> > params)
> > >
> > > # read back each line of reply
> > > line = request.read()
> > >print line
> >
> > This script fills up the correct values in the search.php page.But i am
> not
> > sure if it is doing the POST (submit call).
> > Beacause in 'line' varialble, i am getting the search.php page.Not the
> > result page which is blast_results.php.
> >
> > How to retrieve the result page?
>
> Sounds like you're not POSTing to the right page.
>
> The form on .../search.php lets you fill in values, but those values
> are not necessarily POSTed to search.php. In particular, the form element
> has an action attribute that has a URL to which the values on the page
> should be posted. If that points to .../blast_results.php, then that's
> the page you need to pass to urlopen with your data.
>
> --
> Mike Meyer < [EMAIL PROTECTED]>
> http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 11, 8:04 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > Could you:
>
> > lockerA= Locker( listA, listB )
> > lockerA.op( listB.reverse )
> > lockerA.op( listA.pop )
>
> > Where lockerA ops acquire the locks on all its threads?
>
> I don't understand that question.  The main thing to understand is
> that multi-threaded programming is complicated (especially if you're
> after high performance), and very difficult to get right without
> knowing exactly what you're doing.  The generally preferred approach
> in Python is to keep things simple at some performance cost.
>
> Your Locker approach above looks sort of reasonable if you can be
> absolutely sure that nothing else can mess with listA or listB
> concurrently with those locker operations.  Normally you would put
> listA and listB into a single object along with a lock, then do
> operations on that object.
>
> You might check the Python Cookbook for some specific recipes and
> sample code for this stuff.  If you've used Java, Python's general
> threading mechanisms are similar, but they are in the library rather
> than built into the language (i.e. there is no "synchronized"
> keyword, you have to do that locking explicitly).
>
> What is the actual application, if you don't mind saying?  Are you
> sure that you really need concurrency?

I'm writing an NxN observer pattern, mostly for my own personal
exploration.  Two threads -might- be calling 'Disconnect' at the same
time, and I can't even guarantee that the function runs properly.

for emelem in [ e for e in emlist if e.func is func ]:
try:
emlist.remove( emelem )
except ValueError:
pass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 2:37 am, [EMAIL PROTECTED] wrote:
> On Jan 11, 8:04 pm, Paul Rubin  wrote:
>
>
>
> > [EMAIL PROTECTED] writes:
> > > Could you:
>
> > > lockerA= Locker( listA, listB )
> > > lockerA.op( listB.reverse )
> > > lockerA.op( listA.pop )
>
> > > Where lockerA ops acquire the locks on all its threads?
>
> > I don't understand that question.  The main thing to understand is
> > that multi-threaded programming is complicated (especially if you're
> > after high performance), and very difficult to get right without
> > knowing exactly what you're doing.  The generally preferred approach
> > in Python is to keep things simple at some performance cost.
>
> > Your Locker approach above looks sort of reasonable if you can be
> > absolutely sure that nothing else can mess with listA or listB
> > concurrently with those locker operations.  Normally you would put
> > listA and listB into a single object along with a lock, then do
> > operations on that object.
>
> > You might check the Python Cookbook for some specific recipes and
> > sample code for this stuff.  If you've used Java, Python's general
> > threading mechanisms are similar, but they are in the library rather
> > than built into the language (i.e. there is no "synchronized"
> > keyword, you have to do that locking explicitly).
>
> > What is the actual application, if you don't mind saying?  Are you
> > sure that you really need concurrency?
>
> I'm writing an NxN observer pattern, mostly for my own personal
> exploration.  Two threads -might- be calling 'Disconnect' at the same
> time, and I can't even guarantee that the function runs properly.
>
> for emelem in [ e for e in emlist if e.func is func ]:
> try:
> emlist.remove( emelem )
> except ValueError:
> pass

Though:

class A:
  @synch( 'lockA' )
  def Connect( self, target ): ...
  @synch( 'lockA' )
  def Disconnect( self, target ): ...

where decorator 'synch' is defined as:

take the 'lockA' attribute of the first function parameter, call
acquire(), call the function, call release(); has the right idea.
Another is on __init__, go through and wrap every member function in
self.lockA.acquire() and .release().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Kamaelia] TCPClient: How to sense connection failure?

2008-01-12 Thread Hendrik van Rooyen
"Bjoern Schliessmann"  wrote:

>I'm currently trying to implement a simulation program with Kamaelia
>and need a reliable TCP connection to a data server.
>
>From Twisted, I know that a method is called if the connection fails
>by whatever reason. I tried to get the same results with Kamaelia's
>TCPClient component. If I start up the component and try to connect
>to a closed TCP port it fails and sends a message out of the signal
>box, that's okay.
>
>But if the connection attempt succeeds and, after some time, the
>server drops the connection with full TCP handshake (FIN, FIN+ACK,
>ACK), the component just hangs and does nothing. Is this by design,
>or could there be an error in my setup?
>

Not sure about Kamelia, but I have found that when a FIN comes along,
a socket.recv() gives back an empty string, just like EOF on a file.

I always have my sockets unblocked and fitted with time outs, but then
I am basically a broken down assembler programmer, so there are probably
better techniques around.

Below is what I use - a sort of netstring, synced on a tilde, with human
readable length implementation and escaping of tildes and the escape character.

It seems to work reliably for me, and detects when the server goes down.

The code for a typical client is below.  If anybody is interested I will post
the server
too, but it should be trivial to make, given the example below.

I hope the tabs survive the journey

- Hendrik

#start of code fragment

def sockget_len(s,L,data):
 """
 This fills a buffer of given length from the socket s, recursively.

 s   is the socket
 L   is the length to receive
 data  is the buffer
 """

 error = 0
 req_L = L - len(data)
 try:
  data = data+s.recv(req_L)
 except socket.error,msg:  # broken pipes again
  if 'timed out' in msg:
   rec = '2'*L
   return 2,rec   # time out
  print 'socket error while receiving',msg
  rec = '1'*L
  return 1,rec# error = 1 is a snafu
 if not data:
  print 'end of file while receiving'
  rec = '0'*L
  return 3,rec# This is end of file
 if len(data) != L:
  error,data = sockget_len(s,L,data)
 return error,data


def sockget(s):
 """
 Gets a transmission from host.
 """

 while True:
  tilde = ''
  error,tilde = sockget_len(s,1,tilde) # sync up on tilde
  if error == 1:
   return error,''
  elif error == 2:
   return error,''
  elif error == 3:
   return error,''
  if tilde == '~':
   break

 length = ''
 error,length = sockget_len(s,4,length) # get the length of the data
 if error == 1:
  return error,''   # real error
 elif error == 2:
  return error,''   # Time out
 elif error == 3:
  return error,''   # End of file
 L = int(length)
 buf = ''
 error,data = sockget_len(s,L,buf)  # get the data of length L
 return error, data# same errors as above 0 is all right


#  client communications program

def comms_thread(qi,qo):
 """This listens for the latest values, and sends requests up."""

 while True:

  HOST = 'Linuxbox'   # The remote host
  PORT = 50007# The same port as used by the server
  socket.setdefaulttimeout(10.00)
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

  while True:
   try:
qi.put('Connecting,')
s.connect((HOST, PORT))
break
   except socket.error,msg:
print 'error msg is:',msg
time.sleep(10)
continue
  print 'Connected - Time out is:',s.gettimeout()
  qi.put('Connected,')

  last_rx_time = time.time()
  last_tx_time = time.time()
  while True:

   while True:
error,data = sockget(s)  # see if a message from host
if error == 0 and data:
 msg2 = data.replace('/\x81','~')
 msg1 = msg2.replace('/\xd0','/')
 qi.put(msg1)
 print 'received',msg1
 last_rx_time = time.time()
 break
elif  error == 1:
 print 'Error after sockget'
 break
if time.time() - last_rx_time > 180:
 print 'no comms from host for 3 minutes'
 error = 1
 break   # time out ok, unless they are too long
if error == 2:
 error = 0  # time outs are all right here
 break
if error == 3:
 error = 1
 break   # end of files are a snafu

   if error == 1:
break

   try:
i_string = qo.get(block=False) # see if stuff to transmit
   except Queue.Empty:
if time.time()-last_tx_time > 8.5:
 i_string = 'Keepalive'  # if not for a while, tell server we are alive
 print 'sending keepalive'
else:
 time.sleep(0.1)# else wait a while and carry on
 continue

   msg1 = i_string.replace('/','/\xd0')
   msg2 = msg1.replace('~','/\x81')
   length = str(len(msg2))
   L = len(length)
   if L == 1:
length = '000'+length
   elif L == 2:
length = '00'+length
   elif L == 3:
length = '0'+length
   try:
s.send('~'+length+msg2)
last_tx_time = time.time()
   except socket.error,msg:
print 'Socket error on transmit',msg
break
   time.sleep(0.1)

  s.close()  # Formally close the broken thing
  qi.put('Quit,') # Tell main thread its hopeless

 sys.exit()  # Clobber this thread




-- 
http://mail.python.org/ma

Re: ctypes, GetWindowLongPtr

2008-01-12 Thread Henry Baxter
David,

Quick reply :) That pointed me in the right direction. The documentation I
was reading indicated the use of GetWindowLongPtr, but at compile time (if
one were writing C/C++ code) which particular version (Long/64, or 32 bit)
is chosen. That's where I was getting mixed up - thanks!


Henry

On Jan 11, 2008 9:33 PM, David Wahler <[EMAIL PROTECTED]> wrote:

> On Jan 11, 2008 9:14 PM, Henry Baxter <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > I have been happily using ctypes for a while to do win32 programming. I
> use the Microsoft documentation to understand the function, then call it
> with the help of ctypes.
> >
> > The problem is that the docs says user32.dll has GetWindowLongPtr, but
> ctypes can't find it using windll.user32.GetWindowLongPtrA or
> windll.user32.GetWindowLongPtrW or windll.user32.GetWindowLongPtr. Errors
> look like this:
> >
> > Traceback (most recent call last):
> >   File "Z:\experiments\windowsapp3.py", line 106, in 
> > GetWindowLongPtr = windll.user32.GetWindowLongPtrA
> >   File "C:\Python25\lib\ctypes\__init__.py", line 353, in __getattr__
> > func = self.__getitem__(name)
> >   File "C:\Python25\lib\ctypes\__init__.py", line 358, in __getitem__
> > func = self._FuncPtr((name_or_ordinal, self))
> > AttributeError: function 'GetWindowLongPtrA' not found
> >
> > I have the same problem with the SetWindowLongPtr function.
> >
> > I can use plenty of other functions (GetParent, CreateWindowExA,
> DefWindowProcA, and etc) but not these ones.
> >
> >
> > I don't understand what goes on with ctypes under the hood really, so my
> troubleshooting abilities at this point are quite lacking! I would
> appreciate any help you could offer.
> >
> >
> > Thanks!
>
> I don't have a copy of the official Win32 headers handy, but the MinGW
> version of winuser.h contains this section of code:
>
> WINUSERAPI LONG WINAPI GetWindowLongA(HWND,int);
> WINUSERAPI LONG WINAPI GetWindowLongW(HWND,int);
> #ifdef _WIN64
> WINUSERAPI LONG_PTR WINAPI GetWindowLongPtrA(HWND,int);
> WINUSERAPI LONG_PTR WINAPI GetWindowLongPtrW(HWND,int);
> #else
> #define GetWindowLongPtrA GetWindowLongA
> #define GetWindowLongPtrW GetWindowLongW
> #endif
>
> which I would take to mean you need to use GetWindowLong on 32-bit
> windows, and GetWindowLongPtr on 64-bit windows.
>
> -- David
>
-- 
http://mail.python.org/mailman/listinfo/python-list

eric4 request for contribution

2008-01-12 Thread Detlev Offenbach
Hi,

I am in the progress of writing a refactoring plugin for eric4 using the
rope refactoring library. Unfortunately, this library does not contain a
nice icon to be shown in an About Rope dialog. Is there anybody around,
who could contribute such an icon. Maybe it could look like the Python
snake but instead of the snake a rope is shown.

Regards,
Detlev
-- 
Detlev Offenbach
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:

> > I'm writing an NxN observer pattern, mostly for my own personal
> > exploration.  Two threads -might- be calling 'Disconnect' at the same
> > time, and I can't even guarantee that the function runs properly.

I think the Pythonic way to do this is have the targets communicate
with the observers through queues rather than with callbacks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting JSON to string

2008-01-12 Thread Jeroen Ruigrok van der Werven
-On [20080112 08:38], Gowri ([EMAIL PROTECTED]) wrote:
>Actually, I have one other problem after all this. I see that if I try
>to construct JSON output as above, it is of the form
>[{'isbn': u'1-56592-724-9', 'title': u'The Cathedral & the Bazaar'},
>{'isbn': u'1-56592-051-1', 'title': u'Making TeX Work'}]
>The extra 'u' seems to causing syntax error in JavaScript which is not
>able to parse this response string. Any idea how I can fix this?

JSON does not support Unicode in the sense of allowing raw Unicode codepoints.
Instead JSON uses a \u scheme to encode Unicode characters (a bit flawed
to limit it to four hexadecimal digits though, it leaves the whole CJK Unified
Ideographs Extension B out of scope.).

I use simplejson along with lxml/ElementTree for my JSON<>XML needs.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Any road leads to the end of the world...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: different encodings for unicode() and u''.encode(), bug?

2008-01-12 Thread mario
On Jan 4, 12:02 am, John Machin <[EMAIL PROTECTED]> wrote:
> On Jan 4, 8:03 am, mario <[EMAIL PROTECTED]> wrote:
> > On Jan 2, 2:25 pm, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
>
> > > Apparently for the empty string the encoding is irrelevant as it will not
> > > be used. I guess there is an early check for this special case in the 
> > > code.
>
> > In the module I an working on [*] I am remembering a failed encoding
> > to allow me, if necessary, to later re-process fewer encodings.
>
> If you were in fact doing that, you would not have had a problem. What
> you appear to have been doing is (a) remembering a NON-failing
> encoding, and assuming that it would continue not to fail

Yes, exactly. But there is no difference which ones I remember as the
two subsets will anyway add up to always the same thing. In this
special case (empty string!) the unccode() call does not fail...

> (b) not
> differentiating between failure reasons (codec doesn't exist, input
> not consistent with specified encoding).

There is no failure in the first pass in this case... if I do as you
suggest further down, that is to use s.decode(encoding) instead of
unicode(s, encoding) to force the lookup, then I could remember the
failure reason to be able to make a decision about how to proceed.
However I am aiming at an automatic decision, thus an in-context error
message would need to be replaced with a more rigourous info about how
the guessing should proceed. I am also trying to keep this simple ;)



> In any case, a pointless question (IMHO); the behaviour is extremely
> unlikely to change, as the chance of breaking existing code outvotes
> any desire to clean up a minor inconsistency that is easily worked
> around.

Yes, I would agree. The work around may not even be worth it though,
as what I really want is a unicode object, so changing from calling
unicode() to s.decode() is not quite right, and will anyway require a
further check. Less clear code, and a little unnecessary performance
hit for the 99.9 majority of cases... Anyhow, I have improved a little
further the "post guess" checking/refining logic of the algorithm [*].

What I'd like to understand better is the "compatibility heirarchy" of
known encodings, in the positive sense that if a string decodes
successfully with encoding A, then it is also possible that it will
encode with encodings B, C; and in the negative sense that is if a
string fails to decode with encoding A, then for sure it will also
fail to decode with encodings B, C. Any ideas if such an analysis of
the relationships between encodings exists?

Thanks! mario

[*] http://gizmojo.org/code/decodeh/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Kamaelia] TCPClient: How to sense connection failure?

2008-01-12 Thread Bjoern Schliessmann
Hendrik van Rooyen wrote:

> Not sure about Kamelia, but I have found that when a FIN comes
> along, a socket.recv() gives back an empty string, just like EOF
> on a file.

That Python socket interface can detect it I'm absolutely sure --
Twisted handles it.

I even pdb'ed Kamaelia and control flow ended at a different point
in case of connection closing -- but yielded control to the
scheduler immediately and never continued.
 
> Below is what I use - a sort of netstring, synced on a tilde, with
> human readable length implementation and escaping of tildes and
> the escape character.

Thank you (though I hope I won't have to mess with socket
functions ;) ).
 
> I hope the tabs survive the journey

Looks like they morphed to spaces.

Regards,


Björn

-- 
BOFH excuse #77:

Typo in the code

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


Is unicode.lower() locale-independent?

2008-01-12 Thread Robert Kern
The section on "String Methods"[1] in the Python documentation states that for 
the case conversion methods like str.lower(), "For 8-bit strings, this method 
is 
locale-dependent." Is there a guarantee that unicode.lower() is 
locale-*in*dependent?

The section on "Case Conversion" in PEP 100 suggests this, but the code itself 
looks like to may call the C function towlower() if it is available. On OS X 
Leopard, the manpage for towlower(3) states that it "uses the current locale" 
though it doesn't say exactly *how* it uses it.

This is the bug I'm trying to fix:

   http://scipy.org/scipy/numpy/ticket/643
   http://dev.laptop.org/ticket/5559

[1] http://docs.python.org/lib/string-methods.html
[2] http://www.python.org/dev/peps/pep-0100/

Thanks.

-- 
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


paging in python shell

2008-01-12 Thread Alex K
Hello,

Does anyone know if the python shell supports paging or if I should
look into iPython? Thank you so much.

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


Re: removeall() in list

2008-01-12 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I'm writing an NxN observer pattern, mostly for my own personal
> exploration.  Two threads -might- be calling 'Disconnect' at the same
> time, and I can't even guarantee that the function runs properly.
> 
>   for emelem in [ e for e in emlist if e.func is func ]:
>   try:
>   emlist.remove( emelem )
>   except ValueError:
>   pass

so use a lock.  it's a whopping two lines of code:

creation:

 lock = threading.Lock()

usage:

 with lock:
 for emelem in ...
 ...

more here:

 http://effbot.org/zone/thread-synchronization.htm

and btw, looping over a list to figure out what you want to remove from 
that list is a bit pointless.  better just create a new list:

 with lock:
 # get rid of all func instances
 emlist = [e for e in emlist if e.func is not func]

an alternative approach would be to replace emlist with a dictionary, 
keyed on func objects.  that'll let you remove all items associated with 
a given function with a single atomic operation:

 del emdict[func]



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


upload file and estimation time

2008-01-12 Thread whatazor
Hi all,
unseccsefully, I try to analyze this problem. If I can only work on
the client size, how can I create a module that calculate the upload
time of a file, so the time for finish it? i can start with ftp
protocol and after extend this logic for my requirements.

thx

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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread John Machin
On Jan 12, 8:25 pm, Robert Kern <[EMAIL PROTECTED]> wrote:
> The section on "String Methods"[1] in the Python documentation states that for
> the case conversion methods like str.lower(), "For 8-bit strings, this method 
> is
> locale-dependent." Is there a guarantee that unicode.lower() is
> locale-*in*dependent?
>
> The section on "Case Conversion" in PEP 100 suggests this, but the code itself
> looks like to may call the C function towlower() if it is available. On OS X
> Leopard, the manpage for towlower(3) states that it "uses the current locale"
> though it doesn't say exactly *how* it uses it.
>
> This is the bug I'm trying to fix:
>
>http://scipy.org/scipy/numpy/ticket/643
>http://dev.laptop.org/ticket/5559
>
> [1]http://docs.python.org/lib/string-methods.html
> [2]http://www.python.org/dev/peps/pep-0100/
>

The Unicode standard says that case mappings are language-dependent.
It gives the example of the Turkish dotted capital letter I and
dotless small letter i that "caused" the numpy problem. See
http://www.unicode.org/versions/Unicode4.0.0/ch05.pdf#G21180

Here is what the Python 2.5.1 unicode implementation does in an
English-language locale:

>>> import unicodedata as ucd
>>> eyes = u"Ii\u0130\u0131"
>>> for eye in eyes:
... print repr(eye), ucd.name(eye)
...
u'I' LATIN CAPITAL LETTER I
u'i' LATIN SMALL LETTER I
u'\u0130' LATIN CAPITAL LETTER I WITH DOT ABOVE
u'\u0131' LATIN SMALL LETTER DOTLESS I
>>> for eye in eyes:
...print "%r %r %r %r" % (eye, eye.upper(), eye.lower(),
eye.capitalize())
...
u'I' u'I' u'i' u'I'
u'i' u'I' u'i' u'I'
u'\u0130' u'\u0130' u'i' u'\u0130'
u'\u0131' u'I' u'\u0131' u'I'

The conversions for I and i are not correct for a Turkish locale.

I don't know how to repeat the above in a Turkish locale.

However it appears from your bug ticket that you have a much narrower
problem (case-shifting a small known list of English words like VOID)
and can work around it by writing your own locale-independent casing
functions. Do you still need to find out whether Python unicode
casings are locale-dependent?

Cheers,
John


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


where do my python files go in linux?

2008-01-12 Thread Jorgen Bodde
Hi All,

I am trying to make a debian package. I am following the tutorial by
Horst Jens 
(http://showmedo.com/videos/video?name=linuxJensMakingDeb&fromSeriesID=37)
and it is very informative. However one thing my app has and his
doesn't, is multiple python files which need to be executed. For
example

{dir}/app
app.py

app.py calls a lot of modules in {dir}/app. Horst says the python file
goes in /usr/bin/app.py which is ok with me, but I have multiple
python files, and I decided to use an app.sh script to call my python
files. In the /usr/bin I do not see subdirs so I assume that is not
really desirable.

Question 1. Where do I put the bulk of python scripts in a normal
linux environment?
Question 2. Should I use *.pyc rather then *.py files to speed up
executing as the user cannot write to /usr/bin or any other dir in the
system and everytime my app runs it will recompile it

Thanks for any advice or maybe a good tutorial how to set up files in
a linux environment

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


Re: where do my python files go in linux?

2008-01-12 Thread Jeroen Ruigrok van der Werven
-On [20080112 12:03], Jorgen Bodde ([EMAIL PROTECTED]) wrote:
>app.py calls a lot of modules in {dir}/app. Horst says the python file
>goes in /usr/bin/app.py which is ok with me, but I have multiple
>python files, and I decided to use an app.sh script to call my python
>files. In the /usr/bin I do not see subdirs so I assume that is not
>really desirable.

Personally I'd be loathe to put app.py in /usr/bin. This directory is normally
reserved for OS-specific binaries. For personal/system-extended stuff I'd use
/usr/local/bin or whatever your system mandates. (But hey, that's the typical
mentality difference between the BSD and Linux world it seems, so do with it
what you want.)

>Question 2. Should I use *.pyc rather then *.py files to speed up
>executing as the user cannot write to /usr/bin or any other dir in the
>system and everytime my app runs it will recompile it

.pyc will help execution time so it might be nice to have those in place.

Normally you'd split up the bulk of the code into a module which gets
installed into site-packages and a piece of stand-alone front-end code which
imports the module and executes whatever you need to do and gets installed
into a typical PATH directory.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
...fools rush in where Angels fear to tread.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Robert Kern
John Machin wrote:
> On Jan 12, 8:25 pm, Robert Kern <[EMAIL PROTECTED]> wrote:
>> The section on "String Methods"[1] in the Python documentation states that 
>> for
>> the case conversion methods like str.lower(), "For 8-bit strings, this 
>> method is
>> locale-dependent." Is there a guarantee that unicode.lower() is
>> locale-*in*dependent?
>>
>> The section on "Case Conversion" in PEP 100 suggests this, but the code 
>> itself
>> looks like to may call the C function towlower() if it is available. On OS X
>> Leopard, the manpage for towlower(3) states that it "uses the current locale"
>> though it doesn't say exactly *how* it uses it.
>>
>> This is the bug I'm trying to fix:
>>
>>http://scipy.org/scipy/numpy/ticket/643
>>http://dev.laptop.org/ticket/5559
>>
>> [1]http://docs.python.org/lib/string-methods.html
>> [2]http://www.python.org/dev/peps/pep-0100/
> 
> The Unicode standard says that case mappings are language-dependent.
> It gives the example of the Turkish dotted capital letter I and
> dotless small letter i that "caused" the numpy problem. See
> http://www.unicode.org/versions/Unicode4.0.0/ch05.pdf#G21180

That doesn't determine the behavior of unicode.lower(), I don't think. That 
specifies semantics for when one is dealing with a given language in the 
abstract. That doesn't specify concrete behavior with respect to a given locale 
setting on a real computer. For example, my strings 'VOID', 'INT', etc. are all 
English, and I want English case behavior. The language of the data and the 
transformations I want to apply to the data is English even though the user may 
have set the locale to something else.

> Here is what the Python 2.5.1 unicode implementation does in an
> English-language locale:
> 
 import unicodedata as ucd
 eyes = u"Ii\u0130\u0131"
 for eye in eyes:
> ... print repr(eye), ucd.name(eye)
> ...
> u'I' LATIN CAPITAL LETTER I
> u'i' LATIN SMALL LETTER I
> u'\u0130' LATIN CAPITAL LETTER I WITH DOT ABOVE
> u'\u0131' LATIN SMALL LETTER DOTLESS I
 for eye in eyes:
> ...print "%r %r %r %r" % (eye, eye.upper(), eye.lower(),
> eye.capitalize())
> ...
> u'I' u'I' u'i' u'I'
> u'i' u'I' u'i' u'I'
> u'\u0130' u'\u0130' u'i' u'\u0130'
> u'\u0131' u'I' u'\u0131' u'I'
> 
> The conversions for I and i are not correct for a Turkish locale.
> 
> I don't know how to repeat the above in a Turkish locale.

If you have the correct locale data in your operating system, this should be 
sufficient, I believe:

$ LANG=tr_TR python
Python 2.4.3 (#1, Mar 14 2007, 19:01:42)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import locale
 >>> locale.setlocale(locale.LC_ALL, '')
'tr_TR'
 >>> 'VOID'.lower()
'vo\xfdd'
 >>> 'VOID'.lower().decode('iso-8859-9')
u'vo\u0131d'
 >>> u'VOID'.lower()
u'void'
 >>>

> However it appears from your bug ticket that you have a much narrower
> problem (case-shifting a small known list of English words like VOID)
> and can work around it by writing your own locale-independent casing
> functions. Do you still need to find out whether Python unicode
> casings are locale-dependent?

I would still like to know. There are other places where .lower() is used in 
numpy, not to mention the rest of my code.

-- 
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: Is unicode.lower() locale-independent?

2008-01-12 Thread Fredrik Lundh
Robert Kern wrote:

>> However it appears from your bug ticket that you have a much narrower
>> problem (case-shifting a small known list of English words like VOID)
>> and can work around it by writing your own locale-independent casing
>> functions. Do you still need to find out whether Python unicode
>> casings are locale-dependent?
> 
> I would still like to know. There are other places where .lower() is used in 
> numpy, not to mention the rest of my code.

"lower" uses the informative case mappings provided by the Unicode 
character database; see

 http://www.unicode.org/Public/4.1.0/ucd/UCD.html

afaik, changing the locale has no influence whatsoever on Python's 
Unicode subsystem.



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


Looking for GSM Mobile Phone www.enmac.com.hk

2008-01-12 Thread Farooq
ENMAC Digital Quran Mobile includes Full Quran with Text and
Translation in different languages, Tafaseer books, Ahadees Books,
Universal Qibla Direction, Prayer Timing and much more at good price,
please contact us for best prices and visit our website http://www.enmac.com.hk
for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a proxy with urllib2

2008-01-12 Thread Rob Wolfe
"Jack" <[EMAIL PROTECTED]> writes:

>>> I'm trying to use a proxy server with urllib2.
>>> So I have managed to get it to work by setting the environment
>>> variable:
>>> export HTTP_PROXY=127.0.0.1:8081
>>>
>>> But I wanted to set it from the code. However, this does not set the 
>>> proxy:
>>> httpproxy = '127.0.0.1:3129'
>>> proxy_support = urllib2.ProxyHandler({"http":"http://"; + httpproxy})
>>> opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
>>> urllib2.install_opener(opener)
>
> I find out why it doesn't work in my code but I don't have a solution - 
> somewhere
> else in the code calls these two lines:
>
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> urllib2.install_opener(opener)
>
> and they override the proxy opener. Could anyone tell me how to use both 
> openers?
>

You don't have to create another opener if you only want to add
some handler. You can use `add_handler` method, e.g.:
opener.add_handler(urllib2.HTTPCookieProcessor(cj))

HTH,
Rob

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


Re: Great Python books for the beginner

2008-01-12 Thread Jim
Look at
  http://www.python.org/doc/
.  The tutorial is quite good.

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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Torsten Bronger
Hallöchen!

Fredrik Lundh writes:

> Robert Kern wrote:
>
>>> However it appears from your bug ticket that you have a much
>>> narrower problem (case-shifting a small known list of English
>>> words like VOID) and can work around it by writing your own
>>> locale-independent casing functions. Do you still need to find
>>> out whether Python unicode casings are locale-dependent?
>>
>> I would still like to know. There are other places where .lower()
>> is used in numpy, not to mention the rest of my code.
>
> "lower" uses the informative case mappings provided by the Unicode
> character database; see
>
> http://www.unicode.org/Public/4.1.0/ucd/UCD.html
>
> afaik, changing the locale has no influence whatsoever on Python's
> Unicode subsystem.

Slightly off-topic because it's not part of the Unicode subsystem,
but I was once irritated that the none-breaking space (codepoint xa0
I think) was included into string.whitespace.  I cannot reproduce it
on my current system anymore, but I was pretty sure it occured with
a fr_FR.UTF-8 locale.  Is this possible?  And who is to blame, or
must my program cope with such things?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: upload file and estimation time

2008-01-12 Thread Diez B. Roggisch
whatazor schrieb:
> Hi all,
> unseccsefully, I try to analyze this problem. If I can only work on
> the client size, how can I create a module that calculate the upload
> time of a file, so the time for finish it? i can start with ftp
> protocol and after extend this logic for my requirements.

All you need to to is to

  - count the number of bytes to transfer, U

  - count the bytes already transfered, u

  - measure the time since the upload, t



Then the ETA is

eta = (u / t) * (U - u)

Using the ftp-lib, you best pass a file-wrapper that overload the 
read-method to accumulate the read bytes to yield u.

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


Re: extracting Javadocs using Python

2008-01-12 Thread Wildemar Wildenburger
Rajarshi wrote:
> Does anybody know if something like this is available? Or would I need
> to implement a parser from scratch?
> 
Probably. But using pyparsing, you shouldn't have a lot of trouble with it.

You may want to take a look at epydoc, a python API-doc generator. I 
seem to remember that in addition to using rST markup, it also provides 
markup similar to Javadocs. Maybe you can get some "inspiration" from 
the epydoc sources.

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


eric4 request for contribution

2008-01-12 Thread Detlev Offenbach
Hi,

I am in the progress of writing a refactoring plugin for eric4 using the
rope 
refactoring library. Unfortunately, this library does not contain a nice
icon 
to be shown in an About Rope dialog. Is there anybody around, who could 
contribute such an icon. Maybe it could look like the Python snake but 
instead of the snake a rope is shown.

Regards,
Detlev
-- 
Detlev Offenbach
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread Ben Finney
Landon <[EMAIL PROTECTED]> writes:

> I was wondering if anyone had any opinions on what other titles I
> could look into since this one seems from a glance at reviews to be
> teaching mainly through game programming (a topic I'm not too
> interested in) or if this one is a quality book by itself.

The book "Learning Python" is currently proving very useful to an
associate of mine. I'm watching his knowledge of Python grow
substantially every week, from what was an essentially zero start.

Learning Python, 3rd Edition
Mark Lutz
O'Reilly
http://www.oreilly.com/catalog/9780596513986/>

Looking through the text, it is very well structured, thoroughly
teaching all the fundamentals of the language and types and idioms
while referring back to already-learned material. The author makes a
living training people in Python, and the third edition has benefited
from his many years of experience finding effective ways to teach the
language.

-- 
 \ "If you ever teach a yodeling class, probably the hardest thing |
  `\  is to keep the students from just trying to yodel right off. |
_o__)  You see, we build to that."  -- Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 rate limiting

2008-01-12 Thread Dimitrios Apostolou
On Fri, 11 Jan 2008, Nick Craig-Wood wrote:
> Here is an implementation based on that idea.  I've used urllib rather
> than urllib2 as that is what I'm familiar with.

Thanks! Really nice implementation. However I'm stuck with urllib2 because 
of its extra functionality so I'll try to implement something similar 
using handle.read(1024) to read in small chunks.

It really seems weird that urllib2 is missing reporthook functionality!


Thank you,
Dimitris

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


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 3:51 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I'm writing an NxN observer pattern, mostly for my own personal
> > exploration.  Two threads -might- be calling 'Disconnect' at the same
> > time, and I can't even guarantee that the function runs properly.
>
> >for emelem in [ e for e in emlist if e.func is func ]:
> >try:
> >emlist.remove( emelem )
> >except ValueError:
> >pass
>
> so use a lock.  it's a whopping two lines of code:
>
> creation:
>
>  lock = threading.Lock()
>
> usage:
>
>  with lock:
>  for emelem in ...
>  ...
>
> more here:
>
>  http://effbot.org/zone/thread-synchronization.htm
>
> and btw, looping over a list to figure out what you want to remove from
> that list is a bit pointless.  better just create a new list:
>
>  with lock:
>  # get rid of all func instances
>  emlist = [e for e in emlist if e.func is not func]
>
> an alternative approach would be to replace emlist with a dictionary,
> keyed on func objects.  that'll let you remove all items associated with
> a given function with a single atomic operation:
>
>  del emdict[func]
>
> 

-> so use a lock.  it's a whopping two lines of code:
Yes.
1) I'm wondering what the specifics are on [Rubin]:

>>2. Associate a lock with the list.  Anything wanting to access the
list should acquire the lock, do its stuff, then release the lock.
This gets confusing after a while.<<

I considered these suggestions early on.  They apply often but I ruled
them out for reasons:

2) List is referenced by others; concurrent modifications may be going
on; can not replace it.  Can I make asynchronous modifications and
merge the changes, SCM-style?
3) Dictionary returns non-static order; order is important.  Create a
int-func tuple and sort dictionary results?  Perhaps.  That's sounding
pretty good.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Magic function

2008-01-12 Thread bearophileHUGS
Steven D'Aprano:
> As simple as the above is, it could be made simpler. Judging from the
> example given, the Bigobj constructor doesn't need a keyword argument,
> it could just as easily take an arbitrary number of arguments:
> bigobj = Bigobj(obj1, obj2, obj3, obj4...)

I agree; "Things should be made as simple as possible, but not any
simpler". Hiding those important details from the user is "too much
simple", and in the long run it will give problems.
They don't need to become expert (Python) programmers, but it's
positive for them to learn how to use their tools a bit, and that
example is simple.

For them Python is a good choice as a shell/interface/glue language
(despite the lack of built-in multiprecision floating point numbers
and TONS of other things you can find built-in in Mathematica, that is
quite less easy to program than Python), you can add MatPlotLib to
visualize data on the fly. In the future the Fortress language (by
Sun) may be good for them to use the CPU multi core CPUs too, etc. At
the moment Java/D/Cython/C may be used to write the numerically
intensive routines (and to interface to the already written ones in
Fortran/C/C++, etc) (note: Cython is a better version of Pyrex).

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


Re: executing newgrp from python in current shell possible?

2008-01-12 Thread Svenn Are Bjerkem
On Jan 9, 9:18 pm, Zentrader <[EMAIL PROTECTED]> wrote:
> On Jan 9, 5:56 am, Svenn Are Bjerkem <[EMAIL PROTECTED]>
> wrote:
>
> >I have been looking for a way to execute this command
> > as a part of a script, but it seems that the changes are only valid in
> > the context of the script and when the script exits, the current shell
> > still have the original "users" group setting.
>
> I don't think you would want it any other way.  Would you want a user
> to be able to change the group and have it remain permanently?  Who's
> going to remember whether they were last in "A" or "B", and it opens
> up oportunities for the practical joker when you go to the restroom
> and leave the terminal on.  Put the "change the group" code into a
> separate function in a separate file (with only you as the owner) and
> call it whenever you want to change groups.

I am trying to create a script that make it easy for users in a design
team to create files that belong to the same group, but retain the
users uid. In order to make it visible that the user is creating files
with a different gid, the script will change the prompt to indicate
so. In a tcl solution I have now, the users home is changed to the
design area as some tools are reading and writing setup files into
$HOME. I have not found a way to change the gid in tcl so I turned to
python in hope that this scripting language could do so.

The tcl solution spawns a new tcsh after setting several environment
variables and works quite well except for not being able to change
gid. And it is also a wish from my side to port this script to python.

Is your suggestion to put "newgrp design" into a new file and then
exec this file in my python script? What happens to the group id of
the shell that called the python script in this case? I would try to
avoid spawning a new tcsh as this make execution of tools on a remote
computer difficult as the handover of command line arguments does not
seem to be handed over to the newly spawned shell. I may be
understanding something wrongly here.

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


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread default
On Sat, 12 Jan 2008 02:01:09 -0500, "radiosrfun"
<[EMAIL PROTECTED]> wrote:

>I WISH - that the President and Congress of this country would shut off ALL 
>foreign aid.

Ditto that.  

Israel is the chief beneficiary of our foreign aid largesse.  Some 8
billion dollars annually.  What doesn't find its way into politicians
pockets goes to pay for a military that is winning us a lot of new
friends in the Arab world.

We pay Egypt ~ 2 billion a year in extortion to keep them from
attacking Israel.

The actually amount Israel receives is not really known to the public.
The official numbers read something like 3 billion in aid, and another
5 billion in guaranteed loans - which are turned into grants year
after year.  This is money we borrow so there's an additional interest
burden.

Actually when you talk about shutting off "foreign aid" you may be
making thermate's point for him.
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 11, 5:26 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
>
> 1. Put a single thread in charge of the list, and communicate with it
> by message passing through Queues.  To get X out of the list, you'd
> send the mutator thread a message asking for removal.  The mutator
> thread would loop reading and processing messages from the queue,
> blocking when no requests are pending.  This is sort of the preferred
> Python style and is pretty simple to get correct, but if there are
> many such objects you can end up with more threads than you really
> want.

I've heard this called 'fire and forget'.  You can insure that
mutations are honored one-at-a-time  and in the order received.  How
do you make a -read- operation; wait for queued mutations, that is
lock for a turn on the queue?  Can you optionally read whatever the
state is, regardless of what's happened in the meantime?  Thing is,
one thread needs its -own- preceding operations completed before a
reading operation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread sween119
On Jan 12, 2:03 am, Landon <[EMAIL PROTECTED]> wrote:
> Hi, I'm a freshman in college and I'm going to be taking an intro to
> programming course next semester which mainly uses Python, so I
> thought it might be a good time to pick up Python beyond the scope of
> the class as well. The text book for this class is Python for the
> Absolute Beginner or something similar to that name.
>
> I was wondering if anyone had any opinions on what other titles I
> could look into since this one seems from a glance at reviews to be
> teaching mainly through game programming (a topic I'm not too
> interested in) or if this one is a quality book by itself.

Hi Landon,

I've found the O'reilly books to be useful I have the Python Pocket
reference, which is helpful for me to remember the parameters
surrounding commands and all that.

I've been known to peruse the "Learning Python" book by the same
publisher and I really like "Programming Python" (though it is
thoroughly hefty and runs about $60USD)

But  has excellent documentation and if I may
put a word in for  to check out if you would be
at all interested in starting game programming.

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


Re: Great Python books for the beginner

2008-01-12 Thread Mike
On Jan 12, 7:47 am, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Landon <[EMAIL PROTECTED]> writes:
> > I was wondering if anyone had any opinions on what other titles I
> > could look into since this one seems from a glance at reviews to be
> > teaching mainly through game programming (a topic I'm not too
> > interested in) or if this one is a quality book by itself.
>
> The book "Learning Python" is currently proving very useful to an
> associate of mine. I'm watching his knowledge of Python grow
> substantially every week, from what was an essentially zero start.
>
> Learning Python, 3rd Edition
> Mark Lutz
> O'Reilly
> http://www.oreilly.com/catalog/9780596513986/>
>
> Looking through the text, it is very well structured, thoroughly
> teaching all the fundamentals of the language and types and idioms
> while referring back to already-learned material. The author makes a
> living training people in Python, and the third edition has benefited
> from his many years of experience finding effective ways to teach the
> language.
>
> --
>  \ "If you ever teach a yodeling class, probably the hardest thing |
>   `\  is to keep the students from just trying to yodel right off. |
> _o__)  You see, we build to that."  -- Jack Handey |
> Ben Finney

I would recommend Lutz's other book, the wonderful Python tome
"Programming Python 3rd Ed." as well. It's good for getting into the
deepest part of Python's jungle.

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


Compiling fails on Mac OS X 10.5

2008-01-12 Thread mc
Hi!
I'm trying to compile on my Macbook with OS X 10.5. I have all updates
and Xcode 3.0 installed.

I checked python out with: svn checkout 
http://svn.python.org/projects/python/branches/py3k
After that I did "./configure" in the  created "py3k" dir. Everything
went fine. But make fails with the following error message:
ranlib libpython3.0.a
gcc  -u _PyMac_Error -o python.exe \
Modules/python.o \
libpython3.0.a -ldl
make: *** [sharedmods] Error 1

I tried checking out many times. I also tried de 3.0a2 release,gives
me the same error. I've heard others have compiled it successfully on
Leopard so I wonder what causes the problems on my system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where do my python files go in linux?

2008-01-12 Thread Jorgen Bodde
Hi Jeroen,

Thanks for the advice.

> Personally I'd be loathe to put app.py in /usr/bin. This directory is normally
> reserved for OS-specific binaries. For personal/system-extended stuff I'd use
> /usr/local/bin or whatever your system mandates. (But hey, that's the typical
> mentality difference between the BSD and Linux world it seems, so do with it
> what you want.)

I thought about that too. I just wonder why /usr/local/bin is always
empty and every .deb I install from a source (if it's from Ubuntu or
not) installs files in /usr/bin .. So I looked further and noticed
that most python files do reside in /usr/share/{appname}

> Normally you'd split up the bulk of the code into a module which gets
> installed into site-packages and a piece of stand-alone front-end code which
> imports the module and executes whatever you need to do and gets installed
> into a typical PATH directory.

I would agree but it is not a site package I am trying to distribute,
but a wxPython application. I would not think my app belongs in the
python site packages dir.

Thanks a lot for the input!

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


Re: where do my python files go in linux?

2008-01-12 Thread Faber J. Fedor
On 12/01/08 12:02 +0100, Jorgen Bodde wrote:
> Hi All,
> 
> I am trying to make a debian package. I am following the tutorial by
> Horst Jens 
> (http://showmedo.com/videos/video?name=linuxJensMakingDeb&fromSeriesID=37)
> and it is very informative. However one thing my app has and his
> doesn't, is multiple python files which need to be executed. For
> example
> 
> {dir}/app
> app.py
> 
> app.py calls a lot of modules in {dir}/app. Horst says the python file
> goes in /usr/bin/app.py which is ok with me, but I have multiple
> python files, and I decided to use an app.sh script to call my python
> files. In the /usr/bin I do not see subdirs so I assume that is not
> really desirable.
> 
> Question 1. Where do I put the bulk of python scripts in a normal
> linux environment?

I would think you'd create a directory /usr/bin/app and then symlink
/usr/bin/app.py to /usr/bin/app/app.py.


> Question 2. Should I use *.pyc rather then *.py files to speed up
> executing as the user cannot write to /usr/bin or any other dir in the
> system and everytime my app runs it will recompile it

That would make sense.

> Thanks for any advice or maybe a good tutorial how to set up files in
> a linux environment

http://www.pathname.com/fhs/ (couldn't find a more
recent version, sorry.)


-- 
 
Regards,
 
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701

http://www.linuxnj.com




-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread radiosrfun
"default" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sat, 12 Jan 2008 02:01:09 -0500, "radiosrfun"
> <[EMAIL PROTECTED]> wrote:
>
>>I WISH - that the President and Congress of this country would shut off 
>>ALL
>>foreign aid.
>
> Ditto that.
>
> Israel is the chief beneficiary of our foreign aid largesse.  Some 8
> billion dollars annually.  What doesn't find its way into politicians
> pockets goes to pay for a military that is winning us a lot of new
> friends in the Arab world.
>
> We pay Egypt ~ 2 billion a year in extortion to keep them from
> attacking Israel.
>
> The actually amount Israel receives is not really known to the public.
> The official numbers read something like 3 billion in aid, and another
> 5 billion in guaranteed loans - which are turned into grants year
> after year.  This is money we borrow so there's an additional interest
> burden.
>
> Actually when you talk about shutting off "foreign aid" you may be
> making thermate's point for him.
> --

Well - the first cup of coffee hasn't exactly kicked in yet - but I believe 
I know what you're saying and if correct - you may have a point there. 


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


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 8:04 am, [EMAIL PROTECTED] wrote:
> On Jan 11, 5:26 pm, Paul Rubin  wrote:
>
> > [EMAIL PROTECTED] writes:
>
> > 1. Put a single thread in charge of the list, and communicate with it
> > by message passing through Queues.  To get X out of the list, you'd
> > send the mutator thread a message asking for removal.  The mutator
> > thread would loop reading and processing messages from the queue,
> > blocking when no requests are pending.  This is sort of the preferred
> > Python style and is pretty simple to get correct, but if there are
> > many such objects you can end up with more threads than you really
> > want.
>
> I've heard this called 'fire and forget'.  You can insure that
> mutations are honored one-at-a-time  and in the order received.  How
> do you make a -read- operation; wait for queued mutations, that is
> lock for a turn on the queue?  Can you optionally read whatever the
> state is, regardless of what's happened in the meantime?  Thing is,
> one thread needs its -own- preceding operations completed before a
> reading operation.

Brainstorm.

First, isolation of problem:  Terminates at 2000 or so, on my
computer.

import thread
import time
import random
counter= 0
def simplecounter():
global counter
ret= counter
counter+= 1
time.sleep( random.uniform( 0, .001 ) )
return counter
glist= []
def th3():
while 1:
ret= simplecounter()
glist.append( ret )
print ret,
assert glist== range( 1, len( glist )+1 )
thread.start_new_thread( th3, () )
time.sleep(1)
thread.start_new_thread( th3, () )
time.sleep( 1000 )

Second, the thoughts:  'with a.callbacklock():' looks best currently.

'''multithreading ideas:
1.  Put a single thread in charge
a.k.a. fire and forget.
- Lots of extra threads
+ But most are blocking most of the time
+ honored one-at-a-time, and in order received
+ ...optionally including read-access, blocking on
to get return values
a. synchronous callbacks, for read-access
+ multi-step, user-definitionized operations
- one consumer can hang an entire object
i.  with a.callbacklock():?
+ only call acquire() from curr. thread, enqueue
lock obj., released from producer thread "soon"
using message-queue semantics
b. mini-transaction, guarantees all and only
consumer's ops occur in succession
- can't do anything amidst an indivdual locking
- no multi-step ops
2.  Lock mutation and/or all operations
a. Locker.op
b. with Locker.withop
- In Python, other programmers always have access
to your data; nothing guarantees they'll use "with locker"
+ User-definitioning quite easy
3.  @mutation decorator
def mutation( func ):
def newfunc( self, *a, **k ):
self.lock.acquire()
func( *a, **k )
self.lock.release()
4.  List-only solution:
Use a dictionary, map item to its index.
To retrieve, sort on value, not key
'''
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where do my python files go in linux?

2008-01-12 Thread Grant Edwards
On 2008-01-12, Jorgen Bodde <[EMAIL PROTECTED]> wrote:

>> Normally you'd split up the bulk of the code into a module which gets
>> installed into site-packages and a piece of stand-alone front-end code which
>> imports the module and executes whatever you need to do and gets installed
>> into a typical PATH directory.
>
> I would agree but it is not a site package I am trying to distribute,
> but a wxPython application. I would not think my app belongs in the
> python site packages dir.

That's my opinion also, but I've seen several apps that are
distributed that way.  The bulk of the application code goes
into the site-packages directory and then there's a 5-line
script in /usr/bin that calls the application's main module
that's in site-packages.

That seems wrong to me...

-- 
Grant Edwards   grante Yow!  Civilization is
  at   fun! Anyway, it keeps
   visi.comme busy!!
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get user home directory on Windows

2008-01-12 Thread Giampaolo Rodola'
Hi all,
I'm trying to use the pywin32 extension to find out the user's home
directory but currently I didn't find a solution yet.
What I'd need to do is not getting the home directory of the currently
logged in user but something like:

>>> get_homedir("frank")
"C:\home\users\frank"
>>> get_homedir("josh")
"C:\home\users\josh"

Is there a way to do that?
I tried to search through the Pywin32 documentation with no luck.
In addition I'm not practiced with the Windows API at all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread Mark Dickinson
On Jan 12, 9:41 am, mc <[EMAIL PROTECTED]> wrote:
> Hi!
> I'm trying to compile on my Macbook with OS X 10.5. I have all updates
> and Xcode 3.0 installed.
>
> I checked python out with: svn 
> checkouthttp://svn.python.org/projects/python/branches/py3k
> After that I did "./configure" in the  created "py3k" dir. Everything
> went fine. But make fails with the following error message:
> ranlib libpython3.0.a
> gcc  -u _PyMac_Error -o python.exe \
>                         Modules/python.o \
>                         libpython3.0.a -ldl
> make: *** [sharedmods] Error 1
>
> I tried checking out many times. I also tried de 3.0a2 release,gives
> me the same error. I've heard others have compiled it successfully on
> Leopard so I wonder what causes the problems on my system.

Could you post the rest of the ./configure and compilation output?
make might be rereporting an error that occurred further up.

I don't see anything related on the Python bug tracker.  It might be
worth posting a bug report at bugs.python.org

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


what did the bible say about Mohammad

2008-01-12 Thread small giant
According to the Bible, God said to Moses, on whom be peace: I will
raise up for them a prophet like you from among their brothers; I will
put my words in his mouth, and he will tell them everything I command
him. (The Holy Bible, New International Version, Deuteronomy chapter
18, verse 18). The prophet described in the above verse must have the
following three characteristics: 1. He will be like Moses. 2. He will
come from the brothers of the Israelites, i.e. the Ishmaelites. 3. God
will put His words in the mouth of the prophet and he will declare
what God commanded him. Let us see which prophet God was speaking of.
1. The prophet like Moses Some people feel that this prophecy refers
to the prophet Jesus, on whom be peace. But, although Jesus (peace be
upon him and all of God's prophets and messengers) was truly a prophet
of God, he is not the prophet spoken of here. He was born
miraculously, and finally God raised him up miraculously. On the other
hand, Muhammad is more like Moses; both were born in a natural way and
both died natural deaths.

2. From among the Ishmaelites Abraham had two sons, Ishmael and Isaac
(Genesis, chapter 21). Ishmael became the grandfather of the Arab
nation. And Isaac became the grandfather of Jewish nation. The prophet
spoken of was to come not from among the Jews themselves, but from
among their brothers, the Ishmaelites. Muhammad a descendant of
Ishmael, is indeed that prophet. 3. God will put his words in his
mouth 'Neither the content of the revelation, nor its form, were of
Muhammad's devising. Both were given by the angel, and Muhammad's task
was only to repeat what he heard.' (Word Religions from Ancient
history to the Present, by Geoffrey Parrinder, p. 472). God sent the
angel Gabriel to teach Muhammad the exact words that he should repeat
to the people. The words are therefore not his own; they did not come
from his own thoughts, but were put into his mouth by the angel. These
are written down in the Qur'an word for word, exactly as they came
from God. Now that we know that prophet we must listen to him, for,
according to the Bible, God says: 'I will punish anyone who refuses to
obey him' (Good News Bible, Deut. 18:19). Jesus (on whom be peace) In
the Glorious Qur'an The Qur'an tells us many wonderful things about
Jesus. As a result, believers in the Qur'an love Jesus, honor him and
believe in him. In fact, no Muslim can be a Muslim unless he or she
believes in Jesus, on whom be peace. The Qur'an says that Jesus was
born of a virgin, that he spoke while he was still only a baby, that
he healed the blind and the leper by God's leave and that he raised
the dead by God's leave. What then is the significance of these
miracles? First, the virgin birth. God demonstrates His power to
create in every way. God created everyone we know from a man and a
woman. But how about Adam, on whom be peace? God created him from
neither a man nor a woman. And Eve from only a man, without a woman.
And finally, to complete the picture, God created Jesus from a woman,
without a man. What about the other miracles? These were to show that
Jesus was not acting on his own behalf, but that he was backed by God.
The Qur'an specifies that these miracles were performed by God's
leave. This may be compared to the Book of Acts in the Bible, chapter
2, verse 22, where it says that the miracles were done by God to show
that he approved of Jesus. Also, note that Jesus himself is recorded
in the Gospel of John to have said: 'I can do nothing of my own
authority' (5:30). The miracles, therefore, were done not by his own
authority, but by God's authority. What did Jesus teach? The Qur'an
tells us that Jesus came to teach the same basic message which was
taught by previous prophets from God - that we must shun every false
god and worship only the One True God. Jesus taught that he is the
servant and messenger of the One True God, the God of Abraham. These
Qur'anic teachings can be compared with the Bible (Mark 10:18; Matthew
26:39; John 14:28, 17:3, and 20:17) where Jesus teaches that the one
he worshipped is the only true God. See also Matthew 12:18; Acts 3:13,
and 4:27 where we find that his disciples knew him as 'Servant of
God'. The Qur'an tells us that some of the Israelites rejected Jesus,
and conspired to kill him, but God rescued Jesus and raised him to
Himself. God will cause Jesus to descend again, at which time Jesus
will confirm his true teachings and everyone will believe in him as he
is and as the Qur'an teaches about him. Jesus is the Messiah. He is a
word from God, and a spirit from Him. He is honored in this world and
in the hereafter, and he is one of those brought nearest to God. Jesus
was a man who spoke the truth which he heard from God. This can be
compared with the Gospel According John where Jesus says to the
Israelites: 'You are determined to kill me, a man who has told you the
truth that I heard from God' (John 8:40).

see this site www.sultan.org
-- 
http://mail.python.org/mailman/

Re: How to get user home directory on Windows

2008-01-12 Thread Christian Heimes
Giampaolo Rodola' wrote:
> Is there a way to do that?

home = os.path.expanduser("~")

Christian

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


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 11 jan, 16:10, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Jan 11, 8:59 am, Bruno Desthuilliers  > But I *still* fail to see how it could be "misleading", and
> > *you* still fail to explain in which way it could be misleading.
>
> > If your point is that saying that CPython uses a byte-code/VM scheme
> > "just like Java" necessarily implies JIT compilation just because some
> > JVM support this feature, then it would be time you pay more attention
> > to what is effectively written.
>
> What three different people in this thread have been trying to tell
> you but you seem to miss is that claiming CPython's VM "is just like
> Java"

George, *please*, re-read what I wrote. I *never* claimed that
CPython's VM is just like a JVM, I just stated that both CPython and
Java use a byte-code/VM execution model. Can't you understand that ?

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


Re: Python too slow?

2008-01-12 Thread Paul Boddie
On 12 Jan, 04:03, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
>
> Given the way that people seem to use "interpreted" as a pejorative and a
> synonym for "slow", I don't doubt it one bit. Especially in management,
> where they might be making technical judgments on the basis of half-
> remembered Comp Sci 101 lessons from fifteen years earlier and vague
> buzzword-laden articles in trade magazines.

Indeed. Still, there's reason to be upbeat about Python's potential
here. The big question is this: what is everyone with any degree of
concern about Python's performance doing to improve the situation?
Sure, C (or actually C++) seems to win the shootout [1], but there are
plenty of language implementations between g++ and CPython to suggest
that the old choice of extension modules written in C vs. other code
written in Python doesn't provide a complete map of the opportunities.

Paul

[1] http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=all
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get user home directory on Windows

2008-01-12 Thread Giampaolo Rodola'
On 12 Gen, 17:44, Christian Heimes <[EMAIL PROTECTED]> wrote:
> Giampaolo Rodola' wrote:
> > Is there a way to do that?
>
> home = os.path.expanduser("~")
>
> Christian

That gives the home of the *current logged in user*.
I need another thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 11 jan, 15:41, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]>
> writes:
>
> > fact 1: CPython compiles source code to byte-code.
> > fact 2: CPython executes this byte-code.
> > fact 3: Sun's JDK compiles source code to byte-code.
> > fact 4: Sun's JDK executes this byte-code.
>
> > Care to prove me wrong on any of these points ? Don't bother: you
> > can't.
>
> Fact 4 is misleading because it is only one option available to Sun's
> JDK.  Sun's JDK is also capable of transforming the byte-code to
> native code and letting the processor execute that instead of the
> original byte code, and that is where the most significant speed
> increase comes from.  Most importantly, it does so automatically, by
> default, with no programmer intervention or configuration, and with
> 100% compatibility, so it doesn't compare well to Python accelerators
> like psyco.

Then fact 1 is misleading too since Python handles the compilation
automatically without programmer's intervention while Java requires
someone to explicitely invoke the byte-code compiler.

I just don't understand what's all that fuss with this simple and
quite comparison of Java and Python. You can google this ng archives,
you'll find hundreds of posts saying the same thing, and everyone so
far seemed to be smart enough to understand that this had nothing to
do with the byte-code specifications, VM implementation and presence
or absence of a JIT compiler.

Anyway, I do maintain that what I said is 100% correct, 100% accurate
given the context, and 0% misleading unless you're clueless enough to
not be able to parse a single english sentence (in which case I just
can't help). As a matter of fact, this didn't seem to "mislead" the OP
into thinking such a thing.

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


a problem with py2exe

2008-01-12 Thread [EMAIL PROTECTED]
I wrote an app that uses some Tix widgets and wanted to make an exe
using py2exe .i used the setup script as given in 
http://www.py2exe.org/index.cgi/TixSetup
and it copies the dlls into the dist directory created by py2exe.
But then the application works only if i create a directory named
'DLLs ' and copy the tix84.dll alone into that directory. it seems
silly to have tix84.dll in that dir and all other dlls in the dist
directory.can anyone advise me if i can run the app with all dlls in
one directory.
the  setup script i used is below

import glob,os,sys
from distutils.core import setup
import py2exe

def files(folder):
for path in glob.glob(folder+'/*'):
if os.path.isfile(path):
yield path

data_files=[
('.', glob.glob(sys.prefix+'/DLLs/tix84.dll')),
('tcl/tix8.4', files(sys.prefix+'/tcl/tix8.4')),
('tcl/tix8.4/bitmaps',
files(sys.prefix+'/tcl/tix8.4/bitmaps')),
('tcl/tix8.4/pref',
files(sys.prefix+'/tcl/tix8.4/pref')),
]

setup(
script_args=['py2exe'],
windows=['pyfaces.py'],
data_files=data_files
)

thanx in adv
dn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 11 jan, 17:23, Ed Jensen <[EMAIL PROTECTED]> wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> > fact 1: CPython compiles source code to byte-code.
> > fact 2: CPython executes this byte-code.
> > fact 3: Sun's JDK compiles source code to byte-code.
> > fact 4: Sun's JDK executes this byte-code.
>
> > Care to prove me wrong on any of these points ? Don't bother: you can't.
> > So my first assertion that "CPython is compiled to byte-code, which is
> > then executed by a VM" is true, and since the same assertion also stands
> > for Java (ie: sun's JDK), then the "just like" qualifier is true too.
> > Period.
>
> #2 and #4 are wrong (or, at best, misleading).  Here, I'll fix them
> for you:
>
> Fact 2: CPython interprets the bytecode.
>
> Fact 4: Sun's JVM does some interpretation of the bytecode, but also
> compiles some of the bytecode to native code and executes the
> resulting native code.
>
> These distinctions can be important and it's intellectually dishonest
> to gloss over them.

These distinctions are important if the context is the VM
implementation, which is *obviously* not the case here. FWIW, I you
had spent a bit more time reading the remaining of the discussion with
the OP, I do clearly mention this distinction. So please get a life
and keep your comment about "intellectual dishonesty" where they
belong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 10 jan, 21:47, Ed Jensen <[EMAIL PROTECTED]> wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> > I fail to see how the existence of JIT compilers in some Java VM changes
> > anything to the fact that both Java (by language specification) and
> > CPython use the byte-code/VM scheme.
>
> While your answer was technically correct, by omitting pertinent
> information, your answer lead readers to the wrong conclusion.

That's pure non-sense.

> The only question that remains is if you were being accidentally
> misleading or purposefully misleading.

The only question that remains for me is if you are being just stupid
or totally paranoid.

fu2 /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread mc
On Jan 12, 5:34 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> On Jan 12, 9:41 am, mc <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi!
> > I'm trying to compile on my Macbook with OS X 10.5. I have all updates
> > and Xcode 3.0 installed.
>
> > I checked python out with: svn 
> > checkouthttp://svn.python.org/projects/python/branches/py3k
> > After that I did "./configure" in the  created "py3k" dir. Everything
> > went fine. But make fails with the following error message:
> > ranlib libpython3.0.a
> > gcc  -u _PyMac_Error -o python.exe \
> > Modules/python.o \
> > libpython3.0.a -ldl
> > make: *** [sharedmods] Error 1
>
> > I tried checking out many times. I also tried de 3.0a2 release,gives
> > me the same error. I've heard others have compiled it successfully on
> > Leopard so I wonder what causes the problems on my system.
>
> Could you post the rest of the ./configure and compilation output?
> make might be rereporting an error that occurred further up.
>
> I don't see anything related on the Python bug tracker.  It might be
> worth posting a bug report at bugs.python.org
>
> Mark


Alright!
./configure output is here: http://rafb.net/p/NqSmqc25.html
and make output here: http://rafb.net/p/kzeb2e29.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 10 jan, 03:10, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Wed, 09 Jan 2008 21:26:05 +0100, Bruno Desthuilliers wrote:
> > hint: how can a compiler safely optimize anything in a language so
> > dynamic that even the class of an object can be changed at runtime ?
>
> Is that a trick question?
>
Nope. Just an observation about the tradeoffs of dynamism.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread Rhamphoryncus
On Jan 12, 1:37 am, [EMAIL PROTECTED] wrote:
> On Jan 11, 8:04 pm, Paul Rubin  wrote:
>
>
>
> > [EMAIL PROTECTED] writes:
> > > Could you:
>
> > > lockerA= Locker( listA, listB )
> > > lockerA.op( listB.reverse )
> > > lockerA.op( listA.pop )
>
> > > Where lockerA ops acquire the locks on all its threads?
>
> > I don't understand that question.  The main thing to understand is
> > that multi-threaded programming is complicated (especially if you're
> > after high performance), and very difficult to get right without
> > knowing exactly what you're doing.  The generally preferred approach
> > in Python is to keep things simple at some performance cost.
>
> > Your Locker approach above looks sort of reasonable if you can be
> > absolutely sure that nothing else can mess with listA or listB
> > concurrently with those locker operations.  Normally you would put
> > listA and listB into a single object along with a lock, then do
> > operations on that object.
>
> > You might check the Python Cookbook for some specific recipes and
> > sample code for this stuff.  If you've used Java, Python's general
> > threading mechanisms are similar, but they are in the library rather
> > than built into the language (i.e. there is no "synchronized"
> > keyword, you have to do that locking explicitly).
>
> > What is the actual application, if you don't mind saying?  Are you
> > sure that you really need concurrency?
>
> I'm writing an NxN observer pattern, mostly for my own personal
> exploration.  Two threads -might- be calling 'Disconnect' at the same
> time, and I can't even guarantee that the function runs properly.
>
> for emelem in [ e for e in emlist if e.func is func ]:
> try:
> emlist.remove( emelem )
> except ValueError:
> pass

Is there a reason you're using a list, rather than a dict?  Note that
each call to list.remove() is O(n), whereas deleting a key from a dict
is O(1).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 11:22 am, Rhamphoryncus <[EMAIL PROTECTED]> wrote:
> On Jan 12, 1:37 am, [EMAIL PROTECTED] wrote:
>
>
>
> > On Jan 11, 8:04 pm, Paul Rubin  wrote:
>
> > > [EMAIL PROTECTED] writes:
> > > > Could you:
>
> > > > lockerA= Locker( listA, listB )
> > > > lockerA.op( listB.reverse )
> > > > lockerA.op( listA.pop )
>
> > > > Where lockerA ops acquire the locks on all its threads?
>
> > > I don't understand that question.  The main thing to understand is
> > > that multi-threaded programming is complicated (especially if you're
> > > after high performance), and very difficult to get right without
> > > knowing exactly what you're doing.  The generally preferred approach
> > > in Python is to keep things simple at some performance cost.
>
> > > Your Locker approach above looks sort of reasonable if you can be
> > > absolutely sure that nothing else can mess with listA or listB
> > > concurrently with those locker operations.  Normally you would put
> > > listA and listB into a single object along with a lock, then do
> > > operations on that object.
>
> > > You might check the Python Cookbook for some specific recipes and
> > > sample code for this stuff.  If you've used Java, Python's general
> > > threading mechanisms are similar, but they are in the library rather
> > > than built into the language (i.e. there is no "synchronized"
> > > keyword, you have to do that locking explicitly).
>
> > > What is the actual application, if you don't mind saying?  Are you
> > > sure that you really need concurrency?
>
> > I'm writing an NxN observer pattern, mostly for my own personal
> > exploration.  Two threads -might- be calling 'Disconnect' at the same
> > time, and I can't even guarantee that the function runs properly.
>
> > for emelem in [ e for e in emlist if e.func is func ]:
> > try:
> > emlist.remove( emelem )
> > except ValueError:
> > pass
>
> Is there a reason you're using a list, rather than a dict?  Note that
> each call to list.remove() is O(n), whereas deleting a key from a dict
> is O(1).

4.  List-only solution:
Use a dictionary, map item to its index.
To retrieve, sort on value, not key

Sure: you need to maintain order of the things you're guarding.  I
need this to happen first, then this second.  My application is event
callbacks, that you register in a certain order; think GUIs and the
Gamma et al. Chain of Responsibility pattern.  This is a circumstance;
in a lot of applications order doesn't matter and you can use a hash.

But even so, you still can't check membership during concurrent
operation.  In other words, to remove all elements E such that E.func
is FuncF, the simple
   for e in setofe[:]:
  if e.func is not FuncF: continue
  setofe.remove( e )
still doesn't work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get user home directory on Windows

2008-01-12 Thread Giampaolo Rodola'
Update.
I found a way for getting the home directory of the user but it
requires to validate the user by providing username+password:

def get_homedir(username, password):
token = win32security.LogonUser(
username,
None,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT
)
return win32profile.GetUserProfileDirectory(token)

What I'd like to do is avoiding the requirement of the password, the
same way as if I would on UNIX where it would be enough just using the
pwd module:

 >>> import pwd
 >>> pwd.getpwnam('user').pw_dir
 '/home/user'

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


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread Richard Henry

"radiosrfun" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "default" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On Sat, 12 Jan 2008 02:01:09 -0500, "radiosrfun"
> > <[EMAIL PROTECTED]> wrote:
> >
> >>I WISH - that the President and Congress of this country would shut off
> >>ALL
> >>foreign aid.
> >
> > Ditto that.
> >
> > Israel is the chief beneficiary of our foreign aid largesse.  Some 8
> > billion dollars annually.  What doesn't find its way into politicians
> > pockets goes to pay for a military that is winning us a lot of new
> > friends in the Arab world.
> >
> > We pay Egypt ~ 2 billion a year in extortion to keep them from
> > attacking Israel.
> >
> > The actually amount Israel receives is not really known to the public.
> > The official numbers read something like 3 billion in aid, and another
> > 5 billion in guaranteed loans - which are turned into grants year
> > after year.  This is money we borrow so there's an additional interest
> > burden.
> >
> > Actually when you talk about shutting off "foreign aid" you may be
> > making thermate's point for him.
> > --
>
> Well - the first cup of coffee hasn't exactly kicked in yet - but I
believe
> I know what you're saying and if correct - you may have a point there.

According to the US Govt for 2006:

Israel: $2.6B
Egypt   $1.8B
Iraq:   $9.8B
Afghanistan $3.7B

http://qesdb.usaid.gov/gbk/



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


Re: removeall() in list

2008-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> 2) List is referenced by others; concurrent modifications may be going
> on; can not replace it.  Can I make asynchronous modifications and
> merge the changes, SCM-style?

Nothing else should have direct access to the list.

> 3) Dictionary returns non-static order; order is important.  Create a
> int-func tuple and sort dictionary results?  Perhaps.  That's sounding
> pretty good.

If the list is not too long, that is reasonable.  If it -is- long, the
remove operations can be slow, but that's ok if there's not too many.
If the list is long -and- there's a lot of adds/removes, maybe you
want something like an AVL tree.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread default
On Sat, 12 Jan 2008 09:15:44 -0800, ChairmanOfTheBored
<[EMAIL PROTECTED]> wrote:

> You are both fucked in the head, coffee or not.  He more than you, but
>still, you both don't know what you are talking about.

Any castigation from Bored is an accolade . . . I must be on the right
track to get that knee jerk reaction.
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 12:26 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > 2) List is referenced by others; concurrent modifications may be going
> > on; can not replace it.  Can I make asynchronous modifications and
> > merge the changes, SCM-style?
>
> Nothing else should have direct access to the list.
>
> > 3) Dictionary returns non-static order; order is important.  Create a
> > int-func tuple and sort dictionary results?  Perhaps.  That's sounding
> > pretty good.
>
> If the list is not too long, that is reasonable.  If it -is- long, the
> remove operations can be slow, but that's ok if there's not too many.
> If the list is long -and- there's a lot of adds/removes, maybe you
> want something like an AVL tree.

But items[ item ]= index is the best I can do in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Simple List division problem

2008-01-12 Thread marcstuart
How do I divide a list into a set group of sublist's- if the list is
not evenly dividable ?
consider this example:

x = [1,2,3,4,5,6,7,8,9,10]
y = 3  # number of lists I want to break x into
z = y/x


what I would like to get is 3 sublists

print z[0] = [1,2,3]
print z[2] = [4,5,6]
print z[3] = [7,8,9,10]

obviously not even, one list will have 4 elements, the other 2 will
have 3.,
the overriding logic, is that I will get 3 lists and find a way for
python to try to break it evenly, if not one list can have a greater
amount of elements

Would I use itertools ? How would I do this ?

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


super, decorators and gettattribute

2008-01-12 Thread Richard Szopa
Hello all,

I am playing around w/ Python's object system and decorators and I
decided to write (as an exercise) a decorator that (if applied to a
method) would call the superclass' method of the same name before
doing anything (initially I wanted to do something like CLOS
[1] :before and :end methods, but that turned out to be too
difficult).

However, I cannot get it right (specially, get rid of the eval). I
suspect that I may be misunderstanding something happening between
super objects and __getattribute__ methods.

Here's my code:

def endmethod(fun):
"""Decorator to call a superclass' fun first.

If the classes child and parent are defined as below, it should
work like:

>>> x = child()
>>> x.foo()
I am parent's foo
I am child's foo.
"""
name = fun.__name__
def decorated(self, *args, **kwargs):
try:
super_object = super(self.__class__, self)

# now I want to achieve something equivalent to calling
# parent.foo(*args, **kwargs)
# if I wanted to limit it only to this example

# this doesn't work: in the example, it calls child's foo,
# entering in an eternal loop (instead of calling parent's
# foo, as I would expect).

# super_object.__getattribute__(name)(*args, **kwargs)

# this does work, but I feel it's ugly
eval('super_object.%s(*args, **kwargs)' % name)
except AttributeError:
pass # if parent doesn't implement fun, we don't care
 # about it
return fun(self, *args, **kwargs) # hopefully none

decorated.__name__ = name
return decorated


class parent(object):
def foo(self):
print 'I am parent\'s foo'

class child(parent):
@endmethod
def foo(self):
print "I am foo\'s foo."

if __name__=='__main__':
x = child()
x.foo()

Can anybody tell me how to call a superclass method knowing its name?

Thanks in advance,
-- Richard

[1] http://en.wikipedia.org/wiki/Common_Lisp_Object_System
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread radiosrfun
"ChairmanOfTheBored" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sat, 12 Jan 2008 10:35:38 -0500, "radiosrfun"
> <[EMAIL PROTECTED]> wrote:
>
>>"default" <[EMAIL PROTECTED]> wrote in message
>>news:[EMAIL PROTECTED]
>>> On Sat, 12 Jan 2008 02:01:09 -0500, "radiosrfun"
>>> <[EMAIL PROTECTED]> wrote:
>>>
I WISH - that the President and Congress of this country would shut off
ALL
foreign aid.
>>>
>>> Ditto that.
>>>
>>> Israel is the chief beneficiary of our foreign aid largesse.  Some 8
>>> billion dollars annually.  What doesn't find its way into politicians
>>> pockets goes to pay for a military that is winning us a lot of new
>>> friends in the Arab world.
>>>
>>> We pay Egypt ~ 2 billion a year in extortion to keep them from
>>> attacking Israel.
>>>
>>> The actually amount Israel receives is not really known to the public.
>>> The official numbers read something like 3 billion in aid, and another
>>> 5 billion in guaranteed loans - which are turned into grants year
>>> after year.  This is money we borrow so there's an additional interest
>>> burden.
>>>
>>> Actually when you talk about shutting off "foreign aid" you may be
>>> making thermate's point for him.
>>> --
>>
>>Well - the first cup of coffee hasn't exactly kicked in yet - but I 
>>believe
>>I know what you're saying and if correct - you may have a point there.
>>
>  You are both fucked in the head, coffee or not.  He more than you, but
> still, you both don't know what you are talking about.
>
>  If we stop giving aid to other nations, we are letting the retarded US
> hating bastards win, dipshit.
>

I'm not so sure I agree there - money or no money - they hate our guts. Case 
in point - Mushariff. It has long been rumored that Bin-Laden is lurking 
near by - yet "Mushariff" seems to be too weak in the knees to try to hunt 
him down or allow us to. If he doesn't have the balls to do it - let us! I 
am willing to bet - Bin - Laden will eventually cause Mushariff's downfall 
too.

>  This nation has to be strong within, DESPITE what we give out.
>

I couldn't agree with you more!

>  Some of us are...  some of us just want to piss and moan about things
> they know nothing about.
>

I DO know - I'm sick of our tax dollars being blown on every damned 
"emergency" abroad - and we get kicked in the teeth each and every time - 
following.

> Which do you think both of you fucktards are?

None of the above.

Chairman - I don't think "anyone" (American) will disagree with you - least 
of all me - that "WE" need to be strong from "within". The question comes - 
at what cost? IS it an investment? OR "Black mail"? In some cases - it could 
be a fine line.

I would find it hard to believe that 100% of our money is distributed to 
those who are "supposed" to get it. I think we would be fooling ourselves to 
think that.

Maybe I don't operate with "all" facts in hand - but up until now - you and 
I have pretty much been on the same page. Regardless which sentence or 
paragraph we parted company on - the fact remains - "I" am a U.S.citizen - 
born and raised here - and tired of the shit from all those piss ants. It is 
bad enough we have to put up with "crooked" politicians sucking us dry for 
all they can get - without the rest coming in to play their games.

We can agree to disagree with respect to "how" it is done - but we both want 
to see it "BE" done - for the benefit of this country. You and I - or anyone 
else can debate this in a friendly manner - or be pissed off at each other 
over it - the fact remains - those in charge will do as they please - and we 
have little say in the matter.

Any time some outsider slams this country or our people - it just pisses me 
off - which is why I bothered to reply to this thread at all.

Whether we agree on "tactics" or not - if it come to a battlefield with the 
two of us - or any Americans there - we're still going to fight the same 
enemy - not each other. 


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


Re: removeall() in list

2008-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> > Nothing else should have direct access to the list.
> Impossible to guarantee in Python.  If you do, the reference to you does.

Well, ok.  Nothing else should USE that access.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread Joe Riopel
On Jan 12, 2008 2:00 PM, radiosrfun <[EMAIL PROTECTED]> wrote:
> Whether we agree on "tactics" or not - if it come to a battlefield with the
> two of us - or any Americans there - we're still going to fight the same
> enemy - not each other.

This is a good resource for starting Python
http://diveintopython.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple List division problem

2008-01-12 Thread marcstuart
I have gotten a little further, but not in the order of the original
list

def divide_list(lst, n):
return [lst[i::n] for i in range(n)]

x = [1,2,3,4,5,6,7,8,9,10]
y = 3
z =  divide_list(x,y)

print z[0]
print z[1]
print z[2]


this prints:

[1, 4, 7, 10]
[2, 5, 8]
[3, 6, 9]



closer, but I would like to maintain the original order of the list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 1:03 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > > Nothing else should have direct access to the list.
> > Impossible to guarantee in Python.  If you do, the reference to you does.
>
> Well, ok.  Nothing else should USE that access.

Ah, very agreed.  Access directly at your own risk.

Will you engage with me over e-mail to discuss the Locker
implementation I'm developing?  Aaron
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Import and execfile()

2008-01-12 Thread lloyd
Hello,

> I maintain a few configuration files in Python syntax (mainly nested

> dicts of ints and strings) and use execfile() to read them back to

> Python. This has been working great; it combines the convenience of

> pickle with the readability of Python. So far each configuration is

> contained in a single standalone file; different configurations are

> completely separate files.


> Now I'd like to factor out the commonalities of the different

> configurations in a master config and specify only the necessary

> modifications and additions in each concrete config file. I tried the

> simplest thing that could possibly work:

I've been working with a similar problem; indeed, posted a question about it 
several weeks ago.

I
can't speak to the issue of factoring out commonalities, but I've been
trying to find a really simple, elegant way to avoid the exec
functions. My approaches have been variations in __import__() and
loading as file, etc. Everything I've tried seems a bit kludgy. One
issue, as I recall, was that __import__() became rather unreliable when
you crossed directory boundaries.

Question: Why do so many sources discourage the use of exec(), execfile(), etc.?

Comment:
The Karrigell Python web framework
(http://karrigell.sourceforge.net/en/include.htm) has a truly elegant
function for loading stuff like some_config.py called Include(). I
haven't looked at the source, but it is very handy. I really wish it
was basic Python function.

All the best,

Lloyd



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

Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 12:26 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > 2) List is referenced by others; concurrent modifications may be going
> > on; can not replace it.  Can I make asynchronous modifications and
> > merge the changes, SCM-style?
>
> Nothing else should have direct access to the list.
Impossible to guarantee in Python.  If you do, the reference to you
does.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: where do my python files go in linux?

2008-01-12 Thread lloyd
Hello,

> Question 1. Where do I put the bulk of python scripts in a normal

> linux environment?

In my system I put them in
/usr/local/lib/python2.4/site-packages/my_scripts. And, I have *.pth
file in /usr/local/lib/python2.4/site-packages that points to
my_scripts. The *.pth file simply reads "my_scripts" -- without the
quotes, of course.

This one area where Python docs are pretty vague. It took me awhile to piece 
this together. But it works.

Best wishes,

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

Re: super, decorators and gettattribute

2008-01-12 Thread Richard Szopa
On Jan 12, 7:45 pm, Richard Szopa <[EMAIL PROTECTED]> wrote:

> doing anything (initially I wanted to do something like CLOS
> [1] :before and :end methods, but that turned out to be too
> difficult).

Erm, I meant :before and :after methods.

-- Richard

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


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
Oh.. it seems my naiveness has stirred quite a discussion >_<...

I must admit though, I've learned a bit about Python reading through
this topic.  Thanks to everyone who pointed out the flaws in the
code.  I'll see if I can come up with my own color tracking solution
in a few weeks and post back here.  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple List division problem

2008-01-12 Thread [EMAIL PROTECTED]
On Jan 12, 12:37 pm, marcstuart <[EMAIL PROTECTED]> wrote:
> How do I divide a list into a set group of sublist's- if the list is
> not evenly dividable ?
> consider this example:
>
> x = [1,2,3,4,5,6,7,8,9,10]
> y = 3      # number of lists I want to break x into
> z = y/x
>
> what I would like to get is 3 sublists
>
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]
>
> obviously not even, one list will have 4 elements, the other 2 will
> have 3.,
> the overriding logic, is that I will get 3 lists and find a way for
> python to try to break it evenly, if not one list can have a greater
> amount of elements
>
> Would I use itertools ? How would I do this ?
>
> Thanks

def list_split(x,y):
  dm = divmod(len(x),y)
  if dm[1] != 0:
z = [x[i*y:i*y+y] for i in xrange(len(x)/y) if len(x[i*y:])>=2*y]
z.append(x[(len(x)/y-1)*y:])
  else:
z = [x[i*y:i*y+y] for i in xrange(len(x)/y)]
  return z

>>> list_split([1,2,3,4,5,6,7,8,9,10],3)
[[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
>>> list_split([1,2,3,4,5,6,7,8,9,10],5)
[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
>>> list_split([1,2,3,4,5,6,7,8,9,10],4)
[[1, 2, 3, 4], [5, 6, 7, 8, 9, 10]]
>>> list_split([1,2,3,4,5,6,7,8,9,10],2)
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple List division problem

2008-01-12 Thread Gary Herron
marcstuart wrote:
> How do I divide a list into a set group of sublist's- if the list is
> not evenly dividable ?
> consider this example:
>
> x = [1,2,3,4,5,6,7,8,9,10]
> y = 3  # number of lists I want to break x into
> z = y/x
>
>
> what I would like to get is 3 sublists
>
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]
>
> obviously not even, one list will have 4 elements, the other 2 will
> have 3.,
> the overriding logic, is that I will get 3 lists and find a way for
> python to try to break it evenly, if not one list can have a greater
> amount of elements
>
> Would I use itertools ? How would I do this ?
>
> Thanks
>   

Calculate the size of a normal sublist, and the amount of extra that
goes with the last sublist.
Then extract y-1 normal sized sublists and one possibly larger sublist.

>>> x = [1,2,3,4,5,6,7,8,9,10]
>>> y = 3
>>> s = len(x)/y
>>> s# size of normal sublists
3
>>> e = len(x) - y*s  # extra elements for last sublist
>>> e
1
>>> z = [x[s*i:s*i+s] for i in range(y-1)] + [x[-s-e:]] #extract y-1
normal + 1 larger sublists
>>> z
[[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]

Done!

Gary Herron





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


Re: Great Python books for the beginner

2008-01-12 Thread babycode
On Jan 12, 2:03 am, Landon <[EMAIL PROTECTED]> wrote:

> I was wondering if anyone had any opinions on what other titles I
> could look into since this one seems from a glance at reviews to be
> teaching mainly through game programming (a topic I'm not too
> interested in) or if this one is a quality book by itself.

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


Re: IDLE won't start in Python 2.5 for Windows

2008-01-12 Thread mikez302
I opened a command window in my Python25 folder and tried typing
pythonw.  I just got another command prompt as if the program ran but
didn't do anything.  It looked like this:

C:\Python25>pythonw

C:\Python25>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE won't start in Python 2.5 for Windows

2008-01-12 Thread Fredrik Lundh
mikez302 wrote:

> I opened a command window in my Python25 folder and tried typing
> pythonw.  I just got another command prompt as if the program ran but
> didn't do anything.  It looked like this:
> 
> C:\Python25>pythonw
> 
> C:\Python25>

"pythonw" is the console-less version of the Python runtime, so that's 
expected.  Try using "python" instead.



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


Re: where do my python files go in linux?

2008-01-12 Thread Joe Riopel
On Jan 12, 2008 10:13 AM, Jorgen Bodde <[EMAIL PROTECTED]> wrote:
> I thought about that too. I just wonder why /usr/local/bin is always
> empty and every .deb I install from a source (if it's from Ubuntu or
> not) installs files in /usr/bin .. So I looked further and noticed
> that most python files do reside in /usr/share/{appname}

This link might explain why your /usr/local/bin is empty:

http://www.pathname.com/fhs/pub/fhs-2.3.html#THEUSRHIERARCHY
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Will you engage with me over e-mail to discuss the Locker
> implementation I'm developing?  Aaron

I really can't, sorry.  I'm finding it hard enough to follow over the
newsgroup.  If you just have a single one of these lists, it's
probably simplest to do what Frederik Lundh suggested.  The other
stuff we've discussed is mostly about how to organize having a lot of
them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread Mark Dickinson
On Jan 12, 12:05 pm, mc <[EMAIL PROTECTED]> wrote:
> Alright!
> ./configure output is here:http://rafb.net/p/NqSmqc25.html
> and make output here:http://rafb.net/p/kzeb2e29.html

Hmm. Doesn't seem to be anything unusual here.  I was expecting to see
some more informative error message somewhere.  Does this output
definitely include everything sent to stderr and to stdout, or did it
come from just redirecting stdout?

I don't understand where all the

rm: conftest.dSYM: is a directory

lines in the configure output are coming from.  Can this possibly be
related?

Anyone else here have any ideas how to proceed?

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


Re: Simple List division problem

2008-01-12 Thread Fredrik Lundh
marcstuart wrote:

> How do I divide a list into a set group of sublist's- if the list is
> not evenly dividable ?  consider this example:
> 
> x = [1,2,3,4,5,6,7,8,9,10]
> y = 3  # number of lists I want to break x into
> z = y/x
> 
> what I would like to get is 3 sublists
> 
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]
> 
> obviously not even, one list will have 4 elements, the other 2 will
> have 3.,

here's one way to do it:

# chop it up
n = len(x) / y
z = [x[i:i+n] for i in xrange(0, len(x), n)]

# if the last piece is too short, add it to one before it
if len(z[-1]) < n and len(z) > 1:
 z[-2].extend(z.pop(-1))



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


Re: where do my python files go in linux?

2008-01-12 Thread Carl Banks
On Sat, 12 Jan 2008 12:02:20 +0100, Jorgen Bodde wrote:
> I am trying to make a debian package. I am following the tutorial by
> Horst Jens
> (http://showmedo.com/videos/video?
name=linuxJensMakingDeb&fromSeriesID=37)
> and it is very informative. However one thing my app has and his
> doesn't, is multiple python files which need to be executed. For example
> 
> {dir}/app
> app.py
> 
> app.py calls a lot of modules in {dir}/app. Horst says the python file
> goes in /usr/bin/app.py which is ok with me, but I have multiple python
> files, and I decided to use an app.sh script to call my python files. In
> the /usr/bin I do not see subdirs so I assume that is not really
> desirable.
> 
> Question 1. Where do I put the bulk of python scripts in a normal linux
> environment?
> Question 2. Should I use *.pyc rather then *.py files to speed up
> executing as the user cannot write to /usr/bin or any other dir in the
> system and everytime my app runs it will recompile it
> 
> Thanks for any advice or maybe a good tutorial how to set up files in a
> linux environment

On a Debian system:


I would put app.py in /usr/local/bin.  I would create the directory
/usr/local/lib/app, and put all other *.py and *.pyc files there.  At the 
top of app.py, I'd add the following line so that I could import files 
directly from /usr/local/lib/app:

sys.path.insert(0,'/usr/local/lib/app')


Alternatively, using your app.sh approach, I'd put app.sh in
/usr/local/bin/, and all *.py and *.pyc files in /usr/local/lib/app.  I'd 
invoke Python something like this:

PYTHONPATH=/usr/local/lib/app:$PYTHONPATH  python -m app

(The -m switch searches the Python path for a module to run.) 


If it's more of a library than an application (maybe there is a command 
line script, but users could want to import the modules directly), then 
I'd stick all the modules in /usr/local/lib/python2.x/site-packages, and 
the command line scripts in /usr/local/bin.


Yes, install the *.pyc files.  I recommend putting *.py files there as 
well, so users can refer to it if there are any problems, but you don't 
have to.  The Python module compileall is your friend here.


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


Re: Great Python books for the beginner

2008-01-12 Thread GeneralCody
On 2008-01-12 08:03:42 +0100, Landon <[EMAIL PROTECTED]> said:

> Hi, I'm a freshman in college and I'm going to be taking an intro to
> programming course next semester which mainly uses Python, so I
> thought it might be a good time to pick up Python beyond the scope of
> the class as well. The text book for this class is Python for the
> Absolute Beginner or something similar to that name.
> 
> I was wondering if anyone had any opinions on what other titles I
> could look into since this one seems from a glance at reviews to be
> teaching mainly through game programming (a topic I'm not too
> interested in) or if this one is a quality book by itself.

I would definetly go for Learning Python first, maybe Apress "Python, 
from novice to Professional" as well...

 

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


Re: Import and execfile()

2008-01-12 Thread Mike Meyer
On Fri, 11 Jan 2008 20:55:07 -0800 (PST) George Sakkis <[EMAIL PROTECTED]> 
wrote:
> On Jan 11, 5:24 pm, Mike Meyer <[EMAIL PROTECTED]>
> wrote:
> > On Fri, 11 Jan 2008 14:05:11 -0800 (PST) George Sakkis <[EMAIL PROTECTED]> 
> > wrote:
> > > I maintain a few configuration files in Python syntax (mainly nested
> > > dicts of ints and strings) and use execfile() to read them back to
> > > Python. This has been working great; it combines the convenience of
> > > pickle with the readability of Python. So far each configuration is
> > > contained in a single standalone file; different configurations are
> > > completely separate files.
> > You can make the syntax cleaner by using classes to hold the values
> > instead of nested dicts, etc. That way you don't have to quote the
> > names of the values:
> > class Foo:
> >   bar = 1
> >   baz = 2
> Actually I am using the dict() constructor instead of literals so it's
> as clean as with classes; IMO for nested options it's cleaner than
> nested classes:

Yup, that does that. Wasn't available last time I did this, so...
> > > I understand why this fails but I'm not sure how to tell execfile() to
> > > set the path accordingly. Any ideas ?
> > Manipulate sys.path yourself?
> That's what Mitko suggested too, and indeed it works:
> However this doesn't look very clean to me. Also it's not thread-safe;

I don't know that there is a clean solutions. As for not being
thread-safe, I'd suggest that you should have all your configuration
information loaded *before* you start any threads. This makes shutting
down in case you decide there's something wrong in it easier, and in
some cases may prevent inadvertently doing things that shouldn't
oughta be done. In the case where you config files are parsed by the
python interpreter, this goes double because a busted config file
could lead to exceptions, leaving your application in an unknown
state.

 http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread Landon
One thing I wonder about is the examples these books use to teach the
concepts. I found myself really attached to K&R because the end of
section projects were utilities that I would find be able to find
useful in day to day work such as a version of wc and a program that
would take collapse all consecutive whitespace in a document into one
space. I could just use the projects from K&R, but I imagine a Python
book would have a better selection that highlight Python's abilities.

On another note, I would prefer to have a paper book so I don't have
to keep switching back and forth between documents on my computer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where do my python files go in linux?

2008-01-12 Thread Mike Meyer
On Sat, 12 Jan 2008 16:13:08 +0100 "Jorgen Bodde" <[EMAIL PROTECTED]> wrote:
> > Normally you'd split up the bulk of the code into a module which gets
> > installed into site-packages and a piece of stand-alone front-end code which
> > imports the module and executes whatever you need to do and gets installed
> > into a typical PATH directory.
> I would agree but it is not a site package I am trying to distribute,
> but a wxPython application. I would not think my app belongs in the
> python site packages dir.

I suspect that's because your app is "simple", in that it only has one
command. Many apps have multiple commands that share the same set of
libraries. So putting a package for that app in site-packages makes a
lot of sense. If your app-specific library is properly designed and
documented, users may be able to build further commands for the system
as well.

On the issue of .pyc files - don't distribute them. Instead, arrange
for the install package to run the compileall.py script (in the
standard library) on your libraries. .pyc files are *not* guaranteed
to be platform independent (even though the latest rpm tools seem to
claim otherwise), so if you build them for your platform, they may
well be unusable after being installed.

   http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


sqlite3 is it in the python default distro?

2008-01-12 Thread Martin Marcher
Hello,

I can see that sqlite is in the standard lib documentation:
http://docs.python.org/lib/module-sqlite3.html

however debian and ubuntu (and gentoo according to the packages info) seem
_not_ to include it. 

Now 2 question arise:

a) Is sqlite included in the python default distribution
b) In real life can I consider (on linux) that an installation of python
includes the sqlite stuff?

thanks
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: super, decorators and gettattribute

2008-01-12 Thread Mike Meyer
On Sat, 12 Jan 2008 10:45:25 -0800 (PST) Richard Szopa <[EMAIL PROTECTED]> 
wrote:

> Hello all,
> 
> I am playing around w/ Python's object system and decorators and I
> decided to write (as an exercise) a decorator that (if applied to a
> method) would call the superclass' method of the same name before
> doing anything (initially I wanted to do something like CLOS
> [1] :before and :end methods, but that turned out to be too
> difficult).
> 
> However, I cannot get it right (specially, get rid of the eval). I
> suspect that I may be misunderstanding something happening between
> super objects and __getattribute__ methods.
> 
> Here's my code:
> 
> def endmethod(fun):
> """Decorator to call a superclass' fun first.
> 
> If the classes child and parent are defined as below, it should
> work like:
> 
> >>> x = child()
> >>> x.foo()
> I am parent's foo
> I am child's foo.
> """
> name = fun.__name__
> def decorated(self, *args, **kwargs):
> try:
> super_object = super(self.__class__, self)

There's an apparently common bug here: you don't want to pass super
self.__class__, but the class that the method is bound to. The two
aren't the same, as an instance of a subclass will have the subclass
as self.__class__, and not the current class. So super will return the
current class or a subclass of it, meaning (since you invoked this
method from self) you'll wind up invoking this method recursively.
All of which means your decorator is probably going to have to take
the class as an argument.

> # now I want to achieve something equivalent to calling
> # parent.foo(*args, **kwargs)
> # if I wanted to limit it only to this example
> 
> # this doesn't work: in the example, it calls child's foo,
> # entering in an eternal loop (instead of calling parent's
> # foo, as I would expect).
> 
> # super_object.__getattribute__(name)(*args, **kwargs)
> 
> # this does work, but I feel it's ugly
> eval('super_object.%s(*args, **kwargs)' % name)
> except AttributeError:
> pass # if parent doesn't implement fun, we don't care
>  # about it
> return fun(self, *args, **kwargs) # hopefully none
> 
> decorated.__name__ = name
> return decorated
> 
> 
> class parent(object):
> def foo(self):
> print 'I am parent\'s foo'
> 
> class child(parent):
> @endmethod
> def foo(self):
> print "I am foo\'s foo."
> 
> if __name__=='__main__':
> x = child()
> x.foo()
> 
> Can anybody tell me how to call a superclass method knowing its name?

The same way you call any object's methods if you know it's name":

getattr(super_object, name)(*args, **kwargs)

The code seems to work the way you want:

>>> x.foo()
I am parent's foo
I am foo's foo.

   http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 is it in the python default distro?

2008-01-12 Thread Gary Herron
Martin Marcher wrote:
> Hello,
>
> I can see that sqlite is in the standard lib documentation:
> http://docs.python.org/lib/module-sqlite3.html
>
> however debian and ubuntu (and gentoo according to the packages info) seem
> _not_ to include it. 
>
> Now 2 question arise:
>
> a) Is sqlite included in the python default distribution
> b) In real life can I consider (on linux) that an installation of python
> includes the sqlite stuff?
>
> thanks
> martin
>
>   
As I understand it, Python2.5 includes the *module* which can be
imported to access an sqlite installation, but it does not include the
sqlite installation itself.   That should be installed separately.   (I
suppose a distro of Linux could package them together, but I don't  know
of one that does, and such is not the intent of Python.)

Gary Herron

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


Re: Great Python books for the beginner

2008-01-12 Thread André
On Jan 12, 4:04 pm, Landon <[EMAIL PROTECTED]> wrote:
> One thing I wonder about is the examples these books use to teach the
> concepts. I found myself really attached to K&R because the end of
> section projects were utilities that I would find be able to find
> useful in day to day work such as a version of wc and a program that
> would take collapse all consecutive whitespace in a document into one
> space. I could just use the projects from K&R, but I imagine a Python
> book would have a better selection that highlight Python's abilities.
>
> On another note, I would prefer to have a paper book so I don't have
> to keep switching back and forth between documents on my computer.

You don't need to switch back and forth ... if you use Crunchy!

http://code.google.com/p/crunchy

To see it in action, 
http://showmedo.com/videos/video?name=143&fromSeriesID=143

(the third video in that series shows how to quickly get started using
the official Python tutorial).

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


Re: Simple List division problem

2008-01-12 Thread Paul Rubin
marcstuart <[EMAIL PROTECTED]> writes:
> what I would like to get is 3 sublists
> 
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]

Are you SURE you want that?  In almost every situation I've seen,

 print z[0] = [1,2,3]
 print z[2] = [4,5,6]
 print z[3] = [7,8,9]
 print z[4] = [10]

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


Re: Great Python books for the beginner

2008-01-12 Thread [EMAIL PROTECTED]
On 12 jan, 21:04, Landon <[EMAIL PROTECTED]> wrote:
> One thing I wonder about is the examples these books use to teach the
> concepts. I found myself really attached to K&R because the end of
> section projects were utilities that I would find be able to find
> useful in day to day work such as a version of wc and a program that
> would take collapse all consecutive whitespace in a document into one
> space. I could just use the projects from K&R, but I imagine a Python
> book would have a better selection that highlight Python's abilities.

It wouldn't make any sens to port the K&R stuff to Python - different
languages, different uses, different problems... I mean, C is a low-
level language, mostly useful for low-level system programming, while
Python is a very high level language mostly useful for application
programming and Q&D scripting. So the applicative examples from K&R
are such no-brainers in Python they wouldn't teach you much, and the
more low-level examples (memory handling etc) just don't make sens in
Python because that's definitively not something you'd write in
Python.

But anyway: if you're looking for more real-life-like examples, Mark
Lutz's "Programming Python" might be worth a look.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread John Machin
On Jan 12, 10:51 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Robert Kern wrote:
> >> However it appears from your bug ticket that you have a much narrower
> >> problem (case-shifting a small known list of English words like VOID)
> >> and can work around it by writing your own locale-independent casing
> >> functions. Do you still need to find out whether Python unicode
> >> casings are locale-dependent?
>
> > I would still like to know. There are other places where .lower() is used in
> > numpy, not to mention the rest of my code.
>
> "lower" uses the informative case mappings provided by the Unicode
> character database; see
>
>  http://www.unicode.org/Public/4.1.0/ucd/UCD.html

of which the relevant part is
"""
Case Mappings

There are a number of complications to case mappings that occur once
the repertoire of characters is expanded beyond ASCII. For more
information, see Chapter 3 in Unicode 4.0.

For compatibility with existing parsers, UnicodeData.txt only contains
case mappings for characters where they are one-to-one mappings; it
also omits information about context-sensitive case mappings.
Information about these special cases can be found in a separate data
file, SpecialCasing.txt.
"""

It seems that Python doesn't use the SpecialCasing.txt file. Effects
include:
(a) one-to-many mappings don't happen e.g. LATIN SMALL LETTER SHARP S:
u'\xdf'.upper() produces u'\xdf' instead of u'SS'
(b) language-sensitive mappings (e.g. dotted/dotless I/i for Turkish
(and Azeri)) don't happen
(c) context-sensitive mappings don't happen e.g. lower case of GREEK
CAPITAL LETTER SIGMA depends on whether it is the last letter in a
word.



>
> afaik, changing the locale has no influence whatsoever on Python's
> Unicode subsystem.
>
> 

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


Re: where do my python files go in linux?

2008-01-12 Thread Carl Banks
On Sat, 12 Jan 2008 15:25:53 -0500, Mike Meyer wrote:

> On Sat, 12 Jan 2008 16:13:08 +0100 "Jorgen Bodde"
> <[EMAIL PROTECTED]> wrote:
>> > Normally you'd split up the bulk of the code into a module which gets
>> > installed into site-packages and a piece of stand-alone front-end
>> > code which imports the module and executes whatever you need to do
>> > and gets installed into a typical PATH directory.
>> I would agree but it is not a site package I am trying to distribute,
>> but a wxPython application. I would not think my app belongs in the
>> python site packages dir.
> 
> I suspect that's because your app is "simple", in that it only has one
> command. Many apps have multiple commands that share the same set of
> libraries. So putting a package for that app in site-packages makes a
> lot of sense.

They should go into their own directory in /usr/local/lib (or whatever).


> If your app-specific library is properly designed and
> documented, users may be able to build further commands for the system
> as well.

Users can still add the /usr/local/lib/whatever to their path path and 
use it that way.

I realize it's a fine line and a judgment call in some cases, but site-
packages is really for libraries; applications should use their own 
directories.


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


Re: sqlite3 is it in the python default distro?

2008-01-12 Thread Diez B. Roggisch
Martin Marcher schrieb:
> Hello,
> 
> I can see that sqlite is in the standard lib documentation:
> http://docs.python.org/lib/module-sqlite3.html
> 
> however debian and ubuntu (and gentoo according to the packages info) seem
> _not_ to include it. 
> 
> Now 2 question arise:
> 
> a) Is sqlite included in the python default distribution

Yes, since 2.5

> b) In real life can I consider (on linux) that an installation of python
> includes the sqlite stuff?

distutils is an example of a standard-module that gets ripped out of 
python by distros frequently, so that people need to install python-dev 
or such a package.

So - yes, it happens that distros don't deliver the whole standard 
distribution. Now I'm not sure if that happens for sqlite, but if your 
own tests show so (reminder: python 2.5, accidentially using earlier 
versions that are installed won't work of course), then the answer is - 
no, you can't

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


Re: sqlite3 is it in the python default distro?

2008-01-12 Thread Fredrik Lundh
Martin Marcher wrote:

> I can see that sqlite is in the standard lib documentation:
> http://docs.python.org/lib/module-sqlite3.html
> 
> however debian and ubuntu (and gentoo according to the packages info) seem
> _not_ to include it. 

http://packages.debian.org/python-sqlite



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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread John Machin
On Jan 12, 11:26 pm, Torsten Bronger <[EMAIL PROTECTED]>
wrote:
> Hallöchen!
>
>
>
> Fredrik Lundh writes:
> > Robert Kern wrote:
>
> >>> However it appears from your bug ticket that you have a much
> >>> narrower problem (case-shifting a small known list of English
> >>> words like VOID) and can work around it by writing your own
> >>> locale-independent casing functions. Do you still need to find
> >>> out whether Python unicode casings are locale-dependent?
>
> >> I would still like to know. There are other places where .lower()
> >> is used in numpy, not to mention the rest of my code.
>
> > "lower" uses the informative case mappings provided by the Unicode
> > character database; see
>
> >http://www.unicode.org/Public/4.1.0/ucd/UCD.html
>
> > afaik, changing the locale has no influence whatsoever on Python's
> > Unicode subsystem.
>
> Slightly off-topic because it's not part of the Unicode subsystem,
> but I was once irritated that the none-breaking space (codepoint xa0
> I think) was included into string.whitespace.  I cannot reproduce it
> on my current system anymore, but I was pretty sure it occured with
> a fr_FR.UTF-8 locale.  Is this possible?  And who is to blame, or
> must my program cope with such things?

The NO-BREAK SPACE is treated as whitespace in the Python unicode
subsystem. As for str objects, the default "C" locale doesn't know it
exists; otherwise AFAIK if the character set for the locale has it, it
will be treated as whitespace.

You were irritated because non-break SPACE was included in
string.whiteSPACE? Surely not! It seems eminently logical to me.
Perhaps you were irritated because str.split() ignored the "no-break"?
If like me you had been faced with removing trailing spaces from text
columns in databases, you surely would have been delighted that
str.rstrip() removed the trailing-padding-for-nicer-layout no-break
spaces that the users had copy/pasted from some clown's website :-)

What was the *real* cause of your irritation?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where do my python files go in linux?

2008-01-12 Thread Jeroen Ruigrok van der Werven
Hi Jorgen,

-On [20080112 16:14], Jorgen Bodde ([EMAIL PROTECTED]) wrote:
>I thought about that too. I just wonder why /usr/local/bin is always
>empty and every .deb I install from a source (if it's from Ubuntu or
>not) installs files in /usr/bin .. So I looked further and noticed
>that most python files do reside in /usr/share/{appname}

Well, it always seemed that many Linux distributions had to do things
different from a file/directory hierarchy point of view and I never fully
understood why. It always seemed a bit inspired by NIH-syndrome.
But like I said, whatever works for you.

>I would agree but it is not a site package I am trying to distribute,
>but a wxPython application. I would not think my app belongs in the
>python site packages dir.

Mmm, I guess Python does not have a wonderful solution for this kind of
scenario to be honest. The site-packages solution is one of the cleanest I can
think of.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Only I can change my life. No one can do it for me...
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   >