Re: Https Form Page

2005-04-09 Thread Hasan D
 I cant figure out, always gives me the form page. Everything looks ok but ?


On Apr 9, 2005 2:07 AM, Joshua Ginsberg [EMAIL PROTECTED] wrote:
 If url is your formpage and your formdata is correct, it should work.
 
 Do you need to have a cookie set? Is it 304 redirecting you?
 
 -jag
 
 
 
 Joshua Ginsberg -- [EMAIL PROTECTED]
 Brainstorm Internet Network Operations
 970-247-1442 x131
 On Apr 8, 2005, at 4:51 PM, Hasan D wrote:
 
  Thank you for fast reply.
  Your program works fine. But when i print the https_response it gives
  me the form page. I want to send the form and print the result page.
 
 
 
  On Apr 9, 2005 12:19 AM, Joshua Ginsberg [EMAIL PROTECTED]
  wrote:
  Try:
 
  import urllib2, urllib
  formdata = urllib.urlencode({'a':1,'b':2})
  request = urllib2.Request(url)
  request.add_data(formdata)
  opener = urllib2.build_opener(urllib2.HTTPSHandler())
  urllib2.install_opener(opener)
  fs = urllib2.urlopen(request)
  https_response = fs.read()
  https_headers = fs.info().headers
  https_mimetype = fs.info().type
 
  -jag
 
 
 
  Joshua Ginsberg -- [EMAIL PROTECTED]
  Brainstorm Internet Network Operations
  970-247-1442 x131
  On Apr 8, 2005, at 2:13 PM, Hasan D wrote:
 
  I'm new on this httplib and urllib. Actually I dont know what should
  i
  use.
 
  I want to fill the form in a https page , and return the result . I
  write a test code but always gives errors. I cant find any good
  example about this on the net. What should I do about this ?
 
 
  import urlparse,urllib,httplib,string,htmllib,formatter
 
  #port=443
  target=https://www.abc.com/;
  params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
  http=httplib.HTTP(https://www.abc.com/,443)
 
  data='Name=xAdress=x'
  headers = {Content-type:
  application/x-www-form-urlencoded,Accept: text/plain}
 
  print Sending Data On +target+...\n
  http.putrequest(POST,target+/xxx.asp?q=7b=11,params)
 
  response = http.getresponse()
  print response.status, response.reason
 
  http.send(data)
 
  code,msg,headers = http.getreply()
 
  print HTTP Code : ,str(code)
  print HTTP Connection : ,msg
  print HTTP headers : \n,headers,\n
 
  HTML=http.getfile().read()
  MyParser=htmllib.HTMLParser(formatter.NullFormatter())
  MyParser.feed(HTML)
  # Print all the anchors from the results page
  print MyParser.anchorlist
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 
 
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 
 
 
 
 
 

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


Re: Thoughts on some stdlib modules

2005-04-09 Thread Steve Holden
Ron_Adam wrote:
On Fri, 08 Apr 2005 05:15:23 -0400, vegetax [EMAIL PROTECTED]
wrote:

Are those issues being considered right now? i cant find any PEP addressing
the issue especifically, at least cooking it for python 3000.
specific topics could be:
grouping related modules.
removing useless legacy modules.
refactoring duplicated functionality.
removing/redesigning poorly written modules.
adding a module versioning system.

I've been thinking that the lib directory could be better named and
rearranged a bit.  I sometimes mistakenly open the libs directory
instead of lib because of the name similarity.
An alternative might be to use the name packs or packages in place
of lib, which would emphasize the use of packages as the primary
method of extending python. The standard library could then be a
package called stdlib within this directory. Third party packages
would then be along side stdlib and not within a directory that is
within the standard library.
It would be mostly a cosmetic change, but I believe it would be worth
doing if it could be done without breaking programs that may have hard
coded path references to the library.  :-/
Ron
Ron:
You do a lot of thinking, don't you? :-)
This is a *very large* change, not a cosmetic one, requiring changes to 
many installation routines (including, probably, distutils) and causing 
problems for software that attempts to operate with multiple versions of 
Python - and those projects have problems enough as it is despite 
Python's quite fine record of careful development.

This seems a rather high price to pay just to avoid having you 
mistakenly avoid opening libs instead of lib - a distinction that is 
only meaningful on Windows platforms anyway, I believe.

You are correct in suggesting that the library could be better organized 
than it is, but I felt we would be better off deferring such change 
until the emergence of Python 3.0, which is allowed to break backwards 
compatibility. So, start working on your scheme now - PEP 3000 needs 
contributions. My own current favorite idea is to have the current 
standard library become the stdlib package, but I'm sure a lot of 
people would find that suggestion at least as half-baked as yours.

{If an idea is more-half-baked than something exactly half-baked is it 
0.4-baked or 0.6-baked? Does more half-baked actually mean less baked?)

regards
 Steve
--
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Python/wxPython Reducing memory usage.

2005-04-09 Thread lotmr
I have previously posted a simple app I am working on, and while I love
python and wxWindows, after checking the memory usage on such a simple
app (system try application launcher) I see that it climbs to over
17mb! I have reduced all my imports to the bare workable minimum and
that just gets it under 17mb. Is there any way that I could compile or
optimize the my program and/or its memory usage?
(Note: I don't have a problem with making this program win32 specific,
as it already is only win32)


CODE:
#this section broken down soley for readability, normally one line
from wxPython.wx import wxMessageDialog,wxFrame,wxMenu,
wxBitmap,wxOK,wxID_ANY,wxID_EXIT,wxID_ABOUT,
wxBITMAP_TYPE_ICO,wxBITMAP_TYPE_PNG,wxMenuItem,
wxPySimpleApp,wxTaskBarIcon,wxIcon,EVT_TASKBAR_RIGHT_UP,EVT_MENU
#end

from os import startfile
from sys import exit

class MainWindow(wxFrame):
def OnAbout (self, event):
m = wxMessageDialog( self,  LUNCH Bar 0.1 \n
  A launch bar written in Python using
wxWindows,About LUNCH, wxOK)
m.ShowModal()
m.Destroy
def OnExit (self, event):
self.tbi.Destroy()
exit()
def OnTrayRight (self, event):
self.PopupMenu(self.rhtmenu)
def OnLaunch (self, event):
print event.GetString()
path = 'D:\Program Files\Mozilla Firefox\Firefox.exe'
startfile(path)
def __init__(self,parent,id,title):
wxID_FIREFOX = 1117
wxFrame.__init__(self,parent,wxID_ANY, title, size = (
200,100))
self.tbi = wxTaskBarIcon()
icon = wxIcon('package.ico',wxBITMAP_TYPE_ICO)
self.tbi.SetIcon(icon, '')
self.rhtmenu = wxMenu()
icon = wxBitmap(name = 'ffico.png', type = wxBITMAP_TYPE_PNG)
item = wxMenuItem(parentMenu = self.rhtmenu, id = wxID_FIREFOX,
text='Firefox')
item.SetBitmap(icon)
self.rhtmenu.Append(wxID_EXIT, Exit, Terminate this program)
self.rhtmenu.Append(wxID_ABOUT, About, Information about this
program)
self.rhtmenu.AppendSeparator()
self.rhtmenu.AppendItem(item)
EVT_TASKBAR_RIGHT_UP(self.tbi, self.OnTrayRight)
EVT_MENU(self, wxID_ABOUT, self.OnAbout)
EVT_MENU(self, wxID_EXIT, self.OnExit)
EVT_MENU(self, wxID_FIREFOX, self.OnLaunch)


appwin = wxPySimpleApp()
frame = MainWindow(None, -1, Small editor)
appwin.MainLoop()

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


Re: Declaring variables from a list

2005-04-09 Thread Pierre Quentel
You can use the built-in statement exec 
(http://www.python.org/doc/2.4.1/ref/exec.html) :

# Blob = ['Var1', 'Var2', 'vAR3']
# i = 5
# for listitems in Blob:
# i += 1
# exec('%s = i' %listitems)
#
# print Var1, Var2, vAR3
Regards,
Pierre
--
http://mail.python.org/mailman/listinfo/python-list


Re: EOL created by .write or .encode

2005-04-09 Thread Fredrik Lundh
Xah Lee [EMAIL PROTECTED] wrote:

 Why is that some of my files written out by
outF.write(outtext.encode('utf-8'))
 has ascii 10 as EOL, while others has ascii 13 as EOL?

outF = open(tempName,'wb')
outF.write(outtext.encode('utf-8'))
outF.close()

UTF-8 is not a binary format.  get rid of the b flags, and things
will work as expected.

/F 



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


Re: EOL created by .write or .encode

2005-04-09 Thread Xah Lee
I found the problem now. (after some  one hour debug time) Python
didn't have problem. Emacs does.

If you open a file in emacs, it will open fine regardless whether the
EOL is ascii 10 or 13. (unix or mac) This is a nice feature. However,
the what-cursor-position which is used to show cursor position and the
char's ascii code, says the EOL is ascii 10 when it is in fact ascii
13. Fuck the irresponsible fuckhead who is responsible for this.

http://xahlee.org/UnixResource_dir/writ/responsible_license.html

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/



Xah Lee wrote:
 Why is that some of my files written out by
outF.write(outtext.encode('utf-8'))
 has ascii 10 as EOL, while others has ascii 13 as EOL?
 both of these files's EOL are originally all ascii 10.

 If i remove the EOL after the tt below in the place string, then this
 doesn't happen.

 findreplace = [
 (ur'/body',
 ur'''tt
 /body'''),
 ]

 ...

inF = open(filePath,'rb')
s=unicode(inF.read(),'utf-8')
inF.close()

for couple in findreplace:
outtext=s.replace(couple[0],couple[1])
s=outtext
outF = open(tempName,'wb')
outF.write(outtext.encode('utf-8'))
outF.close()

 thanks.

  Xah
  [EMAIL PROTECTED]
  http://xahlee.org/PageTwo_dir/more.html 

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


ideal rankings for python related search engine queries

2005-04-09 Thread Amir Michail
Hi,

Google is good, but not perfect.

CollaborativeRank takes Google rankings as a starting point but allows
users to tweak them in a collaborative way to achieve something even
better.

Perhaps some people in this group might be interested in producing even
better rankings for python related queries?

http://www.cse.unsw.edu.au/~amichail/collabrank
http://www.cse.unsw.edu.au/~amichail/collabrank/collabrank.pdf

The system uses a hubs and authorities style analysis to encourage
timely and helpful ranking suggestions.  See the paper for details.

Amir

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


check instace already running...

2005-04-09 Thread Fabio Pliger
Hi,
is it possibile, in python, to check for an already running instance of an
application?
My problem is that, if my program i running and the user relaunch it, i
don't want to open a new instance and have to instances of the same program
running togheter...
Can someone help me on this?
Fabio P.


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


Re: Puzzling OO design problem

2005-04-09 Thread Dirk Thierbach
George Sakkis [EMAIL PROTECTED] wrote:

 1. There is a (single inheritance) hierarchy of domain classes, say
 A-B-..-Z (arrows point to the parent in the inheritance tree).
 2. This hierarchy evolved over time to different versions for each
 class. So for example, version's 1 hierarchy would be A_v1 -B_v1
 -..-Z_v1.
 3. At runtime, only one version is selected by a factory function.

 Up to this point, the inheritance graph would be the following:
 
 A - A_V1 ... - A_Vn
 ^ ^   ^
 | |   |
 B - B_V1 ... - B_Vn
 . .   .
 . .   .
 . .   .
 ^ ^   ^
 | |   |
 Z - Z_V1 ... - Z_Vn

Interesting problem.

 This could be implemented either with multiple inheritance (e.g.
 B_V1(B,A_V1)) 

To help myself thinking about that, let's make a somewhat complicated
example, somewhere in the middle of the graph, with the possibility of
introducing a hole at B3. I also shorten A_Vn to An etc. Consider the
subgraph (with nonstandard annotations of method definition after the bar
(to save space) as explained below):

A2 | f   -   A3 | f
^ ^
| |
B2   -   B3   
^ ^
| |
C2 | g   -   C3 | h

Assume a method g that is present in C2 but not changed in C3. Now g
calls a method f, which is inherited unchanged in C2 from A2 (and not
changed in B2, B3 or C3, either), but changed in A3. Finally, let h
call g in C3. As here the inheritance columns have priority, one
would expect then g to call f in A3, and not in A2, for example.

So what you need is that every method, even if not originating from
the real class, is looked up first in the column above the real
class, then in the column left to that, and so on.

Ok. Multiple inheritance can often select priority for conflicting
methods. If you can specify yhat tou want column priority for
each class, you're fine.

 or using the bridge design pattern |Z| times, one per each row.

When I read your description above, I also thought immediately
bridge pattern, but then I tried to write down details,
and got stuck. How would you do it?

 Now the problem is that there are 'holes' in this
 inheritance lattice: Not all versions introduced new variations of
 all types; [...]

 My first thought was to create all the missing classes dynamically,
 but it's somewhat obscure and it may not be that simple. Is there a
 more elegant solution, either a general design pattern or some
 clever python metaprogramming hack ?

In the most general case, you need to access time the whole upper
left subgraph at class creation, collect all methods defined in this
subgraph with column priority, and overwrite or add to that any
methods defined in the newly defined class.

I don't know enough about the intricacies of Python's class creation
to make a concrete suggestion, but I'd think that would be possible
with the help of __metaclass__. You would need some sort of
repository for the complete inheritance. One way to do that would
be to create the chain A ... Z first, letting A inherit from some
special class with __metaclass__ set, and then store an array
of all versions somewhere inside the class namespace.

You'd also need some special syntax to create a new version of a class
(say, again inheriting from some special class with __metaclass__
set).  You could set the version inside the class definition, and then
let the __metaclass__ routine disable the normal inheritance
mechanism, and add missing methods as appropriate.

This could for example look like

class A(Versioning):
  ...

class B(A):
  ...

class C(B):
  def h ...
  ...

class A2(NewVersion,A):
  __version__ = 2
  def f(): ...

class B2(NewVersion,B):
  __version__ = 2

class C2(NewVersion,C): 
  __version__ = 2
  def g(): ... f() ...

class A3(NewVersion,A):
  __version__ = 3
  def f(): ...

class C3(NewVersion,C): 
  __version__ = 3
  def h(): ... g() ...

with a hole at B3, as in the example. C3 will get g from C2 and f from
A3, and hence the call chain will work correctly. Also, C3 will have no
base classes (or maybe only the __metaclass__ ones), the inherited
class A, B, C are just used by the class creation process to find
out where to look for the inheritance matrix.

Others who know more about the class creation mechanism will no doubt
improve this suggestion, point out my errors, and tell you how to
implement it :-) Note that you're basically completely changing the
normal inheritance mechanism, and the class objects will be larger,
because they'll have to copy all the necessary methods.

I cannot think of any pattern that would give similar flexibility.

- Dirk

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


Re: Counting iterations

2005-04-09 Thread Fredrik Lundh
Derek Basch wrote:

 ooops you are right. Should have been:

 pets = [cat, dog, bird]
 num_pets = 0
 for i in pets:
num_pets += 1
print pet + # + num_pets

Traceback (most recent call last):
  File example.py, line 5, in ?
print pet + # + num_pets
TypeError: cannot concatenate 'str' and 'int' objects

/F 



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


Re: check instace already running...

2005-04-09 Thread Sidharth Kuruvila
I haven't tested this. There is probably a better way of doing this
looking at process information. I use a lock file to mark that the
program is already running. The problem is that for an abrupt shutdown
the file might not be removed.

import atexit
if os.path.exists(lockfile):
   print there is an instance already running
else:
   file(lockfile, w).close()
   atexit.register(lambda:os.remove(lockfile))

//Your code here

On Apr 9, 2005 2:32 PM, Sidharth Kuruvila [EMAIL PROTECTED] wrote:
 I haven't tested this. There is probably a better way of doing this
 looking at process information. I use a lock file to mark that the
 program is already running. The problem is that for an abrupt shutdown
 the file might not be removed.
 
 import atexit
 if os.path.exists(lockfile):
 print there is an instance already running
 else:
 file(lockfile, w).close()
 atexit.register(lambda:os.remove(lockfile))
 
 //Your code here
 
 On Apr 9, 2005 2:01 PM, Fabio Pliger [EMAIL PROTECTED] wrote:
  Hi,
  is it possibile, in python, to check for an already running instance of an
  application?
  My problem is that, if my program i running and the user relaunch it, i
  don't want to open a new instance and have to instances of the same program
  running togheter...
  Can someone help me on this?
  Fabio P.
 
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 
 --
 http://blogs.applibase.net/sidharth
 


-- 
http://blogs.applibase.net/sidharth
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on some stdlib modules

2005-04-09 Thread Ron_Adam
On Sat, 09 Apr 2005 02:22:45 -0400, Steve Holden [EMAIL PROTECTED]
wrote:

Ron_Adam wrote:
 On Fri, 08 Apr 2005 05:15:23 -0400, vegetax [EMAIL PROTECTED]
 wrote:
 
 
Are those issues being considered right now? i cant find any PEP addressing
the issue especifically, at least cooking it for python 3000.

specific topics could be:

grouping related modules.
removing useless legacy modules.
refactoring duplicated functionality.
removing/redesigning poorly written modules.
adding a module versioning system.
 
 
 I've been thinking that the lib directory could be better named and
 rearranged a bit.  I sometimes mistakenly open the libs directory
 instead of lib because of the name similarity.
 
 An alternative might be to use the name packs or packages in place
 of lib, which would emphasize the use of packages as the primary
 method of extending python. The standard library could then be a
 package called stdlib within this directory. Third party packages
 would then be along side stdlib and not within a directory that is
 within the standard library.
 
 It would be mostly a cosmetic change, but I believe it would be worth
 doing if it could be done without breaking programs that may have hard
 coded path references to the library.  :-/
 
 Ron
 
Ron:

You do a lot of thinking, don't you? :-)

Just the way my mind works. ;-)

