Re: How do I add users using Python scripts on a Linux machine

2007-01-03 Thread Tim Roberts
"Ramdas" <[EMAIL PROTECTED]> wrote:
>
>I need to add users from a web interface for a web server, which runs
>only Python. I need to add users, set quotas and in future even look at
>managing ip tables to limit bandwidth.
>
>I know os.system(), but this has to be done through a form entry
>through a web interface.
>
>Anyways thanks, do advise if there more pythonic solutions

os.system is perfectly Pythonic, and can be executed from a CGI script. The
challenge is becoming root, which is necessary to do what you ask.  You can
write a simple C program that is setuid root that calls your script for
you.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list/dictionary as case statement ?

2007-01-03 Thread Tom Plunket
Hendrik van Rooyen wrote:

> It works well - and it is surprisingly fast too...
> And its easy if the opcodes are all say one byte,
> else you need an opcode length field too, and fancier
> parsing.

Often (always?) RISC architectures' instruction+operand lengths are
fixed to the word size of the machine.  E.g. the MIPS 3000 and 4000 were
32 bits for every instruction, and PC was always a multiple of four.
...which means the parsing is pretty straight forward, but as you say,
simulating the rest of the machine is the hard part.


-tom!

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


Re: DOS, UNIX and tabs

2007-01-03 Thread Hendrik van Rooyen
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote:

> I've spent a lot of time reading both sides of the tabs versus spaces
> argument, and I haven't found anything yet that explains why tabs are, in
> and of themselves, bad.

+1 for QOTW

Searching for the "badness" of tabs
is like searching for the holy grail.
You are doomed to failure.
You cannot find something 
that does not exist.

: - )

- Hendrik

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


pythoncom module

2007-01-03 Thread Scripter47
Hey,


I need a module called "pythoncom" anyone that knows where a can find 
that module???

thanks!

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


Re: Writing more efficient code

2007-01-03 Thread Hendrik van Rooyen
"Jon Harrop" <[EMAIL PROTECTED]> wrote:


> I think that is an excellent idea. Who will pay me? ;-)

The same fellow who is paying you to post to this newsgroup...

- Hendrik

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


Re: Synchronization methodology

2007-01-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Chris Ashurst
wrote:

> Hi, I'm coming in from a despised Java background, and I'm having some 
> trouble wrapping my head around sharing an object between multiple 
> instances of a single class (in simpler terms, I would say imagine a 
> simple chat server that has to share a list of connected users to each 
> instance of a connected user).
> 
> Usually, I would have a synchronized list instantiated inside each 
> instance of a client class, which would do the trick, but since there's 
> no synchronization in Python, I'm stuck staring at little tests 
> involving a standalone non-threaded class instance that holds the list 
> of users, and each connected user being passed this instance to be 
> "synchronized".

There's no ``synchronized`` keyword, but of course you can synchronize
methods.  You have to attach an `threading.RLock` to the objects you want
to synchronize on and use its `aquire()` and `release()` methods in places
where you used ``synchronized (someObject) { ... }`` in Java.

synchronized foo() { /* code */ }

is the same as

foo() {
  synchronized (this) { /* code */ }
}

in Java.  And that's basically:

def foo(self):
self.lock.aquire()
# code
self.lock.release()

You may want to make sure the lock will be released in case of an
exception:

def foo(self):
self.lock.aquire()
try:
pass # code
finally:
self.lock.release()

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


import order or cross import

2007-01-03 Thread Roland Hedberg
Hi!

I'm having a bit of a problem with import.

I'm writing a marshalling system that based on a specification will
create one or more files containing mostly class definitions.

If there are more than one file created (and there are reasons for
creating more than one file in some instances) then they will import
each other since there may be or is interdependencies in between them.

And this is where the going gets tough.

Let's assume I have the following files:

- ONE.py 

import TWO

class Car:
def __init__(self):
self.color = None

def set_color(self,v):
if isinstance(v,TWO.Black) or isinstance(v,TWO.White):
self.color = v

class BaseColor:
def __init__(self):
pass
def __str__(self):
return self.color

if __name__ == "__main__":
car = Car()
color = TWO.Black()
car.set_color(color)
print car.color

-- TWO.py ---

import ONE

class Black(ONE.BaseColor):
color = "Black"
def __init__(self):
ONE.BaseColor.__init__(self)

class White(ONE.BaseColor):
color = "White"
def __init__(self):
ONE.BaseColor.__init__(self)

-

Now, running ONE.py causes no problem it will print "Black", but running
TWO.py I get:
AttributeError: 'module' object has no attribute 'BaseColor'

So, how can this be solved if it can be ?

To join ONE.py and TWO.py into one file could be a solution if there
where no other conditions (non-language based) that prevented it.

-- Roland

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


Re: how to use execfile with argument under windows

2007-01-03 Thread baur79
os.system() solve my problem

thanks you guys and happy new year

with best wishes from Kazakhstan / Shymkent city / sodbisystems.kz


On Jan 2, 11:49 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> baur79 wrote:
> > i need to execute this command line (different source for n times)
>
> > filename.exe -type png -source sourcearg -file filename.png
> > i try with python (python script and filename.exe in same directory)
> > execfile("filename.exe -type png -source sourcearg -file filename.png")That 
> > does not do what you think it does, see
>
> http://docs.python.org/lib/built-in-funcs.html#l2h-26
>
> You need os.system() or, for more complex applications, the subprocess
> module.
> 
> Peter

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


Re: Synchronization methodology

2007-01-03 Thread [EMAIL PROTECTED]
Chris Ashurst wrote:
> Hi, I'm coming in from a despised Java background

Consider strongly the fact that Python supports multiple process
solutions well, so you're not stuck having to use multithreaded
solutions in every circumstance (but can still use them when necessary).

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


Re: import order or cross import

2007-01-03 Thread Jussi Salmela
Roland Hedberg kirjoitti:
> Hi!
> 
> I'm having a bit of a problem with import.
> 
> I'm writing a marshalling system that based on a specification will
> create one or more files containing mostly class definitions.
> 
> If there are more than one file created (and there are reasons for
> creating more than one file in some instances) then they will import
> each other since there may be or is interdependencies in between them.
> 
> And this is where the going gets tough.
> 
> Let's assume I have the following files:
> 
> - ONE.py 
> 
> import TWO
> 
> class Car:
> def __init__(self):
> self.color = None
> 
> def set_color(self,v):
> if isinstance(v,TWO.Black) or isinstance(v,TWO.White):
> self.color = v
> 
> class BaseColor:
> def __init__(self):
>   pass
> def __str__(self):
> return self.color
> 
> if __name__ == "__main__":
> car = Car()
> color = TWO.Black()
> car.set_color(color)
> print car.color
> 
> -- TWO.py ---
> 
> import ONE
> 
> class Black(ONE.BaseColor):
> color = "Black"
> def __init__(self):
> ONE.BaseColor.__init__(self)
> 
> class White(ONE.BaseColor):
> color = "White"
> def __init__(self):
> ONE.BaseColor.__init__(self)
> 
> -
> 
> Now, running ONE.py causes no problem it will print "Black", but running
> TWO.py I get:
> AttributeError: 'module' object has no attribute 'BaseColor'
> 
> So, how can this be solved if it can be ?
> 
> To join ONE.py and TWO.py into one file could be a solution if there
> where no other conditions (non-language based) that prevented it.
> 
> -- Roland
> 

Maybe I'm missing something, but why is the class BaseColor in file 
ONE.py and not in TWO.py?

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


Re: import order or cross import

2007-01-03 Thread Duncan Booth
Roland Hedberg <[EMAIL PROTECTED]> wrote:

> Now, running ONE.py causes no problem it will print "Black", but running
> TWO.py I get:
> AttributeError: 'module' object has no attribute 'BaseColor'
> 
> So, how can this be solved if it can be ?
> 

When you execute an import statement, it checks whether the module already 
exists. If it does exist then it immediately returns the module object. If 
the module does not yet exist then the module is loaded and the code it 
contains is executed.

Remember that all statements in Python are executed at the time they are 
encountered: there are no declarations (apart from 'global') so no looking 
ahead to see what classes or functions are coming up.

One other complication in your particular instance: when you run a ONE.py 
as a script the script is loaded in a module called '__main__', so 'import 
ONE' will actually load a separate module which is NOT the same as the 
__main__ module. Likewise when you run TWO.py as a script you have three 
modules __main__ (loaded from TWO.py), ONE, and TWO.

So running TWO.py, you get:

   import ONE
  --- loads the module ONE and starts executing it
  import TWO
  --- loads the module TWO and starts executing it
  import ONE
  --- the module ONE already exists 
  (even though so far it hasn't got beyond
  the import TWO line) so the empty module is returned.
  class Black(ONE.BaseColor):
  --- ONE doesn't have a BaseColor attribute yet so you get 
  an error.

The fix in this sort of case is usually to extract the base class out to a 
third module. If you put BaseColor in base.py then you can safely import 
that anywhere you want it.

An alternative in this case would be to edit ONE.py and move the line 
'import TWO' down below the definition of BaseColor: nothing before that 
actually requires TWO to have been imported yet.

However, you really should try to separate scripts from modules otherwise 
the double use as both __main__ and a named module is going to come back 
and bite you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Synchronization methodology

2007-01-03 Thread Paul Rubin
Chris Ashurst <[EMAIL PROTECTED]> writes:
> Hi, I'm coming in from a despised Java background, and I'm having some
> trouble wrapping my head around sharing an object between multiple
> instances of a single class (in simpler terms, I would say imagine a
> simple chat server that has to share a list of connected users to each
> instance of a connected user).

If you're doing this with threads, one common Pythonic style is
generally to have the threads communicate through queues (see docs for
the Queue module).  This is sort of a cheap version of the CSP
(communicating sequential processes) approach.  You might have a
service thread that takes care of those shared objects, reading
requests from a queue (untested):

   # All client threads write their requests to this queue, and
   # the service loop reads from it
   service_queue = Queue()

   # make one of these in each client thread
   class Request(Queue.Queue):
  def __call__(self, reply_queue, func, *args, **kwargs):
  service_queue.put((self, func, args, kwargs))
  return self.get()

   def service_loop():
 while True:
client, func, args, kwargs = service_queue.get()
client.put (func(*args, **kwargs))

   Threading.Thread(target=service_loop).start()

Then in your connected user thread you could say:

   # set up a reply queue for this user's thread
   request = Request()
   ...

   # add the user to the connected user list, with timestamp and remote IP
   status = request(user_list.append, self, time(), remote_ip=whatever)

The last line would drop a request on the service queue to perform the
function call

user_list.append(time(), remote_ip=whatever)

The service queue thread would retrieve the request, call the
function, and pass the result back through the reply queue.  The idea
is you'd handle all operations on user_list in the service thread, so
access is completely serialized using the queues.  You can see that
you can easily construct any function call that then gets executed in
the other thread, without having to use a bunch of boilerplate at each
request.  You have to be a bit careful to not use long-running
requests that could block other threads from getting their requests
serviced.  Use additional threads if you need such requests.

You sometimes end up creating more threads than necessary this way but
you tend to not have many synchronization problems if you stick with
this style.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import order or cross import

2007-01-03 Thread Roland Hedberg
Duncan Booth wrote:

> 
> Remember that all statements in Python are executed at the time they are 
> encountered: there are no declarations (apart from 'global') so no looking 
> ahead to see what classes or functions are coming up.

Yes, I've seen this time and time again.

> One other complication in your particular instance: when you run a ONE.py 
> as a script the script is loaded in a module called '__main__', so 'import 
> ONE' will actually load a separate module which is NOT the same as the 
> __main__ module. Likewise when you run TWO.py as a script you have three 
> modules __main__ (loaded from TWO.py), ONE, and TWO.

Hmm, that's interesting.

> 
> The fix in this sort of case is usually to extract the base class out to a 
> third module. If you put BaseColor in base.py then you can safely import 
> that anywhere you want it.

OK, so I'll go for this option. Takes some more intelligence in the
marshalling code but it should be doable.

> An alternative in this case would be to edit ONE.py and move the line 
> 'import TWO' down below the definition of BaseColor: nothing before that 
> actually requires TWO to have been imported yet.

Since no person is involved, in creating files like ONE.py and TWO.py,
this also has to be done by the marshalling code.
I've no clear idea which alternative would be best/easiest but your
first one seems clearer.

> However, you really should try to separate scripts from modules otherwise 
> the double use as both __main__ and a named module is going to come back 
> and bite you.

Oh, that was only there as an example, so you could see the intent usage.

Thanks Duncan!

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


Re: Synchronization methodology

2007-01-03 Thread Paul Rubin
Paul Rubin  writes:
># add the user to the connected user list, with timestamp and remote IP
>status = request(user_list.append, self, time(), remote_ip=whatever)

Editing error, ignore the "self," arg up there.  Of course there may be
other mistakes too, I didn't test any of that code ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Synchronization methodology

2007-01-03 Thread Duncan Booth
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

> You may want to make sure the lock will be released in case of an
> exception:
> 
> def foo(self):
> self.lock.aquire()
> try:
> pass # code
> finally:
> self.lock.release()
> 

In Python 2.5 this can also be written more succintly using the with 
statement so foo becomes:

from __future__ import with_statement
...

def foo(self):
with self.lock:
pass # insert your code here


or write a decorator.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import order or cross import

2007-01-03 Thread Roland Hedberg
Jussi Salmela wrote:
> Roland Hedberg kirjoitti:

>> I'm having a bit of a problem with import.
>>
>> I'm writing a marshalling system that based on a specification will
>> create one or more files containing mostly class definitions.

> Maybe I'm missing something, but why is the class BaseColor in file 
> ONE.py and not in TWO.py?

This has to do with the how the specifications that the marshallings
system works with are structured. And it is therefor not something I can
control.

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


Using codecs.EncodedFile() with Python 2.5

2007-01-03 Thread David Hughes
I used this function successfully with Python 2.4 to alter the encoding
of a set of database records from latin-1 to utf-8, but the same
program raises an exception using Python 2.5. This small example shows
the problem:

import codecs
fo = open('test.dat', 'w')
fo.write('G\xe2teaux')
fo.close()

fi = open("test.dat",'r')
fx = codecs.EncodedFile(fi, 'utf-8', 'latin-1')
astring = fx.readline()
print astring
ustring = unicode(astring, 'utf-8' )
print repr(ustring)
print ustring.encode('latin-1')
print ustring.encode('utf-8')

Python 2.4 gives:

Gâteaux
u'G\xe2teaux'
Gâteaux
Gâteaux

which I believe is correct, while 2.5 produces

Traceback (most recent call last):
  File "test_codec.py", line 8, in 
astring = fx.readline()
  File "C:\Python25\lib\codecs.py", line 709, in readline
data = self.reader.readline()
  File "C:\Python25\lib\codecs.py", line 471, in readline
data = self.read(readsize, firstline=True)
  File "C:\Python25\lib\codecs.py", line 418, in read
newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-3:
invalid data

Is there a genuine problem here, or have I been misusing this function?
--
Regards
David Hughes

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


Re: How do I add users using Python scripts on a Linux machine

2007-01-03 Thread Sebastian 'lunar' Wiesner
Piet van Oostrum <[EMAIL PROTECTED]> typed

>> Sebastian 'lunar' Wiesner <[EMAIL PROTECTED]> (SW) wrote:
> 
>>SW> Linux seems to ignore SUID bit on scripts:
> 
> The reason is that obeying SUID bits on scripts would be a security
> risk.

I don't see a problem with SUID on scripts. If you restrict write access
to the owner, modification is hardly possible. 
However, if you allow world-wide write access to your binaries and
scripts, both can easily be modified...

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


Re: Using codecs.EncodedFile() with Python 2.5

2007-01-03 Thread Peter Otten
David Hughes wrote:

> I used this function successfully with Python 2.4 to alter the encoding
> of a set of database records from latin-1 to utf-8, but the same
> program raises an exception using Python 2.5. This small example shows
> the problem:
> 
> import codecs
> fo = open('test.dat', 'w')
> fo.write('G\xe2teaux')
> fo.close()
> 
> fi = open("test.dat",'r')
> fx = codecs.EncodedFile(fi, 'utf-8', 'latin-1')
> astring = fx.readline()
> print astring
> ustring = unicode(astring, 'utf-8' )
> print repr(ustring)
> print ustring.encode('latin-1')
> print ustring.encode('utf-8')
> 
> Python 2.4 gives:
> 
> Gâteaux
> u'G\xe2teaux'
> Gâteaux
> Gâteaux
> 
> which I believe is correct, while 2.5 produces
> 
> Traceback (most recent call last):
>   File "test_codec.py", line 8, in 
> astring = fx.readline()
>   File "C:\Python25\lib\codecs.py", line 709, in readline
> data = self.reader.readline()
>   File "C:\Python25\lib\codecs.py", line 471, in readline
> data = self.read(readsize, firstline=True)
>   File "C:\Python25\lib\codecs.py", line 418, in read
> newchars, decodedbytes = self.decode(data, self.errors)
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-3:
> invalid data
> 
> Is there a genuine problem here, or have I been misusing this function?

This is indeed a bug in Python 2.5. Fixed in subversion.

http://svn.python.org/view/python/trunk/Lib/codecs.py?rev=52517&view=log

Peter

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


[Half-off] How to get textboxes (text blocks) from ps/pdf files?

2007-01-03 Thread durumdara
Hi!

I need to get textboxes/textblocks from pdf files. I can convert them 
into ps.
Is anyone knows about method, trick, routine to I can get the textboxes 
from ps or pdf?
(Pythonic, COM, or command line solutions needed.)

I need to redraw them into my application, and user can reorder them, 
and next I concat. every text to process it.

I need these infos:
x, y, w, h, text

Example:
page1
textbox1{x:100,y:100;w:600;h:27;text:"TextBox1 /xfc /xfa"}
textbox2{x:100,y:180;w:600;h:27;text:"TextBox2"}
page2
textbox1{x:100,y:100;w:600;h:27;text:"TextBox1"}
textbox2{x:100,y:180;w:600;h:27;text:"TextBox2"}
...

Any solution?

Thanks for it!
dd

ps1:
I tried every pdf2text and pdf2html application. All failed in the 
test.
Only one provide good informations, the pdftohtml, because it is 
makes divs with abs. position and size and the texts.
But this program is not handle the iso-8859-2 chars, so I lost them.

ps2:
The program must run under Windows XP. So the solution is os specific.
   

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


convert frames from mpeg to array

2007-01-03 Thread seb
Hi, I need to convert each frame from a movie (mpeg for example) to an
array (in order to do some computation)  and then back to a video
format mpeg for example. Do you know of any tools ?

The equipment :

I got myself an IP axis camera with wich I am playing to trying to do
some shape recognition.
My PC is running winXP SP2.

The plan is :
--
1) to manage to record the movies to my hard disk (in mpeg format for
example)
2) to analyse the films in order to tests various algorythms /
computation
3) to generate the transformed frame back to mpeg (or any format).

What is already done is :
-
1) record to hard disk is easily donne using vlc for example
vlc "http://192.168.0.90/axis-cgi/mjpg/video.cgi?fps=30&nbrofframes=0";
--sout file/ts:test.mpg

The problem is point 2
-
I have tried to use pygame (on winXP) but it seems that it does not
suppport movies.
Pycar does not run on my PC.
I have looked for some other tools but without any success.
There is possibily a python binding to vlc but I am not sure of what
can be done with it.


I thank you in advance for taking the time to read this mail.

Best regards.
Seb.

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


Re: list/dictionary as case statement ?

2007-01-03 Thread Bjoern Schliessmann
Tom Plunket wrote:

> Often (always?) RISC architectures' instruction+operand lengths
> are fixed to the word size of the machine.  E.g. the MIPS 3000 and
> 4000 were 32 bits for every instruction, and PC was always a
   ^^
> multiple of four.

Intels aren't RISC, are they?

But for PowerPC it's the same, every instruction has 32 bit.

Regards,


Björn

-- 
BOFH excuse #278:

The Dilithium Crystals need to be rotated.

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


function without brackets ?

2007-01-03 Thread Stef Mientki
If I call a parameterless function without brackets at the end,
the function is not performed, but ...
I don't get an error message ???

Is this normal  behavior ?

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


Re: a question on python dict

2007-01-03 Thread Fredrik Lundh
Tim Peters wrote:

> Taking my response out of context to begin with doesn't really change that
> I answered the question he asked ;-)

welcome to comp.lang.python.

 



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


Re: function without brackets ?

2007-01-03 Thread Carsten Haese
On Wed, 2007-01-03 at 15:37 +0100, Stef Mientki wrote:
> If I call a parameterless function without brackets at the end,
> the function is not performed, but ...
> I don't get an error message ???
> 
> Is this normal  behavior ?

Yes. If you "call" a function without brackets, it's not a call.

Remember that functions are first class objects that can be passed
around like any other object. Hence, Python needs the distinction
between

x = foo() # Assign the *result* of calling foo to x

and

x = foo # Assign the *function* foo itself to x.

You don't get an error message because a function name without
parentheses is a valid expression that refers to that function.

Hope this helps,

Carsten.


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


Re: function without brackets ?

2007-01-03 Thread Sebastian 'lunar' Wiesner
Stef Mientki <[EMAIL PROTECTED]> typed

> If I call a parameterless function without brackets at the end,
> the function is not performed, but ...

If you omit the brackets, you don't actually call the function. Instead
you get a reference to the function object.

Consider this example:

cwd = os.getcwd()
# cwd now contains a string, denoting the current working directory
func = os.getcwd
# func now contains a reference to the function os.getcwd
print func == os.getcwd # prints True
# you can even call it:
cwd_2 = func()
# cwd_2 now also contains a string with the current directory.
print cwd == cwd_2 # prints True, too

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


Re: function without brackets ?

2007-01-03 Thread rzed
Stef Mientki <[EMAIL PROTECTED]> wrote in news:57668
[EMAIL PROTECTED]:

> If I call a parameterless function without brackets at the end,
> the function is not performed, but ...
> I don't get an error message ???
> 
> Is this normal  behavior ?
> 

Yes, it's normal, but you did not in fact call the function, if you 
were using Python. Functions are objects that, for example, can be 
passed to other functions. The way to refer to the functions 
themselves is to omit the arguments and parentheses. So by simply 
stating the name of a function, that's all you've done. 

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


Re: function without brackets ?

2007-01-03 Thread Kay Schluehr

Stef Mientki schrieb:

> If I call a parameterless function without brackets at the end,
> the function is not performed, but ...
> I don't get an error message ???
>
> Is this normal  behavior ?

Yes, this is perfectly o.k. because each function is a first class
citizen in Python. The difference between foo() and foo is simply that
foo() is the value returned by the function call on foo and foo is a
function object. 

Kay

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


code optimization (calc PI)

2007-01-03 Thread mm
(Yes, I konw whats an object is...)
BTW. I did a translation of a pi callculation programm in C to Python. 
(Do it by your own... ;-)

Calc PI for 800 digs(?). (german: Stellen)
--
int a=1,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;
 for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,
 f[b]=d%--g,d/=g--,--b;d*=b);}

$ ./a.exe
31415926535897932384626433832795028841971693993751058209749445923078164062862089
98628034825342117067982148086513282306647093844609550582231725359408128481117450
28410270193852110555964462294895493038196442881097566593344612847564823378678316
52712019091456485669234603486104543266482133936072602491412737245870066063155881
74881520920962829254091715364367892590360011330530548820466521384146951941511609
43305727036575959195309218611738193261179310511854807446237996274956735188575272
48912279381830119491298336733624406566430860213949463952247371907021798609437027
70539217176293176752384674818467669405132000568127145263560827785771342757789609
17363717872146844090122495343014654958537105079227968925892354201995611212902196
0864034418159813629774771309960518707211349983729780499510597317328160963185


But Python is much slower here then C here. I used a while-loop within a 
while-loop. Not that much calculation here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: array of class / code optimization

2007-01-03 Thread mm

Yes, it was the (), equivalent to thiks like new() create new object 
from class xy.
>   s1.append(Word)
s1.append(Word())

But I was looking for a "struct" equivalent like in c/c++.
And/or "union". I can't find it.

Maybe you know a source (URL) "Python for c/c++ programmers" or things 
like that.


Yes, I konw whats an object is...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unsubscribing from the list

2007-01-03 Thread Fredrik Lundh
Dotan Cohen wrote:

> > Go to the bottom of the page. Next to the button "Unsubscribe or edit 
> > options",
> > enter your email address. Click the button. On the next page, click
> > "Unsubscribe". Follow the instructions in the email that is sent to you.

> Thanks. I read that page, got as far as this:
>
> (The subscribers list is only available to the list administrator.)
>
> and decided that there was no futher interest on the page for me.

if you're unable to follow written instructions, how on earth did you manage
to subscribe to this list ?

 



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


Re: array of class / code optimization

2007-01-03 Thread hg
mm wrote:

> 
> Yes, it was the (), equivalent to thiks like new() create new object
> from class xy.
>>   s1.append(Word)
> s1.append(Word())
> 
> But I was looking for a "struct" equivalent like in c/c++.
> And/or "union". I can't find it.
> 
> Maybe you know a source (URL) "Python for c/c++ programmers" or things
> like that.
> 
> 
> Yes, I konw whats an object is...


A struct in C is unrelated to a struct in C++ as a struct in C++ _is_ a
class.


hg

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


Re: Can I beat perl at grep-like processing speed?

2007-01-03 Thread Fredrik Lundh
Nick Craig-Wood wrote:

>>  #!/usr/bin/env python
>>  import re
>>  r = re.compile(r'destroy', re.IGNORECASE)
>>
>>  for s in file('bigfile'):
>>if r.search(s): print s.rstrip("\r\n")

footnote: if you're searching for literal strings with Python 2.5, using "in" 
is a
lot faster than using re.search.

 



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


Re: Unsubscribing from the list

2007-01-03 Thread mm
Fredrik Lundh wrote:

> if you're unable to follow written instructions, how on earth did you manage
> to subscribe to this list ?
> 
>  
> 
> 
> 

*lol*   Just click ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code optimization (calc PI)

2007-01-03 Thread Diez B. Roggisch
mm wrote:

> (Yes, I konw whats an object is...)
> BTW. I did a translation of a pi callculation programm in C to Python.
> (Do it by your own... ;-)

Is that a question on how to optimize code you won't show us? If yes, I'm
sorry to tell you that crystal balls are short these days. Too much
new-year-outlooks.

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


C/C++, Perl, etc. to Python converter

2007-01-03 Thread mm

Is there a Perl to Python converter?
Or in general: a XY to Python converter?

Is see, that Python is much better then Perl anyway.
But for beginners, they whant to konw how is this done with Python etc.

Sure, there are some docus out there in the internet. But a converter?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does Python never add itself to the Windows path?

2007-01-03 Thread Martin v. Löwis
Ben Sizer schrieb:
> Firstly, that solution only works for actual Python scripts; it doesn't
> solve the utility scripts that are often installed to the /scripts
> directory.

Those packages should install .bat files into /scripts on Windows.

> It's a shame that many responses on this thread don't
> address that half of the issue. Am I the only person who installs
> packages that add scripts (not all of which are Python ones)?

Perhaps not. However, people apparently disagree what the "full issue"
is. If you have non-Python scripts (eg. VBScript) in /scripts, how will
having python.exe on PATH help at all?

>> Unfortunately the Python installer is not an InnoSetup installer.
> 
> The page I linked to is a bit misleading but there is an executable on
> that page. All you then have to do is invoke it with the relevant
> parameter.

Please submit a patch that does so, then. Make sure you add user
interface to make it an option.

These things are *not* easy, and claiming that they are is
misleading.

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


Re: Why does Python never add itself to the Windows path?

2007-01-03 Thread Martin v. Löwis
vbgunz schrieb:
> I don't understand what all the fuss is about. Add a single page to the
> installer and on it, have 3 radio buttons. The choices could be "add to
> path (recommended)", "add to path with version", "do not add to path
> (not recommended)".

Please submit a patch to sf.net/projects/python that does so.

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


Re: code optimization (calc PI)

2007-01-03 Thread mm

Hmm... it's a question. It was not that easy to translate this [EMAIL 
PROTECTED] 
C-Program into readable code and then to Python. But it works.

There are only two while-loops (a while within an other while).

I konw, that for example while-loops in Perl are very slow. Maybe this 
is also known in Pyhton. Then, I can translate the while-loops in to 
for-loops, for example.
More general, maybe there is a speed optimazation docu out there.

(Anyway, this code for C-calc is complex. And I realy don't understand 
it right now... 8-)


But anyway, there is not that much calculation, it has more something to 
do with the too while-loops. Here is some code:

(In general, it has basically nothing to do with PI-calc.)


c=2800  ## a counter


while c*2:
## do some calc. did not change c here.
...


b=c  ## number of elements

while (b-1):
   ## so some calc.
   ...
   b=b-1 ## just for while-loop condition.


   c = c-14;  ## this is code vor the 1st while-loop, BUT bust run after 
the 2nd-while-loop.
   pi = pi + str("%04d" % int(e + d/a))  ## this should be fast?! I dont 
know.


There are a output string, a list, and integers. No complex data 
structures; and no complex calculations.



Diez B. Roggisch wrote:

> mm wrote:
> 
> 
>>(Yes, I konw whats an object is...)
>>BTW. I did a translation of a pi callculation programm in C to Python.
>>(Do it by your own... ;-)
> 
> 
> Is that a question on how to optimize code you won't show us? If yes, I'm
> sorry to tell you that crystal balls are short these days. Too much
> new-year-outlooks.
> 
> Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Filename encoding on XP

2007-01-03 Thread Martin v. Löwis
kent sin schrieb:
> What encoding does the NTFS store the filename?

In UTF-16LE. However, on-disk storage is mostly irrelevant, what
matters is what encoding is used on the OS API.

Windows has two forms of file API: Wide (Unicode) and ANSI
(byte-oriented). On NT, the Wide API is "native"; the ANSI API
converts strings forth and back (introducing ? if the conversion
fails).

> I use walk, then print the filename, there are some ? in it, but some
> Chinese characters were display with no problem. I suspect the
> encoding of the filename is not unicode. 

You need to pass a Unicode string into walk as the directory; then
recursively all results should also be Unicode strings.

Regards,
Martin


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


Re: bad marshal data in site.py in fresh 2.5 install win

2007-01-03 Thread Martin v. Löwis
TiNo schrieb:
>  File "F:\Python25\lib\encodings\__init__.py", line 32, in 
>from encodings import aliases
> ValueError: bad marshal data
> 
> also removed site.pyc, and run it again, but with the same result.

It's likely rather aliases.pyc which is bad, so try removing that.
If in doubt, remove all .pyc files.

If one of them is bad, it's either because the stick wasn't ejected
properly at some point, or it suffers from data loss.

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


Re: C/C++, Perl, etc. to Python converter

2007-01-03 Thread Diez B. Roggisch
mm wrote:

> 
> Is there a Perl to Python converter?
> Or in general: a XY to Python converter?
> 
> Is see, that Python is much better then Perl anyway.
> But for beginners, they whant to konw how is this done with Python etc.
> 
> Sure, there are some docus out there in the internet. But a converter?

Nope. Different languages have different idioms, translating them to each
other - while technically possible, at least to some extend - won't result
in anything that a human being can work with.

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


Re: C/C++, Perl, etc. to Python converter

2007-01-03 Thread Matimus
I don't know of a converter, one may exist. I have seen similar
requests though and will give you a similar response to what I have
seen. A converter, if it exists, may be able to produce working code
but _not_ readable code. Python is a language whose strength comes
from, among other things, its readability and conventions. Learning
python is best done by using the online documentation
(http://docs.python.org/tut/tut.html) and reading existing code (take a
look at the built in modules).

My biggest fear of teaching someone to program by using a program to
convert perl to python is that they will end up writing python that
still looks like perl.

I don't know if it helps, but I know others will give you similar
advice.

-Matt

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


Re: code optimization (calc PI)

2007-01-03 Thread Michael

Ah, no. It was a HASH (assoziative Array or somethings like that).


mm wrote:
> 
> I konw, that for example while-loops in Perl are very slow. Maybe this 
> is also known in Pyhton. Then, I can translate the while-loops in to 
> for-loops, for example.
> More general, maybe there is a speed optimazation docu out there.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I add users using Python scripts on a Linux machine

2007-01-03 Thread Ivan Voras
Sebastian 'lunar' Wiesner wrote:
> Carsten Haese <[EMAIL PROTECTED]> typed

>> I don't think that that has anything to do with Linux or not. The
>> script is not the actual executable, hence its suid bit is irrelevant.
> 
> I don't think so. From what I know, the script is passed as executable
> to the kernel loader, which interprets the shebang and feeds the script
> through the correct interpreter. So the kernel loader sees the script
> itself as executable instead of the interpreter binary. I've heard of
> other Unix systems, which handle this differently (meaning that the
> SUID bit on scripts has an effect), but I may be wrong.

Yes, the kernel parses #! but the suid-ness is still controlled by the
target interpreter (i.e. python executable). At least BSD systems also
behave this way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C/C++, Perl, etc. to Python converter

2007-01-03 Thread Michael
Yes, I konw what you mean. And thats the right way to do it - for 
beginners. --But not for someone who allready know programmings things 
for many years.

They ask themself: How can I do this in Python? I can remember, it was 
that-way with Perl or C or C++ or whatever.

So, not only a ververter can be useful, also a translation table.
(Maybe just a table for print out.)

LangX <-> LangY



Matimus wrote:

> I don't know of a converter, one may exist. I have seen similar
> requests though and will give you a similar response to what I have
> seen. A converter, if it exists, may be able to produce working code
> but _not_ readable code. Python is a language whose strength comes
> from, among other things, its readability and conventions. Learning
> python is best done by using the online documentation
> (http://docs.python.org/tut/tut.html) and reading existing code (take a
> look at the built in modules).
> 
> My biggest fear of teaching someone to program by using a program to
> convert perl to python is that they will end up writing python that
> still looks like perl.
> 
> I don't know if it helps, but I know others will give you similar
> advice.
> 
> -Matt
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


When argparse will be in the python standard installation

2007-01-03 Thread [EMAIL PROTECTED]
Hi,

I feel argparse has some useful things that optparse doesn't have. But
I can't find it argparse in python library reference. I'm wondering
when it will be available in the python standard installation.

Thanks,
Peng

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


Re: C/C++, Perl, etc. to Python converter

2007-01-03 Thread Richard Charts

mm wrote:
> Is there a Perl to Python converter?
> Or in general: a XY to Python converter?
>
> Is see, that Python is much better then Perl anyway.
> But for beginners, they whant to konw how is this done with Python etc.
>
> Sure, there are some docus out there in the internet. But a converter?
I don't know of any converter, but I have seen a number of tutorials
that show how to do OO things in both perl and python for example.
Avi Kak of Purdue U. has one such tutorial.
When I took his class, he had a large package of notes that he said was
the basis for his next book.  It doesn't look like he ever got around
to publishing that one.
However, if you google his homepage, he does have at last one tutorial
posted for Perl vs. Python.

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


Re: Unsubscribing from the list

2007-01-03 Thread Dotan Cohen
On 03/01/07, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> if you're unable to follow written instructions, how on earth did you manage
> to subscribe to this list ?
>
> 
>

Actually, I'm a compete idiot and I always post to the mailing list
instead of RTFM or STFW. What's the name of that big big website?
goobble or something?!?

The first sentance under the heading "Python-list Subscribers" is:
The subscribers list is only available to the list administrator.
Admin address: Password:

As I'm not an admin, I read no further.

Dotan Cohen

http://lyricslist.com/lyrics/artist_albums/169/duran_duran.html
http://dapot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: array of class / code optimization

2007-01-03 Thread Jussi Salmela
hg kirjoitti:
> mm wrote:
> 
>> Yes, it was the (), equivalent to thiks like new() create new object
>> from class xy.
>>>   s1.append(Word)
>> s1.append(Word())
>>
>> But I was looking for a "struct" equivalent like in c/c++.
>> And/or "union". I can't find it.
>>
>> Maybe you know a source (URL) "Python for c/c++ programmers" or things
>> like that.
>>
>>
>> Yes, I konw whats an object is...
> 
> 
> A struct in C is unrelated to a struct in C++ as a struct in C++ _is_ a
> class.
> 
> 
> hg
> 

What does your sentence mean, exactly? If I take a C file xyz.c 
containing a struct definition S, say, rename it to be xyz.cpp and feed 
it to a C++ compiler, the S sure remains a struct and the C++ compiler 
has no difficulty in handling it as a struct, so ?!?

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


Re: C/C++, Perl, etc. to Python converter

2007-01-03 Thread Thomas Ploch
Matimus schrieb:
> I don't know of a converter, one may exist. I have seen similar
> requests though and will give you a similar response to what I have
> seen. A converter, if it exists, may be able to produce working code
> but _not_ readable code. Python is a language whose strength comes
> from, among other things, its readability and conventions. Learning
> python is best done by using the online documentation
> (http://docs.python.org/tut/tut.html) and reading existing code (take a
> look at the built in modules).
> 
> My biggest fear of teaching someone to program by using a program to
> convert perl to python is that they will end up writing python that
> still looks like perl.
> 
> I don't know if it helps, but I know others will give you similar
> advice.
> 
> -Matt
> 

I think that it *is* possible to do it, but a whole lot of work had to
be done to achieve this. It is all about how many rules (like how to
convert this block of unreadable code of language X into a readable
python block) you are willing to find/program (and these are a lot). It
is a almost gigantic task to make this work proper, but it definitely
*is* possible.

Something like this doesn't exist yet, but people (especially
Computational Linguists) are working on this.

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


Re: How do I add users using Python scripts on a Linux machine

2007-01-03 Thread Sebastian 'lunar' Wiesner
[ Ivan Voras <[EMAIL PROTECTED]> ]

> Sebastian 'lunar' Wiesner wrote:
>> Carsten Haese <[EMAIL PROTECTED]> typed
> 
>>> I don't think that that has anything to do with Linux or not. The
>>> script is not the actual executable, hence its suid bit is
>>> irrelevant.
>> 
>> I don't think so. From what I know, the script is passed as
>> executable to the kernel loader, which interprets the shebang and
>> feeds the script through the correct interpreter. So the kernel
>> loader sees the script itself as executable instead of the
>> interpreter binary. I've heard of other Unix systems, which handle
>> this differently (meaning that the SUID bit on scripts has an
>> effect), but I may be wrong.
> 
> Yes, the kernel parses #! but the suid-ness is still controlled by the
> target interpreter (i.e. python executable). At least BSD systems also
> behave this way.

I don't think, that the interpreter controls SUID-ness. Privileges are
always handled by the kernel. At least the kernel needs to agree, when
a normal user wants to execute a SUID scripts.

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


Re: function without brackets ?

2007-01-03 Thread Stef Mientki

> Hope this helps,
> 
thanks You all guys,
It's perfectly clear to me now !

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


Re: Synchronization methodology

2007-01-03 Thread Jeremy Dillworth
Hi Chris,

Have you looked at the mutex module?

Jeremy

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


type classobj not defined?

2007-01-03 Thread Wesley Brooks
Dear Users,

I'm in the process of adding assert statements to a large piece of
code to aid with bug hunting and came across the following issue;

Using python in a terminal window you can do the following:

>type(False) == bool
True

I would like to check that an object is a class, here's an example:

>class b:
def __init__(self):
self.c = 1
def d(self):
print self.c

>type(b)


But the following fails:

>type(b) == classobj
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'classobj' is not defined

For the time being I'll use b.__name__ == b to ensure I'm getting the
right class. Is there a reason why the other types such as bool are
defined but classobj isn't?

I'm running the following version of python:

Python 2.4.3 (#1, Jun 13 2006, 11:46:08)
[GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2

Cheers,

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


Re: type classobj not defined?

2007-01-03 Thread Peter Otten
Wesley Brooks wrote:

> Dear Users,
> 
> I'm in the process of adding assert statements to a large piece of
> code to aid with bug hunting and came across the following issue;
> 
> Using python in a terminal window you can do the following:
> 
>>type(False) == bool
> True
> 
> I would like to check that an object is a class, here's an example:
> 
>>class b:
> def __init__(self):
> self.c = 1
> def d(self):
> print self.c
> 
>>type(b)
> 
> 
> But the following fails:
> 
>>type(b) == classobj
> Traceback (most recent call last):
>   File "", line 1, in ?
> NameError: name 'classobj' is not defined
> 
> For the time being I'll use b.__name__ == b to ensure I'm getting the
> right class. Is there a reason why the other types such as bool are
> defined but classobj isn't?

No idea. You can easily define it yourself, though:

>>> class Classic: pass
...
>>> classobj = type(Classic)
>>> isinstance(Classic, classobj)
True

Note that "newstyle" classes (those deriving from object) are of type
'type', not 'classobj':

>>> class Newstyle(object): pass
...
>>> isinstance(Newstyle, classobj)
False
>>> isinstance(Newstyle, (classobj, type))
True

The inspect module wraps the functionality in a function:

>>> import inspect
>>> inspect.isclass(Newstyle)
True
>>> inspect.isclass(Classic)
True

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


Re: Why does Python never add itself to the Windows path?

2007-01-03 Thread Ben Sizer
Chris Lambacher wrote:
> On Tue, Jan 02, 2007 at 09:08:41AM -0800, Ben Sizer wrote:
> > Chris Lambacher wrote:
> > > The python part of the 'python setup.py install' idiom needs to be 
> > > omitted on
> > > Windows, but that does not mean that the solution is to automatically add 
> > > it
> > > to PATH.
> >
> > Firstly, that solution only works for actual Python scripts; it doesn't
> > solve the utility scripts that are often installed to the /scripts
> > directory. It's a shame that many responses on this thread don't
> > address that half of the issue. Am I the only person who installs
> > packages that add scripts (not all of which are Python ones)?
>
> Nope, but just adding the scripts directory to the PATH does not solve the
> problem.  You also need to either create an executable launcher (.bat  or
> .exe) for the script or mess with environment variables to tell Windows to
> treat .py files a executable.  This issue is solved in Unix by toggling the
> executable bit on the file in the file system.

Many of the scripts that are installed come as batch files or other
executables. They just assume the directory is in your PATH already,
which they aren't, until you set it that way.

> > Secondly, it's still a significant difference from the Unix-based
> > installs.
>
> Its not really.  Unix installs default to being installed to the prefix /usr,
> which just happens to put the executable in your path.  It does not modify the
> user's path in any way.

I was talking more in terms of the end-user experience. I don't know of
any binary package on the distros I've used (Mandriva/Mandrake, Fedora
Core, and Kubuntu) that install Python without it going into your path,
nor of any that allow you to avoid that while using their standard
package managers. It may be incidental in some meaning of the term, but
it's expected and apparently intended.

-- 
Ben Sizer

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


Re: code optimization (calc PI)

2007-01-03 Thread Matimus
Using the '+' operator for string concatonation can be slow, especially
when done many times in a loop.

>pi = pi + str("%04d" % int(e + d/a))  ## this should be fast?! I dont

The accepted solution would be to make pi an array and append to the
end...

pi = [] #create the array (empty)
...
...
pi.append(str("%04d"%int(e+d/a))) # append to it

And when it is time to print the results do the following:

print "".join(pi)

It may look strange, but it is a common Python idiom. You might also
look into an optimizer such as psycho: http://psyco.sourceforge.net/.

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


Re: Why does Python never add itself to the Windows path?

2007-01-03 Thread Ben Sizer
Martin v. Löwis wrote:

> Ben Sizer schrieb:
> > Firstly, that solution only works for actual Python scripts; it doesn't
> > solve the utility scripts that are often installed to the /scripts
> > directory.
>
> Those packages should install .bat files into /scripts on Windows.

Which still need their location to be be fully qualified, due to
/scripts not being in the path. This is not my experience with Linux
installations of the same packages.

> Please submit a patch that does so, then. Make sure you add user
> interface to make it an option.
>
> These things are *not* easy, and claiming that they are is
> misleading.

I will look into it.

-- 
Ben Sizer

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

Re: Unsubscribing from the list

2007-01-03 Thread Diez B. Roggisch
Dotan Cohen wrote:

> On 03/01/07, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> if you're unable to follow written instructions, how on earth did you
>> manage to subscribe to this list ?
>>
>> 
>>
> 
> Actually, I'm a compete idiot and I always post to the mailing list
> instead of RTFM or STFW. What's the name of that big big website?
> goobble or something?!?
> 
> The first sentance under the heading "Python-list Subscribers" is:
> The subscribers list is only available to the list administrator.
> Admin address: Password:
> 
> As I'm not an admin, I read no further.

Well, you should work on your reading skills then - just a sentence further
the solution lures:

"""
Python-list Subscribers 

(The subscribers list is only available to the list administrator.) 
Enter your admin address and password to visit the subscribers list: 
 Admin address: Password:   Visit Subscriber List

 To unsubscribe from Python-list, get a password reminder, or change your
subscription options enter your subscription email address: 
 Unsubscribe or edit options
"""

So, how about entering your email in that last input field, and
press "Unsubscribe or edit options"

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


A python library to convert RTF into PDF ?

2007-01-03 Thread leonel . gayard
Hi,

Does anyone know a good python library to convert a RTF file into PDF ?

This should be done automaticaly: I have a web page that takes some
values and inserts them into a RTF template, resulting in an RTF file.
However, I cannot send the output back to the user in RTF, it must be
sent in PDF instead, so I need to convert the result.

So, what library can I use to convert from RTF to PDF ? GPL / BSD
Libraries are welcome.

Thanks
Leonel

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


Re: a question on python dict

2007-01-03 Thread Tim Peters
[Tim Peters]
>> ...
>> Taking my response out of context to begin with doesn't really change
>> that I answered the question he asked ;-)

[Fredrik Lundh]
> welcome to comp.lang.python.
> 
>  

Thanks for the welcome!  It's tough to be a newbie here ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unsubscribing from the list

2007-01-03 Thread Fredrik Lundh
Dotan Cohen wrote:

> Actually, I'm a compete idiot

Robert provided *detailed* instructions, which you ignored.   I quoted 
the same instructions in my reply, which you also ignored.  the sentence 
after the one where you stopped reading also tells you what to do.  one 
might suspect that you don't really want to unsubscribe from this list...



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


Re: array of class / code optimization

2007-01-03 Thread Neil Cerutti
On 2007-01-03, Jussi Salmela <[EMAIL PROTECTED]> wrote:
> hg kirjoitti:
>> mm wrote:
>> 
>>> Yes, it was the (), equivalent to thiks like new() create new object
>>> from class xy.
   s1.append(Word)
>>> s1.append(Word())
>>>
>>> But I was looking for a "struct" equivalent like in c/c++.
>>> And/or "union". I can't find it.
>>>
>>> Maybe you know a source (URL) "Python for c/c++ programmers" or things
>>> like that.
>>>
>>>
>>> Yes, I konw whats an object is...
>> 
>> 
>> A struct in C is unrelated to a struct in C++ as a struct in C++ _is_ a
>> class.
>> 
>> 
>> hg
>
> What does your sentence mean, exactly? If I take a C file xyz.c
> containing a struct definition S, say, rename it to be xyz.cpp
> and feed it to a C++ compiler, the S sure remains a struct and
> the C++ compiler has no difficulty in handling it as a struct,
> so ?!?

That's true.

But it's also true that

struct foo {
  int x, y;
};

is exactly equivalent to:

class foo {
  public:
int x, y;
};

The only difference between struct and class in C++ is the
default access specification of its members.

-- 
Neil Cerutti
For those of you who have children and don't know it, we have a nursery
downstairs. --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unsubscribing from the list

2007-01-03 Thread Dotan Cohen
On 03/01/07, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Robert provided *detailed* instructions, which you ignored.   I quoted
> the same instructions in my reply, which you also ignored.  the sentence
> after the one where you stopped reading also tells you what to do.  one
> might suspect that you don't really want to unsubscribe from this list...
>

I didn't ignore his instructions. I went to the page, and found what I
was looking for. I told him thank you, and explained why I didn't find
it the first time. That was public on the mailing list, go check the
archives. Specifically, the first three messages in this thread.

I haven't yet unsubscribed because I'm waiting for this thread to die.
It's actually rather amusing, because I can't decide if some list
members are genuinly upset at me, or if it is a orm of humour that I
am unfamiliar with. Either way, the thread is entertaining enough that
I remain.

Dotan Cohen

http://lyricslist.com/lyrics/artist_albums/443/seger_bob.html
http://technology-sleuth.com/long_answer/how_can_i_be_safe_online.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list/dictionary as case statement ?

2007-01-03 Thread Tom Plunket
Bjoern Schliessmann wrote:

> Intels aren't RISC, are they?

Not the ones in PCs.  The OP didn't specify the CPU that's being used,
however.


-tom!

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


Re: A python library to convert RTF into PDF ?

2007-01-03 Thread Tom Plunket
[EMAIL PROTECTED] wrote:

> So, what library can I use to convert from RTF to PDF ? GPL / BSD
> Libraries are welcome.

If you could write to LaTeX files instead, you could then just use
pdflatex that comes with all of the LaTeX distributions.


-tom!

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


Re: list/dictionary as case statement ?

2007-01-03 Thread MRAB

Bjoern Schliessmann wrote:
> Tom Plunket wrote:
>
> > Often (always?) RISC architectures' instruction+operand lengths
> > are fixed to the word size of the machine.  E.g. the MIPS 3000 and
> > 4000 were 32 bits for every instruction, and PC was always a
>^^
> > multiple of four.
>
> Intels aren't RISC, are they?
>
I think that "PC" referred to the CPU's Program Counter.

The x86 CPUs if typical Windows PCs aren't RISC but Intel also
manufacture X-Scale (ARM core) processors which are.

> But for PowerPC it's the same, every instruction has 32 bit.
>
As are those of ARM processors like X-Scale (although some ARM
processors support the Thumb instruction set).

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


Sorting on multiple values, some ascending, some descending

2007-01-03 Thread dwelden
I have successfully used the sort lambda construct described in
http://mail.python.org/pipermail/python-list/2006-April/377443.html.
However, how do I take it one step further such that some values can be
sorted ascending and others descending? Easy enough if the sort values
are numeric (just negate the value), but what about text?

Is the only option to define an external sorting function to loop
through the list and perform the comparisons one value at a time?

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


Re: A python library to convert RTF into PDF ?

2007-01-03 Thread leonel . gayard
No, this won't work.

First, pdflatex is too slow. Second, my templates are M$-Word doc
files, and they cannot be easily converted to tex. I have tried to
convert them to tex using OpenOffice, but the result is ugly as hell.

I cannot convert the doc files into PDF, because I do not have a
library that allows me to manipulate PDF files. Reportlab does *not* do
the trick, it can create new pdf files, but it cannot manipulate
existing pdf files.

So, converting the doc files to RTF, in order to manipulate them is my
best chance. Now how can I convert them to PDF ?

[]'s
Leonel


Tom Plunket wrote:
> [EMAIL PROTECTED] wrote:
>
> > So, what library can I use to convert from RTF to PDF ? GPL / BSD
> > Libraries are welcome.
>
> If you could write to LaTeX files instead, you could then just use
> pdflatex that comes with all of the LaTeX distributions.
> 
> 
> -tom!
> 
> --

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


Re: list/dictionary as case statement ?

2007-01-03 Thread Bjoern Schliessmann
MRAB wrote:

> I think that "PC" referred to the CPU's Program Counter.

Argh, thanks. :)
 
> The x86 CPUs if typical Windows PCs aren't RISC but Intel also
> manufacture X-Scale (ARM core) processors which are.

Okay, sorry for lack of precision. I was referring to x86.
 
Regards,


Björn

-- 
BOFH excuse #101:

Collapsed Backbone

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


Re: code optimization (calc PI)

2007-01-03 Thread Stefan Schwarzer
On 2007-01-03 16:50, mm wrote:
> More general, maybe there is a speed optimazation docu out there.

At least Alex Martellis "Python in a Nutshell" has a section on
optimization.

I presented this at the last EuroPython conference:
http://sschwarzer.com/download/optimization_europython2006.pdf

Stefan

-- 
Dr.-Ing. Stefan Schwarzer
SSchwarzer.com - Softwareentwicklung für Technik und Wissenschaft
http://sschwarzer.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code optimization (calc PI)

2007-01-03 Thread Michael
Hmm..  thanks. I did this changes, but without any performance profits.


Matimus wrote:

> Using the '+' operator for string concatonation can be slow, especially
> when done many times in a loop.
> 
> 
>>   pi = pi + str("%04d" % int(e + d/a))  ## this should be fast?! I dont
> 
> 
> The accepted solution would be to make pi an array and append to the
> end...
> 
> pi = [] #create the array (empty)
> ...
> ...
> pi.append(str("%04d"%int(e+d/a))) # append to it
> 
> And when it is time to print the results do the following:
> 
> print "".join(pi)
> 
> It may look strange, but it is a common Python idiom. You might also
> look into an optimizer such as psycho: http://psyco.sourceforge.net/.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: array of class / code optimization

2007-01-03 Thread Bjoern Schliessmann
mm wrote:

> But I was looking for a "struct" equivalent like in c/c++.
> And/or "union". I can't find it.

class Honk(object):
pass

test = Honk()
test.spam = 4
test.eggs = "Yum"

Is it this what you're looking for?

> Maybe you know a source (URL) "Python for c/c++ programmers" or
> things like that.

Have a look at "Learning Python" by Mark Lutz and David Ascher. I
found it very helpful because they often refer to C/C++.

Regards,


Björn

-- 
BOFH excuse #344:

Network failure -  call NBC

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


Re: type classobj not defined?

2007-01-03 Thread Martin v. Löwis
Wesley Brooks schrieb:
>> type(b) == classobj
> Traceback (most recent call last):
>  File "", line 1, in ?
> NameError: name 'classobj' is not defined
> 
> For the time being I'll use b.__name__ == b to ensure I'm getting the
> right class. Is there a reason why the other types such as bool are
> defined but classobj isn't?

In general, only those types which you also use as constructors are
builtin. I.e. you would write bool(foo) (where foo is a variable),
but you would not write classobj("bar") (to create a class named
"bar"). That you can also use it for a type test is a side-effect.

Some more types are available in the types module. In this case,
you can use types. In this case, types.ClassType would do the trick.

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


Re: When argparse will be in the python standard installation

2007-01-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I feel argparse has some useful things that optparse doesn't have. But
> I can't find it argparse in python library reference. I'm wondering
> when it will be available in the python standard installation.

there's already two different option parsing modules in the standard 
library.  maybe improving one of the existing ones might be a better 
idea than adding a third one?



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


Re: Why does Python never add itself to the Windows path?

2007-01-03 Thread Martin v. Löwis
Ben Sizer schrieb:
>> Those packages should install .bat files into /scripts on Windows.
> 
> Which still need their location to be be fully qualified, due to
> /scripts not being in the path. This is not my experience with Linux
> installations of the same packages.

Ah, so you not only want the directory that contains Python added to
the path, but also /scripts. That's again a new requirement, and I
think it is the first time that somebody requests it.

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


Re: When argparse will be in the python standard installation

2007-01-03 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> I feel argparse has some useful things that optparse doesn't have. But
> I can't find it argparse in python library reference. I'm wondering
> when it will be available in the python standard installation.

On its own, never. Somebody has to contribute it to Python, and that
somebody has to be the author.

However, it would be better if missing features where provided in
existing libraries, rather than introducing new libraries to replace
the existing ones (i.e. I would likely reject a patch to add yet another
argument parsing library - we already have getopt and optparse).

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


Cannot build 2.5 on FC6 x86

2007-01-03 Thread Paul Watson
./configure
make
make test

The result appears to hang after the test_tkl... line.  I had to kill 
the 'make test' process which terminated it.  Any suggestions?


280 tests OK.
4 tests failed:
 test_optparse test_socket test_socket_ssl test_urllib2
35 tests skipped:
 test_aepack test_al test_applesingle test_bsddb185 test_bsddb3
 test_cd test_cl test_codecmaps_cn test_codecmaps_hk
 test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_curses
 test_gl test_imgfile test_linuxaudiodev test_logging test_macfs
 test_macostools test_nis test_normalization test_ossaudiodev
 test_pep277 test_plistlib test_scriptpackages test_socketserver
 test_startfile test_sunaudiodev test_tcl test_timeout
 test_urllib2net test_urllibnet test_winreg test_winsound
 test_zipfile64
2 skips unexpected on linux2:
 test_tcl test_logging

make: *** [test] Terminated
Terminated
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does Python never add itself to the Windows path?

2007-01-03 Thread vbgunz
> > I don't understand what all the fuss is about. Add a single page to the
> > installer and on it, have 3 radio buttons. The choices could be "add to
> > path (recommended)", "add to path with version", "do not add to path
> > (not recommended)".
>
> Please submit a patch to sf.net/projects/python that does so.

If I could I would. My only point jumping in here is this; adding
python to the path has got to be more beneficially productive for
everyone than not adding it at all. I don't even use Windows enough to
complain about it and I thought I'll voice my agreement on it.

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


Re: Sorting on multiple values, some ascending, some descending

2007-01-03 Thread Raymond Hettinger

dwelden wrote:
> I have successfully used the sort lambda construct described in
> http://mail.python.org/pipermail/python-list/2006-April/377443.html.
> However, how do I take it one step further such that some values can be
> sorted ascending and others descending? Easy enough if the sort values
> are numeric (just negate the value), but what about text?
>
> Is the only option to define an external sorting function to loop
> through the list and perform the comparisons one value at a time?

The simplest way is to take advantage of sort-stability and do
successive sorts.  For example, to sort by a primary key ascending and
a secondary key decending:

   L.sort(key=lambda r: r.secondary, reverse=True)
   L.sort(key=lambda r: r.primary)

A less general technique is to transform fields in a way that reverses
their comparison order:

  L.sort(key=lambda r: (-r.age, r.height))# sorts descending age
and ascending height


Raymond

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


Re: bad marshal data in site.py in fresh 2.5 install win

2007-01-03 Thread TiNo
Removing aliases.pyc solved it.

Thank you.

2007/1/3, "Martin v. Löwis" <[EMAIL PROTECTED]>:
> TiNo schrieb:
> >  File "F:\Python25\lib\encodings\__init__.py", line 32, in 
> >from encodings import aliases
> > ValueError: bad marshal data
> >
> > also removed site.pyc, and run it again, but with the same result.
>
> It's likely rather aliases.pyc which is bad, so try removing that.
> If in doubt, remove all .pyc files.
>
> If one of them is bad, it's either because the stick wasn't ejected
> properly at some point, or it suffers from data loss.
>
> Regards,
> Martin
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting on multiple values, some ascending, some descending

2007-01-03 Thread Carsten Haese
On Wed, 2007-01-03 at 10:48 -0800, dwelden wrote:
> I have successfully used the sort lambda construct described in
> http://mail.python.org/pipermail/python-list/2006-April/377443.html.
> However, how do I take it one step further such that some values can be
> sorted ascending and others descending? Easy enough if the sort values
> are numeric (just negate the value), but what about text?
> 
> Is the only option to define an external sorting function to loop
> through the list and perform the comparisons one value at a time?

If by "external sorting function" you mean a custom comparison function
to pass to sort as the cmp argument, then that's one option, but not the
only one.

If you know in advance which columns contain strings, you could write a
function that operates on strings and is strictly monotonically
decreasing, i.e. it behaves such that f(x) < f(y) if and only if x > y.
This function could then be used in the sort key for sorting on a string
column in descending order. The following function does the trick:

def antistring(x):
   return [256-ord(c) for c in x]+[257]

(Proof by vigorous handwaving.)

Lastly, if your array is small enough that you can tolerate the
performance hit of multiple passes, you could exploit the fact that
sort() is guaranteed to be stable in sufficiently recent releases of
CPython. Split your sort on n columns into n separate sorts on a single
column each, and use the 'reverse' parameter to specify whether to sort
forward or backwards.

Hope this helps,

Carsten.


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


Re: A python library to convert RTF into PDF ?

2007-01-03 Thread Felipe Almeida Lessa
On 3 Jan 2007 10:52:02 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> I have tried to
> convert them to tex using OpenOffice, but the result is ugly as hell.

Why not use OO.org to convert DOC to PDF? It does so natively, IIRC.

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


Re: list/dictionary as case statement ?

2007-01-03 Thread Stef Mientki
Tom Plunket wrote:
> Bjoern Schliessmann wrote:
> 
>> Intels aren't RISC, are they?
> 
> Not the ones in PCs.  The OP didn't specify the CPU that's being used,
> however.
> 
Well it was meant for a small micro-controller, the PIC-14-series,
e.g. PIC16F877.

I already build a simulator for this device in  Delphi,
but it seemed a nice idea, and a good exercise for me,
to see how this could be done in Python.

And thanks to you all,
I've the core (not the pheripherals) working now,
and my experience with Python are very positive.

The main advantages of the simulator in Python are:
   - very elegant and lean code
   - the treshold of Python is much lower
 (in my opinion, simulators only live when more people are involved)
The main disadvantages (I think, not yet tested)
   - the speed is much lower
   - the GUI is much more complex

For those who are interested,

The rough code of the Python code can be seen here
(I might have committed a mortal sin, by changing "self" into "S" ??)
   http://oase.uci.kun.nl/~mientki/download/cpu2.txt
btw, as I'm a total newbie, any comment is welcome !!

The Delphi simulator can be seen here
   http://oase.uci.kun.nl/~mientki/data_www/pic/jalss/jalss.html

thanks again,
for all your fast and very adequate responses !!

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


Re: A python library to convert RTF into PDF ?

2007-01-03 Thread robert
[EMAIL PROTECTED] wrote:
> Hi,
> 
> Does anyone know a good python library to convert a RTF file into PDF ?
> 
> This should be done automaticaly: I have a web page that takes some
> values and inserts them into a RTF template, resulting in an RTF file.
> However, I cannot send the output back to the user in RTF, it must be
> sent in PDF instead, so I need to convert the result.
> 
> So, what library can I use to convert from RTF to PDF ? GPL / BSD
> Libraries are welcome.
> 

Don't know a mere self-contained job.

But probably then you are on a Windows - print the RTF through Word 
(win32com/ctypes) or through a RichEdit control into a .ps  then convert via 
ghostscript/ps2pdf into a pdf.  (gs obviously doesn't know RTF by default or at 
all...)


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


Re: Why does Python never add itself to the Windows path?

2007-01-03 Thread Martin v. Löwis
vbgunz schrieb:
>>> I don't understand what all the fuss is about. Add a single page to the
>>> installer and on it, have 3 radio buttons. The choices could be "add to
>>> path (recommended)", "add to path with version", "do not add to path
>>> (not recommended)".
>> Please submit a patch to sf.net/projects/python that does so.
> 
> If I could I would. My only point jumping in here is this; adding
> python to the path has got to be more beneficially productive for
> everyone than not adding it at all. I don't even use Windows enough to
> complain about it and I thought I'll voice my agreement on it.

Ok. So I can answer your (implied) question: much of the fuss is about
lack of contributions.

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


Re: Cannot build 2.5 on FC6 x86

2007-01-03 Thread Martin v. Löwis
Paul Watson schrieb:
> ./configure
> make
> make test
> 
> The result appears to hang after the test_tkl... line.  I had to kill
> the 'make test' process which terminated it.  Any suggestions?

There isn't (or shouldn't be) any "test_tkl..." line. What precisely
was the line, and how long did you wait until you thought it hangs?

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


Re: Sorting on multiple values, some ascending, some descending

2007-01-03 Thread bearophileHUGS
Raymond Hettinger:
> The simplest way is to take advantage of sort-stability and do
> successive sorts.  For example, to sort by a primary key ascending and
> a secondary key decending:
>L.sort(key=lambda r: r.secondary, reverse=True)
>L.sort(key=lambda r: r.primary)

That's probably the faster and simpler way.
The following solution is probably slow, memory-hungry, and it's not
tested much so it may be buggy too, but it shows my idea, and bugs can
be fixed:

class Inverter:
def __init__(self, item, reversed=False):
self.item = item
self.reversed = reversed
def __cmp__(self, other):
if self.reversed:
return cmp(other.item, self.item)
else:
return cmp(self.item, other.item)

data = [[1, "a", "b"], [1, "b", "d"], [1, "d", "a"]]
reverses = [True, False, False]

print sorted(data, key=lambda subseq: map(Inverter, subseq, reverses))

Bye,
bearophile

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


Re: Sorting on multiple values, some ascending, some descending

2007-01-03 Thread Peter Otten
Raymond Hettinger wrote:

> dwelden wrote:
>> I have successfully used the sort lambda construct described in
>> http://mail.python.org/pipermail/python-list/2006-April/377443.html.
>> However, how do I take it one step further such that some values can be
>> sorted ascending and others descending? Easy enough if the sort values
>> are numeric (just negate the value), but what about text?
>>
>> Is the only option to define an external sorting function to loop
>> through the list and perform the comparisons one value at a time?
> 
> The simplest way is to take advantage of sort-stability and do
> successive sorts.  For example, to sort by a primary key ascending and
> a secondary key decending:
> 
>L.sort(key=lambda r: r.secondary, reverse=True)
>L.sort(key=lambda r: r.primary)
> 
> A less general technique is to transform fields in a way that reverses
> their comparison order:
> 
>   L.sort(key=lambda r: (-r.age, r.height))# sorts descending age
> and ascending height

You can get generality if you are willing to pay the performance penalty:

>>> items
[(3, 1), (2, 2), (1, 1), (1, 3), (2, 1), (2, 3), (1, 2)]
>>> class Reverse:
... def __cmp__(self, other):
... return -cmp(self.value, other.value)
... def __init__(self, value):
... self.value = value
...
>>> items.sort(key=lambda (x, y): (x, Reverse(y)))
>>> items
[(1, 3), (1, 2), (1, 1), (2, 3), (2, 2), (2, 1), (3, 1)]

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


Re: Sorting on multiple values, some ascending, some descending

2007-01-03 Thread George Sakkis
dwelden wrote:

> I have successfully used the sort lambda construct described in
> http://mail.python.org/pipermail/python-list/2006-April/377443.html.
> However, how do I take it one step further such that some values can be
> sorted ascending and others descending? Easy enough if the sort values
> are numeric (just negate the value), but what about text?

You got already some good replies; here's yet another less-than-optimal
way:

class revstr(str):
def __lt__(self, other):
return str.__gt__(self,other)
def __gt__(self, other):
return str.__lt__(self,other)

L.sort(key=lambda i: (i.somestring, revstr(i.someotherstring),
i.anotherkey))


George

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


Re: array of class / code optimization

2007-01-03 Thread hg
Neil Cerutti wrote:

> On 2007-01-03, Jussi Salmela <[EMAIL PROTECTED]> wrote:
>> hg kirjoitti:
>>> mm wrote:
>>> 
 Yes, it was the (), equivalent to thiks like new() create new object
 from class xy.
>   s1.append(Word)
 s1.append(Word())

 But I was looking for a "struct" equivalent like in c/c++.
 And/or "union". I can't find it.

 Maybe you know a source (URL) "Python for c/c++ programmers" or things
 like that.


 Yes, I konw whats an object is...
>>> 
>>> 
>>> A struct in C is unrelated to a struct in C++ as a struct in C++ _is_ a
>>> class.
>>> 
>>> 
>>> hg
>>
>> What does your sentence mean, exactly? If I take a C file xyz.c
>> containing a struct definition S, say, rename it to be xyz.cpp
>> and feed it to a C++ compiler, the S sure remains a struct and
>> the C++ compiler has no difficulty in handling it as a struct,
>> so ?!?
> 
> That's true.
> 
> But it's also true that
> 
> struct foo {
>   int x, y;
> };
> 
> is exactly equivalent to:
> 
> class foo {
>   public:
> int x, y;
> };
> 
> The only difference between struct and class in C++ is the
> default access specification of its members.
> 
> --
> Neil Cerutti
> For those of you who have children and don't know it, we have a nursery
> downstairs. --Church Bulletin Blooper


And that is what I meant.

hg


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


Re: Unsubscribing from the list

2007-01-03 Thread Robert Kern
Dotan Cohen wrote:
> On 03/01/07, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> Robert provided *detailed* instructions, which you ignored.   I quoted
>> the same instructions in my reply, which you also ignored.  the sentence
>> after the one where you stopped reading also tells you what to do.  one
>> might suspect that you don't really want to unsubscribe from this list...
> 
> I didn't ignore his instructions. I went to the page, and found what I
> was looking for. I told him thank you, and explained why I didn't find
> it the first time.

He misunderstood you (as I nearly did, too). The way you phrased "decided that
there was no futher interest on the page for me" is somewhat ambiguous: it can
seem like it refers to the second time, not the first.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


M. Hammonds python panel

2007-01-03 Thread [EMAIL PROTECTED]
Hello all

I am a great fan of Mark Hammonds python pannel. But since starship
went down it didn't come up again ...with the link in my favs to
http://starship.python.net/crew/mhammond/mozilla/pythonpanel.xul
still pointing nowhere.

Maybe Mark is around here somewhere...

Jürgen

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


Re: Unsubscribing from the list

2007-01-03 Thread Dotan Cohen
On 03/01/07, Robert Kern <[EMAIL PROTECTED]> wrote:
> He misunderstood you (as I nearly did, too). The way you phrased "decided that
> there was no futher interest on the page for me" is somewhat ambiguous: it can
> seem like it refers to the second time, not the first.
>

Ah. Sorry. I'm getting better at confusing people :)

if ($you=="got_offended") {
$dotan="sorry";
}

Dotan Cohen

http://what-is-what.com/what_is/website.html
http://lyricslist.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unsubscribing from the list

2007-01-03 Thread Jan Dries
Dotan Cohen wrote:
> On 03/01/07, Robert Kern <[EMAIL PROTECTED]> wrote:
>> He misunderstood you (as I nearly did, too). The way you phrased "decided 
>> that
>> there was no futher interest on the page for me" is somewhat ambiguous: it 
>> can
>> seem like it refers to the second time, not the first.
>>
> 
> Ah. Sorry. I'm getting better at confusing people :)
> 
> if ($you=="got_offended") {
> $dotan="sorry";
> }

Except that on this list, you might offend people just by using vulgar 
language like that. Better rephrase it to:

if you == "got_offended":
 dotan = "sorry"


Regards,
Jan


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


Re: M. Hammonds python panel

2007-01-03 Thread Thomas Heller
[EMAIL PROTECTED] schrieb:
> Hello all
> 
> I am a great fan of Mark Hammonds python pannel. But since starship
> went down it didn't come up again ...with the link in my favs to
> http://starship.python.net/crew/mhammond/mozilla/pythonpanel.xul
> still pointing nowhere.
> 
> Maybe Mark is around here somewhere...

It may be better to mail him directly.  You should be able to find his
email address.

Thomas

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


Re: When argparse will be in the python standard installation

2007-01-03 Thread Steven Bethard
Martin v. Löwis wrote:
> [EMAIL PROTECTED] schrieb:
>> I feel argparse has some useful things that optparse doesn't have. But
>> I can't find it argparse in python library reference. I'm wondering
>> when it will be available in the python standard installation.
> 
> On its own, never. Somebody has to contribute it to Python, and that
> somebody has to be the author.

As the author of argparse, I'm happy to contribute it, though I've been 
thinking that it would be more appropriate for the Python 3.0 line than 
the Python 2.X line.

> However, it would be better if missing features where provided in
> existing libraries, rather than introducing new libraries to replace
> the existing ones (i.e. I would likely reject a patch to add yet another
> argument parsing library - we already have getopt and optparse).

That was my original intention, and argparse started out using the 
optparse code. But optparse is quite difficult to extend, and in the 
end, when I found that I had monkey-patched or rewritten just about 
everything in optparse, I decided to drop the optparse code entirely.

If someone has an idea how to include argparse features into optparse, 
I'm certainly all for it. But I tried and failed to do this myself, so I 
don't know how to go about it.

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


Py_BuildValue or PyList_SetItem()

2007-01-03 Thread Sheldon
Hi,

I have a function that creates python objects out of C arrays and
returns them to Python. Below is a working example that I later want to
expand to return 12 arrays back to Python. The problem is that when I
print out the values in Python I get undesired reults. See below. Does
anyone know what is going on here?
The array values are good before the conversion.

**
int createPythonObject(void) {
  int i,j,k;
  PyObject *Rva=PyList_New(12);

  for (i = 0; i < 12; i++) {
PyObject *op = PyFloat_FromDouble((double)va[i]);
if (PyList_SetItem(Rva,i,op) !=0) {
  fprintf(stderr,"Error in creating python va object\n");
  exit(EXIT_FAILURE);
}
Py_DECREF(op);
op = 0;
  return Py_BuildValue("N",Rva);
 }

Results in Python:

, , , , , , , ,
, , , 


Any help is appreciated!

/Sheldon

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


Re: Py_BuildValue or PyList_SetItem()

2007-01-03 Thread Jack Diederich
On Wed, Jan 03, 2007 at 01:16:38PM -0800, Sheldon wrote:
> I have a function that creates python objects out of C arrays and
> returns them to Python. Below is a working example that I later want to
> expand to return 12 arrays back to Python. The problem is that when I
> print out the values in Python I get undesired reults. See below. Does
> anyone know what is going on here?
> The array values are good before the conversion.
> 
> **
> int createPythonObject(void) {
>   int i,j,k;
>   PyObject *Rva=PyList_New(12);
> 
>   for (i = 0; i < 12; i++) {
> PyObject *op = PyFloat_FromDouble((double)va[i]);
> if (PyList_SetItem(Rva,i,op) !=0) {
>   fprintf(stderr,"Error in creating python va object\n");
>   exit(EXIT_FAILURE);
> }
> Py_DECREF(op);
> op = 0;
>   return Py_BuildValue("N",Rva);
>  }
> 
> Results in Python:
> 
> , ,  0x80d885c>, , ,  at 0x80d885c>, , ,
> , ,  0x80d885c>, 
> 

PyList_SetItem steals a reference to "op" so DECREF'ing it reduces
the refcount to zero.

http://docs.python.org/api/listObjects.html

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


  1   2   >