pyvm 1.1

2006-01-28 Thread stelios xanthakis
WHAT IS IT
--

pyvm is an experimental python virtual machine with a compiler written
in python.  pyvm is very incomplete and does not care about backwards
compatibility so you shouldn't use it unless:

- you are interested in vm hacking.
- you want to build another big program based on a fork of pyvm.
- you have a lot of free time and you are very bored.


WHERE IS IT
---

http://students.ceid.upatras.gr/~sxanth/pyvm/


WHAT'S NEW
--

In this release pyvm has real lightweight threads (co-routines). That is
that there are two OS threads, one running the main interpreter loop and
another one polling for file descriptors. When there is a blocking system
call, the main interpreter thread passes a request to the polling thread
and removes the co-routines from the running list. With this setup, pyvm
can run unlimited python threads with just two OS threads.


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

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


Re: Checking free disk space on Win32 ?

2006-01-28 Thread Ravi Teja
http://mail.python.org/pipermail/python-list/2001-January/025344.html

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


Re: How do I dynamically create functions without lambda?

2006-01-28 Thread Kay Schluehr
Steven D'Aprano wrote:
 On Fri, 27 Jan 2006 11:41:56 -0800, Kay Schluehr wrote:

 
  Russell wrote:
  I want my code to be Python 3000 compliant, and hear
  that lambda is being eliminated. The problem is that I
  want to partially bind an existing function with a value
  foo that isn't known until run-time:
 
 someobject.newfunc = lambda x: f(foo, x)
 
  The reason a nested function doesn't work for this is
  that it is, well, dynamic. I don't know how many times
  or with what foo's this will be done.
 
  Now, I am sure there are a half-dozen ways to do this.
  I just want the one, new and shiny, Pythonic way. ;-)
 
  If you want to code partial application without lambda I recommend
  using the code presented in the accepted PEP 309 that will be
  implemented in the functional module in Python 2.5.
 
  http://www.python.org/peps/pep-0309.html


 Fascinating. A couple of thoughts:

 - I really wish that people would make up their minds about what currying
 is, and how it differs from partials and closures. If the people who
 do know can't agree, how do they expect the rest of us to understand?

If they can't agree they probably don't know ;)

Concepts like closure and currying are well defined in lambda
calculus and hence in functional programming.

 - What, if anything, is the difference between a closure and an iterator?
 Is an iterator just a closure wrapped up with an API?

I would expect a closure to be a function with free/unbound variables
that are bound by an enclosing context. In FP slang a function without
any free variables is called a combinator. An iterator is a function
related to an abstract data type equipped with a partial order. The
iterator abstracts from the particular ordering scheme and makes the
ADT look like a list. In Python we have a nice correspondence between
generators as implicit defined sequences of yielded values, iterators
that enable uniform access to the values produced by generators and
lists that make the sequence explicit ( if finite ).

Fun with combinators
==
There are quite interesting relationships deep down in the theory of
computation. For instance understanding recursion in lambda calculus is
not that easy because you cannot simply reintroduce an anonymous
function by the name into its own body. The idea is to create a
fixpoint of a higher order curried function instead. See for example
this curried extension of a factorial:

F = lambda h: lambda n : n2 and 1 or n*h(n-1)

Now imagine you have a fixpoint fix(F) of F which is again a function
and pass it into F then you will get:

fix(F) = F(fix(F)) = lambda n : n2 and 1 or n*fix(F)(n-1)

That is fix(F) is actually the searched factorial ! There is a generic
way to create fixpoints of higher order curried functions such as F.
The most popular one is the so called Y-combinator ( not to confuse
with Paul Grahams company ;).

In Python you can write:

Y = lambda g: (lambda f: g(lambda arg: f(f)(arg))) (lambda f: g(lambda
arg: f(f)(arg)))

This serves the purpose. Try Y(F) and see.

Kay

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


Re: Python vs C for a mail server

2006-01-28 Thread al pacino
but i am not able to choose the language.Should i go for C(socket API)

Ravi is right
(using sockets is more or less the same
from any language.)

..try JSP(java server pages), some guys in nit warangal implemented a
mail server
(foa  LAN though)for their minor project.

my contention is that using sockets(in c++) will improve your
understanding of the protocol
suite and improve your programming as well.




Ravi Teja wrote:
  Why don't you use an existing mail server?

 Probably because that was his homework assignment for a networking
 class. Not uncommon to be told to implement a server from the scratch
 from the RFC. Although that does not explain his concern about
 performance.

 Abhinav, if that is the case, using sockets is more or less the same
 from any language. Python as usual will be cleaner than C. You might
 want to look at Twisted Mail. Use SocketServer module in the standard
 library to implement the RFC. Other than that it is silly to try to
 write a Mail Server unless you have some extra ordinary need.

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


Re: VB to Python migration

2006-01-28 Thread Luis M. González
I second the suggestion of using Boo for this case.
Why use Delphi or VB when you have a more pythonic first class .NET
language?
You already have a very good IDE for creating your project
(SharpDevelop), which is free, open source and already has the Boo
bindings included (download here the latest version:
http://build.sharpdevelop.net/BuildArtefacts/).

Boo is a perfect language for someone wanting to develop Windows GUI
apps because it has all the nice features and syntax of Python, while
being specifically created to run on the .NET framework.

However, if you still want to use pure Python, it won't take too long
to get what you need. Ironpython is in version 1.0 Beta 2, and moving
full steam towards a stable release.
I'm sure that soon it will be integrated to Visual Studio.

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


Re: Python vs C for a mail server

2006-01-28 Thread Jim Segrave
In article [EMAIL PROTECTED],
Ravi Teja [EMAIL PROTECTED] wrote:
 Why don't you use an existing mail server?

Probably because that was his homework assignment for a networking
class. Not uncommon to be told to implement a server from the scratch
from the RFC. Although that does not explain his concern about
performance.

Abhinav, if that is the case, using sockets is more or less the same
from any language. Python as usual will be cleaner than C. You might
want to look at Twisted Mail. Use SocketServer module in the standard
library to implement the RFC. Other than that it is silly to try to
write a Mail Server unless you have some extra ordinary need.

Any lecturer assigning write a mail server as a class project is
doing his/her students a true dis-service. Mail server RFC compliance is a
nightmare to get right, performance issues and mail routeing are both
material for at least a full year's university study.

A student who tries to make an even vaguely RFC compliant mail server
probably won't finish their project, as student who completes such a
project might come away with the mistaken belief that they actually
have done it correctly. 

The number of software products which use eail and do so incorrectly
is astounding and depressing. There's a reason that the source for
sendmail is about 120K lines, exim is nearly 270K lines. Doing it
right is _hard_.





-- 
Jim Segrave   ([EMAIL PROTECTED])

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


Re: Python vs C for a mail server

2006-01-28 Thread al pacino
jim you are probably right.

i have had exp. with this. i had to create a server(multipurpose such
as file sharing, games (pretty simple tho like tic tac toe..) we were
in 6th sem with learning OS and comp. n/w for the first time.

it seems like these jack ass jerks (proffs/instuctors) like to bully
students...
obviously we cud not complete the project as most of the time was spent
on
learning the stuff(like TCP, multithreading..) .

i don't know how things work out in the west, but i feel the faculty
really care about their students in american colleges..in contrast to
here (in inida, though things are little different in the IITs)


Jim Segrave wrote:
 In article [EMAIL PROTECTED],
 Ravi Teja [EMAIL PROTECTED] wrote:
  Why don't you use an existing mail server?
 
 Probably because that was his homework assignment for a networking
 class. Not uncommon to be told to implement a server from the scratch
 from the RFC. Although that does not explain his concern about
 performance.
 
 Abhinav, if that is the case, using sockets is more or less the same
 from any language. Python as usual will be cleaner than C. You might
 want to look at Twisted Mail. Use SocketServer module in the standard
 library to implement the RFC. Other than that it is silly to try to
 write a Mail Server unless you have some extra ordinary need.

 Any lecturer assigning write a mail server as a class project is
 doing his/her students a true dis-service. Mail server RFC compliance is a
 nightmare to get right, performance issues and mail routeing are both
 material for at least a full year's university study.

 A student who tries to make an even vaguely RFC compliant mail server
 probably won't finish their project, as student who completes such a
 project might come away with the mistaken belief that they actually
 have done it correctly.

 The number of software products which use eail and do so incorrectly
 is astounding and depressing. There's a reason that the source for
 sendmail is about 120K lines, exim is nearly 270K lines. Doing it
 right is _hard_.
 
 
 
 
 
 -- 
 Jim Segrave   ([EMAIL PROTECTED])

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


Re: Python vs C for a mail server

2006-01-28 Thread abhinav
ya its supposed to be some stupid 6 month project which my friend has
to do.I am just helping him out.he may not be implementing a full
fledged rfc compliance mail server but may support some of the major
functionalities.so basically its an extra ordinary need.I just wanted
to know which language would be better for implementation and has
faster development cycle.I have heard a lot about python and its ease
of use.My point is it should be worth a 6 month project and speedy
development since he is already proficient in C/C++ socket programming
and taking the pain of learning python should be worth the effort.

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


Re: How do I tell if I'm running in the PyWin interpreter?

2006-01-28 Thread Peter Otten
Charles Krug wrote:

 Is there a way to detect that I'm running the the PyWin interpreter so
 that I can bypass its raw_input behavior?

You could test

if pywin_specific_module in sys.modules:
   # use workaraound

Or maybe you can get away with always using sys.stdin.readline() instead of
raw_input()? Look into cmd.py for an example.

Peter

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


Re: Returning a value from code string

2006-01-28 Thread Kirk McDonald
Fredrik Lundh wrote:
 executing the code in a custom namespace is a lot cleaner:
 
 ns = {}
 ns[os] = os # insert preimported values
 ns[app] = app # insert preloaded objects
 exec self.code in ns
 try:
 func = ns[std_func_name]
 except KeyError:
 pass
 else:
 func(**kwargs)
 
 instead of using a standard function, you can let the code
 objects talk to the application via a preloaded object or an
 interface module.  e.g. instead of
 
 def std_func_name(app, args):
 app.something()
 
 your code object could simply become
 
 app.something()
 

These code objects should all return an instance of a certain class (or 
one of its descendants). In another branch of this topic, I described 
roughly what this is for. So, without going into too much detail, I'll 
just repeat that this is for a website backend. Whenever an HTML form is 
submitted, a hidden op element (short for operation) in the form is 
checked. This value will send the rest of the form data on to the code 
object it represents. (If you've read my other post: These code objects 
are nodes, the value for the op element is the ID number of one of 
them, or possibly one of a few mnemonics for some of the more important 
ops.)

So, taking another swipe at it with your suggestions:

def __call__(self, args=None, **kwargs):
 ns = {}
 ns.update(kwargs)
 ns[args] = args
 ns[retval] = None
 exec self.code in ns
 try:
 func = ns[std_func_name]
 except KeyError:
 return ns[retval]
 else:
 # Already passed kwargs into the namespace
 return func()

Then, a code object can either return a value by using whatever happens 
to be in 'retval' when it's done executing, or by defining a 
'std_func_name' function and using its return value.

So the interface for these Codenodes needs to be able to accept 
arguments as a name/value dictionary corresponding to the elements in 
the HTML form (the 'args' argument in my example above). This dictionary 
is passed on to the code object. The kwargs are a few important 
variables (not supplied by the form) that all Codenodes need to know, 
such as the current user and maybe a database cursor.

Each Codenode knows how to deal with the input from its associated form. 
(Or forms! There is, for example, a generalized commit Codenode that 
knows how to update the state of *any* node if a form follows a certain 
template.) When it is done, it needs to then return whichever node 
should be displayed next. If the operation being attempted violates the 
user's permissions, it might return the access denied node. (Actually, 
in that case it will raise an AccessDenied exception and expect 
something down the line to deal with it, so I can define what the 
access denied node is in a central place, but you get the idea.) If 
the operation resulted in a new node being created, it might return the 
new node. c.

Sorry if I tend to ramble, heh. :-)

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


Re: Fast generation of permutations

2006-01-28 Thread Anton Vredegoor
Paul Rubin wrote:

 def deals():
 for i in xrange(13**5):
 cards = [(i//p) % 13 for p in (1, 13, 169, 2197, 28561)]
 yield cards

This gives hands like [0,0,0,0,1] and [0,0,0,1,0] which are
permutations of one another.

Below is a piece of code that avoids this. Here's how to interprete its
output. Suppose one gets a hand like [0,1,2,3,4]. This means that it
would be possible to create 1024 (4**5) poker hands from this, by
coloring the cards.

Another hand, for example [0,0,1,2,3], would allow only 384 colorings,
because the two zeros would contribute choose 2 out of 4 (colors), so 6
colorings. The other numbers remain available for 4 colorings, which
gives 6*4**3 (==384) colorings for this hand.

Similar things happen for other partionings of the hands into numbers.
In fact I am now investigating a description based on integer
partitions  of the number 5. I am not sure whether I want to partition
based on colors or on numbers, that seems to arbitrary.

This is very fascinating. Maybe someday I'll make a tkinter script with
a visual tree structure allowing all kinds of numbers of cards, and
arbitrary numbers of variables to partition by.

This would then give result sets like those strange quantum particles,
such as quarks.

Have fun,

Anton

def hands(L = [0]):
if len(L) == 6:
if L[1] != L[-1]: #no five of a kind
yield L[1:]
else:
for i in range(L[-1],13):
for H in hands(L+[i]):
yield H

def pprint(i,hand):
print '%5i:   ' %i,
for x in hand:
print '%2i ' % x,
print

def test():
H = hands()
total = 0
for i,x in enumerate(H):
pprint(i,x)

if __name__=='__main__':
test()

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


Re: writing large files quickly

2006-01-28 Thread Jens Theisen
Donn wrote:

 How the heck does that make a 400 MB file that fast? It literally takes
 a second or two while every other solution takes at least 2 - 5 minutes.
 Awesome... thanks for the tip!!!

 Because it isn't really writing the zeros.   You can make these
 files all day long and not run out of disk space, because this
 kind of file doesn't take very many blocks.   The blocks that
 were never written are virtual blocks, inasmuch as read() at
 that location will cause the filesystem to return a block of NULs.

Under which operating system/file system?

As far as I know this should be file system dependent at least under  
Linux, as the calls to open and seek are served by the file system driver.

Jens

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


Re: Intro to Pyparsing Article at ONLamp

2006-01-28 Thread Anton Vredegoor
Paul McGuire wrote:

 I just published my first article on ONLamp, a beginner's walkthrough for
 pyparsing.

 Please check it out at
 http://www.onlamp.com/pub/a/python/2006/01/26/pyparsing.html, and be sure to
 post any questions or comments.

I like your article and pyparsing. But since you ask for comments I'll
give some. For unchanging datafile formats pyparsing seems to be OK.
But for highly volatile data like videotext pages or maybe some html
tables one often has the experience of failure after investing some
time in writing a grammar because the dataformats seem to change
between the times one uses the script. For example, I had this
experience when parsing chess games from videotext pages I grab from my
videotext enabled TV capture card. Maybe once or twice in a year
there's a chess page with games on videotext, but videotext chess
display format always changes slightly in the meantime so I have to
adapt my script. For such things I've switched back to 'hand' coding
because it seems to be more flexible.

(Or use a live internet connection to view the game instead of parsing
videotext, but that's a lot less fun, and I don't have internet in some
places.)

What I would like to see, in order to improve on this situation is a
graphical (tkinter) editor-highlighter in which it would be possible to
select blocks of text from an (example) page and 'name' this block of
text and select a grammar which it complies with, in order to assign a
role to it later. That would be the perfect companion to pyparsing.

At the moment I don't even know if such a thing would be feasible, or
how hard it would be to make it, but I remember having seen data
analyzing tools based on fixed column width data files, which is of
course in a whole other league of difficulty of programming, but at
least it gives some encouragement to the idea that it would be
possible.

Thank you for your ONLamp article and for making pyparsing available. I
had some fun experimenting with it and it gave me some insights in
parsing grammars.

Anton

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


Re: writing large files quickly

2006-01-28 Thread Jens Theisen
Ivan wrote:

 Steven D'Aprano wrote:

 Isn't this a file system specific solution though? Won't your file system
 need to have support for sparse files, or else it won't work?

 Yes, but AFAIK the only modern (meaning: in wide use today) file
 system that doesn't have this support is FAT/FAT32.

I don't think ext2fs does this either. At least the du and df commands  
tell something different.

Actually I'm not sure what this optimisation should give you anyway. The  
only circumstance under which files with only zeroes are meaningful is  
testing, and that's exactly when you don't want that optimisation.

On compressing filesystems such as ntfs you will get this behaviour as a  
special case of compression and compression makes more sense.

Jens

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


Re: writing large files quickly

2006-01-28 Thread Jens Theisen
Donn wrote:

 Because it isn't really writing the zeros.   You can make these
 files all day long and not run out of disk space, because this
 kind of file doesn't take very many blocks.   The blocks that
 were never written are virtual blocks, inasmuch as read() at
 that location will cause the filesystem to return a block of NULs.

Are you sure that's not just a case of asynchronous writing that can be  
done in a particularly efficient way? df quite clearly tells me that I'm  
running out of disk space on my ext2fs linux when I dump it full of  
zeroes.

Jens


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


Re: Python vs C for a mail server

2006-01-28 Thread Nicolas Lehuen
If your friend is proficient in C/C++ then learning Python should not
be a pain. Quite the contrary, it should be an enlightnement. Being
good in C/C++ AND Python is a killer combination, as you can promptly
and efficiently code big chunks of your application in Python and
interface with C/C++ code where (and if) high performance is required.

Now, you should definitely check the requirements for the homework.

If the assignment is about being able to decipher an RFC and implement
it correctly with a nice software design, then I would definitely opt
for Python. Having to squish memory management, string manipulation and
character encoding bugs in C/C++ is not fun and not related to
high-level design nor RFC support.

If it's just a way to throw a programming challenge at your friend's
face, then you should check whether it's okay to use Python rather than
C/C++, otherwise he could be charged of cheating by using a more
productive language :).

Regards,
Nicolas

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


Re: beta.python.org content

2006-01-28 Thread Ron Rogers Jr.
Steve Holden wrote:
 How does
 
   http://beta.python.org/about/beginners/
 
 look?
 
 regards
  Steve

Hi, I'm an actualy Python beginner, decided recently to play with 
Python.  I'm a user, not a professional programmer or developer of any 
sort, so I guess the beginner's page would be aimed at folks like me.

It looks fine, degrades pretty well in Dillo.

But.it needs more Beginners links and info.  The Why Python seems 
a bit out of place, more akin to something that would be on the beta 
home, which looks a little corporate brochure site to me.  It also 
seems a little bland as a beginner site goes. A little bit of fun 
and friendliness in the spirit of Python for Everyone might be 
something to add.  That's what brought me to Python.  The idea that 
Python was not just for people like ESR who've been programmers for 
decades, or for corporate types designing applications containing a new 
paradigm of competencies in objective oriented programming, but for high 
school students, hobbyist programmers and even those who've never 
written a line of code in their lives.

It has been suggested that a Google-like hierarchy might be useful and I 
agree, though I don't know how that might work in practice. You could 
have a bland brochure site with the proper buzzwords for the 
corporates, another for the devs with late breaking patches, news, RSS 
feeds, whatever they need. and one for Education and/or beginners, with 
perhaps a colorful friendly look. (but perhaps keeping the same basic 
overall base look)

I actually like the look of the current http://www.python.org  It packs 
a lot of useful links in one page and it seems friendly  Which 
probably sounds silly to describe an emotional reaction or feel to a 
site. Admittedly it doesn't look corporate or slick professional but 
that's not necessarily a bad thing.

I agree with others about the new logo. It lacks a certain, pardon the 
expression, je ne sais quoi. (one of the things that got me interested 
in Linux was seeing that penguin associated with the word Linux and 
making me curious about what that Linux thing was all about)  But it 
would make a good logo for a enterprise.python.org 
business.python.org  So perhaps different logos for different purposes?

A cartoony friendly python in front of a blackboard for education 
(similar to the Pygame python)

A python reading a book at the base of a larch for a listing of books

That sort of thing.

The python.org site's been useful to me, pointing me to interesting 
software, documentation and whatnot. Though I didn't know about IDLE 
until I saw it mentioned in a post on Slashdot in a story asking for 
recommendations for Python IDE's.  I am very new to Python.


CronoCloud (Ron Rogers Jr.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I dynamically create functions without lambda?

2006-01-28 Thread Steven D'Aprano
On Sat, 28 Jan 2006 00:13:28 -0800, Kay Schluehr wrote:

[snip lambda calculus stuff]

 In Python you can write:
 
 Y = lambda g: (lambda f: g(lambda arg: f(f)(arg))) (lambda f: g(lambda
 arg: f(f)(arg)))
 
 This serves the purpose. Try Y(F) and see.


Is any of this stuff maintainable in the real world of IT, where
most programmers don't have computer science degrees? You come along six
months after the project was finished to maintain this code and discover
that the whiz-kid lambda calculus guy never commented anything because
that would detract from the elegance of his one liners; what happens next?



-- 
Steven.

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


File date attribute

2006-01-28 Thread Bruce R Graham
Hi: am a Newbie and this is my first script:
We were recently burgled and had our computers stolen. Easy to replace,
but the data that was lost is years and years of work. I've
investigated offsite data backup but it seems expensive. In any case,
the data we have is not volumous.
Rather, would like to send emails of files to a backup address at
gmail.
So, this is my plan:
Run a script in cron.daily. The script should check a timestamp placed
by the last occurrence of that script. Then check my home folder for
files modified between that timestamp and now. Then send those files
off to gmail.
I have most of the pieces in place, except I can't find out how to
retrieve the date modified attribute of a file. Does anybody know how
to do that?
I'll post the full script when I'm done in case there is anybody who
would like to use it.
Kindest,
BG

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


Re: Python vs C for a mail server

2006-01-28 Thread Jens Theisen
Nicolas wrote:

 If it's just a way to throw a programming challenge at your friend's
 face, then you should check whether it's okay to use Python rather than
 C/C++, otherwise he could be charged of cheating by using a more
 productive language :).

Though this comment of mine is likely to start a religious war, it might  
also bring up some useful points.

I'm a bit relucted to swallow the common view of Python being a so- 
productive language, especially compared to C++. I value C++  
productiveness actually much higher than it's performance.

To stick to the mailserver example, I'm pretty sure I'd do it in C++. I  
got very exited about Python when I first saw it, but I've encountered  
several problems that hindered productivity dramatically.

One thing is the lack of static types. The problem is not only that the  
compiler can't tell you very basic things you're doing wrong but also that  
code isn't intrinsically documented:

def send_mail(mail):
...

What can I do with mail? In C++, you're looking up what type it is  
(presumably by pressing M-x in Emacs on the word before it) and have a  
look on it's type definition. In Python, it can be quite difficult to tell  
what you can do with it because the information of what will be passed in  
can be several layers up.

Also there is not even symbol-safety: self.not_defined will never rise a  
compile-time error.

And to address the memory management critisism about C++: Unless you have  
cyclic structures (you probably won't have in a mail server), just use  
smart pointers and you don't have to be concerned more about it than you'd  
have to be in Python.

I aggree on C++ libraries being weak on unicode strings though, or even  
generally weak in the libraries (you have the C libraries, but they're not  
very type safe or elegant to use).

I'm aware that C++ is a horrible monstrosity, an argument whiches weight  
depends on the OP's friends C++ experience.

Please don't be offended, but if anyone could make a point of how Python's  
disadvantages in these regards could be alleviated, I'd be very  
interested.

Jens

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


Re: File date attribute

2006-01-28 Thread Sybren Stuvel
Bruce R Graham enlightened us with:
 Run a script in cron.daily. The script should check a timestamp
 placed by the last occurrence of that script. Then check my home
 folder for files modified between that timestamp and now. Then send
 those files off to gmail.
 I have most of the pieces in place, except I can't find out how to
 retrieve the date modified attribute of a file. Does anybody know
 how to do that?

man find. You can even tell it to list all files older than a
reference file.

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


Re: Python vs C for a mail server

2006-01-28 Thread Sybren Stuvel
Jim Segrave enlightened us with:
 Any lecturer assigning write a mail server as a class project is
 doing his/her students a true dis-service.

At one time, I got an assignment Write a robust, user friendly SMTP
client.  That was just after we learned how to user 'for' loops and
'if' statements. Talk about dis-services ;-)

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


Re: beta.python.org content

2006-01-28 Thread Bruce Cropley
I'd like to see the use of Python grow as dramatically as it
deserves to. As I see it, there are at least three major categories
of web visitors that we need to cater to:
- Existing python users
- Potential python users
- Managers

The current site's front page seems to be aimed mainly at existing
python developers. I agree with Magnus about not specifying who
should be interested in a particular page.

The most effective web marketing of an Open Source development
tool recently has probably been http://www.rubyonrails.org/.
I think the link on the front page to a very slick coding video
demonstration helped a lot there.
Do we have anything like that for Python yet?

TurboGears (http://www.turbogears.org/index.html) seems to have
captured the same spirit of exciting marketing hype. They are both
very cool tools as well, but so is Python.
Can we adapt any of the techniques they use for the Python website?

Hope that helps,
Bruce

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


Re: Efficient Find and Replace

2006-01-28 Thread Raymond Hettinger
   for i,v in enumerate(L):
   if v == X:
   L[i] = Y
 
  Here's an alternate solution using a replacement dictionary:
 
M = {X:Y}
for i, v in enumerate(L):
L[i] = M.get(v, v)

[Fredrik Lundh]
 but that's 2-3 times slower than the OP's corrected code for his use
 case, so I'm not sure it qualifies as more efficient...

The alternate wasn't presented for efficiency.  Its virtue is that with
no additional effort, it generalizes to substituting multiple
find/replace pairs in a single pass.


Raymond

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


Re: How do I tell if I'm running in the PyWin interpreter?

2006-01-28 Thread vincent wehren
Charles Krug [EMAIL PROTECTED] schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
| On 2006-01-28, Steven D'Aprano [EMAIL PROTECTED] wrote:
| 
|  As the comment says, when I run this under Python Win, I get an (pretty
|  sure) Tkinter interface, not a command line, and I don't get my
|  EOFError when I expect to.
| 
|  When do you expect to get an EOFError? The only way I get an EOFError is
|  if I explicitly hit Ctrl-D while raw_input is running. When do you 
expect
|  to get it? Have you tried Ctrl-Z under Windows?
| 
|
| That's exactly how I use it everywhere else.  Type until you're done
| then hit Ctrl-D
|
| The problem is only when running under the PyWin IDE . . I'd been using
| this for months under Idle and every place else I needed it.
|
| The problem is that PyWin doesn't give you a raw command line with in
| response to raw_input, but gives you a text entry box and a nice
| OK-Cancel yada yada interface that silently eats my EOF.
|
| I'd like to have a single tool I can use everywhere.  So far as I can
| tell, that means I have to detect the PyWin IDE and handle it
| separately on initialization so I get a real raw input and not the
| redefined Tkinter version.
|

import sys
import os
if os.path.basename(sys.executable) == 'Pythonwin.exe':
#Pythonwin specific  initialization
else:
#Other

HTH,

Vincent Wehren



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


Re: Returning a value from code string

2006-01-28 Thread Max
Kirk McDonald wrote:
 Another kind of node (I'm still deciding
 whether to call them Codenodes or Opcodes or maybe Pynodes) is a chunk
 of code that can be asked to run itself, and which can be edited, on the 
 fly, from within the website. Thus, one can both alter the functionality 
 of the site, and add functionality, from the site itself (so long as you 
 have the user permissions to do so).
 

As Steven said, U R pwn3d. 1f you d0n't sp3a| l33t (if you don't 
speak leet), that means you are screaming hack me, use me to launch 
attacks on other computers, and than attack my computer. Unless you 
have some revolutionary ideas in code-security analysis. In which case 
you can a lot more money than from implementing Everything2 in python.

 -Kirk McDonald

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


Re: How do I dynamically create functions without lambda?

2006-01-28 Thread Kay Schluehr
Steven D'Aprano wrote:
 On Sat, 28 Jan 2006 00:13:28 -0800, Kay Schluehr wrote:

 [snip lambda calculus stuff]

  In Python you can write:
 
  Y = lambda g: (lambda f: g(lambda arg: f(f)(arg))) (lambda f: g(lambda
  arg: f(f)(arg)))
 
  This serves the purpose. Try Y(F) and see.


 Is any of this stuff maintainable in the real world of IT, where
 most programmers don't have computer science degrees?

Probably not. But the good thing about Y is that it is in closed form
and the expression is not infinitely long. By the way I have no less a
hard time to read C code with advanced data-structures and many type
casts which is much more likely to happen in the real world.

From what I've seen the only *practical* purpose fixpoint combinators
serve is a kind of recursion overloading. Without modifying F one can
memoize values by adapting the fixpoint combinator. We already know
something similar from the Go4 command pattern but there is no
self-referential entanglement and it is less general.

 You come along six
 months after the project was finished to maintain this code and discover
 that the whiz-kid lambda calculus guy never commented anything because
 that would detract from the elegance of his one liners; what happens next?

Ask a Scheme guy at LtU. Accuse the original author in Den Haag and if
caught put him to shame by making photos at a dentist. Google for
lambda calculus Y. Ask someone here at comp.lang.python. Ask your
boss for more time ;)

Kay

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


Re: writing large files quickly

2006-01-28 Thread Ivan Voras
Jens Theisen wrote:
 Ivan wrote:

Yes, but AFAIK the only modern (meaning: in wide use today) file
system that doesn't have this support is FAT/FAT32.
 
 I don't think ext2fs does this either. At least the du and df commands  
 tell something different.

ext2 is a reimplementation of BSD UFS, so it does. Here:

f = file('bigfile', 'w')
f.seek(1024*1024)
f.write('a')

$ l afile
-rw-r--r--  1 ivoras  wheel  1048577 Jan 28 14:57 afile
$ du afile
8   afile

 Actually I'm not sure what this optimisation should give you anyway. The  
 only circumstance under which files with only zeroes are meaningful is  
 testing, and that's exactly when you don't want that optimisation.

I read somewhere that it has a use in database software, but the only 
thing I can imagine for this is when using heap queues 
(http://python.active-venture.com/lib/node162.html).
-- 
http://mail.python.org/mailman/listinfo/python-list


SLUT distibution mangled?

2006-01-28 Thread Ido Yehieli
Hi,
 I was trying to download and install the latest SLUT (0.9.0) from
http://slut.sourceforge.net/download/index.html
and it seems both the zip and the tar.gz files are corrupted - the
directory aux and the files within can not be extracted (using
windows BTW). This happened with both the zip _and_ the tar.gz file.
The strange thing is: even when I'm trying to create a directory 'aux'
by myself it is not possible!
Anyone here ever encountered this problem?

Thank you in advance,
Ido Yehieli.

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


Re: SLUT distibution mangled?

2006-01-28 Thread Ido Yehieli
OKl, sorry this seems to have nothing to do with SLUT it self, for some
reason a directory names 'aux' can not be created... most bizzare.
mkdir aux just returns The directory name is invalid.

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


Re: Using non-ascii symbols

2006-01-28 Thread Ivan Voras
Rocco Moretti wrote:

 Could it be APL?

No, it was much newer... someone did it as a hobby language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SLUT distibution mangled?

2006-01-28 Thread Fredrik Lundh
Ido Yehieli wrote:

 OKl, sorry this seems to have nothing to do with SLUT it self, for some
 reason a directory names 'aux' can not be created... most bizzare.
 mkdir aux just returns The directory name is invalid.

on windows ?

win32 reserves the file names CON, PRN, AUX, CLOCK$, NUL, COM1,
COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2,
LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 for devices.

/F



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


Re: Python code written in 1998, how to improve/change it?

2006-01-28 Thread Petr Jakes
To provide some feedback I vould like to show the code which works fine
for me as a FSM machine. As speed is not the crucial issue for my
application, I have decided to use  an approach showed in the Skip
Montanaro's code.
http://orca.mojam.com/~skip/python/fsm.py
(it is using dictionary to store state/transition dependencies).

Tanks to all for your previous postings.

Petr Jakes

State machine example, for the pull/push button mentioned earlier in
this discussion thread

class FSM:
'''the states dictionary contains user defined state/transition
table in the format:
{'start_state': {'event': {'guard': ('action', 'end_state')}},
according to the actual start_state, event and guard
combination,
the execute method reads the relevant  action and end_state
from the states dictionary, then executes action and setup
end_state   '''
def __init__(self):
self.states = {}

def add(self,start_state, event_trigger,event_guard,
action,newstate):
add a new state/transition information to the state
machine dictionary
if self.states.has_key(start_state)== False :
self.states[start_state]={}
if self.states[start_state].has_key(event_trigger)== False :
self.states[start_state][event_trigger]={}
if
self.states[start_state][event_trigger].has_key(event_guard)== False :
self.states[start_state][event_trigger][event_guard]={}
self.states[start_state][event_trigger][event_guard]=(action,
newstate)

def start(self, state):
set the start state
self.state = state

def execute(self, event,guard=None):
'''according to the actual start_state, event and guard
combination
read the relevant  action and end_state from the
states dictionary,
then execute action and setup end_state '''
action, end_state = self.states[self.state][event][guard]
if action is not None:
apply(action, (self.state, event))
self.state = end_state
return

'''actions they has to be executed while the event occurs'''
def motor_off(state, input): print pushing the switch to the OFF
position
def motor_on(state, input): print lifting the switch to the ON
position


fsm = FSM()

'''we have to define state/transition table first,
wher state transitions are defined as:
('start_state', 'event', 'guard', 'action', 'end_state)'''
fsm.add(ON,lift,None,None,ON)
fsm.add(ON,push,None,motor_off,OFF)
fsm.add(OFF,push,None,None,OFF)
fsm.add(OFF,lift,None,motor_on,ON)

fsm.start(ON)
print start state is, fsm.state
events=(push,push,push,lift,lift,push,lift,push,lift,lift,lift,push,lift)

for  event in (events):

fsm.execute(event)
print switch is , fsm.state

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


textvariable help

2006-01-28 Thread swisscheese
I must be missing something basic.
Can anyone explain why 'A' does not show on the entry widget?

import Tkinter
root = Tkinter.Tk()
class Col:
Rows = [0]
def __init__(self):
Frame = Tkinter.Frame(root);
Frame.pack (side='left')
self.Rows[0] = Tkinter.StringVar();
Tkinter.Entry(Frame,textvariable=self.Rows[0]).pack ();
X = Col()
# X.Rows[0].set ('A') # 'A' displays in Entry this way
Y = Col()
X.Rows[0].set ('A') # Why not also this way?
Y.Rows[0].set ('B')
root.mainloop()

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


Re: Python Drive Name is the search, what is the question?

2006-01-28 Thread Gregory Piñero
On 1/28/06, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 However, you do have an entry that covers Python and Drive, with
 your URL at the bottom...

 Look Familiar???

 -=-=-=-=-=-=-
 Gregory Piñero  | 3 Dec 01:23
 Picon
 Re: Detect Blank DVD or CD in CDROM Drive
 From: Gregory Piñero gregpinero at gmail.com
 Subject: Re: Detect Blank DVD or CD in CDROM Drive
 Newsgroups: gmane.comp.python.general
 Date: 2005-12-03 00:23:47 GMT

That would be interesting if that's what they're looking for.  I never
did figure out how to do that.  In fact, my post on using Python with
NeroCmd.exe comes up first in a google search for python drivename
no quotes.

Here's the link if you're curious:
http://www.answermysearches.com/index.php/nerocmdexe-and-python-automating-the-burning-process/10/

But I just don't think that's what they're looking for.  I'll keep
thinking about it.

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


Re: How do I tell if I'm running in the PyWin interpreter?

2006-01-28 Thread Charles Krug
On 2006-01-28, Peter Otten [EMAIL PROTECTED] wrote:
 Charles Krug wrote:

 Is there a way to detect that I'm running the the PyWin interpreter so
 that I can bypass its raw_input behavior?

 You could test

 if pywin_specific_module in sys.modules:
# use workaraound

 Or maybe you can get away with always using sys.stdin.readline() instead of
 raw_input()? Look into cmd.py for an example.

 Peter


cmd.py is the battery included I was thinking of last night.
Unfortunately it uses something that PyWin replaces.

However I did note that PyWin's version raises KeyboardInterrupt out of
its dialog box.

That's not ideal, but at least it gives me an idea what I need to trap
to exit.

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


Re: writing large files quickly

2006-01-28 Thread Jens Theisen
Ivan wrote:

 ext2 is a reimplementation of BSD UFS, so it does. Here:

 f = file('bigfile', 'w')
 f.seek(1024*1024)
 f.write('a')

 $ l afile
 -rw-r--r--  1 ivoras  wheel  1048577 Jan 28 14:57 afile
 $ du afile
 8 afile

Interesting:

cp bigfile bigfile2

cat bigfile  bigfile3

du bigfile*
8   bigfile2
1032bigfile3

So it's not consumings 0's. It's just doesn't store unwritten data. And I  
can think of an application for that: An application might want to write  
the biginning of a file at a later point, so this makes it more efficient.

I wonder how other file systems behave.

 I read somewhere that it has a use in database software, but the only
 thing I can imagine for this is when using heap queues
 (http://python.active-venture.com/lib/node162.html).

That's an article about the heap efficient data structure. Was it your  
intention to link this?

Jens


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


Re: textvariable help

2006-01-28 Thread Fredrik Lundh
swisscheese wrote:

 I must be missing something basic.
 Can anyone explain why 'A' does not show on the entry widget?

 import Tkinter
 root = Tkinter.Tk()
 class Col:
 Rows = [0]
 def __init__(self):
 Frame = Tkinter.Frame(root);
 Frame.pack (side='left')
 self.Rows[0] = Tkinter.StringVar();
 Tkinter.Entry(Frame,textvariable=self.Rows[0]).pack ();
 X = Col()
 # X.Rows[0].set ('A') # 'A' displays in Entry this way
 Y = Col()
 X.Rows[0].set ('A') # Why not also this way?
 Y.Rows[0].set ('B')
 root.mainloop()

Rows is a class variable, and since you're modifying it in place, Rows[0] will
always be set to the most recently created Entry widget.

what is it you're trying to do here ?

/F



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


Re: Checking free disk space on Win32 ?

2006-01-28 Thread M�ta-MCI
Hi !


Another method :

import os
print str(os.popen4('dir C:\ /AD |find octets|find 
libre')[1].readlines()[0].split()[2])

Warning !  It's French version.
For english, perhaps (depend of DIR return format) :

import os
print str(os.popen4('dir C:\ /AD |find bytes|find 
free')[1].readlines()[0].split()[2])


@-salutations

Michel Claveau



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


General Type Checks (int, str, tuple, etc.)

2006-01-28 Thread Fabian Steiner
Hello!

So far, I am using something like »if isinstance(var, int):« to 
determine, whether var's value is an integer. Now I would like to know 
if there is any better possibility to do such general checks or may a 
construct with isinstance() even fail in certain cases?

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

Re: textvariable help

2006-01-28 Thread swisscheese
Thanks for the quick reply. With your reply and another tutorial I get
it now. I needed self.Rows = ... in the constructor. I find myself
wasting a lot of time with poor python docs. Whatever time Python is
supposed to save I'm losing so far in looking up things. I suppose that
will change as I get past the learning curve. Are you aware of any good
docs on python that make it easy to find things?

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


curses won't refresh screen

2006-01-28 Thread Casey Bralla
For some reason, I can't get curses to refresh the screen.  Can someone
offer a suggestion to try to debug this?

Here is my python code snippet:

stdscr=curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
global screen
screen = stdscr.subwin(23, 79, 0, 0)
screen.border()

while 1 == 1:
screen.addstr(5,5, str(time.localtime()))
screen.refresh()



When  run this, the local time is displayed ONCE, and then never changes. 
Why isn't the screen.refresh() command refreshing the display?

I'm running a terminal session from within KDE, but I didn't think this
would matter.

Any ideas to suggest?
-- 
Casey Bralla
Chief Nerd in Residence
The NerdWorld Organisation
http://www.NerdWorld.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intro to Pyparsing Article at ONLamp

2006-01-28 Thread Paul McGuire
Anton Vredegoor [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I like your article and pyparsing. But since you ask for comments I'll
 give some. For unchanging datafile formats pyparsing seems to be OK.
 But for highly volatile data like videotext pages or maybe some html
 tables one often has the experience of failure after investing some
 time in writing a grammar because the dataformats seem to change
 between the times one uses the script.

There are two types of parsers: design-driven and data-driven.  With
design-driven parsing, you start with a BNF that defines your language or
data format, and then construct the corresponding grammar parser.  As the
design evolves and expands (new features, keywords, additional options), the
parser has to be adjusted to keep up.

With data-driven parsing, you are starting with data to be parsed, and you
have to discern the patterns that structure this data.  Data-driven parsing
usually shows this exact phenomenon that you describe, that new structures
that were not seen or recognized before arrive in new data files, and the
parser breaks.  There are a number of steps you can take to make your parser
less fragile in the face of uncertain data inputs:
- using results names to access parsed tokens, instead of relying on simple
position within an array of tokens
- anticipating features that are not shown in the input data, but that are
known to be supported (for example, the grammar expressions returned by
pyparsing's makeHTMLTags method support arbitrary HTML attributes - this
creates a more robust parser than simply coding a parser or regexp to match
'A HREF=' + quotedString)
- accepting case-insensitive inputs
- accepting whitespace between adjacent tokens, but not requiring it -
pyparsing already does this for you

 For example, I had this
 experience when parsing chess games from videotext pages I grab from my
 videotext enabled TV capture card. Maybe once or twice in a year
 there's a chess page with games on videotext, but videotext chess
 display format always changes slightly in the meantime so I have to
 adapt my script. For such things I've switched back to 'hand' coding
 because it seems to be more flexible.


Do these chess games display in PGN format (for instance, 15. Bg5 Rf8 16.
a3 Bd5 17. Re1+ Nde5)? The examples directory that comes with pyparsing
includes a PGN parser (submitted by Alberto Santini).

 What I would like to see, in order to improve on this situation is a
 graphical (tkinter) editor-highlighter in which it would be possible to
 select blocks of text from an (example) page and 'name' this block of
 text and select a grammar which it complies with, in order to assign a
 role to it later. That would be the perfect companion to pyparsing.

 At the moment I don't even know if such a thing would be feasible...

There are some commercial parser generator products that work exactly this
way, so I'm sure it's feasible.  Yes, this would be a huge enabler for
creating grammars.

 Thank you for your ONLamp article and for making pyparsing available. I
 had some fun experimenting with it and it gave me some insights in
 parsing grammars.


Glad you enjoyed it, thanks for taking the time to reply!

-- Paul


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


Re: Match First Sequence in Regular Expression?

2006-01-28 Thread Armin Steinhoff
Alex Martelli wrote:
 Christoph Conrad [EMAIL PROTECTED] wrote:
 
 
Hello Roger,


since the length of the first sequence of the letter 'a' is 2. Yours
accepts it, right?

Yes, i misunderstood your requirements. So it must be modified
essentially to that what Tim Chase wrote:

m = re.search('^[^a]*a{3}b', 'xyz123aabbaaab')
 
 
 ...but that rejects 'aazaaab' which should apparently be accepted.

  ... and that is OK. That was the request:

 I'm looking for a regular expression that matches the first, and only
  the first, sequence of the letter 'a', and only if the length of the
  sequence is exactly 3.

--Armin

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


MYSql, CGI web page search code not working

2006-01-28 Thread Fred
OK,

I can now successfully enter data into my MySQL database through my CGI
web page. I can click a button and retrieve all the records, but I can
not seem to get the search code to work.

Below is the web page code and then my Python script. When I click my
search button it just gives me all the records

I know this line is executing: cursor.execute(Select * from phone
where name = name order by name)

Because I played with the order by but it seems to ignore my where
clause.

No matter what I type in the form text box (or even if I leave it
blank) I get all the records.

I can hard code this line to: cursor.execute(Select * from phone where
name = 'Fred' order by name)

and it returns the one record corectly.

Any ideas?

Fred

--
form action=cgi-bin/searchdata.py
 pEnter the name to find:
pinput type=text name=name size=30
input type=submit value=Search
/form
--

#!/usr/local/bin/python
print Content-Type: text/html\n
import MySQLdb
import cgi

db=MySQLdb.connect(host = 'localhost', db = 'phone')
cursor=db.cursor()
cursor.execute(Select * from phone where name = name order by name)

result = cursor.fetchall()
for record in result:
   print 'p'
   print record[0]
   print '--'
   print record[1]
   print '--'
   print record[2]
   print '--'
   print record[3]
   print '/p'

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


Re: Using non-ascii symbols

2006-01-28 Thread Jorge Godoy
Runsun Pan [EMAIL PROTECTED] writes:

 Can you guys figure out the details ?

 Here is the decoded version:

It looks that with all my 26 years I'm too old to understand something like
that...  All I can say is OMG... :-) 

 IMO, a language is a living organism, it has its own life and often
 evolves with unexpected turns. Maybe in the future some of those
 Martian Words will become part of formal Taiwanese, who knows ? :)

I am extremely against that for pt_BR (Brazilian Portuguese).  There's a TV
channel here that has some movies with net terms instead of pt_BR for the
translation...  

-- 
Jorge Godoy  [EMAIL PROTECTED]

Quidquid latine dictum sit, altum sonatur.
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems with documentation

2006-01-28 Thread Ron Rogers Jr.
BartlebyScrivener wrote:
 Specifically it's the TOPICS that I can't seem to get to work. The
 keywords and modules etc do work. But if I type, e.g.,
 help(functions) it says, No documentation found If I type
 help(os) I get help on the os module.
 
 rpd
 

The TOPICS seem to be case sensitve so

help assertion

would not work, but

help ASSERTION

will.


Just figured this out myself, yesterday.


CronoCloud (Ron Rogers Jr.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: textvariable help

2006-01-28 Thread Fredrik Lundh
swisscheese wrote:

 Thanks for the quick reply. With your reply and another tutorial I get
 it now. I needed self.Rows = ... in the constructor. I find myself
 wasting a lot of time with poor python docs. Whatever time Python is
 supposed to save I'm losing so far in looking up things. I suppose that
 will change as I get past the learning curve. Are you aware of any good
 docs on python that make it easy to find things?

just curious, but what documentation told you to use a class variable
in the way you did ?

/F



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


Re: Fast generation of permutations

2006-01-28 Thread Paul Rubin
Anton Vredegoor [EMAIL PROTECTED] writes:
  def deals():
  for i in xrange(13**5):
  cards = [(i//p) % 13 for p in (1, 13, 169, 2197, 28561)]
  yield cards
 
 This gives hands like [0,0,0,0,1] and [0,0,0,1,0] which are
 permutations of one another.

Yes, that's intentional, I thought the idea was to figure out the
probability of each type of poker hand, which means you have to
count those multiple occurrences.

 Below is a piece of code that avoids this.

Nice.

 Another hand, for example [0,0,1,2,3], would allow only 384 colorings,...
 Similar things happen for other partionings of the hands into numbers...
 
 This is very fascinating. Maybe someday I'll make a tkinter script with
 a visual tree structure allowing all kinds of numbers of cards, and
 arbitrary numbers of variables to partition by.

Cool, I'd still like to know why (13**5)-13 = C(52,5) other than
by just doing the arithmetic and comparing the results.  Maybe your
tkinter script can show that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Curses won't update screen - Solved!

2006-01-28 Thread Casey Bralla
My problem was caused by a getch() function which paused, waiting for the
character.  Live and learn.  sigh

For some reason, I can't get curses to refresh the screen.  Can someone
offer a suggestion to try to debug this?

Here is my python code snippet:

stdscr=curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
global screen
screen = stdscr.subwin(23, 79, 0, 0)
screen.border()

while 1 == 1:
        screen.addstr(5,5, str(time.localtime()))
        screen.refresh()

KeyPress = screen.getch()



When  run this, the local time is displayed ONCE, and then never changes. 
Why isn't the screen.refresh() command refreshing the display?

I'm running a terminal session from within KDE, but I didn't think this
would matter.

Any ideas to suggest?
-- 
Casey Bralla
Chief Nerd in Residence
The NerdWorld Organisation
http://www.NerdWorld.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: VB to Python migration

2006-01-28 Thread DH
see vb2py to help the conversion
http://vb2py.sourceforge.net/
or if you want to convert vb6 to vb.net instead, there are tools from 
microsoft and others to help with that, such as:
http://www.microsoft.com/downloads/details.aspx?FamilyId=10C491A2-FC67-4509-BC10-60C5C039A272displaylang=en

or if you want to start over from scratch, the other recommendations are 
good, like pyqt and qt designer, or else do it as a web app instead of 
desktop app if it just involves basic form controls.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Diez B. Roggisch
 
 db=MySQLdb.connect(host = 'localhost', db = 'phone')
 cursor=db.cursor()
 cursor.execute(Select * from phone where name = name order by name)

You don't parametrize the query. The where-clause thus is a tautology, 
as the name is always the name.

Do something like this:


cursor.execute(Select * from phone where name = ? order by name, (name,))


Actually it might be necessary to use something different from the ? to 
specify the parameter - that depends on the paramstyle of your DB-Api. 
Check that in the interpreter with

import MySQLdb
print mySQLdb.paramstyle



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


Re: textvariable help

2006-01-28 Thread swisscheese
None - it was a false impression I got somehow.

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


Re: [IDE] - The Dynamic Opportunity - ActiveState Komodo IDE / Open Source

2006-01-28 Thread Scott David Daniels
Ilias Lazaridis wrote:
 As a first step, a free personal edition (non-commercial and academic
 use) would help to spread the Komodo IDE within the communities.
Yeah, and ActiveState makes up the loss in income on volume, eh?
I've got no problem paying for good work.

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


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Fred
print MySQLdb.paramstyle returns: format

I found one example like this:

cursor.execute('''Select * from phone where name=%s order by
name''',(name))

But I get this in my Apache error log:
NameError: name 'name' is not defined

Like my last problem I posted, I am sure it is something very simple
that I am missing!!
Fred

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


Re: writing large files quickly

2006-01-28 Thread Scott David Daniels
Jens Theisen wrote:
 Ivan wrote:
 I read somewhere that it has a use in database software, but the only
 thing I can imagine for this is when using heap queues
 (http://python.active-venture.com/lib/node162.html).

I've used this feature eons ago where the file was essentially a single
large address space (memory mapped array) that was expected to never
fill all that full.  I was tracking data from a year of (thousands? of)
students seeing Drill-and-practice questions from a huge database of
questions.  The research criticism we got was that our analysis did not
rule out any kid seeing the same question more than once, and getting
practice that would improve performance w/o learning.  I built a
bit-filter and copied tapes dropping any repeats seen by students.
We then just ran the same analysis we had on the raw data, and found
no significant difference.

The nice thing is that file size grew over time, so (for a while) I
could run on the machine with other users.  By the last block of
tapes I was sitting alone in the machine room at 3:00 AM on Sat mornings
afraid to so much as fire up an editor.

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


Re: Python vs C for a mail server

2006-01-28 Thread Alex Martelli
Jens Theisen [EMAIL PROTECTED] wrote:
   ...
 Please don't be offended, but if anyone could make a point of how Python's
 disadvantages in these regards could be alleviated, I'd be very  
 interested.

http://www.artima.com/weblogs/viewpost.jsp?thread=4639
http://www.mindview.net/WebLog/log-0025

Since Robert Martin and Bruce Eckel (the authors of the two documents
linked above) are both acknowledged gurus of statically typechecked
languages such as C++, the convergence of their thinking and experience
indicated by those documents is interesting.

Tools such as pychecker, pylint, etc, are also considered by some to be
a useful backstop, but unit-tests are the real answer.

The but without declaration it can't be self-documenting issue is a
red herring.  Reading, e.g.:

int zappolop(int frep) { ...

gives me no _useful_ self-documenting information about the role and
meaning of frep, or zappolop's result.  The code's author must obviously
add a little comment here to clarify -- and in that little comment,
adding the information about type, if at all relevant, is an obvious
task.

At Google, we collectively have rather a lot of experience in these
issues, since we use three general-purpose languages: Python, Java, C++.
In this mix, the role of C++ is essentially that of allowing the
programmer to have complete control on memory allocation issues: the
only widespread modern language to do that, since all others, including
both Java and Python, have garbage-collection.  In the internal style
guide for C++, we forbid the use of so-called ``smart'' pointers which
would basically amount to a hacked-up garbage collection system (which
can never be as solid and thorough as those built into the virtual
machines used in Java or Python -- a GC system that's thread-safe is a
nightmare to build and debug based only on those smart pointers, for
example, and if you start locking and mutexing all over the place for
that purpose you'll soon see performance plummet...): if you want
garbage collection you use a garbage-collected language -- the choice of
C++ for a component implies that you need complete control of memory
issues for that component, therefore choosing C++ and ``too smart for
their own good'' pointers would be mutually contradictory.  Our style
guides for all languages also impose using unit-tests, code reviews, and
standard formats for internal documentation, from naming of variables,
functions and classes to structure and form of comments.  As a result,
quality and reliability are remarkably consistent and uniform.

We could say that Python is Google's secret weapon, except it's not so
very secret, since, in order to attract and hire Python experts, we do
of course need to let it be known that Python's important to us;-).  In
a sense, I guess, we are fortunate that our competitors still appear not
to be fully aware of this -- it gives us a better chance to hire Python
luminaries and maintain a productivity edge;-).


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


Re: Python vs C for a mail server

2006-01-28 Thread Nicolas Lehuen
Jens Theisen wrote:
 Please don't be offended, but if anyone could make a point of how Python's
 disadvantages in these regards could be alleviated, I'd be very
 interested.

 Jens

Well, I write Java, C++ and Python code, and I have posted a few
thoughts about this on my blog :

http://nicolas.lehuen.com/

My two latest problems with coding in C++ are due to the environments :
libraries using different string types and the whole problem with the
building system. I love the language, but I get a much better leverage
through Python and Java due to the quality and ease of use of their
built-in and third party libraries. I use C++ only for my core data
structure (namely a tuned version of a ternary search tree which I use
to build full text indices).

Regards,
Nicolas

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


Re: Efficient Find and Replace

2006-01-28 Thread Scott David Daniels

Murali wrote:
  Given: L = list of integers. X and Y are integers.
  Problem: find every occurrence of X and replace with Y

  Problem with both solutions is the efficiency.

As everyone else says, you are hallucinating efficiency problems
probably brought on by an overdose of Lisp or ML.  Here is another
way to get to what you want that will go even faster than the
not-a-problem speed you have from simple compare and replace.

 lst = range(50) * 10
 try:
 position = lst.index(X)
 while True:
 lst[position] = Y
 position = lst.index(X, position + 1)
 except ValueError:
 pass   # finally could not find X

I mention this only because people always seem to forget than index 
allows you to specify a start (and/or stop) position w/in the list.

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


Re: writing large files quickly

2006-01-28 Thread Tim Peters
[Jens Theisen]
 ...
 Actually I'm not sure what this optimisation should give you anyway. The
 only circumstance under which files with only zeroes are meaningful is
 testing, and that's exactly when you don't want that optimisation.

In most cases, a guarantee that reading uninitialized file data will
return zeroes is a security promise, not an optimization.  C doesn't
require this behavior, but POSIX does.

On FAT/FAT32, if you create a file, seek to a large offset, write a
byte, then read the uninitialized data from offset 0 up to the byte
just written, you get back whatever happened to be sitting on disk at
the locations now reserved for the file.  That can include passwords,
other peoples' email, etc -- anything whatsoever that may have been
written to disk at some time in the disk's history.  Security weenies
get upset at stuff like that ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: General Type Checks (int, str, tuple, etc.)

2006-01-28 Thread Scott David Daniels
Fabian Steiner wrote:
 Hello!
 
 So far, I am using something like »if isinstance(var, int):« to 
 determine, whether var's value is an integer. Now I would like to know 
 if there is any better possibility to do such general checks or may a 
 construct with isinstance() even fail in certain cases?

The general rule is: don't check, let it fail if it wants to.
If you are looking for an integral value check, you might prefer:

isinstance(x, (int, long))

but again, think long and hard about your requirements.  Embrace
dynamic typing; don't try to write your old language in Python.

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

Re: writing large files quickly

2006-01-28 Thread Ivan Voras
Jens Theisen wrote:

 cp bigfile bigfile2
 
 cat bigfile  bigfile3
 
 du bigfile*
 8   bigfile2
 1032bigfile3
 
 So it's not consumings 0's. It's just doesn't store unwritten data. And I  

Very possibly cp understands sparse file and cat (doint what it's 
meant to do) doesn't :)


I read somewhere that it has a use in database software, but the only
thing I can imagine for this is when using heap queues
(http://python.active-venture.com/lib/node162.html).
 
 That's an article about the heap efficient data structure. Was it your  
 intention to link this?

Yes. The idea is that in implementing such a structure, in which each 
level is 2^x (x=level of the structure, and it's depentent on the 
number of entries the structure must hold) wide, most of blocks could 
exist and never be written to (i.e. they'd be empty). Using sparse 
files would save space :)

(It has nothing to do with python; I remembered the article so I linked 
to it; The sparse-file issue is useful only when implementing heaps 
directly on file or in mmaped file).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient Find and Replace

2006-01-28 Thread Murali
Thanks for the replies. I always thought that Python lists were
actually lists under the hood. If they are implemented as arrays of
pointers things should be a lot more efficient. In particular what I
thought was a Linear-time operation is actually an O(1) operation.

Since python allows you to replace single items with lists e.g.
L[x:x+1]= [a,b,c], It has to be a little more clever. But with
good data structure design I beleive that this overhead can be
amortized to O(1).

The optional argument to lst.index also makes that an linear time code.
Thanks for all the help.

- Murali

PS: Slowly python is becoming my more favourite language than even C
(except in cases you just cannot use anything but C, e.g. writing a
boot loader)

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


Re: beta.python.org content

2006-01-28 Thread Scott David Daniels
Terry Hancock wrote:
 On Fri, 27 Jan 2006 13:44:19 -0800
 Scott David Daniels [EMAIL PROTECTED] wrote:
 Paragraph 3 in Why Python:
 and later in that paragraph, I'd change:
  ... extensions that provide compact numerical
  solutions
 to:
  ... extensions that provide compact high-speed
  numerical solutions
 
 And while we're at it, let's say Python is a language for
 programming high-speed, digital, electronic computers. Do
 you have any experience with high-speed, digital, electronic
 computers?

The reason I included high-speed is that the paragraph is
responding to its topic sentence:

 Some people (s)uppose because Python is an interpreted language
 that it is slow and unsuitable for scientific and engineering tasks.
 ... Python's easy extensibility has allowed ... extensions that
 provide compact numerical solutions.

I am simply saying that compact numerical solutions doesn't really
address the question of whether they are too slow.

  For those who are too young, or weren't film students, the
  answer is Yes, my aunt has one.
Well, I am definitely not too young, but I was never a film student.
What movie?

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


Re: We have zipimport, how about dllimport?

2006-01-28 Thread M�ta-MCI
ctypes ?


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


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Kirk McDonald
Fred wrote:
 No matter what I type in the form text box (or even if I leave it
 blank) I get all the records.

Try this:

#!/usr/local/bin/python
print Content-Type: text/html\n
import MySQLdb
import cgi

db=MySQLdb.connect(host = 'localhost', db = 'phone')
cursor=db.cursor()
cursor.execute(Select * from phone where name=%s order by name, (name,))

result = cursor.fetchall()
for record in result:
 print 'p'
 print record[0]
 print '--'
 print record[1]
 print '--'
 print record[2]
 print '--'
 print record[3]
 print '/p'

(Assuming the name of your text field is name.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Fred
Yeah, I already tried that (except you have a , after name.

Your code produces the same error:

 NameError: name 'name' is not defined

I know I am close!! Just missing some small thing...

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


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Kirk McDonald
Fred wrote:
 Yeah, I already tried that (except you have a , after name.
 
 Your code produces the same error:
 
  NameError: name 'name' is not defined
 
 I know I am close!! Just missing some small thing...
 

Oh, duh. I forgot something:

#!/usr/local/bin/python
print Content-Type: text/html\n
import MySQLdb
import cgi

form = cgi.FieldStorage()

db=MySQLdb.connect(host = 'localhost', db = 'phone')
cursor=db.cursor()
cursor.execute(Select * from phone where name=%s order by name,
 (form['name'].value,))

result = cursor.fetchall()
for record in result:
 print 'p'
 print record[0]
 print '--'
 print record[1]
 print '--'
 print record[2]
 print '--'
 print record[3]
 print '/p'

The comma is intentional: the MySQLdb wants the argument(s) as a tuple.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Returning a value from code string

2006-01-28 Thread Kirk McDonald
Max wrote:
 Kirk McDonald wrote:
 
 Another kind of node (I'm still deciding
 whether to call them Codenodes or Opcodes or maybe Pynodes) is a chunk
 of code that can be asked to run itself, and which can be edited, on 
 the fly, from within the website. Thus, one can both alter the 
 functionality of the site, and add functionality, from the site itself 
 (so long as you have the user permissions to do so).

 
 As Steven said, U R pwn3d. 1f you d0n't sp3a| l33t (if you don't 
 speak leet), that means you are screaming hack me, use me to launch 
 attacks on other computers, and than attack my computer. Unless you 
 have some revolutionary ideas in code-security analysis. In which case 
 you can a lot more money than from implementing Everything2 in python.
 
 --Max

Heavens! Normal users can't edit code! They won't even see it! I'm not a 
*total* moron. The only thing users will be able to enter is some 
simplified HTML. This is a convenience feature for the (trusted) admins 
of the site. There are some simple permission features built into the 
API. Every database-altering API call takes the current user as an 
argument, and if they're not allowed, it tells them to get bent.

Everything2 does this more or less the same way, and they've had few 
issues in the seven or so years they've been operating.

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


Re: writing large files quickly

2006-01-28 Thread Bengt Richter
On Fri, 27 Jan 2006 12:30:49 -0800, Donn Cave [EMAIL PROTECTED] wrote:

In article [EMAIL PROTECTED],
 rbt [EMAIL PROTECTED] wrote:
 Won't work!? It's absolutely fabulous! I just need something big, quick 
 and zeros work great.
 
 How the heck does that make a 400 MB file that fast? It literally takes 
 a second or two while every other solution takes at least 2 - 5 minutes. 
 Awesome... thanks for the tip!!!

Because it isn't really writing the zeros.   You can make these
files all day long and not run out of disk space, because this
kind of file doesn't take very many blocks.   The blocks that
were never written are virtual blocks, inasmuch as read() at
that location will cause the filesystem to return a block of NULs.

I wonder if it will also write virtual blocks when it gets real
zero blocks to write from a user, or even with file system copy utils?

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Fred
Thanks Kirk! That worked perfect! And makes perfect since now that I
see it...

Now that I have the main pieces working I can start expanding from
here!

Fred

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


Calling DLL with several data fields in output params

2006-01-28 Thread Java script Dude
Hi,

I basically need to write a script that will make calls to a DLL and
parse the return result for API calls that consist of several data
fields in the input and output parameters.

[Questions]
[q1] Is ctypes the right Python library to use for this interaction.
. . . . . I know about calldll but it seems quite poorly documented.
[q2] Are there any existing windows DLLs that one could use to build
simplified test code.
. . . . . One that has several input and output parameters and playing
with it will not kill my system.
. . . . . Also, I'd rather not have to learn how to write a DLL to
build a test case.

BTY - I have not decided on the language yet but would love to do this
in Python. Although, I am considering writing in C++ (me_b_newbie) -or-
JNI (it_b_ugly) -or- Obj-C (it_b_cool). MS languages are not an option
in my book :}

Thanks,
JsD

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


Re: We have zipimport, how about dllimport?

2006-01-28 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
 I may be on particularly potent crack, but I was wondering whether it
 would make sense to distribute python code in DLLs so that the memory
 occupied by the bytecode would be consumed only once even if there were
 multiple processes using the same bytecode. Or is there another way to
 accomplish code sharing?

That wouldn't help much: as soon as a .pyc file is imported, it is
passed to the marshal module, which will create a code object out
of it (copying the actual data in the pyc file). Then, this code
object gets executed, containing import, def, and other statements.
The def statements, in turn, result in yet other code objects being
created, copying fragments of the original code object. Then, the
original code object is discarded (and its memory released).

So typically, you have two levels of copying, each involving interaction
with the per-process memory management. There is little hope for sharing
here.

 Of course I don't need the functionality right this week, but
 capability of running shared code is one of the advantages of natively
 compiled languages and someone must already have thought of this and
 knows why it would never work. ;-)

It's an advantage only if the code occupies a signifcant portion of the
memory. In bytecode languages, byte code is much more compact than
machine code, so there is comparatively little opportunity for savings.

OTOH, in *JIT* languages, the JIT code again counts for something,
and it typically has to be generated for each process. That's why
Microsoft's .NET has ngen.exe, the ahead-of-time (traditional)
compiler. The primary rationale is not sharing, though, but reducing
the startup time. In .NET 2.0, there is even an OS service that
creates compiled images of IL byte code.

LISP and Smalltalk implementations have yet another approach: the image.
They dump everything in memory into a disk file which can then be mapped
into memory. This image is created after all the loading indirections
and copies, and so constitutes the final form. So on the plus side,
this allows for sharing of code across multiple instances of the same
application. On the minus side, each Smalltalk application needs its
own image (even if they share a lot of code).

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


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Fred
OK one more... how would I do a LIKE instead of a = in this code?

 cursor.execute(Select * from phone where name=%s order by name,
 (form['name'].value,))

Right off I think:

 cursor.execute(Select * from phone where name like %%s% order by
name,
 (form['name'].value,))

But it blows up...

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


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Fred
Perfect again Kirk! Now I will study all this so I actually understand
what is happening..

Thanks!

Fred

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


User login system

2006-01-28 Thread sophie_newbie
Can anyone recommend an open source user login system already written
in Python that I could use with my site?

Simplicity is the most important factor, but the ability to track users
using cookies would be helpful.

Hopefully somebody knows one?

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


Re: User login system

2006-01-28 Thread Jorge Godoy
sophie_newbie [EMAIL PROTECTED] writes:

 Can anyone recommend an open source user login system already written
 in Python that I could use with my site?

 Simplicity is the most important factor, but the ability to track users
 using cookies would be helpful.

 Hopefully somebody knows one?

Take a look at TurboGears Identity module and at PEAK.security...  

-- 
Jorge Godoy  [EMAIL PROTECTED]

Quidquid latine dictum sit, altum sonatur.
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: indentation messing up my tuple?

2006-01-28 Thread localpricemaps
sorry i forgot to add in the code for my tuple which is at the very end

tuple = (food+ drink + \n)
data.append(tuple)
f = open(froogle.sql, 'a')
f.write ( ''.join( tuple )

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


Re: indentation messing up my tuple?

2006-01-28 Thread localpricemaps
sorry i left out my tuple which is at the end of my code

tuple = (food + drink + \n)
data.append(tuple)
f = open(froogle.sql, 'a')
f.write ( ''.join( tuple )

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


Re: VB to Python migration

2006-01-28 Thread Thomas Ganss
Josh schrieb:

You haven't specified where your main pains are.
Do you have at least rudimentary architecture ?
How often do you have code reviews / refactored your code ?
Have you been striving for good code ? Is it a total mess ?

Guessing only from the number of screens, you probably
have more than trivial amounts of data.

*Based on that assumption*, I'ld move the data FIRST.
Get rid of the JET engine! If you are certain you will
have to support SQL server, make it SQL server and
MSDE/new express version first. Only then (perhaps)
think about adding a totally free database engine.
If not, take your pick but *move the data*.

While you are on it, refactor the old code into something
at least resembling a 3 to 5 layered approach with COM.
Doesn't need to be perfect 100%, but more than 50%.

Then exchange the parts that benefit the most by
implementation inheritance, since VB's interface inheritance
is arguably the best technical reason for redundant code.

I'ld guess the business layer[s] would be the next things to convert -
but if your VB-forms are mostly slightly augmented copies differing
only slightly, the GUI actually might benefit most from a rewrite,
if the business rules are written redundance poor.

One of the typical scenarios asking for GUI inheritance
is insurance - customer data is only specific for few fields
and even policy field groupings resemble each other across
similar policies. A minmally redundant business layer could
even in VB be implemented without too much sweat- for instance
by having methods overwritten in a inheritance based OOP -
design as name mangled methods on objects responsible across
similar problem domains, keeping the common methods clean.

Check your code with a critical eye -
even code forced to be totally OOP for

technical reason=langauge

can be written across a wide spectrum of quality.

If there is nothing which is good enogh to be converted last
or no segregation/layering at all in the current program,
(even if it came from the DOS dinosaurs, there were
good coding practices known - some of the old libraries
were better decoupled than modern day OOP class libraries.)
get rid of most of the people responsible and start only then.

my 0.02 EUR

thomas



 We have a program written in VB6 (over 100,000 lines of code and 230 UI 
 screens) that we want to get out of VB and into a better language. The 
 program is over 10 years old and has already been ported from VB3 to 
 VB6, a job which took over two years. We would like to port it to 
 Python, but we need to continue to offer upgrades and fixes to the 
 current VB6 version. Does anybody know of ways we could go about 
 rewriting this, one screen at a time, in Python, and calling the screens 
 from the existing program?
 
 We are also looking for a graphics toolkit to use. IronPython with it's 
 .NET bindings and ability to integrate with Visual Studio looks good, 
 but leaves that bad MS taste in the mouth.
 
 We currently use a MS Access back end and need to migrate to a proper 
 SQL server. We need to leave options open for SQL Server (for customers 
 who want to use existing infrastructure) and something like MySQL or 
 PostgreSQL. But in the mean time, we need to be able to access an 
 MSAccess (Jet) database from Python.
 
 Any answers/suggestions/pointers are greatly appreciated.
 
 Thanks,
 
 Josh Isted
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking free disk space on Win32 ?

2006-01-28 Thread [EMAIL PROTECTED]
You might find the following interesting too
http://unpythonic.net/jeff/tkdu/

Cheers,
Davy Mitchell

Mood News
 - BBC News Headlines Auto-Classified as   Good,   Bad or   Neutral.
 http://www.latedecember.com/sites/moodnews/

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


Re: Python vs C for a mail server

2006-01-28 Thread Grant Edwards
On 2006-01-28, Steven D'Aprano [EMAIL PROTECTED] wrote:

 I am a novice in python.I have to implement a full fledged mail server

 Because that's just what the world needs, yet another mail server.

:)

 C can be faster.

And can be is the key.  It's easy to write slow programs in C
if you don't choose the right algorithms and architecture.

 which language will be easier? 

 Python is easier to read, and write, and debug, and you will
 have fewer hard-to-debug memory issues.

And you'll have fewer security issues with Python since you
don't have to worry about buffer and stack exploits.

-- 
Grant Edwards   grante Yow!  There's enough money
  at   here to buy 5000 cans of
   visi.comNoodle-Roni!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: textvariable help

2006-01-28 Thread James Stroud
swisscheese wrote:
 Thanks for the quick reply. With your reply and another tutorial I get
 it now. I needed self.Rows = ... in the constructor. I find myself
 wasting a lot of time with poor python docs.

I have found the standard library documentation amazingly well written:

http://www.python.org/doc/


 Whatever time Python is
 supposed to save I'm losing so far in looking up things. I suppose that
 will change as I get past the learning curve.

Python will save you a lot of time when you come back to your code 6 
months later and when you begin to get some competence at the more 
esoteric aspects of python, like generators, closures, and magic methods.

 Are you aware of any good
 docs on python that make it easy to find things?

It depends on your task. Jumping into GUI programming without a solid 
grasp of the language you are writing in can be frustrating. In fact 
jumping into GUI programming at all can be frustrating.

I learnt from Learning Python by O'Reilly. Beyond that I highly 
recommend Python Programming. I especially recommend chapters 2, 3, 6, 
7, and 8 of the latter. If you have the time, try to get through as much 
of both of those as you can. Beyond that, you may want to keep a copy of 
Python in a Nutshell by your keyboard. I use the classic Python 
Essential Reference, which is now pretty dated.

If you have not worked through a tutorial on python basics, you should 
really stop what you are doing and spend a few hours doing that. It will 
make you much more pleased with the language.

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


String Manipulation Help!

2006-01-28 Thread Dave
OK, I'm stumped.

I'm trying to find newline characters (\n, specifically) that are NOT
in comments.

So, for example (where - = a newline character):
==
1: -
2: /*-
3: ---
4: comment-
5: ---
6: */-
7: -
8: CODE CODE CODE-
9: -
==

I want to return the newline characters at lines 1, 6, 7, 8, and 9 but
NOT the others.

I've tried using regular expressions but I dislike them because they
aren't immediately readable (and also I don't bloody understand the
things). I'm not opposed to using them, though, if they provide a
solution to this problem!

Thanks in advance for any suggestions anyone can provide.

- Dave

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


Re: MYSql, CGI web page search code not working

2006-01-28 Thread Kirk McDonald
Dennis Lee Bieber wrote:
 On Sat, 28 Jan 2006 10:14:44 -0800, Kirk McDonald [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:
 
 
 
The comma is intentional: the MySQLdb wants the argument(s) as a tuple.
 
 
   The DB-API wants tuples... But my last perusal of the MySQLdb Python
 code showed that it would work with naked singletons...

Ah! So it does. However, I still pass 'em as a tuple as a matter of 
course, since it's documented that way. *shrug* (Also, it saves that 
many keystrokes if I need to add arguments.)

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


Re: [IDE] - The Dynamic Opportunity - ActiveState Komodo IDE / Open Source

2006-01-28 Thread Ilias Lazaridis
Scott David Daniels wrote:
 Ilias Lazaridis wrote:
 
 As a first step, a free personal edition (non-commercial and academic
 use) would help to spread the Komodo IDE within the communities.
 
 Yeah, and ActiveState makes up the loss in income on volume, eh?

The personal edition costs currently $29,95.

A $0,- personal edition would spread around quickly.

Commercial users still have to order/upgrade the professional version 
($295,-).

 I've got no problem paying for good work.

This is not about paying for good work or not.

It is about an opportunity for ActiveState and the dynamic language 
communities.

-

It is about a weaknesses-of [1] and upcoming/existent threats-for [2] 
the ActiveState Komodo IDE.

After implementing the initial step (free personal edition), the 
situation would change slightly:

*Strength*: free edition for non-commercial and educational use *available*.

*Strength*: simplified distribution due to no-cost version (which could 
be packaged e.g. within distributions which have not strict open-source 
requirements. ActiveState would keep his rights).

Those (and the other existent) strengths would not be enouth to deal 
with the threat [2].

Further steps would be necessary (like a step by step transformation to 
open source).

The NetBeans IDE [end of 2004 - current status unknown] contained 
several non-open-source binaries, thus it was partial open source and 
not open source, as it was marketed.

ActiveState could follow this example initially (whilst clarifying the 
status patial open source of course).

Step by step, more and more binaries would be released into open source, 
allowing this way ActiveState to go slowly through the process of 
applying the necessary changes (including 'mentality'-change of the 
staff and the developers).

The license could(!) be similar to the eclipse foundation's one.

-

Hope this has clarified the topic further.

-
-
-

both excerpts below are taken from:
http://lazaridis.com/samples/com/ActiveState/product.html

[1]

*Weakness*

 * Komodo Free Edition Not Available
   o Could have e.g. negative influence on Open-Source-Communities
   o Reduces distribution

*Suggestion*

a) Initial Step: ActiveState should make the Komodo personal edition 
free of charge.
*Commercial* users still need to upgrade to the *professional* version 
for a license fee.

*Benefit*

This would most possibly lead to *spreading* the IDE *widely* within the 
dynamic language communities and would attract users which look for a 
free IDE (which partially will update to the professional version).

A free edition would *simplify* the *download* procedure drastically. A 
link get the free personal edition from the main page would be enough. 
No license-key required. Quick, Easy and no hassle - get an IDE for 5 
dynamic languages.


-

[2]

Threats

eclipse dynamic language support - http://www.eclipse.org/proposals/dltk/
upcoming competitive IDE's (based on eclipse or others)



.

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


Re: String Manipulation Help!

2006-01-28 Thread Kirk McDonald
Dave wrote:
 OK, I'm stumped.
 
 I'm trying to find newline characters (\n, specifically) that are NOT
 in comments.
 
 So, for example (where - = a newline character):
 ==
 1: -
 2: /*-
 3: ---
 4: comment-
 5: ---
 6: */-
 7: -
 8: CODE CODE CODE-
 9: -
 ==

[snip]

Well, I'm sure there is some regex that'll do it, but here's a stupid 
iterative solution:

def newlines(s):
 nl = []
 inComment = False
 for i in xrange(len(s)):
 if s[i:i+2] == '/*':
 inComment = True
 if s[i:i+2] == '*/':
 inComment = False
 if inComment: continue
 if s[i] == '\n':
 nl.append(i)
 return tuple(nl)

Your example returns:
(0, 64, 65, 80, 81)

This probably isn't as fast as a regex, but at least it works.

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


Re: - The Dynamic Opportunity - ActiveState Komodo IDE / Open Source

2006-01-28 Thread tclguy
*Weakness*

* Komodo Free Edition Not Available
   o Could have e.g. negative influence on Open-Source-Communities
   o Reduces distribution 

You logic is badly flawed.

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


Calling C++ function from python script

2006-01-28 Thread Pankaj
The module which i am creating is like

Part A:
1. It does some processing by using python code.
2. The result of this python code execution is written to a text file.
[This part is already compelete]]

Part B:
1. I read a text file which is outputted by above python script in a
C++ program
2. and again output of this c++ code is text file
[This part is as well complete with graph data structure construction
part involved, which i feel can be done in better way in C++ than in
python]

Now i want to integrate this flow.

The communication between part A and part B is by call to a function
present in C++
How should i do that? 
Kindly suggest some ways.

Regards
Pankaj

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


Re: Checking free disk space on Win32 ?

2006-01-28 Thread M�ta-MCI
Hi!

Fun.
Slow, but fun.
Thanks.

@-salutations

Michel Claveau



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


Re: String Manipulation Help!

2006-01-28 Thread Dave
This is great, thanks!

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


Re: User login system

2006-01-28 Thread Alex Martelli
Jorge Godoy [EMAIL PROTECTED] wrote:

 sophie_newbie [EMAIL PROTECTED] writes:
 
  Can anyone recommend an open source user login system already written
  in Python that I could use with my site?
 
  Simplicity is the most important factor, but the ability to track users
  using cookies would be helpful.
 
  Hopefully somebody knows one?
 
 Take a look at TurboGears Identity module and at PEAK.security...  

Twisted's cred is another possibility.


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


Re: - The Dynamic Opportunity - ActiveState Komodo IDE / Open Source

2006-01-28 Thread Ilias Lazaridis
[EMAIL PROTECTED] wrote:
*Weakness*

   * Komodo Free Edition Not Available
  o Could have e.g. negative influence on Open-Source-Communities

My apologies for the inconvenience.

The corrected sentence:

Could have negative influence on image (e.g. within 
Open-Source-Communities ) 

http://lazaridis.com/samples/com/ActiveState/product.html

  o Reduces distribution 
 
 You logic is badly flawed.

My statements are normally backupd by rationales.

You can simply verify their validity.

-

Reduces distribution

I think no one can doubt that a free version (ideally one which can be 
redistributed freely) increases the distribution of a product.

simplified distribution due to no-cost version (which could be packaged 
e.g. within distributions which have not strict open-source 
requirements. ActiveState would keep his rights). 

-

The simplified download should be undoubtable, too:

A free edition would simplify the download procedure drastically. A 
link get the free personal edition from the main page would be enough. 
No license-key required. Quick, Easy and no hassle - get an IDE for 5 
dynamic languages.

-

Thank you for notifying me about the wrong wording.

.

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


Re: String Manipulation Help!

2006-01-28 Thread Paul McGuire
Dave [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 OK, I'm stumped.

 I'm trying to find newline characters (\n, specifically) that are NOT
 in comments.

 So, for example (where - = a newline character):
 ==
 1: -
 2: /*-
 3: ---
 4: comment-
 5: ---
 6: */-
 7: -
 8: CODE CODE CODE-
 9: -
 ==

 I want to return the newline characters at lines 1, 6, 7, 8, and 9 but
 NOT the others.


Dave -

Pyparsing has built-in support for detecting line breaks and comments, and
the syntax is pretty simple, I think.  Here's a pyparsing program that gives
your desired results:

===
from pyparsing import lineEnd, cStyleComment, lineno

testsource = 
/*
--
comment
--
*/

CODE CODE CODE



# define the expression you want to search for
eol = lineEnd

# specify that you don't want to match within C-style comments
eol.ignore(cStyleComment.leaveWhitespace())

# loop through all the occurrences returned by scanString
# and print the line number of that location within the original string
for toks,startloc,endloc in eol.scanString(testsource):
print lineno(startloc,data)
===

The expression you are searching for is pretty basic, just a plain
end-of-line, or pyparsing's built-in expression, lineEnd.  The curve you are
throwing is that you *don't* want eol's inside of C-style comments.
Pyparsing allows you to designate an ignore expression to skip undesirable
content, and fortunately, ignoring comments happens so often during parsing,
that pyparsing includes common comment expressions for C, C++, Java, Python,
and HTML.  Next, pyparsing's version of re.search is scanString.  scanString
returns a generator that gives the matching tokens, start location, and end
location of every occurrence of the given parse expression, in your case,
eol.  Finally, in the body of our for loop, we use pyparsing's lineno
function to give us the line number of a string location within the original
string.

About the only real wart on all this is that pyparsing implicitly skips over
leading whitespace, even when looking for expressions to be ignored.  In
order not to lose eols that are just before a comment (like your line 1), we
have to modify cStyleComment to leave leading whitespace.

Download pyparsing at http://pyparsing.sourceforge.net.

-- Paul


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


Decoupling the version of the file from the name of the module.

2006-01-28 Thread bobueland
I'm a newbie experimenting with Python. I want to incrementally develop
a module called 'circle'. The problem is now that the file name is used
for two purposes. To keep track of the version number and as the name
for the module. So when I develop the first version of my file I have
to call it circle_a.py. The name of the module then automatically
becomes circle_a. But when I develop the next increment and call my
file circle_b.py the module name changes as well.

Basically I want to decouple the version of my file from the name of
the module.

Is there a *simple* way out of this dilemma.

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


Re: Decoupling the version of the file from the name of the module.

2006-01-28 Thread Xavier Morel
[EMAIL PROTECTED] wrote:
 I'm a newbie experimenting with Python. I want to incrementally develop
 a module called 'circle'. The problem is now that the file name is used
 for two purposes. To keep track of the version number and as the name
 for the module. So when I develop the first version of my file I have
 to call it circle_a.py. The name of the module then automatically
 becomes circle_a. But when I develop the next increment and call my
 file circle_b.py the module name changes as well.
 
 Basically I want to decouple the version of my file from the name of
 the module.
 
 Is there a *simple* way out of this dilemma.
 

You have two choices:

1- Just get rid of the version number in the name (what's the point) and 
define a __version__ attribute in the module, that's what is usually done.
2- create a wrapper module called circle.py whose content will be 
something along the lines of from your_current_module_with_version 
import *

I'd strongly suggest the first choice, there is no point in giving the 
version number into the file name of a module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decoupling the version of the file from the name of the module.

2006-01-28 Thread Kirk McDonald
[EMAIL PROTECTED] wrote:
 I'm a newbie experimenting with Python. I want to incrementally develop
 a module called 'circle'. The problem is now that the file name is used
 for two purposes. To keep track of the version number and as the name
 for the module. So when I develop the first version of my file I have
 to call it circle_a.py. The name of the module then automatically
 becomes circle_a. But when I develop the next increment and call my
 file circle_b.py the module name changes as well.
 
 Basically I want to decouple the version of my file from the name of
 the module.
 
 Is there a *simple* way out of this dilemma.
 

I would recommend just naming the file circle.py, and defining something 
like a variable named __version__ or maybe __revision__ at the top of 
the module. Then you can, I don't know, back up your old versions to 
other filenames or something.

Or, if you really want to do this right, you could install Subversion. :-)

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


Re: Decoupling the version of the file from the name of the module.

2006-01-28 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 Basically I want to decouple the version of my file from the name of
 the module.
 
 Is there a *simple* way out of this dilemma.

Really, you should use a source control system.  That's a program that
tracks the different versions of the files in your program.  When one
of your files reaches a state of stability, you check it in to a
source repository which then remembers that version.  You then go on
editing the file in place.  Later, you can restore the old version
from the repository if you need to.

Source control is the only sane way to do what you're trying to do.
Messing around with renaming files to save old versions, as you're
doing, only works for very small, short-lived projects.  That scheme
will drive you crazy in short order.

SubVersion (http://subversion.tigris.org) is a popular source control
system, maybe not the best, but compatible with some older widely used
ones.  I'd personally choose this one because I have some experience
with it, but it's not ideal.  Even if you don't choose to use it, you
might read its online docs, to get a sense of what kinds of problems
these programs try to solve.

There's a newer one called Codeville, written in Python, that I
haven't tried.  There are numerous others I won't bother trying to
list.  Which one is best is the topic of religious wars, like the
best editor or the best language.  Just pick one that you like and
stick with it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SLUT distibution mangled?

2006-01-28 Thread Ido Yehieli
So I can't run SLUT on windows then?

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


Python loading library containing embedded python...

2006-01-28 Thread Brennus

I have a dll/so which embeds python. I can verify it works by
compiling it as an executable and adding an appropriate main.

I tried to write unit tests for this library with ctypes and a simple
python script. Access violations and other strange things result. I
suspect this is because I am basically embedding python in python at
this point.

How can I make my dll/so with embedded python support use via ctypes?

If Py_NewInterpreter is the answer, why does it hang indefinitely?

The dll/so must support use in processes which might contain other
instances of Python. I can not change that requirement. Running via
ctypes is an easy test of this capability (or much of it I suspect).
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >