Re: urllib2 performance on windows, usb connection

2009-02-05 Thread Martin v. Löwis
> So does anyone know what the deal is with this?  Why is the same code so
> much slower on Windows?  Hope someone can tell me before a holy war
> erupts :-)

Only the holy war can give an answer here. It certainly has *nothing* to
do with Python; Python calls the operating system functions to read from
the network and write to the disk almost directly. So it must be the
operating system itself that slows it down.

To investigate further, you might drop the write operating, and measure
only source.read(). If that is slower, then, for some reason, the
network speed is bad on Windows. Maybe you have the network interfaces
misconfigured? Maybe you are using wireless on Windows, but cable on
Linux? Maybe you have some network filtering software running on
Windows? Maybe it's just that Windows sucks?-)

If the network read speed is fine, but writing slows down, I ask the
same questions. Perhaps you have some virus scanner installed that
filters all write operations? Maybe Windows sucks?

Regards,
Martin

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


urllib2 performance on windows, usb connection

2009-02-05 Thread dq
I've googled this pretty extensively and can't find anyone who's had the 
same problem, so here it is:


I wrote a console program in python to download podcasts, so speed is an 
issue.  I have 1.6 M down.  The key bit of downloading code is this:


source = urllib2.urlopen( url )
target = open( filename, 'wb' )
target.write( source.read() )

This runs great on Ubuntu.  I get DL speeds of about 1.5 Mb/s on the 
SATA HD or on a usb-connected iPod, but if I run the same program on 
Windows (with a 2 GHz core 2 duo, 7200 rpm sata drive---better hardware 
specs than the Ubuntu box), it maxes out at about 500 kb/s.  Worse, if I 
DL directly to my iPod in disk mode, I'm lucky if I even hit 100 kb/s.


So does anyone know what the deal is with this?  Why is the same code so 
much slower on Windows?  Hope someone can tell me before a holy war 
erupts :-)


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


Re: web2py 1.56 is OUT

2009-02-05 Thread Markus Gritsch
Hi,

when copying and pasting the example from the announcement into files,
it wont run due to some errors:

2009/2/5 Massimo Di Pierro :
>
> Example of code (complete app)
> =
>## in model db.py
>from gluon.tools import *
>db=SQLDB()
>db.define_table('puppy', db.Field('name'), db.Field('image','upload'))
>auth=Auth(globals(),db)

Here the line auth.define_tables() is missing.

>crud=Crud(flobals(),db)

flobals -> globals

>## in controller default.py
>def user():
>" to expose register, login, logout, etc "
>return dict(form=auth())
>
>@auth.requires_login()
>def data():
> " to expose select, create, update, delete, etc "

The above line is indented one character too much which results in an error.

>return dict(form=crud())
>
>@auth.requires_login()
>def download():
>" for downloading uploaded images "
>return response.download(request,db)
>
>## in view default/user.html
>{{extend 'layout.html'}}
>{{=form}}
>
>## in view default/data.html
>{{extend 'layout.html'}}
>{{=form}}

The above example is not (although stated) a complete app, even when
correcting the errors.  No index action, no links to register, login,
etc, no functionality in the data action.  If one has not already read
the web2py auth docu, one cannot understand what should be going on.

If I would have been looking at web2py for the first time, I would
have been disapointed and would not bother looking deeper.  Also the
glued-together code style without spaces after colons and around
operators looks quite special.  When suggesting PEP 8 compliance I
suggested using it in the *examples*, and just optionally in the gluon
code itself.  The example and the documentation is the stuff people
are seeing and reading when trying to get started with web2py.

I know, the above paragraphs sound quite negative.  *I* like web2py
very much and am a happy user.  I just fear that such examples will
not draw new users towards this great project.  Maybe use a simple
example without Auth the next time, which is *really* complete and
fully functional.

Kind regards,
Markus
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Volodymyr Orlenko



On 05/02/2009 9:54 PM, James Mills wrote:

On Fri, Feb 6, 2009 at 3:21 PM, Volodymyr Orlenko  wrote:
  

[...] Maybe there's another
way to fix the forking module?



I believe the best way to fix this is to fix the underlying
issue that Mark has pointed out (monkey-patching mp won't do).

  
But according to Mark's second message in this thread, there's no way to 
make pythonservice.exe set its sys.argv[0] to a python module -- it uses 
sys.argv for debug parameters in debug mode, and for custom service 
parameters in normal mode.

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


Re: Where to host a (Python) project?

2009-02-05 Thread alex goretoy
I use google code.
http://code.google.com/p/pynutbutter

-Alex Goretoy
http://www.alexgoretoy.com



On Thu, Feb 5, 2009 at 6:55 PM, Ben Finney <
bignose+hates-s...@benfinney.id.au >wrote:

> a...@pythoncraft.com (Aahz) writes:
>
> > In article <
> 6dcb8ce5-c93e-458c-9047-e5db60f27...@v18g2000pro.googlegroups.com>,
> > andrew cooke   wrote:
> > >hi, just fyi, i investigated this and you can join any publicly
> > >readable group by sending an email to the "-subscribe" address. you
> > >do not need a google login for this and, as far as i can tell, it
> > >then operates for you like a normal mailing list.
> >
> > The same thing is theoretically true for Yahoo groups, but I've
> > heard from people over the years about various difficulties fixing
> > problems with list subscriptions in the absence of a real Yahoo
> > login and I'm not particularly interested in finding out that the
> > same thing ends up being true for Google lists.
>
> Indeed it does. I have succeeded in subscribing to Google mailing
> lists in the absence of a Google account, but *managing* that
> subscription thereafter in the absence of a Google account is
> obnoxiously difficult. Your caution is well advised.
>
> --
>  \"I got fired from my job the other day. They said my |
>  `\  personality was weird. … That's okay, I have four more." |
> _o__)   —Bug-Eyed Earl, _Red Meat_ |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


reconstruct html form in pyGTK window and create dict from pyGTK

2009-02-05 Thread alex goretoy
Hello All,

What would be the best way to fetch a form/s from a webpage and then
recreate it in a pygtk window?

I'm doing some research on this for a project called pynutbutter. This is
for jellpy actually, which handles creating option mappings for pynutbutter
from a GUI.
The things I know I would need some examples on:

How to work multiple glade files? (so i can have multiple pages for
different types of options) more efficient way, is this a good option?

loading of forms fields and reconstructiting in pyGTK with
comboboxes/comboboxtextentry textboxes/textentry and textviews, not how to
load them or display them...I can see that on pygtk websitebut the more
efficient way to do this dynamically.

What is the best way to create a dict from a gui? just have a user type the
dict: somedict={"some":thing} or have another window pop up that handles for
name value pairs of the dict and a field for dict name.

After all this what would be the best way for me to merge this dict into a
options file. There will be other options in there. How would I only either
prepend the new dict or if one with same name exists overwrite it. Would
that be a safe move?

What would be the most effiecient and user friendly way to contruct this on
a form basis in a pyGTK GUI

defaults = {"formfield":"somevalue","anotherfield":"somefieldvalue"}
mappings =
{"somefield":"filefield1","anotherfield":"some_function(filefield2)"}
headers = {"filefield1":"somefield","filefield2":"anotherfield"}

What would be the best way for me to construct this dict from a user
friendly form in pyGTK

Sorry this is alot of questions. Any advise on this matter will be greatly
appreciated. Thank you.


-Alex Goretoy
http://www.alexgoretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Hendrik van Rooyen

"Steve Holden"  wrote:

> Yes, and I'm fine well sure this is somewhere between a silly thread and
> a troll.

"Fine" reads wrong - it should be fining.

Silly? Us here on clp, silly?

What a monstrous thought!

I'll have you know this is a respectable
establishment, and you should be grateful
that such fine, serious folk suffer your 
impertinence without taking umbrage !

Ok Steve now it's your turn to tell me it 
does not scan.

I think this thread has buggered up a perfectly
good word for me - It will be difficult, in future,
to hear the word without having to suppress
an involuntary snigger.

- Hendrik


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


Python Power Point Slides

2009-02-05 Thread Tehseen Siddiqui





--
DISCLAIMER:  The information in this email is confidential and may be legally 
privileged. It is intended solely for the addressee. Access to this email by 
anyone else is unauthorized. If you are not the intended recipient, any 
disclosure, copying, distribution or any action taken or omitted to be taken in 
reliance on it, is prohibited and may be unlawful. ARL cannot accept liability 
for any loss or damage sustained as a result of software viruses.
--
--
http://mail.python.org/mailman/listinfo/python-list


i have an query regarding pyodbc

2009-02-05 Thread Rahul
hello all,

I have installed pyodbc on my red hat enterprise 4 linux machine but
when i go to use that using statement,

import pyodbc

through python console it gives me error as

ImportError : dynamic module does not define init function
(initpyodbc)

and when i do 'nm pyodbc.so' command i get output as

[r...@dbserver site-packages]# nm pyodbc.so 1600 A __bss_start
03ec t call_gmon_start 1600 b completed.1 14fc d
__CTOR_END__
14f8 d __CTOR_LIST__
 w __cxa_finalize@@GLIBC_2.1.3
04a8 t __do_global_ctors_aux
0410 t __do_global_dtors_aux
15f8 d __dso_handle
1504 d __DTOR_END__
1500 d __DTOR_LIST__
150c A _DYNAMIC
1600 A _edata
1604 A _end
04d8 T _fini
046c t frame_dummy
04f4 r __FRAME_END__
15e8 A _GLOBAL_OFFSET_TABLE_
 w __gmon_start__
03b4 T _init
1508 d __JCR_END__
1508 d __JCR_LIST__
 w _Jv_RegisterClasses
15fc d p.0


which means there is no init function.

So what might be the cause for that?

I have build that pyodbc twice.
Any help regarding this will be greatly appreciated.

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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Hendrik van Rooyen
"Mensanator" 


>On Feb 5, 4:20 pm, Terry Reedy  wrote:
>> mk wrote:
>>
>> > (duck)
>>
>> > 542 comp.lang.python rtfm
>>
>> What is so unfriendly about 'read the fine manual'?
>
>You've seen a fine manual?

Oh Fine!

- Hendrik


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


Re: What is difference between ADO and RDO

2009-02-05 Thread Chris Rebert
On Thu, Feb 5, 2009 at 9:52 PM, agile  wrote:
> Explain ADO and RDO

Take 5 seconds to Google them and find their Wikipedia pages:
http://en.wikipedia.org/wiki/Remote_Data_Objects
http://en.wikipedia.org/wiki/ActiveX_Data_Objects

Apparently they're 2 Microsoft technology acronyms -- and they're
**completely irrelevant** to this mailinglist, which is about
*Python*.

My but your post is lazy, terse, and rude.

Bye now,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


What is difference between ADO and RDO

2009-02-05 Thread agile
Explain ADO and RDO
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using multiprocessing from a Windows service

2009-02-05 Thread James Mills
On Fri, Feb 6, 2009 at 3:21 PM, Volodymyr Orlenko  wrote:
> In the patch I submitted, I simply check if the name of the supposed module
> ends with ".exe". It works fine for my case, but maybe this is too general.
> Is there a chance that a Python module would end in ".exe"? If so, maybe we
> should check specifically for "pythonservice.exe". But then, if someone
> renames the executable (as I did, because I wanted to see meaningful service
> names in the process list), the patch will not work. Maybe there's another
> way to fix the forking module?

I believe the best way to fix this is to fix the underlying
issue that Mark has pointed out (monkey-patching mp won't do).

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


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Volodymyr Orlenko



On 05/02/2009 8:26 PM, Mark Hammond wrote:

On 6/02/2009 2:50 PM, Mark Hammond wrote:

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set
sys.argv[] to resemble a normal python process with argv[0] being the
script. I'll fix it...


Actually it appears I spoke too soon:

* A bug in pywin32 exists such that when you use 'debug' on a service, 
the argv reflected the full argv of the application, including the 
'-debug' portion of the command-line.  However, even if that is fixed, 
the next argument is actually the name of the service (as declared in 
the .py file for the service), not the .py module itself.  Thus, I 
could make argv a little more sane in this case, but still the initial 
problem would remain as argv[0] would still not be a .py file.


* When the service is started by windows itself, there are usually 
zero additional command-line arguments.  If there *are* arguments, 
they are likely to be the string the user entered via control panel as 
a special case (Windows doesn't actually remember service args - they 
are used once and discarded).  It is important we continue to expose 
whatever argv we actually got from Windows to the service code.


So unfortunately I don't think I can change pythonservice to resolve 
the issue you reported.



Thanks Mark, this makes perfect sense.

In the patch I submitted, I simply check if the name of the supposed 
module ends with ".exe". It works fine for my case, but maybe this is 
too general. Is there a chance that a Python module would end in ".exe"? 
If so, maybe we should check specifically for "pythonservice.exe". But 
then, if someone renames the executable (as I did, because I wanted to 
see meaningful service names in the process list), the patch will not 
work. Maybe there's another way to fix the forking module?

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


Re: return multiple objects

2009-02-05 Thread Vincent Davis
That is what I was missing,
Thanks
Vincent Davis



On Thu, Feb 5, 2009 at 8:37 PM, Rhodri James wrote:

> On Fri, 06 Feb 2009 03:03:01 -, Vincent Davis <
> vinc...@vincentdavis.net> wrote:
>
>  Is it correct that if I want to return multiple objects from a function I
>> need to in some way combine them?
>> def test1():
>>a = [1,3,5,7]
>>b = [2,4,6,8]
>>c=[a,b]
>>   return a, b # this does not work?
>>   return [a, b] # does not work?
>>   return c # this works but I don't like it, , is there a better way?
>>
>
> Strictly speaking, you can only return one object from a function.
>  However,
> that one object can be a container (list, tuple, dict, set, or what have
> you) that contains multiple objects.  Tuples are a popular choice:
>
>  return a, b
>
> ...but almost any ordered type would do, because you can automagically
> unpack the results if you want to:
>
>  x, y = test1()
>
> (You might be expecting brackets around the "a, b" and the "x, y", and
> you'd be sort of right.  The brackets (parentheses) for tuples are
> optional, except for a couple of cases where you *have* to put them
> in to avoid ambiguity.  I tend to put them in always, but leaving them
> out in cases like this seems to be normal practice.)
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Mark Hammond

On 6/02/2009 2:50 PM, Mark Hammond wrote:

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set
sys.argv[] to resemble a normal python process with argv[0] being the
script. I'll fix it...


Actually it appears I spoke too soon:

* A bug in pywin32 exists such that when you use 'debug' on a service, 
the argv reflected the full argv of the application, including the 
'-debug' portion of the command-line.  However, even if that is fixed, 
the next argument is actually the name of the service (as declared in 
the .py file for the service), not the .py module itself.  Thus, I could 
make argv a little more sane in this case, but still the initial problem 
would remain as argv[0] would still not be a .py file.


* When the service is started by windows itself, there are usually zero 
additional command-line arguments.  If there *are* arguments, they are 
likely to be the string the user entered via control panel as a special 
case (Windows doesn't actually remember service args - they are used 
once and discarded).  It is important we continue to expose whatever 
argv we actually got from Windows to the service code.


So unfortunately I don't think I can change pythonservice to resolve the 
issue you reported.


Cheers,

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


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Mark Hammond

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set 
sys.argv[] to resemble a normal python process with argv[0] being the 
script.  I'll fix it...


Cheers,

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


Re: return multiple objects

2009-02-05 Thread Rhodri James
On Fri, 06 Feb 2009 03:03:01 -, Vincent Davis  
 wrote:



Is it correct that if I want to return multiple objects from a function I
need to in some way combine them?
def test1():
a = [1,3,5,7]
b = [2,4,6,8]
c=[a,b]
   return a, b # this does not work?
   return [a, b] # does not work?
   return c # this works but I don't like it, , is there a better way?


Strictly speaking, you can only return one object from a function.   
However,

that one object can be a container (list, tuple, dict, set, or what have
you) that contains multiple objects.  Tuples are a popular choice:

  return a, b

...but almost any ordered type would do, because you can automagically
unpack the results if you want to:

  x, y = test1()

(You might be expecting brackets around the "a, b" and the "x, y", and
you'd be sort of right.  The brackets (parentheses) for tuples are
optional, except for a couple of cases where you *have* to put them
in to avoid ambiguity.  I tend to put them in always, but leaving them
out in cases like this seems to be normal practice.)

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


Re: Converting numbers to words

2009-02-05 Thread Brian Allen Vanderburg II

todp...@hotmail.com wrote:
>
> I've been trying to figure this out for over 2 hours and I'm really 
frustrated right now.

>
> I first made Python to ask user to input height in meters. If user 
puts certain value in meter, then it converts it to feet and inches as 
follows:
>  
>

> Enter the height (in metres): 1.6
>
> It is 5 feet, 3 inches high.
>  
>  
> What I want to do is to make it type only words. For example, instead 
of its saying, "It is 5 feet, 3 inches high," I want it to say, "it is 
five feet, three inches high."

> I'd appreciate any suggestions.

I made something similar in the past.  First I break it into two 
functions, one function handles 0-999 and return '' for zero or a 
meaningful value for 999, another function handles how many groups there 
are and for each one, gets the value for it calls the first function, 
and appends the correct word.  This only works for the English language 
though


Brian Vanderburg II

num_words1 = ("zero", # not used
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen")

num_words2 = ("twenty",
"thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety")

num_words3 = ("thousand",
"million",
"billion",
"trillion",
"quadrillion")

def word_func1(value):
  # value can be from 0 to 999
  result = ''

  if value == 0:
  return result

  # Handle hundreds
  if value >= 100:
  hvalue = int(value / 100)
  if result:
  result += ' '
  result += num_words1[hvalue]
  result += ' hundred'
  value -= (hvalue * 100)

  if value == 0:
  return result

  # Handle 1-19
  if value < 20:
  if result:
  result += ' '
  result += num_words1[value]
  return result

  # Handle 10s (20-90)
  tvalue = int(value / 10)
  if result:
  result += ' '
  result += num_words2[tvalue - 2]
  value -= (tvalue * 10)

  if value == 0:
  return result

  # Handle ones
  if result:
  result += ' '
  result += num_words1[value]

  return result

def word_func2(value):
  result = ''

  if value == 0:
  return 'zero'

  # Determine support values
  divider = 1
  l = len(num_words3)
  for i in range(l):
  divider *= 1000

  for i in range(l):
  if value >= divider:
  dvalue = int(value / divider)
  if result:
  result += ' '
  result += word_func1(dvalue)
  result += ' '
  result += num_words3[l - i - 1]
  value -= (dvalue * divider)
  divider /= 1000

  if value > 0:
  if result:
  result += ' '
  result += word_func1(value)

  return result

number_to_word = word_func2

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


Re: subprocess returncode windows

2009-02-05 Thread Gabriel Genellina
En Thu, 05 Feb 2009 17:34:29 -0200, Andrew   
escribió:



On Dec 16 2008, 5:11 pm, "Gabriel Genellina" 
wrote:

En Tue, 16 Dec 2008 17:21:35 -0200, Andrew   
escribió:



> On Dec 16, 12:50 pm, Christian Heimes  wrote:
>> Andrew schrieb:

>> > I'm running into a strange situation with getting incorrect
>> > returncodes / exit status from python subprocess.call. I'm using a
>> > python script (runtime 2.6.1 on windows) to automate the deploy of
>> > java applications to glassfish application server. Below is an >>  
> example



I've tried this several ways now. It seems to be something specific
with python and asadmin.bat.

I've tried the following manually in the cmd.exe prompt:


[examples showing %ERRORLEVEL% correctly set when running from the command  
line, but subprocess.call doesn't get it]



Notice how python never gets the correct returncode from asadmin.bat
but I can get the correct returncode from the shell every time. Can
anyone tell me why Python wouldn't be able to get the correct
returncode for asadmin?


The last exit code set by a command *should* propagate as the exit code of  
the whole .bat, then as the exit code of the cmd.exe instance that runs  
it, and finally Python *should* receive that value. Some old Windows  
versions didn't behave like that, but AFAIK XP does the right thing here.

Unless asadmin.bat is playing tricks with %ERRORLEVEL% or something.
Can you post the contents of asadmin.bat?

Without looking into it, I can think of a few alternatives:

- rewrite asadmin.bat in Python, if feasible. Some scripts just check/set  
a few environment variables and execute some process at the end, and  
that's all; in this case it should be easy to emulate the same thing in  
Python.


- try using another layer of your own, e.g., my_asadmin.bat:

call asadmin.bat %*
exit /b %ERRORLEVEL%

- variation: write the exit code somewhere:

call asadmin.bat %*
echo %ERRORLEVEL% > asadmin.err

and read asadmin.err from Python. (I've used something like this in a  
chain Win32 process --> 16 bits GUI application --> .bat script --> old  
DOS executable)


--
Gabriel Genellina

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


Re: return multiple objects

2009-02-05 Thread Chris Rebert
On Thu, Feb 5, 2009 at 7:03 PM, Vincent Davis  wrote:
> Is it correct that if I want to return multiple objects from a function I
> need to in some way combine them?
> def test1():
> a = [1,3,5,7]
> b = [2,4,6,8]
> c=[a,b]
>return a, b # this does not work?
>return [a, b] # does not work?
>return c # this works but I don't like it, , is there a better way?

All 3 of those *do work* just fine.
I suspect you happen to not be familiar with how to retrieve the
multiple results.

Here's how:

q, w = test1()
print q # prints [1,3,5,7]
print w # prints [2,4,6,8]

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


return multiple objects

2009-02-05 Thread Vincent Davis
Is it correct that if I want to return multiple objects from a function I
need to in some way combine them?
def test1():
a = [1,3,5,7]
b = [2,4,6,8]
c=[a,b]
   return a, b # this does not work?
   return [a, b] # does not work?
   return c # this works but I don't like it, , is there a better way?

I saw examples where dictionaries where used but I would prefer to
just access the object names directly. As in

test1()
print a # not haing to refer to it as

is there something I am missing?


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


Re: Flattening lists

2009-02-05 Thread Benjamin Peterson
mk  gmail.com> writes:
> Hmm, I'm surprised by even that! Apparently list creation is more 
> expensive than I thought - it seems somewhat more expensive than the 
> cost of interpreting bytecode for "if var is None". Either list creation 
> is somewhat costly, or "if var is None" is really cheap.

Creating a list requires several function calls on the C level (including the
dictionary lookup for the name "list") and memory allocation, which is usually
quite expensive. In contrast, the eval loop for "is None" basically uses a
pointer comparison.




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


Re: Converting numbers to words

2009-02-05 Thread Steve Holden
todp...@hotmail.com wrote:
> I've been trying to figure this out for over 2 hours and I'm really
> frustrated right now.
> 
> I first made Python to ask user to input height in meters. If user puts
> certain value in meter, then it converts it to feet and inches as follows:
>  
> 
> Enter the height (in metres): 1.6
> 
> It is 5 feet, 3 inches high.
>  
>  
> What I want to do is to make it type only words. For example, instead of
> its saying, "It is 5 feet, 3 inches high," I want it to say, "it is five
> feet, three inches high."
> I'd appreciate any suggestions.

Create a list or tuple of strings, and use the numbers to index the list.

lst = ['a', 'b', 'c']
ndx = 1
print "The letter", lst[ndx], "is number one"

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: MacPython 3.0 dmg installer?

2009-02-05 Thread Benjamin Peterson
Con  gmail.com> writes:

> 
> Hi, I was wondering, what's the status of the MacPython 3.0 installer
> (.i.e. dmg file) ?  I have been using the previous MacPython dmg
> installers with great success  without conflicting with other
> installations on the system.

There should be ones for 3.0.1 which is coming out within the next few weeks.




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


Re: sorting for recursive folder rename

2009-02-05 Thread ianaré
On Dec 16 2008, 7:36 pm, "Rhodri James" 
wrote:
> On Tue, 16 Dec 2008 18:20:52 -, ianaré  wrote:
> > Hello all,
>
> > I trying to recursivelyrenamefolders and files, and am looking for
> > some ideas on the best way of doing this. The problem is that the
> > given list of items can be in order, and one to all items may be
> > renamed. Here is some preliminary code I have, but which does not work
> > very well.

self.toRename has the following structure :
[
[original_name, new_name, os.path.isdir]
..
]

# define these here for faster processing
def split(item):
return os.path.split(item)
def addSep(path):
return os.sep + path + os.sep
def recursiveFolderSort(x,y):
return cmp(y[0], x[0])

sortedRename = sorted(self.toRename)

# make a list of all folders that will be processed
foldersToAdjust = []
for item in sortedRename:
if item[2] is False:
oF = split(item[0])[1] # original folder name
nF = split(item[1])[1] # new folder name
if oF is not nF:
foldersToAdjust.append((oF, nF))

# replace all occurences of folders in path
for i in range(len(self.toRename)):
for f in foldersToAdjust:
oF = addSep(f[0]) # original folder name
nF = addSep(f[1]) # new folder name
self.toRename[i][0] = self.toRename[i][0].replace(oF,nF)
self.toRename[i][1] = self.toRename[i][1].replace(oF,nF)

if progressDialog.update(i) is False:
error = 'cancelled'
break

# make sure renaming will be in correct order !
self.toRename.sort(recursiveFolderSort)

> import os
>
> for item in self.toRename:
>      os.renames(item[0], item[1])
>
> That's it.  os.renames will take care of all the intermediate
> directory creation so you don't even need to sort the list.
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses

It's been a while since I decided to work on this again ...

Anyway, if only it were that easy !!

Traceback (most recent call last):
  File "/home/ianare/Desktop/file-folder-ren/metamorphose2/Source/
MainWindow.py", line 1477, in renameItems
os.renames(original[0], renamed[0])
  File "/usr/lib/python2.5/os.py", line 213, in renames
rename(old, new)
OSError: [Errno 2] No such file or directory


The problem is that if a directory is changed, all lower instances
need to be changed as well.

given the following directory structure ...

recursive
|
|_1
|  |_1
|  |  |_1.txt
|  |  |_2.txt
|  |_2
| |_1.txt
| |_2.txt
|_2
   |_1
   |  |_1.txt
   |  |_2.txt
   |_2
  |_1.txt
  |_2.txt

... and assuming I want to change :
recursive/2/2/2.txt  -->  recursive/2/2/14.txt

but, I ALSO want to change :
recursive/2  -->  recursive/04

it means that the first operation is really :
recursive/04/2/2.txt  -->  recursive/04/2/14.txt

os.renames will work, but it needs to have the correct path, so it
comes down to the same thing.

IOW, I need a way of :
A) adjusting paths taking into consideration all changes up and down
the tree
B) sorting normalized paths so they are renamed in the proper sequence
(depends on point 'A', obviously)

I'm pretty sure I can take care of 'B' with the following sorting
method:

# order by path depth
def recursiveFolderSort(x, y):
x = x[0].count(os.sep)
y = y[0].count(os.sep)
return cmp(x, y)
self.toRename.sort(recursiveFolderSort)

but I still need a way of generating the correct names.

Solution finder will have his/her name placed on the credits page.
http://file-folder-ren.sourceforge.net/index.php?page=Links

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


ANN: Nucular full text indexing 0.4

2009-02-05 Thread Aaron Watters
ANNOUNCING NUCULAR 0.4
==

This release adds a simple "table space" wrapper
which makes Nucular easier to use for some
purposes.  It also fixes a number of bugs.

WHERE IS IT?

Find documentation and downloads at

  http://nucular.sourceforge.net/

WHAT IS IT?

Nucular is a system for creating full text
indices for fielded data. It can be accessed
via a Python API or via a suite of command
line interfaces.

Nucular archives fielded documents and
retrieves them based on field value, field
prefix, field word prefix, or full text
word prefix, word proximity or combinations
of these. Nucular also includes features
for determining values related to a query
often called query facets.

FEATURES

* Nucular is very light weight.
Updates and accesses do not require
any server process or other system
support such as shared memory locking.

* Nucular supports concurrency.
Arbitrary concurrent updates and
accesses by multiple processes or
threads are supported, with no
possible locking issues.

* Nucular indexes and retrieves
data quickly.

* Nucular has a funny name.

NOTES

The file storage format for this release is
not compatible with older formats (the change
was needed to fix a bug).

On Windows XP I had to delete the old
package manually from the Python library
before the install for the new package
would work properly.

I hope you like it.

   -- Aaron Watters

===
Fear has several advantages over gratitude.
Gratitude is intrinsically limited,
if only by the finite creative capacity of
the scientific community. Moreover, as
pointed out by a colleague at MIT, appealing
to people’s gratitude and trust is usually
less effective than pulling a gun.
  -- Richard Lindzen
--
http://mail.python.org/mailman/listinfo/python-list


Converting numbers to words

2009-02-05 Thread todp...@hotmail.com

I've been trying to figure this out for over 2 hours and I'm really frustrated 
right now.I first made Python to ask user to input height in meters. If user 
puts certain value in meter, then it converts it to feet and inches as follows: 
Enter the height (in metres): 1.6It is 5 feet, 3 inches high.  What I want to 
do is to make it type only words. For example, instead of its saying, "It is 5 
feet, 3 inches high," I want it to say, "it is five feet, three inches 
high."I'd appreciate any suggestions.
_
Twice the fun—Share photos while you chat with Windows Live Messenger.
http://www.microsoft.com/windows/windowslive/messenger.aspx--
http://mail.python.org/mailman/listinfo/python-list


MacPython 3.0 dmg installer?

2009-02-05 Thread Con
Hi, I was wondering, what's the status of the MacPython 3.0 installer
(.i.e. dmg file) ?  I have been using the previous MacPython dmg
installers with great success  without conflicting with other
installations on the system.

Thanks in advance,

-Conrad


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


Re: Use list name as string

2009-02-05 Thread Rhodri James
On Thu, 05 Feb 2009 03:32:59 -, Vincent Davis  
 wrote:



"The problem is you seem to be thinking in terms of objects having names.
They don't.  Names have objects."I agree this is my problem. This is not
correct terminology then?
The name of the object is anobject


No.  The name of the object is a name.  It doesn't really exist as an
object at all.

As others have said, if you really want this information you'll need to
write your own class with a "name" attribute, and assign a suitable string
to it.

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


Re: global name 'sqrt' is not defined

2009-02-05 Thread Robert Kern

On 2009-02-05 18:55, James Mills wrote:

On Fri, Feb 6, 2009 at 10:48 AM, Nick Matzke  wrote:

(PS: Is there a way to force a complete reload of a module, without exiting
ipython?  Just doing the import command again doesn't seem to do it.)


m = __import__("mymobile")
reload(m)


Or more straightforwardly:

  import mymobile
  reload(mymobile)

If you have done

  from mymobile import *

anywhere, you will need to re-execute that line again.

--
Robert Kern

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

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


Re: Where to host a (Python) project?

2009-02-05 Thread Ben Finney
a...@pythoncraft.com (Aahz) writes:

> In article 
> <6dcb8ce5-c93e-458c-9047-e5db60f27...@v18g2000pro.googlegroups.com>,
> andrew cooke   wrote:
> >hi, just fyi, i investigated this and you can join any publicly
> >readable group by sending an email to the "-subscribe" address. you
> >do not need a google login for this and, as far as i can tell, it
> >then operates for you like a normal mailing list.
> 
> The same thing is theoretically true for Yahoo groups, but I've
> heard from people over the years about various difficulties fixing
> problems with list subscriptions in the absence of a real Yahoo
> login and I'm not particularly interested in finding out that the
> same thing ends up being true for Google lists.

Indeed it does. I have succeeded in subscribing to Google mailing
lists in the absence of a Google account, but *managing* that
subscription thereafter in the absence of a Google account is
obnoxiously difficult. Your caution is well advised.

-- 
 \“I got fired from my job the other day. They said my |
  `\  personality was weird. … That's okay, I have four more.” |
_o__)   —Bug-Eyed Earl, _Red Meat_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: where clause

