Can't uninstall wxPython

2005-11-11 Thread Justin

I have two versions of wxPython installed on my Mac (OS X Tiger).  One
is version 2.6.1.0 and the other is version 2.6.0.0.  I want to keep
the newer version, but I can't seem to uninstall either one using the
uninstall_wxPython.py script.

When I run that script, I get this error message:
  $ sudo: uninstall_wxPython.py: command not found

Is there any way I could delete one, or both, of these installations
manually?  For some reason, whenever I try to run a wxPython script, it
uses the older version of wxPython and it doesn't always run correctly.

Thanks in advance.


Justin

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


Re: LARGE numbers

2005-11-11 Thread Mike Meyer
"Tuvas" <[EMAIL PROTECTED]> writes:

> I've been thinking about writing a program to generate the world's
> largest prime numbers, just for the fun of it. This would require being
> able to hold an 800 digit number into memory (25 megabits, or a
> little over 3 megs of memory for just one variable...) I would also
> need several smaller variables. This came about as I optimised a prime
> number generator more and more, until I came with the idea to try to
> find the largest ever, using python. Any ideas? I'll probably try to
> run this on a mainframe eventually, although they might not like it
> very much... I'll run it on my home computer to first test it. Anyways,
> let me know if there's a way to make python support numbers so high.

Python already supports numbers that large:

>>> math.log(10 ** 800)
18420680.743952367
>>> 

However, you probably want to look into something like gmpy, as you'll
get better performance out of it.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Which blog do you use?

2005-11-11 Thread could ildg
I want to to get a free blog sapce these days,
which has category for my posts.
What blog do you use?
I'll apprecaite your recommendation.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Good python reference?

2005-11-11 Thread Fredrik Lundh
"derek" <[EMAIL PROTECTED]> wrote:

> Hello! I'm new to the group and am looking for a decent reference for
> information about the history / evolution of the Python language and
> its features.  Typing, scoping, etc...  I'd appreciate any good links.

$ tar xvfz Python-2.4.2.tgz
$ cd Python-2.4.2
$ more Misc/HISTORY





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


Re: modify dictionary while iterating

2005-11-11 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> hi
> I wish to pop/del some items out of dictionary while iterating over it.
> a = { 'a':1, 'b':2 }
> for k, v in a.iteritems():
> if v==2:
> del a[k]
> 
> the output say RuntimeError: dictionary changed size during iteration
> how can i suppress this message in an actual script and still get the
> final value of the dict?
> is it something like try/except/else statment?
> try:
>for v,k in a.iteritems():
>  if v==something:
>  del a[k]
> except RuntimeError:
>< don't know what to do here>
> else:
>< should i include this part ? >
> 
> what other ways can i do this ? thanks for any help.

If you expect to delete only a few items:

>>> a = dict(a=1, b=2, c=3, d=2)
>>> delenda = [k for k, v in a.iteritems() if v == 2]
>>> for k in delenda:
... del a[k]
...
>>> a
{'a': 1, 'c': 3}

If you expect to delete most items:

>>> a = dict(a=1, b=2, c=3, d=2)
>>> a = dict((k, v) for k, v in a.iteritems() if v != 2)
>>> a
{'a': 1, 'c': 3}

or (if rebinding a is not an option)

>>> a = dict(a=1, b=2, c=3, d=2)
>>> for k, v in a.items():
... if v == 2:
... del a[k]
...
>>> a
{'a': 1, 'c': 3}

Peter

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


Re: modify dictionary while iterating

2005-11-11 Thread Ben Finney
[EMAIL PROTECTED] wrote:
> I wish to pop/del some items out of dictionary while iterating over
> it.

Iterate over a copy.

a_orig = { 'a': 1, 'b': 2 }
a = dict(a_orig)
for k, v in a_orig.iteritems():
if v == 2:
del a[k]

-- 
 \  "I know the guy who writes all those bumper stickers. He hates |
  `\  New York."  -- Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I bind multiple Pmw.Balloon tooltip with Buttons to the same widget?

2005-11-11 Thread Hako
hi,

I find a code in FAQTs about how to bind a tooltip with a button.
FAQTs link
http://www.faqts.com/knowledge_base/view.phtml/aid/20565/fid/264

but not enough informatin for how to make multiple tooltip.

Someone can help me and show  a little example how it's done.


thanks in advance.

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


Re: Diff. between Class types and classic classes

2005-11-11 Thread venk
Dear Colin,
Forgive me for this late reply. Your explanation was of great help to
me. 
Thank you very much. It was crystal clear.

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


how to start a process and get it's pid?

2005-11-11 Thread Yves Glodt
Hello,

another question rose for me today...

Is there a way to start an external process, in it's own context (not as 
the exec-() functions do), and get it's pid...?

e.g.:

pid = wonderfulstartprocfunction('/usr/bin/wine bla.exe')
#... later

if (...):
os.kill(pid,9)


best regards,
Yves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to start a process and get it's pid?

2005-11-11 Thread Gerhard Häring
Yves Glodt wrote:
> Hello,
> 
> another question rose for me today...
> 
> Is there a way to start an external process, in it's own context (not as 
> the exec-() functions do), and get it's pid...? [...]

Check out the subprocess module if you're using Python 2.4.

Otherwise, you can always use os.spawn*, for example:

 >>> os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
1944

HTH,

-- Gerhard

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


Re: LARGE numbers

2005-11-11 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote:

> An early alpha-quality release is available at
> http://home.comcast.net/~casevh/


Given the module named "Decimal" in Python 2.4, I'd suggest you to rename
your library.
-- 
Giovanni Bajo


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


RE: Looking Python script to compare two files

2005-11-11 Thread Tim Golden
[david]
> So if I want to use these tools: antiword,pdf2text, 
> can I pack these tools and python script into a 
> windows EXE file? I know there is open source tool 
> which can pack python script and libs and generate 
> the windows EXE file.

I'm not especially qualified to answer this, but I
think the answer's Yes. I think that you can just
tell py2exe that the executables and DLLs of the
other products are data files for the Python one.
Best look at the py2exe site and mailing list for
further info. An alternative is just to use an
installer to package the whole thing in the usual
Windows way.

> Yes, this approach can't handle the pictures in 
> the PDF/WORD file. There is a way to play around 
> it? maybe it's very hard.

I'm not even sure how I'd go about it conceptually.
How *do* you compare two pictures? Do you really
want to do this?

BTW, don't forget that if you're comparing Word with
Word, you can use its inbuilt comparison ability,
which just needs COM automation. (Don't know how
that takes care of picture either, but if Word's
own Compare can't, no-one else has got a chance).

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


output buffering

2005-11-11 Thread JD

Hello,

When reading a large datafile, I want to print a '.' to show the
progress. This fails, I get the series of '.'s after the data has been
read. Is there a trick to fix this?

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


Re: output buffering

2005-11-11 Thread Fredrik Lundh
"JD" <[EMAIL PROTECTED]> wrote:

> When reading a large datafile, I want to print a '.' to show the
> progress. This fails, I get the series of '.'s after the data has been
> read. Is there a trick to fix this?

assuming that you're printing to stdout,

sys.stdout.flush()

should do the trick.

 



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


Re: derived / base class name conflicts

2005-11-11 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
(snip)
> So putting two underscores in front of an instance variable (or any
> identifier used inside the scope of a class statement) invokes a name
> mangling mechanism 

(snip)

> Is it commonplace to use underscores

I assume you mean double underscore...

> when defining derived class
> instance variables,
> or is this considered against the grain of python?

I don't know if it's 'commonplace', but that's something I only do when
I absolutely want to protect a given attribute of a base class from
being accidentally overriden by a derived class. Else I use the usual
convention ('_name' => implementation, 'name' => API), and assume users
 of my code will read the documentation (or the source FWIW) before
subclassing. Note that since 'users of my code' are mostly my coworkers
and I, this is a quite sensible assumption !-)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Command-line tool able to take multiple commands at one time?

2005-11-11 Thread bruno at modulix
Peter A. Schott wrote:
> Per subject - I realize I can copy/paste a line at a time into an interactive
> session when I'm trying to debug, but was wondering if there is any tool out
> there that allows me to copy sections of working Python scripts to paste into 
> my
> interactive console and let those run so I don't have to copy line-by-line.

There's much better than that : emacs + python-mode let you evaluate
either the whole script, a single class or def statement, or an
arbitrary region in an interactive Python interpreter running as an
emacs sub-process. Of course, this interpreter don't die after, so you
can inspect/play with/do whatever with the results of this evaluation.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Needed class whose instances are many test cases

2005-11-11 Thread Sumit
I have scinario like I have to Create resource(in __init__()) Before
Running a set of testcases and then In Testcases resources are going to
used and then It will cleared off after Running the testcases  by
destructor __del__()
import unittest
import time

class app_adminfunc(unittest.TestCase):

def __init__(self, method = 'runTests'):
unittest.TestCase.__init__(self, method)
#Resource Creation 

def __del__(self):
#--Resource Deletion -

   def test01-
   def test02-
...


But in this above code Problem is that __init__() called at each time
when the Testcase is run ,But i want Single time run of the Init Prior
to run of each tests inside the class .
Can Anybody help me on this ?

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


Re: Newb ??

2005-11-11 Thread Norman Silverstone

> did you test the script?  here's a simulator:

< snip>

Fredrik, thank you very much indeed for taking the trouble to show me the
way. I am sorry that I made the comment I did, that will teach me to read
more carefully. It is said that there is no fool like an old fool and, as
I am approaching 78 years old, I think I qualify. It is also said that you
are never too old to learn so I am trying.

Now, I put the script you gave into an editor and ran it , (I use Ubuntu
Linux by the way). It certainly showed how the computer arrived at the
number guessed but guessed the number itself and gave me no chance to say
whether high or low. I noticed also that the numbers were all greater than
50 and the loop ran until the number guessed was 100, then it stopped.
Perhaps you can point out to me how I should go about debugging.

Incidentally, I am only just starting to learn about functions and have
not come across the module 're'. Also why is it (lo+hi)//2 and not
(lo+hi)/2.

Thanks again for your help.

Norman




> # end
> 
>> Comments please.
> 
> if this had been a java "let's pretend you're the java runtime"
> certification question, you would have failed.
> 
> 

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


Re: MoinMoin - Can't create new pages

2005-11-11 Thread Kolossi
In case anyone else finds this thread, the solution is that for Moin >=
1.3.5, the 404 handling in IIS has to be changed for the Wiki Virtual
Directory.

See my blog at http://www.bloglines.com/blog/Kolossi?id=13 for details.

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


Re: XML GUI

2005-11-11 Thread Jarek Zgoda
py napisał(a):

> Looking for information on creating a GUI using a configuration file
> (like an XML file or something).  Also, how do you map actions (button
> clicks, menu selections, etc) to the XML?

Depending on GUI toolkit, you will have a range of choices: Glade for
GTK, XRC for wxPython, Qt dialog editor also produces XML files with UI
description. Each of these toolkits has its own way to process GUI events.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: output buffering

2005-11-11 Thread JD
On 2005-11-11, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> "JD" <[EMAIL PROTECTED]> wrote:
>
>> When reading a large datafile, I want to print a '.' to show the
>> progress. This fails, I get the series of '.'s after the data has been
>> read. Is there a trick to fix this?
>
> assuming that you're printing to stdout,
>
> sys.stdout.flush()
>
> should do the trick.

It does,

Thanks!

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


Re: SuSe 10.0 missing Idle

2005-11-11 Thread Michael Ströder
Joseph Garvin wrote:
> SuSE probably has a seperate package, something like python-tk, that
> will install IDLE.

# rpm -qf `which idle`
python-idle-2.4.1-3

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good python reference?

2005-11-11 Thread Hans Georg Krauthaeuser
derek schrieb:
> Hello! I'm new to the group and am looking for a decent reference for
> information about the history / evolution of the Python language and
> its features.  Typing, scoping, etc...  I'd appreciate any good links.
> Thanks!
> 
> - Derek
> 
Looking at the title of your mail I would answer

http://rgruet.free.fr/PQR24/PQR2.4.html

But history? Sorry

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


Re: Needed class whose instances are many test cases

2005-11-11 Thread Chris Smith
> "Sumit" == Sumit  <[EMAIL PROTECTED]> writes:

Sumit> I have scinario like I have to Create resource(in
Sumit> __init__()) Before Running a set of testcases and then In
Sumit> Testcases resources are going to used and then It will
Sumit> cleared off after Running the testcases by destructor
Sumit> __del__() import unittest import time

Sumit> class app_adminfunc(unittest.TestCase):

Sumit> def __init__(self, method = 'runTests'):
Sumit> unittest.TestCase.__init__(self, method)
Sumit> #Resource Creation 

Sumit> def __del__(self): #--Resource
Sumit> Deletion -

Sumit>def test01- def test02- ...  

Sumit> But in this above code Problem is that __init__() called at
Sumit> each time when the Testcase is run ,But i want Single time
Sumit> run of the Init Prior to run of each tests inside the class
Sumit> .  Can Anybody help me on this ?

The unittest module runs a setUp and tearDown before each test case.
If that is too high-frequency, why not just do something like

class app_adminfunc(unittest.TestCase):
def setUp(self): pass
def tearDown(self): pass
def allYourTestCase(self):
def test01(): pass
def test02(): pass

since python is so mellow about nesting functions and classes and
such.

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


Re: Looking Python script to compare two files

2005-11-11 Thread david
Thanks Tim!

I will have a try,maybe this weekend and let you know the result.

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


Re: Needed class whose instances are many test cases

2005-11-11 Thread Ben Finney
Sumit <[EMAIL PROTECTED]> wrote:
> I have scinario like I have to Create resource(in __init__()) Before
> Running a set of testcases and then In Testcases resources are going
> to used and then It will cleared off after Running the testcases  by
> destructor __del__()

This is a poor design; your tests will each be starting in a different
state, and will likely not run the same way if run in a different
order, making them fragile.

Test cases should each run individually, from a known state, and not
depend on any other tests. You can define a fixture for several tests
in the unittest.TestCase methods setUp() and tearDown(), to establish
and clear up respectively for each test.

-- 
 \  "When I wake up in the morning, I just can't get started until |
  `\ I've had that first, piping hot pot of coffee. Oh, I've tried |
_o__) other enemas..."  -- Emo Philips |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


creating single-instance executables using python/py2exe

2005-11-11 Thread Satchidanand Haridas
Hi,

I have created an application using python/wxPython and py2exe. I have 
associated a certain file extension with this application so that when I 
double-click the file, my application is launched. The application runs 
fine except that a new instance is created when I double click on two 
different files. Is there a way in which I can make sure only one 
instance is created? Any additional files are opened in the same running 
instance? Would appreciate any comments/feedback.

thanks,
Satchit

-- 

Satchidanand Haridas (sharidas at zeomega dot com)

ZeOmega (www.zeomega.com)
Open  Minds' Open Solutions

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


Re: how to start a process and get it's pid?

2005-11-11 Thread Fredrik Lundh
Daniel Crespo wrote:

>> >>> os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
>> 1944
>
> I don't get the correct PID.
>
> When I do os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
> I get 168 (for example), while in the tasklist appears notepad.exe with
> the 2476 PID.
>
> Why?

not sure, but the return value looks like a PID, so maybe you're seeing the
PID for the cmd.exe instance used to run the program.  or something.

try this instead:

>>> import subprocess
>>> p = subprocess.Popen("c:/windows/notepad.exe")
>>> p.pid
1948

 



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


Re: LARGE numbers

2005-11-11 Thread casevh
Already done for next version. Tentatively, there will be a package
called "ar" (Arbitrary Radix) and the module will be called BigInt. I'm
also working on an arbitrary radix BigFloat module.

Case

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


Import statements for timeit module

2005-11-11 Thread ChaosKCW
Hi

I was wondering if someone could help with the import statements needed
to use the timeit module in the following code. I need to access the
"cur" object.

Thanks,

import cx_Oracle
import timeit

def VerifyTagIntegrity(con, TableOwner):
cur = con.cursor()
sql = 'select (select count(*) from %s.f4111) as F4111_COUNT,
(select count(*) from %s.f4111_tag) as TAG_COUNT from dual;' %
(TableOwner, TableOwner)
print "  SQL: %s" % (sql)
timer = timeit.Timer('cur.execute(sql)', 'from __main__ import
cur')
print timer.timeit()

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


Re: how to start a process and get it's pid?

2005-11-11 Thread Daniel Crespo
Hi

> >>> os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
> 1944

I don't get the correct PID.

When I do os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
I get 168 (for example), while in the tasklist appears notepad.exe with
the 2476 PID.

Why?

Thanks

Daniel

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


Re: testing C code with python

2005-11-11 Thread Ruben Charles
On 11/10/05, Peter Hansen <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > A simple question - Is it common/good practice to test C code using
> > Python? For example one could wrap individual C functions, and test
> > each of them using python, maybe not for low-level things but at least
> > for algorithmic correctness. Anyone effectively doing this as common
> > practice?

Take a look at swig.org

There are some examples for testing C code y python and/or extend
python with C functions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating single-instance executables using python/py2exe

2005-11-11 Thread Sybren Stuvel
Satchidanand Haridas enlightened us with:
> a new instance is created when I double click on two different
> files. Is there a way in which I can make sure only one instance is
> created?

You could open a listening socket to listen for "open file" commands.
If opening that socket fails (address already in use), connect a
client socket to it, send the appropriate "open file" command, and
exit.

That way, you even have a cross-platform solution.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Tcl/Tk programmer learns Python--any advice?

2005-11-11 Thread Roy Smith
"Robert Hicks" <[EMAIL PROTECTED]> wrote:
> Why does there need to be OO "in the core"? That is one thing I have
> never understood. If you want OO, get a package that fits your style of
> OO and "package require" you are off and running. That probably isn't
> what you would be looking at Tcl for anyway.

The problem there is that you end up with N different implementations.  
They each have roughly similar capabilities, but are different enough in 
the details that somebody who knows one will have trouble maintaining code 
using another.  Each one probably has some features which make it better 
than the others in some ways, and some ugly warts too.  None is superior 
enough in all respects to become dominant.

It's just like C++ went through with strings and containers before STL came 
along.  Everybody rolled their own, or bought one of the several 
commercially available libraries.  That meant you could be an expert at C++ 
and still have a steep learning curve when coming into a new project.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Needed class whose instances are many test cases

2005-11-11 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 Ben Finney <[EMAIL PROTECTED]> wrote:

> This is a poor design; your tests will each be starting in a different
> state, and will likely not run the same way if run in a different
> order, making them fragile.
> 
> Test cases should each run individually, from a known state, and not
> depend on any other tests. You can define a fixture for several tests
> in the unittest.TestCase methods setUp() and tearDown(), to establish
> and clear up respectively for each test.

In general, I certainly agree with the above.  The problem is that 
sometimes setup is so expensive, it becomes impractical to do a full 
setup/teardown cycle for each test.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: modify dictionary while iterating

2005-11-11 Thread Fuzzyman
Iterate over the keys ( for entry in adict.keys(): )

All the best,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


something wrong in wx

2005-11-11 Thread Robert
something wrong in wx

I wrote program training na Artificial Neural Network. It work well in
console mode, but when I try to add GUI there is an error:
FANN Error 10: Error reading info from train data file "zapis.txt", line: 2

There is a code:
# this work 
#!/usr/bin/python
import fann

connection_rate = 1
learning_rate = 0.7
num_layers = 3
num_input = 319
num_neurons_hidden = 50
num_output = 5


ann = fann.fann_create(connection_rate, learning_rate, num_layers,num_input,
num_neurons_hidden, num_output)

desired_error = 0.1
max_iterations = 50
iterations_between_reports = 1000

fann.fann_train_on_file(ann, "zapis.txt", max_iterations,
iterations_between_reports, desired_error)
print fann.fann_get_MSE(ann)
fann.fann_save(ann, "po_nauce.net")

fann.fann_destroy(ann)

# with GUI (not work) #
#!/usr/bin/python

import wx
import fann

class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Trenowanie sieci", pos=(50, 
50))
panel = wx.Panel(self)

# First create the controls
topLbl = wx.StaticText(panel, -1, "Trenowanie sieci", 
size=wx.Size(400, 
21), style=wx.ALIGN_CENTRE)
topLbl.Center(wx.HORIZONTAL)
topLbl.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))


polaczenia_Lbl = wx.StaticText(panel, -1, u'Stopie\u0144
po\u0142\u0105cze\u0144 [%]:')
self.polaczenia = wx.SpinCtrl(panel, -1, "")
self.polaczenia.SetRange(0,100)
self.polaczenia.SetValue(100)

ilosc_warstw_Lbl = wx.StaticText(panel, -1, u'Ilo\u015b\u0107 
warstw:')
self.ilosc_warstw = wx.SpinCtrl(panel, -1, "")
self.ilosc_warstw.SetRange(0,5)
self.ilosc_warstw.SetValue(3)

cstLbl1 = wx.StaticText(panel, -1, '\n'
u'Poszczeg\xf3lne warstwy sieci: ')
cstLbl = wx.StaticText(panel, -1, '\n'
u'wej\u015biowa ukryta wyj\u015biowa')

self.ilosc_wejsc = wx.SpinCtrl(panel, -1, "")
self.ilosc_wejsc.SetRange(0,2000)
self.ilosc_wejsc.SetValue(319)
self.ukryte = wx.SpinCtrl(panel, -1, "")
self.ukryte.SetRange(0,500)
self.ukryte.SetValue(50)
self.ilosc_wyjsc = wx.SpinCtrl(panel, -1, "")
self.ilosc_wyjsc.SetRange(0,100)
self.ilosc_wyjsc.SetValue(5)

uczenie_Lbl = wx.StaticText(panel, -1, 
u'Cz\u0119sto\u015b\u0107 uczenia
[%]:')
self.uczenie = wx.SpinCtrl(panel, -1, "")
self.uczenie.SetRange(0,100)
self.uczenie.SetValue(70)

oczekiwany_blad_Lbl = wx.StaticText(panel, -1, u'Oczekiwany
b\u0142\u0105d: [1/x]')
self.oczekiwany_blad = wx.SpinCtrl(panel, -1, "")
self.oczekiwany_blad.SetRange(0,1)
self.oczekiwany_blad.SetValue(10)

powtorzen_Lbl = wx.StaticText(panel, -1, u'Maxymalna liczba 
powt\xf3rze\u0144:')
self.powtorzen = wx.SpinCtrl(panel, -1, "")
self.powtorzen.SetRange(0,10)
self.powtorzen.SetValue(5)

raporty_Lbl = wx.StaticText(panel, -1, u'raport co:')
self.raporty = wx.SpinCtrl(panel, -1, "")
self.raporty.SetRange(0,1)
self.raporty.SetValue(1000)


trenujBtn = wx.Button(panel, -1, "Trenuj Siec")
self.Bind(wx.EVT_BUTTON, self.on_trenujBtn, trenujBtn)
cancelBtn = wx.Button(panel, -1, "Cancel")


# Now do the layout.

# mainSizer is the top-level one that manages everything
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(topLbl, 0, wx.ALL, 5)
ainSizer.Add(wx.StaticLine(panel), 0, 
wx.EXPAND|wx.TOP|wx.BOTTOM, 5)

# addrSizer is a grid that holds all of the address info
addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
addrSizer.AddGrowableCol(1)
addrSizer.Add(polaczenia_Lbl, 0, 
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(self.polaczenia, 0, wx.EXPAND)
addrSizer.Add(ilosc_warstw_Lbl, 0, wx.ALIGN_RIGHT|  
wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(self.ilosc_warstw, 0, wx.EXPAND)
#addrSizer.Add((10,10)) # some empty space
#addrSizer.Add(addr2, 0, wx.EXPAND)

addrSizer.Add(cstLbl1, 0, 
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(cstLbl, 0, 
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add((10,10)) # some empty space

# the city, state, zip fields are in a sub-sizer
cstSizer = wx

Re: Python obfuscation

2005-11-11 Thread Magnus Lycka
The Eternal Squire wrote:
> Two things:
...
> 2) Only sell to an honest customer willing to be locked into
> nondisclosure agreements.  This goes back to the maxim of good
> salesmanship:  Know Your Customer.

If you have this, you don't need the obfuscation.

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


Re: Python obfuscation

2005-11-11 Thread Magnus Lycka
petantik wrote:
> Alex Martelli wrote:
>>I think that's feeble protection.  If you have valuable code, and
>>distribute it, people WILL crack it -- just check the warez sites for
>>experimental proof... EVERYTHING that people are really interested in
>>DOES get cracked, no matter what tricky machine-code the "protections"
>>are coded in.
>>
>>There's ONE way to have uncrackable code -- don't distribute it, but
>>rather put it up on the net on a well-secured machine under your
>>control, available as (say) a webservice (subscription-only, pay per
>>use, or whatever business model you want). 
...
> I think that is not workable because it is easy to say the the internet
> is available everywhere.
> 
> It is not available in developing countries... 

Erh, the internet is certainly spreading to most of the
world, and there is an abundance of cracked and pirated
software in the poorer countries in the world, so the
obfuscation part has certainly proven not to work there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: modify dictionary while iterating

2005-11-11 Thread skip
>> I wish to pop/del some items out of dictionary while iterating over
>> it.

Ben> Iterate over a copy.

Ben> a_orig = { 'a': 1, 'b': 2 }
Ben> a = dict(a_orig)
Ben> for k, v in a_orig.iteritems():
Ben> if v == 2:
Ben> del a[k]

Or iterate over just a copy of the keys:

for k in a_orig.keys():
if a_orig[k] == 2:
del a_orig[k]

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


Re: Job - PYTHON Engineers, BitTorrent, Inc., San Francisco, CA

2005-11-11 Thread Jeffrey Schwab
camdenjobs wrote:
> PYTHON Engineers, BitTorrent, Inc., San Francisco, CA
> 
> Interested candidates should forward their resumes to 

...

> Please understand that due to the large volume of responses, I will 
> not be able to acknowledge each of you individually.


Now, that's confidence!

May such optimism always be fulfilled. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: output buffering

2005-11-11 Thread skip

jd> When reading a large datafile, I want to print a '.' to show the
jd> progress. This fails, I get the series of '.'s after the data has
jd> been read. Is there a trick to fix this?

As Fredrik indicated, you need to flush the output buffer.  You might also
want to check out the progress module available from my Python Bits page:

http://orca.mojam.com/~skip/python/

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


Re: Python obfuscation

2005-11-11 Thread Ben Sizer
Mike Meyer wrote:
> Yu-Xi Lim <[EMAIL PROTECTED]> writes:
> > Ben's analogy of the house is not a perfect example, but it's still a
> > fair one. You know that if some one really wants to break into your
> > house, he will get in, regardless of your sophisticated laser trip
> > wire system, ex-SAS guards, and genetically-engineered guard dogs. But
> > as long as the cost of protection is less than the cost of the item
> > you're protecting (multiplied by the relevant probabilities, factoring
> > recurring costs, etc), it's worthwhile to spend money on
> > protection. If that fails, then you will of course fall back on the
> > law, but you still try to prevent it from happening in the first place.
>
> Sounds like you just said that manufacturers should improve their
> protection until they aren't making any profit on the product. That's
> silly. The goal isn't to maximize protection, it's to maximize
> profit. That means it only makes sense to spend money on better
> protection if the cost of the protection is less than the expected
> profit from adding it.

I agree with what you're saying, but it seems like you're arguing
against what was said rather than what was intended. Without wishing to
put words into anybody's mouths, I'm pretty sure what Yu-Xi Lim meant
was just that even imperfect protection is worthwhile if you estimate
that it will benefit you more than it will cost you. This is in
contrast to the opinion that any protection is useless because someone
will break it if they want to.

> A recent, heavily
> publicized case where Sony added copy protection to a product cost
> them sales, and from what I've heard, even legal fees.

I think that's a poor example - the cost hasn't come from the mere act
of adding protection, but the method in which that protection operates.
I don't think anybody here - certainly not me - is talking about
infecting a user's system to protect our property, or taking any other
intrusive steps. I'd just like to make it non-trivial to make or use
additional copies.

-- 
Ben Sizer.

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


Re: What do you use as symbols for Python ?

2005-11-11 Thread Sion Arrowsmith
Gary Herron  <[EMAIL PROTECTED]> wrote:
>Another similar approach that keeps those values together in a single 
>namespace is this (my favorite):
>
>  class State:
>  OPENED, CLOSED, ERROR = range(3)
>
>Then you can refer to the values as
>State.OPENED
>State.CLOSED
>State.ERROR
>
>The extra clarity (and slight wordiness) of the dotted notation seems, 
>somehow, quite Pythonic to me.

I have here an implementation (written by a colleague) of a whole pile
of such -- in this particular case it's helpful to do it in this style
rather than the class OPENED: pass because the values are coming from/
going to a database. And it goes a little further, with

class State:
Enum = range(3)
OPENED, CLOSED, ERROR = Enum
Names = { OPENED: "OPENED", CLOSED: "CLOSED", ERROR: "ERROR" }

so you can used State.Names[state] to provide something user-readable,
and state in State.Enum to check data consistency. (OK, that probably
doesn't make much sense with this particular State, but it does when
your getting value-as-number from an external source.)

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

Re: Python obfuscation

2005-11-11 Thread Ben Sizer
Mike Meyer wrote:
> There are ways to distribute
> Python modules so that the user can't just open them in a text
> editor. There are also ways to get cryptographic security for
> distributed modules.

I know distributing as bytecode helps, but I was under the impression
that the disassembers worked pretty well. With the dynamic nature of
the language I expect that all the variable names are largely left
intact. You win some, you lose some, I guess.

As for cryptographic security, could you provide a link or reference
for this? I am quite interested for obvious reasons. I'd be concerned
that there's a weak link in there at the decoding stage, however.

I have considered distributing my program as open source but with
encrypted data. Unfortunately anyone can just read the source to
determine the decryption method and password. Maybe I could put that
into an extension module, but that just moves the weak link along the
chain.

> Yes, if you use the same methods you use in C++,
> it's "much harder". But by the same token, if you tried to use the
> methods you'd use in a Python program in C++, you'd find that the C++
> version was "much harder".

Well, I'm not sure what you mean here. A compiled C++ program is much
harder to extract information from than a compiled Python program.
That's without applying any special 'methods' on top of the normal
distribution process.

> Of course, as Alex pointed out, all of these are just keeping honest
> people honest. The crooks have all the advantages in this game, so you
> really can't expect to win.

No, certainly not. But if you can mitigate your losses easily enough -
without infringing upon anyone else's rights, I must add - then why not
do so.

-- 
Ben Sizer.

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


Re: modify dictionary while iterating

2005-11-11 Thread François Pinard
[EMAIL PROTECTED]

>I wish to pop/del some items out of dictionary while iterating over it.

>a = { 'a':1, 'b':2 }
>for k, v in a.iteritems():
>if v==2:
>del a[k]

A simple change would be using "items()" instead of "iteritems()".

Or else, you may prefer to loop over keys, and retrieve values, either:

for k in a.keys():
if a[k] == 2:
del a[k]

or:

for k in set(a):
if a[k] == 2:
del a[k]

But in no way, you may directly iterate over the original dictionary 
while altering its keys, this is explicitly forbidden in Python.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help make it faster please

2005-11-11 Thread Sion Arrowsmith
 <[EMAIL PROTECTED]> wrote:
>Oh sorry indentation was messed here...the
>wordlist = countDict.keys()
>wordlist.sort()
>should be outside the word loop now
>def create_words(lines):
>cnt = 0
>spl_set = '[",;<>{}_&?!():-[\.=+*\t\n\r]+'
>for content in lines:
>words=content.split()
>countDict={}
>wordlist = []
>for w in words:
>w=string.lower(w)
>if w[-1] in spl_set: w = w[:-1]
>if w != '':
>if countDict.has_key(w):
>countDict[w]=countDict[w]+1
>else:
>countDict[w]=1
>wordlist = countDict.keys()
>wordlist.sort()
>cnt += 1
>if countDict != {}:
>for word in wordlist: print (word+' '+
>str(countDict[word])+'\n')
>
>ok now this is the correct question I am asking...

(a) You might be better off doing:
words = words.lower()
for w in words:
...
instead of calling lower() on each separate word (and note that most
functions from string are deprecated in favour of string methods).

(b) spl_set isn't doing what you might think it is -- it looks like
you've written it as a regexp but your using it as a character set.
What you might want is:
spl_set = '",;<>{}_&?!():-[\.=+*\t\n\r'
and
while w[-1] in spl_set: w = w[:-1]
That loop can be written:
w = w.rstrip(spl_set)
(which by my timings is faster if you have multiple characters from
spl_set at the end of your word, but slower if you have 0 or 1).

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

Re: Abstract Base Classes

2005-11-11 Thread Colin J. Williams
Ben Finney wrote:
> Howdy all,
> 
> Okay, so Guido doesn't like Abstract Base Classes[0], and interfaces
> are the way of the future[1]. But they're not here now, and I
> understand ABCs better.
This is a very interesting discussion - not all of it understandable to me.

Are interfaces really in our future?

I found the contributions of "steffen" particularly appealing. 
Interfaces seem to add another level of complexity without significant 
benefit.

Colin W.
> 
> I want my modules to (sometimes) define an abstract base exception
> class, that all other exceptions in that module inherit from.
> 
> class FooException(Exception):
> """ Base class for all FooModule exceptions """
> 
> class FooBadFilename(FooException):
> """ Raised when a bad filename is used in a foo """
> 
> class FooUnknownBar(FooException, KeyError):
> """ Raised when an unknown bar is used with a foo """
> 
> However, there should never be an exception raised of class
> FooException, and in fact I want that to cause an appropriate error to
> be raised from the module.
> 
> Normally, I'd pick some key part of the functionality of the class,
> and cause that to raise NotImplementedError. It's then the
> responsibility of subclasses to override that.
> 
> However, in the case of exceptions, I don't want to override *any*
> functionality; everything should be provided by the base classes. It'd
> be messy to have to override something in every subclass just to
> ensure the abstraction of the module base exception.
> 
> I've tried doing this in the __init__():
> 
> class FooException(Exception):
> """ Base class for all FooModule exceptions """
> def __init__(self):
> raise NotImplementedError, \
> "%s is an abstract class for exceptions" % self.__class__
> 
> When I use this, I discovered to my horror that the subclasses were
> calling FooException.__init__ -- which I though wasn't supposed to
> happen in Python!
> 
> It's also rather semantically weird, to my eye.
> 
> Can I do something tricky with checking base classes in the
> FooException.__init__() ?
> 
> 
> [0] Although he's apparently been quoted earlier as saying he did.
> He's changed his mind[1] since then.
> 
> [1] http://www.artima.com/weblogs/viewpost.jsp?thread=92662>
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gmpy 1.01 rc near... anybody wanna test>

2005-11-11 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> I've created Windows binaries for Python 2.3 and 2.4. It should be
> compatible with PentiumPro or later processors.

Thanks!  I hope to package up a release early next week, and to include
these.


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


Re: Newb ??

2005-11-11 Thread Alex Martelli
Norman Silverstone <[EMAIL PROTECTED]> wrote:
   ...
> Incidentally, I am only just starting to learn about functions and have
> not come across the module 're'. Also why is it (lo+hi)//2 and not
> (lo+hi)/2.

Using // ensures truncation, which is what you want. A single / may mean
truncating division in the default legacy/compatibility mode, but with
the new division behavior (which one day will become standard) it means
true division, so that for example 1/2 means 0.5 -- better get used to
the new behavior ASAP (which is why you can ask for new division
behavior with -Qnew on Python's commandline or 'from __future__ import
division' at the top of your module -- to help you get used to it).


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


Re: how to start a process and get it's pid?

2005-11-11 Thread Daniel Crespo
> >>> import subprocess
> >>> p = subprocess.Popen("c:/windows/notepad.exe")
> >>> p.pid

> 1948

Yes, it works. But in my case, I need to run the program totally
separated from my main program. So, when I start a new program through
subprocess, it doesn't unlink. I mean, if I close my main app, so does
the launched program. With startfile() it does the job, but I then I
have to find what pid is through win32all module, etc.

it would be very good if I can use spawnl

Daniel

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


Is there a built-in method for transforming (1, None, "Hello!") to 1, None, "Hello!"?

2005-11-11 Thread Daniel Crespo
Is there a built-in method for transforming (1,None,"Hello!") to
1,None,"Hello!"?

Thanks

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


Calling values from a webform to Python

2005-11-11 Thread mjakowlew
hi,

I'm trying to pass some values from a webform into a python script.

___



 Name: 
 Email: 
 


___

Now, how do I call these individual attributes (filename,title, etc.)
in my "processForm.py".
I think it has something to do with the:

REQUEST=context.REQUEST

command, but I'm not quite sure how to implement it properly. Also this
is done through Zope if that makes a difference to anyone.

Thanks in advance,
mjakowlew

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


Re: how to start a process and get it's pid?

2005-11-11 Thread Daniel Crespo
> not sure, but the return value looks like a PID, so maybe you're seeing the
> PID for the cmd.exe instance used to run the program.  or something.

No. There wasn't a 196 PID for any of the processes.

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


Re: Is there a built-in method for transforming (1, None, "Hello!") to 1, None, "Hello!"?

2005-11-11 Thread Grant Edwards
On 2005-11-11, Daniel Crespo <[EMAIL PROTECTED]> wrote:
> Is there a built-in method for transforming (1,None,"Hello!") to
> 1,None,"Hello!"?

What transformation? The two are identical:

>>> x = (1,None,"Hello!")
>>> y = 1,None,"Hello!"
>>> x == y
True

-- 
Grant Edwards   grante Yow!  Nice decor!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import statements for timeit module

2005-11-11 Thread bruno at modulix
ChaosKCW wrote:
> Hi
> 
> I was wondering if someone could help with the import statements needed
> to use the timeit module in the following code. I need to access the
> "cur" object.
> 
> Thanks,
> 
> import cx_Oracle
> import timeit
> 
> def VerifyTagIntegrity(con, TableOwner):
> cur = con.cursor()
> sql = 'select (select count(*) from %s.f4111) as F4111_COUNT,
> (select count(*) from %s.f4111_tag) as TAG_COUNT from dual;' %
> (TableOwner, TableOwner)
> print "  SQL: %s" % (sql)
> timer = timeit.Timer('cur.execute(sql)', 'from __main__ import
> cur')
> print timer.timeit()
> 

'cur' is local to the function, so it's not an attribute of your module,
so you can't hope to import it anyway.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a built-in method for transforming (1, None, "Hello!") to 1, None, "Hello!"?

2005-11-11 Thread [EMAIL PROTECTED]
do you mean this ? otherwise, don't know what you want.

a, b, c = (1, None, "Hello!")

Daniel Crespo wrote:
> Is there a built-in method for transforming (1,None,"Hello!") to
> 1,None,"Hello!"?
> 
> Thanks

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


Re: Is there a built-in method for transforming (1, None, "Hello!") to 1, None, "Hello!"?

2005-11-11 Thread Simon Brunning
On 11 Nov 2005 07:21:46 -0800, Daniel Crespo <[EMAIL PROTECTED]> wrote:
> Is there a built-in method for transforming (1,None,"Hello!") to
> 1,None,"Hello!"?

There's no conversion to do:

>>> (1,None,"Hello!")
(1, None, 'Hello!')
>>> 1,None,"Hello!"
(1, None, 'Hello!')

They are both tuples contining identicle elements. What is it that you
want to do?

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


This Week in PyPy 2

2005-11-11 Thread Michael Hudson
Introduction


This is the second of what will hopefully be many summaries of what's
been going on in the world of PyPy in the last week.  I'd still like
to remind people that when something worth summarizing happens to
recommend if for "This Week in PyPy" as mentioned on:

http://codespeak.net/pypy/dist/pypy/doc/weekly/

where you can also find old summaries.

There were about 100 commits to the pypy section of codespeak's
repository this week.


pypy-c py.py


Over the weekend (while I was being blown around Wales by the remnants
of hurricane Wilma) Armin and a few others worked on trying to get a
translated pypy-c to run the interpreted py.py.  This resulted in a
fixing a welter of small differences between CPython and pypy-c,
though at the end of it all "we are still left in the dark of
incomprehensible geninterplevel crashes caused by subtle differences
between the most internal types of CPython and pypy-c."


Multiple Spaces
===

In one of the reports we're currently writing for the end of phase 1
EU review:

http://codespeak.net/pypy/dist/pypy/doc/draft-low-level-encapsulation.html

we made this claim:

The situation of multiple interpreters is thus handled
automatically: if there is only one space instance, it is regarded
as a pre-constructed constant and the space object pointer (though
not its non-constant contents) disappears from the produced
source, i.e. both from function arguments and local variables and
from instance fields. If there are two or more such instances, a
'space' attribute will be automatically added to all application
objects (or more precisely, it will not be removed by the
translation process), the best of both worlds.

And then we tried to do it, and had to tune the claim down because it
doesn't work.  This is because the StdObjSpace class has a
'specialized method' -- a different version of the wrap() method is
generated for each type it is seen to be called with.  This causes
problems when there are genuine StdObjSpace instances in the
translated pypy because of limitations in our tools.  We looked at
these limitations and decided that it was time to rewrite the world
again, leading in to the next section...


SomePBC-refactoring
===

One of the more unusual annotations produced by PyPy's annotator is
that of 'SomePBC', short for 'SomePrebuiltConstant'.  This annotation
means that a variable contains a reference to some object that existed
before the annotation process began (key example: functions).  Up
until now, the annotation has actually explicitly included which
prebuiltconstants a variable might refer to, which seems like the
obvious thing to do.  Unfortunately, not all things that we'd like to
annotate as a prebuiltconstant actually exist as unique CPython
objects -- in particular the point of specializing a function is that
it becomes many functions in the translated result.  Also for
'external', i.e. not written in RPython, functions we want to be able
to supply annotations for the input and exit args even if there is no
corresponding CPython function at all.

The chosen solution is to have the SomePBC annotation refer not to a
CPython object but to a more abstracted 'Description' of this object.
In some sense, this isn't a very large change but it affects most
files in the annotation directory and a fair fraction of those under
rpython/ and translator/.  We're also cleaning up some other mess
while we're there and breaking everything anyway.


Draft-Dynamic-...
=

It's not linked from anywhere on the website (yet...) but the report
that will become "Deliverable 05.1":

   
http://codespeak.net/pypy/dist/pypy/doc/draft-dynamic-language-translation.html

has been reviewed and re-reviewed in the last couple of weeks and is
definitely required reading for anyone who has an interest in the more
theoretical side of PyPy.


Gtbg Sprint in December
===

Hopefully very soon, we'll announce the next PyPy sprint... stay tuned!

Cheers,
mwh

-- 
  > I'm a little confused.
  That's because you're Australian!  So all the blood flows to
  your head, away from the organ most normal guys think with.
-- Mark Hammond & Tim Peters, comp.lang.python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: derived / base class name conflicts

2005-11-11 Thread christopherlmarshall
I see what you mean now.

It would indeed be enlightening if I wanted to study the internals of
Tkinter, and perhaps one day I will.

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


Re: Python obfuscation

2005-11-11 Thread Mike Meyer
"Ben Sizer" <[EMAIL PROTECTED]> writes:
>> A recent, heavily
>> publicized case where Sony added copy protection to a product cost
>> them sales, and from what I've heard, even legal fees.
> I think that's a poor example - the cost hasn't come from the mere act
> of adding protection, but the method in which that protection operates.

That was sort of the point - that the effect on the bottom line of
adding copy protection is usually worse than just the cost of the
software, and can be much worse. This is a particularly egregious
example, but that just makes it an egregious example, not a poor one.

> I don't think anybody here - certainly not me - is talking about
> infecting a user's system to protect our property, or taking any other
> intrusive steps. I'd just like to make it non-trivial to make or use
> additional copies.

I've returned software that wouldn't run from a backup copy. Would I
return your software? If yes, have you factored the loss of sales to
people like me into your profit calculations?

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LARGE numbers

2005-11-11 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> Python does support large numbers, but it's not very fast for such
> large numbers. There is a Python module called GMPY that uses the GMP
> (Gnu Multiple Precision) library for faster operations on large
> numbers.

As the author of gmpy, I'd like to point out that the speed difference
isn't all that large, if all you're doing is ordinary arithmetic -- a
few times at most (it can be better if you need some of GMP's
functionality which gmpy exposes, such as primality testing).


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


Re: derived / base class name conflicts

2005-11-11 Thread christopherlmarshall
Your suggestion ('_name' -> implementation, 'name' -> API) makes sense
as a convention between programmers that know a fair amount about each
other's classes before using them.

I don't think it is reasonable in general to only subclass from base
classes you have studied the full API of, however.  The double
underscore is a decent solution to my problem.

I imagine  it must be used a lot in domains where people are making
heavy use of third party python code.

Chris Marshall

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


Re: Newb ??

2005-11-11 Thread Fredrik Lundh
Norman Silverstone wrote:

> > did you test the script?  here's a simulator:
>
> < snip>
>
> Fredrik, thank you very much indeed for taking the trouble to show me the
> way. I am sorry that I made the comment I did, that will teach me to read
> more carefully. It is said that there is no fool like an old fool and, as
> I am approaching 78 years old, I think I qualify. It is also said that you
> are never too old to learn so I am trying.
>
> Now, I put the script you gave into an editor and ran it , (I use Ubuntu
> Linux by the way). It certainly showed how the computer arrived at the
> number guessed but guessed the number itself and gave me no chance to say
> whether high or low. I noticed also that the numbers were all greater than
> 50 and the loop ran until the number guessed was 100, then it stopped.
> Perhaps you can point out to me how I should go about debugging.

debugging?  the script I posted was intended to show you that given an
honest human (simulated by the raw_input function), the posted algorithm
found the right answer for all values in the given range.  (if the algorithm
had been broken, the simulator wouldn't have finished).

if you want to play yourself, use Steven's original code, and follow the in-
structions...





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


Re: Import statements for timeit module

2005-11-11 Thread Alex Martelli
ChaosKCW <[EMAIL PROTECTED]> wrote:

> So timeit is mostly useless then ?

No, it's a precious jewel, but if you want to use it you must allow it
to import the code you want it to run.


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


Re: how to start a process and get it's pid?

2005-11-11 Thread Yves Glodt
Gerhard Häring wrote:
> Yves Glodt wrote:
>> Hello,
>>
>> another question rose for me today...
>>
>> Is there a way to start an external process, in it's own context (not as 
>> the exec-() functions do), and get it's pid...? [...]
> 
> Check out the subprocess module if you're using Python 2.4.
> 
> Otherwise, you can always use os.spawn*, for example:
> 
>  >>> os.spawnl(os.P_NOWAIT, "c:/windows/notepad.exe")
> 1944

Thanks, in Linux it seems to work.

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


Re: derived / base class name conflicts

2005-11-11 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> I don't think it is reasonable in general to only subclass from base
> classes you have studied the full API of, however.  The double

I think you underestimate the level of coupling that inevitably occurs
between base and derived classes.  In general, such coupling being
strong, knowing the full API of the base class is inevitable (although
in some special corner-case, when you do only need to add private data,
you may, exceptionally, get away with less knowledge).


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


Inserting Records into SQL Server - is there a faster interface than ADO

2005-11-11 Thread geskerrett
I have a program that reads records from a binary file and loads them
into an MS-SQL Server database.  It is using a stored proc, passing the
parameters.

I am using pywin32 to create a connection object.  Once the connection
is open I simple pass the SQL formatted commands using
cnx.Execute(sqlstring).

My test examples;

20,000 records using the ADO connection: 0:04:45:45

If I setup the program to not send the record to the database - so all
other variables and processes are constant, it simply just skips the
cnx.Execute(sqlstring) step, then it takes only 0:00:25:78 to process
thru the same number of trx.

Obviously the times in my test are that , but I have a client that woud
like to use this and has several million transactions to content with.

So my questions is 
Is there a "faster" method I can use to connect to the SQL server ?
Or does anyone have any "optimization" tips the can offer ?

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


Re: Is there a built-in method for transforming (1, None, "Hello!") to 1, None, "Hello!"?

2005-11-11 Thread Alex Martelli
Daniel Crespo <[EMAIL PROTECTED]> wrote:

> Is there a built-in method for transforming (1,None,"Hello!") to
> 1,None,"Hello!"?

You're mentioning two different literal syntaxes for the same object (a
tuple) -- the one with parentheses works everywhere, the other one
_almost_ everywhere (not where parentheses would be ambiguous).

Not sure, therefore, what you mean by "transforming" here; if you're
dealing with a string for in either case, for example, you could remove
the first and last characters by slicing with [1:-1], etc, etc.  Perhaps
you can clarify exactly what you're asking for!


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


Nufox : Nouveaux examples...

2005-11-11 Thread Salvatore
Sur : http://www.salvatore.exolia.net:9090/
(Nécessite Firefox ou Mozilla)

Cordialement

Salvatore.

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


Re: LARGE numbers

2005-11-11 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes:
> As the author of gmpy, I'd like to point out that the speed difference
> isn't all that large, if all you're doing is ordinary arithmetic -- a
> few times at most (it can be better if you need some of GMP's
> functionality which gmpy exposes, such as primality testing).

For numbers of this size, won't gmpy use FFT-based multiplication?
That's potentially orders of magnitude faster than ordinary n**2
multiplication.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python obfuscation

2005-11-11 Thread petantik
Ben Sizer wrote:
> Mike Meyer wrote:
> > There are ways to distribute
> > Python modules so that the user can't just open them in a text
> > editor. There are also ways to get cryptographic security for
> > distributed modules.
>
> I know distributing as bytecode helps, but I was under the impression
> that the disassembers worked pretty well. With the dynamic nature of
> the language I expect that all the variable names are largely left
> intact. You win some, you lose some, I guess.
>
> As for cryptographic security, could you provide a link or reference
> for this? I am quite interested for obvious reasons. I'd be concerned
> that there's a weak link in there at the decoding stage, however.
>
> I have considered distributing my program as open source but with
> encrypted data. Unfortunately anyone can just read the source to
> determine the decryption method and password. Maybe I could put that
> into an extension module, but that just moves the weak link along the
> chain.
>
> > Yes, if you use the same methods you use in C++,
> > it's "much harder". But by the same token, if you tried to use the
> > methods you'd use in a Python program in C++, you'd find that the C++
> > version was "much harder".
>
> Well, I'm not sure what you mean here. A compiled C++ program is much
> harder to extract information from than a compiled Python program.
> That's without applying any special 'methods' on top of the normal
> distribution process.
>
> > Of course, as Alex pointed out, all of these are just keeping honest
> > people honest. The crooks have all the advantages in this game, so you
> > really can't expect to win.
>
> No, certainly not. But if you can mitigate your losses easily enough -
> without infringing upon anyone else's rights, I must add - then why not
> do so.
>
> --
> Ben Sizer.

The economics of software distribution must certainly come into it,
doing a cost/benefit analysis of whether it's worth the effort to
protect your code from would be crackers.

The problem with code protection methodology in general is that once
its cracked everyone has access to code for, maybe, all software using
the particular protection scheme.

the argument that most people buy software rather than get a pirated
version depends on the country  that they are in e.g. china's piracy
problem where shops sell pirated software with no retribution by the
state - remember china is about to be the worlds largest economic
superpower

The above problem illustrate why code needs to be protected in an
effective way, by law and code protection schemes

With python there is no comfort factor in knowing that your code is
being protected, well not than I can see, compared with protection
schemes for compiled code which are used by many commercial software
companies.

Of course, we know that there can never be a 100% way to protect code
that some pirate won't overcome but it still stops the casual user or
beginner 'crackers' from stealing the code and digging in to your
profit margin.

btw i'm no expert on copy protection mechanism but the question I
raised originally, i believe, is valid and should be discussed









http://petantik.blogsome.com - A Lucid Look at Reality

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


Re: Import statements for timeit module

2005-11-11 Thread ChaosKCW
So timeit is mostly useless then ?

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


Re: gmpy 1.01 rc near... anybody wanna test>

2005-11-11 Thread David Gutierrez
Include me in your list, please.

David


From: [EMAIL PROTECTED] (Alex Martelli)
To: python-list@python.org
Subject: Re: gmpy 1.01 rc near... anybody wanna test>
Date: Fri, 11 Nov 2005 07:10:01 -0800
MIME-Version: 1.0
Received: from smtp-vbr7.xs4all.nl ([194.109.24.27]) by mc10-f5.hotmail.com 
with Microsoft SMTPSVC(6.0.3790.211); Fri, 11 Nov 2005 07:15:45 -0800
Received: from bag.python.org (bag.python.org [194.109.207.14])by 
smtp-vbr7.xs4all.nl (8.13.3/8.13.3) with ESMTP id jABFFh8j021412for 
<[EMAIL PROTECTED]>; Fri, 11 Nov 2005 16:15:43 +0100 (CET)(envelope-from 
[EMAIL PROTECTED])
Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) 
with ESMTP id 9F2C51E4028for <[EMAIL PROTECTED]>; Fri, 11 Nov 2005 
16:15:43 +0100 (CET)
X-Message-Info: JGTYoYF78jGfyzkyXoeo8ch9fcaQi0v8snnTTXNK87Q=
Path: 
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!newsfeed.fjserv.net!nx02.iad01.newshosting.com!newshosting.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 11 Nov 2005 09:09:59 -0600
Newsgroups: comp.lang.python
References: 
<[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL 
PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL 
PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]>
Organization: None in Sight
User-Agent: MacSOUP/2.7 (unregistered for 40 days)
Lines: 10
NNTP-Posting-Host: 67.174.192.152
X-Trace: 
sv3-Yf86cpyoEmrCYhyX8lOf5fInoVfid2sHdLjs5wGBsNNfmQ+Y+TUXQ3tQv3nKjaKF2OJSybv1oOjUIdf!CXoxdwIrHFQSorKECjQhg+5m0exXk34yybLQwCedyYraRrLvSb1squreROVZuY6cShDftkfCWDdr!7/VhGxMMM9id
X-Complaints-To: [EMAIL PROTECTED]
X-DMCA-Complaints-To: [EMAIL PROTECTED]
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your 
complaintproperly
X-Postfilter: 1.3.32
Xref: news.xs4all.nl comp.lang.python:405582
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.6
Precedence: list
List-Id: General discussion list for the Python programming 
language
List-Unsubscribe: 
,
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: 
,
Errors-To: [EMAIL PROTECTED]
X-Virus-Scanned: by XS4ALL Virus Scanner
Return-Path: [EMAIL PROTECTED]
X-OriginalArrivalTime: 11 Nov 2005 15:15:46.0002 (UTC) 
FILETIME=[CA368B20:01C5E6D2]

<[EMAIL PROTECTED]> wrote:

 > I've created Windows binaries for Python 2.3 and 2.4. It should be
 > compatible with PentiumPro or later processors.

Thanks!  I hope to package up a release early next week, and to include
these.


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


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


Re: Python obfuscation

2005-11-11 Thread Mike Meyer
"Ben Sizer" <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>> There are ways to distribute
>> Python modules so that the user can't just open them in a text
>> editor. There are also ways to get cryptographic security for
>> distributed modules.
> As for cryptographic security, could you provide a link or reference
> for this? I am quite interested for obvious reasons. I'd be concerned
> that there's a weak link in there at the decoding stage, however.

How about some ideas: Store your code in a zip file, and add it to the
search path. That immediately takes you out of the "just open the file
with a text editor" mode. For cryptographic security, use the ihooks
module to make "import" detect and decode encrypted modules before
actually importing them. Or digitally sign the modules, and check the
signature at import time. All of these are dead simple in Python.

> I have considered distributing my program as open source but with
> encrypted data. Unfortunately anyone can just read the source to
> determine the decryption method and password. Maybe I could put that
> into an extension module, but that just moves the weak link along the
> chain.

This isn't aPython problem, it's a problem with what you're doing. Try
Alex's solution, and put the data on a network server that goes
through whatever authentication you want it to.

>> Yes, if you use the same methods you use in C++,
>> it's "much harder". But by the same token, if you tried to use the
>> methods you'd use in a Python program in C++, you'd find that the C++
>> version was "much harder".
> Well, I'm not sure what you mean here. A compiled C++ program is much
> harder to extract information from than a compiled Python program.

It is? Is the Python disassembler so much advanced over the state of
the art of binary disassemblers, then? Or maybe it's the Python
decompilers that are so advanced? As far as I can tell, the only real
difference between Python bytecodes and x86 (for instance) binaries is
that Python bytecodes keep the variable names around so it can do
run-timme lookups. That's not that big a difference.

As for what I meant - Python has ihooks and imp, that make it simple
to customize import behavior. Doing those kinds of things with C++
code requires building the tools to do that kind of thing from
scratch.

>> Of course, as Alex pointed out, all of these are just keeping honest
>> people honest. The crooks have all the advantages in this game, so you
>> really can't expect to win.
> No, certainly not. But if you can mitigate your losses easily enough -
> without infringing upon anyone else's rights, I must add - then why not
> do so.

Elsewhere in the thread, you said:

> I'd just like to make it non-trivial to make or use additional copies.

How do you do that without infringing my fair use rights?

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nufox : Nouveaux examples...

2005-11-11 Thread bruno at modulix
Salvatore wrote:
> Sur : http://www.salvatore.exolia.net:9090/
> (Nécessite Firefox ou Mozilla)
> 


Heu, Salvatore, tu te serais pas un peu trompé de ng, là ?-)
(x-post et fu2 f.c.l.py)



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Nufox : New examples

2005-11-11 Thread Salvatore
On : http://www.salvatore.exolia.net:9090/
(Firefox ou Mozilla)
Regards

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


Re: Inserting Records into SQL Server - is there a faster interface than ADO

2005-11-11 Thread Jarek Zgoda
[EMAIL PROTECTED] napisał(a):

> Is there a "faster" method I can use to connect to the SQL server ?
> Or does anyone have any "optimization" tips the can offer ?

This has nothing with python, but the fastest way to load large amount
of data to MS SQL Server database is DTS import from flat file.

To spped up the things a bit, do not commit transaction after each row
inserted -- commit whole batch.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting Records into SQL Server - is there a faster interface than ADO

2005-11-11 Thread Alan Kennedy
[EMAIL PROTECTED]
> I have a program that reads records from a binary file and loads them
> into an MS-SQL Server database.  It is using a stored proc, passing the
> parameters.

[snip]

> So my questions is 
> Is there a "faster" method I can use to connect to the SQL server ?
> Or does anyone have any "optimization" tips the can offer ?

Is there a reason why you need to use a stored procedure?

Do you need to process the data in some way in order to maintain 
referential integrity of the database?

If the answer to both these questions is "no", then you can use the 
"bcp" (Bulk CoPy) utility to transfer data into SQLServer *very* quickly.

http://msdn.microsoft.com/library/en-us/coprompt/cp_bcp_61et.asp
http://www.sql-server-performance.com/bcp.asp

thought-it-was-worth-mentioning-ly y'rs,

-- 
alan kennedy
--
email alan:  http://xhaus.com/contact/alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling values from a webform to Python

2005-11-11 Thread bruno at modulix
mjakowlew wrote:
> hi,
> 
> I'm trying to pass some values from a webform into a python script.
> 
(snip)
> Also this
> is done through Zope if that makes a difference to anyone.

Yes, it makes a difference. Zope is a world in itself, and is slighty OT
here. Note that there's a Zope mailing-list:
http://mail.zope.org/mailman/listinfo/zope

(Zope answers sent in private)
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LARGE numbers

2005-11-11 Thread Scott David Daniels
Paul Rubin wrote:
> [EMAIL PROTECTED] (Alex Martelli) writes:
> 
> For numbers of this size, won't gmpy use FFT-based multiplication?
> That's potentially orders of magnitude faster than ordinary n**2
> multiplication.

But Python is no slouch with its use of Karatsuba multiplication.
(in other words, Python is not N**2 for large numbers).

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


Re: Python-based Document Management System?

2005-11-11 Thread W. Borgert
> If you search for CONTENT management system,  there is
> Plone: A user-friendly and powerful open source Content Management ...
> http://plone.org/

No, I'm looking for a DMS, not a CMS.  My impression from
the Plone web page is, that it does not have DMS features.

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


Re: Python-based Document Management System?

2005-11-11 Thread Fredrik Lundh
W. Borgert wrote:

> > If you search for CONTENT management system,  there is
> > Plone: A user-friendly and powerful open source Content Management ...
> > http://plone.org/
>
> No, I'm looking for a DMS, not a CMS.  My impression from
> the Plone web page is, that it does not have DMS features.

maybe this is what you want ?

http://bscw.fit.fraunhofer.de/

for a hosted (and very polished) implementation of BSCW, see

http://www.projectplace.com/index.html





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


Re: Import statements for timeit module

2005-11-11 Thread Scott David Daniels
bruno at modulix wrote:
> ChaosKCW wrote:
> 
>>Hi
>>
>>I was wondering if someone could help with the import statements needed
>>to use the timeit module in the following code. I need to access the
>>"cur" object.
>>
>>Thanks,
>>
...>
> 'cur' is local to the function, so it's not an attribute of your module,
> so you can't hope to import it anyway.

Although you could change your code as follows:

 >>import cx_Oracle
 >>import timeit
 >>
 >>def VerifyTagIntegrity(con, TableOwner):
   global cur, sql  ###
 >>cur = con.cursor()
 >>sql = 'select (select count(*) from %s.f4111) as F4111_COUNT,
 >>(select count(*) from %s.f4111_tag) as TAG_COUNT from dual;' %
 >>(TableOwner, TableOwner)
 >>print "  SQL: %s" % (sql)
XXX>>  timer = timeit.Timer('cur.execute(sql)', 'from __main__ import
 >>cur')
   timer = timeit.Timer('cur.execute(sql)',   ###
'from __main__ import cur, sql') ###
 >>print timer.timeit()

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


Re: Inserting Records into SQL Server - is there a faster interfacethan ADO

2005-11-11 Thread Scott David Daniels
Alan Kennedy wrote:
> [EMAIL PROTECTED]
> 
>> I have a program that reads records from a binary file and loads them
>> into an MS-SQL Server database.  It is using a stored proc, passing the
>> parameters.
> 
>> So my questions is 
>> Is there a "faster" method I can use to connect to the SQL server ?
>> Or does anyone have any "optimization" tips the can offer ?
> 
> Is there a reason why you need to use a stored procedure?
> 
> Do you need to process the data in some way in order to maintain 
> referential integrity of the database?
> 
> If the answer to both these questions is "no", then you can use the 
> "bcp" (Bulk CoPy) utility to transfer data into SQLServer *very* quickly.
> 
> http://msdn.microsoft.com/library/en-us/coprompt/cp_bcp_61et.asp
> http://www.sql-server-performance.com/bcp.asp
> 
> thought-it-was-worth-mentioning-ly y'rs,
> 
If the answer to some of the earlier questions is "yes," I have
found "bcp" can be a great tool to fill up a new table of data
"on its way in."  SQL can then move it to where it should really
go with nice transaction-protected SQL, proper index-building
and so on.  After distributing the data, you can drop the table
of pending data.

I agree this is off-topic, but it is too close to my experience.

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


Re: Lie Hetland book: Beginning Python..

2005-11-11 Thread Scott David Daniels
Magnus Lycka wrote:
> Vittorio wrote:
> Using the same symbol for both string substitutions and SQL placeholder
> such as pysqlite 1 and the MySQL interface does, is not really a bright
> idea in my opinion. Who thinks this is pretty?
> 
> sql = "SELECT %s FROM %s WHERE %s = %%s"
> cur.execute(sql % (col,table,search_col), (param,))
> 
> I think it's less confusing with:
> 
> sql = "SELECT %s FROM %s WHERE %s = ?"
> cur.execute(sql % (col,table,search_col), (param,))
> 
or you could use:

   sql = "SELECT %s FROM %s WHERE %s = %s"
   cur.execute(sql % (col,table,search_col, '%s'), (param,))

which I like better, because you don't have to read
extremely carefully for the double-percents.

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


Re: LARGE numbers

2005-11-11 Thread casevh

Paul Rubin wrote:
> [EMAIL PROTECTED] (Alex Martelli) writes:
> > As the author of gmpy, I'd like to point out that the speed difference
> > isn't all that large, if all you're doing is ordinary arithmetic -- a
> > few times at most (it can be better if you need some of GMP's
> > functionality which gmpy exposes, such as primality testing).
>
> For numbers of this size, won't gmpy use FFT-based multiplication?
> That's potentially orders of magnitude faster than ordinary n**2
> multiplication.

Python's native longs use Karatsuba multiplication with is O(n^1.585).

My early version of DecInt (BigDecimal) uses 4-way Toom-Cook
multiplication which is O(n^1.4). My development version uses
Nussbaumer convolution with is O(n ln(n)).

For multiplicaiton of two 1,000,000 digits numbers and conversion to a
decimal string, here are some times:

GMPY
multiplication: 0.96 seconds
conversion to string: 712.7 seconds

DecInt with GMPY
multiplication: 1.33 seconds
conversion to string: 0.83 seconds

DecInt without GMPY
multiplication: 2.84 seconds
conversion to string: 0.45 seconds

Python (using native long)
multiplication: 8.47 seconds
conversion to string: a really long time

Case

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


Re: LARGE numbers

2005-11-11 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Python's native longs use Karatsuba multiplication with is O(n^1.585).
> My early version of DecInt (BigDecimal) uses 4-way Toom-Cook ...

Wow, cool!  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Invoking Python from Python

2005-11-11 Thread Scott David Daniels
Cameron Laird wrote:
...
> I should make that explicit:  application developers, you
> don't have to tell customers everything your programs do.
> Your obligation is to make 'em meet requirements.  If it
> helps *you* that they do more, so be it.
I'd agree with the proviso that you at least inform your
customer if you are creating a security hole.

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


Re: Import statements for timeit module

2005-11-11 Thread bruno at modulix
ChaosKCW wrote:
> So timeit is mostly useless then ?
> 
I wouldn't say so.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Inserting Records into SQL Server - is there a faster interface thanADO

2005-11-11 Thread Tim Golden
[EMAIL PROTECTED]

> I have a program that reads records from a 
> binary file and loads them into an MS-SQL Server 
> database.  It is using a stored proc, passing the
> parameters.

> I am using pywin32 to create a connection object.  
> Once the connection is open I simple pass the 
> SQL formatted commands using cnx.Execute(sqlstring).

> So my questions is 
> Is there a "faster" method I can use to connect 
> to the SQL server ? Or does anyone have any 
> "optimization" tips the can offer ?

If you haven't, try to form your SQL statement
so it is parameterised. ie do this:



db = 
q = db.cursor ()

list_of_data = [...]
for row in list_of_data:
  q.execute ("INSERT INTO  (x, y, z) VALUES (?, ?, ?)", row)



rather than this:


...
for row in list_of_data:
  q.execute ("INSERT INTO  (x, y, z) VALUES (%s, %s, %s)" % row)
...


In theory, that should be more efficient, as the RDBMS can
optimise the SQL once. Don't know if it'll really make a 
difference.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: What do you use as symbols for Python ?

2005-11-11 Thread Scott David Daniels
Sion Arrowsmith wrote:
...
> class State:
> Enum = range(3)
> OPENED, CLOSED, ERROR = Enum
> Names = { OPENED: "OPENED", CLOSED: "CLOSED", ERROR: "ERROR" }

> so you can used State.Names[state] to provide something user-readable, ...

Or use a function like:

def named(value, classes):
 for klass in classes:
 for name, val in vars(klass).iteritems():
 if val == value:
 return name
 raise ValueError, "No names for %r in %s" (value, classes)

Remember CPU time is almost free when it is associated with a line
typed to a user paying attention.  This way you (A) don't have
to repeat the names in the source (a great place for errors),
and (B) you can say to yourself, "I think this is in one of these
several things" and go hunting happily.

In our example, named(2, [State]) gives us "ERROR"

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


Re: output buffering

2005-11-11 Thread Larry Bates
This is something I wrote that might help.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/299207

-Larry Bates

JD wrote:
> Hello,
> 
> When reading a large datafile, I want to print a '.' to show the
> progress. This fails, I get the series of '.'s after the data has been
> read. Is there a trick to fix this?
> 
> Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: testing C code with python

2005-11-11 Thread Scott David Daniels
>[EMAIL PROTECTED] wrote:
> A simple question - Is it common/good practice to test C code using
> Python? 

I certainly do such testing (hand-wrapped, because it doesn't
seem to cost too much time to do so.  Usually I develop in Python
and accumulate my tests there, then write the C equivalent, and
move the tests to the C code.  I've done this for programs that
were always to have become C programs as well as for those things
I intend to wrap as Python modules.

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


PIL- error message- cannot open libtiff.so.3

2005-11-11 Thread Tuvas
Okay, so I've been getting this error message when trying to use PIL to
open a JPEG, that there isn't a library by the name of libtiff.so.3 .
I've been searching the documentation, there isn't any reference to
this library. Also, I don't know why it's doing this as I'm trying to
open a JPEG, and not a tiff. I tried with a .bmp with similar results.
Any ideas? Thanks!

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


Re: testing C code with python

2005-11-11 Thread christopherlmarshall
I have recently started using tcl to do this with C++ code and will
soon be switching to doing it with python.

I think it is a fantastic way to arrange to test C++ and C code.
Python makes an excellent test-harness, and writing interfaces for
complex units of C++ code to enable them to be tested from Python is an
valuable exercise in itself.  It forces you to make your code
inspectable and brings up all sorts of important design issues that
otherwise would never occur to you.

It was a lot of work to get started with this but once you put in the
initial effort, it gets eaiser to maintiain.  And the payoff is that it
lets you write regression tests easily so that would be too hard to do
otherwise.

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


Dynamically Update Class Definitions?

2005-11-11 Thread chrisspen
Is there a way to loop through all instantiated objects and update
their classes when a source file changes? I know about Michael Hudson's
method
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164), but
you have to modify all your classes to subclass AutoReloader. Is there
something less intrusive (visitor pattern?) that you can use like
update(old_class, new_class) to automagically do the work?

Chris

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


Re: LARGE numbers

2005-11-11 Thread Tuvas
Well, as I'll be doing lots of multiplication, guess that GMPY is the
way to go. I'll use DecInt only for converting to strings if I find
anything interesting. This is all just kind of a theoretical aproach,
but, it can be lots of fun. Who knows if Python'll help find the
largest prime number ever? That would sure be cool. Thanks for all of
your help.

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


Re: What do you use as symbols for Python ?

2005-11-11 Thread Daniel Evers
Hi!

Never would have thought of this...
I mixed this with the class-version and created a new class derived from
"str" for easier printing and added an iterator:

---

class Enum:
class Type(str):
def __init__(self, name):
self.__name = name
def __str__(self):
return self.__name

def __init__(self, *keys):
self.__keys = []
for key in keys:
mytype = self.Type(key)
self.__dict__[key] = mytype
self.__keys.append(mytype)
self.__index = -1
self.__count = len(keys)

def __iter__(self):
return self

def next(self):
self.__index = self.__index + 1
if (self.__index >= self.__count):
self.__index = -1
raise StopIteration
return self.__keys[self.__index]

friends = Enum("Eric", "Kyle", "Stan", "Kenny")
print "These are my friends:",
print ", ".join([kid for kid in friends])
for kid in friends:
print kid,
if kid is friends.Kenny:
print "dead"
else:
print "alive"
---

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


Re: PIL- error message- cannot open libtiff.so.3

2005-11-11 Thread Fredrik Lundh
Tuvas wrote:

> Okay, so I've been getting this error message when trying to use PIL to
> open a JPEG, that there isn't a library by the name of libtiff.so.3 .
> I've been searching the documentation, there isn't any reference to
> this library. Also, I don't know why it's doing this as I'm trying to
> open a JPEG, and not a tiff. I tried with a .bmp with similar results.

sounds like someone has linked _imaging.so against the libtiff library.

what PIL version is this, and where did you get it ?

 



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


  1   2   3   >