keep a list of read and unread items

2006-08-13 Thread a
keep a list of read and unread items

hi guys
i m building an rss reader and i want you suggestions for datastructure
for keeping read and unread list for each use
i m assuming it will be very sparse
thanks

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


Re: keep a list of read and unread items

2006-08-13 Thread Ant

a wrote:

> i m building an rss reader and i want you suggestions for datastructure
> for keeping read and unread list for each use
> i m assuming it will be very sparse

A dictionary for each site seems to be the obvious choice, mapping the
article ID to True or False.

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


Re: keep a list of read and unread items

2006-08-13 Thread Stargaming
Ant schrieb:
> a wrote:
> 
> 
>>i m building an rss reader and i want you suggestions for datastructure
>>for keeping read and unread list for each use
>>i m assuming it will be very sparse
> 
> 
> A dictionary for each site seems to be the obvious choice, mapping the
> article ID to True or False.
> 

You could also write a class, let's say RSSEntry, with attributes like 
"read", "title", "author", "content", "date" and everything you need.
Another class-way would be some class like RSSFeed, being a container 
holding entries like RSSFeed[0] RSSFeed[1] etc., each again with 
attributes like RSSFeed[0].author.
Those class instances can be pickle'd easily, so you don't have to 
bother about any database or stuff.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble with replace

2006-08-13 Thread Anthra Norell
This might well take the trouble out ot the OP's replace:

http://cheeseshop.python.org/pypi/SE/2.2%20beta

Regards

Frederic

--
And here is how it works:

>>> text = '''defgefabcdefy

  effwerbyuuuterrfr'''
>>> import SE
>>> String_Editor = SE.SE ( 'abcdef=highway defgef=news effwer=monitor')
>>> print String_Editor (text)
newshighwayy

  monitorbyuuuterrfr
--

- Original Message - 
From: "f pemberton" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Saturday, August 12, 2006 6:49 PM
Subject: trouble with replace


> I have a string (xdata) and theres a newline after every 17 characters
> of the string. I was wondering how I can replace multiple substrings
> multiple times within a string? To put it another way, this is what i
> want to do.
> 
> Substring to find ("abcdef") replace it with ("highway")
> search again, substring to find ("defgef") replace it with
> ("news").Search again and find ("effwer") replace it with
> ("monitor").Example string to search under is '''defgefabcdefy
> 
> 
>   effwerbyuuuterrfr'''
> 
> I've tried using replace but its not working for me.
> xdata.replace('abcdef', 'highway')
> xdata.replace('defgef', 'news')
> xdata.replace('effwer', 'monitor')
> Basically I would want to get the output of   "newshighwayy
> 
> 
>monitorbyuuuterrfr"
> 
> Thanks, any help would be appreciated.
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Newbie doing lengthy initialization with Tkinter gui

2006-08-13 Thread Pasi Oja-Nisula
I have written a small image viewer application for
sorting out photos downloaded from camera. This was quite easy,
thanks to the great Python Imaging Library. Since the loading and 
thumbnailing phase takes a while at the start of the program, 
I figured that it would be nice to show the gui and put some kind
of "loading image 25/50" text there while processing the images. 
So now I construct the simple Tkinter gui in init and when mainloop 
is called the gui is shown.

The question is how (or where) can I call my loadImages function right 
after the mainloop starts? Or is there a better way to do this?

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


__LINE__ and __FILE__ functionality in Python?

2006-08-13 Thread Joakim Hove

Hello,

i have simple[1] function like this:

   def log_msg(msg , file , line):
   print "%s:%s   %s" % (file,line,msg)

the file and line arguments should be the filename and linenumber of
the source file where the function is called. If this were C I would
have used the __FILE__ and __LINE__ macros as:

  log_msg(msg , __FILE__ , __LINE__)

Is there a way to emulate this behaviour in Python?


Best Regards

Joakim Hove



[1]: It is not *that* simple, but you get the point.


-- 
Joakim Hove
hove AT ntnu.no/
Tlf: +47 (73 5)9 34 27/ Stabburveien 18  
Fax: .   /  N-5231 Paradis   
http://www.ift.uib.no/~hove//   55 91 28 18 / 92 68 57 04
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a dictionary to pass data to/from embedded python functions

2006-08-13 Thread Bill Pursell

Alex Martelli wrote:
>
> I wrote the following file za.c:



> and proceeded to compile and execute as follows: [[Note: it does not
> matter that I'm using 2.5, the code is just as fine with previous
> versions -- it just happens that 2.5 is what I'm using right now in
> order to help out with 2.5's beta testing]]:
>
> brain:~/pyex alex$ gcc -c za.c -I/usr/local/include/python2.5
> brain:~/pyex alex$ gcc -o za za.o -L/usr/local/lib/python2.5/config/
> -lpython2.5
> brain:~/pyex alex$ ./za


I needed to include a lot more flags to make the example compile.
In particular:
-L /usr/local/lib/python2.4/config/ -lpython2.4 -lrt -lm -ldl -lutil

Why did you not need them?  Is this a misconfiguration on my
box, or something entirely different?  I've seen this type of thing
come up a lot, and I can't tell if it is simply the author omitting
flags for the sake of brevity, or if I'm actually missing something.

--
Bill Pursell

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


Re: Newbie doing lengthy initialization with Tkinter gui

2006-08-13 Thread Maric Michaud
Le dimanche 13 août 2006 12:39, Pasi Oja-Nisula a écrit :

> The question is how (or where) can I call my loadImages function right
> after the mainloop starts? Or is there a better way to do this?
>
Seems a good use case for multi-thread, try something like this :

In [28]: import Tix

In [29]: main=Tix.Tk()

In [30]: p=Tix.Meter(main)

In [31]: p.pack()

In [32]: def process(progress) :
   : from time import sleep
   : for i in range(10) :
   : sleep(1)
   : p.configure(value=float(p.cget('value'))+0.1)
   :
   :


In [33]: import thread

In [34]: thread.start_new_thread(process, (p,)) and main.mainloop()

Of course the last line is tricky, the thread should be started by the 
App(Tix.Tk) mainloop.


> Pasi

-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __LINE__ and __FILE__ functionality in Python?

2006-08-13 Thread Maric Michaud
Le dimanche 13 août 2006 13:31, Joakim Hove a écrit :
> Hello,
>
> i have simple[1] function like this:
>
>def log_msg(msg , file , line):
>print "%s:%s   %s" % (file,line,msg)
>
> the file and line arguments should be the filename and linenumber of
> the source file where the function is called. If this were C I would
> have used the __FILE__ and __LINE__ macros as:
>
>   log_msg(msg , __FILE__ , __LINE__)
>
> Is there a way to emulate this behaviour in Python?

Sure, try :

In [46]: import inspect

In [47]: c=inspect.currentframe()

In [48]: c.f_lineno
Out[48]: 1

In [49]: c.f_code.co_filename
Out[49]: ''

Of course, in the console, these are not truly relevant.


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __LINE__ and __FILE__ functionality in Python?

2006-08-13 Thread John Machin
Joakim Hove wrote:
> Hello,
>
> i have simple[1] function like this:
>
>def log_msg(msg , file , line):
>print "%s:%s   %s" % (file,line,msg)
>
> the file and line arguments should be the filename and linenumber of
> the source file where the function is called. If this were C I would
> have used the __FILE__ and __LINE__ macros as:
>
>   log_msg(msg , __FILE__ , __LINE__)
>
> Is there a way to emulate this behaviour in Python?
>

It's better in Python not to emulate that but to let the caller do the
work:

C:\junk>type caller_id.py
import inspect

def logger(msg):
print "logger:", msg
print "called from %s:%d" % inspect.stack()[1][1:3]
print

def client1():
logger("one")

def client2():
logger("two")

client1()
client2()


C:\junk>caller_id.py
logger: one
called from C:\junk\caller_id.py:9

logger: two
called from C:\junk\caller_id.py:12

If you care to search for __LINE__ in this newsgroup, there's a slight
chance you might find a thread or two or twenty-two on the topic :-)

I don't usually go for one-liners, especially ugly ones like
"inspect.stack()[1][1:3]" but it avoids the risk of hanging on to a
reference to the frame object -- see the warning in the inspect docs.

You can get the name of the calling function or method (and,
indirectly, the method's class) if you want to log the whole dossier --
details left as an exercise :-)

HTH,
John

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


Re: __LINE__ and __FILE__ functionality in Python?

2006-08-13 Thread Joakim Hove

Maric Michaud <[EMAIL PROTECTED]> writes:


> Sure, try :
>
> In [46]: import inspect
>
> In [47]: c=inspect.currentframe()
>
> In [48]: c.f_lineno
> Out[48]: 1
>
> In [49]: c.f_code.co_filename
> Out[49]: ''

Thanks a lot - that was just what I wanted.


Regards - Joakim


-- 
Joakim Hove
hove AT ntnu.no/
Tlf: +47 (73 5)9 34 27/ Stabburveien 18  
Fax: .   /  N-5231 Paradis   
http://www.ift.uib.no/~hove//   55 91 28 18 / 92 68 57 04
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] John Salerno

2006-08-13 Thread jason
Alan Connor wrote:

> Looks like pretty much all trolls to me. 
> 
> Note: I won't be downloading any articles on this thread.
> 
> Alan
> 

Funny how you keep saying that but keep downloading and responding.
-- 
http://mail.python.org/mailman/listinfo/python-list


set_focus_chain in pygtk and wxPython

2006-08-13 Thread egbert
In pygtk is available: set_focus_chain
Does wxPython have something similar ?
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

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


ERROR "no mem to add parser accelerator"

2006-08-13 Thread John Savage
When I attempt to run the MSDOS version of python I get the error
message "no mem to add parser accelerator" and am returned to the DOS
prompt. Yet I've been successfully running this python executable for
months on this pc and as far as I know I haven't changed anything that
could have upset python. Any ideas on a fix?

I'm giving it 620k of conventional memory to play with.
--
John Savage   (my news address is not valid for email)
-- 
http://mail.python.org/mailman/listinfo/python-list


Installed correctly

2006-08-13 Thread Ray


I've just installed Python 2.4.3 on windows 2000. On the download page
it says that if python is installed the version number will be
displayed if you enter "python" in a command line window, but that
does not happen - it just says "unrecognized command". Rebooting does
not help.

So is it correctly installed? I installed it under "program
files/python" instead of the default location C:\python, since I don-t
like to have the root of C: cluttered with stuff, are there any
problems with this?


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


Re: Installed correctly

2006-08-13 Thread John Machin

Ray wrote:
> I've just installed Python 2.4.3 on windows 2000. On the download page
> it says that if python is installed the version number will be
> displayed if you enter "python" in a command line window, but that
> does not happen - it just says "unrecognized command". Rebooting does
> not help.
>
> So is it correctly installed? I installed it under "program
> files/python" instead of the default location C:\python, since I don-t
> like to have the root of C: cluttered with stuff, are there any
> problems with this?

Your recollection that the default was C:\python is [I hope] faulty; it
*should* have been C:\Python24

You probably need to add "C:\Program Files\Python" (if that's where you
installed it) to your Windows path.

HTH, 
John

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


Re: __LINE__ and __FILE__ functionality in Python?

2006-08-13 Thread Maric Michaud
Le dimanche 13 août 2006 14:18, John Machin a écrit :
> I don't usually go for one-liners, especially ugly ones like
> "inspect.stack()[1][1:3]" but it avoids the risk of hanging on to a
> reference to the frame object -- see the warning in the inspect docs.

Yes, my mistake, thanks for pointing this out, my suggestion should have been 
more accurate :

import inspect

try :
c=inspect.currentframe()
log_msg(c.f_lineno, c.f_code.co_filename)
finally :
del c

or shorter ;

from inspect import currentframe
log_msg(currentframe().f_lineno,
currentframe().f_code.co_filename)


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installed correctly

2006-08-13 Thread Angelo Zhou
Ray wrote:
> 
> I've just installed Python 2.4.3 on windows 2000. On the download page
> it says that if python is installed the version number will be
> displayed if you enter "python" in a command line window, but that
> does not happen - it just says "unrecognized command". Rebooting does
> not help.
> 
> So is it correctly installed? I installed it under "program
> files/python" instead of the default location C:\python, since I don-t
> like to have the root of C: cluttered with stuff, are there any
> problems with this?
> 
> 
Do you know how to set up the %PATH% variable in win2k? Add the path of 
the bin directory of your python installation to the %PATH%
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which KDE IDE for Python?

2006-08-13 Thread Detlev Offenbach
Bart Ogryczak wrote:

> 
> Diez B. Roggisch wrote:
>> Bart Ogryczak schrieb:
>> > Hi,
>> > Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both
>> > have drawbacks. KDevelop is a multilanguage IDE, and doesn't really
>> > have anything special for Python. There's no Python debugger, no
>> > PyDOC integration, it's class browser doesn't display attributes. On
>> > the other side there's Eric, which is made just for Python. But.. it
>> > doesn't integrate with KDE, doesn't support remote files (fish://,
>> > ftp:// etc.). Does anyone know a better IDE for Python, that'll
>> > integrate nicely with KDE?
>>
>> I bet you can try and convince Detlev Offenbach (eric developer) to
>> add that - he already has _some_ KDE-specific stuff in there, and I
>> presume supporting IO-Slaves might not be too hard.
> 
> Actually I doubt it. For example on question why doesn't Eric use
> katepart as editor, he responded:
> "Because it is actually written using PyQt and is meant to work on
> Win... and Mac OS X as well. Therefore it must not depend on KDE (or
> any other non-portable or non-ported toolkit)."

I am thinking about support for loading/saving files via ftp for eric4.
However, this will most probably be a feature for eric4 4.1 and not the
first release. This will be done in a way, that is independent of KDE.

Regards,
Detlev
-- 
Detlev Offenbach
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installed correctly

2006-08-13 Thread BartlebyScrivener

Ray wrote:
> are there any
> problems with this?

Apparently, yes ;)

>> Do you know how to set up the %PATH% variable in win2k?

In case you don't, this is from another thread:

Sequence on XP is Start | Control Panel | System | Advanced |
Environmental Variables. Then in the lower half of the dialogue box is
the "System Variables" Select Path, and then edit and enter the path to
Python.exe. I used ActiveState which puts it in c:\python24

>From what you've told us you should try c:\Program Files\Python

But as the wise man says, the spaces in path names will haunt you on
windows.

Good luck.

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


Re: Newbie doing lengthy initialization with Tkinter gui

2006-08-13 Thread jmdeschamps
Maric Michaud wrote:
> Le dimanche 13 août 2006 12:39, Pasi Oja-Nisula a écrit :
>
> > The question is how (or where) can I call my loadImages function right
> > after the mainloop starts? Or is there a better way to do this?
> >
> Seems a good use case for multi-thread, try something like this :
>
> In [28]: import Tix
>
> In [29]: main=Tix.Tk()
>
> In [30]: p=Tix.Meter(main)
>
> In [31]: p.pack()
>
> In [32]: def process(progress) :
>: from time import sleep
>: for i in range(10) :
>: sleep(1)
>: p.configure(value=float(p.cget('value'))+0.1)
>:
>:
>
>
> In [33]: import thread
>
> In [34]: thread.start_new_thread(process, (p,)) and main.mainloop()
>
> Of course the last line is tricky, the thread should be started by the
> App(Tix.Tk) mainloop.
>
>
> > Pasi
>
> --
> _
>
> Maric Michaud
> _
>
> Aristote - www.aristote.info
> 3 place des tapis
> 69004 Lyon
> Tel: +33 426 880 097

Tkinter also has a timer-type function called *after*. Use this to call
your init function just befrore the mainloop call. You gui wil show up
and you can then update it to show progress as you wish
No neep for thread or Tix modules...!

Here's a working example:
#
from Tkinter import *
# Your progress showing function
def showProgress(i):
# Tell the gui to show some progress here
obj=c.find_withtag("job")[0]
c.itemconfig(obj,text="Ok from job is up to "+str(i))
c.update()

# Your app init function
def doInitOne():
#Do some init work here
for i in range(100):
for j in range(100):
for k in range(100):
for m in range(100):
a=1
# Once in a while update the gui
showProgress(i)

# your main app
root=Tk()
c=Canvas(root,bg="yellow",width=300,height=300)
monobj=c.create_text(100,200,text="Some ",tags="job")
c.pack()
# this will *sleep* one millisec before calling
# your doInitOne function and continue
# with the rest of the code during that sleep time
# in this case just the mainloop
root.after(1, doInitOne)
root.mainloop()

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


Re: start a multi-sockets server (a socket/per thread) with different ports but same host

2006-08-13 Thread Jean-Paul Calderone
On 12 Aug 2006 21:59:20 -0700, zxo102 <[EMAIL PROTECTED]> wrote:
>Jean-Paul,
>I just start to learn Twisted. Here is my simple case: I can find
>the data sent by clients in dataReceived but I don't know which
>client/which port the data is from. After I know where the data comes
>from, I can do different things there, for example, write them into
>different files via bsddb.  I am not sure if it is the correct way to
>do it.
>
>
>   def dataReceived(self, data):
>   # Accumulate the new data in our list
>   self.received.append(data)
>   # And then echo the entire list so far back to the client
>   self.transport.write(''.join(data))
>
>   print "> data: ", data
>   print " which Port? : ", self.factory.port  # unforunately it is
>an object here.

Check out self.transport.getHost().  It, too, is an object, with a 'port'
attribute.

You may also want to glance over the API documentation:

  http://twistedmatrix.com/documents/current/api/

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


Re: reading from sockets

2006-08-13 Thread AndrewTK
Simon Forman wrote:
> So I'm guessing it's something wrong in your java server.

Thanks then. I'll keep testing then...

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


Re: reading from sockets

2006-08-13 Thread AndrewTK
Simon Forman wrote:
> So I'm guessing it's something wrong in your java server.

Thanks then. I'll keep testing then... Although I don't seem to have
netcat on my unit...

I'm using a uni computer so I can't install stuff... but I'm guessing
what I wrote is something like a basic-basic thingy that does what
netcat is designed to do.?

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


Re: Installed correctly

2006-08-13 Thread Rich


Well thanks for all your replies. 

I've now uninstalled Python, and reinstalled it using the default path
(C:\pythoh24). But command line still says "unrecognized command",
when typng "pythoin". so maybe you have to 


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


Re: Installed correctly

2006-08-13 Thread BartlebyScrivener

Rich wrote:
>> But command line still says "unrecognized command",

You don't say which installer you are using? I know the ActiveState
installer puts the python directory in your environment automatically,
and I bet the Python.org installer does too.

Do you see Python24 in your path?

If you get desperate, try:

http://dooling.com/index.php/category/geekophilia

It's a hand-holding install guide.

rd

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


Re: Installed correctly

2006-08-13 Thread Rich

(sorry, I accidentally hit "send" before I was finished)

Well thanks for all your replies. 

I've now uninstalled Python, and reinstalled it using the default path
(C:\python24), to avoid any complications. But command line still said
"unrecognized command", when typing "python". So apparently you have
to do that manually (at least in some cases). In any case I added the
path according to your instructions, and now it seems to work. 

Perhaps the page refered to systems that comes with Python
pre-installed (they mention that some HP machines do). Obviously, the
pre-iinstallation would have to include setting the path. 

Again, thanks for your help! :)


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


Re: Kill process based on window name (win32)

2006-08-13 Thread drodrig
I am running the program mentioned below as an NT service on a terminal
server. The service listens on a UDP port for any of a series of
commands. In this case, the command "closeApps " will notify the
service to close all the open apps for user (). So while the code
below works great for a standalone app, it fails as a service because
the window handles of each user are not retrievable (I should say I
don't know how to retrieve them). Is this even possible? I looked at
some of the Windows API calls but nothing stuck out.

Suggestions?

drodrig wrote:
> Thank you Roger. Your advice did the trick. For anyone interested, the
> basic code to terminate a process (politely) would be something like
> this (hwnd is retrieved using win32gui.EnumerateWindows):
>
> # Get the window's process id's
> t, p = win32process.GetWindowThreadProcessId(hwnd)
> # Ask window nicely to close
> win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
> # Allow some time for app to close
> time.sleep(10)
> # If app didn't close, force close
> try:
> handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, p)
> if handle:
> win32api.TerminateProcess(handle,0)
>   win32api.CloseHandle(handle)
> except:
> pass:
>
> Roger Upole wrote:
> > drodrig wrote:
> > > Hi.
> > >
> > > I am trying to close/kill all processes that show visible windows on
> > > Windows XP. So far I've created a script that uses win32gui.EnumWindows
> > > to iterate through all windows, check for which windows are visible,
> > > then send a WM_CLOSE message to the window to request that it closes.
> > > Of course, not all apps want to close nicely. At this point I need to
> > > use something like TerminateProcess to kill the app, but how do I find
> > > the process id (hopefully based on the window id).
> > >
> > > Thanks for any help.
> > >
> >
> > win32process.GetWindowThreadProcessId should do the trick.
> > 
> >Roger

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


Re: reading from sockets

2006-08-13 Thread Simon Forman
AndrewTK wrote:
> Simon Forman wrote:
> > So I'm guessing it's something wrong in your java server.
>
> Thanks then. I'll keep testing then... Although I don't seem to have
> netcat on my unit...
>
> I'm using a uni computer so I can't install stuff... but I'm guessing
> what I wrote is something like a basic-basic thingy that does what
> netcat is designed to do.?

First link from googling netcat:
http://netcat.sourceforge.net/

Online man page for netcat (a.k.a. nc)
http://www.openbsd.org/cgi-bin/man.cgi?query=nc
 (Note, it's the openbsd man page. YMMV)

If you can compile C on your university computer then you should be
able to download, compile, and "install" it to a dir in your homedir.
I've done it, so I know it's possible. :-) (I was working on a remote
machine that I didn't have root on, and I needed to test a tcp server I
was writing.)

Netcat's a truly awesome and surprisingly useful little tool.  Any
effort you spend to learn it will be well repaid.

Peace,
~Simon

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


Re: Using a dictionary to pass data to/from embedded python functions

2006-08-13 Thread Alex Martelli
Bill Pursell <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> >
> > I wrote the following file za.c:
> 
> 
> 
> > and proceeded to compile and execute as follows: [[Note: it does not
> > matter that I'm using 2.5, the code is just as fine with previous
> > versions -- it just happens that 2.5 is what I'm using right now in
> > order to help out with 2.5's beta testing]]:
> >
> > brain:~/pyex alex$ gcc -c za.c -I/usr/local/include/python2.5
> > brain:~/pyex alex$ gcc -o za za.o -L/usr/local/lib/python2.5/config/
> > -lpython2.5
> > brain:~/pyex alex$ ./za
> 
> 
> I needed to include a lot more flags to make the example compile.
> In particular:
> -L /usr/local/lib/python2.4/config/ -lpython2.4 -lrt -lm -ldl -lutil

You no doubt needed that for linking, not for compiling (I needed the -L
and -l too for linking, see above, just not the "other" libraries).


> Why did you not need them?  Is this a misconfiguration on my
> box, or something entirely different?  I've seen this type of thing
> come up a lot, and I can't tell if it is simply the author omitting
> flags for the sake of brevity, or if I'm actually missing something.

Neither: we're just talking about different platforms -- probably both
Unix variants, but with different linking-loader behavior and/or
dependencies among libraries.  Considering that my platform's ld is
doubtlessly the single most prominent difference between it and other
Unix variants from a developer's viewpoint (see
 for more details) I was remiss in not mentioning my
platform; I apologize, I was concentrating on the C++ and Python sources
rather than on the build process (but I should have mentioned it in the
Note, just as I mentioned that I was using 2.5 but it didn't matter!).


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


Re: semi-Newbie question

2006-08-13 Thread len
Sample and test code shows you are correct.

tpsFile - is really the SQL file I will be inserting new policy records
into

tagFile - is a CVS file containing all of the information for a new
policy in an XMLish fashion (one record per filed of the policy) I will
receive from a third party

tagIdxFile - is just a file that where the data from the tagFile should
be mapped into the tpsFile

CODE

tpsFile = {'tpsFirstName' : 'Kate', 'tpsLastName' : 'Sumner',
'tpsPhone': '532-1234'}
tagFile = {'tagname' : 'tagFirst', 'tagScope' : 'POL0', 'tagValue' :
'Rose'}
tagIdxFile = {'idxtagname' : 'tagFirst', 'idxtpsname' : 'tpsFirstName'}
print tpsFile['tpsFirstName']
tpsFile[tagIdxFile['idxtpsname']] = tagFile['tagValue']
print tpsFile['tpsFirstName']

RESULTS

>>>
Kate
Rose
>>>

Just a small note:  As trivial as this may seem this task was not
possible in the compiled language I work in due to the fact that there
was no way for me to get the data referenced by
tagIdxFile['idxtpsname'] and then use it as a field label on the left
side of the assignment statement because in the compiled language the
left side must be a label and NOT and expression.

Just strengthens my commitment to learn Python.


I would like to thank every one for their help, advice and patients.

Len Sumnler
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> len <[EMAIL PROTECTED]> wrote:
>   .
>   .
>   .
> >I have done some more reading and I think the code I need is as
> >follows;
> >
> >mycode = "TagToSQL['mySQLfieldname'] = Tagfile['Value']"
> >exec mycode
> >
> >This is very new to me because I don't believe this can be done in a
> >compiled language or at least not as easily as in an interpeted
> >language like Python.
> >
> >I hope this clarifies the problem
>   .
>   .
>   .
> I don't understand how
>
>   TagToSQL[mySQLfieldname] = Tagfile[Value]
>
> fails to meet requirements that
>
>   mycode = "TagToSQL['mySQLfieldname'] = Tagfile['Value']"
>   exec mycode
>
> satisfies.
>
> This thread confuses me.  Maybe you already have all the answers
> you seek.  If not, I recommend that you simplify--perhaps work
> through a single example datum in detail.  In the meantime, I
> applaud your judgment that you can achieve what you're after with
> table lookups and such rather than the thousand-way if-else at
> which you hinted at least once.

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


yet another noob question

2006-08-13 Thread mike_wilson1333
I would like to generate every unique combination of numbers 1-5 in a 5
digit number and follow each combo with a newline.  So i'm looking at
generating combinations such as: (12345) , (12235), (4) and so on.
What would be the best way to do this? So, basically i'm looking for a
list of all combinations of 1-5 in a 5 digit unique number. Also, when
I send the list to print there can't be any duplicates of the combos.


  Thanks,

  Mike

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


Re: Newbie doing lengthy initialization with Tkinter gui

2006-08-13 Thread Pasi Oja-Nisula
In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] wrote:
> Tkinter also has a timer-type function called *after*. Use this to call
> your init function just befrore the mainloop call. You gui wil show up
> and you can then update it to show progress as you wish
> No neep for thread or Tix modules...!

Thanks for the great example! I hoped that there would be a simple way 
to show the progress and this is just what I was looking for. 

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


open() and Arabic language

2006-08-13 Thread MaaSTaaR
Hello ...

firstly , sorry for my bad English .

i have problem with open() function when i use it with file which name
in Arabic , the open() will not find the file , and i am sure the file
is exist .


so how i can solve this problem ?

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


Re: open() and Arabic language

2006-08-13 Thread Simon Forman
MaaSTaaR wrote:
> Hello ...
>
> firstly , sorry for my bad English .
>
> i have problem with open() function when i use it with file which name
> in Arabic , the open() will not find the file , and i am sure the file
> is exist .
>
>
> so how i can solve this problem ?

On this page http://www.amk.ca/python/howto/unicode , there is a brief
section near the bottom on "Unicode filenames". If your problem is
related to Unicode, this may help you, but I'm not sure.

HTH,
~Simon

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


Re: yet another noob question

2006-08-13 Thread Stargaming
mike_wilson1333 schrieb:
> I would like to generate every unique combination of numbers 1-5 in a 5
> digit number and follow each combo with a newline.  So i'm looking at
> generating combinations such as: (12345) , (12235), (4) and so on.
> What would be the best way to do this? So, basically i'm looking for a
> list of all combinations of 1-5 in a 5 digit unique number. Also, when
> I send the list to print there can't be any duplicates of the combos.
> 
> 
>   Thanks,
> 
>   Mike
> 

Generally, it is range(1, 5)

Sincerely,
Stargaming
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Simon Forman
mike_wilson1333 wrote:
> I would like to generate every unique combination of numbers 1-5 in a 5
> digit number and follow each combo with a newline.  So i'm looking at
> generating combinations such as: (12345) , (12235), (4) and so on.
> What would be the best way to do this? So, basically i'm looking for a
> list of all combinations of 1-5 in a 5 digit unique number. Also, when
> I send the list to print there can't be any duplicates of the combos.
>
>
>   Thanks,
>
>   Mike

Hi Mike, this is one of those "Somebody must have had this problem
before me" kind of situations. Google on "python combination" and you
should be well rewarded. :-)

Peace,
~Simon

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


Re: yet another noob question

2006-08-13 Thread Rene Pijlman
mike_wilson1333:
>I would like to generate every unique combination of numbers 1-5 in 
>a 5 digit number [...] What would be the best way to do this?

Ask the Java newsgroup to design a clever algorithm and post it here for
pythonification. Ask for the pseudocode, not the Java code.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Rene Pijlman
Stargaming:
>Generally, it is range(1, 5)

Minus all numbers whose decimal string representation matches
[0-9]*[06-9][0-9]* Briljant!

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Stargaming
Stargaming schrieb:
> mike_wilson1333 schrieb:
> 
>> I would like to generate every unique combination of numbers 1-5 in a 5
>> digit number and follow each combo with a newline.  So i'm looking at
>> generating combinations such as: (12345) , (12235), (4) and so on.
>> What would be the best way to do this? So, basically i'm looking for a
>> list of all combinations of 1-5 in a 5 digit unique number. Also, when
>> I send the list to print there can't be any duplicates of the combos.
>>
>>
>>   Thanks,
>>
>>   Mike
>>
> 
> Generally, it is range(1, 5)
> 
> Sincerely,
> Stargaming

Whoops, I'm sorry. I think I was a little bit too enthusiastic and "wow 
look 'print range' is fun!". You could do a list comprehension over the 
range thingy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Simon Forman
Stargaming wrote:
> Stargaming schrieb:
> > mike_wilson1333 schrieb:
> >
> >> I would like to generate every unique combination of numbers 1-5 in a 5
> >> digit number and follow each combo with a newline.  So i'm looking at
> >> generating combinations such as: (12345) , (12235), (4) and so on.
> >> What would be the best way to do this? So, basically i'm looking for a
> >> list of all combinations of 1-5 in a 5 digit unique number. Also, when
> >> I send the list to print there can't be any duplicates of the combos.
> >>
> >>
> >>   Thanks,
> >>
> >>   Mike
> >>
> >
> > Generally, it is range(1, 5)
> >
> > Sincerely,
> > Stargaming
>
> Whoops, I'm sorry. I think I was a little bit too enthusiastic and "wow
> look 'print range' is fun!". You could do a list comprehension over the
> range thingy.


def stoopid_way(start, end):
for n in xrange(start, end + 1):

# Make a string.
s = '%d' % n

# Exclude 0's.
if '0' in s: continue

# Exclude 6-9's.
try:
int(s, 6)
except ValueError:
continue

yield s

Use it like so:

# Get all the strings as a list..
data = list(stoopid_way(1, 5))

# ..or print the strings one-by-one..
for s in stoopid_way(1, 5):
print s

# ..or print one big string, joined by newlines.
print '\n'.join(stoopid_way(1, 5))