2009-02-05 Thread Rhodri James

On Thu, 05 Feb 2009 18:04:35 -,  wrote:


p = a / b
  where
a = 20 / len(c)
b = foo(d)


You'd want to do it with paired keywords, in the manner of try/except,
to avoid utterly breaking Python's syntax conventions.  Perhaps
something like this:

do:
  p = a / b
where:
  a = 20 / len(c)
  b = foo(d)

or even:

where:
  a = 20 / len(c)
  b = foo(d)
do:
  p = a / b


Effectively you're creating a little local namespace for temporary
variables.  I'm not sure it buys you a lot, even as sugar, and I'm
really not convinced by the bypartite form, but it's definitely
possible.

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


Re: global name 'sqrt' is not defined

2009-02-05 Thread James Mills
On Fri, Feb 6, 2009 at 10:48 AM, Nick Matzke  wrote:
> (PS: Is there a way to force a complete reload of a module, without exiting
> ipython?  Just doing the import command again doesn't seem to do it.)

m = __import__("mymobile")
reload(m)

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


Re: subprocess returncode windows

2009-02-05 Thread Mark Hammond

On 6/02/2009 6:34 AM, Andrew wrote:

Notice how python never gets the correct returncode from asadmin.bat
but I can get the correct returncode from the shell every time. Can
anyone tell me why Python wouldn't be able to get the correct
returncode for asadmin?


I think the problem will be that cmd.exe doesn't return the exit code to 
*its* caller correctly.  You can often work around this by avoiding the 
use of cmd.exe to spawn the child process, but obviously you do need it 
with a .bat file.  I'm not aware of an easy work-around.


Cheers,

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


Re: global name 'sqrt' is not defined

2009-02-05 Thread Nick Matzke
OK, so the problem was that I had to exit ipython, re-enter it, and then 
import my module to get the errors to disappear.  Thanks for the help!


(PS: Is there a way to force a complete reload of a module, without 
exiting ipython?  Just doing the import command again doesn't seem to do 
it.)


Thanks!
Nick


Diez B. Roggisch wrote:

Nick Matzke schrieb:



Scott David Daniels wrote:

M.-A. Lemburg wrote:

On 2009-02-05 10:08, Nick Matzke wrote:

..., I can run this in the ipython shell just fine:
a = ["12", "15", "16", "38.2"]
dim = int(sqrt(size(a)))
...But if I move these commands to a function in another file, it 
freaks out:

You need to add:

from math import sqrt

or:
from cmath import sqrt
or:
from numpy import sqrt






The weird thing is, when I do this, I still get the error:


n...@mws2[phylocom]|27> a = ["12", "15", "16", "38.2"]
n...@mws2[phylocom]|28> from LR_run_functions_v2 import 
make_half_square_array

n...@mws2[phylocom]|24> d = make_half_square_array(a)
--- 

NameError Traceback (most recent call 
last)


/bioinformatics/phylocom/ in ()

/bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in 
make_half_square_array(linear_version_of_square_array)

   1548 from numpy import sqrt
   1549 a = linear_version_of_square_array
-> 1550 dim = int(sqrt(size(a)))
   1551
   1552

NameError: global name 'sqrt' is not defined
n...@mws2[phylocom]|25>


Is there some other place I should put the import command?  I.e.:
1. In the main script/ipython command line

2. In the called function, i.e. make_half_square_array() in 
LR_run_functions_v2.py


3. At the top of LR_run_functions_v2.py, outside of the individual 
functions?


The latter. Python's imports are always local to the module/file they 
are in, not globally effective.



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



--

Nicholas J. Matzke
Ph.D. student, Graduate Student Researcher
Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370

Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264
Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140

-
"[W]hen people thought the earth was flat, they were wrong. When people 
thought the earth was spherical, they were wrong. But if you think that 
thinking the earth is spherical is just as wrong as thinking the earth 
is flat, then your view is wronger than both of them put together."


Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 
14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

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


Using multiprocessing from a Windows service

2009-02-05 Thread Volodya
Hi all,

I think I've found a small bug with multiprocessing package on
Windows. If you try to start a multiprocessing.Process from a Python-
based Windows service, the child process will fail to run. When
running the parent process as a regular Python program, everything
works as expected.

I've tracked the problem down to how main_path is prepared in
multiprocessing.forking.get_preparation_data() (lines 370-377):

def get_preparation_data(name):
[...skipped a few lines...]
if not WINEXE:
main_path = getattr(sys.modules['__main__'], '__file__', None)
if not main_path and sys.argv[0] not in ('', '-c'):
main_path = sys.argv[0]
if main_path is not None:
if not os.path.isabs(main_path) and \
  process.ORIGINAL_DIR is not
None:
main_path = os.path.join(process.ORIGINAL_DIR,
main_path)
d['main_path'] = os.path.normpath(main_path)
return d

When the program is running as a Windows service, but is not packaged
into a single executable, main_path will become the path to the
service executable (typically, pythonservice.exe). When this data
makes it to the child process, the prepare() function will treat
main_path as a path to a python module, and will try to import it.
This causes it to fail.

My quick-and-dirty solution was to check in get_preparation_data() if
main_path ends with '.exe', and if it does, to not pass it at all.
This solves the problem in my case, but perhaps there's a better way
to fix this? Here is my version of get_preparation_data():

def get_preparation_data(name):
'''
Return info about parent needed by child to unpickle process
object
'''
from .util import _logger, _log_to_stderr

d = dict(
name=name,
sys_path=sys.path,
sys_argv=sys.argv,
log_to_stderr=_log_to_stderr,
orig_dir=process.ORIGINAL_DIR,
authkey=process.current_process().authkey,
)

if _logger is not None:
d['log_level'] = _logger.getEffectiveLevel()

if not WINEXE:
main_path = getattr(sys.modules['__main__'], '__file__', None)
if not main_path and sys.argv[0] not in ('', '-c'):
main_path = sys.argv[0]
if main_path is not None:
if not os.path.isabs(main_path) and \
  process.ORIGINAL_DIR is not
None:
main_path = os.path.join(process.ORIGINAL_DIR,
main_path)
if not main_path.endswith('.exe'):
d['main_path'] = os.path.normpath(main_path)

return d


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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Terry Reedy

Mensanator wrote:

On Feb 5, 4:20 pm, Terry Reedy  wrote:

mk wrote:


(duck)
542 comp.lang.python rtfm

What is so unfriendly about 'read the fine manual'?


You've seen a fine manual?


Yes, and I and others have spent hours and hours making the Python 
manuals finer.


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


Re: Skipping bytes while reading a binary file?

2009-02-05 Thread Lionel
On Feb 5, 3:35 pm, Lionel  wrote:
> On Feb 5, 2:56 pm, Lionel  wrote:
>
>
>
>
>
> > On Feb 5, 2:48 pm, MRAB  wrote:
>
> > > Lionel wrote:
>
> > >  > Hello,
> > >  > I have data stored in binary files. Some of these files are
> > >  > huge...upwards of 2 gigs or more. They consist of 32-bit float complex
> > >  > numbers where the first 32 bits of the file is the real component, the
> > >  > second 32bits is the imaginary, the 3rd 32-bits is the real component
> > >  > of the second number, etc.
> > >  >
> > >  > I'd like to be able to read in just the real components, load them
> > >  > into a numpy.ndarray, then load the imaginary coponents and load them
> > >  > into a numpy.ndarray.  I need the real and imaginary components stored
> > >  > in seperate arrays, they cannot be in a single array of complex
> > >  > numbers except for temporarily. I'm trying to avoid temporary storage,
> > >  > though, because of the size of the files.
> > >  >
> > >  > I'm currently reading the file scanline-by-scanline to extract rows of
> > >  > complex numbers which I then loop over and load into the real/
> > >  > imaginary arrays as follows:
> > >  >
> > >  >
> > >  >         self._realData         = numpy.empty((Rows, Columns), dtype =
> > >  > numpy.float32)
> > >  >         self._imaginaryData = numpy.empty((Rows, Columns), dtype =
> > >  > numpy.float32)
> > >  >
> > >  >         floatData = array.array('f')
> > >  >
> > >  >         for CurrentRow in range(Rows):
> > >  >
> > >  >             floatData.fromfile(DataFH, (Columns*2))
> > >  >
> > >  >             position = 0
> > >  >             for CurrentColumn in range(Columns):
> > >  >
> > >  >                  self._realData[CurrentRow, CurrentColumn]          =
> > >  > floatData[position]
> > >  >                 self._imaginaryData[CurrentRow, CurrentColumn]  =
> > >  > floatData[position+1]
> > >  >                 position = position + 2
> > >  >
> > >  >
> > >  > The above code works but is much too slow. If I comment out the body
> > >  > of the "for CurrentColumn in range(Columns)" loop, the performance is
> > >  > perfectly adequate i.e. function call overhead associated with the
> > >  > "fromfile(...)" call is not very bad at all. What seems to be most
> > >  > time-consuming are the simple assignment statements in the
> > >  > "CurrentColumn" for-loop.
> > >  >
> > > [snip]
> > > Try array slicing. floatData[0::2] will return the real parts and
> > > floatData[1::2] will return the imaginary parts. You'll have to read up
> > > how to assign to a slice of the numpy array (it might be
> > > "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow,
> > > :] = real_parts").
>
> > > BTW, it's not the function call overhead of fromfile() which takes the
> > > time, but actually reading data from the file.
>
> > Very nice! I like that! I'll post the improvement (if any).
>
> > L- Hide quoted text -
>
> > - Show quoted text -
>
> Okay, the following:
>
>             self._realData[CurrentRow]      = floatData[0::2]
>             self._imaginaryData[CurrentRow] = floatData[1::2]
>
> gives a 3.5x improvement in execution speed over the original that I
> posted. That's much better. Thank you for the suggestion.
>
> L- Hide quoted text -
>
> - Show quoted text -

Correction: improvement is around 7-8x.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Skipping bytes while reading a binary file?

2009-02-05 Thread Lionel
On Feb 5, 2:56 pm, Lionel  wrote:
> On Feb 5, 2:48 pm, MRAB  wrote:
>
>
>
>
>
> > Lionel wrote:
>
> >  > Hello,
> >  > I have data stored in binary files. Some of these files are
> >  > huge...upwards of 2 gigs or more. They consist of 32-bit float complex
> >  > numbers where the first 32 bits of the file is the real component, the
> >  > second 32bits is the imaginary, the 3rd 32-bits is the real component
> >  > of the second number, etc.
> >  >
> >  > I'd like to be able to read in just the real components, load them
> >  > into a numpy.ndarray, then load the imaginary coponents and load them
> >  > into a numpy.ndarray.  I need the real and imaginary components stored
> >  > in seperate arrays, they cannot be in a single array of complex
> >  > numbers except for temporarily. I'm trying to avoid temporary storage,
> >  > though, because of the size of the files.
> >  >
> >  > I'm currently reading the file scanline-by-scanline to extract rows of
> >  > complex numbers which I then loop over and load into the real/
> >  > imaginary arrays as follows:
> >  >
> >  >
> >  >         self._realData         = numpy.empty((Rows, Columns), dtype =
> >  > numpy.float32)
> >  >         self._imaginaryData = numpy.empty((Rows, Columns), dtype =
> >  > numpy.float32)
> >  >
> >  >         floatData = array.array('f')
> >  >
> >  >         for CurrentRow in range(Rows):
> >  >
> >  >             floatData.fromfile(DataFH, (Columns*2))
> >  >
> >  >             position = 0
> >  >             for CurrentColumn in range(Columns):
> >  >
> >  >                  self._realData[CurrentRow, CurrentColumn]          =
> >  > floatData[position]
> >  >                 self._imaginaryData[CurrentRow, CurrentColumn]  =
> >  > floatData[position+1]
> >  >                 position = position + 2
> >  >
> >  >
> >  > The above code works but is much too slow. If I comment out the body
> >  > of the "for CurrentColumn in range(Columns)" loop, the performance is
> >  > perfectly adequate i.e. function call overhead associated with the
> >  > "fromfile(...)" call is not very bad at all. What seems to be most
> >  > time-consuming are the simple assignment statements in the
> >  > "CurrentColumn" for-loop.
> >  >
> > [snip]
> > Try array slicing. floatData[0::2] will return the real parts and
> > floatData[1::2] will return the imaginary parts. You'll have to read up
> > how to assign to a slice of the numpy array (it might be
> > "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow,
> > :] = real_parts").
>
> > BTW, it's not the function call overhead of fromfile() which takes the
> > time, but actually reading data from the file.
>
> Very nice! I like that! I'll post the improvement (if any).
>
> L- Hide quoted text -
>
> - Show quoted text -


Okay, the following:

self._realData[CurrentRow]  = floatData[0::2]
self._imaginaryData[CurrentRow] = floatData[1::2]

gives a 3.5x improvement in execution speed over the original that I
posted. That's much better. Thank you for the suggestion.

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


Re: updating nntplib

2009-02-05 Thread Travis
On Thu, Feb 05, 2009 at 04:40:36PM -0600, Travis wrote:
> 2) In some cases, it will bomb out upon receiving certain greetings
> that it doesn't expect.  As I understand it, it actually terminates
> the connection, not allowing for catching an exception or anything.
> I have not verified this myself.

I just verified this; if the server responds to authentication with
the string "200 Welcome feeder", then nntplib bombs out with a:

nntplib.NNTPPermanentError

IMHO, it shouldn't be sensitive to anything but the numeric code,
and 200 indicates success.
-- 
Crypto ergo sum.  http://www.subspacefield.org/~travis/
Do unto other faiths as you would have them do unto yours.
If you are a spammer, please email j...@subspacefield.org to get blacklisted.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is the subprocess module robust enough in 2.4?

2009-02-05 Thread James Mills
On Fri, Feb 6, 2009 at 2:20 AM,   wrote:
> The subprocess module was added in Python 2.4.  I'm running 2.4.5 at work.
> I know it's seen many bugfixes since first released.  Is the version in 2.4
> robust enough to use in preference to os.popen and friends?

"Is xxx rubust enough" is an untangible question.
What you really -should- be doing is looking at the
bug reports (as you've mentioned) and determine whether
or not they will affect your use-case(s) in any way.

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


Re: Skipping bytes while reading a binary file?

2009-02-05 Thread Lionel
On Feb 5, 2:48 pm, MRAB  wrote:
> Lionel wrote:
>
>  > Hello,
>  > I have data stored in binary files. Some of these files are
>  > huge...upwards of 2 gigs or more. They consist of 32-bit float complex
>  > numbers where the first 32 bits of the file is the real component, the
>  > second 32bits is the imaginary, the 3rd 32-bits is the real component
>  > of the second number, etc.
>  >
>  > I'd like to be able to read in just the real components, load them
>  > into a numpy.ndarray, then load the imaginary coponents and load them
>  > into a numpy.ndarray.  I need the real and imaginary components stored
>  > in seperate arrays, they cannot be in a single array of complex
>  > numbers except for temporarily. I'm trying to avoid temporary storage,
>  > though, because of the size of the files.
>  >
>  > I'm currently reading the file scanline-by-scanline to extract rows of
>  > complex numbers which I then loop over and load into the real/
>  > imaginary arrays as follows:
>  >
>  >
>  >         self._realData         = numpy.empty((Rows, Columns), dtype =
>  > numpy.float32)
>  >         self._imaginaryData = numpy.empty((Rows, Columns), dtype =
>  > numpy.float32)
>  >
>  >         floatData = array.array('f')
>  >
>  >         for CurrentRow in range(Rows):
>  >
>  >             floatData.fromfile(DataFH, (Columns*2))
>  >
>  >             position = 0
>  >             for CurrentColumn in range(Columns):
>  >
>  >                  self._realData[CurrentRow, CurrentColumn]          =
>  > floatData[position]
>  >                 self._imaginaryData[CurrentRow, CurrentColumn]  =
>  > floatData[position+1]
>  >                 position = position + 2
>  >
>  >
>  > The above code works but is much too slow. If I comment out the body
>  > of the "for CurrentColumn in range(Columns)" loop, the performance is
>  > perfectly adequate i.e. function call overhead associated with the
>  > "fromfile(...)" call is not very bad at all. What seems to be most
>  > time-consuming are the simple assignment statements in the
>  > "CurrentColumn" for-loop.
>  >
> [snip]
> Try array slicing. floatData[0::2] will return the real parts and
> floatData[1::2] will return the imaginary parts. You'll have to read up
> how to assign to a slice of the numpy array (it might be
> "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow,
> :] = real_parts").
>
> BTW, it's not the function call overhead of fromfile() which takes the
> time, but actually reading data from the file.

Very nice! I like that! I'll post the improvement (if any).

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


updating nntplib

2009-02-05 Thread Travis
Hello all,

There are some notable deficiencies in nntlib.  Here are two:

1) It says it implements NNTP as defined in RFC 977, but NNTP
has a newer RFC, RFC 3977, which clarifies some vagueness and
has more commands defined.  However, as it currently stands you
cannot issue these commands, since they aren't available to
call.

2) In some cases, it will bomb out upon receiving certain greetings
that it doesn't expect.  As I understand it, it actually terminates
the connection, not allowing for catching an exception or anything.
I have not verified this myself.

I'd like to remedy these deficiencies.  In the case of #1, I'd
like to implement some of the new commands and provide a way to
send arbitrary commands to the server, because NNTP is designed
to allow servers to implement optional features.

I'm not sure how I'll remedy #2, but I imagine it will be clear
once I examine the code.

I am guessing that this is the right list for discussing this,
but perhaps python-dev is better.  Anyone have feedback?
-- 
Crypto ergo sum.  http://www.subspacefield.org/~travis/
Do unto other faiths as you would have them do unto yours.
If you are a spammer, please email j...@subspacefield.org to get blacklisted.
--
http://mail.python.org/mailman/listinfo/python-list


Re: HOWTO for setting up a PyQt project in Eclipse ?

2009-02-05 Thread David Boddie
On Thursday 05 February 2009 18:13, Linuxguy123 wrote:

> Does anyone know of a HOWTO for setting up a PyQt project in Eclipse ?
> 
> I know about setting up a PyDev project, just wondering how to integrate
> the QtDesigner parts.
> 
> For example, should I save the QtDesigner project in the root PyDev
> directory ?

I'm not an Eclipse user, but I recently noticed that the Python(x,y)
project uses (or at least refers to) both PyQt and PyDev. Maybe there's
some useful information, or useful starting points, on these pages:

  http://pythonxy.com/help.php
  http://pythonxy.com/discussions.php

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


Re: Skipping bytes while reading a binary file?

2009-02-05 Thread MRAB

Lionel wrote:
> Hello,
> I have data stored in binary files. Some of these files are
> huge...upwards of 2 gigs or more. They consist of 32-bit float complex
> numbers where the first 32 bits of the file is the real component, the
> second 32bits is the imaginary, the 3rd 32-bits is the real component
> of the second number, etc.
>
> I'd like to be able to read in just the real components, load them
> into a numpy.ndarray, then load the imaginary coponents and load them
> into a numpy.ndarray.  I need the real and imaginary components stored
> in seperate arrays, they cannot be in a single array of complex
> numbers except for temporarily. I'm trying to avoid temporary storage,
> though, because of the size of the files.
>
> I'm currently reading the file scanline-by-scanline to extract rows of
> complex numbers which I then loop over and load into the real/
> imaginary arrays as follows:
>
>
> self._realData = numpy.empty((Rows, Columns), dtype =
> numpy.float32)
> self._imaginaryData = numpy.empty((Rows, Columns), dtype =
> numpy.float32)
>
> floatData = array.array('f')
>
> for CurrentRow in range(Rows):
>
> floatData.fromfile(DataFH, (Columns*2))
>
> position = 0
> for CurrentColumn in range(Columns):
>
>  self._realData[CurrentRow, CurrentColumn]  =
> floatData[position]
> self._imaginaryData[CurrentRow, CurrentColumn]  =
> floatData[position+1]
> position = position + 2
>
>
> The above code works but is much too slow. If I comment out the body
> of the "for CurrentColumn in range(Columns)" loop, the performance is
> perfectly adequate i.e. function call overhead associated with the
> "fromfile(...)" call is not very bad at all. What seems to be most
> time-consuming are the simple assignment statements in the
> "CurrentColumn" for-loop.
>
[snip]
Try array slicing. floatData[0::2] will return the real parts and
floatData[1::2] will return the imaginary parts. You'll have to read up 
how to assign to a slice of the numpy array (it might be 
"self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow, 
:] = real_parts").


BTW, it's not the function call overhead of fromfile() which takes the
time, but actually reading data from the file.

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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Steve Holden
Mensanator wrote:
> On Feb 5, 4:20 pm, Terry Reedy  wrote:
>> mk wrote:
>>
>>> (duck)
>>> 542 comp.lang.python rtfm
>> What is so unfriendly about 'read the fine manual'?
> 
> You've seen a fine manual?

Yes, and I'm fine well sure this is somewhere between a silly thread and
a troll.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Skipping bytes while reading a binary file?

2009-02-05 Thread Lionel
On Feb 5, 2:22 pm, Lionel  wrote:
> Hello,
> I have data stored in binary files. Some of these files are
> huge...upwards of 2 gigs or more. They consist of 32-bit float complex
> numbers where the first 32 bits of the file is the real component, the
> second 32bits is the imaginary, the 3rd 32-bits is the real component
> of the second number, etc.
>
> I'd like to be able to read in just the real components, load them
> into a numpy.ndarray, then load the imaginary coponents and load them
> into a numpy.ndarray.  I need the real and imaginary components stored
> in seperate arrays, they cannot be in a single array of complex
> numbers except for temporarily. I'm trying to avoid temporary storage,
> though, because of the size of the files.
>
> I'm currently reading the file scanline-by-scanline to extract rows of
> complex numbers which I then loop over and load into the real/
> imaginary arrays as follows:
>
>         self._realData         = numpy.empty((Rows, Columns), dtype =
> numpy.float32)
>         self._imaginaryData = numpy.empty((Rows, Columns), dtype =
> numpy.float32)
>
>         floatData = array.array('f')
>
>         for CurrentRow in range(Rows):
>
>             floatData.fromfile(DataFH, (Columns*2))
>
>             position = 0
>             for CurrentColumn in range(Columns):
>
>                  self._realData[CurrentRow, CurrentColumn]          =
> floatData[position]
>                 self._imaginaryData[CurrentRow, CurrentColumn]  =
> floatData[position+1]
>                 position = position + 2
>
> The above code works but is much too slow. If I comment out the body
> of the "for CurrentColumn in range(Columns)" loop, the performance is
> perfectly adequate i.e. function call overhead associated with the
> "fromfile(...)" call is not very bad at all. What seems to be most
> time-consuming are the simple assignment statements in the
> "CurrentColumn" for-loop.
>
> Does anyone see any ways of speeding this up at all? Reading
> everything into a complex64 ndarray in one fell swoop would certainly
> be easier and faster, but at some point I'll need to split this array
> into two parts (real / imaginary). I'd like to have that done
> initially to keep the memory usage down since the files are so
> ginormous.
>
> Psyco is out because I need 64-bits, and I didn't see anything on the
> forums regarding a method that reads in every other 32-bit chunk form
> a file into an array. I'm not sure what else to try.
>
> Thanks in advance.
> L

Hmmm...I've just discovered "weave.inline()". Maybe I'll just do the
assignments in C.

Still soliciting advice, of course. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: kinterbasdb + firebird 1.5 with python 2.6 ?

2009-02-05 Thread Benjamin Kaplan
On Thu, Feb 5, 2009 at 4:42 PM, Laszlo Nagy  wrote:

> Uwe Grauer írta:
>
>> Laszlo Nagy wrote:
>>
>>
>>> Does anyone know how to get firebird 1.5 driver (kinterbasdb) for
>>> FireBird 1.5?
>>>
>>> My problem:
>>>
>>>   * python 2.6 already installed on a server
>>>   * there is a firebird 1.5 database on the same server
>>>   * I need to access it from python 2.6
>>>
>>> Any thoughts?
>>>
>>>
>>>
>>>
>>
>> Get it from here:
>> http://www.firebirdsql.org/index.php?op=devel&sub=python
>>
>>
> Thanks. Unfortunately, this does not support Firebird 1.5 anymore. I can
> only find Python 2.5 + Firebird 1.5. But not for Python 2.6. I'm going to
> downgrade. :-(
>

The prebuilt binaries don't support Firebird 1.5. The installation guide
says that you can compile it from source to get 1.5 support.


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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Mensanator
On Feb 5, 4:20 pm, Terry Reedy  wrote:
> mk wrote:
>
> > (duck)
>
> > 542 comp.lang.python rtfm
>
> What is so unfriendly about 'read the fine manual'?

You've seen a fine manual?
--
http://mail.python.org/mailman/listinfo/python-list


Skipping bytes while reading a binary file?

2009-02-05 Thread Lionel
Hello,
I have data stored in binary files. Some of these files are
huge...upwards of 2 gigs or more. They consist of 32-bit float complex
numbers where the first 32 bits of the file is the real component, the
second 32bits is the imaginary, the 3rd 32-bits is the real component
of the second number, etc.

I'd like to be able to read in just the real components, load them
into a numpy.ndarray, then load the imaginary coponents and load them
into a numpy.ndarray.  I need the real and imaginary components stored
in seperate arrays, they cannot be in a single array of complex
numbers except for temporarily. I'm trying to avoid temporary storage,
though, because of the size of the files.

I'm currently reading the file scanline-by-scanline to extract rows of
complex numbers which I then loop over and load into the real/
imaginary arrays as follows:


self._realData = numpy.empty((Rows, Columns), dtype =
numpy.float32)
self._imaginaryData = numpy.empty((Rows, Columns), dtype =
numpy.float32)

floatData = array.array('f')

for CurrentRow in range(Rows):

floatData.fromfile(DataFH, (Columns*2))

position = 0
for CurrentColumn in range(Columns):

 self._realData[CurrentRow, CurrentColumn]  =
floatData[position]
self._imaginaryData[CurrentRow, CurrentColumn]  =
floatData[position+1]
position = position + 2


The above code works but is much too slow. If I comment out the body
of the "for CurrentColumn in range(Columns)" loop, the performance is
perfectly adequate i.e. function call overhead associated with the
"fromfile(...)" call is not very bad at all. What seems to be most
time-consuming are the simple assignment statements in the
"CurrentColumn" for-loop.

Does anyone see any ways of speeding this up at all? Reading
everything into a complex64 ndarray in one fell swoop would certainly
be easier and faster, but at some point I'll need to split this array
into two parts (real / imaginary). I'd like to have that done
initially to keep the memory usage down since the files are so
ginormous.

Psyco is out because I need 64-bits, and I didn't see anything on the
forums regarding a method that reads in every other 32-bit chunk form
a file into an array. I'm not sure what else to try.

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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Terry Reedy

mk wrote:


(duck)

542 comp.lang.python rtfm


What is so unfriendly about 'read the fine manual'?

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


Re: Ordered dict by default

2009-02-05 Thread Terry Reedy

andrew cooke wrote:

so what is happening with pep 372?

http://www.python.org/dev/peps/pep-0372/


There seems to be a number of unanswered questions as to the exact 
behavior (see Q and A section).  The author needs to promote more 
discussion by those interested, including here, and make a decision.


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


Re: Ordered dict by default

2009-02-05 Thread Terry Reedy

Paul Rubin wrote:

bearophileh...@lycos.com writes:

Now Ruby dicts are ordered by default:
http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/


Maybe I didn't read that carefully enough, but it looks like "ordered"
means the dict records come out in the same order you inserted them
in.  That is if you insert B,A,D,C in that order, you get them out in
that order.


This seems to have become the more common meaning of 'ordered dict'.


 I would have thought an ordered dict meant you get A,B,C,D,
which seems a lot more useful.


I once thought that too, but this would be a 'sorted dict'.

tjr

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


Re: Extracting file from zip archive in Python 2.6.1

2009-02-05 Thread Brandon Taylor
On Feb 4, 12:16 am, "Gabriel Genellina" 
wrote:
> En Wed, 04 Feb 2009 00:36:40 -0200, Brandon Taylor  
>  escribió:
>
>
>
> > On Feb 3, 1:16 pm, Brandon Taylor  wrote:
> >> On Feb 3, 9:45 am, "Gabriel Genellina"  wrote:
> >> > En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor  
> >> >  escribió:
> >> > > zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path)
> >> > > What is happening is that the extract method is creating a folder >  
> >> > with
> >> > > the name of 'zip_name' and extracting the files to it. Example:
> >> > extract will create all directories in member name. Use open instead:
> >> > with zip_file.open(zip_name + '/' + thumbnail_image) as source:
> >> >    with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as  
> >> > target:
> >> >      shutil.copyfileobj(source, target)
> > Ok, the first thing I needed to do was add:
>
> > from __future__ import with_statement at the beginning of my file
>
> That should not be necesary with your Python version (2.6.1 isn't it?)
>
> > with zip_file.open(zip_name + '/' + thumbnail_image) as source:
> >                     with open(os.path.join(thumbnail_path,
> > thumbnail_image), 'wb') as target:
> >                         shutil.copyfileobj(source, target)
>
> > Returns an error on the first line:
>
> > ZipExtFile instance has no attribute '__exit__'
>
> Ouch, sorry, this new feature will appear in the not-yet-released 2.7  
> version...
> Try this instead:
>
> source = zip_file.open(zip_name + '/' + thumbnail_image)
> try:
>    with open(os.path.join(thumbnail_path, thumbnail_image), 'wb') as target:
>      shutil.copyfileobj(source, target)
> finally:
>    source.close()
>
> --
> Gabriel Genellina

Awesome. Works perfectly, and saves me the extra step of having to
move the files.

Many, many thanks!

Kind regards,
Brandon
--
http://mail.python.org/mailman/listinfo/python-list


Re: kinterbasdb + firebird 1.5 with python 2.6 ?

2009-02-05 Thread Laszlo Nagy

Uwe Grauer írta:

Laszlo Nagy wrote:
  

Does anyone know how to get firebird 1.5 driver (kinterbasdb) for
FireBird 1.5?

My problem:

   * python 2.6 already installed on a server
   * there is a firebird 1.5 database on the same server
   * I need to access it from python 2.6

Any thoughts?





Get it from here:
http://www.firebirdsql.org/index.php?op=devel&sub=python
  
Thanks. Unfortunately, this does not support Firebird 1.5 anymore. I can 
only find Python 2.5 + Firebird 1.5. But not for Python 2.6. I'm going 
to downgrade. :-(


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


Re: database wrapper ?

2009-02-05 Thread Mike Orr
On Feb 1, 3:47 pm, Stephen Hansen  wrote:
> Googling, I found SQLalchemy,
> which looks quit good.
> SQLAlchemy is very good. I'm very slowly migrating our entire codebase to it.
>  
>
>
> But as I only want to choose once,
> I googled for  "SQLalchemy alternatives",
> but it didn't find many answers.
> (Storm / Grok are of no interest, because manipulating the structure of the 
> database is a key issue).
> There's a few other alternatives-- if you google "Python ORM" you'll find a 
> lot more, and PyPi might have a list. But IMHO, SQLAlchemy is the best of 
> breed so far. Its very, very flexible and doesn't really impose on you with 
> any rules about how you must do things.
> Storm's not bad, don't get me wrong!
> But one question on your requirements: manipulating the structure of the 
> database. How so? If you mean that you want to be able to modify the object 
> wrapper to change some field of a table and have that change propagated to 
> the database layer... then SQLAlchemy doesn't support that. If you add new 
> tables it'll create them, and it MIGHT add new columns or indexes if you add 
> them after and it notices they aren't there... but I'm not entirely sure on 
> that.

engine.execute("ALTER TABLE ...")

However, this may confuse ORM objects already in memory as well as
transactions, so clear these out both before and afterward.  The
syntax is database specific.  MySQL can add and delete columns and
change a column's type.  SQLite can only rename tables.  However, your
ORM objects won't know about the new columns unless you reinitialize
the Table objects and mapper with autoloading.  So it's best to modify
the schema in a standalone program that does not use the ORM.

As for modifying the columns in the Table objects and propagating the
changes to the database, you can't do that.  You have to execute
"ALTER TABLE" as a string command.  SQLAlchemy would have to add a
whole new layer to deal with alternations at the Table or SQL builder
level, and in the end they're still database specific.


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


Re: where clause

2009-02-05 Thread Paul Rubin
bearophileh...@lycos.com writes:
> Note that where may also be designed to create a new scope (as in
> Haskell, I think), that's why I have inlined the bar and p/b.

In Haskell, "where" is only allowed at the outermost level of a
function definition (including a nested one), not in an arbitrary
expression.
--
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Feb 5)

2009-02-05 Thread Gabriel Genellina
QOTW:  "Findability trumps usability. If you can't find it, you can't use
it." - information architect Robert Morville


Boolean expressions don't necesarily yield a boolean type - and that's
very useful:
http://groups.google.com/group/comp.lang.python/t/e834202d1a6a919/

Using __del__ is rather fragile:
http://groups.google.com/group/comp.lang.python/t/c1e7fccbfd7e5e73/
http://groups.google.com/group/comp.lang.python/t/25d36f0a74245bc4/

Good or bad usage of __repr__?
http://groups.google.com/group/comp.lang.python/t/d7e2b1637db02f2a/

Which OOP concepts apply to the Python language? A long thread, at the
end mostly focused on access restrictions:
http://groups.google.com/group/comp.lang.python/t/abf06e897aacc3d9/

A class implementing an iterator, and how the iterator protocol works:
http://groups.google.com/group/comp.lang.python/t/edaa3cc79a0581ea/

Computing the n-th root of big numbers:
http://groups.google.com/group/comp.lang.python/t/7eb4facfe4b0ffa1/

A list that knows when any of its elements is modified:
http://groups.google.com/group/comp.lang.python/t/4b7f993274ece50d/

Embedding 2.6.1 in Windows doesn't work due to missing C runtime
libraries:
http://groups.google.com/group/comp.lang.python/t/3ec6af1279a162ca/

How to call Python code from another thread written in C:
http://groups.google.com/group/comp.lang.python/t/1d05f3f215346249/

How SQLAlchemy compares to similar ORMs:
http://groups.google.com/group/comp.lang.python/t/547d0a7c0477293c/





Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available, see:
http://www.python.org/channews.rdf
For more, see:
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse
http://ww

Re: global name 'sqrt' is not defined

2009-02-05 Thread Diez B. Roggisch

Nick Matzke schrieb:



Scott David Daniels wrote:

M.-A. Lemburg wrote:

On 2009-02-05 10:08, Nick Matzke wrote:

..., I can run this in the ipython shell just fine:
a = ["12", "15", "16", "38.2"]
dim = int(sqrt(size(a)))
...But if I move these commands to a function in another file, it 
freaks out:

You need to add:

from math import sqrt

or:
from cmath import sqrt
or:
from numpy import sqrt






The weird thing is, when I do this, I still get the error:


n...@mws2[phylocom]|27> a = ["12", "15", "16", "38.2"]
n...@mws2[phylocom]|28> from LR_run_functions_v2 import 
make_half_square_array

n...@mws2[phylocom]|24> d = make_half_square_array(a)
---
NameError Traceback (most recent call last)

/bioinformatics/phylocom/ in ()

/bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in 
make_half_square_array(linear_version_of_square_array)

   1548 from numpy import sqrt
   1549 a = linear_version_of_square_array
-> 1550 dim = int(sqrt(size(a)))
   1551
   1552

NameError: global name 'sqrt' is not defined
n...@mws2[phylocom]|25>


Is there some other place I should put the import command?  I.e.:
1. In the main script/ipython command line

2. In the called function, i.e. make_half_square_array() in 
LR_run_functions_v2.py


3. At the top of LR_run_functions_v2.py, outside of the individual 
functions?


The latter. Python's imports are always local to the module/file they 
are in, not globally effective.



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


Re: tkSimpleDialog window focus problem

2009-02-05 Thread inkhorn
After much tinkering, I figured out the problem.  Before the call to
the ftp.login function, I had another simpledialog asking for a
userid.  The focus was leaving the parent Tk window altogether right
after userid entry.  So, right after the call to obtain the userid
from the user, i called the Frame.focus_force() method.  Observe:

self.userid = tkSimpleDialog.askstring("UTSCID Entry","UTSCID:")
self.focus_force()

Now, the next tkSimpleDialog.askstring call that I made ACTUALLY gets
the keyboard focus automatically.

Cheers,
Matt


On Feb 4, 10:21 am, inkhorn  wrote:
> Hi all,
>
> As part of the program I've created and am maintaining, the user has
> to type in his/her username and password into tkinter simple dialog
> windows.  What you'll see below is that I've nested an askstring
> dialog window within a call to use the ftp module to login to an FTP
> server.
>
> result = self.ftp.login(self.userid, tkSimpleDialog.askstring
> ("Password Entry",
>                                               "Password:", show="*"))
>
> Annoyingly, every time this password entry window pops up, the focus
> does not go on it automatically.  Anyone know what I can do to put the
> focus on it automatically, while *not* storing the user's password in
> my script for the remainder of its runtime?
>
> Thanks,
> Matt Dubins

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


Re: Python Integrated Parallel Pipeline EnviRonment: PIPPER

2009-02-05 Thread Kyle
PIPPER doesn't yet have a very large user base, and is still in
Alpha.  So if there is enough demand, syntax changes would still be
possible at this stage.

Kyle

> I'm not a big fan of comments that change semantics. Wouldn't a modified
> 'with' statement look better?
>
> We have a couple of other syntax proposals in the Cython Wiki.
>
> http://wiki.cython.org/enhancements/parallel
>
> Stefan

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


Re: global name 'sqrt' is not defined

2009-02-05 Thread Nick Matzke



Scott David Daniels wrote:

M.-A. Lemburg wrote:

On 2009-02-05 10:08, Nick Matzke wrote:

..., I can run this in the ipython shell just fine:
a = ["12", "15", "16", "38.2"]
dim = int(sqrt(size(a)))
...But if I move these commands to a function in another file, it 
freaks out:

You need to add:

from math import sqrt

or:
from cmath import sqrt
or:
from numpy import sqrt






The weird thing is, when I do this, I still get the error:


n...@mws2[phylocom]|27> a = ["12", "15", "16", "38.2"]
n...@mws2[phylocom]|28> from LR_run_functions_v2 import 
make_half_square_array

n...@mws2[phylocom]|24> d = make_half_square_array(a)
---
NameError Traceback (most recent call last)

/bioinformatics/phylocom/ in ()

/bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in 
make_half_square_array(linear_version_of_square_array)

   1548 from numpy import sqrt
   1549 a = linear_version_of_square_array
-> 1550 dim = int(sqrt(size(a)))
   1551
   1552

NameError: global name 'sqrt' is not defined
n...@mws2[phylocom]|25>


Is there some other place I should put the import command?  I.e.:
1. In the main script/ipython command line

2. In the called function, i.e. make_half_square_array() in 
LR_run_functions_v2.py


3. At the top of LR_run_functions_v2.py, outside of the individual 
functions?


Thanks...sorry for the noob questions!
Nick





Each with their own, slightly different, meaning.
Hence the reason many of us prefer to import the module
and reference the function as a module attribute.

Note that _many_ (especially older) package documents describe
their code without the module name.  I believe that such behavior
is because, when working to produce prose about a package, it
feels too much like useless redundancy when describing each function
or class as "package.name".


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



--

Nicholas J. Matzke
Ph.D. student, Graduate Student Researcher
Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370

Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264
Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140

-
"[W]hen people thought the earth was flat, they were wrong. When people 
thought the earth was spherical, they were wrong. But if you think that 
thinking the earth is spherical is just as wrong as thinking the earth 
is flat, then your view is wronger than both of them put together."


Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 
14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

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


Re: Flattening lists

2009-02-05 Thread Michele Simionato
On Feb 5, 7:24 pm, a...@pythoncraft.com (Aahz) wrote:
> In article 
> ,
> Michele Simionato   wrote:
>
>
>
> >Looks fine to me. In some situations you may also use hasattr(el,
> >'__iter__') instead of isinstance(el, list) (it depends if you want to
> >flatten generic iterables or only lists).
>
> Of course, once you do that, you need to special-case strings...

Strings are iterable but have no __iter__ method, which is fine in
this context, since I would say 99.9% of times one wants to treat them
as atomic objects, so no need to special case.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Installation Error

2009-02-05 Thread Benjamin Kaplan
On Thu, Feb 5, 2009 at 12:46 PM, Ahmed Majeed  wrote:

> Hi,
> I am working over a research project and need Python 2.3 or later to
> be installed on my Intel Centrino machine, running Fedora 9 as OS. I
> have downloaded latest stable release Python 2.6.1 from Python.org,
> but when I tried installing it, terminal returned an error on 'make',
> saying:
>
> "Failed to find the necessory Bits to build these modules:
> _tkinter bsddb185, sunaaudiodev
> To find the necessory bits, look in setup.py in detect_modules() for
> the module's name."
>
> How should I correct this and go ahead for installation. Anxiously
> waiting reply and thanking you in anticiaption.



Are you sure there was an error in make? What you see isn't a problem, it's
just a notification. Make is telling you the tk, bsddb, and sunaaudiodev
modules won't be installed because you don't have the libraries on your
computer. If it got that far, I'm almost certain that the build was
sucessful. Make install should work from there. If you aren't going to use
those modules, go ahead and install it, otherwise download those libraries
and try again.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Integrated Parallel Pipeline EnviRonment: PIPPER

2009-02-05 Thread Stefan Behnel
Kyle wrote:
> def do_call(x,y):
>   print "Hello World", x, y, os.getpid()
> 
> if __name__ == '__pipper_main__':
>   a_range = range( int(sys.argv[1]) )
>   #pragma pipper_start
>   for a in  a_range :
>   for b in a_range :
>   do_call(a,b)
>   #pragma pipper_end

I'm not a big fan of comments that change semantics. Wouldn't a modified
'with' statement look better?

We have a couple of other syntax proposals in the Cython Wiki.

http://wiki.cython.org/enhancements/parallel

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


Re: os.system issues

2009-02-05 Thread Chris Rebert
On Thu, Feb 5, 2009 at 6:00 AM, Youri Lammers
 wrote:
> Ok,
>
> I want to run a program called 'muscle' with my python script,
> muscle uses the following command:
> 'muscle.exe -in filename -out filename'
> so far I got:
>
> import os
> args = ['-in filename', '-out filename']

As Christian indirectly points out, that's an incorrect tokenization
of the arguments. Remember that the shell has no knowledge of what
arguments a program takes and so doesn't treat the arguments
differently or specially for each program; it instead applies the
consistent rule of breaking arguments at spaces (unless you put an
argument in quotes). Thus, args should be:

args = ['-in', 'filename', '-out', 'filename']

The fact that the program happens to semantically pair those adjacent
arguments together is entirely up to and done by the program itself.
You can verify this by printing sys.argv from a command-line Python
program which you've given arguments to.

And of course, you'd only use `args` like this if you were using the
`subprocess` module; as others have pointed out, os.system() is more
primitive and just takes a single string of the entire command. But
`subprocess` is better anyway.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: where clause

2009-02-05 Thread bearophileHUGS
Albert Hopkins:

> One could imagine this getting "out of hand" e.g.

Yes, any syntax can be abused (your example isn't abusive enough).


>   a = 20 / len(c)
>   where
>   c = p / b
>   try:
>   b = foo(d)
>   where
>   d = bar()
>   except:
>   b = 0
>
> It also begs the question, should the except: clause be written to
> handle an exception raised in foo() as well as bar()? or should one also
> write a try/except around bar()?

This code:

>   a = 20 / len(c)
>   where
>   c = p / b
>   try:
>   b = foo(d)
>   where
>   d = bar()
>   except:
>   b = 0

Equals to:

a = 20 / len(p / b)
try:
b = foo(bar())
except:
b = 0
p = a / b

So the answer is positive.


> Usually when I'm looking at an identifier (function, class, variable)
> being used, I tend to look *up* to see where it is defined.

Right, the main purpose of where is to change that usual way, if you
want.

Note that where may also be designed to create a new scope (as in
Haskell, I think), that's why I have inlined the bar and p/b.

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


Re: subprocess returncode windows

2009-02-05 Thread Andrew
On Dec 16 2008, 5:11 pm, "Gabriel Genellina" 
wrote:
> En Tue, 16 Dec 2008 17:21:35 -0200, Andrew   
> escribió:
>
>
>
> > On Dec 16, 12:50 pm, Christian Heimes  wrote:
> >> Andrew schrieb:
>
> >> > I'm running into a strange situation with getting incorrect
> >> > returncodes / exit status from python subprocess.call. I'm using a
> >> > python script (runtime 2.6.1 on windows) to automate the deploy of
> >> > java applications to glassfish application server. Below is an example
>
> > I've removed shell=True, unfortunately, if I structure the call like:
>
> > call(["c:/glassfish/bin/asadmin.bat", "list-system-properties", "--
> > host
> > mydomain", "--port 4848", "--user admin", "server-01"])
>
> > It doesn't seem to recognize any arguments after list-system-
> > properties.
>
> Should be:
>
> call(["c:/glassfish/bin/asadmin.bat", "list-system-properties", "--host",
> "mydomain", "--port", "4848", "--user", "admin", "server-01"])
>
> *Every* argument should be an item in the list (your way, "--port 4848"  
> becomes a single argument, not two: option plus value)
> (This is independent of your other issue)
>
> > If I structure it like:
>
> > call("c:/glassfish/bin/asadmin.bat "+"list-system-properties --host
> > mydomain --port 4848 --user admin server-01")
>
> > Then it executes correctly but still gives invalid returncode of 0
> > when it fails instead of 1.
>
> A similar example works fine for me:
>
> C:\temp>type ret.c
> #include 
>
> int main(int argc, char* argv[])
> {
>    return atoi(argv[1]);
>
> }
>
> C:\temp>ret 5
>
> C:\temp>echo %errorlevel%
> 5
>
> C:\temp>type testret.bat
> ret %1
>
> C:\temp>testret 3
>
> C:\temp>ret 3
>
> C:\temp>echo %errorlevel%
> 3
>
> C:\temp>type testret.py
>  from subprocess import call
> ret = call(["testret.bat", "42"])
> print "testret.bat exit code =", ret
>
> C:\temp>python testret.py
>
> C:\temp>ret 42
> testret.bat exit code = 42
>
> C:\temp>python -V
> Python 2.6
>
> C:\temp>ver
>
> Microsoft Windows XP [Versión 5.1.2600]
>
> --
> Gabriel Genellina

I've tried this several ways now. It seems to be something specific
with python and asadmin.bat.

I've tried the following manually in the cmd.exe prompt:

--
C:\temp>c:\glassfish\bin\asadmin.bat list-system-properties
Instance-01

properties here


Command list-system-properties executed successfully.

C:\temp>echo %errorlevel%
0

C:\temp>c:\glassfish\bin\asadmin.bat list-system-properties
Instance-05//note that Instance-05 does not exist
Cannot determine type for target : Instance-05
CLI137 Command list-system-properties failed.

C:\temp>echo %errorlevel%
1

C:\temp>ping 019293.com
Ping request could not find host 019293.com. Please check the name and
try again
.

C:\temp>echo %errorlevel%
1

C:\temp>ping google.com

Pinging google.com [74.125.45.100] with 32 bytes of data:

Reply from 74.125.45.100: bytes=32 time=48ms TTL=234
Reply from 74.125.45.100: bytes=32 time=66ms TTL=234
Reply from 74.125.45.100: bytes=32 time=63ms TTL=234
Reply from 74.125.45.100: bytes=32 time=44ms TTL=234

Ping statistics for 74.125.45.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 44ms, Maximum = 66ms, Average = 55ms

C:\temp>echo %errorlevel%
0


Then I tried the following in python (2.6.1)

---script---
import subprocess
import sys


try:
retcode = subprocess.call(["ping","019293.com"])
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError, e:
print >>sys.stderr, "Execution failed:", e

try:
retcode = subprocess.call(["ping","google.com"])
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError, e:
print >>sys.stderr, "Execution failed:", e


try:
retcode = subprocess.call(["c:/glassfish/bin/asadmin.bat","list-
system-properties","Instance-01"], shell=False)
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError, e:
print >>sys.stderr, "Execution failed:", e

try:
retcode = subprocess.call(["c:/glassfish/bin/asadmin.bat","list-
system-properties","Instance-05"], shell=False)
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError, e:
print >>sys.stderr, "Execution failed:", e
---script---

Executed Output:

---output---
C:\temp>c:\Python26\python.exe example2.py
Ping request could not find host 019293.com. Please check the name and
try again.
Child returned 1

Pinging google.com [74.125.67.100] with 32 bytes of data:

Reply from 74.125.67.100: bytes=32 time=244ms TTL=239
Reply from 74.125.67.100: bytes=32 time=244ms TTL

Re: where clause

2009-02-05 Thread Albert Hopkins
On Thu, 2009-02-05 at 10:04 -0800, bearophileh...@lycos.com wrote:
> This comes after a small discussion in another Python newsgroup.
> Haskell supports a where clause, that's syntactic sugar that allows
> you to define things like this:
> 
> p = a / b
>   where
> a = 20 / len(c)
> b = foo(d)
> 
> That means:
> 
> a = 20 / len(c)
> b = foo(d)
> p = a / b
> 
> I don't know how much good this syntax can be in my Python programs,
> probably I have to use it some time to judge.
> 
> In the Python shell you usally have to use a bottom-up style of
> programming, while a where may allow you a more top-down too. I can
> enjoy this.
> 

I don't like it for the following reasons:

  * Flat is better than nested.
  * There should be one-- and preferably only one --obvious way to
do it.

One could imagine this getting "out of hand" e.g.

p = a / b
   where
  a = 20 / len(c)
  where
  c = p / b
  try:
  b = foo(d)
  where
  d = bar()
  except:
  b = 0


It also begs the question, should the except: clause be written to
handle an exception raised in foo() as well as bar()? or should one also
write a try/except around bar()?

Usually when I'm looking at an identifier (function, class, variable)
being used, I tend to look *up* to see where it is defined.

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


Re: Flattening lists

2009-02-05 Thread Tobiah
On Thu, 05 Feb 2009 11:06:39 -0800, Tobiah wrote:

> 
>> Hello everybody,
>> 
>> Any better solution than this?
> 
> a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print str(a).replace('[',
> '').replace(']', '').split(', ')
> 
> ;)

Or:

a = ['text', 'string', 3, [4, 5, 6], [[7, 8], [9, 10]]]
print eval("[" + str(a).replace('[', '').replace(']', '') + "]")

Just tongue in cheek...

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


Re: Flattening lists

2009-02-05 Thread Tobiah

> Hello everybody,
> 
> Any better solution than this?

a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]]
print str(a).replace('[', '').replace(']', '').split(', ')

;)


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


Re: Flattening lists

2009-02-05 Thread rdmurray
Quoth J Kenneth King :
> mk  writes:
> 
> > Hello everybody,
> >
> > Any better solution than this?
> >
> > def flatten(x):
> > res = []
> > for el in x:
> > if isinstance(el,list):
> > res.extend(flatten(el))
> > else:
> > res.append(el)
> > return res
> >
> > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]]
> > print flatten(a)
> >
> >
> > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> >
> > Regards,
> > mk
> 
> http://mail.python.org/pipermail/python-list/2005-July/330367.html

That's worth reading.  I'm not sure why I'm finding this fun, but who
cares.  I tried a couple of other functions after reading that article,
and it looks like a generator that scans the nested lists is actually
the winner, and also is in many ways the most elegant implementation.
Of course, as noted in the emails following above article, the test data
is really inadequate for proper optimization testing ;)

-
from __future__ import print_function
from timeit import Timer
from itertools import chain

# This is the one from the article quoted above.
def flatten6(seq):
i = 0
while (i != len(seq)):
while hasattr(seq[i], '__iter__'):
seq[i:i+1] = seq[i]
i = i + 1
return seq


#This is my favorite from a readability standpoint out of
#all the things I tried.  It also performs the best.
def flatten8(seq):
for x in seq:
if not hasattr(x, '__iter__'): yield x
else:
for y in flatten8(x):
yield y



l = [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [5, 
4], 3], 4, 3], 3, 1, 45], 9], 10]]



if __name__=="__main__":
print(l)
print('flatten6', flatten6(l))
print('flatten8', list(flatten8(l)))
print('flatten6', Timer("flatten6(l)", "from temp3 import flatten6, 
l").timeit())
print('flatten8', Timer("list(flatten8(l))", "from temp3 import flatten8, 
l").timeit())


-

>src/python/Python-3.0/python temp3.py
[[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [5, 4], 
3], 4, 3], 3, 1, 45], 9], 10]]
flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 
3, 1, 45, 9, 10]
flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 
3, 1, 45, 9, 10]
flatten6 32.8386368752
flatten8 30.7509689331

>python temp3.py 
[[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [5, 4], 
3], 4, 3], 3, 1, 45], 9], 10]]
flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 
3, 1, 45, 9, 10]
flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 
3, 1, 45, 9, 10]
flatten6 34.730714798
flatten8 32.3252940178

--RDM

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


Re: Python Installation Error

2009-02-05 Thread Diez B. Roggisch

Ahmed Majeed schrieb:

Hi,
I am working over a research project and need Python 2.3 or later to
be installed on my Intel Centrino machine, running Fedora 9 as OS. I
have downloaded latest stable release Python 2.6.1 from Python.org,
but when I tried installing it, terminal returned an error on 'make',
saying:

