Re: PEP 382: Namespace Packages

2009-04-29 Thread Martin v. Löwis
syt wrote:
> Another point: I don't like .pth, .pkg files. Isn't this pep an opportunity 
> to at least unify them?

Can you propose a unification? I'm concerned that if I propose one,
you may still not like it.

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


Silent install of Python software(2.5) for windows.

2009-04-29 Thread kc.pyt...@gmail.com
Hi All,

Is it possible to "automate" the installation of python software(2.5)
without the need of pressing "Next" so many times?
Below is the platform in which it should be installed.
OS : windows

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


Re: CSV performance

2009-04-29 Thread Peter Otten
Lawrence D'Oliveiro wrote:

> In message , Peter Otten wrote:
> 
>> gc.disable()
>> # create many small objects that you want to keep
>> gc.enable()
> 
> Every time I see something like this, I feel the urge to save the previous
> state and restore it afterwards:
> 
> save_enabled = gc.isenabled()
> gc.disable()
> # create many small objects that you want to keep
> if save_enabled :
> gc.enable()
> #end if
> 
> Maybe that's just me. :)

There's probably someone out there who does nested GC states on a daily 
basis ;)

When I see the sequence

save state
change state
do something
restore state

I feel compelled to throw in a try ... finally

save state
try:
change state
do something
finally:
restore state

which in turn leads to

import gc

from contextlib import contextmanager

@contextmanager
def gcdisabled():
was_enabled = gc.isenabled()
gc.disable()
try:
yield
finally:
if was_enabled:
gc.enable()

if __name__ == "__main__":
try:
with gcdisabled():
assert not gc.isenabled()
try:
with gcdisabled():
assert not gc.isenabled()
1/0
finally:
assert not gc.isenabled()
except ZeroDivisionError:
pass
assert gc.isenabled()

So far, so good. But is it thread-safe?

I think you are beginning to see why the original suggestion was my best 
option...

Peter

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


Re: Can not run under python 2.6?

2009-04-29 Thread Gabriel Genellina
En Wed, 29 Apr 2009 03:20:14 -0300, Jianchun Zhou  
 escribió:



Traceback (most recent call last):
mod = __import__(modpath, fromlist=[mod_name])
ImportError: Import by filename is not supported.

Any body any idea what should I do?


See this recent thread on the same topic:
http://groups.google.com/group/comp.lang.python/t/1beda7d8ee474b64/

--
Gabriel Genellina

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


Re: Get item from set

2009-04-29 Thread Peter Otten
Aahz wrote:

> In article ,
> Peter Otten  <__pete...@web.de> wrote:
>>
>>Here's a trick to find the actual element. I think Raymond Hettinger
>>posted an implementation of this idea recently, but I can't find it at the
>>moment.
> 
> Your code is inverted from Raymond's:

I can't see the inversion.
 
> http://code.activestate.com/recipes/499299/

Thanks for providing the reference.

Peter

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


Re: Python Noob - a couple questions involving a web app

2009-04-29 Thread Bruno Desthuilliers

Kyle T. Jones a écrit :
Been programming for a long time, but just starting out with Python. Not 
a professional programmer, just that guy in one of those organizations 
that won't hire a pro, instead saying "Hey, Kyle knows computer stuff - 
let's have him do this (and that, and the other, etc)".


So, the higher ups want a web app that'll let them enter (from an 
intranet page) a rather simple, but quite lengthy, list - details to be 
stored in a MySQL database... just normal stuff here, entering, editing, 
and deleting entries, sorting, etc.


On the internet side of things, folks get the info served up to them, 
can sort it in a few ways, etc - it's pretty basic stuff.



(snip)

I can only second Arnaud and Emile : Django is very probably what you're 
looking for, and by all means better than any PHP thingie - wrt/ both 
development time and security.


You'll indeed first have to learn the framework (and Python of course), 
and learn how to deploy your app in production (which can be a bit 
tricky if you're not familiar with server admin), but there's a good 
documentation and a very helpful community around both the Django 
framework and the Python language.


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


Re: Silent install of Python software(2.5) for windows.

2009-04-29 Thread Gabriel Genellina
En Wed, 29 Apr 2009 03:58:02 -0300, kc.pyt...@gmail.com  
 escribió:



Is it possible to "automate" the installation of python software(2.5)
without the need of pressing "Next" so many times?
Below is the platform in which it should be installed.
OS : windows


Try using:

msiexec /i python.msi /qn /l*v install.log TARGETDIR=c:\desired\path

See http://technet.microsoft.com/en-us/library/bb490936.aspx for more info.

--
Gabriel Genellina

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


Re: How to retry something with a timeout in Python?

2009-04-29 Thread tinnews
Scott David Daniels  wrote:
> tinn...@isbd.co.uk wrote:
> > This feels like it should be simple but I can't see a clean way of
> > doing it at the moment.
> > 
> > I want to retry locking a file for a number of times and then give up,
> > in pseudo-code it would be something like:-
> > 
> > 
> > for N times
> > try to lock file
> > if successful break out of for loop
> > if we don't have a lock then give up and exit
> 
>  for attempt in range(N):
>   try:
>   lock_file_with_timeout(per_try)  # change to what you mean
>   except LockAttemptFailure: # or however the failure is shown
>   pass  # here the attempt+1th try failed.
>   else:
>   break # success -- have the lock
>  else:
>  raise ImTiredError  # however you handle N attempts w/o success
>  
> 
Ah, yes, it's the 'else:' with the 'for' that makes it easier, I've
come from languages which don't have that, thank you!  :-)

> Often it is easiest to stick it in a function:
> 
>  def retry_lock(tries=3, wait_per_attempt=.5):
>  for attempt in range(tries):
>  try:
>  # change following to whatever you do to attempt a lock.
>  lock_file_with_timeout(wait_per_attempt)
>  except LockAttemptFailure: # or however the failure is shown
>  pass  # here the attempt+1th try failed.
>  else:
>  return # success -- have the lock
>  raise ImTiredError
> 
> --Scott David Daniels
> scott.dani...@acm.org

-- 
Chris Green

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


Screenshot of a web page

2009-04-29 Thread mattia
Are you aware of any python module that automatically gives you a 
screenshot of a web page?
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-29 Thread Lawrence D'Oliveiro
In message , Peter Otten wrote:

> When I see the sequence
> 
> save state
> change state
> do something
> restore state
> 
> I feel compelled to throw in a try ... finally

Yeah, but I try to avoid using exceptions to that extent. :)

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


Re: desperately looking for a howto on running my wxPython app on Vista

2009-04-29 Thread Paul Sijben
Gabriel Genellina wrote:

>> I am currently stuck on the infamous R6034 error but I understand that
>> after that there may be another issue with certain wxPython functions.
> 
> That should be fixed in Python 2.6.2, I think.
> Are you compiling all your dependencies, including Python itself? R6034
> is likely a DLL mismatch between parts of your project.

I am using 2.6.2 and am compiling only my own changed modules. For all
the other support modules I have taken the most recent ones (win32,
wxpython)

Is there any way to check which is the offending pyd/dll?  (normally
Vista does not give out much data on what went wrong)

Paul

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


Re: What do you think of ShowMeDo

2009-04-29 Thread Jeremiah Dodds
On Wed, Apr 29, 2009 at 6:48 AM, Banibrata Dutta
wrote:

> Personally, I faced some despair with a large number of the free
> ShowMeDo tutorials, example the one on WxPython, where for the first 4
> free tutorials, the tutor hardly progresses to any bit of programming,
> and what is demonstrated was too basic, too slow - to hold my
> attention.
>

I must agree here. I'll add that the vast majority of video tutorials or
lectures that I've seen are way too slow to hold my interest, with the
exception of google tech talks, and stuff like OCW from MIT. (These are at
http://research.google.com/video.html and
http://ocw.mit.edu/OcwWeb/web/home/home/index.htm respectively).

However, I do really like the idea of showmedo, especially for people who
like learning through not-so-dense video on the introductory level. I
haven't been incredibly impressed with the quality of the free stuff there
either, but I also haven't looked at any of the paid stuff. I don't think
that it's safe to assume that it's of a substantially higher quality.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Silent install of Python software(2.5) for windows.

2009-04-29 Thread Martin P. Hellwig

kc.pyt...@gmail.com wrote:

Hi All,

Is it possible to "automate" the installation of python software(2.5)
without the need of pressing "Next" so many times?
Below is the platform in which it should be installed.
OS : windows

Thanks & Regards,
Kalyan.


Distribute the msi using Active Directories group policies (perhaps 
tweak it a bit with orca):

http://www.windowsnetworking.com/articles_tutorials/Group-Policy-Deploy-Applications.html

--
MPH
http://blog.dcuktec.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict is really slow for big truck

2009-04-29 Thread Sion Arrowsmith
  wrote:
>On Apr 28, 2:54 pm, forrest yang  wrote:
>> for line in open(file)
>>    arr=line.strip().split('\t')
>>    dict[line.split(None, 1)[0]]=arr
>
>Keys are integers, so they are very efficiently managed by the dict.

The keys aren't integers, though, they're strings. Though I don't
think that's going to make much difference.

You can still get the original result with a single split call
(which may indeed be a significant overhead):

for line in open(file)
   arr=line.strip().split('\t')
   dict[arr[0]]=arr

unless I've misunderstood the data format. (And if I have, is it
really the intention that "1 1\t1\t1" gets overwritten by a
subsequent "1 2\t3\t4" as the original code does?)

-- 
\S

   under construction

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


Problems resolved

2009-04-29 Thread Paul Hemans
Thanks to everyone for all the suggestions. Here's what I did:
Stuck with sqlAlchemy because I like the idea of ORMs and I like being able 
to abstract from the database vendor.
Left the schema definitions to be generated in a separate file, so that it 
could be re-used
Dumped xml.dom and went to lxml
Brought the data processing into the main program

Works like a charm and the code is poetry.
Great community. 


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


Re: What do you think of ShowMeDo

2009-04-29 Thread Berkin Malkoc
I do not get why the level of criticism is rising so high in some of
the messages.

I have nothing to say about more "philosophical" aspects of the issue
but would like to comment from a more pragmatic point of view:

I am completely happy with the *structure* of site (*visually* it may
get better, I agree): You choose your topic, go to the relevant page,
select among the video series and start watching at anyone video (ie
any level) you want. I think those of you criticising may be in some
kind of rush hence not being able to get this "structure". Or maybe
visual hints are more important than I think.

And you can do nothing about the content being too "simple". But me
personally I learned something more than None (see eg blender
tutorials). You should read the exlanations put below the videos  more
carefully anyway!

I did not get any broken link (and I visited quite a few videos), or
login requirement. Am I talking about another site?

A last, more subjective, comment: I think we must be more constructive
in our criticisms.

Regards.



On Wed, Apr 29, 2009 at 12:24 PM, Jeremiah Dodds
 wrote:
>
>
> On Wed, Apr 29, 2009 at 6:48 AM, Banibrata Dutta 
> wrote:
>>
>> Personally, I faced some despair with a large number of the free
>> ShowMeDo tutorials, example the one on WxPython, where for the first 4
>> free tutorials, the tutor hardly progresses to any bit of programming,
>> and what is demonstrated was too basic, too slow - to hold my
>> attention.
>
> I must agree here. I'll add that the vast majority of video tutorials or
> lectures that I've seen are way too slow to hold my interest, with the
> exception of google tech talks, and stuff like OCW from MIT. (These are at
> http://research.google.com/video.html and
> http://ocw.mit.edu/OcwWeb/web/home/home/index.htm respectively).
>
> However, I do really like the idea of showmedo, especially for people who
> like learning through not-so-dense video on the introductory level. I
> haven't been incredibly impressed with the quality of the free stuff there
> either, but I also haven't looked at any of the paid stuff. I don't think
> that it's safe to assume that it's of a substantially higher quality.
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Geohashing

2009-04-29 Thread djc
Raymond Hettinger wrote:
> import hashlib
> 
> def geohash(latitude, longitude, datedow):
> '''Compute geohash() in http://xkcd.com/426/
> 
> >>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
> 37.857713 -122.544543
> 
> '''
> h = hashlib.md5(datedow).hexdigest()
> p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16], h
> [16:32])]
> print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:]))
> 
> if __name__ == '__main__':
> import doctest
> doctest.testmod()

Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>>
>>> def geohash(latitude, longitude, datedow):
... '''Compute geohash() in http://xkcd.com/426/
...
... >>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
... 37.857713 -122.544543
...
... '''
... h = hashlib.md5(datedow).hexdigest()
... p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16],
h[16:32])]
... print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:]))
...
>>> if __name__ == '__main__':
... import doctest
... doctest.testmod()
...
**
File "__main__", line 4, in __main__.geohash
Failed example:
geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.5/doctest.py", line 1228, in __run
compileflags, 1) in test.globs
  File "", line 1
 geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
  ^
 SyntaxError: invalid syntax
**
1 items had failures:
   1 of   1 in __main__.geohash
***Test Failed*** 1 failures.
(1, 1)
>>>


-- 
djc @work
--
http://mail.python.org/mailman/listinfo/python-list


Re: Geohashing

2009-04-29 Thread Marco Mariani

djc wrote:


Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17)



 geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
  ^
 SyntaxError: invalid syntax



The byte type is new in 2.6

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-29 Thread Denis L
"Phil Thompson"  wrote in message 
news:mailman.4719.1240945001.11746.python-l...@python.org...
> On Tue, 28 Apr 2009 19:07:30 +0200, "Denis L"  wrote:
>> "Phil Thompson"  wrote in message
>> news:mailman.4699.1240932385.11746.python-l...@python.org...
>>
>>> If there was a bug with lambda slots it's been fixed by now.
>>
>> I just tried it and I'm getting the same errors with regular functions.
>>
>> Could you try running the code bellow? What output you are getting when
>> barTextChanged is called?
>>
>> On my system self.foo and text point to the same QString object.
>
> I see different objects.
>
> Phil

So it really was a PyQt bug. Thanks for your help. 


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


Re: Python servlet for Java applet ?

2009-04-29 Thread Linuxguy123
On Sat, 2009-04-25 at 02:00 +0200, Piet van Oostrum wrote:
> > Linuxguy123  (L) wrote:
> 
> >L> Hi guys.
> >L> Is there a way to use a python application as the back end (ie rpc) for
> >L> a Java based applet ?
> 
> Yes, you can use Corba, XMLRPC, SOAP, JSON-RPC. Corba probably will have
> to be tunnelled through port 80 (the others already do this by default
> because they are based on HTTP).
> 
> >L> How does it work compared to a Java servlet with a Java applet ?
> 
> With a Java applet communicating with a Java servlet you also have the
> option of using RMI. For the rest it is similar.

How does one "connect" the servlet to the applet ?  Does anyone know of
an example program that demonstrates a Python servlet with a Java
applet ?

Thanks !

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


Re: sorting items in a table problematic because of scientific notation

2009-04-29 Thread skip
>> Thanks.  Didn't used to be that way I don't think.

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> float('1.23456789e+004   ')
12345.6789

John> :-)

Maybe string.ato[if] used to behave that way?

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


Re: Python servlet for Java applet ?

2009-04-29 Thread Marco Bizzarri
On Wed, Apr 29, 2009 at 3:14 PM, Linuxguy123  wrote:
>
> How does one "connect" the servlet to the applet ?  Does anyone know of
> an example program that demonstrates a Python servlet with a Java
> applet ?
>
> Thanks !
>


Ok, let's make some basic questions:

1) do you know how to program an applet in order to invoke an URL on a server?

2) do you know how to program a server in order to answer to HTTP requests?

If the answer is *NO* in both cases, better if you take a look at this
topic in general (I'm sure you can google around a number of tutorials
on this) and then return here asking questions about what you're
unable to do in python.

Of course, these are my 2 cents.

Regards
Marco

-- 
Marco Bizzarri
http://sf.net/projects/qt-asterisk/
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Pythonic emptiness checking

2009-04-29 Thread Filip Gruszczyński
One of the Python Zen rules is Explicit is better implicit. And yet
it's ok to do:

if x:
   do_sth

when x is string or list. Since it's very comfy, I've got nothing
against though. I am just curious, why is it so?

And one more thing: is it ok to do

if x:

instead of

if x is not None:

Because I often encounter it and would like to know, if I can simplify
it. Especially that I liked similar construction in C/C++.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why bool( object )?

2009-04-29 Thread Bruno Desthuilliers

Lawrence D'Oliveiro a écrit :

In message <54cb7f8a-
fef4-4bf8-8054-16dc9b5c8...@d2g2000pra.googlegroups.com>, Aaron Brady wrote:


What is the rationale for considering all instances true of a user-
defined type?


It's a stupid idea, 


Nope, it's a very sensible default (given you can redefine the 
'nothingness' value of your types instances), specially when the 
language doesn't have a proper boolean type (which was the case for 
Python until 2.2 or 2.3, can't remember exactly).


and there seem to be instances of users tripping over it 
here in comp.lang.python every week.


Which is why some users opposed to the introduction of a boolean type in 
Python by the time. Please read Steven D'aprano's post upper in this 
thread, and follow the provided link. Laura Creighton was alas spot on: 
introducing a boolean type only resulted in confusion.




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


Re: Tools for web applications

2009-04-29 Thread Mario
On Tue, 28 Apr 2009 17:37:57 -0700, Daniel Fetchinson wrote:

>> What easyToLearn tools you suggest for creating: 1. powerfull web
>> applications
> 
> Have a look at http://wiki.python.org/moin/WebFrameworks
> 
> You will find that there are many options each with its own fan crowd
> emphasizing the advantages and downplaying the disadvantages of their
> favorite framework. You will pretty much have to decide for yourself
> which suits you best. I'm personally very happy with turbogears.
> 
>> 2. desktop applications
> 
> Dabo is a desktop application framework: http://dabodev.com/ Or you
> perhaps mean a GUI framework? Have a look at
> http://wiki.python.org/moin/GuiProgramming The same comments as above
> apply, you need to detail your requirements before an informed advice
> can be given.
> 
> Cheers,
> Daniel

And what IDE you suggest ? I need an information about tools for a quick 
start, so that I can decide about learning Ruby, python or something 
else. My field of interest is a small business applications (desktop and 
web), so that I have a practical tool for practical use of accounting and 
financial methods. 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic emptiness checking

2009-04-29 Thread Bruno Desthuilliers

Filip Gruszczyński a écrit :

One of the Python Zen rules is Explicit is better implicit. And yet
it's ok to do:

if x:
   do_sth

when x is string or list. Since it's very comfy, I've got nothing
against though. I am just curious, why is it so?


Because it is explicit (or at least considered as such) that in Python, 
an empty list or string (as well as empty tuples, dicts and sets and 
numeric zeros, False and None) have a false value in a boolean context.



And one more thing: is it ok to do

if x:

instead of

if x is not None:


Depends on the context. You of course understand that the two 
expressions are not equivalent, don't you ?-)


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


Re: Pythonic emptiness checking

2009-04-29 Thread Sibylle Koczian
Filip Gruszczyński schrieb:
> One of the Python Zen rules is Explicit is better implicit. And yet
> it's ok to do:
> 
> if x:
>do_sth
> 
> when x is string or list. Since it's very comfy, I've got nothing
> against though. I am just curious, why is it so?
> 
> And one more thing: is it ok to do
> 
> if x:
> 
> instead of
> 
> if x is not None:
> 
> Because I often encounter it and would like to know, if I can simplify
> it. Especially that I liked similar construction in C/C++.
> 
Depends on what you need. If your x is 0 or 0.0, '', the empty list,
dictionary or set, or a class instance with __len__ 0 or __nonzero__
false, then x is false, but "x is not None" is true.

HTH
Sibylle

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


Re: sorting items in a table problematic because of scientific notation

2009-04-29 Thread John Machin

On 29/04/2009 11:33 PM, s...@pobox.com wrote:

>> Thanks.  Didn't used to be that way I don't think.

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> float('1.23456789e+004   ')
12345.6789

John> :-)

Maybe string.ato[if] used to behave that way?


Nope.

  Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
  Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
  >>> import string
  >>> string.atof('1.234567')
  1.234567
  >>> string.atoi('1234567')
  1234567
  >>>


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


Re: Why bool( object )?

2009-04-29 Thread Aahz
In article <340175e7-b349-4ca2-bf66-fa9113253...@v23g2000pro.googlegroups.com>,
Aaron Brady   wrote:
>
>The sound of that metaphor is rather pleasing ('sweet nothings'), but
>I'm not so sure that metaphors belong in computer science and
>programming.  

Well, you won't be a good programmer if you can't wrap your head around
metaphor.  All programming is about translating human thought into human
language -- albeit a very special language with (mostly) precise rules.
Repeat: programming languages are human languages.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get item from set

2009-04-29 Thread Aahz
In article ,
Peter Otten  <__pete...@web.de> wrote:
>Aahz wrote:
>> In article ,
>> Peter Otten  <__pete...@web.de> wrote:
>>>
>>>Here's a trick to find the actual element. I think Raymond Hettinger
>>>posted an implementation of this idea recently, but I can't find it at the
>>>moment.
>> 
>> Your code is inverted from Raymond's:
>
>I can't see the inversion.

You were wrapping the objects inserted into the set; Raymond's trick
involved only wrapping the comparison object.  It's therefore much more
convenient.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tools for web applications

2009-04-29 Thread Mario
On Wed, 29 Apr 2009 13:38:53 +, Mario wrote:

> On Tue, 28 Apr 2009 17:37:57 -0700, Daniel Fetchinson wrote:
> 
>>> What easyToLearn tools you suggest for creating: 1. powerfull web
>>> applications
>> 
>> Have a look at http://wiki.python.org/moin/WebFrameworks
>> 
>> You will find that there are many options each with its own fan crowd
>> emphasizing the advantages and downplaying the disadvantages of their
>> favorite framework. You will pretty much have to decide for yourself
>> which suits you best. I'm personally very happy with turbogears.
>> 
>>> 2. desktop applications
>> 
>> Dabo is a desktop application framework: http://dabodev.com/ Or you
>> perhaps mean a GUI framework? Have a look at
>> http://wiki.python.org/moin/GuiProgramming The same comments as above
>> apply, you need to detail your requirements before an informed advice
>> can be given.
>> 
>> Cheers,
>> Daniel
> 
> And what IDE you suggest ? I need an information about tools for a quick
> start, so that I can decide about learning Ruby, python or something
> else. My field of interest is a small business applications (desktop and
> web), so that I have a practical tool for practical use of accounting
> and financial methods.

Is it NetBeans suitable for Python ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Noob - a couple questions involving a web app

2009-04-29 Thread Kyle T. Jones
Bruno Desthuilliers, my dear, dear friend, there was this time, oh, 
4/29/2009 3:02 AM or thereabouts, when you let the following craziness 
loose on Usenet:

Kyle T. Jones a écrit :
Been programming for a long time, but just starting out with Python. 
Not a professional programmer, just that guy in one of those 
organizations that won't hire a pro, instead saying "Hey, Kyle knows 
computer stuff - let's have him do this (and that, and the other, etc)".


So, the higher ups want a web app that'll let them enter (from an 
intranet page) a rather simple, but quite lengthy, list - details to 
be stored in a MySQL database... just normal stuff here, entering, 
editing, and deleting entries, sorting, etc.


On the internet side of things, folks get the info served up to them, 
can sort it in a few ways, etc - it's pretty basic stuff.



(snip)

I can only second Arnaud and Emile : Django is very probably what you're 
looking for, and by all means better than any PHP thingie - wrt/ both 
development time and security.


You'll indeed first have to learn the framework (and Python of course), 
and learn how to deploy your app in production (which can be a bit 
tricky if you're not familiar with server admin), but there's a good 
documentation and a very helpful community around both the Django 
framework and the Python language.




Thanks everyone!  Wow, pretty much a consensus - a rarity with these 
"types" of questions, at least in my experience.


Ok, sounds like I need to be looking at Django.  Thanks for the advice!

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


Re: sorting items in a table problematic because of scientific notation

2009-04-29 Thread skip
>> Maybe string.ato[if] used to behave that way?

John> Nope.
...

OK, I remember what it was.  The C atof()/atoi() functions will stop at the
first non-numeric character.  (I believe the more modern strtod/strtof
functions behave the same way.)  You could thus call

atof(" 12345 abcdef")

and get back 12345.  That I'm certain is an error in Python.  Somewhere in
my small walnut of a brain I must have conflated that with numeric strings
which contain extraneous whitespace but no other extra characters.

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


Inspecting And Changing Strings In Python

2009-04-29 Thread Jim Carlock
Anyone here able to provide a link to the Python functions for
comparing strings and updating strings? I'm looking to do some
character by character analysis until I find the '@' character
and then change the rest of the string after that.

Thank you for your help.

-- 
Jim Carlock
http://www.microcosmotalk.com/


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


Re: Inspecting And Changing Strings In Python

2009-04-29 Thread Joel Madigan
Start here:
http://www.lmgtfy.com/?q=python+string

On Wed, Apr 29, 2009 at 10:36 AM, Jim Carlock
 wrote:
> Anyone here able to provide a link to the Python functions for
> comparing strings and updating strings? I'm looking to do some
> character by character analysis until I find the '@' character
> and then change the rest of the string after that.
>
> Thank you for your help.
>
> --
> Jim Carlock
> http://www.microcosmotalk.com/
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic emptiness checking

2009-04-29 Thread Filip Gruszczyński
Yes, I get the difference. If x is [], than

if x:

won't be executed and

if x is not None:

will be.

Thanks for clarifying.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Inspecting And Changing Strings In Python

2009-04-29 Thread Duncan Booth
"Jim Carlock"  wrote:

> Anyone here able to provide a link to the Python functions for
> comparing strings and updating strings? I'm looking to do some
> character by character analysis until I find the '@' character
> and then change the rest of the string after that.
> 
You cannot update a string: you must just build a new string with whatever 
content you require.

Something like (assuming your input is in the variable 'input':

def process(input):
  prefix, suffix = input.split('@')
  do_analysis(prefix)
  return prefix + '@' + create_new_suffix(suffix)

Have you been through the tutorial? 
http://www.python.org/doc/current/tutorial/index.html


-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict is really slow for big truck

2009-04-29 Thread Bruno Desthuilliers

bearophileh...@lycos.com a écrit :

On Apr 28, 2:54 pm, forrest yang  wrote:

i try to load a big file into a dict, which is about 9,000,000 lines,
something like
1 2 3 4
2 2 3 4
3 4 5 6

code
for line in open(file)
   arr=line.strip().split('\t')
   dict[line.split(None, 1)[0]]=arr

but, the dict is really slow as i load more data into the memory, by
the way the mac i use have 16G memory.
is this cased by the low performace for dict to extend memory or
something other reason.
is there any one can provide a better solution


Keys are integers,


Actually strings. But this is probably not the problem here.


so they are very efficiently managed by the dict.
If I do this:
d = dict.fromkeys(xrange(900))
It takes only a little more than a second on my normal PC.
So probably the problem isn't in the dict, it's the I/O


If the OP experiments a noticeable slow down during the process then I 
doubt the problem is with IO. If he finds the process to be slow but of 
constant slowness, then it may or not have to with IO, but possibly not 
as the single factor.


Hint : don't guess, profile.


and/or the
list allocation. A possible suggestion is to not split the arrays,


The OP is actually splitting a string.


but
keep it as strings, and split them only when you use them:

d = {}
for line in open(file):
  line = line.strip()
  d[line.split(None, 1)[0]] = line


You still split the string - but only once, which is indeed better !-)

Bu you can have your cake and eat it too:

d = {}
for line in open(thefile):
   arr = line.strip().split()
   d[arr[0]] = arr



if that's not fast enough you can simplify it:

d = {}
for line in open(file):
  d[line.split(None, 1)[0]] = line


I doubt this will save that much processing time...


If you have memory problems still, then you can only keep the line
number as dict values, of even absolute file positions, to seek later.
You can also use memory mapped files.

Tell us how is the performance now.


IMHO, not much better...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Noob - a couple questions involving a web app

2009-04-29 Thread David Smith
Kyle T. Jones wrote:
> Bruno Desthuilliers, my dear, dear friend, there was this time, oh,
> 4/29/2009 3:02 AM or thereabouts, when you let the following craziness
> loose on Usenet:
>> Kyle T. Jones a écrit :
>>> Been programming for a long time, but just starting out with Python.
>>> Not a professional programmer, just that guy in one of those
>>> organizations that won't hire a pro, instead saying "Hey, Kyle knows
>>> computer stuff - let's have him do this (and that, and the other, etc)".
>>>
>>> So, the higher ups want a web app that'll let them enter (from an
>>> intranet page) a rather simple, but quite lengthy, list - details to
>>> be stored in a MySQL database... just normal stuff here, entering,
>>> editing, and deleting entries, sorting, etc.
>>>
>>> On the internet side of things, folks get the info served up to them,
>>> can sort it in a few ways, etc - it's pretty basic stuff.
>>>
>> (snip)
>>
>> I can only second Arnaud and Emile : Django is very probably what
>> you're looking for, and by all means better than any PHP thingie -
>> wrt/ both development time and security.
>>
>> You'll indeed first have to learn the framework (and Python of
>> course), and learn how to deploy your app in production (which can be
>> a bit tricky if you're not familiar with server admin), but there's a
>> good documentation and a very helpful community around both the Django
>> framework and the Python language.
>>
> 
> Thanks everyone!  Wow, pretty much a consensus - a rarity with these
> "types" of questions, at least in my experience.
> 
> Ok, sounds like I need to be looking at Django.  Thanks for the advice!
> 
> Cheers!

Consensus?! ... that just won't do. :-)

I've started with Pylons and have found it very nice.  Loose enough to
tinker with the inner workings but complete and working right out of the
box (or paster in Pylons case).

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


Re: Python Noob - a couple questions involving a web app

2009-04-29 Thread Kyle Terry
On Wed, Apr 29, 2009 at 8:24 AM, David Smith  wrote:

> Kyle T. Jones wrote:
> > Bruno Desthuilliers, my dear, dear friend, there was this time, oh,
> > 4/29/2009 3:02 AM or thereabouts, when you let the following craziness
> > loose on Usenet:
> >> Kyle T. Jones a écrit :
> >>> Been programming for a long time, but just starting out with Python.
> >>> Not a professional programmer, just that guy in one of those
> >>> organizations that won't hire a pro, instead saying "Hey, Kyle knows
> >>> computer stuff - let's have him do this (and that, and the other,
> etc)".
> >>>
> >>> So, the higher ups want a web app that'll let them enter (from an
> >>> intranet page) a rather simple, but quite lengthy, list - details to
> >>> be stored in a MySQL database... just normal stuff here, entering,
> >>> editing, and deleting entries, sorting, etc.
> >>>
> >>> On the internet side of things, folks get the info served up to them,
> >>> can sort it in a few ways, etc - it's pretty basic stuff.
> >>>
> >> (snip)
> >>
> >> I can only second Arnaud and Emile : Django is very probably what
> >> you're looking for, and by all means better than any PHP thingie -
> >> wrt/ both development time and security.
> >>
> >> You'll indeed first have to learn the framework (and Python of
> >> course), and learn how to deploy your app in production (which can be
> >> a bit tricky if you're not familiar with server admin), but there's a
> >> good documentation and a very helpful community around both the Django
> >> framework and the Python language.
> >>
> >
> > Thanks everyone!  Wow, pretty much a consensus - a rarity with these
> > "types" of questions, at least in my experience.
> >
> > Ok, sounds like I need to be looking at Django.  Thanks for the advice!
> >
> > Cheers!
>
> Consensus?! ... that just won't do. :-)
>
> I've started with Pylons and have found it very nice.  Loose enough to
> tinker with the inner workings but complete and working right out of the
> box (or paster in Pylons case).
>
> --David
> --
> http://mail.python.org/mailman/listinfo/python-list


This Kyle T. is starting with Python as well.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why bool( object )?

2009-04-29 Thread Marco Mariani

Bruno Desthuilliers wrote:


Lawrence D'Oliveiro a écrit :



What is the rationale for considering all instances true of a user-
defined type?


It's a stupid idea, 


Nope, it's a very sensible default (given you can redefine the 
'nothingness' value of your types instances), specially when the 
language doesn't have a proper boolean type (which was the case for 
Python until 2.2 or 2.3, can't remember exactly).


Man, you've given a serious answer to a sarcastic reply to an OP who has 
been -- for years -- second in trolliness only to Xah Lee.


Either that, or I have to replace my humor detector.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get item from set

2009-04-29 Thread Peter Otten
Aahz wrote:

> In article ,
> Peter Otten  <__pete...@web.de> wrote:
>>Aahz wrote:
>>> In article ,
>>> Peter Otten  <__pete...@web.de> wrote:

Here's a trick to find the actual element. I think Raymond Hettinger
posted an implementation of this idea recently, but I can't find it at
the moment.
>>> 
>>> Your code is inverted from Raymond's:
>>
>>I can't see the inversion.
> 
> You were wrapping the objects inserted into the set; Raymond's trick
> involved only wrapping the comparison object.  It's therefore much more
> convenient.

I think you are misreading my code. I took the items (of class X) as they 
were specified by the OP.

The reason I changed their __eq__() method is not that I did not understand 
Raymond's trick, but rather a quirk in the set's item lookup:

>>> class A(object):
... def __init__(self, value):
... self.value = value
... def __hash__(self):
... return hash(self.value)
... def __eq__(self, other):
... return self.value == other.value
...
>>> item = A("a")
>>> container = map(A, "abc")
>>> from get_equivalent import get_equivalent
TestResults(failed=0, attempted=0)

get_equivalent() is Raymond's implementation from the recipe. Let's try it:

>>> get_equivalent(container, item)
<__main__.A object at 0x2091e50>
>>> _ is not item
True

Works. Now the same with a set:

>>> container = set(container)
>>> print get_equivalent(container, item)
None

Oops.

wanted in some_list

performs wanted.__eq__(candidate) 

where candidate is an item in the list.

wanted in some_set

tries

candidate.__eq__(wanted) 

first. You must ensure that this fails in an orderly manner for

wanted.__eq__(candidate)

to be tried at all:

>>> def __eq__(self, other):
... if not isinstance(other, A):
... return NotImplemented
... return self.value == other.value
...
>>> A.__eq__ = __eq__
>>> print get_equivalent(container, item)
<__main__.A object at 0x2091e50>
>>> _ is not item
True

Peter

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


Re: Get item from set

2009-04-29 Thread Aahz
In article ,
Peter Otten  <__pete...@web.de> wrote:
>Aahz wrote:
>> In article ,
>> Peter Otten  <__pete...@web.de> wrote:
>>>Aahz wrote:
 In article ,
 Peter Otten  <__pete...@web.de> wrote:
>
>Here's a trick to find the actual element. I think Raymond Hettinger
>posted an implementation of this idea recently, but I can't find it at
>the moment.
 
 Your code is inverted from Raymond's:
>>>
>>>I can't see the inversion.
>> 
>> You were wrapping the objects inserted into the set; Raymond's trick
>> involved only wrapping the comparison object.  It's therefore much more
>> convenient.
>
>I think you are misreading my code. I took the items (of class X) as they 
>were specified by the OP.
>
>The reason I changed their __eq__() method is not that I did not understand 
>Raymond's trick, but rather a quirk in the set's item lookup:

Gotcha -- thanks for the explanation!
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tools for web applications

2009-04-29 Thread Daniel Fetchinson
>>> What easyToLearn tools you suggest for creating: 1. powerfull web
>>> applications
>>
>> Have a look at http://wiki.python.org/moin/WebFrameworks
>>
>> You will find that there are many options each with its own fan crowd
>> emphasizing the advantages and downplaying the disadvantages of their
>> favorite framework. You will pretty much have to decide for yourself
>> which suits you best. I'm personally very happy with turbogears.
>>
>>> 2. desktop applications
>>
>> Dabo is a desktop application framework: http://dabodev.com/ Or you
>> perhaps mean a GUI framework? Have a look at
>> http://wiki.python.org/moin/GuiProgramming The same comments as above
>> apply, you need to detail your requirements before an informed advice
>> can be given.
>>
>> Cheers,
>> Daniel
>
> And what IDE you suggest ?

I use vi, I like it much more than any IDE (or is vi an IDE?). Your
needs might be different though. I'd suggest using something you are
already familiar with, most IDEs work with different languages so if
you used one already chances are it will understand python too.

> I need an information about tools for a quick
> start, so that I can decide about learning Ruby, python or something
> else.

This will give you a good start: http://docs.python.org/tutorial/index.html
And also this: http://diveintopython.org/

> My field of interest is a small business applications (desktop and
> web), so that I have a practical tool for practical use of accounting and
> financial methods.

