Re: Python's "only one way to do it" philosophy isn't good?

2007-07-01 Thread Paul Rubin
Douglas Alan <[EMAIL PROTECTED]> writes:
> > Haskell and ML are both evaluate typed lambda calculus unlike Lisp
> > which is based on untyped lambda calculus.  Certainly the most
> > familiar features of Lisp (dynamic typing, S-expression syntax,
> > programs as data (Lisp's macro system results from this)) are absent
> > from Haskell and ML.
> 
> And that is supposed to make them better and more flexible??? 

Well no, by itself the absence of those Lisp characteristics mainly
means it's a pretty far stretch to say that Haskell and ML are Lisp
dialects.

> The ideal language of the future will have *optional* manifest
> typing along with type-inference, and will have some sort of pramgma
> to turn on warnings when variables are forced to become dynamic due
> to there not being enough type information to infer the type.  But
> it will still allow programming with dynamic typing when that is
> necessary.

If I understand correctly, in Haskell these are called existential types:

   http://haskell.org/hawiki/ExistentialTypes

> The last time I looked at Haskell, it was still in the stage of being
> a language that only an academic could love.  

I used to hear the same thing said about Lisp.

> > Haskell's type system lets it do stuff that Lisp can't approach.
> 
> What kind of stuff?  Compile-time polymorphism is cool for efficiency
> and type safety, but doesn't actually provide you with any extra
> functionality that I'm aware of.

For example, it can guarantee referential transparency of functions
that don't live in certain monads.  E.g. if a function takes an
integer arg and returns an integer (f :: Integer -> Integer), the type
system guarantees that computing f has no side effects (it doesn't
mutate arrays, doesn't open network sockets, doesn't print messages,
etc).  That is very helpful for concurrency, see the paper "Composable
Memory Transactions" linked from here:

  http://research.microsoft.com/Users/simonpj/papers/stm/index.htm

other stuff there is interesting too.

> Where do you get this idea that the Lisp world does not get such
> things as parallelism?  StarLisp was designed for the Connection
> Machine...

Many parallel programs have been written in Lisp and *Lisp, and
similarly in C, C++, Java, and Python, through careful use of manually
placed synchronization primitives, just as many programs using dynamic
memory allocation have been written in C with manual use of malloc and
free.  This presentation shows some stuff happening in Haskell that
sounds almost as cool as bringing garbage collection to the
malloc/free era:

 http://research.microsoft.com/~simonpj/papers/ndp/NdpSlides.pdf

As for where languages are going, I think I already mentioned Tim
Sweeney's presentation on "The Next Mainstream Programming Language":

  http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf

It's not Haskell, but its type system is even more advanced than Haskell's.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to uninstall packages

2007-07-01 Thread Martin v. Löwis
> So now my question:  How does one uninstall  *cleanly*
> 
> 1> a package installed using setup.py install
> 2> a package installed with easy_install

Run "setup.py install" with the --record option; then remove
all files that have been recorded as installed.

This is clean depending on the package being installed;
a package may perform additional actions which don't get
recorded in the --record option; in such a case, you need
to study setup.py and find out what these additional
actions are and how to revert them.

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


Re: Memory leak in PyQt application

2007-07-01 Thread Daniel Nogradi
> Python 2.5.1
> Boost.Python
> Qt 4.2.2
> SIP 4.6
> PyQt 4.2
> WinXp
>
> I've a memory leak in a PyQt application and no idea how to find it. What
> happens in the application ?
>
>  From QWindow a QDialog is called on a button "pressed()" signal, that
> instantiate a QThread and waits for it. If the thread has finished, the
> QDialog
> closes.
>
> I've stipped down everything that nothing more happens (to me obviously).
> Boost.Python is used to wrap a C++ Lib (used in the thread). Every time
> memory
> usage increases for ~70 KB.
>
> Sometimes the application crash on closing QWindow. (QtCore.dll)
>
> - One thing I ask me is weather garbage collection is done in the PyQt main
> loop?
>
> What hints do you have to find the leak?


Have a look at valgrind: http://valgrind.org/

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


Re: How to close a program I execute with subprocess.Popen?

2007-07-01 Thread Nick Craig-Wood
A.T.Hofkamp <[EMAIL PROTECTED]> wrote:
>  In principle, you should only kill your own child processes, your child 
> process
>  should handle its own childs (your grant child processes). SIGTERM is one 
> way.
>  Another solution often adopted is to close the stdin of the child.

That is a good idea.

You could also make the parent a process group leader and kill the
process group.  You'll get the kill signal too which you'll need to
ignore.  That is how the shell keeps track of things IIRC.

Read man setpgid, getpgid should be helful.  There are equivalent
commands in os, ie os.setpgid and os.getpgid.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


howto resend args and kwargs to other func?

2007-07-01 Thread dmitrey
I need something like this:

def func1(*args, **kwargs):
  if some_cond:
return func2(*args, **kwargs)
  else:
return func3(some_other_args, **kwargs)

Thank you in advance, D.

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


Re: howto resend args and kwargs to other func?

2007-07-01 Thread Duncan Booth
dmitrey <[EMAIL PROTECTED]> wrote:

> I need something like this:
> 
> def func1(*args, **kwargs):
>   if some_cond:
> return func2(*args, **kwargs)
>   else:
> return func3(some_other_args, **kwargs)
> 
> Thank you in advance, D.
> 
> 
You 'need something like this', so write something like that.
Did you intend to ask a question?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto resend args and kwargs to other func?

2007-07-01 Thread dmitrey
On Jul 1, 12:00 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:

> You 'need something like this', so write something like that.
> Did you intend to ask a question?

I would gladly write the one, but the example doesn't work, and I
don't know any easy way (moreover any way) to make it work correctly.
D.

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


Re: Reversing a string

2007-07-01 Thread Duncan Booth
Martin Durkin <[EMAIL PROTECTED]> wrote:

> def rev(x):
>> mylist = []
>> for char in x:
>>  mylist.append(char)
>> mylist.reverse()
>> for letter in mylist:
>>  print letter
>> 
>> However, compare the incredible difference in clarity and elegance
>> between that and:
>> 
>>> >>> print "\n".join("spam"[::-1])
>> 
> 
> OK, maybe I'm missing the point here as I'm new to Python. The first one 
> seems clearer to me. What am I missing?
> 
I think all you are missing is familarity with Python, but I too don't like 
one-liners simply for their own sake.

Slicing is one of Pythons great features, but even experienced programmers 
often forget that you can have a third argument to a slice or that it can 
even be negative.

The syntax for joining a sequence of strings with a separator is ugly, I 
sometimes prefer to write it out as:
   print str.join('\n', whatever)
or:
   joinlines = '\n'.join
   ...
   print joinlines(whatever)

but in this case I'd be as likely to go for an explicit loop for the print:

def rev(x):
for letter in x[::-1]:
print letter

which I think hits about the optimum between brevity and clarity. Your own 
optimum point may of course vary.
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.isfile()

2007-07-01 Thread 7stud
Here is a program to print out the files in a directory:

---
import os

myfiles = os.listdir("../")
print myfiles

for afile in myfiles:
print afile
if os.path.isfile(afile):
print afile, "___file"
if os.path.isdir(afile):
print afile, "___dir"
print


Here is what's in the directory:

--
$ ls -al ../

total 2576
drwxr-xr-x8 nnn  nnn  272 Jul  1 03:03 .
drwxr-xr-x   25 nnn  nnn  850 Jul  1 01:34 ..
-rw-r--r--1 nnn  nnn 6148 Jul  1 03:02 .DS_Store
-rw-r--r--1 nnn  nnn  130 Jun 27 14:02 aaa.txt
drwxr-xr-x   55 nnn  nnn 1870 Jul  1 03:09 dir1
-rwxrwxrwx1 nnn  nnn  263 Jun 27 22:40 mytest.py
-rw-r--r--1 nnn  nnn0 Mar  4 16:15 scratch.txt
-rw-r--r--1 nnn  nnn  275 Apr 11 03:40 xmlFile.xml


Here is the output from my program:

--
$ python 1test.py

['.DS_Store', 'aaa.txt', 'dir1', 'mytest.py', 'scratch.txt',
'xmlFile.xml']
.DS_Store
.DS_Store ___file

aaa.txt
aaa.txt ___file

dir1

mytest.py

scratch.txt

xmlFile.xml

$
--

I expected the output:

---
DS_Store
.DS_Store ___file

aaa.txt
aaa.txt ___file

dir1
dir1 ___dir

mytest.py
mytest.py ___file

scratch.txt
scratch.txt ___file

xmlFile.xml
xmlFile.xml ___file


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


Re: howto resend args and kwargs to other func?

2007-07-01 Thread Duncan Booth
dmitrey <[EMAIL PROTECTED]> wrote:

> On Jul 1, 12:00 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> 
>> You 'need something like this', so write something like that.
>> Did you intend to ask a question?
> 
> I would gladly write the one, but the example doesn't work, and I
> don't know any easy way (moreover any way) to make it work correctly.
> D.
> 
The example doesn't work because it isn't a real example (what are 
some_cond or some_other_args?). An identical example which runs but doesn't 
give the output you expect would be more meaningful.

If you actually wrote a runnable example, and explained what about it you 
think doesn't work, then I could probably tell you how to fix it without 
having to engage my telepathy.

The only thing I can see wrong with your made-up example is that you may 
have intended a * before some_other_args, but since it isn't a real example 
it is probably just a typo rather than being your question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.isfile()

2007-07-01 Thread Duncan Booth
7stud <[EMAIL PROTECTED]> wrote:

> Here is a program to print out the files in a directory:
> 
> ---
> import os
> 
> myfiles = os.listdir("../")
> print myfiles
> 
> for afile in myfiles:
> print afile
> if os.path.isfile(afile):
> print afile, "___file"
> if os.path.isdir(afile):
> print afile, "___dir"
> print
> 
> 
> Here is what's in the directory:
> 
> --
> $ ls -al ../
> 
> total 2576
> drwxr-xr-x8 nnn  nnn  272 Jul  1 03:03 .
> drwxr-xr-x   25 nnn  nnn  850 Jul  1 01:34 ..
> -rw-r--r--1 nnn  nnn 6148 Jul  1 03:02 .DS_Store
> -rw-r--r--1 nnn  nnn  130 Jun 27 14:02 aaa.txt
> drwxr-xr-x   55 nnn  nnn 1870 Jul  1 03:09 dir1
> -rwxrwxrwx1 nnn  nnn  263 Jun 27 22:40 mytest.py
> -rw-r--r--1 nnn  nnn0 Mar  4 16:15 scratch.txt
> -rw-r--r--1 nnn  nnn  275 Apr 11 03:40 xmlFile.xml
> 

Yes, but what does 'ls -al .' show you? You didn't put any kind of path in 
your calls to isfile/isdir, so you are checking for the existence of 
files/directories called '.DS_Store' etc. in the *current* directory, not 
the one above. From your output I'd guess you have .DS_Store and aaa.txt 
files but the other names are not duplicated.

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


Re: howto resend args and kwargs to other func?

2007-07-01 Thread dmitrey
Thanks all, I have solved the problem.
D.

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


Re: os.path.isfile()

2007-07-01 Thread 7stud
On Jul 1, 3:36 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> 7stud <[EMAIL PROTECTED]> wrote:
> > Here is a program to print out the files in a directory:
>
> > ---
> > import os
>
> > myfiles = os.listdir("../")
> > print myfiles
>
> > for afile in myfiles:
> > print afile
> > if os.path.isfile(afile):
> > print afile, "___file"
> > if os.path.isdir(afile):
> > print afile, "___dir"
> > print
> > 
>
> > Here is what's in the directory:
>
> > --
> > $ ls -al ../
>
> > total 2576
> > drwxr-xr-x8 nnn  nnn  272 Jul  1 03:03 .
> > drwxr-xr-x   25 nnn  nnn  850 Jul  1 01:34 ..
> > -rw-r--r--1 nnn  nnn 6148 Jul  1 03:02 .DS_Store
> > -rw-r--r--1 nnn  nnn  130 Jun 27 14:02 aaa.txt
> > drwxr-xr-x   55 nnn  nnn 1870 Jul  1 03:09 dir1
> > -rwxrwxrwx1 nnn  nnn  263 Jun 27 22:40 mytest.py
> > -rw-r--r--1 nnn  nnn0 Mar  4 16:15 scratch.txt
> > -rw-r--r--1 nnn  nnn  275 Apr 11 03:40 xmlFile.xml
> > 
>
> Yes, but what does 'ls -al .' show you? You didn't put any kind of path in
> your calls to isfile/isdir, so you are checking for the existence of
> files/directories called '.DS_Store' etc. in the *current* directory, not
> the one above. From your output I'd guess you have .DS_Store and aaa.txt
> files but the other names are not duplicated.

Thanks.

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


Re: shelve crashing under Win ME

2007-07-01 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> OK, here's my workaround for shelve -- it's primitive and obviously
> much slower (it saves the entire dictionary each time), and you have
> to manually save -- BUT: it works...even on the Win ME machine. And
> it's possibly more universally portable in the long run than
> shelve...Also, once you open the dictionary, it is just as fast
> (perhaps faster?) than shelve for reading the contents (just not for
> saving...)

Notice that you don't need to use bsddb for shelve. Instead, you might
use dumbdbm instead, passing the dbm directly to shelve.Shelf. It's
probably slower than bsddb, however, updating a single key should be
faster than pickling an entire dictionary.

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


Re: howto resend args and kwargs to other func?

2007-07-01 Thread Adriano Varoli Piazza
dmitrey ha escrito:
> Thanks all, I have solved the problem.
> D.

If you take the time to comment this, it is good form to comment on
how you solved the problem, so the next one wondering about it can
find an answer before posting.

--
Saludos
Adriano

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


Re: unicode

2007-07-01 Thread Sander Steffann
Hi,

"Erik Max Francis" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 7stud wrote:
>
>> Based on this example and the error:
>>
>> -
>> u_str = u"abc\u"
>> print u_str
>>
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\u' in
>> position 3: ordinal not in range(128)
>> --
>>
>> it looks like when I try to display the string, the ascii decoder
>> parses each character in the string and fails when it can't convert a
>> numerical code that is higher than 127 to a character, i.e. the
>> character \u.
>
> If you try to print a Unicode string, then Python will attempt to first 
> encode it using the default encoding for that file.  Here, it's apparent 
> the default encoding is 'ascii', so it attempts to encode it into ASCII, 
> which it can't do, hence the exception.

If you want to change the default encoding of your stdout and stderr, you 
can do something like this:

import codecs, sys
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
sys.stderr = codecs.getwriter('utf-8')(sys.stderr)

After doing this, print u_str will work as expected (when using an utf-8 
terminal)

- Sander



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


Re: Reversing a string

2007-07-01 Thread Martin Durkin
Duncan Booth <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> Martin Durkin <[EMAIL PROTECTED]> wrote:
> 
>> def rev(x):
>>> mylist = []
>>> for char in x:
>>>  mylist.append(char)
>>> mylist.reverse()
>>> for letter in mylist:
>>>  print letter
>>> 
>>> However, compare the incredible difference in clarity and elegance
>>> between that and:
>>> 
 >>> print "\n".join("spam"[::-1])
>>> 
>> 
>> OK, maybe I'm missing the point here as I'm new to Python. The first
>> one seems clearer to me. What am I missing?
>> 
> I think all you are missing is familarity with Python, but I too don't
> like one-liners simply for their own sake.
> 

I guess that's it. The first one reads more like a textbook example which 
is about where I am at. Is there any speed benefit from the one liner?
thanks
Martin

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-01 Thread Diez B. Roggisch
> 
> """
> Because of the different flight path, a data conversion from a 64-bit 
> floating point to 16-bit signed integer value caused a hardware 
> exception (more specifically, an arithmetic overflow, as the floating 
> point number had a value too large to be represented by a 16-bit signed 
> integer).
> """
> 
> As far as I'm concerned, it surely qualifies as a runtime type error - 
> "data conversion from a floating point to a 16-bit signed int" should 
> not be allowed when unsafe, isn't it ?

I wouldn't say so. The conversion is a partial function. It _has_ to be 
a partial function, as you can't cram 64 bit into 16 without losses. If 
you could, infinite compression would be possible.

So - you _have_ to allow such a conversion. That has nothing to do with 
types, the types were proper. The values weren't.


> """
> Efficiency considerations had led to the disabling of the software 
> handler (in Ada code) for this error trap.
> """
> 
> Which implies that even in ADA, runtime type errors are in fact expected 
> - else there would be no handler for such a case.

Well, yes, runtime errors occur - in statically typed languages as well. 
That's essentially the halting-problem.


 > But what, how could an ADA module not be correct if it compiles - the
 > ADA type system is here to "prove the absence of certain bugs", isn't
 > it ?-)


Yes, certain bugs. Not those though. In the same sense as the python 
compiler pukes statically on me if I write

def f():
n = x * 2
x = n


The whole point of the Ariane failure was that nobody believed in the 
code because the type analyzer had woven it through - but because the 
specs and a mathematical analysis of the code had shown it was to be 
trusted. For the old rocket, that was.

The question is not if static typing that prevents certain errors is a 
bad thing. It's not. But it comes with a pricetag - the lack of 
flexibility. And usually, I'm not willing to pay that price, because it 
makes my whole design much more cumbersome and thus often error-prone - 
as line numbers increase.

But in a constrained environment like the ariane, where you have limited 
resources, you want as much certainity as you can get, together with 
operations that run on the native types of your processor in an 
efficient way.


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


Re: Reversing a string

2007-07-01 Thread Stefan Behnel
Martin Durkin wrote:
> Duncan Booth <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]: 
> 
>> Martin Durkin <[EMAIL PROTECTED]> wrote:
>>
>>> def rev(x):
 mylist = []
 for char in x:
  mylist.append(char)
 mylist.reverse()
 for letter in mylist:
  print letter

 However, compare the incredible difference in clarity and elegance
 between that and:

 print "\n".join("spam"[::-1])