"Failed to find the necessory Bits to build these modules:
_tkinter bsddb185, sunaaudiodev
To find the necessory bits, look in setup.py in detect_modules() for
the module's name."

How should I correct this and go ahead for installation. Anxiously
waiting reply and thanking you in anticiaption.


You are missing tcl/tk and bsddb development packages. Or if you don't 
care about these functionalities, you should be able to disable them 
using configure.


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


Re: Ordered dict by default

2009-02-05 Thread Steve Holden
bearophileh...@lycos.com wrote:
> Bryan Olson:
>> A few bits fuzzy. Is the following True or False if dict is insert-ordered?
>> dict(a=6, b=7) == dict(b=7, a=6)
> 
> In my odict implementation I have disallowed that syntax because if
> you want to define a mydict(**kwds) function that allows a syntax
> like:
> 
> mydict(a=6, b=7)
> 
> it takes a dict as argument, such dict is currently not ordered. If
> built-in dicts become ordered, then that dict too may become
> ordered :-)
> 
> Anyway, maybe it's good to ignore the inserting order of items when
> you look for odict equality.
> 
But then they wouldn't be equal. As I said right at the start if this
thread:

> one of the prime issues every time
> this comes up is the inability of the various proponents to agree on how
> dicts should actually be ordered.

The remainder of the thread vindicates that comment.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Python Integrated Parallel Pipeline EnviRonment: PIPPER

2009-02-05 Thread Kyle
I wanted to share a Python based project which I've been working on.
Python Integrated Parallel Pipeline EnviRonment (PIPPER) is an MPI
based programming environment that works much like an OpenMP on Python
code.  It is designed to create a python programming environment where
parallel computations on a set of distributed memory processors (you
may call it a cluster, or a Beowulf cluster) is easy to accomplish.
The idea is to make writing parallel code easy in order to promote
rapid development of script based distributed calculations.
There are tools, such as MPI or PVM that help with communicating
between processes running on different machines, but most people are
quickly scared off by the additional complexity in programming.
PIPPER eliminates this barrier to entry by automating the process of
data passing and job scheduling.
Most importantly is that there is no code 'lock-in'.  PIPPER works as
a pre-parser and is designed to be completely backward compatible with
a single CPU python environment.  If you write a script for PIPPER, it
will still work on systems that don't have PIPPER installed.

You can find the source code and documentation at http://pipper.sourceforge.net

A 'Hello Work' example of PIPPER code:

#!/usr/bin/python

import sys
import os

def do_call(x,y):
print "Hello World", x, y, os.getpid()

if __name__ == '__pipper_main__':
a_range = range( int(sys.argv[1]) )
#pragma pipper_start
for a in  a_range :
for b in a_range :
do_call(a,b)
#pragma pipper_end
--
http://mail.python.org/mailman/listinfo/python-list


Re: Flattening lists

2009-02-05 Thread Aahz
In article ,
Michele Simionato   wrote:
>
>Looks fine to me. In some situations you may also use hasattr(el,
>'__iter__') instead of isinstance(el, list) (it depends if you want to
>flatten generic iterables or only lists).

Of course, once you do that, you need to special-case strings...
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordered dict by default

2009-02-05 Thread bearophileHUGS
Bryan Olson:
> A few bits fuzzy. Is the following True or False if dict is insert-ordered?
>     dict(a=6, b=7) == dict(b=7, a=6)

In my odict implementation I have disallowed that syntax because if
you want to define a mydict(**kwds) function that allows a syntax
like:

mydict(a=6, b=7)

it takes a dict as argument, such dict is currently not ordered. If
built-in dicts become ordered, then that dict too may become
ordered :-)

Anyway, maybe it's good to ignore the inserting order of items when
you look for odict equality.

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


Re: How to call python from a foreign language thread (C++)

2009-02-05 Thread Philip Semanchuk


On Feb 3, 2009, at 11:37 PM, Victor Lin wrote:


It does not work. But however, thanks your help. I have tired so many
methods to do. But it
crash...crash..deadlock...deadlock..crash...crash... I have no any
tried success. I am going crazy. Could someone help me, thanks.



Hi Victor,
I have some code that works, although I'm not terribly confident of  
it. The Python documentation in this area is as clear as mud. I'd be  
interested to see if my code works for you as well.


This is part of my function that the Python code calls to set up the  
callback:


if (!PyEval_ThreadsInitialized()) {
   DPRINTF("calling PyEval_InitThreads()\n");
   PyEval_InitThreads();
   // PyEval_InitThreads() acquires the GIL on my behalf but
   // I don't want it at the moment.
   PyEval_ReleaseLock();
}

This sets up the GIL if necessary (i.e. if this is a single-threaded  
program) and is a no-op otherwise (i.e. if the app has already created  
a Python thread).


Then I have this function to perform the callback. It is invoked in a  
new C thread. Comments are inline.


void process_notification(union sigval notification_data) {
/* Invoked by the system in a new thread as notification of a  
message

   arriving in the queue. */
PyObject *arglist;
PyObject *result;
PyGILState_STATE gstate;
PyThreadState *main_thread;
PyThreadState *callback_thread;
MessageQueue *self = notification_data.sival_ptr;

DPRINTF("C thread %ld invoked\n", pthread_self());

// PyGILState_Ensure() implicitly acquires the GIL so I don't need
// to call PyEval_AcquireLock().
DPRINTF("Calling PyGILState_Ensure()\n");
gstate = PyGILState_Ensure();

// Get the current thread state so that I have an interpreter to
// which to point.
DPRINTF("Calling PyThreadState_Get()\n");
main_thread = PyThreadState_Get();

// Create a new Python thread for the callback.
DPRINTF("Calling PyThreadState_New()\n");
callback_thread = PyThreadState_New(main_thread->interp);

// Make the callback thread current.
DPRINTF("Calling PyThreadState_Swap()\n");
PyThreadState_Swap(callback_thread);

// Perform the callback.
arglist = Py_BuildValue("(O)", self->notification_function_param);
result = PyEval_CallObject(self->notification_function, arglist);
Py_DECREF(arglist);

DPRINTF("Done calling\n");

// Clean up my internal pointers
Py_XDECREF(self->notification_function);
Py_XDECREF(self->notification_function_param);
self->notification_function = NULL;
self->notification_function_param = NULL;

// Now unwind the Python thread/GIL stuff above
DPRINTF("Calling PyThreadState_Swap()\n");
PyThreadState_Swap(main_thread);

DPRINTF("Calling PyThreadState_Clear()\n");
PyThreadState_Clear(callback_thread);

DPRINTF("Calling PyThreadState_Delete()\n");
PyThreadState_Delete(callback_thread);

// PyGILState_Ensure() acquires the lock, but does  
PyGILState_Release()
// release it? The documentation doesn't say, but it seems like  
it does.

DPRINTF("Calling PyGILState_Release()\n");
PyGILState_Release(gstate);

DPRINTF("exiting thread\n");
};



This code works (in my limited testing) regardless of whether or not  
the Python code has created a thread. For the threaded test, I created  
a background thread that prints "ding!" every second. That thread  
continued to run even after my callback thread was invoked which I  
assume means that I released the GIL properly.


As I mentioned before, this is part of my posix_ipc extension. This  
code (assuming I feel confident enough to release it) will be in the  
next version that should be out soon, so you will have a full working  
example with which to experiment.


HTH,
Philip



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


where clause

2009-02-05 Thread bearophileHUGS
This comes after a small discussion in another Python newsgroup.
Haskell supports a where clause, that's syntactic sugar that allows
you to define things like this:

p = a / b
  where
a = 20 / len(c)
b = foo(d)

That means:

a = 20 / len(c)
b = foo(d)
p = a / b

I don't know how much good this syntax can be in my Python programs,
probably I have to use it some time to judge.

In the Python shell you usally have to use a bottom-up style of
programming, while a where may allow you a more top-down too. I can
enjoy this.

Compared to Haskell a possible problem may from mutability, in Haskell
often the order of the operations isn't important (it's only/mostly
significant during I/O), while in Python is generally important.

The interpreter has to look ahead, to use such 'where', because the
point of 'where' is to allow the programmer with such inversions.

In Python you probably want to put a : after where.
But that Haskell syntax also enjoys having where too indented, this is
less easy (or impossible?) to mix with the usual Python syntax.

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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Bruno Desthuilliers

Tim Rowe a écrit :

2009/2/5 Tim Chase :


Is this where we tell you to shut up?  ;-)


[snip]


It would also be interesting to see how many of those posts are concentrated
in certain threads


And, as you have clearly demonstrated, how many of those posts also
contain a smiley or some other form of hedging in a position that
could modify the "unfriendly" text?

Not to mention when the "rtfm" comes with a pointer to the relevant url 
and a couple explanations.


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


Python Installation Error

2009-02-05 Thread Ahmed Majeed
Hi,
I am working over a research project and need Python 2.3 or later to
be installed on my Intel Centrino machine, running Fedora 9 as OS. I
have downloaded latest stable release Python 2.6.1 from Python.org,
but when I tried installing it, terminal returned an error on 'make',
saying:

"Failed to find the necessory Bits to build these modules:
_tkinter bsddb185, sunaaudiodev
To find the necessory bits, look in setup.py in detect_modules() for
the module's name."

How should I correct this and go ahead for installation. Anxiously
waiting reply and thanking you in anticiaption.

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


Re: Couple of noobish question

2009-02-05 Thread Tim Rowe
2009/2/5 Bruno Desthuilliers :

> Thanks for the correction - as you may have guessed, I have not used windows
> for years !-)

And I can't get Linux running (more precisely, I can't /keep/
X-Windows running). Isn't it a good job that Python is cross-platform
-- as long as we stay clear of the os module :-)


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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Dan Upton
On Thu, Feb 5, 2009 at 12:37 PM, Tim Rowe  wrote:
> 2009/2/5 Tim Chase :
>
>> Is this where we tell you to shut up?  ;-)
>
> [snip]
>
>> It would also be interesting to see how many of those posts are concentrated
>> in certain threads
>
> And, as you have clearly demonstrated, how many of those posts also
> contain a smiley or some other form of hedging in a position that
> could modify the "unfriendly" text?

I'd be amused to see "shut up and rtfm ;)"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordered dict by default

2009-02-05 Thread Bryan Olson

Stephen Hansen wrote:

Ooh, as an addendum... I found one case where I want insertion-and-update
order: meaning that its an ordered dictionary that maintains insertion
order, but
an update to a particular item moves that item to the back so an update behaves
like del d[key]; d[key] = value in terms of the key order.

"Ordered Dictionaries" are a bit fuzzy. :)


A few bits fuzzy. Is the following True or False if dict is insert-ordered?

   dict(a=6, b=7) == dict(b=7, a=6)



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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Tim Rowe
2009/2/5 Tim Chase :

> Is this where we tell you to shut up?  ;-)

[snip]

> It would also be interesting to see how many of those posts are concentrated
> in certain threads

And, as you have clearly demonstrated, how many of those posts also
contain a smiley or some other form of hedging in a position that
could modify the "unfriendly" text?


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


Re: Ordered dict by default

2009-02-05 Thread Bryan Olson

MRAB wrote:

Paul Rubin wrote:

bearophileh...@lycos.com writes:

Now Ruby dicts are ordered by default:
http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/


Maybe I didn't read that carefully enough, but it looks like "ordered"
means the dict records come out in the same order you inserted them
in.  That is if you insert B,A,D,C in that order, you get them out in
that order.  I would have thought an ordered dict meant you get A,B,C,D,
which seems a lot more useful.


[snip]
You're confusing "ordered" with "sorted"! :-)


He's really not.

  http://en.wikipedia.org/wiki/Ordered_set


A list is an ordered collection, for example.


True.


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


Re: sorting mesh data an from abaqus simulation

2009-02-05 Thread Gabriel Genellina

En Mon, 02 Feb 2009 10:10:15 -0200, Alessandro Zivelonghi
 escribió:


*Ntop = odb.rootAssembly.instances['PART-1-1'].nodeSets['TOP'].nodes
*
Problem:
1) the list of nodes Ntop contains all the node labels [2673,   2675,
2676,   2677,   2678,   3655,   3656, 119939, 124154, 127919] already
ordered in ascending order.
What I need is the same list *ordered by coordinate_x* of each node, i.e.
from left to right in the model (unfortunately, for example node 124154
cames before node 3656 in the model, if you read the model from left to
right)


Use the key= argument to the sorted() builtin function


def get_node_x(node):
   return node.coordinates[0]

sorted_nodes = sorted(Ntop, key=get_node_x)

(For a list of reasonable size, that's fine. For a giant list, this could
be written more efficiently, although less readable)


1b) I don't understand which kind of data are EL, N, Ntop (list?) and how
can I sort Ntop  with the criterium based on coordinate_x (coordinate[0])


AFAIK those are plain lists. You can try:

py> print type(Ntop)

and see what happens. If you don't get , try with:

py> type(Ntop).mro()

to see the chain of base classes.

--
Gabriel Genellina

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


Re: Flattening lists

2009-02-05 Thread rdmurray
Quoth rdmur...@bitdance.com:
> This is all premature optimization, except for the goopy code, which is
> presumably used enough to make it worth optimizing.  And guess what?
> The goopy code wins.  What the people theorizing about the speed of
> extend vs list creation miss is that the things with high overhead in the
> above functions are (1) isinstance and (2) the recursive function call.
> The goopy code avoids this by using type and is, and by unrolling the
> lowest level without a function call.  On the other hand, extend
> _is_ faster than append if you aren't creating a new list, so the
> goopy code can be optimized a little more.
> 
> I remembered the bit about high function call overhead, but the rest
> of it measured:

Oooh, that's embarrassing.  Not only didn't I read the code carefully
enough, I didn't test the actual output of the functions.  The goopy
code doesn't flatten to arbitrary depth, so of course it is faster.

--RDM

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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Tim Chase

(duck)

542 comp.lang.python rtfm
467 comp.lang.python shut+up
263 comp.lang.perl rtfm
45 comp.lang.perl shut+up


Is this where we tell you to shut up?  ;-)

As others mentioned, the raw numbers don't mean much without a 
total-volume-of-posts to demonstrate the percentage.


It would also be interesting to see how many of those posts are 
concentrated in certain threads -- for the most part, c.l.python 
has been a pretty civil place, but a few threads have degraded 
into puerile spats.


-tkc



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


Re: subprocess.Popen not creating a pipe

2009-02-05 Thread Gabriel Genellina

En Sun, 01 Feb 2009 18:00:36 -0200, Andrew Parker 
escribió:


On Sun, Feb 1, 2009 at 1:46 PM, Andrew Parker  wrote:

I'm having some fun with Popen.  I have the following line:

   process = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
   print process.stdout

Under normal circumstances, this displays:

   ', mode 'w' at 0xb7f8e068>

However, I have a binary that I use to kick off this script, and when
that runs, it displays:

   None

So, two questions:

   1.  What the heck is this binary doing that upsets Popen so much?
   2.  What can *my script* do to get around this problem.

Unfortunately I'm stuck using this binary, so its the python where I
have to solve this.


so, tracing through subprocess.Popen, I see that os.pipe() is being
invoked for stdout.  This is returning (0, 3), and I assume the 0 is
conflicting with what python is assuming is stdin.  Calling pipe()
before Popen gets around my problem, as the pipe the Popen gets then
returns (4,5) which Popen seems happy with.


Seems that "your binary" is closing stdin before running your script, so
the first available file descriptor is 0.

Sounds like a bug.  Should I report this, or is it expected/known  
behaviour?


It's hardly a Python error, and I don't think the subprocess module should
consider this very special case, but you may report it at
http://bugs.python.org/ anyway.

--
Gabriel Genellina

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


HOWTO for setting up a PyQt project in Eclipse ?

2009-02-05 Thread Linuxguy123
Does anyone know of a HOWTO for setting up a PyQt project in Eclipse ?

I know about setting up a PyDev project, just wondering how to integrate
the QtDesigner parts.  

For example, should I save the QtDesigner project in the root PyDev
directory ?

Thanks

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


Re: Structuring Modules with a Ubiquitous Base Class (Circular Dependencies)

2009-02-05 Thread Gabriel Genellina

En Wed, 04 Feb 2009 21:12:58 -0200, andrew cooke 
escribió:


On Feb 4, 7:49 pm, andrew cooke  wrote:

This leads to a circular dependency - the base class wants to import
the components, which in turn want to import the base class.


well, to partially answer my own question, this is certainly
possible.  in the general case it might get quite complex, but for the
structure described it is quite simple.  the 'trick' is to import the
component in the *method* of the common base class.

for example:

class Base(object):

def __init__(self):
from first import First
from second import Second
self.first = lambda *args: First(*args)
self.second = lambda *args: Second(*args)

where First, defined in first, subclasses Base in the normal way.

however, i suspect this will have a performance hit, since "linking"
is being done at "run time" rather than "compile time".  anyone have
any guidance on how serious that would be?  i guess it could be
ameliorated by doing the work in the constructor (as above, which is
just that way for a compact example - in "real life" the components
are used in a more complex manner).


There is no "linking" step in Python, all is done at run time.
Once a module is imported the first time, any subsequent import is very
cheap.


and i still suspect there is a more efficient metaclass or similar
approach.


This approach is fine to me.

--
Gabriel Genellina

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


Re: Scanning a file character by character

2009-02-05 Thread Gabriel Genellina

En Thu, 05 Feb 2009 04:48:13 -0200, Spacebar265 
escribió:


Hi. Does anyone know how to scan a file character by character and
have each character so I can put it into a variable. I am attempting
to make a chatbot and need this to read the saved input to look for
spelling mistakes and further analysis of user input.


Read the file one line at a time, and process each line one character at a
time:

with open(filename, "r") as f:
   for line in f:
 for c in line:
   process(c)

But probably you want to process one *word* at a time; the easiest way
(perhaps inaccurate) is to just split on whitespace:

   ...
 for word in line.split():
   process(word)

--
Gabriel Genellina

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


Re: Flattening lists

2009-02-05 Thread Sion Arrowsmith
mk   wrote:
>Brian Allen Vanderburg II wrote:
>> I think it may be just a 'little' more efficient to do this:
>> 
>> def flatten(x, res=None):
>>if res is None:
>>   res = []
>>for el in x:
>>   if isinstance(el, (tuple, list)):
>>  flatten(el, res)
>>   else:
>>  res.append(el)
>>return res
>
>
>Hmm why should it be more efficient [than
def flatten(x):
res = []
for el in x:
if isinstance(el,list):
res.extend(flatten(el))
   else:
res.append(el)
return res

]? extend operation should not be very costly?

It's not a question of extend/append, it's the fact that your
original function creates (and destroys) a new list for every
recursive call. Which, if you've got large nested lists, will
have an impact.

-- 
\S -- si...@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
--
http://mail.python.org/mailman/listinfo/python-list


Re: Flattening lists

2009-02-05 Thread J Kenneth King
mk  writes:

> Hello everybody,
>
> Any better solution than this?
>
> def flatten(x):
> res = []
> for el in x:
> if isinstance(el,list):
> res.extend(flatten(el))
> else:
> res.append(el)
> return res
>
> a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]]
> print flatten(a)
>
>
> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>
> Regards,
> mk

http://mail.python.org/pipermail/python-list/2005-July/330367.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Flattening lists

2009-02-05 Thread rdmurray
Baolong zhen  wrote:
> On Thu, Feb 5, 2009 at 10:17 PM, mk  wrote:
>
> > Brian Allen Vanderburg II wrote:
> > >> def flatten(x):
> > >> res = []
> > >> for el in x:
> > >> if isinstance(el,list):
> > >> res.extend(flatten(el))
> > >> else:
> > >> res.append(el)
> > >> return res
> >
> > >
> > > I think it may be just a 'little' more efficient to do this:
> > >
> > > def flatten(x, res=None):
> > >if res is None:
> > >   res = []
> > >
> > >for el in x:
> > >   if isinstance(el, (tuple, list)):
> > >  flatten(el, res)
> > >   else:
> > >  res.append(el)
> > >
> > >return res
> >
> >
> > Hmm why should it be more efficient? extend operation should not be very
> > costly?
>
> less list creation.

(Took me a while to find the content of your post because
you top posted it.  I've taken the liberty of correcting that.)

This is all premature optimization, except for the goopy code, which is
presumably used enough to make it worth optimizing.  And guess what?
The goopy code wins.  What the people theorizing about the speed of
extend vs list creation miss is that the things with high overhead in the
above functions are (1) isinstance and (2) the recursive function call.
The goopy code avoids this by using type and is, and by unrolling the
lowest level without a function call.  On the other hand, extend
_is_ faster than append if you aren't creating a new list, so the
goopy code can be optimized a little more.

I remembered the bit about high function call overhead, but the rest
of it measured:

temp.py
-
from __future__ import print_function
from timeit import Timer

def flatten1(x):
res = []
for el in x:
if isinstance(el, list):
res.extend(flatten1(el))
else:
res.append(el)
return res

def flatten1a(x):
res = []
for el in x:
if isinstance(el, (tuple, list)):
res.extend(flatten1a(el))
else:
res.append(el)
return res

def flatten1b(x):
res = []
for el in x:
if type(el) is list or type(el) is tuple:
res.extend(flatten1b(el))
else:
res.append(el)
return res


def flatten2(x, res=None):
if res is None:
   res = []
for el in x:
   if isinstance(el, list):
  flatten2(el, res)
   else:
  res.append(el)
return res


def flatten2a(x, res=None):
if res is None:
   res = []
for el in x:
   if isinstance(el, (tuple, list)):
  flatten2a(el, res)
   else:
  res.append(el)
return res


def flatten2b(x, res=None):
if res is None:
   res = []
for el in x:
   if type(el) is list or type(el) is tuple:
  flatten2b(el, res)
   else:
  res.append(el)
return res



def flatten3z(seq):
  lst = []
  for x in seq:
if type(x) is list or type(x) is tuple:
  for val in x:
lst.append(val)
else:
  lst.append(x)
  return lst

def flatten3(seq):
  lst = []
  for el in seq:
if type(el) == list or type(el) is tuple:
  lst.extend(flatten3z(el))
else:
  lst.append(el)
  return lst


def flatten3y(seq):
  lst = []
  for x in seq:
if type(x) is list or type(x) is tuple:
  lst.extend(x)
else:
  lst.append(x)
  return lst

def flatten3a(seq):
  lst = []
  for el in seq:
if type(el) == list or type(el) is tuple:
  lst.extend(flatten3y(el))
else:
  lst.append(el)
  return lst



l = [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [5, 
4], 3], 4, 3], 3, 1, 45], 9], 10]]

cases = dict(
base = Timer(),
c1 = Timer("flatten1(l)", "from temp import flatten1, l"),
c1a = Timer("flatten1a(l)", "from temp import flatten1a, l"),
c1b = Timer("flatten1b(l)", "from temp import flatten1b, l"),
c2 = Timer("flatten2(l)", "from temp import flatten2, l"),
c2a = Timer("flatten2a(l)", "from temp import flatten2a, l"),
c2b = Timer("flatten2b(l)", "from temp import flatten2b, l"),
c3 = Timer("flatten3(l)", "from temp import flatten3, l"),
c3a = Timer("flatten3a(l)", "from temp import flatten3a, l"),
)

if __name__=="__main__":
for (name, case) in sorted(cases.items()):
print("{0:4s} {1}".format(name, case.timeit()))

-

It is also interesting to note that python3.0 is faster in this
particular case (unless there are timing vagrancies on my machine, which
is possible, though the results were fairly consistent over several runs
of the script).  The second run below is using python2.6.1.

>src/python/Python-3.0/python temp.py
base 0.0278329849243
c1   30.4776289463
c1a  44.3886289597
c1b  32.5621030331
c2   25.6131818295
c2a  39.0944678783
c2b  27.1573381424
c3   15.346280098
c3a  14.3178970814

>python temp.py 
base 0.02882695

Re: Flattening lists

2009-02-05 Thread Stephen Hansen
> Either list creation is somewhat
> costly, or "if var is None" is really cheap.

"if x is y" is extremely cheap, I believe. Unlike most comparisons
which are (relatively) expensive, that one is just comparing simple
object address. You can't override "is" so there's a whole series of
checks that don't have to get done. You don't have to go through the
richcompare machinery, check if there's a __ne__, etc, etc.

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


Re: Flattening lists

2009-02-05 Thread mk

Brian Allen Vanderburg II wrote:


Is list creation really more costly than above?

Probably not.  I wrote a small test program using a list several levels 
deep, each list containing 5 sublists at each level and finally just a 
list of numbers.  Flattening 1000 times took about 3.9 seconds for the 
one creating a list at each level, and 3.2 for the one not creating the 
list at each level.


Hmm, I'm surprised by even that! Apparently list creation is more 
expensive than I thought - it seems somewhat more expensive than the 
cost of interpreting bytecode for "if var is None". Either list creation 
is somewhat costly, or "if var is None" is really cheap.


Regards,
mk

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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Diez B. Roggisch

mk schrieb:


(duck)

542 comp.lang.python rtfm

467 comp.lang.python shut+up

263 comp.lang.perl rtfm

45 comp.lang.perl shut+up


It appears to me that comp.lang.perl isn't even active anymore. Or 
googles interface is just crappy.


c.l.perl.misc seems to be the place to search.

And raw numbers are nothing without actual postings. FWIW, I can't 
remember reading the last time RTFM here, but then I usually skip the 
giant-size horse-beatings about GIL removal and encapsulation...



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


  1   2   >