Re: How to create linked list automatically

2005-12-19 Thread Shahriar Shamil Uulu
Thank you very much to all,
we have figured it out, how to make it work,
w=[]
for i in range(10):
 node=Node(i)
 w.append(node)

for i in range(10):
a=w[i]
if i+1>9:
   b=w[9]
   a.next=b
else:
   b=w[i+1]
   a.next=b

we have runned in this way

Dave Hansen wrote:
> On Mon, 19 Dec 2005 20:51:39 + in comp.lang.python, Simon Brunning
> <[EMAIL PROTECTED]> wrote:
>
> >I haven't the time (or inclination) to sort out all your problems
> >here, but one thing jumps out at me:
> >
> >On 12/19/05, Shahriar Shamil Uulu <[EMAIL PROTECTED]> wrote:
> >> class Node:
> >> def __init__(self,name=None,next=None):
> >> self.name=name
> >> self.next=next
> >>
> >> def __str__(self):
> >> return str(self.name)
> >
> >Your Node classes str() prints the instances self.name attribute,
> >which is set by an optional named argument on the initialiser...
> >
> >> w=[]
> >> for i in range(10):
> >> node=Node(i)
> >
> >... but you aren't providing this argument when you build your Node 
> >objects...
>
> Actually, he is.  Look closer.
>
> As /F pointed out, his problem is in the linking.  By making a small
> modification to his code, I was able to get it to print
>
>1 2 3 4 5 6 7 8 9 None
>
> As (I assume) was expected.  I'd post the code, but the margin is too
> small to contain it...  Besides, I'd like the OP to figure it out
> himself.
>
> Regards,
> -=Dave
> 
> -- 
> Change is inevitable, progress is not.

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


Weird memory consumption problem.

2005-12-19 Thread Bo Peng
Dear list,

I spent the last 12 hours in catching this bug (?) and what I found out 
is very difficult to explain:

Basically, I need to call a user-provided function many times, with a 
tuple as parameter.

C/C++ side: (class A, constructed using a python function m_func)

// create in the constructor, used to hold the parameter
m_numArray = PyTuple_New(m_len);
...

   // member function, will be called many times
   void fun(){

// set the tuple
for( j=0; jhttp://mail.python.org/mailman/listinfo/python-list


Re: valide html - Encoding/Decoding

2005-12-19 Thread gene tani

rabby wrote:
> hello world!
> how to get the string "/ + ( ) + \ + [ ] + : + äöü" converted into
> valide html.
> "...".decode("html") does not run :(
> thank you for help

the a-umlaut <=> ä and other translations are in htmlentitydefs,
like Dennis said.

cgi.escape will give you < & "e; etc, xml.sax.saxutils has
parallel functions
http://docs.python.org/lib/module-xml.sax.saxutils.html

of the RFC 1738 encodings you need to do for chars in URLs, i believe
"~" is the only one you commonly have to worry about so rewrite as
"%7E" manually...

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


Re: adding vectors

2005-12-19 Thread Terry Hancock
On Mon, 19 Dec 2005 22:06:31 -0500
Andy Leszczynski <[EMAIL PROTECTED]> wrote:
> Short question: why (1,"abc",0.3)+(2,"def",10.2) !=
> (3,"abcdef",10.5)?
> 
> How to elegantly achieve (3,"abcdef",10.5) as a result of
> addition ...

(a,b,c) is a "tuple", not a "vector".

IMHO, the "elegant" thing to do is to define a vector class
and use it. For convenience, allow a tuple initializer:

V = Vector
a = V(1,"abc",0.3) + V(2,"def",10.2)

Of course, the class "Vector" will have to define math
operators appropriately.  Note that "%" has the correct
precedence to sub for cross-product, and sort of looks like
an X if you squint hard enough ;-).

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: putenv

2005-12-19 Thread Terry Hancock
On Tue, 20 Dec 2005 05:35:48 -
Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2005-12-20, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> wrote:
> > I have csh script that calls a bunch of python programs
> > and I'd like to use env variables as kind of a global
> > variable that I can pass around to the pythong scripts.
> 
> You can't change the environment of the parent process.
> 
> IOW, the python programs can't change the environment of
> the calling csh script (or, by extenstion, the environment
> of subsequent python programs that are called by the csh
> script).

There is an evil trick, however:

Instead of setting the environment directly, have the python
program return csh code to alter the environment the way you
want, then call the python code by "sourcing" its output:

source `my_script.py`

This will cause the csh script to execute the code and set
the variables, which will then be visible to subsequent
Python scripts.

If you don't want your script to alter anything, then you
just return '' and nothing happens, otherwise you return
something like:

"""
setenv VKG1 spam
setenv VKG2 eggs
"""

It's ugly, but it does work -- I have had to use this
before in a production environment.  Well, it's not really
any less advisable than scripting in csh to begin with. ;-)

Cheers,
Terry

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: What is unique about Python?

2005-12-19 Thread Kay Schluehr
gsteff wrote:

> So I'm wondering, what is
> innovative about Python, either in its design or implementation?  Or is
> its magic really just in combining many useful features of prior
> languages in an unusually pleasant way?
>
> Greg

The latter.

http://www.python-in-business.org/ep2005/download.cpy?document=8599

As Guido described in his presentation Python is a decendent of ABC
developed at the university where he studied.

Here is some material about the primary motivations of ABC:

http://homepages.cwi.nl/~steven/abc/language.html

Python seems to proof that eclecticism can be done right. 

Kay

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


UDP socket, need help setting sending port

2005-12-19 Thread Sells, Fred
I'm using MSW XP Pro with Python 2.4 to develop but production will be Linux
with Python 2.3.  (could upgrade to 2.4 if absolutely necessary) I can also
switch to Linux for development if necessary.

I am writing some python to replace proprietary software that talks to a
timeclock via UDP.

The timeclock extracts the sending port from the UDP header and uses that
for all response messages.

I cannot find out how to set the sending port in the header.  Windows XP
appears to set an arbitrary port.  I've been using ethereal to analyze
network traffic and it seems that if I can set the sending port, I should be
OK.

I have been googling various combinations of "python udp ..." for the last
two hours and have not found anything that addresses how to set the sending
port.  I'm guessing that this may be in setsockopt but don't see any
parameters that "click".

Any help would be greatly appreciated.

Fred Sells
fred at adventistcare dott org


---
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: putenv

2005-12-19 Thread Grant Edwards
On 2005-12-20, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Is there a trick to getting putenv/getenv to work?

No.

> I have csh script that calls a bunch of python programs and I'd like to
> use env variables as kind of a global variable that I can pass around
> to the pythong scripts.

You can't change the environment of the parent process.

IOW, the python programs can't change the environment of the
calling csh script (or, by extenstion, the environment of
subsequent python programs that are called by the csh script).

-- 
Grant Edwards
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


putenv

2005-12-19 Thread [EMAIL PROTECTED]
Is there a trick to getting putenv/getenv to work?
I have csh script that calls a bunch of python programs and I'd like to
use env variables as kind of a global variable that I can pass around
to the pythong scripts.

Thanks,
Dave

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


Re: adding vectors

2005-12-19 Thread Paul Rubin
Mike Meyer <[EMAIL PROTECTED]> writes:
> >>> map(operator.add, (1, "abc", 0.3), (2, "def", 10.2))
> [3, 'abcdef', 10.5]
> 
> Not having to do the zip is win. operator.add is a lose. I'm not sure
> either is what I'd call elegant.

Yeah, I didn't bother checking whether you could pass dyadic functions
to map.  Given that you can, I see nothing wrong with lambda x,y: x+y
instead of operator.add, but that's just me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adding vectors

2005-12-19 Thread Alex Martelli
Andy Leszczynski <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> Short question: why (1,"abc",0.3)+(2,"def",10.2) != (3,"abcdef",10.5)?

Because '+' applied to sequences means to concatenate them -- a more
frequent need than "element by element addition" (which I notice you
would NOT want to apply to strings, only to sequences for which it
happens to be convenient for your specific app...!-).

> How to elegantly achieve (3,"abcdef",10.5) as a result of addition ...

If you mean "by using operator + on tuples", no way.  If you're not hung
up on syntax, e.g.

def elemadd(t1, t2):
  return tuple(i1+i2 for i1, i2 in zip(t1, t2))

or any of several other ways.


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


Re: step argument for count

2005-12-19 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> Does anyone know why a step argument was left off of count? There must
> be something that I am missing in why this is the case. For example, I
> read that the negative start and step were left off of islice because
> iterables can be of "infinite length" so you won't know apriori where
> the end is. But how would you be using count in a way that *couldn't*
> use a step argument?

I think it's a reasonable extra-feature request for Python 2.5 -- you
should post it as such to sourceforge.


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


Re: adding vectors

2005-12-19 Thread Mike Meyer
Paul Rubin  writes:

> Andy Leszczynski <[EMAIL PROTECTED]> writes:
>> Short question: why (1,"abc",0.3)+(2,"def",10.2) != (3,"abcdef",10.5)?
>> How to elegantly achieve (3,"abcdef",10.5) as a result of addition ...
> tuple([(a+b) for a,b in zip((1,"abc",0.3),(2,"def",10.2))])

>>> map(operator.add, (1, "abc", 0.3), (2, "def", 10.2))
[3, 'abcdef', 10.5]

Not having to do the zip is win. operator.add is a lose. I'm not sure
either is what I'd call elegant.

As for the "why" question, it's because the current behavior is more
generally useful. You can always concatenate two lists to get a longer
lists. The elements in a list don't have to support add, so using "+"
to denote elementwise addition is sorta pointless.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE; Try python beta

2005-12-19 Thread Mike Meyer
[EMAIL PROTECTED] writes:
> >> It does work for me in FireFox and Netscape:
> >> >>> 1+1
> >> 2
> Mike> Also Safari, Mozilla and Netscape. 
> I tried 4+3 in Safari and got

I've been futzing with it all evening. Various things I've done have
broken it in strange ways. It's working now (or was - someone may have
found a way to break it).

I'm tempted to put in a hook to log expressions and let people play
them back - it's kind of amusing.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


step argument for count

2005-12-19 Thread smichr
Does anyone know why a step argument was left off of count? There must
be something that I am missing in why this is the case. For example, I
read that the negative start and step were left off of islice because
iterables can be of "infinite length" so you won't know apriori where
the end is. But how would you be using count in a way that *couldn't*
use a step argument?

/c

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


Re: ANNOUNCE; Try python beta

2005-12-19 Thread Mike Meyer
"David  Wahler" <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>> The previous version was in a jail, which is why I didn't want it
>> generally announced. The logs made amusing reading. I like Gerhard's
>> idea of removing __import__, and have done that.
> Oh, you have, eh? Are you absolutely sure? Try running "grep 'all your
> base' log".

Yup, removing it securely is more trouble than it's worth. Which is
why this is running in a sandbox inside a jail - I knew that securing
Python was a probably impossible.

I put __import__ back, and even imported os just to save you some
time. I also put the expression that will get do the equivalent of "ls
-R /" up for anyone to read.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adding vectors

2005-12-19 Thread Paul Rubin
Andy Leszczynski <[EMAIL PROTECTED]> writes:
> Short question: why (1,"abc",0.3)+(2,"def",10.2) != (3,"abcdef",10.5)?
> How to elegantly achieve (3,"abcdef",10.5) as a result of addition ...

tuple([(a+b) for a,b in zip((1,"abc",0.3),(2,"def",10.2))])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to SetFocus to an activex control when a dialog is prompted?

2005-12-19 Thread Haobing
Got it!!
Thanks for everybody!!

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


adding vectors

2005-12-19 Thread Andy Leszczynski
Hi,

Short question: why (1,"abc",0.3)+(2,"def",10.2) != (3,"abcdef",10.5)?

How to elegantly achieve (3,"abcdef",10.5) as a result of addition ...


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


synchronized enumerate

2005-12-19 Thread smichr
I see that there is a thread of a similar topic that was posted
recently ( enumerate with a start index  ) but thought I would start a
new thread since what I am suggesting is a little different.

I posted a very similar item to python-dev, but they said to post it
here. Tutor also said that if anything is to be considered as PEP
worthy, it should be run through here first.  So...here goes.

Whenever I use enumerate, I am doing so because I will use the index to
access some other element in the list (the previous or next, usually)
while also looking at the element that is returned from enumerate.
Several times, however, in the development phase of the work, I end up
sending a subset of the list at hand and then get bitten by the fact
that the indices returned by enumerate are not the indices of the
original list, they are the indices of the slice that I sent. e.g. in
the following, "0" is the first index but I wanted it to be "3"

###
>>> start=3; count=5
>>> for i, x in enumerate(range(10)[start:start+count]):
...  print i, x
...
0 3
1 4
2 5
3 6
4 7
>>>
###

There is a "flexible enumerate()" in the ASPN Cookbook that shows how
to return an arbitrary integer starting point for an iterable,

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307582

but I would vote against that since enumerate is suppose to give
indices of the original list.  What I would like to see supported is
the concept that enumerate should give indices and items from an
iterable--it does right now--but it should also allow you to access a
different portion of the original list and *still* give the indices of
that slice.  What I propose is an optional slice argument that would be
used to return the sliced indices and items:

def enum(l, slc=None):
if slc==None: #the usual ennumerate
for i, dat in enumerate(l):
yield i, dat
else:
if type(slc)<>slice:
raise TypeError, "slc must be a valid slice"
start, step = slc.start, slc.step
#
# we need actual values for start and step, so check for None
# and supply defaults
#
if step==None:step=1
if start==None:
if step>0:
start=0
else:
start=-1
for i, dat in enumerate(l[slc]):
j = i*step+start
if j<0: j+=len(l) #always give positive indices
yield j, dat
###
>>> for i, x in enum(range(10), slice(start, start+count)):
...  print i, x
...
3 3
4 4
5 5
6 6
7 7
>>> for i, j in enum(range(10), slice(None,None,-3)):
...  print i,j
...
9 9
6 6
3 3
0 0
>>>
###

An advantage to processing the iteratable with a slice argument is that
then the slice information is given only once and it can do 2 things:
slice the original iterable and provide the synchronized indices.

NOTE: the same thing that I am proposing could also be done with
xrange, islice and izip, but it's more ackward and you have to supply
the same information in two places:

###
aList = range(10)
>>> start=2;stop=2+5
>>> for i,j in itertools.izip(xrange(start, stop), itertools.islice(range(10), 
>>> start, stop)):
... print i,j
...
2 2
3 3
4 4
5 5
6 6
>>>
###

It just seems that a function which was suppose to simplify accessing
indices and elements of an iterable should easily allow you to look at
a slice of the iterable and get the same synchronized inidces.

/c

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Scott David Daniels
Alex Martelli wrote:
> Scott David Daniels <[EMAIL PROTECTED]> wrote:
>> If the data you store and update is sufficiently valuable to your
>> enterprise, picking a database may be vital.  Transactions guarantee
>> every update either happens or not, and infrastructure is provided
>> for you to be able to backup and restore the data you've obtained.
> 
> A good point, but there are others.  If the data is valuable, there WILL
> be requests from parts of the enterprise to use that data in other ways
> that were originally not anticipated.  If you keep the data in a
> relational DB with any kind of sensible schema, then the data IS
> reusable, including in impromptu exploratory ways from interactive
> prompts of many kinds -- you don't necessarily need "programmers" to
> enable such reuse.
We are in violent agreement here.  My contention is that you need a
_real_ relational database here, not that you need to pick a vendor.
MySQL vs. Pick vs. ... should be shut out early.  A truly relational DB
has value, picking a particular one early does not.  The attributes I
describe are available from any reputable relational DB vendor, and make
no mistake, PostgreSQL is what I consider a vendor -- a provider of a
fully thought-out and implemented solution.

 > ... maintaining portability among different databases may well be a
 > great choice, even when it requires the overhead of a "database
 > independence layer".
Yup.  I think you should choose a vendor, but not in the sense of buying
lock-in; in the sense of accepting a data model.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Existing FTP server code?

2005-12-19 Thread [EMAIL PROTECTED]
Hi, I'm writing a program that needs to upload files to a server
(probably using FTP), that also needs to be secured and be able to
setup username/password programmatically.

I wonder if there are already well written base code I can work on.

The reason I choose FTP is because it is well known/supported and I
don't need to write much code at all. Any better ideas?


Thank you


===
kychan

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


Re: Existing FTP server code?

2005-12-19 Thread Murtog (sent by Nabble.com)

So you want to upload some files to a FTP Server. This is pretty easy with Python. Give a look at this page: http://docs.python.org/lib/module-ftplib.html

Look for the examples, they should help you a lot.

cheers! =]

Sent from the Python - python-list forum at Nabble.com:
Re: Existing FTP server code?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What is unique about Python?

2005-12-19 Thread Alex Martelli
gsteff <[EMAIL PROTECTED]> wrote:

> The indentation-based syntax seems to be unique

No, you can find it in Haskell too (independently developed), and older
languages such as Occam.


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


Re: What is unique about Python?

2005-12-19 Thread jhujsak
Indeed. I've found that I can code applications with 10-20% of the
amount of code required by other languages and write the code in a
correspondingly shorter period of time. The result is far less brittle,
more functional and far more maintainable. This is code you can come
back to a year later and pick right up with ease. That's not something
I can say for most traditional compiled languages. All of this, of
course, translates directly to much lower lifecycle cost and safer,
more reliable code.

--Jon

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


Re: ANN: DecInt 0.4 and processor specific GMPY binaries

2005-12-19 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> I've also compiled processor-specific binaries of GMPY. I have versions
> for AMD 32-bit processors and Intel Pentium 4 processors. The Pentium 4
> version is approximately 4x faster than the default version of GMPY.
> 
> DecInt and the experimental GMPY binaries are located at
> http://home.comcast.net/~casevh

Cool!  Mind if I point there from the gmpy homepage?  What OSs (as well
as CPUs) do you support with your binary builds?  [[funny, I guess I
also have a comcast.net homepage, being currently a comcast customer,
but I find their internet services so abysmal I wouldn't want to rely on
them... hmmm... mind if I COPY your binaries and make them available for
downloads from the gmpy pages on sourceforge...?]]

Feel free to mail me to discuss this, but avoid the never-working-right
comcast address: aleaxit at the excellent gmail (with a dot and a com)
is a much better way to reach me, whether for gmpy or any other issue...
thanks!


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


Re: mod_python and threads

2005-12-19 Thread grahamd
Depends on what you mean exactly.

If one is on Win32 or using worker mode for Apache, the threads are
actually initially created down at the Apache level as part of a common
pool and are not bound to a specific Python interpreter. That is, two
distinct requests in time could make use of the same thread from the
common pool, but may end up calling into the context of two different
distinct Python interpreters if it happened that the URL namespace is
assigned against different interpreter instances.

The data for each Python interpreter is distinct, but if multiple
requests come in at the same time which map to the same Python
interpreter instance, then multiple threads can be operating within the
context of the same Python interpreter instance. If the two threads can
be accessing the same code/data, then you would obviously need to worry
about threading issues such as locking etc.

Anyway, you may have to be clearer about what you want to know. The
following may or may not also help.

  http://www.dscpl.com.au/articles/modpython-004.html

BTW, there are bugs related to threading in mod_python 3.1.4 and
earlier. Better if you can use mod_python 3.2.5b, which gets rid of the
nastier threading issues.

Graham

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


Re: Writing pins to the RS232

2005-12-19 Thread [EMAIL PROTECTED]
For those looking, I've already used IC's that convert RS232 to TTL,
look up MAX233.  It drops 12 to 5, essentially converting RS232 to TTL
and vice versa.  PyParallel is definitely the way I'll go, however,
this project will be on hold for me for my priorities have been
shifted.  Thanks again for all of your help.

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


Re: ANNOUNCE; Try python beta

2005-12-19 Thread David Wahler
Mike Meyer wrote:
> The previous version was in a jail, which is why I didn't want it
> generally announced. The logs made amusing reading. I like Gerhard's
> idea of removing __import__, and have done that.

Oh, you have, eh? Are you absolutely sure? Try running "grep 'all your
base' log".

-- David

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


mod_python and threads

2005-12-19 Thread skip
I'm just getting started with Myghty and using it under mod_python (also a
new beast for me).  Do I have to worry about threading conflicts between
different mod_python interpreters or are they all independent?

Thx,

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


Re: ANNOUNCE; Try python beta

2005-12-19 Thread skip

>> It does work for me in FireFox and Netscape:
>> >>> 1+1
>> 2

Mike> Also Safari, Mozilla and Netscape. 

I tried 4+3 in Safari and got



500 Internal Server Error

Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator,
 [EMAIL PROTECTED] and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.
More information about this error may be available
in the server error log.

Apache/1.3.26 Server at www.mired.org Port 80


in the terminal just now (9:05 or so CST).

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


Re: How can I load python script into Html ??

2005-12-19 Thread Roger Upole

"Claudio Grondi" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> PatPoul wrote:
>> Yes I register Python script.
>> I see in your exemple that you use file extention pys.
>> That was why my exemple does'nt work.
>>
>> Thanks !
>>
>> Patrick Poulin
>>
>
> In this context I have a question:
>
> How can the registering of the Python scripting engine be easily and 
> completely removed? (i.e. how can I get rid of it when 
> already registered?)
>
> Claudio

Run pyscript.py passing --unregister on the command line.

Roger




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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Alex Martelli
Scott David Daniels <[EMAIL PROTECTED]> wrote:

> Mike Meyer wrote:
> > Benji York <[EMAIL PROTECTED]> writes:
> >> Perhaps it's off-topic for this thread, but I think "picking a
> >> database" is the first mistake most people make.  It's a form of
> >> premature optimization.
> > 
> > For lots of problems, that's true. But not for all of them.
> 
> If the data you store and update is sufficiently valuable to your
> enterprise, picking a database may be vital.  Transactions guarantee
> every update either happens or not, and infrastructure is provided
> for you to be able to backup and restore the data you've obtained.

A good point, but there are others.  If the data is valuable, there WILL
be requests from parts of the enterprise to use that data in other ways
that were originally not anticipated.  If you keep the data in a
relational DB with any kind of sensible schema, then the data IS
reusable, including in impromptu exploratory ways from interactive
prompts of many kinds -- you don't necessarily need "programmers" to
enable such reuse.

Picking ONE database engine may well be premature nevertheless --
perhaps the small amounts of data you have today make SQLite ideal, but
tomorrow there will be many more data, and you'll want PostgreSQL, or
whatever; which is why maintaining portability among different databases
may well be a great choice, even when it requires the overhead of a
"database independence layer".  But being able to rely on a relational
underlying model remains an excellent idea in many cases, even when
minute details of SQL dialects &c require such a layer...


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


Re: ANNOUNCE; Try python beta

2005-12-19 Thread Mike Meyer
Claudio Grondi <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>> Ok, I've given it the interface I want, and made it less of an
>> attractive nuisance.
>> http://www.mired.org/home/mwm/try_python/ is now ready for people to
>> play with. There's no tutorial information on it yet, that's the next
>> thing to do. However, I won't be able to work on it for a while, so if
>> you want to make suggestions about what that should look like, all
>> such suggestions will be given proper consideration.
>>  I suggest it should work like IDLE do and not remain limited to
> evaluating of expressions. One can easily get the impression Python is
> very limited and this is not what can help Python to show its
> strengths.

I thought about that. It's not clear that it's fixable at this
level. If not, it'll be documented.

> By the way:
> The page doesn't work for me in MSIE (I am on a Windows system)
>  >>> 1+1
> SyntaxError: unexpected EOF while parsing (line 1)

Yeah, I know. I poked at it briefly, but couldn't figure out what was
goiing on. MSIE on the Mac doesn't work at all (no AJAT), and I don't
have regular access to a Windows box to try it on.

> It does work for me in FireFox and Netscape:
>  >>> 1+1
> 2

Also Safari, Mozilla and Netscape. If you try it with a browser
without XMLHttpRequest, it'll suggest them.

> but in Opera I get:
>  >>> 1+1
> 祓瑮硡牅潲㩲甠敮灸捥整⁤佅⁆桷汩⁥慰獲湩⁧氨湩⁥⤱>>>

Yup, I've seen that one as well. I have *no* idea what Opera thinks
it's doing. Adding a charset to the content-type didn't solve the
problem. I checked opera's web site, and couldn't find a page for web
developers.

I've added a note about these problems.

> Maybe the subject of your posting should be changed to:
> Try my skills in processing form requests from different Internet browser?

Actually, it's doing form processing. It's doing XMLHttpRequests.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: show in GUI stdout of a command

2005-12-19 Thread Noah
Try Pexpect for running your command interactively
http://pexpect.sourceforge.net/

For example, if you wanted to run the "top" command you could
use a script like below. This updates the output every 5 seconds.
You can easily adjust the timeout.
---
import pexpect
def progress_callback (d):
"""This callback updates child command output.
This is used when running external commands
with pexpect.run.The callback is given a dictionary
of the local variables in pexpect.run. This explains
the syntax of d['child'].before, which you would
otherwise simple enter as child.before.
"""
print d['child'].before

pexpect.run("top", timeout=5,
events={pexpect.TIMEOUT:progress_callback})
---

Next you would then have to add that whole
GUI thing yourself :-)

You can also try using pipes (popen and friends), but the
output will be block buffered, so it would come out chunky
and not in real time. There is no way to change the child's
buffering from block buffering to line buffering without using
a pseudo-TTY.

Yours,
Noah

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


Re: ANNOUNCE; Try python beta

2005-12-19 Thread Mike Meyer
"Lonnie Princehouse" <[EMAIL PROTECTED]> writes:
> Pretty neat =)
> But aren't you concerned about security?  Letting anybody execute
> arbitrary Python expressions (and therefore also arbitrary system
> commands?!) on your box --- even from within a FreeBSD jail --- seems a
> bit dangerous.

What's there is actually more restricted than a FreeBSD jail. This one
has been tightened down to a statically linked Python interpreter, the
statically linked cgi program which does nothing but launch the Python
interpreter with the right arguments, and python library files. I've
even removed most of the latter that aren't used by the python
script. So yeah - you can run arbitrary system commands, except there
shouldn't be any.

The previous version was in a jail, which is why I didn't want it
generally announced. The logs made amusing reading. I like Gerhard's
idea of removing __import__, and have done that.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing text

2005-12-19 Thread Noah
sicvic wrote:
> I was wondering if theres a way where python can read through the lines
> of a text file searching for a key phrase then writing that line and
> all lines following it up to a certain point, such as until it sees a
> string of "-"
>...
> Thanks,
> Victor

You did not specify the "key phrase" that you are looking for, so for
the sake
of this example I will assume that it is "key phrase".
I assume that you don't want "key phrase" or "-" to
be returned
as part of your match, so we use minimal group matching (.*?)
You also want your regular expression to use the re.DOTALL flag because
this
is how you match across multiple lines. The simplest way to set this
flag is
to simply put it at the front of your regular expression using the (?s)
notation.

This gives you something like this:
print re.findall ("(?s)key phrase(.*?)-",
your_string_to_search) [0]

So what that basically says is:
1. Match multiline -- that is, match across lines (?s)
2. match "key phrase"
3. Capture the group matching everything (?.*)
4. Match "-"
5. Print the first match in the list [0]

Yours,
Noah

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


ANN: DecInt 0.4 and processor specific GMPY binaries

2005-12-19 Thread casevh
I've released a new version of DecInt that fixes a bug in
multiplication. Anyone using version 0.3b or earlier should upgrade.

DecInt implements fast arithmetic on large decimal integers. For
example, it can calculate the decimal representation of the largest
Mersenne prime, all 7816230 digits, in just a few seconds.

I've also compiled processor-specific binaries of GMPY. I have versions
for AMD 32-bit processors and Intel Pentium 4 processors. The Pentium 4
version is approximately 4x faster than the default version of GMPY.

DecInt and the experimental GMPY binaries are located at
http://home.comcast.net/~casevh

Enjoy,

casevh

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


Re: ANNOUNCE; Try python beta

2005-12-19 Thread Devan L
Mike Meyer wrote:
> Ok, I've given it the interface I want, and made it less of an
> attractive nuisance.
>
> http://www.mired.org/home/mwm/try_python/ is now ready for people to
> play with. There's no tutorial information on it yet, that's the next
> thing to do. However, I won't be able to work on it for a while, so if
> you want to make suggestions about what that should look like, all
> such suggestions will be given proper consideration.
>
I was bored so I wrote some code that takes input one line at a time
and spits out the a tuple representing the state and a message to be
echoed. It handles statements on multiple lines, too. So it might be
helpful, since your tutorial doesn't  seem to handle multiple lines or
statements.

You can see it at 

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Scott David Daniels
Mike Meyer wrote:
> Benji York <[EMAIL PROTECTED]> writes:
>> Perhaps it's off-topic for this thread, but I think "picking a
>> database" is the first mistake most people make.  It's a form of
>> premature optimization.
> 
> For lots of problems, that's true. But not for all of them.

If the data you store and update is sufficiently valuable to your
enterprise, picking a database may be vital.  Transactions guarantee
every update either happens or not, and infrastructure is provided
for you to be able to backup and restore the data you've obtained.
If you don't get transaction guarantees, your applications will have
to deal with all kinds of inconsistent data (either by ignoring the
problem or guessing the best answer).

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Dave Benjamin
On Mon, 19 Dec 2005, Paul Rubin wrote:

> "Russell E. Owen" <[EMAIL PROTECTED]> writes:
>> I disagree. Once you've picked a database (not trivial in itself, of
>> course), you typically only have a few options for talking to in in
>> Python. Also, typically either:
>> - One stands out (because others have been abandoned or whatever), so
>> there's an easy answer, or
>
> But none of them stand out, the way the ones in PHP stand out, by
> being included in the standard library.

Well, even with PHP there are several ways to talk to a given database, 
and the library du jour has changed a few times. When I first learned PHP, 
it was pretty standard to use the mysql_* functions (and for another 
database, a set of functions specific to that database). Then, PEAR DB 
came out, which wrapped around these functions and provided some database 
abstraction for portability. This is the direction I went, but I don't 
know many others that followed.

PEAR is distributed with PHP, so it's basically standard, but in the early 
days it wasn't in the library path by default so it didn't stick out as 
the obvious way to talk to a database. Also, ADOdb was around at the time, 
which was (and still is) a pretty popular third-party interface -- maybe 
more popular than PEAR DB. And now there's the new "mysqli" interface, 
which is yet another (this time object-oriented) alternative to the 
mysql_* functions, but once again tied specifically to MySQL.

So, PHP has had the same kind of problems, even with database functions in 
the core. There's more than one way to do it, even with standard 
functions. Same with Java -- should we use the native Type 3 driver or the 
pure-Java Type 4 driver? Scrap JDBC and go with JDO or EJB? Hibernate?

I'm not saying it's necessarily a good thing to have all these options, 
but it's not atypical, especially considering how many database users are 
out there and how different their needs are. In the Java world, commercial 
vendors actually compete to produce better JDBC driver implementations, 
which increases the number of options even more but results in some 
wickedly fast and advanced drivers.

I do agree that the "obsolete" MySQLdb page needs a makeover, or to be 
removed entirely. Also, getting psycopg to install on Windows involves 
hunting around for some magic installers, and I'm afraid to delete them 
off of my hard drive because I'm not sure I'll be able to find them again. 
Perhaps all that is needed is some better organization.

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


Re: What is unique about Python?

2005-12-19 Thread Kevin Yuan
2005/12/20, Murtog (sent by Nabble.com) <[EMAIL PROTECTED]>:

I would say to your teacher that Python is one of the few languagens that are fun to program with. 
It realy is! I have to say it although I have used it for only 3 days! 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: modify a long-running python script while it is running?

2005-12-19 Thread Kevin Yuan
2005/12/20, Mike Meyer <[EMAIL PROTECTED]>:
Benjamin Rutt <[EMAIL PROTECTED]> writes:> I suppose this question could be reformatted as "does CPython read the> entire script file into memory and then close the file before
> executing the script, making it safe for me to modify the script after> I know it has started?"[1]Yes, but (didn't you expect that?) it loads imported files when itfirst executes an import statement for them. Future import statements
will just get a reference to the loaded module, and won't reloadit.I have a silly question: Can  *VERY*  large script cause memory overflow if python load all the entire script file into memory?  

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

Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Paul Rubin
Paul Rubin  writes:
> If the transactions are simple and low-latency, then it can be enough
> to have a single process own the whole database, and have every client
> send all its requests to the db process.

Meant to say: it can be enough to let the clients lock the database,
do their thing quickly, and release the lock.  What I described is of
course how it's usually done with SQL.  Sigh.  Other approaches
include running the whole app in one process (asyncore/twisted),
having a multi-threaded app where one thread owns the db and
serializes requests through Queues, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Paul Rubin
Mike Meyer <[EMAIL PROTECTED]> writes:
> What makes me think "I need a database" is a requirement that says
> "multiple simultaneous writers". 

I'd go a little further and say "multiple simultaneous writers doing
multi-step transactions with steps that can have high latency",
e.g. transactions that have to wait for user input while the
transaction is in progress.

> Yes, it's possible to deal with the data locking and the like on
> your own - but this tends to be system-dependent, and hard to get
> right except in the simple cases.

If the transactions are simple and low-latency, then it can be enough
to have a single process own the whole database, and have every client
send all its requests to the db process.

> If your web clients can write data, then you've got multiple
> simultaneous writers - which means you probably want a database. Of
> course, people like to build web apps that don't write data on top of
> relational databases, which I think are well deserving of your rant.

It's been a long-time source of puzzlement to me why so many web sites
are so slow, and RDBMS overhead is an obvious candidate.  So the rant
seems appropriate even in the case of web apps where clients can cause
db updates.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE; Try python beta

2005-12-19 Thread Gerhard Häring
Lonnie Princehouse wrote:
> Pretty neat =)
> 
> But aren't you concerned about security?  Letting anybody execute
> arbitrary Python expressions (and therefore also arbitrary system
> commands?!) on your box --- even from within a FreeBSD jail --- seems a
> bit dangerous.

I found out about the FreeBSD jail myself, too ;-)

Removing __import__ from the builtins would make such detective work 
much harder, though ;-)

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


Re: Double-Ended Heaps

2005-12-19 Thread Scott David Daniels
Bryan Olson wrote:
> Scott David Daniels wrote:
>> I've just put together a Double-Ended Heap package.
>> Of course I'd love comments.
>>
>>http://members.dsl-only.net/~daniels/deheap.html
> 
> I think there's a typo in:
> 
> Note that any change to the contents of a DeHeap (and
> therefore a DeHeap2) any re-arrange the indices of a
> number of entries in the DeHeap.
> 
> A useful Python class will follow Python convention, where
> relevant convention exists. In this case that means optionally
> passing the ordering relation; look at sort() and sorted().
> 
> Adopting the convention will raises another issue: distinct
> objects can compare as equal, so the DeHeap2 operations that
> find items by value will be at least under-defined, and maybe
> even broken. There are several ways to solve the problem, and
> I don't know of Python convention as to which to choose.
> 
> 
OK, I've a new version out there.

deheap.deheap(iterable=(), key=None, sequence=False)

is a factory function making an appropriate instance.
The testing is not all that thorough on the sequence=True
classes (where even pop can use an index), but I suspect it
all works (famous last words).

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE; Try python beta

2005-12-19 Thread Claudio Grondi
Mike Meyer wrote:
> Ok, I've given it the interface I want, and made it less of an
> attractive nuisance.
> 
> http://www.mired.org/home/mwm/try_python/ is now ready for people to
> play with. There's no tutorial information on it yet, that's the next
> thing to do. However, I won't be able to work on it for a while, so if
> you want to make suggestions about what that should look like, all
> such suggestions will be given proper consideration.
> 
> >> 1+1
SyntaxError: unexpected EOF while parsing (line 1)

It does work for me in FireFox and Netscape:
 >>> 1+1
2

but in Opera I get:
 >>> 1+1
祓瑮硡牅潲㩲甠敮灸捥整⁤佅⁆桷汩⁥慰獲湩⁧氨湩⁥⤱>>>


I am most curious about the last one with no idea how it comes?

Maybe the subject of your posting should be changed to:

Try my skills in processing form requests from different Internet browser?

Claudio

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

Re: ANNOUNCE; Try python beta

2005-12-19 Thread Lonnie Princehouse
Pretty neat =)

But aren't you concerned about security?  Letting anybody execute
arbitrary Python expressions (and therefore also arbitrary system
commands?!) on your box --- even from within a FreeBSD jail --- seems a
bit dangerous.

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


Re: Parsing text

2005-12-19 Thread Peter Hansen
sicvic wrote:
> I was wondering if theres a way where python can read through the lines
> of a text file searching for a key phrase then writing that line and
> all lines following it up to a certain point, such as until it sees a
> string of "-"
> 
> Right now I can only have python write just the line the key phrase is
> found in.

That's a good start.  Maybe you could post the code that you've already 
got that does this, and people could comment on it and help you along. 
(I'm suggesting that partly because this almost sounds like homework, 
but you'll benefit more by doing it this way than just by having an 
answer handed to you whether this is homework or not.)

-Peter

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


Re: How to get the local mac address?

2005-12-19 Thread Daniel Crespo
> I was looking on how to get MAC address universally (Windows and Linux) and
> found one package that is doing that and more...

> http://libdnet.sourceforge.net/

Thank you for the info too :)

Daniel

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


Re: How can I load python script into Html ??

2005-12-19 Thread Claudio Grondi
PatPoul wrote:
> Yes I register Python script.
> I see in your exemple that you use file extention pys.
> That was why my exemple does'nt work.
> 
> Thanks !
> 
> Patrick Poulin
> 

In this context I have a question:

How can the registering of the Python scripting engine be easily and 
completely removed? (i.e. how can I get rid of it when already registered?)

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


ANNOUNCE; Try python beta

2005-12-19 Thread Mike Meyer
Ok, I've given it the interface I want, and made it less of an
attractive nuisance.

http://www.mired.org/home/mwm/try_python/ is now ready for people to
play with. There's no tutorial information on it yet, that's the next
thing to do. However, I won't be able to work on it for a while, so if
you want to make suggestions about what that should look like, all
such suggestions will be given proper consideration.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Mike Meyer
Benji York <[EMAIL PROTECTED]> writes:
> Russell E. Owen wrote:
>> I disagree. Once you've picked a database (not trivial in itself, of
>> course), you typically only have a few options for talking to in in
>> Python.
> Perhaps it's off-topic for this thread, but I think "picking a
> database" is the first mistake most people make.  It's a form of
> premature optimization.

For lots of problems, that's true. But not for all of them.

> Just like any other component in a system, develop your app without a
> database until you see that you need one, don't just assume you do
> from the beginning.

What makes me think "I need a database" is a requirement that says
"multiple simultaneous writers". Yes, it's possible to deal with the
data locking and the like on your own - but this tends to be
system-dependent, and hard to get right except in the simple
cases. It's also one of the things that databases are *really* good
at. In this case, using a database isn't a performance optimization,
it's a code simplification optimization, sort of like using
Queue.Queue to do threading.

> That's also why I don't see much point to the
> relational-database-centric web frameworks that are all the rage
> today, but I'll save that rant for another day.

If your web clients can write data, then you've got multiple
simultaneous writers - which means you probably want a database. Of
course, people like to build web apps that don't write data on top of
relational databases, which I think are well deserving of your rant.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: modify a long-running python script while it is running?

2005-12-19 Thread Mike Meyer
Benjamin Rutt <[EMAIL PROTECTED]> writes:
> I suppose this question could be reformatted as "does CPython read the
> entire script file into memory and then close the file before
> executing the script, making it safe for me to modify the script after
> I know it has started?"[1]

Yes, but (didn't you expect that?) it loads imported files when it
first executes an import statement for them. Future import statements
will just get a reference to the loaded module, and won't reload
it. So after your application imports all the modules it needs, it
won't refer to the copies on disk again, after which it will be safe
for you to modify the on-disk copies.

Of course, you really ought to be working on a *copy* of the
application sources. When you're happy that your modifications are ok,
copy your development sources into production.

And finally, to force python to reload a module that it's already
loaded, use "reload(modulename)".

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to lock a file in ftp site

2005-12-19 Thread andy
[EMAIL PROTECTED] wrote:

>hi all
>
>am trying to write some information into the file, which is located in
>ftp, and this file can be updated by number of people, but if at all i
>download a file from the ftp to my local machine, update it and then
>upload it back to ftp, and at the same time if some one else downloads
>the same file for the modification, then the data will be overwritten.
>
>so is there a way in Python script where i can lock the file, so that
>no one updates it until i release the lock.
>
>Or is there a way where i can directly update the file from the ftp
>itself, i mean without downloading it to my local machine.
>
>Thanks in advance for the help
>
>regards
>yogi
>
>  
>
I've come across this problem - instead of uploading the file to it's

intended directory, upload it to a temp directory, with a unique name
(say ummddhhmmss where u is username and the rest are
obvious) and then *rename* it to it's correct name in the real
destination directory. Do the move in a try... except block and if it
fails, take evasive action.

In FTP a rename (i.e. move) is usually an atomic action but an upload is
not. You have an unavoidable race condition here trying to lock a file
(even if ftp allowed it) but with the method described above, you can
avoid it, but get the same effect.

Hope that helps!
-andyj

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Benji York
Russell E. Owen wrote:
> I disagree. Once you've picked a database (not trivial in itself, of 
> course), you typically only have a few options for talking to in in 
> Python.

Perhaps it's off-topic for this thread, but I think "picking a database" 
is the first mistake most people make.  It's a form of premature 
optimization.

Just like any other component in a system, develop your app without a 
database until you see that you need one, don't just assume you do from 
the beginning.

I was listening to an interview with Ron Jeffries the other day, and 
when asked what he considers one of his greatest accomplishments (as a 
software developer), he told a story about working on a large 
development project for a system that was going to process large amounts 
of data.

At the beginning of the project he was asked what database they should 
use, he said (something like) "wait until we need one".  During 
development several people asked what database they were going to use, 
he reiterated: "wait until we need one".  After the system went into 
production (without a database) he eventually left the company.  Years 
later he found out that they still hadn't "chosen a database" because 
they had yet to need one.  Sounds like a pretty good application of 
YAGNI to me.  http://xp.c2.com/YouArentGonnaNeedIt.html

That's also why I don't see much point to the 
relational-database-centric web frameworks that are all the rage today, 
but I'll save that rant for another day.
--
Benji
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: attach a pdf file to an email

2005-12-19 Thread [EMAIL PROTECTED]
also the code are useful thanks again

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


Parsing text

2005-12-19 Thread sicvic
I was wondering if theres a way where python can read through the lines
of a text file searching for a key phrase then writing that line and
all lines following it up to a certain point, such as until it sees a
string of "-"

Right now I can only have python write just the line the key phrase is
found in.

Thanks,
Victor

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Paul Rubin
"Russell E. Owen" <[EMAIL PROTECTED]> writes:
> I disagree. Once you've picked a database (not trivial in itself, of 
> course), you typically only have a few options for talking to in in 
> Python. Also, typically either:
> - One stands out (because others have been abandoned or whatever), so 
> there's an easy answer, or

But none of them stand out, the way the ones in PHP stand out, by
being included in the standard library.

> - They all work about the same, so even if you decide to switch for some 
> reason it makes little difference.

You should not even have to spend one millisecond of your attention
thinking about it then.

With Python's web template systems, there's a real set of distinct
ones and it's maybe still too early to say there's an easy answer.
Hopefully there will eventually be one.

With db modules, if there's an easy answer, then I can't understand
why that easy answer isn't incorporated into the stdlib so people can
stop having to research it.  If there's no easy answer, then maybe the
dbapi standardization process hasn't worked so well after all.
-- 
http://mail.python.org/mailman/listinfo/python-list


modify a long-running python script while it is running?

2005-12-19 Thread Benjamin Rutt
I often execute a long-running python script which is a "driver" for
my application; it may run for several hours on a large input.

Under CPython, is it safe for me to modify the Python script and run
it under some smaller inputs for test purposes, while the long-running
script is still running?  It seems safe to do so, but I want to be
sure.  I know, for example, that #!/bin/sh on my system is not safe in
this regard.

I suppose this question could be reformatted as "does CPython read the
entire script file into memory and then close the file before
executing the script, making it safe for me to modify the script after
I know it has started?"[1]

Thank you,

Footnotes: 
[1] how would I know that it is started?  For example, at least one
print statement I am expecting has been executed.
-- 
Benjamin Rutt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> 
wrote:

>"Ben Sizer" <[EMAIL PROTECTED]> writes:
>> I see what you mean, but unfortunately I think there is a lot more
>> fuzziness than that. If the separate parts were clearly delineated
>> things would be a lot better. I look to the Database API Specification
>> as a great example of how this could (should?) be done, allowing for
>> easy interchangeability while still providing a well-documented
>> standard
>
>Constant queries on c.l.python for "Which DB module should I use"
>would indicate that having a standard and to many choices isn't really
>better than having no standard and to many choices.

I disagree. Once you've picked a database (not trivial in itself, of 
course), you typically only have a few options for talking to in in 
Python. Also, typically either:
- One stands out (because others have been abandoned or whatever), so 
there's an easy answer, or
- They all work about the same, so even if you decide to switch for some 
reason it makes little difference.

SQLObject breaks that mold, but for excellent reasons. It's nice to 
start from a standard and then maybe somebody figures out a really nifty 
way to do things. (I haven't used SQLObject yet, but I plan to try it 
out when things calm down a bit).

If we had a standard basic web framework or a standard template language 
it would really help (more folks using it, more folks who can help folks 
learning it, better documentation, more focused development). Something 
better might come along, and then it'd be easier to evaluate and more 
appreciated.

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Paul Rubin  wrote:

>[EMAIL PROTECTED] (Alex Martelli) writes:
>> To put it another way: one reason I love Python is that I strongly
>> subscribe to the idea that there should preferably be only one obvious
>> way to do something.  Unfortunately, this principle is very badly broken
>> by the multiplicity of Python web frameworks.
>
>This also has to be a big part of why PHP is kicking the pants off of
>Python for popularity in web development.

I agree. It's sad to see such a terrible language as PHP so popular, and 
such a complicated mess in python, my language of choice.

I love python and am lucky enough to be able to do almost all my coding 
in it. Yet even I use PHP to serve a database. I loathe PHP, but:
- it came preinstalled on my system (MacOS X 10.3.x).
- I found a nice simple intro to it (a quickstart guide, which taught me 
all I needed to know for my simple needs).
- I started out by looking at the choices in python. Of course. I read 
the shootout. I asked for help. But the results were utterly 
overwhelming.

I wanted (and I am guessing this isn't too far off for most users -- at 
least most non-web-gurus) a framework that was:
- Well designed, robust, "finished" (i.e. not alpha).
- Easy to use, especially for simple, basic tasks. (And not a toy, of 
course -- powerful enough to handle reasonable traffic and tasks.)
- Easy to install.
- Well documented, with a good introduction or tutorial.
- Likely to be around for awhile. The plethora of options on Python do 
NOT inspire confidence in that area.

Some choice is good -- especially if the choices solve obviously 
different problems. But too much choice is paralyzing and fragments the 
community.

Anyway, thanks for holding this discussion. Django and TurboGears were 
both new to me. I hope something finally gets popular enough to be worth 
betting on.

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


Re: What is unique about Python?

2005-12-19 Thread Murtog (sent by Nabble.com)

I would say to your teacher that Python is one of the few languagens that are fun to program with. 

Cheers =]

Sent from the Python - python-list forum at Nabble.com:
Re: What is unique about Python?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: attach a pdf file to an email

2005-12-19 Thread [EMAIL PROTECTED]
Thanks
I think I should use MIMEBase for any file.

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


Re: Enumeration idioms: Values from different enumerations

2005-12-19 Thread Ben Finney
[EMAIL PROTECTED] writes:
> Ben Finney wrote:
>> Is there some behaviour other than "evaluate to False" or "raise an
>> exception", that could indicate "not comparable"?
>
> Yes: return NotImplemented.  Note that the == operator automagically
> returns False in this case.
>
> >>> "spam".__eq__("spam")
> True
> >>> "spam".__eq__("ham")
> False
> >>> "spam".__eq__(23)
> NotImplemented
>
> This way, the user could explicitly call __eq__ and check for
> NotImplemented if he desires the exceptional behavior.

Thanks, I was unaware of the standard usage of NotImplemented. That
seems like a sensible solution.

http://docs.python.org/ref/types.html#l2h-29>

-- 
 \"My doctor told me to stop having intimate dinners for four. |
  `\Unless there are three other people."  -- Orson Welles |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is unique about Python?

2005-12-19 Thread James
>> The indentation-based syntax seems to be unique

I think Haskell was there first. As well as ABC, one of Python's
precursors.

Python is a pragmatic language, just like C (I wish I could say that
about Java). It does not necessarily innovate but incorporates things
known to work elsewhere. C and Java have not done anything particularly
unique either. They are included in curricula by their popularity.
Isn't that a good enough argument?

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


Re: understanding mod_python

2005-12-19 Thread grahamd

PyPK wrote:
> Hi I'm trying to learn mod python and need some one to explain how to
> do http redirection(302) with an example code

Have you read the documentation?

Specifically, check out the function mod_python.util.redirect():

  http://www.modpython.org/live/current/doc-html/pyapi-util-funcs.html

Mod_python questions are also perhaps better directed at the mod_python
users mailing list. Details of mailing list on the mod_python home
page:

  http://www.modpython.org

Graham

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Luis M. Gonzalez
Sorry for the interruption, but...
Has anyone tried KARRIGELL??

I find hard to believe there is any easier python framework than this
one.
It's incredibly flexible, very fun, very powerful and with an almost
flat learning curve.

Go check it out (NOW!)
http://karrigell.sourceforge.net/

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


Re: How to create linked list automatically

2005-12-19 Thread Dave Hansen
On Mon, 19 Dec 2005 20:51:39 + in comp.lang.python, Simon Brunning
<[EMAIL PROTECTED]> wrote:

>I haven't the time (or inclination) to sort out all your problems
>here, but one thing jumps out at me:
>
>On 12/19/05, Shahriar Shamil Uulu <[EMAIL PROTECTED]> wrote:
>> class Node:
>> def __init__(self,name=None,next=None):
>> self.name=name
>> self.next=next
>>
>> def __str__(self):
>> return str(self.name)
>
>Your Node classes str() prints the instances self.name attribute,
>which is set by an optional named argument on the initialiser...
>
>> w=[]
>> for i in range(10):
>> node=Node(i)
>
>... but you aren't providing this argument when you build your Node objects...

Actually, he is.  Look closer.

As /F pointed out, his problem is in the linking.  By making a small
modification to his code, I was able to get it to print 

   1 2 3 4 5 6 7 8 9 None

As (I assume) was expected.  I'd post the code, but the margin is too
small to contain it...  Besides, I'd like the OP to figure it out
himself.

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Merging Subway and TurboGears

2005-12-19 Thread Jan Niklas Fingerle
[EMAIL PROTECTED] wrote:
> My real worries are the controller styles (functions vs classes) and

You can wrap those quite easily, but ...

> the templating language (Cheetah vs Kid). Those will be points of

... how should the user base of one migrate to the other? I depend on
(as far as "depend" might go) the Kid funtionality (i.e. importing
ElementTree-s as sub-trees, and ElementTree is part of the heart of my
application logics).

> conflict between the two projects, but I hope we would be able to solve
> them.

Use Kid ;-) Well, no, make it easy to change templating engines,
whatever you ship as included engine. 

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


Announcement: mrquery finds duplicate images

2005-12-19 Thread Edward C. Jones
I have uploaded "mrquery.05.12.19.tgz"' to my web page
"http://members.tripod.com/~edcjones/pycode.html";.

"mrquery" finds the duplicate images in a collection of
images. It implements a variant of the algorithm in
"Fast Multiresolution Image Querying" by Charles E.
Jacobs, Adam Finkelstein and David H. Salesin. Search
for "mrquery.pdf" at Citeseer or on the Internet. The
mrquery algorithm has been implemented elsewhere.
Especially check out "imgSeek" at
"http://imgseek.python-hosting.com/";.

I order to use this program, you need:
   Familiarity with the standard UNIX commands
   Linux (other UNIX systems may work)
   Python 2.4 or later (2.2 or 2.3 may work)
   Experience programming with Python
   To know how to compile C programs (preferably with gcc)

Warning: this program is new, buggy and command-line
oriented.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to create linked list automatically

2005-12-19 Thread Simon Brunning
I haven't the time (or inclination) to sort out all your problems
here, but one thing jumps out at me:

On 12/19/05, Shahriar Shamil Uulu <[EMAIL PROTECTED]> wrote:
> class Node:
> def __init__(self,name=None,next=None):
> self.name=name
> self.next=next
>
> def __str__(self):
> return str(self.name)

Your Node classes str() prints the instances self.name attribute,
which is set by an optional named argument on the initialiser...

> w=[]
> for i in range(10):
> node=Node(i)

... but you aren't providing this argument when you build your Node objects...

> am trying to connect them, but when i try to print the connection i
> got this:
> ===
> >>>
> connection done
> None

So it's hardly surprising that printing your Node objects always prints "None".

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to create linked list automatically

2005-12-19 Thread Fredrik Lundh
"Shahriar Shamil Uulu" wrote:

> w=[]
> for i in range(10):
> node=Node(i)
> w.append(node)
>
> for i in range(10):
> a=w[i]
> if i+1>9:
> b=w[9]
> a.next=b

I'm not sure what you're trying to do here, but I'm quite sure that this
code doesn't do what you think it does.

(hint: i will range from 0 to 9.  what happens when i=0?  what happens
when i=9?)





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


Re: how to lock a file in ftp site

2005-12-19 Thread billie
No, I think you have to manually set this policy directly on the ftp server. 


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


Re: canceling and joining threads

2005-12-19 Thread sir_alex
1) no, i didn't; i'll go and read that function
2) well, the actual situation is: there's the main thread (the
application itself) and then the second thread that i create with
threading.Thread, in which i make some things; in this thread i call
gtk.gdk to update a window with a progress bar...
3) i'm on linux (ubuntu, specifically, but i don't think the distro is
important...)

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


How to create linked list automatically

2005-12-19 Thread Shahriar Shamil Uulu
Hi All,
i have this program,
=
class Node:
def __init__(self,name=None,next=None):
self.name=name
self.next=next

def __str__(self):
return str(self.name)

w=[]
for i in range(10):
node=Node(i)
w.append(node)

for i in range(10):
a=w[i]
if i+1>9:
b=w[9]
a.next=b

print "connection done"

def printNodes(node):
while node:
node=node.next
print node, 

a=w[0]
printNodes(a)

i want to create 10 node objects and i want to connect them to each 
other as linked list, so i have created two loops in first one iam 
creating 10 objects and inserting them to list and in the second i 
am trying to connect them, but when i try to print the connection i 
got this:
===
>>> 
connection done
None
>>> 
can anybody tell me how to overcome this

2. is there any way to create objects something like this 
for i in range(10):
node.i=Node(i) # some thing like node1=Node(1) etc.

Please help me with this.



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


Re: Testing the availability of a module

2005-12-19 Thread Erik Max Francis
Bo Peng wrote:

> Is there a better way than doing
> 
> try:
>import aModule
> except:
>has_aModule = False
> else:
>has_aModule = True
> 
> The main concern here is that loading aModule is unnecessary (and may 
> take time).

Yes.  Specifically catch ImportError in your except clause.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Substance is one of the greatest of our illusions.
   -- Sir Arthur Eddington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is unique about Python?

2005-12-19 Thread Luis M. Gonzalez
Perhaps you should ask yourself why you like Python first, and then
you'll probably have an answer.

I'd say that Python is all about productivity.
You can get more done in less time and with fewer lines of code because
it's more consice, flexible and expressive.
It's also very clear, easy to write and easy to read.
You don't need to compile before running your code, and its
interactivity lets you experiment and try different approaches faster
and better when writing algorithms. This leads to better results and
much faster than with any other traditional language.

Luis

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


Re: Difference between ActivePython and Python.org

2005-12-19 Thread Peter A.Schott
Amen to this one.  Found out this after struggling with no SSL module when
trying to write some secure FTP and HTTPS code.  Downloaded the version from
Python.org and it worked like a champ.

I believe you can get both and have no issues with the install, though.  For my
part, I decided to standardize on the main distribution from Python.org and then
throw on the Win32 extensions as well.  That handles the majority of my needs
and gets around any licensing issues with ActivePython.

-Peter

Neil Hodgson <[EMAIL PROTECTED]> wrote:

> S.Chang:
> 
> > Anyone knows the difference(s) between the Python binaries from 
> > ActiveState and Python.org?
> 
> As well as the differences mentioned by others, ActivePython does
> not include SSL (Secure Socket Layer) and thus HTTPS support. It would 
> be helpful if the ActivePython "What's Included" page listed which parts 
> of the python.org distribution are not included.
> http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/about.html
> 
> Neil
-- 
http://mail.python.org/mailman/listinfo/python-list


this where I am so far !

2005-12-19 Thread Marian
Any one who  have a clue how can I add and  remove records from a list. if the record is dictionary type)   This the program I am working on. I have no idea how can I remove and  add some more courses !   import cPickle, shelve  def  write_file():           CIT101 = ["Academic Computer Skills"]      CIT111 = ["Database Management"]      CIT115 = ["Intro to Computer scince"]      CIT127 = ["ACCESS"]      CIT211 = ["Systems Analysis and Design"]      CIT216 = ["Visual Basic"]      CIT218 = ["Intermediate Visual Basic"]      CIT234 = ["Decision Support Using
 Excel"]      pickle_file = open("pickles1.dat","w")    cPickle.dump(CIT101, pickle_file)      cPickle.dump(CIT111, pickle_file)      cPickle.dump(CIT115, pickle_file)      cPickle.dump(CIT127, pickle_file)      cPickle.dump(CIT211, pickle_file)      cPickle.dump(CIT216, pickle_file)      cPickle.dump(CIT218, pickle_file)      cPickle.dump(CIT234, pickle_file)      print "A file has been created and the required specifications have been added"      pickle_file.closedef read_file():      pickle_file = open("pickles1.dat","r")      CIT101 = cPickle.load(pickle_file)      CIT111 = cPickle.load(pickle_file)      CIT115 = cPickle.load(pickle_file)    &nbs!
 p; CIT127
 = cPickle.load(pickle_file)      CIT211 = cPickle.load(pickle_file)      CIT216 = cPickle.load(pickle_file)      CIT218 = cPickle.load(pickle_file)      CIT234 = cPickle.load(pickle_file)      pickle_file.close()      pickles = shelve.open("pickles2.dat")      pickles["CIT101"] = ["Academic Computer Skills"]      pickles["CIT111"] = ["Database Management"]      pickles["CIT115"] = ["Intro to Computer scince"]      pickles["CIT127"] = ["ACCESS"]      pickles["CIT211"] = ["Systems Analysis and Design"]      pickles["CIT216"] = ["Visual Basic"]      pickles["CIT218"] = ["Intermediate Visual Basic"]      pickles["CIT234"] = ["Decision Support Using Excel"]    pickles.sync() !
   
     for key in pickles.keys():      print key, "-", pickles[key]def dele_file():      word_dele = raw_input("Which record do u want to delete?: ")    if word_dele in picles.keys():      del word_dele    else:      print "There is no such record in file pickles2.dat"            pickles.close()  def display_instructions():      """Display the Main menue"""      print \    """      Main Manue:        1. Exit  &nb!
 sp; 2.
 Create a new file and add specifications    3. (not working)Add more courses to the file    4. Read the file    5. (not working)Delete file  """        # exit the  program    >>> 1 <<<  def over_program():      """Exit the program"""      print "Good Bye!"      def main():      choice = None      display_instructions()                  while choice != 1: 
     choice = raw_input("\nChoice: ")      if choice == "1":      over_program()      break            elif choice == "2":      write_file()    elif choice == "3":      add_to_file()                  elif choice == "4":      read_file()    elif choice == !
 "5": 
     delete_file()            else:      print "\nSorry, but", choice, "isn't a valid choice."main()  raw_input("Press Enter Key to Exit.")    __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

Re: What is unique about Python?

2005-12-19 Thread Kent Johnson
gsteff wrote:
> I'm a computer science student, and have recently been trying to
> convince the professor who teaches the programming language design
> course to consider mentioning scripting languages in the future.  Along
> those lines, I've been trying to think of features of Python, and
> scripting languages in general, that can't be found in older languages,
> and have been having a surprising amount of trouble.  Dynamic typing
> can be found in Smalltalk, the module concept can be found in Ada,
> functional parameters and the dynamic creation of functions can be
> found in Lisp.  The indentation-based syntax seems to be unique, but
> that's not really what I'm looking for.  So I'm wondering, what is
> innovative about Python, either in its design or implementation?  Or is
> its magic really just in combining many useful features of prior
> languages in an unusually pleasant way?

IMO it is the latter. Most of the features of Python can be found in other 
languages. Not 
so many languages have them all. It is the combination of ease of use and power 
that makes 
Python stand out.

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


how to lock a file in ftp site

2005-12-19 Thread muttu2244
hi all

am trying to write some information into the file, which is located in
ftp, and this file can be updated by number of people, but if at all i
download a file from the ftp to my local machine, update it and then
upload it back to ftp, and at the same time if some one else downloads
the same file for the modification, then the data will be overwritten.

so is there a way in Python script where i can lock the file, so that
no one updates it until i release the lock.

Or is there a way where i can directly update the file from the ftp
itself, i mean without downloading it to my local machine.

Thanks in advance for the help

regards
yogi

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


Re: Wingide is a beautiful application

2005-12-19 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
 ...
> I get the feeling that a ot of people working with heavy IDEs don't
> realize how capable vim/emacs are, so I'll give a brief rundown of what
> my Vim environment does for me.  (I do Python web development)--if you
> don't like the Vi keybindings, the Cream package is Vim that behaves
> like a regular modeless editor but with all of vim's power (and a nice
> embedded Python interpreter for writing extensions):
> 
> 1. Python syntax checking: as I'm typing along, if I input a syntax
> error then the line is immediately highlighted in red.  Useful for
> catching brainos like:
> if a=1:
> (which will highlight in red when I hit enter, point out that I need ==
> instead of =).

What do you use to do this?  Cream doesn't seem to do this oob.


> 2. Normal tag-jump stuff: Ctrl-click on a function/method call (or
> class or whatever) will jump to the function/method/class definition
> (Ctrl-T works as well if you don't like clicking).  It keeps a stack of
> visited files so you can drill down through your call stack and then
> pop back up to where you came from.

Do you set up ctags for this?  I get error messages "E433: No tags file" 
and "E426: tag not found: xxx" when I Ctrl-click on a method call.


> 3. Python class browsing stuff: A Class menu shows the parent and child
> classes of the one you're currently in, and all the methods of the
> current class; selecting any of the above jumps to the appropriate file
> and line.

Is this the Tag List?


> 4. Interactive documentation stuff: When I type an open-paren, it looks
> to see what the prior keyword is and displays help for it in the status
> line (preferring Python documentation, then docstrings, then comments
> before the function/method/class definition).  Even if there's no
> help/comments, it'll show the arguments that the function takes.  So
> if, say, I type:
> 
> cmp(
> 
> then the status line displays:
> 
> cmp(x, y) Compare the two objects X and Y and return an integer
> according to ...
> 
> If I hit F1 it'll show the full help text.  Often the arguments are
> enough, and I find the status-line display a lot less intrusive than
> many on-the-fly help systems I've seen.

This stuff doesn't happen either.  How is it set up?


> 5. A client menu selects which client I want to work in (so, say, I get
> a bug report for Client A, I select them from the menu).  The Class
> menu and other functions respect this (if I'm in the generic Company
> class, the Class menu will list Client A's Company subclass before the
> subclasses of other companies; if I jump to the Company definition,
> it'll go to Company A's client-specific version).  It also restarts
> development httpd servers on the current machine running with conf
> files appropriate to that client.
 ...

Where is this "client menu"?  How is it set up?

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I load python script into Html ??

2005-12-19 Thread PatPoul
Yes I register Python script.
I see in your exemple that you use file extention pys.
That was why my exemple does'nt work.

Thanks !

Patrick Poulin

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


understanding mod_python

2005-12-19 Thread PyPK
Hi I'm trying to learn mod python and need some one to explain how to
do http redirection(302) with an example code

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


show in GUI stdout of a command

2005-12-19 Thread twigster
Hi,

I need to display in real time the output of a command line tool in a 
GUI written so far with Tkinter and Pmw. I've got a command line tool 
that I want to integrate to a GUI. The parameters are set using the GUI 
and a button executes the command. The calc is long so I need to see how 
fast it goes. This is given by the stdout...

any idea how to do this?

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


valide html - Encoding/Decoding

2005-12-19 Thread rabby
hello world!
how to get the string "/ + ( ) + \ + [ ] + : + äöü" converted into
valide html.
"...".decode("html") does not run :(
thank you for help

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


Re: Please i need a hand with writing a simple task.

2005-12-19 Thread Brian van den Broek
Marian said unto the world upon 2005-12-19 10:58:
> Can you pleae help me with this task. I have really hard time with
> my textbook desolving this problem. The Task:  Write a program that
> will create a text file, print the contents of the text file as you
> create the file. Read the contents of the file after it's been
> created, add a record and print the contents of the file, remove a
> record(s) from the specified file, write it again, read it again,
> print the contens of the new file.



> 
> Thanks a lot in advance !! Mario !!!
> 

Hi Mario,

since this is pretty clearly a homework type problem, I think you will 
find that you get much more useful help if you show people the code 
that you've already tried. Have you got as far as trying file() or open()?

Best,

Brian vdB

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


Re: Enumeration idioms: Values from different enumerations

2005-12-19 Thread eswald
Ben Finney wrote:
> Antoon Pardon wrote:
> > I just downloaded your enum module for python [from the Cheeseshop]
> > and played a bit with it. IMO some of the behaviour makes it less
> > usefull.
> [...]
> > I also think it would be more usefull if enums from different
> > enumerations just tested unequal.
> [...]
>
> However, I'm aware that this is not how other Python types behave:
>
> >>> 23 == 23
> True
> >>> 42 == 23
> False
> >>> "spam" == 23
> False
>
> Is there a semantic difference between these cases? Is that difference
> enough to want different behaviour?
>
> Is there some behaviour other than "evaluate to False" or "raise an
> exception", that could indicate "not comparable"?

Yes: return NotImplemented.  Note that the == operator automagically
returns False in this case.

>>> "spam".__eq__("spam")
True
>>> "spam".__eq__("ham")
False
>>> "spam".__eq__(23)
NotImplemented

This way, the user could explicitly call __eq__ and check for
NotImplemented if he desires the exceptional behavior.

- Eric

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


Re: settings network timeouts in python

2005-12-19 Thread Narendra
Thanks Steve

Itz working. Thanks a lot!

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


What is unique about Python?

2005-12-19 Thread gsteff
I'm a computer science student, and have recently been trying to
convince the professor who teaches the programming language design
course to consider mentioning scripting languages in the future.  Along
those lines, I've been trying to think of features of Python, and
scripting languages in general, that can't be found in older languages,
and have been having a surprising amount of trouble.  Dynamic typing
can be found in Smalltalk, the module concept can be found in Ada,
functional parameters and the dynamic creation of functions can be
found in Lisp.  The indentation-based syntax seems to be unique, but
that's not really what I'm looking for.  So I'm wondering, what is
innovative about Python, either in its design or implementation?  Or is
its magic really just in combining many useful features of prior
languages in an unusually pleasant way?

Greg

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


Re: hi, ive a new mail address (Away from my office until January 2)

2005-12-19 Thread Aaron Del Monte
Thank you for your e-mail.  I am away from my office until Monday, January 2. I 
will respond to your e-mail when I return. Happy Holidays!

Aaron

* * * * * * * * * * * * * * * * * * * * * * * * * * *
Aaron Del Monte
Assistant Information Systems Analyst
Webmaster, CDFG Marine Region Web Site
http://www.dfg.ca.gov/mrd
(916) 525-2712 (w)
(916) 502-5630 (c)
[EMAIL PROTECTED]

>>> python-list 12/19/05 09:21 >>>

hey its me, my old address dont work at time. i dont know why?!
in the last days ive got some mails. i' think thaz your mails but im not sure!

plz read and check ...
cyaaa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: debian and python--any potential pitfalls?

2005-12-19 Thread Brian van den Broek
[EMAIL PROTECTED] said unto the world upon 2005-12-19 00:36:
> Brian van den Broek wrote:



>>I've tried solo and failed a few times to install various Linux
>>distros on Intel x86 laptops. (The software modem was always the
>>sticking point.) A recent acquaintance has volunteered to guide me
>>through an install tomorrow. He's a Debian fellow. I'm not in a
>>position to have any preferences, so am inclined to follow his distro
>>choice.
>>
>>The only area of computing in which I am interested and with which
>>he's unfamiliar is Python. He suggested I try to find out if there are
>>any potential issues with Debian stable and Python.



>>Thanks bunches,
>>
> 
> Try to ask him to install ubuntu for you. It use the same debian
> packaging system(and most package setup is the same as debian) but has
> a newer python which is based on 2.4. Should have better hardware
> support too. I would say it is a good choice for desktop/laptop over
> vanilla debian. You will still get the same kind of help from him as
> they are 95% similar.
> 
> I use debian when I don't want cutting edge things(mostly for servers)
> but ubuntu for desktop/laptop.

Thanks to Robert and bonono for the responses. I think I will see if 
he'd be willing to give ubuntu a go.

Best,

Brian vdB

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


Re: how to remove duplicated elements in a list?

2005-12-19 Thread Brian van den Broek
Alex Martelli said unto the world upon 2005-12-19 10:48:
> Brian van den Broek <[EMAIL PROTECTED]> wrote:
>...
> 
>orig_list = [3,1,2,3,1,2,3,1,2,1,2,1,3]
>new_list = list(set(orig_list))
>new_list.sort(cmp= lambda x,y: cmp(orig_list.index(x), 
>>
>>orig_list.index(y)))
>>
>new_list
>>
>>[3, 1, 2]
>>
> 
> A better way to exploit exactly the same idea is to use:
> 
> new_list.sort(key=orig_list.index)
> 

Thanks, Alex.

This time, I knew to try the new'ish key argument, but I couldn't 
quite see how to do it. Now you've shown it -- Doh!

Best,

Brian vdB

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


Re: Testing the availability of a module

2005-12-19 Thread Peter Otten
Bo Peng wrote:

> def GUI():
>if options['cml']:
>  cml()
>else:
>  if imp.find_module('wx'):
>wxGUI()
>  elif imp.find_module('Tkinter'):
>tkGUI()
>  else:
>cml()

On the other hand, I don't see how this is superior to an exception-based
approach...

def GUI():
if options["cml"]:
cml()
else:
for ui in wxGUI, tkGUI, cml:
try:
ui()
except ImportError:
pass
else:
break

...especially as you have to deal with ImportError exceptions, too:

>>> import imp
>>> imp.find_module("not_there")
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named not_there

Peter

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


Re: Testing the availability of a module

2005-12-19 Thread Fredrik Lundh
Bo Peng wrote:

> > here's an outline that matches your use case:
> >
> > if user wants command line:
> > command line only
> > else:
> > if wxPython is available:
> > prepare wx based GUI
> > elif Tkinter is available:
> > prepare tk based GUI
> > else:
> > command line only
>
> This is exactly the logic I use,... Eliminating all unrelated stuff, I
> have something like (thanks for the imp hint):
>
> def wxGUI():
>import wx
>wx...
>
> def tkGUI():
>import Tkinter as tk
>tk
>
> def cml():
>command line
>
> def GUI():
>if options['cml']:
>  cml()
>else:
>  if imp.find_module('wx'):

that imp call is completely unnecessary, and means that you'll scan
the path *twice* for each module, instead of once.

this is more efficient:

try:
wxGUI()
except ImportError:
try:
tkGUI()
except ImportError:
cml()





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


Re: reading files

2005-12-19 Thread Mike Meyer
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> The text you read is still hanging around, waiting for you to use it. Once
> you are done with it, you might want to reclaim that memory used,
> especially if it is a 100MB text file:
>
> mytext = ""  # re-bind the name 'mytext' to the empty string

If you have no further use for the variable, then "del mytext" will
also free up the memory, and make it clear to the reader that you're
done with the memory.

> But even that is not always needed: if the name 'mytext' is local to a
> function, then when the function ends, the block of memory used will be
> collected by the Python garbage collector, and you don't have to do a
> thing. 

The immediate collection is implementation-dependent. It works that
way in Cpython. Other implementations may leave the memory allocated
unil there's a GC run. Since I'm dealinng with trivia, whether or not
the OS gets the memory back or it stays part of the python process
varies from platform to platform and implementation to implementation.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: settings network timeouts in python

2005-12-19 Thread Steve Holden
Narendra wrote:
> Hi All,
> 
> I have a problem here. I'm connecting to some pop server.Here i need to
> set the network timeouts,since some times my program disconnecting from
> net at tht point of time I'm unable to connect to POP server. Can any
> one provide the solution for it.
> 
> code;
> 
> import poplib
> m=poplib.POP3('pop.mail.yahoo.com',110)
> m.user('XXX')
> m.pass_('XXX')
>  # here i need to set the network time out when I'm connecting to POP
> server. i.e in the line
> m=poplib.POP3('pop.mail.yahoo.com')
> 
> 
> Any help can be greatly appreciated
> 
Precede your code with

import socket
socket.setdefaulttimeout(60)

for a one-minute timeout.

Regarding your other problem, I don't know what will make a message be 
classified as "bulk" by a particular receiving MTS, you'll have to ask 
the operators of the mail server in question.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Wingide is a beautiful application

2005-12-19 Thread Claudio Grondi
BartlebyScrivener wrote:
> Go to Options. Near the bottom, it will say "Edit Init.File"  Click on
> it.
Done. A completely new file was created.
> 
> Make an entry on a separate line near the top as follows
> 
> (require 'python-mode)
> 
> Then save the init file.
Have copy/pasted to it including braces

(require 'python-mode)

No effect on reopening emacs, except:
"
(1) (initialization/error) An error has occurred while loading 
c:\Dokumente und Einstellungen\Admin\.xemacs\init.el:

Cannot open load file: python-mode

To ensure normal operation, you should investigate the cause of the 
error in your initialization file and remove it.  Use the `-debug-init' 
option to XEmacs to view a complete error backtrace.
"



To summarize my evaluation of XEmacs here:
   - nothing valuable for Python script development out of the box or 
easy achievable in its Windows version.

XEmacs is out from beeing considered an option for someone looking for 
an editor helping him doing his Python scripting.



My final conclusions (I am tired now of evaluating):

The only worth to consider freeware option to Wingide on Windows seems 
to be SPE (or other Scintilla based free editors with the disadvantage 
of not having specific support for Python scripting).

The best not free overall text editing tool on Windows is UltraEdit, but 
for someone interested in an editor for the limited purpose of editing 
Python scripts Wingide in its Personal Version is probably actual a much 
better choice (and multiplatform).

As closing words I would like to encourage anyone to start using
SPE ( http://pythonide.stani.be )
and contribute to its development making it beside IDLE a further 
standard editor for Python scripting having the potential to become one 
day a serious competitor to Wing. Why? Just because I decided to start 
using it and am eager to see it improving.

Claudio

> 
> When you open files with a .py extension xemacs should automatically go
> into "python mode"
> 
> If you read the init.el file it will teach you a little about how to
> configure it. If you don't care about that and only want a python
> editor, then just add the line above.
> 
> rpd
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >