Re: 3d programming without opengl

2006-10-30 Thread Fredrik Lundh
nelson - 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)

the scene is simple so I don't want to use a well-supported and widely 
used standard API because it might use hardware acceleration under the hood?

I know they keep saying that premature optimization is evil, but I'm not 
sure premature unoptimization is any better :-)

anyway, here are some links:

 http://www.vpython.org/
 http://panda3d.org/
 http://www.google.com/search?q=python+3D



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


Re: Python windows interactive.

2006-10-30 Thread Hendrik van Rooyen

"notejam" <[EMAIL PROTECTED]> Top posted:

> Thanks everyone for the help.   I got a simple two line program to work
> from a text file.
> Can not figure out how to write more than one line in interpreter mode.
>  Is that all interpreter is good for, testing one liners?  I have it
> run the program everytime I hit return, and can not figure out how to
> enter multiple lines of code.  I can do multiple lines in text file, so
> no problem, but I am jsut wondering can a program with 2 or more lines
> be wrote from the interpreter mode?

the interactive interpreter remembers the stuff you type.

so you can assign values to variables, and refer to them later.
you can define functions and call them later

that is enough to start with.

try it - you will like it...

- Hendrik



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


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

2006-10-30 Thread Hendrik van Rooyen
I am populating a listbox from a directory that looks like this:

variable_dict = {"funny_long_or_short_variable_name_as_key": (2,45),..

the tuple represents a "card, line" pair.
medf is a font object and a forward reference here.

I write:

for x in variable_dict:
txt = x
while medf.measure(txt) < 350:
txt = txt + ' '
txt = txt + str(variable_dict[x])

and I use the txt string to populate the list box.

At first glance, it seems to work, as the names are on the left, and the tuples
are in a column...

But if you scroll the listbox, the inherent error makes it appear as if the
tuple column is a snake doing the twist.

I tried using a tab but got a backslash - t in the text, and simply counting
spaces is worse than useless.

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...

A blank char of one pixel width would sort this nicely - but as the hilbilly
said when he first saw a rhinoceros: " There aint no such animal! "  -  or is
there?

- Hendrik

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


3d programming without opengl

2006-10-30 Thread nelson -
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unescape HTML entities

2006-10-30 Thread Rares Vernica
Thanks a lot for all the answers!
Ray

Frederic Rentsch wrote:
> Rares Vernica wrote:
>> Hi,
>>
>> How can I unescape HTML entities like " "?
>>
>> I know about xml.sax.saxutils.unescape() but it only deals with "&", 
>> "<", and ">".
>>
>> Also, I know about htmlentitydefs.entitydefs, but not only this 
>> dictionary is the opposite of what I need, it does not have " ".
>>
>> It has to be in python 2.4.
>>
>> Thanks a lot,
>> Ray
>>
> One way is this:
> 
>  >>> import SE  # 
> Download from http://cheeseshop.python.org/pypi/SE/2.2%20beta
>  >>> SE.SE ('HTM2ISO.se')('input_file_name', 'output_file_name')# 
> HTM2ISO.se is included
> 'output_file_name'
> 
> For repeated translations the SE object would be assigned to a variable:
> 
>  >>> HTM_Decoder = SE.SE ('HTM2ISO.se')
> 
> SE objects take and return strings as well as file names which is useful 
> for translating string variables, doing line-by-line translations and 
> for interactive development or verification. A simple way to check a 
> substitution set is to use its definitions as test data. The following 
> is a section of the definition file HTM2ISO.se:
> 
> test_string = '''
> ø=(xf8)   #  248  f8
> ù=(xf9)   #  249  f9
> ú=(xfa)   #  250  fa
> û=(xfb)#  251  fb
> ü=(xfc) #  252  fc
> ý=(xfd)   #  253  fd
> þ=(xfe)#  254  fe
> é=(xe9)
> ê=(xea)
> ë=(xeb)
> ì=(xec)
> í=(xed)
> î=(xee)
> ï=(xef)
> '''
> 
>  >>> print HTM_Decoder (test_string)
> 
> ø=(xf8)   #  248  f8
> ù=(xf9)   #  249  f9
> ú=(xfa)   #  250  fa
> û=(xfb)#  251  fb
> ü=(xfc) #  252  fc
> ý=(xfd)   #  253  fd
> þ=(xfe)#  254  fe
> é=(xe9)
> ê=(xea)
> ë=(xeb)
> ì=(xec)
> í=(xed)
> î=(xee)
> ï=(xef)
> 
> Another feature of SE is modularity.
> 
>  >>> strip_tags = '''
>~<(.|\x0a)*?>~=(9)   # one tag to one tab
>~~=(9)  # one comment to one tab
> |   # run
>"~\x0a[ \x09\x0d\x0a]*~=(x0a)"   # delete empty lines
>~\t+~=(32)   # one or more tabs to one space
>~\x20\t+~=(32)   # one space and one or more tabs to 
> one space
>~\t+\x20~=(32)   # one or more tab and one space to 
> one space
> '''
> 
>  >>> HTM_Stripper_Decoder = SE.SE (strip_tags + ' HTM2ISO.se ')   # 
> Order doesn't matter
> 
> If you write 'strip_tags' to a file, say 'STRIP_TAGS.se' you'd name it 
> together with HTM2ISO.se:
> 
>  >>> HTM_Stripper_Decoder = SE.SE ('STRIP_TAGS.se  HTM2ISO.se')   # 
> Order doesn't matter
> 
> Or, if you have two SE objects, one for stripping tags and one for 
> decoding the ampersands, you can nest them like this:
> 
>  >>> test_string = " style='line-height:110%'>René est un garçon qui 
> paraît plus âgé. "
> 
>  >>> print Tag_Stripper (HTM_Decoder (test_string))
>   René est un garçon qui paraît plus âgé.
> 
> Nesting works with file names too, because file names are returned:
> 
>  >>> Tag_Stripper (HTM_Decoder ('input_file_name'), 'output_file_name')
> 'output_file_name'
> 
> 
> Frederic
> 
> 
> 

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


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

2006-10-30 Thread Bryan Olson
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.

> 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.

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.


[...]
> 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.


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


Re: make a simple search function for homepage

2006-10-30 Thread James Stroud
HYRY wrote:
> I want to add some simple search function for my homepage. It need to
> search through all the html files of my homepage (about 300 pages), and
> highlight the search words.
> 
> I made some test with HTMLParser, it works but slow. So, my question is
> how can I improve its speed?
> 
> from HTMLParser import HTMLParser
> 
> class HightLightParser(HTMLParser):
>   def __init__(self, outfile, words):
>   self.outfile = outfile
>   self.words = words
>   self.found = False
>   HTMLParser.__init__(self)
> 
>   def handle_starttag(self, tag, attrs):
>   self.outfile.write( self.get_starttag_text( ) )
> 
>   def handle_endtag(self, tag):
>   self.outfile.write( "" % tag )
> 
>   def handle_data(self, data):
>   for word in self.words:
>   data = data.replace(word, "%s" % 
> word)
> #highlight
>   self.outfile.write(data)
> 
> class SearchParser(HTMLParser):
>   def __init__(self, words):
>   self.words = words
>   self.found = False
>   HTMLParser.__init__(self)
> 
>   def handle_data(self, data):
>   for word in self.words:
>   if word in data:  # search
>   self.found = True
> 
> 
> words = ["the"]
> x = SearchParser(words)
> data = file("input.htm").read()
> x.feed(data)
> if x.found:
>   y = HightLightParser(file("output.htm", "w"),words)
>   y.feed(data)
> 

google "google".

Seriously though, perhaps you may want to index your pages first. Maybe 
checkout divmod (http://divmod.org/trac/wiki/DivmodXapwrap).

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


create global variables?

2006-10-30 Thread aking


J. Clifford Dyer wrote:
> Alistair King wrote:
>   
>> Hi,
>>
>> is there a simple way of creating global variables within a function?
>>
>> ive tried simply adding the variables in:
>>
>> def function(atom, Xaa, Xab):
>> Xaa = onefunction(atom)
>> Xab = anotherfunction(atom)
>>
>> if i can give something like:
>>
>> function('C')#where atom = 'C' but not necessarly include Xaa or Xab
>>
>> i would like to recieve:
>>
>> Caa = a float
>> Cab = another float
>>
>> ive tried predefining Xaa and Xab before the function but they are
>> global values and wont change within my function. Is there a simple way
>> round this, even if i call the function with the variables ('C', Caa, Cab)?
>>
...
>>
>> some actual code:
>>
>> # sample dictionaries
>> DS1v = {'C': 6}
>> pt = {'C': 12.0107}
>>
>> def monoVarcalc(atom):
>> a = atom + 'aa'
>> Xaa = a.strip('\'')
>> m = atom + 'ma'
>> Xma = m.strip('\'')
>> Xaa = DS1v.get(atom)
>> Xma = pt.get(atom)
>> print Xma
>> print Xaa
>>
>> monoVarcalc('C')
>>
>> print Caa
>> print Cma
>>
...
>> it seems to work but again i can only print the values of Xma and Xaa
>>
>> ?
>>
>> Alistair
>>
>> 
>
> I suspect you are misusing the concept of a function.  In most basic 
> cases, and I suspect your case applies just as well as most, a function 
> should take arguments and return results, with no other communication 
> between the calling code and the function itself.  When you are inside 
> your function don't worry about the names of the variables outside.  I'm 
> not sure exactly where your floats are coming from, but try something 
> like this:
>
>  >>> def monoVarCalc(relevant_data):
> ... float1 = relevant_data * 42.0
> ... float2 = relevant_data / 23.0
> ... return float1, float2
>
>  >>> C = 2001
>  >>> Caa, Cab = monoVarCalc(C)
>  >>> Caa
> 84042.0
>  >>> Cab
> 87.0
>
> Notice that you don't need to use the variable C (or much less the 
> string "C", inside monoVarCalc at all.  It gets bound to the name 
> relevant_data instead.
>
> Also, if you are going to have a lot of these little results lying 
> around, (Cab, Cac ... Czy, Czz), you might consider making them a list 
> or a dictionary instead.  I won't tell you how to do that, though.  The 
> online tutorial has plenty of information on that.
>
> http://docs.python.org/tut/tut.html
>
>
> Cheers,
> Cliff
>   
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')


thanks

Ali

-- 
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: Adding a comment to an image using PIL

2006-10-30 Thread Fredrik Lundh
Jeffrey Barish wrote:

> I am trying to use PIL to add a comment to an image.  I have never used PIL
> before, but I discovered that it is possible to print an existing comment
> with the following:
> 
> im = PIL.Image.open('filename.jpg')
> print im.app['COM']
> 
> I figured that I could write a comment by reversing this procedure:
> 
> im.app['COM'] = 'New comment'
> im.save('newfilename.jpg')
> 
> However, when I open newfilename.jpg, I find that key 'COM' does not
> exist -- the comment is not being written.  Presumably, I am doing
> something wrong.

PIL's support for JPEG markers is mostly read-only.  Adding comments
by decoding/encoding isn't a very good idea anyway; to do that right, 
you need to work on the JPEG data stream, not on a decoded image.

it would probably not be too hard to write a JPEG stream editor based
on PIL's JPEG stream parser, but for the time being, I recommend using 
IJG's "wrjpgcom" utility for things like this.



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


[no subject]

2006-10-30 Thread aking

J. Clifford Dyer wrote:
> Alistair King wrote:
>   
>> Hi,
>>
>> is there a simple way of creating global variables within a function?
>>
>> ive tried simply adding the variables in:
>>
>> def function(atom, Xaa, Xab):
>> Xaa = onefunction(atom)
>> Xab = anotherfunction(atom)
>>
>> if i can give something like:
>>
>> function('C')#where atom = 'C' but not necessarly include Xaa or Xab
>>
>> i would like to recieve:
>>
>> Caa = a float
>> Cab = another float
>>
>> ive tried predefining Xaa and Xab before the function but they are
>> global values and wont change within my function. Is there a simple way
>> round this, even if i call the function with the variables ('C', Caa, Cab)?
>>
...
>>
>> some actual code:
>>
>> # sample dictionaries
>> DS1v = {'C': 6}
>> pt = {'C': 12.0107}
>>
>> def monoVarcalc(atom):
>> a = atom + 'aa'
>> Xaa = a.strip('\'')
>> m = atom + 'ma'
>> Xma = m.strip('\'')
>> Xaa = DS1v.get(atom)
>> Xma = pt.get(atom)
>> print Xma
>> print Xaa
>>
>> monoVarcalc('C')
>>
>> print Caa
>> print Cma
>>
...
>> it seems to work but again i can only print the values of Xma and Xaa
>>
>> ?
>>
>> Alistair
>>
>> 
>
> I suspect you are misusing the concept of a function.  In most basic 
> cases, and I suspect your case applies just as well as most, a function 
> should take arguments and return results, with no other communication 
> between the calling code and the function itself.  When you are inside 
> your function don't worry about the names of the variables outside.  I'm 
> not sure exactly where your floats are coming from, but try something 
> like this:
>
>  >>> def monoVarCalc(relevant_data):
> ... float1 = relevant_data * 42.0
> ... float2 = relevant_data / 23.0
> ... return float1, float2
>
>  >>> C = 2001
>  >>> Caa, Cab = monoVarCalc(C)
>  >>> Caa
> 84042.0
>  >>> Cab
> 87.0
>
> Notice that you don't need to use the variable C (or much less the 
> string "C", inside monoVarCalc at all.  It gets bound to the name 
> relevant_data instead.
>
> Also, if you are going to have a lot of these little results lying 
> around, (Cab, Cac ... Czy, Czz), you might consider making them a list 
> or a dictionary instead.  I won't tell you how to do that, though.  The 
> online tutorial has plenty of information on that.
>
> http://docs.python.org/tut/tut.html
>
>
> Cheers,
> Cliff
>   
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')


thanks

Ali

-- 
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: enumerate improvement proposal

2006-10-30 Thread Paddy

James Stroud wrote:
> Steve Holden wrote:
> > How could you end up marrying
> > someone who counts from one and not zero? ;-)
>
> She's the only other person I've ever met who used vi key binding at the
> command line.
>
Wow. Now I see!

It's only Python. Just add one to indices where appropriate, buy her
chocolates. Don't say a thing when you squelch your seventh off-by-one
error. Look interested in the shoe store. (even for the fifth shoe, of
the third store). - *Your partner does vi*

 Whoa!

- Paddy :-)

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


make a simple search function for homepage

2006-10-30 Thread HYRY
I want to add some simple search function for my homepage. It need to
search through all the html files of my homepage (about 300 pages), and
highlight the search words.

I made some test with HTMLParser, it works but slow. So, my question is
how can I improve its speed?

from HTMLParser import HTMLParser

class HightLightParser(HTMLParser):
def __init__(self, outfile, words):
self.outfile = outfile
self.words = words
self.found = False
HTMLParser.__init__(self)

def handle_starttag(self, tag, attrs):
self.outfile.write( self.get_starttag_text( ) )

def handle_endtag(self, tag):
self.outfile.write( "" % tag )

def handle_data(self, data):
for word in self.words:
data = data.replace(word, "%s" % 
word)
#highlight
self.outfile.write(data)

class SearchParser(HTMLParser):
def __init__(self, words):
self.words = words
self.found = False
HTMLParser.__init__(self)

def handle_data(self, data):
for word in self.words:
if word in data:  # search
self.found = True


words = ["the"]
x = SearchParser(words)
data = file("input.htm").read()
x.feed(data)
if x.found:
y = HightLightParser(file("output.htm", "w"),words)
y.feed(data)

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


Re: scared about refrences...

2006-10-30 Thread J. Clifford Dyer
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.


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


Re: Talks at PyCon that Teach How to Be Better Programmers

2006-10-30 Thread jeff
Paul Rubin <"http://phr.cx"@NOSPAM.invalid> writes:

> "Robert Brewer" <[EMAIL PROTECTED]> writes:
>> 2. Dynamic languages naturally more lang-maven oriented?
>>See http://osteele.com/archives/2004/11/ides
>
> Not sure what you mean by this, even after reading that (interesting)
> article.  These days Haskell (which has static types) seems to be all
> the rage with language geeks.

dynamic type != dynamic language

Those are two orthogonal concepts.  A dynamic language means introspection,
the ability to modify itself at runtime, such as by creating new classes.

Dynamic typing refers to whether a particular variable can change its type at
runtime.

Another dimension is whether typing is "strong" or "weak".  Python is strongly
typed in it does not implicitly change types for you, such as Perl's coercing
numeric strings into actual integers to complete an addition operation.

I led a discussion on these last month to a local user group.  The slides are
at:

 http://www.dfwuug.org/wiki/Main/PresentationSlides

It was a vigorous discussion among programmers of several languages. ;-)

-Jeff

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


Cann't connect zope server

2006-10-30 Thread steve
Can I ask question about zope here?

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)
Traceback (most recent call last):
  File "/usr/bin/zope/lib/python/Zope2/Startup/run.py", line 56, in ?
run()
  File "/usr/bin/zope/lib/python/Zope2/Startup/run.py", line 21, in run
starter.prepare()
  File "/usr/bin/zope/lib/python/Zope2/Startup/__init__.py", line 98,
in prepare
self.dropPrivileges()
  File "/usr/bin/zope/lib/python/Zope2/Startup/__init__.py", line 234,
in dropPrivileges
return dropPrivileges(self.cfg)
  File "/usr/bin/zope/lib/python/Zope2/Startup/__init__.py", line 403,
in dropPrivileges
raise ZConfig.ConfigurationError(msg)
ZConfig.ConfigurationError: A user was not specified to setuid to; fix
this to start as root (change the effective-user directive in
zope.conf)

I configured Username:root;How to setuid?etc.

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


Re: slice's indices() method

2006-10-30 Thread smichr

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > Is there any reason not to change the behavior of the indices() method
> > so it gives indices that can be used in range (to give indices
> > corresponding to elements that would be extracted by a given slice)
> > *and* used as arguments for slices so that the slice with the new
> > indices (obtained from the indices() method) would extract the same
> > elements as the original slice from whence they were obtained?
>
> and this month's "absolutely most pointless of all pointless proposals"
> award goes to...
>
> 

I don't see the suggestion that much different than wanting the output
of a function like ord() to be able to be used again in str() to get
back a given character. There was some good conversation about the
indices method a year ago...I was hoping to get some useful feedback as
to why this might not be an improvement to the behavior of the slice's
indices() method.

Although you have not run into the need to get the specific indices
from a slice (and perhaps that's why you think it's pointless) I did
need them and got bitten by the non-round-trip-able behavior of the
indices() method...and ended up writing a workaround rather than being
able to use the built in method.

/chris

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


Re: Serious wxPython Error while executing..

2006-10-30 Thread Paul McNett
kath wrote:
> Hello, sorry about the lengthy message.
> 
>  I finding difficult to execute this program. The wx.Notebook i created
> is coming on the splitted frame(self.p2). How do I that. I am started
> to learn wxPython, and when I run the code, the code doesnot close
> gracefully, it throughs me an error.
> 
> "pythonw.exe has encountered a problem and needs to close.  We are
> sorry for the inconvenience"

I get a segmentation fault on Linux, after running the script, choosing
"Add new fund" from the menu, and then closing the application. I don't
get the segmentation fault if I merely start the app and close it.

> here is the code seems a bit lengthy, sorry about that.
> Please help me to find my mistake, and how do I go forward resolving
> this problem.

You actually have several problems. But, the segmentation fault appears
to be directly related to the fact that you add boxsizer to the border
sizer twice.

Another problem is that you create the notebook every single time, and
add just one page to it, but you probably want just one notebook with
one or more pages.

-- 
pkm ~ http://paulmcnett.com


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


Adding a comment to an image using PIL

2006-10-30 Thread Jeffrey Barish
I am trying to use PIL to add a comment to an image.  I have never used PIL
before, but I discovered that it is possible to print an existing comment
with the following:

im = PIL.Image.open('filename.jpg')
print im.app['COM']

I figured that I could write a comment by reversing this procedure:

im.app['COM'] = 'New comment'
im.save('newfilename.jpg')

However, when I open newfilename.jpg, I find that key 'COM' does not
exist -- the comment is not being written.  Presumably, I am doing
something wrong.
-- 
Jeffrey Barish

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


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

2006-10-30 Thread Klaas
It seems clear that the import lock does not include fully-executing
the module contents.  To fix this, just import cookielib before the
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).

regards,
-Mike

