Re: comparing two lists

2007-08-24 Thread Ladislav Andel
Peter Otten wrote:
> Ladislav Andel wrote:
>
>   
>> Peter Otten wrote:
>> 
>>> Ladislav Andel wrote:
>>>
>>>   
>>>   
 what would be the most efficient way to do following?

 I have a list of dictionaries  taken from DB e.g.
 dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'},
 {'id:3, 'host':'yahoo.com','ip_address':'5.6.7.8'},
 {'id:9, 'host':'msn.com','ip_address':'11.3.2.3'}]

 and list of object instances in memory(it's just for example)
 which are looping within itself and testing particular hosts

 memlist = [,]
 memlist[0].id  is 1 and  memlist[0].host is google.com etc.
 memlist[1].id  is 9 and  memlist[1].host is msn.com etc.

 Now I want to add a new instance to memlist since id=3(in dblist) is not
 in memlist.
 How would you iterate through it and insert a new instance?

 The result should be:
 memlist = [,, ]
 memlist[0].id  is 1 and  memlist[0].host is google.com etc.
 memlist[1].id  is 3 and  memlist[1].host is yahoo.com etc.
 memlist[2].id  is 9 and  memlist[2].host is msn.com etc.
 
 
>>> You should replace the memlist with a dictionary using (host, id) tuples
>>> as the keys. Here's an example that uses a set but requires you to modify
>>> the  class:
>>>
>>> dblist = [{'id':1, 'host':'google.com','ip_address':'1.2.3.4'},
>>> {'id':3, 'host':'yahoo.com','ip_address':'5.6.7.8'},
>>> {'id':9, 'host':'msn.com','ip_address':'11.3.2.3'}]
>>>
>>> class Item(object):
>>> def __init__(self, id, host, **discarded):
>>> self._tuple = (id, host)
>>> def __hash__(self):
>>> return hash(self._tuple)
>>> def __eq__(self, other):
>>> return self._tuple == other._tuple
>>> def __repr__(self):
>>> return "Item(id=%r, host=%r)" % self._tuple
>>>
>>> items = set([Item(1, "google.com")])
>>> for d in dblist:
>>> item = Item(**d)
>>> if item not in items:
>>> print "adding", item
>>> items.add(item)
>>> else:
>>> print item, "already there"
>>>
>>>   
>>>   
>> Thank you for this nice solution. I wouldn't be able to write it this
>> way at all
>> 
>
> Then think twice before you use it. The dictionary approach should be
> straightforward.
>
>   
>> but what about removing from memlist if there is less items in dblist
>> than in items (instances)?
>> I will have to iterate over items(instances) and remove that one which
>> is not in dblist I guess.
>> 
>
> Yes, but again, if you use a dictionary instead of a list the lookup will be
> efficient.
>
> To follow up on my previous post: with sets there is a concise spelling:
>
> items &= set(Item(**d) for d in dblist)
>
> or even
>
> items.intersection_update(Item(**d) for d in dblist)
>
> if you don't mind object identity.
>
> Peter
>
>   
Thanks again for this solution, but I forgot to say that in the instance 
is a looping call which
need to be stopped before deleting any instance from items.
So I need to call stopLoop method in the given item in items before it 
gets removed.
If there is any addition to items it's quite easy to call
item.startLoop() method.


my class would look like (I use twisted but it should not make any 
difference):

class Item(object):
def __init__(self, id, host, interval, **discarded):
self._tuple = (id, host)
self.interval = interval
def __hash__(self):
return hash(self._tuple)
def __eq__(self, other):
return self._tuple == other._tuple
def __repr__(self):
return "Item(id=%r, host=%r)" % self._tuple
def startLoop(self):
self.l = task.LoopingCall(self.serverTest)
self.l.start(self.interval, False)
def serverTest(self):
return getReply()   
 # this is just for example. It returns something on each start of the 
loop
 # but because it sends packets within network, it takes some time 
before it gets a reply
 # so if I remove this object instance before I get reply it gets 
broken somewhere else
 # and I need to stop the loop before removing. Hopefully, this make 
sence.

def stopLoop(self):
self.l.stop()







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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Paul Rubin
Torsten Bronger <[EMAIL PROTECTED]> writes:
> The differences to LaTeX are explained comprehensively on the
> webpage, and actually LaTeX is the real competitor rather than
> reStructuredText.

TeX/LateX have been around forever and are well established standards,
as awful as they are.  Why do we want ANOTHER markup language?  We
need fewer, not more.
-- 
http://mail.python.org/mailman/listinfo/python-list


Error with Simplemapi.py

2007-08-24 Thread Mick Duprez
On Dec 24 2004, 4:56 pm, [EMAIL PROTECTED] wrote:
> I wish I new why google doesn't show nicely aligned python code when
> you paste the script.
> Anyways, in case this helps someone else you can download the script
> fromhttp://www.kirbyfooty.com/simplemapi.py
>
> Ian

First of all, thanks to all involved, this looks like what I need
without re-inventing the wheel.
Sorry to Ian if he just recieved 2 emails, my bad, I need to learn how
to use this board better!

I have a small problem. I get an error I don't know how to resolve,
any help would be much appreciated.
I'm using Python25 on winXP pro and the script from the link above.
Here's the error -

>>> mailtest.SendMail('[EMAIL PROTECTED]','test','test string','c:\dbs.txt')

Traceback (most recent call last):
  File "", line 1, in 
mailtest.SendMail('[EMAIL PROTECTED]','test','test string','c:
\dbs.txt')
  File "C:\Python25\mailtest.py", line 135, in SendMail
cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
  File "C:\Python25\lib\ctypes\__init__.py", line 478, in cast
return _cast(obj, obj, typ)
ArgumentError: argument 1: : wrong type
>>>

I have had a brief look at the C api for these structs and functions
but I can't resolve it, it is probably something simple.
The piece of code I don't understand though is this -

MapiRecipDesc_A = MapiRecipDesc * len(RecipWork) #size of struct??
rda = MapiRecipDesc_A() # isn't it MapiRecipDesc as declared??

There's some new stuff going on here I don't understand.

thanks for your help,
Mick.

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


Re: beginner, idomatic python 2

2007-08-24 Thread Bruno Desthuilliers
bambam a écrit :
> Would someone like to suggest a replacement for this? This is a
> function that returns different kinds of similar objects, depending
> on what is asked for. PSP and PWR are classes.  I don't really
> want to re-write the calling code very much: I'm just wondering
> if the function can be replaced with some kind of OOP pattern.

Dan already answered to this. Just as a side note, and since you're 
trying to be "idiomatic", Python's naming convention is to use all_lower 
for functions, MixedCaps for classes (except - mostly for historical 
reasons - the builtin types...), and ALL_LOWER for symbolic (pseudo) 
constants.


> def Device(DeviceType):
> if DeviceType=='PSP':
> return PSP()
> elif DeviceType=="Power Supply"
> return PWR()
> etc...
> 
> 
> Thanks! 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner, idomatic python 2

2007-08-24 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit :
(snip)
 > and ALL_LOWER

That's 'ALL_UPPER', of course :(

> for symbolic (pseudo) 
> constants.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: List file system roots

2007-08-24 Thread Tim Golden
Einar W. Høst wrote:
> Hi,
> 
> How would you list the file system roots in Python? That is, I'm looking
> for a way to list all connected drives (C:, D: etc) on a Windows box, or
> all /root, /tmp etc on a *nix box. In Java, there's a built-in API
> function to do this, File.listRoots(), but I couldn't find any
> equivalents in the Python libraries.

Couple of options for Windows (probably more as well):

http://timgolden.me.uk/python/win32_how_do_i/find-drive-types.html
http://timgolden.me.uk/python/wmi_cookbook.html#find-drive-types

TJG

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


Unequal Length Maze

2007-08-24 Thread tomtim20
Hi All,
what's the best algorithm to solve such problem ?
http://www.stetson.edu/~efriedma/unequal/

I will really appreciate some pieces of code (python).


Thanks,
 Tommy

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Evan Klitzke
On 8/23/07, Torsten Bronger <[EMAIL PROTECTED]> wrote:
> Hallöchen!
>
> Some LaTeX users in Aachen thought about a general-use markup
> language this spring.  I wrote some code and a rough project
> description, however, we could need some help.
>
> If you are interested, visit the provisional project page at
> http://latex-bronger.sourceforge.net/gummi/
>
> Tschö,
> Torsten.

I briefly looked over the specification, and it looks like you're
targeting a LaTeX backend. Are you planning on outputting to LaTeX and
using that to generate e.g. PDF versions of documents, or do you plan
to have a real PDF/Postscript backend?

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: comparing two lists

2007-08-24 Thread Peter Otten
Ladislav Andel wrote:

> need to be stopped before deleting any instance from items.
> So I need to call stopLoop method in the given item in items before it
> gets removed.
> If there is any addition to items it's quite easy to call
> item.startLoop() method.

Unless you want to rely on the __del__ method or introduce another
complication (weak references) you have to be explicit:

# untested
# removing items
db_items = set(Item(**d) for d in dblist)
delenda = items - db_items
for item in delenda:
item.stopLoop()
items.remove(item)

> (I use twisted but it should not make any difference):

I've not worked with twisted, so I can't confirm that.
I can imagine that they provide their own way to spell a finalizer...

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


Does shuffle() produce uniform result ?

2007-08-24 Thread tooru honda
Hi,

I have read the source code of the built-in random module, random.py.  
After also reading Wiki article on Knuth Shuffle algorithm, I wonder if 
the shuffle method implemented in random.py produces results with modulo 
bias.

The reasoning is as follows: Because the method random() only produces 
finitely many possible results, we get modulo bias when the number of 
possible results is not divisible by the size of the shuffled list.

1. Does shuffle() produce uniform result ?

2. If not, is there a fast and uniform shuffle() available somewhere ?

Thanks !

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


tarfile module for version 2.2.3

2007-08-24 Thread Antoon Pardon
I have to write a little program that has to run on a number of hosts.
Versions of python range from 2.2.3. to 2.4.2.

The easiest way to implement the necessary behaviour seems to me to
use the tarfile module. However that was only introduced in 2.3
I had a look in the code and at first sight couldn't find anything
that would cause problems if I used this module with python 2.2.3.

Could someone confirm that the tarmodule is compatible with python 2.2.
I will try some tests myself but it would be nice to have confirmation
from elsewhere.

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


Re: How would I go about making a file open. Not the way you might think.

2007-08-24 Thread Tim Golden
[... snip extended discussion on opening text files ...]

Lamonte Harris wrote:
 > I've completed this request and I got the answer already.

Yes, but discussions here never simply end when the answer
is found! :)

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


Re: tarfile module for version 2.2.3

2007-08-24 Thread billiejoex
On 24 Ago, 09:57, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> I have to write a little program that has to run on a number of hosts.
> Versions of python range from 2.2.3. to 2.4.2.
>
> The easiest way to implement the necessary behaviour seems to me to
> use the tarfile module. However that was only introduced in 2.3
> I had a look in the code and at first sight couldn't find anything
> that would cause problems if I used this module with python 2.2.3.
>
> Could someone confirm that the tarmodule is compatible with python 2.2.
> I will try some tests myself but it would be nice to have confirmation
> from elsewhere.
>
> --
> Antoon Pardon

Try also the test suite (Lib/test/test_tarfile.py).

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


Re: beginner, idomatic python 2

2007-08-24 Thread bambam
> trying to be "idiomatic"

...I hope that if a python programmer looks at my code it
won't be an excuse to discard it. Less of an issue with Python
than with C/C++, but since I'm just starting...

def device(DeviceType):
if DeviceType=='PSP':
return Psp()
elif DeviceType=="Power Supply"
return Pwr()

What about the parameter "DeviceType"?

Also, I see what you mean now, DEVICE_DICT is upper
case because it is a 'constant' -- I'd missed that point.

Steve.

"Bruno Desthuilliers" <[EMAIL PROTECTED]> 
wrote in message news:[EMAIL PROTECTED]
> bambam a écrit :
>> Would someone like to suggest a replacement for this? This is a
>> function that returns different kinds of similar objects, depending
>> on what is asked for. PSP and PWR are classes.  I don't really
>> want to re-write the calling code very much: I'm just wondering
>> if the function can be replaced with some kind of OOP pattern.
>
> Dan already answered to this. Just as a side note, and since you're trying 
> to be "idiomatic", Python's naming convention is to use all_lower for 
> functions, MixedCaps for classes (except - mostly for historical reasons - 
> the builtin types...), and ALL_LOWER for symbolic (pseudo) constants.
>
>
>> def Device(DeviceType):
>> if DeviceType=='PSP':
>> return PSP()
>> elif DeviceType=="Power Supply"
>> return PWR()
>> etc...
>>
>>
>> Thanks! 


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

Re: Co-developers wanted: document markup language

2007-08-24 Thread Torsten Bronger
Hallöchen!

Paul Rubin writes:

> Torsten Bronger <[EMAIL PROTECTED]> writes:
>
>> The differences to LaTeX are explained comprehensively on the
>> webpage, and actually LaTeX is the real competitor rather than
>> reStructuredText.
>
> TeX/LateX have been around forever and are well established
> standards, as awful as they are.  Why do we want ANOTHER markup
> language?

Well, because they are awful.  ;-)  I don't see that there is a
bunch of already existing projects, in fact, I don't see anyone
challenging LaTeX at all.  However, competition is a good thing, and
I think there are enough aspects about LaTeX that can be done better
so that this project is worth being done.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner, idiomatic python

2007-08-24 Thread bambam
> This isn't a "cast" in the sense of some less-strongly-typed languages; 
> it's just a conversion.  The `list` function/type iterates over its 
> argument and turns it into a list.  Sets are iterable, so that's all 
> that's really going on here.

oh :~). Learning experience happening here... Thank you.

> The reason that lists don't have set-like methods is because
> lists aren't sets -- lists can contain duplicate elements

Interesting point -- if that's all there is in it, then lists should
have difference and intersection methods. Not because they
are the same as sets -- because they are slightly different than
sets. In this case it doesn't matter - my lists don't contain
duplicate elements this time - but I have worked with lists in
money market and in inventory, and finding the intersection
and difference for matching off and netting out are standard
operations.
Still, any built in feature would probably be too simple to
use in any but the simplest cases.

Steve.



"Erik Max Francis" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> bambam wrote:
>
>> Excellent. By symmetry, I see that "list" casts the set back into a list.
>>
>> I wonder why list has not been extended with the same (difference,
>> interesection) methods?  Casting to set looks a little kludgy:
>>
>> c = list(set(a)-set(b))
>> I wonder if that is clearer than the explicit loop?
>
> This isn't a "cast" in the sense of some less-strongly-typed languages; 
> it's just a conversion.  The `list` function/type iterates over its 
> argument and turns it into a list.  Sets are iterable, so that's all 
> that's really going on here.
>
> The reason that lists don't have set-like methods is because lists aren't 
> sets -- lists can contain duplicate elements, whereas sets cannot.  You 
> should use the proper type for your needs; if you want to take two lists, 
> remove duplicate elements, and then end up with a list, then the 
> sets-difference-and-then-make-a-list mechanism is appropriate.
>
> -- 
> Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
>  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
>   It [freedom] must be demanded by the oppressed.
>-- Dr. Martin Luther King, Jr. 


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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Torsten Bronger
Hallöchen!

Evan Klitzke writes:

> On 8/23/07, Torsten Bronger <[EMAIL PROTECTED]> wrote:
>
>> Some LaTeX users in Aachen thought about a general-use markup
>> language this spring.  I wrote some code and a rough project
>> description, however, we could need some help.
>>
>> If you are interested, visit the provisional project page at
>> http://latex-bronger.sourceforge.net/gummi/
>
> I briefly looked over the specification, and it looks like you're
> targeting a LaTeX backend. Are you planning on outputting to LaTeX
> and using that to generate e.g. PDF versions of documents, or do
> you plan to have a real PDF/Postscript backend?

Yes, I plan to use LaTeX as a mere backend slave for getting PDFs.
I will *try* to keep the LaTeX readable but mostly for debugging
purposes.  I don't think that a native PDF backend is helpful on the
short run because LaTeX just works well for this (I don't like
LaTeX's usability but I do like TeX's typesetting abilities).

There is another way to get PDFs which I certainly want to give a
try sometime, namely XSL:FO.

However, I don't know how feasible direct PDF output is.  I'm
somewhat scared by line breaking algorithms, hyphenation and all
this, though.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


I know almost all basics

2007-08-24 Thread Lamonte Harris
Now I'm moving more into the gaming world.  What libs/modules would you
recommend?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Co-developers wanted: document markup language

2007-08-24 Thread olive
>
> Well, because they are awful.  ;-)  I don't see that there is a
> bunch of already existing projects, in fact, I don't see anyone
> challenging LaTeX at all.  However, competition is a good thing, and
> I think there are enough aspects about LaTeX that can be done better
> so that this project is worth being done.

What about ODF ? (http://www.odfalliance.org/)
Isn't it a good competitor ?

Olive

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


Clipboard Monitor (tkinter,windows)

2007-08-24 Thread Peter Sutton
Hi. I am an A-level student studying computer science. I have taken it upon 
myself to learn python. It is now my weapon of choice. I have had a problem 
trying to creating a clipboard monitor in Windows(XP,Vista) that is linked to a 
tkinter GUI. I have a perfectly good code for clipboard monitoring, but as soon 
as it is linked to a tkinter gui, the gui locks when a WM.DRAWCLIPBOARD message 
is recieved. I am at the point of giving up. If anyone can help or offer an 
alternativethat is not pollingI would be very happy.  Thanks. Peter

import win32ui, win32clipboard, win32con, win32api, win32gui
from Tkinter import *

def paste():
win32clipboard.OpenClipboard(0)
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return data


class ClipRecord(object):
def __init__(self):
self.gui = Tk()
self.hPrev = 0
self.first = True
self.win = win32ui.CreateFrame()
self.win.CreateWindow(None,'',win32con.WS_OVERLAPPEDWINDOW)
self.win.HookMessage(self.OnDrawClipboard,win32con.WM_DRAWCLIPBOARD)
self.win.HookMessage(self.OnChangeCBChain,win32con.WM_CHANGECBCHAIN)
self.win.HookMessage(self.OnDestroy,win32con.WM_DESTROY)
try:
self.hPrev=win32clipboard.SetClipboardViewer(self.win.GetSafeHwnd())
except win32api.error, err:
if win32api.GetLastError () == 0:
# information that there is no other window in chain
pass
else:
raise
self.l = Label(self.gui,text="I have losted the will to live")
self.l.pack()
self.gui.mainloop()
def OnChangeCBChain(self, *args):
msg, wParam, lParam = args[-1][1:4]
if self.hPrev == wParam:
# repair the chain
self.hPrev = lParam
if self.hPrev:
# pass the message to the next window in chain
win32api.SendMessage (self.hPrev, msg, wParam, lParam)

def OnDrawClipboard(self, *args):
msg, wParam, lParam = args[-1][1:4]
if self.first:
self.first = False
else:
self.l["text"] = "Lord be Praised"
print paste()
if self.hPrev:
# pass the message to the next window in chain
win32api.SendMessage (self.hPrev, msg, wParam, lParam)
def OnDestroy(self):
if self.hPrev:

win32clipboard.ChangeClipboardChain(self.win.GetSafeHwnd(),self.hPrev)
else:
win32clipboard.ChangeClipboardChain(self.win.GetSafeHwnd(),0)

if __name__ == "__main__":
cr = ClipRecord()




  ___
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ -- 
http://mail.python.org/mailman/listinfo/python-list

Re: beginner, idiomatic python

2007-08-24 Thread Mikael Olofsson


bambam wrote:
>
> In this case it doesn't matter - my lists don't contain
> duplicate elements this time - but I have worked with lists in
> money market and in inventory, and finding the intersection
> and difference for matching off and netting out are standard
> operations.

I would use a list comprehension for that case:

A = ['a','b','c','a','c','d']
U = ['a','b','e']
B = [x for x in A if x in U]

The result would be B==['a','b','a']

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


Re: Newbie: List file system roots

2007-08-24 Thread Bjoern Schliessmann
"Einar W. Høst" wrote:
> How would you list the file system roots in Python? That is, I'm
> looking for a way to list all connected drives (C:, D: etc) on a
> Windows box, or all /root, /tmp etc on a *nix box. 

/root and /tmp are no "roots", but normal directories.
glob.glob("/*") will give you all of those. 

Regards,


Björn

-- 
BOFH excuse #236:

Fanout dropping voltage too much, try cutting some of those little
traces

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


Re: beginner, idomatic python 2

2007-08-24 Thread Bruno Desthuilliers
bambam a écrit :
>> trying to be "idiomatic"
> 
> ...I hope that if a python programmer looks at my code it
> won't be an excuse to discard it. 

Hopefully not - and nothing forces you into adopting the common 
convention !-) But it's a fact that Python relies heavily on naming 
conventions, and that it greatly helps readability.

> Less of an issue with Python
> than with C/C++, but since I'm just starting...
> 
> def device(DeviceType):
> if DeviceType=='PSP':
> return Psp()
> elif DeviceType=="Power Supply"
> return Pwr()
> 
> What about the parameter "DeviceType"?

DEVICE_TYPES = {
   'PSP' : Psp,
   'Power Supply' : Pwr,
}

def get_device(device_type):
 cls = DEVICE_TYPES.get(device_type, None)
 if cls is not None:
return cls()
 # implicitly returns None, which may or not be a GoodThing(tm)



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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Wildemar Wildenburger
Torsten Bronger wrote:
> Hallöchen!
>
>   
Yes, you're German. Have you ever noticed that (we) Germans are 
virtually the only ones that feel the need to rub our nationality into 
everyones faces? ;)


> Paul Rubin writes
>   
>> TeX/LateX have been around forever and are well established
>> standards, as awful as they are.  Why do we want ANOTHER markup
>> language?
>> 
> Well, because they are awful.  ;-)  I don't see that there is a
> bunch of already existing projects, in fact, I don't see anyone
> challenging LaTeX at all.  However, competition is a good thing, and
> I think there are enough aspects about LaTeX that can be done better
> so that this project is worth being done.
>   
Well there is ConTeXt http://wiki.contextgarden.net/>. I've never 
actually used it, but from reading the docs I deem it a very attractive 
alternative to LaTeX.

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


How to minimize command window when running wxPython script

2007-08-24 Thread care02
Dear friends,

I have almost completed my first wxPython application. The only thing
I need now is to minimize the command window. How is this accomplished
on Win32? What about Mac and Linux?

Carl

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


Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread Paul Rubin
Boris Borcic <[EMAIL PROTECTED]> writes:
> >> For example, if I have x=[ [1,2], [3,4] ]
> >>
> >> What I want is a new list of list that has four sub-lists:
> >>
> >> [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
> > [[a, map(f,a)] for a in x]
> 
> no, that one will be [[[1,2], [f(1), f(2)]], [[3,4], [f(3), f(4)]]]
> eg two sublists instead of four.

Oh ugh, I misread the original request and thought the extra brackets
were there.  I think the following works and is reasonably intuitive:

from itertools import chain
y = list(chain(*([a, map(f,a)] for a in x)))

But the original request itself seems a bit weird.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to minimize command window when running wxPython script

2007-08-24 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
> Dear friends,
> 
> I have almost completed my first wxPython application. The only thing
> I need now is to minimize the command window. How is this accomplished
> on Win32? 

Use a .pyw main module (eventually a wrapper calling your main .py 
module) - it is associated with pythonw.exe, which dont open a console.
[note: this is in the FAQ]

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


Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread Boris Borcic
Paul Rubin wrote:
> beginner <[EMAIL PROTECTED]> writes:
>> For example, if I have x=[ [1,2], [3,4] ]
>>
>> What I want is a new list of list that has four sub-lists:
>>
>> [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
> 
> [[a, map(f,a)] for a in x]

no, that one will be [[[1,2], [f(1), f(2)]], [[3,4], [f(3), f(4)]]]
eg two sublists instead of four.

[map(g,a) for a in x for g in [None,f]]

will do it.

...a bit too cleverly, but there's worse :

list((yield a) or map(f,a) for a in x)

Cheers, BB

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


Re: Server-side scripting in python

2007-08-24 Thread Bruno Desthuilliers
Nagarajan a écrit :
> On Aug 22, 8:50 pm, [EMAIL PROTECTED] (Cameron Laird) wrote:
>> In article <[EMAIL PROTECTED]>,Nagarajan  <[EMAIL PROTECTED]> wrote:
>>
 .
 .
 .
>>> Let me phrase my problem in a finer way.
>>> I have done simple projects inpython.
>>> I wanted to explore web programming facet ofpython. The problem at my
>>> hand is to develop an email web client. I've developed web
>>> applications in PHP. I need to evaluatepython-based web frameworks to
>>> make a smart choice of the web framework or a language like PHP, Perl
>>> based on performance predominantly. Do I make myself clear now?
>> .
>> .
>> .
(snip Cameron's answer)

> Django is intuitive and handy. I think I would go with that.
> Any suggestions?

Yes : have a look at Pylons too. It's actually quite less 'polished' 
than Django, but it's IMHO going in the right direction (as a matter of 
fact, Turbogears 2.0 - another well-known Python MVC framework -  will 
be based on Pylons...). Django is clearly more oriented toward 
content-management, which might not be what you want for this project.

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Torsten Bronger
Hallöchen!

olive writes:

> [...]
>
>> Well, because they are awful.  ;-) I don't see that there is a
>> bunch of already existing projects, in fact, I don't see anyone
>> challenging LaTeX at all.  However, competition is a good thing,
>> and I think there are enough aspects about LaTeX that can be done
>> better so that this project is worth being done.
>
> What about ODF ? (http://www.odfalliance.org/) Isn't it a good
> competitor ?

I'd be a nice further backend but I doubt that people want to enter
XML.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Server-side scripting in python

2007-08-24 Thread olive

> Yes : have a look at Pylons too. It's actually quite less 'polished'
> than Django, but it's IMHO going in the right direction (as a matter of
> fact, Turbogears 2.0 - another well-known Python MVC framework -  will
> be based on Pylons...). Django is clearly more oriented toward
> content-management, which might not be what you want for this project.

this opinion about Django is a little bit dated (see http://www.djangosites.org/
and http://code.djangoproject.com/wiki/DjangoPoweredSites).

Django is really multi-purpose and is rarely use as a CMS, excepted
through Ellington CMS which is itself a commercial fork oriented
toward newspaper like publishing.

I would use Plone instead as a general CMS.

Olive.

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


Re: Does shuffle() produce uniform result ?

2007-08-24 Thread Steve Holden
tooru honda wrote:
> Hi,
> 
> I have read the source code of the built-in random module, random.py.  
> After also reading Wiki article on Knuth Shuffle algorithm, I wonder if 
> the shuffle method implemented in random.py produces results with modulo 
> bias.
> 
> The reasoning is as follows: Because the method random() only produces 
> finitely many possible results, we get modulo bias when the number of 
> possible results is not divisible by the size of the shuffled list.
> 
> 1. Does shuffle() produce uniform result ?
> 
Given the cycle length of the Mersenne twister algorithm that generates 
the underlying random numbers, it would have to be a pretty long list to 
see a significant bias, don't you think? Have you done any calculations 
on the length of list you propose to use?

> 2. If not, is there a fast and uniform shuffle() available somewhere ?
> 
Frankly I don't think you need to worry.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


any problem with py's RC?

2007-08-24 Thread Yan Zhu
hi all,
Here is 3 PYs, we found there is a big memory wasting, specially the program
c.py, we found the memory will increase very soon.
any body knows why? any RC's problem? thanks

-- 
eSX
class a():
def __init__(self):
fp = open("a_file_lager_1M","rb")
self.ll = fp.read()
fp.close()
self.h = b(self.aaa)
def aaa(self):
pass

class b:
def __init__(self,bbb):
self.a = bbb  #remove the "self.", the memory use will be very 
low!
pass

def c():
k=a()

while True:
c()


import haha
import time

def c():
b=haha.Client(["127.0.0.1"])
while True:
   # time.sleep(1)
c()


#!/usr/bin/env python

from threading import local


class Client(local):
def __init__(self, servers, debug=0):
self.k = [_Host(s, self.debuglog) for s in servers]

def debuglog(self, str):
pass
class _Host:

def __init__(self, host, debugfunc=None):
self.debuglog = debugfunc  #a -> b  b->a, make the memory be huge!
pass


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

Re: Regular expression use

2007-08-24 Thread anno4000
Nick Maclaren <[EMAIL PROTECTED]> wrote in comp.lang.perl.misc:
> 
> For reasons that I won't explain, as they are too complicated
> and not terribly relevant,

Your reasons are relevant as a motivation for your readers to
answer such a broad question.

> I am interested in discovering what
> people actually use regular expressions for.  Not the subject
> domain, but the construction of the regular expressions.

How is the construction of a regex related to what it is used
for?  That makes no sense.

> I know about computer scientists and parsing,

That's a (broad) subject domain.

> and I know about
> the use of relatively simple ones for things like extracting
> HTML links from Web pages.

That's another subject domain (and a regex for that purpose wouldn't
qualify as "relatively simple").

> But I don't have much feel for the
> (probably rare but difficult) uses of more complex ones for
> other purposes.  I have heard of several such uses, but don't
> have an overall idea of what is going on.

Your question is so badly defined, it would take considerable effort
just to make sense of it.  Given your premise of "Never mind what I
need it for, just gimme the info," I won't even try.

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Wildemar Wildenburger
olive wrote:
> What you need is good structured text editor which hides as much as
> possible the underlying XML (or other) format.
>   
What you do there is pose extra requirements on the user ("Use a text 
editor with some far-out functions"). That will prevent your (well, 
Torsten's ;)) standard from spreading easily. Plain text (read: less 
intrusive) markup is a way better approach there, IMHO, because it can 
be done in any old editor.

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Torsten Bronger
Hallöchen!

Wildemar Wildenburger writes:

> [...]
> 
>> Well, because they are awful.  ;-)  I don't see that there is a
>> bunch of already existing projects, in fact, I don't see anyone
>> challenging LaTeX at all.  However, competition is a good thing,
>> and I think there are enough aspects about LaTeX that can be done
>> better so that this project is worth being done.
>  
> Well there is ConTeXt http://wiki.contextgarden.net/>. I've
> never actually used it, but from reading the docs I deem it a very
> attractive alternative to LaTeX.

That's right, I failed to mention ConTeXt, which really is a
competitor to LaTeX.  I even took one good idea from context, namely
the availability of syntax elements in different human languages.

However, ConTeXt documents are as much cluttered as LaTeX.  ConTeXt
is a huge system with the aim of fine control on the PDF layout.
Therefore, it is even harder to convert it to HTML than it is for
LaTeX.  Besides, I never managed to comprehend its documentation.

It has its good aspects, too, but these are the reasons why I don't
think that it would be a good starting point for improving the
situation with plain text document markup languages.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Regular expression use

2007-08-24 Thread Nick Maclaren

For reasons that I won't explain, as they are too complicated
and not terribly relevant, I am interested in discovering what
people actually use regular expressions for.  Not the subject
domain, but the construction of the regular expressions.

I know about computer scientists and parsing, and I know about
the use of relatively simple ones for things like extracting
HTML links from Web pages.  But I don't have much feel for the
(probably rare but difficult) uses of more complex ones for
other purposes.  I have heard of several such uses, but don't
have an overall idea of what is going on.

Any pointers appreciated, to more-or-less anything.


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


Re: Co-developers wanted: document markup language

2007-08-24 Thread olive
On 24 août, 12:43, Torsten Bronger <[EMAIL PROTECTED]>
wrote:
> Hallöchen!
>
> olive writes:
> > What about ODF ? (http://www.odfalliance.org/) Isn't it a good
> > competitor ?
>
> I'd be a nice further backend but I doubt that people want to enter
> XML.
>

Why not if the schema is designed toward data entry.

You could then use XSLT to convert to ODF for publishing.

What you need is good structured text editor which hides as much as
possible the underlying XML (or other) format.

Olive.

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread olive
On 24 août, 13:34, Wildemar Wildenburger <[EMAIL PROTECTED]>
wrote:
> olive wrote:
> > What you need is good structured text editor which hides as much as
> > possible the underlying XML (or other) format.
>
> What you do there is pose extra requirements on the user ("Use a text
> editor with some far-out functions"). That will prevent your (well,
> Torsten's ;)) standard from spreading easily. Plain text (read: less
> intrusive) markup is a way better approach there, IMHO, because it can
> be done in any old editor.

We are talking about two different things: data entry and document
publishing.

for me ODF is good for document publishing only.

I agree that Plain Text Markup is usually better than XML even with a
good XML editor and a simple schema.

But few people are used to Plain Text Markup (excepted in some
scientific area maybe) and it is error prone.

This is why some user-friendly PTM or XML based editors are needed.

Good user-friendly editor will help in spreading standard.
OpenOffice is a good example for ODF but this has never happened to
XML or any other markup language.

Olive

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

Re: Regular expression use

2007-08-24 Thread Zara
On 24 Aug 2007 10:58:46 GMT, [EMAIL PROTECTED] (Nick Maclaren) wrote:

>
>For reasons that I won't explain, as they are too complicated
>and not terribly relevant, I am interested in discovering what
>people actually use regular expressions for.  Not the subject
>domain, but the construction of the regular expressions.
>
>I know about computer scientists and parsing, and I know about
>the use of relatively simple ones for things like extracting
>HTML links from Web pages.  But I don't have much feel for the
>(probably rare but difficult) uses of more complex ones for
>other purposes.  I have heard of several such uses, but don't
>have an overall idea of what is going on.
>
>Any pointers appreciated, to more-or-less anything.
>

In the linked project, regular expression are used to parse
communication protocol responses, file contents, and interporocess
communcation (at least).

They may not be pretty elegant solutions, but this is the first
project I made in python (and also with regex)!!

NOTE: I am the author, and I swear the application is free of viruses,
it has been fully developed with a python and a WingWare standar
installation, and it will only deposit some files on your
$python$/Lib/site-packages folder. 
Any comments welcome.

NOTE2: Software in spanish, but it should not be pretty difficult to
follow (I hope!)

best regards,

Zara

http://www.albalaing.com/Firmware.aspx?id_firmware=2359

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread David Boddie
On Fri Aug 24 11:04:33 CEST 2007, Torsten Bronger wrote:

> Paul Rubin writes:
> 
> > TeX/LateX have been around forever and are well established
> > standards, as awful as they are.  Why do we want ANOTHER markup
> > language?
> 
> Well, because they are awful.  ;-)  I don't see that there is a
> bunch of already existing projects, in fact, I don't see anyone
> challenging LaTeX at all.  However, competition is a good thing, and
> I think there are enough aspects about LaTeX that can be done better
> so that this project is worth being done.

There are alternatives to LaTeX if you are prepared to look for them.
One of these is Lout:

  http://lout.sourceforge.net/

Another option is to use TeX, but with Python as an alternative "macro
language":

  http://www.pytex.org/

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


Re: Regular expression use

2007-08-24 Thread Mirco Wahab
Nick Maclaren wrote:
> For reasons that I won't explain, as they are too complicated
> and not terribly relevant, I am interested in discovering what
> people actually use regular expressions for.  Not the subject
> domain, but the construction of the regular expressions.

After I figured out how to solve a problem,
I'll surely rewrite the solution again in
pure Perl5 regular expressions in order to
outrun the normal mental degradation processes
related to aging ... :)

> I know about computer scientists and parsing, and I know about
> the use of relatively simple ones for things like extracting
> HTML links from Web pages.  But I don't have much feel for the
> (probably rare but difficult) uses of more complex ones for

Using complex regular expressions is like tank destruction
with contact charges glued on them. Only a few people
will even survive the first "usage", but survivors will
then eventually be able to destroy almost every tank with
tremendous speed and precision.

> other purposes. I have heard of several such uses, but don't
> have an overall idea of what is going on.

On business software projects, maintainability is a key
prerequisite - after using complex regular expressions
on business critical parts you are bound to involve
very very expensive maintenance programmers ... :)

What exactly did you "hear" of several "uses"? Which
application? Academia, Business, ...?


Regards

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


Tinker question 1

2007-08-24 Thread Lamonte Harris
What does the pack function do exactly?  Just puts everything together?

Also I've been reading this manual/tutorial and I'm confused on the Frame,
what does it do, I'm pretty confused on that.

http://www.pythonware.com/library/tkinter/introduction/hello-again.htm
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression use

2007-08-24 Thread Aahz
In article <[EMAIL PROTECTED]>,
Nick Maclaren <[EMAIL PROTECTED]> wrote:
>
>For reasons that I won't explain, as they are too complicated
>and not terribly relevant, I am interested in discovering what
>people actually use regular expressions for.  Not the subject
>domain, but the construction of the regular expressions.

Your question as phrased makes no sense to me.  For that matter, it isn't
even a question.  ;-)

Side note: please don't cross-post between c.l.py and c.l.perl.* -- the
group cultures are different and it's too easy to start flamewars.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any problem with py's RC?

2007-08-24 Thread Marc 'BlackJack' Rintsch
On Fri, 24 Aug 2007 19:44:37 +0800, Yan Zhu wrote:

> Here is 3 PYs, we found there is a big memory wasting, specially the program
> c.py, we found the memory will increase very soon.
> any body knows why? any RC's problem? thanks

You are creating reference cycles and instantiate many in very short time.
Objects with cyclic dependencies must be detected by the garbage collector
which takes some time.

Usually this is not a problem because generating lots of cycles in a tight
and endless ``while``-loop is not *that* common.  ;-)

You may take a look into the `weakref` module to avoid the cycles.

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


Re: Does shuffle() produce uniform result ?

2007-08-24 Thread Hrvoje Niksic
tooru honda <[EMAIL PROTECTED]> writes:

> I have read the source code of the built-in random module,
> random.py.  After also reading Wiki article on Knuth Shuffle
> algorithm, I wonder if the shuffle method implemented in random.py
> produces results with modulo bias.

It doesn't have modulo bias because it doesn't use modulo to produce a
random index; it multiplies the floating point value with the desired
range.  I'm not sure if that method produces any measurable bias.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread beginner
On Aug 24, 12:44 am, beginner <[EMAIL PROTECTED]> wrote:
> On Aug 24, 12:41 am, Davo <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Aug 23, 9:24 pm, beginner <[EMAIL PROTECTED]> wrote:
>
> > > Hi All,
>
> > > How do I map a list to two lists with list comprehension?
>
> > > For example, if I have x=[ [1,2], [3,4] ]
>
> > > What I want is a new list of list that has four sub-lists:
>
> > > [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
>
> > > [1,2] is mapped to [1,2] and [f(1), f(2)] and [3,4] is mapped to
> > > [3,4], [f(3), f(4)].
>
> > > I just can't find any way to do that with list comprension. I ended up
> > > using a loop (untested code based on real code):
>
> > > l=[]
> > > for y in x:
> > >l.append(y)
> > >l.append([f(z) for z in y])
>
> > > Thanks,
> > > Geoffrey
>
> > This may be what you want:
>
> > l = [[y, [f(z) for z in y]] for y in x]
>
> > But It's a bit dense.  How about:
> > l=[]
> > for y in x:
> > Fy = [f(z) for z in y]
> > l.extend([y, Fy])
>
> > -- David- Hide quoted text -
>
> > - Show quoted text -
>
> This is exactly what I was looking for. Thanks.- Hide quoted text -
>
> - Show quoted text -

On second thought, that will generate one additional level. So it is
not what I am looking for.

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


how to tar with python

2007-08-24 Thread Brian McCann
Hi,
 
I'm trying to tar the contents of a directory "test" which contains
3 files foo1.xml ,foo2.xml, foo3.xml
 
in my current directory /home/pythonbox/tmp I have the directory "test"
 
if I run the below script it fails with the below error, but the files exist in 
the directory test
any help would be greatly appreciated
--Brian
 
##
[tmp]$ ./tarup.py
Traceback (most recent call last):
  File "./tarup.py", line 29, in ?
tfile .add(f)
  File "/usr/lib64/python2.4/tarfile.py", line 1229, in add
tarinfo = self.gettarinfo(name, arcname)
  File "/usr/lib64/python2.4/tarfile.py", line 1101, in gettarinfo
statres = os.lstat(name)
OSError: [Errno 2] No such file or directory: 'viz2.xml'

###
import string
import os
import shutil
import tarfile


tfile = tarfile.open("files.tar.gz", 'w:gz')
files = os.listdir("test")
for f in files:
tfile .add(f)
tfile.close
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression use

2007-08-24 Thread Bert Heymans
Nick,

In "Mastering Regular Expressions" by Jeffrey E. F. Friedl your
question is answered in the first 6 chapters. Seriously, that's what
it takes. It's a really good book.

Cheers

Bert

On Aug 24, 12:58 pm, [EMAIL PROTECTED] (Nick Maclaren) wrote:
> For reasons that I won't explain, as they are too complicated
> and not terribly relevant, I am interested in discovering what
> people actually use regular expressions for.  Not the subject
> domain, but the construction of the regular expressions.
>
> I know about computer scientists and parsing, and I know about
> the use of relatively simple ones for things like extracting
> HTML links from Web pages.  But I don't have much feel for the
> (probably rare but difficult) uses of more complex ones for
> other purposes.  I have heard of several such uses, but don't
> have an overall idea of what is going on.
>
> Any pointers appreciated, to more-or-less anything.
>
> Regards,
> Nick Maclaren.


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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Aahz
In article <[EMAIL PROTECTED]>,
Torsten Bronger  <[EMAIL PROTECTED]> wrote:
>Aahz writes:
>>
>> My point is that docutils already exists; given the combined
>> competition from LaTeX and docutils and OpenOffice, you should
>> probably explain what differentiates your project and why people
>> should support your project instead of (or in addition to) others.
>
>reStructuredText, AsciiDoc, and some others focus on source code
>documentation, or on software documentation.  In contrast to that,
>our markup should be suitable for PhD theses, papers and the like.
>Thus, it has weaker means for code snippets, RFC citation etc, but
>rich syntax for bibliographic entries, index entries, math, and
>floating figures.  

Enh.  reST is intended to be a general-purpose system.  It's certainly
extensible, and I've added code for index entries myself.  There has
been some recent activity on improving bibliographic support, and I
believe some people are working on integrating MathML.

>Additionally, input methods simplify using characters like δ, ⇒, or
>”.

"Everyone" says to just use a Unicode editor.  Long-term, I think that's
what's going to happen -- you're starting your project too late for this
to make much sense.

>The differences to LaTeX are explained comprehensively on the
>webpage, and actually LaTeX is the real competitor rather than
>reStructuredText.  OOo isn't a plain text format, and has no strong
>semantic markup.

Then you're really caught between a rock and a hard place.  LaTeX is
extremely well-entrenched; at the same time reST is gaining features.
You would probably make much better progress on your goals by simply
working on the reST project -- I doubt you can improve on reST as a
markup language, and the more you try to cram in, the more you're going
to look like LaTeX, anyway.

OTOH, this is Open Source, and nobody's going to stop you.  ;-)  I just
think you're also not going to get much traction.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Unequal Length Maze

2007-08-24 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hi All,
> what's the best algorithm to solve such problem ?
> http://www.stetson.edu/~efriedma/unequal/
> 
> I will really appreciate some pieces of code (python).

If you pay me 100$ (really a bargain), you get a solution in python.

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


Re: Unequal Length Maze

2007-08-24 Thread tomtim20
On Aug 24, 4:41 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
> > Hi All,
> > what's the best algorithm to solve such problem ?
> >http://www.stetson.edu/~efriedma/unequal/
>
> > I will really appreciate some pieces of code (python).
>
> If you pay me 100$ (really a bargain), you get a solution in python.
>
> Diez

What about Barack Obama Autographed Photo ?

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


Re: Regular expression use

2007-08-24 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
Mirco Wahab <[EMAIL PROTECTED]> writes:
|> 
|> Using complex regular expressions is like tank destruction
|> with contact charges glued on them.  Only a few people
|> will even survive the first "usage", but survivors will
|> then eventually be able to destroy almost every tank with
|> tremendous speed and precision.

I must remember that!  It is nicely put.

|> On business software projects, maintainability is a key
|> prerequisite - after using complex regular expressions
|> on business critical parts you are bound to involve
|> very very expensive maintenance programmers ... :)

Yes :-)  Even regular expression experts have major problems
ensuring that complicated ones match everything that they need
to and nothing that they don't.  The same thing applies to
uses of the C preprocessor and many uses of Perl 

|> What exactly did you "hear" of several "uses"?  Which
|> application? Academia, Business, ...?

Mainly academic research, but that still covers many fields.
However, I am not and never have been a 'pure' academic, and
am as interested in other uses as in academic research.


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


Re: creating a tar file with python

2007-08-24 Thread J. Cliff Dyer

Brian McCann wrote:

Hi,
 
I'm trying to create a tar file of the contents of the current directory
 
right now there is only one file "text.xml" in the current dir,  I'm 
using"." current dir as source

but that gives syntax error

any help would be greatly appreciated
--Brian
 
 
#!/usr/bin/python

import string
import os
import sys
import time
import errno
import shutil
import tarfile
 


tar = tarfile.open(.,"test.tar.gz", "w:gz)
 
Over the course of this thread, I found the following variations on one 
line of code.


Original problem code:   tar = tarfile.open(.,"test.tar.gz", "w:gz)
(missing quotes around arg[0], and at the end of arg[2])

SH's First solution:tar = tarfile(".", "test.tar.gz", "w:gz")
(quotes around everything, and tarfile.open() becomes tarfile())

OP's attempt at implementing 1st solution:tar = 
tarfile.open(".","test.tar.gz",w:gz)

(now the quotes are entirely missing around arg[2])

SH's concatenation into file what\ I\ wrote:  tar = tarfile(".", 
"test.tar.gz", w:gz")

(suddenly the quotes are missing from the beginning of arg[2])

Result from SH's diff: > tar = tarfile(".", "test.tar.gz", "w:gz")
(the quotes have magically returned).

Then the conversation devolves into grouchiness on both sides, until JM 
steps in with an entirely new solution. 

Sheesh.  Both of y'all needed to pay more attention to detail.  This is 
*one* line of code folks.  Better yet, get a decent editor that will do 
syntax highlighting, so you don't need to pay attention.  If quotes 
don't close, you need to know that.  Train yourself so that looking for 
unclosed quotes, parens, brackets, etc. becomes second nature.  And make 
sure you quote ALL strings.  Some languages are forgiving on this 
count.  Python is not.


Blessings to all, and may all find their good cheer restored by some 
rest.  I offer you both a virtual pint.  You seem like you could use it.


Cheers,
Cliff


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

Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread beginner
On Aug 24, 5:47 am, Paul Rubin  wrote:
> Boris Borcic <[EMAIL PROTECTED]> writes:
> > >> For example, if I have x=[ [1,2], [3,4] ]
>
> > >> What I want is a new list of list that has four sub-lists:
>
> > >> [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
> > > [[a, map(f,a)] for a in x]
>
> > no, that one will be [[[1,2], [f(1), f(2)]], [[3,4], [f(3), f(4)]]]
> > eg two sublists instead of four.
>
> Oh ugh, I misread the original request and thought the extra brackets
> were there.  I think the following works and is reasonably intuitive:
>
> from itertools import chain
> y = list(chain(*([a, map(f,a)] for a in x)))
>
> But the original request itself seems a bit weird.

Not so werid. :-) Just to put this into context, I have a list of list
of objects x=[[o1, o2, o3, o4], [o5,o6]]

I was trying to plot them with matplotlib. Each sub-list is a line. So
I would have to re-organize the list to be like the following:

v=[[o1.x, o2.x, o3.x, o4.x], [o1.y, o2.y, o3.y, o4.y], [o5.x, o6.x],
[o5.y, o6.y]]

So that I can pass it to plot:

plot(*tuple(v))

I like the chain and map solutions.

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread J. Robertson
olive wrote:

>>> [snip]

> 
> But few people are used to Plain Text Markup (excepted in some
> scientific area maybe) and it is error prone.
> 

It looks very much like Gummi's authors and target audience actually are 
part of the few people you are talking about: i.e. console-happy folks 
that are perfectly fine with how the math system goes in LaTeX, say, but 
are annoyed by the clutter besides that.  I can't imagine they would 
want to go anywhere near an equation editor, for example.

Looks like a worthwhile project to me :-)

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


Re: Unequal Length Maze

2007-08-24 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> On Aug 24, 4:41 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] schrieb:
>>
>>> Hi All,
>>> what's the best algorithm to solve such problem ?
>>> http://www.stetson.edu/~efriedma/unequal/
>>> I will really appreciate some pieces of code (python).
>> If you pay me 100$ (really a bargain), you get a solution in python.
>>
>> Diez
> 
> What about Barack Obama Autographed Photo ?

I'm living in germany, couldn't care less about USA presedential 
candidates.

If you want others to make your homework, you gotta pay.

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Torsten Bronger
Hallöchen!

David Boddie writes:

> On Fri Aug 24 11:04:33 CEST 2007, Torsten Bronger wrote:
>
>> Paul Rubin writes:
>> 
>>> TeX/LateX have been around forever and are well established
>>> standards, as awful as they are.  Why do we want ANOTHER markup
>>> language?
>> 
>> Well, because they are awful.  ;-) I don't see that there is a
>> bunch of already existing projects, in fact, I don't see anyone
>> challenging LaTeX at all.  However, competition is a good thing,
>> and I think there are enough aspects about LaTeX that can be done
>> better so that this project is worth being done.
>
> There are alternatives to LaTeX if you are prepared to look for
> them.  One of these is Lout:
>
>   http://lout.sourceforge.net/

I know Lout but its syntax is not simple enough to me.  Besides, it
does not enforce semantic markup.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression use

2007-08-24 Thread A.T.Hofkamp
On 2007-08-24, Nick Maclaren <[EMAIL PROTECTED]> wrote:
> people actually use regular expressions for.  Not the subject
> domain, but the construction of the regular expressions.

This is easy.
I use RE for checking whether some input matches a certain pattern, and
optionally, to extract some special part from the text.

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


Re: Socket recv(1) seems to block instead of returning end of file.

2007-08-24 Thread Grant Edwards
On 2007-08-24, Bryan Olson <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
> [...]
>> import socket,random
>> 
>> HOST = '' # Symbolic name meaning the local host
>> PORT = 8765   # Arbitrary non-privileged port
>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>> s.connect((HOST, PORT))
>
> Actually the empty string passed for the host means INADDR_ANY,

You're correct.  I copied that code from the server example on
the Python socket module doc page, and forgot to change the host.

  http://docs.python.org/lib/socket-example.html

> which does not really make sense for the client. On my Win-XP
> system, the client fails with
>
>socket.error: (10049, "Can't assign requested address")

It's interesting that it works on Linux.

> For the loop-back adapter, 'localhost' or '127.0.0.1' should
> work.

Yup.

-- 
Grant Edwards   grante Yow! YOU PICKED KARL
  at   MALDEN'S NOSE!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket recv(1) seems to block instead of returning end of file.

2007-08-24 Thread Hendrik van Rooyen
"Grant Edwards"  wrote:

> On 2007-08-23, Hendrik van Rooyen  wrote:
> 
> > While doing a netstring implementation I noticed that if you
> > build a record up using socket's recv(1), then when you close
> > the remote end down, the recv(1) hangs,
> 
> I don't see that behavior running 2.4 on Gentoo.

I express myself badly - when I say "close down" I don't mean
"close down as in socket.close" I mean "close down as in click on the
tkinter window, or with keyboard interrupt" - sorry for the confusion

> 
> > despite having a short time out of 0.1 set.
> 
> What time out?  A socket's recv method doesn't do timeouts.

If I set a time out, then the recv does not block,
but gives me a timed out exception.

> 
> > If however, you try to receive more than one char, (I tested
> > with 3, did not try 2), then when you shut the remote end down
> > you do not get a time out, but an empty string - the normal
> > end of file, I suppose.
> >
> > Has anybody else seen this behaviour?
> 
> No.  recv(1) works fine for me (Python 2.4 under Gentoo).
> Perhaps you could post a minimal example that doesn't work for
> you?

I am now frustrated - its not as simple as I thought - my application 
still only detects EOF if I do more than recv(1), but I cannot 
demonstrate simply - anyway, I have modified your code to look more 
like my program's code, and it follows below - if it does nothing else, 
it should convince you that recv() *does* time out...

The receiver code below detects if I close the sending console window, 
as well as control-c - Rats!

I will muck around with this more to see if I can get to the bottom of it,
as I can't see anything different between what is below and my program,
except that in both cases the comms are done in threads which are not
the main loop.

- Hendrik


#!/usr/bin/python

#reader
import socket

HOST = 'Linuxbox' # Symbolic name meaning the local host
PORT = 57001 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
socket.setdefaulttimeout(0.100)

s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
data = ''
while 1:
try:
data = data + conn.recv(1)
except socket.error,msg:
if 'timed out' in msg:
print msg
continue
else:
print 'socket error is',msg
break
if not data: break
if data.endswith('\n'):
print data
data = ''
print 'heigh ho the end has come!'
conn.close()






#!/usr/bin/python

# writer
import socket,time,random

HOST = 'Linuxbox' # Symbolic name meaning the local host
PORT = 57001 # Arbitrary non-privileged port
socket.setdefaulttimeout(0.100)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

while True:
try:
print 'Attempting to connect to server'
s.connect((HOST, PORT))
break
except socket.error, msg:
time.sleep(5)
continue
print 'Connected - Time out is:',s.gettimeout()

data = "The quick brown fox jumps over the lazy dog 0123456789\n"
count = 0
while count < 500:
try:
s.send(data)
except socket.error,msg:
if 'timed out' in msg:
print msg
time.sleep(0.05)
continue
else: 
print 'socket error is:',msg
break
print "tx:",len(data)
time.sleep(random.randint(200,800)/1000.0)
s.close()







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


Re: Socket recv(1) seems to block instead of returning end of file.

2007-08-24 Thread Hendrik van Rooyen
 "Dan Stromberg - Datallegro"  wrote:

> 
> Are you using sock.settimeout()?

Yes.

> 
> I've always done timed-out sockets in python using select; IINM, the
> settimeout method is a new addition.
> 
> I agree with Grant though - posting a minimal snippet of code that
> replicates the problem would help us help you.  In fact, it might help you
> help yourself :)

I will try - in the interim, please see my reply to Grant

 - Hendrik

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


Re: Socket recv(1) seems to block instead of returning end of file.

2007-08-24 Thread Hendrik van Rooyen
"Grant Edwards"  wrote:


> On 2007-08-23, Dan Stromberg - Datallegro  wrote:
> 
> > Are you using sock.settimeout()?
> 
> Hey, somebody snuck timeouts into the socket module when I wasn't
> looking...
> 
> > I agree with Grant though - posting a minimal snippet of code that
> > replicates the problem would help us help you.  In fact, it might help you
> > help yourself :)
> 
> Yup, in my experience attempting to produce a minimally failing
> example will usually reveal what's wrong.
> 

I am now extremely frustrated - I have spent most of the day mucking
around with this, and now I have managed to lose the version that
was giving me grief, and I can't remember what I have done.

At the moment everything works, and detects remote comm loss, 
no matter what I do.

So I must have done something stupid, and destroyed the evidence.

Some mothers have children.
Others have bad luck.

My apologies for chasing you up like that, and thanks to all who responded.

- Hendrik


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


csv module

2007-08-24 Thread luca72
Hello at all i have a problem with the csv module, really i don't
undestud the writerows:

if i have to write only one row i do as follow:
def scrivo_csv(self):
import csv
q_righe = self.tableWidget.rowCount()
for row in range(q_righe) :
e_vuota = self.tableWidget.item(row, 5)
if e_vuota == None :
ultima = row
break
writerdocs = open("some.csv", "wb")
scritt = csv.writer(writerdocs, delimiter='|')
q_colonne = self.tableWidget.columnCount()
ss = 0
while ss < row :
riga = []
for val in range(q_colonne):
esiste = self.tableWidget.item(ss, val)
if esiste == None :
luca = ''
else :
luca = str(QtGui.QTableWidgetItem.text(esiste))
riga.append(luca)
scritt.writerow(riga)
ss+=1
This work only with one row in the tablewidget, but if i have more
than one row how i have to proceed?

Thanks for the help

Luca

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


Re: Server-side scripting in python

2007-08-24 Thread Bruno Desthuilliers
olive a écrit :
>> Yes : have a look at Pylons too. It's actually quite less 'polished'
>> than Django, but it's IMHO going in the right direction (as a matter of
>> fact, Turbogears 2.0 - another well-known Python MVC framework -  will
>> be based on Pylons...). Django is clearly more oriented toward
>> content-management, which might not be what you want for this project.
> 
> this opinion about Django is a little bit dated

Possibly. I worked with pre 1.0 versions, then switched to other 
solutions (there were things I didn't like that much in Django... 
personal taste, not a criticism).

> 
> Django is really multi-purpose and is rarely use as a CMS,
(snip)
> I would use Plone instead as a general CMS.

I meant it was more oriented toward *building* CMS - not that it was a 
CMS by itself.

And as far as I'm concerned, I would not use Plone without *really* 
needing such a heavyweight thingie (and yes, I do have recent working 
experience with Plone...).


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


Re: creating a tar file with python

2007-08-24 Thread Ed Leafe
On Aug 23, 2007, at 11:27 PM, Brian McCann wrote:

> I ran the code as you suggested, didn't work, tried variations of  
> it didn't work,
> If you don't know the answer don't pretend you do!
>
> Apology not accepted, please don't wake up!
>
> Future correspondence on any python questions from you go to trash.
> May your pillow not have pity on your head!

What a tool.

Add another to the twit filter...

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


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


I can't get value of entry box, Tinker

2007-08-24 Thread Lamonte Harris
I tried w/ my following code:

from Tkinter import *

master = Tk()
Label(master, text="Username").grid(row=0, sticky=W)
Label(master, text="Password").grid(row=1, sticky=W)
e1 = Entry(master)
e2 = Entry(master,show="*")
def login():
global e2,e1
print e2
print e1
e3 = Button(master,text="Login",command=login).grid(row=3, sticky=W+E+S+N)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
master.mainloop()


it outputted something like:
.11972160
.11972080

What/should I, can I do?
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: creating a tar file with python

2007-08-24 Thread Carsten Haese
On Thu, 2007-08-23 at 23:27 -0400, Brian McCann wrote:
>  
> 
> Steve,
>  
> I ran the code as you suggested, didn't work, tried variations of it
> didn't work,
> If you don't know the answer don't pretend you do!
> 
> Apology not accepted, please don't wake up!
> 
> Future correspondence on any python questions from you go to trash.

You clearly have no idea who you're talking to. I suggest you Google for
'"Steve Holden" Python' to get a clue. Good luck finding any more help
here.

-Carsten



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


Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread ZeD
Boris Borcic wrote:

>>> For example, if I have x=[ [1,2], [3,4] ]
>>> What I want is a new list of list that has four sub-lists:
>>> [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
>> [[a, map(f,a)] for a in x]
> [map(g,a) for a in x for g in [None,f]]
> will do it.
> 
> ...a bit too cleverly, but there's worse :
> list((yield a) or map(f,a) for a in x)

worse (in *many* ways) solutions:

l = [[a, map(f,a)] for a in x]

1) s = sum(l, [])

2) from operator import add
   r = reduce(add, l, [])

3) a = []
   for e in l: a.extend(e)

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


Re: python setup.py: how to override a setup.cfg value ?

2007-08-24 Thread Michael Ströder
Chris Shenton wrote:
> I'm building python-ldap and need to change values of library and
> include paths that are in the setup.cfg file.  This is an automated
> build (using "buildit") so I'd prefer not to have edit the .cfg by hand,
> with sed, or even with buildit's Substitute().

Almost everything in python-ldap's setup.cfg is subject to local system
configuration. The default shipped in source distribtion has to be
tweaked on most systems (examples: Build/setup.cfg.*). Therefore I don't
understand why you don't just provide your own setup.cfg reflecting your
OpenLDAP/OpenSSL/Cyrus-SASL/Kerberos installation.

I don't know anything about "buildit" though.

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


Re: creating a tar file with python

2007-08-24 Thread Ed Leafe
On Aug 24, 2007, at 11:24 AM, Carsten Haese wrote:

> You clearly have no idea who you're talking to. I suggest you  
> Google for
> '"Steve Holden" Python' to get a clue. Good luck finding any more help
> here.

Even if it were Joe Nobody to whom he was directing those comments,  
it was *way* out of line. The fact that it was Steve only reinforces  
the cluelessness of the writer.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


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


Re: Regular expression use

2007-08-24 Thread Larry W. Virden
On Aug 24, 6:58 am, [EMAIL PROTECTED] (Nick Maclaren) wrote:
> I am interested in discovering what
> people actually use regular expressions for.

Hmm - let's see. I tend to use regular expressions when I am writing
code that needs to search through output to find certain patterns. I
also use them to convert text in one format into another format. I
also frequently use them to validate input - if I need input to be all
alphabetics, or a properly formatted floating point number, etc.

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


Re: Socket recv(1) seems to block instead of returning end of file.

2007-08-24 Thread Grant Edwards
On 2007-08-24, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> "Grant Edwards"  wrote:
>
>> On 2007-08-23, Hendrik van Rooyen  wrote:
>> 
>> > While doing a netstring implementation I noticed that if you
>> > build a record up using socket's recv(1), then when you close
>> > the remote end down, the recv(1) hangs,
>> 
>> I don't see that behavior running 2.4 on Gentoo.
>
> I express myself badly - when I say "close down" I don't mean
> "close down as in socket.close" I mean "close down as in click on the
> tkinter window, or with keyboard interrupt" - sorry for the confusion

A FIN is a FIN is a FIN.  It shouldn't matter whether the app
called close() or the c library called close() or the OS called
close().

>> > despite having a short time out of 0.1 set.
>> 
>> What time out?  A socket's recv method doesn't do timeouts.
>
> If I set a time out, then the recv does not block,
> but gives me a timed out exception.

My aplogies -- my question was prompted by my ignorance of the
fact that a timeout feature had been added to the socket module
since the last time I worked on it.

> I am now frustrated - its not as simple as I thought - my
> application still only detects EOF if I do more than recv(1),
> but I cannot demonstrate simply - anyway, I have modified your
> code to look more like my program's code, and it follows below
> - if it does nothing else, it should convince you that recv()
> *does* time out...

Yes.

> The receiver code below detects if I close the sending console window, 
> as well as control-c - Rats!

Same here.

-- 
Grant Edwards   grante Yow! Am I having fun yet?
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating a tar file with python

2007-08-24 Thread kyosohma
On Aug 24, 10:33 am, Ed Leafe <[EMAIL PROTECTED]> wrote:
> On Aug 24, 2007, at 11:24 AM, Carsten Haese wrote:
>
> > You clearly have no idea who you're talking to. I suggest you
> > Google for
> > '"Steve Holden" Python' to get a clue. Good luck finding any more help
> > here.
>
> Even if it were Joe Nobody to whom he was directing those comments,
> it was *way* out of line. The fact that it was Steve only reinforces
> the cluelessness of the writer.
>
> -- Ed Leafe
> --http://leafe.com
> --http://dabodev.com

Where is this guy posting his code? I see a lot of responses from
Steve and Gabriel to posts that never seem to begin anywhere. Are
these posts originating from the noob python list and somehow getting
cross-posted here?

I like Steve, but he seems pretty crabby/rude much of the time.

Mike

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


RE: creating a tar file with python

2007-08-24 Thread Brian McCann
I don't care if Steve Holden is the python God himself,
He's a rude, arrogant, vulgar human who shows his true level
of intellect by his use of profanity


And he goes one level lower stating he respects the python group
he spews his profanity to

He chose to respond to my question, no one dragged him out of bed
as hi so quickly pointed out. Re-read the thread!



If your three chums are indicative to the type of people in this group
Python is in sorry state

 

 

 
 
 



From: [EMAIL PROTECTED] on behalf of Ed Leafe
Sent: Fri 8/24/2007 11:33 AM
To: Carsten Haese
Cc: python-list@python.org
Subject: Re: creating a tar file with python



On Aug 24, 2007, at 11:24 AM, Carsten Haese wrote:

> You clearly have no idea who you're talking to. I suggest you 
> Google for
> '"Steve Holden" Python' to get a clue. Good luck finding any more help
> here.

Even if it were Joe Nobody to whom he was directing those comments, 
it was *way* out of line. The fact that it was Steve only reinforces 
the cluelessness of the writer.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


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


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

How to replace a method in an instance.

2007-08-24 Thread Steven W. Orr
In the program below, I want this instance to end up calling repmeth 
whenever inst.m1 is called. As it is now, I get this error:

Hello from init
inst =  <__main__.CC instance at 0x402105ec>
Traceback (most recent call last):
   File "./foo9.py", line 17, in ?
 inst.m1()
TypeError: repmeth() takes exactly 1 argument (0 given)


#! /usr/bin/python
def repmeth( self ):
 print "repmeth"

class CC:
 def __init__( self ):
 self.m1 = repmeth
 print 'Hello from init'

 def m1 ( self ):
 print "m1"

inst = CC()
inst.m1()

TIA

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Co-developers wanted: document markup language

2007-08-24 Thread Jeremy Sanders
Torsten Bronger wrote:

> Some LaTeX users in Aachen thought about a general-use markup
> language this spring.  I wrote some code and a rough project
> description, however, we could need some help.
> 
> If you are interested, visit the provisional project page at
> http://latex-bronger.sourceforge.net/gummi/

Sounds a good idea - LaTeX has so many historical hangovers. How many people
on earth can actually write a LaTeX style file?

I'm not sure about writing LaTeX output, however, due to the crude nasty
ways it handles fonts and so on. How are you going to get enough controls
for users over what they always complain about: fonts, page breaking, and
positioning of figures? Maybe it's an okay first step however.

Jeremy

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


Re: Co-developers wanted: document markup language

2007-08-24 Thread Torsten Bronger
Hallöchen!

Aahz writes:

> Torsten Bronger  <[EMAIL PROTECTED]> wrote:
>
>> [...]
>>
>> reStructuredText, AsciiDoc, and some others focus on source code
>> documentation, or on software documentation.  In contrast to
>> that, our markup should be suitable for PhD theses, papers and
>> the like.  Thus, it has weaker means for code snippets, RFC
>> citation etc, but rich syntax for bibliographic entries, index
>> entries, math, and floating figures.
>
> Enh.  reST is intended to be a general-purpose system.  It's
> certainly extensible, and I've added code for index entries
> myself.

I like reST very much, and it is used for all documentation in the
"Gummi" source files.  I could probably use it as a starting point
for the features that I want but the same is true for AsciiDoc or
MediaWiki.  I doubt, however, that the resulting syntax is what I
want (see below).

> There has been some recent activity on improving bibliographic
> support, and I believe some people are working on integrating
> MathML.

But I hope only for the backend side?

>> Additionally, input methods simplify using characters like δ,
>> ⇒, or ”.
>
> "Everyone" says to just use a Unicode editor.  Long-term, I think
> that's what's going to happen -- you're starting your project too
> late for this to make much sense.

Well, your newsreader failed to specify UTF-8, and my newsreader
failed to do a proper auto-detect.  So, Unicode has not arrived yet.
;-)

Seriously: Most people can't enter those characters.  In LaTeX, you
can use many Unicode characters directy for years, however, only few
documents make use of this.  To most people, it's probably simpler
to write \alpha than to find and use the Unicode-insertion tool of
their editor.

> [...]
>
> Then you're really caught between a rock and a hard place.  LaTeX
> is extremely well-entrenched;

But only in a small group (compared to Word for example).

The main motivation of our group was to see that many people stay
away from LaTeX because it is too complicated.  The basic assertion
of our project is that this complexity is not necessary while still
maintaining important features of LaTeX (plain text file format,
semantic markup).  It is a tradeoff, though: You give up a lot of
flexibility.  However, I think that this particular type of
flexibility (namely, local layout tweaking) is of minor
importance.

Probably one important thing that didn't get through yet is that we
try to get people to semantic markup who don't come from engineering
or science.  These are heavily under-represented in the LaTeX
community.  "Gummi" (or however we'll call it) is not supposed to be
another Geek language.  On the contrary, our goal is that even a
typical linguistics student loves to write their seminar paper with
"Gummi".

Reading only forums and newsgroups, one may think that this is
impossible but in real life, I've seen more people using LaTeX
exactly once and never again than people who keep using it.  If I
look at typical modern LaTeX preambles, I know what went wrong, so I
see a lot of potential.

However, then a very defensively constructed syntax is crucial, and
everything must just work -- without having to use a tool chain or
declaring things before you can use them.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: creating a tar file with python

2007-08-24 Thread Brian McCann
Ed, Carsten, Steve,
 
I don't care if  Steve Holden is the python God himself,
He's a rude, arrogant, vulgar human who shows his true level
of intellect by his use of profanity


And he goes one level lower, stating he respects the python group
he spews his profanity to.

He chose to respond to my question, no one dragged him out of bed,
as he so quickly pointed out. Re-read the thread!



If your three chums are indicative to the type of people in this group
Python is in sorry state

 

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

Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread Eduardo O. Padoan
> For example, if I have x=[ [1,2], [3,4] ]
>
> What I want is a new list of list that has four sub-lists:
>
> [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]

[[a, [f(b) for b in a]] for a in x]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to replace a method in an instance.

2007-08-24 Thread kyosohma
On Aug 24, 11:02 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> In the program below, I want this instance to end up calling repmeth
> whenever inst.m1 is called. As it is now, I get this error:
>
> Hello from init
> inst =  <__main__.CC instance at 0x402105ec>
> Traceback (most recent call last):
>File "./foo9.py", line 17, in ?
>  inst.m1()
> TypeError: repmeth() takes exactly 1 argument (0 given)
>
> #! /usr/bin/python
> def repmeth( self ):
>  print "repmeth"
>
> class CC:
>  def __init__( self ):
>  self.m1 = repmeth
>  print 'Hello from init'
>
>  def m1 ( self ):
>  print "m1"
>
> inst = CC()
> inst.m1()
>
> TIA
>
> --
> Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
> happened but none stranger than this. Does your driver's license say Organ ..0
> Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
> individuals! What if this weren't a hypothetical question?
> steveo at syslang.net

Remove "self" from repmeth as it's not required in a function, only in
functions that are defined within a class. Of course, a function in a
class is also know as a method.

Mike

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


Re: How to replace a method in an instance.

2007-08-24 Thread Steven W. Orr
On Friday, Aug 24th 2007 at 09:12 -0700, quoth [EMAIL PROTECTED]:

=>On Aug 24, 11:02 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
=>> In the program below, I want this instance to end up calling repmeth
=>> whenever inst.m1 is called. As it is now, I get this error:
=>>
=>> Hello from init
=>> inst =  <__main__.CC instance at 0x402105ec>
=>> Traceback (most recent call last):
=>>File "./foo9.py", line 17, in ?
=>>  inst.m1()
=>> TypeError: repmeth() takes exactly 1 argument (0 given)
=>>
=>> #! /usr/bin/python
=>> def repmeth( self ):
=>>  print "repmeth"
=>>
=>> class CC:
=>>  def __init__( self ):
=>>  self.m1 = repmeth
=>>  print 'Hello from init'
=>>
=>>  def m1 ( self ):
=>>  print "m1"
=>>
=>> inst = CC()
=>> inst.m1()

=>Remove "self" from repmeth as it's not required in a function, only in
=>functions that are defined within a class. Of course, a function in a
=>class is also know as a method.

Sorry. I need repmeth to have self passed to it automatically if it's 
called. I didn't mean to obfuscate the problem by not making a reference 
to self in repmeth. 

Am I being clear?

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Steve Holden is a moronic, self-indulgent BASTARD [WAS: Re: creating a tar file with python]

2007-08-24 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote:
> I like Steve, but he seems pretty crabby/rude much of the time.
>   

Now what is going on here? I've been on this list for quite some time 
now and over all of Steves very frequent posts this is the first thread 
that I recall in which he sort of snapped. All of the other times he 
managed insults with admirable grace (How's that for fan-mail? ;)). And 
his tone is usually much milder than that of most other regulars here 
(all of whom are very friendly albeit the concise, technical manner of 
communication, sprinkled of course with the occasional sarcastic remark).

Steve, you might want to consider becoming more rude in your 
communication style; that way you don't get flamed for that *one time* 
you actually loose your cool. ;)

Rhetorical closing-questions: Do people start flame wars like this so 
easily in the real world as well? Why do internet-discussions tend to 
burst into all-out battles so quickly? Why do people on the net tend to 
forget that a 1--10 scale actually contains 2--9?

*sigh*
/W
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I know almost all basics

2007-08-24 Thread Terry Reedy

"Lamonte Harris" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Now I'm moving more into the gaming world.  What libs/modules would you
| recommend?

One of the basics is learning to use search engines.
Try 'Python game programming' with Google, for instance. 



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


Re: How to replace a method in an instance.

2007-08-24 Thread Wildemar Wildenburger
Steven W. Orr wrote:
> Sorry. I need repmeth to have self passed to it automatically if it's 
> called. I didn't mean to obfuscate the problem by not making a reference 
> to self in repmeth. 
>
> Am I being clear?
>
>   
Sort of. Maybe you fare better if you state what you want to achieve, 
instead of how you think you should do it. Chances are you don't need to 
replace a method in __init__, but there's another, less tricky way.

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


Re: Regular expression use

2007-08-24 Thread brad
Nick Maclaren wrote:
> For reasons that I won't explain, as they are too complicated
> and not terribly relevant, I am interested in discovering what
> people actually use regular expressions for.

Finding credit card numbers in files...among other things:

http://filebox.vt.edu/users/rtilley/public/find_ccns/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to replace a method in an instance.

2007-08-24 Thread James Stroud
Steven W. Orr wrote:
> On Friday, Aug 24th 2007 at 09:12 -0700, quoth [EMAIL PROTECTED]:
> 
> =>On Aug 24, 11:02 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> =>> In the program below, I want this instance to end up calling repmeth
> =>> whenever inst.m1 is called. As it is now, I get this error:
> =>>
> =>> Hello from init
> =>> inst =  <__main__.CC instance at 0x402105ec>
> =>> Traceback (most recent call last):
> =>>File "./foo9.py", line 17, in ?
> =>>  inst.m1()
> =>> TypeError: repmeth() takes exactly 1 argument (0 given)
> =>>
> =>> #! /usr/bin/python
> =>> def repmeth( self ):
> =>>  print "repmeth"
> =>>
> =>> class CC:
> =>>  def __init__( self ):
> =>>  self.m1 = repmeth
> =>>  print 'Hello from init'
> =>>
> =>>  def m1 ( self ):
> =>>  print "m1"
> =>>
> =>> inst = CC()
> =>> inst.m1()
> 
> =>Remove "self" from repmeth as it's not required in a function, only in
> =>functions that are defined within a class. Of course, a function in a
> =>class is also know as a method.
> 
> Sorry. I need repmeth to have self passed to it automatically if it's 
> called. I didn't mean to obfuscate the problem by not making a reference 
> to self in repmeth. 

At least you are consistent in that you obfuscate every question.

Here's what you seem to want:



import types

def repmeth(self):
   print "repmeth"

# inherit from object!
class CC(object):
   def __init__(self):
 self.m1 = types.MethodType(repmeth, self)
 print 'Hello from init'
   def m1(self):
 print 'm1'

inst = CC()
inst.m1()



Output:

py> import types
py>
py> def repmeth(self):
...   print "repmeth"
...
py> # inherit from object!
py> class CC(object):
...   def __init__(self):
... self.m1 = types.MethodType(repmeth, self)
... print 'Hello from init'
...   def m1(self):
... print 'm1'
...
py> inst = CC()
Hello from init
py> inst.m1()
repmeth



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


GUI and distrubution

2007-08-24 Thread anders
I have looked att Python on www.showmedo.com
And after this i start testing writing som program i Python.
But...

So how is the preferably way to distribute software written i Python
i am NOT into hiding stuff, more a easy way of giving eg friends
a copy of the program without having them installtion a lott
och other stuff.

My next question is witch is the best GUI to use, also consider
the delivery question above.

// Anders

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


Re: Regular expression use

2007-08-24 Thread Simon Brunning
On 24 Aug 2007 10:58:46 GMT, Nick Maclaren <[EMAIL PROTECTED]> wrote:
>
> For reasons that I won't explain, as they are too complicated
> and not terribly relevant, I am interested in discovering what
> people actually use regular expressions for.

http://xkcd.com/208/

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How would I compile a Python file to a exe

2007-08-24 Thread vasudevram
On Aug 24, 2:11 am, Charlie <[EMAIL PROTECTED]> wrote:
> Quoting Lamonte Harris <[EMAIL PROTECTED]>:
>
> > Been a while and I'm wondering how I would go about doing it.
>
> py2exe seems to be a fairly good option for this, at least in the
> world of Windows.

Yes, py2exe looks good. I've tried it out. Make sure to test for the
cases you'll need, though.

- Vasudev
-
Vasudev Ram
http://www.dancingbison.com
http://jugad.livejournal.com
http://sourceforge.net/projects/xtopdf
-

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


Fwd: How would I compile a Python file to a exe

2007-08-24 Thread Lamonte Harris
I thought I answered this lol..

-- Forwarded message --
From: vasudevram <[EMAIL PROTECTED]>
Date: Aug 24, 2007 11:56 AM
Subject: Re: How would I compile a Python file to a exe
To: python-list@python.org

On Aug 24, 2:11 am, Charlie <[EMAIL PROTECTED]> wrote:
> Quoting Lamonte Harris <[EMAIL PROTECTED]>:
>
> > Been a while and I'm wondering how I would go about doing it.
>
> py2exe seems to be a fairly good option for this, at least in the
> world of Windows.

Yes, py2exe looks good. I've tried it out. Make sure to test for the
cases you'll need, though.

- Vasudev
-
Vasudev Ram
http://www.dancingbison.com
http://jugad.livejournal.com
http://sourceforge.net/projects/xtopdf
-

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

Re: Regular expression use

2007-08-24 Thread Wildemar Wildenburger
Simon Brunning wrote:
> On 24 Aug 2007 10:58:46 GMT, Nick Maclaren <[EMAIL PROTECTED]> wrote:
>   
>> For reasons that I won't explain, as they are too complicated
>> and not terribly relevant, I am interested in discovering what
>> people actually use regular expressions for.
>> 
>
> http://xkcd.com/208/
>
>   
That was the one that got me hooked on xkcd. I remember laughing so hard 
at that. A friend and I still quote that one (and others).

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



Re: Using Regular Expresions to change .htm to .php in files

2007-08-24 Thread J. Cliff Dyer

Tim Williams wrote:

On 23/08/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
  

Hi,

I have a bunch of files that have changed from standard htm files to
php files but all the links inside the site are now broken because
they point to the .htm files while they are now .php files.

Does anyone have an idea about how to do a simple script that changes
each .htm in a given file to a .php

Thanks a lot in advance




Something like:

Infile = open(f_name,'r+')
Data =  Infile.read()
InFile.write(Data.replace('.htm','.php'))
Infile.close()

:)
  
Yeah, but you'd better make darn sure that *all* links point to .htm 
files (including external links), because you could very easily end up 
pointing to http://some.othersite.com/index.phpl


And that's just no good.

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

Re: online doc bug

2007-08-24 Thread O.R.Senthil Kumaran
> hyperlink "site module documentation" in   Section 4.1  on page
> http://docs.python.org/inst/search-path.html  leads to a nonexistent
> page.

Thank you. Submitted the report and patch at:
http://bugs.python.org/issue1012

-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to replace a method in an instance.

2007-08-24 Thread Steven W. Orr
On Friday, Aug 24th 2007 at 12:26 -0400, quoth Steven W. Orr:

=>On Friday, Aug 24th 2007 at 09:12 -0700, quoth [EMAIL PROTECTED]:
=>
=>=>On Aug 24, 11:02 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
=>=>> In the program below, I want this instance to end up calling repmeth
=>=>> whenever inst.m1 is called. As it is now, I get this error:
=>=>>
=>=>> Hello from init
=>=>> inst =  <__main__.CC instance at 0x402105ec>
=>=>> Traceback (most recent call last):
=>=>>File "./foo9.py", line 17, in ?
=>=>>  inst.m1()
=>=>> TypeError: repmeth() takes exactly 1 argument (0 given)
=>=>>
=>=>> #! /usr/bin/python
=>=>> def repmeth( self ):
=>=>>  print "repmeth"
=>=>>
=>=>> class CC:
=>=>>  def __init__( self ):
=>=>>  self.m1 = repmeth
=>=>>  print 'Hello from init'
=>=>>
=>=>>  def m1 ( self ):
=>=>>  print "m1"
=>=>>
=>=>> inst = CC()
=>=>> inst.m1()
=>
=>=>Remove "self" from repmeth as it's not required in a function, only in
=>=>functions that are defined within a class. Of course, a function in a
=>=>class is also know as a method.
=>
=>Sorry. I need repmeth to have self passed to it automatically if it's 
=>called. I didn't mean to obfuscate the problem by not making a reference 
=>to self in repmeth. 
=>
=>Am I being clear?

On Friday, Aug 24th 2007 at 18:44 +0200, quoth Wildemar Wildenburger:

=>Steven W. Orr wrote:
=>> Sorry. I need repmeth to have self passed to it automatically if it's
=>> called. I didn't mean to obfuscate the problem by not making a 
reference
=>> to self in repmeth.
=>>
=>> Am I being clear?
=>>
=>>
=>Sort of. Maybe you fare better if you state what you want to achieve,
=>instead of how you think you should do it. Chances are you don't need to
=>replace a method in __init__, but there's another, less tricky way.
  
Ok. I have a collection of classes that are produced by a factory. They   
all inherit from a baseclass. One (maybe more) of the classes inherits a  
method that he shouldn't. All I want is to be able to change that
particular class so that he will have the special method that he needs
instead of the default one that he inherits. I was thinking that instead 
of making a special class for CC to inherit from which would give him his 
special replacement method(s), I could simply assign them in a manner 
which would more easily lend itself to later being table driven.

If I had a choice, I'd rather not do it in init. Instead, I'd rather be 
able to say something like 
CC.m1 = repmeth
but since in the real world, CC inherits from his baseclass, the above 
assignment causes the baseclass to be altered. :-(

Please tell me if I need to provide more.

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I can't get value of entry box, Tinker

2007-08-24 Thread Matt McCredie
> What/should I, can I do?

Fix your code?

> def login():
> global e2,e1
> print e2.get()
> print e1.get()

That should work.

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


Re: optparse - required options

2007-08-24 Thread Robert Dailey
Thank you VERY much for mentioning argparse- this is EXACTLY what I needed!
Thank you!

On 8/23/07, Steven Bethard <[EMAIL PROTECTED]> wrote:
>
> Omari Norman wrote:
> > On Mon, Aug 20, 2007 at 05:31:00PM -0400, Jay Loden wrote:
> >> Robert Dailey wrote:
> >>> Well, I don't know what is wrong with people then. I don't see how
> >>> required arguments are of bad design.
> >
> >> I tend to agree...while "required option" may be an oxymoron in
> >> English, I can think of quite a few scripts I've written myself (in
> >> various languages) that needed at least some kind of user input to
> >> operate.
> >
> > The idea with optparse is not that programs should not require certain
> > information on the command line; rather, the idea is that this
> > information should be positional arguments, not 'options'.
> >
> > That is, to use the compiler example:
> >
> > compiler file
> >
> > is preferred if a file argument is necessary.
> >
> > compiler --file file
> >
> > is not preferred.
>
> I agree with the optparse philosophy, but Practicality Beats Purity.
> That's why I was convinced to add "required options" to argparse --
> there are too many applications that want that kind of interface.
> *I* don't write applications with interfaces like that, but enough
> people do that the use case should really be supported.
>
> STeVe
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: GUI and distrubution

2007-08-24 Thread Kevin Walzer
anders wrote:

> So how is the preferably way to distribute software written i Python

> My next question is witch is the best GUI to use, also consider
> the delivery question above.
>

These are two of the most-often-asked questions on this list (along with 
"What's the best Python IDE?"). Search the list archives via Google, or 
do a general Google search. Some helpful terms to get you started 
include pyinstaller, py2exe, py2app, Tkinter, wxPython, PyQt, and pyGTK.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


question

2007-08-24 Thread JYOUNG79
Still trying to learn Python and was hoping some of you might be able to give 
me some advice 
on my code 
below.  It works but I'm wondering if there's more efficient ways of doing this 
than the way 
I've done it.

The first step is I have to loop thru nested folders and find all files that 
start with "LOGO".  So 
I use Unix's 'find' 
and write all the paths out to a text file like so:

find ~/Desktop/logoFiles/ -type f -iname "LOGO*" > 
~/Desktop/logo_stuff/paths.txt"

Next, I use Python (code below) to look thru each paragraph of that file 
(paths.txt).  While 
looping thru each 
paragraph, I want to first make sure that the folder name that the file is in 
is a number.  For 
example, if it found 
file 'LOGO9012', then I'd want to make sure the folder name that this file was 
in was a 
number (~/Desktop/
logoFiles/12/LOGO9012).  If that's ok then I grab the number off the file name. 
 If there's not 
a number in the 
file name then I ignore it.  I then create a dictionary that has a key which 
equals the number I 
grabbed from the 
file name and then the value contains the full file path (that I grabbed out of 
the text file) 
followed by a 
delimiter (<::>) followed by 'LOGO' and the number I got from the file name 
(making sure to 
keep any leading 
zeroes if they were there originally).  Finally, I sort the keys in numerical 
order and save out a 
file with all the 
appropriate info from my dictionary (which will be a list of paths followed by 
a delimiter and 
file name).  Here's 
an example of what this new file might contain:

/Users/jyoung1/Desktop/logoFiles/02/Logo002<::>LOGO002
/Users/jyoung1/Desktop/logoFiles/02/LOGO102<::>LOGO102
/Users/jyoung1/Desktop/logoFiles/02/LOGO302<::>LOGO302
/Users/jyoung1/Desktop/logoFiles/9/LOGO462.2PMS<::>LOGO462


Anyway, if anyone has time to look at this I'd appreciate your thoughts.  
Thanks!

Jay

#!/usr/bin/python

import re

dList = {}
sortedList = ""

pathFile = open("~/Desktop/logo_stuff/paths.txt", "r")

for x in pathFile:
  if len(re.findall(r"^\d+$", x.split("/")[-2])) > 0:  #make sure folder name 
is a number
n = re.findall(r"\d+", x.split("/")[-1])   #Grab number off file name
if len(n) > 0: dList[int(n[0])] = x[:-1] + "<::>LOGO" + n[0] + "\n"

pathFile.close()

keyList = dList.keys()
keyList.sort()

for x in keyList:
  sortedList += dList[x]

newFile = open("~/Desktop/logo_stuff/sortedPaths.txt", "w")
newFile.write(sortedList)
newFile.close()



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


Re: How to replace a method in an instance.

2007-08-24 Thread James Stroud
Steven W. Orr wrote:
> Ok. I have a collection of classes that are produced by a factory.  They
> all inherit from a baseclass. One (maybe more) of the classes inherits a  
> method that he shouldn't. All I want is to be able to change that
> particular class so that he will have the special method that he needs
> instead of the default one that he inherits. I was thinking that instead 
> of making a special class for CC to inherit from which would give him his 
> special replacement method(s), I could simply assign them in a manner 
> which would more easily lend itself to later being table driven.
> 
> If I had a choice, I'd rather not do it in init. Instead, I'd rather be 
> able to say something like 
> CC.m1 = repmeth
> but since in the real world, CC inherits from his baseclass, the above 
> assignment causes the baseclass to be altered. :-(
> 
> Please tell me if I need to provide more.


def f1(self):
   print 'f1'

def f2(self):
   print 'f2'

def classfactory(replacements=None):
   class _C(object):
 def doit(self):
   print 'doit'
 def doit2(self):
   print 'doit2'
   if replacements is not None:
 for fname, f in replacements.items():
   setattr(_C, fname, f)
   return _C

Aclass = classfactory()
Aclass().doit()

Aclass2 = classfactory({'doit':f1, 'doit2':f2})
Aclass().doit2()
Aclass2().doit2()



Here's the output:


py> def f1(self):
...   print 'f1'
...
py> def f2(self):
...   print 'f2'
...
py> def classfactory(replacements=None):
...   class _C(object):
... def doit(self):
...   print 'doit'
... def doit2(self):
...   print 'doit2'
...   if replacements is not None:
... for fname, f in replacements.items():
...   setattr(_C, fname, f)
...   return _C
...
py> Aclass = classfactory()
py> Aclass().doit()
doit
py>
py> Aclass2 = classfactory({'doit':f1, 'doit2':f2})
py> Aclass().doit2()
doit2
py> Aclass2().doit2()
f2


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


  1   2   >