Well, pretty much any modern dynamical language will be suitable for
what you describe. I would personally recommend python but that
doesn't mean ruby or anything else can't do the job, you have to
decide which language "feels" right for you.

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Screenshot of a web page

2009-04-29 Thread Daniel Fetchinson
> Are you aware of any python module that automatically gives you a
> screenshot of a web page?


http://mail.python.org/pipermail/tutor/2008-December/065847.html

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Return value usage

2009-04-29 Thread Zac Burns
I would like to know when my function is called whether or not the
return value is used. Is this doable in python? If it is, can it ever
be pythonic?

The use case is that I have functions who's side effects and return
values are cached. I would like to optimize them such that I don't
have to recall (from a network) the return values if they are not
used. Obviously it would be possible to add a parameter to the
function but I would like this optimization to be implemented
passively because 1. The api is already widely used and 2. I would
like to keep the complexity of the api to a bare minimum.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict is really slow for big truck

2009-04-29 Thread Scott David Daniels

Bruno Desthuilliers wrote:

d = {}
for line in open(thefile):
   arr = line.strip().split()
   d[arr[0]] = arr


Sorry, not picking on Bruno in particular, but I keep seeing
this formulation around various places.
When does line.strip().split() ever differ from line.split()?

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


Re: fcntl and siginfo_t in python

2009-04-29 Thread ma
 Here's something that I came up with so far, I'm having some issues with
segfaulting, if I want to pass a struct member by ref in ctypes(see below),
if not, I just get a
"Real-time signal 0" sent back to me.

Any ideas?

#!/usr/bin/env python import os, sys, re
try: import fcntl
except ImportError:
 raise OSError, "Only runs on unix!"
 import signal from ctypes import * #ugh, but just for this exercise from
ctypes import util ### # sigaction /
siginfo structs ### # struct sigaction {
# void (*sa_handler)(int); # void (*sa_sigaction)(int, siginfo_t *, void *);
# sigset_t sa_mask; # int sa_flags; # void (*sa_restorer)(void); # }
## class sigval(Union): _fields_ = [
('sival_int', c_int), ('sival_ptr', c_void_p), ] class __siginfo(Structure):
_fields_ = [ ('si_signo', c_int), ('si_errno', c_int), ('si_code', c_int),
('si_pid', c_uint), ('si_uid', c_uint), ('si_status', c_int), ('si_addr',
c_void_p), ('si_value', sigval), ('si_band', c_long), ('pad', c_ulong * 7),
] siginfo_t = __siginfo class __sigaction_u(Union): _fields_ = [
('__sa_handler', CFUNCTYPE(None, c_int)), ('__sa_sigaction', CFUNCTYPE(None,
c_int,  POINTER(siginfo_t),
 c_void_p)), ] sigaction_u = __sigaction_u class __sigaction(Structure):
_fields_ = [ ('__sigaction_u',sigaction_u), ('sa_tramp', CFUNCTYPE(None,
c_void_p,
c_int, c_int,
 POINTER(siginfo_t), c_void_p)), ('sa_mask', c_uint), ('sa_flags', c_int), ]
class sigaction(Structure): _fields_ = [ ('__sigaction_u', sigaction_u),
('sa_mask', c_uint), ('sa_flags', c_int), ]
### # END sigaction / siginfo structs
## #call back that should be signalled,
void so return nothing def detailed_callback(signalno, siginfostruct, data):
print "detailed callback: ", signalno, \
siginfostruct, \
 data #ctypes prototype implementation C_PROTOTYPE_SIGNHANDLER =
CFUNCTYPE(None, c_int,
POINTER(__siginfo), c_void_p) #cast callback sighandler_cb =
C_PROTOTYPE_SIGNHANDLER(detailed_callback)
# # globals/literals
# ABS_PATH_LIBC =
util.find_library('libc') FCNTL_FLAGS=
[fcntl.DN_MODIFY,fcntl.DN_CREATE,fcntl.DN_DELETE,fcntl.DN_RENAME]
FCNTL_BIT_FLAG = reduce(lambda x, y: x | y, FCNTL_FLAGS) |
fcntl.DN_MULTISHOT #get library __clib = cdll.LoadLibrary(ABS_PATH_LIBC)
assert __clib is not None
#struct sigaction act; act = sigaction()

#act.sa_sigaction = handler;
act.__sigaction_u.sa_sigaction = sighandler_cb

#sigemptyset(&act.sa_mask);
#python2.6 has byref(act, offset),how can i port this over?
#maybe addressof(act)+sizeof(sigaction.sa_mask)*(position_in_sigaction)
rc = __clib.sigemptyset(byref(act))
assert rc == 0

#act.sa_flags = SA_SIGINFO;
#/usr/include/bit/signum.h SA_SIGINFO
#TODO: look this up from python act.sa_flags = 4;

#sigaction(SIGRTMIN, &act, NULL);
#signal.signal( signal.SIGRTMIN, sighandler_cb )
rc = __clib.sigaction( signal.SIGRTMIN, byref(act), None ) assert rc == 0

#fd stuff, open cwd, monitor for changes, should invoke
#my callback.. __fd = os.open(os.getcwd(), os.O_RDONLY | os.O_NONBLOCK)
__clib.fcntl( __fd, fcntl.F_SETSIG, signal.SIGRTMIN) __clib.fcntl( __fd,
fcntl.F_NOTIFY, FCNTL_BIT_FLAG ) import time while True: signal.pause()
--
http://mail.python.org/mailman/listinfo/python-list


Installing Python 2.5.4 from Source under Windows

2009-04-29 Thread Paul Franz

I have looked and looked and looked. But I can not find any directions

on how to install the version of Python build using Microsoft's 
compiler. It builds. I get the dlls and the exe's. But there is no 
documentation that says how to install what has been built. I have read 
every readme and stop by the IRC channel and there seems to be nothing.


Any ideas where I can look?

Paul Franz


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


Re: Return value usage

2009-04-29 Thread Simon Brunning
2009/4/29 Zac Burns :
> I would like to know when my function is called whether or not the
> return value is used. Is this doable in python? If it is, can it ever
> be pythonic?

AFAIK, no, it's not.

> The use case is that I have functions who's side effects and return
> values are cached. I would like to optimize them such that I don't
> have to recall (from a network) the return values if they are not
> used. Obviously it would be possible to add a parameter to the
> function but I would like this optimization to be implemented
> passively because 1. The api is already widely used and 2. I would
> like to keep the complexity of the api to a bare minimum.

Why not return a proxy, and have the proxy do the retrieval of the
needed data if it's used? Delegation is ridiculously easy in Python.

-- 
Cheers,
Simon B.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Return value usage

2009-04-29 Thread Zac Burns
On Wed, Apr 29, 2009 at 10:14 AM, Simon Brunning
 wrote:
> 2009/4/29 Zac Burns :

> Why not return a proxy, and have the proxy do the retrieval of the
> needed data if it's used? Delegation is ridiculously easy in Python.

Interesting idea. I like it.

I've looked through some recipes here, but everything I've looked at
has limitations regarding magic methods and such. Several of the
workarounds involve creating a new subclass on the fly, but without
reading the pickle file to know the type of the return value that
would not be possible.

How would you suggest implementing the delegation? Do you know of a
particularly useful recipe?

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games
--
http://mail.python.org/mailman/listinfo/python-list


Re: Return value usage

2009-04-29 Thread MRAB

Zac Burns wrote:

I would like to know when my function is called whether or not the
return value is used. Is this doable in python? If it is, can it ever
be pythonic?


It doesn't sound Pythonic to me.


The use case is that I have functions who's side effects and return
values are cached. I would like to optimize them such that I don't
have to recall (from a network) the return values if they are not
used. Obviously it would be possible to add a parameter to the
function but I would like this optimization to be implemented
passively because 1. The api is already widely used and 2. I would
like to keep the complexity of the api to a bare minimum.


The point of caching is that it lets you retrieve a result cheaply that
was expensive to produce by saving the result in case it's needed again.
If the caching itself is expensive because it requires network access
then, IMHO, that's not proper caching! (You would need a 2-level cache,
ie a small local cache to speed up your a larger network-based cache; a
cache for a cache.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework for embedded system

2009-04-29 Thread Thomas Heller
Thomas Heller schrieb:
> I'm looking for a lightweight web-framework for an embedded system.
> The system is running a realtime linux-variant on a 200 MHz ARM
> processor, Python reports a performance of around 500 pystones.
> 
> The web application will not be too fancy, no databases involved
> for example, but it will need to control some simple peripherals
> (some parallel in/out, some dacs) attached to the system.
> 
> It should provide a user interface showing the current state and
> allowing to manipulate it via a browser, and I will probably need
> to support some rpc as well.

Thanks for all the replies I got.

I will take the 'traditional' route, and probably go with cherrypy first,
but will still keep an eye on webpy.

I'm very happy to see that these frameworks deliver ~10 pages per second
(cherrypy) or ~3.5 pages per second (webpy) out of the box on a system
that is 50 times slower than a typical desktop PC.  Of course these
were very short pages.


The other ideas that were posted, the SIMPL toolkit and the
'Batteries Included! Python on Low Cost Tiny Embedded Wireless Devices'
stuff, are very interesting as well, but not for this project.  Food for
thought, at least.


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


Python installation challenge

2009-04-29 Thread Evan Kroske
I'm not one to overreact, but I've got a serious problem with my Python
installation. I've tried to install from source, and I've tried to install
with apt-get, but no matter which method I use, my installation is crippled.
When I try to install Python 2.6.2 or 2.6.1, the installer warns me that it
has failed to install zlib and binascii. I promptly looked up my error and
found only a single other instance of it:
http://www.velocityreviews.com/forums/t648624-building-from-source-zlibbinascii-problems-252261.html.
I asked the python help mailing list for answers, but that effort stalled
out as well and didn't leave a public record (python-help's archives are
private.)

I will try to provide all the necessary information, and I'll be glad to
execute whatever tests or experiments you need. However, I will need
specific instructions because I don't have much experience with Linux and
the terminal. I'm using Intrepid Ibex 64 bit on a PC. Attached is a zip file
containing the output of ./configure and make. If you need any more info,
just tell me how to get it for you. Thanks for helping.

Best regards,
Evan Kroske
--
http://mail.python.org/mailman/listinfo/python-list


import and package confusion

2009-04-29 Thread Dale Amon
I am going around in circles right now and have to
admit I do not understand what is going on with
import of hierarchical packages/modules. Perhaps someone
can get me on the road again. Here is a subset of what I 
am trying to accomplish:

The package directory set up:

VLMLegacy/
  __init__.py
  Reader.py
  Conditions.py
  VLM4997/
__init__.py
Conditions.py
  WINGTL/
__init__.py
Conditions.py

The inheritance:

object
  Reader
Conditions
  VLM4997.Conditions
  WINGTL.Conditions


Now how do I use import or from to be able to 
use these modules? The following is not 'real'
code and is only intended to give some idea of
what I am trying to accomplish:

import sys
sys.path.extend (['../lib', '../bin'])

import VLMLegacy.VLM4997.Conditions
import VLMLegacy.WINGTL.Conditions

b = VLM4997.Conditions(2)
b.test()

c = WINGTL.Conditions(2)
c.test()

And of course note that both of those must inherit
VLMLegacy.Conditions().



signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Return value usage

2009-04-29 Thread Zac Burns
> The point of caching is that it lets you retrieve a result cheaply that
> was expensive to produce by saving the result in case it's needed again.
> If the caching itself is expensive because it requires network access
> then, IMHO, that's not proper caching! (You would need a 2-level cache,
> ie a small local cache to speed up your a larger network-based cache; a
> cache for a cache.)
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Agreed, to some extent.

In my application the cache resulted in enormous savings over
calculating every time - but still several minutes could be saved in
some common use cases.

Calculating the values is very expensive indeed (anywhere between
seconds and minutes each). Getting the cached values takes ~.05sec.
However, it is common to request 1 or so calculations - which
costs ~8min. Of those, perhaps 10% actually use the return value - all
of them use the side effects. Also the full cache is very large - in
the hundreds of GB. Having a local cache wouldn't help because
generally a machine wouldn't request the same cached values twice.
They are borrowing runtime from other machines.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python installation challenge

2009-04-29 Thread skip

Evan> ...  've tried to install from source, and I've tried to install
Evan> with apt-get, but no matter which method I use, my installation is
Evan> crippled.  When I try to install Python 2.6.2 or 2.6.1, the
Evan> installer warns me that it has failed to install zlib and
Evan> binascii.

Do you have the zlib -dev package installed?  If not, you need it.  Dunno if
that will affect binascii installation.  Pick through the setup.py file
looking for binascii.  See what header files it's looking for.

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/
America's vaunted "free press" notwithstanding, story ideas that expose
the unseemly side of actual or potential advertisers tend to fall by the
wayside.  Not quite sure why.  -- Jim Thornton
--
http://mail.python.org/mailman/listinfo/python-list


Re: Screenshot of a web page

2009-04-29 Thread Дамјан Георгиевски
> Are you aware of any python module that automatically gives you a
> screenshot of a web page?

PyQt then use it's WebKit based component, load the web page, then 
render it into an image.


-- 
дамјан ( http://softver.org.mk/damjan/ )

Give me the knowledge to change the code I do not accept, 
the wisdom not to accept the code I cannot change, 
and the freedom to choose my preference.

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


Re: Return value usage

2009-04-29 Thread MRAB

Zac Burns wrote:

The point of caching is that it lets you retrieve a result cheaply that
was expensive to produce by saving the result in case it's needed again.
If the caching itself is expensive because it requires network access
then, IMHO, that's not proper caching! (You would need a 2-level cache,
ie a small local cache to speed up your a larger network-based cache; a
cache for a cache.)



Agreed, to some extent.

In my application the cache resulted in enormous savings over
calculating every time - but still several minutes could be saved in
some common use cases.

Calculating the values is very expensive indeed (anywhere between
seconds and minutes each). Getting the cached values takes ~.05sec.
However, it is common to request 1 or so calculations - which
costs ~8min. Of those, perhaps 10% actually use the return value - all
of them use the side effects. Also the full cache is very large - in
the hundreds of GB. Having a local cache wouldn't help because
generally a machine wouldn't request the same cached values twice.
They are borrowing runtime from other machines.


I'd probably suggest a local cache storing the most recently requested
results, backed up by a larger non-local cache.

You could even record how long it takes to produce each result and how
often or how recently it has been requested; you might decide not to
cache some values in order to reduce the size of the cache if it won't
affect the overall processing time significantly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict is really slow for big truck

2009-04-29 Thread MRAB

Scott David Daniels wrote:

Bruno Desthuilliers wrote:

d = {}
for line in open(thefile):
   arr = line.strip().split()
   d[arr[0]] = arr


Sorry, not picking on Bruno in particular, but I keep seeing
this formulation around various places.
When does line.strip().split() ever differ from line.split()?


http://www.python.org/doc/current/library/stdtypes.html?highlight=split#str.split

If sep is not specified or is None, a different splitting algorithm is 
applied: runs of consecutive whitespace are regarded as a single 
separator, and the result will contain no empty strings at the start or 
end if the string has leading or trailing whitespace. Consequently, 
splitting an empty string or a string consisting of just whitespace with 
a None separator returns [].

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


Re: import and package confusion

2009-04-29 Thread Scott David Daniels

Dale Amon wrote:

I am going around in circles right now and have to
admit I do not understand what is going on with
import of hierarchical packages/modules. Perhaps someone
can get me on the road again. Here is a subset of what I 
am trying to accomplish:


The package directory set up:

VLMLegacy/
  __init__.py
  Reader.py
  Conditions.py
  VLM4997/
__init__.py
Conditions.py
  WINGTL/
__init__.py
Conditions.py

The inheritance:
object
  Reader
Conditions
  VLM4997.Conditions
  WINGTL.Conditions

>
Now how do I use import or from to be able to 
use these modules? The following is not 'real'

code and is only intended to give some idea of
what I am trying to accomplish:

import sys
sys.path.extend (['../lib', '../bin'])

import VLMLegacy.VLM4997.Conditions
import VLMLegacy.WINGTL.Conditions

Each of these imports a module in a subpackage in a package.


b = VLM4997.Conditions(2)

I see some confusion here.
(1) This should give a NameError('VLM4997')
(2) Even if changed to b = VLMLegacy.VLM4997.Conditions(2),
You are calling an imported module, rather than a function or class.

So, using my crystal ball (which came back from the shop covered
in some sticky fluid), I guess you might mean:
import VLMLegacy.VLM4997.Conditions.Conditions as VLM4997_Conditions
import VLMLegacy.WINGTL.Conditions.Conditions as WINGTL_Conditions
...
b = VLM4997_Conditions(2)
b.test()
...

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


Re: import and package confusion

2009-04-29 Thread Dale Amon
I am trying to get to the heart of what it is I am
missing. Is it the case that if you have a module C in a 
package A:

A.C

that there is no way to load it such that you can use:

x = A.C()

in your code? This is just a simpler case of what I'm
trying to do now, which has a module C in a sub-package
to be imported:

A.B.C

ie with files:
mydir/A/B/C.py
mydir/mymain.py

and executed in mymain.py as:

x = A.B.C()

I may still chose to do it the way you suggested, but I
would still like to understand why this does not work.



signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Would you support adding UNC support to os.path on Windows?

2009-04-29 Thread Larry Hastings


norseman wrote:
"...This patch changes "ntpath" ..."changing or adding to such a 
module which is OS specific is fine with me.

[...]
To point it bluntly:  How does one use "F:" in Linux in the identical 
fashion as a MicroSoft OS?


Sorry, I assumed this was common knowledge: os.path is implemented by 
different modules depending on what operating system you're using.  On 
Windows it uses "ntpath", on OS2 it may use "os2emxpath" or "ntpath" 
depending, and on all other platforms it uses "posixpath".  My patch 
adds UNC path support to "ntpath"; it does not modify the other "path" 
implementations.


And sorry for the late reply,


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


Re: dict is really slow for big truck

2009-04-29 Thread Scott David Daniels

MRAB wrote:

Scott David Daniels wrote:

Bruno Desthuilliers wrote:

d = {}
for line in open(thefile):
   arr = line.strip().split()
   d[arr[0]] = arr


Sorry, not picking on Bruno in particular, but I keep seeing
this formulation around various places.
When does line.strip().split() ever differ from line.split()?

... 


You misunderstand the question.  For what values of line is
the following expression False?

line.strip().split() == line.split()

If you know of one, I'd like to hear of it.  If not, I assert
that (baring some incredibly over-ambitous optimizer operations)
line.strip().split()
is simply an inefficient (both performance and text) way of saying:
line.split()

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


Re: import and package confusion

2009-04-29 Thread Scott David Daniels

Dale Amon wrote:

I am trying to get to the heart of what it is I am
missing. Is it the case that if you have a module C in a 
package A:

A.C
that there is no way to load it such that you can use:
x = A.C()
in your code? 

OK, here's a simple question.  What do you expect from:
   import sys
   sys()
sys is a module, and as such, it is not callable.
Just because you put a class inside a module, does not mean
that class magically does something by virtue of having the
same name as the module.

A module is a namespace to hold classes, functions, etc
A package is a namespace to hold modules (possibly more).

I don't understand why you don't use files like:

VLMLegacy/
 __init__.py
 Reader.py
 VLM4997.py
 WINGTL.py
But, presuming some kind of rationale,
put the code you want in 
	VLMLegacy/VLM4997/__init__.py


--Scott David Daniels
scott.dani...@acm.org


--Scott David Daniels
scott.dani...@acm.org

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


Re: dict is really slow for big truck

2009-04-29 Thread J. Cliff Dyer
On Wed, 2009-04-29 at 10:05 -0700, Scott David Daniels wrote:
> Bruno Desthuilliers wrote:
> > d = {}
> > for line in open(thefile):
> >arr = line.strip().split()
> >d[arr[0]] = arr
> 
> Sorry, not picking on Bruno in particular, but I keep seeing
> this formulation around various places.
> When does line.strip().split() ever differ from line.split()?

Good question.  I can't count the number of times I've used
line.strip().split() in my own code, just because I didn't 1) read the
documentation closely enough, or 2) try the alternative, but lo and
behold, they are the same, at least in the cases I was trying to account
for.

' a b c '.split() == ' a b c '.strip().split() == 'a b c'.split()

Thanks for pointing this out.

Cheers,
Cliff


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


Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 01:12:33PM -0700, Scott David Daniels wrote:
> Dale Amon wrote:
>> I am trying to get to the heart of what it is I am
>> missing. Is it the case that if you have a module C in a package A:
>>  A.C
>> that there is no way to load it such that you can use:
>>  x = A.C()
>> in your code? 
> OK, here's a simple question.  What do you expect from:
>import sys
>sys()
> sys is a module, and as such, it is not callable.
> Just because you put a class inside a module, does not mean
> that class magically does something by virtue of having the
> same name as the module.
>
> A module is a namespace to hold classes, functions, etc
> A package is a namespace to hold modules (possibly more).
>
> I don't understand why you don't use files like:
>
>   VLMLegacy/
>  __init__.py
>  Reader.py
>  VLM4997.py
>  WINGTL.py

Well, it is far more complex than that: I just cut it down to 
the most minimal case I could.

> But, presuming some kind of rationale,
> put the code you want in  VLMLegacy/VLM4997/__init__.py

That doesn't really do it. Perhaps I should try to describe
the situation better.

There are n different similar systems, each with multiple classes.
They could either be implimented as a class at the first level:

VLMLegacy
   Condition.py
   Plan.py
 |
 |
etc

but in that case each class will be filled with conditionals
that try to do the correct thing depending on which system's
data they are reading. That approach has already gotten *insane*
and I need to objectify things: put all the common code into 
abstract superclasses, and then create a subclass for each 
different system (of which there will be an unknown number added
over time), ie:

VLMLegacy/
   Conditions.pyAbstract classes
   Plan.py
 |
 |
etc
   TYPE1/   Subclasses of above specific to Type 1
   Conditions.py
   Plan.py
 |
 |
etc
   TYPE2/   Subclasses for Type 2
   Conditions.py
   Plan.py
 |
 |
etc

 |
   TYPEn/   Subclasses for Type n
   Conditions.py
   Plan.py
 |
 |
etc

Every VLMLegacy.TYPEn.Conditions (or other class) has exactly
the same set of methods; each of those methods inherits much 
of its basic behavior from VLMLegacy.Conditions.

If I make every subclass a unique name, things will
rapidly get out of hand, especially when I start
adding TYPEn+1,2... etc.

So yes, the approach isn't arbitrary, it is a solution
to real design problems which even the above does not
fully do justice to.

What I would really like to do when executing is more
like:

type = "VLM4997"
type.Header(args)
type.Plan(args)
type.Conditions(args)

Where the type might change from execution to execution
or even on different iterations.



signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 04:34:03PM -0400, Dale Amon wrote:
>   type = "VLM4997"
>   type.Header(args)
>   type.Plan(args)
>   type.Conditions(args)
> Where the type might change from execution to execution
> or even on different iterations.

Actually let me make that reflect more accurately what
is going on:

obj = Deck(rdr)
obj.header  = type.Header(rdr)
obj.plan[0] = type.Plan(rdr)
obj.plan[1] = type.Plan(rdr)
obj.cond= type.Conditions(rdr)

obj.cond.calcsomething(args)

and so forth through many pages of code...






signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


numpy choosing groups / clusters of values

2009-04-29 Thread T Kirstine
I have a numpy array and would like to get the values from the array where
groups  of values are the same.

Select the groups of 0 where group is > 3 and change 0 to 5

This
[3, 2, 1, 0, 0],
[1, 0, 3, 0, 0],
[2, 0, 1, 3, 0],
[0, 2, 3, 3, 0]

to this
[3, 2, 1, 5, 5],
[1, 0, 3, 5, 5],
[2, 0, 1, 3, 5],
[0, 2, 3, 3, 5]

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


Re: import and package confusion

2009-04-29 Thread Pascal Chambon

 Actually, the parethesis mean "calling" the object.

"Callable" objects can be of different types :
-functions - in which case they get executed
-classes (or metaclasses) - in which case they get "instantiated" (with 
all the protocol : __new__(), __init__()...)
-other objects - in which case they must contain a __call__ method with 
will be executed when we use the parenthesis operator on the object.


But a module is none of these : when you write "mymodule()", python 
doesn't have a clue what he must execute/instantiate.


Moduels aren't callable, but they can be "imported", simply by doing 
"import mymodule", or "import mypackage.mymodule"
Note that when you use packages, the modules that the package really 
contains are searched with a protocol that can be rather elaborate, at 
least (if I remember) the submodule name must be in the __all__ 
attribute of the package (i.e, the __all__ array defiend in the package 
__init__.py file).


I hope I haven't made you more confused with these quick explanations :p


Regards,
pascal

Dale Amon a écrit :

I am trying to get to the heart of what it is I am
missing. Is it the case that if you have a module C in a 
package A:


A.C

that there is no way to load it such that you can use:

x = A.C()

in your code? This is just a simpler case of what I'm
trying to do now, which has a module C in a sub-package
to be imported:

A.B.C

ie with files:
mydir/A/B/C.py
mydir/mymain.py

and executed in mymain.py as:

x = A.B.C()

I may still chose to do it the way you suggested, but I
would still like to understand why this does not work.

  



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


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


Re: dict is really slow for big truck

2009-04-29 Thread MRAB

Scott David Daniels wrote:

MRAB wrote:

Scott David Daniels wrote:

Bruno Desthuilliers wrote:

d = {}
for line in open(thefile):
   arr = line.strip().split()
   d[arr[0]] = arr


Sorry, not picking on Bruno in particular, but I keep seeing
this formulation around various places.
When does line.strip().split() ever differ from line.split()?

... 


You misunderstand the question.  For what values of line is
the following expression False?

line.strip().split() == line.split()

If you know of one, I'd like to hear of it.  If not, I assert
that (baring some incredibly over-ambitous optimizer operations)
line.strip().split()
is simply an inefficient (both performance and text) way of saying:
line.split()


From the explanation it's clear that the .strip() is unnecessary.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Silent install of Python software(2.5) for windows.

2009-04-29 Thread Martin v. Löwis
> Is it possible to "automate" the installation of python software(2.5)
> without the need of pressing "Next" so many times?

See

http://www.python.org/download/releases/2.5/msi/

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


Re: Installing Python 2.5.4 from Source under Windows

2009-04-29 Thread Martin v. Löwis
> I have looked and looked and looked. But I can not find any directions
> 
> on how to install the version of Python build using Microsoft's
> compiler. It builds. I get the dlls and the exe's. But there is no
> documentation that says how to install what has been built. I have read
> every readme and stop by the IRC channel and there seems to be nothing.
> 
> Any ideas where I can look?

You would need to take many manual steps: copy files around, add
registry keys, and so on. There is no real automatic procedure.
In essence, just match what the python.org installer does, by hand.

What *is* supported is creating an MSI installer out of your build
tree. See Tools/msi for details.

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


Re: CSV performance

2009-04-29 Thread Jorgen Grahn
On Mon, 27 Apr 2009 23:56:47 +0200, dean  wrote:
> On Mon, 27 Apr 2009 04:22:24 -0700 (PDT), psaff...@googlemail.com wrote:
>
>> I'm using the CSV library to process a large amount of data - 28
>> files, each of 130MB. Just reading in the data from one file and
>> filing it into very simple data structures (numpy arrays and a
>> cstringio) takes around 10 seconds. If I just slurp one file into a
>> string, it only takes about a second, so I/O is not the bottleneck. Is
>> it really taking 9 seconds just to split the lines and set the
>> variables?
>
> I assume you're reading a 130 MB text file in 1 second only after OS
> already cashed it, so you're not really measuring disk I/O at all.
>
> Parsing a 130 MB text file will take considerable time no matter what.
> Perhaps you should consider using a database instead of CSV.

Why would that be faster? (Assuming all data is actually read from the
database into data structures in the program, as in the text file
case.)

I am asking because people who like databases tend to overestimate the
time it takes to parse text. (And I guess people like me who prefer
text files tend to underestimate the usefullness of databases.)

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Third Party Modules

2009-04-29 Thread Jorgen Grahn
On Tue, 28 Apr 2009 10:15:23 -0700, John Nagle  wrote:
> Brock wrote:
>> Hi Everyone,
>> 
>> I know this is most likely a basic question and you will roll your
>> eyes, but I am just starting out with Python (hobbyist) and I see many
>> tutorials on the web referring to the use of external modules.
...

> There are several different mechanism for handling this, and they all 
> suck.
> The whole Python module distribution scheme is so uncoordinated that there's
> no uniform way to do this.  It's not your fault.
...
> I'm not going to put Python software out for public use again.  I don't
> have the time to deal with this crap.

And which other language would have made it easier? Once you have odd
third-party dependencies, you (or your users, rather) will have
problems.

/orgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
--
http://mail.python.org/mailman/listinfo/python-list


Re: stuck with PyOBEX

2009-04-29 Thread Jorgen Grahn
On Tue, 28 Apr 2009 18:52:38 +0200, Diez B. Roggisch  
wrote:
> alejandro wrote:

[AF_BLUETOOTH]

>> Can you tell me what is it? Maybe I can search it and pass it in another
>> way... if it is an address or protocol name
>
> I'm not entirely sure, but I guess no, you can't simply pass it in.
>
> Unix uses streams as abstraction for a lot of things - all kinds of devices
> for example.

You mean "uses the BSD Socket API as an abstraction" here. That's the
framework where "AF_BLUETOOTH" apparently lives.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
--
http://mail.python.org/mailman/listinfo/python-list


Re: import and package confusion

2009-04-29 Thread Scott David Daniels

Dale Amon wrote:

On Wed, Apr 29, 2009 at 01:12:33PM -0700, Scott David Daniels wrote:
  

Dale Amon wrote:


I am trying to get to the heart of what it is I am
missing. Is it the case that if you have a module C in a package A:
A.C
that there is no way to load it such that you can use:
x = A.C()
in your code? 
  

OK, here's a simple question.  What do you expect from:
   import sys
   sys()
sys is a module, and as such, it is not callable.


You did not answer the question above, and I think the answer is the root
of your misunderstanding.  A class and a module are _not_the_same_thing_.
sys is not a package, it is a module.

Just because you put a class inside a module, does not mean
that class magically does something by virtue of having the
same name as the module.

A module is a namespace to hold classes, functions, etc
A package is a namespace to hold modules (possibly more).

I don't understand why you don't use files like:

VLMLegacy/
 __init__.py
 Reader.py
 VLM4997.py
 WINGTL.py

Unlike Java, we are free to have several things in a module:

several classes, several functions, several constants



There are n different similar systems, each with multiple classes.
They could either be implimented as a class at the first level:

VLMLegacy
   Condition.py
   Plan.py
 |
 |
etc

but in that case each class will be filled with conditionals
that try to do the correct thing depending on which system's
data they are reading. That approach has already gotten *insane*
and I need to objectify things: put all the common code into 
abstract superclasses, and then create a subclass for each 
different system (of which there will be an unknown number added

over time), ie:

VLMLegacy/
   Conditions.pyAbstract classes
   Plan.py
 |
 |
etc
   TYPE1/   Subclasses of above specific to Type 1
   Conditions.py
   Plan.py
 |
 |
etc
   TYPE2/   Subclasses for Type 2
   Conditions.py
   Plan.py
 |
 |
etc

 |
   TYPEn/   Subclasses for Type n
   Conditions.py
   Plan.py
 |
 |
etc

Every VLMLegacy.TYPEn.Conditions (or other class) has exactly...
  

But VLMLegacy.TYPEn.Conditions is a _module_, not a _class_.
I suggest VLM4497.py look a bit like the following:
   from VLMLegacy import abstract_classes
   class Condition(abstract_classes.BaseCondition):
...
   class Plan(abstract_classes.BasePlan):
...
   Header = abstract_classes.BaseHeader # Note we needed no customization
   ...
the same set of methods; each of those methods inherits much 
of its basic behavior from VLMLegacy.Conditions.


If I make every subclass a unique name, things will
rapidly get out of hand, especially when I start
adding TYPEn+1,2... etc.

So yes, the approach isn't arbitrary, it is a solution
to real design problems which even the above does not
fully do justice to.

What I would really like to do when executing is more
like:

type = "VLM4997"
type.Header(args)
type.Plan(args)
type.Conditions(args)

Where the type might change from execution to execution
or even on different iterations.
  

Well, "VLM4997" is a _string_, and it has no attributes (nor methods)
named "Header", "Plan", or "Conditions."  And "type" is a perfectly awful
name for a variable, since it hides the builtin named type.  You seem to
confuse names, files, and classes defined in files (at least in your 
writing).


--Scott David Daniels
scott.dani...@acm.org


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


Re: dict is really slow for big truck

2009-04-29 Thread pruebauno
On Apr 29, 1:05 pm, Scott David Daniels  wrote:
> Bruno Desthuilliers wrote:
> > d = {}
> > for line in open(thefile):
> >    arr = line.strip().split()
> >    d[arr[0]] = arr
>
> Sorry, not picking on Bruno in particular, but I keep seeing
> this formulation around various places.
> When does line.strip().split() ever differ from line.split()?
>
> --Scott David Daniels
> scott.dani...@acm.org

They don't.
It is probably out of habit of using the generalized idiom:
>>> line="a,b,c\n"
>>> line.strip().split(",")
['a', 'b', 'c']
>>> line.split(",")
['a', 'b', 'c\n']
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why bool( object )?

2009-04-29 Thread Aaron Brady
On Apr 28, 9:54 pm, Steven D'Aprano
 wrote:
> On Tue, 28 Apr 2009 11:59:18 -0700, Aaron Brady wrote:
> >> To steal an idiom from Laura: Python has a float-shaped Nothing 0.0, a
> >> list-shaped Nothing [], a dict-shaped Nothing {}, an int-shaped Nothing
> >> 0, a singleton Nothing None, and so forth.
>
> > The sound of that metaphor is rather pleasing ('sweet nothings'), but
> > I'm not so sure that metaphors belong in computer science and
> > programming.
>
> Programming models the world, it isn't the world. Every model is a
> metaphor. You can't get away from metaphors in programming, you can only
> hide them and pretend they aren't there.

I was not aware that the intended use for 'True' was 'Something'.  I
thought it merely signified membership in a predicate or relation.
'GreaterThan( 3, 2 )', so '3> 2== True'.  You might argue that numbers
are metaphors for the world, since they are external to causality,
have no temperature, etc., and likewise with logical predicates.  But
just because True is one metaphor, doesn't mean it is every metaphor.
Is casting to a boolean a metaphor for a metaphor?

Mathematically, 'bool' injects mathematical objects into the set
{ True, False }.  I would say it's a stretch to say that the empty
list maps to the True value, and non-empty lists map to the False
value.  Mathematically, there's no reason to choose that mapping as
the natural meaning and definition over any other, say 'list( x ) iff
len( list( x ) )% 2'.  (Some shells, I understand, suppose that there
are multiple ways to fail, while others suppose that there are
multiple ways to succeed.)  In programming practice, there is a
frequent division between empty lists and non-empty lists, so the
author chose to map one case to one value, and the other case to the
other.

> > Nothing can't have many shapes.
>
> In computing, you can't have a literal "nothing", because EVERYTHING
> needs to be stored as a pattern of bits.

Correct... until memory gates can self-destruct.  

> In practice, for most high-level
> languages, those bits are interpreted as a type as well as a value, so
> the same bit pattern can mean different things according to what type it
> is expected to be. Alternatively, the same information can be represented
> in different bit patterns depending on how you interpret those bit
> patterns.
>
> So in the context of computer programming, of course you can have nothing
> with many "shapes": you have the number 0 represented as a single byte, a
> 16-bit integer, a 32-bit integer, a long-int or BigNum, a pointer with
> address 0, fixed point decimals of various sizes, Binary Coded Decimal, a
> rational, a single float 0.0, a double float 0.0, a string of "tally
> marks" without any tally, and so on, all of them in big-endian and little-
> endian formats.
>
> > Having no onions is the same as having no carrots.
>
> "If you have one onion and I take it away, how many onions do you have
> left?"
>
> If you answered "no carrots", I'd consider that a bizarre and unhelpful
> answer, and wonder what you possibly thought carrots had to do with my
> question.
>
> "Nothing" is not an absolute. "There is no wind" is not the same thing as
> "there is no money left in my bank account".
>
> > If the different shapes of nothing don't
> > compare equal to each other, which they don't, then they aren't all the
> > same thing in different shapes.
>
> Who said they were the same thing?

The fact that bool( [] ) == bool( {} ).  Merely that 'f( x )== f( y )'
does not imply that 'x== y'.  I am not arguing that '[]== {}', and I'm
pretty sure you aren't either.  However, x and y do form an
equivalence class under 'f', IIRC.

If you ask of (blank), 'Is there anything?', which is what you state
the 'bool' function means to do, there are only two answers: 'Yes,
there is something', and 'No, there is nothing'.

> > Furthermore, it is awfully presumptuous to give objects a default
> > 'nothing-ness' of 'something'.  If anything, they should be nothing by
> > default.  
>
> That's a stupid idea.
[argument] snip

Fine, withdrawn.  They shouldn't have one.

> > Conversion to other primitives is very picky; why should
> > Boolean be so tolerant?
>
> Because it is useful and meaningful to ask whether an arbitrary object
> represents something or nothing, but it's not useful or meaningful to ask
> what integer is equivalent to an arbitrary object.

It's more common for it to make sense to divide a set into two pieces
than it is to divide it into N pieces, the cardinality of the
integers.  But that doesn't make the presumed implementation 'return
True' for an entire type.

I think the closest you could come would be to try the '__len__'
method, and raise an exception if there isn't one.  But if '__len__'
is defined, then there is also a mapping from the type into the
integers.  By your logic, 'int( object )' should default to '__len__'
as well, since the mapping is defined!

The 'bool' function means to ask, 'What Boolean value is this obj

Python 2.6 Install on OSX Server 10.5: lWhich flag to use in "configure" to Change the Install location?

2009-04-29 Thread Omita
Long story short... I am installing Python 2.6 on OSX Server.  By
default the Python.framework is installing in /Library:

/Library/Frameworks/Python.framework

However, as I am using OSX Server I would ideally like the install
location to be here:

/System/Library/Frameworks/Python.framework/

Do I need to use the "--libdir" flag? Or is that referring to "lib"
not "Library"?

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


Techkicks.com technology links, community driven

2009-04-29 Thread Steven
TechKicks.com is a community based technology site. It specializes in
Hi-Technologies like Robotics, ERP, GPS, Python, Haskell, Lisp, Ruby
On Rails,
and common techs like c#, PHP, Java, Sql and many more. Individual
users of the site submit and review stories, the most popular of which
make it to the homepage. Users are encouraged to 'kick' stories that
they would like to appear on the homepage. If a story receives enough
kicks, it will be promoted.
Individual users of the site submit and review stories, the most
popular of which make it to the homepage. Users are encouraged to
'kick' stories that they would like to appear on the homepage. If a
story receives enough kicks, it will be promoted.

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


command prompt history filtered by initial letters

2009-04-29 Thread limit
Hello,

On WindowsXP with Python 2.5.1 (from the python-2.5.1.msi): when I'm
at the python prompt, up-arrow scrolls through the command history. If
I type group of characters first, up-arrow shows only the previous
commands that start with that group of characters.

On CentOS 5 with Python 2.5.4 (that I built locally): up-arrow does
not filter the command history based on initial characters at the
prompt.

How do I get this command history filter working on the centos
install?

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


Re: desperately looking for a howto on running my wxPython app on Vista

2009-04-29 Thread Mike Driscoll
On Apr 29, 4:17 am, Paul Sijben  wrote:
> Gabriel Genellina wrote:
> >> I am currently stuck on the infamous R6034 error but I understand that
> >> after that there may be another issue with certain wxPython functions.
>
> > That should be fixed in Python 2.6.2, I think.
> > Are you compiling all your dependencies, including Python itself? R6034
> > is likely a DLL mismatch between parts of your project.
>
> I am using 2.6.2 and am compiling only my own changed modules. For all
> the other support modules I have taken the most recent ones (win32,
> wxpython)
>
> Is there any way to check which is the offending pyd/dll?  (normally
> Vista does not give out much data on what went wrong)
>
> Paul

You might be able to find it using the Dependency Walker utility:

http://www.dependencywalker.com/

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


Re: Restart generator when it is exhausted.

2009-04-29 Thread Lacrima
On Apr 28, 6:38 pm, "J. Cliff Dyer"  wrote:
> On Tue, 2009-04-28 at 10:41 +, Duncan Booth wrote:
> > Lacrima  wrote:
>
> > > If it is not possible what are common techniques to use iterator or
> > > generator objects that allow restarting when it is needed?
>
> > The usual thing if you want to use the generator's output more than once  
> > would be to convert the generator to a list, then you can iterate over it
> > as often as you want.
>
> > >>> a = ['a', 'b', 'c']
> > >>> g = (i for i in a)
> > >>> restartable = list(g)
>
> > If you want the output of the generator to potentially change each time you
> > iterate then you need to create a new generator.
>
> More verbosely, but without putting your generator in , you can use the
> iterator protocol to create a reusable iterable:
>
> An iterable is a class with an __iter__ method that returns an iterator.
>
> So for example:
>
> class Iterator(object):
>     def __init__(self, filename):
>         self.f = open(filename)
>
>     def __iter__(self):
>         return self
>
>     def next(self):
>         line = self.f.readline()
>         if not line:
>             raise StopIteration
>         return line.strip()[:8]
>
> is an iterator (which is also an iterable), which will grab each line of
> a file, returning the first eight non-whitespace characters until the
> file is used up.  Then the iterator is exhausted, and will continue to
> raise StopIteration each time it is called.
>
> class Iterable(object):
>     def __init__(self, filename):
>         self.filename = filename
>
>     def __iter__(self):
>         return Iterator(self.filename)
>
> This is a reusable iterable which returns a new instance of the Iterator
> class above each time it is exhausted.
>
> So given a file hello.txt:
>
>   Hello world
>     Hola mundo
>   Guten tag, weld.
>
> The classes can be used as followed:>>> iterator = Iterator('hello.txt')
> >>> for i in xrange(3):
> >>>     print "*** %d ***" % i
> >>>     for j in iterator:
> >>>         print j
>
> *** 0 ***
> Hello wo
> Hola mun
> Guten ta
> *** 1 ***
> *** 2 ***>>> iterable = Iterable('hello.txt')
> >>> for i in xrange(3):
> >>>     print "*** %d ***" % i
> >>>     for j in iterable:
> >>>         print j
>
> *** 0 ***
> Hello wo
> Hola mun
> Guten ta
> *** 1 ***
> Hello wo
> Hola mun
> Guten ta
> *** 2 ***
> Hello wo
> Hola mun
> Guten ta
>
> When Iterator hits a StopIteration, it passes out of the inner loop, and
> when it comes back in, the inner loop calls iterator.__iter__(), and
> gets the same exhausted iterator (which immediately breaks the inner
> loop by raising StopIteration).  In Iterable, when the loop calls
> iterable.__iter__(), it gets a fresh iterator, so it can loop over the
> file again.
>
> The important thing is that when you call x.__iter__() (which you do
> when entering a loop), you get a fresh iterator that won't just call
> StopIteration right away.
>
> Cheers,
> Cliff

Thank you very much! You completely have enlightened me on all my
questions!

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


Re: can't use "glog" to find the path with square bracket

2009-04-29 Thread winterTTr
yes , i works as your advise. Thanks a lot . :-)


On Apr 28, 9:52 am, MRAB  wrote:
> winterTTr wrote:
> > I want to list the file with glob .
> > The path( which is a directory ) is contain square bracket as "[ab]
> > xxx"
> > .  However , i can't find how to do it rightly with glob .
>
> > with the coding :
>
> > {{{
> > import glob
> > glob.glob('[ab]xxx' )
> > }}}
>
> > and with the path "[ab]xxx" really exits.
> > result : []
>
> > Is there a way to do it rightly ?
>
> > And i know the fact that  [ is a special character for glob().
> > But how can i escape it when using glob?
>
> > PS:
> >  Python : 2.5
> >  Platform : Win XP
>
> There's no escape character as such, but you can put '[', '?' and '*' in
> a character set in their own:
>
>      glob.glob('[[]ab]xxx')
>                 ^^^
>                 '[' within [...]

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


Python SocketServer with IPv6

2009-04-29 Thread godshorse
Hello,

I am working on a overlay network implementation with python. I need
to use both IPv4 and IPv6 at each node. Python socketserver is being
used for this task. can anybody pls suggest me how to input an IPv6
address to the socketserver.

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


Re: complementary lists?

2009-04-29 Thread Bryan
On Apr 28, 11:16 pm, Arnaud Delobelle  wrote:
> Kay Schluehr  writes:
> > On 29 Apr., 05:41, Ross  wrote:
> >> If I have a list x = [1,2,3,4,5,6,7,8,9] and another list that is a
> >> subset of x:  y = [1,4,7] , is there a quick way that I could return
> >> the complementary subset to y z=[2,3,5,6,8,9] ?
>
> >> The reason I ask is because I have a generator function that generates
> >> a list of tuples and I would like to divide this list into
> >> complementary lists.
>
> > z = [u for u in x if u not in y]
>
> > or
>
> > z = [u for u in x if u not in set(y)]
>
> The above will evaluate set(y) for each element in x.
>
> s = set(y)
> z = [u for u in x if u not in s]
>
> --
> Arnaud

>>>y = [1, 2, 3, 4, 5]
>>>s = set(y)
>>>s.complimentary()
['you are handsome', 'you are smart', 'nice jacket']
--
http://mail.python.org/mailman/listinfo/python-list


Which flag to use in "configure" to Change the Install location?

2009-04-29 Thread Omita
Long story short... I am installing Python 2.6 on OSX.  By default the
Library is installing here:

/Library/Frameworks/Python.framework

However, as I am using OSX Server I would ideally like the location to
be here:

/System/Library/Frameworks/Python.framework/

Do I need to use the "--libdir" flag? Or is that referring to "lib"
not "Library"?

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


Re: Python 2.6 Install on OSX Server 10.5: lWhich flag to use in "configure" to Change the Install location?

2009-04-29 Thread uuid
My first intuition would be that - even if it works - this would break 
future OS X updates, since you're probably not fixing the receipt files.



On 2009-04-29 23:43:34 +0200, Omita  said:


However, as I am using OSX Server I would ideally like the install
location to be here:

/System/Library/Frameworks/Python.framework/



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


Re: Python 2.6 Install on OSX Server 10.5: lWhich flag to use in "configure" to Change the Install location?

2009-04-29 Thread Benjamin Kaplan
On Wed, Apr 29, 2009 at 5:43 PM, Omita  wrote:

> Long story short... I am installing Python 2.6 on OSX Server.  By
> default the Python.framework is installing in /Library:
>
> /Library/Frameworks/Python.framework
>
> However, as I am using OSX Server I would ideally like the install
> location to be here:
>
> /System/Library/Frameworks/Python.framework/
>

No, you don't want the install location to be there.
"""
Third-party frameworks should never be installed in the
/System/Library/Frameworks directory. Access to this directory is restricted
and is reserved for Apple-provided frameworks only.
"""
http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/InstallingFrameworks.html

Regardless, the linker searches /Library/Frameworks before
/System/Library/Frameworks so a user-installed framework gets priority over
the system one.



>
> Do I need to use the "--libdir" flag? Or is that referring to "lib"
> not "Library"?
>
> -Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 03:06:13PM -0700, Scott David Daniels wrote:
> You did not answer the question above, and I think the answer is the root
> of your misunderstanding.  A class and a module are _not_the_same_thing_.
> sys is not a package, it is a module.
>>> Just because you put a class inside a module, does not mean
>>> that class magically does something by virtue of having the
>>> same name as the module.
>>>
>>> A module is a namespace to hold classes, functions, etc
>>> A package is a namespace to hold modules (possibly more).
>>>
>>> I don't understand why you don't use files like:
>>>
>>> VLMLegacy/
>>>  __init__.py
>>>  Reader.py
>>>  VLM4997.py
>>>  WINGTL.py
> Unlike Java, we are free to have several things in a module:
> several classes, several functions, several constants

These modules would grow to be hundreds of pages long and a 
difficult to deal with to debug a problem related to one obscure 
system without looking at (or potentially screwing up) any of the
others. I prefer one class per module.

This gets more into philosophy, but I figure any function or method
that does not fit on one page is too big; and any source file that
is more than 20 pages long should be broken in half. I like my modules
in the 5-10 page size range, including the embedded Unix ManPages and
the cvs history. But that's just my house style.

> Well, "VLM4997" is a _string_, and it has no attributes (nor methods)
> named "Header", "Plan", or "Conditions."  And "type" is a perfectly awful
> name for a variable, since it hides the builtin named type.  You seem to
> confuse names, files, and classes defined in files (at least in your  
> writing).

Actually I'm not. I am simply trying to use a pseudo code
to explain roughly what is going on. There will be a string
that selects what the set of classes are to be used on any
given iteration and it will be used to generate the name
of the class and/or name of the module where it is to be found.
I'm an old ObjC hacker. I often put the class or method in a
variable and do the bindings at runtime. I am already doing some
of that sort of thing in this system with the method names and 
it works nicely.

The point I take away from this is that packages and
modules have dotted names, but Classes do not and there
is no way to do exactly what I wanted to do. 

The dot syntax would have been quite nice (I quite like the
"::" syntax in Perl) and would have made the code much
clearer. The way you suggested with a 'typename_classname'
generated using a from/import statement will just have to
suffice.






signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


[ANN] BPT (Boxed Package Tool)

2009-04-29 Thread Giuseppe Ottaviano

Hi all,
I am pleased to announce BPT 0.2a (despite the number, this is the  
first public version).


http://pypi.python.org/pypi/bpt

Like virtualenv, BPT allows to create isolate environments, but it is  
not limited to Python software, as it can be used to install arbitrary  
Unix software. It can be used for development (several versions of the  
same software can be installed in the same environment, and  
administrator privileges are not needed), and for deployment of  
complete installations (the environments are relocatable).


Feel free to use and test it, comments are welcome.

What is BPT
===

BPT is a Python library (``bpt``) and a command line application
(``box``) to create and manage isolated enviroments, or *boxes*. Boxes
are *relocatable*, which means that they can be moved to a different
directory or even distributed to other machines (provided that the
architecture is compatible). Packages inside the box can be easily
disabled, enabled and removed, so that different versions of the same
software can be installed simultaneously, allowing to switch between
them.

BPT is similar in some ways to `virtualenv
`_, but it is not restricted
to Python packages, allowing to install virtually any Unix
software. It also takes some ideas from `jhbuild
`_, but without the dependency
resolution and automatic downloading machinery, and the ``bpt-rules``
format is inspired by `Gentoo `_'s ebuilds.

--
Giuseppe Ottaviano

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


Re: complementary lists?

2009-04-29 Thread Bryan
On Apr 28, 11:16 pm, Arnaud Delobelle  wrote:
> Kay Schluehr  writes:
> > On 29 Apr., 05:41, Ross  wrote:
> >> If I have a list x = [1,2,3,4,5,6,7,8,9] and another list that is a
> >> subset of x:  y = [1,4,7] , is there a quick way that I could return
> >> the complementary subset to y z=[2,3,5,6,8,9] ?
>
> >> The reason I ask is because I have a generator function that generates
> >> a list of tuples and I would like to divide this list into
> >> complementary lists.
>
> > z = [u for u in x if u not in y]
>
> > or
>
> > z = [u for u in x if u not in set(y)]
>
> The above will evaluate set(y) for each element in x.
>
> s = set(y)
> z = [u for u in x if u not in s]
>
> --
> Arnaud

>>>ls = [1, 2, 3, 4, 5]
>>>s = set(ls)
>>>s.complimentary()
['your are handsome', 'your are smart', 'nice jacket'
--
http://mail.python.org/mailman/listinfo/python-list


c array

2009-04-29 Thread luca72
hello i'm using ctypes

i have this c function
PREF0 short usb_tc08_get_single (
  short   handle,
  float * temp,
  short * overflow_flags,
  short   units);
where :
nt main(void)
{
short handle = 0; /* The handle to a TC-08 returned by
usb_tc08_open_unit() */
char selection = 0;   /* User selection from teh main menu */
float temp[9];/* Buffer to store temperature readings from
the TC-08 */
int channel, reading; /* Loop counters */
int retVal = 0;   /* Return value from driver calls indication
success / error */
USBTC08_INFO unitInfo;/* Struct to hold unit information */

how i can pass the value using c types?
strumento = ctypes.cdll.LoadLibrary('libusbtc08.so') and here is ok
but when i call the function
strumento.short usb_tc08_get_single(arg1, arg2,arg3,arg4)
arg1 is 0 arg2 2 is a carray i dont know how to convert, arg3 is none
and arg 4 is a string here is the c example
usb_tc08_get_single(handle, temp, NULL, USBTC08_UNITS_CENTIGRADE)
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict is really slow for big truck

2009-04-29 Thread Scott David Daniels

prueba...@latinmail.com wrote:

It is probably out of habit of using the generalized idiom:

line="a,b,c\n"
line.strip().split(",")


Ah, thank you.  I just couldn't figure out where it started.

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


ctypes

2009-04-29 Thread luca72
can you explain how to use this function :
this is the api documentation :
PREF0 short usb_tc08_get_single (
  short   handle,
  float * temp,
  short * overflow_flags,
  short   units);

This is the sample made in c:
int main(void)
{
short handle = 0; /* The handle to a TC-08 returned by
usb_tc08_open_unit() */
char selection = 0;   /* User selection from teh main menu */
float temp[9];/* Buffer to store temperature readings
from
the TC-08 */
int channel, reading; /* Loop counters */
int retVal = 0;   /* Return value from driver calls
indication
success / error */
USBTC08_INFO unitInfo;/* Struct to hold unit information */

usb_tc08_get_single(handle, temp, NULL, USBTC08_UNITS_CENTIGRADE);
i do
strumento = ctypes.cdll.LoadLibrary('/home/luca/Desktop/luca/
progetti_eric/Pico/libusbtc08-1.7.2/src/.libs/libusbtc08.so')
strumento.usb_tc08_get_single.argtypes = [ctypes.c_short,
ctypes.c_float, ctypes.c_short, ctypes.c_short] is this correct?
strumento.usb_tc08_get_single.restype = ctypes.c_short is this
correct?
now how i can use the function?
leggo = strumento.usb_tc08_get_single(0, temp,
'NULL','USBTC08_UNITS_CENTIGRADE')
how i can define ad pas the value temp, null,USBTC08_UNITS_CENTIGRADE

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


Re: command prompt history filtered by initial letters

2009-04-29 Thread MRAB

limit wrote:

Hello,

On WindowsXP with Python 2.5.1 (from the python-2.5.1.msi): when I'm
at the python prompt, up-arrow scrolls through the command history. If
I type group of characters first, up-arrow shows only the previous
commands that start with that group of characters.

On CentOS 5 with Python 2.5.4 (that I built locally): up-arrow does
not filter the command history based on initial characters at the
prompt.

How do I get this command history filter working on the centos
install?


If it works in the command prompt (in Windows XP: Start > All Programs >
Accessories > Command Prompt) then it's a feature of the operating
system, not Python.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which flag to use in "configure" to Change the Install location?

2009-04-29 Thread Diez B. Roggisch

Omita schrieb:

Long story short... I am installing Python 2.6 on OSX.  By default the
Library is installing here:

/Library/Frameworks/Python.framework

However, as I am using OSX Server I would ideally like the location to
be here:

/System/Library/Frameworks/Python.framework/


Why?


Do I need to use the "--libdir" flag? Or is that referring to "lib"
not "Library"?


I'm not 100% sure, but I think you should be able to simply move the 
framework to your desired location.


However, a simple "configure --help" reveals this:

 --enable-framework[=INSTALLDIR]

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


Re: Third Party Modules

2009-04-29 Thread David Lyon

> On Tue, 28 Apr 2009 10:15:23 -0700, John Nagle  wrote:
>> Brock wrote:
>>> Hi Everyone,
>>>
>>> I know this is most likely a basic question and you will roll your
>>> eyes, but I am just starting out with Python (hobbyist) and I see many
>>> tutorials on the web referring to the use of external modules.
> ...
> 
>> There are several different mechanism for handling this, and they
> all suck.
>> The whole Python module distribution scheme is so uncoordinated that
> there's
>> no uniform way to do this.  It's not your fault.
> ...
>> I'm not going to put Python software out for public use again.  I
> don't
>> have the time to deal with this crap.

People are working on this for example, I am working on a Package
Manager Project on sourceforge to solve exactly these problems.

Hopefully soon we will be ready to do a release.

In the spirit of open source, you would be welcome to join our project,
and do some testing. Report some bugs etc.

http://sourceforge.net/projects/pythonpkgmgr/

Best Regards

David









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


Re: What do you think of ShowMeDo

2009-04-29 Thread showm...@googlemail.com
On 29 Apr, 07:27, Steven D'Aprano
 wrote:
> On Tue, 28 Apr 2009 21:56:08 -0700, kyran wrote:
> > I stumbled across this thread while typing a speculative 'showmedo' in
> > google, as you do while taking a break on a (very) late Tuesday evening.
> > To declare my interest, as things stand I amShowmedoCEO, CTO,
> > boywhomakesthetea etc.. I'm not going to plug anything specific and
> > normally let these things go but it's comp.lang.python and a
> > misconception is a misconception. Besides which, every now and then an
> > attitude really grates.
>
> Yeah, it really sucks when you spend time and effort to build something,
> and then discover that it isn't what people want.
>
> Or at least some people.
>
> [...]
>
> > As for the author immediately above, I think he fails his own test of
> > prudence. There are rather blindingly obvious download links below each
> > video.
>
> Perhaps you should forget your preconceptions and take a long, hard look
> at the site with the eyes of a first time visitor.
>
> As a first time visitor, this is what I see:
>
> * A bunch of "stuff" all over the front page. My eye is drawn to a bunch
> of thumbnails on the right hand side, which look somewhat vaguely what
> I'd see on YouTube. So I click on a thumbnail, expecting to see a video,
> but instead I get taken to a page with no video or download link. I think
> this is what you call a "series", but at first the page just looks broken
> to me -- where's the video?
>
> * Since I'm unusually interested in your site, and have nothing better to
> do, I click on the series heading, and go to another page. This one does
> have a download link, and a broken "click here to play" icon. Oh well,
> I'm used to video sites being broken on everything but IE, or requiring
> Javascript, or both. So I click on the download link, and learn that you
> require a login. Do I care enough about your content to create Yet
> Another Damn Login Identity? No.
>
> (And yet I care enough to spend 20 minutes explaining you how you could
> improve your site. Fancy that. That's because if you improve your site,
> it could be useful to me, but if I create a login account, I've got the
> burden of dealing with yet another login account.)
>
> * Since I'm feeling especially enthusiastic, I go back to the home page,
> and click a link under the "Popular Paths" heading in the "Blog roll".
> (You seem to be using the term blog roll to mean something completely
> different to the way it is used in virtually every blogging site I've
> ever seen.) This takes me to an even more complicated page showing a
> "Path", filled with things that look like clickable buttons but aren't,
> and thumbnails that at first glance look identical. If I spend a couple
> of minutes inspecting them closely and mousing over them, I see that the
> *left* hand side of the thumbnail is the author and the *right* hand side
> is something else.
>
> (No doubt some clever PHP programmer thought he was being clever to come
> up with that UI abomination.)
>
> * I see *one* thumbnail that has a "Click to play" icon next to it. None
> of the others appear to be videos. There is no download link. I give up,
> and decide that your website's UI is too large a barrier for me to bother
> with it any further.
>
> > All that being said, I do feel the need to make that point that we have
> > generated 350 odd completely free video-tutorials for the Python
> > community, including some truly inspirational demonstrations, if the
> > feedback is anything to go by. The site has been refined over time and
> > is at least striving constantly to improve. But some people will always
> > focus only on the negatives. They are few and far between but
> > occasionally, during those long, dark teatimes of the soul, it does make
> > one wonder why one bothers. You provide them with free videos, make no
> > claim upon them and all they do is moan that the format is wrong or
> > their time too precious to waste on a non-mandatory signing- up, though
> > not so precious they can't take time out of their day to whinge about it
> > in a group posting. I think it's the kind of attitude that kills the
> > spirit of FOSS stone-dead.
>
> You think that FOSS is under threat because people are willing to give
> you feedback that your use of non-FOSS software (Flash) is inconvenient
> to them? Oh dear.
>
> For every person who takes the time to write about it, probably one
> hundred people equally dislike your site but just walk away and never
> come back. You should be dancing for joy that Ben gave you valuable
> feedback about his user experience, instead of just walking away. Some
> companies pay tens of thousands of dollars to hire UI consultants to make
> sure their website is usable by first-time visitors, and that's excluding
> development costs. I've just given you twenty minutes of my time writing
> up my experiences for free. Is that enough in the spirit of FOSS for you?

Well since you ask, no. Your post is sarcastic, patr

  1   2   >