robert wrote:
> I get python crashes and (in better cases) strange Python exceptions when (in 
> most cases) importing and using cookielib lazy on demand in a thread.
> It is mainly with cookielib, but remember the problem also with other imports 
> (e.g. urllib2 etc.).
> And again very often in all these cases where I get weired Python exceptions, 
> the problem is around re-functions - usually during re.compile calls during 
> import (see some of the exceptions below). But not only.
>
> Very strange: The errors occur almost only on machines with dual core/multi 
> processors - and very very rarely on very fast single core machines (>3GHz).
>
> I'm using Python2.3.5 on Win with win32ui (build 210) - the cookielib taken 
> from Python 2.5.
>
> I took care that I'm not starting off thread things or main application loop 
> etc. during an import (which would cause a simple & explainable deadlock 
> freeze on the import lock)
>
> With real OS-level crashes I know from user reports (packaged app), that 
> these errors occur very likely early after app start - thus when lazy imports 
> are likely to do real execution.
>
> I researched this bug for some time. I think I can meanwhile exclude 
> (ref-count, mem.leak) problems in win32ui (the only complex extension lib I 
> use) as cause for this. All statistics point towards import problems.
>
> Any ideas?
> Are there problems known with the import lock (Python 2.3.5) ?
>
> (I cannot easily change from Python 2.3 and it takes weeks to get significant 
> feedback after random improvements)
>
> -robert
>
> PS:
>
> The basic pattern of usage is:
>
> ==
> 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,())
> =
>
> Symptoms:
> __
>
> sometimes ufile is None and other weired invalid states.
>
> typical Python exceptions when in better cases there is no OS-level crash:
>
> -
>
>  # Attributes randomly missing like:
>  #<2
>
> "AttributeError: \'module\' object has no attribute \'CookieJar\'\\n"]
>
>
> -
>
> # weired invalid states during computation like:
> #<1
>
> ...  File "cookielib.pyo", line 184, in ?\\n\', \'  File
> "sre.pyo", line 179, in compile\\n\', \'  File "sre.pyo", line 228, in 
> _compile\\n\', \'  File
> "sre_compile.pyo", line 467, in compile\\n\', \'  File "sre_parse.pyo", line 
> 624, in parse\\n\', \'
> File "sre_parse.pyo", line 317, in _parse_sub\\n\', \'  File "sre_parse.pyo", 
> line 588, in
> _parse\\n\', \'  File "sre_parse.pyo", line 92, in closegroup\\n\', 
> \'ValueError: list.remove(x): x
> not in list\\n\']
> ...
> 'windows', "(5, 1, 2600, 2, 'Service Pack 2')/NP=2")
>
>
> -
>
> #<1
>
>
> File "cookielib.pyo", line 116, in ?\\n\', \'  File "sre.pyo", line 179, in 
> compile\\n\', \'  File "sre.pyo", line 228, in _compile\\n\', \'  File 
> "sre_compile.pyo", line 467, in compile\\n\', \'  File "sre_parse.pyo", line 
> 624, in parse\\n\', \'  File "sre_parse.pyo", line 317, in _parse_sub\\n\', 
> \'  File "sre_parse.pyo", line 494, in _parse\\n\', \'  File "sre_parse.pyo", 
> line 140, in __setitem__\\n\', \'IndexError: list assignment index out of 
> range\\n\']
>
> ('windows', "(5, 1, 2600, 2, 'Service Pack 2')/NP=2"
>
> -
>
> # weired errors in other threads:
>
> # after dlg.DoModal() in main thread
>
> File "wintools.pyo", line 115, in PreTranslateMessage\\n\', \'TypeError: an 
> integer is required\\n\']
>
> ('windows', "(5, 1, 2600, 2, 'Service Pack 2')/NP=2")
>
> -
>
> # after win32ui.PumpWaitingMessages(wc.WM_PAINT, wc.WM_MOUSELAST) in main 
> thread
> 
> \'TypeError: argument list must be a tuple\\n\'
> 
> 
> ...

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


Re: beginner's refcount questions

2006-10-30 Thread Scott David Daniels
Jens Theisen wrote:
> python uses gc only where refcounts alone haven't yet done the
> job. Thus, the following code
> class Foo:
> def __del__(self):
>print "deled!"
... In c++, this is a central technique used for all sorts of tasks,
whereas in garbage collected languages it's usually not available.

> Is there a reason not to rely on this in Python? For example, are
> there alternative Python implementations that behave differently?  Or
> some other subtle problems?

Python (the language) does not guarantee when (or even if) __del__
methods will be invoked, while C++ does (for the corresponding method).
Jython relies on Java's GC, IronPython?  CPython's garbage collector
(which finds loops of references and drops them as a group) avoids
any loops containing more than a single __del__ method.  In the spirit
of "explicit is better than implicit," ignore this problem and stop
using __del__.  In some cases you might want to check into the semantics
of the "with" construct introduced in 2.5, it may allow you to do what
you really mean.

> And some other minor question: Is there a way to query the use count
> of an object? This would be useful for debugging and testing.
 >>> import sys
 >>> sys.getrefcount(42 * 7)
 2

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


Re: Python windows interactive.

2006-10-30 Thread Steve Holden
notejam wrote:
> Thanks everyone for the help.   I got a simple two line program to work
> from a text file.
> Can not figure out how to write more than one line in interpreter mode.
>  Is that all interpreter is good for, testing one liners?  I have it
> run the program everytime I hit return, and can not figure out how to
> enter multiple lines of code.  I can do multiple lines in text file, so
> no problem, but I am jsut wondering can a program with 2 or more lines
> be wrote from the interpreter mode?
> 
The interactive interpreter is mostly for experimentation, but of course 
its advantage is that you can test out complex functionality imported 
from modules and packages. Want to know what's on the Google home page?

  >>> import urllib
  >>> f = urllib.urlopen("http://www.google.com";)
  >>> data = f.read()
  >>> print data
Google



 ...
©2006 Google

  >>>

You can also define funcitons and classes, and write multi-line 
statements interactively once you learn the conventions, but once 
functionality "hardens" into something of five lines or more that you 
want to experiment with you will find it's usually easier to edit a 
script or program in a text file and run it. This is even more the case 
when you start to use "test-driven development", something we shoudl all 
aspire to.

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


python, threading and a radio timer

2006-10-30 Thread Renato
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

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


Re: Error importing .pyd python extension

2006-10-30 Thread Toby
P.S. I have run 'depends', and all the dll's are there, the only error
its throwing up is:

"Warning: At least one module has an unresolved import due to a missing
export function in a delay-load dependent module."

The offending file is mpr.dll in c:\windows\system32\

Any ideas?

Toby

Toby wrote:
> Hi, I've managed to get my hands on the ms 2003 toolkit, and have
> successfully (i think) created a .pyd file in win xp (setup.py is
> provided intersystems cache):
>
> 
> C:\CacheSys\Dev\python>setup.py install
> enter directory where you installed Cache'c:\CacheSys
> libdir=c:\CacheSys\dev\cpp\lib
> include dir=c:\CacheSys\dev\cpp\include
> running install
> running build
> running build_py
> running build_ext
> running install_lib
> creating C:\Program Files\Python243\Lib\site-packages\intersys
> copying build\lib.win32-2.4\intersys\pythonbind.py -> C:\Program
> Files\Python243
> \Lib\site-packages\intersys
> copying build\lib.win32-2.4\intersys\pythonbind1.pyd -> C:\Program
> Files\Python2
> 43\Lib\site-packages\intersys
> copying build\lib.win32-2.4\intersys\__init__.py -> C:\Program
> Files\Python243\L
> ib\site-packages\intersys
> byte-compiling C:\Program
> Files\Python243\Lib\site-packages\intersys\pythonbind.
> py to pythonbind.pyc
> byte-compiling C:\Program
> Files\Python243\Lib\site-packages\intersys\__init__.py
>  to __init__.pyc
>
> C:\CacheSys\Dev\python>cd \program
> files\python243\Lib\site-packages\intersys\
>
> C:\Program Files\Python243\Lib\site-packages\intersys>dir
>  Volume in drive C is SYSTEM
>  Volume Serial Number is 3835-49DE
>
>  Directory of C:\Program Files\Python243\Lib\site-packages\intersys
>
> 31/10/2006  10:47 AM  .
> 31/10/2006  10:47 AM  ..
> 19/10/2006  05:50 PM 1,598 pythonbind.py
> 31/10/2006  10:47 AM 1,961 pythonbind.pyc
> 31/10/2006  09:44 AM69,632 pythonbind1.pyd
> 17/07/2006  05:34 PM 2 __init__.py
> 31/10/2006  10:47 AM   145 __init__.pyc
>5 File(s) 73,338 bytes
>2 Dir(s)  16,709,017,600 bytes free
> 
>
> However, when I try to import pythonbind1.pyd I get the following
> error:
>
> Traceback (most recent call last):
>   File
> "C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
> line 1843, in runMain
> self.dbg.runfile(debug_args[0], debug_args)
>   File
> "C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
> line 1538, in runfile
> h_execfile(file, args, module=main, tracer=self)
>   File
> "C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
> line 596, in __init__
> execfile(file, globals, locals)
>   File "C:\Program
> Files\Python243\Lib\site-packages\intersys\tobytest.py", line 1, in
> __main__
> import pythonbind1.pyd
> ImportError: DLL load failed: The specified module could not be found.
> 
> 
> Any suggestions?

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


Re: enumerate improvement proposal

2006-10-30 Thread Ben Finney
Mark Elston <[EMAIL PROTECTED]> writes:

> * James Stroud wrote (on 10/30/2006 4:39 PM):
> > She's the only other person I've ever met who used vi key binding
> > at the command line.
>
> Well, there's your problem.  You need to C-x C-f a new mate. :)

I don't have the commitment for that. What if I were to C-x C-v
a few different ones instead?

-- 
 \"If you continue running Windows, your system may become |
  `\ unstable."  -- Microsoft, Windows 95 BSOD message |
_o__)  |
Ben Finney

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


Re: Python windows interactive.

2006-10-30 Thread Tiefeng Wu
> notejam wrote:
> Thanks everyone for the help.   I got a simple two line program to work
> from a text file.
> Can not figure out how to write more than one line in interpreter mode.
> Is that all interpreter is good for, testing one liners?  I have it
> run the program everytime I hit return, and can not figure out how to
> enter multiple lines of code.  I can do multiple lines in text file, so
> no problem, but I am jsut wondering can a program with 2 or more lines
> be wrote from the interpreter mode?

I think for this purpose you can just define a function, like this:

>>> def test():
...print "Hello"
...print "World"
...
>>> test()
"Hello"
"World"
>>>



___ 
雅虎免费邮箱-3.5G容量,20M附件 
http://cn.mail.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Leo 4.4.2.1 final released

2006-10-30 Thread Edward K. Ream
>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 windows interactive.

2006-10-30 Thread Gabriel Genellina

At Monday 30/10/2006 21:15, notejam wrote:


Thanks everyone for the help.   I got a simple two line program to work
from a text file.
Can not figure out how to write more than one line in interpreter mode.
 Is that all interpreter is good for, testing one liners?  I have it
run the program everytime I hit return, and can not figure out how to
enter multiple lines of code.  I can do multiple lines in text file, so
no problem, but I am jsut wondering can a program with 2 or more lines
be wrote from the interpreter mode?


The command-line interpreter (python.exe), in interactive mode, is 
just for testing purposes: one or two lines or code.
You could write your program in a file (using notepad by example), 
save it with filename.py, and run it using: python filename.py
There are some integrated environments for working in python. IDLE 
already comes with your Python installation. For Windows you can get 
PythonWin 



--
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: Python windows interactive.

2006-10-30 Thread BartlebyScrivener
Try this, assuming you're in IDLE.

http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

You can enter as many lines as you want in the interpreter. Then press
ENTER twice to get the result.

Or try here if you're looking for some tutorials.

http://tinyurl.com/w7wgp

rd

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


Re: scared about refrences...

2006-10-30 Thread Gabriel Genellina

At Monday 30/10/2006 20:37, Nick Vatamaniuc wrote:


In  Python all the primitives are copied and all other entities are
references.


What do you mean?
primitives==builtin classes?
entities==objects?
In Python, objects are never automatically copied, either builtin or 
user-defined. Even 123 is an object. Names provide references to objects.

Perhaps you were thinking of *another* language.


--
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: enumerate improvement proposal

2006-10-30 Thread Mark Elston
* James Stroud wrote (on 10/30/2006 4:39 PM):
> Steve Holden wrote:
>> How could you end up marrying someone who counts from one and not 
>> zero? ;-)
> 
> She's the only other person I've ever met who used vi key binding at the 
> command line.
> 
> James
> 
> 

Well, there's your problem.  You need to C-x C-f a new mate. :)

Mark
(Emacs rules)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: enumerate improvement proposal

2006-10-30 Thread James Stroud
Steve Holden wrote:
> How could you end up marrying 
> someone who counts from one and not zero? ;-)

She's the only other person I've ever met who used vi key binding at the 
command line.

James


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

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


Error importing .pyd python extension

2006-10-30 Thread Toby
Hi, I've managed to get my hands on the ms 2003 toolkit, and have
successfully (i think) created a .pyd file in win xp (setup.py is
provided intersystems cache):


C:\CacheSys\Dev\python>setup.py install
enter directory where you installed Cache'c:\CacheSys
libdir=c:\CacheSys\dev\cpp\lib
include dir=c:\CacheSys\dev\cpp\include
running install
running build
running build_py
running build_ext
running install_lib
creating C:\Program Files\Python243\Lib\site-packages\intersys
copying build\lib.win32-2.4\intersys\pythonbind.py -> C:\Program
Files\Python243
\Lib\site-packages\intersys
copying build\lib.win32-2.4\intersys\pythonbind1.pyd -> C:\Program
Files\Python2
43\Lib\site-packages\intersys
copying build\lib.win32-2.4\intersys\__init__.py -> C:\Program
Files\Python243\L
ib\site-packages\intersys
byte-compiling C:\Program
Files\Python243\Lib\site-packages\intersys\pythonbind.
py to pythonbind.pyc
byte-compiling C:\Program
Files\Python243\Lib\site-packages\intersys\__init__.py
 to __init__.pyc

C:\CacheSys\Dev\python>cd \program
files\python243\Lib\site-packages\intersys\

C:\Program Files\Python243\Lib\site-packages\intersys>dir
 Volume in drive C is SYSTEM
 Volume Serial Number is 3835-49DE

 Directory of C:\Program Files\Python243\Lib\site-packages\intersys

31/10/2006  10:47 AM  .
31/10/2006  10:47 AM  ..
19/10/2006  05:50 PM 1,598 pythonbind.py
31/10/2006  10:47 AM 1,961 pythonbind.pyc
31/10/2006  09:44 AM69,632 pythonbind1.pyd
17/07/2006  05:34 PM 2 __init__.py
31/10/2006  10:47 AM   145 __init__.pyc
   5 File(s) 73,338 bytes
   2 Dir(s)  16,709,017,600 bytes free


However, when I try to import pythonbind1.pyd I get the following
error:

Traceback (most recent call last):
  File
"C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
line 1843, in runMain
self.dbg.runfile(debug_args[0], debug_args)
  File
"C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
line 1538, in runfile
h_execfile(file, args, module=main, tracer=self)
  File
"C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
line 596, in __init__
execfile(file, globals, locals)
  File "C:\Program
Files\Python243\Lib\site-packages\intersys\tobytest.py", line 1, in
__main__
import pythonbind1.pyd
ImportError: DLL load failed: The specified module could not be found.


Any suggestions?

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


Re: scared about refrences...

2006-10-30 Thread SpreadTooThin

J. Clifford Dyer wrote:
> SpreadTooThin wrote:
> > Steven D'Aprano wrote:
> >> On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
> >>
> > How do I specify or create deep copies of objects that may contain
> > other objects that may contain other object that may contain other
> > objects
>  See the `copy` module especially `copy.deepcopy()`.
> 
> >>> This appears to be the right thing to do to me.. (but what do I know?)
> >> Yes, copy.deepcopy() is the thing you want.
> >>
> >> But remember Fredrik's advice that well-designed Python code should not
> >> need to copy data structures often. I don't think I've ever needed to use
> >> deepcopy, and rarely copy.copy().
> >>
> >> In general, functions should not modify their caller's data. So this is
> >> bad practice:
> >>
> >> def print_list(alist):
> >> """Print a sorted list"""
> >> alist.sort()  # modifies the caller's data -- bad!
> >> for index, value in enumerate:
> >> print "Value %s at index %d" % (index, value)
> >>
> >> This is better:
> >>
> >> def print_list(alist):
> >> """Print a sorted list"""
> >> alist = alist[:]  # makes a local shallow copy of the list
> >> alist.sort()  # safe to modify now
> >> for index, value in enumerate:
> >> print "Value %s at index %d" % (index, value)
> >>
> >> But notice that you only need a shallow copy, not a deep copy, because you
> >> aren't modifying the objects within the list, only the list itself.
> >>
> >>
> >>
> >>> I tried this which more closely resembles my project but this doesn't
> >>> work:
> >> Unfortunately my crystal ball is back at the shop being repaired, so
> >> you'll have to explain what "doesn't work" means in this case. Does it
> >> raise an exception? If so, please post the exception. Does it do something
> >> different from what you expected? Then what did you expect, and what did
> >> it do?
> >>
> > 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...

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

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


Re: Python windows interactive.

2006-10-30 Thread notejam
Thanks everyone for the help.   I got a simple two line program to work
from a text file.
Can not figure out how to write more than one line in interpreter mode.
 Is that all interpreter is good for, testing one liners?  I have it
run the program everytime I hit return, and can not figure out how to
enter multiple lines of code.  I can do multiple lines in text file, so
no problem, but I am jsut wondering can a program with 2 or more lines
be wrote from the interpreter mode?





Larry Bates wrote:
> notejam wrote:
> > I am trying to get started with a interactive version of Python for
> > windows and need some help.
> > I have played with the tutorial, and now want to write a program.
> >
> > In basic language, I could write something like
> > 10 print "hello"
> > 20 print "Jim"
> >
> > and if I run it I would get
> > hello
> > Jim
> >
> > How do I do sometihing simple like that in python?
> > How do I enter line numbers, or if none, what do I do.
> > Can the interpreter load a text file with my program in it?
> > How do I list a program or the parts of a program I am interested in
> > looking at?
> >
> > How do I run a python program?
> >
> Start with the tutorial here:
>
> http://docs.python.org/tut/tut.html
>
> Your program in python would be:
>
> print "hello"
> print "jim"
>
> You don't have line numbers in Python
>
> Yes the interpreter can load a text file with your program.
> A good "beginners" version of Python for windows is:
>
> http://www.activestate.com/Products/ActivePython/?tn=1
>
> It has an easy to use interpreter window with both your
> program and interactive prompt open on the screen.
>
> To run a program you click run icon.  To run outside the
> interpreter you type python programname.py
> 
> -Larry

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


Re: I want to work on Python

2006-10-30 Thread [EMAIL PROTECTED]
I could use help with my project.  It should be very popular  when more
of it is done and credit may be a good way to build your resume

https://sourceforge.net/projects/dex-tracker

ArdPy wrote:
> Hi there, these days I am desperately searching everywhere on the
> Internet for part time python jobs. The reason is I want to get
> actively involved with python programming and get some practical
> exposure. Please help me in whatever way you can.

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


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

2006-10-30 Thread Ben Finney
[EMAIL PROTECTED] writes:

> So, I have a module with an arbitrary file name and I want to load it,
> and later access its function definitions.
> How can I do this ?  In my example, the last line will obviously not
> work.

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

-- 
 \   "A celebrity is one who is known by many people he is glad he |
  `\   doesn't know."  -- Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: checking if a sqlite connection and/or cursor is still open?

2006-10-30 Thread Nick Vatamaniuc
I am not familiar with SQLite driver, but a typical Pythonic  way to
check if you can do something is to just try it, and see what happens.
In more practical terms: try to just use the cursor or the connection
and see if an exception will be raised.

Nick V.



John Salerno wrote:
> John Salerno wrote:
> > Is there a way to check if a SQLite connection and cursor object are
> > still open? I took a look at the docs and the DB API but didn't see
> > anything like this.
> >
> > Thanks.
>
> Well, I might have somewhat solved this problem. Since SQLite allows you
> to use execute* methods directly on the connection object (thus no need
> to create a cursor object), all I need to do is call connection.close()
> and this doesn't seem to raise an error even if the connection has
> already been closed.
>
> I'm still curious if there's a way to check for an open connection, but
> it seems like without the cursor object, the task is much easier.

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


PyDoc link to source code

2006-10-30 Thread Taylor, Martin



When you use PyDoc, 
either with -w to generate a static web page or with -p to run as a web server, 
the generated pages have a link in the upper right corner to the source code for 
the referenced module. I can never get this link to work.  I think 
part of the problem is that MS-IE doesn't know what to do with a .py file 
(should treat it like plain text).  Does anyone know how to make these 
links work?
 
Thanks,
 

C. Martin 
Taylor Sr. Test 
Automation Specialist Texas Instruments, Inc. Educational and Productivity Solutions 7800 Banner Dr. MS 3908 
Dallas, TX 75251 

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

Re: dict problem

2006-10-30 Thread Ben Finney
Alistair King <[EMAIL PROTECTED]> writes:

> heavy = raw_input("\n\n@@\n\nPlease enter the heaviest
> atom for which you obtained percentage values for, but not Oxygen, eg,
> 'C', 'N', 'S', 'Br'...: ")
>
> print DSvalues
>
> def updateDS1v(Fxas, x):
> if Fxas != 0:
> value = DSvalues.get(heavy)
> floatvalue = float(value)
> atoms = DS1v.get(x) + Fxas*floatvalue
> DS1v[x] = atoms
>
> updateDS1v(FCas, 'C')
>
> print DS1v

I see from later posts that you have found solutions to your current
issues.

Just a note on what you posted: Please make sure that you post your
message as plain text. As you can see from what I quoted above, the
indentation is completely lost in the code you posted.

-- 
 \"We cannot solve our problems with the same thinking we used |
  `\when we created them."  -- Albert Einstein |
_o__)  |
Ben Finney

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


Serious wxPython Error while executing..

2006-10-30 Thread kath
Hello, sorry about the lengthy message.

 I finding difficult to execute this program. The wx.Notebook i created
is coming on the splitted frame(self.p2). How do I that. I am started
to learn wxPython, and when I run the code, the code doesnot close
gracefully, it throughs me an error.

"pythonw.exe has encountered a problem and needs to close.  We are
sorry for the inconvenience"

I clicked for more information, then I got the error message which is

"AppName: pythonw.exeAppVer: 0.0.0.0 ModName: wxmsw26uh_vc.dll
ModVer: 2.6.3.3  Offset: 0016bb6f




.."

here is the code seems a bit lengthy, sorry about that.
Please help me to find my mistake, and how do I go forward resolving
this problem.

[code]
import wx

ID_ADD_NEW = 5001
ID_DEACTIVATE = 5002
ID_EXIT = 5003

class _AddNewFund(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
box=wx.StaticBox(self, -1, "Add New Fund")
boxsizer=wx.StaticBoxSizer(box, wx.HORIZONTAL)

t=wx.StaticText(self, -1, "Please select an Excel file to
upload new funds.", (20,20))
boxsizer.Add(t, 0, wx.TOP|wx.LEFT, 10)
t=wx.StaticText(self, -1, "This is page one content2", (20,40))
boxsizer.Add(t, 0, wx.TOP|wx.LEFT, 10)

self.text1=wx.TextCtrl(self, -1, "")

b1 = wx.Button(self, 10, " Browse ")
b2 = wx.Button(self, 10, " Upload ", (60, 20))
self.Bind(wx.EVT_BUTTON, self.OnBrowse, b1)
self.Bind(wx.EVT_BUTTON, self.OnUpload, b2)
b1.SetDefault()
b1.SetSize(b1.GetBestSize())
b2.SetSize(b2.GetBestSize())

grid1=wx.FlexGridSizer(0,2,0,0)
grid1.Add( self.text1, 0,
wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
grid1.Add( b1, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
#grid1.Add( b2, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
border=wx.BoxSizer()
border.Add(boxsizer, 1, wx.EXPAND)
self.SetSizer(border)
boxsizer.Add(grid1, 0, wx.ALIGN_CENTRE)
border.Add(boxsizer, 0, wx.ALIGN_CENTRE)
#print "end ADD NEW class"

def OnBrowse(self, event):
self.dirname=""
d=wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*",
wx.Open)
if d.ShowModal() == wx.ID_OK:
self.filename=d.GetFilename()
self.dirname=d.GetDirectory()
self.text1.WriteTest(join(os.path.join(self.dirname,
self.filename)))
d.Destroy()

def OnUpload(self, event):
pass

class ParentWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Euro Fund manager")
self.createMenu()
self.Bind(wx.EVT_MENU, self.onAddnewfund, id=ID_ADD_NEW)
self.Bind(wx.EVT_MENU, self.onDeactivate, id=ID_DEACTIVATE)
self.Bind(wx.EVT_MENU, self.onExit, id=ID_EXIT)
self.spw=wx.SplitterWindow(self)
self.p1=wx.Panel(self.spw, style=wx.BORDER_NONE)
self.p1.SetBackgroundColour("white")
self.p2=wx.Panel(self.spw, style=wx.BORDER_NONE)

self.spw.SplitVertically(self.p1, self.p2, 200)

self.CreateStatusBar()

def createMenu(self):
menu=wx.Menu()
menu.Append(ID_ADD_NEW, "&Add new fund(s)", "Add new fund(s)")
menu.Append(ID_DEACTIVATE, "&Deactivate fund(s)", "Deactivate
fund(s)")
menu.AppendSeparator()
menu.Append(ID_EXIT, "E&xit", "Exit")

menubar=wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)

def onAddnewfund(self, event):
#p=wx.Panel(self.p2)
#print "panel created"
nb=wx.Notebook(self.p2)
#print "notebook created"
addPage=_AddNewFund(nb)
nb.AddPage(addPage, "Add new Fund")
#print "page got added"
sizer=wx.BoxSizer()
sizer.Add(nb, 1, wx.EXPAND)
self.p2.SetSizer(sizer)
#print "end of add function"

def onDeactivate(self, event): pass

def onExit(self, event):
self.Close()


app = wx.App()
frm=ParentWindow()
frm.SetSize((800,500))
frm.Show()
app.SetTopWindow(frm)
app.MainLoop()

[/code]



thank you,
Regards,
kath

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


Re: enumerate improvement proposal

2006-10-30 Thread Steve Holden
James Stroud wrote:
> Diez B. Roggisch wrote:
> 
>>>Okay, I've googled "leaky abstractions" (as was probably your intended
>>>affect with your silence), read the famous essay, and still
>>>don't know what you mean and how it applies to what I have described.
>>>
>>>Do you plan to justify your statement or emptily accuse people of 
>>>violating
>>>esoteric principles?
>>
>>
>>While I can't claim to know what the effbot thinks (the 
>>skull-socks-wearing-python-coder-mindlink-technology is yet to be 
>>developed), I think it's pretty clear what he is after here:
>>
>>Computers compute offsets into data zero-based. Some languages like 
>>pascal completely abstract that away from the user, but python doesn't.
>>
>>So if your colleague/boss/whatever insists on indices being one-based, 
>>this abstraction you introduced for her pretty fast leaks pretty badly. 
>>Consider this simple example:
>>
>>for offset, item in enumerate(some_list, start=1):
>>if item.is_the_chosen_one():
>>chosen_one_offset = offset
>>
>>the_chosen_one = some_list[chosen_one_offset]
>>
>>And bang, its Judas not Petrus who gets the pearly gates inc. stock 
>>options.
>>
>>Diez
> 
> 
> Thank you for this explanation. Very illuminating. I think understand 
> this idea well and the thought of 1 basing this function makes me cringe 
> as much as the next guy (though I lacked the vocabulary to explain 
> exactly why I cringe).
> 
> But you see, weaning this university faculty level economist (who 
> already has her own way of doing everything...and to whom I happen to be 
> married) from the traditional economics tools of gauss and sas towards 
> the more sane and flexible tools of python, numarray, and rpy has been a 
> multi-stage process. Tweaking the chosen abstractions to not be as leaky 
> (thank you and thank Fredrik for introducing me to this vocabulary) is 
> still one of the things I'm working towards. I want to solidify the 
> conversion before I concentrate on nuance.
> 
> So, before too much criticism, I challenge even the most skilled python 
> programmer to find his or her own faculty economist (or statistician or 
> physicist) and get them to radically change their computational tools. 
> When you've walked a mile in my shoes, leaky abstractions won't seem 
> like such a big deal after all.
> 
Divorce is obviously the only answer. How could you end up marrying 
someone who counts from one and not zero? ;-)

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

2006-10-30 Thread Nick Vatamaniuc
I think you are afraid of references because you are not trusting your
own code. You are afraid it will do "magic" behind the scenes and mess
everything up.  One way around that is to simply write better code and
test often.

If everything was copied when passed around it would be pretty awful --
imagine passing around a 1Gb worth of data to a function...

In  Python all the primitives are copied and all other entities are
references. If you want to just copy a list you can :
1) use the list class: new_list=list(old_list)
2) use the [:] syntax: new_list=old_list[:]
3) if your list has nested lists, for example, the above methods will
not copy everything, so you need a deep copy -- copy.deepcopy()

Hope this helps,
Nick V.


SpreadTooThin wrote:
> I'm really worried that python may is doing some things I wasn't
> expecting... but lets see...
>
> if I pass a list to a function def fn(myList):
>
> and in that function I modify an element in the list, then does the
> callers list get modied as well.
>
> def fn(list):
>list[1] = 0
>
> myList = [1, 2, 3]
> print myList
> fn(myList)
> print myList
>
> >>> [1,2,3]
> >>> [1,0,3]
>
> How can I avoid this?  In this case this is a really simplified example
> but the effects are the same...
> How do I specify or create deep copies of objects that may contain
> other objects that may contain other
> object that may contain other objects

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


Re: enumerate improvement proposal

2006-10-30 Thread James Stroud
Diez B. Roggisch wrote:
>> Okay, I've googled "leaky abstractions" (as was probably your intended
>> affect with your silence), read the famous essay, and still
>> don't know what you mean and how it applies to what I have described.
>>
>> Do you plan to justify your statement or emptily accuse people of 
>> violating
>> esoteric principles?
> 
> 
> While I can't claim to know what the effbot thinks (the 
> skull-socks-wearing-python-coder-mindlink-technology is yet to be 
> developed), I think it's pretty clear what he is after here:
> 
> Computers compute offsets into data zero-based. Some languages like 
> pascal completely abstract that away from the user, but python doesn't.
> 
> So if your colleague/boss/whatever insists on indices being one-based, 
> this abstraction you introduced for her pretty fast leaks pretty badly. 
> Consider this simple example:
> 
> for offset, item in enumerate(some_list, start=1):
> if item.is_the_chosen_one():
> chosen_one_offset = offset
> 
> the_chosen_one = some_list[chosen_one_offset]
> 
> And bang, its Judas not Petrus who gets the pearly gates inc. stock 
> options.
> 
> Diez

Thank you for this explanation. Very illuminating. I think understand 
this idea well and the thought of 1 basing this function makes me cringe 
as much as the next guy (though I lacked the vocabulary to explain 
exactly why I cringe).

But you see, weaning this university faculty level economist (who 
already has her own way of doing everything...and to whom I happen to be 
married) from the traditional economics tools of gauss and sas towards 
the more sane and flexible tools of python, numarray, and rpy has been a 
multi-stage process. Tweaking the chosen abstractions to not be as leaky 
(thank you and thank Fredrik for introducing me to this vocabulary) is 
still one of the things I'm working towards. I want to solidify the 
conversion before I concentrate on nuance.

So, before too much criticism, I challenge even the most skilled python 
programmer to find his or her own faculty economist (or statistician or 
physicist) and get them to radically change their computational tools. 
When you've walked a mile in my shoes, leaky abstractions won't seem 
like such a big deal after all.

James

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

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


Re: scared about refrences...

2006-10-30 Thread J. Clifford Dyer
SpreadTooThin wrote:
> Steven D'Aprano wrote:
>> On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
>>
> How do I specify or create deep copies of objects that may contain
> other objects that may contain other object that may contain other
> objects
 See the `copy` module especially `copy.deepcopy()`.

>>> This appears to be the right thing to do to me.. (but what do I know?)
>> Yes, copy.deepcopy() is the thing you want.
>>
>> But remember Fredrik's advice that well-designed Python code should not
>> need to copy data structures often. I don't think I've ever needed to use
>> deepcopy, and rarely copy.copy().
>>
>> In general, functions should not modify their caller's data. So this is
>> bad practice:
>>
>> def print_list(alist):
>> """Print a sorted list"""
>> alist.sort()  # modifies the caller's data -- bad!
>> for index, value in enumerate:
>> print "Value %s at index %d" % (index, value)
>>
>> This is better:
>>
>> def print_list(alist):
>> """Print a sorted list"""
>> alist = alist[:]  # makes a local shallow copy of the list
>> alist.sort()  # safe to modify now
>> for index, value in enumerate:
>> print "Value %s at index %d" % (index, value)
>>
>> But notice that you only need a shallow copy, not a deep copy, because you
>> aren't modifying the objects within the list, only the list itself.
>>
>>
>>
>>> I tried this which more closely resembles my project but this doesn't
>>> work:
>> Unfortunately my crystal ball is back at the shop being repaired, so
>> you'll have to explain what "doesn't work" means in this case. Does it
>> raise an exception? If so, please post the exception. Does it do something
>> different from what you expected? Then what did you expect, and what did
>> it do?
>>
> 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.

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


Re: scared about refrences...

2006-10-30 Thread SpreadTooThin

Steven D'Aprano wrote:
> On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:
>
> >> > How do I specify or create deep copies of objects that may contain
> >> > other objects that may contain other object that may contain other
> >> > objects
> >>
> >> See the `copy` module especially `copy.deepcopy()`.
> >>
> >
> > This appears to be the right thing to do to me.. (but what do I know?)
>
> Yes, copy.deepcopy() is the thing you want.
>
> But remember Fredrik's advice that well-designed Python code should not
> need to copy data structures often. I don't think I've ever needed to use
> deepcopy, and rarely copy.copy().
>
> In general, functions should not modify their caller's data. So this is
> bad practice:
>
> def print_list(alist):
> """Print a sorted list"""
> alist.sort()  # modifies the caller's data -- bad!
> for index, value in enumerate:
> print "Value %s at index %d" % (index, value)
>
> This is better:
>
> def print_list(alist):
> """Print a sorted list"""
> alist = alist[:]  # makes a local shallow copy of the list
> alist.sort()  # safe to modify now
> for index, value in enumerate:
> print "Value %s at index %d" % (index, value)
>
> But notice that you only need a shallow copy, not a deep copy, because you
> aren't modifying the objects within the list, only the list itself.
>
>
>
> > I tried this which more closely resembles my project but this doesn't
> > work:
>
> Unfortunately my crystal ball is back at the shop being repaired, so
> you'll have to explain what "doesn't work" means in this case. Does it
> raise an exception? If so, please post the exception. Does it do something
> different from what you expected? Then what did you expect, and what did
> it do?
>
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...





> 
> -- 
> Steven.

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


Re: scared about refrences...

2006-10-30 Thread Steven D'Aprano
On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:

>> > How do I specify or create deep copies of objects that may contain
>> > other objects that may contain other object that may contain other
>> > objects
>>
>> See the `copy` module especially `copy.deepcopy()`.
>>
> 
> This appears to be the right thing to do to me.. (but what do I know?)

Yes, copy.deepcopy() is the thing you want.

But remember Fredrik's advice that well-designed Python code should not
need to copy data structures often. I don't think I've ever needed to use
deepcopy, and rarely copy.copy().

In general, functions should not modify their caller's data. So this is
bad practice:

def print_list(alist):
"""Print a sorted list"""
alist.sort()  # modifies the caller's data -- bad!
for index, value in enumerate:
print "Value %s at index %d" % (index, value)

This is better:

def print_list(alist):
"""Print a sorted list"""
alist = alist[:]  # makes a local shallow copy of the list
alist.sort()  # safe to modify now
for index, value in enumerate:
print "Value %s at index %d" % (index, value)

But notice that you only need a shallow copy, not a deep copy, because you
aren't modifying the objects within the list, only the list itself.



> I tried this which more closely resembles my project but this doesn't
> work:

Unfortunately my crystal ball is back at the shop being repaired, so
you'll have to explain what "doesn't work" means in this case. Does it
raise an exception? If so, please post the exception. Does it do something
different from what you expected? Then what did you expect, and what did
it do?


-- 
Steven.

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


Re: create global variables?

2006-10-30 Thread Jason

Alistair King wrote:
> have tried:
>
> def monoVarcalc(atom):
> a = atom + 'aa'
> Xaa = a.strip('\'')
> m = atom + 'ma'
> Xma = m.strip('\'')
> global Xma
> global Xaa
> Xaa = DS1v.get(atom)
> Xma = pt.get(atom)
> print Xma
> print Xaa
>
> monoVarcalc('C')
>
> print Caa
> print Cma
> ...
>
> where global Xma & Xaa are before and after any further functions
>
> i get still get the error
>
> Traceback (most recent call last):
>   File "DS1excessH2O.py", line 54, in ?
> print Caa
> NameError: name 'Caa' is not defined

Mr King, please look at the documentation for the global keyword.  You
can either see it at "http://docs.python.org/ref/global.html#l2h-564";.
You can also access information about it using Python's help function
(use "help('global')" to see its help).

The global statement makes the names that follow available globally.
It does *not* evaluate the name in any way.  If you have "global Xma"
in your code as above, the name Xma becomes a global name.  That name
happens to contain the string value "Caa" in it.  The local name "Caa"
is not placed into the global name-space because you didn't put it into
the global statement.

Heck, I don't see that you have a local variable with the name "Caa".
You have three local variables and two global variables in the
monoVarcalc function:
  -- "atom" is the name of the parameter to the function.  The name is
only local to the function.
  -- "a" and "m" are local variables in the function.  They are the
result of adding strings to atom.
  -- "Xaa" and "Xma" are global names.  They are assigned values from
the local variables "m" and "a".  You then overwrite their values with
the global object DSv1's and pt's get methods.

As others have shown, you can use the dictionary-like object returned
by the globals() function to place arbitrary names into the global
namespace.

However, I highly recommend that you review your algorithms.  I
generally find that programs designed with many globals is a sign that
the program is badly designed.  I also recommend that you resolve any
syntax warnings that your program may be generating (hint: relocate
your global statement to the top of your function).

Your program could probably benefit from a number of things that Python
does well:

  -- Python has very efficient dictionaries.  Dictionaries allow you to
easily pass around things like your values in the above program.

  -- Python makes it trivial to return multiple values.  If you simply
need to return more than one value from the function, just return a
tuple.

  -- Python's object-oriented programming model and nested name-spaces
are pretty easy to use.  If you are unfamiliar with object-oriented
programming, there are a number of tutorials out there that can help.
You don't need to use objects with Python, but there are many cases
where they will "obviously" work far better than ugly procedural-level
hacks.  (By obviously, I mean that it will be pretty easy to understand
exactly what you did later on.)

Python's website has a tutorial section
(http://www.python.org/doc/Intros.html) and many people recommend the
"Dive Into Python" tutorial series (http://www.diveintopython.org/).
Do a google search for "Python tutorials" for more information.

--Jason

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


Re: Python windows interactive.

2006-10-30 Thread Larry Bates
notejam wrote:
> I am trying to get started with a interactive version of Python for
> windows and need some help.
> I have played with the tutorial, and now want to write a program.
> 
> In basic language, I could write something like
> 10 print "hello"
> 20 print "Jim"
> 
> and if I run it I would get
> hello
> Jim
> 
> How do I do sometihing simple like that in python?
> How do I enter line numbers, or if none, what do I do.
> Can the interpreter load a text file with my program in it?
> How do I list a program or the parts of a program I am interested in
> looking at?
> 
> How do I run a python program?
> 
Start with the tutorial here:

http://docs.python.org/tut/tut.html

Your program in python would be:

print "hello"
print "jim"

You don't have line numbers in Python

Yes the interpreter can load a text file with your program.
A good "beginners" version of Python for windows is:

http://www.activestate.com/Products/ActivePython/?tn=1

It has an easy to use interpreter window with both your
program and interactive prompt open on the screen.

To run a program you click run icon.  To run outside the
interpreter you type python programname.py

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


Re: create global variables?

2006-10-30 Thread Steve Holden
Wojciech Muła wrote:
> Alistair King wrote:
> 
>>is there a simple way of creating global variables within a function?
> 
> 
> def foo(name):
>   globals()[name] = "xxx"
>   globals()[name + 'aa'] = "yyy"
>   globals()[name + 'ab'] = "zzz"

Please note that this is a terrible programming practice. Anyone who 
really thinks they need to do this should be thinking hard about whether 
they are using Python correctly (though tere are occasionaly 
requirements where the feature can legitimately be used).

It would be *much* easier and *much* better programming practice to 
modify your code so the function returns a two-element tuple, which you 
then assign to two variables in an unpacking assignment.

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: Python windows interactive.

2006-10-30 Thread Paul McGuire
"notejam" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I am trying to get started with a interactive version of Python for
> windows and need some help.
> I have played with the tutorial, and now want to write a program.
>
> In basic language, I could write something like
> 10 print "hello"
> 20 print "Jim"
>
> and if I run it I would get
> hello
> Jim
>
> How do I do sometihing simple like that in python?
> How do I enter line numbers, or if none, what do I do.
> Can the interpreter load a text file with my program in it?
> How do I list a program or the parts of a program I am interested in
> looking at?
>
> How do I run a python program?
>
Hmmm, exactly how much have you "played with the tutorial"?  I think if you 
go back and play some more, you will answer many of these questions for 
yourself.

In fact, you should find Python to be quite friendly to your past 
experience.  For example, if you take your basic language example, remove 
the line numbers (Python doesn't use them, and many modern Basics don't 
either), and just enter the same print statements at the Python command 
line, you should get the exact same output.

Python editing doesn't require a specialized development environment (the 
way VisualBasic does, for example).  Python programs are simply text files, 
usually saved with a .py extension, that you create, view, print, list, etc. 
using any plain text editor.  (Note: Windows WordPad does not fall in this 
category - like a slimmed-down version of Word, WordPad inserts many special 
binary characters for text formatting, which is not at all Python-friendly.)

If you use a simple text editor like notepad, enter those same two lines 
above (remember, without the line numbers) in a text file, name it 
"HelloJimThisIsYourFirstPythonProgram.py", then open a console window, set 
your working directory to the same directory where you saved 
HelloJimThisIsYourFirstPythonProgram.py, and enter at the command line: 
"python HelloJimThisIsYourFirstPythonProgram.py" (leave off the quotes, they 
are just there in this message to show you what to type), you should get the 
same output.  And voila! you have run your Python program.

I've left out a lot, because there is quite a bit of meat in the tutorials 
already available.  Also, there are more tutorials than just the official 
one, google about a bit and you should find quite a bit of entry-level 
material.

Lastly, before posting again, please review the Python FAQ's at 
http://www.python.org/doc/faq/.  Don't be another one to exclaim "Shoot! I 
wish I'd checked the FAQ's before posting that newbie question that everyone 
is tired of hearing again and again!"

Best of luck to you in your new Python adventure!
-- Paul 


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


Re: Compile Python With SSL On Solaris 10

2006-10-30 Thread Martin v. Löwis
[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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CHM help file for Python 2.5

2006-10-30 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> Can anyone point me to new location of this version of manual,
> or tell me why this format is no longer supported ... ?

It's on the download page itself:

http://www.python.org/download/releases/2.5/
http://www.python.org/ftp/python/2.5/Python25.chm

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


Re: Python windows interactive.

2006-10-30 Thread abcd
> How do I do sometihing simple like that in python?

print "hello"
print "Jim"

> How do I enter line numbers, or if none, what do I do.

no line numbers needed

> Can the interpreter load a text file with my program in it?

read in a text file:
data = open("something.txt").read()

> How do I list a program or the parts of a program I am interested in
> looking at?

say you want to know what you can do with a list
x = [1,2,3,4,5]

dir(x)
help(x)
help(x.append)

>
> How do I run a python program?

create a file, type some code.  then to at the end of the file (put
this)...

if __name__ == "__main__":
# call your functions here

this will let you run it from command line like this:
c:> python foo.py

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


Re: importing class

2006-10-30 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Thanks for your help. Actually my idea was that command1 and command2
> would be defined within the program, not the module, as I would have
> different choices in different programs. Should I pass them in as a
> parameter too?
> 
It would seem to be the only way to tell your object which callbacks to 
call!

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: Python windows interactive.

2006-10-30 Thread robfalck
edit a plain text file, just type one line


print "hello, world"


Now save that one-line text file as "hello.py".  From the command line,
in the same directory, type:

python hello.py


And it should run your script.  Python doesnt require line numbers.

Happy coding.

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


Re: scared about refrences...

2006-10-30 Thread SpreadTooThin

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, SpreadTooThin
> wrote:
>
> > I'm really worried that python may is doing some things I wasn't
> > expecting... but lets see...
>
> Expect that Python never copies something if don't ask explicitly for a
> copy.
>
> > if I pass a list to a function def fn(myList):
> >
> > and in that function I modify an element in the list, then does the
> > callers list get modied as well.
> >
> > def fn(list):
> >list[1] = 0
> >
> > myList = [1, 2, 3]
> > print myList
> > fn(myList)
> > print myList
> >
>  [1,2,3]
>  [1,0,3]
> >
> > How can I avoid this?  In this case this is a really simplified example
> > but the effects are the same...
>
> In this case:
>
> def fn(lst):
> lst = list(lst)
> lst[1] = 0
>
>
> > How do I specify or create deep copies of objects that may contain
> > other objects that may contain other object that may contain other
> > objects
>
> See the `copy` module especially `copy.deepcopy()`.
>

This appears to be the right thing to do to me.. (but what do I know?)
I tried this which more closely resembles my project but this doesn't
work:

import array
import copy

class test:
def __init__(self):
self.a = array.array('H', [1, 2, 3])
self.b = ['a', 'b', 'c']

def dump(self):
print self.a, self.b

t = test()
t.dump()

def testit(x):
t = copy.deepcopy(x)
t.a[1] = 0
t.b[1] = 0

testit(t)

t.dump()

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


Re: How to convert " " in a string to blank space?

2006-10-30 Thread Frederic Rentsch
一首诗 wrote:
> Oh, I didn't make myself clear.
>
> What I mean is how to convert a piece of html to plain text bu keep as
> much format as possible.
>
> Such as convert " " to blank space and convert  to "\r\n"
>
> Gary Herron wrote:
>   
>> 一首诗 wrote:
>> 
>>> Is there any simple way to solve this problem?
>>>
>>>
>>>   
>> Yes, strings have a replace method:
>>
>> 
> s = "abc def"
> s.replace(' ',' ')
>   
>> 'abc def'
>>
>> Also various modules that are meant to deal with web and xml and such
>> have functions to do such operations.
>>
>>
>> Gary Herron
>> 
>
>   
 >>> my_translations = '''
   " = "
   # "=\r\n"  "=\r\n"   # Windows
   "=\n"  "=\n" # Linux
   # Add others to your heart's content
'''

 >>> import SE  # From http://cheeseshop.python.org/pypi/SE/2.2%20beta

 >>> My_Translator = SE.SE (my_translations)

 >>> print My_Translator ('ABC DEFGXYZ')
ABC DEFG
XYZ

SE can also strip tags and translate all HTM escapes and generally lets 
you do ad hoc translations in seconds. You just write them up, make an 
SE object from your text an run your data through it. As simple as that.
  If you wish further explanations, I'll be happy to explain.

Frederic


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

Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
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).

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


Python windows interactive.

2006-10-30 Thread notejam
I am trying to get started with a interactive version of Python for
windows and need some help.
I have played with the tutorial, and now want to write a program.

In basic language, I could write something like
10 print "hello"
20 print "Jim"

and if I run it I would get
hello
Jim

How do I do sometihing simple like that in python?
How do I enter line numbers, or if none, what do I do.
Can the interpreter load a text file with my program in it?
How do I list a program or the parts of a program I am interested in
looking at?

How do I run a python program?

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


Odd build errors

2006-10-30 Thread Jeff Blaine
We have a GCC in /usr/rcf that was not built with --disable-shared.
As such, there is a /usr/rcf/lib/libgcc_s.so.

We also have a (preferred) GCC in /afs/rcf/lang/gcc/current that
was built with --disable-shared.  As such, there is no
/afs/rcf/lang/gcc/current/lib/libgcc_s.so and binaries built
with this compiler do not link to any shared libgcc_s.

I have the following problem with Python 2.4.2.  I also tried
2.4.4.  Moving up to 2.5 is not an option.

Problem: Builds fine!  Rebuild after dropping in Setup.local
  causes some magic new build process that ends up
  finding and linking in /usr/rcf/lib/libgcc_s.so !

===
PATH=/afs/rcf/lang/gcc/sun4x_59/4.1.1/bin:/usr/ccs/bin:/usr/bin:/bin:/usr/ucb
# NOTE: No reference to /usr/rcf/bin, therefore NO picking up the bogus
# GCC and its shared libgcc_s.so
===
sun4x_59:cairo> ../configure --prefix=/afs/rcf/lang/python/sun4x_59/2.4.2
sun4x_59:cairo> make
...
===
# after successful build...
sun4x_59:cairo> ldd python
 libresolv.so.2 =>/usr/lib/libresolv.so.2
 libsocket.so.1 =>/usr/lib/libsocket.so.1
 libnsl.so.1 =>   /usr/lib/libnsl.so.1
 librt.so.1 =>/usr/lib/librt.so.1
 libdl.so.1 =>/usr/lib/libdl.so.1
 libm.so.1 => /usr/lib/libm.so.1
 libpthread.so.1 =>   /usr/lib/libpthread.so.1
 libc.so.1 => /usr/lib/libc.so.1
 libmp.so.2 =>/usr/lib/libmp.so.2
 libaio.so.1 =>   /usr/lib/libaio.so.1
 libmd5.so.1 =>   /usr/lib/libmd5.so.1
 libthread.so.1 =>/usr/lib/libthread.so.1
 /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1
 /usr/platform/SUNW,Sun-Fire-280R/lib/libmd5_psr.so.1
sun4x_59:cairo>
#
# Ta daaa!  No libgcc_s.so linked in.  GOOD.
#
# Now we drop our Setup.local in place for Solaris 9.
#
sun4x_59:cairo> cp ~/Python242.sun4x_59.Setup.local Modules/Setup.local
===
sun4x_59:cairo> make
...
c++ -pthread   -o python \
 Modules/python.o \
 libpython2.4.a -lresolv -lsocket -lnsl -lrt -ldl 
-L/afs/rcf/lang/tcl/@sys/8.2.3/lib -R/afs/rcf/lang/tcl/@sys/8.2.3/lib 
-L/afs/rcf/lang/tk/@sys/8.2.3/lib -R/afs/rcf/lang/tk/@sys/8.2.3/lib 
-ltk8.2 -ltcl8.2 -L/usr/openwin/lib -R/usr/openwin/lib -lX11 
-R/usr/rcf/lib -L/usr/rcf/lib -lreadline -ltermcap  -L/usr/rcf/lib 
-R/usr/rcf/lib -lssl -lcrypto  -L/usr/rcf/lib -R/usr/rcf/lib -lgdbm 
-L/usr/rcf/lib -R/usr/rcf/lib -lz -lm
ld: warning: global symbol `_GLOBAL_OFFSET_TABLE_' has non-global binding:
 (file /usr/rcf/lib/libstdc++.so value=LOCL);
ld: warning: global symbol `_GLOBAL_OFFSET_TABLE_' has non-global binding:
 (file /usr/rcf/lib/libgcc_s.so.1 value=LOCL);
case $MAKEFLAGS in \
*-s*)  CC='gcc -pthread' LDSHARED='gcc -pthread -shared' OPT='-DNDEBUG 
-g -O3 -Wall -Wstrict-prototypes' ./python -E ../setup.py -q build;; \
*)  CC='gcc -pthread' LDSHARED='gcc -pthread -shared' OPT='-DNDEBUG -g 
-O3 -Wall -Wstrict-prototypes' ./python -E ../setup.py build;; \
esac
ld.so.1: python: fatal: libgcc_s.so.1: open failed: No such file or 
directory
Killed
make: *** [sharedmods] Error 137
sun4x_59:cairo> ldd python
 libresolv.so.2 =>/usr/lib/libresolv.so.2
 libsocket.so.1 =>/usr/lib/libsocket.so.1
 libnsl.so.1 =>   /usr/lib/libnsl.so.1
 librt.so.1 =>/usr/lib/librt.so.1
 libdl.so.1 =>/usr/lib/libdl.so.1
 libX11.so.4 =>   /usr/openwin/lib/libX11.so.4
 libcurses.so.1 =>/usr/lib/libcurses.so.1
 libgdbm.so.2 =>  /usr/rcf/lib/libgdbm.so.2
 libstdc++.so.5 =>/usr/rcf/lib/libstdc++.so.5
 libm.so.1 => /usr/lib/libm.so.1
 libpthread.so.1 =>   /usr/lib/libpthread.so.1
 libc.so.1 => /usr/lib/libc.so.1
 libmp.so.2 =>/usr/lib/libmp.so.2
 libaio.so.1 =>   /usr/lib/libaio.so.1
 libmd5.so.1 =>   /usr/lib/libmd5.so.1
 libXext.so.0 =>  /usr/openwin/lib/libXext.so.0
 libgcc_s.so.1 => (file not found) # NOO
 libthread.so.1 =>/usr/lib/libthread.so.1
 /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1
 /usr/platform/SUNW,Sun-Fire-280R/lib/libmd5_psr.so.1
sun4x_59:cairo>

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


Re: Python 123 introduction

2006-10-30 Thread John Salerno
[EMAIL PROTECTED] wrote:
> dakman> This is great! A excellent tutorial for somone who has prior
> dakman> experience in programming and is starting out in python. My
> dakman> friend keeps wanting me to teach him python, I think this would
> dakman> be the perfect link for him.
> 
> I'm not trying to minimize Jeremy's efforts in any way, but how is his
> tutorial a significant improvement over the original
> (http://www.python.org/doc/current/tut/)?
> 
> Skip

well, not to minimize the efforts of guido's tutorial, but sometimes it 
seems less of a tutorial and more of a summary of python's features, so 
it never hurts to have things explained in a different way...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread John Salerno
abcd wrote:
>> But one question that comes to mind is, do you not add sizerTextPanel to
>> sizerMainPanel? I think all sub-sizers should be added to the main
>> sizer, unless there's some weird reason I don't know of.
> 
> well i set the sizer on the textPanel and then I add the textPanel to
> sizerMainPanel
> 

Ah, I see. Seems like it may be a sizer issue, since you are adding a 
bunch of things together. I noticed that one object you refer to is 
self.textPane, is that supposed to be self.textPanel?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
> But one question that comes to mind is, do you not add sizerTextPanel to
> sizerMainPanel? I think all sub-sizers should be added to the main
> sizer, unless there's some weird reason I don't know of.

well i set the sizer on the textPanel and then I add the textPanel to
sizerMainPanel

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


Re: Python 123 introduction

2006-10-30 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I'm not trying to minimize Jeremy's efforts in any way, but how is his
> tutorial a significant improvement over the original
> (http://www.python.org/doc/current/tut/)?

don't forget the community-enhanced edition over at:

pytut.infogami.com



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


Re: Python 123 introduction

2006-10-30 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> I'm not trying to minimize Jeremy's efforts in any way, but how is his
> tutorial a significant improvement over the original
> (http://www.python.org/doc/current/tut/)?

It's not intended as a replacement, but what I wanted to do was write a
quick 2 hour course for people to work through. It overlaps quite a bit
with the tutorial, but I tried to minimise any detail.

I just publicised it in case anybody wanted something similar.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread John Salerno
abcd wrote:

> sizerMainPanel.Add(self.textPanel, 3, wx.ALL|wx.EXPAND, 0)

Your best bet may be to post to [EMAIL PROTECTED]

But one question that comes to mind is, do you not add sizerTextPanel to 
sizerMainPanel? I think all sub-sizers should be added to the main 
sizer, unless there's some weird reason I don't know of.

If you post to the wxPython mailing list, you might want to include more 
of your code so we can see the bigger picture.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scared about refrences...

2006-10-30 Thread SpreadTooThin

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, SpreadTooThin
> wrote:
>
> > I'm really worried that python may is doing some things I wasn't
> > expecting... but lets see...
>
> Expect that Python never copies something if don't ask explicitly for a
> copy.
>
> > if I pass a list to a function def fn(myList):
> >
> > and in that function I modify an element in the list, then does the
> > callers list get modied as well.
> >
> > def fn(list):
> >list[1] = 0
> >
> > myList = [1, 2, 3]
> > print myList
> > fn(myList)
> > print myList
> >
>  [1,2,3]
>  [1,0,3]
> >
> > How can I avoid this?  In this case this is a really simplified example
> > but the effects are the same...
>
> In this case:
>
> def fn(lst):
> lst = list(lst)
> lst[1] = 0
>
>
> > How do I specify or create deep copies of objects that may contain
> > other objects that may contain other object that may contain other
> > objects
>
> See the `copy` module especially `copy.deepcopy()`.
>
I'm aware of __deepcopy__ but does that mean that every object in the
object
needs to have its own deep copy?  And how do I ensure that?




> Ciao,
>   Marc 'BlackJack' Rintsch

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


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
On Oct 30, 2:52 pm, John Salerno <[EMAIL PROTECTED]> wrote:
Don't know for sure, but you can try calling the Refresh() method on
the
> text control and see if that fixes it.

Didn't make a difference.  Not sure what the problem is, I am wondering
if it is a layout issue since that is my weak spot with wxPython.

sizerTextPanel =
wx.StaticBoxSizer(self.sizerTextPanel_staticbox, wx.HORIZONTAL)
sizerTextPanel .Add(self.textPane, 1, wx.ALL|wx.EXPAND, 2)
self.textPanel.SetAutoLayout(True)
self.textPanel.SetSizer(sizerTextPanel )
sizerTextPanel .Fit(self.textPanel)
sizerTextPanel .SetSizeHints(self.textPanel)
sizerMainPanel.Add(self.textPanel, 3, wx.ALL|wx.EXPAND, 0)


not sure if that means anything to anyone :)

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


Re: scared about refrences...

2006-10-30 Thread Fredrik Lundh
SpreadTooThin wrote:

> I'm really worried that python may is doing some things I wasn't
> expecting... but lets see...
> 
> if I pass a list to a function def fn(myList):
> 
> and in that function I modify an element in the list, then does the
> callers list get modied as well.
> 
> def fn(list):
>list[1] = 0
> 
> myList = [1, 2, 3]
> print myList
> fn(myList)
> print myList
> 
 [1,2,3]
 [1,0,3]
> 
> How can I avoid this?

by not modifying your arguments nilly-willy, of course.

> How do I specify or create deep copies of objects that may contain
> other objects that may contain other
> object that may contain other objects

http://www.effbot.org/pyfaq/how-do-i-copy-an-object-in-python.htm

but if you find yourself needing to copy things a lot, you need to look 
over your design.  well-designed Python code seldom needs to copy object
values.



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


Re: wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread John Salerno
abcd wrote:
> I have a TextCtrl which is set to be multi-line.  I have a function
> say, updateText(msg), which takes some string and appends it to the
> text control...
> 
> txtControl.AppendText(msg)
> 
> however, if the text that I am appending would cause the scroll
> bars to appear/or scroll since the text is long the textcontrol appears
> to be blank, until you click on the scroll bar...then the text appears.
>  Any ideas?  is this is a sizer problem or a TextCtrl issue??
> 
> thanks
> 

Don't know for sure, but you can try calling the Refresh() method on the 
text control and see if that fixes it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a sqlite connection and/or cursor is still open?

2006-10-30 Thread John Salerno
John Salerno wrote:
> Is there a way to check if a SQLite connection and cursor object are 
> still open? I took a look at the docs and the DB API but didn't see 
> anything like this.
> 
> Thanks.

Well, I might have somewhat solved this problem. Since SQLite allows you 
to use execute* methods directly on the connection object (thus no need 
to create a cursor object), all I need to do is call connection.close() 
and this doesn't seem to raise an error even if the connection has 
already been closed.

I'm still curious if there's a way to check for an open connection, but 
it seems like without the cursor object, the task is much easier.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: enumerate improvement proposal

2006-10-30 Thread Diez B. Roggisch
> Okay, I've googled "leaky abstractions" (as was probably your intended
> affect with your silence), read the famous essay, and still
> don't know what you mean and how it applies to what I have described.
> 
> Do you plan to justify your statement or emptily accuse people of violating
> esoteric principles?

While I can't claim to know what the effbot thinks (the 
skull-socks-wearing-python-coder-mindlink-technology is yet to be 
developed), I think it's pretty clear what he is after here:

Computers compute offsets into data zero-based. Some languages like 
pascal completely abstract that away from the user, but python doesn't.

So if your colleague/boss/whatever insists on indices being one-based, 
this abstraction you introduced for her pretty fast leaks pretty badly. 
Consider this simple example:

for offset, item in enumerate(some_list, start=1):
 if item.is_the_chosen_one():
 chosen_one_offset = offset

the_chosen_one = some_list[chosen_one_offset]

And bang, its Judas not Petrus who gets the pearly gates inc. stock options.

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


wxPython TextCtrl - weird scrolling behavior

2006-10-30 Thread abcd
I have a TextCtrl which is set to be multi-line.  I have a function
say, updateText(msg), which takes some string and appends it to the
text control...

txtControl.AppendText(msg)

however, if the text that I am appending would cause the scroll
bars to appear/or scroll since the text is long the textcontrol appears
to be blank, until you click on the scroll bar...then the text appears.
 Any ideas?  is this is a sizer problem or a TextCtrl issue??

thanks

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


Re: scared about refrences...

2006-10-30 Thread John Henry
I am no Python guru - just an ordinary user.

There is nothing "scary" about this.  There are (many) situations where
this is actually *desirable* but of course there are (many) situations
where this is an unwelcomed side-effect.

In situations where I don't want this to happen, I simply pass down the
list as an non-mutable object (like converting the list to a tuple).

It took me a little bit of getting used to this concept as well:
everything is either a mutable object, or a non-mutable object.  I just
have to throw away trying to use concept of "pointers" in Python.

SpreadTooThin wrote:
> I'm really worried that python may is doing some things I wasn't
> expecting... but lets see...
>
> if I pass a list to a function def fn(myList):
>
> and in that function I modify an element in the list, then does the
> callers list get modied as well.
>
> def fn(list):
>list[1] = 0
>
> myList = [1, 2, 3]
> print myList
> fn(myList)
> print myList
>
> >>> [1,2,3]
> >>> [1,0,3]
>
> How can I avoid this?  In this case this is a really simplified example
> but the effects are the same...
> How do I specify or create deep copies of objects that may contain
> other objects that may contain other
> object that may contain other objects

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


Re: scared about refrences...

2006-10-30 Thread Neil Cerutti
On 2006-10-30, SpreadTooThin <[EMAIL PROTECTED]> wrote:
> def fn(list):
>list[1] = 0
>
> myList = [1, 2, 3]
> print myList
> fn(myList)
> print myList
>
 [1,2,3]
 [1,0,3]
>
> How can I avoid this?  In this case this is a really simplified
> example but the effects are the same... How do I specify or
> create deep copies of objects that may contain other objects
> that may contain other object that may contain other
> objects

See 3.18 Copy -- Shallow and deep copy operations.

-- 
Neil Cerutti
I pulled into a lay-by with smoke coming from under the bonnet. I
realized the car was on fire so took my dog and smothered it with a
blanket. --Insurance Claim Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scared about refrences...

2006-10-30 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, SpreadTooThin
wrote:

> I'm really worried that python may is doing some things I wasn't
> expecting... but lets see...

Expect that Python never copies something if don't ask explicitly for a
copy.

> if I pass a list to a function def fn(myList):
> 
> and in that function I modify an element in the list, then does the
> callers list get modied as well.
> 
> def fn(list):
>list[1] = 0
> 
> myList = [1, 2, 3]
> print myList
> fn(myList)
> print myList
> 
 [1,2,3]
 [1,0,3]
> 
> How can I avoid this?  In this case this is a really simplified example
> but the effects are the same...

In this case:

def fn(lst):
lst = list(lst)
lst[1] = 0


> How do I specify or create deep copies of objects that may contain
> other objects that may contain other object that may contain other
> objects

See the `copy` module especially `copy.deepcopy()`.

Ciao,
Marc 'BlackJack' Rintsch

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


scared about refrences...

2006-10-30 Thread SpreadTooThin
I'm really worried that python may is doing some things I wasn't
expecting... but lets see...

if I pass a list to a function def fn(myList):

and in that function I modify an element in the list, then does the
callers list get modied as well.

def fn(list):
   list[1] = 0

myList = [1, 2, 3]
print myList
fn(myList)
print myList

>>> [1,2,3]
>>> [1,0,3]

How can I avoid this?  In this case this is a really simplified example
but the effects are the same...
How do I specify or create deep copies of objects that may contain
other objects that may contain other
object that may contain other objects

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


Re: ANN: SPE 0.8.3.c Python IDE editor

2006-10-30 Thread Chris Seymour
Hi Stani,
Not able to reach Berlios.  The SourceForge page does not have the
Windows installer.  Any ideas when it will be available?

Thanks.

Chris
Bernard wrote:
> thanks Stani!
>
> SPE - Stani's Python Editor wrote:
> > This is a maintenance release (mostly bug fixing) to prove that SPE is
> > alive and well! In case you are using wxPython2.7 you'll need to
> > upgrade to this release. Submitted patches will be reviewed and
> > included if approved for next release. Thanks for all your patient
> > support and continuing donations.
> >
> > The SPE 0.8.2.a release got downloaded 110550 times on berlios and
> > sourceforge together. Not bad. This means SPE has not seen an update
> > for a while or is getting very popular. Maybe both ;-)
> >
> > Installers are available for python 2.3, 2.4 and 2.5 for Windows and as
> > a rpm including wxPython. Other operating systems can choose the
> > no-setup.zip or targ.gz archives. A .deb archive is being prepared for
> > Debian Linux systems such as Ubuntu.
> >
> > wxGlade is unfortunately not compatible with wxPython2.7. So if you
> > want to use, you'll need wxPython2.6.
> >
> > :**Fixes**:
> >
> > - output is now done with a fixed font
> > - uml.py is now again a stand alone demo
> > - upgraded and fixed wxGlade
> > - fixed for wxPython2.7 (and still backwards compatible with
> > wxPython2.6)
> > - updated NotebookCtrl
> >
> > :**Contributors**:
> >
> > - Andrea Gavana (NoteBookCtrl)
> > - Alberto Griggio (wxGlade)
> > - Michael Foord (python 2.3 + 2.5 releases for windows)
> >
> > :**Donations**:
> >
> > The development of SPE is driven by donations. Each of these donors
> > receives the pdf manual in thanks for their support of SPE.
> >
> > - James Carroll (60 euro)
> > - John DeRosa (50 euro)
> > - Fumph LLC (50 euro)
> > - Ronald Britton (40 euro)
> > - David Downes (40 euro)
> > - Jorge Carrillo (40 euro)
> > - Nicolas Berney (40 euro)
> > - Francois Schnell (30 euro)
> > - Olivier Cortes (30 euro)
> > - Ayrshire Business Consulting Limited (30 euro)
> > - Chris White (25 euro)
> > - Thomas Wengerek (20 euro)
> > - John Rudolph (20 euro)
> > - Michael O'Keefe (20 euro)
> > - Michael Brickenstein (20 euro)
> > - Richard Walkington (20 euro)
> > - Oliver Tomic (20 euro)
> > - Jose Maria Cortes Arnal (20 euro)
> > - Jeffrey Emminger (20 euro)
> > - Eric Pederson (20 $)
> > - Charles Bosson (15 euro)
> > - Angelo Caruso (15 euro)
> > - Chris Hengge (15 $)
> > - Loïc Allys (15 euro)
> > - Marcin Chojnowski (15 euro)
> > - Boris Krasnoiarov (15 euro)
> > - Paul Furber (15 euro)
> > - Gary Robson (15 euro)
> > - Ralf Wieseler (15 euro)
> > - Samuel Schulenburg (10 euro)
> > - Leland Hulbert II (10 euro)
> > - Javier De La Mata Viader (10 euro)
> > - Dorman Musical Instruments (10 euro)
> > - Jaroslaw Sliwinski (10 euro)
> > - Alessandro Patelli (10 euro)
> > - James Pretorius (10 euro)
> > - Richard Wayne Garganta (10 euro)
> > - Maurizio Bracchitta (10 euro)
> > - Larry Lynch (10 euro)
> > - Kay Fricke (10 euro)
> > - Henrik Binggl (10 euro)
> > - Jerol Harrington (10 euro)
> > - Victor Adan (10 euro)
> > - James Fuqua (10 euro)
> > - Christian Seberino (5 euro)
> > - Serge Smeesters (5 euro)
> > - Jarek Libert (5 euro)
> > - Robin Friedrich (5 euro)
> > - Udo Rabe (5 euro)
> > - Roch Leduc (4 euro)
> > - Rha Diseno y Desarrollo (2 euro)
> >
> > :**Installation**:
> >
> > - See http://pythonide.stani.be/manual/html/manual2.html
> >
> > :**Development**:
> >
> > - http://developer.berlios.de/mail/?group_id=4161
> >
> > About SPE:
> > SPE is a python IDE with auto-indentation, auto completion, call tips,
> > syntax coloring, uml viewer, syntax highlighting, class explorer,
> > source index, auto todo list, sticky notes, integrated pycrust shell,
> > python file browser, recent file browser, drag&drop, context help, ...
> > Special is its blender support with a blender 3d object browser and its
> > ability to run interactively inside blender. Spe integrates with XRCed
> > (gui
> > designer) and ships with wxGlade (gui designer), PyChecker (source
> > code doctor), Kiki (regular expression console) and WinPdb (remote,
> > multi-threaded debugger).
> >
> > The development of SPE is driven by its donations. Anyone who donates
> > can ask for an nice pdf version of the manual without ads (74 pages).

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


Re: Calling GNU/make from a Python Script

2006-10-30 Thread skip

>> os.system("make -C %s" % build_dir)

>> OP specified GNU make, so that works fine, but make sure you're not
>> going to need to use it with another make before settling on that
>> alternative.  Frederik's works with more versions of make.

Understood.  That was the only reason I suggested it.

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


Re: Python 123 introduction

2006-10-30 Thread skip

dakman> This is great! A excellent tutorial for somone who has prior
dakman> experience in programming and is starting out in python. My
dakman> friend keeps wanting me to teach him python, I think this would
dakman> be the perfect link for him.

I'm not trying to minimize Jeremy's efforts in any way, but how is his
tutorial a significant improvement over the original
(http://www.python.org/doc/current/tut/)?

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


Re: Calling GNU/make from a Python Script

2006-10-30 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> Fredrik> build_dir = "path/to/makefile"
>
> Fredrik> cwd = os.getcwd() # get current directory
> Fredrik> try:
> Fredrik>  os.chdir(build_dir)
> Fredrik>  os.system("make")
> Fredrik> finally:
> Fredrik>  os.chdir(cwd)
>
> Or even:
>
> os.system("make -C %s" % build_dir)

OP specified GNU make, so that works fine, but make sure you're not
going to need to use it with another make before settling on that
alternative.  Frederik's works with more versions of make.

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


Re: create global variables?

2006-10-30 Thread Fredrik Lundh
Wojciech Muła wrote:

>> is there a simple way of creating global variables within a function?
> 
> def foo(name):
>   globals()[name] = "xxx"
>   globals()[name + 'aa'] = "yyy"
>   globals()[name + 'ab'] = "zzz"

that kind of coding is punishable by law in some jurisdictions.



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

Re: How to convert " " in a string to blank space?

2006-10-30 Thread Fredrik Lundh
一首诗 wrote:

> Is there any simple way to solve this problem?

  corresponds to a non-breaking space, chr(160).  if you're only 
dealing with this specific XML/HTML entity, you can do

 text = text.replace(" ", " ")

or

 text = text.replace(" ", chr(160))

to handle arbitrary entities and character references, pass the data 
through an HTML or XML parser, or use something like:

 http://effbot.org/zone/re-sub.htm#unescape-html



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

Re: How to convert " " in a string to blank space?

2006-10-30 Thread [EMAIL PROTECTED]


On Oct 30, 6:44 pm, "一首诗" <[EMAIL PROTECTED]> wrote:
> Oh, I didn't make myself clear.
>
> What I mean is how to convert a piece of html to plain text bu keep as
> much format as possible.
>
> Such as convert " " to blank space and convert  to "\r\n"
>

Then you can explore the parser,
http://docs.python.org/lib/module-HTMLParser.html, like

#!/usr/bin/env python
from HTMLParser import HTMLParser

parsedtext = ''

class Parser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == 'br':
global parsedtext
parsedtext += '\\r\\n'

def handle_data(self, data):
global parsedtext
parsedtext += data

def handle_entityref(self, name):
if name == 'nbsp':
pass

x = Parser()
x.feed('An   text')
print parsedtext


> Gary Herron wrote:
> > 一首诗 wrote:
> > > Is there any simple way to solve this problem?
>
> > Yes, strings have a replace method:
>
> > >>> s = "abc def"
> > >>> s.replace(' ',' ')
> > 'abc def'
>
> > Also various modules that are meant to deal with web and xml and such
> > have functions to do such operations.
> 
> > Gary Herron

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

Re: Python 123 introduction

2006-10-30 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> This is great! A excellent tutorial for somone who has prior experience
> in programming and is starting out in python. My friend keeps wanting
> me to teach him python, I think this would be the perfect link for him.

I'm glad you think it is useful. It needs a bit of cleaning up as it assumes
things such as python being in /usr/local/bin... I may try to improve this
later.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Observation on "Core Python Programming"

2006-10-30 Thread wesley chun
(warning: LONG reply)

thanks to those above for the kind remarks.  tackling comments
and questions, not quite in chronological order.  :-)


> Who would you say the book is aimed at? Advanced programmers?

this book is targeted towards technical professionals already
literate in another high-level language who wants to pick up
Python as quickly as possible.  it is not a topical coverage
of a programming language's features.  you know how after
learning a new language, it takes a few months to really "feel
comfortable" enough to *not* pick up a book in order to commence
writing code?  my goal is to reduce that time period while
provide the reader a comprehensive understanding of how the
standard types work, esp. in their relationship to Python's
memory model.  it is my belief that a solid foundation here
will reduce or eliminate any potential bugs you would've
written had you read a more conventional introductory text.


> What really jumped out at me is an interesting feature about how
> it sequences its topics, namely, (user-defined) functions are not
> introduced until chapter 11, fully 400 pages into the book.

i guess i found this post quite interesting because there is
such a focus on "what should be introduced when."  the purpose
of chapter 2 (getting started) is to proxy for the standard
"introduction to programming X" book.  if you read it, you
should be able to "get started in Python" immediately. you
have enough info on functions to start coding and probably
don't need var args, decorators, or any of that stuff yet. the
chapter on functions occur later because most of the time, what
we've shown you in "getting started" is enough to, ummm..., get
you started, and that all successive chapters are meant to dive
more deeply into each area.


> seems to confirm the "batteries are included" philosophy of
> Python. Perhaps there is less need to learn how to roll your
> own batteries as soon as possible.

this is definitely one of the hallmarks of the language. the
current user base already knows this... it's just more difficult
to get this out there to the general programming populus, esp.
when there are already so many languages starting with "P".  :-)


> The revenge of lambdas. Will they stay or will they go?"  ;-)

they will stay.  ;-)


> am interested in seeing the extend to which Python is genuinely
> "multi-paradigm" - able to blend the functional and imperative
> (and OO) paradigms together.

this comes from guido himself.  he "wants you to be able to see
the forest through the trees."  i see Python as a "greatest hits"
of many computer programming languages.  for our benefit, he's
given us the best stuff.


> I cant' exactly figure out why yet, but he has a way of explaining
> something, like, say, decorators, that in minimal words elucidates
> for me the intent behind why they are useful. That helps me
> understand how they work.

"Python fits your brain." (bruce eckel) i don't see why python
should have a monopoly on your brain.  i want me share too.  ;-)
the thing that makes writing a pleasurable is when the language
has so much to offer.  i use this book in teaching my python
courses, and the book mirrors my lecturing style.  i suppose that
rather than a dry college textbook, i'd rather write in a way as
if i was having a conversation with you, or if you were actually
sitting there attending one of my courses.  readers (as well as
course attendees) have remarked how questions they may come up
with as they are learning a topic are answered in the next section
or chapter (or 3-4 presentation slides) as the case may be.


> The second edition site doesn't give a sample chapter (but
> does give the complete preface)

ahhh, the secret here is that you need to look in the right place.
"prentice hall"s web page doesn't have it, but PHPTR's does, even
if they are the same publishing house.  for some reason, we've got
the featured book of the month!!  just go to http://phptr.com and
click the book's link there. you'll find:

- book's description
- table of contents
- preface
- sample chapter (getting started, chapter 2!)
- index

the last three are in PDF format.  if for some reason, october
ends and it's gone from the front page, here is a direct link:

http://phptr.com/title/0132269937

thanks to everyone for their support, esp. my excellent technical
reviewers for keeping me honest!  please send comments, suggestions,
corrections, and other feedback to me. i am happy to hear about any
issues you find in the book -- everything.  it doesn't matter if it
is the smallest grammatical edit, errors in the code, or just plain
wrong or misleading information.  don't believe everything you read!
(sometimes writing at 2, 3, and 4a in the morning does something to
your writing when you're trying to tackle a publisher's deadlines.)
keep checking the book's errata page at http://corepython.com
all book correspondence should go to corepython at yahoo dot com.

cheers!
-- wesley
- - - - - - - - - - - - - - - -

Re: create global variables?

2006-10-30 Thread J. Clifford Dyer
Alistair King wrote:
> Hi,
> 
> is there a simple way of creating global variables within a function?
> 
> ive tried simply adding the variables in:
> 
> def function(atom, Xaa, Xab):
> Xaa = onefunction(atom)
> Xab = anotherfunction(atom)
> 
> if i can give something like:
> 
> function('C')#where atom = 'C' but not necessarly include Xaa or Xab
> 
> i would like to recieve:
> 
> Caa = a float
> Cab = another float
> 
> ive tried predefining Xaa and Xab before the function but they are
> global values and wont change within my function. Is there a simple way
> round this, even if i call the function with the variables ('C', Caa, Cab)?
> ...
> 
> some actual code:
> 
> # sample dictionaries
> DS1v = {'C': 6}
> pt = {'C': 12.0107}
> 
> def monoVarcalc(atom):
> a = atom + 'aa'
> Xaa = a.strip('\'')
> m = atom + 'ma'
> Xma = m.strip('\'')
> Xaa = DS1v.get(atom)
> Xma = pt.get(atom)
> print Xma
> print Xaa
> 
> monoVarcalc('C')
> 
> print Caa
> print Cma
> ...
> it seems to work but again i can only print the values of Xma and Xaa
> 
> ?
> 
> Alistair
> 

I suspect you are misusing the concept of a function.  In most basic 
cases, and I suspect your case applies just as well as most, a function 
should take arguments and return results, with no other communication 
between the calling code and the function itself.  When you are inside 
your function don't worry about the names of the variables outside.  I'm 
not sure exactly where your floats are coming from, but try something 
like this:

 >>> def monoVarCalc(relevant_data):
... float1 = relevant_data * 42.0
... float2 = relevant_data / 23.0
... return float1, float2

 >>> C = 2001
 >>> Caa, Cab = monoVarCalc(C)
 >>> Caa
84042.0
 >>> Cab
87.0

Notice that you don't need to use the variable C (or much less the 
string "C", inside monoVarCalc at all.  It gets bound to the name 
relevant_data instead.

Also, if you are going to have a lot of these little results lying 
around, (Cab, Cac ... Czy, Czz), you might consider making them a list 
or a dictionary instead.  I won't tell you how to do that, though.  The 
online tutorial has plenty of information on that.

http://docs.python.org/tut/tut.html


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


Re: Python 123 introduction

2006-10-30 Thread [EMAIL PROTECTED]
This is great! A excellent tutorial for somone who has prior experience
in programming and is starting out in python. My friend keeps wanting
me to teach him python, I think this would be the perfect link for him.
Thanks.


Jeremy Sanders wrote:
> 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).
>
> HTML version:
>  http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123/
> Postscript LaTeX output:
>  http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123.ps
> PDF LaTeX output:
>  http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123.pdf
> LaTeX source:
>  http://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/python_123.tex
> 
> Jeremy
> 
> -- 
> Jeremy Sanders
> http://www.jeremysanders.net/

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


Re: How to convert " " in a string to blank space?

2006-10-30 Thread 一首诗
Oh, I didn't make myself clear.

What I mean is how to convert a piece of html to plain text bu keep as
much format as possible.

Such as convert " " to blank space and convert  to "\r\n"

Gary Herron wrote:
> 一首诗 wrote:
> > Is there any simple way to solve this problem?
> >
> >
> Yes, strings have a replace method:
>
> >>> s = "abc def"
> >>> s.replace(' ',' ')
> 'abc def'
>
> Also various modules that are meant to deal with web and xml and such
> have functions to do such operations.
> 
> 
> Gary Herron

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

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

2006-10-30 Thread [EMAIL PROTECTED]
I had to do something like this a while back for a modular IRC bot that
I wrote.
__import__() will do the trick, however to avoid getting a cache of the
module I recomend doing something like...

mod = reload( __import__("%s-%s-%s" % ( t[0], t[1], t[2] ) ) )


[EMAIL PROTECTED] wrote:
> Hi all,
>
> I have a script responsible for loading and executing scripts on a
> daily basis. Something like this:
>
> import time
> t = time.gmtime()
> filename = t[0] + '-' + t[1] + '-' + t[2] + '.py'
> import filename
>
> So, I have a module with an arbitrary file name and I want to load it,
> and later access its function definitions.
> How can I do this ?  In my example, the last line will obviously not
> work.

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


Re: How to convert " " in a string to blank space?

2006-10-30 Thread Gary Herron
一首诗 wrote:
> Is there any simple way to solve this problem?
>
>   
Yes, strings have a replace method:

>>> s = "abc def"
>>> s.replace(' ',' ')
'abc def'

Also various modules that are meant to deal with web and xml and such
have functions to do such operations.


Gary Herron



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

Re: How to convert " " in a string to blank space?

2006-10-30 Thread [EMAIL PROTECTED]
Is this what you want?

py> s = 'This string contains   two times   - end'
py> print s.replace(' ', ' '*6)
This string containstwo times- end


see http://docs.python.org/lib/string-methods.html

On Oct 30, 6:26 pm, "一首诗" <[EMAIL PROTECTED]> wrote:
> Is there any simple way to solve this problem?

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

Re: How to convert " " in a string to blank space?

2006-10-30 Thread martdi

一首诗 wrote:
> Is there any simple way to solve this problem?

>>> myString = " "
>>> myString = myString.replace(" ", "")

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

Re: enumerate improvement proposal

2006-10-30 Thread Anders J. Munch
Ben Finney wrote:
> 
> >>> def obstinate_economist_enumerate(items):
> ... enum_iter = iter((i+1, x) for (i, x) in enumerate(items))
> ... return enum_iter

iter is redundant here.

def natural_enumerate_improvement(items, start=0):
 return ((i+start, x) for (i, x) in enumerate(items))

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


How to convert " " in a string to blank space?

2006-10-30 Thread 一首诗
Is there any simple way to solve this problem?

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


Re: create global variables?

2006-10-30 Thread Alistair King
Gary Herron wrote:
> Alistair King wrote:
>   
>> Hi,
>>
>> is there a simple way of creating global variables within a function?
>>
>>   
>> 
> Use the "global" statement within a function to bind a variable to a
> global. 
>
> See http://docs.python.org/ref/global.html for details.
>
>
>   
 def x():
 
> ...  global g
> ...  g = 123
> ...
>   
 x()
 g
 
> 123
>   
>
> Gary Herron
>
>
>
>
>   
>> ive tried simply adding the variables in:
>>
>> def function(atom, Xaa, Xab):
>> Xaa = onefunction(atom)
>> Xab = anotherfunction(atom)
>>
>> if i can give something like:
>>
>> function('C')#where atom = 'C' but not necessarly include Xaa or Xab
>>
>> i would like to recieve:
>>
>> Caa = a float
>> Cab = another float
>>
>> ive tried predefining Xaa and Xab before the function but they are
>> global values and wont change within my function. Is there a simple way
>> round this, even if i call the function with the variables ('C', Caa, Cab)?
>> ..
>>
>> some actual code:
>>
>> # sample dictionaries
>> DS1v = {'C': 6}
>> pt = {'C': 12.0107}
>>
>> def monoVarcalc(atom):
>> a = atom + 'aa'
>> Xaa = a.strip('\'')
>> m = atom + 'ma'
>> Xma = m.strip('\'')
>> Xaa = DS1v.get(atom)
>> Xma = pt.get(atom)
>> print Xma
>> print Xaa
>>
>> monoVarcalc('C')
>>
>> print Caa
>> print Cma
>> ..
>> it seems to work but again i can only print the values of Xma and Xaa
>>
>> ?
>>
>> Alistair
>>
>>   
>> 
>
>   
have tried:

def monoVarcalc(atom):
a = atom + 'aa'
Xaa = a.strip('\'')
m = atom + 'ma'
Xma = m.strip('\'')
global Xma
global Xaa
Xaa = DS1v.get(atom)
Xma = pt.get(atom)
print Xma
print Xaa

monoVarcalc('C')

print Caa
print Cma
...

where global Xma & Xaa are before and after any further functions

i get still get the error

Traceback (most recent call last):
  File "DS1excessH2O.py", line 54, in ?
print Caa
NameError: name 'Caa' is not defined


-- 
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-30 Thread Wojciech Muła
Alistair King wrote:
> is there a simple way of creating global variables within a function?

def foo(name):
globals()[name] = "xxx"
globals()[name + 'aa'] = "yyy"
globals()[name + 'ab'] = "zzz"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create global variables?

2006-10-30 Thread robert
Alistair King wrote:
> Hi,
> 
> is there a simple way of creating global variables within a function?
> 

#module global:

def f(atom):
global a
a=1
globals()[atom+'var']=2

def f():
a=b=1
globals().update(locals())

_global=sys.modules[__name__]

def f(atom):
_global.a = 1
setattr(_global,atom+'var', 2)

# all/app global 

import myglobals

def f(atom):
myglobals.a=1
setattr(myglobals)


your example application seems to point towards 'odd' use of these techniques.


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


Re: create global variables?

2006-10-30 Thread Gary Herron
Alistair King wrote:
> Hi,
>
> is there a simple way of creating global variables within a function?
>
>   
Use the "global" statement within a function to bind a variable to a
global. 

See http://docs.python.org/ref/global.html for details.


>>> def x():
...  global g
...  g = 123
...
>>> x()
>>> g
123
>>>

Gary Herron




> ive tried simply adding the variables in:
>
> def function(atom, Xaa, Xab):
> Xaa = onefunction(atom)
> Xab = anotherfunction(atom)
>
> if i can give something like:
>
> function('C')#where atom = 'C' but not necessarly include Xaa or Xab
>
> i would like to recieve:
>
> Caa = a float
> Cab = another float
>
> ive tried predefining Xaa and Xab before the function but they are
> global values and wont change within my function. Is there a simple way
> round this, even if i call the function with the variables ('C', Caa, Cab)?
> ..
>
> some actual code:
>
> # sample dictionaries
> DS1v = {'C': 6}
> pt = {'C': 12.0107}
>
> def monoVarcalc(atom):
> a = atom + 'aa'
> Xaa = a.strip('\'')
> m = atom + 'ma'
> Xma = m.strip('\'')
> Xaa = DS1v.get(atom)
> Xma = pt.get(atom)
> print Xma
> print Xaa
>
> monoVarcalc('C')
>
> print Caa
> print Cma
> ..
> it seems to work but again i can only print the values of Xma and Xaa
>
> ?
>
> Alistair
>
>   

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


Re: IE7 skulduggery?

2006-10-30 Thread Alistair King
BartlebyScrivener wrote:
> Found fix for this at Mozilla:
>
> http://kb.mozillazine.org/Default_browser
>
> Apparently, even though it LOOKS and ACTS like Firefox is still your
> default browser after an IE7 upgrade, it's not.
>
> To fix, you must run:
>
> firefox.exe -silent -nosplash -setDefaultBrowser
>
> Which also fixes the webbrowser. py problem.
>
> At least so far.
>
> rd
>
>   
yes, annoying

i know that this may not be related to python but occasionally when im
using firefox under windows and /i think/ when i open IE7, firefox hangs
and wont reopen until i restart. Is this likely to be anything related
to IE7?

-- 
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


  1   2   >