I originally meant this as a joke and was going to say not to use it.
But on my old, slow computer it only takes about a second or two.  If
that's fast enough for you then it won't do any harm to use it.  (Just
don't mention my name ;-)  )

Peace,
~Simon

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


Re: Subtyping a non-builtin type in C/C++

2006-08-13 Thread johan2sson
[EMAIL PROTECTED] wrote:

> > > I am trying to create a subclass of a python class, defined in python,
> > > in C++, but I am having some problems.

Note to future news group archeologists:

I have since learned that that's because it "can't be done", in the
sense that there's no defined way that is supposed to work. Of course
it could probably be done by reverse engineering what is done by the
interpreter and then applying the same steps manually, but it would be
a real hack.

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


NNTPLIB STRANGE ERROR

2006-08-13 Thread 2Good4You-Veki(Cro)
HI,
when I want use python nntplib:

>>> import nntplib
>>> s=nntplib.NNTP('news.t-com.hr')
>>> s.group('hr.mag.bug')

THEN ERROR IS:

Traceback (most recent call last):
  File "", line 1, in -toplevel-
s.group('hr.mag.bug')
  File "C:\Python24\lib\nntplib.py", line 346, in group
resp = self.shortcmd('GROUP ' + name)
  File "C:\Python24\lib\nntplib.py", line 260, in shortcmd
return self.getresp()
  File "C:\Python24\lib\nntplib.py", line 215, in getresp
resp = self.getline()
  File "C:\Python24\lib\nntplib.py", line 204, in getline
line = self.file.readline()
  File "C:\Python24\lib\socket.py", line 340, in readline
data = self._sock.recv(self._rbufsize)
error: (10053, 'Software caused connection abort')

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


Re: yet another noob question

2006-08-13 Thread Alex Martelli
mike_wilson1333 <[EMAIL PROTECTED]> wrote:

> I would like to generate every unique combination of numbers 1-5 in a 5
> digit number and follow each combo with a newline.  So i'm looking at
> generating combinations such as: (12345) , (12235), (4) and so on.
> What would be the best way to do this? So, basically i'm looking for a
> list of all combinations of 1-5 in a 5 digit unique number. Also, when
> I send the list to print there can't be any duplicates of the combos.

[[warning: haven't tried out any of the following code, just typed it
into the newsreader, so there may be typos or whatnot, but, I'm focusing
on communicating the general ideas anyway:-)]]


A working but boilerplatey solution is to nest 5 loops...:

r = range(1, 6)
for i0 in r:
  for i1 in r:
for i2 in r:
  for i3 in r:
for i4 in r:
  print '(%d%d%d%d%d)' % (i0,i1,i2,i3,i4)

While this does work, it's inelegant -- "flat is better than nested",
and all that.  Hard-coding the exact number of nested loops, etc, is
definitely not ideal.

So here's an alternative:

def allcomb(seq=range(1, 6), reps=5):
counter = reps*[0]
format = '(' + '%s'*reps + ')'
maxcount = len(seq)-1
while True:
print format % tuple(seq[i] for i in counter)
i = 0
while i= reps: return
counter[i] += 1

You can have many variations on this theme, but basically what they're
doing is "counting in base N" (where N is len(seq)) -- variations around
that are mere stylistic issues.  For example, the inner loop (after the
print statement) could become:
for i in range(reps):
if counter[i] < maxcount:
counter[i] += 1
break
else:
counter[i] = 0
else:
return
or, you could loop with "for i, c in enumerate(counter):", etc, etc --
but these variations are all implementing the same algorithm. One
algorithms that's definitely different enough to distinguish is to use
recursion -- but it won't offer much advantage over this one.


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


Py_Initialize crashes with winpdb

2006-08-13 Thread eastier
Hi all,

I've an application with embedded python.

In order to reload the python scripts, I end the python session, and
reopen one just after :

<...release used modules...>
Py_Finalize();

Py_Initialize();
<...Acquire relevant modules...>

In order to debug the python script, I recently tried winPdb, which is
pretty decent for a free debugger working with embedded python.
So I just have :
import rpdb2;
rpdb2.start_embedded_debugger("toto", True)
in my python script

But when I use it, the Py_Finalize / Py_initialize sequence crashes in
py_initialize.

I didn't have Python sources to have more complete informations, but
perhaps some one knows about this problem, and what I can do to avoid
this ?

When using a custom debugger, and a custom Trace function, is there
something particular to do when Finalizing Python ?

Any help really welcomed, 

Emmanuel

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


Re: Kill process based on window name (win32)

2006-08-13 Thread Roger Upole
Trying to do this for different sessions is going to be much more
complicated. Each terminal service session has its own
window station, and there may be more than one desktop per
window station. You'll need several functions from the win32service
module for accessing window stations and desktops,
and the win32ts module (which was just added in Pywin32 build 209)
for terminal services functions.

As a start:
win32ts.WTSEnumerateSessions to list the sessions
win32ts.WTSQuerySessionInformation to get the username and window
station name for the session
win32service.OpenWindowStation
EnumDesktops to get a list of all desktops in the window station
win32service.OpenDesktop to access each desktop
EnumDesktopWindows to get handles to all windows on the desktop

You might be better off to use win32ts.WTSLogoffSession to kill the session
altogether.

Roger


"drodrig" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>I am running the program mentioned below as an NT service on a terminal
> server. The service listens on a UDP port for any of a series of
> commands. In this case, the command "closeApps " will notify the
> service to close all the open apps for user (). So while the code
> below works great for a standalone app, it fails as a service because
> the window handles of each user are not retrievable (I should say I
> don't know how to retrieve them). Is this even possible? I looked at
> some of the Windows API calls but nothing stuck out.
>
> Suggestions?
>
> drodrig wrote:
>> Thank you Roger. Your advice did the trick. For anyone interested, the
>> basic code to terminate a process (politely) would be something like
>> this (hwnd is retrieved using win32gui.EnumerateWindows):
>>
>> # Get the window's process id's
>> t, p = win32process.GetWindowThreadProcessId(hwnd)
>> # Ask window nicely to close
>> win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
>> # Allow some time for app to close
>> time.sleep(10)
>> # If app didn't close, force close
>> try:
>> handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, p)
>> if handle:
>> win32api.TerminateProcess(handle,0)
>> win32api.CloseHandle(handle)
>> except:
>> pass:
>>
>> Roger Upole wrote:
>> > drodrig wrote:
>> > > Hi.
>> > >
>> > > I am trying to close/kill all processes that show visible windows on
>> > > Windows XP. So far I've created a script that uses win32gui.EnumWindows
>> > > to iterate through all windows, check for which windows are visible,
>> > > then send a WM_CLOSE message to the window to request that it closes.
>> > > Of course, not all apps want to close nicely. At this point I need to
>> > > use something like TerminateProcess to kill the app, but how do I find
>> > > the process id (hopefully based on the window id).
>> > >
>> > > Thanks for any help.
>> > >
>> >
>> > win32process.GetWindowThreadProcessId should do the trick.
>> >
>> >Roger
> 


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


Re: yet another noob question

2006-08-13 Thread bearophileHUGS
Simon Forman:
> I originally meant this as a joke and was going to say not to use it.
> But on my old, slow computer it only takes about a second or two.

Another possibility, still using a filter:

nodig = set("06789")
r = [i for i in xrange(1, 5+1) if not (set(`i`) & nodig)]

Bye,
bearophile

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


looking for a simple way to load a program from another python program..

2006-08-13 Thread [EMAIL PROTECTED]
I was looking for a simple way to load a simple python program from
another python program.

I tried

os.system(cabel)

The file name is cabel.py a csound instrument editor..

The error I am getting is

Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\boa-constructor\test of
snake\Frame1.py", line 212, in OnCabelItems0Menu
os.system(cabel)
NameError: global name 'cabel' is not defined
Localisation of messages is disabled, using default language.
time resolution is 279.365 ns

This is with cabel in the current directory.  I have managed to use
import to run it but it will only do it once.  I may be able to use the
exec commands but I don't want to exit the program I am using only to
run other programs and then exit.  I would also perfer that cabel is in
it's own directory.

thanks in advance for any help

http://www.stormpages.com/edexter/csound.html

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


Re: open() and Arabic language

2006-08-13 Thread Butternut Squash
MaaSTaaR wrote:

> Hello ...
> 
> firstly , sorry for my bad English .
> 
> i have problem with open() function when i use it with file which name
> in Arabic , the open() will not find the file , and i am sure the file
> is exist .
> 
> 
> so how i can solve this problem ?

probably a unicode problem. Good luck.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Paul Rubin
"mike_wilson1333" <[EMAIL PROTECTED]> writes:
> I would like to generate every unique combination of numbers 1-5 in a 5
> digit number and follow each combo with a newline.  So i'm looking at
> generating combinations such as: (12345) , (12235), (4) and so on.
> What would be the best way to do this? So, basically i'm looking for a
> list of all combinations of 1-5 in a 5 digit unique number. Also, when
> I send the list to print there can't be any duplicates of the combos.

Basically you want to print a list of integers in 5-digit base-5
notation, except relabelling the digits.  There will be (5**5 - 1)
numbers in the list.  You want to print 0 as '1', 1 as '2',
etc.  Here's one way to get the representation.  It's sort of a
"functional" approach using recursion, but feels natural if you're
into that sort of thing:

def base5x(k, ndigits):
if ndigits == 1: return '%d'% (k+1)
return base5x(k//5, ndigits-1) + base5x(k%5, 1)

Now you can use the function to print the list you wanted:

for i in xrange(1234,1333):
   print base5x(i, 5)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Paul Rubin
Paul Rubin  writes:
> Now you can use the function to print the list you wanted:
> 
> for i in xrange(1234,1333):
>print base5x(i, 5)


Whoops, pasted the wrong thing from my test window.  Sorry.  That
was supposed to say:

 for i in xrange(5**5):
print base5x(i, 5)
-- 
http://mail.python.org/mailman/listinfo/python-list


Compiling wxPython app for Windows; Single EXE

2006-08-13 Thread Vincent Delporte
Hi

I browsed the archives, but since some messages date back a bit, I
wanted to make sure that

- py2exe is still the best tool in town to compile Python scripts to
run on a Windows host that doesn't have Python installed, including
wxWidgets/wxPython

- there's no way to build a single EXE, to make deployment easier (if
multiple files, I need to build an installer with eg. NSIS or
InnoSetup)?

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


Re: John Salerno

2006-08-13 Thread Bretts

Alan Connor wrote:
> On alt.os.linux, in <[EMAIL PROTECTED]>, "jason" wrote:
> > Path: 
> > text.usenetserver.com!atl-c01.usenetserver.com!news.usenetserver.com!atl-c05.usenetserver.com!news.usenetserver.com!postnews.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!4.24.21.153!newsfeed3.dallas1.level3.net!news.level3.com!newsfeed1.easynews.com!easynews.com!easynews!easynews-local!fe12.news.easynews.com.POSTED!not-for-mail
> > From: jason <[EMAIL PROTECTED]>
> > User-Agent: Debian Thunderbird 1.0.2 (X11/20060724)
> > X-Accept-Language: en-us, en
> > MIME-Version: 1.0
> > Newsgroups: alt.os.linux,comp.editors,comp.lang.python
> > Subject: Re: [OT] John Salerno
> > References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
> > In-Reply-To: <[EMAIL PROTECTED]>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> > Content-Transfer-Encoding: 7bit
> > Lines: 16
> > Message-ID: <[EMAIL PROTECTED]>
> > X-Complaints-To: [EMAIL PROTECTED]
> > Organization: EasyNews, UseNet made Easy!
> > X-Complaints-Info: Please be sure to forward a copy of ALL headers 
> > otherwise we will be unable to process your complaint properly.
> > Date: Sun, 13 Aug 2006 03:11:58 GMT
> > Xref: usenetserver.com alt.os.linux:422390 comp.editors:161251 
> > comp.lang.python:548515
> > X-Received-Date: Sat, 12 Aug 2006 23:11:58 EDT (text.usenetserver.com)
>
>  http://slrn.sourceforge.net/docs/README.offline>
>
> Posting through easynews. Let's see who else posts through
> easynews on the groups I am subscribed to:
>
> #From: "Ciaran Keating" <[EMAIL PROTECTED]>
> #From: "Clayton Sutton" <[EMAIL PROTECTED]>
> #From: "DanielP" <[EMAIL PROTECTED]>
> #From: "Snoopy :-))" <[EMAIL PROTECTED]>
> #From: "smtjs" <[EMAIL PROTECTED]>
> #From: <[EMAIL PROTECTED]>
> #From: "Ciaran Keating" <[EMAIL PROTECTED]>
> #From: "Clayton Sutton" <[EMAIL PROTECTED]>
> #From: "DanielP" <[EMAIL PROTECTED]>
> #From: "Snoopy :-))" <[EMAIL PROTECTED]>
> #From: "William B. Cattell" <[EMAIL PROTECTED]>
> #From: <[EMAIL PROTECTED]>
> #From: "Ciaran Keating" <[EMAIL PROTECTED]>
> #From: "Clayton Sutton" <[EMAIL PROTECTED]>
> #From: "DanielP" <[EMAIL PROTECTED]>
> #From: "Snoopy :-))" <[EMAIL PROTECTED]>
> #From: "William B. Cattell" <[EMAIL PROTECTED]>
> #From: <[EMAIL PROTECTED]>
> #From: Alan Connor <[EMAIL PROTECTED]>
>
> A troll forging my name. I only post through Earthlink.
>
> #From: Andrew Schulman <[EMAIL PROTECTED]>
> #From: Aratzio <[EMAIL PROTECTED]>
> #From: Bosco Pelone <[EMAIL PROTECTED]>
> #From: Bretts Christ <[EMAIL PROTECTED]>
> #From: Bretts of God <[EMAIL PROTECTED]>
> #From: Bretts of The Apocalypse <[EMAIL PROTECTED]>
> #From: Cam <[EMAIL PROTECTED]>
> #From: Derek Munsley <[EMAIL PROTECTED]>
> #From: Elo Magar <[EMAIL PROTECTED]>
> #From: Gospel Bretts <[EMAIL PROTECTED]>
> #From: Gospel Bretts <[EMAIL PROTECTED]>
> #From: Hallelujah Bretts <[EMAIL PROTECTED]>
> #From: Hallelujah Bretts <[EMAIL PROTECTED]>
> #From: Holy Brett McCoy <[EMAIL PROTECTED]>
> #From: Holy Bretts <[EMAIL PROTECTED]>
> #From: Jason <[EMAIL PROTECTED]>
> #From: John <[EMAIL PROTECTED]>
> #From: John Blake <[EMAIL PROTECTED]>
> #From: Mark Healey <[EMAIL PROTECTED]>
> #From: Mark Healey <[EMAIL PROTECTED]>
> #From: McBretts of God <[EMAIL PROTECTED]>
> #From: Mike Coddington <[EMAIL PROTECTED]>
> #From: Paul Colquhoun <[EMAIL PROTECTED]>
> #From: Realto Margarino <[EMAIL PROTECTED]>
> #From: River <[EMAIL PROTECTED]>
> #From: SINNER <[EMAIL PROTECTED]>
> #From: The Apostle Bretts <[EMAIL PROTECTED]>
> #From: The Beloved Disciple Bretts <[EMAIL PROTECTED]>
> #From: The Holy Apostle <[EMAIL PROTECTED]>
> #From: The Holy Trinity of Bretts <[EMAIL PROTECTED]>
> #From: The Reverend Doctor Bretts <[EMAIL PROTECTED]>
> #From: To Garo <[EMAIL PROTECTED]>
> #From: Uni <[EMAIL PROTECTED]>
> #From: Wes Gray <[EMAIL PROTECTED]>
> #From: WhyMe <[EMAIL PROTECTED]>
> #From: ea aro <[EMAIL PROTECTED]>
> #From: jason <[EMAIL PROTECTED]>
> #From: le seigneur des rateaux <[EMAIL PROTECTED]>
> #From: lordy <[EMAIL PROTECTED]>
> #From: [EMAIL PROTECTED] (beginner_girl)
>
> Looks like pretty much all trolls to me.
>
> Note: I won't be downloading any articles on this thread.
>
> Alan

Mr. Connor,

I applaud your efforts to nail down anonymous trolls, and please feel
free to continue labelling me as one of them if you insist, but my full
name and location are in the usenet archives. My posts are almost
exclusively confined to alt.atheism and alt.politics.homosexuality (and
cross-posts initiated by others), and all of my nicks contain the word
"Bretts", which is a derivative of my real first name "Brett". Further,
I'm willing to meet in real life anyone here who wants to meet me and
I've already offered to do so several times. If you'd like to meet me,
just drop me an email and we can make arrangements.

(That said, I have occassionally trolled as a stupid obnoxious
christian cretin, but mostly just for the purpose of parody

selecting base class from user input

2006-08-13 Thread Jackson
I want a class that will determine its base class by the argument passed
in.  What I am about to write _does_not_work_, but it shows what I am
trying to do.

class ABC(some_super):
def __init__(self,some_super):
some_super.__init__(self)

if some_super == list:
   self.append('ABC')

elif some_super == dict:
   self['ABC'] = None


Then, the user can call this function:

>>> example = ABC(list)
>>> print example
['ABC']

>>> example = ABC(dict)
>>> print example
{'ABC': None}

Clearly, this is a bad example, but the central idea is what I am trying
to do.  ABC is a particular example which can be represented in various
forms.  I want an ABC class that will create the example in the form
specified by the user.

So how can I achieve this? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling wxPython app for Windows; Single EXE

2006-08-13 Thread Tim N. van der Leeuw

Vincent Delporte wrote:
> Hi
>
> I browsed the archives, but since some messages date back a bit, I
> wanted to make sure that
>
> - py2exe is still the best tool in town to compile Python scripts to
> run on a Windows host that doesn't have Python installed, including
> wxWidgets/wxPython
>
> - there's no way to build a single EXE, to make deployment easier (if
> multiple files, I need to build an installer with eg. NSIS or
> InnoSetup)?
>
> Thank you.

Hi,

I have a wxPython app, which I compile into one EXE file. Then there's
just 1 support file needed: a MS DLL (which, once distributed, you will
not need to update).
Oh, and for w9x support there's an extra file, popenw9x.exe (or
something like that) which you can probably forget about if you don't
wish to support that.

Well, OK, that makes 3 files... Icons for windows are extra too, and
any other setup/ini/datafiles you wish to add and that are opened as
'normal' files too.

So what I do then is bundle it up as an self-extracting-archives, using
7-zip, which by default extracts into a sub-directory of the directory
where you copy the SEA-exe.

Voila, simple and easy, no installer required.

Works for me; dunno if it's good enough for your needs as well. (Oh,
and creating the SEA-exe you can probably automate if from the setup.py
but I haven't bothered yet)

Cheers and good luck,

--Tim

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


Re: looking for a simple way to load a program from another python program..

2006-08-13 Thread Simon Forman
[EMAIL PROTECTED] wrote:
> I was looking for a simple way to load a simple python program from
> another python program.
>
> I tried
>
> os.system(cabel)
>
> The file name is cabel.py a csound instrument editor..
>
> The error I am getting is
>
> Traceback (most recent call last):
>   File "C:\Python24\Lib\site-packages\boa-constructor\test of
> snake\Frame1.py", line 212, in OnCabelItems0Menu
> os.system(cabel)
> NameError: global name 'cabel' is not defined
> Localisation of messages is disabled, using default language.
> time resolution is 279.365 ns
>
> This is with cabel in the current directory.  I have managed to use
> import to run it but it will only do it once.  I may be able to use the
> exec commands but I don't want to exit the program I am using only to
> run other programs and then exit.  I would also perfer that cabel is in
> it's own directory.
>
> thanks in advance for any help
>
> http://www.stormpages.com/edexter/csound.html

Read the docs: os.system() takes a string. You're calling it with an
uninitialized variable name. Unless you have something like "cabel =
'cabel'" somewhere before your call os.system() you can expect that
error.

"import cabel" will only work once because python's module import
mechanism caches imported modules to save time when a script imports
them more than once.  To force the module to be reloaded use the reload
function: "reload(cabel)"

os.system() docs: http://docs.python.org/lib/os-process.html#l2h-1692
(But see the subprocess module too:
http://docs.python.org/lib/module-subprocess.html)

Peace,
~Simon

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


Re: looking for a simple way to load a program from another python program..

2006-08-13 Thread Caleb Hattingh
Hi Eric

Check that ".py" and ".pyw" are in your PATHEXT environment variable
(are you using Windows?).   Then, if the folder that cabel is in is in
your PATH environment variable, and the correct association for .py
files is set up (i.e. they get run by python.exe),

either
os.system('cabel')
or
os.system('cabel.py')

should work.

Alternatively, you could not do any of those things, and run

os.system('python cabel.py')

with 'cabel.py' in the same folder as the parent script, and that
should work too, assuming that the path to your python executable is on
the PATH environment variable.

If you run other commands from python quite frequently, it is probably
a good idea to look into the "os.popen" set of commands, for more
flexibilty.

Caleb

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


Re: yet another noob question

2006-08-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Alex Martelli <[EMAIL PROTECTED]> wrote:
>mike_wilson1333 <[EMAIL PROTECTED]> wrote:
>
>> I would like to generate every unique combination of numbers 1-5 in a 5
>> digit number and follow each combo with a newline.  So i'm looking at
.
.
.
>but these variations are all implementing the same algorithm. One
>algorithms that's definitely different enough to distinguish is to use
>recursion -- but it won't offer much advantage over this one.
>
>
>Alex

For light reading on still other enumerations and their algorithms,
see http://www.unixreview.com/documents/s=10089/ur0606j/ >.
-- 
http://mail.python.org/mailman/listinfo/python-list


outputting a command to the terminal?

2006-08-13 Thread John Salerno
Here's my new project: I want to write a little script that I can type 
at the terminal like this:

$ scriptname package1 [package2, ...]

where scriptname is my module name and any subsequent arguments are the 
names of Linux packages to install. Running the script as above will 
create this line:

sudo aptitude install package1 package2 ...

It will run that line at the terminal so the package(s) will be installed.

Now, the extra functionality I want to add (otherwise I would just 
install them normally!) is to save the package names to a text file so I 
can now the names of programs I've manually installed, if I ever want to 
check the list or remove packages.

So creating the proper bash command (sudo aptitude install ...) is easy, 
and writing the names to a file is easy. But I have two questions:

1. First of all, does Linux keep track of the packages you manually 
install? If so, then I won't have to do this at all.

2. Assuming I write this, how do output the bash command to the 
terminal? Is there a particular module that Python uses to interact with 
the terminal window that I can use to send the install command to the 
terminal?

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


Re: seeking the "Hello World" of Packages

2006-08-13 Thread dwhall
Kevin,

I just posted a small package to the python package index.  It has one
source file of interest and some unit tests.The remaining files are
either needed for or made by distutils.  Should be pretty easy to
follow if you've read the distutils docs.  Note that the package you
get does not have the MANIFEST.in file (the tool creates MANIFEST
automatically using info from MANIFEST.in).

http://cheeseshop.python.org/pypi/pycscope/0.2

share and enjoy,

!!Dean

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


Re: outputting a command to the terminal?

2006-08-13 Thread Diez B. Roggisch
John Salerno schrieb:
> Here's my new project: I want to write a little script that I can type 
> at the terminal like this:
> 
> $ scriptname package1 [package2, ...]
> 
> where scriptname is my module name and any subsequent arguments are the 
> names of Linux packages to install. Running the script as above will 
> create this line:
> 
> sudo aptitude install package1 package2 ...
> 
> It will run that line at the terminal so the package(s) will be installed.
> 
> Now, the extra functionality I want to add (otherwise I would just 
> install them normally!) is to save the package names to a text file so I 
> can now the names of programs I've manually installed, if I ever want to 
> check the list or remove packages.
> 
> So creating the proper bash command (sudo aptitude install ...) is easy, 
> and writing the names to a file is easy. But I have two questions:
> 
> 1. First of all, does Linux keep track of the packages you manually 
> install? If so, then I won't have to do this at all.
> 
> 2. Assuming I write this, how do output the bash command to the 
> terminal? Is there a particular module that Python uses to interact with 
> the terminal window that I can use to send the install command to the 
> terminal?


You don't put a command to the terminal. The shell executes commands. 
But it is mainly just a program itself - it can spawn subprocesses and 
make these execute the actual commands. so - the module you need is most 
probably subprocess.

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


Re: [OT] John Salerno

2006-08-13 Thread Joe Feise
John Salerno wrote on 08/12/06 21:44:

> Alan Connor wrote:
> 
>> So. You post using three different newsservers, which no one who
>> posts under the same alias all the time does.
>>
>> And there are virtually no Linux groups in your posting history 
>> for the last year.
> 
> Wow, you need some help. I post at work on one server, and then also at 
> home on another (and sometimes two), on both Windows and Linux, which I 
> just installed last Saturday and am currently exploring for the first time.
> 
> If that isn't enough to convince you, then *you* are the troll.


Please killfile AC. He is a known net-kook.

 .:\:/:.
 +---+ .:\:\:/:/:.
 |   PLEASE DO NOT   |:.:\:\:/:/:.:
 |  FEED THE TROLLS  |   :=.' -   - '.=:
 |   |   '=(\ 9   9 /)='
 |   Thank you,  |  (  (_)  )
 |   Management  |  /`-vvv-'\
 +---+ / \
 |  |@@@  / /|,|\ \
 |  |@@@ /_//  /^\  \\_\
   @x@@x@|  | |/ WW(  (   )  )WW
   \/|  |\|   __\,,\ /,,/__
\||/ |  | |  jgs (__Y__)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==

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


Re: outputting a command to the terminal?

2006-08-13 Thread Yu-Xi Lim
John Salerno wrote:
> 1. First of all, does Linux keep track of the packages you manually 
> install? If so, then I won't have to do this at all.

I assume you're using a Debian-based distro with aptitude as the front 
end. In which case, all dpkg operations should be logged in 
/var/log/dpkg.log

Generally, after the initial installation, all subsequent operations are 
either updates of existing packages or packages you installed manually. 
Only rarely do you get new packages installed automatically as a result 
of an additional dependency from an original automatically installed 
package.

If you know when you completed your initial installation, you can easily 
parse the log files to determine what else was installed after that.

> 2. Assuming I write this, how do output the bash command to the 
> terminal? Is there a particular module that Python uses to interact with 
> the terminal window that I can use to send the install command to the 
> terminal?

I'm wondering about the need to "output the bash command to the 
terminal". It would probably suffice if your Python script just spawned 
an instance of the shell with the necessary command line. Take a look at 
the subprocess module.

But this really calls for a bash script:

#!/bin/bash
echo $@ >> /path/to/manual_install.log
sudo aptitude install $@


Shorter than the equivalent Python code. You could probably declare this 
as a function in your bash initialization files too, if you know how to 
do this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a simple way to load a program from another python program..

2006-08-13 Thread [EMAIL PROTECTED]

Caleb Hattingh wrote:
> Hi Eric
>
> Check that ".py" and ".pyw" are in your PATHEXT environment variable
> (are you using Windows?).   Then, if the folder that cabel is in is in
> your PATH environment variable, and the correct association for .py
> files is set up (i.e. they get run by python.exe),
>
> either
> os.system('cabel')
> or
> os.system('cabel.py')
>
> should work.
>
> Alternatively, you could not do any of those things, and run
>
> os.system('python cabel.py')
>
> with 'cabel.py' in the same folder as the parent script, and that
> should work too, assuming that the path to your python executable is on
> the PATH environment variable.
>
> If you run other commands from python quite frequently, it is probably
> a good idea to look into the "os.popen" set of commands, for more
> flexibilty.
>
> Caleb

import cabel and reload(cabel) seem to work fine.  I am not sure why I
am having trouble with os.system .  Tells me it isn't a command.
thanks for the help, I will look into os.popen to see what it does.
would there be ay

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


Re: looking for a simple way to load a program from another python program..

2006-08-13 Thread [EMAIL PROTECTED]

Caleb Hattingh wrote:
> Hi Eric
>
> Check that ".py" and ".pyw" are in your PATHEXT environment variable
> (are you using Windows?).   Then, if the folder that cabel is in is in
> your PATH environment variable, and the correct association for .py
> files is set up (i.e. they get run by python.exe),
>
> either
> os.system('cabel')
> or
> os.system('cabel.py')
>
> should work.
>
> Alternatively, you could not do any of those things, and run
>
> os.system('python cabel.py')
>
> with 'cabel.py' in the same folder as the parent script, and that
> should work too, assuming that the path to your python executable is on
> the PATH environment variable.
>
> If you run other commands from python quite frequently, it is probably
> a good idea to look into the "os.popen" set of commands, for more
> flexibilty.
>
> Caleb

import cabel and reload(cabel) seem to work fine.  I am not sure why I
am having trouble with os.system, probily something to do with the
path.  Is one better than the other when it comes to distributing
software??  Thanks for the help.  Hopefully this message I get isn't
anything important..  (I will have to look into os.popen later.

Localisation of messages is disabled, using default language.
time resolution is 279.365 ns

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


Re: Compiling wxPython app for Windows; Single EXE

2006-08-13 Thread Vincent Delporte
On 13 Aug 2006 13:46:14 -0700, "Tim N. van der Leeuw"
<[EMAIL PROTECTED]> wrote:
>I have a wxPython app, which I compile into one EXE file. Then there's
>just 1 support file needed: a MS DLL (which, once distributed, you will
>not need to update).

OK. So you compile the Python app into an EXE using py2exe, and then
use eg. 7Zip to combine all the files into a single EXE, that
1. uncompresses itself in the directory validated by the user
2. when done, runs the Python EXE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a simple way to load a program from another python program..

2006-08-13 Thread Luis M. González
Try this:

import os
os.startfile('cabel.py')

This should work with any program or file, not only python ones.

Hope this helps,
Luis

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


Nested if and expected an indent block

2006-08-13 Thread [EMAIL PROTECTED]
Greetings:

I'm brand new to Python and decided to write a syllogism solver for a
class I'm taking. At the start of the program, I define a function that
classifies the type of each statement in the syllogism. Python tells me
that it is expecting an indented block at the s in "some". I can see
what I'm doing wrong. Here's the code:

def class_stmt(q,c):
"""
This function classifies a statement according to the rules of
categorical syllogisms and returns A, E, I, O to identify the
statement type.
"""
if q.lower() == "all":
if "not" in c:
stmt_type = "E"
else:
stmt_type = "A"
elif q.lower() == "some"# s in some is highlighted
if "not" in c:
stmt_type = "O"
else:
stmt_type = "I"
elif q.lower() == "no":
if "not" in c:
stmt_type = "A"
else:
stmt_type = "E"
else:
if "not" in c:
stmt_type = "E"
else:
stmt_type = "A"

return stmt_type

Any ideas? Thanks in advance.

Keith

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


Re: yet another noob question

2006-08-13 Thread [EMAIL PROTECTED]

Sybren Stuvel wrote:
> mike_wilson1333 enlightened us with:
> > I would like to generate every unique combination of numbers 1-5 in a 5
> > digit number and follow each combo with a newline.  So i'm looking at
> > generating combinations such as: (12345) , (12235), (4) and so on.
>
> Count from 0 to 4 in a base-5 numbering, and add 1 to every
> number.
>
> b5_1 = int('1', 5)
>
> for i in range(int('4', 5)+1):
> i += b5_1
> print i
>
> Only the print command needs to convert back to base-5. Does anyone
> know of an elegant way to do that?

Use the gmpy module which does base conversion in both directions.

>>> import gmpy
>>> b5_1 = gmpy.mpz('1',5)
>>> b5_1
mpz(781)
>>> print gmpy.digits(b5_1,5)
1


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

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


Re: Nested if and expected an indent block

2006-08-13 Thread Tim Williams
On 13 Aug 2006 16:28:45 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Greetings:
>
> I'm brand new to Python and decided to write a syllogism solver for a
> class I'm taking. At the start of the program, I define a function that
> classifies the type of each statement in the syllogism. Python tells me
> that it is expecting an indented block at the s in "some". I can see
> what I'm doing wrong. Here's the code:
>
> def class_stmt(q,c):
> """
> This function classifies a statement according to the rules of
> categorical syllogisms and returns A, E, I, O to identify the
> statement type.
> """
> if q.lower() == "all":
> if "not" in c:
> stmt_type = "E"
> else:
> stmt_type = "A"
> elif q.lower() == "some"# s in some is highlighted
> if "not" in c:
> stmt_type = "O"
> else:
> stmt_type = "I"

It might be the missing colon after "some"

If that's a typo on your email rather than in your script you should
post the full traceback of the error.

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


Re: Nested if and expected an indent block

2006-08-13 Thread alisonken1

[EMAIL PROTECTED] wrote:
> Greetings:


> elif q.lower() == "some"# s in some is highlighted

> Any ideas? Thanks in advance.
>
> Keith

Would the missing colon have something to do with it?

> elif q.lower() == "some":

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


Re: open() and Arabic language

2006-08-13 Thread John Machin
MaaSTaaR wrote:
> Hello ...
>
> firstly , sorry for my bad English .
>
> i have problem with open() function when i use it with file which name
> in Arabic , the open() will not find the file , and i am sure the file
> is exist .
>
>
> so how i can solve this problem ?

Provide more information --  a major factor is which operating system
[my crystal ball says  that you are using Linux but it could be wrong].
Also an actual test case with a short file name. Here's an example with
a part-Chinese filename on a Windows machine, which just uses the
information in the Unicode HOWTO that you were pointed at by another
poster:

C:\junk\unicode_name>dir
[snip]
30/05/2006  09:25 AM17 ??.txt
[snip]

# only 1 file in the directory; dir command mangles the displayed name

C:\junk\unicode_name>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
|>>> import os
|>>> os.listdir('.')
['??.txt']
|>>> os.listdir(u'.')
[u'\u5f20\u654f.txt']

# filename is kept in Unicode, so we can open it that way

|>>> f = open(u'\u5f20\u654f.txt')
|>>> f.read()
'yadda yadda yadda'
# success

|>>> import sys
|>>> sys.getfilesystemencoding()
'mbcs'

... I'm guessing that you will find that you have to encode the
filename in utf-8 then feed it to the open() function.

If you still have a problem, come back with exact (copy/paste) results
of both os.listdir() [the '.' and the u'.'], the
sys.getfilesystemencoding(), and your failed open() attempt.

Hope this helps,
John

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


Re: Nested if and expected an indent block

2006-08-13 Thread [EMAIL PROTECTED]

alisonken1 wrote:
> [EMAIL PROTECTED] wrote:
> > Greetings:
>
> 
> > elif q.lower() == "some"# s in some is highlighted
> 
> > Any ideas? Thanks in advance.
> >
> > Keith
>
> Would the missing colon have something to do with it?
>
> > elif q.lower() == "some":

Thanks for the replies:

I'm sorry, the colon is there in the original, I accidentally blew it
off when I added the comment. The only information I get from IDLE is a
dialog box that says:

Syntax Error
There's an error in your program:
expected an indented block

Keith

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


Re: yet another noob question

2006-08-13 Thread Jason Nordwick
def pr(x): print(x)

>>> x=map(pr,[x for x in xrange(11,56) if '1'<=min(str(x)) and 
>>> max(str(x))<='5'])
11
12
13
14
15
21
22
23
24
25
31
32
33
34
35
41
42
43
44
45
51
52
53
54
55


mike_wilson1333 wrote:
> I would like to generate every unique combination of numbers 1-5 in a 5
> digit number and follow each combo with a newline.  So i'm looking at
> generating combinations such as: (12345) , (12235), (4) and so on.
> What would be the best way to do this? So, basically i'm looking for a
> list of all combinations of 1-5 in a 5 digit unique number. Also, when
> I send the list to print there can't be any duplicates of the combos.
> 
> 
>   Thanks,
> 
>   Mike
> 

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


Re: outputting a command to the terminal?

2006-08-13 Thread John Salerno
Yu-Xi Lim wrote:

> I assume you're using a Debian-based distro with aptitude as the front 
> end. In which case, all dpkg operations should be logged in 
> /var/log/dpkg.log

Yes, I'm using Ubuntu. But I checked this log file and I'm a bit 
confused. It has a lot of listings for 5-31-06, but I didn't even 
install Linux until last Saturday. The next date after 5-31 is 8-5-06, 
and I know I installed things between last Saturday and Aug. 5.

(But this is OT, so don't worry about it.)

> I'm wondering about the need to "output the bash command to the 
> terminal". It would probably suffice if your Python script just spawned 
> an instance of the shell with the necessary command line. Take a look at 
> the subprocess module.
> 
> But this really calls for a bash script:
> 
> #!/bin/bash
> echo $@ >> /path/to/manual_install.log
> sudo aptitude install $@
> 
> 
> Shorter than the equivalent Python code. You could probably declare this 
> as a function in your bash initialization files too, if you know how to 
> do this.

Hmm, interesting. I figured I could do this with a bash script, but I 
don't know bash at all and I'm trying to stick with Python. I don't 
quite understand your bash script (not familiar with the $@ syntax).

I think I'll take a look at the subprocess module, just for fun. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Jason Nordwick
Or without filter:

from operator import add
def pr(x): print x
def cross(x,y): return reduce(add, [[a+b for b in y] for a in x])
x=map(pr, reduce(cross, [map(str,range(1,6))]*5))



mike_wilson1333 wrote:
> I would like to generate every unique combination of numbers 1-5 in a 5
> digit number and follow each combo with a newline.  So i'm looking at
> generating combinations such as: (12345) , (12235), (4) and so on.
> What would be the best way to do this? So, basically i'm looking for a
> list of all combinations of 1-5 in a 5 digit unique number. Also, when
> I send the list to print there can't be any duplicates of the combos.
> 
> 
>   Thanks,
> 
>   Mike
> 

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


Re: yet another noob question

2006-08-13 Thread Jason Nordwick
better (sorry, still learning Python):

def cross(x,y): return [a+b for a in x for y in b]

Jason Nordwick wrote:
> Or without filter:
> 
> from operator import add
> def pr(x): print x
> def cross(x,y): return reduce(add, [[a+b for b in y] for a in x])
> x=map(pr, reduce(cross, [map(str,range(1,6))]*5))
> 
> 
> 
> mike_wilson1333 wrote:
>> I would like to generate every unique combination of numbers 1-5 in a 5
>> digit number and follow each combo with a newline.  So i'm looking at
>> generating combinations such as: (12345) , (12235), (4) and so on.
>> What would be the best way to do this? So, basically i'm looking for a
>> list of all combinations of 1-5 in a 5 digit unique number. Also, when
>> I send the list to print there can't be any duplicates of the combos.
>>
>>
>>   Thanks,
>>
>>   Mike
>>
> 

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


Re: Nested if and expected an indent block

2006-08-13 Thread Dustan
> Thanks for the replies:
>
> I'm sorry, the colon is there in the original, I accidentally blew it
> off when I added the comment. The only information I get from IDLE is a
> dialog box that says:
>
> Syntax Error
> There's an error in your program:
> expected an indented block
>
> Keith

To see the full traceback, assuming you're using windows, you need to
run it on the Command prompt.

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


Re: NNTPLIB STRANGE ERROR

2006-08-13 Thread Bryan Olson
2Good4You-Veki(Cro) wrote:

> when I want use python nntplib:
[...]
> error: (10053, 'Software caused connection abort')

That's not such a strange error; various network problems can
cause it. It means something went wrong with the TCP connection,
so your system aborted it.

Does it happen consistently at that point?


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


Re: Nested if and expected an indent block

2006-08-13 Thread [EMAIL PROTECTED]

Dustan wrote:

>
> To see the full traceback, assuming you're using windows, you need to
> run it on the Command prompt.

Hi Dustan:

Here's the traceback:

C:\docs\Python>SylloSolver.py
  File "C:\docs\Python\SylloSolver.py", line
"""
  ^
IndentationError: expected an indented block

I got rid of the triple quote string at the start of the function, and
that cleared up the problem, though I don't know why.

Thanks

Keith

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


Re: Compiling wxPython app for Windows; Single EXE

2006-08-13 Thread Satya
Vincent Delporte wrote:

 
> - there's no way to build a single EXE, to make deployment easier (if
> multiple files, I need to build an installer with eg. NSIS or
> InnoSetup)?
>

I am using InnoSetup. The included example script (I believe in py2exe) is
adequate for simple applications. I just modified a few lines and I had a
neat Windows Installer.

Satya

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: Nested if and expected an indent block

2006-08-13 Thread Simon Forman
[EMAIL PROTECTED] wrote:
> Dustan wrote:
>
> >
> > To see the full traceback, assuming you're using windows, you need to
> > run it on the Command prompt.
>
> Hi Dustan:
>
> Here's the traceback:
>
> C:\docs\Python>SylloSolver.py
>   File "C:\docs\Python\SylloSolver.py", line
> """
>   ^
> IndentationError: expected an indented block
>
> I got rid of the triple quote string at the start of the function, and
> that cleared up the problem, though I don't know why.
>
> Thanks
>
> Keith

Ah, yes. The docstring for a function (or at least its first
triple-quote) must be indented to the same degree as its statements.
(If you're using IDLE it should have indented it for you when you hit
return after the def statement.)

HTH,
~Simon

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


Easy to use distributed system?

2006-08-13 Thread Jim Jones
I am looking for a system in Python that will easily allow me to distribute 
processes across multiple systems?So, if I have a function 'foo', I'd 
like to be able to call something along the lines of

distribute(foo(x))

And have the system figure out which node is available for process, and then 
have the results returned in some sort of callback fashion.

Any insight is greatly appreciated.

-- 
Jim
http://www.runfatboy.net - Exercise for the rest of us. 


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


Re: Nested if and expected an indent block

2006-08-13 Thread [EMAIL PROTECTED]

Simon Forman wrote:
> > I got rid of the triple quote string at the start of the function, and
> > that cleared up the problem, though I don't know why.
> >
> Ah, yes. The docstring for a function (or at least its first
> triple-quote) must be indented to the same degree as its statements.
> (If you're using IDLE it should have indented it for you when you hit
> return after the def statement.)
>
> HTH,
> ~Simon

Hi Simon:

Thanks. I code in VB / VBA, and use indented structure, but it's not
enforced they way it is in Python - still getting used to that. Also, I
got goofed up editing some of the code in VIM, indenting with tabs, and
then switching to IDLE, with space indentation. Whoops...

Thanks for all the help everyone, my first Python program is now
working!

Keith

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


recommended general-purpose string template packages?

2006-08-13 Thread John Machin
Hi,

In general, I'm mainly interested in a template engine for dynamic web
pages but would like a general purpose one to avoid learning yet
another package for generating e-mail messages, form letters, source
code, whatever.

In particular, does anyone have much experience with the Python
interface to Terence Parr's StringTemplate
(http://www.stringtemplate.org/)? Reading the website, I'm attracted by
the approach, but a Google search (both generally and in this
newsgroup) gives me the impression that it's little used in the Python
world.

TIA,
John

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


Re: selecting base class from user input

2006-08-13 Thread danielx
Is your declaration of ABC supposed to have some_super as one of the
base classes? Your constructor has some_super as a parameter. What is
this supposed to mean in light of the declaration for ABC?

If you are trying to customize the base class of ABC by passing an
argument to the constructor of ABC, you should probably reconsider. If
constructing one instance of ABC can change ABC (the class) itself,
then the behavior of other instances will be affected as well. No
programmer can stay sane if he creates instances of a class that could
suddenly change its behavior (due to someone else's code).

What you could do instead is to create a function which constructs
classes based on the arguments it recieves. Then, you'll be able to
create instances of the generated classes (all this meta-thinking is
huring my brain ;). I am talking about something like this:

def createClass(name, base):
  exec "class %s(%s): pass" % (name, base)
  return eval( "name" )

...

Can you please tell us why you are doing this? My curiosity is killing
me!

Another meta-thought: Hopefully I've beaten everyone else to the punch
about that question. Is it just me, or will a reply with such a
question always tell the original poster that what he wants to do MUST
be flawed? I hope I have been gentler than this.

Jackson wrote:
> I want a class that will determine its base class by the argument passed
> in.  What I am about to write _does_not_work_, but it shows what I am
> trying to do.
>
> class ABC(some_super):
>   def __init__(self,some_super):
> some_super.__init__(self)
>
> if some_super == list:
>self.append('ABC')
>
> elif some_super == dict:
>self['ABC'] = None
>
>
> Then, the user can call this function:
>
> >>> example = ABC(list)
> >>> print example
> ['ABC']
>
> >>> example = ABC(dict)
> >>> print example
> {'ABC': None}
>
> Clearly, this is a bad example, but the central idea is what I am trying
> to do.  ABC is a particular example which can be represented in various
> forms.  I want an ABC class that will create the example in the form
> specified by the user.
> 
> So how can I achieve this? Thanks.

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


Re: outputting a command to the terminal?

2006-08-13 Thread John Machin

John Salerno wrote:

>
> I think I'll take a look at the subprocess module, just for fun. :)

... and for learning too :-)

Also, consider that some operating system commands are built into the
shell (i.e. not run as a separate process), which makes using the
subprocess module a bit difficult -- for more fun and learning, check
out os.system()

Cheers,
John

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


Re: Easy to use distributed system?

2006-08-13 Thread Ravi Teja
Jim Jones wrote:
> I am looking for a system in Python that will easily allow me to distribute
> processes across multiple systems?So, if I have a function 'foo', I'd
> like to be able to call something along the lines of
>
> distribute(foo(x))
>
> And have the system figure out which node is available for process, and then
> have the results returned in some sort of callback fashion.
>
> Any insight is greatly appreciated.

Sounds like Grid computing. Google for Globus toolkit and ActiveGrid.

Good luck.

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


Re: recommended general-purpose string template packages?

2006-08-13 Thread Ravi Teja
> In general, I'm mainly interested in a template engine for dynamic web
> pages but would like a general purpose one to avoid learning yet
> another package for generating e-mail messages, form letters, source
> code, whatever.
>
> In particular, does anyone have much experience with the Python
> interface to Terence Parr's StringTemplate
> (http://www.stringtemplate.org/)? Reading the website, I'm attracted by
> the approach, but a Google search (both generally and in this
> newsgroup) gives me the impression that it's little used in the Python
> world.

Most Python templating engines are general purpose. Choice between them
however is sometimes a matter of preference, like editors. I settled
down on Cheetah for most part.

Here is a list of some popular ones.
http://wiki.python.org/moin/Templating

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


Re: Easy to use distributed system?

2006-08-13 Thread Maurice LING
Jim Jones wrote:
> I am looking for a system in Python that will easily allow me to distribute 
> processes across multiple systems?So, if I have a function 'foo', I'd 
> like to be able to call something along the lines of
> 
> distribute(foo(x))
> 
> And have the system figure out which node is available for process, and then 
> have the results returned in some sort of callback fashion.
> 
> Any insight is greatly appreciated.
> 

Globus toolkit
pyGlobus, python interface to Globus 
(http://dsd.lbl.gov/gtg/projects/pyGlobus/)
pyLinda (http://www-users.cs.york.ac.uk/aw/pylinda/)

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


Re: Python/Tk not working in Linux

2006-08-13 Thread BinnyVA
> Some distributions move the
> `Tkinter` stuff into an own package.  Search for a package called
> `python-tk` or `python-tkinter` or similar.

I could use a 'python-tk' package - but the problem is the latest
version of python may not be available.

I am going to download Tcl/Tk and install it. Then I would try to
install Python once again. If that works, great. If not I will install
a full 'python-tk' package. Maybe
'ActivePython'(http://www.activestate.com/Products/Download/Download.plex?id=ActivePython)
like Cameron Laird have suggested.

-- 
Binny V A
http://www.bin-co.com/ - Bin-Co

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


Drawing a grid on a picture

2006-08-13 Thread Jive Dadson
Hello folks.  I know precisely zero about image processing.  I want to 
draw a grid of lines one or two pixels wide on a picture (.jpg, .png, or 
whatever). [I want to transfer a sketch of the picture to a canvas (for 
oil painting), using the "grid method."]

I figure this is probably a very easy thing to do, but I can't seem to 
find the documentation I need.  It all seems to assume you already know 
something.  I have wxPython installed.  I also have the wxPython demo. 
The section "Using Images/Image" looked promising.  It just shows how to 
  read a picture and display it as a bitmap.

Can someone show me how, or point me in the right direction?

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


Re: Drawing a grid on a picture

2006-08-13 Thread Jive Dadson
I also found a reference to something called PIL.  Maybe that's the 
ticket.  If so, where can I find it (with documentation)?  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python/Tk not working in Linux

2006-08-13 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, BinnyVA wrote:

>> Some distributions move the `Tkinter` stuff into an own package. 
>> Search for a package called `python-tk` or `python-tkinter` or similar.
> 
> I could use a 'python-tk' package - but the problem is the latest
> version of python may not be available.

That's always the problem with packaged software.  But you gain fast and
easy installation via the package system.

> I am going to download Tcl/Tk and install it. Then I would try to
> install Python once again.

Just install the necessary development packages for your installed Tcl/Tk
and compile the Python sources.  Unless you really want to compile
everything yourself.

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


Re: Drawing a grid on a picture

2006-08-13 Thread Brian Quinlan
Jive Dadson wrote:
> I also found a reference to something called PIL.  Maybe that's the 
> ticket.  If so, where can I find it (with documentation)?  Thanks.

The will likely do what you want. And you can find it the same way that 
you would find anything online i.e. with google. But here is the link:
http://www.pythonware.com/products/pil/

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


PIL and solaris

2006-08-13 Thread kepioo
Hi all,

I am trying to install PIL with python 2.3 on solaris X86, but I get
this error message :

building '_imaging' extension
creating build/temp.solaris-2.10-i86pc-2.3 creating
build/temp.solaris-2.10-i86pc-2.3/libImaging
/sgnome/tools/x86-solaris/forte/SOS8/SUNWspro/bin/cc -i -xO4 -xspace
-xstrconst -xpentium -mr -DANSICPP -D__STDC_VERSION__=199409L -DNDEBUG
-O -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/sfw/include/freetype2 -IlibImaging
-I/usr/sfw/include -I/usr/local/include -I/usr/include
-I/usr/sfw/include/python2.3 -c libImaging/Antialias.c -o
build/temp.solaris-2.10-i86pc-2.3/libImaging/Antialias.o
unable to execute /sgnome/tools/x86-solaris/forte/SOS8/SUNWspro/bin/cc:
No such file or directory
error: command '/sgnome/tools/x86-solaris/forte/SOS8/SUNWspro/bin/cc'
failed with exit status 1
[EMAIL PROTECTED] # pwd
/export/home/lmtansu/Imaging-1.1.6b1


It works fine with python 2.2 however

Do you have any recommendation? Advices?

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


Re: access abook addressbook with curses

2006-08-13 Thread Fabian Braennstroem
Hi Ben,
* Ben C <[EMAIL PROTECTED]> wrote:
> On 2006-08-08, Fabian Braennstroem <[EMAIL PROTECTED]> wrote:
>> Hi Ben,
>>
>> * Ben C <[EMAIL PROTECTED]> wrote:
>>> On 2006-08-06, Fabian Braennstroem <[EMAIL PROTECTED]> wrote:
 Hi Ben,

 * Ben C <[EMAIL PROTECTED]> wrote:
> On 2006-08-05, Fabian Braennstroem <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I want to get access to my abook address file with python.
>> Does anyone have some python lines to achive this using
>> curses? If not, maybe anybody has small python program doing
>> it with a gui!?
>
> You can just parse the abook addressbook with the ConfigParser, try
> this:
>
> import os
> from ConfigParser import *
>
> abook = ConfigParser()
> abook.read(os.environ["HOME"] + "/.abook/addressbook")
>
> for s in abook.sections():
> print abook.items(s)

 Thanks! I found a different example too:

 import ConfigParser
 import string

 config = ConfigParser.ConfigParser()

 config.read("/home/fab/.abook/addressbook")

 # print summary
 print
 for number in [2,200]:
 print string.upper(config.get(str(number), "email"))
 print string.upper(config.get(str(number), "name"))
 print string.upper(config.get(str(number), "city"))
 print string.upper(config.get(str(number), "address"))

 but the problem seems to be that abook does not write every
 field, so I get an exception when there is a field missing:

 Traceback (most recent call last):
   File "configparser-example-1.py", line 13, in ?
 print string.upper(config.get(str(number), "city"))
   File "/usr/lib/python2.4/ConfigParser.py", line 520, in get
 raise NoOptionError(option, section)
 ConfigParser.NoOptionError: No option 'city' in section: '2'

 Section 2 looks like:

 [2]
 name=Andrs Gzi
 [EMAIL PROTECTED]
 nick=oz

 Is there a workaround?
>>>
>>> You can construct the parser with a dictionary of defaults:
>>>
>>> config = ConfigParser.ConfigParser({"city" : "unknown",
>>> "zip" : "unknown"})
>>>
>>> that kind of thing.
>>>
>>> Or catch the exceptions. Or use config.options("2") to see what options
>>> exist in section 2 before you try to read them.
>>
>> Thanks! I will try it out!
>
> Looking at the bigger picture here, though, I may be giving you the
> wrong advice. Mutt just invokes abook to get the addresses I think,
> that's why you put
>
> set query_command="abook --mutt-query '%s'"
>
> So you could do the same (if what you're trying to do is write a mutt
> clone in Python):
>
> import subprocess
>
> name = "Andrs"
> subprocess.Popen("abook --mutt-query " + name,
> stdout=subprocess.PIPE, shell=True).communicate()[0]
>
> The difference is that this "leverages" abook to do the search, not just
> to store the data, which is a logical approach.
>
> On the other hand, this way, you require that abook is installed on the
> machine, which is no good if the object of the exercise is a portable
> Python-only solution.

The biggest problem is a missing and not allowed
abook installation. But thanks for your tips!

Greetings!
 Fabian

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