>>> OK, maybe I'm missing the point here as I'm new to Python. The first
>>> one seems clearer to me. What am I missing?
>>>
>> I think all you are missing is familarity with Python, but I too don't
>> like one-liners simply for their own sake.
>>
> 
> I guess that's it. The first one reads more like a textbook example which 
> is about where I am at. Is there any speed benefit from the one liner?

Almost definitely. But you can check yourself by using the timeit module.

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


Re: Reading image dimensions before it is loaded from a web form using python.

2007-07-01 Thread Diez B. Roggisch
> 
> Without running some special client-side application, I think you'd
> have to do some trickery with the web server involving artificially
> stopping the upload after receiving enough bytes to constitute the
> image header, and then deciding whether or not to proceed with the
> upload at that point. I think that this is definitely nontrivial since
> it would most likely involve some hacking of Apache (or whatever web
> server you are using).


Certainly not. The upload is a simple HTTP POST request, and it's dealt 
by with your application. For example, you could put a simple CGI script 
behind a certain url, and once it has read a few bytes or KBytes from 
stdin, it will test for compliance.

Admittedly, most people use some webframework - which usually abstracts 
away the uploading and passes some  file-like object to you when the 
upload is finished.

But then it's an extension to that framework, and given the fact that 
most of these support out of the box file upload meters, or at least 
there are recipies how to do so, things should work pretty easy.

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


Re: Python + Google Calendar API issue

2007-07-01 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hi,
> 
> I was trying to hook into Google Calendar today using their gdata
> module for Python, but I can't seem to get Python to work with it.
> When I run the setup.py from the command line, I get the following:
> 
> Traceback (most recent call last):
>   File "J:\Python\Lib\site-packages\gdata\setup.py", line 39, in ?
> package_dir = {'gdata':'src/gdata', 'atom':'src/atom'}
>   File "J:\Python\lib\distutils\core.py", line 137, in setup
> raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" %
> msg
> SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2
> [cmd2_opts] ...]
>or: setup.py --help [cmd1 cmd2 ...]
>or: setup.py --help-commands
>or: setup.py cmd --help
> 
> error: no commands supplied
> 
> 
> I tried using some different commands, like --verbose, but it would
> just give me the same traceback. I also tried manually copying all the
> files into my site-packages directory (as you can see from the
> traceback) in hopes that it might work without running the setup.py
> file.
> 
> Does anyone have any ideas? I don't usually have any problem getting
> these things to work. I am using Python 2.4.3 on Windows XP Pro SP2.

Did you supply an install command:


python setup.py install

--verbose is no command.

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


Re: Python app as a Display Manager

2007-07-01 Thread Martin v. Löwis
> I feel at this stage that what I miss is: assuming I manage to get a
> python-based dialog box started automatically from init.rc (instead of xdm,
> gdm, ...): how do I start an X11 session with the user/pw information
> retrieved ... + set the correct *nix environment variables.

First, the user will enter username and password into your dialog box.
You need to verify this, either by using the pwd module, or by using PAM
(through python-pam).

Then you need start a session. Fork a subprocess, and use setuid/setgid
to take the identity of the subprocess. In the parent process, wait for
this child process to terminate, then display your dialog again (perhaps
restarting the X server in-between).

What you do in your session is your own choice. It is custom to set a
few environment variables, and then run /etc/X11/Xsession (or whereever
the standard X11 session script lives); the latter is done through exec,
i.e. when Xsession returns, the user has chosen to logout.

This is the basic working principle; different display managers deviate
in how precisely they setup the session, and what precisely they run in
what order.

However, this entire discussion is off-topic for comp.lang.python;
please ask on comp.windows.x instead.

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


how to send files via bluetooth with python to a mobile

2007-07-01 Thread Drex
Hi,

I have been looking on the internet for some info about sending files
from PC to a mobile phone (I have a nokia 6288) but I was not able to
find anything.

there is a lot of info how to transfer files from a symbian phone to a
pc, but nothing about sending them in the oposite direction.

would anybody point me to some resources on the topic?

thanks, regards
dz

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


eGenix Partner Network (Pre-Announcement)

2007-07-01 Thread M.-A. Lemburg
Hello,

we are currently looking into setting up a partner network of
companies interested and able to sell and support our products with a
more regional focus than we can deliver.

The idea is to provide customers with a closer and more direct contact
for first level support. Network partners should be able to do projects
using or based on eGenix products and maintain a proper customer
relationship in their native language.

If you are interested in joining the network, please contact us
or, even better, arrange a meeting at EuroPython or PyCon UK
with us to discuss the details.

We will be making an official announcement of the eGenix Partner
Network sometime after EuroPython:

http://www.egenix.com/company/partners/

Thanks,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 01 2007)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

2007-07-09: EuroPython 2007, Vilnius, Lithuania 7 days to go

 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Peter J. Holzer
On 2007-06-22 20:33, James Harris <[EMAIL PROTECTED]> wrote:
> I have a requirement to store timestamps in a database. Simple enough
> you might think but finding a suitably general format is not easy. The
> specifics are
>
> 1) subsecond resolution - milliseconds or, preferably, more detailed
> 2) not bounded by Unix timestamp 2038 limit
> 3) readable in Java
> 4) writable portably in Perl which seems to mean that 64-bit values
> are out
> 5) readable and writable in Python
> 6) storable in a free database - Postgresql/MySQL

Stick to unix timestamps but store them as a double precision floating
point number. The 53 bit mantissa gives you currently a resolution of
about 200 ns, slowly deteriorating (you will hit ms resolution in about
280,000 years, if I haven't miscalculated). Any language and database
should be able to handle double-precision FP numbers, so that's as
portable as it gets and conversion from/to system time should be
trivial.

If you need to represent milliseconds exactly, you can just multiply the
timestamp with 1000 (and get java timestamps).

hp



-- 
   _  | Peter J. Holzer| I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR   | with an emu on his shoulder.
| |   | [EMAIL PROTECTED] |
__/   | http://www.hjp.at/ |-- Sam in "Freefall"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python app as a Display Manager

2007-07-01 Thread hg
"Martin v. Löwis" wrote:

>> I feel at this stage that what I miss is: assuming I manage to get a
>> python-based dialog box started automatically from init.rc (instead of
>> xdm, gdm, ...): how do I start an X11 session with the user/pw
>> information retrieved ... + set the correct *nix environment variables.
> 
> First, the user will enter username and password into your dialog box.
> You need to verify this, either by using the pwd module, or by using PAM
> (through python-pam).
> 
> Then you need start a session. Fork a subprocess, and use setuid/setgid
> to take the identity of the subprocess. In the parent process, wait for
> this child process to terminate, then display your dialog again (perhaps
> restarting the X server in-between).
> 
> What you do in your session is your own choice. It is custom to set a
> few environment variables, and then run /etc/X11/Xsession (or whereever
> the standard X11 session script lives); the latter is done through exec,
> i.e. when Xsession returns, the user has chosen to logout.
> 
> This is the basic working principle; different display managers deviate
> in how precisely they setup the session, and what precisely they run in
> what order.
> 
> However, this entire discussion is off-topic for comp.lang.python;
> please ask on comp.windows.x instead.
> 
> HTH,
> Martin

Martin,

Many many thanks, I did post here also so someone would tell me whether
using Python was feasible or not for this project (ex, having tkinter or
wxPython running prior t oan actual X11 session). Also I did not know about
comp.windows.x.

Regards,

hg


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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Roedy Green
On 25 Jun 2007 18:46:25 -0700, Paul Rubin
 wrote, quoted or indirectly quoted
someone who said :

>You cannot accurately compute
>the number of seconds between Nixon's resignation and 1800 UTC today,
>unless you take into account the leap seconds have been occurred
>between then and now.

There are two valid answers to those questions.  In a court of law,
say did some document arrive before  deadline, you must use civil
time.  Arguing leap seconds would not fly.

On the other hand, if you used civil seconds to computer satellite
orbits, tiny errors mount up quickly in the calculation.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object references/memory access

2007-07-01 Thread Martin v. Löwis
> I have searched a good deal about this topic and have not found
> any good information yet. It seems that the people asking all want
> something a bit different than what I want and also don't divulge much
> about their intentions. I wish to improve the rate of data transfer
> between two python programs on the same machine.

I don't understand why you want exactly this. Wouldn't it be
sufficient/better if the response time for a request as seen
by the client web browser would improve? Why is it necessary
to start optimizing at the data transfer rate?

As a starting point, I would try to eliminate the CGI part. There
are two ways to do that:
a) run the Python code inside the Apache process, and
b) use a single Python server (possibly shared with the database
   process), and connect this to Apache through the
   reverse proxy protocol.

The cost you observe might be in the repeated creation of
new processes, and the repeated establishment of new TCP
connections. Either solution would drop some of that overhead.

> I am fairly ignorant of how Apache works with the
> CGI module but here is what I'd like to do. I want to somehow let the
> server print out to the user's browser instead of the search script in
> order to cut out the time of sending the results over the socket.

That is not possible. The CGI script does not "print out to the
user's browser". Instead, it prints to its stdout, which is a pipe
being read by Apache; Apache then copies all data to the socket
going to the user's browser (possibly after manipulating the
headers also).

> Mainly, I'd like
> to know if there is any kind of descriptor or ID that can be passed
> and used by another process to print output to the user's browser
> instead of the script that Apache invoked.

No. The CGI script has a file handle, and it is not possible to pass
a file handle to a different process.

> If there is not a good Pythonic way to do the above, I am open to
> mixing in some C to do the job if that is what it takes.

No, it's not Python that fails to support that - it's the operating
system. See above for solutions that avoid one such copying in
the first place.

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


Re: object references/memory access

2007-07-01 Thread Martin v. Löwis
> b) use a single Python server (possibly shared with the database
>process), and connect this to Apache through the
>reverse proxy protocol.

Following up to myself: Instead of using a reverse proxy, you can
also implement the FastCGI protocol in the server.

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Paul Rubin
Roedy Green <[EMAIL PROTECTED]> writes:
> >You cannot accurately compute
> >the number of seconds between Nixon's resignation and 1800 UTC today,
> >unless you take into account the leap seconds have been occurred
> >between then and now.
> 
> There are two valid answers to those questions.  In a court of law,
> say did some document arrive before  deadline, you must use civil
> time.  Arguing leap seconds would not fly.

I'd say if the deadline is "the document must arrive before noon
on August 9, 2009", that is civil time, including any leap seconds.
We don't know the exact number of seconds until then because
there might be some leap seconds that haven't yet been announced.

On the other hand if the deadline is "the document must arrive
no more than 1 billion seconds after noon on January 20, 2001"
that is an exact number of seconds.  We don't yet know the exact
civil time because we don't know about the leap seconds to come.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Roedy Green
On Tue, 26 Jun 2007 13:04:50 +0100, Martin Gregorie
<[EMAIL PROTECTED]> wrote, quoted or indirectly quoted
someone who said :

>TAI? Care to provide a reference?

see http://mindprod.com/jgloss/tai.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object references/memory access

2007-07-01 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> No. The CGI script has a file handle, and it is not possible to pass
> a file handle to a different process.
> 
> > If there is not a good Pythonic way to do the above, I am open to
> > mixing in some C to do the job if that is what it takes.
> 
> No, it's not Python that fails to support that - it's the operating
> system. See above for solutions that avoid one such copying in
> the first place.

If this is a Linux server, it might be possible to use the SCM_RIGHTS
message to pass the socket between processes.  That would require a
patch to Python's socket library which I've never gotten around to
writing but it's been on my want-to-do list for a long time.  There is
something similar for Solaris and probably for *BSD.  I've been under
the impression that this is how preforked Apache distributes requests
between processes, but I never got around to checking.

http://sourceforge.net/tracker/index.php?func=detail&aid=814689&group_id=5470&atid=355470
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Thomas Jollans
On Sunday 01 July 2007, Roedy Green wrote:
> On 25 Jun 2007 18:46:25 -0700, Paul Rubin
>  wrote, quoted or indirectly quoted
>
> someone who said :
> >You cannot accurately compute
> >the number of seconds between Nixon's resignation and 1800 UTC today,
> >unless you take into account the leap seconds have been occurred
> >between then and now.
>
> There are two valid answers to those questions.  In a court of law,
> say did some document arrive before  deadline, you must use civil
> time.  Arguing leap seconds would not fly.
>
> On the other hand, if you used civil seconds to computer satellite
> orbits, tiny errors mount up quickly in the calculation.

"civil" time/seconds ? I dare say that if they exist, they are variably 
defined.

I know for a fact that here in Germany, official time is based on UTC, NOT UT 
(was GMT) or some other approximation of local time. Ergo, you *can* argue 
leap seconds in a court of law as they *are* "civil time".

In fact Wikipedia [1] makes it sound like UTC is used in the US, and as leap 
seconds are part of UTC, you could probably argue with them in a US court as 
well

Also, UTC and UT/GMT are always less than a second apart, so who cares...

[1] http://en.wikipedia.org/wiki/Eastern_Time_Zone etc.

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Roedy Green
On 25 Jun 2007 18:46:25 -0700, Paul Rubin
 wrote, quoted or indirectly quoted
someone who said :

>TAI really does seem like the most absolute--if you are a user in
>orbit or on Mars, then UTC timestamps will seem pretty meaningless and
>artificial.

According to Einstein all time is local time, so perhaps our wish for
a clean UT is a pipedream.

To add to the confusion you have GPS, Loran and Julian day also used
as scientific times.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object references/memory access

2007-07-01 Thread Martin v. Löwis
> If this is a Linux server, it might be possible to use the SCM_RIGHTS
> message to pass the socket between processes.

I very much doubt that the OP's problem is what he thinks it is,
i.e. that copying over a local TCP connection is what makes his
application slow.

> That would require a
> patch to Python's socket library which I've never gotten around to
> writing but it's been on my want-to-do list for a long time.  There is
> something similar for Solaris and probably for *BSD.  I've been under
> the impression that this is how preforked Apache distributes requests
> between processes, but I never got around to checking.

No, it doesn't. Instead, it is the operating system itself which
distributes the requests: the parent process opens the server socket,
then forks the actual server processes. They all do accept, and
the operating system selects an arbitrary one for the next request.
That process returns from accept, so for the next incoming
connection, one of the remaining processes will be selected.

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


Re: how to send files via bluetooth with python to a mobile

2007-07-01 Thread vedrandekovic

Drex je napisao/la:
> Hi,
>
> I have been looking on the internet for some info about sending files
> from PC to a mobile phone (I have a nokia 6288) but I was not able to
> find anything.
>
> there is a lot of info how to transfer files from a symbian phone to a
> pc, but nothing about sending them in the oposite direction.
>
> would anybody point me to some resources on the topic?
>
> thanks, regards
> dz

Hi,

I'm not sure but try this:   (  py_s60 )

http://sourceforge.net/projects/pyed/

regards,

vedran

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


Re: using urllib, urllib2 , mechanize to access password protected site

2007-07-01 Thread John J. Lee
comeshopcheap <[EMAIL PROTECTED]> writes:

> Hi
>
> I am using this script to access doba.com (I need to download some
> files) but I keep on being sent back to the login page not the user
> home page. Any help. I think I may need to use a post method and
> opener is using a get method
>
> Thanks
>
> import mechanize
> cookies = mechanize.CookieJar()
> # build_opener() adds standard handlers (such as HTTPHandler and
> # HTTPCookieProcessor) by default.  The cookie processor we supply
> # will replace the default one.
> opener =
> mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
> opener.addheaders = [("User-agent", "Mozilla/5.0 (Windows; U; Windows
> NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"), ]
> data="username=user&password=pw"
> #r = opener.open("http://comeshopcheap.com/";)  # GET
> r = opener.open("https://www.doba.com/members/login.php";, data)  # POST

You shouldn't need to worry re POST and GET.

Visiting the login page is presumably not enough in itself to log you
in.  So, what are you doing to ensure you're logged in?

Probably you want to fill in and submit the login form on the login
page.  Alternatively, use e.g. mechanize.MozillaCookieJar and load
cookies from your web browser (this option requires that you are
already logged in persistently, though, so I'd suggest filling in the
login form as the safe option).


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


Re: how to send files via bluetooth with python to a mobile

2007-07-01 Thread vedrandekovic

[EMAIL PROTECTED] je napisao/la:
> Drex je napisao/la:
> > Hi,
> >
> > I have been looking on the internet for some info about sending files
> > from PC to a mobile phone (I have a nokia 6288) but I was not able to
> > find anything.
> >
> > there is a lot of info how to transfer files from a symbian phone to a
> > pc, but nothing about sending them in the oposite direction.
> >
> > would anybody point me to some resources on the topic?
> >
> > thanks, regards
> > dz
>
> Hi,
>
> I'm not sure but try this:   (  py_s60 )
>
> http://sourceforge.net/projects/pyed/
>
> regards,
>
> vedran

Hi again,

and also try this:

http://sourceforge.net/projects/pys60

regards,

vedran

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


hi every one please become a member to this site and win much more money!!!!

2007-07-01 Thread kasim
http://www.agloco.com/r/BBFR2592

http://www.agloco.com/r/BBFR2592


http://www.agloco.com/r/BBFR2592


Dear __,

I recently joined AGLOCO because of a friend recommended it to me. I
am now promoting it to you because I like the idea and I want you to
share in what I think will be an exciting new Internet concept.

AGLOCO's story is simple:

Do you realize how valuable you are? Advertisers, search providers and
online retailers are paying billions to reach you while you surf.  How
much of that money are you making? NONE!

AGLOCO thinks you deserve a piece of the action.

AGLOCO collects money from those companies on behalf of its members.
(For example, Google currently pays AOL 10 cents for every Google
search by an AOL user. And Google still has enough profit to pay $1.6
billion dollars for YouTube, an 18-month old site full of content that
YouTube's users did not get paid for!

AGLOCO will work to get its Members their share of this and more.

AGLOCO is building a new form of online community that they call an
Economic Network. They are not only paying Members their fair share,
but they're building a community that will generate the kind of
fortune that YouTube made. But instead of that wealth making only a
few people rich, the entire community will get its share.

What's the catch? No catch - no spyware, no pop-ups and no spam -
membership and software are free and AGLOCO is 100% member owned.
Privacy is a core value and AGLOCO never sells or rents member
information.

So do both of us a favor: Sign up for AGLOCO right now! If you use
this link to sign up, I automatically get credit for referring you and
helping to build AGLOCO. http://www.agloco.com/r/BBFR2592
Please  follow this link and create own membership by this link

Thanks

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


Re: Reversing a string

2007-07-01 Thread Evan Klitzke
On 1 Jul 2007 11:09:40 GMT, Martin Durkin <[EMAIL PROTECTED]> wrote:
> Duncan Booth <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]:
>
> > Martin Durkin <[EMAIL PROTECTED]> wrote:
> >
> >> def rev(x):
> >>> mylist = []
> >>> for char in x:
> >>>  mylist.append(char)
> >>> mylist.reverse()
> >>> for letter in mylist:
> >>>  print letter
> >>>
> >>> However, compare the incredible difference in clarity and elegance
> >>> between that and:
> >>>
>  >>> print "\n".join("spam"[::-1])
> >>>
> >>
> >> OK, maybe I'm missing the point here as I'm new to Python. The first
> >> one seems clearer to me. What am I missing?
> >>
> > I think all you are missing is familarity with Python, but I too don't
> > like one-liners simply for their own sake.
> >
>
> I guess that's it. The first one reads more like a textbook example which
> is about where I am at. Is there any speed benefit from the one liner?

The one line is quite a bit faster:

[EMAIL PROTECTED] ~ $ python -m timeit 's = "onomatopoeia"; s = s.join(s[::-1])'
10 loops, best of 3: 6.24 usec per loop

[EMAIL PROTECTED] ~ $ python -m timeit '
> def rev(x):
> mylist = []
> for char in x:
> mylist.append(char)
> mylist.reverse()
> return "".join(mylist)
>
> s = "onomatopoeia"
> s = rev(s)'
10 loops, best of 3: 9.73 usec per loop

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object references/memory access

2007-07-01 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> > If this is a Linux server, it might be possible to use the SCM_RIGHTS
> > message to pass the socket between processes.
> 
> I very much doubt that the OP's problem is what he thinks it is,
> i.e. that copying over a local TCP connection is what makes his
> application slow.

Right, the copying should be very fast, but serializing and
deserializing the stuff being copied can be slow.  This is an issue
with something I'm currently working on, for example.

> [Apache] Instead, it is the operating system itself which
> distributes the requests: the parent process opens the server socket, ...

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Martin Gregorie
Roedy Green wrote:
> 
> To add to the confusion you have GPS, Loran and Julian day also used
> as scientific times.
 >
GPS time is UTC time and I'd assume the same is true for Loran. Both are 
primarily for navigation and so are on Zulu time, which is another name 
for UTC. Zulu is the international radio word for the letter Z.

I've never seen Julian time used outside the world of IBM mainframes. 
I'd be interested to know who else uses it.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org   |
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Martin Gregorie
Roedy Green wrote:
> On Tue, 26 Jun 2007 13:04:50 +0100, Martin Gregorie
> <[EMAIL PROTECTED]> wrote, quoted or indirectly quoted
> someone who said :
> 
>> TAI? Care to provide a reference?
> 
> see http://mindprod.com/jgloss/tai.html
 >
Thanks.

Your list of NTP servers on http://mindprod.com/jgloss/timesources.html 
may be a bit out of date: I notice that it doesn't include the European 
or Oceania time server pools (0.europe.pool.ntp.org, 
0.oceania.pool.ntp.org). It may be best to just hold a link to the NTP 
project servers page, http://support.ntp.org/bin/view/Servers/WebHome


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org   |
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-07-01 Thread Mark Dufour
hi felix,

On 6/29/07, felix seltzer <[EMAIL PROTECTED]> wrote:
> does this project include support for pygtk type GUI's?

No, it won't work for arbitrary python programs. Shed Skin is
currently limited to smallish programs (up to a few hundred lines),
that only use a few basic modules (random, math, string, and a few
others) and are written in the static subset of Python that Shed Skin
supports.

A serious pygtk program would probably be too large and too dynamic to
compile directly.  Instead, you'd typically move some speed-critical
functionality to a separate module, and compile this into an extension
module or separate program.

Look at Shed Skin as something that allows you to write fast extension
modules in pure Python, not as something that can convert arbitrary
Python programs.


Thanks,
Mark Dufour.
-- 
"One of my most productive days was throwing away 1000 lines of code"
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-01 Thread Lenard Lindstrom
Douglas Alan wrote:
> Lenard Lindstrom <[EMAIL PROTECTED]> writes:
> 
>> Explicitly clear the exception? With sys.exc_clear?
> 
> Yes.  Is there a problem with that?
> 

As long as nothing tries to re-raise the exception I doubt it breaks 
anything:

 >>> import sys
 >>> try:
raise StandardError("Hello")
except StandardError:
sys.exc_clear()
raise


Traceback (most recent call last):
   File "", line 5, in 
 raise
TypeError: exceptions must be classes, instances, or strings 
(deprecated), not NoneType


But it is like calling the garbage collector. You are tuning the program 
to ensure some resource isn't exhausted. It relies on implementation 
specific behavior to be provably reliable*. If this is indeed the most 
obvious way to do things in your particular use case then Python, and 
many other languages, is missing something. If the particular problem is 
isolated, formalized, and general solution found, then a PEP can be 
submitted. If accepted, this would ensure future and cross-platform 
compatibility.


* reference counting is an integral part of the CPython C api so cannot 
be changed without breaking a lot of extension modules. It will remain 
as long as CPython is implemented in C.


---
Lenard Lindstrom
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to send files via bluetooth with python to a mobile

2007-07-01 Thread Drex
Hey,

> > I'm not sure but try this:   (  py_s60 )
>
> >http://sourceforge.net/projects/pyed/

> and also try this:
>
> http://sourceforge.net/projects/pys60

thanks, but I am affraid this is not what I was looking for. I need to
have some library on my pc (linux) that would allow me to transfer a
file to a bluetooth mobile phone (the mine doesn't have symbian). I
have some programs that allow to do that like for ex. obex_client but
I would like to write something similar using python.

thanks!
regards
dz


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


Re: Reversing a string

2007-07-01 Thread Jay Loden

Evan Klitzke wrote:
>
>> I guess that's it. The first one reads more like a textbook example which
>> is about where I am at. Is there any speed benefit from the one liner?
> 
> The one line is quite a bit faster:
> 
> [EMAIL PROTECTED] ~ $ python -m timeit 's = "onomatopoeia"; s = 
> s.join(s[::-1])'
> 10 loops, best of 3: 6.24 usec per loop
> 
> [EMAIL PROTECTED] ~ $ python -m timeit '
>> def rev(x):
>> mylist = []
>> for char in x:
>> mylist.append(char)
>> mylist.reverse()
>> return "".join(mylist)
>>
>> s = "onomatopoeia"
>> s = rev(s)'
> 10 loops, best of 3: 9.73 usec per loop


For what it's worth, with python 2.5 on my Macbook:

[EMAIL PROTECTED] jloden]$ python -m timeit 's = "onomatopoeia"; s = 
s.join(s[::-1])'
10 loops, best of 3: 5.2 usec per loop

[EMAIL PROTECTED] jloden]$ python -m timeit ' 
> def rev(x):
>   mylist = list(x)
>   mylist.reverse()
>   return "".join(mylist)
> 
> s = "onomatopoeia"
> s = rev(s)'
10 loops, best of 3: 3.94 usec per loop 

Note that in the second version, I changed the code a little bit so that it no 
longer iterates over every char in the string and instead just calls lis() to 
convert it to a list of chars in order to call list.reverse() on it. 

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


Re: Python + Google Calendar API issue

2007-07-01 Thread kyosohma
On Jul 1, 7:15 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
>
>
> > Hi,
>
> > I was trying to hook into Google Calendar today using their gdata
> > module for Python, but I can't seem to get Python to work with it.
> > When I run the setup.py from the command line, I get the following:
>
> > Traceback (most recent call last):
> >   File "J:\Python\Lib\site-packages\gdata\setup.py", line 39, in ?
> > package_dir = {'gdata':'src/gdata', 'atom':'src/atom'}
> >   File "J:\Python\lib\distutils\core.py", line 137, in setup
> > raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" %
> > msg
> > SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2
> > [cmd2_opts] ...]
> >or: setup.py --help [cmd1 cmd2 ...]
> >or: setup.py --help-commands
> >or: setup.py cmd --help
>
> > error: no commands supplied
>
> > I tried using some different commands, like --verbose, but it would
> > just give me the same traceback. I also tried manually copying all the
> > files into my site-packages directory (as you can see from the
> > traceback) in hopes that it might work without running the setup.py
> > file.
>
> > Does anyone have any ideas? I don't usually have any problem getting
> > these things to work. I am using Python 2.4.3 on Windows XP Pro SP2.
>
> Did you supply an install command:
>
> python setup.py install
>
> --verbose is no command.
>
> Diez

Oops. When I typed  it gave me lots of info, but I guess I mis-
read it. Turns out you were quite right and that all I needed was the
"install" command.

Thanks a lot!

Mike

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


Re: How to uninstall packages

2007-07-01 Thread Thomas Jollans
On Sunday 01 July 2007, Rustom Mody wrote:

> I first installed the debian package python-pysqlite1.1 using
> synaptic. Since this seemed too old for other packages (sqlalchemy) I
> downloaded the sources  pysqlite-2.3.4.tar.gz and ran setup install.

I wonder why you chose not to use python-pysqlite2...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing a string

2007-07-01 Thread Alex Martelli
Martin Durkin <[EMAIL PROTECTED]> wrote:
   ...
> >> def rev(x):
> >>> mylist = []
> >>> for char in x:
> >>>  mylist.append(char)
> >>> mylist.reverse()
> >>> for letter in mylist:
> >>>  print letter
> >>> 
> >>> However, compare the incredible difference in clarity and elegance
> >>> between that and:
> >>> 
>  >>> print "\n".join("spam"[::-1])
   ...
> >> OK, maybe I'm missing the point here as I'm new to Python. The first
> >> one seems clearer to me. What am I missing?
> >> 
> > I think all you are missing is familarity with Python, but I too don't
> > like one-liners simply for their own sake.
> 
> I guess that's it. The first one reads more like a textbook example which
> is about where I am at. Is there any speed benefit from the one liner?

The first example reads "excruciatingly low-level" to me: its autor is
thinking in terms of what the machine is doing, mapped into pretty
elementary low-level constructs.

The second example depends first of all on knowledge of extended-slicing
(specifically the fact that x[::-1] is a reversal, because of the
negative -1 "step" aka "stride").  If you don't know about extended
slicing, you're unlikely to just "get it from context", because it uses
a syntax based on punctuation rather than readable words whose meaning
you might guess at.  Python has a modest amount of such "punctuation
syntax" -- about the same amount as C but definitely more than Cobol
(where one would typically write "ADD a TO b" to avoid shocking totally
clueless readers with "mysterious punctuation" such as "a + b"...!!!-).
Punctuation is often very concise but not "intrinsically obvious" unless
you've been exposed to it already;-).

If I was targeting total newbies, since extended slicing is something
that they can well wait a while to learn, I'd probably compromise in
favor of "reversed(x)".  The "reversed" built-in function does basically
the same job as a [::-1] slicing, but any English speaker can probably
guess what it's doing -- presenting a reversed permutation of its
sequence argument.

So, something like:

for c in reversed(x): print c

is mostly likely how I'd present the solution to the task.  Using join
to make a single string is (in this particular case) needlessly
precious, though not really a big deal (and beginners had better learn
about joining pretty early on).  But that definitely does not justify
the excruciating, "micromanaged" nature of the first example, which
uselessly belabors the concept of "reversing" to a silly extent.

Python LETS you program at such lowish levels, if you insist, but it
encourages thinking more about your problem and less about the way the
inner gears of the machine will turn in order to produce a solution for
it...!  Part of the encouragement is indeed that coding at a higher
level of abstraction tends to make your program faster (an "abstraction
reward" to replace the "abstraction penalty" so common with some other
languages:-) -- but clarity and productivity are more important still.


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


Re: how to send files via bluetooth with python to a mobile

2007-07-01 Thread Diez B. Roggisch
Drex schrieb:
> Hey,
> 
>>> I'm not sure but try this:   (  py_s60 )
>>> http://sourceforge.net/projects/pyed/
> 
>> and also try this:
>>
>> http://sourceforge.net/projects/pys60
> 
> thanks, but I am affraid this is not what I was looking for. I need to
> have some library on my pc (linux) that would allow me to transfer a
> file to a bluetooth mobile phone (the mine doesn't have symbian). I
> have some programs that allow to do that like for ex. obex_client but
> I would like to write something similar using python.


Wrap this

http://www.zuckschwerdt.org/apidocs/

using ctypes.

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


How does py2exe work?

2007-07-01 Thread vasudevram
Hi,

I recently checked out py2exe (on Windows). Looks good.
Was able to build an EXE out of one of my Python apps.

Wondering how it works? Does it actually compile the Python source of
your script into machine language, or does it do something more like
bundling the Python interpreter, the Python libraries and the script
itself, into a file?

Will look at the source code but would like to get some ideas ...

Thanks ...

Vasudev Ram
Dancing Bison Enterprises
Biz site: http://www.dancingbison.com
Blog on software innovation: http://jugad.livejournal.com
xtopdf: PDF creation/construction toolkit:
  http://www.dancingbison.com/products.html

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Paul Rubin
Martin Gregorie <[EMAIL PROTECTED]> writes:
> GPS time is UTC time 

According to Wikipedia, 

While most clocks are synchronized to Coordinated Universal Time
(UTC), the Atomic clocks on the satellites are set to GPS time. The
difference is that GPS time is not corrected to match the rotation of
the Earth, so it does not contain leap seconds or other corrections
which are periodically added to UTC. GPS time was set to match
Coordinated Universal Time (UTC) in 1980, but has since diverged. The
lack of corrections means that GPS time remains at a constant offset
(19 seconds) with International Atomic Time (TAI).

http://en.wikipedia.org/wiki/GPS#Ephemeris_and_clock_errors
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Roedy Green
On Sun, 01 Jul 2007 17:47:36 +0100, Martin Gregorie
<[EMAIL PROTECTED]> wrote, quoted or indirectly quoted
someone who said :

>GPS time is UTC time and I'd assume the same is true for Loran.

not according to this site that has clocks running on all three.
They are out slightly.


http://www.leapsecond.com/java/gpsclock.htm
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
-- 
http://mail.python.org/mailman/listinfo/python-list


The best platform and editor for Python

2007-07-01 Thread kimiraikkonen
Hi,
For experienced with Pyhton users, which developing software and
enviroment would you suggest for Pyhton programming? Compiler+Editor
+Debugger.

Also what are your suggestions for beginners of Pyhton programming?


Thank you.

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread CBFalconer
Roedy Green wrote:
> On 25 Jun 2007 18:46:25 -0700, Paul Rubin
>
... snip ...
> 
>> TAI really does seem like the most absolute--if you are a user
>> in orbit or on Mars, then UTC timestamps will seem pretty
>> meaningless and artificial.
> 
> According to Einstein all time is local time, so perhaps our wish
> for a clean UT is a pipedream.
> 
> To add to the confusion you have GPS, Loran and Julian day also
> used as scientific times.

In summary, time is now defined as a non-continuous function, and
is thus proof against manipulation by most standard algebraic
techniques.  Take that :-)  In fact, it is not even quanticized.

-- 
 
 
 
cbfalconer at maineline dot net



-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: how to send files via bluetooth with python to a mobile

2007-07-01 Thread Drex
Hello,

>
> Wrap this
>
> http://www.zuckschwerdt.org/apidocs/
>
> using ctypes.

thanks, no idea on how to do it (yet hopefully), but I will try ;)

regards
dz

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


Re: The best platform and editor for Python

2007-07-01 Thread Sönmez Kartal
Hello,

Emacs is the best for anything for me. Some people prefers Eclipse
with PyDev extension.

Build some real world applications with Python. Pick what do you need
from SourceForge or similar one then write it. If it is something you
need then you probably will make it more special then you found and
this will take you to the more coding and more...

By the way, thanks for winning Magny Cours grand prix Kimi... :-P

On 7/1/07, kimiraikkonen <[EMAIL PROTECTED]> wrote:
> Hi,
> For experienced with Pyhton users, which developing software and
> enviroment would you suggest for Pyhton programming? Compiler+Editor
> +Debugger.
>
> Also what are your suggestions for beginners of Pyhton programming?
>
>
> Thank you.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The best platform and editor for Python

2007-07-01 Thread kimiraikkonen
On Jul 1, 10:30 pm, "Sönmez Kartal" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Emacs is the best for anything for me. Some people prefers Eclipse
> with PyDev extension.
>
> Build some real world applications with Python. Pick what do you need
> from SourceForge or similar one then write it. If it is something you
> need then you probably will make it more special then you found and
> this will take you to the more coding and more...
>
> By the way, thanks for winning Magny Cours grand prix Kimi... :-P
>
> On 7/1/07, kimiraikkonen <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
> > For experienced with Pyhton users, which developing software and
> > enviroment would you suggest for Pyhton programming? Compiler+Editor
> > +Debugger.
>
> > Also what are your suggestions for beginners of Pyhton programming?
>
> > Thank you.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text -
>
> - Show quoted text -

Sa ol say n Kartal :-)

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

Re: How does py2exe work?

2007-07-01 Thread Thomas Jollans
On Sunday 01 July 2007, vasudevram wrote:
> Wondering how it works? Does it actually compile the Python source of
> your script into machine language, or does it do something more like
> bundling the Python interpreter, the Python libraries and the script
> itself, into a file?

essentially, that's what it does.

-- 
  Regards,   Thomas Jollans
GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu
Hacker key :
v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The best platform and editor for Python

2007-07-01 Thread kimiraikkonen
On Jul 1, 10:30 pm, "Sönmez Kartal" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Emacs is the best for anything for me. Some people prefers Eclipse
> with PyDev extension.
>
> Build some real world applications with Python. Pick what do you need
> from SourceForge or similar one then write it. If it is something you
> need then you probably will make it more special then you found and
> this will take you to the more coding and more...
>
> By the way, thanks for winning Magny Cours grand prix Kimi... :-P
>
> On 7/1/07, kimiraikkonen <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
> > For experienced with Pyhton users, which developing software and
> > enviroment would you suggest for Pyhton programming? Compiler+Editor
> > +Debugger.
>
> > Also what are your suggestions for beginners of Pyhton programming?
>
> > Thank you.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text -
>
> - Show quoted text -

Thank you for the suggestions. Tesekkurler Say n Kartal :-)

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

Re: The best platform and editor for Python

2007-07-01 Thread kimiraikkonen
On Jul 1, 10:30 pm, "Sönmez Kartal" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Emacs is the best for anything for me. Some people prefers Eclipse
> with PyDev extension.
>
> Build some real world applications with Python. Pick what do you need
> from SourceForge or similar one then write it. If it is something you
> need then you probably will make it more special then you found and
> this will take you to the more coding and more...
>
> By the way, thanks for winning Magny Cours grand prix Kimi... :-P
>
> On 7/1/07, kimiraikkonen <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
> > For experienced with Pyhton users, which developing software and
> > enviroment would you suggest for Pyhton programming? Compiler+Editor
> > +Debugger.
>
> > Also what are your suggestions for beginners of Pyhton programming?
>
> > Thank you.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text -
>
> - Show quoted text -

Thank you for the suggestions. I'd prefer a GUI-based, helpful and
easy-implemention skilled enviroment. Tesekkurler Sayin Kartal :-)

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

Re: object references/memory access

2007-07-01 Thread dlomsak
Thanks for the responses folks. I'm starting to think that there is
merely an inefficiency in how I'm using the sockets. The expensive
part of the program is definitely the socket transfer because I timed
each part of the routine individually. For a small return, the whole
search and return takes a fraction of a second. For a large return (in
this case 21,000 records - 8.3 MB) is taking 18 seconds. 15 of those
seconds are spent sending the serialized results from the server to
the client. I did a little bit of a blind experiment and doubled the
bytes on the client's socket.recv line. This improved the rate of
transfer each time. The original rate when I was accepting 1024 bytes
per recv took 47 seconds to send the 8.3 MB result. By doubling this
size several times, I reduced the time to 18 seconds until doubling it
further produced diminishing results. I was always under the
impression that keeping the send and recv byte sizes around 1024 is a
good idea and I'm sure that jacking those rates up is a lousy way to
mitigate the transfer. It is also interesting to note that increasing
the bytes sent per socket.send on the server side had no visible
effect. Again, that was just a curious experiment.

What bothers me is that I am sure sending data over the local loopback
address should be blazing fast. 8.3 MB should be a breeze because I've
transferred files over AIM to people connected to the same router as
me and was able to send hundreds of megabytes in less than a two or
three seconds. With that said, I feel like something about how I'm
send/recv-ing the data is causing lots of overhead and that I can
avoid reading the memory directly if I can speed that up.

I guess now I'd like to know what are good practices in general to get
better results with sockets on the same local machine. I'm only
instantiating two sockets total right now - one client and one server,
and the transfer is taking 15 seconds for only 8.3MB. If you guys have
some good suggestions on how to better utilize sockets to transfer
data at the speeds I know I should be able to achieve on a local
machine, let me know what you do. At present, I find that using
sockets in python requires very few steps so I'm not sure where I
could really improve at this point.

Thanks for the replies so far, I really appreciate you guys
considering my situation and helping out.

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


Re: How does py2exe work?

2007-07-01 Thread Wildemar Wildenburger
Thomas Jollans wrote:
> On Sunday 01 July 2007, vasudevram wrote:
>   
>> Wondering how it works? Does it actually compile the Python source of
>> your script into machine language, or does it do something more like
>> bundling the Python interpreter, the Python libraries and the script
>> itself, into a file?
>> 
>
> essentially, that's what it does.
>
>   
Q: A or B?
A: Yes.

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


Re: unicode

2007-07-01 Thread 7stud

Erik Max Francis wrote:
> 7stud wrote:
>
> > Based on this example and the error:
> >
> > -
> > u_str = u"abc\u"
> > print u_str
> >
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u' in
> > position 3: ordinal not in range(128)
> > --
> >
> > it looks like when I try to display the string, the ascii decoder
> > parses each character in the string and fails when it can't convert a
> > numerical code that is higher than 127 to a character, i.e. the
> > character \u.
>
> If you try to print a Unicode string, then Python will attempt to first
> encode it using the default encoding for that file.  Here, it's apparent
> the default encoding is 'ascii', so it attempts to encode it into ASCII,
> which it can't do, hence the exception.  The error is no different from
> this:
>
>  >>> u_str = u'abc\u'
>  >>> u_str.encode('ascii')
> Traceback (most recent call last):
>File "", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u' in
> position 3: ordinal not in range(128)
>
> > In the following example, I use encode() to convert a unicode string
> > to a regular string:
> >
> > -
> > u_str = u"abc\u"
> > reg_str = u_str.encode("utf-8")
> > print repr(reg_str)
> > -
> >
> > and the output is:
> >
> > 'abc\xe9\xa6\x99'
> >
> > 1) Why aren't the characters 'a', 'b', and 'c' in hex notation?  It
> > looks like python must be using the ascii decoder to parse the
> > characters in the string again--with the result being python converts
> > only the 1 byte numerical codes to characters. 2) Why didn't that
> > cause an error like above for the 3 byte character?
>
> Since you've already encoded the Unicode object as a normal string,
> Python isn't trying to do any implicit encoding.  As for why 'abc'
> appears in plain text, that's just the way repr works:
>
>  >>> s = 'a'
>  >>> print repr(s)
> 'a'
>  >>> t = '\x99'
>  >>> print repr(t)
> '\x99'
>
> repr is attempting to show the string in the most readable fashion.  If
> the character is printable, then it just shows it as itself.  If it's
> unprintable, then it shows it in hex string escape notation.
>
> > Then if I try this:
> >
> > ---
> > u_str = u"abc\u"
> > reg_str = u_str.encode("utf-8")
> > print reg_str
> > ---
> >
> > I get the output:
> >
> > abc
> >
> > Here it looks like python isn't using the ascii decoder anymore.  2)
> > What determines which decoder python uses?
>
> Again, that's because by already encoding it as a string, Python isn't
> doing any implicit encoding.  So it prints the raw string, which happens
> to be UTF-8, and which your terminal obviously supports, so you see the
> proper character.
>
> --
> Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
>   San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
>Let us not seek the Republican answer or the Democratic answer but
> the right answer. -- John F. Kennedy


So let me see if I have this right:

Here is some code:
-
print "print unicode string:"
#print u"abc\u"   #error
print repr(u'abc\u')
print

print "print regular string containing chars in unicode syntax:"
print 'abc\u'
print repr('abc\u')
print

print "print regular string containing chars in utf-8 syntax:"
#encode() converts unicode strings to regular strings
print u'abc\u'.encode("utf-8")
print repr(u'abc\u'.encode("utf-8") )
-

Here is the output:
---
print unicode string:
u'abc\u'

print regular string containing chars in unicode syntax:
abc\u
'abc\\u'

print regular string containing chars in utf-8 syntax:
abc
'abc\xe9\xa6\x99'
--




1) If you print a unicode string:

*print implicitly calls str()*

a) str() calls encode(), and encode() tries to convert the unicode
string to a regular string.  encode() uses the default encoding, which
is ascii.  If encode() can't convert a character, then encode() raises
an exception.

b) repr() calls encode(), but if encode() raises an exception for a
character, repr() catches the exception and skips over the character
leaving the character unchanged.

2) If you print a regular string containing characters in unicode
syntax:

a) str() calls encode(), but if encode() raises an exception for a
character, str() catches the exception and skips over the character
leaving the character unchanged.  Same as 1b.

b) repr() similar to a), but repr() then escapes the escapes in the
string.


3) If you print a regular string containing characters in utf-8
syntax:

a) str() outputs the string to your terminal, and if your terminal can
convert the utf-8 numerical codes to characters it does so.

b) repr() blocks your terminal from interpreting the characters by
escaping the escapes in your string.  Why don't I see two slashes like
in the output for 2b?

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


Re: The best platform and editor for Python

2007-07-01 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 kimiraikkonen <[EMAIL PROTECTED]> wrote:

> Hi,
> For experienced with Pyhton users, which developing software and
> enviroment would you suggest for Pyhton programming? Compiler+Editor
> +Debugger.
> 
> Also what are your suggestions for beginners of Pyhton programming?
> 
> 
> Thank you.

I'm very happy with emacs using python mode (http://www.python.org/emacs/).  
It's a love it or hate it kind of thing.  If you're an emacs fan, you'll 
probably not want to use anything else.  If you're not an emacs fan, this 
is probably not for you.

There really is no separate compiler.  It's part and parcel of the 
interpreter.  Your .py files do get compiled into .pyc files, but it 
happens automatically the first time you run a module.  No need to run a 
separate compilation phase like you would with C or Java.

As for a debugger, I've honestly never found the need for one.  I invest a 
lot of time in unit tests, which smoke out most of the bugs.  For what's 
left, it's easy enough to stick print statements in strategic places to see 
what's going on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The best platform and editor for Python

2007-07-01 Thread cyberco
There is one tool you won't be able to live without: iPython (no, it's
not an Apple product, but it would be worth waiting in line for 3 days
for)
http://ipython.scipy.org/moin/

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


Re: The best platform and editor for Python

2007-07-01 Thread Stef Mientki

> Thank you for the suggestions. I'd prefer a GUI-based, helpful and
> easy-implemention skilled enviroment. Tesekkurler Sayin Kartal :-)
> 

then first decide which graphical package you want to use,
because that limits your choice.

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How does py2exe work?

2007-07-01 Thread vasudevram
On Jul 2, 12:43 am, Wildemar Wildenburger <[EMAIL PROTECTED]>
wrote:
> Thomas Jollans wrote:
> > On Sunday 01 July 2007, vasudevram wrote:
>
> >> Wondering how it works? Does it actually compile the Python source of
> >> your script into machine language, or does it do something more like
> >> bundling the Python interpreter, the Python libraries and the script
> >> itself, into a file?
>
> > essentially, that's what it does.
>
> Q: A or B?
> A: Yes.
>
> *nudgenudge*
> /W

He should have said "the 2nd way" but thanks, I did guess what he
meant :-)

- Vasudev


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


Re: object references/memory access

2007-07-01 Thread Martin v. Löwis
> I guess now I'd like to know what are good practices in general to get
> better results with sockets on the same local machine. I'm only
> instantiating two sockets total right now - one client and one server,
> and the transfer is taking 15 seconds for only 8.3MB.

It would be good if you had showed the code that does that. It is hard
for us to guess what programming error you have made.

As you won't show code, I will. Please try the attached cli.py and
server.py on your machine, and report the timing. On my machine, I get

0.00105595588684 0.076632976532 830

which means I can transmit 8.3MB in 76ms, which is a lot less than
15s.

My guess is that you sum up the incoming data with

  total_data += received_data

That is O(n**2).

Regards,
Martin
import socket,time,cStringIO

t1 = time.time()
s = socket.socket()
s.connect(('localhost', 8989))
t2 = time.time()
storage = cStringIO.StringIO()
while True:
data = s.recv(1024)
if not data:
break
storage.write(data)
result = storage.getvalue()
t3 = time.time()

print t2-t1,t3-t2,len(result)
import socket

data = ' '*830
s = socket.socket()
s.bind(('', 8989))
s.listen(10)
while True:
s1, peer = s.accept()
print s1,peer
s1.send(data)
s1.close()

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

ctype and functions that return a pointer to a structure

2007-07-01 Thread hg
Hi,

I have the following code:
**
from ctypes import * 
g_lib = cdll.LoadLibrary("libc.so.6")
class Struct_Password(Structure): 
""" 
 
""" 
_fields_ = [ ('name', c_char_p), 
('code', c_char_p), 
('date', c_long), 
('min',  c_long), 
('max',  c_long), 
('warn', c_long), 
('inact', c_long), 
('expire', c_long), 
('flag', c_ulong) 
]
l_res =  g_lib.getspnam('john') 
l_struct = cast(l_res, POINTER( Struct_Password() ) ) 
print l_struct
**

The exception I get is "unhashable type" - apparently cast only handles
simple types.

Is there a way to convert l_res to Struct_Password ?

Thanks,

hg

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


Re: how to send files via bluetooth with python to a mobile

2007-07-01 Thread morphine
Diez B. Roggisch wrote:

> Wrap this
> 
> http://www.zuckschwerdt.org/apidocs/

seams that python bindings are already there?
http://dev.zuckschwerdt.org/openobex/wiki/ObexFtpExampleClientPython

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


Re: The best platform and editor for Python

2007-07-01 Thread kimiraikkonen
On Jul 1, 10:59 pm, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> > Thank you for the suggestions. I'd prefer a GUI-based, helpful and
> > easy-implemention skilled enviroment. Tesekkurler Sayin Kartal :-)
>
> then first decide which graphical package you want to use,
> because that limits your choice.
>
> cheers,
> Stef Mientki

I only have experience with Dev C++ for GUI and debugging based
programming for C/C++.
But i didn't know about Python.

So, like Visual Studio and Dev C++ similiar Python editor is welcome.

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


Re: unicode

2007-07-01 Thread Martin v. Löwis
> 1) If you print a unicode string:
> 
> *print implicitly calls str()*

No. print does nothing if the object is already a string or unicode
object, and calls str() only otherwise.

> a) str() calls encode(), and encode() tries to convert the unicode
> string to a regular string.  encode() uses the default encoding, which
> is ascii.  If encode() can't convert a character, then encode() raises
> an exception.

Yes and no. This is what str() does, but str() isn't called. Instead,
print inspects sys.stdout.encoding, and uses that encoding to encode
the string. That, in turn, may raise an exception (in particular if
sys.stdout.encoding is "ascii" or not set).

> b) repr() calls encode(), but if encode() raises an exception for a
> character, repr() catches the exception and skips over the character
> leaving the character unchanged.

No. repr() never calls encode. Instead, each type, including unicode,
may have its own __repr__ which is called. unicode.__repr__ escapes
all non-ASCII characters.

> 2) If you print a regular string containing characters in unicode
> syntax:

No. There is no such thing:

py> len("\u")
2
py> "\u"[0]
'\\'
py> "\u"[1]
'u'

In a regular string, \u has no meaning, so \ stands just for itself.

> a) str() calls encode(), but if encode() raises an exception for a
> character, str() catches the exception and skips over the character
> leaving the character unchanged.  Same as 1b.

No. Printing a string never invokes .encode(), and no exception occurs
at all. Instead, the \ just gets printed as is.

> b) repr() similar to a), but repr() then escapes the escapes in the
> string.

str.__repr__ escapes the backslash just in case, so that it won't have
to check for the next character; in that sense, it generates a normal
form.

> 3) If you print a regular string containing characters in utf-8
> syntax:
> 
> a) str() outputs the string to your terminal, and if your terminal can
> convert the utf-8 numerical codes to characters it does so.

Correct. In general, you should always use the terminal's encoding
when printing to the terminal. That way, you can print everything
just fine what the terminal can display, and get an exception if
you try to print something that the terminal would be unable to
display.

> b) repr() blocks your terminal from interpreting the characters by
> escaping the escapes in your string.  Why don't I see two slashes like
> in the output for 2b?

str.__repr__ produces an output that is legal Python syntax for a string
literal. len(u'\u'.encode('utf-8')) is 3, so this Chinese character
really encodes as three separate bytes. As these are non-ASCII bytes,
__repr__ choses a representation that is legal Python syntax. For that
characters, only \xe9, \xa6 and \x99 are valid Python syntax (each
representing a single byte). For a backslash, Python could have
generated \x5c or \134 as well, which are all different spellings
of "backslash in a string literal". Python chose the most legible
one, which is the double-backslash.

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


Re: how to send files via bluetooth with python to a mobile

2007-07-01 Thread Diez B. Roggisch
morphine schrieb:
> Diez B. Roggisch wrote:
> 
>> Wrap this
>>
>> http://www.zuckschwerdt.org/apidocs/
> 
> seams that python bindings are already there?
> http://dev.zuckschwerdt.org/openobex/wiki/ObexFtpExampleClientPython

Cool, didn't find that.

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


Re: object references/memory access

2007-07-01 Thread dlomsak

Martin v. Löwis wrote:
> > I guess now I'd like to know what are good practices in general to get
> > better results with sockets on the same local machine. I'm only
> > instantiating two sockets total right now - one client and one server,
> > and the transfer is taking 15 seconds for only 8.3MB.
>
> It would be good if you had showed the code that does that. It is hard
> for us to guess what programming error you have made.
>
> As you won't show code, I will. Please try the attached cli.py and
> server.py on your machine, and report the timing. On my machine, I get
>
> 0.00105595588684 0.076632976532 830
>
> which means I can transmit 8.3MB in 76ms, which is a lot less than
> 15s.
>
> My guess is that you sum up the incoming data with
>
>   total_data += received_data
>
> That is O(n**2).
>
> Regards,
> Martin
>
> import socket,time,cStringIO
>
> t1 = time.time()
> s = socket.socket()
> s.connect(('localhost', 8989))
> t2 = time.time()
> storage = cStringIO.StringIO()
> while True:
> data = s.recv(1024)
> if not data:
> break
> storage.write(data)
> result = storage.getvalue()
> t3 = time.time()
>
> print t2-t1,t3-t2,len(result)
>
> import socket
>
> data = ' '*830
> s = socket.socket()
> s.bind(('', 8989))
> s.listen(10)
> while True:
> s1, peer = s.accept()
> print s1,peer
> s1.send(data)
> s1.close()

I would have put my code up if it were here but it is on my machine at
work which I can't touch until Monday. I know people tend to like to
see code when you're asking for help but it is not available to me
right now so I apologize. You are right though, I believe I made the
mistake of using += to sum the data up and I had never considered the
fact that the runtime of that approach is O(n^2).  I am willing to bet
that this was my major shortcoming and you just solved my problem. I
bet the reason that jacking up the socket.recv size is because it took
fewer concatenations. I'll give an official report tomorrow on weather
or not that was the fix but I am very convinced that you got it and
that I won't have to step around the socket transmission.

Thanks a lot Martin and also to the others who responded.

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

Re: ctype and functions that return a pointer to a structure

2007-07-01 Thread Lenard Lindstrom
hg wrote:
> Hi,
> 
> I have the following code:
> **
> from ctypes import * 
> g_lib = cdll.LoadLibrary("libc.so.6")
> class Struct_Password(Structure): 
> """ 
>  
> """ 
> _fields_ = [ ('name', c_char_p), 
> ('code', c_char_p), 
> ('date', c_long), 
> ('min',  c_long), 
> ('max',  c_long), 
> ('warn', c_long), 
> ('inact', c_long), 
> ('expire', c_long), 
> ('flag', c_ulong) 
> ]
> l_res =  g_lib.getspnam('john') 
> l_struct = cast(l_res, POINTER( Struct_Password() ) ) 

l_struct = cast(l_res, POINTER( Struct_Password ) )

POINTER wants a ctypes type as an argument. Struct_Password() is a 
Structure instance.

A better way to do it is define the return type for getspnam:

g_lib.getspnam.restype = POINTER( Struct_Password )

Now the function returns a structure pointer so the cast is unnecessary.

---
Lenard Lindstrom
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The best platform and editor for Python

2007-07-01 Thread Laurent Pointal
kimiraikkonen wrote:

> Hi,
> For experienced with Pyhton users, which developing software and
> enviroment would you suggest for Pyhton programming? Compiler+Editor
> +Debugger.
> 
> Also what are your suggestions for beginners of Pyhton programming?

Under Windows, take a look at PyScripter.

For students learning Python, we are switching from Scite to PyScripter,
good editor, online Python shell, graphical debugger with step by step,
showing variables values in popups and many other sympathic features...
test it.


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


Re: object references/memory access

2007-07-01 Thread Alex Martelli
dlomsak <[EMAIL PROTECTED]> wrote:
   ...
> search and return takes a fraction of a second. For a large return (in
> this case 21,000 records - 8.3 MB) is taking 18 seconds. 15 of those
> seconds are spent sending the serialized results from the server to
> the client. I did a little bit of a blind experiment and doubled the

So here's a tiny example to show that the mere transfer of bytes on the
socket should be taking nowhere like that long:

#!/usr/local/bin/python
import socket, os, time, sys

port = 8881
sendsize = 1024
recvsize = 1024
totsize = 8*1024*sendsize

def server():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 8881))
sock.listen(5)
newSocket, address = sock.accept()
totbytes = 0
start = time.time()
while totbytes < totsize:
receivedData = newSocket.recv(recvsize)
if not receivedData: break
totbytes += len(receivedData)
newSocket.close()
sock.close()
return totbytes, time.time()-start

def client():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 8881))
totbytes = 0
while totbytes < totsize:
sock.sendall(sendsize*'x')
totbytes += sendsize
sock.close()

def main():
print "moving %d bytes (ss=%d, rs=%d)" % (totsize, sendsize,
recvsize)
if os.fork():
# parent process
forbytes, tooktime = server()
else:
# child process
time.sleep(0.5)
client()
sys.exit(0)
stend = time.time()
print "%d bytes in %5.2f sec (ss=%d, rs=%d)" % (forbytes,
tooktime, sendsize, recvsize)

main()


brain:~/downloads alex$ python sere.py 
moving 8388608 bytes (ss=1024, rs=1024)
8388608 bytes in  0.08 sec (ss=1024, rs=1024)

So, moving 8.3 MB on a bare socket should take about 100 milliseconds,
give or take.

So let's try WITH pickling and unpickling (done right):

#!/usr/local/bin/python
import socket, os, time, sys, random, cPickle

port = 8881
sendsize = 1024
recvsize = 1024

data = [random.random() for i in xrange(1000*1000)]
pickled_data = cPickle.dumps(data, 2)
totsize = len(pickled_data)

def server():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 8881))
sock.listen(5)
newSocket, address = sock.accept()
totbytes = 0
recvdata = []
start = time.time()
while totbytes < totsize:
receivedData = newSocket.recv(recvsize)
if not receivedData: break
totbytes += len(receivedData)
recvdata.append(receivedData)
newSocket.close()
sock.close()
data = cPickle.loads(''.join(recvdata))
return totbytes, time.time()-start

def client():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 8881))
totbytes = 0
while totbytes < totsize:
totbytes += sock.send(pickled_data[totbytes:totbytes+sendsize])
sock.close()

def main():
print "moving %d bytes (ss=%d, rs=%d)" % (totsize, sendsize,
recvsize)
if os.fork():
# parent process
forbytes, tooktime = server()
else:
# child process
time.sleep(0.5)
client()
sys.exit(0)
stend = time.time()
print "%d bytes in %5.2f sec (ss=%d, rs=%d)" % (forbytes,
tooktime, sendsize, recvsize)

main()


brain:~/downloads alex$ python sere.py 
moving 9002006 bytes (ss=1024, rs=1024)
9002006 bytes in  0.32 sec (ss=1024, rs=1024)

So, a bit more data, quite a bit longer, but still on the order of
magnitude of 300 milliseconds or so.

Again this suggests the problems are not "intrinsic" to the task.

It's hard to guess at exactly what it may be that you're doing wrong.
For example, if recvdata was a string (grown with +=) rather than a list
(grown with append), this would boost the runtime to 0.76 seconds; a
huge waste (more than a factor of two blown away by a minor programming
gaucheness) but still a long way from the several orders of magniture
you're observing.

So, I suggest you try programming the interaction directly to bare
sockets, as I do here (and in several examples in Chapter 20 in "Python
in a Nutshell" 2nd edition), and see what difference that makes to your
timings.


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


Re: Reversing a string

2007-07-01 Thread Alex Martelli
Jay Loden <[EMAIL PROTECTED]> wrote:
   ...
> For what it's worth, with python 2.5 on my Macbook:

Hmmm, doesn't look to me as if it's worth much...:

> [EMAIL PROTECTED] jloden]$ python -m timeit 's = "onomatopoeia"; s =
s.join(s[::-1])'

since what you're doing is...:

>>> s = "onomatopoeia"
>>> s = s.join(s[::-1])
>>> s
'aonomatopoeiaionomatopoeiaeonomatopoeiaoonomatopoeiaponomatopoeiaoonoma
topoeiatonomatopoeiaaonomatopoeiamonomatopoeiaoonomatopoeianonomatopoeia
o'
>>>

...which isn't really just reversing the string, but quite a bit more
work!-)


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


Re: ctype and functions that return a pointer to a structure

2007-07-01 Thread hg
Lenard Lindstrom wrote:

> hg wrote:
>> Hi,
>> 
>> I have the following code:
>> **
>> from ctypes import *
>> g_lib = cdll.LoadLibrary("libc.so.6")
>> class Struct_Password(Structure):
>> """
>>  
>> """
>> _fields_ = [ ('name', c_char_p),
>> ('code', c_char_p),
>> ('date', c_long),
>> ('min',  c_long),
>> ('max',  c_long),
>> ('warn', c_long),
>> ('inact', c_long),
>> ('expire', c_long),
>> ('flag', c_ulong)
>> ]
>> l_res =  g_lib.getspnam('john')
>> l_struct = cast(l_res, POINTER( Struct_Password() ) )
> 
> l_struct = cast(l_res, POINTER( Struct_Password ) )
> 
> POINTER wants a ctypes type as an argument. Struct_Password() is a
> Structure instance.
> 
> A better way to do it is define the return type for getspnam:
> 
> g_lib.getspnam.restype = POINTER( Struct_Password )
> 
> Now the function returns a structure pointer so the cast is unnecessary.
> 
> ---
> Lenard Lindstrom
> <[EMAIL PROTECTED]>

Many thanks,

hg

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


pos to blepeis

2007-07-01 Thread [EMAIL PROTECTED]
http://kokonis.aygoystinos.googlepages.com/
http://theologos.kokkonis.googlepages.com/

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


what is the PythonWin

2007-07-01 Thread steveandleyla
I downloaded Python 5.1 for windows so I could run a program.

I have to do the following:

In PythonWin, select Tools | COM MakePy utility | Microsoft Speech
Object Library 5.1).

I can't find PythonWin .. Does anybody know what this is.  I have the
Python shell gui but no "PythonWin".

THanks.

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Martin Gregorie
Roedy Green wrote:
> On Sun, 01 Jul 2007 17:47:36 +0100, Martin Gregorie
> <[EMAIL PROTECTED]> wrote, quoted or indirectly quoted
> someone who said :
> 
>> GPS time is UTC time and I'd assume the same is true for Loran.
> 
> not according to this site that has clocks running on all three.
> They are out slightly.
>  
> http://www.leapsecond.com/java/gpsclock.htm
 >
A useful reference: thanks. Interesting that GPS and Loran are slightly 
out from Zulu. I'll ask round and see if this is something that ATP 
pilots are aware of: as a glider pilot and GPS user I'd never heard of 
it. So far the deviations from UTC are probably not enough to affect 
navigation significantly, but I wonder if banks using networks that 
timestamp transactions with GPS time know about it. Of course the 
deviation can't affect disputes where the timestamps are being used to 
decide event sequences within a single network. However, there could be 
legal implications if absolute time is important or if the timestamps 
are being compared across different networks, e.g SWIFT vs CHAPS or Fedwire.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org   |
-- 
http://mail.python.org/mailman/listinfo/python-list


Tiny/small/minimalist Python?

2007-07-01 Thread rtk
I'm looking for information on building a tiny/small/minimalist/
vanilla python interpreter.  One that implements the core language and
a few of the key modules but isn't tied to any specific operating
system.

I guess I'm asking for the smallest subset of the standard Python
source code files that is necessary to get a working interpreter using
a plain C compiler.

Is this even possible?  If so, has someone done it already?  I've
looked on Google and in comp.lang.python but nothing comes up.

Thanks!
Ron

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Paul Rubin
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:
>   What is not mentioned is that, as part of the data stream picked up
> by GPS receivers, is a term specifying the "correction factor" between
> GPS and UTC; so receivers can display UTC time.

Oh yes, good point, the article ought to mention that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The best platform and editor for Python

2007-07-01 Thread [EMAIL PROTECTED]
kimiraikkonen wrote:
> Hi,
> For experienced with Pyhton users, which developing software and
> enviroment would you suggest for Pyhton programming? Compiler+Editor
> +Debugger.

I use standard CPython bytecode compiler/virtual machine, the Vim
editor, and standard pdb for debugging.  Vim is nice as it's
multiplatform, has a built-in Python interpreter for writing
extensions, is free and lightweight.  It's a modal editor so that's a
matter of taste--people either love it or hate it.

> Also what are your suggestions for beginners of Pyhton programming?

Start with something like http://www.diveintopython.org for a brief
intro.
Pick a very small project and program it.  Then pick something bigger
and do that.  Once you're comfortable with small projects, find an
open-source project that you like and try to understand the code
enough to make some change you find useful; reading code is as
important as writing it.

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


Re: Portable general timestamp format, not 2038-limited

2007-07-01 Thread Ben Finney
Martin Gregorie <[EMAIL PROTECTED]> writes:

> I've never seen Julian time used outside the world of IBM
> mainframes. I'd be interested to know who else uses it.

Systems which need to perform date+time computations into the
past. One advantage of Julian time is that it ignores the "1 BC was
immediately followed by 1 AD, there is no 0 AD" hiccup, so Julian time
allows dates to use simple arithmetic to determine the interval.

I know that PostgreSQL at least stores date values in Julian time, for
exactly this benefit.

-- 
 \  "My roommate got a pet elephant. Then it got lost. It's in the |
  `\   apartment somewhere."  -- Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing a string

2007-07-01 Thread Frank Swarbrick
Alex Martelli wrote:
> Martin Durkin <[EMAIL PROTECTED]> wrote:
>...
> print "\n".join("spam"[::-1])
>...
 OK, maybe I'm missing the point here as I'm new to Python. The first
 one seems clearer to me. What am I missing?

>>> I think all you are missing is familarity with Python, but I too don't
>>> like one-liners simply for their own sake.
>> I guess that's it. The first one reads more like a textbook example which
>> is about where I am at. Is there any speed benefit from the one liner?
> 
> The first example reads "excruciatingly low-level" to me: its autor is
> thinking in terms of what the machine is doing, mapped into pretty
> elementary low-level constructs.
> 
> The second example depends first of all on knowledge of extended-slicing
> (specifically the fact that x[::-1] is a reversal, because of the
> negative -1 "step" aka "stride").  If you don't know about extended
> slicing, you're unlikely to just "get it from context", because it uses
> a syntax based on punctuation rather than readable words whose meaning
> you might guess at.  Python has a modest amount of such "punctuation
> syntax" -- about the same amount as C but definitely more than Cobol
> (where one would typically write "ADD a TO b" to avoid shocking totally
> clueless readers with "mysterious punctuation" such as "a + b"...!!!-).
> Punctuation is often very concise but not "intrinsically obvious" unless
> you've been exposed to it already;-).

Since you mentioned Cobol I couldn't resist...

move "spam" to spam
Display Function Reverse(spam)

There's also slicing (known in Cobol as "reference modification")
move mystring(5:3) to my-newstring
* moves 3 characters starting with character 5

No "negative" slicing, though it could be simulated with Function 
Reverse() and ref.mod.

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


Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-07-01 Thread Alan Isaac
A.T.Hofkamp wrote:
> Hmm, maybe numbers in sets are broken then?
a = 12345
b = 12345
a == b
> 
> True
> 
a is b
> 
> False
> 
set([a,b])
> 
> set([12345])
> 
> Numbers and my Car2 objects behave the same w.r.t. '==' and 'is', yet I get a
> set with 1 number, and a set with 2 cars.
> Something is wrong here imho.
> 
> The point I intended to make was that having a default __hash__ method on
> objects give weird results that not everybody may be aware of.
> In addition, to get useful behavior of objects in sets one should override
> __hash__ anyway, so what is the point of having a default object.__hash__ ?


The point is: let us have good default behavior.
Generally, two equal numbers are two conceptual
references to the same "thing".  (Say, the Platonic
form of the number.) So it is good that the hash value
is determined by the number.  Similarly for strings.
Two equal numbers or strings are **also** identical,
in the sense of having the same conceptual reference.
In contrast, two "equal" cars are generally not identical
in this sense.  Of course you can make them so if you wish,
but it is odd.  So *nothing* is wrong here, imo.

Btw:
>>> a = 12
>>> b = 12
>>> a == b
True
>>> a is b
True

Cheers,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto resend args and kwargs to other func?

2007-07-01 Thread Frank Swarbrick
dmitrey wrote:
> Thanks all, I have solved the problem.

Why do people do this without posting what the actual solution is
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 : https and proxy

2007-07-01 Thread O.R.Senthil Kumaran
* Maric Michaud <[EMAIL PROTECTED]> [2007-06-28 23:38:39]:

>  Hmmm, i've tried something similar but I get the same result.
> 
>  For the code example I gave, I've put correctly the http_proxy and 
>  https_proxy environment variables, the default ProxyHandler get them right 
>  as this is the proxy itself which returns the error. I checked this with 
>  wireshark, the proxy said that there is incompatibilities in some request 
>  methods, like POST, with some protocols, Gopher is the example it gave.
>  That doesn't make much sense to me as the wget command I tried is intended 
>  to do exactly the same thing (POST over https and retrieve some cookies from 
>  the response), and go through with no problems.
> 

Maric, in the ActiveState urllib2 HOWTO which seems to apply for Python 2.5, I
came across a point which mentions urllib2 does not support PROXY for HTTPS.
Your case seems the same, I would suggest you to look up the Python Tracker
for any already open issues, or if not kindly log one yourself. 
I shall if I can help further, working on urllib2 is a project am doing as
part of Summer of Code 2007.

Thanks,

-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing a string

2007-07-01 Thread Jay Loden

Alex Martelli wrote:
> since what you're doing is...:
> 
 s = "onomatopoeia"
 s = s.join(s[::-1])
 s
> 'aonomatopoeiaionomatopoeiaeonomatopoeiaoonomatopoeiaponomatopoeiaoonoma
> topoeiatonomatopoeiaaonomatopoeiamonomatopoeiaoonomatopoeianonomatopoeia
> o'
> 
> ...which isn't really just reversing the string, but quite a bit more
> work!-)

That's what I get for copying and pasting from the post preceding mine and not 
actually checking it for what it does ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tiny/small/minimalist Python?

2007-07-01 Thread Terry Reedy

"rtk" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| I'm looking for information on building a tiny/small/minimalist/
| vanilla python interpreter.  One that implements the core language and
| a few of the key modules but isn't tied to any specific operating
| system.
|
| I guess I'm asking for the smallest subset of the standard Python
| source code files that is necessary to get a working interpreter using
| a plain C compiler.
|
| Is this even possible?  If so, has someone done it already?  I've
| looked on Google and in comp.lang.python but nothing comes up.

Google 'tinypython' and first entry is Mark Hammond's answer to nearly same 
question.  And some other responses might help you



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


Re: what is the PythonWin

2007-07-01 Thread O.R.Senthil Kumaran
* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [2007-07-01 15:53:30]:

> In PythonWin, select Tools | COM MakePy utility | Microsoft Speech
> Object Library 5.1).
> 
> I can't find PythonWin .. Does anybody know what this is.  I have the
> Python shell gui but no "PythonWin".
> 
PythonWin is a separate project by Mark Hammond providing win32 extensions for
python. 

http://sourceforge.net/projects/pywin32/

-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


delicious.py 0.2.5: Patch to solve the 401 issue

2007-07-01 Thread Kai Kuehne

Hi,
I just wanted to mention that I wrote a patch for delicious.py 0.2.5
that solves the 401 "bug". The delicious guys changed their
api to use ssl and stuff. I already sent the patch to the author,
but in case you need the library asap (as I did) you
can apply it and it should work.

Greetings
Kai


delicious-0.2.5-401.patch
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to uninstall packages

2007-07-01 Thread Rustom Mody
Yeah sure thats what is (finally) working but its never clear upfront
for a package what its dependency needs are -- linux version of DLL
hell.  And it gets worse for systems that are little worlds in
themselves like python, ruby, eclipse, webmin etc.  because they have
their own package-management systems which invariably quarell with the
native apt/rpm or whatever...

On 7/1/07, Thomas Jollans <[EMAIL PROTECTED]> wrote:
> On Sunday 01 July 2007, Rustom Mody wrote:
>
> > I first installed the debian package python-pysqlite1.1 using
> > synaptic. Since this seemed too old for other packages (sqlalchemy) I
> > downloaded the sources  pysqlite-2.3.4.tar.gz and ran setup install.
>
> I wonder why you chose not to use python-pysqlite2...
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode

2007-07-01 Thread 7stud
Hi,

Thanks for the detailed response.

On Jul 1, 2:14 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > 1) If you print a unicode string:
> >
> > a) str() calls encode(), and encode() tries to convert the unicode
> > string to a regular string.  encode() uses the default encoding, which
> > is ascii.  If encode() can't convert a character, then encode() raises
> > an exception.
>
> Yes and no. This is what str() does, but str() isn't called. Instead,
> print inspects sys.stdout.encoding, and uses that encoding to encode
> the string. That, in turn, may raise an exception (in particular if
> sys.stdout.encoding is "ascii" or not set).
>

Is that the same as print calling encode(u_str, sys.stdout.encoding)


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

Re: unicode

2007-07-01 Thread 7stud
On Jul 1, 9:51 pm, 7stud <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Thanks for the detailed response.
>
> On Jul 1, 2:14 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
>
> > > 1) If you print a unicode string:
>
> > > a) str() calls encode(), and encode() tries to convert the unicode
> > > string to a regular string.  encode() uses the default encoding, which
> > > is ascii.  If encode() can't convert a character, then encode() raises
> > > an exception.
>
> > Yes and no. This is what str() does, but str() isn't called. Instead,
> > print inspects sys.stdout.encoding, and uses that encoding to encode
> > the string. That, in turn, may raise an exception (in particular if
> > sys.stdout.encoding is "ascii" or not set).
>
> Is that the same as print calling encode(u_str, sys.stdout.encoding)

ooops.  I mean is that the same as print calling
u_str.encode(sys.stdout.encoding)?

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

Re: Tiny/small/minimalist Python?

2007-07-01 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
rtk  <[EMAIL PROTECTED]> wrote:
>I'm looking for information on building a tiny/small/minimalist/
>vanilla python interpreter.  One that implements the core language and
>a few of the key modules but isn't tied to any specific operating
>system.
>
>I guess I'm asking for the smallest subset of the standard Python
>source code files that is necessary to get a working interpreter using
>a plain C compiler.
>
>Is this even possible?  If so, has someone done it already?  I've
>looked on Google and in comp.lang.python but nothing comes up.
.
.
.
Tiny Python, PyMite, EmbeddedPython, Diet Python, deeply embedded
python, ...--I need to write up a page that explains these.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >