Re: Opening Photoshop EPS with PIL?

2007-04-03 Thread [EMAIL PROTECTED]
On Apr 1, 12:01 pm, "Méta-MCI" <[EMAIL PROTECTED]>
wrote:
> .eps  ==> vector ; not bitmap

I was under the impression that .eps could be opened with PIL (and by
the way, their contents are actually raster (but with a work path
which shouldn't be displayed anyway)

Any ideas?

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


Re: python on mac os 10.4.x

2007-04-03 Thread martin . laloux
Go to http://wiki.python.org/moin/MacPython and http://pythonmac.org/packages/
if you want to download  macpython 2.5 or macpython 2.4.4 ("framework"
builds). Installation is very easy (package) and you have all you want
without problem with the 2.3.5 version wich  remains installed and
functional (you have 2 python installed)

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


Re: pyc file [Newbie Question]

2007-04-03 Thread Steven D'Aprano
On Mon, 02 Apr 2007 23:44:41 -0700, Jim Aikin wrote:

> Working through the tutorial, I created a file called fibo.py in my text 
> editor, and imported it into Idle. It worked as expected. I then edited the 
> file and resaved it. I used del fibo, followed by import fibo.

That probably won't cause a full re-import. del fibo will only delete the
reference called "fibo". The underlying module object will still exist
until it is garbage-collected. It will only be garbage-collected if it
isn't being used. Chances are, the module *is* being used somewhere, so
when you call "import fibo" the import machinery simply gives you a new
reference to the old module object.

The correct way to do what you want is to simply say "reload(fibo)".

But don't forget that any old objects from the module will NOT pick up the
new behaviour. They will keep their old behaviour, so after a reload() you
have to recreate all the objects you created.

For example:


import fibo # imports the module as it exists *now*
x = fibo.SomeClass()
# x is an instance defined in fibo

# now edit the fibo module and change the behaviour of SomeClass

reload(fibo)

# now the module fibo has picked up the new behaviour
# but the object x still has the code belonging to the OLD module
x = fibo.SomeClass() # recreate x with new code


[snip]
 
> One point of possible confusion here is in the line in the following 
> paragraph of 6.1.2, "Whenever spam.py is successfully compiled" My 
> question is, is it compiled when being imported? I didn't spot any mention 
> in the Tutorial of when or how a .py file might be (or would automatically 
> be) compiled, so I'm assuming that it's automatically compiled while being 
> imported. If this is a bad assumption, then maybe it's the root of my 
> misunderstanding. Maybe I have to _do_ something to fibo.py in order to 
> create a new version of fibo.pyc.

Just import it, or reload().


-- 
Steven D'Aprano 

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


Re: Tkinter <> and bindtags ordering

2007-04-03 Thread Rob Wolfe

bytecolor wrote:

[...]

> changing = False
> root = tk.Tk()
> t = tk.Text(master=root)
> t.pack()
> t.focus_set()
> t.tk.call(t._w, 'edit', 'modified', 0)

What about instead of:

> t.bind('<>', text_changed)

this event:

   t.bind('', text_changed)

> root.mainloop()

--
HTH,
Rob

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


Re: doing standart window icons unvisible in python

2007-04-03 Thread Tim Golden
gslm wrote:
> Hi!
> I want to do close-minimize icons unvisible in python.How can I do
> this?I want to do this especially for printing.
> And is it possible to provide .exe file for any program in python or
> only we can change the file as .pyw?

I *think* -- and it's a bit hard to tell from your
description -- that you want to print the client
area of a window, and not the non-client area
(which includes the max/min/close buttons).

A lot depends on whether it's your window or
someone else's. If it's yours, then you have some
control over the styling and do at least have the
window handle available to you. If it's someone
else's, you have to employ some fairly dark magic
to do what I think you want.

Depending on what you're after, you might find
the PIL ImageGrab module at least a useful tool:

http://www.pythonware.com/library/pil/handbook/imagegrab.htm

But could you be more precise as to what you're
trying to do?

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


Re: Generic logic/conditional class or library for classification of data

2007-04-03 Thread [EMAIL PROTECTED]
On Apr 3, 5:43 am, "Basilisk96" <[EMAIL PROTECTED]> wrote:
> Thanks for the help, guys.
> Dictionaries to the rescue!
>
> Steven, it's certainly true that runtime creation of attributes does
> not fit well here. At some point, an application needs to come out of
> generics and deal with logic that is specific to the problem. The
> example I gave was classification of books, which is relatively easy
> to understand. The particular app I'm working with deals with
> specialty piping valves, where the list of rules grows complicated
> fairly quickly.
>
> So, having said that "attributes are not known at design time", it
> seems that dictionaries are best for the generic core functionality:
> it's easy to iterate over arbitrary "key, value" pairs without
> hiccups. I can even reference a custom function by a key, and call it
> during the iteration to do what's necessary. The input/output
> dictionaries would dictate that behavior, so that would be the
> implementation-specific stuff. Easy enough, and the core functionality
> remains generic enough for re-use.
>
> Michael, I looked at the sample snippets at that link, and I'll have
> to try it out. Thanks!

Hello,

If your rules become more complicated and maybe increase in number
significantly,
it might be an idea to switch to a rule-based system. Take a look at
CLIPS and the
associated Python bindings:

http://www.ghg.net/clips/CLIPS.html
http://pyclips.sourceforge.net/

Kind regards,

Marco

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


Re: pyc file [Newbie Question]

2007-04-03 Thread Peter Otten
Jim Aikin wrote:

> Just starting to learn Python and going through the Tutorial in the Help
> file. FWIW, I'm a hobbyist programmer -- not extremely knowledgeable, but
> not entirely clueless.
> 
> In 6.1.2 of the Tutorial, I find this: "The modification time of the
> version of spam.py used to create spam.pyc is recorded in spam.pyc, and
> the .pyc file is ignored if these don't match." Either I don't understand
> this, or it isn't correct.

$ echo 'print "Hello, Jim"' > tmp.py
$ python -c'import tmp'
Hello, Jim

Now let's change tmp.pyc in a way that we can see but Python won't notice:

$ python -c's = open("tmp.pyc").read(); open("tmp.pyc",
"w").write(s.replace("Jim", "JIM"))'
$ python -c'import tmp'
Hello, JIM

As you can see, tmp.pyc is not recreated. But if we change the timestamp of
tmp.py

$ touch tmp.py
$ python -c'import tmp'
Hello, Jim

it is. As Steven says, the behaviour you experience is caused by the module
cache. That is, a module "my_module" is only imported once per session, no
matter how many 'import my_module' statements you have in your application:

$ python -c'import tmp; import tmp'
Hello, Jim

That is why the greeting above is printed only once, and why your changes
don't have any immediate effect.

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


Re: pyc file [Newbie Question]

2007-04-03 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote:

> On Mon, 02 Apr 2007 23:44:41 -0700, Jim Aikin wrote:
> 
>> Working through the tutorial, I created a file called fibo.py in my
>> text editor, and imported it into Idle. It worked as expected. I then
>> edited the file and resaved it. I used del fibo, followed by import
>> fibo. 
> 
> That probably won't cause a full re-import. del fibo will only delete
> the reference called "fibo". The underlying module object will still
> exist until it is garbage-collected. It will only be garbage-collected
> if it isn't being used. Chances are, the module *is* being used
> somewhere, so when you call "import fibo" the import machinery simply
> gives you a new reference to the old module object.
> 

The underlying module won't be garbage collected. If nowhere else, it will 
still be accessible as sys.modules['fibo']
-- 
http://mail.python.org/mailman/listinfo/python-list


cli user interface ala cisco IOS or JUNOS

2007-04-03 Thread phil . aerts . tln
Hi,

for one of my python projects I need an user interface similar to that
of cisco IOS or even better Juniper JUNOS.
Does anyone know of existing python modules that gives this kind of
functionality ?

-P

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


Re: socket read timeout

2007-04-03 Thread Hendrik van Rooyen
 "Steve Holden" <[EMAIL PROTECTED]> wrote:

> 
> Right, but collisions are *so* twentieth-century, aren't they. With a 
> properly-implemented switched infrastructure Ethernet interfaces can 
> transmit and receive at the same time.

This is true, while "A" and "B" are not simultaneously trying to address
"C" - Then you need something like store and forward, on the fly...

: - )better known as "routing"...

Some (most?) of the little switches I have seen are too dumb even to 
allow  "A" to talk to "B" while "C" is talking to "D"  - they just broadcast 
the first "talker"'s message to all the "listeners" - little better than 
active hubs, destroying the end point's hardware capability to talk and
listen at the same time.

I think the keywords here are "properly implemented" - its actually not a 
trivial problem, as the switch has to know or learn who is where, and set 
up paths accordingly, in real time.  This is hard to do without store and
forward.

- Hendrik


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


p2p chat framework

2007-04-03 Thread Ghirai
Hello python-list,

Are there any p2p chat/filetransfer frameworks/examples floating
around?

If not, can someone give me some rough directions towards writing my
own?

Thanks.

-- 
Best regards,
Ghirai.

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


Re: Tkinter <> and bindtags ordering

2007-04-03 Thread bytecolor
On Apr 3, 3:16 am, "Rob Wolfe" <[EMAIL PROTECTED]> wrote:
> What about instead of:
>
> > t.bind('<>', text_changed)
>
> this event:
>
>t.bind('', text_changed)
>
> > root.mainloop()
>
> --
> HTH,
> Rob

Hey Rob,
I actually started with that event, until I came across the modified
event. I'm working on syntax highlighting. So I need any text change.
Also, colorizing on a key release is annoyingly noticeable to the
user. I tried it :)

I'm sure there are going to be other perils along the way as this is
my first attempt at syntax highlighing. I can load a file and the
highlighting works very well. I used an elaborate regex with named
groups and re.finditer(). I either use the names directly as edit
tags, or they help me look up other tags in a dict. It's quite fast.

screenshot with random (ugly) colors:
http://bytecolor.homelinux.org/~bytecolor/vapt_colorizing.png

That part wasn't bad at all. Now I need to code the text change
logistics but this bindtags ordering has got me perplexed.

--
bytecolor

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


Parsing Problems

2007-04-03 Thread saif . shakeel
Hi,

 I have just started learning python.I need to parse an XML file
and present the contents in a particular format.The format is called
as "ini" file.I have written some code.A section of the format needs
the data to be present in format as given below:

[Services]
supported=0x10,0x1A,0x3B,0x20,0x27,0x28,0x34,0x36,0x3E,0xA2,0xA5,0x2D,
0x22,0xA9,0x04,0xAA,0xAE

My code for this section parses the xml file and gives :
[Services]
Supported=['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa',
'0x10', '0xae', '0x34', '0x36', '0x2d', '0xa9', '0xa5', '0x4', '0xa2',
'0x1a']

{forget the numericals matching}.As you can see there
are single quotes around numericals ,which is not desired .I think the
problem lies in me using a list for storing and later printing out
values.I have attached few lines of code,not sure how clear it can be
to you:

for l in range(0,len(ser_par),
1):
if
ser_par[l].getAttribute('Semantics')==u'serviceId':
if
tag_exists(ser_par[l].childNodes,'VALUE'):
val =
ser_par[l].getElementsByTagName('VALUE')
value =
str(val[0].getAttribute('value'))
valu = hex(int(value))
rval.append(valu)
ser_par_num = ser_par_num + 1
prim_num = prim_num + 1

service_num = service_num + 1
variant_num = variant_num + 1
ser = list(set(rval))

print "\n[Services]"
print "Supported="+str(ser)

  How can i get rid of those single quotes.

 Thanking you
 
shakeel

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


Re: Mastering Python (OT)

2007-04-03 Thread Hendrik van Rooyen

 "Steve Holden" <[EMAIL PROTECTED]> wrote:

> Speaking of which, here's a limerick To read it you need to know not 
> only that Hampshire is colloquially know as Hants, but also that 
> Salisbury's ancient Roman name is Sarum.
> 
> There once was a young man of Salisbury
> Whose manners were most halisbury-scalisbury
> He visited Hampshire
> Without any pampshire
> Till somebody told him to walisbury.
> 
> try-running-a-spell-checker-on-that-ly y'rs  - steve

Nice one! - Thanks Steve

- Hendrik

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


Re: Parsing Problems

2007-04-03 Thread Daniel Nogradi
>  I have just started learning python.I need to parse an XML file
> and present the contents in a particular format.The format is called
> as "ini" file.I have written some code.A section of the format needs
> the data to be present in format as given below:
>
> [Services]
> supported=0x10,0x1A,0x3B,0x20,0x27,0x28,0x34,0x36,0x3E,0xA2,0xA5,0x2D,
> 0x22,0xA9,0x04,0xAA,0xAE
>
> My code for this section parses the xml file and gives :
> [Services]
> Supported=['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa',
> '0x10', '0xae', '0x34', '0x36', '0x2d', '0xa9', '0xa5', '0x4', '0xa2',
> '0x1a']
>
> {forget the numericals matching}.As you can see there
> are single quotes around numericals ,which is not desired .I think the
> problem lies in me using a list for storing and later printing out
> values.I have attached few lines of code,not sure how clear it can be
> to you:
>
> for l in range(0,len(ser_par),
> 1):
> if
> ser_par[l].getAttribute('Semantics')==u'serviceId':
> if
> tag_exists(ser_par[l].childNodes,'VALUE'):
> val =
> ser_par[l].getElementsByTagName('VALUE')
> value =
> str(val[0].getAttribute('value'))
> valu = hex(int(value))
> rval.append(valu)
> ser_par_num = ser_par_num + 1
> prim_num = prim_num + 1
>
> service_num = service_num + 1
> variant_num = variant_num + 1
> ser = list(set(rval))
>
> print "\n[Services]"
> print "Supported="+str(ser)
>
>   How can i get rid of those single quotes.


mylist = ['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa',
'0x10', '0xae', '0x34', '0x36', '0x2d', '0xa9', '0xa5', '0x4', '0xa2',
'0x1a']

','.join( mylist )

This will give you:

0x3e,0x28,0x3b,0x22,0x20,0x27,0xaa,0x10,0xae,0x34,0x36,0x2d,0xa9,0xa5,0x4,0xa2,0x1a


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


Re: Parsing Problems

2007-04-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, saif.shakeel
wrote:

>  I have just started learning python.I need to parse an XML file
> and present the contents in a particular format.The format is called
> as "ini" file.I have written some code.A section of the format needs
> the data to be present in format as given below:
> 
> [Services]
> supported=0x10,0x1A,0x3B,0x20,0x27,0x28,0x34,0x36,0x3E,0xA2,0xA5,0x2D,
> 0x22,0xA9,0x04,0xAA,0xAE
> 
> My code for this section parses the xml file and gives :
> [Services]
> Supported=['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa',
> '0x10', '0xae', '0x34', '0x36', '0x2d', '0xa9', '0xa5', '0x4', '0xa2',
> '0x1a']
> 
> {forget the numericals matching}.As you can see there
> are single quotes around numericals ,which is not desired .I think the
> problem lies in me using a list for storing and later printing out
> values.

It's not that you store them in the list but that you simply print the
string representation of the list which does not meet your requirements. 
You want to join the list elements with a comma::

  print 'supported=%s' % ','.join(ser)

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


Re: Parsing Problems

2007-04-03 Thread irstas

[EMAIL PROTECTED] wrote:
> Hi,
>
>  I have just started learning python.I need to parse an XML file
> and present the contents in a particular format.The format is called
> as "ini" file.I have written some code.A section of the format needs
> the data to be present in format as given below:
>
> [Services]
> supported=0x10,0x1A,0x3B,0x20,0x27,0x28,0x34,0x36,0x3E,0xA2,0xA5,0x2D,
> 0x22,0xA9,0x04,0xAA,0xAE
>
> My code for this section parses the xml file and gives :
> [Services]
> Supported=['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa',
> '0x10', '0xae', '0x34', '0x36', '0x2d', '0xa9', '0xa5', '0x4', '0xa2',
> '0x1a']
>
> {forget the numericals matching}.As you can see there
> are single quotes around numericals ,which is not desired .I think the
> problem lies in me using a list for storing and later printing out
> values.I have attached few lines of code,not sure how clear it can be
> to you:
>
> for l in range(0,len(ser_par),
> 1):
> if
> ser_par[l].getAttribute('Semantics')==u'serviceId':
> if
> tag_exists(ser_par[l].childNodes,'VALUE'):
> val =
> ser_par[l].getElementsByTagName('VALUE')
> value =
> str(val[0].getAttribute('value'))
> valu = hex(int(value))
> rval.append(valu)
> ser_par_num = ser_par_num + 1
> prim_num = prim_num + 1
>
> service_num = service_num + 1
> variant_num = variant_num + 1
> ser = list(set(rval))
>
> print "\n[Services]"
> print "Supported="+str(ser)
>
>   How can i get rid of those single quotes.
>
>  Thanking you
>
> shakeel

Hi,
Instead of using str(ser), you should create a string which combines
the individual strings in ser, separated by commas. Luckily for you,
there's a string method does just that: join.
http://docs.python.org/lib/string-methods.html

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


Re: Parsing Problems

2007-04-03 Thread bytecolor
On Apr 3, 5:13 am, [EMAIL PROTECTED] wrote:
> Hi,
>
>  I have just started learning python.I need to parse an XML file
> and present the contents in a particular format.The format is called
> as "ini" file.I have written some code.A section of the format needs
> the data to be present in format as given below:
>
> [Services]
> supported=0x10,0x1A,0x3B,0x20,0x27,0x28,0x34,0x36,0x3E,0xA2,0xA5,0x2D,
> 0x22,0xA9,0x04,0xAA,0xAE
>
> My code for this section parses the xml file and gives :
> [Services]
> Supported=['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa',
> '0x10', '0xae', '0x34', '0x36', '0x2d', '0xa9', '0xa5', '0x4', '0xa2',
> '0x1a']
>
> {forget the numericals matching}.As you can see there
> are single quotes around numericals ,which is not desired .I think the
> problem lies in me using a list for storing and later printing out
> values.I have attached few lines of code,not sure how clear it can be
> to you:
>
> for l in range(0,len(ser_par),
> 1):
> if
> ser_par[l].getAttribute('Semantics')==u'serviceId':
> if
> tag_exists(ser_par[l].childNodes,'VALUE'):
> val =
> ser_par[l].getElementsByTagName('VALUE')
> value =
> str(val[0].getAttribute('value'))
> valu = hex(int(value))
> rval.append(valu)
> ser_par_num = ser_par_num + 1
> prim_num = prim_num + 1
>
> service_num = service_num + 1
> variant_num = variant_num + 1
> ser = list(set(rval))
>
> print "\n[Services]"
> print "Supported="+str(ser)
>
>   How can i get rid of those single quotes.
>
>  Thanking you
>
> shakeel

>>> l = ['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa']
>>> ','.join(l)
'0x3e,0x28,0x3b,0x22,0x20,0x27,0xaa'

You may want to look at the ConfigParser package too. It's for reading/
writing .ini file.

--
bytecolor

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


Re: Question about text in Python

2007-04-03 Thread Steven D'Aprano
On Tue, 03 Apr 2007 12:26:47 +1000, Ben Finney wrote:

> "Steve" <[EMAIL PROTECTED]> writes:
> 
>> Yes it is [a homework question].
>>
>> Where else to ask for help but here.
> 
> That's between you, your teacher, and your teaching institute's
> plagiarism guidelines.


Plagiarism is a serious example of fraud, which is not only a crime but is
unethical as well. You don't need to be a student or an academic to commit
plagiarism. Anybody can commit plagiarism.

If we applied the plagiarism guidelines that university students labour
under to the rest of us, perhaps we'd be a little less quick to toss
accusations of plagiarism around so easily. If it is plagiarism for a
student to ask how to detect an empty line, then it is plagiarism for
any of us to ask how to do anything.

At the point that students are unable to ask for information because
they're accused of plagiarism, well, that's "a total collapse of critical
reasoning", to quote Professor Steven Dutch of the University of Wisconsin.

Citation: http://www.uwgb.edu/dutchs/PSEUDOSC/PlagShame.HTM
Accessed 2007-04-03.


If the Original Poster _accidentally_ sees a newsgroup post that answers
his question -- "Oh, so that's how you exit a loop in Python!" -- is that
plagiarism? Or is it only plagiarism if he _asks_ for the information
first? Does he have to spend the rest of his life as a Python coder giving
credit to J. Random Hacker for using "his" technique of "using break to
exit a while loop"?

None of this is to excuse students who try to have their homework done for
them, or well-meaning but foolish people who, in response to a simple
question end up providing an entire working piece of code, essentially
doing the student's homework for them. Plagiarism does exist, and it is
fraud. But I'm sickened and saddened to see how plagiarism has been
bastardised by academia, turning it from serious fraud to trivial re-use
of phrases and ideas, and even _learning things from anyone someone other
than your lecturer_.

That's what it has come to. If you ask "how do I detect the user has
entered an empty line in raw_input?", you're deemed to be committing
fraud. WTF? There's a gulf the size of the Atlantic Ocean between
_learning_ and _committing fraud_, and we're so frightened by the thought
that somebody might fraudulently claim another person's ideas (which begs
the question of whether people can own ideas) that we're prohibiting
learning except through a couple of narrowly approved channels.

If you think I'm exaggerating, I challenge you to read Professor Dutch's
pages on plagiarism:

http://www.uwgb.edu/dutchs/PSEUDOSC/PlagShame.HTM
http://www.uwgb.edu/dutchs/PSEUDOSC/PlagiarNonsense.HTM

I challenge you to try to work as a coder, whether professional or
amateur, under the same restrictions that we've been placing on students.
I can't count the number of times people write to comp.lang.python asking
"How do I transmogrify the frombulator?" And let's not even mention
copying code snippets posted on Usenet.

These things are not fraud. They are learning.

This is not a call to turn a blind eye for plagiarism, or to do students
homework for them. It's a plea for common-sense. We're not bound by
university guidelines, or universities' over-broad definition of
plagiarism, and we don't have to live by them. We are ethically bound not
to do student's homework for them -- but that doesn't mean we're bound to
refuse to answer their reasonable questions, or to treat those who are
looking for help as frauds _just because they are a student_.



-- 
Steven D'Aprano 

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


Re: Tkinter <> and bindtags ordering

2007-04-03 Thread Rob Wolfe

bytecolor wrote:

> Hey Rob,
> I actually started with that event, until I came across the modified
> event. I'm working on syntax highlighting. So I need any text change.
> Also, colorizing on a key release is annoyingly noticeable to the
> user. I tried it :)
>
> I'm sure there are going to be other perils along the way as this is
> my first attempt at syntax highlighing. I can load a file and the
> highlighting works very well. I used an elaborate regex with named
> groups and re.finditer(). I either use the names directly as edit
> tags, or they help me look up other tags in a dict. It's quite fast.
>
> screenshot with random (ugly) colors:
> http://bytecolor.homelinux.org/~bytecolor/vapt_colorizing.png
>
> That part wasn't bad at all. Now I need to code the text change
> logistics but this bindtags ordering has got me perplexed.

Have you looked at ColorDelegator.py from idlelib?
There has been done such a syntax highlighting based on Tkinter.Text.

--
HTH,
Rob

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


Re: Any "consumer review generators" available?

2007-04-03 Thread nullified
On Fri, 30 Mar 2007 22:15:20 +0200, Schraalhans Keukenmeester
<[EMAIL PROTECTED]> wrote:

>nullified wrote:
>> On 30 Mar 2007 07:01:16 -0700, "Evil Otto" <[EMAIL PROTECTED]> wrote:
>> 
>>> On Mar 30, 3:46 am, nullified <[EMAIL PROTECTED]> wrote:
 On 29 Mar 2007 20:34:26 -0700, "Evil Otto" <[EMAIL PROTECTED]> wrote:

> On Mar 29, 2:19 pm, [EMAIL PROTECTED] wrote:
>> I am looking for a fake consumer review generator that could generate 
>> realistic looking reviews for any products, kind of like on amazon.com 
>> but generated by Artificial Intelligence. Is there a package available 
>> in your favorite programing language... thx alan
> I really, really hope that you're looking to generate test data or
> filler text.
> If you're not, then DIAF.
 Die In A Fire? Drop In A Fryer? Doug Is A Fucker? Drown In A Fart?
>>> Any of those would accurately describe the underlying sentiment, but I
>>> had "Die In A Fire" in mind specifically.
>> 
>> FM!, IWRFT!
>Perhaps if he finds his miracle script he can also train it to create
>and 'solve' funny acronyms?

Sorry. That was "Fuck Me! I Was Right First Time!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cli user interface ala cisco IOS or JUNOS

2007-04-03 Thread Ben Finney
[EMAIL PROTECTED] writes:

> for one of my python projects I need an user interface similar to that
> of cisco IOS or even better Juniper JUNOS.
> Does anyone know of existing python modules that gives this kind of
> functionality?

I suspect you've not checked the standard library index:

Python Library Reference
http://docs.python.org/lib/>

which lists the 'cmd' module:

cmd -- Support for line-oriented command interpreters
http://docs.python.org/lib/module-cmd.html>

If that doesn't meet your needs, you might need to be more specific
about what you're looking for.

-- 
 \   "Success is going from one failure to the next without a loss |
  `\ of enthusiasm."  -- Winston Churchill |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter <> and bindtags ordering

2007-04-03 Thread bytecolor
On Apr 3, 5:48 am, "Rob Wolfe" <[EMAIL PROTECTED]> wrote:

> Have you looked at ColorDelegator.py from idlelib?
> There has been done such a syntax highlighting based on Tkinter.Text.
>
> --
> HTH,
> Rob

I've been poking around it a bit. I actually use the tabpage module in
my app. Guess I should take a harder look at it. Nice bit of software.

--
bytecolor

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


Standard Library Structure (was Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed)

2007-04-03 Thread Paul Boddie
On 2 Apr, 20:17, "Kay Schluehr" <[EMAIL PROTECTED]> wrote:
>
> Note that the conflict of putting modules on top level or better
> within separate packages is not an either-or decision from a
> programmers point of view who just wants to access those modules. A
> top level module like lib or std can be pretty virtual since you can
> create modules at runtime whenever you try to import them.

Or, if the subpackages/submodules are small enough, just import them
and make their contents available at higher levels in the hierarchy.

> I used this strategy for a project where editing objects in separate files 
> leaded
> to a better overview compared to one large file containing all
> definitions. However I created one module at runtime that served as a
> common access point for all these particular definitions that were
> tedious to import separately and would have required file system
> lookups quite often. This might even allow multiple classifications
> but I haven't experimented with them yet.

Yes, I tend to make aliases available quite a bit. It seems to me that
introducing a hierarchy into the standard library has a fairly limited
cost: you need to occupy some more top-level names, some unfortunately
being potentially common, but any growth in the library isn't as
likely to introduce more naming conflicts - something that anyone with
their own calendar.py, new.py or xml.py programs might find
desirable. ;-)

One problem I've become more aware of, however, is the role of C-based
modules in the library. I think there was an unresolved issue about
such modules living at non-root locations in the library hierarchy,
but aside from that, the work required to clean up any abstractions
eventually requires people to roll up their sleeves and look at non-
Python code.

Paul

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


Re: Numeric compiling problem under QNX 4.25

2007-04-03 Thread [EMAIL PROTECTED]
Hi,

unfortunately I don't have a solution. However, if you're not forced
to use Python2.2 and Numeric you should use Numpy (the successor for
both, Numeric and Numarray). Numpy requires Python2.3, though.

Bernhard


On Apr 3, 7:32 am, "ZMY" <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I am a real newbie for both python and QNX, but I am still trying to
> compile Numeric-24.2 under QNX4.25 with python 2.2. I got following
> error message:
>
> $ sudo python setup.py install
> Password:
> running install
> ...
> building '_numpy' extension
> skipping Src/_numpymodule.c (build/temp.qnx-O-PCI-2.2/_numpymodule.o
> up-to-date)
> skipping Src/arrayobject.c (build/temp.qnx-O-PCI-2.2/arrayobject.o up-
> to-date)
> skipping Src/ufuncobject.c (build/temp.qnx-O-PCI-2.2/ufuncobject.o up-
> to-date)
> ld build/temp.qnx-O-PCI-2.2/_numpymodule.o build/temp.qnx-O-PCI-2.2/
> arrayobject.o build/temp.qnx-O-PCI-2.2/ufuncobject.o -o build/lib.qnx-
> O-PCI-2.2/_numpy.so
> unable to execute ld: No such file or directory
> error: command 'ld' failed with exit status 1
>
> I looked at directory /build/temp.qnx-O-PCI-2.2/ and found following
> object files:
>
> _numpymodule.o, arrayobject.o, ufuncobject.o
>
> So it looks that ld got all files before linking them - or is it??
>
> Thanks a lot for any suggestions,
>
> - ZMY


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


Re: Question about text in Python

2007-04-03 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Tue, 03 Apr 2007 12:26:47 +1000, Ben Finney wrote:
>
> > "Steve" <[EMAIL PROTECTED]> writes:
> > 
> >> Yes it is [a homework question].
> >>
> >> Where else to ask for help but here.
> > 
> > That's between you, your teacher, and your teaching institute's
> > plagiarism guidelines.
>
> Plagiarism is a serious example of fraud, which is not only a crime
> but is unethical as well. You don't need to be a student or an
> academic to commit plagiarism. Anybody can commit plagiarism.
>
> If we applied the plagiarism guidelines that university students
> labour under to the rest of us, perhaps we'd be a little less quick
> to toss accusations of plagiarism around so easily.

I agree with the severity of such an accusation, which is why I didn't
make it in this case.

-- 
 \ "[T]he question of whether machines can think [...] is about as |
  `\ relevant as the question of whether submarines can swim."  -- |
_o__)   Edsger W. Dijkstra |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


XML DTD analysis, diffing ...

2007-04-03 Thread olive
Hi,

I have a bunch of similar DTDs written by different coders.

I would like to normalize, sort elements and attributes by name and
compare those files.

Do you know any XML DTD parser/normalizer written in Python ?

If not, how would you perform that task in Python language ?

Please,

Olive.

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


Re: Question about text in Python

2007-04-03 Thread Bjoern Schliessmann
Steve wrote:

> Yes it is.
> 
> Where else to ask for help but here.

http://www.catb.org/~esr/faqs/smart-questions.html#homework

Regards&Good luck,


Björn

-- 
BOFH excuse #247:

Due to Federal Budget problems we have been forced to cut back on
the number of users able to access the system at one time. (namely
none allowed)

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


Re: Inserting '-' character in front of all numbers in a string

2007-04-03 Thread Jorgen Grahn
On 30 Mar 2007 08:38:27 -0700, kevinliu23 <[EMAIL PROTECTED]> wrote:
> Hey guys,
>
> I want to be able to insert a '-' character in front of all numeric
> values in a string. I want to insert the '-' character to use in
> conjunction with the getopt.getopt() function.
...
> "2a 3ab" into "-2a -3ab".

Are you sure you want getopt, or are you just reusing it because you
don't know enough about string parsing and REs?

-2a -3ab is a bit limited: if you run out of digits and have to use
10, 11, ... then getopt will treat '-10ab' as '-1' without argument
and -0 with 'ab' as argument. It will probably choke on the
argumentless -1, too.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding and copying files with python.

2007-04-03 Thread gtb
I wish to copy   the highest version number of a file from directory \
\
\fileserver\D:\scripts to C:\scripts where the file names are of the
form

filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
digits.

Example directory:
other.zip
dx_ver_1.1.63.zip
dx_ver_1.2.01.zip
dx_ver_1.12.7.zip
temp.txt


Does python have string matching routines  that would find the bottom
listed zip file and/or file copying routines?

A little pointer or two would be much appreciated.

Thanks,

jh

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


Re: python installation destination directory

2007-04-03 Thread Kushal Kumaran
On Apr 3, 9:33 am, "ZMY" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am installing python 2.2 on QNX4.25 but can't get it into /usr/local/
> bin/ directory. Here is what I did:
>
> 1) untar Python-2.2 into directory /openqnx/Python-2.2/
>
> 2) use command:
> CONFIG_SHELL=/usr/local/bin/bash CC=cc RANLIB=:
> ./configure --verbose --without-gcc --with-libm=""
>
> 3) Enabled array, math, os, struct, time, cmath modules
>
> 4) use command:
> make SHELL=/usr/local/bin/bash
>
> and I got a python excutable in directory
>  /openqnx/Python-2.2/
>
> which works well with all the modules. But I really want to have it
> at /usr/local/bin
>
> I checked the Makefile, and it seems python should be installed in /
> usr/local/bin instead, since I got following lines in Makefile:
>
> # Install prefix for architecture-independent files
> prefix= /usr/local
>
> # Install prefix for architecture-dependent files
> exec_prefix=${prefix}
>
> Do any of you know what the problem is?
>

You need to do a make install.

--
Kushal

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


raw_input just continues anyway?

2007-04-03 Thread [EMAIL PROTECTED]
Hey Everyone,

This is probably going to sound like a bit of a stupid question - but
why does (in the following code) the script just continue to run past
the raw_input, when the user hasn't entered anything?

if __name__ == "__main__":
bucket_name = raw_input('Name of the bucket you wish the files to be
placed into? ')
update_s3()

Basically, it just asks the question and continues anyway?

Many Thanks,
Oliver

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


Re: XML DTD analysis, diffing ...

2007-04-03 Thread kyosohma
On Apr 3, 7:38 am, "olive" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a bunch of similar DTDs written by different coders.
>
> I would like to normalize, sort elements and attributes by name and
> compare those files.
>
> Do you know any XML DTD parser/normalizer written in Python ?
>
> If not, how would you perform that task in Python language ?
>
> Please,
>
> Olive.

Olive,

Beautiful Soup is usually recommended for parsing XML/HTML.
www.crummy.com/software/BeautifulSoup/

You could also use pyXML. See the recipe below for one way to use it:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/220472

xmlproc has a way of parsing DTDs, or so I hear. I think it's a part
of pyXML.

I hope this stuff gives you some ideas.

Mike
See also the SAX module: http://docs.python.org/lib/module-xml.sax.handler.html

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


Re: Finding and copying files with python.

2007-04-03 Thread [EMAIL PROTECTED]
Just sort them and then select the bottom one from a list by using a
negative indices. I.e.:

list[-1]

Would return the bottom result out of a list

On Apr 3, 2:21 pm, "gtb" <[EMAIL PROTECTED]> wrote:
> I wish to copy   the highest version number of a file from directory \
> \
> \fileserver\D:\scripts to C:\scripts where the file names are of the
> form
>
> filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
> digits.
>
> Example directory:
> other.zip
> dx_ver_1.1.63.zip
> dx_ver_1.2.01.zip
> dx_ver_1.12.7.zip
> temp.txt
>
> Does python have string matching routines  that would find the bottom
> listed zip file and/or file copying routines?
>
> A little pointer or two would be much appreciated.
>
> Thanks,
>
> jh


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


Re: Finding and copying files with python.

2007-04-03 Thread kyosohma
On Apr 3, 8:21 am, "gtb" <[EMAIL PROTECTED]> wrote:
> I wish to copy   the highest version number of a file from directory \
> \
> \fileserver\D:\scripts to C:\scripts where the file names are of the
> form
>
> filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
> digits.
>
> Example directory:
> other.zip
> dx_ver_1.1.63.zip
> dx_ver_1.2.01.zip
> dx_ver_1.12.7.zip
> temp.txt
>
> Does python have string matching routines  that would find the bottom
> listed zip file and/or file copying routines?
>
> A little pointer or two would be much appreciated.
>
> Thanks,
>
> jh

You could just use string slicing to cut off the first 7 characters
and have the numbers available to compare. There's also the os.stat
module to find the last modified date of the file. You might be able
to use the glob module to grab a list of the files and then sort the
list too.

Mike

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


Re: raw_input just continues anyway?

2007-04-03 Thread kyosohma
On Apr 3, 8:27 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hey Everyone,
>
> This is probably going to sound like a bit of a stupid question - but
> why does (in the following code) the script just continue to run past
> the raw_input, when the user hasn't entered anything?
>
> if __name__ == "__main__":
> bucket_name = raw_input('Name of the bucket you wish the files to be
> placed into? ')
> update_s3()
>
> Basically, it just asks the question and continues anyway?
>
> Many Thanks,
> Oliver

This code works on my machine: Python 2.4, Windows XP Pro SP2

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


Re: print the screen shot in python

2007-04-03 Thread kyosohma
On Apr 2, 4:24 pm, "gslm" <[EMAIL PROTECTED]> wrote:
> Hi!
> I want to print an application view in python.I use labels and frames
> in my program.And ý want to know if it is possible to print all of the
> view of my program?
> Thanks a lot...

You need to give us more details. Are you using wxPython, Tkinter,
pyQT or what? And what version of python and OS? Do you want to take a
picture of the programs interface and print that with Python?

Mike

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


Re: Finding and copying files with python.

2007-04-03 Thread gtb
On Apr 3, 8:31 am, [EMAIL PROTECTED] wrote:
> On Apr 3, 8:21 am, "gtb" <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
>
>
> > I wish to copy   the highest version number of a file from directory \
> > \
> > \fileserver\D:\scripts to C:\scripts where the file names are of the
> > form
>
> > filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
> > digits.
>
> > Example directory:
> > other.zip
> > dx_ver_1.1.63.zip
> > dx_ver_1.2.01.zip
> > dx_ver_1.12.7.zip
> > temp.txt
>
> > Does python have string matching routines  that would find the bottom
> > listed zip file and/or file copying routines?
>
> > A little pointer or two would be much appreciated.
>
> > Thanks,
>
> > jh
>
> You could just use string slicing to cut off the first 7 characters
> and have the numbers available to compare. There's also the os.stat
> module to find the last modified date of the file. You might be able
> to use the glob module to grab a list of the files and then sort the
> list too.
>
> Mike

Thanks for posting folks. I didn't make my question clear. Before I
sort the files I need to ensure that I am only sorting the files that
match the profile of "filename_MM.NN.SS.zip", where MM, NN, and SS can
be one to three
digits.

Thanks again,

jh

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


Re: raw_input just continues anyway?

2007-04-03 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

> if __name__ == "__main__":
> bucket_name = raw_input('Name of the bucket you wish the files to be 
> placed into? ')
> update_s3()
> 
> Basically, it just asks the question and continues anyway?

It reads stdin until a line break. Then it continues. Exactly what
behaviour do you get?

Regards,


Björn

-- 
BOFH excuse #328:

Fiber optics caused gas main leak

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


Re: XML DTD analysis, diffing ...

2007-04-03 Thread olive
Mike,

I know all of these tools and I already suspected xmlproc as a good
candidate.

The problem is I can't download it for the moment since Lars website
is blocked here at my work and PyXML is dead.

Maybe there is an alternative download link ?

Thank you for the Cookbook recipe anyway.

Olivier.

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


Re: XML DTD analysis, diffing ...

2007-04-03 Thread Paul Boddie
On 3 Apr, 15:52, "olive" <[EMAIL PROTECTED]> wrote:
>
> I know all of these tools and I already suspected xmlproc as a good
> candidate.
>
> The problem is I can't download it for the moment since Lars website
> is blocked here at my work and PyXML is dead.
>
> Maybe there is an alternative download link ?

Isn't xmlproc part of PyXML anyway? Detailed public information about
various PyXML packages suggests that it is. For example:

http://packages.debian.org/unstable/python/python-xml

Paul

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


Re: XML DTD analysis, diffing ...

2007-04-03 Thread kyosohma
On Apr 3, 8:52 am, "olive" <[EMAIL PROTECTED]> wrote:
> Mike,
>
> I know all of these tools and I already suspected xmlproc as a good
> candidate.
>
> The problem is I can't download it for the moment since Lars website
> is blocked here at my work and PyXML is dead.
>
> Maybe there is an alternative download link ?
>
> Thank you for the Cookbook recipe anyway.
>
> Olivier.

When I go to the xmlproc website, it states that it is now a part of
the PyXML package, which can be found on Soureforge here:

http://pyxml.sourceforge.net/

Mike

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


Re: Finding and copying files with python.

2007-04-03 Thread kyosohma
On Apr 3, 8:47 am, "gtb" <[EMAIL PROTECTED]> wrote:
> On Apr 3, 8:31 am, [EMAIL PROTECTED] wrote:
>
>
>
> > On Apr 3, 8:21 am, "gtb" <[EMAIL PROTECTED]> wrote:
>
> > > I wish to copy   the highest version number of a file from directory \
> > > \
> > > \fileserver\D:\scripts to C:\scripts where the file names are of the
> > > form
>
> > > filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
> > > digits.
>
> > > Example directory:
> > > other.zip
> > > dx_ver_1.1.63.zip
> > > dx_ver_1.2.01.zip
> > > dx_ver_1.12.7.zip
> > > temp.txt
>
> > > Does python have string matching routines  that would find the bottom
> > > listed zip file and/or file copying routines?
>
> > > A little pointer or two would be much appreciated.
>
> > > Thanks,
>
> > > jh
>
> > You could just use string slicing to cut off the first 7 characters
> > and have the numbers available to compare. There's also the os.stat
> > module to find the last modified date of the file. You might be able
> > to use the glob module to grab a list of the files and then sort the
> > list too.
>
> > Mike
>
> Thanks for posting folks. I didn't make my question clear. Before I
> sort the files I need to ensure that I am only sorting the files that
> match the profile of "filename_MM.NN.SS.zip", where MM, NN, and SS can
> be one to three
> digits.
>
> Thanks again,
>
> jh

Then you probably need to use the glob module and the re module. You
may even be able to just use the glob module by doing something like:

filenames = glob.glob(r'pathtofiles\*.*.*.*.zip')

and then sort that.

Mike

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


Re: Finding and copying files with python.

2007-04-03 Thread Steve Holden
gtb wrote:
> On Apr 3, 8:31 am, [EMAIL PROTECTED] wrote:
>> On Apr 3, 8:21 am, "gtb" <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>
>>
>>
>>
>>> I wish to copy   the highest version number of a file from directory \
>>> \
>>> \fileserver\D:\scripts to C:\scripts where the file names are of the
>>> form
>>> filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
>>> digits.
>>> Example directory:
>>> other.zip
>>> dx_ver_1.1.63.zip
>>> dx_ver_1.2.01.zip
>>> dx_ver_1.12.7.zip
>>> temp.txt
>>> Does python have string matching routines  that would find the bottom
>>> listed zip file and/or file copying routines?
>>> A little pointer or two would be much appreciated.
>>> Thanks,
>>> jh
>> You could just use string slicing to cut off the first 7 characters
>> and have the numbers available to compare. There's also the os.stat
>> module to find the last modified date of the file. You might be able
>> to use the glob module to grab a list of the files and then sort the
>> list too.
>>
>> Mike
> 
> Thanks for posting folks. I didn't make my question clear. Before I
> sort the files I need to ensure that I am only sorting the files that
> match the profile of "filename_MM.NN.SS.zip", where MM, NN, and SS can
> be one to three
> digits.
> 
> Thanks again,
> 
> jh
> 
OK, well look at the glob module to get a list of the filenames.

You are going to have to be careful doing the sort, however, because a 
simple string comparison won't work for numbers of differing lengths.

One way would be to define a function that extracts the numeric 
components from a filename and produces a three-element tuple or list. 
Then pass this function to sort() as the "key" argument.

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

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


Re: XML DTD analysis, diffing ...

2007-04-03 Thread olive
Thanks Paul and Mike,

I've found the good link and just downloaded pyXML.

Olive.

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


Re: Finding and copying files with python.

2007-04-03 Thread Daniele Varrazzo
> > > I wish to copy   the highest version number of a file from directory \
> > > \
> > > \fileserver\D:\scripts to C:\scripts where the file names are of the
> > > form
>
> > > filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
> > > digits.
>
> > > Example directory:
> > > other.zip
> > > dx_ver_1.1.63.zip
> > > dx_ver_1.2.01.zip
> > > dx_ver_1.12.7.zip
> > > temp.txt
>
> > > Does python have string matching routines  that would find the bottom
> > > listed zip file and/or file copying routines?

> > You could just use string slicing to cut off the first 7 characters
> > and have the numbers available to compare. There's also the os.stat
> > module to find the last modified date of the file. You might be able
> > to use the glob module to grab a list of the files and then sort the
> > list too.

Comparing the version strings is not enough: you have to convert the
parts into integers, because else:

>>> "dx_ver_1.12.7.zip" < "dx_ver_1.2.1.zip"
True

> Thanks for posting folks. I didn't make my question clear. Before I
> sort the files I need to ensure that I am only sorting the files that
> match the profile of "filename_MM.NN.SS.zip", where MM, NN, and SS can
> be one to three
> digits.

Match the file names against the pattern "dx_ver_(\d+).(\d+).(\d
+).zip". You may also use the glob function, but then you will have to
parse the version number from the file name anyway: with the regexp
you can use match.groups() to get the version number.

You can do:

import re
ver_re = re.compile(r"dx_ver_(\d+).(\d+).(\d+).zip")

def getVer(fn):
"""Return a *comparable* file version, None for bad file names"""
m = ver_re.match(fn)
return m and map(int, m.groups())

print sorted(os.listdir('/path/to/wherever'), key=getVer)[-1]

--Daniele

P.S. I guess in Obfuscated Python one would write something like:

>>> print sorted((pair for pair in ((re.match(r"dx_ver_(\d+).(\d+).(\d+).zip", 
>>> fn), fn) for fn in os.listdir('/path/to/wherever')) if pair[0]), key=lambda 
>>> _: map(int, _[0].groups()))[-1][1]
dx_ver_1.12.7.zip

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


numpy performance and list comprehension

2007-04-03 Thread TG
Hi there.

Reading the page on python performance ( http://scipy.org/PerformancePython
) made me realize that I can achieve tremendous code acceleration with
numpy just by using "u[:,:]" kind of syntax the clever way.

Here is a little problem (Oja's rule of synaptic plasticity)

* W is a matrix containing the weights of connections between elements
i
and j
* V is an array containing the values of elements

I want to make W evolve with this rule :

dW[i,j] / dt = alpha * (V[i] * V[j] - W[i,j] * V[i]^2)

(don't pay attention to the derivate and stuff)

So, how would you write it in this nifty clever way ?

As a begining I wrote this :

  W += V.flatten().reshape((V.size,1)) *
V.flatten().reshape((1,V.size))

But it is not complete and, I guess, not efficient.

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


Problem installing Python 2.5

2007-04-03 Thread Sebastian Bassi
I was trying to install Python 2.5 compiling from sources. I used:
./compile
It run OK.
Then:
make altintall
After a lot of output, got this:
Listing /usr/local/lib/python2.5/xml/sax ...
Compiling /usr/local/lib/python2.5/xml/sax/__init__.py ...
Compiling /usr/local/lib/python2.5/xml/sax/_exceptions.py ...
Compiling /usr/local/lib/python2.5/xml/sax/expatreader.py ...
Compiling /usr/local/lib/python2.5/xml/sax/handler.py ...
Compiling /usr/local/lib/python2.5/xml/sax/saxutils.py ...
Compiling /usr/local/lib/python2.5/xml/sax/xmlreader.py ...
Compiling /usr/local/lib/python2.5/xmllib.py ...
Compiling /usr/local/lib/python2.5/xmlrpclib.py ...
Compiling /usr/local/lib/python2.5/zipfile.py ...
make: *** [libinstall] Error 1

It seems I am not the only one with this error:
http://www.thescripts.com/forum/thread613458.html
http://www.megasolutions.net/python/Python-installation-problem-(sorry-if-this-is-a-dup)-22624.aspx
http://ubuntuforums.org/showthread.php?p=1912370

System: Freespire 1.0.13 (based on Debian).
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with filter()

2007-04-03 Thread Boudreau, Emile
Hey all,
So I'm trying to filter a list with the built-in function
filter(). My list looks something like this:
['logs', 'rqp-8.2.104.0.dep', 'rqp-8.2.93.0.dep',
'rqp-win32-app-8.2.96.0-inst.tar.gz',
'rqp-win32-app-8.2.96.0-inst.tar.gz']

Calling filter like this: compFiles = filter(is_Dev, compFiles)
compFiles is my list and is_dev is the following 

def is_Dev(stringy):
  print stringy
  stringx = stringy.split('-')
  if stringx[1] == r'win32':
if stringx[2] == r'app':
  if stringx[4] == r'dev.tar.gz':
return 1

For some reason I only get 'logs' printed when is_Dev is called. (ie.
It's only going through is_dev once)
Does anyone see something wrong that I'm not seeing??

Thanks,

Emile Boudreau
 
 This message may contain privileged and/or confidential information.  If 
you have received this e-mail in error or are not the intended recipient, you 
may not use, copy, disseminate or distribute it; do not open any attachments, 
delete it immediately from your system and notify the sender promptly by e-mail 
that you have done so.  Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: raw_input just continues anyway?

2007-04-03 Thread [EMAIL PROTECTED]
Hi There,

Here's the full code, if it helps:

"""
Takes a list of filenames via standard input and uploads them to
Amazon S3.

Requires S3.py:

http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134&categoryID=47

Usage:
cd /directory/with/media/files/
find | grep -v ".svn" | python /path/to/update_s3.py

Before you use this, change the aws_access_key_id, aws_secret_key and
bucket_name variables at the top of the file.

You can run this multiple times on the same files -- it'll just
override the
files that were in your S3 account previously.
"""

import mimetypes
import os
import settings
import os.path
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from custom_filters import filename_slugify
import S3
import settings

aws_access_key_id = settings.AWS_ACCESS_KEY_ID
aws_secret_key = settings.AWS_SECRET_KEY

def update_s3(bucket_name=bucket_name):
conn = S3.AWSAuthConnection(aws_access_key_id, aws_secret_key)
for line in sys.stdin:
filename = os.path.normpath(line[:-1])
if ((filename == '.' or not os.path.isfile(filename)) or
(filename.find('ds_store') >= 0)):
continue # Skip this, because it's not a file.
print "Uploading %s" % filename_slugify(filename)
filedata = open(filename, 'rb').read()
content_type = mimetypes.guess_type(filename)[0]
if not content_type:
content_type = 'text/plain'
conn.put(bucket_name, filename_slugify(filename),
S3.S3Object(filedata),
{'x-amz-acl': 'private', 'Content-Type': content_type})

if __name__ == "__main__":
bucket_name = raw_input('Name of the bucket you wish the files to be
placed into? ')
update_s3()


Basically I pipe some files into the script - so would this cause a
linebreak?

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


Re: Finding and copying files with python.

2007-04-03 Thread gtb
On Apr 3, 9:42 am, "Daniele Varrazzo" <[EMAIL PROTECTED]>
wrote:
> > > > I wish to copy   the highest version number of a file from directory \
> > > > \
> > > > \fileserver\D:\scripts to C:\scripts where the file names are of the
> > > > form
>
> > > > filename_MM.NN.SS.zip, where MM, NN, and SS can be one to three
> > > > digits.
>
> > > > Example directory:
> > > > other.zip
> > > > dx_ver_1.1.63.zip
> > > > dx_ver_1.2.01.zip
> > > > dx_ver_1.12.7.zip
> > > > temp.txt
>
> > > > Does python have string matching routines  that would find the bottom
> > > > listed zip file and/or file copying routines?
> > > You could just use string slicing to cut off the first 7 characters
> > > and have the numbers available to compare. There's also the os.stat
> > > module to find the last modified date of the file. You might be able
> > > to use the glob module to grab a list of the files and then sort the
> > > list too.
>
> Comparing the version strings is not enough: you have to convert the
> parts into integers, because else:
>
> >>> "dx_ver_1.12.7.zip" < "dx_ver_1.2.1.zip"
>
> True
>
> > Thanks for posting folks. I didn't make my question clear. Before I
> > sort the files I need to ensure that I am only sorting the files that
> > match the profile of "filename_MM.NN.SS.zip", where MM, NN, and SS can
> > be one to three
> > digits.
>
> Match the file names against the pattern "dx_ver_(\d+).(\d+).(\d
> +).zip". You may also use the glob function, but then you will have to
> parse the version number from the file name anyway: with the regexp
> you can use match.groups() to get the version number.
>
> You can do:
>
> import re
> ver_re = re.compile(r"dx_ver_(\d+).(\d+).(\d+).zip")
>
> def getVer(fn):
> """Return a *comparable* file version, None for bad file names"""
> m = ver_re.match(fn)
> return m and map(int, m.groups())
>
> print sorted(os.listdir('/path/to/wherever'), key=getVer)[-1]
>
> --Daniele
>
> P.S. I guess in Obfuscated Python one would write something like:
>
> >>> print sorted((pair for pair in 
> >>> ((re.match(r"dx_ver_(\d+).(\d+).(\d+).zip", fn), fn) for fn in 
> >>> os.listdir('/path/to/wherever')) if pair[0]), key=lambda _: map(int, 
> >>> _[0].groups()))[-1][1]
>
> dx_ver_1.12.7.zip

Thanks all. Much to learn, but you have certainly helped me get
started.

jh

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


RE: Problem with filter()

2007-04-03 Thread Boudreau, Emile
Sorry folks my mistake def is_dev should be:
def is_Dev(stringy):
  stringx = stringy.split('-')
  if stringx[0] == '':
if stringx[1] == r'win32':
  if stringx[2] == r'app':
if stringx[4] == r'dev.tar.gz':
  return 1
 
But now the results of the filter is an empty list and i know it
shouldn't be.
 

Emile Boudreau 


From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Boudreau, Emile
Sent: Tuesday, April 03, 2007 10:52 AM
To: [email protected]
Subject: Problem with filter()



Hey all, 
So I'm trying to filter a list with the built-in function
filter(). My list looks something like this: 
['logs', 'rqp-8.2.104.0.dep', 'rqp-8.2.93.0.dep',
'rqp-win32-app-8.2.96.0-inst.tar.gz',
'rqp-win32-app-8.2.96.0-inst.tar.gz']

Calling filter like this: compFiles = filter(is_Dev, compFiles) 
compFiles is my list and is_dev is the following 

def is_Dev(stringy): 
  print stringy 
  stringx = stringy.split('-') 
  if stringx[1] == r'win32': 
if stringx[2] == r'app': 
  if stringx[4] == r'dev.tar.gz': 
return 1 

For some reason I only get 'logs' printed when is_Dev is called. (ie.
It's only going through is_dev once) 
Does anyone see something wrong that I'm not seeing?? 

Thanks, 

Emile Boudreau 


 
 This message may contain privileged and/or confidential
information.  If you have received this e-mail in error or are not the
intended recipient, you may not use, copy, disseminate or distribute it;
do not open any attachments, delete it immediately from your system and
notify the sender promptly by e-mail that you have done so.  Thank you. 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: numpy performance and list comprehension

2007-04-03 Thread irstas
On Apr 3, 5:42 pm, "TG" <[EMAIL PROTECTED]> wrote:
> Hi there.
>
> Reading the page on python performance (http://scipy.org/PerformancePython
> ) made me realize that I can achieve tremendous code acceleration with
> numpy just by using "u[:,:]" kind of syntax the clever way.
>
> Here is a little problem (Oja's rule of synaptic plasticity)
>
> * W is a matrix containing the weights of connections between elements
> i
> and j
> * V is an array containing the values of elements
>
> I want to make W evolve with this rule :
>
> dW[i,j] / dt = alpha * (V[i] * V[j] - W[i,j] * V[i]^2)
>
> (don't pay attention to the derivate and stuff)
>
> So, how would you write it in this nifty clever way ?
>
> As a begining I wrote this :
>
>   W += V.flatten().reshape((V.size,1)) *
> V.flatten().reshape((1,V.size))
>
> But it is not complete and, I guess, not efficient.

alpha * (V[i] * V[j] - W[i,j] * V[i]^2) =
alpha * V[i] * (V[j] - W[i,j] * V[i])

Assuming that V is a column vector, you could do it like this:

V = array([[5],[3],[7]])
W = array([[1,5,3],[2,2,7],[3,9,8]])
W += alpha * V * (transpose(V) - W * V)

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


Re: XML DTD analysis, diffing ...

2007-04-03 Thread Stéphane Muller
olive a écrit :
> Hi,
> 
> I have a bunch of similar DTDs written by different coders.
> 
> I would like to normalize, sort elements and attributes by name and
> compare those files.
> 
> Do you know any XML DTD parser/normalizer written in Python ?

Yes, you can try http://c.python.free.fr/dtdnormalize.zip

Parse a sample XML file with the document type declaration. There are 
XHTML, SVG and MML samples in the zip file.

The DTDParser is based on the standard xml.parsers.expat module.


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


Re: Problem installing Python 2.5

2007-04-03 Thread Jaroslaw Zabiello
Dnia Tue, 3 Apr 2007 11:52:55 -0300, Sebastian Bassi napisał(a):

> I was trying to install Python 2.5 compiling from sources. I used:
> ./compile
> It run OK.
> Then:
> make altintall
> After a lot of output, got this:
> Listing /usr/local/lib/python2.5/xml/sax ...
> Compiling /usr/local/lib/python2.5/xml/sax/__init__.py ...
> Compiling /usr/local/lib/python2.5/xml/sax/_exceptions.py ...
> Compiling /usr/local/lib/python2.5/xml/sax/expatreader.py ...
> Compiling /usr/local/lib/python2.5/xml/sax/handler.py ...
> Compiling /usr/local/lib/python2.5/xml/sax/saxutils.py ...
> Compiling /usr/local/lib/python2.5/xml/sax/xmlreader.py ...
> Compiling /usr/local/lib/python2.5/xmllib.py ...
> Compiling /usr/local/lib/python2.5/xmlrpclib.py ...
> Compiling /usr/local/lib/python2.5/zipfile.py ...
> make: *** [libinstall] Error 1
> 
> It seems I am not the only one with this error:
> http://www.thescripts.com/forum/thread613458.html
> http://www.megasolutions.net/python/Python-installation-problem-(sorry-if-this-is-a-dup)-22624.aspx
> http://ubuntuforums.org/showthread.php?p=1912370
> 
> System: Freespire 1.0.13 (based on Debian).

After executing 

   ./configure 

you have to edito 

   Modules/Setup 

file and uncomment the following line:

#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

Then continue with normal make; make install.

-- 
Jaroslaw Zabiello
http://blog.zabiello.com
-- 
http://mail.python.org/mailman/listinfo/python-list


low level networking in python

2007-04-03 Thread Maxim Veksler
Hello,

I wish to do some low level network stuff using python.

I've googled somewhat and came up with pylibpcap[1], trouble is I
can't compile it on my Ubuntu 6.10 workstation. Can someone please
suggest a way to read some bits from random ports? I'm looking to
write a simple pen-testing tool that would try from one side
connecting to ports and from the other side sniff traffic to see on
what ports traffic is coming.

For pylibpcap I'm getting:

"""
[EMAIL PROTECTED]:~/development/personal/pylibpcap/pylibpcap-0.5.1$ python
setup.py build
running build
running build_ext
building '_pcapmodule' extension
swig -python -shadow -ISWIG -o pcap.c pcap.i
pcap.i:72: Warning(124): Specifying the language name in %typemap is
deprecated - use #ifdef SWIG instead.
pcap.i:77: Warning(124): Specifying the language name in %typemap is
deprecated - use #ifdef SWIG instead.
pcap.i:82: Warning(124): Specifying the language name in %typemap is
deprecated - use #ifdef SWIG instead.
/usr/bin/python ./build-tools/docify.py pcap.c
/usr/bin/python ./build-tools/docify-shadow.py pcap.py
Traceback (most recent call last):
  File "./build-tools/docify-shadow.py", line 30, in ?
raise 'source file doesn\'t look like swigged shadow class code'
source file doesn't look like swigged shadow class code
error: command '/usr/bin/python' failed with exit status 1
"""

[1] http://pylibpcap.sourceforge.net/
[2] http://py.vaults.ca/apyllo.py/126307487

-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with filter()

2007-04-03 Thread Jerry Hill
On 4/3/07, Boudreau, Emile <[EMAIL PROTECTED]> wrote:
> Sorry folks my mistake def is_dev should be:
> def is_Dev(stringy):
>   stringx = stringy.split('-')
>   if stringx[0] == '':
> if stringx[1] == r'win32':
>   if stringx[2] == r'app':
> if stringx[4] == r'dev.tar.gz':
>   return 1
>
> But now the results of the filter is an empty list and i know it shouldn't
> be.

Well, you haven't told us what you expect the result to be, but as far
as I can tell, an empty list is the correct answer, because you don't
have any files in your list that match your rules.

This line
>   if stringx[0] == '':
is very likely your problem.  That requires that your file start with
a '-', so that after you split it stringx[0] will equal ''.

You may need something more like this:
def is_Dev(stringy):
print stringy
try:
stringx = stringy.split('-')
if stringx[1] == r'win32':
if stringx[2] == r'app':
if stringx[4] == r'dev.tar.gz':
return 1
except IndexError, e:
pass

That will still give you an empty list when run on your proposed
inputs though, because none of them are of the form
-win32-app--dev.tar.gz

If this doesn't help, please give us some sample inputs and what you
expect the output to be.

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


Re: XML/encoding/prolog/python hell...

2007-04-03 Thread fscked
Any ideas?

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


Re: pyc file [Newbie Question]

2007-04-03 Thread Jim Aikin
Thanks, Steven. I'm sure that answers the question.

The Tutorial is very good, but there are numerous topics that it slides past 
(as it would have to do, in order to avoid being ten times as long). I 
haven't yet gotten deep enough into Python to even know where to look for a 
full explanation of what "import" does or what alternatives there might be 
to using it.

--JA




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


Re: low level networking in python

2007-04-03 Thread kyosohma
On Apr 3, 10:29 am, "Maxim Veksler" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I wish to do some low level network stuff using python.
>
> I've googled somewhat and came up with pylibpcap[1], trouble is I
> can't compile it on my Ubuntu 6.10 workstation. Can someone please
> suggest a way to read some bits from random ports? I'm looking to
> write a simple pen-testing tool that would try from one side
> connecting to ports and from the other side sniff traffic to see on
> what ports traffic is coming.
>
> For pylibpcap I'm getting:
>
> """
> [EMAIL PROTECTED]:~/development/personal/pylibpcap/pylibpcap-0.5.1$ python
> setup.py build
> running build
> running build_ext
> building '_pcapmodule' extension
> swig -python -shadow -ISWIG -o pcap.c pcap.i
> pcap.i:72: Warning(124): Specifying the language name in %typemap is
> deprecated - use #ifdef SWIG instead.
> pcap.i:77: Warning(124): Specifying the language name in %typemap is
> deprecated - use #ifdef SWIG instead.
> pcap.i:82: Warning(124): Specifying the language name in %typemap is
> deprecated - use #ifdef SWIG instead.
> /usr/bin/python ./build-tools/docify.py pcap.c
> /usr/bin/python ./build-tools/docify-shadow.py pcap.py
> Traceback (most recent call last):
>   File "./build-tools/docify-shadow.py", line 30, in ?
> raise 'source file doesn\'t look like swigged shadow class code'
> source file doesn't look like swigged shadow class code
> error: command '/usr/bin/python' failed with exit status 1
> """
>
> [1]http://pylibpcap.sourceforge.net/
> [2]http://py.vaults.ca/apyllo.py/126307487
>
> --
> Cheers,
> Maxim Veksler
>
> "Free as in Freedom" - Do u GNU ?

I would assume you could use the socket module. This post details
someone else who opened ports with Python:

http://www.thescripts.com/forum/thread44280.html

Here's another resource using some python servers:

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

Finally, a Socket programming howto:
http://www.amk.ca/python/howto/sockets/

I'm also told that the Twisted framework is excellent for this sort of
thing.

Mike

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


Re: raw_input just continues anyway?

2007-04-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> if __name__ == "__main__":
>   bucket_name = raw_input('Name of the bucket you wish the files to be
> placed into? ')
>   update_s3()
> 
> 
> Basically I pipe some files into the script - so would this cause a
> linebreak?

Yes of course.  `raw_input()` is reading from `stdin` so the very first
line you pipe in will be assigned to `bucket_name`.

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


Re: Problem installing Python 2.5

2007-04-03 Thread Sebastian Bassi
On 4/3/07, Jaroslaw Zabiello <[EMAIL PROTECTED]> wrote:
> After executing
>./configure
> you have to edito
>Modules/Setup
> file and uncomment the following line:
> #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
> Then continue with normal make; make install.

Thank you. I already did this:
make -i altinstall
and then:
make altinstall

And added a comment in bug#1669349
Best,
SB.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getattr/setattr q.

2007-04-03 Thread Paulo da Silva
7stud escreveu:
> On Apr 2, 10:08 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote:
>> Is it possible to use getattr/setattr for variables not inside
>> classes...?
> 
> What does the python documentation say about the definition of
> setattr()?
> 
I didn't read the full python documentation, yet! I hope to survive
until then :-)
In the meanwhile, I searched google for setattr python but all
references I could see were about X.foo type.

One more "RTFM culture" response ...

Thanks.
Paulo

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


Re: getattr/setattr q.

2007-04-03 Thread Paulo da Silva
Steven Bethard escreveu:
> Paulo da Silva wrote:
...

> If you're at the module level, you can do::
> 
> globals()['x'] = 10
> 
> If you're inside a function, you probably want to look for another way
> of doing what you're doing.
> 
> What's the actual task you're trying to accomplish here?


None. I asked just for curiosity. My problem has to do with the normal
case of a class or class instance. When I saw setattr/getattr as the way
to solve my problem I just felt curiosity on if and how it could be done
outside a class.

Thank you very much for your response.
Paulo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: low level networking in python

2007-04-03 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Apr 3, 10:29 am, "Maxim Veksler" <[EMAIL PROTECTED]> wrote:
>> Hello,
>>
>> I wish to do some low level network stuff using python.
>>
>> I've googled somewhat and came up with pylibpcap[1], trouble is I
>> can't compile it on my Ubuntu 6.10 workstation. Can someone please
>> suggest a way to read some bits from random ports? I'm looking to
>> write a simple pen-testing tool that would try from one side
>> connecting to ports and from the other side sniff traffic to see on
>> what ports traffic is coming.
>>
>> For pylibpcap I'm getting:
>>
>> """
>> [EMAIL PROTECTED]:~/development/personal/pylibpcap/pylibpcap-0.5.1$ python
>> setup.py build
>> running build
>> running build_ext
>> building '_pcapmodule' extension
>> swig -python -shadow -ISWIG -o pcap.c pcap.i
>> pcap.i:72: Warning(124): Specifying the language name in %typemap is
>> deprecated - use #ifdef SWIG instead.
>> pcap.i:77: Warning(124): Specifying the language name in %typemap is
>> deprecated - use #ifdef SWIG instead.
>> pcap.i:82: Warning(124): Specifying the language name in %typemap is
>> deprecated - use #ifdef SWIG instead.
>> /usr/bin/python ./build-tools/docify.py pcap.c
>> /usr/bin/python ./build-tools/docify-shadow.py pcap.py
>> Traceback (most recent call last):
>>   File "./build-tools/docify-shadow.py", line 30, in ?
>> raise 'source file doesn\'t look like swigged shadow class code'
>> source file doesn't look like swigged shadow class code
>> error: command '/usr/bin/python' failed with exit status 1
>> """
>>
>> [1]http://pylibpcap.sourceforge.net/
>> [2]http://py.vaults.ca/apyllo.py/126307487
>>
>> --
>> Cheers,
>> Maxim Veksler
>>
>> "Free as in Freedom" - Do u GNU ?
> 
> I would assume you could use the socket module. This post details
> someone else who opened ports with Python:
> 
> http://www.thescripts.com/forum/thread44280.html
> 
> Here's another resource using some python servers:
> 
> http://docs.python.org/lib/socket-example.html
> 
> Finally, a Socket programming howto:
> http://www.amk.ca/python/howto/sockets/
> 
> I'm also told that the Twisted framework is excellent for this sort of
> thing.
> 
The problem with dealing with ports is that you'd have to open each port 
individually. So the OP, I presume, is trying to capture packets 
generically as they arrive at a particular point int he processing cycle 
to avoid that necessity.

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

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


Stack experiment

2007-04-03 Thread tom
Hi! Im new to Python and doing exercise found from internet. It is 
supposed to evaluate expression given with postfix operator using 
Stack() class.

class Stack:
 def __init__(self):
 self.items = []

 def push(self, item):
 self.items.append(item)

 def pop(self):
 return self.items.pop()

 def isEmpty(self):
 return (self.items == [])

def evaluatePostfix(expr):
 import re
 tokenList = re.split(" ([^0-9])", expr)
 stack = Stack()
 for token in tokenList:
 if token == '' or token == ' ':
 continue
 if token == '+':
 sum = stack.pop() + stack.pop()
 stack.push(sum)
 elif token == '*':
 product = stack.pop() * stack.pop()
 stack.push(product)
 else:
 stack.push(int(token))
 return stack.pop()

print evaluatePostfix("56 47 + 2 *")

Errormsg:
Traceback (most recent call last):
   File "C:\*\postfix1.py", line 31, in 
 print evaluatePostfix("56 47 + 2 *")
   File "C:\*\postfix1.py", line 28, in evaluatePostfix
 stack.push(int(token))
ValueError: invalid literal for int() with base 10: '56 47'

How can I avoid the error and get desired result?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python at Google

2007-04-03 Thread olsongt
Here's an article about python at google.  Apologies in advance.

http://valleywag.com/tech/google/missing-python-tracked-down-249208.php

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


Re: getattr/setattr q.

2007-04-03 Thread Steve Holden
Paulo da Silva wrote:
> Steven Bethard escreveu:
>> Paulo da Silva wrote:
> ...
> 
>> If you're at the module level, you can do::
>>
>> globals()['x'] = 10
>>
>> If you're inside a function, you probably want to look for another way
>> of doing what you're doing.
>>
>> What's the actual task you're trying to accomplish here?
> 
> 
> None. I asked just for curiosity. My problem has to do with the normal
> case of a class or class instance. When I saw setattr/getattr as the way
> to solve my problem I just felt curiosity on if and how it could be done
> outside a class.
> 
> Thank you very much for your response.
> Paulo

You don't need setattr/getattr if you know in advance the name of the 
attribute you need to access and you can get a reference to the object 
whose attribute it is. So:

  >>> import sys
  >>> x = "Hello, Paulo"
  >>> sys.modules['__main__'].x
'Hello, Paulo'
  >>> globals()['x']
'Hello, Paulo'
  >>>

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

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


Re: Stack experiment

2007-04-03 Thread irstas

[EMAIL PROTECTED] wrote:
> Hi! Im new to Python and doing exercise found from internet. It is
> supposed to evaluate expression given with postfix operator using
> Stack() class.
>
> class Stack:
>  def __init__(self):
>  self.items = []
>
>  def push(self, item):
>  self.items.append(item)
>
>  def pop(self):
>  return self.items.pop()
>
>  def isEmpty(self):
>  return (self.items == [])
>
> def evaluatePostfix(expr):
>  import re
>  tokenList = re.split(" ([^0-9])", expr)
>  stack = Stack()
>  for token in tokenList:
>  if token == '' or token == ' ':
>  continue
>  if token == '+':
>  sum = stack.pop() + stack.pop()
>  stack.push(sum)
>  elif token == '*':
>  product = stack.pop() * stack.pop()
>  stack.push(product)
>  else:
>  stack.push(int(token))
>  return stack.pop()
>
> print evaluatePostfix("56 47 + 2 *")
>
> Errormsg:
> Traceback (most recent call last):
>File "C:\*\postfix1.py", line 31, in 
>  print evaluatePostfix("56 47 + 2 *")
>File "C:\*\postfix1.py", line 28, in evaluatePostfix
>  stack.push(int(token))
> ValueError: invalid literal for int() with base 10: '56 47'
>
> How can I avoid the error and get desired result?

Obviously your tokens are wrong since one of the tokens is '56 47' as
the error message indicates.

import re
print re.split(" ([^0-9])", "56 47 + 2 *")

It looks like you'd just want expr.split().

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


Re: Stack experiment

2007-04-03 Thread kyosohma
On Apr 3, 10:57 am, [EMAIL PROTECTED] wrote:
> Hi! Im new to Python and doing exercise found from internet. It is
> supposed to evaluate expression given with postfix operator using
> Stack() class.
>
> class Stack:
>  def __init__(self):
>  self.items = []
>
>  def push(self, item):
>  self.items.append(item)
>
>  def pop(self):
>  return self.items.pop()
>
>  def isEmpty(self):
>  return (self.items == [])
>
> def evaluatePostfix(expr):
>  import re
>  tokenList = re.split(" ([^0-9])", expr)
>  stack = Stack()
>  for token in tokenList:
>  if token == '' or token == ' ':
>  continue
>  if token == '+':
>  sum = stack.pop() + stack.pop()
>  stack.push(sum)
>  elif token == '*':
>  product = stack.pop() * stack.pop()
>  stack.push(product)
>  else:
>  stack.push(int(token))
>  return stack.pop()
>
> print evaluatePostfix("56 47 + 2 *")
>
> Errormsg:
> Traceback (most recent call last):
>File "C:\*\postfix1.py", line 31, in 
>  print evaluatePostfix("56 47 + 2 *")
>File "C:\*\postfix1.py", line 28, in evaluatePostfix
>  stack.push(int(token))
> ValueError: invalid literal for int() with base 10: '56 47'
>
> How can I avoid the error and get desired result?

I don't know why you're using the "re" module. For this, I would skip
it. Change your code so that it looks like this:

def evaluatePostfix(expr):
 tokenList = expr.split(" ")
 stack = Stack()
 for token in tokenList:
 if token == '' or token == ' ':
 continue
 if token == '+':
 sum = stack.pop() + stack.pop()
 stack.push(sum)
 elif token == '*':
 product = stack.pop() * stack.pop()
 stack.push(product)
 else:
 stack.push(int(token))
return stack.pop()

# this worked for me. There may be something wrong with the "re" code
in your example, but I don't know enough about that to help in that
area.

Mike

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


How to have a list of lists (or array of lists)

2007-04-03 Thread bahoo
Hi,

I want to have many lists, such as list0, list1, list2, ..., each one
holding different number of items.
Is there something like
list[0]
list[1]
list[2]

so that I can iterate through this list of lists?

Thanks!
bahoo

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


Re: Stack experiment

2007-04-03 Thread Richard Brodie

<[EMAIL PROTECTED]> wrote in message

>There may be something wrong with the "re" code in your example,
>but I don't know enough about that to help in that area.

There is a stray leading space in it. 


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


Re: Stack experiment

2007-04-03 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Hi! Im new to Python and doing exercise found from internet. It is 
> supposed to evaluate expression given with postfix operator using 
> Stack() class.
> 
> class Stack:
>  def __init__(self):
>  self.items = []
> 
>  def push(self, item):
>  self.items.append(item)
> 
>  def pop(self):
>  return self.items.pop()
> 
>  def isEmpty(self):
>  return (self.items == [])
> 
> def evaluatePostfix(expr):
>  import re
>  tokenList = re.split(" ([^0-9])", expr)

If you add a print statement here I think you will find that the 
tokenisation here isn't really what you want:

  >>> expr = "56 47 + 2 *"
  >>> re.split(" ([^0-9])", expr)
['56 47', '+', ' 2', '*', '']

>  stack = Stack()
>  for token in tokenList:
>  if token == '' or token == ' ':
>  continue
>  if token == '+':
>  sum = stack.pop() + stack.pop()
>  stack.push(sum)
>  elif token == '*':
>  product = stack.pop() * stack.pop()
>  stack.push(product)
>  else:
>  stack.push(int(token))
>  return stack.pop()
> 
> print evaluatePostfix("56 47 + 2 *")
> 
> Errormsg:
> Traceback (most recent call last):
>File "C:\*\postfix1.py", line 31, in 
>  print evaluatePostfix("56 47 + 2 *")
>File "C:\*\postfix1.py", line 28, in evaluatePostfix
>  stack.push(int(token))
> ValueError: invalid literal for int() with base 10: '56 47'
> 
> How can I avoid the error and get desired result?

I'd try using

tokenList = split(expr)

instead - this has the added benefit of removing the spaces, so you can 
simplify your code by removing the case that handles empty tokens and 
sapaces, I suspect.

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

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


Re: How to have a list of lists (or array of lists)

2007-04-03 Thread irstas
On Apr 3, 7:12 pm, "bahoo" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I want to have many lists, such as list0, list1, list2, ..., each one
> holding different number of items.
> Is there something like
> list[0]
> list[1]
> list[2]
>
> so that I can iterate through this list of lists?
>
> Thanks!
> bahoo

listOfLists = [[1,2], [5,7,9], [4,2,1,4,6,6]]

No problem there. The lists can contain any objects, including lists.

for x in listOfLists:
print 'list:',
for y in x:
print y,
print

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


Re: Stack experiment

2007-04-03 Thread irstas
On Apr 3, 7:14 pm, "Richard Brodie" <[EMAIL PROTECTED]> wrote:
> <[EMAIL PROTECTED]> wrote in message
> >There may be something wrong with the "re" code in your example,
> >but I don't know enough about that to help in that area.
>
> There is a stray leading space in it.

Nah, I'd say there's a stray ([^0-9]) after the space. With just space
in it (same as basic split) one would get the tokens 56, 47, +, 2 and
*. Without the space one would get: ['56', ' ', '47', ' + ', '2', '
*', '']

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


Re: Stack experiment

2007-04-03 Thread Matimus
On Apr 3, 8:57 am, [EMAIL PROTECTED] wrote:
> Hi! Im new to Python and doing exercise found from internet. It is
> supposed to evaluate expression given with postfix operator using
> Stack() class.
>
> class Stack:
>  def __init__(self):
>  self.items = []
>
>  def push(self, item):
>  self.items.append(item)
>
>  def pop(self):
>  return self.items.pop()
>
>  def isEmpty(self):
>  return (self.items == [])
>
> def evaluatePostfix(expr):
>  import re
>  tokenList = re.split(" ([^0-9])", expr)
>  stack = Stack()
>  for token in tokenList:
>  if token == '' or token == ' ':
>  continue
>  if token == '+':
>  sum = stack.pop() + stack.pop()
>  stack.push(sum)
>  elif token == '*':
>  product = stack.pop() * stack.pop()
>  stack.push(product)
>  else:
>  stack.push(int(token))
>  return stack.pop()
>
> print evaluatePostfix("56 47 + 2 *")
>
> Errormsg:
> Traceback (most recent call last):
>File "C:\*\postfix1.py", line 31, in 
>  print evaluatePostfix("56 47 + 2 *")
>File "C:\*\postfix1.py", line 28, in evaluatePostfix
>  stack.push(int(token))
> ValueError: invalid literal for int() with base 10: '56 47'
>
> How can I avoid the error and get desired result?

Two things:
1. The regular expression contains a space, so it is trying to split
on a space character followed by a non number, when you really want to
split on any nonnumber. Remove the space.

tokenList = re.split(" ([^0-9])", expr) -> tokenList =
re.split("([^0-9])", expr)

2. The return statement in evaluatePostfix is part of the for loop, it
will exit on the first loop.

This:

for token in tokenList:
if token == '' or token == ' ':
continue
if token == '+':
sum = stack.pop() + stack.pop()
stack.push(sum)
elif token == '*':
product = stack.pop() * stack.pop()
stack.push(product)
else:
stack.push(int(token))
return stack.pop()

Should Be:

for token in tokenList:
if token == '' or token == ' ':
continue
if token == '+':
sum = stack.pop() + stack.pop()
stack.push(sum)
elif token == '*':
product = stack.pop() * stack.pop()
stack.push(product)
else:
stack.push(int(token))
return stack.pop()

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


Problem with filter()

2007-04-03 Thread Birone Lynch

"""Sorry folks my mistake def is_dev should be:


def is_Dev(stringy):
  stringx = stringy.split('-')
  if stringx[0] == '':
if stringx[1] == r'win32':
  if stringx[2] == r'app':
if stringx[4] == r'dev.tar.gz':
  return 1

But now the results of the filter is an empty list and i know it shouldn't
be."""



I think the problem is the first "if" - using the list from your previous
mail, stringx[0] is never empty. So the filter fn never returns true, & the
return list is empty...
stringx[4] never matches either.

This is what I did:

compFiles=['logs', 'rqp-8.2.104.0.dep', 'rqp-8.2.93.0.dep', '

rqp-win32-app-8.2.96.0-inst.tar.gz', 'rqp-win32-app-8.2.96.0-inst.tar.gz ']

for i in compFiles:

   print i.split('-')   # ie the equivalent of stringx

['logs']
['rqp', '8.2.104.0.dep']
['rqp', '8.2.93.0.dep']
['rqp', 'win32', 'app', ' 8.2.96.0', 'inst.tar.gz']
['rqp', 'win32', 'app', ' 8.2.96.0', 'inst.tar.gz']

Birone
PS - I'm new at this.  Please forgive me if I got it totally wrong!
-- 
http://mail.python.org/mailman/listinfo/python-list

Retrieve an item from a dictionary using an arbitrary object as the key

2007-04-03 Thread abcd
Hi,
I have a class such as,

class Type:
def __init__(self, val):
self.val = val

class Person:
def __init__(self, name, age):
self.name = name
self.age = age

So I have a dictionary which maps an instance of Type to an instance
of Person.  Now I need to retrieve a particular Person given a Type
object.  What method in Type do I need to implement to allow it to be
retrieved?

For example (this is just an example):

t = Type(19)
p = Person("bob", 99)

x = {t : p}



def getPerson(val):
return x[Type(val)]

getPerson(19)  should return me the Person with name "bob" and age
99.  I am thinking there is some method that is used by the dictionary
to know if the key exists, just not sure which.

thanks

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


Re: Stack experiment

2007-04-03 Thread Richard Brodie

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

>> There is a stray leading space in it.
>
> Nah, I'd say there's a stray ([^0-9]) after the space.

If you regard the spaces as being a required part of the postfix
grammar, it would be simpler. But who would design a language
where white space was significant ;) 


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


Re: Stack experiment

2007-04-03 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
| Hi! Im new to Python and doing exercise found from internet. It is
| supposed to evaluate expression given with postfix operator using
| Stack() class.
|
| class Stack:
| def __init__(self):
| self.items = []
|
| def push(self, item):
| self.items.append(item)
|
| def pop(self):
| return self.items.pop()
|
| def isEmpty(self):
| return (self.items == [])
|
| def evaluatePostfix(expr):
| import re
| tokenList = re.split(" ([^0-9])", expr)

To see what is wrong, print tokenList.
tokenList = expr.split() is probably what you want

| stack = Stack()
| for token in tokenList:
| if token == '' or token == ' ':
| continue
| if token == '+':
| sum = stack.pop() + stack.pop()
| stack.push(sum)
| elif token == '*':
| product = stack.pop() * stack.pop()
| stack.push(product)
| else:
| stack.push(int(token))
| return stack.pop()
|
| print evaluatePostfix("56 47 + 2 *")
|
| Errormsg:
| Traceback (most recent call last):
|   File "C:\*\postfix1.py", line 31, in 
| print evaluatePostfix("56 47 + 2 *")
|   File "C:\*\postfix1.py", line 28, in evaluatePostfix
| stack.push(int(token))
| ValueError: invalid literal for int() with base 10: '56 47'
|
| How can I avoid the error and get desired result?
| -- 
| http://mail.python.org/mailman/listinfo/python-list
| 



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


Re: Retrieve an item from a dictionary using an arbitrary object as the key

2007-04-03 Thread irstas
On Apr 3, 7:26 pm, "abcd" <[EMAIL PROTECTED]> wrote:
> Hi,
> I have a class such as,
>
> class Type:
> def __init__(self, val):
> self.val = val
>
> class Person:
> def __init__(self, name, age):
> self.name = name
> self.age = age
>
> So I have a dictionary which maps an instance of Type to an instance
> of Person.  Now I need to retrieve a particular Person given a Type
> object.  What method in Type do I need to implement to allow it to be
> retrieved?
>
> For example (this is just an example):
>
> t = Type(19)
> p = Person("bob", 99)
>
> x = {t : p}
>
> 
>
> def getPerson(val):
> return x[Type(val)]
>
> getPerson(19)  should return me the Person with name "bob" and age
> 99.  I am thinking there is some method that is used by the dictionary
> to know if the key exists, just not sure which.
>
> thanks

You'll need __eq__ for testing if two objects are equivalent, and
__hash__ for calculating object's hash value.

class Type:
def __init__(self, val):
self.val = val

def __eq__(self, other):
return self.val == other.val

def __hash__(self):
return hash(self.val)


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


Re: getattr/setattr q.

2007-04-03 Thread Steven Bethard
Steve Holden wrote:
> You don't need setattr/getattr if you know in advance the name of the 
> attribute you need to access and you can get a reference to the object 
> whose attribute it is. So:
> 
>  >>> x = "Hello, Paulo"
>  >>> import sys
>  >>> sys.modules['__main__'].x
> 'Hello, Paulo'

a.k.a

 >>> import __main__
 >>> __main__.x
 'Hello, Paulo'

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


Re: getattr/setattr q.

2007-04-03 Thread Steve Holden
Steven Bethard wrote:
> Steve Holden wrote:
>> You don't need setattr/getattr if you know in advance the name of the 
>> attribute you need to access and you can get a reference to the object 
>> whose attribute it is. So:
>>
>>  >>> x = "Hello, Paulo"
>>  >>> import sys
>>  >>> sys.modules['__main__'].x
>> 'Hello, Paulo'
> 
> a.k.a
> 
>  >>> import __main__
>  >>> __main__.x
>  'Hello, Paulo'
> 
Indeed. Any handle on the right object will do.

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

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


Re: Stack experiment

2007-04-03 Thread Steve Holden
[EMAIL PROTECTED] wrote:
[...]
> 
> Steve,
> 
> How do you do "tokenList = split(expr)"? There is no builtin called
> "split".
> 
> Mike
> 

Sorry, that should have been a call to the .split() method of expr, i.e.:

tokenList = expr.split()

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

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


Re: Numeric compiling problem under QNX 4.25

2007-04-03 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Hi,
> 
> unfortunately I don't have a solution. However, if you're not forced
> to use Python2.2 and Numeric you should use Numpy (the successor for
> both, Numeric and Numarray). Numpy requires Python2.3, though.

He's already asked about numpy. He is stuck with 2.2.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


How can I kill a running thread when exiting from __main__

2007-04-03 Thread care02
Hi!

I have the following problem: I have written a short Python server
that creates an indefinite simulation thread that I want to kill when
quitting (Ctrl-C) from Python. Googling around has not given me any
hints on how to cleanly kill running threads before exiting. Any help
is appreciated!

Carl

### CODE EXTRACT ###

import pythoncom

class QueueThread( threading.Thread):
def __init__(self, command):
threading.Thread.__init__(self)
self.command = command

def run(self):
pythoncom.CoInitialize()
try:
object = Dispatch('application')
execute = getattr(object, 'Execute')
execute(self.command )
finally:
object = None
pythoncom.CoUnitialize()

queuethread = QueueThread("queuehandler")
queuethread.setDaemon(True)
queuethread.start()

## How can I kill "queuethread" when exiting (Ctrl-C)?

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


Extracting a file from a tarball

2007-04-03 Thread Boudreau, Emile
I am trying to extract one file from a tarball, without success. This is
the code I'm using to open the tarball and extract the file:

tar = tarfile.open(component+'-win32-app-'+bestVersion+'-dev.tar.gz',
'r')
extractedFile = tar.extractfile('symbols.xml')

And this is my error:

Traceback (most recent call last):
  File "C:\CognosInstalls\AutoTest\PollDir.py", line 121, in 
main()
  File "C:\CognosInstalls\AutoTest\PollDir.py", line 119, in main
extract('c:\\', 'I:\\daily\\'+components[i], components[i])
  File "C:\CognosInstalls\AutoTest\PollDir.py", line 27, in extract
filelike = tar.extractfile('symbols.xml')
  File "C:\Python25\lib\tarfile.py", line 1488, in extract
tarinfo = self.getmember(member)
  File "C:\Python25\lib\tarfile.py", line 1171, in getmember
raise KeyError("filename %r not found" % name)
KeyError: "filename 'symbols.xml' not found"

I know that the tarball contants this file "symbols.xml" but I don't
understand why it's not extracting it. Any help will be greatly
appreciated.

Thanks,

Emile Boudreau
 
 This message may contain privileged and/or confidential information.  If 
you have received this e-mail in error or are not the intended recipient, you 
may not use, copy, disseminate or distribute it; do not open any attachments, 
delete it immediately from your system and notify the sender promptly by e-mail 
that you have done so.  Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: numpy performance and list comprehension

2007-04-03 Thread Robert Kern
TG wrote:
> Hi there.
> 
> Reading the page on python performance ( http://scipy.org/PerformancePython
> ) made me realize that I can achieve tremendous code acceleration with
> numpy just by using "u[:,:]" kind of syntax the clever way.
> 
> Here is a little problem (Oja's rule of synaptic plasticity)
> 
> * W is a matrix containing the weights of connections between elements
> i
> and j
> * V is an array containing the values of elements
> 
> I want to make W evolve with this rule :
> 
> dW[i,j] / dt = alpha * (V[i] * V[j] - W[i,j] * V[i]^2)
> 
> (don't pay attention to the derivate and stuff)
> 
> So, how would you write it in this nifty clever way ?

irstas is correct. I'm just going to show off another feature of numpy,
numpy.newaxis.

import numpy as np

V = np.array([1, 2, 3])
VT = V[:, np.newaxis]  # VT.shape == (3, 1)

W = np.array([[1,2,3], [4,5,6], [7,8,9]])

dWdt = alpha * VT*(V - W*VT)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: How can I kill a running thread when exiting from __main__

2007-04-03 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Hi!
> 
> I have the following problem: I have written a short Python server
> that creates an indefinite simulation thread that I want to kill when
> quitting (Ctrl-C) from Python. Googling around has not given me any
> hints on how to cleanly kill running threads before exiting. Any help
> is appreciated!
> 
> Carl
> 
> ### CODE EXTRACT ###
> 
> import pythoncom
> 
> class QueueThread( threading.Thread):
> def __init__(self, command):
> threading.Thread.__init__(self)
> self.command = command
> 
> def run(self):
> pythoncom.CoInitialize()
> try:
> object = Dispatch('application')
> execute = getattr(object, 'Execute')
> execute(self.command )
> finally:
> object = None
> pythoncom.CoUnitialize()
> 
> queuethread = QueueThread("queuehandler")
> queuethread.setDaemon(True)
> queuethread.start()
> 
> ## How can I kill "queuethread" when exiting (Ctrl-C)?
> 
The only way to do this is to have the thread regularly examine a 
"please quit" flag that is set from the main thread when termination is 
required.

There have been many suggestions to allow external forced termination of 
threads, but this is impossible to specify in a clean way that is both 
platform-independent and reliable, so it's not likely to happen.

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

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


Re: How can I kill a running thread when exiting from __main__

2007-04-03 Thread kyosohma
On Apr 3, 12:21 pm, [EMAIL PROTECTED] wrote:
> Hi!
>
> I have the following problem: I have written a short Python server
> that creates an indefinite simulation thread that I want to kill when
> quitting (Ctrl-C) from Python. Googling around has not given me any
> hints on how to cleanly kill running threads before exiting. Any help
> is appreciated!
>
> Carl
>
> ### CODE EXTRACT ###
>
> import pythoncom
>
> class QueueThread( threading.Thread):
> def __init__(self, command):
> threading.Thread.__init__(self)
> self.command = command
>
> def run(self):
> pythoncom.CoInitialize()
> try:
> object = Dispatch('application')
> execute = getattr(object, 'Execute')
> execute(self.command )
> finally:
> object = None
> pythoncom.CoUnitialize()
>
> queuethread = QueueThread("queuehandler")
> queuethread.setDaemon(True)
> queuethread.start()
>
> ## How can I kill "queuethread" when exiting (Ctrl-C)?

If you can get the pid of the process you created, you should be able
to use the killProcName function that's included with the win32
package...if you're server is a Windows box. You should be able to use
the join() method if you don't set your thread to a Daemon.

This post talks about using the os module to kill a thread as well:

http://www.daniweb.com/techtalkforums/thread36752.html

The wxPython wiki has one of the best threading examples I've seen:
http://wiki.wxpython.org/index.cgi/LongRunningTasks

Mike

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


Re: XML DTD analysis, diffing ...

2007-04-03 Thread olive
Thank you Stephane,

it is almost what I want.

I'm going to improve it a little and then provide the code back.
Where is the best place ?

Olive.


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


Re: Retrieve an item from a dictionary using an arbitrary object as the key

2007-04-03 Thread abcd
> You'll need __eq__ for testing if two objects are equivalent, and
> __hash__ for calculating object's hash value.
>
> class Type:
> def __init__(self, val):
> self.val = val
>
> def __eq__(self, other):
> return self.val == other.val
>
> def __hash__(self):
> return hash(self.val)

that's exactly what I needed, thanks.

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


Re: Stack experiment

2007-04-03 Thread kyosohma
On Apr 3, 11:17 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hi! Im new to Python and doing exercise found from internet. It is
> > supposed to evaluate expression given with postfix operator using
> > Stack() class.
>
> > class Stack:
> >  def __init__(self):
> >  self.items = []
>
> >  def push(self, item):
> >  self.items.append(item)
>
> >  def pop(self):
> >  return self.items.pop()
>
> >  def isEmpty(self):
> >  return (self.items == [])
>
> > def evaluatePostfix(expr):
> >  import re
> >  tokenList = re.split(" ([^0-9])", expr)
>
> If you add a print statement here I think you will find that the
> tokenisation here isn't really what you want:
>
>   >>> expr = "56 47 + 2 *"
>   >>> re.split(" ([^0-9])", expr)
> ['56 47', '+', ' 2', '*', '']
>
>
>
> >  stack = Stack()
> >  for token in tokenList:
> >  if token == '' or token == ' ':
> >  continue
> >  if token == '+':
> >  sum = stack.pop() + stack.pop()
> >  stack.push(sum)
> >  elif token == '*':
> >  product = stack.pop() * stack.pop()
> >  stack.push(product)
> >  else:
> >  stack.push(int(token))
> >  return stack.pop()
>
> > print evaluatePostfix("56 47 + 2 *")
>
> > Errormsg:
> > Traceback (most recent call last):
> >File "C:\*\postfix1.py", line 31, in 
> >  print evaluatePostfix("56 47 + 2 *")
> >File "C:\*\postfix1.py", line 28, in evaluatePostfix
> >  stack.push(int(token))
> > ValueError: invalid literal for int() with base 10: '56 47'
>
> > How can I avoid the error and get desired result?
>
> I'd try using
>
> tokenList = split(expr)
>
> instead - this has the added benefit of removing the spaces, so you can
> simplify your code by removing the case that handles empty tokens and
> sapaces, I suspect.
>
> regards
>   Steve
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenwebhttp://del.icio.us/steve.holden
> Recent Ramblings  http://holdenweb.blogspot.com

Steve,

How do you do "tokenList = split(expr)"? There is no builtin called
"split".

Mike

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


Re: Extracting a file from a tarball

2007-04-03 Thread Carsten Haese
On Tue, 2007-04-03 at 13:26 -0400, Boudreau, Emile wrote:
> I am trying to extract one file from a tarball, without success. This
> is the code I'm using to open the tarball and extract the file:
> 
> tar = tarfile.open(component+'-win32-app-'+bestVersion+'-dev.tar.gz',
> 'r') 
> extractedFile = tar.extractfile('symbols.xml')
> 
> And this is my error:
> 
> Traceback (most recent call last): 
>   File "C:\CognosInstalls\AutoTest\PollDir.py", line 121, in  
> main() 
>   File "C:\CognosInstalls\AutoTest\PollDir.py", line 119, in main 
> extract('c:\\', 'I:\\daily\\'+components[i], components[i]) 
>   File "C:\CognosInstalls\AutoTest\PollDir.py", line 27, in extract 
> filelike = tar.extractfile('symbols.xml') 
>   File "C:\Python25\lib\tarfile.py", line 1488, in extract 
> tarinfo = self.getmember(member) 
>   File "C:\Python25\lib\tarfile.py", line 1171, in getmember 
> raise KeyError("filename %r not found" % name) 
> KeyError: "filename 'symbols.xml' not found"
> 
> I know that the tarball contants this file "symbols.xml"

What does tar.getnames() return?

-Carsten


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


Re: Numeric compiling problem under QNX 4.25

2007-04-03 Thread Robert Kern
ZMY wrote:
> Dear all,
> 
> I am a real newbie for both python and QNX, but I am still trying to
> compile Numeric-24.2 under QNX4.25 with python 2.2. I got following
> error message:
> 
> 
> $ sudo python setup.py install
> Password:
> running install
> ...
> building '_numpy' extension
> skipping Src/_numpymodule.c (build/temp.qnx-O-PCI-2.2/_numpymodule.o
> up-to-date)
> skipping Src/arrayobject.c (build/temp.qnx-O-PCI-2.2/arrayobject.o up-
> to-date)
> skipping Src/ufuncobject.c (build/temp.qnx-O-PCI-2.2/ufuncobject.o up-
> to-date)
> ld build/temp.qnx-O-PCI-2.2/_numpymodule.o build/temp.qnx-O-PCI-2.2/
> arrayobject.o build/temp.qnx-O-PCI-2.2/ufuncobject.o -o build/lib.qnx-
> O-PCI-2.2/_numpy.so
> unable to execute ld: No such file or directory
> error: command 'ld' failed with exit status 1

It looks like it can't find the command ld. Can you compile any other extension
modules?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Stack experiment

2007-04-03 Thread tom
Ok, I got it running. Thank you!

I removed the space and top of that I had foul indentation in return 
statement.

I'll try the approaches you suggest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I kill a running thread when exiting from __main__

2007-04-03 Thread skip

Steve> The only way to do this is to have the thread regularly examine a
Steve> "please quit" flag that is set from the main thread when
Steve> termination is required.

I thought the process would terminate when only daemon threads were left.

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


Re: Numeric compiling problem under QNX 4.25

2007-04-03 Thread ZMY
On Apr 3, 10:22 am, Robert Kern <[EMAIL PROTECTED]> wrote:
> ZMY wrote:
> > Dear all,
>
> > I am a real newbie for both python and QNX, but I am still trying to
> > compile Numeric-24.2 under QNX4.25 with python 2.2. I got following
> > error message:
>
> > $ sudo python setup.py install
> > Password:
> > running install
> > ...
> > building '_numpy' extension
> > skipping Src/_numpymodule.c (build/temp.qnx-O-PCI-2.2/_numpymodule.o
> > up-to-date)
> > skipping Src/arrayobject.c (build/temp.qnx-O-PCI-2.2/arrayobject.o up-
> > to-date)
> > skipping Src/ufuncobject.c (build/temp.qnx-O-PCI-2.2/ufuncobject.o up-
> > to-date)
> > ld build/temp.qnx-O-PCI-2.2/_numpymodule.o build/temp.qnx-O-PCI-2.2/
> > arrayobject.o build/temp.qnx-O-PCI-2.2/ufuncobject.o -o build/lib.qnx-
> > O-PCI-2.2/_numpy.so
> > unable to execute ld: No such file or directory
> > error: command 'ld' failed with exit status 1
>
> It looks like it can't find the command ld. Can you compile any other 
> extension
> modules?
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>  that is made terrible by our own mad attempt to interpret it as though it had
>  an underlying truth."
>   -- Umberto Eco

Is "ld" part of make command? I am not familiar with compiling with
make in general.

Most other extensions (including math, os, struct, cPickle) from
Python 2.2 works when I install python on QNX.

Thanks a lot to all of you.

-ZMY

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


Re: python installation destination directory

2007-04-03 Thread ZMY
On Apr 3, 6:26 am, "Kushal Kumaran" <[EMAIL PROTECTED]> wrote:
> On Apr 3, 9:33 am, "ZMY" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi all,
>
> > I am installing python 2.2 on QNX4.25 but can't get it into /usr/local/
> > bin/ directory. Here is what I did:
>
> > 1) untar Python-2.2 into directory /openqnx/Python-2.2/
>
> > 2) use command:
> > CONFIG_SHELL=/usr/local/bin/bash CC=cc RANLIB=:
> > ./configure --verbose --without-gcc --with-libm=""
>
> > 3) Enabled array, math, os, struct, time, cmath modules
>
> > 4) use command:
> > make SHELL=/usr/local/bin/bash
>
> > and I got a python excutable in directory
> >  /openqnx/Python-2.2/
>
> > which works well with all the modules. But I really want to have it
> > at /usr/local/bin
>
> > I checked the Makefile, and it seems python should be installed in /
> > usr/local/bin instead, since I got following lines in Makefile:
>
> > # Install prefix for architecture-independent files
> > prefix= /usr/local
>
> > # Install prefix for architecture-dependent files
> > exec_prefix=${prefix}
>
> > Do any of you know what the problem is?
>
> You need to do a make install.
>
> --
> Kushal

Thanks. It works.

-ZMY

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


troubles building python 2.5 on Windows XP x64 Windows Server 2003 sp1 Platform SDK

2007-04-03 Thread bhochstetler
I am needing to build python 2.5 on Windows XP x64 Windows Server 2003
sp1 Platform SDK and am not finding anything documented on the process
to use. Has anyone had any success with this? If so has anyone
documented it? The documentation that resides in pcbuild/readme.txt is
not helpful at all.
Any help is greatly appreciated.

Thanks
Brad

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


  1   2   3   >