Re: Structures

2008-11-03 Thread Michele Simionato
On Nov 4, 2:57 am, Glenn Linderman <[EMAIL PROTECTED]> wrote: > Note that classes, by default, are based on a contained dict!  There are > games to be played with slots that can apparently improve that.  I am > not yet experienced enough with Python to know if a slot is as fast as a > C struct, but

Re: Embedding: Is it possible to limit number of virtual instructions executed?

2008-11-03 Thread juliangrendell
Thanks to those who replied; it seems that it is possible to do, but would require some changes to the python core, and may not be as fine-grained as I'd presumed. I think I'll consider running python in a seperate thread and create a couple of message queues to/from that thread and the main threa

Re: how to call this dll in python

2008-11-03 Thread Mark Tolonen
"Shark" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] I have a windows dll1.dll with a export function: int f1(char filename,char **buf,int *bufLen) { int len; //got the length of file anyway,such as 100 len = 100;//len = getLen(filename); *buf = (char*)calloc(100); *bufLen = len

Re: Structures

2008-11-03 Thread Glenn Linderman
On approximately 11/3/2008 5:28 PM, came the following characters from the keyboard of Aaron Brady: On Nov 3, 5:38 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> wr

Re: redirection in a file with os.system

2008-11-03 Thread [EMAIL PROTECTED]
On Nov 4, 12:06 am, TP <[EMAIL PROTECTED]> wrote: > Hi everybody, > > The following code does not redirect the output of os.system("ls") in a > file: > > import sys, os > saveout = sys.stdout > fd = open( 'toto', 'w' ) > sys.stdout = fd > os.system( "ls" ) > sys.stdout = saveout > fd.close() os.sy

Which was the best Lib of GUI for python

2008-11-03 Thread 3000 billg
Hi Guy, I am a leaner. for your experience. Which GUI Lib will be the best for Python? wxpython, Tkinter or... -- http://mail.python.org/mailman/listinfo/python-list

Re: buffer

2008-11-03 Thread Tim Roberts
"Aditi Meher" <[EMAIL PROTECTED]> wrote: > >i am using it postgresql as back-end and HTML as front-end,i want to, >display 10-10 records at a time which is there in the database using, >python.so what is function for buffer that we can use it in python?i, >am able to connect my databse in python,bu

Jobs vacancies and openings in Asia. Create a more stable financial future by teaching English in Asia. Explore the options of starting a successful new career and lifestyle in Asia.

2008-11-03 Thread Jobs, Work, Teaching English, TEFL, TESOL, Gap Year, Travel, Thailand, Cambodia, Vietnam Languagecorps
Jobs vacancies and openings in Asia. Create a more stable financial future by teaching English in Asia. Explore the options of starting a successful new career and lifestyle in Asia. Teach and travel in Asia. TEFL / TESOL training can give you the international skills you need to teach and trav

Re: storing a string data in access

2008-11-03 Thread Tim Arnold
"alex23" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Nov 3, 3:47 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> Hi >> I have >> access.Fields("Time").value=t >> I would like t to be a string reprsenting a data. How can I do this? > > t = "string representing a datum" > ac

Re: Finding the instance reference of an object

2008-11-03 Thread Aaron Brady
On Nov 3, 8:33 pm, Joe Strout <[EMAIL PROTECTED]> wrote: > On Nov 3, 2008, at 5:27 PM, Marc 'BlackJack' Rintsch wrote: > > > Maybe this is a surprise for you, because we haven't discussed this in > > much detail in this group lately, but it applies to Python which does > > call-by-object or call-by

locating the chorus in a MIDI song?

2008-11-03 Thread Joe Strout
We've got a need to generate short "samples" of songs that are in MIDI format, to provide a preview function in a web app. We'd like to do something more clever than just taking the middle 20 seconds (or whatever) of the song -- ideally, we'd like to find the chorus, since that's likely to

Make Money Fast, Guranteed!

2008-11-03 Thread lillylove0826
MAKE MONEY FAST AND EASY HURRY [ Follow Ups ] [ Post Followup ] [ Message Board ] Posted by [IP Address: 12.2.88.76] 'Jed' on March 12, 2001 at 18:15:57 EST: MAKE MONEY FAST AND EASY HURRY Make Money Fast A little while back, I was browsing these newsgroups, just like you are n

Re: Structures

2008-11-03 Thread Steven D'Aprano
On Tue, 04 Nov 2008 00:19:16 +, Marc 'BlackJack' Rintsch wrote: > On Mon, 03 Nov 2008 23:32:25 +, Paulo J. Matos wrote: > >> What's then the reason for adding named tuples if they are not >> mutable...??? > > Names are more descriptive than "magic numbers" as indices. See for > example

Re: how to call this dll in python

2008-11-03 Thread Shark
On Nov 3, 4:22 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Shark schrieb: > > > I have a windows dll1.dll with a export function: > > > int f1(char filename,char **buf,int *bufLen) > > { > > int len; > > //got the length of file anyway,such as 100 > > len = 100;//len = getLen(filename); > >

Re: Structures

2008-11-03 Thread Steven D'Aprano
On Mon, 03 Nov 2008 17:06:07 -0800, Aaron Brady wrote: >> For all practical purposes, dicts have almost constant access time (at >> least with any half-decent __hash__  method). > > Hash tables are slick, but their hash function is their weakest link. > [ hash( 2**x ) for x in range( 0, 256

Re: Finding the instance reference of an object

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 5:27 PM, Marc 'BlackJack' Rintsch wrote: Maybe this is a surprise for you, because we haven't discussed this in much detail in this group lately, but it applies to Python which does call-by-object or call-by-sharing. ;-) There's no such thing. Those are just terms made up

Re: Finding the instance reference of an object

2008-11-03 Thread Steven D'Aprano
On Mon, 03 Nov 2008 15:27:01 -0700, Joe Strout wrote: >> By-Value and By-Reference are not the only passing methods. True or >> False? > > True, but the others are rarely used and don't apply to any of the > languages we've been discussing. Yeah, uncommon, rare languages that nobody uses, like

Re: Simple textual calendar

2008-11-03 Thread Mensanator
On Nov 3, 7:31 am, ostra pikula <[EMAIL PROTECTED]> wrote: > On Mon, 03 Nov 2008 14:14:00 +0100, ostra pikula > > > > > > <[EMAIL PROTECTED]> wrote: > >Hello everyone, > > >please, I need your help. I'm a beginner in python and this is > >probably elemental to you, but represents quote a goggle for

Re: Structures

2008-11-03 Thread Glenn Linderman
On approximately 11/3/2008 3:38 PM, came the following characters from the keyboard of Paulo J. Matos: On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> wrote: "Paulo J. Matos" <[EMAIL PROTECTED]> writes: O

Re: Structures

2008-11-03 Thread Aaron Brady
On Nov 3, 5:38 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: > > On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> > > wrote: > >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > >> Take care with broad sweeping statements a

SQL is many things, but "mini" had never occurred to me as one of them (was: push-style templating - an xml-like way to process xhtml)

2008-11-03 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Tino Wildenhain <[EMAIL PROTECTED]> wrote: . . . >Mini languages is the correct term. And yes they have their >purpose. (Think of SQL for example). .

Re: Anyone in the Houston / College Station / Austin area? Looking to do some sprints / joint projects.

2008-11-03 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, xkenneth <[EMAIL PROTECTED]> wrote: >All, > > I'm in Houston/College Station/Austin quite often and I'm looking >for other coders to do some joint projects with, share experiences, or >do some sprints. Let me know if you're interested. .

Re: Structures

2008-11-03 Thread Aaron Brady
On Nov 3, 6:33 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On Nov 3, 6:32 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > > > Even though I can use dicts where the keys are strings (as if it were > > the name of the field), it seems to heavy, since a structure doesn't > > need to be resizable

Re: How do I find the memory used by a python process

2008-11-03 Thread Scott David Daniels
Ben Finney wrote: Salim Fadhley <[EMAIL PROTECTED]> writes: The unit-test needs to check that after the functions have been run a few thousand times all of the memory used by those functions has been un-allocated, i.e. that there are no memory leaks. This is a great test case, However, I

Re: problem with single-quote and double-quote when using subprocess.

2008-11-03 Thread alex23
On Nov 4, 8:47 am, Evan <[EMAIL PROTECTED]> wrote: > It always failed. > It also failed. > Does anybody have a good suggestion for this matter? thanks in > advance. What do you mean by "it failed"? It always helps to paste the actual error message you received. -- http://mail.python.org/mailman/li

Re: Structures

2008-11-03 Thread George Sakkis
On Nov 3, 6:32 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > Even though I can use dicts where the keys are strings (as if it were > the name of the field), it seems to heavy, since a structure doesn't > need to be resizable (and dicts are) and it has constant time access > (which depending on

Re: Structures

2008-11-03 Thread Paul Rubin
"Paulo J. Matos" <[EMAIL PROTECTED]> writes: > OK, so this is now messing with my lack of knowledge regarding Python. > What's (pure) Python? Is there any impure Python? impure Python = Python with extensions written in C. -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the instance reference of an object

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Nov 2008 15:27:01 -0700, Joe Strout wrote: > On Nov 3, 2008, at 2:36 PM, Aaron Brady wrote: >> Python can do the swap operation on mutable types, for example. > > That's in the "no fair" category. C can do a swap operation on mutable > types, too, though it also has only pass-by-value

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Tue, Nov 4, 2008 at 12:17 AM, George Sakkis <[EMAIL PROTECTED]> wrote: > > Technically there are no private attributes in (pure) Python so the > answer is still classes. > OK, so this is now messing with my lack of knowledge regarding Python. What's (pure) Python? Is there any impure Python? >

Re: Structures

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Nov 2008 23:32:25 +, Paulo J. Matos wrote: > What's then the reason for adding named tuples if they are not > mutable...??? Names are more descriptive than "magic numbers" as indices. See for example the "named tuple" returned by `os.stat()`. Ciao, Marc 'BlackJack' Rints

Re: Structures

2008-11-03 Thread George Sakkis
On Nov 3, 6:51 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > On Mon, Nov 3, 2008 at 11:47 PM, Joe Strout <[EMAIL PROTECTED]> wrote: > > On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: > > >> However, I wouldn't dare to say Python needs structures to be a good > >> language, or anything simila

Re: problem with quote and single-quote when using "subprocess"

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Nov 2008 14:45:22 -0800, Evan wrote: > Hello - > > i'm trying to call subprocess.popen on the 'command-based' function in > linux. When I run the command from the shell, like so: > > goset -f ' "%s %s" name addr ' file_name > > it works fine > > however when I try to do it in pytho

Re: PYTHON WORKING WITH PERL ??

2008-11-03 Thread Craig Allen
> article:http://www.linuxjournal.com/article/3882 even if it is by Eric Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 11:47 PM, Joe Strout <[EMAIL PROTECTED]> wrote: > On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: > >> However, I wouldn't dare to say Python needs structures to be a good >> language, or anything similar. My question was more directed to : if >> there aren't structures in

Re: PYTHON WORKING WITH PERL ??

2008-11-03 Thread Craig Allen
> article:http://www.linuxjournal.com/article/3882 interesting read, thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: However, I wouldn't dare to say Python needs structures to be a good language, or anything similar. My question was more directed to : if there aren't structures in Python, what do Pythonists use instead? Classes. Best, - Joe -- http://mail.

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: > On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> > wrote: >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: >> >> > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney >> > <[EMAIL PROTECTED]> wrote: >> > > I'm wondering a more fundam

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 10:10 PM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Ben Finney <[EMAIL PROTECTED]> writes: > >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > [...] >> Okay, you're talking about 'struct' from the C language. That helps >> answer the question. > > Note that structs are mu

Re: push-style templating - an xml-like way to process xhtml

2008-11-03 Thread has
On 3 Nov 2008, at 18:18, Glenn Linderman wrote: > On approximately 11/3/2008 12:20 AM, came the following characters > from the keyboard of has: >> On 2 Nov, 14:06, Tino Wildenhain <[EMAIL PROTECTED]> wrote: >> >>> "$attr.title$ >>> $if(attr.active)$ >>> $attr.submenu:menuItem()$ >>> $endif$" >>>

problem with single-quote and double-quote when using subprocess.

2008-11-03 Thread Evan
Hello - i'm trying to call subprocess.popen on the 'command-based' function in linux. When I run the command from the shell, like so: goset -f ' "%s %s" name addr ' file_name it works fine however when I try to do it in python like so: p = subprocess.Popen(["goest",'-f \'\"%s %s\" name addr\'

problem with quote and single-quote when using "subprocess"

2008-11-03 Thread Evan
Hello - i'm trying to call subprocess.popen on the 'command-based' function in linux. When I run the command from the shell, like so: goset -f ' "%s %s" name addr ' file_name it works fine however when I try to do it in python like so: p = subprocess.Popen(["goest",'-f \'\"%s %s\" name addr\'

Re: Unyeilding a permutation generator

2008-11-03 Thread sillyhat
On Nov 3, 4:24 pm, Michele Simionato <[EMAIL PROTECTED]> wrote: > On Nov 2, 10:34 pm, [EMAIL PROTECTED] wrote: > > > Anyway what I want to do is experiment with code similar to this (i.e. > > same algorithm and keep the recursion) in other languages, > > particularly vbscript and wondered what it w

Re: Structures

2008-11-03 Thread Arnaud Delobelle
Craig Allen <[EMAIL PROTECTED]> writes: >> >> Care to say more about what they are, not what they're like? >> > > I'm not the OP and I may be biased by C++, I can imagine the > complaints when I say, classes are just structures with function > members for working on the structure. In C++ classes

Re: Finding the instance reference of an object

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 2:36 PM, Aaron Brady wrote: Then please write the Python equivalent of the "Swap" methods shown at (or at , for that matter). And no fair wrapping the two parameters up in an object

Re: Unyeilding a permutation generator

2008-11-03 Thread Aaron Brady
On Nov 3, 4:13 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Mon, 03 Nov 2008 21:09:58 +, Jorgen Grahn wrote: > > Why multi-threading?  I see no concurrency in the original algorithm. > > There is, in my mind, nothing concurrent about 'yield'. > > No "real" concurrency but a gene

Re: Structures

2008-11-03 Thread Craig Allen
> > Care to say more about what they are, not what they're like? > I'm not the OP and I may be biased by C++, I can imagine the complaints when I say, classes are just structures with function members for working on the structure. -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread Aaron Brady
On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > > > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney > > <[EMAIL PROTECTED]> wrote: > > > I'm wondering a more fundamental question: What are structures? > > > That is, what do *you* mean by that te

Re: Unyeilding a permutation generator

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Nov 2008 21:09:58 +, Jorgen Grahn wrote: > Why multi-threading? I see no concurrency in the original algorithm. > There is, in my mind, nothing concurrent about 'yield'. No "real" concurrency but a generator can be seen as independent thread of code where the generator code is al

Re: Structures

2008-11-03 Thread Arnaud Delobelle
Ben Finney <[EMAIL PROTECTED]> writes: > "Paulo J. Matos" <[EMAIL PROTECTED]> writes: [...] > Okay, you're talking about ‘struct’ from the C language. That helps > answer the question. Note that structs are mutable. > In Python, the way to do that is with a dict. A class can be used, but > is of

Re: Structures

2008-11-03 Thread Jorgen Grahn
On Mon, 3 Nov 2008 20:33:45 +, Paulo J. Matos <[EMAIL PROTECTED]> wrote: > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney > <[EMAIL PROTECTED]> wrote: >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: ... >> I'm wondering a more fundamental question: What are structures? That >> is, what do *you* me

Re: How do I find the memory used by a python process

2008-11-03 Thread Ben Finney
Salim Fadhley <[EMAIL PROTECTED]> writes: > The unit-test needs to check that after the functions have been run > a few thousand times all of the memory used by those functions has > been un-allocated, i.e. that there are no memory leaks. This is a great test case, thanks. I must add it to my sto

Re: Structures

2008-11-03 Thread Ben Finney
"Paulo J. Matos" <[EMAIL PROTECTED]> writes: > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney > <[EMAIL PROTECTED]> wrote: > > I'm wondering a more fundamental question: What are structures? > > That is, what do *you* mean by that term; without knowing that, an > > answer isn't likely to be meaningfu

Re: Replacing cmp with key for sorting

2008-11-03 Thread bearophileHUGS
George Sakkis: > but I guess there's not much more room for improvement. That's nonsense, Python is a high level language, so there's nearly always room for improvement (even in programs written in assembly you can generally find faster solutions). If speed is what you look for, and your strings a

Re: Finding the instance reference of an object

2008-11-03 Thread Aaron Brady
On Nov 3, 2:44 pm, Joe Strout <[EMAIL PROTECTED]> wrote: > On Nov 3, 2008, at 12:00 PM, Aaron Brady wrote: > > > I think we can conclude that Python passes by reference, since a > > function can modify objects that were passed in to it. > > Then please write the Python equivalent of the "Swap" meth

Re: Simple textual calendar

2008-11-03 Thread Jorgen Grahn
On Mon, 03 Nov 2008 09:17:25 -0600, Tim Chase <[EMAIL PROTECTED]> wrote: >> Yes, I saw the calendar module, but, as I said, this isn't >> homework or something like that. It is an example which I've >> setted myself to try to solve to see how it would go. Calendar >> just gives me the solution :-(

Re: Unyeilding a permutation generator

2008-11-03 Thread Jorgen Grahn
On Sun, 2 Nov 2008 14:09:01 -0800 (PST), Aaron Brady <[EMAIL PROTECTED]> wrote: > On Nov 2, 3:34 pm, [EMAIL PROTECTED] wrote: ... >> for x in  all_permx("ABCD"): >>   print x ... > I think multi-threading is the "truest" to the original. You might > develop a framework to set events when particula

Re: Finding the instance reference of an object

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 12:00 PM, Aaron Brady wrote: I think we can conclude that Python passes by reference, since a function can modify objects that were passed in to it. Then please write the Python equivalent of the "Swap" methods shown at (or at

Re: How do I find the memory used by a python process

2008-11-03 Thread Martin v. Löwis
> So each test would check the amount of memory available, call the > function N times and then check the amount of memory available > afterwards. If the amount of memory before and after changes by a > certain amount then the test is failed. Please take a look at the muppy package: http://pypi.p

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney <[EMAIL PROTECTED]> wrote: > "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > >> I am a Python beginner, reading through 2.6 tutorial. I am wondering >> where are structures? > > I'm wondering a more fundamental question: What are structures? That > is, wha

How do I find the memory used by a python process

2008-11-03 Thread Salim Fadhley
I'm trying to create a python unit-test which will test a complex program which includes a number of functions which have been implemented in C or C++. The unit-test needs to check that after the functions have been run a few thousand times all of the memory used by those functions has been un-all

Re: Replacing cmp with key for sorting

2008-11-03 Thread George Sakkis
On Nov 3, 1:51 pm, [EMAIL PROTECTED] wrote: > Arnaud Delobelle: > > > Here's another idea, probably more practical: > > >>> sorted(s, key=lambda x: tuple(256-ord(l) for l in x), reverse=True) > > Nice. > A variant that probably works with unicode strings too: > > print sorted(s, key=lambda x: [-or

Re: encoding in lxml

2008-11-03 Thread Stefan Behnel
jasiu85 wrote: > I have a problem with character encoding in LXML. Here's how it goes: > > I read an HTML document from a third-party site. It is supposed to be > in UTF-8, but unfortunately from time to time it's not. You can instantiate your own HTML parser and pass encoding="utf-8". That way,

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Tim Chase
For making a literal tuple, parentheses are irrelevant; only the commas matter: I don't think I'd go so far as to say that the parentheses around tuples are *irrelevant*...maybe just relevant in select contexts >>> def foo(*args): ... for i, arg in enumerate(args): ... print

Re: script that parses command line, and execfile('')

2008-11-03 Thread Diez B. Roggisch
TP schrieb: Hello, I have a script that uses the "optparse" package to parse the command line. For example: $ script.py --help # displays help about script.py Is this possible to call such a script with execfile('') once in the Python interactive shell? execfile( 'script.py' ) I get errors

Re: script that parses command line, and execfile('')

2008-11-03 Thread Arnaud Delobelle
TP <[EMAIL PROTECTED]> writes: > Hello, > > I have a script that uses the "optparse" package to parse the command line. > For example: > > $ script.py --help > # displays help about script.py > > Is this possible to call such a script with execfile('') once in the Python > interactive shell? > >>>

script that parses command line, and execfile('')

2008-11-03 Thread TP
Hello, I have a script that uses the "optparse" package to parse the command line. For example: $ script.py --help # displays help about script.py Is this possible to call such a script with execfile('') once in the Python interactive shell? >>> execfile( 'script.py' ) I get errors because the

Re: redirection in a file with os.system

2008-11-03 Thread Arnaud Delobelle
TP <[EMAIL PROTECTED]> writes: > Hi everybody, > > The following code does not redirect the output of os.system("ls") in a > file: > > import sys, os > saveout = sys.stdout > fd = open( 'toto', 'w' ) > sys.stdout = fd > os.system( "ls" ) > sys.stdout = saveout > fd.close() > > Whereas the followin

Re: Replacing cmp with key for sorting

2008-11-03 Thread bearophileHUGS
Arnaud Delobelle: > It's funny how the obvious escapes me so often. In this case it's a well known cognitive effect: the mind of humans clings to first good/working solution, not allowing its final tuning. For that you may need to think about something else for a short time, and then look at your

redirection in a file with os.system

2008-11-03 Thread TP
Hi everybody, The following code does not redirect the output of os.system("ls") in a file: import sys, os saveout = sys.stdout fd = open( 'toto', 'w' ) sys.stdout = fd os.system( "ls" ) sys.stdout = saveout fd.close() Whereas the following works: old_stdout = os.dup( sys.stdout.fileno() ) fd =

Re: Finding the instance reference of an object

2008-11-03 Thread Aaron Brady
On Nov 2, 10:13 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 02 Nov 2008 13:23:11 -0800, Aaron Brady wrote: > > But, doing so, an object is not the same as a reference to it, and all > > Python does is pass and copy references. > > No, that's what at least one particular implementation

Re: Replacing cmp with key for sorting

2008-11-03 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > Arnaud Delobelle: >> Here's another idea, probably more practical: >> >>> sorted(s, key=lambda x: tuple(256-ord(l) for l in x), reverse=True) > > Nice. > A variant that probably works with unicode strings too: > > print sorted(s, key=lambda x: [-ord(l) for l in x], reve

Re: Problem using urllib to download images

2008-11-03 Thread tstrogen
> That's because you downloaded some HTML and saved it in a file named > logo.gif. That's unlikely to work in any image viewing program. Try > opening the file you downloaded in a text editor and you'll see. > > -- > Jerry Aha, so the first param is the file, and second is the name you save the

Re: wrapping a method function call?

2008-11-03 Thread Aaron Brady
On Nov 3, 3:57 am, [EMAIL PROTECTED] wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > > Now you can monkey patch class A if you want. It's probably not a great > > idea to do this in production code, as it will effect class A everywhere. > > This is perfect for me.  The code in question is bas

Re: Replacing cmp with key for sorting

2008-11-03 Thread bearophileHUGS
Arnaud Delobelle: > Here's another idea, probably more practical: > >>> sorted(s, key=lambda x: tuple(256-ord(l) for l in x), reverse=True) Nice. A variant that probably works with unicode strings too: print sorted(s, key=lambda x: [-ord(l) for l in x], reverse=True) Bye, bearophile -- http://ma

Re: encoding in lxml

2008-11-03 Thread pjacobi . de
Hi Mike, > I read an HTML document from a third-party site. It is supposed to be > in UTF-8, but unfortunately from time to time it's not. There will be host of more lightweight solutions, but you can opt to sanizite incominhg HTML with HTML Tidy (python binding available). It will replace inval

Re: Replacing cmp with key for sorting

2008-11-03 Thread bearophileHUGS
Alan G Isaac: > Probably not what you had in mind ... > ... > >>> maxlen = max(len(si) for si in s) >      >>> def k(si): return si+'z'*(maxlen-len(si)) This looks a little better: assert isinstance(s, str) sorted(s, key=lambda p: p.ljust(maxlen, "\255")) If the string is an unicode that ma

Re: Problem using urllib to download images

2008-11-03 Thread Jerry Hill
On Mon, Nov 3, 2008 at 2:21 PM, <[EMAIL PROTECTED]> wrote: > Then perhaps it's a problem with my os. > [TERMINAL SESSION] > [18:16:33 Mon Nov 03] python > Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) > [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin > Type "help", "copyright", "c

Re: Replacing cmp with key for sorting

2008-11-03 Thread Arnaud Delobelle
George Sakkis <[EMAIL PROTECTED]> writes: > I want to sort sequences of strings lexicographically but those with > longer prefix should come earlier, e.g. for s = ['a', 'bc', 'bd', > 'bcb', 'ba', 'ab'], the sorted sequence is ['ab', 'a', 'ba', 'bcb', > 'bc', 'bd']. Currently I do it with: > > s.so

Re: Replacing cmp with key for sorting

2008-11-03 Thread Alan G Isaac
George Sakkis wrote: s.sort(cmp=lambda x,y: 0 if x==y else -1 if x.startswith(y) else +1 if y.startswith(x) else cmp(x,y)) Probably not what you had in mind ... >>> s ['a', 'b

Re: length of a tuple or a list containing only one element

2008-11-03 Thread bearophileHUGS
Arnaud Delobelle: >And introduces some new inconsistencies for newcomers, e.g. > s = {1, 2, 3} # A set with 3 elements > s = {1} # A set with one element > s = {} # Surely, this should be an empty set!! Are you able to list other inconsistencies? Python3 introduces one or two warts, but removes

Re: Replacing cmp with key for sorting

2008-11-03 Thread bearophileHUGS
On Nov 3, 6:49 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > I want to sort sequences of strings lexicographically but those with > longer prefix should come earlier, e.g. for s = ['a', 'bc', 'bd', > 'bcb', 'ba', 'ab'], the sorted sequence is ['ab', 'a', 'ba', 'bcb', > 'bc', 'bd']. Currently I do

Re: Problem using urllib to download images

2008-11-03 Thread tstrogen
Then perhaps it's a problem with my os. [TERMINAL SESSION] [18:16:33 Mon Nov 03] python Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> url = '

Re: push-style templating - an xml-like way to process xhtml

2008-11-03 Thread Glenn Linderman
On approximately 11/3/2008 12:20 AM, came the following characters from the keyboard of has: On 2 Nov, 14:06, Tino Wildenhain <[EMAIL PROTECTED]> wrote: An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by Terence Parr: Hm. "$att

Re: 2.6, 3.0, and truly independent intepreters

2008-11-03 Thread Andy O'Meara
On Oct 30, 11:09 pm, alex23 <[EMAIL PROTECTED]> wrote: > On Oct 31, 2:05 am, "Andy O'Meara" <[EMAIL PROTECTED]> wrote: > > > I don't follow you there. If you're referring to multiprocessing, our > > concerns are: > > > - Maturity (am I willing to tell my partners and employees that I'm > > betting

Re: Tiny yet useful utility

2008-11-03 Thread George Sakkis
On Nov 3, 12:55 pm, [EMAIL PROTECTED] wrote: >     Mariyam> Process Manager for Windows >     Mariyam> (http://processpriority.wiki.sourceforge.net/) It has always >     Mariyam> been a pain to use applications like >     Mariyam> Office/Outlook/Matlab/Delphi/Mozilla...Image editing s/w >     Mariy

Re: Tiny yet useful utility

2008-11-03 Thread skip
Mariyam> Process Manager for Windows Mariyam> (http://processpriority.wiki.sourceforge.net/) It has always Mariyam> been a pain to use applications like Mariyam> Office/Outlook/Matlab/Delphi/Mozilla...Image editing s/w Mariyam> ...video editing s/w What is the connection with

Replacing cmp with key for sorting

2008-11-03 Thread George Sakkis
I want to sort sequences of strings lexicographically but those with longer prefix should come earlier, e.g. for s = ['a', 'bc', 'bd', 'bcb', 'ba', 'ab'], the sorted sequence is ['ab', 'a', 'ba', 'bcb', 'bc', 'bd']. Currently I do it with: s.sort(cmp=lambda x,y: 0 if x==y else

Tiny yet useful utility

2008-11-03 Thread Mariyam Pinto
Process Manager for Windows (http:// processpriority.wiki.sourceforge.net/) It has always been a pain to use applications like Office/Outlook/Matlab/Delphi/Mozilla...Image editing s/w ...video editing s/w They take huge memory... they eat up half of your CPU and when you wanna close them, then

Re: Why does numpy.array(a[0],b[0]) have this meaning?

2008-11-03 Thread Robert Kern
Rick Giuly wrote: Hello All, Case 1 This generates an error, which makes sense because the argument should be a list of numbers: numpy.array(10,10) Case 2 This does not generate an error and the result is an array with a single element: a = numpy.array([10]) b = numpy.array([10]) numpy.array(a[

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > Steve Holden: >> While this kind of beginner >> mistake is common it isn't one that's frequently repeated once the >> learner understands the syntax. > > You may be right, but I don't have to like it. > When you teach programming to people that have never done it before

Re: Problem using urllib to download images

2008-11-03 Thread [EMAIL PROTECTED]
On Nov 3, 11:48 am, [EMAIL PROTECTED] wrote: > I am using Python 2.6 on Mac OS 10.3.9. > I have been trying to use: > image = urllib.URLopener() > image.retrieve(url, filename) > to download images from websites. I am able to do so, and end up with > the appropriate file. However, when I try to ope

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Scott David Daniels
Tim Chase wrote: For making a literal tuple, parentheses are irrelevant; only the commas matter: I don't think I'd go so far as to say that the parentheses around tuples are *irrelevant*...maybe just relevant in select contexts >>> def foo(*args): ... for i, arg in enumerate(args): ..

Tktable on 3.0rc1

2008-11-03 Thread info
Has anyone used Tktable on python 3.0 ? -- http://mail.python.org/mailman/listinfo/python-list

Problem using urllib to download images

2008-11-03 Thread tstrogen
I am using Python 2.6 on Mac OS 10.3.9. I have been trying to use: image = urllib.URLopener() image.retrieve(url, filename) to download images from websites. I am able to do so, and end up with the appropriate file. However, when I try to open the file, I get an error message. It's something about

Re: split() and string.whitespace

2008-11-03 Thread Scott David Daniels
Steven D'Aprano wrote: On Fri, 31 Oct 2008 12:18:32 -0700, Chaim Krause wrote: I have arrived here while attempting to break down a larger problem. I got to this question when attempting to split a line on any whitespace character so that I could then add several other characters like ';' and ':

Re: Unyeilding a permutation generator

2008-11-03 Thread Michele Simionato
On Nov 2, 10:34 pm, [EMAIL PROTECTED] wrote: > Anyway what I want to do is experiment with code similar to this (i.e. > same algorithm and keep the recursion) in other languages, > particularly vbscript and wondered what it would look like if it was > rewritten to NOT use the yield statement - or a

Re: Unyeilding a permutation generator

2008-11-03 Thread Terry Reedy
Steve Holden wrote: [EMAIL PROTECTED] wrote: Anyway what I want to do is experiment with code similar to this (i.e. same algorithm and keep the recursion) in other languages, particularly vbscript and wondered what it would look like if it was rewritten to NOT use the yield statement - or at l

Re: Simplifying anonymous inner classes?

2008-11-03 Thread Tim Chase
Is there a more Pythonic way to instantiate sub-classes and provide instance-specific implementations without the overhead of an unused "anonymous" class cluttering my code/namespace? I agree with Carl Banks that what you do is already fairly Pythonic: explicit is better than implicit, and simpl

Re: Decorator for validation - inefficient?

2008-11-03 Thread Bryan
Steven D'Aprano wrote: > On Sun, 02 Nov 2008 09:33:41 -0800, Bryan wrote: > > > I'm coming from a .Net background, and yes, one of the reasons I did not > > consider raising exceptions was to avoid the overhead of an exception > > handler clause, which in .Net land is expensive. > > Actually catchi

Re: How to protect website from access without authentication?

2008-11-03 Thread Shawn Milochik
This isn't really a Python question -- it's a Web development question. The easy answer is to just password protect the directory all the pages are stored in, and require a password. This can be set up using Apache or IIS. If what you really meant to ask was how to prevent anyone from accessing ce

  1   2   >