Re: Implementaion of random.shuffle

2007-07-16 Thread shabda raaj
On Jul 16, 8:29 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Hrvoje Niksic wrote:
> > Steve Holden <[EMAIL PROTECTED]> writes:
>
> >> So it would appear that the developers chose the Knuth algorithm
> >> (with a slight variation) for *their* implementation. Now you have
> >> to ask yourself whether your surmise is genuinely correct (in which
> >> case the documentation may contain a bug) or whether the
> >> documentation is indeed correct and you are in error.
>
> > That is a good question.  The random module uses the Mersenne twister,
> > which has a repetition period of 2**19937.  The number of n-sized
> > permutations of a list with n elements is n!, while each shuffle
> > requires n calls to the PRNG.  This means that to be able to generate
> > all permutations, the PRNG must have a period of at least n! * n.  In
> > the case of MT, it means that, regarding the period, you are safe for
> > lists with around 2079 elements.  shuffle's documentation may have
> > been written before the random module was converted to use the MT.
>
> > 2**19937 being a really huge number, it's impossible to exhaust the
> > Mersenne twister by running it in sequence.  However, there is also
> > the question of the spread of the first shuffle.  Ideally we'd want
> > any shuffle, including the first one, to be able to produce any of the
> > n! permutations.  To achieve that, the initial state of the PRNG must
> > be able to support at least n! different outcomes, which means that
> > the PRNG must be seeded by at least log2(n!) bits of randomness from
> > an outside source.  For reference, Linux's /dev/random stops blocking
> > when 64 bits of randomness are available from the entropy pool, which
> > means that, in the worst case, shuffling more than 20 elements cannot
> > represent all permutations in the first shuffle!
>
> Thanks for this thoughtful analysis. I believe we can therefore leave
> the documentation (which almost certainly *was* written before the
> adoption of MT) alone for now.
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -

The code for shuffle is

 if random is None:
 random = self.random
 for i in reversed(xrange(1, len(x))):
 # pick an element in x[:i+1] with which to exchange x[i]
 j = int(random() * (i+1))
 x[i], x[j] = x[j], x[i]

With
 j = int(random() * (i+1))
being the only call to random().
As long as (i + 1) is not large enough so that j is generated with
equal probability in range [0, i] we would get all permutations with
equal probability. With MT with period of 2**19937 (i+1) would have to
be really large before this the case.

Anyway, is there some test harness we can run to test the robustness
of shuffle? We can run that test harness for large values and see at
what point all permutations are not possible or come with unequal
probability.

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


Re: Can a low-level programmer learn OOP?

2007-07-16 Thread Hendrik van Rooyen
"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote:

>My my my... Would you believe that my coworkers do consider me like an 
>old sage because I started programming in 1990 with HyperTalk on Mac 
>Classic !-)
>
>I suddenly feel 20 again ! Woo !-)

*hands him a straw boater and a cane*

ok youngster - lets see you strut your stuff...

; - )




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


Re: Access Object From 2 Applications or Fix Scheduler

2007-07-16 Thread Hendrik van Rooyen
 "Robert Rawlins - Think Blue" <[EMAIL PROTECTED]> top posted:

>Also Hendrik,
>
>I should probably mention that the second application is a constant running
>application, it's nothing something that can just be 'started' by the first
>one, its running non-stop and just needs data passed into it regularly when
>the first application finds it.
>
>Application 1 Application 2
>Work with dict
>Work with dict
>Work with dict
>Work with dict
>New XML Found, Parse Into Dict --> Work with new dict
>Work with new dict
>Work with new dict
>Work with new dict
>
>You see how that works? Application 1 has a function that runs every minute
>and _may_ find a new xml file, if it does then I need it to parse that file
>into a list of dictionary and then pass that into application 2, which then
>starts using it :-)

ok - I see the difference - when you said schedule, I was thinking 
something like a cron job..

>
>Now we may be able to avoid this if there is some type of file watcher
>function available in python, my second application could then just watch
>the XML file and as soon as a new one is available parse it itself. Is that
>something you've heard of?

no to the tail like functionality - but then I am not an expert on what
is available

Now being a thread fanatic, I would do this sort of thing with a 
thread for scanning the world for the new XML, and if it finds 
a new thing, have it create the new dict.  (While it is doing this, 
the main thread is still using the old one).  Then, when the new 
dict is ready, I would put it on a Queue, which the main thread 
checks every time before it accesses the working dict, and then
if there is a new one, "overwrites" the old working one with the
new one by assigning the working dict name to the one from 
the queue:

try:
workdict = dict_q.get()
except Queue.Empty:
pass

where dict_q is the instance of Queue.Queue() that is used 
to link the two threads - create it in  __main__ before
starting the seeker thread so that it is visible to both the seeker
and worker that __main__ calls.   "  dict_q = Queue.Queue() "

After making the new dict, the seeker simply puts it on the queue
like this:

dict_q.put(new_dict)

Can't be simpler.

This has the advantage that the swap is made at a sensible point
in the worker thread, and the scheduling can be done in the 
seeker thread simply by calling time.sleep(60.0) at the start
of a while True loop. - it won't give you exactly sixty seconds 
to the millisecond, but this probably does not matter for something 
like this. - as long as you start using the new data "soon" its
probably all right.

For starting a thread, look at thread for basics and threading
for fancy, if you don't know already. I use thread because 
I am simple minded.

- Hendrik


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


Re: Best method for inter process communications

2007-07-16 Thread Hendrik van Rooyen
"Steve Holden" <[EMAIL PROTECTED]> wrote:

> Given the radically inefficient representations that XML typically 
> requires, however, I think that worrying about localhost socket overhead 
> is unnecessary: if your application was *that* critical you wouldn't be 
> using XML in the first place.

I heard a rumour once that a "hello world" string takes something like
10k bytes in XMLRPC - have never bothered to find out if its BS...

- Hendrik

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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Asun Friere
In practice the different placeholders give you a handle to achieve
different formatting effects.

Compare for example:

for x in range(15) :
  print '%02d' % x

against:

for x in range(15) :
  print '%02s' % x
  #the '0' in this case being redundant

Or again:

from math import pi
print '%.4f' % pi
print '%.4s' % pi
#if that last seems silly consider
print '%.4s % 'hello world'

Given that there already exists an established (and documented) printf
convention, one could argue that overloading (or even augmenting) the
established placeholders is not the best option in this case.

>If the above is the case, we could've avoided all those exceptions
>that happen when a %d is specified but say a string is passed.

Generally I prefer handling exceptions to avoiding them.

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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Paddy
On Jul 17, 1:10 am, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:
> Hi,
>
> The string format operator, %, provides a functionality similar to the
> snprintf function in C. In C, the function does not know the type of
> each of the argument and hence relies on the embedded %
> specifier to guide itself while retrieving args.
>
> In python, the language already provides ways to know the type of an
> object.
>
> So in
>
> output = '%d foo %d bar" % (foo_count, bar_count),
> why we need to use %d? I'm thinking some general common placeholder,
> say %x (currently it's hex..) could be used.
>
> output = '%x foo %x bar" % (foo_count, bar_count).
> Since % by definition is string formatting, the operator should be
> able to infer how to convert each of the argument into strings.
>
> If the above is the case, we could've avoided all those exceptions
> that happen when a %d is specified but say a string is passed.
>
> Thanks,
> Karthik

'%s' might be what your after as a more 'general purpose' moifier.

- Paddy.

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


Re: sqlite3 db update extremely slow

2007-07-16 Thread Ben Finney
Steve Holden <[EMAIL PROTECTED]> writes:

> # We try to ensure the database is always closed by registering
> # the nodule's close() function to be called on program exit

Ooh! Where do I find more about writing Python nodules? Is it related
to cluster programming?

-- 
 \"If you go parachuting, and your parachute doesn't open, and |
  `\you friends are all watching you fall, I think a funny gag |
_o__)  would be to pretend you were swimming."  -- Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting text inside the HTML tag

2007-07-16 Thread BMintern
On Jul 14, 2:01 pm, [EMAIL PROTECTED] wrote:
> Oi! Try Beautiful Soup instead. That seems to be the defacto HTML
> parser for Python:
>
> http://www.crummy.com/software/BeautifulSoup/

After reading the docs through a bit and working through my own
examples, I can see why. Thanks for the link!

Brandon

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


Programming Jokes

2007-07-16 Thread Jokeslide
Muahahaha

http://www.jokeslide.com/index.php?cmd=4&project_id=78&obby_id=242

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


Is it possible to run two "while 1:" loops in two threadings respectively?

2007-07-16 Thread zxo102
Hi,
   I would like to combine two python applications into a single one
with two threadings. Both of them have a "while 1:" loop respectively.
For example, one application is to monitoring serial port 'com1' and
another application is a TCP/IP server which has used threadings
already. I write the following demo code but it does not work right.
It stays in the first "while 1:" and never thingOne.start(). The
second threading never be started.
Any ideas?

Thanks a lot.

Ouyang
#
import threading, time
class serial_port_com1:
  def spc(self):
 i = 0
 while 1:
time.sleep(5)
print "%d: hello, I am here in spc()"%i
i += 1

class TCP_IP:
  def tcpip(self):
 i = 0
 while 1:
time.sleep(5)
print "%d: hello, I am here in tcpip()"%i
i += 1

class ThreadOne ( threading.Thread ):
   def run ( self ):
  print 'Thread', self.getName(), 'started.'
  time.sleep ( 5 )
  print 'Thread', self.getName(), 'ended.'

class ThreadTwo ( threading.Thread ):
   def run ( self ):
  print 'Thread', self.getName(), 'started.'
  thingOne.join()
  print 'Thread', self.getName(), 'ended.'

if __name__=="__main__":
   spc  = serial_port_com1()
   tcpip = TCP_IP()
   thingOne = ThreadOne(target=spc.spc())
   thingOne.start()
   thingTwo = ThreadTwo(target=tcpip.tcpip())
   thingTwo.start()

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

Re: Implementaion of random.shuffle

2007-07-16 Thread Martin v. Löwis
>> 2**19937 being a really huge number, it's impossible to exhaust the
>> Mersenne twister by running it in sequence.
> 
> "Impossible"?

Unfeasible.

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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Kay Schluehr
On Jul 17, 3:10 am, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:

> output = '%d foo %d bar" % (foo_count, bar_count),
> why we need to use %d? I'm thinking some general common placeholder,
> say %x (currently it's hex..) could be used.

You already answered it in the parenthesized remark: the %d
placeholder is not only type bound but provides an additonal
distinction e.g. the one between decimals and hexadecimals. The kind
of general placeholder you want %x being requested for is actually %s
which formats decimals quite well unless you want leading zeros.

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


Re: Fetching a clean copy of a changing web page

2007-07-16 Thread Carsten Haese
On Tue, 2007-07-17 at 00:47 +, John Nagle wrote:
> Miles wrote:
> > On Jul 16, 1:00 am, John Nagle <[EMAIL PROTECTED]> wrote:
> > 
> >>I'm reading the PhishTank XML file of active phishing sites,
> >>at "http://data.phishtank.com/data/online-valid/";  This changes
> >>frequently, and it's big (about 10MB right now) and on a busy server.
> >>So once in a while I get a bogus copy of the file because the file
> >>was rewritten while being sent by the server.
> >>
> >>Any good way to deal with this, short of reading it twice
> >>and comparing?
> >>
> >>John Nagle
> > 
> > 
> > Sounds like that's the host's problem--they should be using atomic
> > writes, which is usally done be renaming the new file on top of the
> > old one.  How "bogus" are the bad files?  If it's just incomplete,
> > then since it's XML, it'll be missing the "" and you should
> > get a parse error if you're using a suitable strict parser.  If it's
> > mixed old data and new data, but still manages to be well-formed XML,
> > then yes, you'll probably have to read it twice.
> 
> The files don't change much from update to update; typically they
> contain about 10,000 entries, and about 5-10 change every hour.  So
> the odds of getting a seemingly valid XML file with incorrect data
> are reasonably good.

Does the server return a reliable last-modified timestamp? If yes, you
can do something like this:

prev_last_mod = None
while True:
u = urllib.urlopen(theUrl)
if prev_last_mod==u.headers['last-modified']:
break
prev_last_mod = u.headers['last-modified']
contents = u.read()
u.close()

That way, you only have to re-read the file if it actually changed
according to the time stamp, rather than having to re-read in any case
just to check whether it changed.

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Accessing Python variables in an extension module

2007-07-16 Thread Alex Martelli
MD <[EMAIL PROTECTED]> wrote:

> Hi Alex,
>   Thanks for the answer. Are there any C defines (for e.g. STRING,
> BOOLEAN) corresponding to each Python type?

No, I know of no such "defines" -- what good would they do?


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


RE: testing with coverage.py problem

2007-07-16 Thread Ryan Ginstrom
> On Behalf Of Piotr Hrebieniuk
> I've spent few hours and found nothing, so here's my question:
> How can i run tests wrote by myself on a module, using coverage.py ?
> Let's assume i have a module mymod.py which i want to test 
> with tests from file mytest.py (i.e. class inherited from 
> unittest.TestCase). How to do that with coverage.py? Where i 
> should put the code that runs the tests?

The easiest way is probably by using nose
http://somethingaboutorange.com/mrl/projects/nose/

In particular, check out the "--with-coverage" flag.

Regards,
Ryan Ginstrom

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


how to compile python to have gtk and Tkinter modules in Linux environment.

2007-07-16 Thread cfpete
Hello,
  How do I go about to have python compiled from source so that I can
import gtk and Tkinter modules.  Those don't seem to be included when
I use the default ./configure or python setup.py.

Thanks in advance,
-Peter

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


how to compile python to have gtk and Tkinter modules in Linux environment.

2007-07-16 Thread cfpete
Hello,
  How do I go about to have python compiled from source so that I can
import gtk and Tkinter modules.  Those don't seem to be included when
I use the default ./configure or python setup.py.

Thanks in advance,
-Peter

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


Re: Implementaion of random.shuffle

2007-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2007 14:45:48 +, shabda raaj wrote:

> On Jul 16, 5:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> shabda raaj wrote:
>> > I was going through the docs for module-random
>> >   And I came through
>> > this,
>>
>> > * shuffle*(x[, random])
>>
>> > Shuffle the sequence x in place. The optional argument random is
>> > a 0-argument function returning a random float in [0.0, 1.0); by
>> > default, this is the function random().
>>
>> > Note that for even rather small |len(x)|, the total number of
>> > permutations of x is larger than the period of most random number
>> > generators; this implies that most permutations of a long
>> > sequence can never be generated.

[snip]

> Oh, I wasn't aware that I could see the source of all python modules. I
> guess, then the implementation is correct(its just the knuth shuffle,
> moving downward), its just the doc which is in error. Might be we should
> log a doc bug for this?


No, it is not a doc error, you are confused.

Suppose you have a random number generator that has the tiny period of 
120. (Obviously that's a really lousy RNG, but it will do for an 
example.) That means it can only produce 120 different results (the 
current number, plus the state the generator it is in) before repeating.

Note that the period is not the same as the spread of values returned, 
the two are independent, although naturally the period must be at least 
equal to the number of unique values returned.

If you have a list of just six items, there are 6! = 720 possible 
permutations of the list, so AT BEST the random number generator can 
produce 120/720 or 17% of the permutations.

That's an example of the pigeonhole principle, one of the most simple yet 
powerful mathematical principles around. If you've got more items than 
pigeonholes to put them in, either some will double up or some will miss 
out.
 
In the case of CPython, the current implementation uses the Mersenne 
Twister, which has a huge period of 2**19937. However, 2081! is larger 
than that number, which means that at best a list of 2081 items or longer 
can't be perfectly shuffled (not every permutation can be selected by the 
algorithm).


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


Re: Implementaion of random.shuffle

2007-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2007 16:55:53 +0200, Hrvoje Niksic wrote:

> 2**19937 being a really huge number, it's impossible to exhaust the
> Mersenne twister by running it in sequence.

"Impossible"?

Surely this will do it:

for n in xrange(2**19937 + 1):
random.random()

Admittedly, if each call to random() took a picosecond, it would still 
take 1e5982 centuries to run through the lot. You might want to go make a 
coffee or something while you're waiting...



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


Re: Implementaion of random.shuffle

2007-07-16 Thread Scott David Daniels
shabda raaj wrote:
> ... Oh, I wasn't aware that I could see the source of all python modules
Well, actually not _all_ (or is that __all__), but that is exactly why 
so many of us love Python -- no magic (or at least as little as needed).

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Miles
On Jul 16, 8:10 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:
> Since % by definition is string formatting, the operator should be
> able to infer how to convert each of the argument into strings.

In addition to what Dan mentioned, you can use "%s" with any object to
perform an automatic string conversion.

>>> '%s %s %s %s' % ('Hello!', 3.14, 42+1j, object())
'Hello! 3.14 (42+1j) '

-Miles

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


Re: how to find available classes in a file ?

2007-07-16 Thread Gabriel Genellina
En Mon, 16 Jul 2007 20:13:19 -0300, Alex Popescu  
<[EMAIL PROTECTED]> escribió:

> On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]>
> wrote:
>> I want to have a (dynamically) list of all classes defined in a py-file.
>> Is there a way of getting this list, without manually parsing the file ?
>
> I have written something that does something like this, but I am not
> sure it is the pythonic way.
> Bascially I am loading the module and then using dir() on the module
> object I am looking for
> attribute of the type classobj (for old style classes) and type type
> (for new style classes).

There is also the pyclbr standard module  
 that does not load the  
module (just reparses enough of it to get the info needed). So a broken  
import, or any other initialization error, won't hurt.

> I also heard of the inspect module, but I haven't checked it yet.

inspect.getmembers(the_module, inspect.isclass) would do. But this  
requires the module to be importable.

-- 
Gabriel Genellina

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


ANN: Tftpy 0.4.3

2007-07-16 Thread msoulier
Copyright, Michael P. Soulier, 2006.

About Release 0.4.3:

Buxfix release for an issue with the server's detection of the end of
the file
during a download.

About Release 0.4.2:

Bugfix release for some small installation issues with earlier Python
releases.

About Release 0.4.1:

Bugfix release to fix the installation path, with some restructuring
into a
tftpy package from the single module used previously.

About Release 0.4:
==
This release adds a TftpServer class with a sample implementation in
bin.
The server uses a single thread with multiple handlers and a select()
loop to
handle multiple clients simultaneously.

Only downloads are supported at this time.

About Release 0.3:
==
This release fixes a major RFC 1350 compliance problem with the remote
TID.

About Release 0.2:
==
This release adds variable block sizes, and general option support,
implementing RFCs 2347 and 2348. This is accessible in the TftpClient
class
via the options dict, or in the sample client via the --blocksize
option.

About Release 0.1:
==

This is an initial release in the spirit of "release early, release
often".
Currently the sample client works, supporting RFC 1350. The server is
not yet
implemented, and RFC 2347 and 2348 support (variable block sizes) is
underway,
planned for 0.2.

About Tftpy:


Purpose:

Tftpy is a TFTP library for the Python programming language. It
includes
client and server classes, with sample implementations. Hooks are
included for
easy inclusion in a UI for populating progress indicators. It supports
RFCs
1350, 2347 and 2348.

Dependencies:
-
This library was developed against Python 2.3.

Trifles:

Project page: http://sourceforge.net/projects/tftpy/

License is the CNRI Python License.
http://www.opensource.org/licenses/pythonpl.php

See COPYING in this distribution.

Limitations:

- Server only supports downloads.
- Client only supports downloads.
- Only 'octet' mode is supported
- The only option supported is blksize

Author:
===

Michael P. Soulier <[EMAIL PROTECTED]>

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


Re: sqlite3 db update extremely slow

2007-07-16 Thread Steve Holden
coldpizza wrote:
> Thanks a lot, Roel, adding a single commit() at the end did solve the
> speed problem.
> 
> Another question is do I have to explicitly close the DB connection,
> or is it automatically garbage collected? Is it Ok to no have any
> cleanup code?
> 
It's generally OK, but you can register a function with atexit() if you 
are paranoid about cleanup. Here's a sample with an ugly global variable.

from atexit import register

def close():
 global conn
 if conn:
 conn.close()
 print "Database closed"
 conn = None

#
# We try to ensure the database is always closed by registering
# the nodule's close() function to be called on program exit
#
register(close)

import psycopg2 as db
conn = db.connect(database="billing", user="steve", password="tadaa!")
curs = conn.cursor()

print "Database opened"

> Another question would be how to define the encoding for newly added
> records?
> And how do set the encoding for the retrieved records? Is it always
> utf-8 by default?
> 
Generally speaking each database instance will have an associated 
encoding. Trying to establish some other encoding would then be pissing 
into the wind.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Fetching a clean copy of a changing web page

2007-07-16 Thread Steve Holden
John Nagle wrote:
> Miles wrote:
>> On Jul 16, 1:00 am, John Nagle <[EMAIL PROTECTED]> wrote:
>>
>>>I'm reading the PhishTank XML file of active phishing sites,
>>> at "http://data.phishtank.com/data/online-valid/";  This changes
>>> frequently, and it's big (about 10MB right now) and on a busy server.
>>> So once in a while I get a bogus copy of the file because the file
>>> was rewritten while being sent by the server.
>>>
>>>Any good way to deal with this, short of reading it twice
>>> and comparing?
>>>
>>>John Nagle
>>
>> Sounds like that's the host's problem--they should be using atomic
>> writes, which is usally done be renaming the new file on top of the
>> old one.  How "bogus" are the bad files?  If it's just incomplete,
>> then since it's XML, it'll be missing the "" and you should
>> get a parse error if you're using a suitable strict parser.  If it's
>> mixed old data and new data, but still manages to be well-formed XML,
>> then yes, you'll probably have to read it twice.
> 
> The files don't change much from update to update; typically they
> contain about 10,000 entries, and about 5-10 change every hour.  So
> the odds of getting a seemingly valid XML file with incorrect data
> are reasonably good.
> 
I'm still left wondering what the hell kind of server process will start 
serving one copy of a file and complete the request from another. Oh, well.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: 2**2**2**2**2 wrong? Bug?

2007-07-16 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Jul 15, 4:37 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> Wayne Brehaut wrote:
>>> On Fri, 13 Jul 2007 14:32:03 -0700, "[EMAIL PROTECTED]"
>> [...]
>>> But I digress (but only because provoked!)...
> [for purposes of this argument, at least]
>>> This statement is the informal equivalent to  saying  "Define a base-1
>>> number system as...", as I noted above. If you'd noted this, and
>>> understood it, or were willing to accept it whether or not you
>>> understood it, you'd have saved us both some bother--but me more than
>>> you I guess, so maybe you were just trolling?
>> wwway to beat a response to a pulp.
> 
> Crackpot math is the way to beat a response to a pulp?
> 
> And why does the response need to be beaten to a pulp?
> 
Well, having just seen your posted reply to the same message I'd have to 
acknowledge you as the expert at flogging dead horses.

> Isn't the purpose of comp.lang.python to promote knowledge,
> not ignorance?
> 
About Python, specifically, yes.

> When someone posts
> 
> x = []
> for i in range(255):
> x.append(i)
> 
> are you being a troll when you point out this could be
> done better using list comprehension?
> 
Nope, but you don;t have to write a 3,500-word essay to do it.

>> Sometimes it's easier and better for
>> your blood pressure just to let someone else have the last word, however
>> ill-informed
> 
> What was ill-informed? That there's no base 1?
> 
> >>> x = int('',1)
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> x = int('',1)
> ValueError: int() base must be >= 2 and <= 36
> 
> Or that Roman numerals aren't equivalent to tallying?
> 
>> or hostile.
> 
> What hostility?
> 
I was addressing someone else's expressed opinions of your contribution 
rather than my opinions of it. Anyway, I was trying to persuade someone 
to shorten his responses. Do I have to start on *you* now? ;-)

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread marduk
On Mon, 2007-07-16 at 17:33 -0700, Karthik Gurusamy wrote:
> Thanks. The above surprised me as I didn't expect that %s will accept
> 42.
> 
> Looks like the implicit conversion doesn't work the other way.
> 
> >>> '%s' % 42
> '42'
> >>> '%d' % '42'
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: int argument required
> >>>
> 
> Looks like %s can be used even when I'm sending non-strings.
> >>> '%s foo %s bar' % (25, 25.34)
> '25 foo 25.34 bar'
> >>>
> 
> So %s seems to serve the multi-type placeholder.

According to the docs: http://docs.python.org/lib/typesseq-strings.html

By design, %s "converts any python object using str()".  OTOH it does
not specify that %d, for example, calls int().


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


Re: Fetching a clean copy of a changing web page

2007-07-16 Thread John Nagle
Miles wrote:
> On Jul 16, 1:00 am, John Nagle <[EMAIL PROTECTED]> wrote:
> 
>>I'm reading the PhishTank XML file of active phishing sites,
>>at "http://data.phishtank.com/data/online-valid/";  This changes
>>frequently, and it's big (about 10MB right now) and on a busy server.
>>So once in a while I get a bogus copy of the file because the file
>>was rewritten while being sent by the server.
>>
>>Any good way to deal with this, short of reading it twice
>>and comparing?
>>
>>John Nagle
> 
> 
> Sounds like that's the host's problem--they should be using atomic
> writes, which is usally done be renaming the new file on top of the
> old one.  How "bogus" are the bad files?  If it's just incomplete,
> then since it's XML, it'll be missing the "" and you should
> get a parse error if you're using a suitable strict parser.  If it's
> mixed old data and new data, but still manages to be well-formed XML,
> then yes, you'll probably have to read it twice.

The files don't change much from update to update; typically they
contain about 10,000 entries, and about 5-10 change every hour.  So
the odds of getting a seemingly valid XML file with incorrect data
are reasonably good.

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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Karthik Gurusamy
On Jul 16, 5:18 pm, Dan Bishop <[EMAIL PROTECTED]> wrote:
> On Jul 16, 7:10 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:> Hi,
>
> > The string format operator, %, provides a functionality similar to the
> > snprintf function in C. In C, the function does not know the type of
> > each of the argument and hence relies on the embedded %
> > specifier to guide itself while retrieving args.
>
> > In python, the language already provides ways to know the type of an
> > object.
>
> > So in
>
> > output = '%d foo %d bar" % (foo_count, bar_count),
> > why we need to use %d?
>
> In order to distinguish between, for example:
>
>
>
> >>> '%c' % 42
> '*'
> >>> '%d' % 42
> '42'
> >>> '%e' % 42
> '4.20e+01'
> >>> '%f' % 42
> '42.00'
> >>> '%g' % 42
> '42'
> >>> '%i' % 42
> '42'
> >>> '%o' % 42
> '52'
> >>> '%r' % 42
> '42'
> >>> '%s' % 42
> '42'

Thanks. The above surprised me as I didn't expect that %s will accept
42.

Looks like the implicit conversion doesn't work the other way.

>>> '%s' % 42
'42'
>>> '%d' % '42'
Traceback (most recent call last):
  File "", line 1, in 
TypeError: int argument required
>>>

Looks like %s can be used even when I'm sending non-strings.
>>> '%s foo %s bar' % (25, 25.34)
'25 foo 25.34 bar'
>>>

So %s seems to serve the multi-type placeholder.

Karthik


> >>> '%u' % 42
> '42'
> >>> '%x' % 42
>
> '2a'


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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Matimus
I don't have a good answer for you, but you might be interested to
read this: http://python.org/dev/peps/pep-3101/. Which according to a
recent blog post by BDFL is going to be how string formatting is done
in Python3000.

The character doesn't specify the type to expect, but the formatting
function. So, %s calls a string formatter, %r calls repr and %x calls
a hex formatter. The there may be multiple formatters that produce
different results for given types. An integer can use %d,%e,%f,%s,%x
or %r, and they all produce slightly different results. Also, the
formatters take parameters. Such as "%+010.5f"%(1.23) which produces
"+001.23000".


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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread [EMAIL PROTECTED]
On Jul 16, 7:10 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:
> Hi,
>
> The string format operator, %, provides a functionality similar to the
> snprintf function in C. In C, the function does not know the type of
> each of the argument and hence relies on the embedded %
> specifier to guide itself while retrieving args.
>
> In python, the language already provides ways to know the type of an
> object.
>
> So in
>
> output = '%d foo %d bar" % (foo_count, bar_count),
> why we need to use %d? I'm thinking some general common placeholder,
> say %x (currently it's hex..) could be used.
>
> output = '%x foo %x bar" % (foo_count, bar_count).
> Since % by definition is string formatting, the operator should be
> able to infer how to convert each of the argument into strings.

You want all your numbers to print in hexadecimal?

>
> If the above is the case, we could've avoided all those exceptions
> that happen when a %d is specified but say a string is passed.

Who does that?

>
> Thanks,
> Karthik


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


Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Dan Bishop
On Jul 16, 7:10 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:
> Hi,
>
> The string format operator, %, provides a functionality similar to the
> snprintf function in C. In C, the function does not know the type of
> each of the argument and hence relies on the embedded %
> specifier to guide itself while retrieving args.
>
> In python, the language already provides ways to know the type of an
> object.
>
> So in
>
> output = '%d foo %d bar" % (foo_count, bar_count),
> why we need to use %d?
In order to distinguish between, for example:

>>> '%c' % 42
'*'
>>> '%d' % 42
'42'
>>> '%e' % 42
'4.20e+01'
>>> '%f' % 42
'42.00'
>>> '%g' % 42
'42'
>>> '%i' % 42
'42'
>>> '%o' % 42
'52'
>>> '%r' % 42
'42'
>>> '%s' % 42
'42'
>>> '%u' % 42
'42'
>>> '%x' % 42
'2a'

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


Re: Semantics of file.close()

2007-07-16 Thread Matimus
> How do I ensure that the close() methods in my finally clause do not
> throw an exception?

You have no choice. If close is going to fail, it will fail.
Fortunately you can catch the exception and continue on.

try:
try:
file1.write(somestuff)
finally:
file1.close()
except IOError:
pass

or you could wrap it in the inner scope:

try:
file1.write(somestuff)
finally:
try:
   file1.close()
except IOError:
pass


This doesn't prevent the exception from happening, but it prevents the
user for seeing it. Also, you don't need to use semicolons in python.

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


In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Karthik Gurusamy
Hi,

The string format operator, %, provides a functionality similar to the
snprintf function in C. In C, the function does not know the type of
each of the argument and hence relies on the embedded %
specifier to guide itself while retrieving args.

In python, the language already provides ways to know the type of an
object.

So in

output = '%d foo %d bar" % (foo_count, bar_count),
why we need to use %d? I'm thinking some general common placeholder,
say %x (currently it's hex..) could be used.

output = '%x foo %x bar" % (foo_count, bar_count).
Since % by definition is string formatting, the operator should be
able to infer how to convert each of the argument into strings.

If the above is the case, we could've avoided all those exceptions
that happen when a %d is specified but say a string is passed.

Thanks,
Karthik

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


Re: Semantics of file.close()

2007-07-16 Thread Dan Bishop
On Jul 16, 6:35 pm, [EMAIL PROTECTED] wrote:
> Hello,
>
> I'm a Python beginner and I'm trying to open, write and close a file
> in a
> correct manner. I've RTFM, RTFS, and I've read this 
> thread:http://groups.google.ca/group/comp.lang.python/browse_thread/thread/7...
>
> I still cannot figure out the semantic of file.close(). As far as I
> can
> tell it is undocumented.

It's documented.  Not necessarily very well, but it's documented.
Type help(file.close) at the interactive prompt.


close(...)
close() -> None or (perhaps) an integer.  Close the file.

Sets data attribute .closed to True.  A closed file cannot be used
for
further I/O operations.  close() may be called more than once
without
error.  Some kinds of file objects (for example, opened by
popen())
may return an exit status upon closing.

> How do I ensure that the close() methods in my finally clause do not
> throw an exception?

def quiet_close(fp):
"""Close a file, silently ignoring errors."""
try:
   fp.close()
except IOError:
   pass

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


Re: Binary blobs to jpeg

2007-07-16 Thread jayharvard
On Jul 16, 3:23 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> >> Have you tried to open the file in "wb" mode?
>
> > The data is coming from a record set selection from the Access
> > database. I guess I could write the data to a temp file and
> > open that file handle with the "wb" mode. But, no, I haven't
> > tried that.
>
> I think you missed the point.
>
> When you want to write the binary data to a file, you must open
> the destination file using "wb" mode.  It's binary data, not
> text data, so you have to open the output file in binary mode.
>
> --
> Grant Edwards   grante Yow! Is my fallout shelter
>   at   termite proof?
>visi.com

I did miss the point. I will give that a shot. Thanks Carsten and Grant

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


Re: trouble controlling vim with subprocess on windows machine

2007-07-16 Thread [EMAIL PROTECTED]
On Jul 16, 7:45 am, Yves Pouplard <[EMAIL PROTECTED]> wrote:
> On Mon, 09 Jul 2007 05:30:04 -0500, Nick Craig-Wood
>
> <[EMAIL PROTECTED]> wrote:
> >[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >>   I am having trouble contolling vim with subprocess on a windows
> >>  machine.  It appears that vim comes up on the machine all right and it
> >>  sometimes looks like it is doing the searchs what I am asking it to do
> >>  but when I am asking it to load a file it doesn't do anything.  Is
> >>  there something I need to do to push the data through the pipe??  Here
> >>  is a couple different ways I am trying to do it.
>
> >For controlling an interactive program subprocess isn't the right
> >tool.  Subprocess only really does one way communication - it isn't
> >good at conversations.  I'd suggest pexpect but it doesn't work on
> >windows.
>
> pexpect works with Cygwin's python :)
>
>
>
> >You appear to be doing stuff withcsound.  There are several python
> >modules out there which interface withcsound- did you investigate
> >those?- Hide quoted text -
>
> - Show quoted text -

I managed to get it as a com object (they have an example that isn't
very good on the gvim site) and it is in csound routines as of 2pm
today...  Looks like it should be easy to do with sed also but I don't
know that much about it.

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


Re: Semantics of file.close()

2007-07-16 Thread seerdecker
Sorry for the bad formatting; I've had to post this through the google
groups.

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


Semantics of file.close()

2007-07-16 Thread seerdecker
Hello,

I'm a Python beginner and I'm trying to open, write and close a file
in a
correct manner. I've RTFM, RTFS, and I've read this thread:
http://groups.google.ca/group/comp.lang.python/browse_thread/thread/73bbda2c920521c/98c731229d86b01d?lnk=st&q=python+file+explicit+close&rnum=1&hl=en#98c731229d86b01d

I still cannot figure out the semantic of file.close(). As far as I
can
tell it is undocumented. Explanations and example follow.

There are two occasions where you have to close a file:

1) At the end of a series of writes to the file, to ensure that all
data
   is written correctly to disk. In this case I want file.close() to
   throw an exception if the file cannot be written (e.g. when there
is
   no more disk space).

2) To clean up after an error occurred during the processing. In that
   case I just want to close the file handle cleanly. I do NOT want an
   exception to be thrown (e.g. in my finally clause).

Man page of fclose() -- in C:

  fclose - close a stream

  Upon successful completion 0 is returned.  Otherwise, EOF is
returned
  and the global variable errno is set to indicate the error.  In
either
  case any further access (including another call  to  fclose())  to
  the  stream results in undefined behaviour.

The man page of fclose() clearly indicates that fclose() may fail.
I've
already tested under Linux that fwrite() indicates success even if the
disk is full; the error is ONLY reported when close() is called.

Consider the following example:

file1 = None;
file2 = None;

try:
file1 = open("foo1.txt", "wb");
file2 = open("foo2.txt", "wb");
file1.close();
file2.close();

finally:
if file1: file1.close();
if file2: file2.close();

How do I ensure that the close() methods in my finally clause do not
throw an exception?

Thanks a lot,
Laurent Birtz

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


Re: The ** operator ambiguous?

2007-07-16 Thread Paul Boddie
Robert Dailey wrote:
> I noticed that the ** operator is used as the power operator, however
> I've seen it used when passing variables into a function.

Others have already pointed out the relevant documentation. However,
this ambiguous usage of * and ** is one thing I don't recall appearing
on any of the "Python warts" lists - not that I spend too much time
following such matters. I imagine that * was initially chosen in order
to be similar to the way one may handle collections of values in C
function signatures (ie. using pointers), and that ** was merely a
convenient next step as opposed to being analogous to the "pointer to
pointer" notation from C. The same symbols are used in different ways
in C and C++, of course.

It's interesting to see a fresh interpretation of the notation,
though.

Paul

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


[Music Movies Soft] Free binaries search & download = www.GEGEREKA.com

2007-07-16 Thread GEGEREKA!
Project of the year: Incredible unique search machine like nothing on earth.
MP3,MPEG,AVI,DIVX,DLL,PHP,EXE,ISO, ...and much more
Millions files for everyone. Music, movies, soft and other media.
http://www.GEGEREKA.com : THE LORD OF DOWNLOADS.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to organize control access to source code ?

2007-07-16 Thread Succelus
On 16 juil, 21:10, Erik Jones <[EMAIL PROTECTED]> wrote:
> On Jul 16, 2007, at 3:46 PM, [EMAIL PROTECTED] wrote:
>
> > Hello,
> > How can we organize development team with code source control policy,
> > that limit access to some portion of code ?
>
> The specifics largely depend on the system(s) you're working with
> but, basically (sic), you need to read up on filesystem level
> permissions.
>

Thanks for your response,
But I want to know if there is a process or best practices, to give
not the access to all of the project. in other words, must every
developer work on the entire copy of the project locally ?

Or to work just on his module and manage a process of integration, and
if there is any Agile practices for this problem.


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


Re: how to find available classes in a file ?

2007-07-16 Thread Alex Popescu
On Jul 17, 1:44 am, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> I want to have a (dynamically) list of all classes defined in a py-file.
> Is there a way of getting this list, without manually parsing the file ?
>
> thanks,
> Stef Mientki

I have written something that does something like this, but I am not
sure it is the pythonic way.
Bascially I am loading the module and then using dir() on the module
object I am looking for
attribute of the type classobj (for old style classes) and type type
(for new style classes).

I also heard of the inspect module, but I haven't checked it yet.

bests,
./alex
--
.w( the_mindstorm )p.


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


Re: sqlite3 db update extremely slow

2007-07-16 Thread coldpizza
Thanks a lot, Roel, adding a single commit() at the end did solve the
speed problem.

Another question is do I have to explicitly close the DB connection,
or is it automatically garbage collected? Is it Ok to no have any
cleanup code?

Another question would be how to define the encoding for newly added
records?
And how do set the encoding for the retrieved records? Is it always
utf-8 by default?

On Jul 16, 11:21 pm, Roel Schroeven <[EMAIL PROTECTED]>
wrote:
> coldpizza schreef:
>
> > I am trying to fill a sqlite3 database with records, and to this end I
> > have written a class that creates the db, the table and adds rows to
> > the table.
>
> > The problem is that the updating process is *extremely* slow, and
> > occasionally I get the message "database locked".
>
> > I tried removing "self.con.commit()" in the add_record method, but
> > then nothing is saved in the db. I don't know whether this has
> > anything to do with it, but I have found no option to enable
> > autocommit.
>
> Remove self.con.commit() from add_record(), and do it once after all
> records are added.
>
> The reason that the process is slow with a commit after every INSERT is
> that sqlite syncs the inserted data to disk before it continues.
>
> --
> If I have been able to see further, it was only because I stood
> on the shoulders of giants.  -- Isaac Newton
>
> Roel Schroeven


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


Re: 2**2**2**2**2 wrong? Bug?

2007-07-16 Thread [EMAIL PROTECTED]
On Jul 15, 4:37 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Wayne Brehaut wrote:
> > On Fri, 13 Jul 2007 14:32:03 -0700, "[EMAIL PROTECTED]"
> [...]
> > But I digress (but only because provoked!)...
>
> >>> [for purposes of this argument, at least]
>
> > This statement is the informal equivalent to  saying  "Define a base-1
> > number system as...", as I noted above. If you'd noted this, and
> > understood it, or were willing to accept it whether or not you
> > understood it, you'd have saved us both some bother--but me more than
> > you I guess, so maybe you were just trolling?
>
> wwway to beat a response to a pulp.

Crackpot math is the way to beat a response to a pulp?

And why does the response need to be beaten to a pulp?

Isn't the purpose of comp.lang.python to promote knowledge,
not ignorance?

When someone posts

x = []
for i in range(255):
x.append(i)

are you being a troll when you point out this could be
done better using list comprehension?

> Sometimes it's easier and better for
> your blood pressure just to let someone else have the last word, however
> ill-informed

What was ill-informed? That there's no base 1?

>>> x = int('',1)

Traceback (most recent call last):
  File "", line 1, in 
x = int('',1)
ValueError: int() base must be >= 2 and <= 36

Or that Roman numerals aren't equivalent to tallying?

> or hostile.

What hostility?

>
> regards
>   Steve

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


Re: 2**2**2**2**2 wrong? Bug?

2007-07-16 Thread [EMAIL PROTECTED]
On Jul 15, 4:28 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote:
> On Fri, 13 Jul 2007 14:32:03 -0700, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> wrote:
> >On Jul 13, 2:52 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote:
> >> On Fri, 13 Jul 2007 11:30:16 -0700, Paul McGuire <[EMAIL PROTECTED]>
> >> wrote:
>
> >> >On Jul 13, 1:20 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote:
> >> >> On Mon, 09 Jul 2007 23:51:25 -0700, "[EMAIL PROTECTED]"
>
> >> >> <[EMAIL PROTECTED]> wrote:
> >> >> >On Jul 9, 11:42?pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> >> >> >> On Jul 9, 11:21 pm, "Jim Langston" <[EMAIL PROTECTED]> wrote:> In 
> >> >> >> Python 2.5 on intel, the statement
> >> >> >> > 2**2**2**2**2
> >> >> >> > evaluates to>>> 2**2**2**2**2
>
> === 8< ===
>
> >> >> >Did you count the 'L'?
>
> >> >> numdigits(n)?
>
> >> >> What?  'L' is a digit in Python?  I'm going back to Fortran!
>
> >> >> wwwayne
>
> === 8< ===
>
> >> >'L' counts for 50, but only when you use Roman font.
>
> >> WTL?!  Not Times  New Roman I hope?
>
> >> Now I'll have to extend my remarks below to include:
>
> >> L**L**L
> >> D**D**D
> >> M**M**M
> >> etc. (since I don't recall what comes next)
>
> >> though these (L, D, M, ...)  would seem to be numbers rather than
> >> digits: the Romans used a base-1 system
>
> >No, "base" refers to a Positional Number system for which
> >radix 1 is undefined.
>
> >You can call Roman Numerals a Tally System of Radix 1.
>
> I can call it what I want--within reason--

Noted.

> so long as those I'm mainly
> addressing understand what I mean and the context in which I'm saying
> it.  As I note in my other response to your response below, my remark
> was intended to be humorous, and everyone else who responded took it
> that way.

But this is comp.lang.python, not sci.math. And in that context
"base" implies positional number system. To assume anything else
is not within reason.

>
> There's no need to get all formal in such a context, and there's no
> harm in defining a  tally system to be 1-based or to be a base-1
> system.

You do know that "radix 1" is the proper usage? Since "base 1" is
meaningless in some contexts? Programming languages tend to be a
bit anal about syntax, so yes, you do need to get all formal.

> If I had intended this to be a formal discussion instead of
> just having a little fun (and sorry for doing that) I would have
> instead said: "Define a base-1 number system as...".
>
> Since you clearly don;t want to accept my terminology and assume
> there's just one right one, please 
> seehttp://www.psinvention.com/zoetic/basenumb.htmfor an independent
> opinion of the reasonableness of using this term: "Base Valued Numbers

I prefer Knuth's "The Art of Computer Programming" where these
things are presented formally rather than the informality of
some stupid web page.

>
> Any use of numbers implies the use of a base value for the numbers.
> The simplest base value to use in a numbering scheme is '1'."

And I didn't say you couldn't use it. Just not with positional
number systems.

>
> Because we're most familiar with the use of the term "base" in the
> context of positional notation in no way implies that's the only
> possible context in which it can be used

And I didn't say it was the only context. But since this context
happens to be Python, that argument is moot.

> --or has been used--with
> perfectly clear meaning.  So the Roman system was based on the number
> 1 and was, therefore, 1-based or base-1.

You should say "radix 1" to be unambiguous.

>
> Even in the context of positional systems it's perfectly clear what a
> base-1 system would be and the fact that it's generally excluded isn;t
> because it's not cleaar what it weould be, but only that most assume
> it isn't of any uise,

An assumption that is, in fact, true.

> so exclude it.  As we all know:

Oh boy, here we go. And you were doing so good up to this point.

>
> 1^0 = 1
> 1^1 = 1
> 1^n = 1 for any positive natural number
>  [and negative natural numbers don't exist, but extension to negative
> integers is left as an exercise for the reader]
>
> In the base 1 positional number system, what is the value of:
>
> 1
> 11
> 111
> 1...1 (with n 1s)?

These numbers don't exist in a positional number system of radix 1.

>
> And would the value be any different if I wrote them:
>
>   1
> 11
>   111
> 1...1 (with n 1s)?

No, because they don't exist either.

>
> In pictures:
>
> Pos?   ?
> Value  1
> Digit1
>
> Pos?   ?  ?
> Value  1  1
> Digit1  1
>
> Pos?   ?  ?   ?
> Value  1  1  1
> Digit1  1  1
>
> Pos?   ?  ...   ?
> Value  1  ...  1 (n positions)
> Digit1  ...  1 (n 1s)
>
> >Tally sytems ARE defined for radix 1, but operate
> >completely different from positional systems.
>
> Clearly, the algorithm to find the value of a base-1 number  is to
> multiply the value of each position (1) by the digit in that position
> (1) and add the results--just as you would do for any other positional

Re: Break up list into groups

2007-07-16 Thread James Stroud
Paul Rubin wrote:
> See:
> 
> http://groups.google.com/group/comp.lang.python/msg/2410c95c7f3b3654

Groupby is damn slow as far as I can tell (the Bates numbering in the 
above link assumes more than the OP intended, I assume). It looks like 
the author's original algorithm is the fastest python way as it bypasses 
a lot of lookup, etc.

Here's the output from the script below (doit2 => groupby way):

doit
11.96 usec/pass
doit2
87.14 usec/pass


James

# timer script
from itertools import groupby
from timeit import Timer

alist = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6,
  0xF1, 7, 8, 0xF2, 9, 10, 11, 12, 13,
  0xF0, 14, 0xF1, 15]

def doit(alist):
   ary = []
   for i in alist:
 if 0xf0 & i:
   ary.append([i])
 else:
   ary[-1].append(i)
   return [x for x in ary if x]

def c(x):
   return 0xf0 & x

def doit2(alist):
   i = (list(g) for k,g in groupby(alist, c))
   return [k for k in [j + i.next() for j in i] if len(k)>1]

print doit(alist)

print 'doit'
t = Timer('doit(alist)',
   'from __main__ import groupby, doit, alist, c')
print "%.2f usec/pass" % (100 * t.timeit(number=10)/10)

print 'doit2'
t = Timer('doit2(alist)',
   'from __main__ import groupby, doit2, alist, c')
print "%.2f usec/pass" % (100 * t.timeit(number=10)/10)


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: Break up list into groups

2007-07-16 Thread [EMAIL PROTECTED]
> Here's an ugly way I wouldn't recommended (using itertools groupby):
>
> py> from itertools import groupby
> py> alist = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6,
> ...  0xF1, 7, 8, 0xF2, 9, 10, 11, 12, 13,
> ...  0xF0, 14, 0xF1, 15]
> py> def doit(alist):
> ...   i = (list(g) for k,g in groupby(alist, lambda x: 0xf0&x))
> ...   return [k for k in [j + i.next() for j in i] if len(k)>1]
> ...
> py> doit(alist)
>
> [[240, 1, 2, 3],
>   [240, 4, 5, 6],
>   [241, 7, 8],
>   [242, 9, 10, 11, 12, 13],
>   [240, 14],
>   [241, 15]]
>
> James

Wow that is ugly. I think I like the simpler way better.

Thanks

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


Re: Break up list into groups

2007-07-16 Thread [EMAIL PROTECTED]
On Jul 16, 3:56 pm, marduk <[EMAIL PROTECTED]> wrote:
> On Mon, 2007-07-16 at 16:31 -0500, marduk wrote:
> > Assuming you meant '0xF0' instead of '0x80' do you mean any value
> > >=240 starts a new group?  If so:
No, I meant 0x80. 0x80 is only the most significant bit of the 0xF0
value. Every time this bit is set indicates the start of a new group.
Anyway, I like this algorithm better than mine, less code. I've
modified yours to make the fn a parameter:

def splitIntoGroups(data, fn):
groups  = []
current = []
for i in data:
if fn(i):
current = []
groups.append(current)
current.append(i)

return groups

print splitIntoGroups(l, lambda x : x & 0x80)

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


how to find available classes in a file ?

2007-07-16 Thread Stef Mientki
I want to have a (dynamically) list of all classes defined in a py-file.
Is there a way of getting this list, without manually parsing the file ?

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


Re: Break up list into groups

2007-07-16 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> I can't seem to find an answer to this question anywhere, but I'm
> still looking. My problem is I have a list of values like this:
> 
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
> 
> A value with bit 0x80 set delineates the start of a new packet of
> information. What I want to do is to group the packets so that 1, 2, 3
> go with the 1st packet tagged 0xF0, 4 ,5, 6 go with the 2nd packet
> tagged 0xF0, 7 & 8 go with the packet tagged 0xF1 and so on. The
> length of the data associated with each tag can vary. I've already
> written an algorithm to do this but I was wondering if some
> combination of itertools functions could do the job faster?

See:

http://groups.google.com/group/comp.lang.python/msg/2410c95c7f3b3654
-- 
http://mail.python.org/mailman/listinfo/python-list


www.cerocom.com

2007-07-16 Thread Natalia
.. www.cerocom.com 
..

You will be able to ask yourself:

Is Internet a good investment for my company?
So that an investment would have to do I of this type?
Really is going to serve to me to have a Web site?
So that to be in Internet?

See some of the main advantages have a Web site:

· Increase the productivity and to generate more businesses with the
implementation of collaboration  rofe and integration maximizing the
value of Internet and networks IP.

· Offer solutions of Internet, integration and collaboration in
accordance with our clients, anyone is their size or trains, to
rofesional r to integrate their applications, to fortify their present
position in the market or to impel their growth, assuring
trustworthiness, discharge  rofesional qualification, and customized
service.

I invite it to cross the Web site and interiorice of the services
available.

www.cerocom.com

Contact:

Commercial direction:
Viamonte 783 Piso 3°
Capital Federal
(C1053ABO) Bs. As. Argentina

Tel/Fax: (54.11) 4322.1201

Celular: (54-9-11) (15) 5006.4384

Mail:  [EMAIL PROTECTED]

Web Site:  www.cerocom.com

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


www.cerocom.com

2007-07-16 Thread Natalia
.. www.cerocom.com 
..

You will be able to ask yourself:

Is Internet a good investment for my company?
So that an investment would have to do I of this type?
Really is going to serve to me to have a Web site?
So that to be in Internet?

See some of the main advantages have a Web site:

· Increase the productivity and to generate more businesses with the
implementation of collaboration  rofe and integration maximizing the
value of Internet and networks IP.

· Offer solutions of Internet, integration and collaboration in
accordance with our clients, anyone is their size or trains, to
rofesional r to integrate their applications, to fortify their present
position in the market or to impel their growth, assuring
trustworthiness, discharge  rofesional qualification, and customized
service.

I invite it to cross the Web site and interiorice of the services
available.

www.cerocom.com

Contact:

Commercial direction:
Viamonte 783 Piso 3°
Capital Federal
(C1053ABO) Bs. As. Argentina

Tel/Fax: (54.11) 4322.1201

Celular: (54-9-11) (15) 5006.4384

Mail:  [EMAIL PROTECTED]

Web Site:  www.cerocom.com

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


Re: zipfile 2GB problems?

2007-07-16 Thread John Machin
On Jul 17, 7:37 am, xamdam <[EMAIL PROTECTED]> wrote:
> On Jul 16, 3:39 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>
>
>
> > xamdam wrote:
> > > On Jul 15, 5:39 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> > >> xamdam wrote:
> > > Additional info: my file is from a data provider, do not know what
> > > they used to compress it. Previous files worked ok, this one is the
> > > 1st over 2GB. Winzip has no problem with it.
> >  It could be you are using a Python with an in-built limit of 2GB on 
> >  file
> >  size. What happens if you open the file, seek past the 2GB point and
> >  then try and read data?
> > >>> Steve,
> > >>> I used is_zipfile function, which from does exactly that from a quick
> > >>> read - goes to the end, reads expected string. It worked fine. Tried
> > >>> regular Windows 2.4.4 and 2.5.1, same result.
> > >> Fine, if it isn't file size limitations I suspect you need to post some
> > >> code and a traceback so we can get better insight into exactly what the
> > >> problem is.
>
> > > It's failing in the ZipFile constructor, which ends up throwing
>
> > > zipfile(2.4.3).py:291> raise BadZipfile, "Bad magic number for file
> > > header"
>
> > Well, that one bald line by itself certainly doesn't give *me* any
> > traction an what the problem might be. Getting information about this
> > problem is like (i.e. as difficult as) pulling teeth!
>
> > regards
> >   Steve
>
> Well, Steve, I don't know what else to tell you

"post some code and a traceback"

> I certainly do not
> want to cause you tooth ache!

I suspect that you are inducing unwanted symptoms at the *other* end
of Steve's alimentary canal.

> I was sort of hoping for some ZIP expert
> to go, 'oh, yeah'...

Hope all you want, but supply the information you are asked for.

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


Re: The ** operator ambiguous?

2007-07-16 Thread Klaas
On Jul 16, 10:40 am, Robert Dailey <[EMAIL PROTECTED]> wrote:
> I noticed that the ** operator is used as the power operator, however
> I've seen it used when passing variables into a function. For example,
> I was researching a way to combine dictionaries. I found that if you
> do this:
>
> a = {"t1":"a", "t2":"b"}
> b = {"t3":"c"}
> dict( a, **b )
>
> This combines the two dictionaries.

Use dict.update to combine dictionaries.

-Mike

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


Re: Break up list into groups

2007-07-16 Thread Matimus
This is a perfect place for a generator:


seq = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
13, 0xF0, 14, 0xF1, 15]

def gengroups(seq):
group = []
for val in seq:
if val & 0x80 and group:
yield group
group = []
group.append(val)
yield group

if __name__ == "__main__":
print list(gengroups(seq))


The above assumes that the first value in the input sequence will have
0x80 set. Your implementation seems to makes the same assumption
though.

Also, just a note...

if len(local) > 0:
 ...


is better written


if local:
 ...


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


Re: Break up list into groups

2007-07-16 Thread James Stroud
James Stroud wrote:
> Here's how I *would* do it:
> 
> py> def doit(alist):
> ...   ary = []
> ...   for i in alist:
> ... if 0xf0 & i:
> ...   ary.append([i])
> ... else:
> ...   ary[-1].append(i)
> ...   return [x for x in ary if x]
> ...


To be absolutely compliant with the specifications, it should be

return [x for x in ary if len(x)>1]

in the recommended way. This does not affect the example given, though.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: zipfile 2GB problems?

2007-07-16 Thread John Machin
On Jul 17, 4:59 am, xamdam <[EMAIL PROTECTED]> wrote:
> On Jul 15, 5:39 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>
>
>
> > xamdam wrote:
> > >>> Additional info: my file is from a data provider, do not know what
> > >>> they used to compress it. Previous files worked ok, this one is the
> > >>> 1st over 2GB. Winzip has no problem with it.
> > >> It could be you are using a Python with an in-built limit of 2GB on file
> > >> size. What happens if you open the file, seek past the 2GB point and
> > >> then try and read data?
>
> > > Steve,
> > > I used is_zipfile function, which from does exactly that from a quick
> > > read - goes to the end, reads expected string. It worked fine. Tried
> > > regular Windows 2.4.4 and 2.5.1, same result.
>
> > Fine, if it isn't file size limitations I suspect you need to post some
> > code and a traceback so we can get better insight into exactly what the
> > problem is.
>
> It's failing in the ZipFile constructor, which ends up throwing
>
> zipfile(2.4.3).py:291> raise BadZipfile, "Bad magic number for file
> header"

Suggestion 1: RTEDManual

Manual says:
"""
12.4.1 ZipFile Objects

class ZipFile( file[, mode[, compression[, allowZip64]]])
[snip]
If allowZip64 is True zipfile will create ZIP files that use the ZIP64
extensions when the zipfile is larger than 2 GB. If it is false (the
default) zipfile will raise an exception when the ZIP file would
require ZIP64 extensions. ZIP64 extensions are disabled by default
because the default zip and unzip commands on Unix (the InfoZIP
utilities) don't support these extensions.
"""

It's vague about whether allowZip64=True is needed for reading -- have
you tried it?

Suggestion 2: RTEDCode. At the line you quoted, it is checking the
first 4 bytes of the file for a signature: 'PK\x03\x04'
Do this:
print repr(open('yourfile.zip', 'rb').read(4))
Tell us what you find.

Suggestion 3: RTEDWordsOfWisdomOfSteveHolden. IOW supply the *WHOLE*
EDing traceback.

HTH,
John

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


Re: Break up list into groups

2007-07-16 Thread James Stroud
[EMAIL PROTECTED] wrote:
> All,
> 
> I can't seem to find an answer to this question anywhere, but I'm
> still looking. My problem is I have a list of values like this:
> 
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
> 
> A value with bit 0x80 set delineates the start of a new packet of
> information. What I want to do is to group the packets so that 1, 2, 3
> go with the 1st packet tagged 0xF0, 4 ,5, 6 go with the 2nd packet
> tagged 0xF0, 7 & 8 go with the packet tagged 0xF1 and so on. The
> length of the data associated with each tag can vary. I've already
> written an algorithm to do this but I was wondering if some
> combination of itertools functions could do the job faster?
> 
> Here's what I've done and the expected output of the algorithm:
> 
> def splitIntoGroups(data):
> groups = []
> local = []
> 
> for value in data:
> if 0x80 & value:
> if len(local) > 0:
> groups.append(local)
> 
> local = []
> local.append(value)
> else:
> local.append(value)
> 
> if len(local) > 0:
> groups.append(local)
> 
> return groups
> 
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
> 
> print splitIntoGroups(l)
> 
> Desired result:
> 
> [[240, 1, 2, 3], [240, 4, 5, 6], [241, 7, 8], [242, 9, 10, 11, 12,
> 13], [240, 14], [241, 15]]
> 
> Thanks,
> 
> Dan McLeran
>

Here's how I *would* do it:

py> def doit(alist):
...   ary = []
...   for i in alist:
... if 0xf0 & i:
...   ary.append([i])
... else:
...   ary[-1].append(i)
...   return [x for x in ary if x]
...
py> doit(alist)

[[240, 1, 2, 3],
  [240, 4, 5, 6],
  [241, 7, 8],
  [242, 9, 10, 11, 12, 13],
  [240, 14],
  [241, 15]]


Here's an ugly way I wouldn't recommended (using itertools groupby):

py> from itertools import groupby
py> alist = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6,
...  0xF1, 7, 8, 0xF2, 9, 10, 11, 12, 13,
...  0xF0, 14, 0xF1, 15]
py> def doit(alist):
...   i = (list(g) for k,g in groupby(alist, lambda x: 0xf0&x))
...   return [k for k in [j + i.next() for j in i] if len(k)>1]
...
py> doit(alist)

[[240, 1, 2, 3],
  [240, 4, 5, 6],
  [241, 7, 8],
  [242, 9, 10, 11, 12, 13],
  [240, 14],
  [241, 15]]


James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: Python-URL! - weekly Python news and links (Jul 16)

2007-07-16 Thread Kay Schluehr

Gabriel Genellina schrieb:
> QOTW:  "That's a property of open source projects. Features nobody really
> needs are not implemented." - Gregor Horvath

It's a good QOTW but social romantic nonsense nevertheless.

Not sure if it's important enough to be mentioned in weekly Python
news but Europython 2007 actually happened and took place in Vilnius.

Kay

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


[Music Movies Soft] Free binaries search & download = www.GEGEREKA.com

2007-07-16 Thread GEGEREKA!
Project of the year: Incredible unique search machine like nothing on earth.
MP3,MPEG,AVI,DIVX,DLL,PHP,EXE,ISO, ...and much more
Millions files for everyone. Music, movies, soft and other media.
http://www.GEGEREKA.com : THE LORD OF DOWNLOADS.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Break up list into groups

2007-07-16 Thread marduk
On Mon, 2007-07-16 at 16:31 -0500, marduk wrote:
> Assuming you meant '0xF0' instead of '0x80' do you mean any value
> >=240 starts a new group?  If so:
> 
> groups = []
> current = [] # probably not necessary, but as a safety
> for i in l:
> if i >= 240:
> current = []
> groups.append(current)
> current.append(i)
> 
> 

Misunderstood... actually that should have read

groups = []
current = [] # probably not necessary, but as a safety
for i in l:
if 240 & i:
current = []
groups.append(current)
current.append(i)

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


Re: Class decorators do not inherit properly

2007-07-16 Thread Bruno Desthuilliers
Lee Harr a écrit :
>>>I think the term "class decorator" is going to eventually
>>>mean something other than what you are doing here. I'd
>>>avoid the term for now.
>>>
>>>
>>>When you decorate a class method,
>>>the function you use
>>>needs to be defined before the method definition.
>>
>>FWIW, the term "class method" has a 
>>definite meaning in Python.
> 
> 
> 
> Certainly. But "class decorator" is being introduced in
> Python 3000 with PEP 3129:
> http://www.python.org/dev/peps/pep-3129/
> 

Certainly. But [1] "class methods" have been introduced in Python 2.2 !-)

[1] IIRC - please someone correct me if I'm wrong
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: zipfile 2GB problems?

2007-07-16 Thread xamdam
On Jul 16, 3:39 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> xamdam wrote:
> > On Jul 15, 5:39 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> >> xamdam wrote:
> > Additional info: my file is from a data provider, do not know what
> > they used to compress it. Previous files worked ok, this one is the
> > 1st over 2GB. Winzip has no problem with it.
>  It could be you are using a Python with an in-built limit of 2GB on file
>  size. What happens if you open the file, seek past the 2GB point and
>  then try and read data?
> >>> Steve,
> >>> I used is_zipfile function, which from does exactly that from a quick
> >>> read - goes to the end, reads expected string. It worked fine. Tried
> >>> regular Windows 2.4.4 and 2.5.1, same result.
> >> Fine, if it isn't file size limitations I suspect you need to post some
> >> code and a traceback so we can get better insight into exactly what the
> >> problem is.
>
> > It's failing in the ZipFile constructor, which ends up throwing
>
> > zipfile(2.4.3).py:291> raise BadZipfile, "Bad magic number for file
> > header"
>
> Well, that one bald line by itself certainly doesn't give *me* any
> traction an what the problem might be. Getting information about this
> problem is like (i.e. as difficult as) pulling teeth!
>
> regards
>   Steve

Well, Steve, I don't know what else to tell you - I certainly do not
want to cause you tooth ache! I was sort of hoping for some ZIP expert
to go, 'oh, yeah'...

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


Re: questions about functions inside a function

2007-07-16 Thread Bruno Desthuilliers
Jeremy Sanders a écrit :
> [EMAIL PROTECTED] wrote:
> 
> 
>>What I want is, the value of i should be bounded to the anonymous
>>function. And the output should like this:
> 
> ...
> 
>>How to achieve this?
> 
> 
> This doesn't answer your question (others have), but another (perhaps
> clearer) way to do such things is something like
> 
> class MyFunc(object):
>   """A function object."""
>   def __init__(self, val):
>  self.val = val
> 
>   def __call__(self):
>  """Return value squared"""
>  return self.val**2
> 
> a = []
> for i in range(4):
>   a.append(MyFunc(i))
> 
> for f in a:
>   f()
> 

I wouldn't say it's "clearer" - at least in this concrete use case. And 
it takes more than just defining the __call__ method to have a fully 
function-like object (hint: try using a MyFunc instance as a method).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Discover instance variables

2007-07-16 Thread Lawrence Oluyede
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> The list keeps only the types explicitely enumerated. Other types are
> excluded, as well as names starting with "_". Another criterion would be
> `not attr.startswith('_') and not callable(getattr(obj,attr))`

Why not:

In [1]: class Foo(object):
   ...: a = 3
   ...: 
   ...: 

In [2]: import inspect

In [4]: inspect.getmembers(Foo())
Out[4]: 
[('__class__', ),
 ('__delattr__', ),
 ('__dict__', {}),
 ('__doc__', None),
 ('__getattribute__',
  ),
 ('__hash__', ),
 ('__init__', ),
 ('__module__', '__main__'),
 ('__new__', ),
 ('__reduce__', ),
 ('__reduce_ex__', ),
 ('__repr__', ),
 ('__setattr__', ),
 ('__str__', ),
 ('__weakref__', None),
 ('a', 3)]

and then filter out __xyz__ methods?


-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand 
something when his salary depends on not
understanding it" - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Break up list into groups

2007-07-16 Thread marduk
On Mon, 2007-07-16 at 14:11 -0700, [EMAIL PROTECTED] wrote:
> I can't seem to find an answer to this question anywhere, but I'm
> still looking. My problem is I have a list of values like this:
> 
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
> 
> A value with bit 0x80 set delineates the start of a new packet of
> information. What I want to do is to group the packets so that 1, 2, 3
> go with the 1st packet tagged 0xF0, 4 ,5, 6 go with the 2nd packet
> tagged 0xF0, 7 & 8 go with the packet tagged 0xF1 and so on. The
> length of the data associated with each tag can vary. I've already
> written an algorithm to do this but I was wondering if some
> combination of itertools functions could do the job faster?
> 
> Here's what I've done and the expected output of the algorithm:
> 
> def splitIntoGroups(data):
> groups = []
> local = []
> 
> for value in data:
> if 0x80 & value:
> if len(local) > 0:
> groups.append(local)
> 
> local = []
> local.append(value)
> else:
> local.append(value)
> 
> if len(local) > 0:
> groups.append(local)
> 
> return groups
> 
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
> 
> print splitIntoGroups(l)
> 
> Desired result:
> 
> [[240, 1, 2, 3], [240, 4, 5, 6], [241, 7, 8], [242, 9, 10, 11, 12,
> 13], [240, 14], [241, 15]] 

Assuming you meant '0xF0' instead of '0x80' do you mean any value
>=240 starts a new group?  If so:

groups = []
current = [] # probably not necessary, but as a safety
for i in l:
if i >= 240:
current = []
groups.append(current)
current.append(i)


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


Re: Private functions and inheritance

2007-07-16 Thread Bruno Desthuilliers
Maciej Bliziński a écrit :
(snip the rest - already answered by at least 3 persons).

> I
> don't want to expose the __bar() function outside, but on the other
> hand i want to defer its implementation to a subclass. It seems like I
> need to make it public, doesn't it?

First, keep in mind that that Python *does not* have any notion of 
(languaged enforced) access restriction. All that the  __name thingie 
does is to mangle the name with the class name, so A.bar become 
A._A__bar. This can be useful. Sometimes. Perhaps. (FWIW, I think I've 
used it once in seven years and I'm not sure it was really necessary 
after all).

Now there's a strong convention which says that _names prefixed by a 
single underscore are implementation stuff, and that anyone messing with 
implementation stuff implicitely accepts all the possible consequences.


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

Re: Dynamic method

2007-07-16 Thread Daniel
Bruno Desthuilliers wrote:
>
> > Another way is to use the 'types' module:
>
> True - and that's somewhat cleaner since it doesn't expose the internals
> of the descriptor protocol. OTHO, it can lead to strange results with
> callables not implementing the descriptor protocol:



Actually, the result is not "strange" at all if you understand what's
going. The reason you got an exception is because your __call__()
method only takes a single argument (the implicit self argument, which
is the instance of MyCallable). However, if you define it with two
arguments it works just fine:

>>> class MyCallable(object):
... def __call__(self, inst):
... print self, inst
...
>>> class Foo(object):
... pass
...
>>> fun = MyCallable()
>>> f = Foo()
>>> f.fun = types.MethodType(fun, f, Foo)
>>> f.fun()
<__main__.MyCallable object at 0x648d0> <__main__.Foo object at
0x64810>
>>>

~ Daniel

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


Re: Technology solutions for Ruby?

2007-07-16 Thread Bruno Desthuilliers
vasudevram a écrit :
(snip)
>>To me this means Ruby, Python, or, as mentioned above, Perl.  If anyone
> 
> can tell me of a way to meet the above requirements in either Python
> or
> Perl, I'm all ears (I just prefer Ruby).

>>1. GUI - Native Look and Feel.  According to wxRuby the bindings aren't 
> mature enough for production use.  
(snip)
> wxPython has this (Native Look and Feel), I think

It does - just like wxRuby, since both are language-specific bindings to 
the C++ wxWidgets toolkit.

And FWIW, wxPython has been used on production for many years, so I 
think it qualifies as "production ready" !-)

(snip)
>>2. Databases - contemplating using ActiveRecord, but I would like to use 
> ODBC to support multiple types of DB's in a uniform way (if you know
> of
> alternatives to ODBC or ActiveRecord, please let me know).

In Python, you may want to have a look at SQLAlchemy, which offers lots 
of things from the "db abstraction layer" to the full-blown (and 
possibily somewhat ActiveRecord-like, cf the Elixir project) ORM.

(snip)
>>3. Binary - Are there any utilities for compiling Ruby into a binary 
> executable?  The issue is twofold, speed, and not handing the
> customer
> the source :)


IIRC, Ruby is actually still an interpreted language. Python is much 
like Java wrt/ this issue : it's byte-compiled (the difference being 
that this step is automagically managed by the VM).

IOW, you won't gain any speed from the existing packaging systems(but 
then, if your project is mostly a GUI/DB tunnel, the two most critical 
parts are already somewhat optimized). And the level of protection 
gained from these packaging systems is very debatable at best (which, 
FWIW, is also the case with Java).


(snip)
> I first learned Python, have been using it for some time for various
> projects, and then learned Ruby, and have done some projects with Ruby
> too.
> 
> I've been reading both the Ruby Cookbook and the Python Cookbook
> rather thoroughly in the last few weeks (and trying out and modifying
> many of the recipes), and what I've observed is that the two languages
> are roughly similar in features.

Yes.

(snip)
> For more advanced language features related to object-orientation,
> metaclasses / metaprogramming, both have some support,

s/some/great/g

Both Ruby and Python are known for this.

> but you might
> or might not be able to do in one, what you can do in the other.

I'd say that - wrt/ "advanced" programming tricks - *most* of what you 
can do with one can be done with the other - but usually in a *very* 
different way. While Ruby and Python have similar features and may look 
very similar at first sight, their respective object models are totally 
different.


Basically, it's a matter of
- which language *you* prefer
- which one has the best libs for your app

It seems that, in your case, you prefer Ruby but Python may *or not* 
have the best/more mature toolkit. So the best thing to do would be to 
first try to write a quick 'proof of concept' program in the language 
you prefer. Then, if you're still in doubt, write the same program in 
Python.

My 2 cents (and friendly salutations to the Ruby community).
-- 
http://mail.python.org/mailman/listinfo/python-list


Break up list into groups

2007-07-16 Thread [EMAIL PROTECTED]
All,

I can't seem to find an answer to this question anywhere, but I'm
still looking. My problem is I have a list of values like this:

l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
13, 0xF0, 14, 0xF1, 15]

A value with bit 0x80 set delineates the start of a new packet of
information. What I want to do is to group the packets so that 1, 2, 3
go with the 1st packet tagged 0xF0, 4 ,5, 6 go with the 2nd packet
tagged 0xF0, 7 & 8 go with the packet tagged 0xF1 and so on. The
length of the data associated with each tag can vary. I've already
written an algorithm to do this but I was wondering if some
combination of itertools functions could do the job faster?

Here's what I've done and the expected output of the algorithm:

def splitIntoGroups(data):
groups = []
local = []

for value in data:
if 0x80 & value:
if len(local) > 0:
groups.append(local)

local = []
local.append(value)
else:
local.append(value)

if len(local) > 0:
groups.append(local)

return groups

l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
13, 0xF0, 14, 0xF1, 15]

print splitIntoGroups(l)

Desired result:

[[240, 1, 2, 3], [240, 4, 5, 6], [241, 7, 8], [242, 9, 10, 11, 12,
13], [240, 14], [241, 15]]

Thanks,

Dan McLeran

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


Re: How to organize control access to source code ?

2007-07-16 Thread Erik Jones
On Jul 16, 2007, at 3:46 PM, [EMAIL PROTECTED] wrote:

> Hello,
> How can we organize development team with code source control policy,
> that limit access to some portion of code ?

The specifics largely depend on the system(s) you're working with  
but, basically (sic), you need to read up on filesystem level  
permissions.

Erik Jones

Software Developer | Emma®
[EMAIL PROTECTED]
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com


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


How to organize control access to source code ?

2007-07-16 Thread Succelus
Hello,
How can we organize development team with code source control policy,
that limit access to some portion of code ?

Sincerely,

Ahmed Boukhari

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


Re: Discover instance variables

2007-07-16 Thread JonathanB

> > class Foo():
> > self.a = "bar"
> > self.z = "test"
> > self.var = 2
>
> That's unlikely to work, though: the code is in the context of the
> class, not one of its methods, so unless you happen to be declaring a
> class inside another class's method it's unlikely that there's going to
> be a "self" around when those three lines execute.

Ah, I see. Trouble is I write most of my code on a computer that
doesn't have python (shared computer and I don't have permissions to
install). So I code it here, email it to myself, and test it at home.
I had my debugged code at home so I couldn't post a working example.
Here's working example.

class World():
def __init__(self, name, WTN, Ag, Na, Ex, In, Ni, Al, Port, Type,
Dia, Grav, Atmosphere, Hyd, Climate, Pop, Gov, CR, TL, Wealth,
Trade=None, notes=None):
self.name = name
self.WTN = WTN
self.Ag = Ag
self.Na = Na
self.Ex = Ex
self.In = In
self.Ni = Ni
self.Al = Al
self.Port = Port
self.Trade = Trade
self.Type = Type
self.Dia = Dia
self.Grav = Grav
self.Atmosphere = Atmosphere
self.Hyd = Hyd
self.Climate = Climate
self.Pop = Pop
self.Gov = Gov
self.CR = CR
self.TL = TL
self.Wealth = Wealth
self.notes = notes

The code to execute this is:

def world_info():
# code to prompt for each variable
world = World(name, WTN, Ag, Na, Ex, In, Ni, Al, Port, Type, Dia,
Grav, Atmosphere, Hyd, Climate, Pop, Gov, CR, TL, Wealth)

So given that example, is there a clean way to get this output:

Data for Earth:
Name = Earth
WTN = 5.0
Ag = 0
Na = 0
...
...
Notes = None

> [name for name in dir(x) if not callable(name) and not
> name.startswith("__")]

That does looks almost exactly like what I want I think (I'm still
learning to read code to learn what it does, but from what it looks
like this does a list comprehension that removes everything callable
and that starts with "__")

> [name for name in dir(x) if not callable(name) and not
> name.startswith("__")]
>
> might come close - I presume you don't want __doc__  and the like.
>

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


Re: sqlite3 db update extremely slow

2007-07-16 Thread Roel Schroeven
coldpizza schreef:
> I am trying to fill a sqlite3 database with records, and to this end I
> have written a class that creates the db, the table and adds rows to
> the table.
> 
> The problem is that the updating process is *extremely* slow, and
> occasionally I get the message "database locked".
> 
> I tried removing "self.con.commit()" in the add_record method, but
> then nothing is saved in the db. I don't know whether this has
> anything to do with it, but I have found no option to enable
> autocommit.

Remove self.con.commit() from add_record(), and do it once after all 
records are added.

The reason that the process is slow with a commit after every INSERT is 
that sqlite syncs the inserted data to disk before it continues.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: Can a low-level programmer learn OOP?

2007-07-16 Thread Bruno Desthuilliers
Wayne Brehaut a écrit :
> On Sat, 14 Jul 2007 19:18:05 +0530, "Rustom Mody"
> <[EMAIL PROTECTED]> wrote:
> 
> 
>>On 7/14/07, Alex Martelli <[EMAIL PROTECTED]> wrote:
>>
>>>OOP can be abused (particularly with deep or intricate inheritance
>>>structures).  But the base concept is simple and clear: you can bundle
>>>state and behavior into a stateful "black box" (of which you may make as
>>>many instances, with independent state but equal behavior, as you need).
>>>
>>
>>Many years ago (86??) Wegner wrote a paper in OOPSLA called Dimensions
>>of Object Orientation in which he called the 'base concept' of 'bundle
>>of state and behavior' as 'object based' programming and
>>'object-oriented' as object-based + inheritance.
> 
> 
> Not quite--according to him:
> 
> object-based + classes => class-based
> class-based + class inheritance => object-oriented
> 
> I.e., "object-oriented = objects + classes + inheritance".

What about prototype-based languages then ?-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Technology solutions for Ruby?

2007-07-16 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
.
.
.
>wxPython uses the native widgets of the platform it is running on in
>most (if not all) cases, so if you want the "native look & feel", than
>that is the way I would go. They have the best user's group I've seen
>so far as well.
>
>Mike
>

Now you have me curious--when you write of "the best user's group
...", do you mean http://www.python-forum.de/forum-19.html >?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can a low-level programmer learn OOP?

2007-07-16 Thread Bruno Desthuilliers
Wayne Brehaut a écrit :
> On Fri, 13 Jul 2007 20:37:04 -0400, Steve Holden <[EMAIL PROTECTED]>
> wrote:
> 
> 
>>Aahz wrote:
>>
>>>In article <[EMAIL PROTECTED]>,
>>>Chris Carlen  <[EMAIL PROTECTED]> wrote:
From what I've read of OOP, I don't get it.  
>>>
>>>For that matter, even using OOP a bit with C++ and Perl, I didn't get it
>>>until I learned Python.
>>>
>>>
The problem for me is that I've programmed extensively in C and .asm on 
PC DOS way back in 1988.  
>>>
>>>Newbie.  ;-)
>>>
>>>(I started with BASIC in 1976.)
>>>
>>
>>Newbie ;-)
>>
>>(I started with Algol 60 in 1967).
> 
> 
> Newbie ;-)
> 
> (I started with Royal McBee LGP 30 machine language (hex input) in
> 1958, and their ACT IV assembler later! Then FORTRAN IV in 1965. By
> 1967 I too was using (Burroughs) Algol-60, and 10 years later upgraded
> to (DEC-10) Simula-67.)
> 


My my my... Would you believe that my coworkers do consider me like an 
old sage because I started programming in 1990 with HyperTalk on Mac 
Classic !-)

I suddenly feel 20 again ! Woo !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


[OT] Re: Can a low-level programmer learn OOP?

2007-07-16 Thread Bruno Desthuilliers
Wayne Brehaut a écrit :
> On Mon, 16 Jul 2007 10:10:05 +0200, Bruno Desthuilliers
> <[EMAIL PROTECTED]> wrote:
> 
> 
>>Wayne Brehaut a écrit :
>>(snip)
>>
>>>after Bruno made the
>>>claim: "OO is about machines - at least as conceveid by Alan Key, who
>>>invented the term and most of the concept."
>>
>>Please reread more carefully the above. I do give credit to Smalltalk's 
>>author for the *term* "OOP", and *most* (not *all*) of the concepts (I 
>>strongly disagree with your opinion that message-passing is not a core 
>>concept of OO).
> 
> 
> One problem is that it's often not clear what lists of properties are
> his definition of OOP vs. what are the intended properties of
> Smalltalk--his intended impelmentation of OOP. Many of the lists begin
> with the basic requirements that "everything is an object" and
> "objects communicate by message passing", but the most common
> "generally agreed upon" definition abstracts just four requirements
> from these (changing)  lists--attempting to  separate implementation
> details from what is essential to the underlying framework. As I note
> below, these were:
> 
> 1.  modularity (class-based? object-based?)
> 2.  inheritance (sub-classing)
> 3.  encapsulation (information hiding)

I don't see information hiding and encapsulation as being the very same 
thing. But anyway...

> 4.  polymorphism ((sub-) class-specific response to a message, or
> processing of a method)

subclassing  - and even classes - are not necessary for polymorphism. I 
guess you have a good enough knowledge of Python and/or some 
prototype-based OOPL to know why !-)

> 
> Other details in Kay's lists are considered  implementation details,
> and important advances or alternatives to pevious methods, but not
> required for a language to _be_ OO. It is reputed, though, that in
> 2003 Kay said
> (http://c2.com/cgi/wiki?AlanKaysDefinitionOfObjectOriented)  "OOP to
> me means only messaging, local retention and protection and hiding of
> state-process, and extreme LateBinding of all things."
> 
> So I understand your accepting one of Kay's lists as being a
> definition of OOP instead of "just" a description of Smalltalk, or of
> accepting this fairly recent "definition" as being the true one

Is there any "true one" ?-)

> (as
> opposed to the previous lists of usually 6 properties). "It's hard to
> hit a moving target!"

Indeed.

> 
>>FWIW, I first mentionned Simula too (about the state-machine and 
>>simulation aspect), then sniped this mention because I thought it was 
>>getting a bit too much OT - we're not on comp.object here.
> 
> 
> Understood--sort of--but there is sufficient accurate information
> about Simula available on the web now that it's no longer necessary to
> use quotes from Kay about OOP and Smalltalk just  because they're more
> accessible, as used to be the case. What would be so OT about
> referring to Simulain one sentence instead of or in addition to
> Smalltalk?

What I mean is that I felt my answer to be already OT enough so I sniped 
  large parts of it. FWIW, I could have sniped the reference to Alan Kay 
and kept the one to Simula, but then it would have require more rewrite 
work.

> But I digress--my only real objection to your post was your opinion
> and claim that Kay "invented the term and most of the concept":

I agree that the term "most" is perhaps a bit too strong. For my 
defense, please keep in mind that I'm not a native english speaker, so I 
often have hard time expressing myself with the exact nuance I'd use in 
french.

(snip)

> 
> As has been noted before, it's often the fact that a cause becomes a
> religion:

Good Lord, save us from becoming religious !-)

Ok, I admit that I have my own understanding of OO (as anyone else, I 
guess), which is quite closer to Smalltalk's model than to any other 
OOPL (even Python). It probabaly has to do with the extremely 
generalized and systematic application of two key concepts - objects and 
messages - in such a way that it becomes a coherent whole - while most 
mainstream OOPLs feel to me more like ad-hoc collection of arbitrary 
rules and features. So yes, I'm probably guilty of being a bit too 
impassioned here, and you're right to correct me. But have mercy and 
take time to read a bit more of the offending post, I'm pretty confident 
you won't find me guilty of mis-placed "religiosity".

(snip)
> in contrast, all I've done so far is complain about
> those who don't accept the correct (i.e., my) definition or use of
> terms.

Lol ! I'm afraid this is something we're all guilty of one day or another...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: running a Delphi part from Python ?

2007-07-16 Thread Chris Mellon
On 7/16/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
> Chris Mellon wrote:
> > Delphi components are tightly tied to the Delphi runtime environment
> > and its' gui abstractions, so embedding it as is is will be a massive
> > hack (and require extensive C code) if its even possible.
> The editor I've in mind communicates only through messages, about 20 to the 
> editor and 5 back,
> so that doesn't sound too much.

If it communicates entirely through messages, then it's likely not a
Delphi component at all, and instead a native (to Windows)
implementation and the Delphi component you've used is simply a
wrapper around the messaging API. If that's the case, then you can
probably use it directly in wxPython, using ctypes. Confirm this with
your component vendor by finding out if it's usable from C using the
Windows API.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best method for inter process communications

2007-07-16 Thread JamesHoward
Thanks for the updates.  I think I will try named processes first, but
may just end up using local sockets in the end and not worry about the
overhead.

Jim Howard

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


Re: zipfile 2GB problems?

2007-07-16 Thread Steve Holden
xamdam wrote:
> On Jul 15, 5:39 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> xamdam wrote:
> Additional info: my file is from a data provider, do not know what
> they used to compress it. Previous files worked ok, this one is the
> 1st over 2GB. Winzip has no problem with it.
 It could be you are using a Python with an in-built limit of 2GB on file
 size. What happens if you open the file, seek past the 2GB point and
 then try and read data?
>>> Steve,
>>> I used is_zipfile function, which from does exactly that from a quick
>>> read - goes to the end, reads expected string. It worked fine. Tried
>>> regular Windows 2.4.4 and 2.5.1, same result.
>> Fine, if it isn't file size limitations I suspect you need to post some
>> code and a traceback so we can get better insight into exactly what the
>> problem is.
>>
> 
> It's failing in the ZipFile constructor, which ends up throwing
> 
> zipfile(2.4.3).py:291> raise BadZipfile, "Bad magic number for file
> header"
> 
> 
> 
Well, that one bald line by itself certainly doesn't give *me* any 
traction an what the problem might be. Getting information about this 
problem is like (i.e. as difficult as) pulling teeth!

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Can a low-level programmer learn OOP?

2007-07-16 Thread Steve Holden
Chris Carlen wrote:
> Hendrik van Rooyen wrote:
>>  "Chris Carlen"  wrote:
>>> Form 2:  Use Python and PySerial and TkInter or wxWidgets.
>>> Pro:  Cross-platform goal will likely be achieved fully.  Have a 
>>> programmer nearby with extensive experience who can help.
>>> Con:  Must learn new language and library.  Must possibly learn a 
>>> completely new way of thinking (OOP) not just a new language syntax. 
>>> This might be difficult.
>> This is the way to go. - Trust me on this.
>> When you describe your history, it is almost an exact parallel to mine.
>> In my case, I have been doing real low level stuff (mostly 8031 assembler)
>> since 1982 or so. And then I found python in a GSM module (Telit), and
>> I was intrigued.
>> I really appreciate your comments on OO - it parallels a lot of what I feel 
>> as there is a lot of apparent BS that does not seem to "do anything" at first
>> sight.
>> However-  for the GUI stuff, there is an easily understood relationship 
>> between
>> the objects and what you see on the screen - so its a great way of getting
>> into OO - as far as people like you and me will go with it, which is not very
>> far, as we tend to think in machine instructions...
>> And for what its worth - you can programme assembler-like python, and it 
>> also 
>> works.
>>
>> The best thing to do is just to spend a few days playing with say Tkinter.
>> I use a reference from the web written by John W Shipman at New Mexico
>> Tech - it is succinct and clear, and deserves more widespread publicity.
>>
>> Google for it - I have lost the link, although I still have the pdf file.
> [edit]
> 
> Thanks for the tip.  The next poster provides the link, which I've got 
> bookmarked now.
> 
> The more I play with Python, the more I like it.  Perhaps I will 
> understand OOP quicker than I thought.  What I've learned so far about 
> names binding to objects instead of values stored in memory cells, etc. 
> has been interesting and fascinating.
> 
> 
> 
I'm happy you are proceeding with so little trouble. Without wishing to 
confuse you, however, I should point out that this aspect of Python has 
very little to do with its object-orientation. There was a language 
called Icon, for example, 20 years ago, that used similar semantics but 
wasn't at all object-oriented.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: urllib to cache 301 redirections?

2007-07-16 Thread John Nagle
O.R.Senthil Kumaran wrote:
> Thank you for the reply, Mr. John and I apologize for a very late response
> from my end.
> 
> * John J. Lee <[EMAIL PROTECTED]> [2007-07-06 18:53:09]:
> 
> 
>>"O.R.Senthil Kumaran" <[EMAIL PROTECTED]> writes:
>>
>>
>>>Hi,
>>>There is an Open Tracker item against urllib2 library python.org/sf/735515
>>
>>>I am not completely getting what "cache - redirection" implies and what 
>>>should
>>>be done with the urllib2 module. Any pointers?
>>
>>When a 301 redirect occurs after a request for URL U, via
>>urllib2.urlopen(U), urllib2 should remember the result of that
>>redirection, viz a second URL, V.  Then, when another
>>urllib2.urlopen(U) takes place, urllib2 should send an HTTP request
>>for V, not U.  urllib2 does not currently do this.  (Obviously the
>>cache -- that is, the dictionary or whatever that stores the mapping
>>from URLs U to V -- should not be maintained by function urlopen
>>itself.  Perhaps it should live on the redirect handler.)
>>
> 
> 
> I spent a little time thinking about a solution and figured out that the
> following changes to HTTPRedirectHandler, might be helpful in implementing
> this.
> 
> Class HTTPRedirectHandler(BaseHandler):
> # ... omitted ...
> # Initialize a dictionary to hold cache.
> 
> def __init__(self):
> self.cache = {}
> 
> 
> # Handles 301 errors separately in a different function which maintains a
> # maintains cache.
> 
> def http_error_301(self, req, fp, code, msg, headers):
> 
> if req in self.cache:
> # Look for loop, if a particular url appears in both key and value
> # then there is loop and return HTTPError
> if len(set(self.cache.keys()) & set(self.cache.values())) > 0:
> raise HTTPError(req.get_full_url(), code, self.inf_msg + msg +
> headers, fp)
> return self.cache[req]
> 
> self.cache[req] = self.http_error_302(req,fp,code,msg, headers)
> return self.cache[req]
> 
> 
> John, let me know your comments on this approach.
> I have not tested this code in real scenario yet with a 301 redirect.
> If its okay, I shall test it and submit a patch for the tracker item.

That assumes you're reusing the same object to reopen another URL.

Is this thread-safe?

That's also an inefficient way to test for an empty dictionary.

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


Re: Binary blobs to jpeg

2007-07-16 Thread Grant Edwards
On 2007-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>> Have you tried to open the file in "wb" mode?
>
> The data is coming from a record set selection from the Access
> database. I guess I could write the data to a temp file and
> open that file handle with the "wb" mode. But, no, I haven't
> tried that.

I think you missed the point.

When you want to write the binary data to a file, you must open
the destination file using "wb" mode.  It's binary data, not
text data, so you have to open the output file in binary mode.

-- 
Grant Edwards   grante Yow! Is my fallout shelter
  at   termite proof?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


sqlite3 db update extremely slow

2007-07-16 Thread coldpizza
I am trying to fill a sqlite3 database with records, and to this end I
have written a class that creates the db, the table and adds rows to
the table.

The problem is that the updating process is *extremely* slow, and
occasionally I get the message "database locked".

I tried removing "self.con.commit()" in the add_record method, but
then nothing is saved in the db. I don't know whether this has
anything to do with it, but I have found no option to enable
autocommit.

This is the class that I am using:

class sqliteDB(object):
"Wrapper for SQLite methods"
def __init__(self, db_file="sqlite3.db"):
'Intialize SQLite database, sqlite_db_init("db_file_name.db")'
print 'SQLite db init: ', db_file
self.con = sqlite3.connect(db_file)
self.cur = self.con.cursor()

def create_table(self, table):
"create table (table_name)"

query ='CREATE TABLE %s (hword VARCHAR(256) PRIMARY KEY,
definition TEXT)' % table
try:
self.cur.execute(query)
self.con.commit()
except Exception, e:
print e

def add_record (self, table, headWord, definition):

try:
self.cur.execute('INSERT INTO ' + table + '(hword,
definition) VALUES(?, ?)', (headWord, definition))
self.con.commit()
except Exception,  e:
print e

And this is the actual code that I use to write to the db file:

db = sqliteDB()
db.create_table("table_name")

for k, v in myData:
  db.add_record(table, k,v)

This works extremely slow (~10KB of data per second) and takes ages to
complete even with small files. Where did I go wrong?

Would it be faster (or possible) to import a text file to sqlite using
something like the mysql's command
LOAD DATA INFILE "myfile.csv"...?

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


Re: running a Delphi part from Python ?

2007-07-16 Thread Stef Mientki
> 
> Of course You can always write one, that's succicient for Your needs,
> and make it available under GPL. ;-)

Why not BSD ?
But I've to read all the licenses of the used components first ;-)

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


Re: Best method for inter process communications

2007-07-16 Thread John Nagle
Steve Holden wrote:
> JamesHoward wrote:
> Given the radically inefficient representations that XML typically 
> requires, however, I think that worrying about localhost socket overhead 
> is unnecessary: if your application was *that* critical you wouldn't be 
> using XML in the first place.

 Agreed.  UNIX/Linux/Python interprocess communication is inefficient
compared to, say, QNX or Minix 3.  But where Python and XML are involved,
you've already lost 2-3 orders of magnitude in performance over something
like MsgSend in QNX, or even OpenRPC.  So don't worry about the socket
overhead.

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


Re: running a Delphi part from Python ?

2007-07-16 Thread Stef Mientki
Chris Mellon wrote:
> On 7/16/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
>> tool69 wrote:
>> > Stef Mientki a écrit :
>> >
>> >> AFAIK, Scintilla is a code editor.
>> >> What I need looks more like ms-word,
>> >> handling lists, tables, images, formulas.
>> >>
>> >> thanks,
>> >> Stef Mientki
>> >
>> >
>> > So you'll need the RichTextCtrl
>> >
>> > http://www.wxpython.org/docs/api/wx.richtext.RichTextCtrl-class.html
>> >
>> > See a sample in the demo under "Recent Additions".
>>
>> Well it's better,
>> - it has lists
>> - it has images, but no image editing,
>> It doesn't have
>> - drag & drop
>> - tables,
>> - formula editing,
>> - screen capture,
>> - links
>> - embedded code
>> - CSS
>> - 
>> so unfortunately it's not yet sufficient :-(
>>
> 
> This goes far beyond the requirement for a rich text editor. You're
> now talking about rich object integration, which is about 80% of a
> full featured word processor.
The features I describe, are just 1% of the (in-)capabilities of ms-word,
so what do you call ms-word ;-)

  You won't find a cross platform
> implementation that's suitable for use as a component in anything.
> 
> Delphi components are tightly tied to the Delphi runtime environment
> and its' gui abstractions, so embedding it as is is will be a massive
> hack (and require extensive C code) if its even possible.
The editor I've in mind communicates only through messages, about 20 to the 
editor and 5 back,
so that doesn't sound too much.
> 
> However, any company who writes such a full featured control is likely
> to package it as an ActiveX control so they can get the sales from the
> VB guys, and you can embed ActiveX control in wxPython applications
> (Windows only, of course).
Very good idea,
although I've never done it,
according to the decriptions,
it should be just one press on a button to create an ActiveX of the 
Editor-component.


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


Re: urllib to cache 301 redirections?

2007-07-16 Thread John J Lee
On Tue, 17 Jul 2007, O.R.Senthil Kumaran wrote:
[...]
> I spent a little time thinking about a solution and figured out that the
> following changes to HTTPRedirectHandler, might be helpful in implementing
> this.
[...]

Did you post it on the Python SF patch tracker?

If not, please do, and point us at it.  I'll comment there.


John

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


Re: Accessing Python variables in an extension module

2007-07-16 Thread Hrvoje Niksic
MD <[EMAIL PROTECTED]> writes:

> 2) Is there anyway to find the type of the object in C using something
> like a switch statement? I was looking for something like this
>switch type(object) {
>   STRING: "This is a string object";
>   break;
>   INTEGER: "This is an integer object";
>   break;
>   BOOLEAN: "This is a boolean object";
>   .
>   .
>   }

Not switch, but the closest you'll get is:

if (object->ob_type == PyString_Type) {
  ... string
}
else if (object->ob_type == PyInt_Type) {
  ... int
}
else if (object->ob_type == PyBool_Type) {
  ... bool
}

> I don't want to run all the C Py***_Check functions on the object.

Py*_Check are not expensive if the object really is of the target
type.  They are necessary to support subtyping correctly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Binary blobs to jpeg

2007-07-16 Thread jayharvard1
> Have you tried to open the file in "wb" mode?
>
> HTH,
>
> --
> Carsten Haesehttp://informixdb.sourceforge.net

The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and open that
file handle with the "wb" mode. But, no, I haven't tried that.

jeh

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


Re: Binary blobs to jpeg

2007-07-16 Thread Carsten Haese
On Mon, 2007-07-16 at 18:57 +, [EMAIL PROTECTED] wrote:
> Hello All.
> I'm trying to create jpegs out of data that is stored in a binary blob
> format in an RDBMS (MS Access). I've tried writing the jpeg directly:
> 
> while not rs.EOF:
>  op = file(imgdir + "\\" + pic,"w")
>  print >> op, rs.Fields[3].Value
>  ##where rs.Fields[3].Value is the data in the blob from Access.
> 
> When I try to write out this file, the jpeg doesn't turn out.

Have you tried to open the file in "wb" mode? 

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Bug with make altinstall ?

2007-07-16 Thread bravo . loic
I've made a local installation of Python2.5 with the following
instruction :

export BASE=/usr/local/python251

cd Python.2.5.1
./configure --prefix=${BASE}/\
LDFLAGS="-L\${BASE}/lib/"\
PPFLAGS="-I\${BASE}/include/"\

make
make test
make altinstall

It works fine on Linux except this little inconsistency :
-
% /usr/local/python251/bin/idle
zsh: ./idle: bad interpreter: /usr/local/python25/bin/python: aucun
fich ier ou répertoire de ce type
zsh: exit 127   ./idle


Indeed, the make altinstall instruction does not make the link from
python2.5 to python, but idle contains the following code :
-
%  more idle
#!/usr/local/python251/bin/python

from idlelib.PyShell import main
if __name__ == '__main__':
main()
-

Shouldn't the shebang be replaced with #!/usr/local/python251/bin/
python2.5 ?
This pb doesn't appear with pydoc and pycolor, so it  smells like a
bug to me

Bests,

--
BL

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


testing with coverage.py problem

2007-07-16 Thread Piotr Hrebieniuk
Hi there.

I've spent few hours and found nothing, so here's my question:
How can i run tests wrote by myself on a module, using coverage.py ?
Let's assume i have a module mymod.py which i want to test with tests from
file mytest.py (i.e. class inherited from unittest.TestCase). How to do
that with coverage.py? Where i should put the code that runs the tests?

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


Re: zipfile 2GB problems?

2007-07-16 Thread xamdam
On Jul 15, 5:39 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> xamdam wrote:
> >>> Additional info: my file is from a data provider, do not know what
> >>> they used to compress it. Previous files worked ok, this one is the
> >>> 1st over 2GB. Winzip has no problem with it.
> >> It could be you are using a Python with an in-built limit of 2GB on file
> >> size. What happens if you open the file, seek past the 2GB point and
> >> then try and read data?
>
> > Steve,
> > I used is_zipfile function, which from does exactly that from a quick
> > read - goes to the end, reads expected string. It worked fine. Tried
> > regular Windows 2.4.4 and 2.5.1, same result.
>
> Fine, if it isn't file size limitations I suspect you need to post some
> code and a traceback so we can get better insight into exactly what the
> problem is.
>

It's failing in the ZipFile constructor, which ends up throwing

zipfile(2.4.3).py:291> raise BadZipfile, "Bad magic number for file
header"



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


Binary blobs to jpeg

2007-07-16 Thread jayharvard1
Hello All.
I'm trying to create jpegs out of data that is stored in a binary blob
format in an RDBMS (MS Access). I've tried writing the jpeg directly:

while not rs.EOF:
 op = file(imgdir + "\\" + pic,"w")
 print >> op, rs.Fields[3].Value
 ##where rs.Fields[3].Value is the data in the blob from Access.

When I try to write out this file, the jpeg doesn't turn out.
Strangely, some of the colors partially render. You can see some
outlines and backgrounds, but the full picture doesn't show. Most
jpegs, however, show nothing (in an windows preview).

I then tried opening the image with PIL.Image, with something like
this:

cmd.CommandText = sql
rs=cmd.Execute()[0]
while not rs.EOF:
im = Image.open(StringIO.StringIO(rs.Fields[3].Value))
im.save("c:/projects/temp.jpg", 'JPEG', quality=90,progressive=1)



This is the error I get, I believe at the Image.open() call:
Traceback (most recent call last):
  File "", line 97, in run
  File "C:\Python25\Lib\bdb.py", line 366, in run
exec cmd in globals, locals
  File "C:\Projects\scripts\main.py", line 25, in 
xdb.doImageTbl(db)
  File "C:\Projects\scripts\thunder.py", line 86, in doImageTbl
im = Image.open(StringIO.StringIO(rs.Fields[3].Value))
  File "C:\Python25\lib\site-packages\PIL\Image.py", line 1916, in
open
raise IOError("cannot identify image file")
IOError: cannot identify image file


For a little further information, I was able to accomplish this task
in C#/.Net. A direct write to a file stream produced the exact jpeg
image. So I know the data is not corrupt. I would like to avoid using
the C#/.Net solution if possible.

Any ideas what I'm doing wrong? Any help would be greatly appreciated.

BTW, I'm using Python 2.5 and PIL 1.1.6 on a WinXp box.

Thanks,
jeh

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


Re: urllib to cache 301 redirections?

2007-07-16 Thread O.R.Senthil Kumaran
Thank you for the reply, Mr. John and I apologize for a very late response
from my end.

* John J. Lee <[EMAIL PROTECTED]> [2007-07-06 18:53:09]:

> "O.R.Senthil Kumaran" <[EMAIL PROTECTED]> writes:
> 
> > Hi,
> > There is an Open Tracker item against urllib2 library python.org/sf/735515
> 
> > I am not completely getting what "cache - redirection" implies and what 
> > should
> > be done with the urllib2 module. Any pointers?
> 
> When a 301 redirect occurs after a request for URL U, via
> urllib2.urlopen(U), urllib2 should remember the result of that
> redirection, viz a second URL, V.  Then, when another
> urllib2.urlopen(U) takes place, urllib2 should send an HTTP request
> for V, not U.  urllib2 does not currently do this.  (Obviously the
> cache -- that is, the dictionary or whatever that stores the mapping
> from URLs U to V -- should not be maintained by function urlopen
> itself.  Perhaps it should live on the redirect handler.)
> 

I spent a little time thinking about a solution and figured out that the
following changes to HTTPRedirectHandler, might be helpful in implementing
this.

Class HTTPRedirectHandler(BaseHandler):
# ... omitted ...
# Initialize a dictionary to hold cache.

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


# Handles 301 errors separately in a different function which maintains a
# maintains cache.

def http_error_301(self, req, fp, code, msg, headers):

if req in self.cache:
# Look for loop, if a particular url appears in both key and value
# then there is loop and return HTTPError
if len(set(self.cache.keys()) & set(self.cache.values())) > 0:
raise HTTPError(req.get_full_url(), code, self.inf_msg + msg +
headers, fp)
return self.cache[req]

self.cache[req] = self.http_error_302(req,fp,code,msg, headers)
return self.cache[req]


John, let me know your comments on this approach.
I have not tested this code in real scenario yet with a 301 redirect.
If its okay, I shall test it and submit a patch for the tracker item.

Thanks,
Senthil



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


Re: Technology solutions for Ruby?

2007-07-16 Thread kyosohma
On Jul 16, 1:46 pm, vasudevram <[EMAIL PROTECTED]> wrote:
> On Jul 16, 10:25 pm, vasudevram <[EMAIL PROTECTED]> wrote:
>
>
>
> > [ Though the OP posted his message to comp.lang.ruby, I'm cross-
> > posting it to comp.lang.python, since he mentions Python as a possible
> > alternative he's looking at, and also because I've recommended Python
> > for his stated needs. Also, interested to see what other Pythonistas
> > have to say in response to my reply.
> >  - Vasudev]
>
> > > On Jul 16, 2007, at 2:21 AM, Michael Reiland wrote:
> > > At the heart of the issue is the fact that I refuse to use Java for this
>
> > project, I prefer not to use .Net because of the portability issues,
> > and
> > I'd like to get away from C++ for obvious reasons.
>
> > > To me this means Ruby, Python, or, as mentioned above, Perl.  If anyone
>
> > can tell me of a way to meet the above requirements in either Python
> > or
> > Perl, I'm all ears (I just prefer Ruby).
>
> > Yes, I think it would be really great for the Ruby community and for
> > the growth of the language if wxRuby was more mature as a GUI toolkit.
> > (Not knocking the wxRuby developers at all, its great that they've
> > even done what they have - I know that creating other language (like
> > Ruby) bindings to a C++ lib is a non-trivial task).
>
> > My suggestion: Python + wxPython + Python DBI + (Py2Exe + InnoSetup)
> > *might* meet all your needs. (As with any decision about what software
> > technologies to use, you'll have to evaluate the suggested options to
> > see if they fit your needs.)
>
> > Note: I've used and like both Ruby and Python (saying this after using
> > many, though not all, language features and libraries of both
> > languages), and am not trying to discourage you from using Ruby for
> > your needs; its just that, based on your needs as described, it looks
> > to me as if Python meets them better than Ruby at present:
>
> > > 1. GUI - Native Look and Feel.  According to wxRuby the bindings aren't
>
> > mature enough for production use.  Does anyone have any experience
> > with
> > this and/or can you offer alternatives that provide a native look and
> > feel (I
>
> > I don't know enough about wxRuby to comment.
>
> > wxPython has this (Native Look and Feel), I think (used it some, a
> > while ago), not 100% sure, you can check on the site  - 
> > http:/www.wxpython.org
> >  - to make sure. The site does say that it is cross-platform:
>
> > "wxPython is a cross-platform toolkit. This means that the same
> > program will run on multiple platforms without modification. Currently
> > supported platforms are 32-bit Microsoft Windows, most Unix or unix-
> > like systems, and Macintosh OS X.
> > "
>
> > but that doesn't necessarily mean that it will have native look and
> > feel on all supported platforms. (The two are not the same thing.)
> > That's why you will need to check.
>
> > wxPython pros: Its fairly easy to learn, at least for simple GUI apps
> > (e.g. a few widgets / controls and a file dialog or two). I was able
> > to build these simple ones - see the code, article and screenshots
> > available here (or from links from here):
>
> >http://www.packtpub.com/article/Using_xtopdf
>
> > - in quite a short time, starting from zero knowledge of wxPython (I
> > did know some Python from before), just by looking at the sample apps,
> > and some reading of the docs.
>
> > See the quotes about wxPython:http://www.wxpython.org/quotes.php
>
> > >2. Databases - contemplating using ActiveRecord, but I would like to use
>
> > ODBC to support multiple types of DB's in a uniform way (if you know
> > of
> > alternatives to ODBC or ActiveRecord, please let me know).
>
> > I think, but again, not sure, that Python DBI + appropriate database
> > drivers, may meet this need. Basically Python DBI is similar to ODBC
> > (roughly), and to Perl DBI + DBD, as I understand. There's also ODBC
> > support in the Win32 extensions package for Python - IIRC, Google for
> > 'win32all' to get it. Its also available as a link from the Python for
> > Win32 MSI installer on python.org.
> > I've used Python ODBC some, it works and is easy to use.
> > See this for a simple example:
>
> >http://jugad.livejournal.com/2006/07/07/
>
> > (See the second post at that page, titled "Publishing ODBC database
> > content as PDF
> > ". The code shown in the post is not indented as per proper the Python
> > syntax (LiveJournal messed up the indentation), sorry about that, but
> > its trivial to correct if you know Python indenting rules). Also read
> > the Python ODBC docs and examples, of course.
>
> > >3. Binary - Are there any utilities for compiling Ruby into a binary
>
> > executable?  The issue is twofold, speed, and not handing the
> > customer
> > the source :)
>
> > For Python, there is py2exe (for Windows only). I used py2exe recently
> > and it works well enough for the simple cases that I tried. (I tried
> > building EXEs for a simple Python hello-world program, and for a
> > 

Re: Technology solutions for Ruby?

2007-07-16 Thread vasudevram
On Jul 16, 10:25 pm, vasudevram <[EMAIL PROTECTED]> wrote:
> [ Though the OP posted his message to comp.lang.ruby, I'm cross-
> posting it to comp.lang.python, since he mentions Python as a possible
> alternative he's looking at, and also because I've recommended Python
> for his stated needs. Also, interested to see what other Pythonistas
> have to say in response to my reply.
>  - Vasudev]
>
> > On Jul 16, 2007, at 2:21 AM, Michael Reiland wrote:
> > At the heart of the issue is the fact that I refuse to use Java for this
>
> project, I prefer not to use .Net because of the portability issues,
> and
> I'd like to get away from C++ for obvious reasons.
>
> > To me this means Ruby, Python, or, as mentioned above, Perl.  If anyone
>
> can tell me of a way to meet the above requirements in either Python
> or
> Perl, I'm all ears (I just prefer Ruby).
>
> Yes, I think it would be really great for the Ruby community and for
> the growth of the language if wxRuby was more mature as a GUI toolkit.
> (Not knocking the wxRuby developers at all, its great that they've
> even done what they have - I know that creating other language (like
> Ruby) bindings to a C++ lib is a non-trivial task).
>
> My suggestion: Python + wxPython + Python DBI + (Py2Exe + InnoSetup)
> *might* meet all your needs. (As with any decision about what software
> technologies to use, you'll have to evaluate the suggested options to
> see if they fit your needs.)
>
> Note: I've used and like both Ruby and Python (saying this after using
> many, though not all, language features and libraries of both
> languages), and am not trying to discourage you from using Ruby for
> your needs; its just that, based on your needs as described, it looks
> to me as if Python meets them better than Ruby at present:
>
> > 1. GUI - Native Look and Feel.  According to wxRuby the bindings aren't
>
> mature enough for production use.  Does anyone have any experience
> with
> this and/or can you offer alternatives that provide a native look and
> feel (I
>
> I don't know enough about wxRuby to comment.
>
> wxPython has this (Native Look and Feel), I think (used it some, a
> while ago), not 100% sure, you can check on the site  - http:/www.wxpython.org
>  - to make sure. The site does say that it is cross-platform:
>
> "wxPython is a cross-platform toolkit. This means that the same
> program will run on multiple platforms without modification. Currently
> supported platforms are 32-bit Microsoft Windows, most Unix or unix-
> like systems, and Macintosh OS X.
> "
>
> but that doesn't necessarily mean that it will have native look and
> feel on all supported platforms. (The two are not the same thing.)
> That's why you will need to check.
>
> wxPython pros: Its fairly easy to learn, at least for simple GUI apps
> (e.g. a few widgets / controls and a file dialog or two). I was able
> to build these simple ones - see the code, article and screenshots
> available here (or from links from here):
>
> http://www.packtpub.com/article/Using_xtopdf
>
> - in quite a short time, starting from zero knowledge of wxPython (I
> did know some Python from before), just by looking at the sample apps,
> and some reading of the docs.
>
> See the quotes about wxPython:http://www.wxpython.org/quotes.php
>
> >2. Databases - contemplating using ActiveRecord, but I would like to use
>
> ODBC to support multiple types of DB's in a uniform way (if you know
> of
> alternatives to ODBC or ActiveRecord, please let me know).
>
> I think, but again, not sure, that Python DBI + appropriate database
> drivers, may meet this need. Basically Python DBI is similar to ODBC
> (roughly), and to Perl DBI + DBD, as I understand. There's also ODBC
> support in the Win32 extensions package for Python - IIRC, Google for
> 'win32all' to get it. Its also available as a link from the Python for
> Win32 MSI installer on python.org.
> I've used Python ODBC some, it works and is easy to use.
> See this for a simple example:
>
> http://jugad.livejournal.com/2006/07/07/
>
> (See the second post at that page, titled "Publishing ODBC database
> content as PDF
> ". The code shown in the post is not indented as per proper the Python
> syntax (LiveJournal messed up the indentation), sorry about that, but
> its trivial to correct if you know Python indenting rules). Also read
> the Python ODBC docs and examples, of course.
>
> >3. Binary - Are there any utilities for compiling Ruby into a binary
>
> executable?  The issue is twofold, speed, and not handing the
> customer
> the source :)
>
> For Python, there is py2exe (for Windows only). I used py2exe recently
> and it works well enough for the simple cases that I tried. (I tried
> building EXEs for a simple Python hello-world program, and for a
> simple wxPython GUI app based on my xtopdf toolkit. Both worked ok.)
> For cross-platform (Windows and Linux, IIRC), there is PyInstaller
> (Google for it), haven't tried it out yet, just downloaded it
> recently.
>
> I don't think y

  1   2   >