Re: Web Page Construction in Python

2008-07-22 Thread Diez B. Roggisch

SUBHABRATA schrieb:

Dear Group,
I am getting some questions on doing Web Pages in Python.
I have some interactive codes in python for which I like to make web
pages.
I am trying to use kid.
Kid I learnt, and is easy, too.
My questions are:
i)  Am I going correct?
ii) Is there any language other than kid?
iii)The worked out examples of kid are not opening properly, is there
any other URL where I can see them.
iv) Can cgi scripting be done with kid?
If any one can spend time on my questions.


I suggest you take a look at TurboGears. It's a web-framework that uses 
KID (or genshi, which is extremely similar) to render pages, and makes 
web-development considerably easier.


http://www.turbogears.org/

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


Re: Python Written in C?

2008-07-22 Thread cokofreedom
On Jul 22, 5:59 am, Larry Bates <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
> > On 2008-07-22, Larry Bates <[EMAIL PROTECTED]> wrote:
>
> >> You talk about "writing it in assembly language for each MPU
> >> chip".  Actually it is even better than that.  We now have
> >> these modern inventions, called compilers that do that type of
> >> work for us.  They translate high level instructions, not
> >> into assembler but into machine language.
>
> > Actually, all of the compilers I'm familiar with (gcc and a
> > handful of cross compilers for various microprocessors)
> > translate from high-level languages (e.g. C, C++) into
> > assembly, which is then assembled into relocatable object
> > files, which are then linked/loaded to produce machine
> > language.
>
> I just learned something I did not know.  I was under the impression that they
> translated directly to machine code without ever actually generating Assembler
> text files.  Seems like a waste to generate the text and turn around run that
> through the assembler, but what do I know.  I guess that way the compiler can
> have pluggable assembler back-ends.
>
> -Larry

I also I have just learned something new! Troll threads are useful.
Yay.
--
http://mail.python.org/mailman/listinfo/python-list


Re: fromfile error on windows, not mac

2008-07-22 Thread Uwe Schmitt


jadamwil schrieb:
> Hello,
> I am using the numpy fromfile function to read binary data from a file
> on disk. The problem is that the program runs fine on a Mac, but gives
> an error or warning on windows when trying to read the data. I use it
> like this:
>
> Signal = zeros((N, 16), dtype=float32)
> for sample in range(0, N):
>   # this function gets the next position in the file to seek to
>   s = getFilePos(sample)
>
>   # go to the correct location in the file; this IS checked to make
> sure it is within the file
>   mFile.seek(s)
>
>   # read the 16 float32 values from the file
>   D = fromfile(mFile, dtype=numpy.float32, 16)
>
>   # save D in Signal
>   Signal[sample, :] = D
>
> This will fail when sample is ~4. If I change the range to (5,N),
> skipping the "bad" file location, it will run fine for a few samples,
> and then give another error. The message it gives is:
> "16 items requested but only 7 read"
>
> So D is a 7x1 vector, and the program dies when it tries to assign D
> to the slice of Signal ("ValueError: shape mismatch: objects cannot be
> broadcast to a single shape").
>
> On windows, the Python version is 2.5.2, and the most recent numpy and
> scipy are being used as well. I tried using Enthought, but it gave
> this error as well, in addition to a c runtime error whenever I
> imported scipy (which is another post topic...).
>
> Any ideas on what might be causing this? Is there a way to debug the
> fromfile function? And, remember, this works perfectly on a Mac. Would
> compiling everything (python, scipy, numpy) potentially solve this?

Did you open the file in binary mode ?

Greetings, Uwe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-22 Thread Paul Rudin
DaveM <[EMAIL PROTECTED]> writes:

> On Mon, 21 Jul 2008 03:18:01 +0200, Michiel Overtoom <[EMAIL PROTECTED]>
> wrote:
>
>
>>Many major text/word processing programs (Emacs, vi, MS-Word) are also
>>written in C.
>
> I thought Emacs was written in Lisp.

The core - including the lisp interpreter - is written in C. A lot of
the user functionality is written in (emacs) lisp.

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


Re: string[i:j:k]

2008-07-22 Thread konstantin
Now it's clear.
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Missing sqlite3.h Error when Building Debug Python -- Windows Vista

2008-07-22 Thread Tim Golden

Bev in TX wrote:

Thanks for letting me know about this.  I installed Subversion and
tried to make the build work like that, but it fails.


[... snip problems ...]

I'm afraid I'm not using VS 2005, nor Vista, nor 64-bit,
so I hope someone else can help. If you don't get any take-up
here try the python-win32 list; there may be people there who
don't follow this (rather higher volume) list.

TJG

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


Hello,who can help me!

2008-07-22 Thread birdprince
I have implemented a C++ COM,which contains two interface in one
coclass.
when i use this COM in python:
dll=win32com.client.Dispatch("X")
then i can only call default interface's method,but can't call non
default interface's method.
who can tell me how to call non default interface's method.
thank you very much!
you can send the answer to my mailbox:[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


RE: Change PC to Win or Windows

2008-07-22 Thread Michael . Coll-Barth
 

> From: Derek Martin

> The term "PC" is commonly used in
> English, in the United States and other English speaking countries, to
> mean a computer running Microsoft Windows.  

That isn't quite true.

My kids are heading off to college and are in the market for laptops.
The question they had for the salesman was if there was anything other
than Vista available.  I was so proud.  His response was that they no
longer bother with XP.  Another customer suggested that they look at
Apple and another customer suggested dual booting it with Ubuntu ( why
not Fedora? ).  I was shocked when I asked if either were in the field.
Nope, a mechanic and doctor.

While it might have been true that PCs were becoming synonymous with
Windows boxes, I think that tide is heading back the other way.
Particularly when I hear that the Apple boxes are becoming very popular
as they work better with iPods and iPhones than does Windows.








The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: Change PC to Win or Windows

2008-07-22 Thread Derek Martin
On Mon, Jul 21, 2008 at 02:47:31PM -0700, Lie wrote:
> Common usage isn't always correct. 

Actually it is, inherently...  When usage becomes common, the language
becomes redefined, and its correctness is therefore true by identity
(to borrow a mathematical term).  The scholars complain for a while,
but eventually capitulate, and re-write the dictionary.  Language
bends to its use by the people, not the other way around.  Your
assumption is the opposite, and therefore all of your argument is
false.

> For example, a physicist would not use weight when he meant mass. 
> much, but in technical environment doing so would embarrass him. In
> this analogy, I consider download page for a software source code to
> be a technical area.

Your analogy is still broken.  The term "PC" has been used BY
TECHNCIAL PEOPLE, IN A TECHNICAL CONTEXT, to mean Microsoft on Intel,
FOR DECADES.

 + Authors of technical books, manuals, and other forms of
   documentation have refered to them as PCs... for decades.

 + Educators in CS and EE at major universities have refer to them as
   PCs, since at least as early as 1988 (when I started college).

 + Industry news publications such as Computer World have refered to
   them as PCs, for decades.

 + There are even whole magazines dedicated to them! (PC Magazine, PC
   Shopper, PC World, PC Gamer, etc.)  They are dedicated to Microsoft
   on Intel, and have existed (at least in some cases) long before
   Apple started talking about PCs in their ads.

All of this has been going on, essentially since there has been such
a thing as the IBM PC.  I'm sorry, but you sir, are quite simply,
plainly, and completely, wrong.  With a catastrophic amount of
written documentation, written by technical people in the computer
industry over the last 20+ years, to prove it.

> > > Apple popularizes the term by explicit marketing,
> >
> > And here is the last point you are missing: Apple does no such
> > thing.
> 
> They did, by using the term PC to refer to other computers. 

APPLE CAN NOT POPULARIZE A TERM WHICH IS ALREADY POPULAR.  

> This kind of advertising Apple (the computer company) used is
> misleading, since it implied that their PC is not a PC.

They haven't implied anything; they're stating it outright!  Apple
sells personal computers, but they do not sell PCs.  Apple's personal
computer is NOT a PC, and never was, and never will be.  It's an
Apple.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpM3T8xzDRmR.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: scanf in python

2008-07-22 Thread Fredrik Lundh

AMD wrote:

I had seen this pure python implementation, but it is not as fast or as 
elegant as would be an implementation written in C directly within 
python with no need for import.


maybe you should wait with disparaging comments about how Python is not 
what you want it to be until you've learned the language?




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


xpathEval fails for large files

2008-07-22 Thread Kanchana
Hi,

I tried to extract some data with xpathEval. Path contain more than
100,000 elements.

doc = libxml2.parseFile("test.xml")
ctxt = doc.xpathNewContext()
result = ctxt.xpathEval('//src_ref/@editions')
doc.freeDoc()
ctxt.xpathFreeContext()

this will stuck in following line and will result in high usage of
CPU.
result = ctxt.xpathEval('//src_ref/@editions')

Any suggestions to resolve this.

Is there any better alternative to handle large documents?

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


Re: Instance

2008-07-22 Thread karthikbalaguru
On Jul 17, 5:34 pm, "Calvin Spealman" <[EMAIL PROTECTED]> wrote:
> On Thu, Jul 17, 2008 at 2:56 AM, karthikbalaguru
>
> <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > I am new to python. I am trying to use the python files given to me
> > for bringing up a setup.
> > I get the following error while trying to use a python file -
> > AttributeError : Classroom instance has no attribute 'desk_offset'
>
> > How to resolve this ?
> > Should i need to define desk_offset to zero in the python file ?
>
> > Any ideas ..
>
> This means you did something like this:
>
> class Foo:
>def __init__(self):
>self.bar = 10
>
> f = Foo()
> print f.quu
> ...
> AttributeError : Foo instance has no attribute 'quu'
>
> See? You tried to use an attribute that simply doesn't exist. Look in
> the traceback for where you used the desk_offset attribute, and figure
> out why you thought the object had such an attribute and why it does
> not.
>

Thx!! Your ideas were useful.
I read some basic lessons on python and that were also very helpful in
solving
the problem.

Thx ,
Karthik Balaguru
--
http://mail.python.org/mailman/listinfo/python-list


Re: proliferation of computer languages

2008-07-22 Thread Fredrik Lundh

[EMAIL PROTECTED] wrote:


There is a proliferation of computer languages today like never
before.


"... today ... 1,700 special programming languages used to
'communicate' in over 700 application areas." -- Computer Software
Issues, an American Mathematical Association Prospectus, July
1965. (as quoted in P. J. Landin's classic paper "The Next 700 
Programming Languages" from March 1966).


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


Re: xpathEval fails for large files

2008-07-22 Thread Fredrik Lundh

Kanchana wrote:


I tried to extract some data with xpathEval. Path contain more than
100,000 elements.

doc = libxml2.parseFile("test.xml")
ctxt = doc.xpathNewContext()
result = ctxt.xpathEval('//src_ref/@editions')
doc.freeDoc()
ctxt.xpathFreeContext()

this will stuck in following line and will result in high usage of
CPU.
result = ctxt.xpathEval('//src_ref/@editions')

Any suggestions to resolve this.


what happens if you just search for "//src_ref"?  what happens if you 
use libxml's command line tools to do the same search?



Is there any better alternative to handle large documents?


the raw libxml2 API is pretty hopeless; there's a much nicer binding 
called lxml:


http://codespeak.net/lxml/

but that won't help if the problem is with libxml2 itself, though (in 
case you probably should check with an appropriate libxml2 forum).


there's also cElementTree (bundled with Python 2.5), but that has only 
limited xpath support in the current version.


both lxml and other implementations of the ET API supports incremental 
tree parsing:


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

which handles huge documents quite nicely, but requires you to write the 
search logic in Python:


for event, elem in ET.iterparse("test.xml"):
 if elem.tag == "src_ref" and elem.get("editions"):
 ... process element ...
 elem.clear()



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


Re: The Importance of Terminology's Quality

2008-07-22 Thread Martin Gregorie
On Tue, 24 Jun 2008 18:42:15 -0400, John W Kennedy wrote:

> David Combs wrote:
>> passing
>> *unnamed* functions as args (could Algol 60 also do something like that,
>> via something it maybe termed a "thunk")
> 
> No, the "thunks" were necessary at the machine-language level to 
> /implement/ ALGOL 60, but they could not be expressed /in/ ALGOL.
>
Are you sure about that? 

The first time I ran across the term "thunking" was when Windows 3
introduced the Win32S shim and hence the need to switch addressing between
16 bit and 32 bit modes across call interfaces. That was called "thunking"
by Microsoft and even they would surely admit it was a kludge.

I used Algol 60 on an Elliott 503 and the ICL 1900 series back when it was
a current language. The term "thunking" did not appear in either compiler
manual nor in any Algol 60 language definition I've seen. A60 could pass
values by name or value and procedures by name. That was it. Call by name
is what is now referred to as reference passing.

I should also point out that Algol 60 was initially written as a means for
communicating algorithms between people. Compiler implementations came
later. In consequence the language did not define links to libraries or
i/o methods. Both features were compiler specific - for instance the
Elliott introduced 'input' and 'print' reserved words and syntax while the
1900 compilers used function calls. The Elliott approach was more readable.

Algol 60 did not have 'functions'. It had procedures which could be
declared to return values or not. A procedure that returned a value was
equivalent to a function but the term 'function' was not used. Similarly
it did not have a mechanism for declaring anonymous procedures. That, like
the incorporation of machine code inserts, would have been a
compiler-specific extension, so it is a terminological mistake to refer to
it without specifying the implementing compiler.


-- 
martin@   | Martin Gregorie
gregorie. | 
org   | Zappa fan & glider pilot


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


Re: Hello,who can help me!

2008-07-22 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> I have implemented a C++ COM,which contains two interface in one
> coclass.
> when i use this COM in python:
> dll=win32com.client.Dispatch("X")
> then i can only call default interface's method,but can't call non
> default interface's method.
> who can tell me how to call non default interface's method.
> thank you very much!
> you can send the answer to my mailbox:[EMAIL PROTECTED]

AFAIK win32com only supports IDispatch-based interfaces, not custom
interfaces.

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


regarding SWIG

2008-07-22 Thread Anish Chapagain
Hi..
I'm new to SWIG and need to create Wrapper for C code,
so, I have installed the SWIG already but doesnot know how to run it
for generating Interface file...
My C code is in message.c so what do i need to do the first
step..uisng SWIG..i read the documentation but cannot grasp creating
interface file.

thank's anish
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Importance of Terminology's Quality

2008-07-22 Thread arsyed
On Tue, Jul 22, 2008 at 5:21 AM, Martin Gregorie
<[EMAIL PROTECTED]> wrote:
> On Tue, 24 Jun 2008 18:42:15 -0400, John W Kennedy wrote:
>
>> David Combs wrote:
>>> passing
>>> *unnamed* functions as args (could Algol 60 also do something like that,
>>> via something it maybe termed a "thunk")
>>
>> No, the "thunks" were necessary at the machine-language level to
>> /implement/ ALGOL 60, but they could not be expressed /in/ ALGOL.
>>
> Are you sure about that?
>
> The first time I ran across the term "thunking" was when Windows 3
> introduced the Win32S shim and hence the need to switch addressing between
> 16 bit and 32 bit modes across call interfaces. That was called "thunking"
> by Microsoft and even they would surely admit it was a kludge.
>
> I used Algol 60 on an Elliott 503 and the ICL 1900 series back when it was
> a current language. The term "thunking" did not appear in either compiler
> manual nor in any Algol 60 language definition I've seen. A60 could pass
> values by name or value and procedures by name. That was it. Call by name
> is what is now referred to as reference passing.
>


On Tue, Jul 22, 2008 at 5:21 AM, Martin Gregorie
<[EMAIL PROTECTED]> wrote:
> On Tue, 24 Jun 2008 18:42:15 -0400, John W Kennedy wrote:
>
>> David Combs wrote:
>>> passing
>>> *unnamed* functions as args (could Algol 60 also do something like that,
>>> via something it maybe termed a "thunk")
>>
>> No, the "thunks" were necessary at the machine-language level to
>> /implement/ ALGOL 60, but they could not be expressed /in/ ALGOL.
>>
> Are you sure about that?
>
> The first time I ran across the term "thunking" was when Windows 3
> introduced the Win32S shim and hence the need to switch addressing between
> 16 bit and 32 bit modes across call interfaces. That was called "thunking"
> by Microsoft and even they would surely admit it was a kludge.
>
> I used Algol 60 on an Elliott 503 and the ICL 1900 series back when it was
> a current language. The term "thunking" did not appear in either compiler
> manual nor in any Algol 60 language definition I've seen. A60 could pass
> values by name or value and procedures by name. That was it. Call by name
> is what is now referred to as reference passing.
>

Thunk has more than one meaning. The ALGOL 60 usage predates Windows
obviously.  Also, call-by-name is distinct from call-by-reference.
See:

http://en.wikipedia.org/wiki/Evaluation_strategy

And, for fun with call-by-name:

http://en.wikipedia.org/wiki/Jensen%27s_Device
http://en.wikipedia.org/wiki/Man_or_boy_test
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Importance of Terminology's Quality

2008-07-22 Thread Josef Moellers

Martin Gregorie wrote:

Are you sure about that? 



I used Algol 60 on an Elliott 503 and the ICL 1900 series back when it was
a current language. The term "thunking" did not appear in either compiler
manual nor in any Algol 60 language definition I've seen. A60 could pass
values by name or value and procedures by name. That was it. Call by name
is what is now referred to as reference passing.


Are you sure about that? ;-)

AFAIK "Call by name" is *not* the same as passing an argument by 
reference. With "call by name" you can implement this wonderful thing 
called "Jensen's Device", which you cannot do when you pass parameters 
by reference!


Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: automating python programs

2008-07-22 Thread Anish Chapagain
On Jul 21, 7:28 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 21, 2008 at 2:12 PM, Zach Hobesh <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > I'm trying to figure out how to run a python program on a schedule, maybe
> > every half an hour...  Is this possible?
>
> > Thanks!
>
> > -Zach
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> On Linux, man cron.

Hi!!
I hope if you have written the Python code in Class and module then
you can call the execution of module
in main module using yourroot.after(millisecond,moduletobe executed)
like,
 parent_root.after(3000, child1_root.destroy)#will destroy the
child1_root module after 3second at this stage in mainmodule.
 parent_root.mainloop()

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


DB Pool

2008-07-22 Thread bcurtu
Hi,

I use MySQLdb lib to access my DB, because I want to opttimize my sql
queries. The application I'm working on has quite a few traffic load,
so I want to minimize the time of creating/destroying cursors:

My typical code is sth like:

cursor=con.cursor()
cursor.execute(sql)
all= cursor.fetchall()
cursor.close()

So, the question is... how can I minimize this cost? I was thinking on
Connection Pools, but I didn't find any good documentation or sample.
Any idea?
--
http://mail.python.org/mailman/listinfo/python-list


Re: xpathEval fails for large files

2008-07-22 Thread Paul Boddie
On 22 Jul, 11:00, Kanchana <[EMAIL PROTECTED]> wrote:
>
> I tried to extract some data with xpathEval. Path contain more than
> 100,000 elements.
>
> doc = libxml2.parseFile("test.xml")
> ctxt = doc.xpathNewContext()
> result = ctxt.xpathEval('//src_ref/@editions')
> doc.freeDoc()
> ctxt.xpathFreeContext()

Another note on libraries: if you want a pure Python library which
works on top of libxml2 and the bundled Python bindings, consider
libxml2dom [1].

> this will stuck in following line and will result in high usage of
> CPU.
> result = ctxt.xpathEval('//src_ref/@editions')
>
> Any suggestions to resolve this.

How big is your document and how much memory is the process using
after you have parsed the document? Sometimes, you won't be able to
effectively handle very large documents by having them loaded
completely in memory because you'll require more main memory than your
system has available, making operations on the document somewhat
inefficient.

> Is there any better alternative to handle large documents?

Fredrik pointed out a few. There's also xml.dom.pulldom and xml.sax in
the standard library - the latter attractive mostly if you have
previous experience with it - providing stream-based processing of
documents if you don't mind writing more code.

Paul

[1] http://www.python.org/pypi/libxml2dom
--
http://mail.python.org/mailman/listinfo/python-list


Re: proliferation of computer languages

2008-07-22 Thread J�rgen Exner
Chris Rathman <[EMAIL PROTECTED]> wrote:
>I can't say that I see any particular point to the essay. 

You must be new here. There never is any particular point to  Xah Lee's
rantings except to cross-post borderline topics to borderline relevant
NGs and then lay back and enjoy the ensuing slaughter.

PLEASE DO NOT FEED THE TROLL 

>On Jul 18, 12:17 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

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


Re: Python Embedding Thread

2008-07-22 Thread googler . 1 . webmaster
Hi!

I fixed the code. This code snippet runs in a seperate thread:


PyObject *dict=NULL;
PyGILState_STATE state = PyGILState_Ensure();
dict = CreateMyGlobalDictionary();

PyRun_String(, Py_file_input, dict, 
dict);

ReleaseGlobalDictionary(dict);

But it still does not work... :-/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting List of String to Integer

2008-07-22 Thread dusans
>>> a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']]
>>> [map(int, i) for i in a]
[[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]]

On Jul 21, 9:06 pm, Samir <[EMAIL PROTECTED]> wrote:
> Hi Everyone,
>
> I am relatively new to Python so please forgive me for what seems like
> a basic question.
>
> Assume that I have a list, a, composed of nested lists with string
> representations of integers, such that
>
> a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']]
>
> I would like to convert this to a similar list, b, where the values
> are represented by integers, such as
>
> b = [[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]]
>
> I have unsuccessfully tried the following code:
>
> n = []
> for k in a:
>     n.append([int(v) for v in k])
> print n
>
> Does anyone know what I am doing wrong?
>
> Thanks in advance.
>
> Samir

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


Automatically loading and initialising objects from a plugins directory

2008-07-22 Thread Dave Challis
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I'm trying to write some code which:
1. Finds all modules in a plugin directory
2. Imports those modules
3. Creates an instance of each object defined in the module (each module
will contain exactly 1 object, which is a subclass of 'Plugin')

The closest I've come so far is with something like:

In plugin.py:
# taken from http://docs.python.org/lib/built-in-funcs.html
def my_import(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod

def import_plugins():
mods = []
for filename in os.listdir('/plugins'):
if filename.endswith('.py'):
name = os.path.splitext(filename)[0]
mods.append(my_import('plugins.' + name))
return mods

class Plugin(object):
pass


In plugins/exampleplugin.py:
class ExamplePlugin(Plugin):
def __init__(self):
pass


Calling import_plugins() then gives me a list containing references to
modules.

How can I loop through that list and create an instance of whatever
object was defined within the module? (In this case I'd want to
construct an instance of ExamplePlugin)

Thanks in advance,
Dave


- --
~~

  (
  Dave Challis) ><>
[EMAIL PROTECTED](___
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIhb/Uv26GZvAVVFERAsGaAJ9KwtFI9yXdk2gBGxy0/bjCd5318wCgsiV9
m14BZSvxqZ1EP0OvaXBZoaw=
=TYlD
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: xpathEval fails for large files

2008-07-22 Thread Jim Washington
Kanchana wrote:
> Hi,
> 
> I tried to extract some data with xpathEval. Path contain more than
> 100,000 elements.
> 
> doc = libxml2.parseFile("test.xml")
> ctxt = doc.xpathNewContext()
> result = ctxt.xpathEval('//src_ref/@editions')
> doc.freeDoc()
> ctxt.xpathFreeContext()
> 
> this will stuck in following line and will result in high usage of
> CPU.
> result = ctxt.xpathEval('//src_ref/@editions')
> 
> Any suggestions to resolve this.
> 
> Is there any better alternative to handle large documents?

One option might be an XML database.  I'm familiar with Sedna (
http://modis.ispras.ru/sedna/ ).

In practice, you store the document in the database, and let the
database do the extracting for you.  Sedna does XQuery, which is a very
nice way to get just what you want out of your document or collection of
documents.

Good:
   It's free (Apache 2.0 license)
   It's cross-platform (later Windows x86, Linux x86, FreeBSD, MacOS X)
   It has python bindings (zif.sedna at the cheese shop and others).
   It's pretty fast, particularly if you set-up indexes.
   Document and document collection size are limited only by disk space.

Not so good:
   Sedna runs as a server.  Expect to use in the range of 100M of RAM
per database. A database can contain many many documents, so you
probably only want one database, anyway.

Disclosure: I'm the author of the zif.sedna package, and I'm
interpreting the fact that I have not received much feedback as "It
works pretty well" :)


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


Re: Converting List of String to Integer

2008-07-22 Thread Rishabh Manocha
Just to throw my hat in the ring, this is another way you can do this:

[(lambda x : [int(ii) for ii in x])(y) for y in a]

However, I do think dusans way is more elegant.

Best,

R

On Tue, Jul 22, 2008 at 4:58 PM, dusans <[EMAIL PROTECTED]> wrote:

> >>> a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']]
> >>> [map(int, i) for i in a]
> [[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]]
>
> On Jul 21, 9:06 pm, Samir <[EMAIL PROTECTED]> wrote:
> > Hi Everyone,
> >
> > I am relatively new to Python so please forgive me for what seems like
> > a basic question.
> >
> > Assume that I have a list, a, composed of nested lists with string
> > representations of integers, such that
> >
> > a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']]
> >
> > I would like to convert this to a similar list, b, where the values
> > are represented by integers, such as
> >
> > b = [[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]]
> >
> > I have unsuccessfully tried the following code:
> >
> > n = []
> > for k in a:
> > n.append([int(v) for v in k])
> > print n
> >
> > Does anyone know what I am doing wrong?
> >
> > Thanks in advance.
> >
> > Samir
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python embedding question (2).

2008-07-22 Thread Thomas Troeger

Carl Banks wrote:

On Jul 17, 9:57 am, Thomas Troeger <[EMAIL PROTECTED]>
wrote:

I'd say that PyGame could be a solution.
Or otherwise you could do your own audio/graphics programming (you don't
tell us which OS you use, but there exist python modules that allow you
to do barebones graphics & sound programming on linux...).

Pyglet runs on top of OpenGL, which might have performance problems on
an embedded device, if OpenGL or Mesa is even supported.  If it's
supported, I suspect performance will be adequate for 2D drawing.  It
almost certainly is the lightest solution you can find.


Carl Banks


I've managed to put together a small pyGame program, it runs smoothly 
and seems to be exactly what I wanted. It's fast! Even with 100 moving 
objects it still runs so fast that I can consider using Python/pyGame 
for the whole project.


There are still some questions left which I haven't found out by myself, 
so maybe someone here can answer them:


- I can't see how to create more sophisticated text output, it seems the 
built in font render facilities are limited to simple strings. Is that 
true? I'd need a way to at least render multiline text with paragraphs 
and bidirectionality, like pango does it. Is there a way to integrate 
pango support into pyGame? I'd prefer marked up text display with text 
properties ...
- Is there some way to reserve screen areas so they are excluded from a 
blit, or do I have to manage stuff like this myself? I am thinking about 
several graphic layers where each layer is painted on top of the next 
layer, for example to draw a gui in front of a background image.
- There seems to be support for video overlay, i.e. is it possible to 
have an external program paint an image from a camera into a portion of 
the screen while pyGame is running?


Maybe this is the wrong list to ask, so please forgive the question but 
direct me to somewhere better.


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


Re: Web Page Construction in Python

2008-07-22 Thread [EMAIL PROTECTED]
Also, look at:

http://www.djangoproject.com/

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


Re: Time Complexity of String Operations

2008-07-22 Thread youtoo

On 22 jul, 01:39, "David Wahler" <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 21, 2008 at 10:31 PM, youtoo <[EMAIL PROTECTED]> wrote:
> > It has been extensively discussed the time complexity (quadratic) of
> > string concatenation (due to string's immutability).
>
> Actually, it is roughly linear, at least for reasonable string lengths:
>
> $ python -V
> Python 2.5.2
> $ python -mtimeit -s "n=1000; a='#'*n" "a+a"
> 100 loops, best of 3: 1 usec per loop
> $ python -mtimeit -s "n=1; a='#'*n" "a+a"
> 10 loops, best of 3: 5.88 usec per loop
> $ python -mtimeit -s "n=10; a='#'*n" "a+a"
> 1 loops, best of 3: 59.8 usec per loop
>
> Repeatedly constructing a string by appending a constant number of
> characters at a time, however, is quadratic in the final string length
> (although VM optimizations may affect this).
>
> > But what is:
>
> > == the time complexity of string indexing? Is it constant?
>
> Yes.
>
> > == the time complexity of string slicing? Is it O(K) with K the
> > slice's length?
>
> I suspect so, since the time is dominated by the time taken to copy
> the data into a new string object.
>
> > How are strings stored in Python? As arrays? As linked lists?
>
> Arrays; see Include/stringobject.h in the Python source distribution.
>
> -- David

Thank you very much!

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


is it possible to add a property to an instance?

2008-07-22 Thread Darren Dale
Does anyone know if it is possible to add a property to an instance at
runtime? I didn't see anything about it in the standard library's new
module, google hasn't turned up much either.

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


Re: The Importance of Terminology's Quality

2008-07-22 Thread Rob Warnock
Martin Gregorie  <[EMAIL PROTECTED]> wrote:
+---
| John W Kennedy wrote:
| > No, the "thunks" were necessary at the machine-language level to 
| > /implement/ ALGOL 60, but they could not be expressed /in/ ALGOL.
|
| Are you sure about that? 
+---

I don't know if John is, but *I* am!  ;-}

+---
| I used Algol 60 on an Elliott 503 and the ICL 1900 series back when
| it was a current language. The term "thunking" did not appear in either
| compiler manual nor in any Algol 60 language definition I've seen.
+---

It wouldn't have been. Thunks were something used by Algol 60
*compiler writers* in the code generated by their compilers to
implement the semantics of Algol 60 call-by-name, but were not
visible to users at all [except that they allowed call-by-name
to "work right"].

+---
| A60 could pass values by name or value and procedures by name. That
| was it. Call by name is what is now referred to as reference passing.
+---

(*sigh*) NO, IT IS NOT!!!  Please go read the following:

http://en.wikipedia.org/wiki/Thunk
http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_name
http://en.wikipedia.org/wiki/Jensen%27s_Device

+---
| [Algol 60] did not have a mechanism for declaring anonymous procedures.
+---

Quite correct, but completely off the mark. While an Algol 60 *user*
could not declare an anonymous procedure, the *implementation* of an
Algol 60 compilers required the ability for the compiler itself to
generate/emit internal anonymous procedures, to wit, the above-mentioned
thunks, sometimes creating them dynamically during the procedure call.
[Actually, a pair of them for each actual argument in a procedure call.]

+---
| That, like the incorporation of machine code inserts, would have been
| a compiler-specific extension, so it is a terminological mistake to
| refer to it without specifying the implementing compiler.
+---

Again, "incompetent, irrelevant, and immaterial" [as Perry Mason used
to so frequently object during trials]. Thunks were not "extensions" to
Algol 60 compilers; they were part of the basic implementation strategy
*within* Algol 60 compilers, necessary because of the semantics required
by call-by-name.

Basically, in Algol 60, each parameter must be passed [in general,
that is, one can optimize away many special cases] as *two* closures --
conventionally called "thunks" by Algol 60 compiler writers -- one
for "getting" (evaluating) and the other for "setting" the parameter
[if the parameter was a "place" in Common Lisp terms, else an error
was signalled]... IN THE CALLER'S LEXICAL ENVIRONMENT!!

The big deal was two-fold: (1) each time a formal parameter was
*referenced* in a callee, the expression for the actual parameter
in the caller had to be *(re)evaluated* in the *caller's* lexical
environment, and the value of that (re)evaluation used as the
value of the referenced formal parameter in the callee; and
(2) if a variable appeared twice (or more) in a parameter list,
say, once as a naked variable [which is a "place", note!] and again
as a sub-expression of a more complicated parameter, then setting
the formal parameter in the *callee* would *change* the value of
the actual parameter in the caller(!!), which in turn would change
the value of the *other* actual parameter in the caller the next time
it was referenced in the callee. The above-referenced "Jensen's Device"
shows how this can be used to do "very tricky stuff". A simpler and
shorter example is here:

http://www.cs.rit.edu/~afb/20013/plc/slides/procedures-07.html

Because the actual parameters in the callee had to be evaluated
in the *caller's* lexical environment -- and because Algol 60 was
fully recursive, allowed nested procedure definitions, and could
pass "local" procedures as arguments -- efficient implementation of
Algol 60 procedure calls almost necessitated placing the bodies
of the compiler-generated actual parameter thunks on the caller's
dynamic stack frame [or at least call instructions *to* the thunks
which could pass the current lexical contours as sub-arguments].
Knuth's nasty "man or boy test" stressed this to the limit:

http://en.wikipedia.org/wiki/Man_or_boy_test


-Rob

p.s. IIRC [but it's been a *long* time!], the ALGOL-10 compiler
for the DEC PDP-10 passed each actual parameter as the address of
a triple of words, of which the first two were executable and the
third could be used to store a variables value (simple case) or
to pass the lexical contour (more complicated case). When the
callee needed to reference (evaluate) an argument, it used the 
PDP-10 XCT ("execute") instruction to execute the first word of
the block, which was required to deliver the value to a standard
register [let's say "T0", just for concreteness], and if the callee
wanted to *set* an argument, it executed the *second* word pointed
to by the passed address, with the new value also in a

Re: Problem with Python Server Pages (PSP)

2008-07-22 Thread Sebastian "lunar" Wiesner
[EMAIL PROTECTED] <[EMAIL PROTECTED]>:

> Hi,
> 
> I am facing a very basic problem with PSP. I have installed mod_python
> (in fedora Core 1), added the lines required for loading Python
> modules and handling PSP pages. I have created a hello.psp page. But
> when I try to view this hello.psp page, all Python code are getting
> displayed.

Not directly related to this issue, but I wouldn't start developing with
PSP.  Modern web development is better done with a WSGI compatible
framework like Django ...

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


Re: simple question about dictionaries

2008-07-22 Thread Jeff
On Jul 21, 8:14 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Jeff wrote:
> >   throw KeyError('%s not found' % str(val))
>
> "throw"?  and shouldn't that be a ValueError? ;-)
>
> 

Whoops.  Been working in too many different languages at the same
time :).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically loading and initialising objects from a plugins directory

2008-07-22 Thread Diez B. Roggisch
Dave Challis wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> I'm trying to write some code which:
> 1. Finds all modules in a plugin directory
> 2. Imports those modules
> 3. Creates an instance of each object defined in the module (each module
> will contain exactly 1 object, which is a subclass of 'Plugin')
> 
> The closest I've come so far is with something like:
> 
> In plugin.py:
> # taken from http://docs.python.org/lib/built-in-funcs.html
> def my_import(name):
> mod = __import__(name)
> components = name.split('.')
> for comp in components[1:]:
> mod = getattr(mod, comp)
> return mod
> 
> def import_plugins():
> mods = []
> for filename in os.listdir('/plugins'):
> if filename.endswith('.py'):
> name = os.path.splitext(filename)[0]
> mods.append(my_import('plugins.' + name))
> return mods
> 
> class Plugin(object):
> pass
> 
> 
> In plugins/exampleplugin.py:
> class ExamplePlugin(Plugin):
> def __init__(self):
> pass
> 
> 
> Calling import_plugins() then gives me a list containing references to
> modules.
> 
> How can I loop through that list and create an instance of whatever
> object was defined within the module? (In this case I'd want to
> construct an instance of ExamplePlugin)


Like this:

for name in dir(plugin):
thing = getattr(plugin, name)
try:
   if issubclass(thing, Plugin):
  thing()
except ValueError: # issubclass sucks
   pass

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


Re: simple question about dictionaries

2008-07-22 Thread Jeff
On Jul 21, 8:14 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Jeff wrote:
> >   throw KeyError('%s not found' % str(val))
>
> "throw"?  and shouldn't that be a ValueError? ;-)
>
> 

Whoops.  Been working in too many different languages at the same
time :).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python embedding question (2).

2008-07-22 Thread Uwe Schmitt
On 22 Jul., 14:07, Thomas Troeger <[EMAIL PROTECTED]>
wrote:
> Carl Banks wrote:
> > On Jul 17, 9:57 am, Thomas Troeger <[EMAIL PROTECTED]>
> > wrote:
> >>> I'd say that PyGame could be a solution.
> >>> Or otherwise you could do your own audio/graphics programming (you don't
> >>> tell us which OS you use, but there exist python modules that allow you
> >>> to do barebones graphics & sound programming on linux...).
> > Pyglet runs on top of OpenGL, which might have performance problems on
> > an embedded device, if OpenGL or Mesa is even supported.  If it's
> > supported, I suspect performance will be adequate for 2D drawing.  It
> > almost certainly is the lightest solution you can find.
>
> > Carl Banks
>
> I've managed to put together a small pyGame program, it runs smoothly
> and seems to be exactly what I wanted. It's fast! Even with 100 moving
> objects it still runs so fast that I can consider using Python/pyGame
> for the whole project.
>
> There are still some questions left which I haven't found out by myself,
> so maybe someone here can answer them:
>
> - I can't see how to create more sophisticated text output, it seems the
> built in font render facilities are limited to simple strings. Is that
> true? I'd need a way to at least render multiline text with paragraphs
> and bidirectionality, like pango does it. Is there a way to integrate
> pango support into pyGame? I'd prefer marked up text display with text
> properties ...
> - Is there some way to reserve screen areas so they are excluded from a
> blit, or do I have to manage stuff like this myself? I am thinking about
> several graphic layers where each layer is painted on top of the next
> layer, for example to draw a gui in front of a background image.
> - There seems to be support for video overlay, i.e. is it possible to
> have an external program paint an image from a camera into a portion of
> the screen while pyGame is running?
>
> Maybe this is the wrong list to ask, so please forgive the question but
> direct me to somewhere better.
>
> Cheers,
> Thomas.

Maybe http://sourceforge.net/projects/pygameui/ helps you,
at least the source code.

Greetings, Uwe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-22 Thread Grant Edwards
On 2008-07-22, Larry Bates <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>> On 2008-07-22, Larry Bates <[EMAIL PROTECTED]> wrote:
>> 
>>> You talk about "writing it in assembly language for each MPU
>>> chip".  Actually it is even better than that.  We now have
>>> these modern inventions, called compilers that do that type of
>>> work for us.  They translate high level instructions, not 
>>> into assembler but into machine language.
>> 
>> Actually, all of the compilers I'm familiar with (gcc and a
>> handful of cross compilers for various microprocessors)
>> translate from high-level languages (e.g. C, C++) into
>> assembly, which is then assembled into relocatable object
>> files, which are then linked/loaded to produce machine
>> language.
>> 
> I just learned something I did not know.  I was under the
> impression that they translated directly to machine code
> without ever actually generating Assembler text files.

There may indeed be compilers that work that way.  On Unix
systems (which is what I work with) compilers have
traditionally generated assembly language files.

> Seems like a waste to generate the text and turn around run
> that through the assembler, but what do I know.  I guess that
> way the compiler can have pluggable assembler back-ends.

Since you probably need an assembler anyway, generating
assembly-language in the compiler prevents you from having to
duplicate a bunch of object-code-generation code in two places.

-- 
Grant Edwards   grante Yow! Okay ... I'm going
  at   home to write the "I HATE
   visi.comRUBIK's CUBE HANDBOOK FOR
   DEAD CAT LOVERS" ...
--
http://mail.python.org/mailman/listinfo/python-list


Re: is it possible to add a property to an instance?

2008-07-22 Thread Diez B. Roggisch
Darren Dale wrote:

> Does anyone know if it is possible to add a property to an instance at
> runtime? I didn't see anything about it in the standard library's new
> module, google hasn't turned up much either.

Depending on what you *really* want - yes or no.

It is *not* possible to have a property *only* on one instance, because
properties rely on the descriptor-protocol being used, and that only works
for class-attributes. So it's not a matter of "only" adding 

a = Foo()

a.something = property(...)


However, you can of course try & come up with a scheme that only invokes
getters and setters if defined, and otherwise returns a
default-value/raises an attribute-error. Roughly like this:


class Base(object):
  
   def x_get(self):
   return self.x_get_overload()

   x = property(x_get)


a = Base()

def foo(self):
return "something"

a.x_get_overload = new.instancemethod(foo)

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


Re: is it possible to add a property to an instance?

2008-07-22 Thread GHUM
> Does anyone know if it is possible to add a property to an instance at
> runtime? I didn't see anything about it in the standard library's new
> module, google hasn't turned up much either.

yes. You need nothing special, just add it:

class fish(object):
pass

a=fish()
a.legs=4
print a.legs

(or print (a.legs) on Python 3.0 and above)

so you add a property to an instance and proove that Darwin was right
in one go.

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


Re: Python embedding question (2).

2008-07-22 Thread alex23
On Jul 22, 10:07 pm, Thomas Troeger <[EMAIL PROTECTED]>
wrote:
> Maybe this is the wrong list to ask, so please forgive the question but
> direct me to somewhere better.

http://groups.google.com/group/pygame-mirror-on-google-groups

There are instructions on that page for joining the mailing list if
Google Groups aren't your thing.
--
http://mail.python.org/mailman/listinfo/python-list


Re: is it possible to add a property to an instance?

2008-07-22 Thread Darren Dale
GHUM wrote:

>> Does anyone know if it is possible to add a property to an instance at
>> runtime? I didn't see anything about it in the standard library's new
>> module, google hasn't turned up much either.
> 
> yes. You need nothing special, just add it:
> 
> class fish(object):
> pass
> 
> a=fish()
> a.legs=4
> print a.legs

Sorry, that's an attribute, not a property.

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


Re: Change PC to Win or Windows

2008-07-22 Thread Lie Ryan
On Mon, 2008-07-21 at 18:50 -0400, Derek Martin wrote:
> On Mon, Jul 21, 2008 at 02:47:31PM -0700, Lie wrote:
> > Common usage isn't always correct. 
> 
> Actually it is, inherently...  When usage becomes common, the language
> becomes redefined, and its correctness is therefore true by identity
> (to borrow a mathematical term).  The scholars complain for a while,
> but eventually capitulate, and re-write the dictionary.  Language
> bends to its use by the people, not the other way around.  Your
> assumption is the opposite, and therefore all of your argument is
> false.

But until the dictionary is rewritten, it is incorrect usage. Since
dictionary isn't rewritten unless (nearly) the whole world agrees with
it, not all parts of the world used the term PC exclusively for
Windows-based computer, in this part of the world specifically, PC is
used for any desktop computers. Therefore your argument is false (at
least: yet).

> > For example, a physicist would not use weight when he meant mass. 
> > much, but in technical environment doing so would embarrass him. In
> > this analogy, I consider download page for a software source code to
> > be a technical area.
> 
> Your analogy is still broken.  The term "PC" has been used BY
> TECHNCIAL PEOPLE, IN A TECHNICAL CONTEXT, to mean Microsoft on Intel,
> FOR DECADES.

Yes, and they are wrong on using it. So do some physicist, before the
clear distinction is drawn explicitly between mass and weight.

FOR DECADES, people used the term PC for all sorts of things, in the
most technically correct usage, only IBM-branded home computers could be
called a PC, since PC is officially their advertising term. However,
since Personal Computer is a brand-neutral term (unlike iMac, Lifebook,
etc), it have the tendency to be extended (by the people) to include
other personally owned computers as well. The technically correct
extension would be "PC is computers that is designed and marketed for
personal possession and use", which means it doesn't matter what OS it
is, what hardware it uses. A debate (or a long observation to the
people) might be needed to determine whether that definition extension
is acceptable, but the definition extension you mentioned: "PC is
Windows-based computer" needs no debate, it is completely wrong and is a
baseless misunderstanding.

>  + Authors of technical books, manuals, and other forms of
>documentation have refered to them as PCs... for decades.
> 
>  + Educators in CS and EE at major universities have refer to them as
>PCs, since at least as early as 1988 (when I started college).

I'm sure they were mentioning IBM-PC and its clones, not mentioning
Windows itself. (Well, it's true that IBM-PC and its clones is mostly
Windows-based, but PC is a term for the combination of hardware and
software that makes a personal computer, in the current incorrect usage,
PC is Windows, a software.)

>  + Industry news publications such as Computer World have refered to
>them as PCs, for decades.
> 
>  + There are even whole magazines dedicated to them! (PC Magazine, PC
>Shopper, PC World, PC Gamer, etc.)  They are dedicated to Microsoft
>on Intel, and have existed (at least in some cases) long before
>Apple started talking about PCs in their ads.

Excuse me, those magazines (at least in this part of the world) also
contain non-Microsoft articles. The fact that Windows articles is the
dominant topic, is solely because most of their subscribers are Windows
user, it is not as profitable to write about Linux and Mac and Unix.

> All of this has been going on, essentially since there has been such
> a thing as the IBM PC.  I'm sorry, but you sir, are quite simply,
> plainly, and completely, wrong.  

Compounded with misunderstanding, you sir, are very well ignorant.

> With a catastrophic amount of
> written documentation, written by technical people in the computer
> industry over the last 20+ years, to prove it.
> 
> > > > Apple popularizes the term by explicit marketing,
> > >
> > > And here is the last point you are missing: Apple does no such
> > > thing.
> > 
> > They did, by using the term PC to refer to other computers. 
> 
> APPLE CAN NOT POPULARIZE A TERM WHICH IS ALREADY POPULAR.  

Sure it catches the wave that has been going on for some time. And use
it to their own advantage. I've mentioned that Apple could not be blamed
so much for this, since with or without them, the term would become
popular, although its meaning mightn't have been as twisted as nowadays.

> > This kind of advertising Apple (the computer company) used is
> > misleading, since it implied that their PC is not a PC.
> 
> They haven't implied anything; they're stating it outright!  Apple
> sells personal computers, but they do not sell PCs.  Apple's personal
> computer is NOT a PC, and never was, and never will be.  It's an
> Apple.

Apple's personal computer is NOT a PC? Aren't you contradicting
yourself? Just like what Apple, you have just said: "I'm Apple, 

Re: Converting List of String to Integer

2008-07-22 Thread ptn
> n = []
> for k in a:
>     n.append([int(v) for v in k])
> print n
>
> Does anyone know what I am doing wrong?
>
> Thanks in advance.
>
> Samir

Use extend instead of append:

* Append -> add the one item to the end of the list
* Extend -> add the list of items to the end of the list
--
http://mail.python.org/mailman/listinfo/python-list


tkinter for my python program !!

2008-07-22 Thread karthikbalaguru
Hi,

One of my python program needs tkinter to be installed to run
successfully.
I am using Redhat 9.0 and hence tried installing by copying the
tkinter-2.2.2-36.i386.rpm
alone from the CD 3 to my pc. But, it is not getting installed and is
failing by throwing
the below errors. Should i need to configure / install any specific
files for resolving this issue ?

[EMAIL PROTECTED] karthik]# rpm -ivh tkinter-2.2.2-26.i386.rpm
warning: tkinter-2.2.2-26.i386.rpm: Header V3 DSA signature: NOKEY,
key ID db42a
60e
error: Failed dependencies:
libtcl8.3.so is needed by tkinter-2.2.2-26.i386
libtix8.1.8.3.so is needed by tkinter-2.2.2-26.i386
libtk8.3.so is needed by tkinter-2.2.2-26.i386

Any ideas ?

Thx in advans,
Karthik Balaguru
--
http://mail.python.org/mailman/listinfo/python-list


Re: DB Pool

2008-07-22 Thread Diez B. Roggisch
bcurtu wrote:

> Hi,
> 
> I use MySQLdb lib to access my DB, because I want to opttimize my sql
> queries. The application I'm working on has quite a few traffic load,
> so I want to minimize the time of creating/destroying cursors:
> 
> My typical code is sth like:
> 
> cursor=con.cursor()
> cursor.execute(sql)
> all= cursor.fetchall()
> cursor.close()
> 
> So, the question is... how can I minimize this cost? I was thinking on
> Connection Pools, but I didn't find any good documentation or sample.
> Any idea?

What has the above (getting *cursors* from a given connection) to do with
connection-pooling?

I'm not sure what the actual costs of creating a cursor are (might well be
that these are neglibel) but why don't you stop closing the cursor and just
re-use it?

Connection pooling is of course useful - frameworks such as SQLAlchemy and
SQLObject do that for you, if used proper.


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


Re: regarding SWIG

2008-07-22 Thread Diez B. Roggisch
Anish Chapagain wrote:

> Hi..
> I'm new to SWIG and need to create Wrapper for C code,
> so, I have installed the SWIG already but doesnot know how to run it
> for generating Interface file...
> My C code is in message.c so what do i need to do the first
> step..uisng SWIG..i read the documentation but cannot grasp creating
> interface file.

If it's pure C, stop using SWIG. Create a DLL/SO-file of your message.c &
use ctypes to wrap that.


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


Re: tkinter for my python program !!

2008-07-22 Thread Diez B. Roggisch
karthikbalaguru wrote:

> Hi,
> 
> One of my python program needs tkinter to be installed to run
> successfully.
> I am using Redhat 9.0 and hence tried installing by copying the
> tkinter-2.2.2-36.i386.rpm
> alone from the CD 3 to my pc. But, it is not getting installed and is
> failing by throwing
> the below errors. Should i need to configure / install any specific
> files for resolving this issue ?
> 
> [EMAIL PROTECTED] karthik]# rpm -ivh tkinter-2.2.2-26.i386.rpm
> warning: tkinter-2.2.2-26.i386.rpm: Header V3 DSA signature: NOKEY,
> key ID db42a
> 60e
> error: Failed dependencies:
> libtcl8.3.so is needed by tkinter-2.2.2-26.i386
> libtix8.1.8.3.so is needed by tkinter-2.2.2-26.i386
> libtk8.3.so is needed by tkinter-2.2.2-26.i386
> 
> Any ideas ?

Yes: you should consider reading error-messages. What does

error: Failed dependencies:
 libtcl8.3.so is needed by tkinter-2.2.2-26.i386
 libtix8.1.8.3.so is needed by tkinter-2.2.2-26.i386
 libtk8.3.so is needed by tkinter-2.2.2-26.i386

look like for you? 

Small hint: if you install something that depends on something else, you
need to  the missing dependency first. Fill in the dots...

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


Re: fromfile error on windows, not mac

2008-07-22 Thread jadamwil
On Jul 22, 2:05 am, Uwe Schmitt <[EMAIL PROTECTED]>
wrote:
> jadamwil schrieb:
>
>
>
> > Hello,
> > I am using the numpy fromfile function to read binary data from a file
> > on disk. The problem is that the program runs fine on a Mac, but gives
> > an error or warning on windows when trying to read the data. I use it
> > like this:
>
> > Signal = zeros((N, 16), dtype=float32)
> > for sample in range(0, N):
> >   # this function gets the next position in the file to seek to
> >   s = getFilePos(sample)
>
> >   # go to the correct location in the file; this IS checked to make
> > sure it is within the file
> >   mFile.seek(s)
>
> >   # read the 16 float32 values from the file
> >   D = fromfile(mFile, dtype=numpy.float32, 16)
>
> >   # save D in Signal
> >   Signal[sample, :] = D
>
> > This will fail when sample is ~4. If I change the range to (5,N),
> > skipping the "bad" file location, it will run fine for a few samples,
> > and then give another error. The message it gives is:
> > "16 items requested but only 7 read"
>
> > So D is a 7x1 vector, and the program dies when it tries to assign D
> > to the slice of Signal ("ValueError: shape mismatch: objects cannot be
> > broadcast to a single shape").
>
> > On windows, the Python version is 2.5.2, and the most recent numpy and
> > scipy are being used as well. I tried using Enthought, but it gave
> > this error as well, in addition to a c runtime error whenever I
> > imported scipy (which is another post topic...).
>
> > Any ideas on what might be causing this? Is there a way to debug the
> > fromfile function? And, remember, this works perfectly on a Mac. Would
> > compiling everything (python, scipy, numpy) potentially solve this?
>
> Did you open the file in binary mode ?
>
> Greetings, Uwe

Yes I did. Would that make a difference between a mac and windows?
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Importance of Terminology's Quality

2008-07-22 Thread Lew

Rob Warnock wrote:

Martin Gregorie  <[EMAIL PROTECTED]> wrote:
+---
| John W Kennedy wrote:
| > No, the "thunks" were necessary at the machine-language level to 
| > /implement/ ALGOL 60, but they could not be expressed /in/ ALGOL.

|
| Are you sure about that? 
+---


I don't know if John is, but *I* am!  ;-}


At this point we are so far off topic for clj.programmer, but still impinging 
on functional programming issues with the discussion of closures, et al., that 
I respectfully request that you all exclude clj.programmer from followups to 
this thread.


(f-u set to comp.lang.functional)

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


need thumbnail from video

2008-07-22 Thread John Fabiani
Hi,
I need a py tool that will provide a thumbnail (bmp?) from a video (avi,
wmv) that will be cross platform (linux, windows).  Research has provided
pymedia for Linux but I haven't found anything for windows.  Hopefully,
someone has had to do this in the past and knows what has to be done.

Thanks in Advance,
Johnf 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-22 Thread Ethan Furman

Iain King wrote:

On Jul 21, 6:58 am, "Krishnakant Mane" <[EMAIL PROTECTED]> wrote:


First off all c# is absolute rubbish waist of time.  if I need to
learn it then I better lern java or pythonfor that matter.  and by the
way what is a "real programmer?"


The story of a Real Programmer:

http://www.pbm.com/~lindahl/mel.html

Iain


Wow.  Awesome story.
~Ethan

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


Re: regarding SWIG

2008-07-22 Thread Hyuga
On Jul 22, 5:34 am, Anish Chapagain <[EMAIL PROTECTED]> wrote:
> Hi..
> I'm new to SWIG and need to create Wrapper for C code,
> so, I have installed the SWIG already but doesnot know how to run it
> for generating Interface file...
> My C code is in message.c so what do i need to do the first
> step..uisng SWIG..i read the documentation but cannot grasp creating
> interface file.
>
> thank's anish

Not sure where you're having trouble. I can understand if there's a
language barrier, but I think that the introductory SWIG documentation
is pretty darn straightforward, even if you just look at the code, so
I don't think there's anything that could be said here that's any more
clear, as far as the basics are concerned.  You'd have to explain
exactly what it is you're stuck on.
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter for my python program !!

2008-07-22 Thread karthikbalaguru
On Jul 22, 6:32 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> karthikbalaguru wrote:
> > Hi,
>
> > One of my python program needs tkinter to be installed to run
> > successfully.
> > I am using Redhat 9.0 and hence tried installing by copying the
> > tkinter-2.2.2-36.i386.rpm
> > alone from the CD 3 to my pc. But, it is not getting installed and is
> > failing by throwing
> > the below errors. Should i need to configure / install any specific
> > files for resolving this issue ?
>
> > [EMAIL PROTECTED] karthik]# rpm -ivh tkinter-2.2.2-26.i386.rpm
> > warning: tkinter-2.2.2-26.i386.rpm: Header V3 DSA signature: NOKEY,
> > key ID db42a
> > 60e
> > error: Failed dependencies:
> > libtcl8.3.so is needed by tkinter-2.2.2-26.i386
> > libtix8.1.8.3.so is needed by tkinter-2.2.2-26.i386
> > libtk8.3.so is needed by tkinter-2.2.2-26.i386
>
> > Any ideas ?
>
> Yes: you should consider reading error-messages. What does
>
> error: Failed dependencies:
>  libtcl8.3.so is needed by tkinter-2.2.2-26.i386
>  libtix8.1.8.3.so is needed by tkinter-2.2.2-26.i386
>  libtk8.3.so is needed by tkinter-2.2.2-26.i386
>
> look like for you?
>
> Small hint: if you install something that depends on something else, you
> need to  the missing dependency first. Fill in the dots...
>

I find that it needs python-2.2.2-26.i386 and hence i tried installing
python and i
land here :( :(

[EMAIL PROTECTED] karthik]# rpm -ivh python-2.2.2-26.i386.rpm
warning: python-2.2.2-26.i386.rpm: Header V3 DSA signature: NOKEY, key
ID db42a60e
error: Failed dependencies:
libdb-4.0.so is needed by python-2.2.2-26.i386
python < 2.4.3-18.fc6 conflicts with python-
devel-2.4.3-18.fc6.i386
[EMAIL PROTECTED] karthik]#


I find that python 2.4.3-18.fc6 is being used by many of applications.
But, the program i am trying to run needs python-2.2.2-26.
So, how to resolve this issue ?

Thx in advans,
Karthik Balaguru
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter for my python program !!

2008-07-22 Thread Diez B. Roggisch
karthikbalaguru wrote:

> On Jul 22, 6:32 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> karthikbalaguru wrote:
>> > Hi,
>>
>> > One of my python program needs tkinter to be installed to run
>> > successfully.
>> > I am using Redhat 9.0 and hence tried installing by copying the
>> > tkinter-2.2.2-36.i386.rpm
>> > alone from the CD 3 to my pc. But, it is not getting installed and is
>> > failing by throwing
>> > the below errors. Should i need to configure / install any specific
>> > files for resolving this issue ?
>>
>> > [EMAIL PROTECTED] karthik]# rpm -ivh tkinter-2.2.2-26.i386.rpm
>> > warning: tkinter-2.2.2-26.i386.rpm: Header V3 DSA signature: NOKEY,
>> > key ID db42a
>> > 60e
>> > error: Failed dependencies:
>> > libtcl8.3.so is needed by tkinter-2.2.2-26.i386
>> > libtix8.1.8.3.so is needed by tkinter-2.2.2-26.i386
>> > libtk8.3.so is needed by tkinter-2.2.2-26.i386
>>
>> > Any ideas ?
>>
>> Yes: you should consider reading error-messages. What does
>>
>> error: Failed dependencies:
>>  libtcl8.3.so is needed by tkinter-2.2.2-26.i386
>>  libtix8.1.8.3.so is needed by tkinter-2.2.2-26.i386
>>  libtk8.3.so is needed by tkinter-2.2.2-26.i386
>>
>> look like for you?
>>
>> Small hint: if you install something that depends on something else, you
>> need to  the missing dependency first. Fill in the dots...
>>
> 
> I find that it needs python-2.2.2-26.i386 and hence i tried installing
> python and i
> land here :( :(
> 
> [EMAIL PROTECTED] karthik]# rpm -ivh python-2.2.2-26.i386.rpm
> warning: python-2.2.2-26.i386.rpm: Header V3 DSA signature: NOKEY, key
> ID db42a60e
> error: Failed dependencies:
> libdb-4.0.so is needed by python-2.2.2-26.i386
> python < 2.4.3-18.fc6 conflicts with python-
> devel-2.4.3-18.fc6.i386
> [EMAIL PROTECTED] karthik]#
> 
> 
> I find that python 2.4.3-18.fc6 is being used by many of applications.
> But, the program i am trying to run needs python-2.2.2-26.
> So, how to resolve this issue ?

Are you *sure* it requires python2.2? If yes, why can't fedora install
several python versions together? Ubuntu for sure can. But Python2.2 is
*ancient* - you might need to compile it yourself.

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


Re: Converting List of String to Integer

2008-07-22 Thread Samir
Wow!  Thanks for all of the great additional feedback and responses
since I last checked in.  The help this group provides is amazing.
I'm glad I found it.

@Andrew -- Thanks for the clarification on the nested for loop and how
to intrepret it.  Also, thanks for the information on generators.  I
have never come across this before so I will look into it a bit more.
The same thing goes for iPython.  I have been looking for an IDE that
comes with better debugging capabilities that the default Python
shell.

@dusans -- Just when I thought I couldn't simplify my code anymore,
you provide come up with another way.  Thank you.

@ptn -- Thanks for the explanation between "append" and "extend".  I
guess I've gotten lazy and have always used "append", apparently even
in situations where it may not be appropriate.

Thanks again, everyone!

Samir


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


Re: Best Python packages?

2008-07-22 Thread Ben Sizer
On Jul 19, 5:59 pm, Kay Schluehr <[EMAIL PROTECTED]> wrote:
>
> In the original post you asked for "hidden gems" and now it seems you
> just want to know about Madonna or Justin Timberlake.

Not really, and I don't see why you'd say that.

> Maybe a look on this collection helps
>
> http://wiki.python.org/moin/UsefulModules

Yeah, I saw that. I hoped some people might have some more, but
perhaps not.

--
Ben Sizer

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


convert list of lists to list

2008-07-22 Thread antar2
Is there a way to convert list_of_listsA to list_of_listsB, where one
list in listof lists A is one element of listB?

list_of_listsA:
[['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['koe'],
['arm*', '*', '*(haar)'],
['groei*', '*', '*', '*', '*']]

listB:
['klas* * *', 'mooi* * * *, 'koe',  'arm* * * (haar)',  'groei* * * *
*']

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


Is this a valid use of 'import'?

2008-07-22 Thread Frank Millman
Hi all

I am familiar enough with the normal use of 'import'. However, I have
found a use for it which seems effective, but I have not seen it used
like this before, so I am not sure if there are any downsides.

I know that when a module is imported the first time, it is
'executed'. This normally entails setting up constants, classes,
functions, etc, that you want to make available to the importer.

In this particular case, when it is executed, it does a whole lot
more. It reads in some parameters, establishes a socket connection,
starts a thread, and starts monitoring the socket using select.select.
It also exposes some functions that disguise the complexity of reading
from and writing to the socket.

This enables me to write a 'client' program that look like this -

---
from Utils.client import *

connect(userid='frank',pwd='')
cust = getRecord(
company='chagford',table='ArCustomers',
column='CustNo',value='A001')
print cust
close()
---

As you can see, it makes writing a client program very easy.

Are there any problems with this approach?

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


Re: Is this a valid use of 'import'?

2008-07-22 Thread Tim Golden

Frank Millman wrote:

In this particular case, when it is executed, it does a whole lot
more. It reads in some parameters, establishes a socket connection,
starts a thread, and starts monitoring the socket using select.select.
It also exposes some functions that disguise the complexity of reading
from and writing to the socket.


This is not, in general, a good idea, no matter how appealing!
There is some subtle stuff going on within the chain of imports,
and firing off a new thread is quite likely to confuse it in
nasty ways later on. Less attractive though it may be, you're
better off having a "startup" function or whatever and calling
that:

import Utils.client
Utils.client.startup ()

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


Re: convert list of lists to list

2008-07-22 Thread Fredrik Lundh

antar2 wrote:


Is there a way to convert list_of_listsA to list_of_listsB, where one
list in listof lists A is one element of listB?



list_of_listsA:
[['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['koe'],
['arm*', '*', '*(haar)'],
['groei*', '*', '*', '*', '*']]

listB:
['klas* * *', 'mooi* * * *, 'koe',  'arm* * * (haar)',  'groei* * * *
*']


if there's only one level of recursion, and the lists aren't too long, 
you can simply do:


sum(list_of_lists, [])

(this has quadratic performance, so don't use it for large structures)

for recursive solutions, see:

http://www.google.com/search?q=flatten+lists+python



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


Re: convert list of lists to list

2008-07-22 Thread Stephen Johnson
list_A = [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], ['koe'],  
['arm*', '*', '*(haar)'], ['groei*', '*', '*', '*', '*']]

list_B = []
for inner_list in list_A:
#join elements of list into a string with separator ' '
list_B.append(' '.join(inner_list))
print list_B

Output:
['klas* * *', 'mooi* * * *', 'koe', 'arm* * *(haar)', 'groei* * * * *']

-Steve Johnson

On Jul 22, 2008, at 11:10 AM, antar2 wrote:


Is there a way to convert list_of_listsA to list_of_listsB, where one
list in listof lists A is one element of listB?

list_of_listsA:
[['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['koe'],
['arm*', '*', '*(haar)'],
['groei*', '*', '*', '*', '*']]

listB:
['klas* * *', 'mooi* * * *, 'koe',  'arm* * * (haar)',  'groei* * * *
*']

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


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

Question about admin rights and IDLE

2008-07-22 Thread Murphy . MarkS

Hi All,

Apologies in advance for a potentially redundant posting -- I sent a
similar question to the help box yesterday.

I have a Geographic Info System (GIS) user that is having problems
editing with Python IDLE on a WindowsXP machine unless she has admin
rights.  I had initially thought there might be a place where you can
change the 'user rights' settings in Python, but wasn't able to find it.
So, I did a fresh install of Python 2.5.1 and told it to be available to
all users during the install process.  The problem is that IDLE still
seems to be available only to the person who has admin rights on a given
machine.  Can anybody make sense of this and help me fix it?


Thanks in advance!

Mark



Mark S. Murphy
GIS/Remote Sensing Analyst
Computer Sciences Corporation
ITS-EPA Contract
79 T.W. Alexander Drive
Bldg. 4201Rm 3259
Research Triangle Park, NC 27709
Work 919-767-7088
FAX 919-767-7082
Cell 951-252-4325
[EMAIL PROTECTED]

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


Re: Is this a valid use of 'import'?

2008-07-22 Thread Matimus
On Jul 22, 8:12 am, Frank Millman <[EMAIL PROTECTED]> wrote:
> Hi all
>
> I am familiar enough with the normal use of 'import'. However, I have
> found a use for it which seems effective, but I have not seen it used
> like this before, so I am not sure if there are any downsides.
>
> I know that when a module is imported the first time, it is
> 'executed'. This normally entails setting up constants, classes,
> functions, etc, that you want to make available to the importer.
>
> In this particular case, when it is executed, it does a whole lot
> more. It reads in some parameters, establishes a socket connection,
> starts a thread, and starts monitoring the socket using select.select.
> It also exposes some functions that disguise the complexity of reading
> from and writing to the socket.
>
> This enables me to write a 'client' program that look like this -
>
> ---
> from Utils.client import *
>
> connect(userid='frank',pwd='')
> cust = getRecord(
>             company='chagford',table='ArCustomers',
>             column='CustNo',value='A001')
> print cust
> close()
> ---
>
> As you can see, it makes writing a client program very easy.
>
> Are there any problems with this approach?
>
> Frank Millman

If it works for you that is great. That module however probably isn't
very readable or easy to modify however. Also, you are hiding a lot of
the complexity in a place where it isn't expected. Chances are it
would be easy to do the same thing at the class level instead of the
module level by putting all of that setup into the __init__ method of
a class, which is the proper place to do that sort of thing. Making
your code look something like this:

from utils.client import Connection

conn = Connection(userid='frank', pwd='')
cust = conn.getRecord(
company='chagford',
table='ArCustomers',
column='CustNo',
value='A001'
)
print cust
conn.close()


Without seeing your other code it is difficult to know what the issues
might be. In general, this is what classes are for.

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


Re: Is this a valid use of 'import'?

2008-07-22 Thread Frank Millman
On Jul 22, 5:22 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> Frank Millman wrote:
> > In this particular case, when it is executed, it does a whole lot
> > more. It reads in some parameters, establishes a socket connection,
> > starts a thread, and starts monitoring the socket using select.select.
> > It also exposes some functions that disguise the complexity of reading
> > from and writing to the socket.
>
> This is not, in general, a good idea, no matter how appealing!
> There is some subtle stuff going on within the chain of imports,
> and firing off a new thread is quite likely to confuse it in
> nasty ways later on. Less attractive though it may be, you're
> better off having a "startup" function or whatever and calling
> that:
>
> import Utils.client
> Utils.client.startup ()
>
> TJG

Makes sense.

Thanks, Tim.

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


Re: Is this a valid use of 'import'?

2008-07-22 Thread Fredrik Lundh

Frank Millman wrote:


I know that when a module is imported the first time, it is
'executed'. This normally entails setting up constants, classes,
functions, etc, that you want to make available to the importer.

In this particular case, when it is executed, it does a whole lot
more. It reads in some parameters, establishes a socket connection,
starts a thread, and starts monitoring the socket using select.select.
It also exposes some functions that disguise the complexity of reading
from and writing to the socket.

This enables me to write a 'client' program that look like this -

---
from Utils.client import *

connect(userid='frank',pwd='')
cust = getRecord(
company='chagford',table='ArCustomers',
column='CustNo',value='A001')
print cust
close()
---

As you can see, it makes writing a client program very easy.

Are there any problems with this approach?


besides being fragile and not scalable and not thread-safe and 
incompatible with introspection tools and utterly surprising for people 
used to normal Python behaviour, and only marginally easier to write 
than, say:


from Utils.client import Client

c = Client()
c.connect(userid='frank',pwd='')
cust = c.getRecord(
  company='chagford',table='ArCustomers',
  column='CustNo',value='A001')
print cust
c.close()

and some other problems that I cannot think of right now, you mean?



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


Re: convert list of lists to list

2008-07-22 Thread Peter Otten
antar2 wrote:

> Is there a way to convert list_of_listsA to list_of_listsB, where one
> list in listof lists A is one element of listB?
> 
> list_of_listsA:
> [['klas*', '*', '*'],
> ['mooi*', '*', '*', '*'],
> ['koe'],
> ['arm*', '*', '*(haar)'],
> ['groei*', '*', '*', '*', '*']]
> 
> listB:
> ['klas* * *', 'mooi* * * *, 'koe',  'arm* * * (haar)',  'groei* * * *
> *']

>>> outer = [['klas*', '*', '*'],
... ['mooi*', '*', '*', '*'],
... ['koe'],
... ['arm*', '*', '*(haar)'],
... ['groei*', '*', '*', '*', '*']]
>>> [" ".join(inner) for inner in outer]
['klas* * *', 'mooi* * * *', 'koe', 'arm* * *(haar)', 'groei* * * * *']

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


Re: simple question about dictionaries

2008-07-22 Thread Bruno Desthuilliers

skazhy a écrit :

hi, i am new to python, so i've a really simple question about
dictionaries.
if i have a dictionary and I make have an input after it (to input
numbers) can i get the key of value that was in input?


What if many keys are associated with a same value, ie:
d = {'a':100, 'b':200, 'c':100}



somehting like this:
dict = { "key1"=100,"key2"=200,"key3"=300}


1/ don't use 'dict' as an indentifier - this shadows the builtin dict type.

2/ the 'dict literal' syntax is:

d = {'key1":100, "key2": 200, "key3":300}


a = input()
print 'the key of inputted value is', dict['a']

>

this syntax of course is wrong, but i hope you got the point..


Assuming you don't have duplicate values, you just need to build a 
reverse dictionnary, that is using values as keys and keys as values, 
then lookup this dictionnary. The first operation can be done in one 
single line.


reversed_d = dict((value, key) for key, value in d.items())

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


Re: convert list of lists to list

2008-07-22 Thread Fredrik Lundh

Fredrik Lundh wrote:


['klas* * *', 'mooi* * * *, 'koe',  'arm* * * (haar)',  'groei* * * *
*']


if there's only one level of recursion, and the lists aren't too long, 
you can simply do:


sum(list_of_lists, [])


oops.  that's what you get for taking the subject line too literally...

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


Re: DB Pool

2008-07-22 Thread John Nagle

bcurtu wrote:

Hi,

I use MySQLdb lib to access my DB, because I want to optimize my SQL
queries. The application I'm working on has quite a few traffic load,
so I want to minimize the time of creating/destroying cursors:

My typical code is sth like:

cursor=con.cursor()
cursor.execute(sql)
all= cursor.fetchall()
cursor.close()

So, the question is... how can I minimize this cost? I was thinking on
Connection Pools, but I didn't find any good documentation or sample.
Any idea?


   Creating and destroying MySQLdb cursors is cheap, because it
doesn't really do anything.  MySQL doesn't actually support
cursors; you can only do one thing at a time per connection, and
thus you can only have one cursor per connection.  So cursor creation
is a dummy operation for MySQLdb.

   Creating connections to the database is more expensive, and it
helps to reuse those.  There was once something called the "pool
module" for doing this ("http://dustman.net/andy/python/Pool";)
but it's a dead link now.

   This is usually an issue only in multithreaded programs.
Also, it's OK to have multiple connections open to the database
from multiple threads, until you have so many that the database
server starts to run out of resources.

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


Re: convert list of lists to list

2008-07-22 Thread Bruno Desthuilliers

antar2 a écrit :

Is there a way to convert list_of_listsA to list_of_listsB, where one
list in listof lists A is one element of listB?

list_of_listsA:
[['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['koe'],
['arm*', '*', '*(haar)'],
['groei*', '*', '*', '*', '*']]

listB:
['klas* * *', 'mooi* * * *, 'koe',  'arm* * * (haar)',  'groei* * * *
*']


Your example doesn't match your description. Assuming the example is 
correct and the description incorrect:


listB = [' '.join(sublist) for sublist in list_of_listsA]


NB : totally irrelevant, but your naming convention sucks big time IMHO.

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


Re: Automatically loading and initialising objects from a plugins directory

2008-07-22 Thread Dave Challis
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Diez B. Roggisch wrote:
> Dave Challis wrote:
> 
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>> I'm trying to write some code which:
>> 1. Finds all modules in a plugin directory
>> 2. Imports those modules
>> 3. Creates an instance of each object defined in the module (each module
>> will contain exactly 1 object, which is a subclass of 'Plugin')
>>
>> The closest I've come so far is with something like:
>>
>> In plugin.py:
>> # taken from http://docs.python.org/lib/built-in-funcs.html
>> def my_import(name):
>> mod = __import__(name)
>> components = name.split('.')
>> for comp in components[1:]:
>> mod = getattr(mod, comp)
>> return mod
>>
>> def import_plugins():
>> mods = []
>> for filename in os.listdir('/plugins'):
>> if filename.endswith('.py'):
>> name = os.path.splitext(filename)[0]
>> mods.append(my_import('plugins.' + name))
>> return mods
>>
>> class Plugin(object):
>> pass
>>
>>
>> In plugins/exampleplugin.py:
>> class ExamplePlugin(Plugin):
>> def __init__(self):
>> pass
>>
>>
>> Calling import_plugins() then gives me a list containing references to
>> modules.
>>
>> How can I loop through that list and create an instance of whatever
>> object was defined within the module? (In this case I'd want to
>> construct an instance of ExamplePlugin)
> 
> 
> Like this:
> 
> for name in dir(plugin):
> thing = getattr(plugin, name)
> try:
>if issubclass(thing, Plugin):
>   thing()
> except ValueError: # issubclass sucks
>pass
> 
> Diez

Thanks for that, it helped as a starting point.  I had some trouble with
using issubclass though (issubclass(Plugin, Plugin) returns true), which
was complicating things.

I modified your code to the following instead (which may well have it's
own pitfalls I'm not aware of!):

for name in dir(plugin):
thing = getattr(plugin, name)
if hasattr(thing, '__bases__') and \
   getattr(thing, '__bases__')[0] == Plugin:
thing()

Cheers,
Dave


- --
~~
 ><>   o  )   <><
  .   ((
 )Dave Challis<>< ))  ><>
_([EMAIL PROTECTED]((__
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIhge8v26GZvAVVFERAh86AJ91DVYPPZ/1x3rjoezFL1P5FXuHNwCZAXdr
DgjzmTNV1/H8vcQ/2Hax3js=
=ZAtM
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: convert list of lists to list

2008-07-22 Thread Raymond Hettinger
On Jul 22, 8:25 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> if there's only one level of recursion, and the lists aren't too long,
> you can simply do:
>
>      sum(list_of_lists, [])
>
> (this has quadratic performance, so don't use it for large structures)

For linear performance, you can use itertools:

  list(itertools.chain(*list_of_lists))

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


Re: string[i:j:k]

2008-07-22 Thread Terry Reedy



konstantin wrote:

Hello,
I'm not a newbie in python, but recently faced a problem in simple
expression:
some_string[i:j:k]
What does it mean? I believe this  grammar (http://docs.python.org/ref/
slicings.html) describes the syntax. But I can't grasp it.


When you post a link, please put it on one line by itself, like this:
http://docs.python.org/ref/slicings.html
so it will be clickable as a whole by modern newsreaders.

Experimenting with bits of code in the interactive interpreter (or IDLE, 
which is easier to cut from), like the responders did, is a great way to 
learn.


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


Re: Automatically loading and initialising objects from a plugins directory

2008-07-22 Thread Fredrik Lundh

Dave Challis wrote:


Thanks for that, it helped as a starting point.  I had some trouble with
using issubclass though (issubclass(Plugin, Plugin) returns true), which
was complicating things.

I modified your code to the following instead (which may well have it's
own pitfalls I'm not aware of!):

for name in dir(plugin):
thing = getattr(plugin, name)
if hasattr(thing, '__bases__') and \
   getattr(thing, '__bases__')[0] == Plugin:
thing()


so now you're no longer supporting mixins and multiple-level 
inheritance?  why not just tweak Diez' example a little:


for name in dir(plugin):

thing = getattr(plugin, name)

# make sure this is a plugin
try:
   if thing is Plugin:
   continue
   if not issubclass(thing, Plugin):
   continue
except ValueError: # issubclass sucks
   continue # not a class

thing() # probably needs error handling around this

(I also moved the thing call out of the thing validation part, to allow 
you to distinguish between ValueErrors caused by issubclass and errors 
caused by things)


(btw, another approach would be to use a metaclass to make Plugin 
classes register themselves on import)




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


Question about inheritence

2008-07-22 Thread Catherine Heathcote
If I create a new class inherited from another with a constructor, what
happens with the new class's constructer?
Thanks for your time.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Importance of Terminology's Quality

2008-07-22 Thread Steve Schafer
On Tue, 22 Jul 2008 10:21:50 +0100, Martin Gregorie
<[EMAIL PROTECTED]> wrote:

>The first time I ran across the term "thunking" was when Windows 3
>introduced the Win32S shim and hence the need to switch addressing between
>16 bit and 32 bit modes across call interfaces. That was called "thunking"
>by Microsoft and even they would surely admit it was a kludge.

Win32s thunks are a completely different beast from the original Algol
60 thunks. As far as I know, the first published description of thunks
was:

 Ingerman PZ (1961) Thunks: A way of compiling procedure statements with
 some comments on procedure declarations, CACM 4:55-58.

Steve Schafer
Fenestra Technologies Corp.
http://www.fenestra.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question about inheritence

2008-07-22 Thread Matimus
On Jul 22, 9:26 am, Catherine Heathcote
<[EMAIL PROTECTED]> wrote:
> If I create a new class inherited from another with a constructor, what
> happens with the new class's constructer?
> Thanks for your time.

Nothing, unless you call it in your constructor.

class Base(object):
 def __init__(self):
  print "Base constructor called"

# without calling the base class constructor
class C(Base):
 def __init__(self):
  print "C constructor called"

# call the base class constructor using super
class D(Base):
 def __init__(self):
  super(D, self).__init__()
  print "D constructor called"

c = C()
d = D()


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


Re: Question about inheritence

2008-07-22 Thread Catherine Heathcote
On Tue, 22 Jul 2008 09:35:58 -0700, Matimus wrote:

> On Jul 22, 9:26 am, Catherine Heathcote
> <[EMAIL PROTECTED]> wrote:
>> If I create a new class inherited from another with a constructor, what
>> happens with the new class's constructer?
>> Thanks for your time.
> 
> Nothing, unless you call it in your constructor.
> 
> class Base(object):
>  def __init__(self):
>   print "Base constructor called"
> 
> # without calling the base class constructor
> class C(Base):
>  def __init__(self):
>   print "C constructor called"
> 
> # call the base class constructor using super
> class D(Base):
>  def __init__(self):
>   super(D, self).__init__()
>   print "D constructor called"
> 
> c = C()
> d = D()
> 
> 
> Matt

Aha! Makes sence, thankyou. As you can probably tell I am new to Python,
but not programming as a whole.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question about inheritence

2008-07-22 Thread Jordan
On Jul 22, 12:26 pm, Catherine Heathcote
<[EMAIL PROTECTED]> wrote:
> If I create a new class inherited from another with a constructor, what
> happens with the new class's constructer?
> Thanks for your time.

Well, the __init__ method of the subclass is called, and from within
it you can call the superclass constructor.

Here is a sample code:

class A():
 def __init__(self, bla):
#do some stuff here

class B(A):
 def __init__(self, bla2):
  #do some stuff here
  A.__init__(self,bla)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question about inheritence

2008-07-22 Thread Fredrik Lundh

Catherine Heathcote wrote:


If I create a new class inherited from another with a constructor, what
happens with the new class's constructer?


assuming that you mean "is it called or not?":

Python doesn't really have constructors; when you create an object, 
Python first creates the object and then calls the __init__ method, if 
available


that method is an ordinary method, and behaves like all other methods: 
if you override it, your version is used.  if you don't, the other one 
is used.


>>> class Parent:
... def __init__(self):
... print "init parent"
...
>>> class Child(Parent):
... pass
...
>>> o = Child()
init parent

>>> class Child(Parent):
... def __init__(self):
... print "init child"
...
>>> o = Child()
init child

if you want to override the parent's init method, but still use its 
functionality, you can add an explicit call to the method:


>>> class Child(Parent):
... def __init__(self):
... Parent.__init__(self)
... print "init child"
...
>>> o = Child()
init parent
init child

since it's an ordinary method call, you don't have to initialize the 
parent the first thing you do.  you can also pass in any arguments you 
want (including arguments passed to the child constructor):


>>> class OtherChild(OtherParent):
... def __init__(self, a, b, c):
... self.c = c
... OtherParent.__init__(self, a + b)
...

there's even a common pattern for passing along *all* arguments, no 
matter what they are:


>>> class OtherChild(OtherParent):
... def __init__(self, *args, **kwargs):
... # do something here
... OtherParent.__init__(self, *args, **kwargs)
... # do something else here
...

instead of explicitly naming the baseclass, you can use the "super" 
method to automatically look up the parent class, but this only works

if the parent class inherits from "object" or a subclass thereof:

>>> class Parent(object):
... def __init__(self):
... print "init parent"
...
>>> class Child(Parent):
... def __init__(self):
... super(Child, self).__init__()
... print "init child"
...
>>> o = Child()
init parent
init child

hope this helps!



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


Re: Not entirely serious: recursive lambda?

2008-07-22 Thread Michael Tobis
Thanks all! What a remarkable set of answers, intelligent, thought
provoking and informative without exception.

Of course, now I can't use Paul's version; it hardly counts as a japh
if someone else wrote it! It is probably the closest to my original
vision, alas. Miles' second suggestion was the one I was fumbling
toward; I will study it. No spoilers please.

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


Re: Importing different versions of a module

2008-07-22 Thread mercado mercado
It seems that you can specify the name of the module to be imported at
runtime using the following syntax:

X = __import__('X')

(from http://effbot.org/zone/import-confusion.htm)

Of course, I would rather specify the path to the module at runtime, not the
module name itself, but at least this is a start...
--
http://mail.python.org/mailman/listinfo/python-list

Re: Importing different versions of a module

2008-07-22 Thread Fredrik Lundh

mercado mercado wrote:

It seems that you can specify the name of the module to be imported at 
runtime using the following syntax:


X = __import__('X')

(from http://effbot.org/zone/import-confusion.htm)

Of course, I would rather specify the path to the module at runtime, not 
the module name itself, but at least this is a start...


additional approaches can be found here:

http://effbot.org/zone/import-string.htm

also see my other reply to you in this thread.



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


Re: Is this a valid use of 'import'?

2008-07-22 Thread Terry Reedy



Frank Millman wrote:


I know that when a module is imported the first time, it is
'executed'. This normally entails setting up constants, classes,
functions, etc, that you want to make available to the importer.


And every time thereafter, the module code is not executed*.  So module 
code should only be code you want executed exactly once, on first 
import, and never again.



In this particular case, when it is executed, it does a whole lot
more. It reads in some parameters, establishes a socket connection,
starts a thread, and starts monitoring the socket using select.select.
It also exposes some functions that disguise the complexity of reading
from and writing to the socket.


What if you want to open another connection, because you want a second, 
or because you closed the first (to help the server while the client 
does something else) or because the connection got dropped because the 
server timed it out or because of network congestion or whatever?


tjr

*Python2 has a built-in reload function, but in 3.0 it is removed 
because it almost never did what people wanted or expected and thus lead 
to surprising bugs.  You can delete a module from sys.modules and 
re-import it, but the module object and those it created will not 
disappear as long as there are other references to them.


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


Authentication for XML-RPC Calls

2008-07-22 Thread whitemice
The only documentation regarding doing authentication for XML-RPC I
can find is -

"Both the HTTP and HTTPS transports support the URL syntax extension
for HTTP Basic Authentication: http://user:[EMAIL PROTECTED]:port/path. The
user:pass portion will be base64-encoded as an HTTP `Authorization'
header, and sent to the remote server as part of the connection
process when invoking an XML-RPC method. You only need to use this if
the remote server requires a Basic Authentication user and password."

- from http://docs.python.org/lib/module-xmlrpclib.html

Is this really the only way to do authentication for XML-RPC calls?

Like this:
server = xmlrpclib.Server('http://adam:[EMAIL PROTECTED]/zidestore/so/
adam/'

This works, but is pretty ugly.  Is there no way to setup the
authentication through properties (like in most XML-RPC bindings),
like:

server = xmlrpclib.Server('http://localhost/zidestore/so/adam/'
server.Username = 'adam'
server.Password = 'fred123'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Not entirely serious: recursive lambda?

2008-07-22 Thread Paul McGuire
On Jul 22, 11:52 am, Michael Tobis <[EMAIL PROTECTED]> wrote:
> Thanks all! What a remarkable set of answers, intelligent, thought
> provoking and informative without exception.
>
> Of course, now I can't use Paul's version; it hardly counts as a japh
> if someone else wrote it! It is probably the closest to my original
> vision, alas. Miles' second suggestion was the one I was fumbling
> toward; I will study it. No spoilers please.
>
> best
> mt

Michael -

Sorry to spoil your fun - the concept of a recursive lambda was such
an interesting diversion, I couldn't resist!  I'll try to restrain
myself next time.

-- Paul



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


Re: Hello,who can help me!

2008-07-22 Thread James Matthews
I would recommended on asking on the pywin32 mailing list.

On Tue, Jul 22, 2008 at 2:26 AM, Diez B. Roggisch <[EMAIL PROTECTED]>
wrote:

> [EMAIL PROTECTED] wrote:
>
> > I have implemented a C++ COM,which contains two interface in one
> > coclass.
> > when i use this COM in python:
> > dll=win32com.client.Dispatch("X")
> > then i can only call default interface's method,but can't call non
> > default interface's method.
> > who can tell me how to call non default interface's method.
> > thank you very much!
> > you can send the answer to my mailbox:[EMAIL PROTECTED]<[EMAIL PROTECTED]>
>
> AFAIK win32com only supports IDispatch-based interfaces, not custom
> interfaces.
>
> Diez
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.jewelerslounge.com
http://www.goldwatches.com/mens/
--
http://mail.python.org/mailman/listinfo/python-list

Re: Question about admin rights and IDLE

2008-07-22 Thread Terry Reedy



[EMAIL PROTECTED] wrote:

Hi All,

Apologies in advance for a potentially redundant posting -- I sent a
similar question to the help box yesterday.

I have a Geographic Info System (GIS) user that is having problems
editing with Python IDLE on a WindowsXP machine unless she has admin
rights.  I had initially thought there might be a place where you can
change the 'user rights' settings in Python, but wasn't able to find it.
So, I did a fresh install of Python 2.5.1 and told it to be available to
all users during the install process.  The problem is that IDLE still
seems to be available only to the person who has admin rights on a given
machine.  Can anybody make sense of this and help me fix it?


I have both 2.5.2 and 3.0b2 loaded for all users on stock xp with all 
upgrades.  I put /Python25 and /Python30 under Program Files instead of 
C:.  As normal non-admin user, I can edit files in ./misc (added by me) 
under either, or in ./Lib/site-packages/my_package or, of course, under 
My Documents.


You did not specify the 'problems'.  If it is saving (which is required 
to run a file), then perhaps your user is trying to save in an 
admin-only directory.  If IDLE is not running at all, perhaps you have 
some special government security mods.  Perhaps changing install 
location would help.  Also, does 'fresh install' mean uninstall first? 
This is not normally required, but you are not in a normal situation ;-).


Or perhaps you are running into somthing connected with this warning:

Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.

Perhaps you are getting silent blockage.  Related to the above, there 
can only be one IDLE process running on the machine at one time.  If 
somehow one were being started on the admin account, for instance  .


Terry Jan Reedy

PS. Unless you have good reason not too, consider installing 2.5.2 
instead with its many bug fixes.


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


Re: Authentication for XML-RPC Calls

2008-07-22 Thread Larry Bates

whitemice wrote:

The only documentation regarding doing authentication for XML-RPC I
can find is -

"Both the HTTP and HTTPS transports support the URL syntax extension
for HTTP Basic Authentication: http://user:[EMAIL PROTECTED]:port/path. The
user:pass portion will be base64-encoded as an HTTP `Authorization'
header, and sent to the remote server as part of the connection
process when invoking an XML-RPC method. You only need to use this if
the remote server requires a Basic Authentication user and password."

- from http://docs.python.org/lib/module-xmlrpclib.html

Is this really the only way to do authentication for XML-RPC calls?

Like this:
server = xmlrpclib.Server('http://adam:[EMAIL PROTECTED]/zidestore/so/
adam/'

This works, but is pretty ugly.  Is there no way to setup the
authentication through properties (like in most XML-RPC bindings),
like:

server = xmlrpclib.Server('http://localhost/zidestore/so/adam/'
server.Username = 'adam'
server.Password = 'fred123'


Just write a little factory class that does it for you:

import urlparse

class myauth(object):
def __init__(self, scheme = None, domain = None, path = None):
self.scheme = scheme
self.domain = domain
self.path = path
self.Username = None
self.Password = None

def __str__(self):

for attr in ['scheme', 'domain', 'path', 'Username', 'Password']:
if getattr(self, attr) is None:
raise ValueError('No %s attribute value given' % attr)

url=urlparse.urlunsplit((self.scheme,
  '%s:[EMAIL PROTECTED]' % (self.Username, self.Password, self.domain),
  self.path, '', ''))

return url

if __name__ == "__main__":
auth = auth = myauth(scheme = 'http', domain = 'localhost',
 path='/zidestore/so/adam/')

auth.Username = 'adam'
auth.Password = 'fred123'
print auth


In program

auth = myauth(scheme = 'http', domain = 'localhost',
  path = '/zidestore/so/adam')

auth.Username = 'adam'
auth.Password = 'fred123'

print auth

'http://adam:[EMAIL PROTECTED]/params;/lib/module-xmlrpclib.html'
>>>

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


Re: The Importance of Terminology's Quality

2008-07-22 Thread Grant Edwards
On 2008-07-22, Steve Schafer <[EMAIL PROTECTED]> wrote:
> On Tue, 22 Jul 2008 10:21:50 +0100, Martin Gregorie
><[EMAIL PROTECTED]> wrote:
>
>>The first time I ran across the term "thunking" was when Windows 3
>>introduced the Win32S shim and hence the need to switch addressing between
>>16 bit and 32 bit modes across call interfaces. That was called "thunking"
>>by Microsoft and even they would surely admit it was a kludge.

What?!  Microsoft took a technical term and used it to mean
something completely different than the widely used meaning?
Never.

> Win32s thunks are a completely different beast from the
> original Algol 60 thunks. As far as I know, the first
> published description of thunks was:
>
>  Ingerman PZ (1961) Thunks: A way of compiling procedure statements with
>  some comments on procedure declarations, CACM 4:55-58.

The Algol usage is certainly what we were taught back in the
late 70's.  I wasn't even aware that Microsoft had hijacked it
to mean something else.

-- 
Grant Edwards   grante Yow! My polyvinyl cowboy
  at   wallet was made in Hong
   visi.comKong by Montgomery Clift!
--
http://mail.python.org/mailman/listinfo/python-list


sys.stderr.write returns string length in Python 3

2008-07-22 Thread Alan G Isaac

Is this new behavior intentional? ::

>>> sys.stderr.write("thisisatest\n")
thisisatest
12

Here is the reason for it:

>>> help(sys.stderr.write)
Help on method write in module io:
write(self, s: str) method of io.TextIOWrapper instance

Thank you,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


CPython VM internals - Wiki page

2008-07-22 Thread Terry Reedy
Various people have asked on c.l.p about documentation of CPython's 
virtual machine internals.  The usual answers have been to see the dis 
module doc for bytecodes and 'read the code' for more.  Jakob Sievers 
did so and posted his notes, with additions from Martin v. Löwis, as


http://wiki.python.org/moin/CPythonVmInternals

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


Re: CPython VM internals - Wiki page

2008-07-22 Thread John Nagle

Terry Reedy wrote:
Various people have asked on c.l.p about documentation of CPython's 
virtual machine internals.  The usual answers have been to see the dis 
module doc for bytecodes and 'read the code' for more.  Jakob Sievers 
did so and posted his notes, with additions from Martin v. Löwis, as


http://wiki.python.org/moin/CPythonVmInternals


That's interesting. It's dumber than I thought.  All temporaries
on the stack are "boxed" as PyObjects.  That's simple and portable,
but slow.

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


software engineering foundations?

2008-07-22 Thread skip

Sorry for the off-topic-ish post.  My son (a fairly junior sysadmin type)
mentioned to me today that he was looking for online courses for Perl.  (I
don't hold that against him.  Perl is still a lingua franca in the sysadmin
realm.)  In my work I have from time-to-time had to pick up and maintain
scripts (generally shell/Python stuff) which non-professional programmers
have written.  It's never what you would call a "pleasant" task.

There are software construction skills which are entirely distinct from the
language in which you are programming.  We can tout object-oriented,
structured programming, test-driven development or other software
engineering techniques, but there is a body of knowledge out there which is
orthogonal to the language in which the code is written.  People who are not
professional programmers often lack those skills and their code shows it.

Are there any good online resources for this "software structure" axis?
Googling for "object oriented programming tutorial" yields a bunch of stuff,
much of it language-specific.  I'm trying to find something a bit more
general than that though.

I Googled for "software engineering tutorial" as well.  Most of the early
hits were either inaccessible (ACM subscription only) or contents-like stuff
(conference announcements, for example).  Number eight on the list was this
rather promising page:

http://www.cmcrossroads.com/bradapp/links/swe-links.html

It was last updated over 10 years ago.  I find it hard to believe that
so little has changed in that time that some other page with more recent
references hasn't percolated to the top of Google's page rank!  After all,
the Web has grown just a tad in that timeframe.

I have a sneaking suspicion that what I'm looking for is out there, but that
I'm not asking Google in the right manner.  Any and all pointers/suggestions
cheerfully accepted.

Thx,

-- 
Skip Montanaro - [EMAIL PROTECTED] - http://www.webfast.com/~skip/
--
ELON MUSK: If fuel cells were good, don't think you'd see them somewhere,
like maybe in a laptop or a cell phone or a $200 million military satellite
maybe?  And yet, where do you see them?
SPENCER MICHELS: You don't.
ELON MUSK: Exactly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: proliferation of computer languages

2008-07-22 Thread szr
Jürgen Exner wrote:
> Chris Rathman <[EMAIL PROTECTED]> wrote:
>
>> I can't say that I see any particular point to the essay.
>
> You must be new here. There never is any particular point to  Xah
> Lee's rantings except to cross-post borderline topics to borderline
> relevant NGs and then lay back and enjoy the ensuing slaughter.

Admittedly, I'm not all too familiar with his postings, but on a general 
note, isn't it possible that someone else might not see it the same as 
you do? I really didn't see anything really sinister about the posting 
or it's content. It may very well be someone attempting to create a 
conversation, someone who may not be generally well received a lot of 
the time I gather.

Also, if have such a distaste for his postings, you are free to ignore 
them as well. That said, I am all for alerting someone of something 
which may be a complete waste of their time, but in this case it feels 
like you are projecting your own dislike for the OP. Unless the OP 
really is deserving of such branding (in which case I'd stand 
corrected), I don't think it is reason enough to tell others not to read 
of his work just because you aren't particularly fond of it.

Perhaps citing an actual example illustrating a reason to avoid him like 
the plague would of helped :-)

-- 
szr 


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

Re: CPython VM internals - Wiki page

2008-07-22 Thread Martin v. Löwis
> That's interesting. It's dumber than I thought.  All temporaries
> on the stack are "boxed" as PyObjects.  That's simple and portable,
> but slow.

Not only that - Python does not ever have the concept of unboxed
values, except for local variables in the C implementations of
arithmetic operations and system calls.

Using true objects is slow only if allocation and deallocation is
slow, which it fortunately isn't.

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


Re: scanf in python

2008-07-22 Thread AMD



AMD wrote:

I had seen this pure python implementation, but it is not as fast or 
as elegant as would be an implementation written in C directly within 
python with no need for import.


maybe you should wait with disparaging comments about how Python is not 
what you want it to be until you've learned the language?






Hello Fredrik,

I didn't think my comment would offend anyone, I'm sorry if it did. I 
have been developping in Python for about 5 years, my company uses 
Python as a scripting language for all of its products. We use Jython 
for our server products. I think I know it pretty well by now. So I 
think I have earned the right to try to suggest improvements to the 
language or at least intelligent discussion of new features without need 
for offensive comments, don't you think?


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

Re: software engineering foundations?

2008-07-22 Thread Fredrik Lundh

[EMAIL PROTECTED] wrote:


Sorry for the off-topic-ish post.  My son (a fairly junior sysadmin type)
mentioned to me today that he was looking for online courses for Perl.  (I
don't hold that against him.  Perl is still a lingua franca in the sysadmin
realm.)  In my work I have from time-to-time had to pick up and maintain
scripts (generally shell/Python stuff) which non-professional programmers
have written.  It's never what you would call a "pleasant" task.

There are software construction skills which are entirely distinct from the
language in which you are programming.  We can tout object-oriented,
structured programming, test-driven development or other software
engineering techniques, but there is a body of knowledge out there which is
orthogonal to the language in which the code is written.  People who are not
professional programmers often lack those skills and their code shows it.


just get McDonnell's "Code Complete":

http://www.cc2e.com/



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


  1   2   >