Re: 3d programming without opengl

2006-10-31 Thread Paul McGuire
"nelson -" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> hi!
>   i want to build up a simple 3d interactive geometry application in
> python. Since i want to run it without 3D acceleration (a scene will
> be quite simple) I was wondering if there was a library in python that
> allow me to build 3D graphic without the need to use OpenGL I
> google but i can't find nothing interesting... (the best would be a
> pure python solution)
>
> Thanks,
>  nelson

Here's a page (http://www.vrplumber.com/py3d.py) with links to 73 possible 
libraries.

I've played with Slut (http://slut.sourceforge.net/) and it is quite easy to 
work with.  Here's a Flash movie (recorded using Wink) of a sphere that I 
programmed and rotated about: 
http://www.geocities.com/ptmcg/python/sphere1.htm, and here is the program 
that created it: http://www.geocities.com/ptmcg/python/vecSlut2.py.txt.

The demos that come with Slut are quite impressive, too.  The Slut project 
web page summarizes them here 
(http://slut.sourceforge.net/examples/index.html), but the little videos 
don't do them justice.

-- Paul


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


Re: Python windows interactive.

2006-10-31 Thread Fredrik Lundh
notejam wrote:

> Can not figure out how to write more than one line in interpreter mode.

press return between the lines.  if you get a "..." prompt, keep adding
more lines to the current statement.  press return an extra time to end 
the multiline-statement.

> Is that all interpreter is good for, testing one liners?  I have it
> run the program everytime I hit return

no, it executes the *current statement* when you press return.  a 
program consists usually consists of many statements.

> and can not figure out how to enter multiple lines of code. 

if you'd entered a statement that actually consisted of multiple lines, 
you'd noticed (try entering an "if"-statement, for example).

> I am jsut wondering can a program with 2 or more lines
> be wrote from the interpreter mode?

Type "help", "copyright", "credits" or "license" for more information.
 >>> import urllib
 >>> def gettitle(url):
... f = urllib.urlopen(url)
... s = f.read()
... i = s.find("")
... j = s.find("", i)
... return s[i+7:j]
...
 >>> gettitle("http://www.python.org";)
'Python Programming Language -- Official Website'
 >>> gettitle("http://www.cnn.com";)
'CNN.com - Breaking News, U.S., World, Weather, Entertainment & 
Video News'
 >>> sites = ["http://news.bbc.co.uk";, "http://reddit.com";,
... "http://www.fbi.gov";
... ]
 >>> for site in sites:
... print gettitle(site)
...
BBC NEWS | News Front Page
reddit.com: what's new online
Federal Bureau of Investigation - Home Page
 >>>

etc.



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


Re: Tkinter Listbox string formatting question - how to kill a dancing snake ?

2006-10-31 Thread Fredrik Lundh
Hendrik van Rooyen wrote:

> Is there a way to format this so it will line up with  *any*  font ?
> 
> I would prefer not to give up and use a fixed width font - it looks so
> teletypish...

sounds like contradicting requirements to me.

instead of trying to force the listbox to behave like a multicolumn 
widget, maybe you could switch to another widget?  some alternatives include

 a Text widget (you have to roll your own selection logic)
 bwidgets multicolumn ListBox:
 http://tkinter.unpythonic.net/bwidget/
 tktable:
 http://tktable.sourceforge.net/
 something based on the wck (that's what I'd would use myself):
 http://effbot.org/zone/wck-4.htm
 and perhaps there's something in Pmw:
 http://pmw.sourceforge.net


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


Re: create global variables?

2006-10-31 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> 
> J. Clifford Dyer wrote:
> 
>>Alistair King wrote:

[... advice and help ...]

> this worked a treat:
> 
> def monoVarcalc(atom):
> 
>a = atom + 'aa'
>Xaa = a.strip('\'')
>m = atom + 'ma'
>Xma = m.strip('\'')
>Xaa = DS1v.get(atom)
>Xma = pt.get(atom)
>return Xaa, Xma
> 
> 
> Caa, Cma = monoVarcalc('C')
> 
In which case I suspect you will find that this works just as well:

def monoVarcalc(atom):

Xaa = DS1v.get(atom)
Xma = pt.get(atom)
return Xaa, Xma


Unless there is something decidedly odd about the side-effects of the 
statements I've removed, since you never appear to use the values of a, 
m, Xaa and Xma there seems little point in calculation them.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Cann't connect zope server

2006-10-31 Thread Bruno Desthuilliers
steve wrote:
> Can I ask question about zope here?

Unless it has more to do with Python than with Zope itself, you'd better
ask on Zope's mailing-list.

> I started Zserver but could not connect to it using firefox.The runzope
> gave message:
> 
> /usr/bin/zope/instance/bin/runzope -X debug-mode=on
> 2006-10-31 12:50:45 INFO ZServer HTTP server started at Tue Oct 31
> 12:50:45 2006
> Hostname: 0.0.0.0
> Port: 8080
> 2006-10-31 12:50:45 CRITICAL Zope A user was not specified to setuid
> to; fix this to start as root (change the effective-user directive in
> zope.conf)

And this has absolutely nothing to do with Python.


-- 
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: scared about refrences...

2006-10-31 Thread Peter Otten
J. Clifford Dyer wrote:

> Thanks, that's very helpful.  Playing with your code a bit, I narrowed
> the problem down to the array.array() structure.  Looking at
> help(array), there's a method defined called __deepcopy__, which, it
> seems, takes no arguments, while deepcopy is passing it one argument.
> Looks like a bug in the array module to me.  Maybe others with more

Fixed in subversion: http://www.python.org/sf/1545837 

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


Re: 3d programming without opengl

2006-10-31 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "nelson -" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> hi!
>>   i want to build up a simple 3d interactive geometry application in
>> python. Since i want to run it without 3D acceleration (a scene will
>> be quite simple) I was wondering if there was a library in python that
>> allow me to build 3D graphic without the need to use OpenGL I
>> google but i can't find nothing interesting... (the best would be a
>> pure python solution)
>>
>> Thanks,
>>  nelson
>
> Here's a page (http://www.vrplumber.com/py3d.py) with links to 73 possible 
> libraries.
>
> I've played with Slut (http://slut.sourceforge.net/) and it is quite easy 
> to work with.  Here's a Flash movie (recorded using Wink) of a sphere that 
> I programmed and rotated about: 
> http://www.geocities.com/ptmcg/python/sphere1.htm, and here is the program 
> that created it: http://www.geocities.com/ptmcg/python/vecSlut2.py.txt.
>
> The demos that come with Slut are quite impressive, too.  The Slut project 
> web page summarizes them here 
> (http://slut.sourceforge.net/examples/index.html), but the little videos 
> don't do them justice.
>
> -- Paul
>
>
Well, shoot, I killed my free bandwidth on GeoCities with that link to the 
Flash animation!

I've uploaded a smaller video, should support 20-25 views/hour, instead of 3 
like the old one.  Please bear with me.

Thanks,
-- Paul


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


Re: 3d programming without opengl

2006-10-31 Thread Steve Holden
Paul McGuire wrote:
> "nelson -" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>hi!
>>  i want to build up a simple 3d interactive geometry application in
>>python. Since i want to run it without 3D acceleration (a scene will
>>be quite simple) I was wondering if there was a library in python that
>>allow me to build 3D graphic without the need to use OpenGL I
>>google but i can't find nothing interesting... (the best would be a
>>pure python solution)
>>
>>Thanks,
>> nelson
> 
> 
> Here's a page (http://www.vrplumber.com/py3d.py) with links to 73 possible 
> libraries.
> 
> I've played with Slut (http://slut.sourceforge.net/) and it is quite easy to 
> work with.  Here's a Flash movie (recorded using Wink) of a sphere that I 
> programmed and rotated about: 
> http://www.geocities.com/ptmcg/python/sphere1.htm, and here is the program 
> that created it: http://www.geocities.com/ptmcg/python/vecSlut2.py.txt.
> 
> The demos that come with Slut are quite impressive, too.  The Slut project 
> web page summarizes them here 
> (http://slut.sourceforge.net/examples/index.html), but the little videos 
> don't do them justice.
> 
Looks like c.l.py just slashdotted you ... """The GeoCities web site you 
were trying to view has temporarily exceeded its data transfer limit. 
Please try again later."""

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: create global variables?

2006-10-31 Thread Alistair King
Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
>   
>> J. Clifford Dyer wrote:
>>
>> 
>>> Alistair King wrote:
>>>   
>
> [... advice and help ...]
>
>   
>> this worked a treat:
>>
>> def monoVarcalc(atom):
>>
>>a = atom + 'aa'
>>Xaa = a.strip('\'')
>>m = atom + 'ma'
>>Xma = m.strip('\'')
>>Xaa = DS1v.get(atom)
>>Xma = pt.get(atom)
>>return Xaa, Xma
>>
>>
>> Caa, Cma = monoVarcalc('C')
>>
>> 
> In which case I suspect you will find that this works just as well:
>
> def monoVarcalc(atom):
>
> Xaa = DS1v.get(atom)
> Xma = pt.get(atom)
> return Xaa, Xma
>
>
> Unless there is something decidedly odd about the side-effects of the 
> statements I've removed, since you never appear to use the values of a, 
> m, Xaa and Xma there seems little point in calculation them.
>
> regards
>   Steve
>   
Yup...it works..but now i have to create a dictionary of 'a' and 'm',
ie... "Xaa" and "Xma" string, key:value pairs so i can use other
functions on the Xaa, Xma variables by iterating over them and
retrieving the values from the variables. I think if i just input Xaa
and Xma, only the values associated with those variables will go into
the dictionary and ill just be iterating over nonsence.

atomsmasses = {}

def monoVarcalc(atom):
a = atom + 'aa'
m = atom + 'ma'
atomsmasses[a]=m
Xaa = a.strip('\'')
Xma = m.strip('\'')
Xma = pt.get(atom)
if DS1v.get(atom) != None:
Xaa = DS1v.get(atom)
else:
Xaa = 0
return Xaa, Xma

Caa, Cma = monoVarcalc('C')
Oaa, Oma = monoVarcalc('O')
Haa, Hma = monoVarcalc('H')
Naa, Nma = monoVarcalc('N')
Saa, Sma = monoVarcalc('S')
Claa, Clma = monoVarcalc('Cl')
Braa, Brma = monoVarcalc('Br')
Znaa, Znma = monoVarcalc('Zn')



i think? :)
thanks

a

-- 
Dr. Alistair King
Research Chemist,
Laboratory of Organic Chemistry,
Department of Chemistry,
Faculty of Science
P.O. Box 55 (A.I. Virtasen aukio 1)
FIN-00014 University of Helsinki
Tel. +358 9 191 50392, Mobile +358 (0)50 5279446
Fax +358 9 191 50366 

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


Re: create global variables?

2006-10-31 Thread Steve Holden
Alistair King wrote:
> Steve Holden wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>  
>>
>>>J. Clifford Dyer wrote:
>>>
>>>
>>>
Alistair King wrote:
  
>>
>>[... advice and help ...]
>>
>>  
>>
>>>this worked a treat:
>>>
>>>def monoVarcalc(atom):
>>>
>>>   a = atom + 'aa'
>>>   Xaa = a.strip('\'')
>>>   m = atom + 'ma'
>>>   Xma = m.strip('\'')
>>>   Xaa = DS1v.get(atom)
>>>   Xma = pt.get(atom)
>>>   return Xaa, Xma
>>>
>>>
>>>Caa, Cma = monoVarcalc('C')
>>>
>>>
>>
>>In which case I suspect you will find that this works just as well:
>>
>>def monoVarcalc(atom):
>>
>>Xaa = DS1v.get(atom)
>>Xma = pt.get(atom)
>>return Xaa, Xma
>>
>>
>>Unless there is something decidedly odd about the side-effects of the 
>>statements I've removed, since you never appear to use the values of a, 
>>m, Xaa and Xma there seems little point in calculation them.
>>
>>regards
>>  Steve
>>  
> 
> Yup...it works..but now i have to create a dictionary of 'a' and 'm',
> ie... "Xaa" and "Xma" string, key:value pairs so i can use other
> functions on the Xaa, Xma variables by iterating over them and
> retrieving the values from the variables. I think if i just input Xaa
> and Xma, only the values associated with those variables will go into
> the dictionary and ill just be iterating over nonsence.
> 
> atomsmasses = {}
> 
> def monoVarcalc(atom):
> a = atom + 'aa'
> m = atom + 'ma'
> atomsmasses[a]=m
> Xaa = a.strip('\'')
> Xma = m.strip('\'')
> Xma = pt.get(atom)
> if DS1v.get(atom) != None:
> Xaa = DS1v.get(atom)
> else:
> Xaa = 0
> return Xaa, Xma
> 
> Caa, Cma = monoVarcalc('C')
> Oaa, Oma = monoVarcalc('O')
> Haa, Hma = monoVarcalc('H')
> Naa, Nma = monoVarcalc('N')
> Saa, Sma = monoVarcalc('S')
> Claa, Clma = monoVarcalc('Cl')
> Braa, Brma = monoVarcalc('Br')
> Znaa, Znma = monoVarcalc('Zn')
> 
> 
> 
> i think? :)
> thanks
> 
> a
> 
No fair: you only just added atomsmasses! ;-)

However, it seems to me that your atomsmasses dictionary is going to be 
entirely predictable, and you are still focusing on storing the *names* 
of things rather than building up a usable data structure. Indeed I 
suspect that your problem can be solved using only the names of the 
elements, and not the names of the variables that hold various 
attributes of the elements.

Perhaps if you explain in plain English what you *really* want to do we 
can help you find a more Pythonic solution. It'll probably end up 
something like this:

mass = {}
for element in ['C', 'O', ..., 'Zn']
 mass[element] = monoVarcalc(element)

But I could, of course, be completely wrong ... it wouldn't be the first 
time. Do you understand what I'm saying?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Where do nested functions live?

2006-10-31 Thread Frederic Rentsch
Rob Williscroft wrote:
> Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.python-
> [EMAIL PROTECTED] in comp.lang.python:
>
>   
>>def increment_time (interval_ms):
>>   outer weeks, days, hours, minutes, seconds, mseconds   # 'outer' 
>> akin to 'global'
>>   (...)
>>   mseconds = new_ms - s * 1000# Assignee remains outer
>>   m, seconds = divmod (s, 60)
>>   h, minutes = divmod (m, 60)
>>   d, hours = divmod (h, 24)
>>   weeks, days = divmod (d, 7) # No return necessary
>>
>> The call would now be:
>>
>>increment_time (msec)  # No reassignment necessary
>>
>>
>> Hope this makes sense
>> 
>
> Yes it does, but I prefer explicit in this case:
>
> def whatever( new_ms ):
>   class namespace( object ):
> pass
>   scope = namespace()
>
>   def inner():
> scope.mseconds = new_ms - s * 1000   
> m, scope.seconds = divmod (s, 60)
> h, scope.minutes = divmod (m, 60)
> d, scope.hours = divmod (h, 24)
> scope.weeks, scope.days = divmod (d, 7)
>
>   

This is interesting. I am not too familiar with this way of using 
objects. Actually it isn't all that different from a list, because a 
list is also an object. But this way it's attribute names instead of 
list indexes which is certainly easier to work with. Very good!

> The only thing I find anoying is that I can't write:
>
>   scope = object()
>  
> Additionally if appropriate I can refactor further:
>
> def whatever( new_ms ):
>   class namespace( object ):
> def inner( scope ):
>   scope.mseconds = new_ms - s * 1000   
>   m, scope.seconds = divmod (s, 60)
>   h, scope.minutes = divmod (m, 60)
>   d, scope.hours = divmod (h, 24)
>   scope.weeks, scope.days = divmod (d, 7)
>
>   scope = namespace()
>   scope.inner()
>
> In short I think an "outer" keyword (or whatever it gets called)
> will just add another way of doing something I can already do,
> and potentially makes further refactoring harder.
>
>   

Here I'm lost. What's the advantage of this? It looks more convoluted. 
And speaking of convoluted, what about efficiency? There is much talk of 
efficiency on this forum. I (crudely) benchmark your previous example 
approximately three times slower than a simple inner function taking and 
returning three parameters. It was actually the aspect of increased 
efficiency that prompted me to play with the idea of allowing direct 
outer writes.

> Thats -2 import-this points already.
>
>   

Which ones are the two?

> Rob.
>   

Frederic


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


Re: import in threads: crashes & strange exceptions on dual core machines

2006-10-31 Thread robert
Klaas wrote:
> It seems clear that the import lock does not include fully-executing
> the module contents.  To fix this, just import cookielib before the

What is the exact meaning of "not include fully-executing" - regarding the 
examples "import cookielib" ?
Do you really mean the import statement can return without having executed the 
cookielib module code fully?
(As said, a simple deadlock is not at all my problem)

> threads are spawned.  Better yet, use your own locks around the
> acquisition of the opener instance (this code seems fraughtfully
> thread-unsafe--fix that and you solve other problems besides this one).
> 

thanks. I will probably have to do the costly pre-import of things in main 
thread and spread locks as I have also no other real idea so far.

Yet this costs the smoothness of app startup and corrupts my believe in Python 
capabs of "lazy execution on demand". 
I'd like to get a more fundamental understanding of the real problems than just 
a general "stay away and lock and lock everything without real understanding".

* I have no real explanation why the import of a module like cookielib is not 
thread-safe. And in no way I can really explain the real OS-level crashes on 
dual cores/fast CPU's. Python may throw this and that, Python variable states 
maybe wrong, but how can it crash on OS-level when no extension libs are 
(hopefully) responsible?
* The Import Lock should be a very hard lock: As soon as any thread imports 
something, all other threads are guaranteed to be out of any imports. A dead 
lock is not the problem here.
* cookielib module execution code consists only of definitions and of 
re.compile's. re.compile's should be thread safe?
* the things in my code patter are function local code except "opener = 
urlcookie_openers.get(user)" and "urlcookie_openers[user] = opener" : Simple 
dictionary accesses which are atomic from all my knowledge and experience. I 
think, I have thought about enough, what could be not thread safe. The only 
questionable things have to do with rare change of some globals, but this has  
not at all to do with the severe problems here and could only affect e.g wrong 
url2_proxy or double/unecessary re-creation of an opener, which is uncritical 
in my app.


I'm still puzzled and suspect there is a major problem in Python, maybe in 
win32ui or - no idea ... ?


-robert

==
def f():
   ...
   opener = urlcookie_openers.get(user)
   if not opener:
   import cookielib#<1
   cj=cookielib.CookieJar()#<2 
build_opener = urllib2.build_opener
   httpCookieProcessor = urllib2.HTTPCookieProcessor(cj)
   if url2_proxy:
   opener = build_opener(url2_proxy,httpCookieProcessor)
   else:
   opener = build_opener(httpCookieProcessor)
   opener.addheaders   #$pycheck_no
   opener.addheaders= app_addheaders
   urlcookie_openers[user] = opener
   ufile = opener.open(urllib2.Request(url,data,dict(headers)))
   ...


thread.start_new(f,()) 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python, threading and a radio timer

2006-10-31 Thread ArdPy

Renato wrote:
> Dear all,
>
> I found this nifty article on how to record your favourite radio show
> using cron and mplayer:
> http://grimthing.com/archives/2004/05/20/recording-streaming-audio-with-mplayer/
>
> Because I couldn't get the date in the filename (and was too lazy to
> look into sh/bash manuals), I decided to use Python. It was a good
> choice, because I decided to improve the timer - learning some more
> Python along the way!
>
> So, the idea is:
> - cron runs the script at a specific time
> - the script starts mplayer, and will keep checking the clock until
> it's time to kill mplayer
> - after mplayer has exited, oggenc is started to turn the raw WAV into
> ogg
> - and finally the remaining WAV is deleted
>
> This basic setting is quite easy, and I used os.spawnvp(os.P_WAIT,...),
> along with another CRON entry to kill mplayer.
>
> But then I got more ambitious: I wanted the script to keep checking if
> mplayer was alive - in case the connection goes down. Moreover, I would
> rather have the script stop mplayer than cron.
>
> At this point, I thought I should get some professional help... :) What
> is the right way to go? Would threads be overkill? If so, where can I
> go about looking for process control/management without delving into
> complex daemon architectures?
>
> So, rather than asking for code, I'm looking for guidance - this is a
> didactic experience!
>
> Cheers,
>
> Renato

I would suggest you take a look at Python 'commands' module. The module
lets you run Unix commands by taking them as parameters to function
calls. That is all I can say with my level of expertise.

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


Re: Compile Python With SSL On Solaris 10

2006-10-31 Thread judasi

Martin v. Löwis wrote:
> [EMAIL PROTECTED] schrieb:
> > I am trying to compile py2.4.3/2.5 on a Solaris 10x86 machine, but
> > cannot get it to build an SSL enabled version.  I have added the
> > relevant sfw directories into the path/crle, with no success.  I've
> > even explicitly added ssl via the --with-libs directive, yet an import
> > _ssl still fails.
> >
> > Has anyone else come across this?
>
> setup.py ignores all this. You have to edit Modules/Setup if you want
> to specify non-standard search locations for header files and libraries.
> 
> Regards,
> Martin

That worked a treat, thank you!

Regards

John

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


Re: enumerate improvement proposal

2006-10-31 Thread Steven D'Aprano
On Mon, 30 Oct 2006 23:42:16 +, Steve Holden wrote:

> Divorce is obviously the only answer. How could you end up marrying 
> someone who counts from one and not zero? ;-)


"Should array indices start at 0 or 1? My compromise of 0.5 was rejected
without, I thought, proper consideration." (Stan Kelly-Bootle)


-- 
Steven.

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


Re: How can I import a script with an arbitrary name ?

2006-10-31 Thread Steven D'Aprano
On Tue, 31 Oct 2006 11:00:52 +1100, Ben Finney wrote:

> If you want a solution that gives you an actual module object, here's
> what I use:
> 
> def make_module_from_file(module_name, file_name):
> """ Make a new module object from the code in specified file """
> 
> from types import ModuleType
> module = ModuleType(module_name)
> 
> module_file = open(file_name, 'r')
> exec module_file in module.__dict__
> 
> return module

Isn't that awfully complicated? What's wrong with using __import__ to get
a module object?

>>> mod = __import__("math")
>>> mod



The only advantage (or maybe it is a disadvantage?) I can see to your
function is that it doesn't search the Python path and you can specify an
absolute file name.


-- 
Steven.

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


Re: create global variables?-the full story

2006-10-31 Thread Alistair King
Steve Holden wrote:
> Alistair King wrote:
>   
>> Steve Holden wrote:
>>
>> 
>>> [EMAIL PROTECTED] wrote:
>>>  
>>>
>>>   
 J. Clifford Dyer wrote:



 
> Alistair King wrote:
>  
>   
>>> [... advice and help ...]
>>>
>>>  
>>>
>>>   
 this worked a treat:

 def monoVarcalc(atom):

   a = atom + 'aa'
   Xaa = a.strip('\'')
   m = atom + 'ma'
   Xma = m.strip('\'')
   Xaa = DS1v.get(atom)
   Xma = pt.get(atom)
   return Xaa, Xma


 Caa, Cma = monoVarcalc('C')


 
>>> In which case I suspect you will find that this works just as well:
>>>
>>> def monoVarcalc(atom):
>>>
>>>Xaa = DS1v.get(atom)
>>>Xma = pt.get(atom)
>>>return Xaa, Xma
>>>
>>>
>>> Unless there is something decidedly odd about the side-effects of the 
>>> statements I've removed, since you never appear to use the values of a, 
>>> m, Xaa and Xma there seems little point in calculation them.
>>>
>>> regards
>>>  Steve
>>>  
>>>   
>> Yup...it works..but now i have to create a dictionary of 'a' and 'm',
>> ie... "Xaa" and "Xma" string, key:value pairs so i can use other
>> functions on the Xaa, Xma variables by iterating over them and
>> retrieving the values from the variables. I think if i just input Xaa
>> and Xma, only the values associated with those variables will go into
>> the dictionary and ill just be iterating over nonsence.
>>
>> atomsmasses = {}
>>
>> def monoVarcalc(atom):
>> a = atom + 'aa'
>> m = atom + 'ma'
>> atomsmasses[a]=m
>> Xaa = a.strip('\'')
>> Xma = m.strip('\'')
>> Xma = pt.get(atom)
>> if DS1v.get(atom) != None:
>> Xaa = DS1v.get(atom)
>> else:
>> Xaa = 0
>> return Xaa, Xma
>>
>> Caa, Cma = monoVarcalc('C')
>> Oaa, Oma = monoVarcalc('O')
>> Haa, Hma = monoVarcalc('H')
>> Naa, Nma = monoVarcalc('N')
>> Saa, Sma = monoVarcalc('S')
>> Claa, Clma = monoVarcalc('Cl')
>> Braa, Brma = monoVarcalc('Br')
>> Znaa, Znma = monoVarcalc('Zn')
>>
>>
>>
>> i think? :)
>> thanks
>>
>> a
>>
>> 
> No fair: you only just added atomsmasses! ;-)
>
> However, it seems to me that your atomsmasses dictionary is going to be 
> entirely predictable, and you are still focusing on storing the *names* 
> of things rather than building up a usable data structure. Indeed I 
> suspect that your problem can be solved using only the names of the 
> elements, and not the names of the variables that hold various 
> attributes of the elements.
>
> Perhaps if you explain in plain English what you *really* want to do we 
> can help you find a more Pythonic solution. It'll probably end up 
> something like this:
>
> mass = {}
> for element in ['C', 'O', ..., 'Zn']
>  mass[element] = monoVarcalc(element)
>
> But I could, of course, be completely wrong ... it wouldn't be the first 
> time. Do you understand what I'm saying?
>
> regards
>   Steve
>   
OK...

from the start.

im trying to develop a simple command line application for determining
the degree of substitution (DS) on a polymer backbone from elemental
analysis, i.e., the % weights of different elements in the
monomer-substituent compound ( i want each element to give a result and
heaviest atoms give the most accurate results).

most basic comp chem programs use input files but i dont know anything
about file iteration yet and want the program to be as user friendly as
possible..i.e. command line prompt. GUI would be great but too much for
me at this stage

at the start of the script i have 2 dictionaries 1) containing every
atom in the periodic table with associated isotopic average masses 2)
containing the molecular forumla of the monomer unit...eg for cellulose
AGU {'C': 6, 'H': 10, 'O': 5}.

the basic steps are

1. calculate the weight percentage values for each atom in the monomer
2. iterate into dictionaries from DS=0 - DS=15 (0.5 step) the
projected % values for the monomer plus substituent, for EACH atom in
the compound.
3. find the (local) minimum from each dictionary/atom to give the
appropriate DS value.

*Note* I have to iterate ALL the values as there is a non-linear
relationship between % values and DS due to the different atomic weights
The computer seems to cope with this in about 10 seconds with the above
parameters and about 8 elements for the iteration step

I have a script which works perfectly from some time ago but the problem
is, some of the samples contain excess water so i was going to use the
heaviest atom to give the most accurate DS value i could and then adjust
the polymer back bone dictionary to include the initial substituent from
step 3. Then do the calculation again for water {'H': 2, 'O': 1} as the
new substituent. Once i determine the new 'DS' value of water its simple
to recalculate the % values...iterate..find (local) minima and get more
accurate DS values for all the heavy atoms (not including Hydrogen or
Oxygen).
..

Re: 3d programming without opengl

2006-10-31 Thread nelson -
Hi paul,
 i look at slut and it seem very good... Can i embed it into a
wxpython application?

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


Help me understand this iterator

2006-10-31 Thread LaundroMat
Hi,

I've found this script over at effbot
(http://effbot.org/librarybook/os-path.htm), and I can't get my head
around its inner workings. Here's the script:

import os

class DirectoryWalker:
# a forward iterator that traverses a directory tree

def __init__(self, directory):
self.stack = [directory]
self.files = []
self.index = 0

def __getitem__(self, index):
while 1:
try:
file = self.files[self.index]
self.index = self.index + 1
except IndexError:
# pop next directory from stack
self.directory = self.stack.pop()
self.files = os.listdir(self.directory)
self.index = 0
else:
# got a filename
fullname = os.path.join(self.directory, file)
if os.path.isdir(fullname) and not
os.path.islink(fullname):
self.stack.append(fullname)
return fullname

for file in DirectoryWalker("."):
print file

Now, if I look at this script step by step, I don't understand:
- what is being iterated over (what is being called by "file in
DirectoryWalker()"?);
- where it gets the "index" value from;
- where the "while 1:"-loop is quitted.

Thanks in advance,

Mathieu

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


Re: How can I import a script with an arbitrary name ?

2006-10-31 Thread Fredrik Lundh
Steven D'Aprano wrote:

> The only advantage (or maybe it is a disadvantage?) I can see to your
> function is that it doesn't search the Python path and you can specify an
> absolute file name.

that's the whole point of doing an explicit load, of course.  if you 
think that's a disadvantage, you haven't done enough plugin work...



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


Re: How can I import a script with an arbitrary name ?

2006-10-31 Thread Ben Finney
"Steven D'Aprano" <[EMAIL PROTECTED]> writes:

> On Tue, 31 Oct 2006 11:00:52 +1100, Ben Finney wrote:
>
> > If you want a solution that gives you an actual module object,
> > here's what I use:
> > 
> > def make_module_from_file(module_name, file_name):
> > """ Make a new module object from the code in specified file """
>
> The only advantage (or maybe it is a disadvantage?) I can see to
> your function is that it doesn't search the Python path and you can
> specify an absolute file name.

Which is exactly what the OP asked for (though he didn't necessarily
need a module object).

-- 
 \"We have to go forth and crush every world view that doesn't |
  `\ believe in tolerance and free speech."  -- David Brin |
_o__)  |
Ben Finney

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


Re: Help me understand this iterator

2006-10-31 Thread Fredrik Lundh
LaundroMat wrote:

> Now, if I look at this script step by step, I don't understand:
> - what is being iterated over (what is being called by "file in
> DirectoryWalker()"?);

as explained in the text above the script, this class emulates a 
sequence.  it does this by implementing the __getindex__ method:

 http://effbot.org/pyref/__getitem__

> - where it gets the "index" value from;

from the call to __getitem__ done by the for-in loop.

> - where the "while 1:"-loop is quitted.

the loop stops when the stack is empty, and pop raises an IndexError 
exception.

note that this is an old example; code written for newer versions of 
Python would probably use a recursing generator instead (see the source 
code for os.walk in the standard library for an example).



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


Re: Help me understand this iterator

2006-10-31 Thread Peter Otten
LaundroMat wrote:

> Hi,
> 
> I've found this script over at effbot
> (http://effbot.org/librarybook/os-path.htm), and I can't get my head
> around its inner workings. Here's the script:
> 
> import os
> 
> class DirectoryWalker:
> # a forward iterator that traverses a directory tree
> 
> def __init__(self, directory):
> self.stack = [directory]
> self.files = []
> self.index = 0
> 
> def __getitem__(self, index):
> while 1:
> try:
> file = self.files[self.index]
> self.index = self.index + 1
> except IndexError:
> # pop next directory from stack
> self.directory = self.stack.pop()
> self.files = os.listdir(self.directory)
> self.index = 0
> else:
> # got a filename
> fullname = os.path.join(self.directory, file)
> if os.path.isdir(fullname) and not
> os.path.islink(fullname):
> self.stack.append(fullname)
> return fullname
> 
> for file in DirectoryWalker("."):
> print file
> 
> Now, if I look at this script step by step, I don't understand:
> - what is being iterated over (what is being called by "file in
> DirectoryWalker()"?);
> - where it gets the "index" value from;
> - where the "while 1:"-loop is quitted.

With 

dw = DirectoryWalker(".")

the for loop is equivalent to

index = 0 # internal variable, not visible from Python
while True:
try: 
file = dw[index] # invokes dw.__getitem__(index)
except IndexError:
break
print file

This is an old way of iterating over a sequence which is only used when the
iterator-based approach

dwi = iter(dw) # invokes dw.__iter__()
while True:
try:
file = dwi.next()
except StopIteration:
break
print file

fails.

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


Re: Help me understand this iterator

2006-10-31 Thread Steven D'Aprano
On Tue, 31 Oct 2006 03:36:08 -0800, LaundroMat wrote:

> Hi,
> 
> I've found this script over at effbot
> (http://effbot.org/librarybook/os-path.htm), and I can't get my head
> around its inner workings. 

[snip code]

> Now, if I look at this script step by step, I don't understand:
> - what is being iterated over (what is being called by "file in
> DirectoryWalker()"?);

What is being iterated over is the list of files in the current directory.
In Unix land (and probably DOS/Windows as well) the directory "." means
"this directory, right here".


> - where it gets the "index" value from;

When Python see's a line like "for x in obj:" it does some special
magic. First it looks to see if obj has a "next" method, that is, it
tries to call obj.next() repeatedly. That's not the case here --
DirectoryWalker is an old-style iterator, not one of the fancy new ones.

Instead, Python tries calling obj[index] starting at 0 and keeps going
until an IndexError exception is raised, then it halts the for loop.

So, think of it like this: pretend that Python expands the following code:

for x in obj:
block

into something like this:

index = 0
while True: # loop forever
try:
x = obj[index]
block # can use x in block
except IndexError:
# catch the exception and escape the while loop
break
index = index + 1
# and now we're done, continue the rest of the program

That's not exactly what Python does, of course, it is much more efficient,
but that's a good picture of what happens.


> - where the "while 1:"-loop is quitted.


The while 1 loop is escaped when the function hits the return statement.



-- 
Steven.

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


Re: Where do nested functions live?

2006-10-31 Thread Rob Williscroft
Frederic Rentsch wrote in news:mailman.1536.1162292996.11739.python-
[EMAIL PROTECTED] in comp.lang.python:

> Rob Williscroft wrote:
>> Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.python-
>> [EMAIL PROTECTED] in comp.lang.python:
>>
>>   

>> def whatever( new_ms ):
>>   class namespace( object ):
>> pass
>>   scope = namespace()
>>
>>   def inner():
>> scope.mseconds = new_ms - s * 1000   
>> m, scope.seconds = divmod (s, 60)
>> h, scope.minutes = divmod (m, 60)
>> d, scope.hours = divmod (h, 24)
>> scope.weeks, scope.days = divmod (d, 7)
>>
>>   
> 
> This is interesting. I am not too familiar with this way of using 
> objects. Actually it isn't all that different from a list, because a 
> list is also an object. But this way it's attribute names instead of 
> list indexes which is certainly easier to work with. Very good!
> 

>> In short I think an "outer" keyword (or whatever it gets called)
>> will just add another way of doing something I can already do,
>> and potentially makes further refactoring harder.
>>
>>   
> 
> Here I'm lost. What's the advantage of this? It looks more convoluted.

I'll agree that having to explicitly define a namespace class first
does add some convolution.

But if you refer to having to prefix you "outer" variables with "scope."
then this would be the same as claiming that the explict use of self is
convoluted, which is a valid opinion, so fair enough, but I can't say 
that I agree.

It should also be noted that although I have to declare and create a 
scope object. My method doesn't require the attributes passed back from 
the inner function be pre-declared, should I during coding realise
that I need to return another attribute I just assign it in the inner
function and use it in the outer function. I would count that as less
convoluted, YMMV.
 
> And speaking of convoluted, what about efficiency? There is much talk
> of efficiency on this forum. I (crudely) benchmark your previous 
> example approximately three times slower than a simple inner function 
> taking and returning three parameters. It was actually the aspect of
> increased efficiency that prompted me to play with the idea of 
> allowing direct outer writes.

Did you have optimisation turned on ?

As I see it there should be no reason an optimiser couldn't transform 
my code into the same code we might expect from your "outer keyword"
example, as the scope object's type and attributes are all contained 
within (thus known to) the outer function defenition.

Wether CPython's optimiser does this or not, I don't know.

> 
>> Thats -2 import-this points already.
>>
>>   
> 
> Which ones are the two?

Explicit is better than implicit.
There should be one-- and preferably only one --obvious way to do it.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me understand this iterator

2006-10-31 Thread Peter Otten
LaundroMat wrote:

[me hitting send too soon]

> Now, if I look at this script step by step, I don't understand:

> - where the "while 1:"-loop is quitted.

> class DirectoryWalker:
> # a forward iterator that traverses a directory tree
> 
> def __init__(self, directory):
> self.stack = [directory]
> self.files = []
> self.index = 0
> 
> def __getitem__(self, index):
> while 1:
> try:
> file = self.files[self.index]
> self.index = self.index + 1
> except IndexError:
> # pop next directory from stack
> self.directory = self.stack.pop()

If self.stack is empty, pop() will raise an IndexError which terminates both
the 'while 1' loop in __getitem__() and the enclosing 'for file in ...'
loop

> self.files = os.listdir(self.directory)
> self.index = 0
> else:
> # got a filename
> fullname = os.path.join(self.directory, file)
> if os.path.isdir(fullname) and not
> os.path.islink(fullname):
> self.stack.append(fullname)
> return fullname

The return statement feeds the next file to the for loop.

Peter

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


Python tools for managing static websites?

2006-10-31 Thread Chris Pearl
Are there Python tools to help webmasters manage static websites?

I'm talking about regenerating an entire static website - all the HTML
files in their appropriate directories and sub-directories. Each page
has some fixed parts (navigation menu, header, footer) and some
changing parts (body content, though in specific cases the normally
fixed parts might change as well). The tool should help to keep site
editing DRY every piece of data, including the recurring parts, should
exist only once.

The above should be doable with any decent templating tool, such as
those forming part of most CMSes and full-stack web-frameworks.
Normally I might have just resorted to a CMS/web-framework, running
locally on the webmaster's station, with the only addition being a
mechanism for generating all pages composing the site and saving them
as files.

But such a solution might not be enough, as the system I'm looking for
must be able to control the physical traits of the website as a
collection of files - e.g., creation and distribution of files among
several physical directories and subdirectories.

Any advice would be appreciated,
-Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


concatenating numpy arrays

2006-10-31 Thread Rolf Wester
Hi,

I want to concatenate two numpy arrays with shape (n1,n2) and (n1,n3) 
into a single array with shape (n1,n2+n3). I guess there is an elegant 
way to do this but I couldn't figure it out. So any help is very much 
appreciated.

Regards

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


Re: How can I import a script with an arbitrary name ?

2006-10-31 Thread Steven D'Aprano
On Tue, 31 Oct 2006 12:44:50 +0100, Fredrik Lundh wrote:

> Steven D'Aprano wrote:
> 
>> The only advantage (or maybe it is a disadvantage?) I can see to your
>> function is that it doesn't search the Python path and you can specify an
>> absolute file name.
> 
> that's the whole point of doing an explicit load, of course.  if you 
> think that's a disadvantage, you haven't done enough plugin work...

Guilty as charged.



-- 
Steven.

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


Re: How can I import a script with an arbitrary name ?

2006-10-31 Thread Steven D'Aprano
On Tue, 31 Oct 2006 22:53:56 +1100, Ben Finney wrote:

> "Steven D'Aprano" <[EMAIL PROTECTED]> writes:
> 
>> On Tue, 31 Oct 2006 11:00:52 +1100, Ben Finney wrote:
>>
>> > If you want a solution that gives you an actual module object,
>> > here's what I use:
>> > 
>> > def make_module_from_file(module_name, file_name):
>> > """ Make a new module object from the code in specified file """
>>
>> The only advantage (or maybe it is a disadvantage?) I can see to
>> your function is that it doesn't search the Python path and you can
>> specify an absolute file name.
> 
> Which is exactly what the OP asked for (though he didn't necessarily
> need a module object).

I'm not arguing, you could very well be right, but I'm just curious what
part of the OP's post led you to believe he needed to specify an absolute
filename. Unless I'm missing a second post, he certainly never suggested
that his scripts weren't in the Python path, or that he couldn't add their
location to the path.

*shrug* It probably isn't important -- given the constraints as you read
them (extrapolated them?) your solution looks good.


-- 
Steven.

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


Re: How can I import a script with an arbitrary name ?

2006-10-31 Thread Fredrik Lundh
Steven D'Aprano wrote:

> I'm not arguing, you could very well be right, but I'm just curious what
> part of the OP's post led you to believe he needed to specify an absolute
> filename. Unless I'm missing a second post, he certainly never suggested
> that his scripts weren't in the Python path, or that he couldn't add their
> location to the path.

the fact that he's using dashes in the module name might be a hint, though.

in current versions, __import__ doesn't care as long as the file has
the right extension, but import requires valid Python identifiers, for 
obvious reasons.

execfile doesn't care about any part of the filename, of course (and if 
you replace it with exec, you don't even have to read the script from a 
file).



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


Re: Python tools for managing static websites?

2006-10-31 Thread UrsusMaximus
Firedrop2 is a content management system for static web sites. I have
used it to manage www.awaretek.com for 3-4 yearts now. it is perfect
for what you descibe. You can mkae a change in format and apply it to
all pages in a flash. It is very stable, and it is easy to use. It is
written in Python, actively maintained by Michael foord, and you can
easi;ly extend it with Python plugins. Open source, free as in beer,
etc. 

http://www.voidspace.org.uk/python/firedrop2/

Ron Stephens

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


Re: Printing out the objects stack

2006-10-31 Thread Fabiano Sidler
On Sunday 29 October 2006 17:48, I wrote:
> Now the following things are not clear to me:
> -Why does the VM crash? Did I use the wrong stack boundaries?
> -Why are no locales printed?
> -Why is the function "stack" not right before or after "foo"
>  on the stack? When I disassemble the code of f with dis.dis,
>  it reveals that sys.stack and foo are pushed onto the stack
>  successively.

No hints?

Greetings,
Fips
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: concatenating numpy arrays

2006-10-31 Thread Travis E. Oliphant
Rolf Wester wrote:
> Hi,
> 
> I want to concatenate two numpy arrays with shape (n1,n2) and (n1,n3) 
> into a single array with shape (n1,n2+n3). I guess there is an elegant 
> way to do this but I couldn't figure it out. So any help is very much 
> appreciated.
> 

Suppose a1.shape is (n1,n2)
and a2.shape is (n1,n3)

Then you want to do

a3 = concatenate((a1,a2),axis=1)

or equivalently

a3 = hstack([a1,a2])

a3 = r_['1',a1,a2]


-Travis



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


Re: Event driven server that wastes CPU when threaded doesn't

2006-10-31 Thread Jean-Paul Calderone
On Tue, 31 Oct 2006 07:33:59 GMT, Bryan Olson <[EMAIL PROTECTED]> wrote:
>Snor wrote:
>> I'm attempting to create a lobby & game server for a multiplayer game,
>> and have hit a problem early on with the server design. I am stuck
>> between using a threaded server, and using an event driven server. I've
>> been told time and time again that I should use an event driven server
>> design (that is, use twisted).
>
>I didn't hear the specifics of how you got that advice, so I
>can't comment specifically. I will say that I've have heard a
>lot of advice against threads that struck me as simply naive.

Much of it is quite well informed.

>
>> There is a lot of interaction between the clients and they would often
>> need to write to the same list of values, which of course becomes a
>> problem with a threaded server - so event driven solves that problem,
>> and I assumed it would solve all my problems. [...]
>
>The purely event-driven style solves some problems, but creates
>others. You're forced to structure your code around the blocking
>behavior, and that's not the structure anyone would choose for
>clarity or maintainability.

This is not the case.  However, much event-driven code is written
this way anyway, intentionally, for clarity.  If you _want_ opaque
code, or for some reason think it is not opaque to write code in this
manner, then there you can use a library which supports this.

>
>Suppose we're enhancing an event-driven system, and decide to
>relocate some datum from a variable to the database. Suppose in
>one or more places, accessing the data happens in a call chain
>several function down from the event loop. We can't just change
>the function that accesses the data because a synchronous
>database call could block and stop event processing. Every
>interface on the call chain is broken.

As it must be, because you have changed the atomicity of an operation.
Transparently propagating this up a call stack leads to bugs which are
similar to those found in a system based on pre-emptive multithreading.

>
>[...]
>> I will want the server to support as many users as is possible on any
>> given machine - and so wasted CPU cycles is something I am trying to
>> avoid.
>
>Python is a great scripting language, but squeezing out machine
>performance is not where scripting languages shine. That said, you
>might start in Python, to see if your system is successful and the
>performance of your server really is a limiting factor.
>
>
>> Is the only solution to use a threaded server to let my clients make
>> their requests and receive a response in the fastest possible time?
>
>Maybe. Probably not. It's all good -- multi-threading is your friend.
>

Multithreading is _someone's_ friend.  Probably not the OP's, whose
original post made it sound very strongly like he just needed network
concurrency, which is a perfectly fine use-case for event-driven style
rather than pre-emptive threading.

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


Re: 3d programming without opengl

2006-10-31 Thread Paul McGuire
"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> Looks like c.l.py just slashdotted you ... """The GeoCities web site you 
> were trying to view has temporarily exceeded its data transfer limit. 
> Please try again later."""
>
> regards
>  Steve
> -- 
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb   http://holdenweb.blogspot.com
> Recent Ramblings http://del.icio.us/steve.holden
>

It didn't take long either!  I replaced the 1.4M .swf file with a 170K .swf 
file, so things seem to be working again.  (My b/w limit is 4.2M/hour, but I 
can't complain when it's free!)

-- Paul


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


Re: Help me understand this iterator

2006-10-31 Thread LaundroMat
Ack, I get it now. It's not the variable's name ("index") that is
hard-coded, it's just that the for...in... loop sends an argument by
default. That's a lot more comforting.

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


Re: Tkinter Listbox string formatting question - how to kill a dancingsnake ?

2006-10-31 Thread Hendrik van Rooyen

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote:


> instead of trying to force the listbox to behave like a multicolumn
> widget, maybe you could switch to another widget?  some alternatives include
>
>  a Text widget (you have to roll your own selection logic)

I _really_ don't feel strong enough for this, or for sticking them loose on a
canvas...

>  bwidgets multicolumn ListBox:
>  http://tkinter.unpythonic.net/bwidget/
>  tktable:
>  http://tktable.sourceforge.net/
>  something based on the wck (that's what I'd would use myself):
>  http://effbot.org/zone/wck-4.htm
>  and perhaps there's something in Pmw:
>  http://pmw.sourceforge.net
> 

Thanks I will check these out...

- Hendrik

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


Re: Help me understand this iterator

2006-10-31 Thread LaundroMat
Thanks all, those were some great explanations. It seems I have still
still a long way for me to go before I grasp the intricacies of this
language.

That 'magic index' variable bugs me a little however. It gives me the
same feeling as when I see hard-coded variables. I suppose the
generator class has taken care of this with its next() method (although
- I should have a look - __next__() probable takes self and index as
its arguments). Although I'm very fond of the language (as a
non-formally trained hobbyist developer), that "magic" bit is a tad
disturbing.

Still, thanks for the quick and complete replies!

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


Re: Python tools for managing static websites?

2006-10-31 Thread Walter Dörwald
Chris Pearl wrote:

> Are there Python tools to help webmasters manage static websites?
> 
> [...]

You might give XIST a try: http://www.livinglogic.de/Python/xist/

Basically XIST is an HTML generator, that can be extended to generate
the HTML you need for your site. The website
http://www.livinglogic.de/Python/ itself was generated with XIST. You
can find the source for the website here:
http://www.livinglogic.de/viewcvs/index.cgi/LivingLogic/WWW-Python/site/

Hope that helps!

Bye,
   Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Listbox string formatting question - how to kill adancingsnake ?

2006-10-31 Thread Hendrik van Rooyen
"Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:

> "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:
>
> > instead of trying to force the listbox to behave like a multicolumn
> > widget, maybe you could switch to another widget?  some alternatives include
> >
> >  a Text widget (you have to roll your own selection logic)
>
> I _really_ don't feel strong enough for this, or for sticking them loose on a
> canvas...
8<

sorry - thought has just occurred to me - my basic problem is text formatting,
as variable width fonts make it difficult to get two things to line up under one
another by using spaces as padding  - so how would the Text widget have
helped me with this ?  or - Luxury ! - can I set a tab stop in pixels ?
- maybe I can catch a general clue here...

- Hendrik


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


Re: Help me understand this iterator

2006-10-31 Thread Fredrik Lundh
LaundroMat wrote:

> That 'magic index' variable bugs me a little however. It gives me the
> same feeling as when I see hard-coded variables. 

what magic index?  the variable named "index" is an argument to the 
method it's used in.



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


Re: Python tools for managing static websites?

2006-10-31 Thread Paul Boddie
Walter Dörwald skrev:
> Chris Pearl wrote:
>
> > Are there Python tools to help webmasters manage static websites?
>
> You might give XIST a try: http://www.livinglogic.de/Python/xist/

See also the list on the python.org Wiki:

http://wiki.python.org/moin/Templating

The "Static Website Generators" section has some references to various
tools, although I note that XIST is only featured in the "HTML
Generation Packages" section.

Paul

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


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-31 Thread John Salerno
abcd wrote:
> On Oct 30, 3:47 pm, John Salerno <[EMAIL PROTECTED]> wrote:
>> I noticed that one object you refer to is
>> self.textPane, is that supposed to be self.textPanel?
> 
> no, self.textPane is the actual wx.TextCtrl.
> 
> I used a GUI Builder to the layout stuff...perhaps that's my problem :)
> 
> is there a good site to refer to for how to use sizers?  i am
> essentially creating a chat window (textPane is the history of the
> chat, then a textCtrl below it for typing a new message and a button
> next to the input field and buttons below the input field).
> 

After I watched the screencasts for how Dabo uses sizers, I really 
understood them a lot better. I've never used Dabo itself for GUI 
design, but the screencast, though it shows them in terms of that 
program, still gives a great visual presentation of how sizers work in 
general and I suggest you take a look at that:

http://leafe.com/screencasts/sizers1.html
http://leafe.com/screencasts/sizers2.html

P.S. I suggest you post the full code to the wxPython mailing list. I'll 
take a look at it to see if anything strikes me, but also you will have 
a ton of other (more experienced) people looking at it too, and I 
guarantee they will spot your problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


PIL on Python 2.4 - ImportError: No module named _imagingft

2006-10-31 Thread Nico Grubert
Dear list members,

I have installed Python 2.4.3. and PIL 1.1.5. on a Suse Linux 10 64 Bit 
machine.

If I try

  >>> import _imagingft

I get this error:
   ImportError: No module named _imagingft

Did I miss something?
On my 32 But Linux with Python 2.3.5. everything works fine.

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


Re: What is the cleanest way to for a module to access objects from the script that imports it?

2006-10-31 Thread Michael L Torrie
On Fri, 2006-10-27 at 14:53 -0700, [EMAIL PROTECTED] wrote:
> Hi,
> 
> I am new to python and am currently writing my first application. One
> of the problems I quickly ran into, however, is that python's imports
> are very different from php/C++ includes in the sense that they
> completely wrap the imported script in a module object. One of the
> problems with this was that a plugin system that I am making requires
> use of objects, classes and the such from the original script. Thus, on
> one hand, I am hesitant to use execfile(), since I *do* want to wrap
> the plugin up, but on the other hand, I want the plugin to be able to
> use functions from the original script. Any ideas?

I have a system that uses modules as plugins also.  These are loaded
dynamically when the user specifies them from a gui.  I put all these
modules in an array using the __import__ function.  I found, though,
that I needed to specify whether or not each module had actually loaded,
or if there had been an exception (module not found or whatever).  So I
wrote a wrapper object that would try to load the module and store it as
a local attribute.  I made my wrapper object implement functions like
__getattr__ and pass any unknown calls into the module object itself,
making the wrapper object act as if it was the module, but having extra
capabilities, such as being able to tell me if the module had actually
loaded or not.

Michael


> 
> Sincerely,
> Noam Samuel.
> 

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


Re: Python tools for managing static websites?

2006-10-31 Thread Fuzzyman

Chris Pearl wrote:
> Are there Python tools to help webmasters manage static websites?
>

rest2web is a tool designed specifically for creating and managing
static websites. It uses templates and has built-in tools to aid with
creating side bars and navigation trails.

It allows you to store your pages in reStructured Text or HTML format.
It gives you full control of the 'shape' (in terms of directories) of
both your source files and target files (the html it generates).

http://www.voidspace.org.uk/python/rest2web/

Fuzzyman

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


Re: Help me understand this iterator

2006-10-31 Thread LaundroMat
On Oct 31, 3:53 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> LaundroMat wrote:
> > That 'magic index' variable bugs me a little however. It gives me the
> > same feeling as when I see hard-coded variables.what magic index?  the 
> > variable named "index" is an argument to the
> method it's used in.

Yes, I reacted too quickly. Sorry.

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


Re: PIL on Python 2.4 - ImportError: No module named _imagingft

2006-10-31 Thread Fredrik Lundh
Nico Grubert wrote:

> I have installed Python 2.4.3. and PIL 1.1.5. on a Suse Linux 10 64 Bit 
> machine.
> 
> If I try
> 
>   >>> import _imagingft
> 
> I get this error:
>ImportError: No module named _imagingft
> 
> Did I miss something?

installed how?  _imagingft is an optional component, and requires the 
FreeType library to work.



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


Re: scared about refrences...

2006-10-31 Thread SpreadTooThin

J. Clifford Dyer wrote:
> SpreadTooThin wrote:
> > J. Clifford Dyer wrote:
> >> SpreadTooThin wrote:
> >>> Steven D'Aprano wrote:
>  On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
> 
> 
> >>> I seems that some of the objects in the list don't get along well with
> >>> deep copy..
> >>> See my second example post that used deepcopy... When run blows up...
> >>>
> >> When it blows up, is there a lot of shrapnel, or just smoke and fire?
> >> Is the shrapnel mostly metal, or is it plastic and glass?
> >>
> >> In short, if we don't know what's happening, we can't help.
> >> * Did the program spit out a bunch of text you didn't understand?
> >>If so, show us the text.  That text may be incomprehensible at first,
> >>but it contains crucial clues.
> >>
> >> * Did it close your python window without a word?
> >>Tell us.
> >>
> >> * Did your computer freeze up?
> >>Tell us.
> >>
> >> If you don't tell us what went wrong *exactly*, you won't get a
> >> satisfactory answer.
> >>
> >
> > I would assume that looking at the code you should be able to tell..
> > Silly me..  Here.. is the log.. If I were helping.. I would have cut
> > and pasted the code myself and ran it.. instead of trying to interpret
> > this...
>
> I know it seems unnecessary to post the traceback when I could get the
> same thing by running your code on my machine, but it's actually useful,
> for a couple reasons:  First, when I run the code, I might not get an
> error, or if I do, it might not be the same error you were getting, and
> then we'd be on a wild goose chase.  This could be because your python
> installation is goofy, or because you copied in your code incorrectly.
> Shit happens, and I'd rather not even start down one of those blind
> alleys.  Third, it provides a useful frame for how to look at your
> code.  While a traceback might look like a big mess at first, it's
> actually pretty easy to skim through once you get used to it, and it
> tells me where to focus my attention in your code.
>
> >
> > array('H', [1, 2, 3]) ['a', 'b', 'c']
> > Traceback (most recent call last):
> >   File
> > "/Volumes/Data/Users/bjobrien/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py",
> > line 1806, in runMain
> > self.dbg.runfile(debug_args[0], debug_args)
> >   File
> > "/Volumes/Data/Users/bjobrien/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py",
> > line 1529, in runfile
> > h_execfile(file, args, module=main, tracer=self)
> >   File
> > "/Volumes/Data/Users/bjobrien/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py",
> > line 590, in __init__
> > execfile(file, globals, locals)
> >   File "/Volumes/Data/Users/bjobrien/Desktop/pythonDICOM/Text-1.py",
> > line 20, in __main__
> > test(t)
> >   File "/Volumes/Data/Users/bjobrien/Desktop/pythonDICOM/Text-1.py",
> > line 16, in test
> > t = copy.deepcopy(x)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
> > line 174, in deepcopy
> > y = copier(x, memo)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
> > line 305, in _deepcopy_inst
> > state = deepcopy(state, memo)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
> > line 174, in deepcopy
> > y = copier(x, memo)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
> > line 268, in _deepcopy_dict
> > y[deepcopy(key, memo)] = deepcopy(value, memo)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
> > line 185, in deepcopy
> > y = copier(x, memo)
> > TypeError: __deepcopy__() takes no arguments (1 given)
> >
> >
> >
> >> Cheers,
> >> Cliff
> >
>
> Thanks, that's very helpful.  Playing with your code a bit, I narrowed
> the problem down to the array.array() structure.  Looking at
> help(array), there's a method defined called __deepcopy__, which, it
> seems, takes no arguments, while deepcopy is passing it one argument.
> Looks like a bug in the array module to me.  Maybe others with more
> experience using array will have some deeper insight.
>
>

I don't understand why python would insist that everything must be a
refrence...
It is of course helpful sometime but other times its not...  and now
I'm sorta out
of luck...
I don't know how to make this structure immutable...  Pickle it?  Seems
very
inefficient to me...
Every time I pass a variable now I will worry that it will be changed
by the function...
I haven't worried about things like this since the very early days of
BASIC
I don't know.. maybe I have more to learn.


> Cheers,
> Cliff

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


Re: Python tools for managing static websites?

2006-10-31 Thread jkn
Hi there

I used cheetah (cheetahtemplate) and a makefile for something similar
;-). It worked pretty well for me. I only have a dozen or so pages
though.

I'm currently converting this to Jinja, which is a similar templating
system compatible with Django. I plan to later migrate to dynamic pages
under Django.

http://www.cheetahtemplate.org
http://wsgiarea.pocoo.org/jinja/

HTH
Jon N

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


Re: scared about refrences...

2006-10-31 Thread Tim Chase
> I don't know how to make this structure immutable...  Pickle 
> it?  Seems very inefficient to me...

Well, classes can be made mostly immutable by intercepting the 
attempts to write to it...something like

class Foo(object):
 def __setattr__( self, name, val ):
 raise TypeError("I'm sorry, Dave.  You can't do that.")

It might also be feasible to do something like this with a 
decorator...?

> Every time I pass a variable now I will worry that it will be
> changed by the function... I haven't worried about things like
> this since the very early days of BASIC I don't know..
> maybe I have more to learn.

Well, there are at least solutions to this paranoia that occur to me:

-make a deep-copy of the object in question before calling the 
function, and then pass the copy to the function so that it can't 
alter the original

-trust/read the functions' documentation.  Most functions that 
alter the contents of their parameters are kind enough to note as 
much.  If functions go bunging with your parameters without 
documenting it, the function's coder needs to be smacked.

-tkc




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


Re: enumerate improvement proposal

2006-10-31 Thread Raymond Hettinger
James Stroud wrote:
> I think that it would be handy for enumerate to behave as such:
>
> def enumerate(itrbl, start=0, step=1):
>i = start
>for it in itrbl:
>  yield (i, it)
>  i += step

I proposed something like this long ago and Guido has already rejected
it.  Part of the reason is that it doesn't match his mental model of
enumerate being about pairing sequence elements with their indices.
Another reason is that the syntax has more than one obvious
interpretation:

 enumerate('abcdef', 2) -->  (2, 'c'), (3, 'd'), ...
 enumerate('abcdef', 2) -->  (0, 'c'), (1, 'd'), ...
 enumerate('abcdef', 2) -->  (2, 'a'), (2, 'b'), ...

Also, the order of arguments is odd in comparison with the output order
-- this suggests a syntax like enumerate(2, 'abcdef') --> (2, 'a'), (3,
'b') ...

FWIW, it is not hard to roll-your-own with something like:

for pagenum, page in izip(count(1), book): ...

The izip/count combination runs at C speed, matches enumerate() in its
efficiency, and is arguably clearer in expressing its intended
behavior.


Raymond

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


Re: ANN: Leo 4.4.2.1 final released

2006-10-31 Thread John Henry
Yes, it's Python 2.3, running under Windows XP.

I managed to get it working using the ZIP file.

Thanks,

Edward K. Ream wrote:
> >I downloaded the Windows exe, ran it and a small blank message window poped
> >up and that was it.
> > I am still running 2.3.
>
> I assume you mean Python 2.3, not Leo 2.3 :-)  I know for sure that Leo
> works with Python 2.3. In the future, please report problems to one of Leo's
> forums.  And when reporting problems please tell me what platform you are
> using.
>
> You can probably see more information by running Leo in a console.  See
> Leo's FAQ for instructions:
> http://webpages.charter.net/edreamleo/FAQ.html#how-can-i-run-leo-from-a-console-window
>
> Edward
> 
> Edward K. Ream   email:  [EMAIL PROTECTED]
> Leo: http://webpages.charter.net/edreamleo/front.html
> 

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


Re: ANN: Leo 4.4.2.1 final released

2006-10-31 Thread John Henry
Yes, it's Python 2.3, running under Windows XP.

I managed to get it working using the ZIP file.

Thanks,

Edward K. Ream wrote:
> >I downloaded the Windows exe, ran it and a small blank message window poped
> >up and that was it.
> > I am still running 2.3.
>
> I assume you mean Python 2.3, not Leo 2.3 :-)  I know for sure that Leo
> works with Python 2.3. In the future, please report problems to one of Leo's
> forums.  And when reporting problems please tell me what platform you are
> using.
>
> You can probably see more information by running Leo in a console.  See
> Leo's FAQ for instructions:
> http://webpages.charter.net/edreamleo/FAQ.html#how-can-i-run-leo-from-a-console-window
>
> Edward
> 
> Edward K. Ream   email:  [EMAIL PROTECTED]
> Leo: http://webpages.charter.net/edreamleo/front.html
> 

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


Re: Python tools for managing static websites?

2006-10-31 Thread Harry George
Walter Dörwald <[EMAIL PROTECTED]> writes:

> Chris Pearl wrote:
> 
> > Are there Python tools to help webmasters manage static websites?
> > 
> > [...]
> 
> You might give XIST a try: http://www.livinglogic.de/Python/xist/
> 
> Basically XIST is an HTML generator, that can be extended to generate
> the HTML you need for your site. The website
> http://www.livinglogic.de/Python/ itself was generated with XIST. You
> can find the source for the website here:
> http://www.livinglogic.de/viewcvs/index.cgi/LivingLogic/WWW-Python/site/
> 
> Hope that helps!
> 
> Bye,
>Walter Dörwald

1. If the static page can be autogenerated (e.g., from a data file or
   from an analysis), the best bet is to just write the html directly.
   Typically do as triple quoted text blocks with named variable
   substitutions, then print them with the substitutions filled.  The
   chunks are dictated by the structure of the problem (e.g.,
   functions for beginning and end of html page, for beginning and end
   of a form, for repeating rows in a table, etc.)  Just structure the
   app reasonably and put in the chnks where needed.

   NOTE -  When I first moved from Perl to Python, I thought I'd need
   CGI.pm, so I did cgipm.py:
   http://www.seanet.com/~hgg9140/comp/index.html
   http://www.seanet.com/~hgg9140/comp/cgipm/doc/manual.html

   However, I (and others in this newsgroup) recommend the
   write-directly approach instead.

2. If there must be human-in-the-loop, then it is good to use a markup
   language which can be converted to html (or to other backends).
   Perrl's POD format is one, and I've done that as a Pdx.

   http://www.seanet.com/~hgg9140/comp/index.html
   http://www.seanet.com/~hgg9140/comp/pdx/doc/manual.html


-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: 3d programming without opengl

2006-10-31 Thread Stephen Eilert

nelson - wrote:
> hi!
>i want to build up a simple 3d interactive geometry application in
> python. Since i want to run it without 3D acceleration (a scene will
> be quite simple) I was wondering if there was a library in python that
> allow me to build 3D graphic without the need to use OpenGL I
> google but i can't find nothing interesting... (the best would be a
> pure python solution)
>
> Thanks,
>   nelson

I have no idea why you would want to do that. The fact that the scene
is simple shouldn't be the only reason. After all, if a user is able to
run the latest  but your simple
scene runs much slower, he is going to assume there is something wrong
with it.

If the target user has even a simple 3D accelerator, you are taking a
huge performance hit. That shouldn't be done without a good reason.
What's more, giving it is should be a pure Python solution, you won't
even take advantage of MMX/SSE/3d now!, which all recent processors
have. I'm avoiding talking about raw Python performance here.

I did that once, so that I could learn how to make a software renderer,
but that's not your case, since it is a library you are looking for.
Perhaps there are other requirements that require what you are asking
for, but I can't see in your message.


Stephen

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


Re: Where do nested functions live?

2006-10-31 Thread Frederic Rentsch
Rob Williscroft wrote:
> Frederic Rentsch wrote in news:mailman.1536.1162292996.11739.python-
> [EMAIL PROTECTED] in comp.lang.python:
>
>   
>> Rob Williscroft wrote:
>> 
>>> Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.python-
>>> [EMAIL PROTECTED] in comp.lang.python:
>>>
>>>   
>>>   
>
>   
>>> def whatever( new_ms ):
>>>   class namespace( object ):
>>> pass
>>>   scope = namespace()
>>>
>>>   def inner():
>>> scope.mseconds = new_ms - s * 1000   
>>> m, scope.seconds = divmod (s, 60)
>>> h, scope.minutes = divmod (m, 60)
>>> d, scope.hours = divmod (h, 24)
>>> scope.weeks, scope.days = divmod (d, 7)
>>>
>>>   
>>>   
>> This is interesting. I am not too familiar with this way of using 
>> objects. Actually it isn't all that different from a list, because a 
>> list is also an object. But this way it's attribute names instead of 
>> list indexes which is certainly easier to work with. Very good!
>>
>> 
>
>   
>>> In short I think an "outer" keyword (or whatever it gets called)
>>> will just add another way of doing something I can already do,
>>> and potentially makes further refactoring harder.
>>>
>>>   
>>>   
>> Here I'm lost. What's the advantage of this? It looks more convoluted.
>> 
>
> I'll agree that having to explicitly define a namespace class first
> does add some convolution.
>
> But if you refer to having to prefix you "outer" variables with "scope."
> then this would be the same as claiming that the explict use of self is
> convoluted, which is a valid opinion, so fair enough, but I can't say 
> that I agree.
>
>   

I didn't mean to call into question. I didn't understand the advantage 
of the added complexity of your second example over the first.

> It should also be noted that although I have to declare and create a 
> scope object. My method doesn't require the attributes passed back from 
> the inner function be pre-declared, should I during coding realise
> that I need to return another attribute I just assign it in the inner
> function and use it in the outer function. I would count that as less
> convoluted, YMMV.
>   

That is certainly a very interesting aspect.
>  
>   
>> And speaking of convoluted, what about efficiency? There is much talk
>> of efficiency on this forum. I (crudely) benchmark your previous 
>> example approximately three times slower than a simple inner function 
>> taking and returning three parameters. It was actually the aspect of
>> increased efficiency that prompted me to play with the idea of 
>> allowing direct outer writes.
>> 
>
> Did you have optimisation turned on ?
>
>   

No. I did a hundred thousand loops over each in IDLE using xrange.

> As I see it there should be no reason an optimiser couldn't transform 
> my code into the same code we might expect from your "outer keyword"
> example, as the scope object's type and attributes are all contained 
> within (thus known to) the outer function defenition.
>
>   

I doubt that very much. The 'outer' keyword would give me the choice 
between two alternatives. Such a choice can hardly be automated.

> Wether CPython's optimiser does this or not, I don't know.
>
>   
>>> Thats -2 import-this points already.
>>>
>>>   
>>>   
>> Which ones are the two?
>> 
>
> Explicit is better than implicit.
> There should be one-- and preferably only one --obvious way to do it.
>
> Rob.
>   


Frederic


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


"best" rational number library for Python?

2006-10-31 Thread skip
A guy at work asked for functionality commonly found with rational numbers,
so I said I'd find and install something.  I figured gmpy would be suitable,
alas I'm having trouble successfully building the underlying GMP 4.2.1
library on a PC running Solaris 10 (won't compile with the default --host,
fails "make check" if I go the no-assembly route).  Before I invest a bunch
of time into this, am I barking up the wrong tree?

Performance is, for now, certainly not an issue.  Even a pure Python
rational number class would probably suffice.

Thx,

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


Missing _init_types in MS VisualStudio 2005 (PCBuild8)

2006-10-31 Thread Donovan Kolbly
Hi folks,

I was trying to build Python using MS VisualStudio 2005 (VC++ 8.0)
according to the instructions in PCBuild8/ and got a link error
in config.obj referencing _init_types.

I (barely) know enough about VS 2005 to add files to the project, so I
added Modules/_typesmodule.c to the pythoncore subproject, and that
seemed to fix it -- I can now build the python executable.

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


Re: 3d programming without opengl

2006-10-31 Thread Paul McGuire
"nelson -" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi paul,
> i look at slut and it seem very good... Can i embed it into a
> wxpython application?
>
> thanks,
> nelson

I've no earthly idea, nelson, sorry.  The sphere program is the extent of my 
slut experience (for which my wife is quite grateful!).  I think the slut 
website mentions a mailing list, that should be able to answer your 
technical questions.

Good luck!
-- Paul


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


Re: PIL on Python 2.4 - ImportError: No module named _imagingft [Solved]

2006-10-31 Thread Nico Grubert
> If I try
> 
>  >>> import _imagingft
> 
> I get this error:
>   ImportError: No module named _imagingft
> 
> Did I miss something?

Yes, I did. Somehow, there was no "_imagingft.so" in the PIL directory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "best" rational number library for Python?

2006-10-31 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Performance is, for now, certainly not an issue.  Even a pure Python
> rational number class would probably suffice.

There are certainly some of those around, but I'm surprised there's a
problem with GMP and Solaris.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "best" rational number library for Python?

2006-10-31 Thread skip

Paul> There are certainly some of those around, but I'm surprised
Paul> there's a problem with GMP and Solaris.

That was my thought as well.

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


Re: Event driven server that wastes CPU when threaded doesn't

2006-10-31 Thread Bjoern Schliessmann
Fredrik Lundh wrote:

> by running the database queries in one or more separate threads,
> you can still serve requests that don't hit the database (either
> because they're entirely self-contained, or because they only rely
> on cached data).

Nothing that couldn't also be solved without threads. :)

Regards,


Björn

-- 
BOFH excuse #362:

Plasma conduit breach

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


Overriding traceback print_exc()?

2006-10-31 Thread Bob Greschke
I want to cause any traceback output from my applications to show up in one 
of my dialog boxes, instead of in the command or terminal window (between 
running on Solaris, Linux, OSX and Windows systems there might not be any 
command window or terminal window to show the traceback messages in).  Do I 
want to do something like override the print_exc (or format_exc?) method of 
traceback to get the text of the message and call my dialog box routine?  If 
that is right how do I do that (monkeying with classes is all still a grey 
area to me)?

I kind of understand using the traceback module to alter the output of 
exceptions that I am looking for, but I'm after those pesky ones that should 
never happen. :)

Thanks!

Bob


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


Re: scared about refrences...

2006-10-31 Thread Gabriel Genellina

At Tuesday 31/10/2006 14:16, SpreadTooThin wrote:


I don't understand why python would insist that everything must be a
refrence...
It is of course helpful sometime but other times its not...  and now
I'm sorta out
of luck...
I don't know how to make this structure immutable...  Pickle it?  Seems
very
inefficient to me...
Every time I pass a variable now I will worry that it will be changed
by the function...
I haven't worried about things like this since the very early days of
BASIC
I don't know.. maybe I have more to learn.


If you haven't read this yet, you should: 




--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Danny Colligan
In the following code snippet, I attempt to assign 10 to every index in
the list a and fail because when I try to assign number to 10, number
is a deep copy of the ith index (is this statement correct?).

>>> a = [1,2,3,4,5]
>>> for number in a:
... number = 10
...
>>> a
[1, 2, 3, 4, 5]

So, I have to resort to using enumerate to assign to the list:

>>> for i, number in enumerate(a):
... a[i] = 10
...
>>> a
[10, 10, 10, 10, 10]

My question is, what was the motivation for returning a deep copy of
the value at the ith index inside a for loop instead of the value
itself?  Also, is there any way to assign to a list in a for loop (with
as little code as used above) without using enumerate?

Thanks,

Danny

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


Re: scared about refrences...

2006-10-31 Thread Fredrik Lundh
SpreadTooThin wrote:

> Every time I pass a variable now I will worry that it will be changed
> by the function...

why?  who's writing those scary functions that you cannot trust?  and 
what makes you think they won't abuse any immutable data you give them?



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


Re: FreeImagePy creating thumbnails from TIFF

2006-10-31 Thread Michele Petrazzo
[EMAIL PROTECTED] wrote:
> I a trying to create a series of thumbnail images from a multpage 
> TIFF file.  The sample code is below.  When it executes, we get the 
> following error; FreeImagePy.constants.FreeImagePy_ColorWrong: 'Wrong
>  color 1 in function: FreeImage_MakeThumbnail. I can use: (8, 24,
> 32)'
> 
> 
> Any suggestions?
> 

Found a bug!
Change, into the funct_list, at line 119,
('FreeImage_MakeThumbnail', '@12', (CO.COL_8, CO.COL_24, CO.COL_32) ),
to
('FreeImage_MakeThumbnail', '@12', CO.COL_1TO32 ),
and it'll work.
Or update to the new svn version (r21), that adds the
__iter__ method for the Image class. Now you can do this:

fname = "01-PJ2306.tif"
img = FIPY.Image(fname)

for bmp in img:
 new_img = bmp.thumbnail(300)

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


Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Fredrik Lundh
Danny Colligan wrote:

> My question is, what was the motivation for returning a deep copy of
> the value at the ith index inside a for loop instead of the value
> itself? 

I'm not sure the words "deep copy" and "value" really means what you 
think they do.  maybe you should spend a little time with Python's 
documentation, instead of making up absurd theories about how things 
might work, only to get disappointed every time reality disagrees.

> Also, is there any way to assign to a list in a for loop (with
> as little code as used above) without using enumerate?

what's wrong with using enumerate?  or a list comprehension?  or some 
other of the many different ways you can use to build a list from a set 
of values?



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


Re: "best" rational number library for Python?

2006-10-31 Thread Gabriel Genellina

At Tuesday 31/10/2006 14:53, [EMAIL PROTECTED] wrote:


A guy at work asked for functionality commonly found with rational numbers,
so I said I'd find and install something.  I figured gmpy would be suitable,
alas I'm having trouble successfully building the underlying GMP 4.2.1
library on a PC running Solaris 10 (won't compile with the default --host,
fails "make check" if I go the no-assembly route).  Before I invest a bunch
of time into this, am I barking up the wrong tree?


Try clnum included in:
http://sourceforge.net/projects/calcrpnpy


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: 3d programming without opengl

2006-10-31 Thread Grant Edwards
On 2006-10-31, nelson - <[EMAIL PROTECTED]> wrote:

>i want to build up a simple 3d interactive geometry application in
> python. Since i want to run it without 3D acceleration (a scene will
> be quite simple)

If you just want slow, it's probably easier to use OpenGL and
just put calls to time.sleep() in strategic places.

> I was wondering if there was a library in python that allow me
> to build 3D graphic without the need to use OpenGL I
> google but i can't find nothing interesting... (the best would
> be a pure python solution)

Oy.  A pure Python solution would probably be _really_ slow.

-- 
Grant Edwards   grante Yow!  YOW!! Up ahead! It's
  at   a DONUT HUT!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Duncan Booth
"Danny Colligan" <[EMAIL PROTECTED]> wrote:

> In the following code snippet, I attempt to assign 10 to every index in
> the list a and fail because when I try to assign number to 10, number
> is a deep copy of the ith index (is this statement correct?).

No. There is no copying involved.

Before the assignment, number is a reference to the object to which the ith 
element of the list also refers. After the assignment you have rebound the 
variable 'number' so it refers to the value 10. You won't affect the list 
that way.

> My question is, what was the motivation for returning a deep copy of
> the value at the ith index inside a for loop instead of the value
> itself?

There is no copying going on. It returns the value itself, or at least a 
reference to it.

>  Also, is there any way to assign to a list in a for loop (with
> as little code as used above) without using enumerate?

a[:] = [10]*len(a)

or more usually something like:

a = [ fn(v) for v in a ]

for some suitable expression involving the value. N.B. This last form 
leaves the original list unchanged: if you really need to mutate it in 
place assign to a[:] as in the first example, but if you are changing all 
elements in the list then you usually want a new list.



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


Re: Overriding traceback print_exc()?

2006-10-31 Thread Fredrik Lundh
Bob Greschke wrote:

> I want to cause any traceback output from my applications to show up in one 
> of my dialog boxes, instead of in the command or terminal window (between 
> running on Solaris, Linux, OSX and Windows systems there might not be any 
> command window or terminal window to show the traceback messages in).  Do I 
> want to do something like override the print_exc (or format_exc?) method of 
> traceback to get the text of the message and call my dialog box routine?

one way to do that is to put a big try/except around your main program, 
and display the dialogue box in the except clause:

 import traceback

 def main():
raise RuntimeError("oops!")

 try:
main()
 except (KeyboardInterrupt, SystemExit):
raise
 except:
print "ERROR", repr(traceback.format_exc())

another approach is to install an exit-handler that uses last_traceback 
and friends to generate a traceback:

 import atexit, traceback, sys

 def postmortem():
if hasattr(sys, "last_traceback"):
print "ERROR", repr(traceback.format_exception(
sys.last_type, sys.last_value, sys.last_traceback
))

 atexit.register(postmortem)

 def main():
raise RuntimeError("oops!")

 main()

the latter is less intrusive, and can be squirreled away in a support 
module.  also, the original exception is still reported to the console, 
as usual.



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


Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread [EMAIL PROTECTED]
I'm not quite sure what your asking, but I'll give it a shot.

You do not have to use enumerate, you can use other methods just as
range(len(sequence)), but the reason you cannot asign a value is
because a for loop iterates a sequence meaning when you do

for a in [1, 2, 3, 4, 5]:
   ...
a is just a value pulled from the sequence iteration.

just like i and number is a value pulled from the iteration in

for i, number in enumerate(a):
  ...

(That was worded badly :/ I apologise.)
Danny Colligan wrote:
> In the following code snippet, I attempt to assign 10 to every index in
> the list a and fail because when I try to assign number to 10, number
> is a deep copy of the ith index (is this statement correct?).
>
> >>> a = [1,2,3,4,5]
> >>> for number in a:
> ... number = 10
> ...
> >>> a
> [1, 2, 3, 4, 5]
>
> So, I have to resort to using enumerate to assign to the list:
>
> >>> for i, number in enumerate(a):
> ... a[i] = 10
> ...
> >>> a
> [10, 10, 10, 10, 10]
>
> My question is, what was the motivation for returning a deep copy of
> the value at the ith index inside a for loop instead of the value
> itself?  Also, is there any way to assign to a list in a for loop (with
> as little code as used above) without using enumerate?
> 
> Thanks,
> 
> Danny

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


Re: Overriding traceback print_exc()?

2006-10-31 Thread [EMAIL PROTECTED]
You could always override sys.stderr with a instance of your own with a
write() method. Though you will still have to catch the exceptions.

Bob Greschke wrote:
> I want to cause any traceback output from my applications to show up in one
> of my dialog boxes, instead of in the command or terminal window (between
> running on Solaris, Linux, OSX and Windows systems there might not be any
> command window or terminal window to show the traceback messages in).  Do I
> want to do something like override the print_exc (or format_exc?) method of
> traceback to get the text of the message and call my dialog box routine?  If
> that is right how do I do that (monkeying with classes is all still a grey
> area to me)?
>
> I kind of understand using the traceback module to alter the output of
> exceptions that I am looking for, but I'm after those pesky ones that should
> never happen. :)
> 
> Thanks!
> 
> Bob

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


Re: 3d programming without opengl

2006-10-31 Thread Fredrik Lundh
Grant Edwards wrote:

> Oy.  A pure Python solution would probably be _really_ slow.

Pure Python doesn't necessarily imply "no graphics drawing code written 
in some other language", though.  You can get pretty far by using a 2D 
library for simple 3D rendering.



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


Re: "best" rational number library for Python?

2006-10-31 Thread skip

Gabriel> Try clnum included in:
Gabriel> http://sourceforge.net/projects/calcrpnpy

I tried that as well before trying GMP.  It (the base clnum library)
complained about the absence of GMP during configure and failed to compile.

Skip

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


Re: Missing _init_types in MS VisualStudio 2005 (PCBuild8)

2006-10-31 Thread Martin v. Löwis
Donovan Kolbly schrieb:
> I was trying to build Python using MS VisualStudio 2005 (VC++ 8.0)
> according to the instructions in PCBuild8/ and got a link error
> in config.obj referencing _init_types.

That's a known bug, and has been fixed in the subversion repository
since.

> I (barely) know enough about VS 2005 to add files to the project, so I
> added Modules/_typesmodule.c to the pythoncore subproject, and that
> seemed to fix it -- I can now build the python executable.

That's the correct fix, indeed.

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


Re: scared about refrences...

2006-10-31 Thread Steve Holden
SpreadTooThin wrote:
[...]
> I don't understand why python would insist that everything must be a
> refrence...

We can tell that :)

> It is of course helpful sometime but other times its not...  and now
> I'm sorta out
> of luck...

There are very good reasons for Python's namespace model. Sure it's 
different from some other languages, but it's actually been some 
people's preferred semantics for a very long time now (the 
recently-deceased Ralph Griswold, may he rest in peace, chose a very 
similar model for Icon.

> I don't know how to make this structure immutable...  Pickle it?  Seems
> very
> inefficient to me...
> Every time I pass a variable now I will worry that it will be changed
> by the function...
> I haven't worried about things like this since the very early days of
> BASIC
> I don't know.. maybe I have more to learn.
> 
You do. Firstly, learn to leave your paranoia outside your programming 
life. If a function or method makes undocumented changes to its mutable 
parameters then it needs changing (or its documentation does).

Adequate testing should reveal such nonsenses before release.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Tim Chase
> In the following code snippet, I attempt to assign 10 to every index in
> the list a and fail because when I try to assign number to 10, number
> is a deep copy of the ith index (is this statement correct?).

Sorta...just like with function parameters, there are mutables 
and immutables.

 a = [1,2,3,4,5]
 for number in a:
> ... number = 10
> ...
 a
> [1, 2, 3, 4, 5]

Just as with a function (currently discussed on another thread 
recently), you have the following behavior:

 >>> def a(x):
... x = 42
...
 >>> deb b(x):
... x.append(42)
...
 >>> g = 1
 >>> h = [1]
 >>> a(g)
 >>> b(h)
 >>> g
1
 >>> h
[1, 42]


you have similar behavior:

 >>> a = [[1],[2],[3],[4],[5]]
 >>> for thing in a:
... thing.append(10)
...
 >>> a
[[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]]

Lists/sets/etc are mutable.  Strings, numbers,

> So, I have to resort to using enumerate to assign to the list:
> 
 for i, number in enumerate(a):
> ... a[i] = 10
> ...
 a
> [10, 10, 10, 10, 10]

This would commonly be written with a list comprehension:

a = [10 for _ in a]

or

a = [10] * len(a)

or, if that was a general case of something more specific with 
some "if" brains behind it, you can do things like

a = [odd(v) and 10 or v for v in a]

to only change them to 10 where the value is odd.

> My question is, what was the motivation for returning a deep copy of
> the value at the ith index inside a for loop instead of the value
> itself?  Also, is there any way to assign to a list in a for loop (with
> as little code as used above) without using enumerate?


As stated above, it returns the item...if it's mutable, you can 
mutate it.  If it's an immutable (like your numbers), you just 
change the variable in the local scope of the loop.


-tkc




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


Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Danny Colligan
I see.  Thanks for the helpful response.

Danny

Duncan Booth wrote:
> "Danny Colligan" <[EMAIL PROTECTED]> wrote:
>
> > In the following code snippet, I attempt to assign 10 to every index in
> > the list a and fail because when I try to assign number to 10, number
> > is a deep copy of the ith index (is this statement correct?).
>
> No. There is no copying involved.
>
> Before the assignment, number is a reference to the object to which the ith
> element of the list also refers. After the assignment you have rebound the
> variable 'number' so it refers to the value 10. You won't affect the list
> that way.
>
> > My question is, what was the motivation for returning a deep copy of
> > the value at the ith index inside a for loop instead of the value
> > itself?
>
> There is no copying going on. It returns the value itself, or at least a
> reference to it.
>
> >  Also, is there any way to assign to a list in a for loop (with
> > as little code as used above) without using enumerate?
>
> a[:] = [10]*len(a)
>
> or more usually something like:
>
> a = [ fn(v) for v in a ]
>
> for some suitable expression involving the value. N.B. This last form
> leaves the original list unchanged: if you really need to mutate it in
> place assign to a[:] as in the first example, but if you are changing all
> elements in the list then you usually want a new list.

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


Re: Why can't you assign to a list in a loop without enumerate?

2006-10-31 Thread Bruno Desthuilliers
Danny Colligan wrote:
> In the following code snippet, I attempt to assign 10 to every index in
> the list a and fail because when I try to assign number to 10, number
> is a deep copy of the ith index (is this statement correct?).

It's quite easy to find out:

class Foo(object):
def __init__(self, num):
self.num = num
def __repr__(self):
return "foo %d at %d" % (self.num, id(self))

foos = [Foo(i) for i in range(10)]
print foos
=> [foo 0 at 47281508865040, foo 1 at 47281508865104, foo 2 at
47281508865168, foo 3 at 47281508865232, foo 4 at 47281508865296, foo 5
at 47281508865360, foo 6 at 47281508865424, foo 7 at 47281508865488, foo
8 at 47281508865552, foo 9 at 47281508865616]

for foo in foos:
foo.num = foo.num * 2
print foos
=> [foo 0 at 47281508865040, foo 2 at 47281508865104, foo 4 at
47281508865168, foo 6 at 47281508865232, foo 8 at 47281508865296, foo 10
at 47281508865360, foo 12 at 47281508865424, foo 14 at 47281508865488,
foo 16 at 47281508865552, foo 18 at 47281508865616]

Seems like your statement is *not* correct.

 a = [1,2,3,4,5]
 for number in a:
> ... number = 10

Note that you are *not* "assign(ing) 10 to every index in the list"
here. Rebinding the local name 'number' in each iteration only makes
this name refer to another object (implying of course loosing the
reference to the current list element). Then - on the following
iteration - the name 'number' is rebound to the next object in the list.

 a
> [1, 2, 3, 4, 5]

>>> for foo in foos:
... original = foo
... foo = Foo(10)
... print "original : %s - foo : %s" % (original, foo)
...
original : foo 0 at 47281508865040 - foo : foo 10 at 47281508864144
original : foo 2 at 47281508865104 - foo : foo 10 at 47281508864144
original : foo 4 at 47281508865168 - foo : foo 10 at 47281508864144
original : foo 6 at 47281508865232 - foo : foo 10 at 47281508864144
original : foo 8 at 47281508865296 - foo : foo 10 at 47281508864144
original : foo 10 at 47281508865360 - foo : foo 10 at 47281508864144
original : foo 12 at 47281508865424 - foo : foo 10 at 47281508864144
original : foo 14 at 47281508865488 - foo : foo 10 at 47281508864144
original : foo 16 at 47281508865552 - foo : foo 10 at 47281508864144
original : foo 18 at 47281508865616 - foo : foo 10 at 47281508864144

> So, I have to resort to using enumerate to assign to the list:

Yes. That's still far better than having to manually check for sequence
boundaries and track current index.

 for i, number in enumerate(a):
> ... a[i] = 10
> ...
 a
> [10, 10, 10, 10, 10]

Just for the record: the notation 'a[x] = y' in fact calls
'a.__setitem__(x, y)'. It's really just calling a method that alters the
state of object a.

> My question is, what was the motivation for returning a deep copy of
> the value at the ith index inside a for loop instead of the value
> itself? 

Forget about values. Think objects.
>>> i = 10
>>> i.__class__

>>> dir(i)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
'__floordiv__', '__getattribute__', '__getnewargs__', '__hash__',
'__hex__', '__init__', '__int__', '__invert__', '__long__',
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__',
'__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__',
'__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__',
'__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__',
'__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__',
'__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__']
>>> i.__abs__()
10


> Also, is there any way to assign to a list in a for loop (with
> as little code as used above) without using enumerate?

What's the problem with enumerate() ?



-- 
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: Overriding traceback print_exc()?

2006-10-31 Thread Ziga Seilnacht
Bob Greschke wrote:
> I want to cause any traceback output from my applications to show up in one
> of my dialog boxes, instead of in the command or terminal window (between
> running on Solaris, Linux, OSX and Windows systems there might not be any
> command window or terminal window to show the traceback messages in).  Do I
> want to do something like override the print_exc (or format_exc?) method of
> traceback to get the text of the message and call my dialog box routine?  If
> that is right how do I do that (monkeying with classes is all still a grey
> area to me)?

You can overwrite the sys.exepthook() with your own function:


import sys
from traceback import format_exception

def my_excepthook(exctype, value, traceback):
details = "".join(format_exception(exctype, value, traceback))
# now show the details in your dialog box

sys.excepthook = my_excepthook


See the documentation for details:
http://docs.python.org/lib/module-sys.html#l2h-5125

Hope this helps,
Ziga

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


Re: Overriding traceback print_exc()?

2006-10-31 Thread [EMAIL PROTECTED]
I usually have a function like this:

def get_excinfo_str():
"""return exception stack trace as a string"""

(exc_type, exc_value, exc_traceback) = sys.exc_info()
formatted_excinfo = traceback.format_exception(exc_type, exc_value,
exc_traceback)
excinfo_str = "".join(formatted_excinfo)

del exc_type
del exc_value
del exc_traceback

return(excinfo_str)


I can then call it from within "except" and print it to a log file.

Raghu.

Bob Greschke wrote:
> I want to cause any traceback output from my applications to show up in one
> of my dialog boxes, instead of in the command or terminal window (between
> running on Solaris, Linux, OSX and Windows systems there might not be any
> command window or terminal window to show the traceback messages in).  Do I
> want to do something like override the print_exc (or format_exc?) method of
> traceback to get the text of the message and call my dialog box routine?  If
> that is right how do I do that (monkeying with classes is all still a grey
> area to me)?
>
> I kind of understand using the traceback module to alter the output of
> exceptions that I am looking for, but I'm after those pesky ones that should
> never happen. :)
> 
> Thanks!
> 
> Bob

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


Re: Python and SSL enabled

2006-10-31 Thread matey
Problem:  I want to be able to access an HTTPS website read/write
commands
to this website.

>From reading this group it appears I need M2Crypto and OpenSSL

Current version of Python 2.3.4

I downloaded:
M2Crypto 0.16
OpenSSL 0.9.7k
SWIG 1.3.29

Compiled OpenSSL libraries are located in /home/mmedina/lib/libcrypto.a
and libssl.a
I compiled M2Crytpo

cengsu01:/home/mmedina/crypt/m2kcrypto/m2crypto-0.16/build/lib.solaris-2.9-sun4u-2.3/M2Crypto
>ls -alt
total 1624
drwxr-xr-x   4 mmedina  asip 512 Oct 31 09:45 ./
-rwxr-xr-x   1 mmedina  asip  690332 Oct 31 09:45 __m2crypto.so*
drwxr-xr-x   3 mmedina  asip 512 Oct 30 08:38 ../
drwxr-xr-x   2 mmedina  asip 512 Oct 30 08:38 PGP/
drwxr-xr-x   2 mmedina  asip 512 Oct 30 08:38 SSL/
-rw-r--r--   1 mmedina  asip8655 Jul  5 13:35 EC.py
-rw-r--r--   1 mmedina  asip 771 Jun 12 10:36 __init__.py
-rw-r--r--   1 mmedina  asip   14018 May 22 14:06 DSA.py
-rw-r--r--   1 mmedina  asip1588 May 10 14:31 util.py
-rw-r--r--   1 mmedina  asip7189 Apr 27  2006 SMIME.py
-rw-r--r--   1 mmedina  asip2118 Apr 27  2006 m2urllib.py
-rw-r--r--   1 mmedina  asip   10784 Apr 26  2006 EVP.py
-rw-r--r--   1 mmedina  asip   11238 Apr 26  2006 RSA.py
-rw-r--r--   1 mmedina  asip   25817 Apr 11  2006 X509.py
-rw-r--r--   1 mmedina  asip 207 Mar 31  2006 callback.py
-rw-r--r--   1 mmedina  asip 379 Mar 29  2006 Rand.py
-rw-r--r--   1 mmedina  asip7302 Mar 25  2006 BIO.py
-rw-r--r--   1 mmedina  asip3306 Mar 20  2006 ASN1.py
-rw-r--r--   1 mmedina  asip3085 Mar 20  2006 AuthCookie.py
-rw-r--r--   1 mmedina  asip1330 Mar 20  2006 BN.py
-rw-r--r--   1 mmedina  asip2374 Mar 20  2006 DH.py
-rw-r--r--   1 mmedina  asip 936 Mar 20  2006 Err.py
-rw-r--r--   1 mmedina  asip 692 Mar 20  2006 RC4.py
-rw-r--r--   1 mmedina  asip2896 Mar 20  2006 ftpslib.py
-rw-r--r--   1 mmedina  asip2210 Mar 20  2006 httpslib.py
-rw-r--r--   1 mmedina  asip 785 Mar 20  2006 m2.py
-rw-r--r--   1 mmedina  asip1804 Mar 20  2006 m2xmlrpclib.py
-rw-r--r--   1 mmedina  asip 347 Mar 20  2006 threading.py
cengsu01:/home/mmedina/crypt/m2kcrypto/m2crypto-0.16/build/lib.solaris-2.9-sun4u-2.3/M2Crypto
>

However, when I use the following command: python setup.py install
I get the following error:

creating /usr/local/lib/python2.3/site-packages/M2Crypto
error: could not create
'/usr/local/lib/python2.3/site-packages/M2Crypto': Permission denied

Since I don't have root privleges can I install the M2Crypto somewhere
else?

Also, am I on the right track if I want to be able to access an Https
page?

thanks in advance,

Monica


Heikki Toivonen wrote:
> matey wrote:
> > I am have version 2.3.4.  I want to write a python script to access a
> > secure HTTPS.
> >
> > I tried the following:
> >
> > import urllib
> > urllib.urlopen("https://somesecuresite.com";)
> > s = f.read()
> > f.close()
>
> I hope you know the Python stdlib SSL does not provide certificate
> checking etc. security features you almost certainly want in a
> production application. There are several 3rd party Python crypto
> libraries that provide more secure SSL out of the box, for example M2Crypto.
> 
> -- 
>   Heikki Toivonen

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


best way to check if a file exists?

2006-10-31 Thread John Salerno
What is the best way to check if a file already exists in the current 
directory? I saw os.path.isfile(), but I'm not sure if that does more 
than what I need.

I just want to check if a file of a certain name exists before the user 
creates a new file of that name.

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


Re: best way to check if a file exists?

2006-10-31 Thread utabintarbo

John Salerno wrote:
> What is the best way to check if a file already exists in the current
> directory? I saw os.path.isfile(), but I'm not sure if that does more
> than what I need.
>
> I just want to check if a file of a certain name exists before the user
> creates a new file of that name.
> 
> Thanks.

os.path.exists()?

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


Integrating Python with Fortran

2006-10-31 Thread unexpected
Hi all,

I'm currently working on a large, legacy Fortran application. I would
like to start new development in Python (as it is mainly I/O related).
In order to do so, however, the whole project needs to be able to
compile in Fortran.

I'm aware of resources like the F2Py Interface generator, but this only
lets me access the Fortran modules I need in Python. I'm wondering if
there's a way to generate the .o files from Python (maybe using
py2exe?) and then link the .o file with the rest of the Fortran project
using something like gcc.

I realize that all of this is highly dependent on the libraries I use,
etc, but I'm just looking for general strategies to attack the problem
or someone to tell me that this is impossible.

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


Re: best way to check if a file exists?

2006-10-31 Thread Gabriel Genellina

At Tuesday 31/10/2006 18:01, John Salerno wrote:


What is the best way to check if a file already exists in the current
directory? I saw os.path.isfile(), but I'm not sure if that does more
than what I need.


os.access(full_filename, os.F_OK)
http://docs.python.org/lib/os-file-dir.html


I just want to check if a file of a certain name exists before the user
creates a new file of that name.


Remember that things may change between you check the name and you 
actually create the file.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Integrating Python with Fortran

2006-10-31 Thread Martin v. Löwis
unexpected schrieb:
> I'm aware of resources like the F2Py Interface generator, but this only
> lets me access the Fortran modules I need in Python. I'm wondering if
> there's a way to generate the .o files from Python (maybe using
> py2exe?) and then link the .o file with the rest of the Fortran project
> using something like gcc.
> 
> I realize that all of this is highly dependent on the libraries I use,
> etc, but I'm just looking for general strategies to attack the problem
> or someone to tell me that this is impossible.

Please take a look at the "extending and embedding" tutorial. This
explains you how to integrate Python code into a C application.
If you think this could work for you if just your application was C, I
think the Python-Fortran people can give you precise instructions on how
to integrate Python code into a Fortran program.

In the simplest embedding example, you just link the Python VM itself
into the hosting application. The actual Python files stay on disk, and
invoking a Python function from C/Fortran will just end up doing a
regular Python import (with searching sys.path and everything).

If, for packaging reasons, you prefer to have the Fortran program
stand-alone, I recommend to use freeze. freeze gives you indeed .o files
for Python files, plus a global table of all frozen modules. Then, when
doing an import, the interpreter won't go to disk anymore, but it will
import the byte code "from memory" (it still would be a regular import
operation). Freeze, of course, requires you to recompile/relink your
application every time you change a Python source file.

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


Re: Ctypes Error: Why can't it find the DLL.

2006-10-31 Thread Bruno Desthuilliers
Mudcat a écrit :
> That was it. Once I added the other DLLs then it was able to find and
> make the call.
> 
> Thanks for all the help,

I just googled for "WindowsError: [Errno 126]" and followed the links, 
you know...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to check if a file exists?

2006-10-31 Thread Michael S
If you want to open the file for writing just open it
with append mode. open(¨filename", "a"). If it
doesn't exist - it'll create it, and if it does it'll
start appending to the file

For reading - os.path.exists("filename"). Or (doesn't
make much sense, but still) try to open it for reading
and python will throw an IOException which you can
catch and handle.

Michael

--- John Salerno <[EMAIL PROTECTED]> wrote:

> What is the best way to check if a file already
> exists in the current 
> directory? I saw os.path.isfile(), but I'm not sure
> if that does more 
> than what I need.
> 
> I just want to check if a file of a certain name
> exists before the user 
> creates a new file of that name.
> 
> Thanks.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Python tools for managing static websites?

2006-10-31 Thread Carl Banks
Chris Pearl wrote:
> Are there Python tools to help webmasters manage static websites?
>
> I'm talking about regenerating an entire static website - all the HTML
> files in their appropriate directories and sub-directories. Each page
> has some fixed parts (navigation menu, header, footer) and some
> changing parts (body content, though in specific cases the normally
> fixed parts might change as well). The tool should help to keep site
> editing DRY every piece of data, including the recurring parts, should
> exist only once.
>
> The above should be doable with any decent templating tool, such as
> those forming part of most CMSes and full-stack web-frameworks.
> Normally I might have just resorted to a CMS/web-framework, running
> locally on the webmaster's station, with the only addition being a
> mechanism for generating all pages composing the site and saving them
> as files.
>
> But such a solution might not be enough, as the system I'm looking for
> must be able to control the physical traits of the website as a
> collection of files - e.g., creation and distribution of files among
> several physical directories and subdirectories.

Chris,

If you don't mind me pimping my own static website generator, you might
find HRL useful:

http://www.aerojockey.com/software/hrl

On one hand, it's like an ordinary templating engine in that you can
define macros and variables and such, and stick them into documents.
For example, define a sidebar macro in the file macro.hri:



First menu entry
Second menu entry
Thrid menu entry



This creates a new "sidebar" tag that expands to the macro definition.
You can use this macro in your main document file:




However, HRL is much more powerful than a simple templating system,
because it can embed Python code to be run during page generation.
Here's a very simple example:


import time
hrl.doc.write("Page last generated on %s" %
time.asctime(time.localtime()))


Thus, unlike most templating engines, HRL can adapt very well to
unusual situations.  You can embed the Python "scriptlet" into macro
definitions to create very powerful macros.  For instance, you could
write a sidebar macro to automatically disable the link to the current
page--impossible with a simple text-substitution engine.  Even more
powerful uses are possible.  You could write a macro that inserts
information from a database into the page (which sounds kind of like
what you mentioned).

On the downside, it's not exactly hip to the latest web trends.  It
uses sgmllib for input, bleagh.  The list of HTML tags it knows about
is vintage 1998.  (One of my design goals was freedom to be sloppy with
closing tags.  HRL keeps track of and automatically closes tags when
appropriate, but it doesn't know about tags like embed.)  And it's not
any sort of enterprise-quality content management.  It's just a
templating engine with power.


Carl Banks

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


report progress from C function

2006-10-31 Thread Michael S
Good day all.

I rewrote part of my program in C, it's a usually a
long task. I wanted to be able to report the progress
back to my python program. In  my module (in addition
to the function that performs the above-mentioned
task) there is a function that returns the variable,
indicating the progress. However I am not sure how to
call it. Once I call the C function that does the work
(it's a while loop that takes minutes sometimes) I
can't call that progress function.  
Any ideas?

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


Re: "best" rational number library for Python?

2006-10-31 Thread casevh
> A guy at work asked for functionality commonly found with rational numbers,
> so I said I'd find and install something.  I figured gmpy would be suitable,
> alas I'm having trouble successfully building the underlying GMP 4.2.1
> library on a PC running Solaris 10 (won't compile with the default --host,
> fails "make check" if I go the no-assembly route).  Before I invest a bunch
> of time into this, am I barking up the wrong tree?
>
I've successfully compiled GMP 4.2.1 on Solaris 10 x86 using both the
GCC and Sun Studio compilers on AMD 32-bit platform.

I just compiled GMP 4.2.1 on a P4 using

$ CFLAGS="" CC=gcc ./configure
$ gmake; gmake check

and all tests passed.

casevh

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


Re: "best" rational number library for Python?

2006-10-31 Thread casevh
> A guy at work asked for functionality commonly found with rational numbers,
> so I said I'd find and install something.  I figured gmpy would be suitable,
> alas I'm having trouble successfully building the underlying GMP 4.2.1
> library on a PC running Solaris 10 (won't compile with the default --host,
> fails "make check" if I go the no-assembly route).  Before I invest a bunch
> of time into this, am I barking up the wrong tree?
>
I've successfully compiled GMP 4.2.1 on Solaris 10 x86 using both the
GCC and Sun Studio compilers on AMD 32-bit platform.

I just compiled GMP 4.2.1 on a P4 using

$ CFLAGS="" CC=gcc ./configure
$ gmake; gmake check

and all tests passed.

casevh

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


Re: 3d programming without opengl

2006-10-31 Thread Richard Jones
Fredrik Lundh wrote:
> Grant Edwards wrote:
> 
>> Oy.  A pure Python solution would probably be _really_ slow.
> 
> Pure Python doesn't necessarily imply "no graphics drawing code written
> in some other language", though.  You can get pretty far by using a 2D
> library for simple 3D rendering.

Someone wrote a 3D demo for the pygame.draw challenge*. It worked but
unfortunately he didn't end up finishing and submitting it. It had severe
performance limitations :)


Richard

*: http://media.pyweek.org/static/pygame.draw-0606.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 123 introduction

2006-10-31 Thread Bruno Desthuilliers
Jeremy Sanders a écrit :
> Here is a brief simple introduction to Python I wrote for a computing course
> for graduate astronomers. It assumes some programming experience. Although
> it is not a complete guide, I believe this could be a useful document for
> other groups to learn Python, so I'm making it available for others to
> download, and modify for their own needs (some of the content is site
> specific).

May I emit some observations and suggest a couple of corrections ?

"""
To make it executable type chmod +x test.py, then run it by typing its 
name, test.py on the unix prompt
"""

Unless the current directory is in the path, this won't work:
[EMAIL PROTECTED] ~ $ cat toto.py
#!/usr/bin/python
print 'hello'
[EMAIL PROTECTED] ~ $ chmod +x toto.py
[EMAIL PROTECTED] ~ $ toto.py
-bash: toto.py: command not found
[EMAIL PROTECTED] ~ $ ./toto.py
hello
[EMAIL PROTECTED] ~ $



">>> a+b  # the value is printed at the prompt"
s/value/result/

"Numbers can be integers (int, whole numbers) or floating point (float)"
s/Numbers/Numeric objects/

"Strings are collections of characters"
s/Strings/String objects/

"Lists are collections of any types of variable (even lists)"
List objects are ordered collections of any type of objects (even other 
lists)

"Tuples are like lists but they cannot be changed"
s/Tuples/Tuple objects/


Semantically, a tuple is more a kind of record - a dict indexed by 
position - than an immutable list. That is: lists are homogenous ordered 
collections of arbitrary length. Neither the length of the collection 
nor the position of an object in it  have special meaning. While tuples 
are fixed-length heterogenous ordered   structures where both the number 
of items and their positions are meaningfull. Canonically, a DB table 
can be represented as a list of tuples.


"Files correspond to files on the disk"
File objects correspond to OS files.

 >>> import sys
 >>> type(sys.stdin)


"""
Note that immutable objects (like numbers, strings or tuples) do not 
have this property.

 >>> a = 10  # makes a point to object 10
"""

NB : here '10' is not the id of the object, it's its value. So it should 
be: # makes name 'a' point to an int object

"""
 >>> b = a   # makes b point to object 10
 >>> a = 11  # makes a point to object 11
 >>> print b # prints 10
"""

Hem... This has nothing to do with ints being immutables:

a = [1] # makes 'a' point to a list
b = a   # makes  'b' points to the same object
a = [1] # makes 'a' points to *another* list
print "a is b ? %s" % (a is b)

"""
In Python subroutines, procedures and functions are basically the same thing
"""

NB : The type is 'function'. They *always* return something 
(implicitely, the None object).

"None is a special value meaning ``nothing''"
s/value/object/

"You can test whether something is None by using is None"
There's always only one single None object, so you can test whether 
something is None by using 'is None'.

"""
a = ['foo', 'fred', 42]
for i in a:
 print i
"""

Traditionaly, identifier 'i' is used as the current index in C-like 
loops. Using it in this context might be a bit confusing :

a = ['foo', 'fred', 42]
for obj in a:
 print obj

"""
As an aside, there is a shortcut version of loops called a list 
comprehension which is very convenient:
"""

List comps are a "shortcut" for building lists. They are not a "shortcut 
  version of loops".

"""
filename = 'stupid.dat'
try:
 f = open(filename)
except IOError:  # the file did not open
 print "The filename", filename, "does not exist!"
"""

Actually, the file may exist, but the program may not be able to open it 
for other reasons...

filename = 'stupid.dat'
try:
 f = open(filename)
except IOError, e:  # the file did not open
 print "could not open file %s : %s" % (filename, e)



My 2 cents...
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >