Leipzig Python User Group - Meeting, February 13, 2007, 8:00pm

2007-02-11 Thread Mike Müller
=
Leipzig Python User Group
=

Next Meeting Tuesday, February 13, 2007


We will meet on February 13 at 8:00 pm at the training center
of Python Academy in Leipzig, Germany
(http://www.python-academy.com/center/find.html).

This time our main topic will be Pyrex 
(http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex).
Pyrex makes writing Python extension much easier.
Members of our User Group achieved run time improvements
with Pyrex that exceed the factor of ten.
As usual, there also will be discussions about other Python topics.

Food and soft drinks are provided. Please send a short confirmation
mail to [EMAIL PROTECTED], so we can prepare appropriately.

Everybody who uses Python, plans to do so or is interested in learning
more about the language is encouraged to participate.

While the meeting language will be mainly German, English speakers are
very welcome. We will provide English interpretation if needed.

Current information about the meetings can always be found at
http://www.python-academy.com/user-group/index.html



=
Leipzig Python User Group
=

Stammtisch am 09.01.2007
-

Wir treffen uns am 09.01.2007 um 20:00 Uhr wieder im
im Schulungszentrum der Python Academy in Leipzig
(http://www.python-academy.de/Schulungszentrum/anfahrt.html).

Unser Thema ist diesmal Trac (http://trac.edgewall.org/).
Stefan Schwarzer wird die Nutzung von Trac mit Beispielen
erläutern.

Für das leibliche Wohl wird gesorgt.
Wir bitten um kurze Anmeldung per e-mail an: [EMAIL PROTECTED]

An den Treffen der Python Anwendergruppe kann jeder teilnehmen,
der Interesse an Python hat, die Sprache bereits nutzt oder nutzen möchte.

Die Arbeitssprachen des Treffens ist Deutsch. Englisch sprechende
Python-Enthusiasten sind trotzdem herzlich eingeladen. Wir übersetzen gern.

Aktuelle Informationen zu den Treffen sind immer unter
http://www.python-academy.de/User-Group/index.html
zu finden.


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


[ANN] Initial release of Throxy: throttling HTTP proxy in one Python file

2007-02-11 Thread Johann C. Rocholl
Throxy: throttling HTTP proxy in one Python file

* Simulate a slow connection (like dial-up).
* Adjustable bandwidth limit for download and upload.
* Optionally dump HTTP headers and content for debugging.
* Decompress gzip content encoding for debugging.
* Multiple connections, without threads (uses asyncore).
* Only one source file, written in pure Python.

To use it, run throxy.py on your local machine and adjust your browser
settings to use 127.0.0.1:8080 as HTTP proxy.

Simulate analog modem connection:
$ python throxy.py -u28.8 -d57.6

Show all HTTP headers (request  reply):
$ python throxy.py -qrs

Dump HTTP headers and content to a file, without size limits:
$ python throxy.py -rsRS -l0 -L0 -g0  dump.txt

Tell command line tools to use the proxy:
$ export http_proxy=127.0.0.1:8080

Command line options:
  --version   show program's version number and exit
  -h, --help  show this help message and exit
  -i ip listen on this interface only (default all)
  -p port   listen on this port number (default 8080)
  -d kbps   download bandwidth in kbps (default 28.8)
  -u kbps   upload bandwidth in kbps (default 28.8)
  -o  allow remote clients (WARNING: open proxy)
  -q  don't show connect and disconnect messages
  -s  dump headers sent to server
  -r  dump headers received from server
  -S  dump content sent to server
  -R  dump content received from server
  -l bytes  maximum length of dumped text content (default 1024)
  -L bytes  maximum length of dumped binary content (default 256)
  -g bytes  maximum size for gzip decompression (default 8192)

Subversion repository (or simple download):
http://svn.browsershots.org/trunk/throxy/throxy.py

Pretty source code (and change history):
http://trac.browsershots.org/browser/trunk/throxy/throxy.py

This is a very early release. Please send feedback per email.
Alternatively, you can file bugs and feature requests here:
http://trac.browsershots.org/newticket?component=throxy

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: HTML Parsing

2007-02-11 Thread John Machin
On Feb 11, 6:05 pm, Ayaz Ahmed Khan [EMAIL PROTECTED] wrote:
 mtuller typed:

  I have also tried Beautiful Soup, but had trouble understanding the
  documentation

 As Gabriel has suggested, spend a little more time going through the
 documentation of BeautifulSoup. It is pretty easy to grasp.

 I'll give you an example: I want to extract the text between the
 following span tags in a large HTML source file.

 span class=titleLinux Kernel Bluetooth CAPI Packet Remote Buffer Overflow 
 Vulnerability/span

  import re
  from BeautifulSoup import BeautifulSoup
  from urllib2 import urlopen
  soup = BeautifulSoup(urlopen('http://www.someurl.tld/'))
  title = soup.find(name='span', attrs={'class':'title'}, 
  text=re.compile(r'^Linux \w+'))
  title

 u'Linux Kernel Bluetooth CAPI Packet Remote Buffer Overflow Vulnerability'


One can even use ElementTree, if the HTML is well-formed. See below.
However if it is as ill-formed as the sample (4th td element not
closed; I've omitted it below), then the OP would be better off
sticking with Beautiful Soup :-)

C:\junktype element_soup.py
from xml.etree import cElementTree as ET
import cStringIO

guff = 
tr 
td headers=col1_1  style=width:21%   
span  class=hpPageText LETTER/span/td
td headers=col2_1  style=width:13%; text-align:right   
span  class=hpPageText 33,699/span/td
td headers=col3_1  style=width:13%; text-align:right   
span  class=hpPageText 1.0/span/td
/tr


tree = ET.parse(cStringIO.StringIO(guff))
for elem in tree.getiterator('td'):
key = elem.get('headers')
assert elem[0].tag == 'span'
value = elem[0].text
print repr(key), repr(value)

C:\junk\python25\python element_soup.py
'col1_1' 'LETTER'
'col2_1' '33,699'
'col3_1' '1.0'

HTH,
John





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


irclib problems

2007-02-11 Thread Tina I
I'm playing around with the 'irclib' library working with the first 
example at 
http://www.devshed.com/c/a/Python/IRC-on-a-Higher-Level-Concluded/

When copying the example verbatim and running it from a console it works 
flawlessly. It connects to the server, join the channel and sits there 
'forever'...

However, I want to use it in a PyQt application and have done the following.
I have created a module named 'irclibtest.py' that looks like this:

### irclibtest start ###
import irclib
irclib.DEBUG = True

class Conn:
 def __init__(self):
 # Network information
 self.network = '192.x.x.x'
 self.port = 6667
 self.channel = '#test'
 self.nick = 'IRClibt'
 self.name = 'Python Test'

 # Subclass SimpleIRCClient
 class ClientClass ( irclib.SimpleIRCClient ):
 pass

 # Create an instance of ClientClass and connect.
 self.client = ClientClass()
 self.client.connect ( self.network, self.port, self.nick, 
ircname = self.name )
 self.client.connection.join ( self.channel )
##irclibtest end ###

And my main Qt application:

### Main application start ###
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys, irclib
from PyQt4 import QtGui , QtCore
from tircUI import Ui_MainWindow
from irclibtest import Conn

class TircMain(QtGui.QMainWindow , Conn):
 def __init__(self):
 QtGui.QMainWindow.__init__(self )
 Conn.__init__(self)
 self.ui = Ui_MainWindow()
 self.ui.setupUi(self)

 self.connect(self.ui.sendButton, QtCore.SIGNAL(clicked()), 
self.doSend)

 def doSend(self):
 ''' Just a test to see if I can send to channel'''
 self.client.connection.privmsg('#test' , 'Test text')

if __name__ == __main__:
 app = QtGui.QApplication(sys.argv)
 f = TircMain()
 f.show()
 sys.exit(app.exec_())
### Main application end ##

The problem is that this pings out (PING timeout). As far as I 
understand it rclib.SimpleIRCClient is supposed to handle PING-PONG with 
the server so I don't understand why it does not in my Qt test, but it 
does 'raw'.
I can send to the channel right up to the point it times out by the way.

Anyone know what I'm missing here?

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


Re: pygame and python 2.5

2007-02-11 Thread [EMAIL PROTECTED]
On Feb 11, 1:35�am, Steve Holden [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  On Feb 10, 4:07?pm, Ben Sizer [EMAIL PROTECTED] wrote:
  On Feb 10, 6:31 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

  On Feb 9, 11:39?am, Ben Sizer [EMAIL PROTECTED] wrote:
  Hopefully in the future, some of those convoluted steps will be fixed,
  but that requires someone putting in the effort to do so. As is often
  the case with Python, and indeed many open source projects, the people
  who are knowledgeable enough to do such things usually don't need to
  do them, as their setup already works just fine.
  So you're saying the knowledgeable people's attitude
  is fuck everyone else as lomg as it's not MY problem?
  And you people complain about Microsoft.
  Am I one of those people? You don't exactly make it clear.

  I'm talking about the people who complain about Microsoft
  making the VC6 compiler no longer legally available and
  yet are so irresponsible that they use it for the latest
  release.

 I think you'll find those two sets are disjoint.





  But yes, there is a lot of well, it works for me going around. If
  you do that long enough, people stop complaining, so people wrongly
  assume there's no longer a problem. This is partly why Python has
  various warts on Windows and why the standard libraries are oddly
  biased, why configuring Linux almost always ends up involving hand-
  editing a .conf file, why the leading cross-platform multimedia
  library SDL still doesn't do hardware graphics acceleration a decade
  after such hardware became mainstream, and so on.

  However, the difference between the open-source people and Microsoft
  is the the open-source people aren't being paid by you for the use of
  their product, so they're not obligated in any way to help you.

  This argument has become tiresome. The Python community
  wants Python to be a big fish in the big pond. That's why
  they make Windows binaries available.

 ? I would suggest rather that the Python community (by which you
 apparently mean the developers) hope that the fruits of their labours
 will be used by as wide a cross-section of computer users as possible.

 The goals of open source projects are not those of commercial product
 developers: I and others wouldn't collectively put in thousands of
 unpaid hours a year to make a commercial product better and protect its
 intellectual property, for example.

  After all, they have already given freely and generously, and if they 
  choose
  not to give more on top of that, it's really up to them.

  Right. Get people to commit and then abandon them. Nice.

 Anyone who committed to Python did so without being battered by a
 multi-million dollar advertising campaign.

Multi-million dollar ad campaigns mean nothing to me.
I committed to Python because it's a great language.
I've dabbled in perl, Visual BASIC, UBASIC, REXX, Java,
Scheme, C and C++ but Python is the one I use.

 The Python Software
 Foundation has only recently dipped its toes in the advocacy waters,
 with results that are still under evaluation. And the use of the
 Microsoft free VC6 SDK was never a part of the official means of
 producing Python or its extensions, it was a community-developed
 solution to the lack of availability of a free VS-compatible compilation
 system for extension modules.

 I agree that there are frustrations involved with maintaining extension
 modules on the Windows platform without having a copy of Visual Studio
 (of the correct version) available. One of the reasons Python still uses
 an outdated version of VS is to avoid forcing people to upgrade. Any
 such decision will have fallout.

Such as anyone who tries to get in the game late.

 An update is in the works for those
 using more recent releases,

That's good news, although the responsible thing
to do was not relaease version 2.5 until such issues
are resolved.

 but that won't help users who don't have
 access to Visual Studio.

That can be solved by throwing money at the problem.
But money doesn't help when the solution is on the
far side of the moon.


  Yes, it's
  occasionally very frustrating to the rest of us, but that's life.

  As the Kurds are well aware.

 I really don't think you help your argument by trying to draw parallels
 between the problems of compiler non-availability and those of a
 population subject to random genocide.

You missed the point of the analogy.

The US government suggested to the oppressed tribes
in Iraq that they should rise up and overthrow
Saddam Hussein at the end of the first Gulf War.
And what did the US government do when they rose up?
Nothing. They were left to twist in the wind.

 Try to keep things in perspective, please.

See if you can see the similarity.

I buy into Python. I spend a lot of effort
developing a math library based on GMPY to use
in my research. I discover a bug in GMPY and
actually go to a lot of effort and solve it.
But _I_ can't even use it because I've been
left to 

Re: pygame and python 2.5

2007-02-11 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 On Feb 11, 1:35�am, Steve Holden [EMAIL PROTECTED] wrote:
[...]
 After all, they have already given freely and generously, and if they 
 choose
 not to give more on top of that, it's really up to them.
 Right. Get people to commit and then abandon them. Nice.
 Anyone who committed to Python did so without being battered by a
 multi-million dollar advertising campaign.
 
 Multi-million dollar ad campaigns mean nothing to me.
 I committed to Python because it's a great language.
 I've dabbled in perl, Visual BASIC, UBASIC, REXX, Java,
 Scheme, C and C++ but Python is the one I use.
 
Yes, but your decision must surely have been an informed one, and there 
must surely be reasons why Python remains your choice.

 The Python Software
 Foundation has only recently dipped its toes in the advocacy waters,
 with results that are still under evaluation. And the use of the
 Microsoft free VC6 SDK was never a part of the official means of
 producing Python or its extensions, it was a community-developed
 solution to the lack of availability of a free VS-compatible compilation
 system for extension modules.

 I agree that there are frustrations involved with maintaining extension
 modules on the Windows platform without having a copy of Visual Studio
 (of the correct version) available. One of the reasons Python still uses
 an outdated version of VS is to avoid forcing people to upgrade. Any
 such decision will have fallout.
 
 Such as anyone who tries to get in the game late.
 
I'm afraid it does seem to work out like that, yes.

 An update is in the works for those
 using more recent releases,
 
 That's good news, although the responsible thing
 to do was not relaease version 2.5 until such issues
 are resolved.
 
Well that would be an issue for the release team. I'm not sure what 
Anthony Baxter (the release manager) would have to say in response to 
this point.

 but that won't help users who don't have
 access to Visual Studio.
 
 That can be solved by throwing money at the problem.
 But money doesn't help when the solution is on the
 far side of the moon.
 
I see your problem, but I don't know what I can do to help you. There 
were also, as I remember it, issues with the updated version of Visual 
Studio being non-conformant with standards in some significant way, but 
I never took part in the discussions on those issues.

 Yes, it's
 occasionally very frustrating to the rest of us, but that's life.
 As the Kurds are well aware.
 I really don't think you help your argument by trying to draw parallels
 between the problems of compiler non-availability and those of a
 population subject to random genocide.
 
 You missed the point of the analogy.
 
Perhaps because it wasn't a very good one?

 The US government suggested to the oppressed tribes
 in Iraq that they should rise up and overthrow
 Saddam Hussein at the end of the first Gulf War.
 And what did the US government do when they rose up?
 Nothing. They were left to twist in the wind.
 
 Try to keep things in perspective, please.
 
 See if you can see the similarity.
 
 I buy into Python. I spend a lot of effort
 developing a math library based on GMPY to use
 in my research. I discover a bug in GMPY and
 actually go to a lot of effort and solve it.
 But _I_ can't even use it because I've been
 left to twist in the wind by the fact that
 Python 2.5 for Windows was built with an
 obsolete compiler that's not even available.
 
 Luckily, unlike the Kurds, my situation had
 a happy ending, someone else compiled the fixed
 GMPY source and made a 2.5 Windows version
 available. But can anyone say what will happen
 the next time?
 
Presumably not. I presume you have been reporting your bugs through the 
Sourceforge project to keep the developers in touch with the issues you 
have found? Normally a package's maintainers will produce updated 
installers, but this behaviour is unreliable and (no pun intended) 
patchy sometimes.

 The best I feel I can do is raise these things on occasion,
 on the off-chance that I manage to catch the attention of
 someone who is
 altruistic, knowledgeable, and who has some spare time on
 their hands!
 Someone who, say, solved the memory leak in the GMPY
 divm() function even though he had no way of compiling
 the source code?
 Just think of what such an altruistic, knowedgeable
 person could do if he could use the current VC compiler
 or some other legally available compiler.
 Your efforts would probably be far better spent trying to build a
 back-end for mingw or some similar system into Python's development
 system, to allow Python for Windows to be built on a regular rather than
 a one-off basis using a completely open source tool chain.
 
 No, as I said elsewhere, I'm not a software developer,
 I'm an amateur math researcher. My efforts are best spent
 as an actual end user to find and report bugs that the
 developers never see. Remember, a programmer, because he
 wrote it, only _thinks_ he knows how the 

Re: Regular Expressions

2007-02-11 Thread Steven D'Aprano
On Sun, 11 Feb 2007 07:05:30 +, Steve Holden wrote:

 Geoff Hill wrote:
 What's the way to go about learning Python's regular expressions? I feel 
 like such an idiot - being so strong in a programming language but knowing 
 nothing about RE. 
 
 
 In fact that's a pretty smart stance.

That's a little harsh -- regexes have their place, together with pointer
arithmetic, bit manipulations, reverse polish notation and goto. The
problem is when people use them inappropriately e.g. using a regex when a
simple string.find will do.



 A quote attributed variously to 
 Tim Peters and Jamie Zawinski says Some people, when confronted with a 
 problem, think 'I know, I'll use regular expressions.' Now they have two 
 problems.

I believe that is correctly attributed to Jamie Zawinski.


-- 
Steven

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


Re: Regular Expressions

2007-02-11 Thread John Machin
On Feb 11, 9:25 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Sun, 11 Feb 2007 07:05:30 +, Steve Holden wrote:
  Geoff Hill wrote:
  What's the way to go about learning Python's regular expressions? I feel
  like such an idiot - being so strong in a programming language but knowing
  nothing about RE.

  In fact that's a pretty smart stance.

 That's a little harsh -- regexes have their place, together with pointer
 arithmetic, bit manipulations, reverse polish notation and goto. The
 problem is when people use them inappropriately e.g. using a regex when a
 simple string.find will do.

Thanks for the tip-off, Steve and Steven. Looks like I'll have to
start hiding my 12C (datecode 2214) with its GTO button under the
loose floor-board whenever I hear a knock at the door ;-) Looks like
Agner Fog's gone a million, and there'll be a special place in hell
for people who combine regexes with bit manipulation, like Navarro 
Raffinot. And we won't even mention Heikki Hy,*7g^54d3j+__=

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


Re: pygame and python 2.5

2007-02-11 Thread Steven D'Aprano
On Sun, 11 Feb 2007 01:08:21 -0800, [EMAIL PROTECTED] wrote:

 An update is in the works for those
 using more recent releases,
 
 That's good news, although the responsible thing
 to do was not relaease version 2.5 until such issues
 are resolved.

I realize you're a Windows user, and a Windows user with an AOL email
address at that, so it may come as a shock to learn that the computer
industry doesn't start and finish on Windows. I don't see why the needs of
Windows users like yourself should come ahead of the needs of users on Mac
OS, Linux, Solaris, etc.



 but that won't help users who don't have
 access to Visual Studio.
 
 That can be solved by throwing money at the problem.
 But money doesn't help when the solution is on the
 far side of the moon.

You're mixing metaphors and I don't understand what you mean.


  Yes, it's
  occasionally very frustrating to the rest of us, but that's life.

  As the Kurds are well aware.

 I really don't think you help your argument by trying to draw parallels
 between the problems of compiler non-availability and those of a
 population subject to random genocide.
 
 You missed the point of the analogy.
 
 The US government suggested to the oppressed tribes
 in Iraq that they should rise up and overthrow
 Saddam Hussein at the end of the first Gulf War.
 And what did the US government do when they rose up?
 Nothing. They were left to twist in the wind.

Both the southern Iraqis (mostly so-called marsh Arabs and Shiites) and
the northern Kurds rose up against Saddam Hussein. After the Kurdish
rebellion failed, the US and UK belatedly provided them with aid, lots of
aid, and kept the northern no-fly zone going until it was no longer
relevant (2003, the second invasion of Iraq).

It was the southern Iraqis who were left to be slaughtered. Although
technically there was a no-fly zone in the south, it wasn't enforced
when it really counted -- while the rebellion was in full force, the
Iraqi government asked the US for permission to fly into the south.
Permission was given, and the Iraq air force used combat aircraft against
the rebels. Unlike the Kurds, they got no aid, neither money nor military
support.

The end result was that the southern Iraqs were hung out to dry, while the
Kurds ended up a virtually independent state-within-a-state, with their
own government, their own army, and US and British aircraft protecting
them.


 Try to keep things in perspective, please.
 
 See if you can see the similarity.
 
 I buy into Python. I spend a lot of effort
 developing a math library based on GMPY to use
 in my research. I discover a bug in GMPY and
 actually go to a lot of effort and solve it.

Good on you, and I'm not being sarcastic. But do try to keep a bit of
perspective. Whatever your problem, you're not being bombed or shot.
Frankly, the fact that you not only came up with the analogy, but continue
to defend it, suggests an over-active sense of your own entitlement. 


 But _I_ can't even use it because I've been
 left to twist in the wind by the fact that
 Python 2.5 for Windows was built with an
 obsolete compiler that's not even available.
 Luckily, unlike the Kurds, my situation had
 a happy ending, someone else compiled the fixed
 GMPY source and made a 2.5 Windows version
 available. But can anyone say what will happen
 the next time?

Get yourself a compiler, then you won't be relying on the kindness of
strangers.

If that's not practical, for whatever reason, then remember: you're
relying on the kindness of strangers. They don't owe you a thing. If
anything, you owe them.


[snip]
 Your efforts would probably be far better spent trying to build a
 back-end for mingw or some similar system into Python's development
 system, to allow Python for Windows to be built on a regular rather than
 a one-off basis using a completely open source tool chain.
 
 No, as I said elsewhere, I'm not a software developer,
 I'm an amateur math researcher. My efforts are best spent
 as an actual end user 

If you won't scratch your own itch, don't be surprised if nobody else
cares enough to scratch it for you.


 to find and report bugs that the
 developers never see. Remember, a programmer, because he
 wrote it, only _thinks_ he knows how the program works.
 Whereas I, the user, _know_ how it works.

Oh wow. That's the most audacious, self-involved and sheer arrogant claim
I've ever heard, and I've heard a lot of nonsense sprouted by arrogant
know-nothings with delusions of grandeur. For the sake of your
credibility, I hope you can support that claim.


[snip]
 It's much harder than sniping on a newsgroup,
 
 That figures. You try and contribute and you get
 accused of being a troll.

I have a problem. I demand that somebody fix it for me! is hardly
contributing.

If you don't have the technical skills to fix it yourself, have you
considered putting hand in pocket and paying a software developer to do
it? It might even come out cheaper than buying a commercial compiler, and
it 

Problem with reimporting modules

2007-02-11 Thread Christoph Zwerschke
I'm currently investigating a problem that can hit you in TurboGears 
when Kid template modules are reloaded in the background, because in 
certain situations, global variables suddenly are set to None values.

I tracked it down to the following behavior of Python. Assume you have a 
module hello.py like that:

 hello. py 
greeting = 'Hello!'
def print_hello():
 print greeting
---

Now run the following code:

from hello import print_hello
print_hello()
import sys
del sys.modules['hello'] # delete module
import hello # recreate module
print_hello()

The second print_hello() prints None instead of Hello!. Why is that? 
I had expected that it either prints an error or print Hello! as well.

Is this intended behavior of Python?

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


Re: Regular Expressions

2007-02-11 Thread James Stroud
gregarican wrote:
 On Feb 10, 6:26 pm, Geoff Hill [EMAIL PROTECTED] wrote:
 What's the way to go about learning Python's regular expressions? I feel
 like such an idiot - being so strong in a programming language but knowing
 nothing about RE.
 
 I highly recommend reading the book Mastering Regular Expressions,
 which I believe is published by O'Reilly. It's a great reference and
 helps peel the onion in terms of working through RE. They are a
 language unto themselves. A fun brain exercise.
 

There is no real mention of python in this book, but the first edition 
is probably the best programming book I've ever read (excepting, perhaps 
Text Processing in Python by Mertz.) Well, come to think of it, check 
the latter book out. It has a great chapter on Python Regex. And its 
free to download.

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


How to access an absolute address through Python?

2007-02-11 Thread volcano
Can it be done, and if yes - how?

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


Re: How to access an absolute address through Python?

2007-02-11 Thread Maël Benjamin Mettler
volcano schrieb:
 Can it be done, and if yes - how?
 

Define address. Are you talking about URLs? File paths? Postal
addresses? Memory addresses? Whatever addresses?
I'm afraid the people on this list can't read your thoughts...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 41, Issue 170

2007-02-11 Thread YySwing.杨

- Original Message - 
From: [EMAIL PROTECTED]
To: python-list@python.org
Sent: Sunday, February 11, 2007 5:10 PM
Subject: Python-list Digest, Vol 41, Issue 170


 Send Python-list mailing list submissions to
 python-list@python.org
 
 To subscribe or unsubscribe via the World Wide Web, visit
 http://mail.python.org/mailman/listinfo/python-list
 or, via email, send a message with subject or body 'help' to
 [EMAIL PROTECTED]
 
 You can reach the person managing the list at
 [EMAIL PROTECTED]
 
 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Python-list digest...






 Today's Topics:
 
   1. Re: pygame and python 2.5 (Steve Holden)
   2. Re: can't find a way to display and print pdf through python.
  (Geoff Hill)
   3. Re: pygame and python 2.5 (Hendrik van Rooyen)
   4. Re: HTML Parsing (John Machin)
   5. irclib problems (Tina I)
   6. Re: pygame and python 2.5 ([EMAIL PROTECTED])






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


Re: favourite editor

2007-02-11 Thread Stef Mientki
azrael wrote:
 Since i'm new on this forum, and first time meeting a python comunity,
 i wanted to ask you for your python editors.
 
 Im looking for some good python editor, with integrated run function,
 without having to set it up manualy like komodo.
 I found the pyscripter, and it has all i need, but it's unsatble.
 bloated.
No it is very stable,
but some programs should be started differently,
read the manual !

  it crashes when i close an yplication window run by python
 from pyscripter. please. tell me a good one with buil in run (-very
 important) and nice gui. if possible to suport projects, code
 highlighting, code completition, class browser, python comand line
 (), traceback.
You could try SPE,
but that's really unstable,
and no help manual to read ;-)

and for the rest the answer must certainly be in the still running thread
Best Free and Open Source Python IDE

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: favourite editor

2007-02-11 Thread Szabolcs Nagy

azrael wrote:
 Since i'm new on this forum, and first time meeting a python comunity,
 i wanted to ask you for your python editors.

 Im looking for some good python editor, with integrated run function,
 without having to set it up manualy like komodo.
 I found the pyscripter, and it has all i need, but it's unsatble.
 bloated. it crashes when i close an yplication window run by python
 from pyscripter. please. tell me a good one with buil in run (-very
 important) and nice gui. if possible to suport projects, code
 highlighting, code completition, class browser, python comand line
 (), traceback.

 I didn't take a look on vista (and i dont want to), but i hope they
 improved the notepad.

*sigh*
this question arises at least three times a week on this group

you can use the googlegroups search function:
http://groups.google.com/group/comp.lang.python/search?group=comp.lang.pythonq=python+editor+ideqt_g=Search+this+group

also use the python wiki:
http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
http://wiki.python.org/moin/PythonEditors

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


Re: How to access an absolute address through Python?

2007-02-11 Thread volcano
On Feb 11, 2:21 pm, Maël Benjamin Mettler [EMAIL PROTECTED] wrote:
 volcano schrieb:

  Can it be done, and if yes - how?

 Define address. Are you talking about URLs? File paths? Postal
 addresses? Memory addresses? Whatever addresses?
 I'm afraid the people on this list can't read your thoughts...

I presumed that absolute address somehow qualifies my question. If
it is not - I was talking about physical computer memory, on PC - to
be more specific.

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


Re: Parsing HTML

2007-02-11 Thread Samuel Karl Peterson
mtuller [EMAIL PROTECTED] on 10 Feb 2007 15:03:36 -0800 didst
step forth and proclaim thus:

 Alright. I have tried everything I can find, but am not getting
 anywhere. I have a web page that has data like this:

[snip]

 What is show is only a small section.
 
 I want to extract the 33,699 (which is dynamic) and set the value to a
 variable so that I can insert it into a database.

[snip]

 I have also tried Beautiful Soup, but had trouble understanding the
 documentation.


from BeautifulSoup import BeautifulSoup as parser

soup = parser(tr 
td headers=col1_1  style=width:21%   
span  class=hpPageText LETTER/span/td
td headers=col2_1  style=width:13%; text-align:right   
span  class=hpPageText 33,699/span/td
td headers=col3_1  style=width:13%; text-align:right   
span  class=hpPageText 1.0/span/td
td headers=col4_1  style=width:13%; text-align:right   
/tr)

value = \
   int(soup.find('td', headers='col2_1').span.contents[0].replace(',', ''))


 Thanks,

 Mike

Hope that helped.  This code assumes there aren't any td tags with
header=col2_1 that come before the value you are trying to extract.
There's several ways to do things in BeautifulSoup.  You should play
around with BeautifulSoup in the interactive prompt.  It's simply
awesome if you don't need speed on your side.

-- 
Sam Peterson
skpeterson At nospam ucdavis.edu
if programmers were paid to remove code instead of adding it,
software would be much better -- unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to access an absolute address through Python?

2007-02-11 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], volcano wrote:

 On Feb 11, 2:21 pm, Maël Benjamin Mettler [EMAIL PROTECTED] wrote:
 volcano schrieb:

  Can it be done, and if yes - how?

 Define address. Are you talking about URLs? File paths? Postal
 addresses? Memory addresses? Whatever addresses?
 I'm afraid the people on this list can't read your thoughts...
 
 I presumed that absolute address somehow qualifies my question. If
 it is not - I was talking about physical computer memory, on PC - to
 be more specific.

In pure Python it's not possible and even in C it might be difficult to
get an absolute *physical* memory address unless you run DOS.  Modern
operating systems tend to use some virtualisation of memory.  :-)

What's your goal?  What do you expect at the memory address you want to
access?

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

Re: How to access an absolute address through Python?

2007-02-11 Thread volcano
On Feb 11, 2:46 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 In [EMAIL PROTECTED], volcano wrote:
  On Feb 11, 2:21 pm, Maël Benjamin Mettler [EMAIL PROTECTED] wrote:
  volcano schrieb:

   Can it be done, and if yes - how?

  Define address. Are you talking about URLs? File paths? Postal
  addresses? Memory addresses? Whatever addresses?
  I'm afraid the people on this list can't read your thoughts...

  I presumed that absolute address somehow qualifies my question. If
  it is not - I was talking about physical computer memory, on PC - to
  be more specific.

 In pure Python it's not possible and even in C it might be difficult to
 get an absolute *physical* memory address unless you run DOS.  Modern
 operating systems tend to use some virtualisation of memory.  :-)

 What's your goal?  What do you expect at the memory address you want to
 access?

 Ciao,
 Marc 'BlackJack' Rintsch

My goal is to sync program with external equipment through a register
defined as an absolute physical address. I know how to do it from C -
was curious if it may be done from Python. Can it be done?