This is a *very large* change, not a cosmetic one, requiring changes to 
many installation routines (including, probably, distutils) and causing 
problems for software that attempts to operate with multiple versions of 
Python - and those projects have problems enough as it is despite 
Python's quite fine record of careful development.

I thought it might be more involved than it seemed.

This seems a rather high price to pay just to avoid having you 
mistakenly avoid opening libs instead of lib - a distinction that is 
only meaningful on Windows platforms anyway, I believe.

That's not surprising on windows.  

You are correct in suggesting that the library could be better organized 
than it is, but I felt we would be better off deferring such change 
until the emergence of Python 3.0, which is allowed to break backwards 
compatibility. So, start working on your scheme now - PEP 3000 needs 
contributions. My own current favorite idea is to have the current 
standard library become the stdlib package, but I'm sure a lot of 
people would find that suggestion at least as half-baked as yours.

Yes, I agree, the stdlib should be a package.  So I don't find it
half-baked at all.  Packages are part of python, so python should take
advantage of them.  

As far as a organizing scheme, I've come to the conclusion, files
should be organized by who's responsible for them, as in who to
contact if something doesn't work correctly. And not allowing files to
be intermixed from different sources is definitely worth doing if
possible.  Something Windows does very very badly.

For Python, that would mean packages should be fully self contained
and don't move any files to other directories if possible. Which
simplifies installs, uninstalls, and upgrades. But it would require
much more than a cosmetic change, and more than the simple, or not so
simple, directory changes I suggested.

One of the tools I wrote in C (early 90's), was a make file maker. I
still have the source code here somewhere.  Starting with the main
source file and a template with the compile options in it, it searched
all included files recursively for references and built the make file
using the template.  It really made large projects easy.  I don't
think that's anything new now.  Dist tools should do something like
that to find needed files.  It shouldn't matter what directories they
are in as long as it has read access rights to them, or they are in
the search path, or there's a direct or indirect reference to them in
the source code someplace.

{If an idea is more-half-baked than something exactly half-baked is it 
0.4-baked or 0.6-baked? Does more half-baked actually mean less baked?)

regards
  Steve

All new ideas are un-baked, they aren't fully baked until they are old
ideas which have been implemented. So 0.6 baked is more than half
baked, and 0.4 baked is ... pudding. ;-)

I'll consider working on that PEP. It sounds like it might be a good
project for me. 

Cheers,
Ron



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


Re: Puzzling OO design problem

2005-04-09 Thread Michael Spencer
George Sakkis wrote:
boiled down version of George's exmaple

I'm not sure if it was clear to you, but my problem is the dummy
WorldModel_v1.MovableObject class. It doesn't do anything by itself,
but it has to be in the inheritance chain to make its descendants work
properly.
George,
since you explicit allowed metaprogramming hacks :-), how about something like 
this (not tested beyond what you see):

class WorldVersion(type):
WorldVersion instances are World classes
If a World inherits from another World: Field, Movable, Player
automatically inherit from their corresponding superclasses
def __new__(self, name, bases, clsdict):
clslist = set([Field, Movable, Player])
baseworld = bases[0]
if type(baseworld) is self:
for cls in clslist:
base = getattr(baseworld,cls)
target = clsdict.setdefault(cls, base)
if base is target:
continue
oldbases = list(target.__bases__)
if base in target.__bases__:
continue
try:
oldbases[oldbases.index(object)] = base
except ValueError:
oldbases.append(base)
target = type(target.__name__, tuple(oldbases), 
dict(target.__dict__))
clsdict[cls] = target


return type.__new__(self,name, bases, clsdict)
class World1(object):
__metaclass__ = WorldVersion
class Field(object):
def position(self):
print Positioning in World1
class Movable(Field):
def move(self):
print Moving in World1
class Player(Movable):
def passBall(self):
print Passing in World1
class World2(World1):
__metaclass__ = WorldVersion
class Field(object):
def position(self):
print Positioning in World2
class Movable(Field): # You still need placeholder classes
  # but they are trivial
pass
class Player(Movable):
def passBall(self):
print Passing in World2
class World3(World2):
__metaclass__ = WorldVersion
class Player(object):
def passBall(self):
print Passing in World3
  p3 = World3.Player()
  p3.move()
 Moving in World1
  p3.position()
 Positioning in World2
  p3.passBall()
 Passing in World2
 
Michael
--
http://mail.python.org/mailman/listinfo/python-list


How to check whether a list have specific value exist or not?

2005-04-09 Thread praba kar
Dear All
 In Php we can find in_array() function
which function is mainly useful to check
whether a specific value is exist in the array
or not.

   But In python In cannot find any function
like that.  I want to check a list have specific
value or not. So If any one know regarding this
mail me

with regards
PRabahar



Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check whether a list have specific value exist or not?

2005-04-09 Thread Michael Spencer
praba kar wrote:
Dear All
 In Php we can find in_array() function
which function is mainly useful to check
whether a specific value is exist in the array
or not.
   But In python In cannot find any function
like that.  I want to check a list have specific
value or not. So If any one know regarding this
mail me
with regards
PRabahar

Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
No need to ask this list, ask the built-in one:
  dir(list)
 ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', 
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__', 
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', 
'__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', 
'__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append', 
'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

A minute of two experimenting, would then lead you to:
  l = [1,2,3,4,5]
  l.index(3)
 2
 
Note that all indexing in Python is 0-based
Michael
--
http://mail.python.org/mailman/listinfo/python-list


change the date string into timestamp

2005-04-09 Thread praba kar
Dear All,

In Php strtotime() will change a date
string into timestamp.  I want to know which 
python function will  change a date string
into timestamp. 


Date string format is below 

Fri, 8 Apr 2005 09:22:14 +0900

regards
Prabahar


Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the date string into timestamp

2005-04-09 Thread Michael Hoffman
praba kar wrote:
In Php strtotime() will change a date
string into timestamp.  I want to know which 
python function will  change a date string
into timestamp.
What do you mean by a timestamp?
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to check whether a list have specific value exist or not?

2005-04-09 Thread Heiko Wundram
Am Samstag, 9. April 2005 11:37 schrieb Michael Spencer:
 praba kar wrote:
  I want to check a list have specific
  value or not. So If any one know regarding this
  mail me
 A minute of two experimenting, would then lead you to:
l = [1,2,3,4,5]
l.index(3)

   2

Or, if its that you just want to know whether a value is somewhere in an 
iterable:

 l = [1,2,3,4,5]
 4 in l
True

See how there is special syntax to call the __contains__ method of the 
iterable automatically.

-- 
--- Heiko.
listening to: Pearl Jam - Rearviewmirror
  see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/


pgp73dFMahMxZ.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to check whether a list have specific value exist or not?

2005-04-09 Thread Michael Hoffman
praba kar wrote:
In Php we can find in_array() function
which function is mainly useful to check
whether a specific value is exist in the array
or not.
But In python In cannot find any function
like that.
If you just want a boolean result you can use x in l:
 l = range(5)
 l
[0, 1, 2, 3, 4]
 3 in l
True
 42 in l
False
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: change the date string into timestamp

2005-04-09 Thread praba kar

--- Michael Hoffman [EMAIL PROTECTED] wrote:
 praba kar wrote:
 
  In Php strtotime() will change a date
  string into timestamp.  I want to know which 
  python function will  change a date string
  into timestamp.
 
 What do you mean by a timestamp?
 -- 
Time stamp means datestring will converted as seconds

example is below

Fri, 8 Apr 2005 09:22:14 +0900 this date value

time stamp is 1112962934



Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check whether a list have specific value exist or not?

2005-04-09 Thread Sidharth Kuruvila
Hi Prabha,

if 3 in [1, 2, 3, 4]:
print yes


Python is an amazing language if you understand that it is actually
quite a bit different from php. The python tutorial is pretty good, I
suggest you go through it.


On Apr 9, 2005 3:07 PM, Michael Spencer [EMAIL PROTECTED] wrote:
 praba kar wrote:
  Dear All
   In Php we can find in_array() function
  which function is mainly useful to check
  whether a specific value is exist in the array
  or not.
 
 But In python In cannot find any function
  like that.  I want to check a list have specific
  value or not. So If any one know regarding this
  mail me
 
  with regards
  PRabahar
 
 
  
  Yahoo! India Matrimony: Find your life partner online
  Go to: http://yahoo.shaadi.com/india-matrimony
 
 No need to ask this list, ask the built-in one:
 
dir(list)
   ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
 '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
 '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__',
 '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__',
 '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__',
 '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append',
 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
 
 A minute of two experimenting, would then lead you to:
 
l = [1,2,3,4,5]
l.index(3)
   2
   
 
 Note that all indexing in Python is 0-based
 
 Michael
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
http://blogs.applibase.net/sidharth
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the date string into timestamp

2005-04-09 Thread Heiko Wundram
Am Samstag, 9. April 2005 11:38 schrieb praba kar:
 In Php strtotime() will change a date
 string into timestamp.  I want to know which
 python function will  change a date string
 into timestamp.

You want the standard library function strptime from the time module (in case 
it's a timestamp you're looking for), otherwise have a look at the library 
documentation for the datetime module, which gives you a datetime class which 
can also be constructed strptime-like from a string.

Example:

 date = Fri, 8 Apr 2005 09:22:14 +0900
 timetuple = time.strptime(date,%a, %d %b %Y %H:%M:%S +0900)
 timetuple
(2005, 4, 8, 9, 22, 14, 4, 98, -1)
 timestamp = time.mktime(timetuple)
 timestamp
1112944934.0

The timestamp is in local time, as is the timetuple (I've hardcoded the +0900, 
there's no format string which will parse the timezone parameter, and recode 
the time to UTC, it's up to you to do that).

-- 
--- Heiko.
listening to: Pearl Jam - Spin The Black Circle
  see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/


pgpAlMVOkrzJS.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem with national characters

2005-04-09 Thread Leif B. Kristensen
Martin v. Löwis skrev:

 You need to do locale.setlocale(locale.LC_ALL, ) to get
 locale-specific upper-casing.

That makes a lot of sense. Thank you.

 'før'.upper()
'F\xf8R'
 'FØR'
'F\xd8R'
 import locale
 locale.setlocale(locale.LC_ALL, )
'no_NO'
 'før'.upper()
'F\xd8R'
 'FØR'
'F\xd8R'

I must make a note of the LC_ALL variable in the installation README. 
I for one have been running Gentoo Linux for two years without ever
setting the locale, - but now I've finally gotten around to write my
own /etc/env.d/02locale file :-)

 Notice that things are more difficult in the Windows terminal window,
 as this uses an encoding different from the one that the system's
 locale functions expect.

The real input will come from a GUI or a browser interface, so the
Windows terminal problem isn't really an issue.
-- 
Leif Biberg Kristensen
http://solumslekt.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the date string into timestamp

2005-04-09 Thread Fredrik Lundh
praba kar wrote:

 In Php strtotime() will change a date
 string into timestamp.  I want to know which
 python function will  change a date string
 into timestamp.

you might save yourself (and everyone else) some time by looking for
things in the documentation before you post...

 Time stamp means datestring will converted as seconds

 example is below

 Fri, 8 Apr 2005 09:22:14 +0900 this date value

 time stamp is 1112962934

the quickest way to convert a time value to a string is to use the time.ctime()
function:

 x = 1112962934
 time.ctime(x)
'Fri Apr 08 14:22:14 2005'

to specify a non-standard format, use a format string with the time.strftime
function (or the corresponding datetime functions).  an example:

 x = 1112962934
 time.strftime(%Y%m%d %H%M%S, time.localtime(x))
'20050408 142214'

see the time and datetime documentation for details.

the timestamp format you're using is also known as the RFC(2)822 format.  the
email package contains several functions to deal with this format:

 x = 1112962934
 from email.Utils import formatdate
 formatdate(x) # default is utc
'Fri, 08 Apr 2005 12:22:14 -'
 formatdate(x, localtime=1)
'Fri, 08 Apr 2005 14:22:14 +0200'

 from email.Utils import parsedate_tz
 parsedate_tz(formatdate(x, localtime=1))
(2005, 4, 8, 14, 22, 14, 0, 1, 0, 7200)

for the full story, see:

http://docs.python.org/lib/module-email.Utils.html

/F 



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


RE: Equivalent string.find method for a list of strings

2005-04-09 Thread Sells, Fred
linenums = [i for i in range(len(lines)) if lines[i].find(searchstring) =0]

-Original Message-
From: Joshua Ginsberg [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 4:12 PM
To: [EMAIL PROTECTED]
Subject: Re: Equivalent string.find method for a list of strings


try:

filter(lambda x: lines[x].find(searchstring) != -1, range(len(lines)))

That will return a list with the indices of every line containing a hit 
for your search string.

-jag


Joshua Ginsberg -- [EMAIL PROTECTED]
Brainstorm Internet Network Operations
970-247-1442 x131
On Apr 8, 2005, at 1:52 PM, Jeremy Conlin wrote:

 Joshua Ginsberg wrote:

 Try:

 filter(lambda x: x.find(searchstring) != -1, lines)

 I really like this option, but what I want to  know where in the file 
 this line exists (i.e. line 42).  Can  I somehow access this line and 
 the lines immediately following?
 Thanks,
 Jeremy

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


Re: Declaring variables from a list

2005-04-09 Thread Cactus
Fredrik Lundh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]...
 Cactus wrote:
 
  If I got a list is it possible to declare a variable from the items in that 
  list?
 
  Code Sample:
  Blob = ['Var1', 'Var2', 'vAR3']
  i = 5
  for listitems in Blob:
 i += 1
 listitems = i
 
  print Var1
  6
  print Var2
  7
  print vAR3
  8
 
 
  Something like that? This doesn't work (obviously) but is there a way to do 
  this?
 
 why?
 
 if you want a dictionary, use a dictionary (see the tutorial for details).
 
 /F

Thanks,

I'll look in to that. Seems like that will work

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


Re: Puzzling OO design problem

2005-04-09 Thread George Sakkis
Michael Spencer [EMAIL PROTECTED] wrote:

 George,

 since you explicit allowed metaprogramming hacks :-), how about
something like
 this (not tested beyond what you see):

 [snipped]


Nice try, but ideally all boilerplate classes would rather be avoided
(at least being written explicitly). Also, it is not obvious in your
solution why and which placeholder classes have to be written (like
World2.Movable) and which do not. By the way, my current working
solution involves copying and pasting verbatim these classes :-) Below
is an abstracted example; note that the 'declaration string' of each
original class is exactly the same across all different versions after
the first (e.g. class B(PreviousNamespace.B, A)).


#==
# version_1.py

class Namespace:
class A(object):
def foo(self): return version_1.foo()
class B(A):
def bar(self): return version_1.bar()
class C(B):
def zen(self): return version_1.zen()
#==
# version_2.py

from version_1 import Namespace as PreviousNamespace
class Namespace(PreviousNamespace):
class A(PreviousNamespace.A):
def foo(self): return version_2.foo()
class B(PreviousNamespace.B, A):
pass
class C(PreviousNamespace.C, B):
pass
#==
# version_3.py

from version_2 import Namespace as PreviousNamespace
class Namespace(PreviousNamespace):
class A(PreviousNamespace.A):
pass
class B(PreviousNamespace.B, A):
def bar(self): return version_3.bar()
class C(PreviousNamespace.C, B):
pass

#==
# test.py
# command: python test.py #version

def NamespaceFactory(version):
return __import__(version_%d % version).Namespace

print NamespaceFactory(2).B().foo() # version_2.foo()
print NamespaceFactory(3).C().bar() # version_3.bar()

import sys, inspect
namespace = NamespaceFactory(int(sys.argv[1]))
# print the __mro__ of each 'inner' class
for name,cls in inspect.getmembers(namespace,
   inspect.isclass):
print cls
for ancestor in cls.__mro__:
print \t, ancestor

#==

George

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


Re: changing from python2.3 to python2.4

2005-04-09 Thread Martin v. Löwis
Uwe Mayer wrote:
 How do you suggest dealing with this:
 - is calling /usr/bin/python2.3 in the bang-line problematic?
 - installing into both python2.3 and python2.4 
 - rebuilding (re- ./configure, make, make install) the app solves the
 problem
 
 Whats the usual way to deal with this?

People normally often install multiple versions of Python on a machine
if they need to support many different Python applications. They then
migrate one application after another to the new Python version, and
eventually uninstall the old version.

Putting python2.3 in the bang line should work fine, so if you can
arrange to find all scripts that need to be changed, that might be
the easiest solution. For rebuilding, you probably would need to do
some testing whether everything still works fine; if it does, this
is likely what you will do in the long run either way - at some
point, on a new machine, it will be easier to recompile your application
than installing python2.3 from sources.

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


Re: Thoughts on some stdlib modules

2005-04-09 Thread Martin v. Löwis
vegetax wrote:
 Why does people have to put wrappers around about half of the standart
 library modules? i have wrappers for urllib,urllib2, [... many more ...]
 
 I mean is this normal?

Not sure what this is :-) Is it normal that people write wrappers
around libraries? Yes, most certainly so. I see people writing wrappers
around the C++ library, around Java collection classes (*), around .NET
classes, ... essentially for every library that somebody writes,
somebody else will write a wrapper - unless the library is useless.

Is it normal that *you* write this many wrappers? I don't know you
good enough to answer that question :-)

Is it good that people write these wrappers? I don't think so. Is it
the library's fault? I don't think so, either. People write these
wrappers because they cannot remember how to use the library. This
is not because the library is hard to remember, but because people
cannot remember much at all - except for the things they have done
themselves (**). So they write a library wrapper, and doing so takes
them enough time to ingrain their own API into their own memory.
If somebody else wrote the very same wrapper for them, they still
would not like to use it.

So what can be done? Not much, I think - no matter what the
library reorganization is, people will continue to write wrappers
around it. That is not to say that a library reorganization couldn't
be helpful to some people - if people find enough energy, a library
reorganization will happen. Some will like it, some will hate it.

I personally try to avoid library wrappers like the plague. It makes
my code harder to write, but easier to read.

Regards,
Martin

(*) Just look at the Apache Commons library. People write wrappers
for stuff like

  bool isEmptyString(String s){
   return s==null || s.length()==0;
  }

(**) of course, most people can only remember a subset of these,
as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Text Unicode processing references on the web.

2005-04-09 Thread Martin v. Löwis
anthony hornby wrote:
 Can anyone point out some good Python  Unicode and Python  Text
 processing resources on the net to get me started? Any good book
 recommendations?

As a quick Unicode tutorial, I'd recommend

http://www.jorendorff.com/articles/unicode/python.html
http://www.egenix.com/files/python/Unicode-EPC2002-Talk.pdf

For text processing, you should read the Strings section of the
library reference:

http://www.python.org/doc/current/lib/strings.html

Notice there is also a separate section on SGML/XML

http://www.python.org/doc/current/lib/markup.html

PyXML has its own documentation page, on

http://pyxml.sourceforge.net/topics/docs.html

As for book recommendations: What language? I would recommend

Fischbeck, v. Löwis: Python 2

:-) It covers all of these topics.

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


Re: Python extension performance

2005-04-09 Thread Martin v. Löwis
David Jones wrote:
 Both the C++ executable and python module were linked from the same
 object files, and linked with the same options.  The only difference is
 that the Python module is linked with -shared, and the C++ code is not.
[...]
 Some potential causes of my problems:
 
 - linking to a shared library instead building a static exe.

That is unlikely the problem - the shared library should long be loaded
when you call the function.

 - intel libraries are not being used when I think they are

Very much possible. I would do an strace on each binary (python and
your stand-alone application) to see what libraries are picked up.

 - libpython.so was built with gcc, so I am getting some link issues

Unlikely.

 - can linking to python affect my memory allocation and deallocation in
 c++??

It can - Python grabs a 128k at startup, and then another one if the
first one is exhausted. But that should not cause a performance
difference.

Other possible explanations:
- The intel compiler somehow arranges to use multiple processors in the
  code (e.g. through OpenMP); for some reason, your multiple processor
  are not used when this is run in the Python interpreter (and no,
  the GIL would not be an immediate explanation)
- The Python interpreter (unknowingly) switches the processor to a
  different floating-point operation mode, one which is less efficient
  (but, say, more correct).

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


Re: Python/wxPython Reducing memory usage.

2005-04-09 Thread Joe
On 8 Apr 2005 23:35:57 -0700, lotmr [EMAIL PROTECTED] wrote:
Is there any way that I could compile or optimize the my program and/or its 
memory usage?

... and ideally, if we could also reduce the size of the DLL, so that
it would only include the widgets actually used, it'd be even nicer.

(Note: I don't have a problem with making this program win32 specific,
as it already is only win32)

I don't have much experience with it, but is the PythonWin wrapper to
MFC horrible to use as compared to wxWidgets? If it's good enough and
you don't care about non-Windows platforms, you'll probably save a lot
of RAM and file footprint.

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


RE: PPC OSX vs. x86 Linux

2005-04-09 Thread Sells, Fred
I'm no expert on internals, but I seem to recall that in the past, the
string module could be implemented in either C or Python and I think there
is a strop module that is related to all this.  Could it be that on the Mac,
your string processing is using interpreted Python byte code while linux
uses c?

-Original Message-
From: Joshua Ginsberg [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 1:03 PM
To: [EMAIL PROTECTED]
Subject: PPC OSX vs. x86 Linux


Hello --

I writing some python code to do some analysis of my mail logs. I took 
a 10,000 line snippet from them (the files are about 5-6 million 
usually) to test my code with. I'm developing it on a Powerbook G4 
1.2GHz with 1.25GB of RAM and the Apple distributed Python* and I 
tested my code on the 10,000 line snippet. It took 2 minutes and 10 
seconds to process that snippet. Way too slow -- I'd be looking at 
about 20 hours to process a single daily log file.

Just for fun, I copied the same code and the same log snippet to a 
dual-proc P3 500MHz machine running Fedora Core 2* with 1GB of RAM and 
tested it there. This machine provides web services and domain control 
for my network, so it's moderately utilized. The same code took six 
seconds to execute.

Granted I've got the GUI and all of that bogging down my Mac. However, 
I had nothing else fighting for CPU cycles and 700MB of RAM free when 
my testing was done. Even still, what would account for such a wide, 
wide, wide variation in the time required to process the data file? The 
code is 90% regular expressions and string finds.

Theories? Thanks!

-jag


* versions are:
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
and
Python 2.3.3 (#1, May  7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2


Joshua Ginsberg -- [EMAIL PROTECTED]
Brainstorm Internet Network Operations
970-247-1442 x131
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change the date string into timestamp

2005-04-09 Thread Heiko Wundram
Am Samstag, 9. April 2005 12:10 schrieb Fredrik Lundh:
  from email.Utils import parsedate_tz
  parsedate_tz(formatdate(x, localtime=1))

 (2005, 4, 8, 14, 22, 14, 0, 1, 0, 7200)

Very cool! Learning something new every day!

-- 
--- Heiko.
listening to: Pearl Jam - Dissident
  see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/


pgpSKpnmAtkYS.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: change the date string into timestamp

2005-04-09 Thread Fabio Pliger
You can use some date/time modules as:
time built in module
datetime
wxDatetime from wx

just take a look in the documentation... they are very simple to use.

F.P.

praba kar [EMAIL PROTECTED] ha scritto nel messaggio
news:[EMAIL PROTECTED]
 Dear All,

 In Php strtotime() will change a date
 string into timestamp.  I want to know which
 python function will  change a date string
 into timestamp.


 Date string format is below

 Fri, 8 Apr 2005 09:22:14 +0900

 regards
 Prabahar

 
 Yahoo! India Matrimony: Find your life partner online
 Go to: http://yahoo.shaadi.com/india-matrimony


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


Re: change the date string into timestamp

2005-04-09 Thread John Ridley
 praba kar wrote:
 
  In Php strtotime() will change a date
  string into timestamp.  I want to know which 
  python function will  change a date string
  into timestamp.
 

To convert a date-string *to* a timestamp (as you asked):

 import time, calendar
 date_string = time.strftime('%c', time.gmtime(1112952134))
 print date_string
Fri Apr  8 09:22:14 2005
 calendar.timegm(time.strptime(date_string))
1112952134


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python extension performance

2005-04-09 Thread David Jones
Jack Diederich wrote:
On Fri, Apr 08, 2005 at 10:14:52PM -0400, David Jones wrote:
I am trying to hunt down the difference in performance between some raw 
C++ code and calling the C++ code from Python.  My goal is to use Python 
to control a bunch of number crunching code, and I need to show that 
this will not incur a (big) performance hit.

My C++ function (testfunction) runs in 2.9 seconds when called from a 
C++ program, but runs in 4.3 seconds when called from Python. 
testfunction calculates its own running time with calls to clock(), and 
this is for only one iteration, so none of the time is in the SWIG code 
or Python.

Some potential causes of my problems:
- linking to a shared library instead building a static exe.
- intel libraries are not being used when I think they are
- libpython.so was built with gcc, so I am getting some link issues
- can linking to python affect my memory allocation and deallocation in 
c++??
The main overhead of calling C/C++ from python is the function call overhead
(python creating the stack frame for the call, and then changing the python
objects into regular ints, char *, etc).  You don't mention how many times
you are calling the function.  If it is only once and the difference is 1.4
seconds then something is really, really, messed up.  So I'll guess it is
hundreds of thousands of times?  Let us know.
Sorry I was not clearer above;  the function is only called one time.  I 
have run out of obvious things I may have screwed up.  The part that 
bugs me most is that these are built from the same .o files except for 
the .o file that has the wrapper function for python.


Some things I can try:
- recompile python with the intel compiler and try again
- compile my extension into a python interpreter, statically
- segregate the memory allocations from the numerical work and compare 
how the C++ and Python versions compare
Recompiling with the Intel compiler might help, I hear it is faster than 
GCC for all modern x86 platforms.  I think CPython is only tested on GCC
and windows Visual-C-thingy so you might be SOL.  The other two ideas
seem much harder to do and less likely to show an improvement.

 -jackdied

By the second option, I meant to compile my extension statically instead 
of using a shared library by unpacking the source rpm and putting my 
code in the Modules/ directory.  That is a pretty standard thing to do, 
isn't it?

Thanks for the comments.
Dave
--
http://mail.python.org/mailman/listinfo/python-list


workaround for generating gui tools

2005-04-09 Thread flupke
Hi,
i create my GUIs mainly via wxGlade. However when you start of to 
program and want to do some rearranging to the gui, wxglade overwrites 
your file and you've got to put your own code back in.

I think i can work around that (at least a bit) by making a second file 
that imports the gui generated by wxglade and make classes that extend 
the original ones.
For instance i could have a class MainForm that extends the wxFrame 
class that wxGlade produces.

Are there other clever ways to work around this problem?
Thanks,
Benedict
--
http://mail.python.org/mailman/listinfo/python-list


Re: PPC OSX vs. x86 Linux

2005-04-09 Thread Maurice LING
Sells, Fred wrote:
I'm no expert on internals, but I seem to recall that in the past, the
string module could be implemented in either C or Python and I think there
is a strop module that is related to all this.  Could it be that on the Mac,
your string processing is using interpreted Python byte code while linux
uses c?
I have a suspicion towards Apple-installed Python, although this 
suspicion may be groundless. I've heard that OSX actually uses the 
installed Python for some of its work. Once I've deleted the 
Apple-installed Python totally and it does screw up some of my 
applications, like I can't click on a doc file and let it fire up 
OpenOffice to open the doc file. At the same time, I'm not sure of the 
Apple-installed Python is the same as if you had installed it from Fink, 
or has it been tweaked...

If Apple-installed Python is a problem for you, you might want to 
install a version of Python using Fink and see how it compares up...

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


Re: workaround for generating gui tools

2005-04-09 Thread Harlin Seritt
Benedict,

Best to hand-code your code ;-) -- even GUI. This is kind of why I like
Tkinter so much. Good luck.

Harlin Seritt

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


Re: Multiple inheritance: Interface problem workaround, please comment this

2005-04-09 Thread Axel Straschil
Hello!

 from decorate import decorate # see today thread on decorators for this

Gives me an ImportError: No module named decorate. I've got to donwload
that? (python 2.4)

Thanks,
AXEL.
-- 
Aber naja, ich bin eher der Forentyp. Wolfibolfi's outing in 
http://www.informatik-forum.at/showpost.php?p=206342postcount=10
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python 2.4 on Linux

2005-04-09 Thread John Ridley
* Edward Diener wrote:
 I need python to be python2.3 else many utilities no longer work.

Then leave your 2.3 installation exactly as it is (so that python is a
link to python2.3) and run python2.4 where needed.

To specifically use python 2.4 to run IDLE, simply type in a shell:

[user]$ python2.4 /usr/bin/idle

Alternatively, create your own (executable) idle or pydoc with a
shebang that points permanently at python2.4. For example:

file: $HOME/bin/idle2.4
---
#!/usr/bin/python2.4

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

Then if $HOME/bin is on your PATH, you can simply run: idle2.4

 The problem is then using IDLE and pydoc for Python2.4 since neither
 are .py scripts

Really?! What are they on Fedora, then?


John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Python benchmark suite

2005-04-09 Thread stelios xanthakis
Hi
I'd like to announce the pyvmbench benchmark suite which is designed
to evaluate different python implementations, different versions of
the same implementation and different compilers/compilation flags for
the same version of a python implementation (same).  If you want,
you can of course benchmark Jython on Mac vs IronPython on XP!
It is located right here:
http://students.ceid.upatras.gr/~sxanth/pyvm/pyvmbench.tar.bz2
I've taken code from the computer language shootout, posts in
c.l.py and other code from the internet which seems to be ok to
use.  Hopefully we should be ok.
Ok, the testcases are not many but they are all real programs
that do real jobs and this makes their results at least, realistic:)
Cheers,
Stelios
--
http://mail.python.org/mailman/listinfo/python-list


Are circular dependencies possible in Python?

2005-04-09 Thread Tim Tyler
Like C, Python seems to insist I declare functions before calling
them - rather than, say, scanning to the end of the current script
when it can't immediately find what function I'm referring to.

C lets you predeclare functions to allow for the existence of
functions with circular dependencies.

Does Python allow you to do something similar?

If not how do you create functions with circular dependencies in
Python - where function A could call function B; and function
B could call function A - or is that not possible?
-- 
__
 |im |yler  http://timtyler.org/  [EMAIL PROTECTED]  Remove lock to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple inheritance: Interface problem workaround, please comment this

2005-04-09 Thread Michele Simionato
Look at the comment in the code! I have posted the decorate module in
the this
decorator thread:
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/60f22ed33af5dbcb/b7239b45da6a67ab#b7239b45da6a67ab

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


Re: Puzzling OO design problem

2005-04-09 Thread Michael Spencer
George Sakkis wrote:
Nice try, but ideally all boilerplate classes would rather be avoided
(at least being written explicitly). 
It depends on how much magic you are prepared to accept; this goal is somewhat 
in conflict with the next one...

Also, it is not obvious in your
solution why and which placeholder classes have to be written (like
World2.Movable) and which do not. 
It is systematic, if not obvious.  You need place holder classes only if you 
need to propagate new methods within a given world.  More magic would make this 
even less obvious.

By the way, my current working
solution involves copying and pasting verbatim these classes :-) 

It appears to be basically the same as mine except you spell out the previous 
version explicitly (not that that's bad!)

Have you considered a 'macro' solution composing source?  If I were handling so 
many versions, I would want a complete class definition for each version rather 
than having to scan many sources for each implementation.

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


Re: Are circular dependencies possible in Python?

2005-04-09 Thread Dave Brueck
Tim Tyler wrote:
Like C, Python seems to insist I declare functions before calling
them - rather than, say, scanning to the end of the current script
when it can't immediately find what function I'm referring to.
Yes and no. Yes, they have to exist before you can use them (that only makes 
sense), but no, they don't have to be placed in the same order in the source 
code like they do with C:

 def A(count):
...   print 'A', count
...   B(count + 1)
...
 def B(count):
...   print 'B', count
...   if count  10:
... A(count + 1)
...
 B(0)
B 0
A 1
B 2
...
See - all that matters is that they exist before you call them.
-Dave
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are circular dependencies possible in Python?

2005-04-09 Thread Michael Spencer
Tim Tyler wrote:
Like C, Python seems to insist I declare functions before calling
them - rather than, say, scanning to the end of the current script
when it can't immediately find what function I'm referring to.
C lets you predeclare functions to allow for the existence of
functions with circular dependencies.
Does Python allow you to do something similar?
If not how do you create functions with circular dependencies in
Python - where function A could call function B; and function
B could call function A - or is that not possible?
Of course, for example:
def A(*args):
if len(args)  1:
print Calling B%s % repr(args[1:])
return B(*args[1:])
else:
print A Called with: %s % args[0]
def B(*args):
if len(args)  1:
print Calling A%s % repr(args[1:])
return A(*args[1:])
else:
print B Called with: %s % args[0]
  A(Arg1,Arg2,Arg3,Arg4)
 Calling B('Arg2', 'Arg3', 'Arg4')
 Calling A('Arg3', 'Arg4')
 Calling B('Arg4',)
 B Called with: Arg4
 
Functions have to exist before you call them, but they are not 'declared'.  def 
and its enclosed suite is a statement, like print, while, etc...  The def 
statement is executed to define the function.  For functions defined at module 
level, this statement is executed when the module is first imported (or 
reloaded) in source-code order along with any other module-level code.

Executing a def statement compiles (but does not execute) the body of the 
function.  Each function, when def'd also gets a reference to the global scope 
in which it is defined.  When you execute the function body (by calling the 
function), identifiers that are not resolved in the functions own local scope 
are looked up in this global scope.

So in the example above, the body of A calls B.  B is not defined in A's local 
scope, so it is looked up in A's globals, which is the module.  As long as def 
B(... has been executed in the same module before you first call A, everything 
is fine.

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


Re: Counting iterations

2005-04-09 Thread runes
You should avoid the a + b + c -kind of concatenation. As strings
at immutable in Python you actually makes copies all the time and it's
slow!

The alternative used in Steven Bethard's example is preferable.

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


Re: Are circular dependencies possible in Python?

2005-04-09 Thread Dan Sommers
On Sat, 9 Apr 2005 15:57:15 GMT,
Tim Tyler [EMAIL PROTECTED]  wrote:

 Like C, Python seems to insist I declare functions before calling them
 - rather than, say, scanning to the end of the current script when it
 can't immediately find what function I'm referring to.

Python has no such restriction.

The only restriction is that the function be defined before it is
called.  Unlike C, function definitions in Python are executable
statements.

If your script looks like this:

f( ) # call f

def f( ) # define f
  print 'hello'

then it will fail because f has not yet been defined before it was
called.

 Does Python allow you to do something similar?

No.  Python has no such thing as a function declaration.

 If not how do you create functions with circular dependencies in
 Python - where function A could call function B; and function
 B could call function A - or is that not possible?

Perhaps if you can post a minimal example that shows us what you're
running into, someone here will know how to help.

HTH,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
c = 1
-- 
http://mail.python.org/mailman/listinfo/python-list


SoCal Piggies meeting Tuesday 4/12

2005-04-09 Thread Grig Gheorghiu
The Southern California Python Interest Group (SoCal Piggies) will meet
Tuesday April 12 @ 7:30 PM, at the Kerckhoff Marine Lab in Newport
Beach. If you're a Pythonista in the area and you're interested in
participating, please e-mail socal-piggies at lists.idyll.org and
request more info.

Thanks,

Grig

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


Re: Are circular dependencies possible in Python?

2005-04-09 Thread Tim Tyler
Tim Tyler [EMAIL PROTECTED] wrote or quoted:

 Like C, Python seems to insist I declare functions before calling
 them - rather than, say, scanning to the end of the current script
 when it can't immediately find what function I'm referring to.
 
 C lets you predeclare functions to allow for the existence of
 functions with circular dependencies.
 
 Does Python allow you to do something similar?
 
 If not how do you create functions with circular dependencies in
 Python - where function A could call function B; and function
 B could call function A - or is that not possible?

Thanks guys - that's made how Python works in this area abundantly clear.
-- 
__
 |im |yler  http://timtyler.org/  [EMAIL PROTECTED]  Remove lock to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: workaround for generating gui tools

2005-04-09 Thread Reinhold Birkenfeld
Harlin Seritt wrote:
 Benedict,
 
 Best to hand-code your code ;-) -- even GUI. This is kind of why I like
 Tkinter so much. Good luck.

Have to disagree strongly.

It's evil anyway (for more complex applications) to put GUI construction
in your code. GUI should be described appropriately in data files.

Glade does this very good, and with pygtk it's no problem to use the XML files.

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


Re: workaround for generating gui tools

2005-04-09 Thread Fredrik Lundh
Reinhold Birkenfeld wrote:

 It's evil anyway (for more complex applications) to put GUI construction
 in your code. GUI should be described appropriately in data files.

why use data files when you have an extremely powerful programming
language in your toolbox?  the advantage of building UI's in Python is
that you can quickly create domain specific UI languages, and use them
to generate the interfaces for you.  UI editors may be useful for trivial
applications, but if you're doing complex stuff, you sure want domain-
specific abstractions.  Python gives you that, XML files don't.

/F



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


Help with modem terminal

2005-04-09 Thread Adriano Monteiro
Hey folks,

I need to talk to my modem through a terminal, so I can send commands
and get the answers. Does anybody here know what can I do?
I've tried to use pty.py, but I'm lost...

Regards,
[]'s!

-- 

Adriano Monteiro Marques
www.gopython.com.br
[EMAIL PROTECTED]

I'm FREE... Are you?
(PYTHON powered)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzling OO design problem

2005-04-09 Thread El Pitonero
It may be useful to separate the code into version-independent part and
version-dependent part. Also, one can try to implement the higher-level
logic directly in the class definition of A, B, etc., and then use the
version objects only as patches for the details. That is, one can use
place-holder calls. The place-holder calls do nothing if a feature is
not really implemented (either in a parent class, or in an older
version).

class World(object):

def __init__(w, version):

class A(object):
def ff(): pass # place holder for version-dependent code
def f(self): # version-independent code
return self.ff()

class B(A):
def gg(): pass
def g(self):
return self.gg()

for cls in (A, B):
setattr(w, cls.__name__, w.versionize(cls, version))

def versionize(w, cls, version):
import inspect
methods = inspect.getmembers(version, inspect.ismethod)
methods = [m[1] for m in methods if m[0].split('_')[0] ==
cls.__name__]
for m in methods:
m_name = '_'.join(m.__name__.split('_')[1:])
import new
im = new.instancemethod(m.im_func, None, cls)
setattr(cls, m_name, im)
return cls

class Version1(object):
def A_ff(self):
return 'A.ff: version 1'
def B_gg(self):
return 'B.gg: version 1'

class Version2(Version1):
def A_ff(self):
return 'A.ff: version 2'
def B_ff(self):
return 'B.ff: version 2'

w1, w2 = World(Version1), World(Version2)
a1, b1 = w1.A(), w1.B()
a2, b2 = w2.A(), w2.B()

print a1.f() # prints 'A.ff: version 1'
print b1.f() # prints 'A.ff: version 1'
print b1.g() # prints 'B.gg: version 1'
print ''
print a2.f() # prints 'A.ff: version 2'
print b2.f() # prints 'B.ff: version 2'
print b2.g() # prints 'B.gg: version 1'

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


Re: Help with modem terminal

2005-04-09 Thread Grant Edwards
On 2005-04-09, Adriano Monteiro [EMAIL PROTECTED] wrote:

 I need to talk to my modem through a terminal, so I can send
 commands and get the answers.

Through a terminal?  Just type on the keyboard and look at the
display.

 Does anybody here know what can I do?

Not unless you can clearly describe the problem.  Do you mean
you want to talk to a modem through a serial port?  If so, then
pyserial is probably what you should try.

-- 
Grant Edwards   grante Yow!  ... If I had heart
  at   failure right now,
   visi.comI couldn't be a more
   fortunate man!!
-- 
http://mail.python.org/mailman/listinfo/python-list


ntvdm problem on win2k

2005-04-09 Thread Al Christians
I started having some problems running python programs (python 2.3) from 
the Win2k command line.  I would get crashes with an NTVDM error.  Even 
just executing python would cause it.  I upgraded to python 2.3.5, and 
no difference.  When I rearranged my path to move cygwin and a bunch of 
other stuff (.net, etc) after C:\python23, the problem went away.

Is this problem known to anyone but me?  Any diagnosis, solution of 12 
or fewer steps, or support group?   If I'm distributing python programs 
(python 2.3.5 packaged with py2exe) should I warn or notify the 
recipients that this is a possible problem with the programs?

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


Re: workaround for generating gui tools

2005-04-09 Thread Diez B. Roggisch
 why use data files when you have an extremely powerful programming
 language in your toolbox?  the advantage of building UI's in Python is
 that you can quickly create domain specific UI languages, and use them
 to generate the interfaces for you.  UI editors may be useful for trivial
 applications, but if you're doing complex stuff, you sure want domain-
 specific abstractions.  Python gives you that, XML files don't.

If you do some creative rearranging of widgets and play around with
different layouts and geometry managers, a good gui-designer becomes very
useful.
-- 
Regards,

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


THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (newsgroup-post 127)

2005-04-09 Thread RonGrossi_38157


The reason some people don't know for sure
if they are going to Heaven when they die
is because they just don't know.

The good news is that you can know for
sure that you are going to Heaven which is
described in the Holy Bible as a beautiful
place with no death, sorrow, sickness or
pain.

God tells us in the Holy Bible how simple
it is to be saved so that we can live
forever with Him in Heaven.

For if you confess with your mouth Jesus
is Lord and believe in your heart that God
raised Him from the dead, you
WILL BE SAVED. (Romans 10:9)

Over 2000 years ago God came from Heaven
to earth in the person of Jesus Christ to
shed His blood and die on a cross to pay
our sin debt in full.

Jesus Christ was born in Israel
supernaturally to a virgin Jewish woman
named Mary and lived a sinless life for
thirty-three years.

At the age of thirty-three Jesus was
scourged and had a crown of thorns pressed
onto His head then Jesus was crucified.

Three days after Jesus died on a cross and
was placed in a grave Jesus rose from the
dead as Jesus said would happen before
Jesus died.

If someone tells you that they are going
to die and in three days come back to life
again and it happens then this person must
be the real deal.

Jesus Christ is the only person that ever
lived a perfect sinless life.

This is why Jesus is able to cover our
sins(misdeeds) with His own blood because
Jesus is sinless.

The Holy Bible says, In Him(Jesus) we
have redemption through His blood, the
forgiveness of sins... (Ephesians 1:7)

If you would like God to forgive you of
your past, present and future sins just
ask Jesus Christ to be your Lord and
Saviour.

It doesn't matter how old you are or how
many bad things that you have done in
your life including lying and stealing
all the way up to murder.

Just pray the prayer below with your
mouth and mean it from your heart and
God will hear you and save you.

Dear Jesus Christ, I want to be saved so
that I can have a home in Heaven with You
when I die. I agree with You that I am a
sinner. I believe that You love me and want
to save me. I believe that You bled and
died on the cross to pay the penalty for my
sins and that You rose from the dead.
Please forgive my sins and come into my
heart and be my Lord and Saviour. Thanks
Lord Jesus Christ for forgiving me and
saving me through Your merciful grace.
Amen.

Welcome to the family of God if you just
allowed God to save you. Now you are a real
Christian and you can know for sure that
you will live in Heaven forever when this
life comes to an end.

As a child of God we are to avoid
sin(wrong doing), but if you do sin the
Holy Bible says, My dear children, I
write this to you so that you will not sin.
But if anybody does sin, we have one who
speaks to the Father in our defense Jesus
Christ, the Righteous One.

Those of you that have not yet decided to
place your trust in the Lord Jesus Christ
may never get another chance to do so
because you do not know when you will die.

This means that if you die without
trusting in Jesus Christ as your Lord and
Saviour you will be forever separated from
the love of God in a place called Hell.

The Holy Bible descibes Hell as a place of
eternal torment, suffering, pain and agony
for all those who have rejected Jesus Christ.

The good news is that you can avoid Hell by
allowing Jesus Christ to save you today.
Only then will you have true peace in your
life knowing that no matter what happens you
are on your way to Heaven.



Servant of the Lord Jesus Christ,
Internet Evangelist
Ronald L. Grossi






Got Questions?
http://www.gotquestions.org/archive.html

Other Languages
http://www.godssimpleplan.org/gsps.html

Free Movie: To Hell and Back
http://www.tbn.org/index.php/8/1.html

Animation
http://www.gieson.com/Library/projects/animations/walk/index.html

The Passion Of The Christ
http://www.thepassionofthechrist.com

Beware Of Cults
http://www.carm.org/cults/cultlist.htm

About Hell
http://www.equip.org/free/DH198.htm

Is Jesus God?
http://www.powertochange.com/questions/qna2.html

Free Online Bible
http://www.bibledatabase.net

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


Re: Counting iterations

2005-04-09 Thread Andrew Dalke
runes wrote:
 You should avoid the a + b + c -kind of concatenation. As strings
 at immutable in Python you actually makes copies all the time and it's
 slow!

The OP wrote

print pet + # + num_pets

(properly str(num_pets) )

You recommended the alternative used in Steven Bethard's example

 print 'pet#%i' % (i + 1)

because it's slow.  I disagree, it isn't for this code.
It's comparable in performance to interpolation and most
of the time is spent in converting int - string.  Indeed
if the object to be merged is a string then the addition
version is faster than interpolation.

Here's the details.

The string concatenation performance that you're
talking about doesn't hit until there are multiple
appends to the same string, where multiple is rather
more than 2.  The advice usually applies to things like

  text = 
  for line in open(filename, U):
text += line

which is much slower than, say
  lines = []
  for line in open(filename, U)
lines.append(line)
  text = .join(lines)

or the more modern
  text = .join(open(filename, U))

to say nothing of
  text = open(filename, U).read()  :)

Anyway, to get back to the example at hand,
consider what happens in 

  pet#%i % (i+1)

(NOTE: most times that's written %d instead of %i)

The run-time needs to parse the format string
and construct a new string from the components.
Internally it does the same thing as 

   pet# + str(i+1)

except that it's done at the C level instead
Python and the implementation overallocates
100 bytes so there isn't an extra allocation
in cases like this.

Personally I would expect the % code to be
about the same performance as the + code.


Of course the real test is in the timing. 
Here's what I tried.  NOTE: I reformatted by
hand to make it more readable.  Line breaks and
the \ continuation character may have introduced
bugs.

First, the original code along with the 'str()'
correction.

% python /usr/local/lib/python2.3/timeit.py -s \
'pets = [cat, dog, bird]' \
'num_pets=0' 'for pet in pets:' \
'  num_pets += 1' \
'  s=pet + # + str(num_pets)'
10 loops, best of 3:
14.5 usec per loop


There's no need for the pet + # so I'll
turn that into pet#

% python /usr/local/lib/python2.3/timeit.py -s \
'pets = [cat, dog, bird]' \
'num_pets=0' \
'for pet in pets:' \
' num_pets += 1' \
'  s=pet# + str(num_pets)' 
10 loops, best of 3: 12.8 usec per loop 

That's 1.3 extra usecs.

By comparison here's the % version.

% python /usr/local/lib/python2.3/timeit.py -s \
'pets = [cat, dog, bird]'\
'num_pets=0' \
'for pet in pets:' \
' num_pets += 1' \
'  s=pet#%s % num_pets' 
10 loops, best of 3: 10.8 usec per loop

I'm surprised that it's that much faster - a
good 2 microseconds and that isn't the only
code in that loop.

But both the % and + solutions need to
convert the number into a string.  If I
use an existing string I find

% python /usr/local/lib/python2.3/timeit.py -s \
'pets = [cat, dog, bird]' \
'num_pets=0' \
'for pet in pets:' \
' num_pets += 1' \
'  s=pet# + pet'
10 loops, best of 3: 4.62 usec per loop

So really most of the time - about 8 usec - is
spent in converting int - string and the
hit for string concatenation or interpolation
isn't as big a problem.

Compare with the string interpolation form
of the last version

% python /usr/local/lib/python2.3/timeit.py -s \
'pets = [cat, dog, bird]' \
'num_pets=0' 'for pet in pets:' \
' num_pets += 1' \
'  s=pet#%s % pet' \
10 loops, best of 3: 7.55 usec per loop


In this case you can see that the % version is
slower (by 2usec) than the + version.

I therefore disagree with the idea that simple
string concatenation is always to be eschewed
over string interpolation.

Andrew
[EMAIL PROTECTED]

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


Re: THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (newsgroup-post 127)

2005-04-09 Thread Kato Dakota
[EMAIL PROTECTED] wrote:
The reason some people don't know for sure
if they are going to Heaven when they die
is because they just don't know.




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


Re: ntvdm problem on win2k

2005-04-09 Thread Alexander Schremmer
On Sat, 09 Apr 2005 11:00:08 -0700, Al Christians wrote:

 I started having some problems running python programs (python 2.3) from 
 the Win2k command line.  I would get crashes with an NTVDM error. 

Windows tries to execute the cygwin symbolic link and fails.
Correcting your path works (as you said).

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


Re: ntvdm problem on win2k

2005-04-09 Thread Al Christians
Here's some more info on this:
When I use the Win2k feature to search for files, it turns up python.exe 
in the \cygwin\bin directory.  The file size is shown  as 24 bytes. 
Mighty small for an executable.  The file is hidden.  This is evidently 
the guy who was caussing the problem.

Why does cygwin include a hidden file that hides python on the path?
Al Christians wrote:
I started having some problems running python programs (python 2.3) from 
the Win2k command line.  I would get crashes with an NTVDM error.  Even 
just executing python would cause it.  I upgraded to python 2.3.5, and 
no difference.  When I rearranged my path to move cygwin and a bunch of 
other stuff (.net, etc) after C:\python23, the problem went away.

Is this problem known to anyone but me?  Any diagnosis, solution of 12 
or fewer steps, or support group?   If I'm distributing python programs 
(python 2.3.5 packaged with py2exe) should I warn or notify the 
recipients that this is a possible problem with the programs?

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


Re: Puzzling OO design problem

2005-04-09 Thread George Sakkis
 Have you considered a 'macro' solution composing source?  If I were
handling so
 many versions, I would want a complete class definition for each
version rather
 than having to scan many sources for each implementation.

Can you elaborate on this a little ? You mean something like a
template-based code generating script that creates all the boilerplate
code for each version before you start customising it ? This could be
an option, though you'd better be pretty sure that the template is
frozen; you don't want to go back and fill in the template more than
once !

George

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


Re: How to detect if file is a directory

2005-04-09 Thread Tim Jarman
César Leonardo Blum Silveira wrote:

 Hello all, I'm new to this list.
 
 How can I detect if a file is a directory or not?
 
 Thanks
 
 César

The os module contains many helpful tools for working with files,
directories, links and so forth. Check out the docs and marvel. The
following snippet answers your specific question:

code
import os.path

if os.path.isdir(/some/path/here):
print It's a directory!
/code
-- 
Website: www DOT jarmania FULLSTOP com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzling OO design problem

2005-04-09 Thread Kay Schluehr
Hi George,

it's a nice little puzzle and it is more fun to solve it if one is not
a student anymore :)

Filling the gaps in the lattice is somehow necessary but it is not
necessary to create all the classes.

Ansatz:

We can consider two matrices: one is filled with nodes ( class names )
the other is filled with arrows between the nodes representing the
inheritance relationships.

In symbolic notatation:

| A  B  C |
Nodes = | D  0  F |
| G  H  I |

 | 0   ll  |
Arrows = | u   0   u*l |
 | u  u*l  u*l |


Remarks:
1 ) if a node or an arrow is empty a 0 is inserted into the matrix.

2 ) u is for uppermost, l is for leftmost. A multiplication between
arrows should read as a logical AND: u*l ~ upper AND left.

With this interpretation the above matrizes contains the same
information than the lattice:

A - B - C
^^^
|||
D - 0 - F
^^^
|||
G - H - I

Now we need an algorithm to create all the classes from the matrix
information using multiple inheritance when needed:


# arrows symbolized as primes. Only u and l are used in the impl.
# d and r are somewhat more complicated to implement

l = 2
r = 3
u = 5
d = 7

class ClassGridError(Exception):pass

class ClassGrid(object):
def __init__(self):
   self.class_names = []  # rows of the class-name matrix
   self.arrows  = []  # rows of the arrow matrix
   self.classes = {}  # store the resulting classes

def add_names(self,names):
self.class_names.append(names)

def add_arrow(self,arrow):
self.arrows.append(arrow)

def __repr__(self):
if self.classes:
return self.classes.__repr__()
return object.__repr__(self)

def create_classes(self):
for i,class_row in enumerate(self.class_names):
for j,cls_name in enumerate(class_row):
if cls_name == 0:
continue
arrow = self.arrows[i][j]
if arrow == 0:
   self.classes[cls_name] = type(cls_name,(),{})
else:
   bases = []
   name  = 0
   if arrow%u == 0:   # search uppermost
  k = i-1
  while k=0:
 name = self.class_names[k][j]
 if name:
break
 k-=1
  if not name:
 raise ClassGridError,Wrong arrow matrix
  bases.append(self.classes[name])
   if arrow%l == 0:  # search leftmost
  k = j-1
  while k=0:
 name = self.class_names[i][k]
 if name:
break
 k-=1
  if not name:
 raise ClassGridError,Wrong arrow matrix
  bases.append(self.classes[name])
   self.classes[cls_name] =
type(cls_name,tuple(bases),{})

cg = ClassGrid()

cg.add_names((A,B,C))
cg.add_names((D, 0, F))
cg.add_names((G,H,I))

cg.add_arrow(( 0,  l,   l ))
cg.add_arrow(( u,  0,  u*l))
cg.add_arrow(( u, u*l, u*l))

cg.create_classes()

Now You can checkout Your solution:

 cg.classes[A].__subclasses__()
[class '__main__.B', class '__main__.D']

 cg.classes[B].__subclasses__()
[class '__main__.C', class '__main__.H']

 cg.classes[C].__subclasses__()
[class '__main__.F']

 cg.classes[D].__subclasses__()
[class '__main__.F', class '__main__.G']

 cg.classes[F].__subclasses__()
[class '__main__.I']

 cg.classes[G].__subclasses__()
[class '__main__.H']

 cg.classes[H].__subclasses__()
[class '__main__.I']

 cg.classes[I].__subclasses__()
[]

Ciao,
Kay

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


Re: Recording Video with Python

2005-04-09 Thread tertius
[EMAIL PROTECTED] wrote:
Is there a video module so that I can write a Linux Python script to
record video coming over USB video cams?
http://videocapture.sourceforge.net/
HTH
T
--
http://mail.python.org/mailman/listinfo/python-list


Re: THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (newsgroup-post 127)

2005-04-09 Thread Soy Bomb
The Holy Bible descibes Hell as a place of
eternal torment, suffering, pain and agony
for all those who have rejected Jesus Christ. 

Sounds like the USA 2005.

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


Re: checkbook manager - cross platform printing

2005-04-09 Thread Mike Meyer
David Isaac [EMAIL PROTECTED] writes:

 Alan Isaac [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 I'd like to try personal financial management using Python.
 I just found PyCheckbook, but it does not support check printing.
 Is there a Python check printing application kicking around?
 OK, I'll assume silence means no, so new question.

You really should wait more than a day for answers. Lots of people
(me, for instance) read the newsgroup once aq day.

 What is the current be practice for cross platform printing of PostScript
 files from Python?
 Same question for PDF.  (I'm aware of
 URL:http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html.)

I don't think there's a cross-platform solution for these things,
because different platforms handle printing in different manners. Your
URL talks about shellExecute for Windows. On Unix, I expect to be able
to hand ps to lpr and have the right thing happen. pdf may need a
pdf2ps (part of ghostscript) run on it first, or it may not, depending
on the system setup.

   mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: There's GOT to be a better way!

2005-04-09 Thread Earl Eiland
On Thu, 2005-03-03 at 16:43, Steve Holden wrote:
 Earl Eiland wrote:
 On Thu, 2005-03-03 at 15:11, Steve Holden wrote:
 
 Earl Eiland wrote:
 
 I'm writing my first program where I call custom modules.  The
'global'
 command doesn't seem to apply, so how do I change a variable
internally
 in a module without passing it down n layers, and then back out
again?
 
 
 You are correct in assuming that global isn't what you want - it
really
 means global to the module namespace in which it appears.
 
 However, if two separate pieces of code can both reference the same
 module then one can set an attribute in the module and the other can
 reference it. Don't forget that when you import a module its name
 becomes global within the importing module. Since a module is just a
 glorified namespace, anything that can reference the module can read
 and/or set that module's attributes.
 
 a.py:
 
 import something
 something.x = A value
 
 b.py:
 
 import something
 print something.x
 
 will print A value as long as a is imported before b.
 
 Right.  That part I figured out.  How does one function in an
imported
 module access a variable in the same module?
 
 module.py
   def A():
 global test
   test = 1
   for x in range(10): B()
   
   def B():
 global test
   test = test + 1
 
 
 main.py
   import module
   module.A()
 print module.test
 
 
 This will fail, unless test is passed and returned.
 
 I thought I tried that, and it didn't work.  I must have made some
other
mistake.

Thanks.

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


Re: THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (newsgroup-post 127)

2005-04-09 Thread PA
On Apr 09, 2005, at 21:16, Soy Bomb wrote:
Sounds like the USA 2005.
http://images.ucomics.com/comics/nq/2005/nq050329.gif
Cheers
--
PA, Onnay Equitursay
http://alt.textdrive.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (newsgroup-post 127)

2005-04-09 Thread Kato Dakota
Soy Bomb wrote:
The Holy Bible descibes Hell as a place of
eternal torment, suffering, pain and agony
for all those who have rejected Jesus Christ. 
Sounds like the USA 2005.

Down in the Tsunami many nauts from here

hangin 250K
Tsunami Safaris
Surf City
Indian Ocean
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best editor?

2005-04-09 Thread Mike Meyer
[EMAIL PROTECTED] (Aahz) writes:

 Use vim.  80% of the power of emacs at 20% of the learning curve.

Hmm. Can I read mail/news/web pages in vim? I can in emacs.

Emacs is a computing environment. I read mail and news in it, so I
don't have to worry about learning some applications custom editor
(ok, a good MUA/newsreader will invoke my favorite editor - but that's
Emacs, so why bother). I use emacs for the heavy lifting.

vi is adequate, and I use it for editing things as root. Every once
and a while I'll start an emacs as root, but I do try to avoid that.

For quick edits (as either root or me) I use ex. I can't get past ed
not having a prompt.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


wsh and Python

2005-04-09 Thread David Josty
Hello

I have this function :

import sys
import win32com.client
import win32api

def close_softawre(name)
shell = win32com.client.Dispatch(WScript.Shell)
shell.AppActivate (name)
win32api.Sleep(100)
shell.SendKeys (%{F4})
- 
But sometimes i have any problemes, the programme is not activate a time !!!


== this is wsh !! i don't know translate in python

Do while WshShell.AppActivate (name) = FALSE
 wscript.sleep 100
loop

Thank a lot

a french guy


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


Re: Puzzling OO design problem

2005-04-09 Thread Michael Spencer
George Sakkis wrote:
Have you considered a 'macro' solution composing source?

Can you elaborate on this a little ? You mean something like a
template-based code generating script that creates all the boilerplate
code for each version before you start customising it ? 
I was thinking more along the lines of repeatable code generation.
I started from this idea: 
http://groups-beta.google.com/group/comp.lang.python/msg/77ef889e9f99696c
which is a straightforward wrapping case, but illustrates source code 
composition/generation.

Now given that you have:
#World1.py
class Field:
...
class Movable
...
etc...
#Then in World2Delta.py
class FieldDelta:
   just the classes that have changed
   def somemethod(self):
just the methods that are added or changed
   you could even have nomenclature for method deletion, (a lack which
   sometimes bugs me in OO schemes)
etc...
then you have a 'makefile' that generates a new module for each of your 
worlds
#makefile.py
def generateWorld(baseworld, delta, newworld):
reads two modules:
   baseworld defines the 'superclasses'
   delta defines any changes to these
   writes module newworld, that contains complete
   source for all the classes in the model, with no
   external dependencies

I haven't tried it, but I'm sure it is fairly straightforward to implement (and 
very easy to test).

This could be
an option, though you'd better be pretty sure that the template is
frozen; you don't want to go back and fill in the template more than
once !
I envisage something that could be regenerated at will, simply by re-running the 
makefile.

The thing that would need to be frozen is the inheritance graph within each 
world.  If you want to change that between versions, that would make 
generateWorld much more complex.

The general advantage that I see with this approach is that whatever the hoops 
you have to jump through to get the makefile process working right - the result 
is extremely simple to verify.  You would also probably get better performance, 
by avoiding so much subclassing (not that you mentioned that as factor, but...)

Michael





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


Re: THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (newsgroup-post 127)

2005-04-09 Thread ChinStrap
Thats not what Jack Chick says =(

http://www.chick.com/catalog/tractlist.asp

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


python modules in home dir

2005-04-09 Thread dzieciou
Hello!

I'm new-comer in Python.
I want to install few Python modules (4Suite, RDFLib, Twisted and Racoon)
in my home directory, since Python installation is already installed in the
system
and I'm NOT its admin.
I cannot install pyvm (portable binary python machine) - have no such big
quota.
Any idea how can I solve it?

Best

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


email and smtplib modules

2005-04-09 Thread [EMAIL PROTECTED]
Hi,

I'm writing a small script that generates email and I've noticed that:

1) one should add the 'To' and 'CC' headers to the email message
2) one needs to specify the recipients in the smtplib sendmail() method

Can someone explain how these are related?

Thanks,
Mark

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


Re: ntvdm problem on win2k

2005-04-09 Thread Al Christians
Alexander Schremmer wrote:
Windows tries to execute the cygwin symbolic link and fails.
Correcting your path works (as you said).
One thing about that: I re-installed python (ie upgraded to python 
2.3.5) and it did not solve the error.  I assume that the python 2.3.5 
installer is so well-mannered that it did not put itself at the head of 
the path, but saw that it was already in the path somewhere, and left 
itself there.  This is nice, but it was disappointing, in that I did a 
fresh install to no avail.  And, is it not fairly common for other 
installers of less refined software to add to the head of the path each 
time that they run, no matter how many times the same entry is repeated.
So, by being very nice, python is sort of non-conformist or nearly 
eccentric, which I wish everyone would be.  But how can one despise 99% 
of everything?

When I installed cygwin, I checked it for python.  It had something like 
python2.4.1.exe visible, but that symbolic link was not.

No big deal.
Al
--
http://mail.python.org/mailman/listinfo/python-list


Re: workaround for generating gui tools

2005-04-09 Thread Jeremy Bowers
On Sat, 09 Apr 2005 19:59:18 +0200, Diez B. Roggisch wrote:

 why use data files when you have an extremely powerful programming
 language in your toolbox?  the advantage of building UI's in Python is
 that you can quickly create domain specific UI languages, and use them
 to generate the interfaces for you.  UI editors may be useful for trivial
 applications, but if you're doing complex stuff, you sure want domain-
 specific abstractions.  Python gives you that, XML files don't.
 
 If you do some creative rearranging of widgets and play around with
 different layouts and geometry managers, a good gui-designer becomes very
 useful.

Domain-specific abstractions do that *faster* than GUI designers, not
slower. And better, too, since every iteration tends to be fully
functional and not just a let's see what this looks like prototype.

Heck, switch 'em out dynamically based on what day of the week it is and
how the user feels today. Let's see your GUI-designer do that.

And if you're not used to doing it that way, you'll be *stunned* at how
much stuff tends to factor out and get easily re-used.

An approach that has more data to work with (some idea of what things are
doing and what they are for) will beat an approach with less data (thing
at row 4, col 2 or, worst case, thing at 233,144) any day.

GUI designers are like the regexs in the famous jwz quote: Some people,
when confronted with a problem, think 'I know, I'll use a GUI designer'.
Now they have two problems. Both have a niche in the quick fix
department, both are typically over-used, but overall regexs are the more
useful of the two; at least there are cases where they are the undisputed
right answer (like defining tokens in a language parser).

Generally, over the first couple of weeks of a project, the
domain-specific language writer may seem to be behind the GUI designer
cranking out screen after screen of templated GUI widgets, but after a
couple of weeks the domain-specific language user will pull into the lead
and never give it up, and will be a lot happier to boot.
-- 
http://mail.python.org/mailman/listinfo/python-list


visibility between modules

2005-04-09 Thread max(01)*
hi.
if i have a single program file, different class instances can share 
information in (at least) two fashions:

1. using instance variables:
class AClass:
  def __init__(self):
self.att_1 = 42
self.att_2 = Hello!
class AnotherClass:
  def __init__(self):
self.att_1 = anInstanceOfAClass.att_1
anInstanceOfAClass = AClass()
anInstanceOfAnotherClass = AnotherClass()
print anInstanceOfAnotherClass.att_1  ### This should print out 42
2. using globals:
class AClass:
  def __init__(self):
self.att_1 = 42
self.att_2 = Hello!
class AnotherClass:
  pass
aGlobalString = No way.
anInstanceOfAClass = AClass()
anInstanceOfAClass.att2 = aGlobalString
anInstanceOfAnotherClass = AnotherClass()
anInstanceOfAnotherClass.att_1 = aGlobalString
print anInstanceOfAClass.att2  ### This should output No way.
print anInstanceOfAnotherClass.att_1  ### And this too

i admit i prefer the fisrt way to do it. i have tried to make it work 
even if the main program and each class definition reside in different 
files, but i could not make it work:

[EMAIL PROTECTED]:/tmp$ cat AClass.py
class AClass:
  def __init__(self):
self.att_1 = 42
self.att_2 = Hello!
[EMAIL PROTECTED]:/tmp$ cat AnotherClass.py
class AnotherClass:
  def __init__(self):
self.att_1 = anInstanceOfAClass.att_1
[EMAIL PROTECTED]:/tmp$ cat Main.py
from AClass import *
from AnotherClass import *
anInstanceOfAClass = AClass()
anInstanceOfAnotherClass = AnotherClass()
print anInstanceOfAnotherClass.att_1  ### This should print out 42
[EMAIL PROTECTED]:/tmp$ python Main.py
Traceback (most recent call last):
  File Main.py, line 4, in ?
anInstanceOfAnotherClass = AnotherClass()
  File /tmp/AnotherClass.py, line 3, in __init__
self.att_1 = anInstanceOfAClass.att_1
NameError: global name 'anInstanceOfAClass' is not defined
[EMAIL PROTECTED]:/tmp$

any suggestion?
bye max
--
http://mail.python.org/mailman/listinfo/python-list


Re: email and smtplib modules

2005-04-09 Thread Mike Meyer
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:

 Hi,

 I'm writing a small script that generates email and I've noticed that:

 1) one should add the 'To' and 'CC' headers to the email message
 2) one needs to specify the recipients in the smtplib sendmail() method

 Can someone explain how these are related?

Sure.

It's all to do with smtp. With smtp mail, as with paper mail, there is
an envelope that has addresses on it that the mail system uses to
deliver messages, and the letter, that has addresses in it that are
displayed to the end user.

The To: and Cc: headers in the message itself are in the letter. The
end user sees those. smtp servers ignore them.

The recipients passed to the smtplib sendmail() method go on the
envelope. The smtp server will deliver to those addresses, and they
won't be shown to end users.

This design makes many things possible. Most used these days is spam
delivered to one address while apparently to another.

  mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: visibility between modules

2005-04-09 Thread Mike Meyer
max(01)* [EMAIL PROTECTED] writes:

 hi.

 if i have a single program file, different class instances can share
 information in (at least) two fashions:

 1. using instance variables:

 class AClass:
def __init__(self):
  self.att_1 = 42
  self.att_2 = Hello!

 class AnotherClass:
def __init__(self):
  self.att_1 = anInstanceOfAClass.att_1

 anInstanceOfAClass = AClass()
 anInstanceOfAnotherClass = AnotherClass()
 print anInstanceOfAnotherClass.att_1  ### This should print out 42

 2. using globals:

 class AClass:
def __init__(self):
  self.att_1 = 42
  self.att_2 = Hello!

 class AnotherClass:
pass

 aGlobalString = No way.
 anInstanceOfAClass = AClass()
 anInstanceOfAClass.att2 = aGlobalString
 anInstanceOfAnotherClass = AnotherClass()
 anInstanceOfAnotherClass.att_1 = aGlobalString
 print anInstanceOfAClass.att2  ### This should output No way.
 print anInstanceOfAnotherClass.att_1  ### And this too


Both these methods actually use globals. In ther first case, the
global is anInstanceOfAClass, that is bound to self.att_1 in the
__init__ method of AnotherClass.

The solution is to pass the instance in as a parameter:

class AClass:
  def __init__(self):
  self.att_1 = 42
  self.att_2 = Hello!

class AnotherClass:
  def __init__(self, instance):
  sefl.att_1 = instance

anInstanceOfAClass = AClass()
anInstanceOfAnotherClass = AnotherClass(anInstanceOfAClass)

or maybe just:

anInstaceOfAnotherClass = AnotherClass(AClass())


   mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python 2.4 on Linux

2005-04-09 Thread Edward Diener
John Ridley wrote:
* Edward Diener wrote:
I need python to be python2.3 else many utilities no longer work.

Then leave your 2.3 installation exactly as it is (so that python is a
link to python2.3) and run python2.4 where needed.
To specifically use python 2.4 to run IDLE, simply type in a shell:
[user]$ python2.4 /usr/bin/idle
Alternatively, create your own (executable) idle or pydoc with a
shebang that points permanently at python2.4. For example:
file: $HOME/bin/idle2.4
---
#!/usr/bin/python2.4
from idlelib.PyShell import main
if __name__ == '__main__':
main()
---
Then if $HOME/bin is on your PATH, you can simply run: idle2.4
This change worked. Thanks !

The problem is then using IDLE and pydoc for Python2.4 since neither
are .py scripts

Really?! What are they on Fedora, then?
I realized they are links to the respective idle2.4.py and pydoc2.4.py 
scripts.
--
http://mail.python.org/mailman/listinfo/python-list


serialize a tkinter thing

2005-04-09 Thread max(01)*
hi.
i tried to serialize a list of StringVar's, but i got a pickle error.
this got me to thinking that tkinter objects are not picklable (in general).
would somebody confirm and/or give examples?
thanks
macs
--
http://mail.python.org/mailman/listinfo/python-list


very simple tkinter demo program

2005-04-09 Thread max(01)*
hello.
i wrote a very simple tkinter demo program that uses menus, buttons, 
labels, entries, frames and secondary toplevels.

it is a python version of a java program made by a colleague.
the user can create (Scrivi) a record with his second name, first name 
and date of birth, save (Salva) the record to a file or read in 
(Leggi) a previously created file. Annulla is to cancel. Chiudi is 
to close.

i also used try-except for checking for invalid files.
only one menu is real (File), the others are for future use.
i'd like to hear your suggestions and comments for improving it.
i recently learned tkiner from stephen ferg's website and reading the 
tk8.4 widget demo programs.

one thing i still cannot do is to make the primary window and the 
secondary aware of each other (so avoid that a second instance of a 
secondary window can be generated if an instance still exists, for example).

so, here it is folks:
---cut here---
from Tkinter import *
class MiaApp:
  def __init__(self, genitore):
self.MioGenitore = genitore
fonte = (Helvetica, 12)
self.campi = [Cognome, Nome , Data di nascita]
quadro_grande = Frame(genitore)
quadro_grande.pack(expand = YES, fill = BOTH)
quadro_menu = Frame(quadro_grande)
quadro_menu.configure(
  bd = 1,
  relief = RAISED
  )
quadro_menu.pack(side = TOP, fill = X)
pm_file = Menubutton(quadro_menu)
pm_file.configure(text = File)
pm_file.pack(side = LEFT)
m_file = Menu(pm_file)
pm_file.configure(menu = m_file)
m_file.configure(tearoff = NO)
m_file.add_command(
  label = Scrivi,
  command = self.premuto_scrivi
  )
m_file.add_command(
  label = Leggi,
  command = self.premuto_leggi
  )
m_file.add_separator()
m_file.add_command(
  label = Chiudi,
  command = genitore.destroy
  )
pm_mod = Menubutton(quadro_menu)
pm_mod.configure(text = Modifica)
pm_mod.pack(side = LEFT)
pm_aiuto = Menubutton(quadro_menu)
pm_aiuto.configure(text = ?)
pm_aiuto.pack(side = RIGHT)
msg = Label(quadro_grande)
msg.configure(
  font = fonte,
  relief = RIDGE,
  wraplength = 10c,
  justify = LEFT,
  text = uQuesto \u00E8 un programma in Python \
che trae ispirazione da un analogo lavoro del collega \
G. Renda. Il programma originale era scritto \
in linguaggio Java, e sfruttava le librerie JFC \
(\u00ABJava Foundation Class\u00BB, dette anche \
\u00ABSwing\u00BB); questo invece usa le librerie Tk, \
mediante il modulo Tkinter.
  )
msg.pack(
  side = TOP,
  padx = 2m,
  pady = 2m
  )
quadro_pulsanti = Frame(quadro_grande)
quadro_pulsanti.pack(
  side = BOTTOM,
  fill = X,
  padx = 2m,
  pady = 2m
  )
scrivi = Button(quadro_pulsanti)
scrivi.configure(
  text = Scrivi,
  command = self.premuto_scrivi
  )
scrivi.pack(side = LEFT, expand = YES)
leggi = Button(quadro_pulsanti)
leggi.configure(text = Leggi, command = self.premuto_leggi)
leggi.pack(side = LEFT, expand = YES)
chiudi = Button(quadro_pulsanti)
chiudi.configure(text = Chiudi, command = genitore.destroy)
chiudi.pack(side = LEFT, expand = YES)
  def premuto_scrivi(self):
InserimentoRecord()
  def premuto_leggi(self):
ConsultazioneRecord()
class InserimentoRecord(Toplevel):
  def __init__(self):
Toplevel.__init__(self)
self.titolo = Inserimento
self.wm_title(self.titolo)
quadro_grande = Frame(self)
quadro_grande.pack(expand = YES, fill = BOTH)
self.quadro_pulsanti = Frame(quadro_grande)
self.quadro_pulsanti.pack(
  side = BOTTOM,
  fill = X,
  padx = 2m,
  pady = 2m
  )
quadri_ing = []
self.n = len(miaApp.campi)
self.var = []
eti = []
larg_eti = max(map(len, miaApp.campi))
ing = []
for i in range(self.n):
  quadri_ing.append(None)
  self.var.append(None)
  ing.append(None)
  eti.append(None)
  quadri_ing[i] = Frame(quadro_grande)
  quadri_ing[i].pack(side = TOP, expand = YES, fill = BOTH)
  self.var[i] = StringVar()
  eti[i] = Label(quadri_ing[i])
  eti[i].configure(
text = miaApp.campi[i] + : ,
width = larg_eti,
anchor = E
)
  eti[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)
  ing[i] = Entry(quadri_ing[i], textvariable = self.var[i])
  ing[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)
self.salva = Button(self.quadro_pulsanti)
self.salva.configure(
  text = Salva,
  command = self.premuto_salva
  )
self.salva.pack(side = LEFT, expand = YES)
self.annulla = Button(self.quadro_pulsanti)
self.annulla.configure(
  text = Annulla,
  command = self.premuto_annulla
  )
self.annulla.pack(side = LEFT, expand = YES)
  def premuto_salva(self):
import tkFileDialog
import pickle
dati = []
for i in range(self.n):
  dati.append(None)
  dati[i] = self.var[i].get()
 

Re: EOL created by .write or .encode

2005-04-09 Thread Aidan Kehoe

 Ar an naoi l de m Aibran, scrobh Xah Lee: 

  If you open a file in emacs, it will open fine regardless whether the
  EOL is ascii 10 or 13. (unix or mac) This is a nice feature. However,
  the what-cursor-position which is used to show cursor position and the
  char's ascii code, says the EOL is ascii 10 when it is in fact ascii
  13.

This _is_ the right thing to do--theres no reason naive programs written in
Emacs Lisp should have to worry about different on-disk representations of
line-endings. If you want to open a file which uses \015 as its line
endings, and have those \015 characters appear in the buffer, open it using
a coding system ending in -unix. C-u C-x C-f /path/to/file RET
iso-8859-1-unix RET in XEmacs, something I dont know but Im certain exists
in GNU Emacs. 

-- 
I, for instance, am gung-ho about open source because my family is being
held hostage in Rob Maldas basement. But who fact-checks me, or Enderle,
when we say something in public? No-one! -- Danny OBrien
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to detect if file is a directory

2005-04-09 Thread César Leonardo Blum Silveira
Thanks :-)

On Apr 9, 2005 3:55 PM, Tim Jarman [EMAIL PROTECTED] wrote:
 César Leonardo Blum Silveira wrote:
 
  Hello all, I'm new to this list.
 
  How can I detect if a file is a directory or not?
 
  Thanks
 
  César
 
 The os module contains many helpful tools for working with files,
 directories, links and so forth. Check out the docs and marvel. The
 following snippet answers your specific question:
 
 code
 import os.path
 
 if os.path.isdir(/some/path/here):
 print It's a directory!
 /code
 --
 Website: www DOT jarmania FULLSTOP com
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: python modules in home dir

2005-04-09 Thread [EMAIL PROTECTED]
set the PYTHON_PATH to include your home directory

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


Re: workaround for generating gui tools

2005-04-09 Thread flupke
Jeremy Bowers wrote:
snip
Domain-specific abstractions do that *faster* than GUI designers, not
slower. And better, too, since every iteration tends to be fully
functional and not just a let's see what this looks like prototype.
Heck, switch 'em out dynamically based on what day of the week it is and
how the user feels today. Let's see your GUI-designer do that.
And if you're not used to doing it that way, you'll be *stunned* at how
much stuff tends to factor out and get easily re-used.
An approach that has more data to work with (some idea of what things are
doing and what they are for) will beat an approach with less data (thing
at row 4, col 2 or, worst case, thing at 233,144) any day.
GUI designers are like the regexs in the famous jwz quote: Some people,
when confronted with a problem, think 'I know, I'll use a GUI designer'.
Now they have two problems. Both have a niche in the quick fix
department, both are typically over-used, but overall regexs are the more
useful of the two; at least there are cases where they are the undisputed
right answer (like defining tokens in a language parser).
Generally, over the first couple of weeks of a project, the
domain-specific language writer may seem to be behind the GUI designer
cranking out screen after screen of templated GUI widgets, but after a
couple of weeks the domain-specific language user will pull into the lead
and never give it up, and will be a lot happier to boot.
First time i hear about domain-specific abstractions.
Do you mean that instead of using a GUI designer, you make some sort of 
engine that constructs a gui for you?

One thing i find repetitive to do is designing gui's that are just 
simple views on a database tables where one can create,edit and delete 
records. If one could construct a gui dynamically for these types of 
things, that would be great.

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


Re: Counting iterations

2005-04-09 Thread Steven Bethard
Andrew Dalke wrote:
  pet#%i % (i+1)
(NOTE: most times that's written %d instead of %i)
Any reason to prefer %d over %i? The library reference seems to suggest 
that they're the same thing[1].  I've typically used %i since I can 
remember it from the int type, like I can remember %f from the float 
type.  Is there any reason not to?

STeVe
[1] http://docs.python.org/lib/typesseq-strings.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best editor?

2005-04-09 Thread Aahz
In article [EMAIL PROTECTED], Mike Meyer  [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] (Aahz) writes:

 Use vim.  80% of the power of emacs at 20% of the learning curve.

Hmm. Can I read mail/news/web pages in vim? I can in emacs.

Yup, that's why emacs stands for Eighty Megabytes And Constantly
Swapping.  ;-)

Emacs is a computing environment. I read mail and news in it, so I
don't have to worry about learning some applications custom editor
(ok, a good MUA/newsreader will invoke my favorite editor - but that's
Emacs, so why bother). I use emacs for the heavy lifting.

Doesn't work so well when you want to use an application that isn't
emacs, yet still invoke a custom editor.  But yeah, if you consider emacs
a Way of Life, then you're making sense.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death.  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are circular dependencies possible in Python?

2005-04-09 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Tim Tyler wrote:

 Like C, Python seems to insist I declare functions before calling
 them - rather than, say, scanning to the end of the current script
 when it can't immediately find what function I'm referring to.

They don't have to be declared but to be *defined* in Python before you
can call them.  A ``def`` is executed in Python -- a function object is
given a name.  The content of a Python script is executed in the order the
code is written.

 C lets you predeclare functions to allow for the existence of
 functions with circular dependencies.
 
 Does Python allow you to do something similar?

Yes, just define the function before it gets actually called::

  def func_a(n):
  if n  5:
  return
  else:
  func_b(n + 1)

  def func_b(n):
  print n
  func_a(n + 1)

  func_a(0)

What happens here is

1. Define function A.  That function B doesn't exist by now is no problem
because it is not called yet.  There's just the instruction to call it if
the body of function A is executed.  *Then* function B has to exist.

2. Define function B.  You can swap both definitions without problems.

3. Function A is actually called and *must* exist at this point.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wsh and Python

2005-04-09 Thread Roger Upole
Since AppActivate returns a boolean, you should be able
to do something like this:

while not shell.AppActivate(name):
win32api.Sleep(100)

  Roger

David Josty [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hello

 I have this function :
 
 import sys
 import win32com.client
 import win32api

 def close_softawre(name)
shell = win32com.client.Dispatch(WScript.Shell)
shell.AppActivate (name)
win32api.Sleep(100)
shell.SendKeys (%{F4})
 - 
 But sometimes i have any problemes, the programme is not activate a time 
 !!!


 == this is wsh !! i don't know translate in python

 Do while WshShell.AppActivate (name) = FALSE
 wscript.sleep 100
 loop

 Thank a lot

 a french guy

 




== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 100,000 
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (newsgroup-post 127)

2005-04-09 Thread has
No, the greatest news ever would be that Usenet spammers are being
riveted to trees.

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


Re: Puzzling OO design problem

2005-04-09 Thread Michele Simionato
Dirk wrote:
 So I dug through the documentation and found that new-style classes
 compute a monotonic linearization of the inheritance graph, observing
local precedence order, using the algorithm also used in Dylan
 described here:

http://www.webcom.com/haahr/dylan/linearization-oopsla96.html

nitpick mode
Actually Dylan authors invented the C3 algorithm but Dylan does not use
it:
for compatibility with Lisp, Dylan uses the CLOS algorithm. Languages
that
I know that use C3 are Python and Goo. Playing with the MOP you can get
lispy languages to follow C3 too.
/nitpick mode

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


Re: THE GREATEST NEWS EVER ! °º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°`°º·...·°` (new

2005-04-09 Thread Anthony
I thought 'The Greatest News Ever' might mean something serious like
transfer of the classic Beatles albums to SACD.
But no, it's just religious crap. Now that the Pope's dead, do you
think we could declare christianity officially extinct? Please?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: very simple tkinter demo program

2005-04-09 Thread Samantha
I can not get it to run.
S
max(01)* [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 hello.

 i wrote a very simple tkinter demo program that uses menus, buttons, 
 labels, entries, frames and secondary toplevels.

 it is a python version of a java program made by a colleague.

 the user can create (Scrivi) a record with his second name, first name 
 and date of birth, save (Salva) the record to a file or read in 
 (Leggi) a previously created file. Annulla is to cancel. Chiudi is 
 to close.

 i also used try-except for checking for invalid files.

 only one menu is real (File), the others are for future use.

 i'd like to hear your suggestions and comments for improving it.

 i recently learned tkiner from stephen ferg's website and reading the 
 tk8.4 widget demo programs.

 one thing i still cannot do is to make the primary window and the 
 secondary aware of each other (so avoid that a second instance of a 
 secondary window can be generated if an instance still exists, for 
 example).

 so, here it is folks:

 ---cut here---

 from Tkinter import *

 class MiaApp:
   def __init__(self, genitore):

 self.MioGenitore = genitore

 fonte = (Helvetica, 12)

 self.campi = [Cognome, Nome , Data di nascita]

 quadro_grande = Frame(genitore)
 quadro_grande.pack(expand = YES, fill = BOTH)

 quadro_menu = Frame(quadro_grande)
 quadro_menu.configure(
   bd = 1,
   relief = RAISED
   )
 quadro_menu.pack(side = TOP, fill = X)

 pm_file = Menubutton(quadro_menu)
 pm_file.configure(text = File)
 pm_file.pack(side = LEFT)

 m_file = Menu(pm_file)
 pm_file.configure(menu = m_file)
 m_file.configure(tearoff = NO)
 m_file.add_command(
   label = Scrivi,
   command = self.premuto_scrivi
   )
 m_file.add_command(
   label = Leggi,
   command = self.premuto_leggi
   )
 m_file.add_separator()
 m_file.add_command(
   label = Chiudi,
   command = genitore.destroy
   )

 pm_mod = Menubutton(quadro_menu)
 pm_mod.configure(text = Modifica)
 pm_mod.pack(side = LEFT)

 pm_aiuto = Menubutton(quadro_menu)
 pm_aiuto.configure(text = ?)
 pm_aiuto.pack(side = RIGHT)

 msg = Label(quadro_grande)
 msg.configure(
   font = fonte,
   relief = RIDGE,
   wraplength = 10c,
   justify = LEFT,
   text = uQuesto \u00E8 un programma in Python \
 che trae ispirazione da un analogo lavoro del collega \
 G. Renda. Il programma originale era scritto \
 in linguaggio Java, e sfruttava le librerie JFC \
 (\u00ABJava Foundation Class\u00BB, dette anche \
 \u00ABSwing\u00BB); questo invece usa le librerie Tk, \
 mediante il modulo Tkinter.
   )
 msg.pack(
   side = TOP,
   padx = 2m,
   pady = 2m
   )

 quadro_pulsanti = Frame(quadro_grande)
 quadro_pulsanti.pack(
   side = BOTTOM,
   fill = X,
   padx = 2m,
   pady = 2m
   )

 scrivi = Button(quadro_pulsanti)
 scrivi.configure(
   text = Scrivi,
   command = self.premuto_scrivi
   )
 scrivi.pack(side = LEFT, expand = YES)

 leggi = Button(quadro_pulsanti)
 leggi.configure(text = Leggi, command = self.premuto_leggi)
 leggi.pack(side = LEFT, expand = YES)

 chiudi = Button(quadro_pulsanti)
 chiudi.configure(text = Chiudi, command = genitore.destroy)
 chiudi.pack(side = LEFT, expand = YES)

   def premuto_scrivi(self):
 InserimentoRecord()

   def premuto_leggi(self):
 ConsultazioneRecord()

 class InserimentoRecord(Toplevel):
   def __init__(self):

 Toplevel.__init__(self)

 self.titolo = Inserimento
 self.wm_title(self.titolo)

 quadro_grande = Frame(self)
 quadro_grande.pack(expand = YES, fill = BOTH)

 self.quadro_pulsanti = Frame(quadro_grande)
 self.quadro_pulsanti.pack(
   side = BOTTOM,
   fill = X,
   padx = 2m,
   pady = 2m
   )

 quadri_ing = []
 self.n = len(miaApp.campi)
 self.var = []
 eti = []
 larg_eti = max(map(len, miaApp.campi))
 ing = []
 for i in range(self.n):
   quadri_ing.append(None)
   self.var.append(None)
   ing.append(None)
   eti.append(None)
   quadri_ing[i] = Frame(quadro_grande)
   quadri_ing[i].pack(side = TOP, expand = YES, fill = BOTH)
   self.var[i] = StringVar()
   eti[i] = Label(quadri_ing[i])
   eti[i].configure(
 text = miaApp.campi[i] + : ,
 width = larg_eti,
 anchor = E
 )
   eti[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)
   ing[i] = Entry(quadri_ing[i], textvariable = self.var[i])
   ing[i].pack(side = LEFT, pady = 5, padx = 10, fill = X)

 self.salva = Button(self.quadro_pulsanti)
 self.salva.configure(
   text = Salva,
   command = self.premuto_salva
   )
 self.salva.pack(side = LEFT, expand = YES)

 self.annulla = Button(self.quadro_pulsanti)
 self.annulla.configure(
   text = Annulla,
   command = 

Re: Are circular dependencies possible in Python?

2005-04-09 Thread John Machin
On Sat, 9 Apr 2005 15:57:15 GMT, Tim Tyler [EMAIL PROTECTED]  wrote:

Like C, Python seems to insist I declare functions before calling
them

One is left wondering what gave you that impression about Python.
Nothing could be further from the truth. The only construct in Python
that smells anything like a declaration is the wartish global. The
Python philosophy is that everything is dynamic. You don't muck about
with declarations; you just get on with the job. See example below,
where we have a list of functions, which of course all follow the same
protocol, but what that protocol is is of no concern of the Python
compiler.

def nothing_to_declare(data_fields, validation_funcs, other_info):
for k, fld in enumerate(data_fields):
validation_funcs[k](fld, k, other_info)

Aside: How many iterations would it take for the average C programmer
to get the declaration for validation_funcs correct?

Others have pointed out that def is executed. So is class. An OO
example of dynamism would be a bit longer, but would involve creating
classes on the fly and stuffing into them whatever methods are
required for the task at hand.

HTH,

John

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


  1   2   >