Thanks, Mark

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


Re: How to find all the same words in a text?

2007-02-11 Thread Samuel Karl Peterson
Johny [EMAIL PROTECTED] on 10 Feb 2007 05:29:23 -0800 didst step
forth and proclaim thus:

 I need to find all the same words in a text .
 What would be the best idea  to do that?

I make no claims of this being the best approach:


def findOccurances(a_string, word):

Given a string and a word, returns a double:
[0] = count [1] = list of indexes where word occurs

import re
count = 0
indexes = []
start = 0 # offset for successive passes
pattern = re.compile(r'\b%s\b' % word, re.I)

while True:
match = pattern.search(a_string)
if not match: break
count += 1;
indexes.append(match.start() + start)
start += match.end()
a_string = a_string[match.end():]

return (count, indexes)


Seems to work for me.  No guarantees.

-- 
Sam Peterson
skpeterson At nospam ucdavis.edu
if programmers were paid to remove code instead of adding it,
software would be much better -- unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shed Skin Optimizing Python-to-C++ Compiler 0.0.19

2007-02-11 Thread Michael
Mark Dufour wrote:

 This
 latest release adds basic support for iterators and generators

Oooh, I may try our miniaxon tutorial against shed skin in that case. 
(ie http://kamaelia.sourceforge.net/MiniAxon/)

Great to see you're plowing through this BTW !


Michael.
--
Kamaelia Project Lead
http://kamaelia.sourceforge.net/Home
http://yeoldeclue.com/blog

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


morpholgy toolbox

2007-02-11 Thread azrael
does any one have any expirience with mmorph module. At first i was
unable to run it because some file was missing (instalation problem),
but i managed it. but, did anyone manage to save the new mask, or
anything created with it.

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


Re: How to find all the same words in a text?

2007-02-11 Thread Neil Cerutti
On 2007-02-10, Johny [EMAIL PROTECTED] wrote:
 I need to find all the same words in a text .
 What would be the best idea  to do that?
 I used string.find but it does not work properly for the words.
 Let suppose I want to find a number 324 in the  text

 '45  324 45324'

 there is only one occurrence  of 324 word but string.find()   finds 2
 occurrences  ( in 45324 too)

 Must I use regex?
 Thanks for help

The first thing to do is to answer the question: What is a word?

The second thing to do is to design some code that can find
words in strings.

The last thing to do is to search those actual words for the word
you're looking for.

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


Re: How to access an absolute address through Python?

2007-02-11 Thread Fred of UrlBit.Us
volcano wrote:

 On Feb 11, 2:46 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
...
 My goal is to sync program with external equipment through a register
 defined as an absolute physical address. I know how to do it from C -
 was curious if it may be done from Python. Can it be done?
 
 Thanks, Mark

Your best bet will be to create a C library callable from Python to do it
for you. There may be such a beast in existence already, but it should not
be hard at all to do, given the simplicity of the requirements.

-- 
-- Fred of UrlBit.Us
-- http://UrlBit.Us - Bite those URLs down to size!


 Posted Via Usenet.com Premium Usenet Newsgroup Services
--
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
--
http://www.usenet.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to access an absolute address through Python?

2007-02-11 Thread Steve Holden
volcano wrote:
 On Feb 11, 2:46 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
[...]
 What's your goal?  What do you expect at the memory address you want to
 access?

 Ciao,
 Marc 'BlackJack' Rintsch
 
 My goal is to sync program with external equipment through a register
 defined as an absolute physical address. I know how to do it from C -
 was curious if it may be done from Python. Can it be done?
 
No. You'd have to use a compiled extension.

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
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

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


Re: How to find all the same words in a text?

2007-02-11 Thread Maël Benjamin Mettler
In order to find all the words in a text, you need to tokenize it first.
The rest is a matter of calling the count method on the list of
tokenized words. For tokenization look here:
http://nltk.sourceforge.net/lite/doc/en/words.html
A little bit of warning: depending on what exactly you need to do, the
seemingly trivial taks of tokenizing a text can become quite complex.

Enjoy,

Maël

Neil Cerutti schrieb:
 On 2007-02-10, Johny [EMAIL PROTECTED] wrote:
 I need to find all the same words in a text .
 What would be the best idea  to do that?
 I used string.find but it does not work properly for the words.
 Let suppose I want to find a number 324 in the  text

 '45  324 45324'

 there is only one occurrence  of 324 word but string.find()   finds 2
 occurrences  ( in 45324 too)

 Must I use regex?
 Thanks for help
 
 The first thing to do is to answer the question: What is a word?
 
 The second thing to do is to design some code that can find
 words in strings.
 
 The last thing to do is to search those actual words for the word
 you're looking for.
 

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


urllib2 request htaccess page through proxy

2007-02-11 Thread Alessandro Fachin
I write this simply code that should give me the access to private page with
htaccess using a proxy, i don't known because it's wrong... 


import urllib,urllib2

#input url
url=http://localhost/private/file;

#proxy set up
proxy_handler = urllib2.ProxyHandler({'http': 'http://myproxy:'})

#htaccess set up
user=matteo
password=matteo
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)

opener = urllib2.build_opener(proxy_handler,authhandler)
urllib2.install_opener(opener)

#open the url
req=urllib2.Request(url)
data=urllib2.urlopen(req).read()
print data

i get no access on access.log from apache2 and nothing from the proxy in
tcpdump log. If i use only the proxy with a page that doesn't use htaccess
it works... if anyone could help,regards...




Traceback (most recent call last):
  File proxy.py, line 22, in ?
data=urllib2.urlopen(req).read()
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 130, in urlopen
return _opener.open(url, data)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 364, in open
response = meth(req, response)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 471, in http_response
response = self.parent.error(
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 396, in error
result = self._call_chain(*args)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 337, in _call_chain
result = func(*args)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 741, in http_error_401
host, req, headers)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 720, in http_error_auth_reqed
return self.retry_http_basic_auth(host, req, realm)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 730, in retry_http_basic_auth
return self.parent.open(req)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 364, in open
response = meth(req, response)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 471, in http_response
response = self.parent.error(
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 402, in error
return self._call_chain(*args)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 337, in _call_chain
result = func(*args)
 
File 
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py,
line 480, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Authorization Required




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


gvim: doc string editing

2007-02-11 Thread [EMAIL PROTECTED]
Hi, I am using gvim, and am looking for a way to tell gvim to
automatically wrap long lines into multiple lines ( by automatically
inserting the newline character) when I edit doc strings. I am sure
somebody must have done this.

-
Suresh

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


Re: gvim: doc string editing

2007-02-11 Thread Neil Cerutti
On 2007-02-11, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi, I am using gvim, and am looking for a way to tell gvim to
 automatically wrap long lines into multiple lines ( by
 automatically inserting the newline character) when I edit doc
 strings. I am sure somebody must have done this.

If tw (textwidth) is set to some apposite number, then it should
just work (unfortunately, this will also cause your code to wrap
unless you set up the comment strings properly for Python).
Alternatively, you can use the gq formatting command to wrap the
comment after it is composed.

Do :h format_comments for the full dope.

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


Re: How to access an absolute address through Python?

2007-02-11 Thread volcano
On Feb 11, 3:46 pm, Steve Holden [EMAIL PROTECTED] wrote:
 volcano wrote:
  On Feb 11, 2:46 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 [...]
  What's your goal?  What do you expect at the memory address you want to
  access?

  Ciao,
  Marc 'BlackJack' Rintsch

  My goal is to sync program with external equipment through a register
  defined as an absolute physical address. I know how to do it from C -
  was curious if it may be done from Python. Can it be done?

 No. You'd have to use a compiled extension.

 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
 Blog of Note:  http://holdenweb.blogspot.com
 See you at PyCon?http://us.pycon.org/TX2007


Steve, Fred, thank you. This is exactly what I have done, though I did
hope for shortcut. Life is tough:)!

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


Re: HTML Parsing

2007-02-11 Thread Fredrik Lundh
John Machin wrote:

 One can even use ElementTree, if the HTML is well-formed. See below.
 However if it is as ill-formed as the sample (4th td element not
 closed; I've omitted it below), then the OP would be better off
 sticking with Beautiful Soup :-)

or get the best of both worlds:

http://effbot.org/zone/element-soup.htm

/F 



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


Re: gvim: doc string editing

2007-02-11 Thread [EMAIL PROTECTED]
On Feb 11, 7:01 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
 On 2007-02-11, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

  Hi, I am using gvim, and am looking for a way to tell gvim to
  automatically wrap long lines into multiple lines ( by
  automatically inserting the newline character) when I edit doc
  strings. I am sure somebody must have done this.

 If tw (textwidth) is set to some apposite number, then it should
 just work (unfortunately, this will also cause your code to wrap
 unless you set up the comment strings properly for Python).
 Alternatively, you can use the gq formatting command to wrap the
 comment after it is composed.

 Do :h format_comments for the full dope.

 --
 Neil Cerutti

gq works great. Thanks.
-
Suresh

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


Re: How to access an absolute address through Python?

2007-02-11 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes:
  My goal is to sync program with external equipment through a register
  defined as an absolute physical address. I know how to do it from C -
  was curious if it may be done from Python. Can it be done?
 
 No. You'd have to use a compiled extension.

Well, you don't necessarily have to deal with the C API or ctypes; it
may be enough to invoke an external program that accesses the
necessary memory address.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with reimporting modules

2007-02-11 Thread Dustan
On Feb 11, 5:53 am, Christoph Zwerschke [EMAIL PROTECTED] wrote:
 I'm currently investigating a problem that can hit you in TurboGears
 when Kid template modules are reloaded in the background, because in
 certain situations, global variables suddenly are set to None values.

 I tracked it down to the following behavior of Python. Assume you have a
 module hello.py like that:

  hello. py 
 greeting = 'Hello!'
 def print_hello():
  print greeting
 ---

 Now run the following code:

 from hello import print_hello
 print_hello()
 import sys
 del sys.modules['hello'] # delete module
 import hello # recreate module
 print_hello()

 The second print_hello() prints None instead of Hello!. Why is that?
 I had expected that it either prints an error or print Hello! as well.

 Is this intended behavior of Python?

 -- Christoph

You're most likely looking for reload:
http://docs.python.org/lib/built-in-funcs.html#l2h-61
The documentation does imply that deleting a module from sys.modules
may not be what you want:
http://docs.python.org/lib/module-sys.html#l2h-5147

 import sys
 import warnings as previous_warnings # for example
 # testing whether reload returns the same module object:
... reload(previous_warnings) is previous_warnings
True
 # the following result is rather intuitive, but for
... # the sake of demonstration, I'll do it anyway.
... del sys.modules['warnings']
 import warnings as after_warnings
 after_warnings is previous_warnings
False

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


Re: How to access an absolute address through Python?

2007-02-11 Thread Grant Edwards
On 2007-02-11, volcano [EMAIL PROTECTED] wrote:

 Can it be done,

Yes.

 and if yes - how?

/proc/kmem

-- 
Grant Edwards   grante Yow!  Nipples, dimples,
  at   knuckles, NICKLES,
   visi.comwrinkles, pimples!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to find all the same words in a text?

2007-02-11 Thread attn . steven . kuo
On Feb 11, 5:13 am, Samuel Karl Peterson
[EMAIL PROTECTED] wrote:
 Johny [EMAIL PROTECTED] on 10 Feb 2007 05:29:23 -0800 didst step
 forth and proclaim thus:

  I need to find all the same words in a text .
  What would be the best idea  to do that?

 I make no claims of this being the best approach:

 
 def findOccurances(a_string, word):
 
 Given a string and a word, returns a double:
 [0] = count [1] = list of indexes where word occurs
 
 import re
 count = 0
 indexes = []
 start = 0 # offset for successive passes
 pattern = re.compile(r'\b%s\b' % word, re.I)

 while True:
 match = pattern.search(a_string)
 if not match: break
 count += 1;
 indexes.append(match.start() + start)
 start += match.end()
 a_string = a_string[match.end():]

 return (count, indexes)
 

 Seems to work for me.  No guarantees.




More concisely:

import re

pattern = re.compile(r'\b324\b')
indices = [ match.start() for match in
pattern.finditer(target_string) ]
print Indices, indices
print Count: , len(indices)

--
Cheers,
Steven

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


Re: can't find a way to display and print pdf through python.

2007-02-11 Thread Christian Stapfer
krishnakant Mane wrote in message 
news:[EMAIL PROTECTED]
 On 11/02/07, Vishal Bhargava [EMAIL PROTECTED] wrote:
 Use Report Lab...
 I mentioned in my first email that I am already using reportlab.
 but I can only generate pdf out of that.
 I want to display it on screen and I also will be giving a print
 button which should do the printing job.
 by the way I use wxpython for gui.

Under Windows you could do it by embedding Adobe's
ActiveX control in your application. Don't know
about Linux, though. Perhaps you could just convert
your PDF to a raster image for display (eg. by
using ImageMagick's convert) under Linux?

Regards,
Christian

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


randomly generate n of each of two types

2007-02-11 Thread Alan Isaac
I need access to 2*n random choices for two types
subject to a constraint that in the end I have
drawn n of each.  I first tried::

def random_types(n,typelist=[True,False]):
types = typelist*n
random.shuffle(types)
for next_type in types:
yield next_type

This works but has some obvious costs.
To avoid those I considered this instead::

def random_types(n,typelist=[True,False]):
type0, type1 = typelist
ct0, ct1 = 0,0
while ct0+ct12*n:
if random.random()  ((n-ct0)/(2*n-ct0-ct1)):
next_type = type0
ct0 += 1
else:
next_type = type1
ct1 += 1
yield next_type

Does this seem a good way to go?  Comments welcome.

Thank you,
Alan Isaac


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


Re: pygame and python 2.5

2007-02-11 Thread [EMAIL PROTECTED]
On Feb 11, 4:24 am, Steve Holden [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  On Feb 11, 1:35?am, Steve Holden [EMAIL PROTECTED] wrote:
 [...]
  After all, they have already given freely and generously, and if they 
  choose
  not to give more on top of that, it's really up to them.
  Right. Get people to commit and then abandon them. Nice.
  Anyone who committed to Python did so without being battered by a
  multi-million dollar advertising campaign.

  Multi-million dollar ad campaigns mean nothing to me.
  I committed to Python because it's a great language.
  I've dabbled in perl, Visual BASIC, UBASIC, REXX, Java,
  Scheme, C and C++ but Python is the one I use.

 Yes, but your decision must surely have been an informed one, and there
 must surely be reasons why Python remains your choice.





  The Python Software
  Foundation has only recently dipped its toes in the advocacy waters,
  with results that are still under evaluation. And the use of the
  Microsoft free VC6 SDK was never a part of the official means of
  producing Python or its extensions, it was a community-developed
  solution to the lack of availability of a free VS-compatible compilation
  system for extension modules.

  I agree that there are frustrations involved with maintaining extension
  modules on the Windows platform without having a copy of Visual Studio
  (of the correct version) available. One of the reasons Python still uses
  an outdated version of VS is to avoid forcing people to upgrade. Any
  such decision will have fallout.

  Such as anyone who tries to get in the game late.

 I'm afraid it does seem to work out like that, yes.

  An update is in the works for those
  using more recent releases,

  That's good news, although the responsible thing
  to do was not relaease version 2.5 until such issues
  are resolved.

 Well that would be an issue for the release team. I'm not sure what
 Anthony Baxter (the release manager) would have to say in response to
 this point.

Possibly something like:

I realize you're a Windows user, and a Windows user with
an AOL email address at that, so it may come as a shock
to learn that the computer industry doesn't start and
finish on Windows. I don't see why the needs of Windows
users like yourself should come ahead of the needs of
users on Mac OS, Linux, Solaris, etc. - Steven D'Arpano

I would hope that it would instead be that the needs of
all users are equal.


  but that won't help users who don't have
  access to Visual Studio.

  That can be solved by throwing money at the problem.
  But money doesn't help when the solution is on the
  far side of the moon.

 I see your problem, but I don't know what I can do to help you.

Well, that was the point of this, to get people to
see the problem.

 There
 were also, as I remember it, issues with the updated version of Visual
 Studio being non-conformant with standards in some significant way, but
 I never took part in the discussions on those issues.

  Yes, it's
  occasionally very frustrating to the rest of us, but that's life.
  As the Kurds are well aware.
  I really don't think you help your argument by trying to draw parallels
  between the problems of compiler non-availability and those of a
  population subject to random genocide.

  You missed the point of the analogy.

 Perhaps because it wasn't a very good one?





  The US government suggested to the oppressed tribes
  in Iraq that they should rise up and overthrow
  Saddam Hussein at the end of the first Gulf War.
  And what did the US government do when they rose up?
  Nothing. They were left to twist in the wind.

  Try to keep things in perspective, please.

  See if you can see the similarity.

  I buy into Python. I spend a lot of effort
  developing a math library based on GMPY to use
  in my research. I discover a bug in GMPY and
  actually go to a lot of effort and solve it.
  But _I_ can't even use it because I've been
  left to twist in the wind by the fact that
  Python 2.5 for Windows was built with an
  obsolete compiler that's not even available.

  Luckily, unlike the Kurds, my situation had
  a happy ending, someone else compiled the fixed
  GMPY source and made a 2.5 Windows version
  available. But can anyone say what will happen
  the next time?

 Presumably not. I presume you have been reporting your bugs through the
 Sourceforge project to keep the developers in touch with the issues you
 have found?

Last time I tried, it didn't work and e-mail to the
maintainer didn't get any response.

 Normally a package's maintainers will produce updated
 installers,

Unless they have stopped doing Windows developement as
part of their job as is the case with GMPY. Luckily,
there's someone out there who does create Windows
binaries.

 but this behaviour is unreliable and (no pun intended)
 patchy sometimes.





  The best I feel I can do is raise these things on occasion,
  on the off-chance that I manage to catch the attention of
  someone who is
  

Re: pygame and python 2.5

2007-02-11 Thread [EMAIL PROTECTED]
On Feb 11, 5:33?am, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Sun, 11 Feb 2007 01:08:21 -0800, [EMAIL PROTECTED] wrote:
  An update is in the works for those
  using more recent releases,

  That's good news, although the responsible thing
  to do was not relaease version 2.5 until such issues
  are resolved.

 I realize you're a Windows user, and a Windows user with an AOL email
 address at that,

Now I know what it felt like to be a Shiite
living in Iraq.

 so it may come as a shock to learn that the computer
 industry doesn't start and finish on Windows. I don't see why the needs of
 Windows users like yourself should come ahead of the needs of users on Mac
 OS, Linux, Solaris, etc.

  but that won't help users who don't have
  access to Visual Studio.

  That can be solved by throwing money at the problem.
  But money doesn't help when the solution is on the
  far side of the moon.

 You're mixing metaphors and I don't understand what you mean.





   Yes, it's
   occasionally very frustrating to the rest of us, but that's life.

   As the Kurds are well aware.

  I really don't think you help your argument by trying to draw parallels
  between the problems of compiler non-availability and those of a
  population subject to random genocide.

  You missed the point of the analogy.

  The US government suggested to the oppressed tribes
  in Iraq that they should rise up and overthrow
  Saddam Hussein at the end of the first Gulf War.
  And what did the US government do when they rose up?
  Nothing. They were left to twist in the wind.

 Both the southern Iraqis (mostly so-called marsh Arabs and Shiites) and
 the northern Kurds rose up against Saddam Hussein. After the Kurdish
 rebellion failed, the US and UK belatedly provided them with aid, lots of
 aid, and kept the northern no-fly zone going until it was no longer
 relevant (2003, the second invasion of Iraq).

 It was the southern Iraqis who were left to be slaughtered. Although
 technically there was a no-fly zone in the south, it wasn't enforced
 when it really counted -- while the rebellion was in full force, the
 Iraqi government asked the US for permission to fly into the south.
 Permission was given, and the Iraq air force used combat aircraft against
 the rebels. Unlike the Kurds, they got no aid, neither money nor military
 support.

 The end result was that the southern Iraqs were hung out to dry, while the
 Kurds ended up a virtually independent state-within-a-state, with their
 own government, their own army, and US and British aircraft protecting
 them.

  Try to keep things in perspective, please.

  See if you can see the similarity.

  I buy into Python. I spend a lot of effort
  developing a math library based on GMPY to use
  in my research. I discover a bug in GMPY and
  actually go to a lot of effort and solve it.

 Good on you, and I'm not being sarcastic. But do try to keep a bit of
 perspective. Whatever your problem, you're not being bombed or shot.
 Frankly, the fact that you not only came up with the analogy, but continue
 to defend it, suggests an over-active sense of your own entitlement.

  But _I_ can't even use it because I've been
  left to twist in the wind by the fact that
  Python 2.5 for Windows was built with an
  obsolete compiler that's not even available.
  Luckily, unlike the Kurds, my situation had
  a happy ending, someone else compiled the fixed
  GMPY source and made a 2.5 Windows version
  available. But can anyone say what will happen
  the next time?

 Get yourself a compiler, then you won't be relying on the kindness of
 strangers.

 If that's not practical, for whatever reason, then remember: you're
 relying on the kindness of strangers. They don't owe you a thing. If
 anything, you owe them.

 [snip]

  Your efforts would probably be far better spent trying to build a
  back-end for mingw or some similar system into Python's development
  system, to allow Python for Windows to be built on a regular rather than
  a one-off basis using a completely open source tool chain.

  No, as I said elsewhere, I'm not a software developer,
  I'm an amateur math researcher. My efforts are best spent
  as an actual end user

 If you won't scratch your own itch, don't be surprised if nobody else
 cares enough to scratch it for you.

  to find and report bugs that the
  developers never see. Remember, a programmer, because he
  wrote it, only _thinks_ he knows how the program works.
  Whereas I, the user, _know_ how it works.

 Oh wow. That's the most audacious, self-involved and sheer arrogant claim
 I've ever heard, and I've heard a lot of nonsense sprouted by arrogant
 know-nothings with delusions of grandeur. For the sake of your
 credibility, I hope you can support that claim.

 [snip]

  It's much harder than sniping on a newsgroup,

  That figures. You try and contribute and you get
  accused of being a troll.

 I have a problem. I demand that somebody fix it for me! is hardly
 contributing.

 If you don't 

Re: Regular Expressions

2007-02-11 Thread [EMAIL PROTECTED]

 That's a little harsh -- regexes have their place, together with pointer
 arithmetic, bit manipulations, reverse polish notation and goto. The
 problem is when people use them inappropriately e.g. using a regex when a
 simple string.find will do.

  A quote attributed variously to
  Tim Peters and Jamie Zawinski says Some people, when confronted with a
  problem, think 'I know, I'll use regular expressions.' Now they have two
  problems.

 I believe that is correctly attributed to Jamie Zawinski.

 --
 Steven

So as a newbie, I have to ask. I've played with the re module now for
a while, I think regular expressions are super fun and useful. As far
as them being a problem I found they can be tricky and sometimes the
regex's I've devised do unexpected things...(which I can think of two
instances where that unexpected thing was something that I had hoped
to get into further down the line, yay for me!). So I guess I don't
really understand why they are a bad idea to use. I don't know of
any other way yet to parse specific data out of a text, html, or xml
file without resorting to regular expressions.
What other ways are there?

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


Re: can't find a way to display and print pdf through python.

2007-02-11 Thread krishnakant Mane
well yes,
I need to view reports on line and also print them from within my app.
so yes I need to display the pdf in my app and print it as well.
regards.
Krishnakant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: randomly generate n of each of two types

2007-02-11 Thread Paul Rubin
Alan Isaac [EMAIL PROTECTED] writes:
 I need access to 2*n random choices for two types
 subject to a constraint that in the end I have
 drawn n of each.  I first tried::

You mean you basically want to generate 2*n bools of which exactly
half are True and half are False?  Hmm (untested):

from random import random
def random_types(n):
total = 2*n
trues_needed = n
for i in xrange(total):
   if random()  float(trues_needed) / float(total):
  trues_needed -= 1
  yield True
   else:
  yield False
   total -= 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Pyhton script

2007-02-11 Thread soussou97

Hi; 

I would like to automatically delivery, I seek a script in python which will
be excecute from a Windows station to allows via sftp: 

1- to connect to a Linux server for storing of the files
2- Next execute on the Linux server, some actions: Copy, gzip, mv etc... 
3- to use a config file for the parameters: server name, login, password...

Regards;
-- 
View this message in context: 
http://www.nabble.com/Pyhton-script-tf3209528.html#a8912801
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Generating pdf files in epydoc on Windows

2007-02-11 Thread Don Taylor
Does anyone know what is needed to install to get epydoc to generate pdf
files on Windows.  Besides epydoc itself of course.

Maybe there is a more appropriate forum to ask newbie questions about 
epydoc?

Thanks,

Don.

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


Re: Regular Expressions

2007-02-11 Thread skip

jwz Some people, when confronted with a problem, think 'I know, I'll
jwz use regular expressions.' Now they have two problems.

dbl So as a newbie, I have to ask  So I guess I don't really
dbl understand why they are a bad idea to use. 

Regular expressions are fine in their place, however, you can get carried
away.  For example:

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

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


Re: Regular Expressions

2007-02-11 Thread Gabriel Genellina
En Sun, 11 Feb 2007 13:35:26 -0300, [EMAIL PROTECTED]  
[EMAIL PROTECTED] escribió:

 (Steven?)
 That's a little harsh -- regexes have their place, together with pointer
 arithmetic, bit manipulations, reverse polish notation and goto. The
 problem is when people use them inappropriately e.g. using a regex when  
 a
 simple string.find will do.

 So as a newbie, I have to ask. I've played with the re module now for
 a while, I think regular expressions are super fun and useful. As far
 as them being a problem I found they can be tricky and sometimes the
 regex's I've devised do unexpected things...(which I can think of two
 instances where that unexpected thing was something that I had hoped
 to get into further down the line, yay for me!). So I guess I don't
 really understand why they are a bad idea to use. I don't know of
 any other way yet to parse specific data out of a text, html, or xml
 file without resorting to regular expressions.
 What other ways are there?

For very simple things, it's easier/faster to use string methods like find  
or split. By example, splitting 2007-02-11 into y,m,d parts:
y,m,d = date.split(-)
is a lot faster than matching (\d+)-(\d+)-(\d+)
On the other hand, complex tasks like parsing an HTML/XML document,  
*can't* be done with a regexp alone; but people insist anyway, and then  
complain when it doesn't work as expected, and ask how to fix the  
regexp...
Good usage of regexps maybe goes in the middle.

-- 
Gabriel Genellina

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


Adding an XML fragment as a child node in a pre-existing Element tree

2007-02-11 Thread Rajarshi
Hi, I'm using ElementTree for some RSS processing. The point where I
face a problem is that within an item/item I need to add another
child node (in addition to link etc) which is a well-formed XML
document (Chemical Markup Language to be precise).

So my code looks like:

import cElementTree as ET

c = open('x.cml').readlines()
c = string.join(c)
cml = ET.XML(c)

Now I also have the following code:

def addItem(self, title, link, description, cml = None):
RSSitem = ET.SubElement ( self.RSSchannel, 'item' )

ET.SubElement( RSSitem, 'title' ).text = title
ET.SubElement( RSSitem, 'description' ).text = description

What I'm confused is how I can add the cml Element object that I
generated, to the RSSitem as a child node.

Do I need to manually traverse the tree of the CML document and add it
one by one to the RSSitem as a child node? Or is there a smarter way
to do this?

Any pointers would be greatly appreciated
Thanks,

Rajarshi

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


Re: Problem with reimporting modules

2007-02-11 Thread Christoph Zwerschke
Yes I know about reload(), but TurboGears (TurboKid) does not use it and 
the docs say that removing modules from sys.module is possible to force 
reloading of modules. I don't want to rewrite everything since it's a 
pretty complex thing with modules which are compiled from templates 
which can depend from other templates etc...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding an XML fragment as a child node in a pre-existing Element tree

2007-02-11 Thread Gabriel Genellina
En Sun, 11 Feb 2007 15:15:21 -0300, Rajarshi [EMAIL PROTECTED]  
escribió:

 Hi, I'm using ElementTree for some RSS processing. The point where I
 face a problem is that within an item/item I need to add another
 child node (in addition to link etc) which is a well-formed XML
 document (Chemical Markup Language to be precise).

 So my code looks like:

 import cElementTree as ET

 c = open('x.cml').readlines()
 c = string.join(c)
 cml = ET.XML(c)

All the above thing can be replaced by:
cml = ET.parse(x.cml)


 Now I also have the following code:

 def addItem(self, title, link, description, cml = None):
 RSSitem = ET.SubElement ( self.RSSchannel, 'item' )

 ET.SubElement( RSSitem, 'title' ).text = title
 ET.SubElement( RSSitem, 'description' ).text = description

 What I'm confused is how I can add the cml Element object that I
 generated, to the RSSitem as a child node.

SubElement is just a convenience function for creating a new element and  
appending it to an existing parent element. As you already have the new  
subelement, just use append:

RSSitem.append(cml)

See the documentation at http://www.effbot.org/zone/element-index.htm

-- 
Gabriel Genellina

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


Re: Pyhton script

2007-02-11 Thread Jonathan Curran
On Sunday 11 February 2007 11:47, soussou97 wrote:
 Hi;

 I would like to automatically delivery, I seek a script in python which
 will be excecute from a Windows station to allows via sftp:

 1- to connect to a Linux server for storing of the files
 2- Next execute on the Linux server, some actions: Copy, gzip, mv etc...
 3- to use a config file for the parameters: server name, login, password...

 Regards;
 --
 View this message in context:
 http://www.nabble.com/Pyhton-script-tf3209528.html#a8912801 Sent from the
 Python - python-list mailing list archive at Nabble.com.

How much are you willing to spend on this script? ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyhton script

2007-02-11 Thread Jonathan Curran
On Sunday 11 February 2007 11:47, soussou97 wrote:
 Hi;

 I would like to automatically delivery, I seek a script in python which
 will be excecute from a Windows station to allows via sftp:

 1- to connect to a Linux server for storing of the files
 2- Next execute on the Linux server, some actions: Copy, gzip, mv etc...
 3- to use a config file for the parameters: server name, login, password...

 Regards;
 --
 View this message in context:
 http://www.nabble.com/Pyhton-script-tf3209528.html#a8912801 Sent from the
 Python - python-list mailing list archive at Nabble.com.

Just joking with the last message, though I hope that you weren't looking for 
someone to just send it to you. Take a look at Paramiko, it's exactly the 
library you need to do these things.

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


help please!!

2007-02-11 Thread darren112
Hi Im new to python and I desperately need help with this task
This is everything of what I need to do...

The program to be written in Python obviously..

The program should support brute-forcing of the authentication process
for a Telnet server via a dictionary attack.

The python program is required to take four parameters: a) the IP
address of a Computer, b) the port number that the Telnet server is
running on the computer , c) the name of a file containing a list if
usernames, and b) the name of a file containing a list of word/phrases
to be used as passwords.

The program should then attempt to authenticate itself to the Telnet
server via trying every password for every username. The program
should report when it is successful.

Please help me And as I am new to all this please post step by
step instructions...

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


Re: help please!!

2007-02-11 Thread hg
darren112 wrote:

 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...
 
 The program to be written in Python obviously..
 
 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.
 
 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.
 
 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.
 
 Please help me And as I am new to all this please post step by
 step instructions...

That is funny !

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


Re: help please!!

2007-02-11 Thread azrael
well, this sounds funn.

1) dont expect someone to do your homework.
2) dont expect someone to do dirty homework
3) dont expect someone to do your home work especially when it's
something that could make you problems, or the person that is helping
you
4) from your message i can read that you need the application, and
not some knowledge. I don't know what other guys here think about it,
if my opinion can considered, you are on your own.

i suggest you take a python tutorial and learn how to do it yourself.
This situation stinks.






On Feb 11, 8:40 pm, darren112 [EMAIL PROTECTED] wrote:
 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...

 The program to be written in Python obviously..

 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.

 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.

 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.

 Please help me And as I am new to all this please post step by
 step instructions...


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


Re: help please!!

2007-02-11 Thread Jonathan Curran
On Sunday 11 February 2007 13:40, darren112 wrote:
 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...

 The program to be written in Python obviously..

 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.

 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.

 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.

 Please help me And as I am new to all this please post step by
 step instructions...

/me points and laughs at you. Hahahahaha, stupid script kiddie. Get a life.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with reimporting modules

2007-02-11 Thread Gabriel Genellina
En Sun, 11 Feb 2007 15:56:16 -0300, Christoph Zwerschke [EMAIL PROTECTED]  
escribió:

 Yes I know about reload(), but TurboGears (TurboKid) does not use it and
 the docs say that removing modules from sys.module is possible to force
 reloading of modules. I don't want to rewrite everything since it's a
 pretty complex thing with modules which are compiled from templates
 which can depend from other templates etc...

If you remove the module from sys.modules, when you import it again you  
end up with a *new*, fresh, module object, unrelated to the original one.

Quoting your original message again:

 I tracked it down to the following behavior of Python. Assume you have a
 module hello.py like that:
   hello. py 
 greeting = 'Hello!'
 def print_hello():
  print greeting
 ---
  Now run the following code:
  from hello import print_hello
 print_hello()
 import sys
 del sys.modules['hello'] # delete module
 import hello # recreate module
 print_hello()
  The second print_hello() prints None instead of Hello!. Why is that?

Notice that you are mixing references here. You first import print_hello  
 from hello, and after deleting the module, you import hello (not  
print_hello). And you expect that your old reference to print_hello now  
refers to the new function. The whole point of reloading/reimporting a  
module is to get the *new* contents, but that only works if you refer to  
things using the module.function notation, not if you hold a reference to  
the function (which will always be the original function).

In short, your code should be:

import hello
hello.print_hello()
import sys
del sys.modules['hello']
import hello
hello.print_hello()

or, using reload:

import hello
hello.print_hello()
reload(hello)
hello.print_hello()

If you think that always typing module.function is too much - well, don't  
try to reload modules then :)
Somewhere I read that at Google the policy is to always import modules,  
never functions, and this may be a good reason for it.

If you want to know the details: print_hello doesn't hold a reference to  
the containing module, only to its namespace, in the func_globals  
attribute. When you delete the last reference to the module, it gets  
destroyed. At that time, all values in the module namespace are set to  
None (for breaking possible cycles, I presume). print_hello now has a  
func_globals with all names set to None. (Perhaps the names could have  
been deleted instead, so print_hello() would raise a NameError, but I'm  
just describing the current CPython implementation)

-- 
Gabriel Genellina

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


Re: help please!!

2007-02-11 Thread Gabriel Genellina
En Sun, 11 Feb 2007 16:40:45 -0300, darren112 [EMAIL PROTECTED]  
escribió:

 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.

You should first read the Python Tutorial. After you get proficient with  
the basic programming structures, reading and writing files, networking,  
then use the telnetlib module (included with the standard Python library)  
to write your program. Depending on your previous experience and daily  
time, that might take from a couple days to one or two months.

-- 
Gabriel Genellina

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


Re: Regular Expressions

2007-02-11 Thread John Machin
On Feb 12, 3:35 am, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
  That's a little harsh -- regexes have their place, together with pointer
  arithmetic, bit manipulations, reverse polish notation and goto. The
  problem is when people use them inappropriately e.g. using a regex when a
  simple string.find will do.

   A quote attributed variously to
   Tim Peters and Jamie Zawinski says Some people, when confronted with a
   problem, think 'I know, I'll use regular expressions.' Now they have two
   problems.

  I believe that is correctly attributed to Jamie Zawinski.

  --
  Steven

 So as a newbie, I have to ask. I've played with the re module now for
 a while, I think regular expressions are super fun and useful. As far
 as them being a problem I found they can be tricky and sometimes the
 regex's I've devised do unexpected things...(which I can think of two
 instances where that unexpected thing was something that I had hoped
 to get into further down the line, yay for me!). So I guess I don't
 really understand why they are a bad idea to use.

Regexes are not bad. However people tend to overuse them, whether
they are overkill (like Gabriel's date-splitting example) or underkill
-- see your next sentence :-)

 I don't know of
 any other way yet to parse specific data out of a text, html, or xml
 file without resorting to regular expressions.
 What other ways are there?

Text: Paul Maguire's pyparsing module (Google is your friend); read
David Mertz's book on text processing with Python (free download, I
believe); modules for specific data formats e.g. csv

HTML: htmllib and HTMLParser (both in the Python library),
BeautifulSoup (again GIYF)

XML: xml.* in the Python library. ElementTree (recommended) is
included in Python 2.5; use xml.etree.cElementTree.

HTH,
John

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


Re: urllib2 request htaccess page through proxy

2007-02-11 Thread John J. Lee
Alessandro Fachin [EMAIL PROTECTED] writes:

 I write this simply code that should give me the access to private page with
 htaccess using a proxy, i don't known because it's wrong... 
[...]
 i get no access on access.log from apache2 and nothing from the proxy in
 tcpdump log. If i use only the proxy with a page that doesn't use htaccess
 it works... if anyone could help,regards...
[...]
 urllib2.HTTPError: HTTP Error 401: Authorization Required

Works for me (using Squid and Apache both running on localhost).
Looking at what goes over the wire, I see a 401 followed by a 299
response, which is what is expected (the 401 prompts the client to
send the username and password, which is then rewarded with the 200).

Could you describe in more detail what your proxy and Apache
configuration are like?  And more about your network (on what machines
do proxy, HTTP server, and HTTP client run -- all on the same machine,
some on the same machine, all three on three different machines?)  The
more detail the better.


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


Re: help please!!

2007-02-11 Thread azrael
Hey yo kiddie, I hope that you are using the web for some time. So you
can get the meaning from my post.:


LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL, ROTF, LOL,
ROTF, LOL, ROTF, LOL, ROTF,

my stomach hurts

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


MySQLdb binaries (was Re: huge amounts of pure...)

2007-02-11 Thread John J. Lee
Robin Becker [EMAIL PROTECTED] writes:

 [EMAIL PROTECTED] wrote:
  John MySQLdb isn't fully supported for Python 2.5 yet, and there's no
  John tested Windows executable available, although there's an untested
  John version from a World of Warcraft guild available.
  As Andy Dustman has pointed out a number of times, he doesn't do
  Windows.
  Someone in the MySQLdb community who does use Windows is going to have to
  fill that void.
 ..
 
 well I have managed to build both extant versions
 (MySQL-python-1.2.1_p2  MySQL-python-1.2.2b2) from source with the
 aid of Mr Dustman's comments in the site.cfg files and a very minor
 hack to the earlier version. I had to have the sources for Mysql
 available as well, but that probably comes with the territory. It
 seems the very latest version won't play well with earlier MySQL so I
 used MySQL-python-1.2.1_p2 as we are still using some 4.0.27 databases.
 
 Given that I used a particular version of MySQL, 5.0.33, to build
 against I'm not certain that my builds are useful for everyone. I copy
 here the differences I had to make to the source to get stuff to build
 and run against stock win32 Python-2.5
[...]

Robin may be right, but the resulting binaries are here (not
supported, use at your own risk):

http://www.reportlab.org/ftp/MySQLdb-1.1.2b2-win32-py25.zip

or

ftp://www.reportlab.org/MySQLdb-1.1.2b2-win32-py25.zip


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


Re: randomly generate n of each of two types

2007-02-11 Thread Stargaming
Alan Isaac schrieb:
 I need access to 2*n random choices for two types
 subject to a constraint that in the end I have
 drawn n of each.  I first tried::
 
 def random_types(n,typelist=[True,False]):
 types = typelist*n
 random.shuffle(types)
 for next_type in types:
 yield next_type
 
 This works but has some obvious costs.
 To avoid those I considered this instead::
 
 def random_types(n,typelist=[True,False]):
 type0, type1 = typelist
 ct0, ct1 = 0,0
 while ct0+ct12*n:
 if random.random()  ((n-ct0)/(2*n-ct0-ct1)):
 next_type = type0
 ct0 += 1
 else:
 next_type = type1
 ct1 += 1
 yield next_type
 
 Does this seem a good way to go?  Comments welcome.

I think there's any easier way using random's function `shuffle`.

  from random import shuffle
  def randomly(n, types):
...   types *= n
...   shuffle(types)
...   for x in types: yield x
...
  randomly(1, [True, False])
generator object at 0x00A62AA8
  list(randomly(1, [True, False]))
[True, False]
  list(randomly(2, [True, False]))
[True, False, True, False]
  list(randomly(4, [True, False]))
[False, True, False, False, False, True, True, True]

You can even do this with an arbitrary number of choices:
  list(randomly(2, [True, False, None, NotImplemented]))
[NotImplemented, None, NotImplemented, False, False, None, True, True]

Notice that this method works in-place, ie
  a = [True, False]
  list(randomly(2, a))
[False, False, True, True]
  a # a changed!
[False, False, True, True]

This can be changed by creating a copy, though.

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


Re: Problem with reimporting modules

2007-02-11 Thread Christoph Zwerschke
Thanks for the detailed explanations, Gabriel.

 At that time, all values in the module namespace are set to 
 None (for breaking possible cycles, I presume). print_hello now has a 
 func_globals with all names set to None. (Perhaps the names could have 
 been deleted instead, so print_hello() would raise a NameError, but I'm 
 just describing the current CPython implementation)

Yes, that was the thing that confused me a bit. I had expected that an 
error is raised or that the namespace has a reference to the module and 
is reestablished when the module has been reloaded.

Anyway, I have solved the problem in a different way now.

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


Re: Regular Expressions

2007-02-11 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 That's a little harsh -- regexes have their place, together with pointer
 arithmetic, bit manipulations, reverse polish notation and goto. The
 problem is when people use them inappropriately e.g. using a regex when a
 simple string.find will do.

 A quote attributed variously to
 Tim Peters and Jamie Zawinski says Some people, when confronted with a
 problem, think 'I know, I'll use regular expressions.' Now they have two
 problems.
 I believe that is correctly attributed to Jamie Zawinski.

 --
 Steven
 
 So as a newbie, I have to ask. I've played with the re module now for
 a while, I think regular expressions are super fun and useful. As far
 as them being a problem I found they can be tricky and sometimes the
 regex's I've devised do unexpected things...(which I can think of two
 instances where that unexpected thing was something that I had hoped
 to get into further down the line, yay for me!). So I guess I don't
 really understand why they are a bad idea to use. I don't know of
 any other way yet to parse specific data out of a text, html, or xml
 file without resorting to regular expressions.
 What other ways are there?
 
Re's aren't inherently bad. Just avoid using them as a hammer to the 
extent that all your problems look like nails.

They wouldn't exist if there weren't problems it was appropriate to use 
them on. Just try to use simpler techniques first.

For example, don't use re's to find out if a string starts with a 
specific substring when you could instead use the .startswith() string 
method.

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
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

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


Regexps and lists

2007-02-11 Thread Paddy
I don't know enough to write an R.E. engine so forgive me if I am
being naive.
I have had to atch text involving lists in the past. These are usually
comma separated words such as
 egg,beans,ham,spam,spam
you can match that with:
 r(\w+)(,\w+)*
and when you look at the groups you get the following

 import re
 re.match(r(\w+)(,\w+)*, egg,beans,ham,spam,spam).groups()
('egg', ',spam')


Notice how you only get the last match as the second groups value.

It would be nice if a repeat operator acting on a group turned that
group into a sequence returning every match, in order. (or an empty
sequence for no matches).

The above exaple would become:

  import re
 re.newmatch(r(\w+)(,\w+)*, egg,beans,ham,spam,spam).groups()
('egg', ('beans', 'ham', 'spam', ',spam'))


1, Is it possible? do any other RE engines do this?
2, Should it be added to Python?

- Paddy.

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


Saving PyOpenGl figures as ps

2007-02-11 Thread Frank
Hi,

I installed pyopengl (opengl for python) on my linux box and
everything works fine. But now I want to save the generated images as,
e.g., ps or eps. How can I do that and how can I adjust the resolution
(if necessary)? This is probably simple but for some reason I can not
find out how to do that.

I appreciate every hint!

Thanks, Frank

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


Re: compound statement from C test?true-val:false-val

2007-02-11 Thread Holger
Thanks all for good input.
It seems like there's no the-python-way for this one.

Currently I'm forced to use cygwin - and python in cygwin is still not
2.5 so I can't use the new inline if-else ternary operator.

  if n == 1:
  print I saw a car
  else:
  print I saw %d cars % n

Personally I don't like the if-else approach because of the don't-
repeat-yourself philosophy

 D'accord. Did I mention that, as a for fun approach, s * (n != 1) is
 quite clever :-)

 Peter

I like this one :-)

 print I saw %d car%s\n % (n, (, s)[n != 1])

And this one.

/Holger

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


Re: Parsing HTML

2007-02-11 Thread Paul McGuire
On Feb 10, 5:03 pm, mtuller [EMAIL PROTECTED] wrote:
 Alright. I have tried everything I can find, but am not getting
 anywhere. I have a web page that has data like this:

 tr 
 td headers=col1_1  style=width:21%   
 span  class=hpPageText LETTER/span/td
 td headers=col2_1  style=width:13%; text-align:right   
 span  class=hpPageText 33,699/span/td
 td headers=col3_1  style=width:13%; text-align:right   
 span  class=hpPageText 1.0/span/td
 td headers=col4_1  style=width:13%; text-align:right   
 /tr

 What is show is only a small section.

 I want to extract the 33,699 (which is dynamic) and set the value to a
 variable so that I can insert it into a database. I have tried parsing
 the html with pyparsing, and the examples will get it to print all
 instances with span, of which there are a hundred or so when I use:

 for srvrtokens in printCount.searchString(printerListHTML):
 print srvrtokens

 If I set the last line to srvtokens[3] I get the values, but I don't
 know grab a single line and then set that as a variable.


So what you are saying is that you need to make your pattern more
specific.  So I suggest adding these items to your matching pattern:
- only match span if inside a td with attribute 'headers=col2_1'
- only match if the span body is an integer (with optional comma
separater for thousands)

This grammar adds these more specific tests for matching the input
HTML (note also the use of results names to make it easy to extract
the integer number, and a parse action added to integer to convert the
'33,699' string to the integer 33699).

-- Paul


htmlSource = tr 
td headers=col1_1  style=width:21%   
span  class=hpPageText LETTER/span/td
td headers=col2_1  style=width:13%; text-align:right   
span  class=hpPageText 33,699/span/td
td headers=col3_1  style=width:13%; text-align:right   
span  class=hpPageText 1.0/span/td
td headers=col4_1  style=width:13%; text-align:right   
/tr

from pyparsing import makeHTMLTags, Word, nums, ParseException

tdStart, tdEnd = makeHTMLTags('td')
spanStart, spanEnd = makeHTMLTags('span')

def onlyAcceptWithTagAttr(attrname,attrval):
def action(tagAttrs):
if not(attrname in tagAttrs and tagAttrs[attrname]==attrval):
raise ParseException(,0,)
return action

tdStart.setParseAction(onlyAcceptWithTagAttr(headers,col2_1))
spanStart.setParseAction(onlyAcceptWithTagAttr(class,hpPageText))

integer = Word(nums,nums+',')
integer.setParseAction(lambda t:int(.join(c for c in t[0] if c !=
',')))

patt = tdStart + spanStart + integer.setResultsName(intValue) +
spanEnd + tdEnd

for matches in patt.searchString(htmlSource):
print matches.intValue

prints:
33699


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


Re: Regexps and lists

2007-02-11 Thread John Machin
On Feb 12, 9:08 am, Paddy [EMAIL PROTECTED] wrote:
 I don't know enough to write an R.E. engine so forgive me if I am
 being naive.
 I have had to atch text involving lists in the past. These are usually
 comma separated words such as
  egg,beans,ham,spam,spam
 you can match that with:
  r(\w+)(,\w+)*

You *can*, but why do that? What are you trying to achieve? What is
the point of distinguishing the first element from the remainder?

See if any of the following do what you want:

|  s = egg,beans,ham,spam,spam
|  s.split(',')
| ['egg', 'beans', 'ham', 'spam', 'spam']
|  import re
|  re.split(r,, s)
| ['egg', 'beans', 'ham', 'spam', 'spam']
|  re.split(r(,), s)
| ['egg', ',', 'beans', ',', 'ham', ',', 'spam', ',', 'spam']

 and when you look at the groups you get the following
  import re
  re.match(r(\w+)(,\w+)*, egg,beans,ham,spam,spam).groups()
 ('egg', ',spam')

 Notice how you only get the last match as the second groups value.

 It would be nice if a repeat operator acting on a group turned that
 group into a sequence returning every match, in order. (or an empty
 sequence for no matches).

 The above exaple would become:

   import re re.newmatch(r(\w+)(,\w+)*, 
 egg,beans,ham,spam,spam).groups()

 ('egg', ('beans', 'ham', 'spam', ',spam'))

And then what are you going to do with the answer? Something like
this, maybe:

|  actual_answer = ('egg', ('beans', 'ham', 'spam', ',spam'))
|  [actual_answer[0]] +list(actual_answer[1])
| ['egg', 'beans', 'ham', 'spam', ',spam']


 1, Is it possible?

Maybe, but I doubt the utility ...

 do any other RE engines do this?

If your Google is not working, then mine isn't either.

 2, Should it be added to Python?

No.

HTH,

John

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


Re: Database Programming with Python

2007-02-11 Thread Tim Roberts
[EMAIL PROTECTED] wrote:

I wanted to connect Python to Ms-Access database using ADO or ODBC. I
have Python 2.5 and on mxODBC site, it has no higher version build
than 2.4. Moreoever, mxODBC is required for ADODB.
Can anyone guide me on this what should I do to make it work on Python
2.5? I have python 2.5 running on server.

You don't actually need mxODBC to use ADODB.  As long as you have the
pywin32 extensions, you have what you need.

import win32com.client
conn = win32com.client.Dispatch('ADODB.Connection')
conn.Open( DRIVER={Microsoft Access Driver (*.mdb)};DBQ=x.mdb )
cmd = win32com.client.Dispatch('ADODB.Command')
cmd.ActiveConnection = conn

cmd.CommandText = SELECT firstname,lastname FROM users;
rs = cmd.Execute()[0]
while not rs.EOF:
# Use elements of rs
rs.MoveNext()

There are samples on the web.  Google should help.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


New Pythin user looking foe some good examples to study

2007-02-11 Thread Johnny Garcia
I have just discovered Python and am familiarizing myself with the syntax 
but I have always found that code examples where the best way for me to 
learn.



Can anyone point me to a site with some good open source functioning python 
applications?



I would appreciate any help.



Also, does anyone know of any good Linux or python user groups in the orange 
county, California area?


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


Re: Hacking in python

2007-02-11 Thread Marshillboy
On Feb 10, 5:25 pm, Geoff Hill [EMAIL PROTECTED] wrote:
 The word hack can be known as a smart/quick fix to a problem.

Giving the benefit of the doubt here, perhaps Enes Naci saw this
article: http://www.hetland.org/python/instant-hacking.php and got
some strange idea about confusing programming with breaking into
computer systems.  Maybe.

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


searching a list of lists as a two-dimensional array?

2007-02-11 Thread agent-s
Basically I'm programming a board game and I have to use a list of
lists to represent the board (a list of 8 lists with 8 elements each).
I have to search the adjacent cells for existing pieces and I was
wondering how I would go about doing this efficiently. Thanks

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


Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread James Stroud
agent-s wrote:
 Basically I'm programming a board game and I have to use a list of
 lists to represent the board (a list of 8 lists with 8 elements each).
 I have to search the adjacent cells for existing pieces and I was
 wondering how I would go about doing this efficiently. Thanks
 

This isn't very clear. What do you mean by I have to search the 
adjacent cells for existing pieces?

If piece is 1 and empty is 0 and piece is at ary[row][col]:

import operator
srch = [(i,j) for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)]
is_adj = reduce(operator.or_, [ary[row+i][col+j] for (i,j) in srch]])


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


No module named pyExcelerator Error

2007-02-11 Thread susan
Hi,
I'm new of Python, and this problem stucked me whole day but can't be
solved.

I use python 2.4.3, which is download from cygwin packages. Then I
downloaded pyexcelerator-0.5.3a, unzip it,

$ python ./pyExcelerator/setup.py install
running install
running build
running build_py
package init file 'pyExcelerator/__init__.py' not found (or not a
regular file)
copying pyExcelerator/setup.py - build/lib/pyExcelerator
package init file 'pyExcelerator/__init__.py' not found (or not a
regular file)
running install_lib
copying build/lib/pyExcelerator/setup.py - /usr/lib/python2.4/site-
packages/pyE
xcelerator
byte-compiling /usr/lib/python2.4/site-packages/pyExcelerator/setup.py
to setup.
pyc

But 'pyExcelerator/__init__.py' is absolutely there, I don't know why
I got the warning. Then I tried to import pyExcelerator,
 import pyExcelerator
Traceback (most recent call last):
  File stdin, line 1, in ?
ImportError: No module named pyExcelerator

anybody can tell me where's wrong please? Thanks in advance!

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


Re: compound statement from C test?true-val:false-val

2007-02-11 Thread Carl Banks
On Feb 11, 5:16 pm, Holger [EMAIL PROTECTED] wrote:
 Thanks all for good input.
 It seems like there's no the-python-way for this one.

 Currently I'm forced to use cygwin - and python in cygwin is still not
 2.5 so I can't use the new inline if-else ternary operator.

   if n == 1:
   print I saw a car
   else:
   print I saw %d cars % n

 Personally I don't like the if-else approach because of the don't-
 repeat-yourself philosophy

You shouldn't be worried a repeating few characters from a short,
simple print statement.  It's not a mortal sin.

You don't need any ternary operator to avoid repetition, anyways.  You
could factor the common parts out like this:

if n == 1:
what = a car
else:
what = %d cars % n
print I saw %s % what

but what's the point?  It's just a few repeated characters two lines
apart.  Peter's version is the most easily read version here,
including the one using the official ternary operator.


Carl Banks

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


Re: randomly generate n of each of two types

2007-02-11 Thread Alan Isaac
Stargaming [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 ...   types *= n
 ...   shuffle(types)

This again has the costs I referred to:
creating a potentially large sequence,
and shuffling it.  (Additionally, shuffle
cannot achieve many of the possible
shuffles of a large list, but I doubt this
is easily evaded.)

So as far as I can tell, this is the same
approach as the original (first) solution.

Cheers,
Alan Isaac


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


Re: help please!!

2007-02-11 Thread James Stroud
darren112 wrote:
 Hi Im new to python and I desperately need help with this task
 This is everything of what I need to do...
 
 The program to be written in Python obviously..
 
 The program should support brute-forcing of the authentication process
 for a Telnet server via a dictionary attack.
 
 The python program is required to take four parameters: a) the IP
 address of a Computer, b) the port number that the Telnet server is
 running on the computer , c) the name of a file containing a list if
 usernames, and b) the name of a file containing a list of word/phrases
 to be used as passwords.
 
 The program should then attempt to authenticate itself to the Telnet
 server via trying every password for every username. The program
 should report when it is successful.
 
 Please help me And as I am new to all this please post step by
 step instructions...
 

I'm guessing this is a troll rather than a script kiddy. It seems more 
like bait than an honest question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No module named pyExcelerator Error

2007-02-11 Thread John Machin
On Feb 12, 11:55 am, susan [EMAIL PROTECTED] wrote:
 Hi,
 I'm new of Python, and this problem stucked me whole day but can't be
 solved.

 I use python 2.4.3, which is download from cygwin packages.

Is your Python installation working properly for you with other
things, or is installing pyExcelerator the first thing that you have
tried?

 Then I
 downloaded pyexcelerator-0.5.3a, unzip it,

Is that 5 a typo? The latest version is 0.6.3a


 $ python ./pyExcelerator/setup.py install

Try this instead:
$ cd pyExcelerator
$ python ./setup.py install

i.e. do what the pyExcelerator README tells you to do.

0x0003. Installation.

As usually: python ./setup.py install

This may make a positive difference; it can't be worse.

HTH,
John


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


Re: Generating pdf files in epydoc on Windows

2007-02-11 Thread Duncan Smith
Don Taylor wrote:
 Does anyone know what is needed to install to get epydoc to generate pdf
 files on Windows.  Besides epydoc itself of course.
 
 Maybe there is a more appropriate forum to ask newbie questions about
 epydoc?
 

As I remember, LaTeX and ghostscript.

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


Re: compound statement from C test?true-val:false-val

2007-02-11 Thread BJörn Lindqvist
On 11 Feb 2007 16:57:07 -0800, Carl Banks [EMAIL PROTECTED] wrote:
 You don't need any ternary operator to avoid repetition, anyways.  You
 could factor the common parts out like this:

 if n == 1:
 what = a car
 else:
 what = %d cars % n
 print I saw %s % what

Or even better (IMHO):

what = %d cars % n
if n == 1:
what = a car
print I saw %s % what

One less line and just as readable.

 but what's the point?  It's just a few repeated characters two lines
 apart.  Peter's version is the most easily read version here,
 including the one using the official ternary operator.

Agreed.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Read/write 2D data from/to file..?

2007-02-11 Thread mech point

I was able to read the data from file into a two dimensional array
(lists)

rows=[map(float,line.split())for line in file(data)]

but How to write them back into the file.

Thank you,
srikanth

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


Re: compound statement from C test?true-val:false-val

2007-02-11 Thread Gabriel Genellina
En Sun, 11 Feb 2007 19:16:49 -0300, Holger [EMAIL PROTECTED] escribió:

  if n == 1:
  print I saw a car
  else:
  print I saw %d cars % n

 Personally I don't like the if-else approach because of the don't-
 repeat-yourself philosophy

 D'accord. Did I mention that, as a for fun approach, s * (n != 1) is
 quite clever :-)
 I like this one :-)

 print I saw %d car%s\n % (n, (, s)[n != 1])
 And this one.

I presume all of this is only used as an example on using expressions. In  
any application with any chances of being i18n, the only viable way is the  
first one. Doing algebra on phrases is a no-no.

-- 
Gabriel Genellina

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


Re: Read/write 2D data from/to file..?

2007-02-11 Thread John Machin
On Feb 12, 12:47 pm, mech point [EMAIL PROTECTED] wrote:
 I was able to read the data from file into a two dimensional array
 (lists)

 rows=[map(float,line.split())for line in file(data)]

 but How to write them back into the file.

Presuming that it is either mandatory to adopt the same style (or lack
thereof) as the input code, and/or futile to suggest otherwise:

file('data2','w').write('\n'.join(' '.join(repr(item)for item in
row)for row in rows)+'\n')


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


Re: Read/write 2D data from/to file..?

2007-02-11 Thread Grant Edwards
On 2007-02-12, mech point [EMAIL PROTECTED] wrote:

 I was able to read the data from file into a two dimensional array
 (lists)

 rows=[map(float,line.split())for line in file(data)]

 but How to write them back into the file.

for r in rows:
file.write( .join(map(str,r)) + \n)

-- 
Grant Edwards   grante Yow!  My nose feels like a
  at   bad Ronald Reagan movie...
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read/write 2D data from/to file..?

2007-02-11 Thread Gabriel Genellina
En Sun, 11 Feb 2007 22:47:30 -0300, mech point [EMAIL PROTECTED]  
escribió:

 I was able to read the data from file into a two dimensional array
 (lists)

 rows=[map(float,line.split())for line in file(data)]

 but How to write them back into the file.

This way uses the same structures as your example; line.split(,) -  
,.join(...); map(float,...) - map(str,...)

yourfile.writelines(,.join(map(str,row))+\n for row in rows)

If you are using Python2.5, put [] inside the writelines call:  
writelines([,...]).
Or move the iteration outer. If you want control on the format too:
for row in rows:
   yourfile.write(%.2f,%.6g\n % (row[0], row[1]))

-- 
Gabriel Genellina

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


Help with Optimization of Python software: real-time audio controller

2007-02-11 Thread craiglewiston
I've been working on a Python-based music training application for a
few months, and have recently run into what I believe are some basic
limitations (or at least constraints) of Python with regards to
timing.  I'll try and give a decently thorough description, and
hopefully some of you can process this with your knowledge and help
steer me in the right direction.

As mentioned above, my application deals with music training. I have a
Tkinter GUI, which communicates via pyserial with an external device I
built myself.  The code reads in a MIDI file and converts the song to
output data  for the external device and the GUI, all adjusted to
the user-selected tempo.  While the MIDI file is playing, there are 4
main actions the code must take:
1) Send output data signals out to the external hardware.
2) Poll the input from the external hardware device for incoming
keypresses.  If detected, then the play the sound corresponding to
that key.
3) Start and keep a metronome running for the durations of the song.
4) Update GUI

I'm able to get all the above accomplished through the use of
threads and a top-level loop (for updating the Tkinter GUI  - if
you've worked with threads and Tkinter, then you know that you can't
update a Tkinter GUI from a thread, but instead have to do it on the
top level loop).

While running, I have  the following threads implemented :
1) song processing thread - this thread steps incrementally through a
data matrix (the output data), and updates two variables:  GUI_vars
and  Device_vars
2) metronome thread  - this thread starts at the same time as thread
#1, and outputs a beep to the audio chain
3) poll input thread  - this thread loops continually, looking for
data on the serial Input.  When data is found, it starts playing the
sound corresponding to that key until a note off signal is received
4) top-level recursive loop (technically not a thread) for updating
GUI and calling Serial Write subfunction.  This loop monitors GUI_vars
and Device_vars, updating the GUI and writing out to the device when
either variable has changed

Currently, I have all of the above working, although I'm running
into some serious timing issues.  When I run the program, I get
irregular timing for my metronome (if it sounds at all), as well as
irregular timing in writing to the external device.  It's extremely
crucial that threads #1  #2 are executed as close to real-time as
possible, as they form the core of the song, and their elements
can't be delayed without messing the song up considerably.


I've read up quite a bit on different optimization methods in Python,
but am not sure which direction to head.  I've checked out profile,
Psyco, Pyrex, as well as just porting everything over to C.  Since I'm
on a Mac (Power PC), I can't use Psyco.  And doing any of the others
seemed like a big enough project that I should really ask someone else
before I embark.

So, for a music-based application where it's crucial to have real-time
execution of serial writeouts and audio, as well as keeping a
continual poll on the input from the same portcan this be done
successfully in Python?  Does using Tkinter have anything to do with
my timing issues?  Would it benefit me to move over to wxPython
(something I've been considering doing)?  As for the metronome, should
I incorporate the metronome thread into the song processing thread,
since both are dealing with events whose timing is crucial?

I'm a relative newbie (this is my first Python project) to Python, so
any help is GREATLY appreciated!

Also, just for reference, here's a list of the modules I'm using and
my system info:
Audio:  SndObj
Ser com: pyserial
GUI: Tkinter
System: Apple PowerBook G4 (PowerPC), Mac OS 10.4, Python 2.4.4

Thanks,
Craig Lewiston

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


Re: Read/write 2D data from/to file..?

2007-02-11 Thread Grant Edwards
On 2007-02-12, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2007-02-12, mech point [EMAIL PROTECTED] wrote:

 I was able to read the data from file into a two dimensional array
 (lists)

 rows=[map(float,line.split())for line in file(data)]

 but How to write them back into the file.

 for r in rows:
 file.write( .join(map(str,r)) + \n)

Doh.  Bad choice of names for my file object:

f = file(data,w)
for r in rows:
f.write( .join(map(str,r)) + \n)

You can do it on one line if you want, but I find the above a
little bit clearer.  

-- 
Grant Edwards   grante Yow!  Spreading peanut
  at   butter reminds me of
   visi.comopera!! I wonder why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read/write 2D data from/to file..?

2007-02-11 Thread Vasily Sulatskov
On Feb 12, 6:47 am, mech point [EMAIL PROTECTED] wrote:
 I was able to read the data from file into a two dimensional array
 (lists)

 rows=[map(float,line.split())for line in file(data)]

 but How to write them back into the file.

Using matplotlib it will be:

import pylab
rows = pylab.load('src.dat')
pylab.save(rows, 'dst.dat')



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


Re: How to find all the same words in a text?

2007-02-11 Thread Samuel Karl Peterson
[EMAIL PROTECTED] on 11 Feb 2007 08:16:11 -0800 didst step
forth and proclaim thus:

 More concisely:
 
 import re
 
 pattern = re.compile(r'\b324\b')
 indices = [ match.start() for match in
 pattern.finditer(target_string) ]
 print Indices, indices
 print Count: , len(indices)
 

Thank you, this is educational.  I didn't realize that finditer
returned match objects instead of tuples.

 Cheers,
 Steven
 

-- 
Sam Peterson
skpeterson At nospam ucdavis.edu
if programmers were paid to remove code instead of adding it,
software would be much better -- unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Optimization of Python software: real-time audio controller

2007-02-11 Thread Vasily Sulatskov
Perhaps boosting priorities for time critical threads will help.

I don't know about MacOS but for Win32 something like that helps:

thread = win32api.GetCurrentThread()
win32process.SetThreadPriority(thread,
win32process.THREAD_PRIORITY_TIME_CRITICAL)

current_process = win32process.GetCurrentProcess()
win32process.SetPriorityClass(current_process,
win32process.REALTIME_PRIORITY_CLASS)


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


Re: Help with Optimization of Python software: real-time audio controller

2007-02-11 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 So, for a music-based application where it's crucial to have real-time
 execution of serial writeouts and audio, as well as keeping a
 continual poll on the input from the same portcan this be done
 successfully in Python?  Does using Tkinter have anything to do with
 my timing issues?  Would it benefit me to move over to wxPython
 (something I've been considering doing)?  As for the metronome, should
 I incorporate the metronome thread into the song processing thread,
 since both are dealing with events whose timing is crucial?

I think you can't really do that, not just because of Python but also
as a result of using a multitasking OS that's not especially designed
for real time.  You have to rely on some buffering in the audio
hardware, so you don't have to be sample-accurate with the timings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving PyOpenGl figures as ps

2007-02-11 Thread Vasily Sulatskov
On Feb 12, 3:11 am, Frank [EMAIL PROTECTED] wrote:
 Hi,

 I installed pyopengl (opengl for python) on my linux box and
 everything works fine. But now I want to save the generated images as,
 e.g., ps or eps. How can I do that and how can I adjust the resolution
 (if necessary)? This is probably simple but for some reason I can not
 find out how to do that.

 I appreciate every hint!

Well, that's not that simple. Search the web, there are several
tutorials about PostScipt output.

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


Re: No module named pyExcelerator Error

2007-02-11 Thread Samuel Karl Peterson
susan [EMAIL PROTECTED] on 11 Feb 2007 16:55:35 -0800 didst
step forth and proclaim thus:

 Hi,
 I'm new of Python, and this problem stucked me whole day but can't be
 solved.

[snip]

 anybody can tell me where's wrong please? Thanks in advance!

What are the contents of sys.path from an interactive prompt?  Have
you tried the official windows Python?  Is there a reason you need to
use the cygwin Python?

-- 
Sam Peterson
skpeterson At nospam ucdavis.edu
if programmers were paid to remove code instead of adding it,
software would be much better -- unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


how to store and still search special characters in Python and MySql

2007-02-11 Thread ronrsr
I have an MySQL database called zingers. The structure is:

zid - integer, key, autoincrement
keyword - varchar
citation - text
quotation - text

I am having trouble storing text, as typed in latter two fields.
Special characters and punctuation all seem not to be stored and
retrieved correctly.

Special apostrophes and single quotes from Microsoft Word are causing
a
special problem, even though I have ''ed all 's

perhaps the encoding of the database itself should be different? it
is
currenlty latin_swedish_ci

Input and output is through a browser.

I think my problem may be that I need to encode the string before
saving it in the databse. Can anyone point me in the right direction
here?

here's the error message:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
95: ordinal not in range(128)
  args = ('ascii', update zingers set keywords =
'a;Action;b;Religi... \n \n \n ' where zid = 422, 95, 96, 'ordinal
not
in range(128)')
  encoding = 'ascii'
  end = 96
  object = update zingers set keywords = 'a;Action;b;Religi...
\n
\n \n ' where zid = 422
  reason = 'ordinal not in range(128)'
  start = 95

the characters I am trying to add are startquote and endquote copied
and pasted from Microsoft Word.

Can anyone help me on this?

bests,

-rsr-

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


About getattr()

2007-02-11 Thread Jm lists
Hello,

Since I can write the statement like:

 print os.path.isdir.__doc__
Test whether a path is a directory

Why do I still need the getattr() func as below?

 print getattr(os.path,isdir).__doc__
Test whether a path is a directory

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


standardized us address

2007-02-11 Thread mark

Hi
Is there any python module that will convert address to standard US address
format:
for ex:

314 south chauncey avenue

should be:
314 s chauncey ave


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

Re: Saving PyOpenGl figures as ps

2007-02-11 Thread Mike C. Fletcher
Frank wrote:
 Hi,

 I installed pyopengl (opengl for python) on my linux box and
 everything works fine. But now I want to save the generated images as,
 e.g., ps or eps. How can I do that and how can I adjust the resolution
 (if necessary)? This is probably simple but for some reason I can not
 find out how to do that.

 I appreciate every hint!

 Thanks, Frank
   
Hi Frank,

Take a look at the demos in OpenGL, particularly:

OpenGL-ctypes/OpenGL/Demo/GLUT/tom/conesave.py

which is a little GLUT application that renders into a GLUT windows and 
then allows you to save it. That's raster operation though (i.e. 
produces a PNG or JPG).  Raster operations can only save a portion of 
the screen as rendered, so if you want a higher resolution image you 
need to make a larger window.  If you want to get more advanced you can 
try using an off-screen buffer (pbuffer or MESA) for the rendering, 
which may (depending on implementation) allow for higher resolutions.

If you want a true vector graphic (PS, EPS) you'll need to use something 
like GL2PS.

http://www.geuz.org/gl2ps/

HTH,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


  1   2   >