Re: How to remove subset from a file efficiently?

2006-01-13 Thread Fredrik Lundh
"fynali" wrote:

> Is a rewrite possible of Raymond's or Fredrik's suggestions above which
> will still give me the time saving made?

Python 2.2 don't have a readymade set type (new in 2.3), and it doesn't
support generator expressions (the thing that caused the syntax error).

however, using a dictionary instead of the set

barred = {}
for number in open(open('/home/sjd/python/wip/CBR319.dat')):
barred[number] = None # just add it as a key

and a list comprehension instead of the generator expression

outfile.writelines([number for number in infile if number not in barred])

(note the extra brackets)

should give you decent performance under 2.2.





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


Re: How to remove subset from a file efficiently?

2006-01-13 Thread fynali
[bonono]
> Have you tried the explicit loop variant with psyco ?

Sure I wouldn't mind trying; can you suggest some code snippets along
the lines of which I should try...?

[fynali]
> Needless to say, I'm utterly new to python and my programming
> skills & know-how are rudimentary.

(-:

-- 
fynali

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


Re: How to remove subset from a file efficiently?

2006-01-13 Thread fynali
--
$ ./cleanup.py
Traceback (most recent call last):
  File "./cleanup.py", line 3, in ?
import itertools
ImportError: No module named itertools

--
$ time ./cleanup.py
  File "./cleanup.py", line 8
outfile.writelines(number for number in postpaid_file if number
not in barred)
^
SyntaxError: invalid syntax

The earlier results I posted were run on my workstation which has
Python 2.4.1,

$ uname -a && python -V
Linux sajid 2.6.13-15.7-smp #1 SMP
Tue Nov 29 14:32:29 UTC 2005 i686 i686 i386 GNU/Linux
Python 2.4.1

but the server on which the actual processing will be done has an older
version )-:

$ uname -a && python -V
Linux cactus 2.4.21-20.ELsmp #1 SMP
Wed Aug 18 20:46:40 EDT 2004 i686 i686 i386 GNU/Linux
Python 2.2.3

Is a rewrite possible of Raymond's or Fredrik's suggestions above which
will still give me the time saving made?

--
fynali

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


Re: How to remove subset from a file efficiently?

2006-01-13 Thread bonono

fynali wrote:
> $ cat cleanup_ray.py
> #!/usr/bin/python
> import itertools
>
> b = set(file('/home/sajid/python/wip/stc/2/CBR333'))
>
> file('PSP-CBR.dat,ray','w').writelines(itertools.ifilterfalse(b.__contains__,file('/home/sajid/python/wip/stc/2/PSP333')))
>
> --
> $ time ./cleanup_ray.py
>
> real0m5.451s
> user0m4.496s
> sys 0m0.428s
>
> (-: Damn!  That saves a bit more time!  Bravo!
>
> Thanks to you Raymond.
Have you tried the explicit loop variant with psyco ? My experience is
that psyco is pretty good at optimizing for loop which usually results
in faster code than even built-in map/filter variant.

Though it would just be 1 or 2 sec difference(given what you already
have) so may not be important but could be fun.

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


Re: How to remove subset from a file efficiently?

2006-01-13 Thread fynali
$ cat cleanup_ray.py
#!/usr/bin/python
import itertools

b = set(file('/home/sajid/python/wip/stc/2/CBR333'))

file('PSP-CBR.dat,ray','w').writelines(itertools.ifilterfalse(b.__contains__,file('/home/sajid/python/wip/stc/2/PSP333')))

--
$ time ./cleanup_ray.py

real0m5.451s
user0m4.496s
sys 0m0.428s

(-: Damn!  That saves a bit more time!  Bravo!

Thanks to you Raymond.

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


Re: Marshal Obj is String or Binary?

2006-01-13 Thread Steven D'Aprano
On Fri, 13 Jan 2006 22:20:27 -0800, Mike wrote:

> Thanks everyone. It seems broken storing complex structures as escaped
> strings, but I think I'll take my changes. 


Have you read the marshal reference?

http://docs.python.org/lib/module-marshal.html

marshal doesn't store data as escaped strings, it stores them as binary
strings. When you print the binary string to the console, unprintable
characters are shown escaped.

I'm guessing you probably want to use pickle instead of marshal. marshal
is intended only for dealing with .pyc files, and has some important
limitations. pickle is intended to be a general purpose serializer.


-- 
Steve.

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


Re: Is 'everything' a refrence or isn't it?

2006-01-13 Thread Steven D'Aprano
On Sat, 14 Jan 2006 04:22:53 +, Donn Cave wrote:

> Quoth Steven D'Aprano <[EMAIL PROTECTED]>:
> | On Thu, 12 Jan 2006 16:11:53 -0800, rurpy wrote:
> |> It would help if you or someone would answer these
> |> five questions (with something more than "yes" or "no" :-)
> |> 
> |> 1. Do all objects have values?
> ...
> |> 2. What is the value of object()?
> 
> [ I assume you mean, the object returned by object(). ]
> 
> It doesn't really have a value.  I can't think of any kind of
> computation that could use this object directly.

Here is one:

obj_inst = object()

def computation(data):
global obj_inst
if data is obj_inst:
print FirstOneThousandPrimes()
else:
print TextOfWarAndPeace()


It isn't a particularly useful computation, but it is a computation.



> |> 3. If two objects are equal with "==", does that
> |>   mean their values are the same?
> 
> Yes.
> 
> | >>> 3.0 == 3
> | True
> 
> Evidently the value of 3.0 is the same as the value of 3.

Okay.

>>> "3" == 3
False

Evidently the value of three is not the same as the value of three.

Let's try not to be too deep here, okay? Before asking "what is the value
of foo?", we have to agree on what we mean by "value". It is easy to tie
yourself into knots here.


> |> 4. Are object attributes part of an object's type
> |>   or it's value, or something else?  (I think the first.)
> |
> | The type/class defines what attributes (generic) objects have. The value
> | of the attribute lives with the instance itself (that's why fred.attribute
> | and barney.attribute can be different).
> 
> I think to be strictly accurate, attributes and their values may reside
> in a class instance, or in (one of) its class(es.)

When you call instance.attribute, attribute may be either a class
attribute or an instance attribute. If it is a class attribute, it belongs
to the class, not the instance, even if you access it through the
attribute. 
 

> In the most common
> case, functions will be in the class and data will be in the instance,
> but every variation on this is reasonably common.



> | ... Whether you want to say the
> | attribute itself is part of the class or part of the instance value is, in
> | my opinion, not a useful question. The answer depends on which way you
> | want to look at it.
> 
> For a given class and instance, it can be more obvious.  Take the object
> returned by object(), which has attributes like '__reduce__' - all those
> attributes may reasonably be considered "type" and not "value".

I don't see that "value" or "type" are opposite, I see that they are
orthogonal. The type of 1 is int, the value of 1 is integer one. The
type of object() is object, the value is itself. The type of
object().__reduce__ is method, and the value of object().__reduce__ is
the particular (generic) object bound to the name __reduce__ in the class
object namespace. That method is a class attribute, and so it part of the
value of object().


Am I the only one that wishes that object() had been given another name,
so it would be easier to talk about the generic programming concept object
and the specific Python new-style class object without confusion?


-- 
Steven.

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


Re: Marshal Obj is String or Binary?

2006-01-13 Thread Mike
Thanks everyone. It seems broken storing complex structures as escaped
strings, but I think I'll take my changes. 

Thanks,
Mike

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


Re: How to remove subset from a file efficiently?

2006-01-13 Thread fynali
$ time fgrep -x -v -f CBR333 PSP333 > PSP-CBR.dat.fgrep

real0m31.551s
user0m16.841s
sys 0m0.912s

--
$ time ./cleanup.py

real0m6.080s
user0m4.836s
sys 0m0.408s

--
$ wc -l PSP-CBR.dat.fgrep PSP-CBR.dat.python
  3872421 PSP-CBR.dat.fgrep
  3872421 PSP-CBR.dat.python

Fantastic, at any rate the time is down from my initial ~4 min.!

Thank you Chris.  The fgrep approach is clean and to the point; and one
more reason to love the *nix approach to handling everyday problems.

Fredrik's set|dict approach in Python above gives me one more reason to
love Python.  And it is indeed fast, 5x!

Thank you all for all your help.

-- 
fynali

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


Re: Is 'everything' a refrence or isn't it?

2006-01-13 Thread Donn Cave
Quoth Steven D'Aprano <[EMAIL PROTECTED]>:
| On Thu, 12 Jan 2006 16:11:53 -0800, rurpy wrote:
|> It would help if you or someone would answer these
|> five questions (with something more than "yes" or "no" :-)
|> 
|> 1. Do all objects have values?
...
|> 2. What is the value of object()?

[ I assume you mean, the object returned by object(). ]

It doesn't really have a value.  I can't think of any kind of
computation that could use this object directly.

|> 3. If two objects are equal with "==", does that
|>   mean their values are the same?

Yes.

| >>> 3.0 == 3
| True

Evidently the value of 3.0 is the same as the value of 3.

|> 4. Are object attributes part of an object's type
|>   or it's value, or something else?  (I think the first.)
|
| The type/class defines what attributes (generic) objects have. The value
| of the attribute lives with the instance itself (that's why fred.attribute
| and barney.attribute can be different).

I think to be strictly accurate, attributes and their values may reside
in a class instance, or in (one of) its class(es.)  In the most common
case, functions will be in the class and data will be in the instance,
but every variation on this is reasonably common.

| ... Whether you want to say the
| attribute itself is part of the class or part of the instance value is, in
| my opinion, not a useful question. The answer depends on which way you
| want to look at it.

For a given class and instance, it can be more obvious.  Take the object
returned by object(), which has attributes like '__reduce__' - all those
attributes may reasonably be considered "type" and not "value".

On the other hand, there are no constraints on how you may use these
namespaces.  You can use an instance, or a class, like you would use
a dictionary object, and then it's all value.

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to improve this simple block of code

2006-01-13 Thread Steven D'Aprano
On Wed, 11 Jan 2006 05:58:05 -0800, py wrote:

> Say I have...
> x = "132.00"
> 
> but I'd like to display it to be "132" ...dropping the trailing
> zeros...I currently try this

Mucking about with the string is one solution. Here is another:

print int(float(x))


> I do it like this because if
> x = "132.15"  ...i dont want to modify it.  But if
> x = "132.60" ...I want it to become "132.6"

Then you want:

x = float("123.60") # full precision floating point value
r = round(x, 1) # rounded to one decimal place



-- 
Steven.

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


Re: how do "real" python programmers work?

2006-01-13 Thread Dan Sommers
On Fri, 13 Jan 2006 17:09:13 +,
Tom Anderson <[EMAIL PROTECTED]> wrote:

> Ah, of course - to an true believer, emacs *is* the unix toolset.

> :)

To the true believer, unix runs under emacs.

Regards,
Dan

-- 
Dan Sommers

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


Re: Is 'everything' a refrence or isn't it?

2006-01-13 Thread Steven D'Aprano
On Thu, 12 Jan 2006 16:11:53 -0800, rurpy wrote:

> It would help if you or someone would answer these
> five questions (with something more than "yes" or "no" :-)
> 
> 1. Do all objects have values?

All objects ARE values. Some values themselves are complex objects
which in turn contain other values, e.g. if I execute:

L = [None, 1, "hello"]

I have created a name 'L' which is bound to ("has the value of") a list
with three items. The first item has the value of ("is the object") None,
the second has the value of ("is the object") 1, and the third is the
string "hello".


> 2. What is the value of object()?

These seems complicated because we are using the same word ("object") for
both the generic programming term, the class (strictly type, although the
difference is not important), and the instance itself.

Let's make it less confusing by using a case where the three things are
different:

class Foo:
pass

Foo is a class. Classes are (generic programming term) objects.
Foo() returns an instance of the Foo class. Instances are (generic
programming term) objects.

The value of Foo() is the instance. Why? int(data) returns an instance of
int, and str(data) returns an instance of str. It makes sense to say that
the value of the int instance 1 is one, the value of str instance "abc" is
the string "abc", and so forth. So we'd like to talk the same way about
more complex objects: the value of an instance is itself.

Hence the value of Foo() is the Foo instance at some particular memory
location. In this specific case, Foo() creates an object with very little
behaviour and and no distinguishing characteristics except their location
in memory, where as ints like 1 2 and 7 are easily distinguished.

Now let's return to (non-generic) object(). object is (as well as the
generic programming term) a class (strictly type, but the difference is
unimportant). object() returns an instance of class object:

>>> object()


So the value of object() is some particular instance (of type object).



> 3. If two objects are equal with "==", does that
>   mean their values are the same?

Intuitively yes, but not necessarily:

>>> 3.0 == 3
True

(We want the float 3.0 to be equal to the int 3, but we can distinguish
between them by something more than their location in memory.)

You can define a custom class:

class EqualAll:
def __eq__(self, other):
return True

but that's a pathological case.



> 4. Are object attributes part of an object's type
>   or it's value, or something else?  (I think the first.)

The type/class defines what attributes (generic) objects have. The value
of the attribute lives with the instance itself (that's why fred.attribute
and barney.attribute can be different). Whether you want to say the
attribute itself is part of the class or part of the instance value is, in
my opinion, not a useful question. The answer depends on which way you
want to look at it.



> 5. The (only?) way to get an object's value is to
>   evaluate something (a name or a "reference"(*)
>   that refers to the object.

I can't think of any other way to get at an object except by accessing
that object, or even what it would mean if there was such a way.


-- 
Steven.

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


Re: Newbie to XML-RPC: looking for advice

2006-01-13 Thread Christian Tismer
David Hirschfield wrote:



> All the above works fine...but I'm finding the following: while the 
> actual creation and pickling of the objects only takes a millisecond or 
> so, the actual time before the client call completes is a third of a 
> second or more.
> 
> So where's the slowdown? It doesn't appear to be in the 
> pickling/unpickling or object creation, so it has to be in xmlrpc 
> itself...but what can I do to improve that? It looks like xmlrpclib uses 
> xml.parsers.expat if it's available, but are there faster xml libs? 
> Looking at the xmlrpclib code itself, it seems to want to find either: 
> _xmlrpclib from the code in xmlrpclib.py:
> 
> try:
> # optional xmlrpclib accelerator.  for more information on this
> # component, contact [EMAIL PROTECTED]
> import _xmlrpclib
> FastParser = _xmlrpclib.Parser
> FastUnmarshaller = _xmlrpclib.Unmarshaller
> except (AttributeError, ImportError):
> FastParser = FastUnmarshaller = None

Can you check wether it is actually using expat?
(it can be checked by examining sys.modules, or intercepting
__import__)

I cannot think of a faster parser than expat at the moment.

...

> On the other hand, maybe the slowdown is in twisted.web.xmlrpc? What 
> does that module use to do its work? Is it using xmlrpclib underneath?
> Other xmlrpc libraries that are significantly faster that I should be 
> using instead?

Sorry that this is just a partial answer. I should have more knowledge
about twisted than I actually have.
Hinting to check the imported stuff.

cheers - chris
-- 
Christian Tismer :^)   
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: decode unicode string using 'unicode_escape' codecs

2006-01-13 Thread aurora
Cool, it works! I have also done some due diligence that the utf-8  
encoding would not introduce any Python escape accidentially. I have  
written a recipe in the Python cookbook:

Efficient character escapes decoding
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466293

wy

> Does this do what you want?
>
>  >>> u'€\\n€'
> u'\x80\\n\x80'
>  >>> len(u'€\\n€')
> 4
>  >>> u'€\\n€'.encode('utf-8').decode('string_escape').decode('utf-8')
> u'\x80\n\x80'
>  >>>  
> len(u'€\\n€'.encode('utf-8').decode('string_escape').decode('utf-8'))
> 3
>
> Basically, I convert the unicode string to bytes, escape the bytes using  
> the 'string_escape' codec, and then convert the bytes back into a  
> unicode string.
>
> HTH,
>
> STeVe

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


Re: Why can't I "from module import *" except at module level?

2006-01-13 Thread Steven D'Aprano
On Fri, 13 Jan 2006 10:17:32 -0800, Mudcat wrote:

> I have a directory structure that contains different modules that run
> depending on what the user selects. They are identical in name and
> structure, but what varies is the content of the functions. They will
> only need to be run once per execution.
...
> So if the user selects Sys1 during execution, I want to import the
> modules using "from *" and the run the content of those files.
> 
> Now the way my program is set up, it is very important that I be able
> to "from Sys1 import *" and not "import Sys1". 

Then change the way your program is set up :-)

Seriously, "from module import *" is generally a bad idea. Not always, but
generally, and in this specific instance I'm not sure that your use case
is one of those exceptions. However, be that as it may be, on to solving
your problem:

When you "import foo" or "from module import foo", the name foo is bound
in the local scope, not global. In other words, the name foo will then
only exist inside the function. So this does not work:

>>> def local_import():
... import string
...
>>> local_import()
>>> string.whitespace
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'string' is not defined


However this does work as you would expect:

>>> def func_import():
... global math
... import math
...
>>> func_import()
>>> math.sin



See http://docs.python.org/ref/import.html for more detail on what happens
when you import. Keep in mind that it states that "from module import *"
in function blocks is explicitly stated to be an error, and in Python 2.3
a warning is raised:


>>> def wild_import():
... from math import *
...
:1: SyntaxWarning: import * only allowed at module level




> The names of the
> functions inside are passed in from somewhere else and the program
> requires those function names to be globally scoped.
> 
> So I have a function that looks like this:
> 
> def importModules( type ):
> cwd = os.getcwd()
> path = cwd + "\\" + type
> sys.path.append(path)
> 
> from security import *
> 
> Obviously this is not working and I get a syntax error at runtime.

Should security be defined somewhere?

> So
> without this functionality, how do I target modules to import in other
> directories after program execution has begun?

I'd consider putting your import logic into a module of its own, at
the module-level and not inside a function. Then just call "from importer
import *" in the top level of your code and I think that should meet your
needs.



-- 
Steven.

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


Newbie to XML-RPC: looking for advice

2006-01-13 Thread David Hirschfield
I've written a server-client system using XML-RPC. The server is using 
the twisted.web.xmlrpc.XMLRPC class to handle connections and run 
requests. Clients are just using xmlrpclib.ServerProxy to run remote 
method calls.

I have a few questions about the performance of xmlrpc in general, and 
specifically about increasing the speed with which remote methods return 
their results to the client.

Right now the process of calling a remote method works as follows:

client:
generate some python objects
serialize those objects by cPickling them with cPickle.HIGHEST_PROTOCOL, 
then wrap the pickles with xmlrpclib.Binary() so the data can be sent safely
call the remote method via a ServerProxy object using the Binary object 
as the argument

server:
invoke the method and extract the pickled and Binary()'d arguments back 
into the actual objects
do some work
take result objects and cPickle them and wrap them in a Binary object as 
before
return the result to the client

client:
receive result and unpickle it into real data

All the above works fine...but I'm finding the following: while the 
actual creation and pickling of the objects only takes a millisecond or 
so, the actual time before the client call completes is a third of a 
second or more.

So where's the slowdown? It doesn't appear to be in the 
pickling/unpickling or object creation, so it has to be in xmlrpc 
itself...but what can I do to improve that? It looks like xmlrpclib uses 
xml.parsers.expat if it's available, but are there faster xml libs? 
Looking at the xmlrpclib code itself, it seems to want to find either: 
_xmlrpclib from the code in xmlrpclib.py:

try:
# optional xmlrpclib accelerator.  for more information on this
# component, contact [EMAIL PROTECTED]
import _xmlrpclib
FastParser = _xmlrpclib.Parser
FastUnmarshaller = _xmlrpclib.Unmarshaller
except (AttributeError, ImportError):
FastParser = FastUnmarshaller = None

or it tries to find sgmlop:

#
# the SGMLOP parser is about 15x faster than Python's builtin
# XML parser.  SGMLOP sources can be downloaded from:
#
# http://www.pythonware.com/products/xml/sgmlop.htm
#

Does anyone know what the performance gain from using either of those 
above libraries would be?
On the other hand, maybe the slowdown is in twisted.web.xmlrpc? What 
does that module use to do its work? Is it using xmlrpclib underneath?
Other xmlrpc libraries that are significantly faster that I should be 
using instead?

Any help in improving my xmlrpc performance would be greatly appreciated,
-Dave

-- 
Presenting:
mediocre nebula.

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


full screen gui

2006-01-13 Thread linuxnooby
Hi

I am trying to write a python script to run on windows xp that will
have a full screen gui.

The script has a function that creates a full screen (hides task bar)
top level window using tkinter.

If I close the window and call the function a 2nd time the resulting
window is full screen, but does not hide the task bar this time.

I have included code below. Any suggestions as to how i can fix this? I
am open to suggestions about other python gui

cheers David



from Tkinter import *
import time

#create invisible root window
root = Tk()
root.withdraw()

def closewindow():

top.destroy()
time.sleep(4)
create()

def create():
global top
top = Toplevel(root)


top.overrideredirect(1) #hides max min buttons
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
top.geometry("%dx%d+0+0" % (w, h))


app = Frame(top)
app.grid()

bttnhide = Button(app, text ="destroy window and create a new window
in 4 seconds", command=closewindow)
bttnhide.grid()

bttnclose = Button(app, text ="exit application",
command=root.destroy)
bttnclose.grid()


create()

root.mainloop()

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


Re: Marshal Obj is String or Binary?

2006-01-13 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote:

> Try...
>
 for i in bytes: print ord(i)
>
> or
>
 len(bytes)
>
> What you see isn't always what you have. Your database is capable of
> storing \ x 0 0 characters, but your string contains a single byte of
> value zero. When Python displays the string representation to you, it
> escapes the values so they can be displayed.

He can still store the repr of the string into the database, and then
reconstruct it with eval:

>>> bytes = "\x00\x01\x02"
>>> bytes
'\x00\x01\x02'
>>> len(bytes)
3
>>> ord(bytes[0])
0
>>> rb = repr(bytes)
>>> rb
"'\\x00\\x01\\x02'"
>>> len(rb)
14
>>> rb[0]
"'"
>>> rb[1]
'\\'
>>> rb[2]
'x'
>>> rb[3]
'0'
>>> rb[4]
'0'
>>> bytes2 = eval(rb)
>>> bytes == bytes2
True

-- 
Giovanni Bajo


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


Re: Why can't I "from module import *" except at module level?

2006-01-13 Thread Giovanni Bajo
Mudcat wrote:

> Is there any way to do this or am must I load all modules by function
> name only if it's after initialization?

Not sure. globals().update(mod.__dict__) might do the trick. Or just design a
better system and be done with it.
-- 
Giovanni Bajo


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


Re: import module and execute function at runtime

2006-01-13 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote:

> I'm trying to import a module at runtime using variables to specify
> which module, and which functions to execute. for example:
>
> mStr = "sys"
> fStr = "exit"
>
> # load mod
> mod = __import__(mStr)
> # call function
> mod.fStr()


getattr(mod, fStr)()
-- 
Giovanni Bajo


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


Re: Subclassing socket

2006-01-13 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> I would like to
> create a subclass of socket that fixes the problem.

The socket module is in a messy state right now and subclassing
sockets doesn't work for implementation-specific reasons besides the
issue you described.  Take a look at socket.py to see the situation.

See also:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/76d27388b0d286fa/c9849013e37c995b
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Marshal Obj is String or Binary?

2006-01-13 Thread casevh
Try...

>>> for i in bytes: print ord(i)

or

>>> len(bytes)

What you see isn't always what you have. Your database is capable of
storing \ x 0 0 characters, but your string contains a single byte of
value zero. When Python displays the string representation to you, it
escapes the values so they can be displayed.

casevh

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


Re: Subclassing socket

2006-01-13 Thread groups . 20 . thebriguy
I don't think this is true in all cases - for example, if the protocol
is UDP, and the packet size is less than the MTU size.  Although, I
could be wrong - I've always thought that to be the case.

I knew someone would have your response, that's why I earlier said I
didn't want to argue that.  :-)

But thanks for your comments.

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


Re: Marshal Obj is String or Binary?

2006-01-13 Thread Mike
Wait a sec. \x00 may represent a byte when unmarshaled, but as long as
marshal likes it as \x00, I think my db is capable of storing \ x 0 0
characters. What is the problem? Is it that \? I could escape that...
actually I think my django framework already does that for me.

Thanks,
Mike

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


Re: Marshal Obj is String or Binary?

2006-01-13 Thread Mike
Wait a sec. \x00 may represent a byte when unmarshaled, but as long as
marshal likes it as \x00, I think my db is capable of storing \ x 0 0
characters. What is the problem? Is it that \? I could escape that...
actually I think my django framework already does that for me.

Thanks,
Mike

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


Re: Freezing

2006-01-13 Thread James Stroud
[EMAIL PROTECTED] wrote:
> Dicts and sets require immutable keys, like tuples or frozensets

Not really...

def freeze(anobj):
   """returns a new hashable object"""
   import copy
   try: hash(anobj)
   except: pass
   else: return copy.deepcopy(anobj)
   class FrozenType(type):
 def __new__(cls, name, bases, dct):
   return type.__new__(cls, name, bases, dct)
 def __init__(cls, name, bases, dct):
   super(FrozenType, cls).__init__(name, bases, dct)
   def hashself(self): return hash(repr(self))
   name = 'Frozen_%s' % anobj.__class__.__name__
   bases = (anobj.__class__,)
   dct = dict(anobj.__class__.__dict__)
   dct['__hash__'] = hashself
   cls = FrozenType(name, bases, dct)
   return cls(anobj)

def test():
   class bob:
 def doit(self): print 1,2,3,4
   # amutable = bob()
   # amutable = [1,2,3,4]
   amutable = set((1,2,3,4))
   # amutable = {1:2, 3:4}
   frozen = freeze(amutable)
   print frozen
   print type(frozen)
   adict = {frozen:100}
   frozen2 = freeze(amutable)
   print adict[frozen2]
   print frozen is frozen2
   print frozen == frozen2

test()
-- 
http://mail.python.org/mailman/listinfo/python-list


Pythonic wrappers for SQL?

2006-01-13 Thread Kenneth McDonald
I need to do some data manipulation, and SQLite is a nice little  
product for it, except of course that I'd need to write SQL. Are  
there any good libraries out there that let one write (basic) queries  
in a Pythonic syntax, rather than directly in SQL?

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


Tomcat username and password2

2006-01-13 Thread Michael Oliver
Still trying to get python to access my local tomcat secured with the tomcat
realm

import urllib2
 

 handler = urllib2.HTTPBasicAuthHandler()
 handler.add_password(None,
 'localhost:8080/manager/html', 'root', 'root')
 
 opener = urllib2.build_opener(handler)
 urllib2.install_opener(opener)
 
 try:
 f = urllib2.urlopen( 'http://localhost:8080/manager/html' )
 except urllib2.HTTPError, e:
 if e.code == 401:
 print 'not authorized'
 elif e.code == 404:
 print 'not found'
 elif e.code == 503:
 print 'service unavailable'
 else:
 print 'unknown error: '
 else:
 print 'success'
 for line in f:
 print line,
 

[Mike Oliver>>] this returns 'not authorized' no matter what I put in for
'realm' or 'host' to the add_password() method.  I have tried None, 'tomcat'
for realm and 'localhost' and about every combination I can think of for
'host' if I go to that URL with a browser it asks for username and password
as above and that works.  I can access it with code from PHP or Java just
fine.



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


Re: flatten a level one list

2006-01-13 Thread Cyril Bazin
I added my own function to the benchmark of Robin Becker:from itertools import chaindef flatten9(x, y):   return list(chain(*izip(x, y)))Results: 
no psyco Name   10   20  100  200  500 1000
 flatten1  104.499  199.699  854.301 1673.102 4084.301 8078.504
 flatten2  111.103  204.706  944.901 1778.793 4554.701 8773.494 flatten3  174.594  310.302
 1526.308 2880.001 7332.49212373.209 flatten4  115.204  156.093  467.205  8
53.705 1920.795 2755.713 flatten5   79.894  117.803  406.504  762.892 1764.297 2663.898
 flatten6  136.399  246.596 1142.406 2243.400 5494.809 8625.221
flatten6a  163.889  279.689 1320.195 2691.817 6481.910 9879.899
flatten6b  175.881  275.111 1220.393 2440.596 5955.291 8979.106
flatten6c  160.813  272.989 1138.186 2472.591 5726.314 8415.699
flatten6d  126.004  215.292  988.603 1932.383 4734.492 7447.696
 flatten7   37.217   43.297   89.407  134.897  233.006  343.013
 flatten8   93.198  190.306 1739.597 4987.90727208.01878883.505flat
ten8a  112.915  220.299 1875.997 5491.59028395.31981628.394 flatten9   98.896  159.812
  651.288 1153.994 2980.685 3927.398Unfortunatly I can't test with psyco for the moment...Cyril 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Sudoku solver: reduction + brute force

2006-01-13 Thread znx
Hi,Funny that this just came up in Linux Format, the winner entry was:http://rightside.fissure.org/sudoku/ Won first in the "Linux Format Bounty" (
http://www.linuxformat.co.uk/bounty).

Congrats to David McLeish.-- enter shameless plug and self promotion --You can digg the page here submitted by me:http://digg.com/programming/SudokuBan_Wins_%C2%A3300
-- end --On 13 Jan 2006 16:00:45 -0800, ago <[EMAIL PROTECTED]> wrote:
Inspired by some recent readings on LinuxJournal and an ASPN recipe, Idecided to revamp my old python hack... The new code is a combinationof (2) reduction methods and brute force and it is quite faster thanthe
ASPN program. If anyone is interested I attached the code inhttp://agolb.blogspot.com/2006/01/sudoku-solver-in-python.html--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: New Python.org website ?

2006-01-13 Thread Brendan
Steve

I didn't realize Python.org was being revamped.  The site looks
awesome!
One thing I noticed:  The mac download site still references Jack
Jansen's site, which hasn't been updated since 2004 afaik.  These days
I get most of my mac python downloads from
http://pythonmac.org/packages/

Brendan

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


Sudoku solver: reduction + brute force

2006-01-13 Thread ago
Inspired by some recent readings on LinuxJournal and an ASPN recipe, I
decided to revamp my old python hack... The new code is a combination
of (2) reduction methods and brute force and it is quite faster than
the
ASPN program. If anyone is interested I attached the code in
http://agolb.blogspot.com/2006/01/sudoku-solver-in-python.html

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


Re: Subclassing socket

2006-01-13 Thread Bryan Olson
[EMAIL PROTECTED] wrote:
> To your question of why you'd ever [recv(0)].
> 
> This is very common in any network programming.  If you send a packet
> of data that has a header and payload, and the header contains the
> length (N) of the payload, then at some point you have to receive N
> bytes.  If N is zero, then you receive 0 bytes.  Of course, you CAN
> test for N == 0, that's obvious - but why would you if the underlying
> layers worked correctly?  Its just extra code to handle an special case.

We need "extra code" around recv to ensure we get exactly
N bytes; 'recv(N)' can return less. The most straightforward
code I know to read exactly N bytes never passes zero to
recv (untested):


def recvall(sock, size):
 """ Read and return exactly 'size' bytes from socket 'sock'.
 Kind of the other side of sock.sendall.
 """
 parts = []
 while size > 0:
 data = sock.recv(size)
 if not data:
  raise SomeException("Socket closed early.")
 size -= len(data)
 parts.append(data)
 return ''.join(parts)


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


Re: New Python.org website ?

2006-01-13 Thread [EMAIL PROTECTED]
JW wrote:
> On Fri, 13 Jan 2006 11:00:05 -0600, Tim Chase wrote:
>
> > http://tim.thechases.com/pythonbeta/pythonbeta.html
> >
>
> Very strange.  With FF 1.0.7, I can just get the buttons to violate the
> next column if I "View>Page Style>Large Text", but I wouldn't have noticed
> it unless Tim had pointed it out.  Tim's gifs are much worse than what
> I see. WIth ""View>Page Style>Basic Page Style", it looks really good.

Mine looks like Tim's gifs, with "Basic Page Style".

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


Re: different versions for 2.3.4 documentation

2006-01-13 Thread Martin v. Löwis
Manlio Perillo wrote:
>> It appears that the latex-* set really comes from the 2.4 branch,
>> somehow. That must be a mistake.
>>
> 
> Well, the same happens for 2.3.5...
> And I still don't have checked 2.4.x releases.

OTOH, 2.3 is not maintained anymore, so it is doubtful that
anything will be done about it.

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


httplib or urllib2 tomcat username and password

2006-01-13 Thread Michael Oliver
I am trying to write a Python client to access a Tomcat servlet using Tomcat
Realm authentication with no success.

 

I can use the httplib to connect to localhost port 8080 ok and post and get
and all that is fine, but when I try to set username and password and access
a protected part of tomcat it fails with an Unauthorized.

 

Does anyone have an example of connecting to Tomcat using the Tomcat Realm
(.i.e. tomcat-users.xml) authentication?

I have also tried urllib2 and the example in the header comments still gives
me a HTTP Error 401: Unauthorized when I try to open
http://localhost:8080/slide/



 

Thanks.


 Highly Cohesive and Loosely Coupled

Mike Oliver
CTO Alarius Systems LLC
6800 E. Lake Mead Blvd
Apt 1096
Las Vegas, NV 89156 
[EMAIL PROTECTED]
http://www.alariussystems.com/  tel: 
fax: 
mobile: (702)953-8949 
(702)974-0341
(518)378-6154   

Add me to your address book...   Want a signature like this?

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


Re: Marshal Obj is String or Binary?

2006-01-13 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Mike wrote:

> The example below shows that result of a marshaled data structure is
> nothing but a string
> 
 data = {2:'two', 3:'three'}
 import marshal
 bytes = marshal.dumps(data)
 type(bytes)
> 
 bytes
> '{i\x02\x00\x00\x00t\x03\x00\x00\x00twoi\x03\x00\x00\x00t\x05\x00\x00\x00three0'
> 
> Now, I need to store this data safely in my database as CLEAR TEXT, not
> BLOB. It seems to me that it should work just fine since it is string
> anyways. So, why does O'reilly's Python Cookbook is insisting in saving
> it as a binary file and BLOB type?
> 
> Am I missing out something?

Yes, that a string is *binary* data.  But only a subset of strings is safe
to use as `TEXT` in databases.  Do you see all those '\x??' escapes? 
'\x00' is *one* byte!  A byte with the value zero.  Something your DB
doesn't allow in a `TEXT` type.

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


Re: Newcomer question wrt variable scope/namespaces

2006-01-13 Thread Florian Daniel Otel
Gary,

First of all, many  thanks for the reply. Do I understand it correctly
that actually the rule has to be refined as pertaining  to the (so
called) "immutable" types (like e.g.  integers, tuples/strings)
whereas lists and dictionaries are "mutable" types and the said
scoping rule does not apply ?

Thanks again,

Florian

On 1/13/06, Gary Duzan <[EMAIL PROTECTED]> wrote:
>
> Right. However, assigning to a['foo'] modifies the object to which
> 'a' refers, not the 'a' variable itself. The rule is limited to the
> rebinding of variables, not the modification of the objects to which
> they refer.
>
> Gary Duzan
> Motorola CHS
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode style in win32/PythonWin

2006-01-13 Thread Neil Hodgson
Thomas Heller:

> Hm, I don't know.  I try to avoid converting questionable characters at
> all, if possible.  Then, it seems the error-mode doesn't seem to change
> anything with "mbcs" encoding.  WinXP, Python 2.4.2 on the console:
> 
 u"abc\u034adef".encode("mbcs", "ignore")
> 'abc?def'
 u"abc\u034adef".encode("mbcs", "strict")
> 'abc?def'
 u"abc\u034adef".encode("mbcs", "error")
> 'abc?def'
> 
> With "latin-1", it is different:

Yes, there are no 'ignore' or 'strict' modes for mbcs. It is a 
simple call to WideCharToMultiByte with no options set. 'ignore' may 
need two calls with different values of the default character to allow 
identification and removal of default characters as any given default 
character may also appear naturally in the output. 'strict' and 'error' 
would be easier to implement by checking both the return status and 
lpUsedDefaultChar which is set when any default character insertion is done.

The relevant code is in dist\src\Objects\unicodeobject.c.

Neil


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


Re: Why can't I "from module import *" except at module level?

2006-01-13 Thread Mudcat
Anyone?

Is there any way to do this or am must I load all modules by function
name only if it's after initialization?

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


Re: XML vs. cPickle

2006-01-13 Thread Mike
> I'd guess that XML serialisation with cElementTree is both cpu and
> memory competitive with cpickle, if not superior. Although I'm too lazy
> to fire up the timeit module right now :-)

That maybe true, but I bet Marshal is the fastest. ...right?

> Also, how quickly the relevant parsers work depends on the input, i.e.
> your data structures. Only you can take measurements with your data
> structures 

True.

> > The idea is I want to store data that can be described as XML
> can != should

I certainly 'can', I don't think I should.

> > into my
> > database as cPickle objects. Except my web framework has no support for
> > BLOB datatype yet, and I might have to go with XML.

> Or you could encode the binary pickle in a text-safe encoding such as
> base64, and store the result in a text column. Although that will
> obviously increase your processing time, both going in and out of the
> database.

base64... (used to convert arbitrary binary data to plain text), sounds
fantastic. Except, I don't think I need it when marshaling anymore
since marshaling gives you clear text anyways. (right?)

> > Ideas are appreciated,

> I'd write a few simple prototypes and take some empirical measurements.

I am doing it now. Thanks,

Mike

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


Re: Subclassing socket

2006-01-13 Thread groups . 20 . thebriguy
Correction to my last post:

It should say:

"To your question of why you'd ever recv(0):"

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


Re: XML vs. cPickle

2006-01-13 Thread Alan Kennedy
[Mike]
> I know XML is more (processor) costly than cPickle, but how bad is it?

Are you sure you know that?

I'd guess that XML serialisation with cElementTree is both cpu and 
memory competitive with cpickle, if not superior. Although I'm too lazy 
to fire up the timeit module right now :-)

Also, how quickly the relevant parsers work depends on the input, i.e. 
your data structures. Only you can take measurements with your data 
structures 

> The idea is I want to store data that can be described as XML 

can != should

> into my
> database as cPickle objects. Except my web framework has no support for
> BLOB datatype yet, and I might have to go with XML.

Or you could encode the binary pickle in a text-safe encoding such as 
base64, and store the result in a text column. Although that will 
obviously increase your processing time, both going in and out of the 
database.

> Ideas are appreciated,

I'd write a few simple prototypes and take some empirical measurements.

HTH,

-- 
alan kennedy
--
email alan:  http://xhaus.com/contact/alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subclassing socket

2006-01-13 Thread groups . 20 . thebriguy
Steve,

To your question of why you'd ever receive value:

This is very common in any network programming.  If you send a packet
of data that has a header and payload, and the header contains the
length (N) of the payload, then at some point you have to receive N
bytes.  If N is zero, then you receive 0 bytes.  Of course, you CAN
test for N == 0, that's obvious - but why would you if the underlying
layers worked correctly?  Its just extra code to handle an special case.

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


Re: jython base64.urlsafe_b64xxx

2006-01-13 Thread Alan Kennedy
py wrote:
> anyone know how to do perform the equivalent base64.urlsafe_b64encode
> and base64.urlsafe_b64decode functions that Python has but in jython?
> Jython comes with a base64 module but it does not have the urlsafe
> functions.  Tried copying the pythhon base64.py to replace the Jython
> one, and although it did perform the encode/decode it didnt seem to be
> correctly decoded.

You're probably better off using a java library for the task. There are 
plenty to choose from, but most embedded as utility classes in bigger 
packages. Here's a public domain one for example

http://dev.i2p.net/cgi-bin/cvsweb.cgi/i2p/core/java/src/net/i2p/data/Base64.java?f=H

With javadoc at

http://dev.i2p.net/javadoc/net/i2p/data/Base64.html

Seems to do what you want.

HTH,

-- 
alan kennedy
--
email alan:  http://xhaus.com/contact/alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Weekly Python Patch/Bug Summary

2006-01-13 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  384 open ( +2) /  3016 closed (+13) /  3400 total (+15)
Bugs:  909 open ( +6) /  5500 closed (+21) /  6409 total (+27)
RFE :  208 open ( +5) /   196 closed ( +1) /   404 total ( +6)

New / Reopened Patches
__

add support for thread function result storage  (2006-01-02)
   http://python.org/sf/1395552  opened by  tosi-in

Nit: incorrect subsection LaTeX label in cookielib docs  (2006-01-03)
CLOSED http://python.org/sf/1395715  opened by  John J Lee

Further .vcproj cleanups  (2006-01-03)
   http://python.org/sf/1396093  opened by  Adal Chiriliuc

FreeBSD is system scope threads capable  (2006-01-04)
   http://python.org/sf/1396919  opened by  Valts

Fix dict and set docs, re: immutability  (2006-01-05)
   http://python.org/sf/1397711  opened by  Collin Winter

dictnotes.txt  (2006-01-05)
   http://python.org/sf/1397848  opened by  Jim Jewett

File-iteration and read* method protection  (2006-01-05)
   http://python.org/sf/1397960  opened by  Thomas Wouters

ConfigParser to save with order  (2006-01-07)
   http://python.org/sf/1399309  opened by  Facundo Batista

enhance unittest to define tests that *should* fail  (2006-01-08)
   http://python.org/sf/1399935  opened by  Neal Norwitz

unicode formats floats according to locale  (2006-01-09)
CLOSED http://python.org/sf/1400181  opened by  Neal Norwitz

Need warning that `dl` module can cause segfaults/crashes  (2006-01-10)
   http://python.org/sf/1402224  opened by  Tim Delaney

Fix dictionary subclass semantics when used as global dicts.  (2006-01-10)
   http://python.org/sf/1402289  opened by  crutcher

Suggested patch for #1403410  (2006-01-13)
CLOSED http://python.org/sf/1404357  opened by  Peter van Kampen

Patch for #1394565  (2006-01-13)
CLOSED http://python.org/sf/1404374  opened by  Peter van Kampen

Patches Closed
__

dict.merge  (2005-12-27)
   http://python.org/sf/1391204  closed by  gvanrossum

cookielib LWPCookieJar and MozillaCookieJar exceptions  (2005-02-06)
   http://python.org/sf/1117398  closed by  nnorwitz

Nit: incorrect subsection LaTeX label in cookielib docs  (2006-01-03)
   http://python.org/sf/1395715  closed by  birkenfeld

mingw compile  (2004-10-25)
   http://python.org/sf/1053879  closed by  loewis

skip winsound for Windows/IA64 build  (2005-03-09)
   http://python.org/sf/1160169  closed by  loewis

PCbuild vcproj project files need a cleanup  (2005-09-29)
   http://python.org/sf/1307806  closed by  loewis

look in libbsd.a also for openpty and forkpty  (2004-01-22)
   http://python.org/sf/881820  closed by  loewis

UTF-8-Sig codec  (2005-04-05)
   http://python.org/sf/1177307  closed by  loewis

fix for distutils "upload" command  (2005-09-23)
   http://python.org/sf/1299675  closed by  loewis

unicode formats floats according to locale  (2006-01-09)
   http://python.org/sf/1400181  closed by  nnorwitz

Python crashes in pyexpat.c if malformed XML is parsed  (2005-03-31)
   http://python.org/sf/1173998  closed by  nnorwitz

Suggested patch for #1403410  (2006-01-13)
   http://python.org/sf/1404357  closed by  birkenfeld

Patch for #1394565  (2006-01-13)
   http://python.org/sf/1404374  closed by  birkenfeld

New / Reopened Bugs
___

errata  (2006-01-01)
CLOSED http://python.org/sf/1394868  opened by  Chad Whitacre

os.remove should behave like rm, not unlink  (2006-01-02)
CLOSED http://python.org/sf/1395442  opened by  Chad Whitacre

Please document pyc format guarantees  (2006-01-02)
CLOSED http://python.org/sf/1395511  opened by  Joe Wreschnig

module os, very small doc inconsistency  (2006-01-02)
CLOSED http://python.org/sf/1395597  opened by  tiissa

Can't build Python on POSIX w/o $HOME  (2004-05-24)
   http://python.org/sf/959576  reopened by  birkenfeld

make fails trying to run svnversion  (2006-01-03)
CLOSED http://python.org/sf/1395926  opened by  M.-A. Lemburg

TimedRotatingFileHandler at midnight rolls over at 01:00  (2006-01-03)
   http://python.org/sf/1396030  opened by  Andrew Waters

TimedRotatingFileHandler does not recover from open error  (2006-01-03)
   http://python.org/sf/1396040  opened by  Andrew Waters

KeyboardInterrupt prevents return to Windows console  (2006-01-03)
   http://python.org/sf/1396258  opened by  Vernon Cole

file.tell() returns illegal value on Windows  (2006-01-03)
   http://python.org/sf/1396471  opened by  Tom Goddard

urlparse is confused by /  (2006-01-04)
   http://python.org/sf/1396543  opened by  John Hansen

TimedRotatingFileHandler midnight rollover time increases  (2006-01-04)
   http://python.org/sf/1396622  opened by  Andrew Waters

bsddb.__init__ causes error  (2006-01-04)
   http://python.org/sf/1396678  opened by  Fabian_M

%ehrntDRT support for time.strptime   (2006-01-04)
   http://python.org/sf/1396946  opened by  Johan Dahlin

no han

Re: COM automation, Internet Explorer, DocumentComplete event

2006-01-13 Thread [EMAIL PROTECTED]
R. Bell,

If you could sent me those URLS that are not working with PAMIE it
would be great.
It should be a quick fix. I haven't had any of the Users report this as
of yet.

I notice your writing an app that automates IE also, best of luck with
it!!


Rob

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


Re: How to get Windows system information?

2006-01-13 Thread Paul Watson
Martin P. Hellwig wrote:
> [EMAIL PROTECTED] wrote:
> 
>> Does anybody know how to get the:
>>
>>  Free hard disk space
>>  Amount of CPU load
>>  and Amount of RAM used
>>
>> on windows? I am making an artificial intelligence program that has
>> "moods" based on how much stress the system is under, based on these
>> parameters. I think it could possibly be done via COM. I am not looking
>> for a cross-platform solution- just something that will work on
>> Windows. Thank you for your help!
>>
> 
> Have a look at WMI* , it's specifically designed to getthat kind of 
> stuff, there is also a python layer for WMI**.
> 
> * http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_reference.asp
> ** http://tgolden.sc.sabren.com/python/wmi.html
> 
> hth

WMI sounds like the right way to go.  I recently had to whack a little 
WHS because I could find no Python interface without downloading 
additional modules.  Do you think Tim Golden would submit it for 
inclusion with the standard Python build?  If so, would that require 
pywin32 to be in the build or could Tim do this through ctypes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Marshal Obj is String or Binary?

2006-01-13 Thread Mike
Hi,

The example below shows that result of a marshaled data structure is
nothing but a string

>>> data = {2:'two', 3:'three'}
>>> import marshal
>>> bytes = marshal.dumps(data)
>>> type(bytes)

>>> bytes
'{i\x02\x00\x00\x00t\x03\x00\x00\x00twoi\x03\x00\x00\x00t\x05\x00\x00\x00three0'

Now, I need to store this data safely in my database as CLEAR TEXT, not
BLOB. It seems to me that it should work just fine since it is string
anyways. So, why does O'reilly's Python Cookbook is insisting in saving
it as a binary file and BLOB type?

Am I missing out something?

Thanks,
Mike

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


Re: Converting a string to an array?

2006-01-13 Thread Tim Peters
[Bryan Olson]
> ...
> For sorting, we had the procedure 'sort', then added the pure
> function 'sorted'. We had a 'reverse' procedure, and wisely
> added the 'reversed' function.
>
> Hmmm... what we could we possible do about 'shuffle'?

'permuted' is the obvious answer, but that would leave us open to more
charges of hifalutin elitism, so the user-friendly and slightly risque
'jiggled' it is.

sorry-it-can't-be-'shuffled'-we-ran-out-of-'f's-ly y'rs  - tim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How login & download file from remote web site? Passwords a problem?

2006-01-13 Thread [EMAIL PROTECTED]

# Quick and dirty script example

from win32com.client import DispatchEx
import time

def wait(ie):

while ie.Busy:
time.sleep(0.1)
while ie.Document.ReadyState != 'complete':

time.sleep(0.1)

#instaniate a new ie object so you can call it's methods and
properties...etc..
ie = DispatchEx('InternetExplorer.Application')

# You need to make it Visible
ie.Visible = 1

# Navigate to the page
ie.Navigate('mail.yahoo.com')

wait(ie) # important to wait for the doc to load


# Enter User info and submit the form since it uses submit
# If the button had a name attribute
# You could also use  ie.Document.login_form.buttonName.Click

# ieObject.Document.FormName.TexboxName.value ="??"
ie.Document.login_form.username.value="MyName"
ie.Document.login_form.passwd.value="Mypasswd"
ie.Document.login_form.submit()


Enjoy
Rob M
http://pamie.sourceforge.net

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


Re: Spanish Translation of any python Book?

2006-01-13 Thread Olaf \"El Blanco\"
:)

So Sorry!


"gene tani" <[EMAIL PROTECTED]> escribió en el mensaje 
news:[EMAIL PROTECTED]
>
> Olaf "El Blanco" wrote:
>> Maybe there is someone that speak spanish. I need the best spanish book 
>> for
>> learning python.
>>
>
> you should learn Chinese, Korean and Russian so you can read this many
> times
> http://diveintopython.org/#languages
> 


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

Re: Is 'everything' a refrence or isn't it?

2006-01-13 Thread Bryan Olson
Sybren Stuvel wrote:
> Mike Meyer enlightened us with:
> 
>>>I think type 'object' has only one value, so that's it.
>>
>>In that case, they should all be equal, right?
>>
>>
>object() == object()
>>
>>False
> 
> 
> You compare instances of the type 'object'. They both have one value:
> 
> 
object()
> 
> 
> 
object()
> 
> 
> 
> So the claim "type 'object' has only one value" is true. It's just not
> the same value for all instances.

No, that's not the issue. A type has a set of values (and a set of
operations); each instance takes one value from the type's set. I
think (I'm not sure) that object's set of values has only one element.

In Python, types are extensible, so by 'instance', I mean a direct
instance, not an instance of a class that inherits from 'object'.


Would it make sense to have a type with an empty set of values?
Sure. Such a type could never have a direct instance. Perhaps
'object' should be an abstract base class.


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


Re: return values of os.system() on win32

2006-01-13 Thread Trent Mick
[rbt wrote]
> This is a corner case. I'm trying to detect if the py script is running 
> on a 'special' version of windows. I can't go into the details about 
> what makes it unique. Python installs and runs, but the windows API 
> isn't as complete as a normal Windows install... among other things, it 
> doesn't have a winver.exe file, or if it does, it's crippled... this 
> causes os.system('winver') to return a 1... while it returns 0 on 
> Windows XP, etc.

If you just want to check if winver.exe exists you could just try
os.path.exists("path\\to\\winver.exe") if you know where to expect it
(likely "C:\Windows\system32") or you could use which.py:

>>> import which
>>> which.which("winver.exe")
'C:\\WINDOWS\\system32\\winver.exe'
>>> which.which("nothere")
Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\which.py", line 248, in which
raise WhichError("Could not find '%s' on the path." % command)
which.WhichError: Could not find 'nothere' on the path.

http://trentm.com/projects/which/

Trent

-- 
Trent Mick
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: return values of os.system() on win32

2006-01-13 Thread rbt
Paul Watson wrote:
> rbt wrote:
> 
>> Is it safe to say that any value returned by os.system() other than 0 
>> is an error?
>>
>> if os.system('winver') != 0:
>> print "Winver failed!"
>> else:
>> print "Winver Worked."
>>
>> Thanks!
> 
> 
> What are you really seeking to do?

This is a corner case. I'm trying to detect if the py script is running 
on a 'special' version of windows. I can't go into the details about 
what makes it unique. Python installs and runs, but the windows API 
isn't as complete as a normal Windows install... among other things, it 
doesn't have a winver.exe file, or if it does, it's crippled... this 
causes os.system('winver') to return a 1... while it returns 0 on 
Windows XP, etc.

> Are you wanting to detect if your 
> code is running on a Windows machine?  Are you wanting to know the 
> version number of Windows?  Why not use popen2() and see the output?


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


Re: New Python.org website ?

2006-01-13 Thread [EMAIL PROTECTED]
Tim Chase wrote:
> > Looks fine here on Firefox 1.5 and Konqueror 3.4.3.
>
> Just in case anybody is interested, I've posted screenshots of
> how it comes out here (minus the ugly colors when 24-bit images
> are reduced to 256-color GIF files) in both MozSuite and FF:

FWIW, I'm seeing the same overlap as Tim, in Firefox 1.5 and Konquerer
3.2.2.

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


Re: New Python.org website ?

2006-01-13 Thread JW
On Fri, 13 Jan 2006 11:00:05 -0600, Tim Chase wrote:

> http://tim.thechases.com/pythonbeta/pythonbeta.html
> 

Very strange.  With FF 1.0.7, I can just get the buttons to violate the
next column if I "View>Page Style>Large Text", but I wouldn't have noticed
it unless Tim had pointed it out.  Tim's gifs are much worse than what
I see. WIth ""View>Page Style>Basic Page Style", it looks really good.

Jim Wilson
Gainesvlle, FL
-- 
http://mail.python.org/mailman/listinfo/python-list


Extend&Embed : how to pass user-defined object to scripts

2006-01-13 Thread Oscar
/// Foo.cpp
class CFoo
{

};


# Test.py
#i use foo.cpp build the 'foo' module
import foo

#param : CFoo
def bar(o):
 #call the object o's member functions


at last,i call the bar() function in my main.cpp.
///main.cpp
CFoo foo;
/// how to pass foo to the function 'bar'


now, i use the binder 'boost::python'.

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


Re: import module and execute function at runtime

2006-01-13 Thread iapain
Hi,
if you want to import module dynamically, you can use __import__ ..
always remember modules are objects  ..

mStr="sys"
mod=__import__(mStr)
# Now u can use mod.version .. but cant specify the attribute using
other variable, like u did
mod.version

should read it
http://diveintopython.org/functional_programming/dynamic_import.html

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


Re: string to datetime parser?

2006-01-13 Thread M.-A. Lemburg
beza1e1 wrote:
> Is there a library which can parse strings and output a datetime
> object? It should be as magical as possible and allow things like:
> 12:30
> tomorrow
> 10.10.2005
> 02-28-00
> 28/03/95
> 1995-03-28
> 1996.Feb.29 (Thu) 16:45:23.7
> 
> Is there anything like that out there? My Google can't find anything
> useful ...

http://www.egenix.com/files/python/mxDateTime.html

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 13 2006)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Weak references (- E04 - Leadership! Google, Guido van Rossum, PSF)

2006-01-13 Thread M.-A. Lemburg
Duncan Booth wrote:
> Alex Martelli wrote:
> 
>> It IS true that in Python you cannot set arbitrary attributes on
>> arbitrary objects.  The workaround is to use a dict, indexed by the id
>> of the object you want to "set arbitrary attributes on"; this has the
>> helpful consequence that separate namespaces are used, so your arbitrary
>> setting of metadata cannot interfere with the `true' attributes of the
>> object in question.
>>
> That's a horrible suggestion (using id's, not the bit about separate 
> namespaces). If you use the id then attributes will persist beyond the 
> lifetime of the object and may suddenly reappear on other unrelated objects 
> later.
> 
> A better suggestion here would be to use weak references. Unfortunately, 
> not every Python object can be the target of a weak reference, so there is 
> a limitation here preventing a useful implementation for many builtin 
> types.

mxProxy could help with that:

   http://www.egenix.com/files/python/mxProxy.html

It allows creating weak references to any Python object
(among other things like protecting object access).

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 13 2006)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! 
-- 
http://mail.python.org/mailman/listinfo/python-list


XML vs. cPickle

2006-01-13 Thread Mike
I know XML is more (processor) costly than cPickle, but how bad is it?
The idea is I want to store data that can be described as XML into my
database as cPickle objects. Except my web framework has no support for
BLOB datatype yet, and I might have to go with XML.

Ideas are appreciated,

Thanks,
Mike

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


timeout a process

2006-01-13 Thread iapain
Hello,
I am trying to build and infinite loop handler in python 2.4 on windows
platform. The problem is that i want to create a process and forcely
kill/timeout after 2 sec to handle infinite loop in a gcc complied exe
on cygwin. something like below

os.system("mycpp.exe") # this exe is compiled with g++ and having an
infinite loop

I wish to terminate this after 2 sec. I've tried Watchdog and deamon
thread.. but nothing seem to work here.

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


Re: Creating shortcuts?

2006-01-13 Thread Paul Watson
Ron Griswold wrote:
> Hi Dennis,
> 
> Yes, I am equating a unix soft link to a windows shortcut. Both act as
> links to a file or directory. 
> 
> I have found that windows shortcuts do appear in linux dir listings with
> a .lnk extension, however the file is meaningless to linux. On the other
> hand, a linux soft link does not appear in a windows directory listing,
> not that I really want it to.
> 
> As for os.link and os.symlink, these appear to be unix specific. It
> would be nice if os.symlink, when run on windows, would create a
> shortcut.
> 
> Thanks,
> 
> Ron Griswold
> Character TD
> R!OT Pictures
> [EMAIL PROTECTED]
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Dennis Lee Bieber
> Sent: Friday, January 13, 2006 12:26 AM
> To: python-list@python.org
> Subject: Re: Creating shortcuts?
> 
> On Thu, 12 Jan 2006 22:53:42 -0800, "Ron Griswold"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
> 
>>Is it possible to create a shortcut to a file in Python? I need to do
>>this in both win32 and OSX. I've already got it covered in Linux by
>>system(ln...).
>>
> 
> 
>   Are you equating a Windows "shortcut" to a Unix "link"? Soft
> link,
> at that, I suspect -- as a hard link can be done using os.link(), though
> a soft link can be done with os.symlink(). Lets see if my terminology is
> correct: a "hard link" is an additional directory entry pointing to a
> pre-existing file (with a count of how many entries exist for the file);
> a "soft link" is basically a special file that contains the full path to
> the actual file (and hence, could cross file system boundaries).
> 
>   I don't think Windows "shortcuts" are the same thing (as my
> memory
> struggles, I have vague inklings that NTFS actually supports Unix-like
> links, but practically nothing uses them). At best, they may be similar
> to a soft link, being a particular type of file, being that they are
> files with a ".lnk" extension (and hidden by the OS normally)

UNIX links and Windows .lnk files are not the same thing.

Links on UNIX, both soft and hard, are known by the filesystem.

.lnk files on Windows are recognized by the OS as indicating that a 
different file is to be used.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: return values of os.system() on win32

2006-01-13 Thread Paul Watson
rbt wrote:
> Is it safe to say that any value returned by os.system() other than 0 is 
> an error?
> 
> if os.system('winver') != 0:
> print "Winver failed!"
> else:
> print "Winver Worked."
> 
> Thanks!

What are you really seeking to do?  Are you wanting to detect if your 
code is running on a Windows machine?  Are you wanting to know the 
version number of Windows?  Why not use popen2() and see the output?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML Writer in wxPython

2006-01-13 Thread Peter Decker
On 1/12/06, Marco Meoni <[EMAIL PROTECTED]> wrote:
> I'm building a GUI of a network manager that send its commands in xml files.
> I would can write xml files from GUI (that is in wxPython). Have you
> understand from my "spaghetti" english?

Yes, your English is fine. Much better than my Italian!  :)

Sounds like you could use the xml.dom.minidom module
(http://www.python.org/doc/current/lib/module-xml.dom.minidom.html).
On that page they have information for creating new XML documents.

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


import module and execute function at runtime

2006-01-13 Thread denny
Hello, rookie here.

I'm trying to import a module at runtime using variables to specify
which module, and which functions to execute. for example:

mStr = "sys"
fStr = "exit"

# load mod
mod = __import__(mStr)
# call function
mod.fStr()

can i do this sort of thing? other suggestions?

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


Re: Python Desktop Framework?

2006-01-13 Thread Peter Decker
On 13 Jan 2006 10:06:56 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:

> Is there or should there be a Python Desktop Framework? It would be
> great to have something like Turbogears for desktop apps.

You might want to look at Dabo (http://dabodev.com). They are the far
and away the best framework out there for desktop apps.

> Today I was thinking about actually putting this together. Any
> thoughts?

You would do the community a much greater service if you were to
contribute to Dabo instead.

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XEmacs python-mode question

2006-01-13 Thread Thomas Heller
[EMAIL PROTECTED] writes:

> Thomas> I'm trying to customize the python interpreter that is used to
> Thomas> execute my scripts from within WinXP, XEmacs, python-mode
> Thomas> version $Revision4.70$, but cannot get it to work.
>
> Thomas> The only thing that works is M-x customize-group python, and
> Thomas> change the value of 'Python Command'.  However, this changes the
> Thomas> interpreter for all buffers, but I want different buffers use
> Thomas> different interpreters.  Is that possible?
>
> Thomas,
>
> py-python-command is not buffer local.  Try executing
>
> (make-variable-buffer-local 'py-python-command)
>
> and let me know if that allows your Local Variables setting to work.

No, it doesn't work.  The only ugly workaround that I found was to use
py-toggle-shells, and create a jython.bat file which invokes the other
interpreter.

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


Re: flatten a level one list

2006-01-13 Thread Bengt Richter
On Fri, 13 Jan 2006 07:48:39 -0800, [EMAIL PROTECTED] (Alex Martelli) wrote:

>Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
>   ...
>> I agree with Guido about the special case, but I disagree about the
>> error message.  Not being able to use sum(L,"") reduces the
>> orthogonality of sum for no good reason I could see.
>
I agree.

>Having sum(L,'') work but be O(N squared) would be an "attractive
Are you saying ''.join is O(N squared)? Or that sum would not be
allowed to used the same/equivalent implementation algorithms if it were allowed
to work on strings?

>nuisance" within the meaning of the law; it's bad enough that sum(L,[])
>etc are that way, but at least beginners want to concatenate lists (or
>tuples, arrays, etc) much less often than they want to concatenate
>strings.  sum is meant to work on _numbers_ -- the reason it takes that
If sum is meant to work on _numbers_, why not call it numsum, to suggest
the restriction? ISTM the usual assumption in python is non-restrictive duck 
typing,
and the expectation would be no more restriction than in reduce(operator.add, 
L, init_val).

>second optional parameter is essentially to be able to specify the
>``type'' of numbers.  In retrospect it might have been better to have a
>single argument (or interpret multiple ones like min or max do, maybe),
>forcing the starting value to be integer 0.
>
So it was an accident that user types are permitted?

 >>> class C:
 ... def __getattr__(self, attr): print attr;raise AttributeError
 ...
 >>> sum([C(),C()])
 __coerce__
 __radd__
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: unsupported operand type(s) for +: 'int' and 'instance'
 >>> sum([C(),C()],C())
 __coerce__
 __add__
 __coerce__
 __radd__
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: unsupported operand type(s) for +: 'instance' and 'instance'

Yet user subclassing of str does not yield an acceptable user type?

 >>> S = type('S',(str,),{})
 >>> sum(S(i) for i in xrange(5))
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: unsupported operand type(s) for +: 'int' and 'S'
 >>> sum(S(i) for i in xrange(5), S('start:'))
   File "", line 1
 SyntaxError: invalid syntax
 >>> sum((S(i) for i in xrange(5)), S('start:'))
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: sum() can't sum strings [use ''.join(seq) instead]

Although, notice

 >>> class SI(str):
 ... def __add__(self, other): return SI(str.__add__(self, str(other)))
 ... __radd__ = __add__
 ...
 >>> sum((SI(i) for i in xrange(5)))
 '001234'

But:
 >>> sum((SI(i) for i in xrange(5)), SI('start:'))
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: sum() can't sum strings [use ''.join(seq) instead]
vs
 >>> reduce(operator.__add__, (SI(i) for i in xrange(5)), SI('start:'))
 'start:01234'


Which seems to boil down to incomplete restrictions on duck typing.
Maybe Guido will want to complete it, but ISTM your original implementation
delegating string addition implementation to ''.join was reasonable.

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


Re: Remote Function Call

2006-01-13 Thread Mike
Thanks Everyone for your input.

Mike

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


Re: another docs problem - imp

2006-01-13 Thread Kent Johnson
Fredrik Lundh wrote:
> Kent Johnson wrote:
>>Is there such a list? I have contributed many doc patches and if such
>>glory is mine I would like to know it!
> 
> unfortunately, your name don't seem to be mentioned in the Doc version
> history either:
> 
> do you have more details (a reference to a page you've contributed to should
> be enough).
> 
> or could it be that your submissions are still sitting in the SF tracker ?

There are twelve closed doc bugs in SF tracker that I submitted 
(username kjohnson); I think most of these were accepted. They're all 
pretty minor but certainly as big as the change this thread is 
discussing. I also recently helped Andrew Kuchling rewrite the 
BeginnersGuide in the Wiki.

A note to rurpy and anyone else with a complaint about the docs: it 
really is very easy to suggest a change in SF. In my experience most 
suggestions are accepted very quickly. It's an easy way to help make 
Python better. Definitely easier than fighting on c.l.py about whether 
the docs are confusing.

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


Why can't I "from module import *" except at module level?

2006-01-13 Thread Mudcat
I have a directory structure that contains different modules that run
depending on what the user selects. They are identical in name and
structure, but what varies is the content of the functions. They will
only need to be run once per execution.

Example (directory level):
Sys1:
  A
  B
  C
Sys2:
  A
  B
  C
Sys3:
  A
  B
  C
Sys4:
  A
  B
  C

So if the user selects Sys1 during execution, I want to import the
modules using "from *" and the run the content of those files.

Now the way my program is set up, it is very important that I be able
to "from Sys1 import *" and not "import Sys1". The names of the
functions inside are passed in from somewhere else and the program
requires those function names to be globally scoped.

So I have a function that looks like this:

def importModules( type ):
cwd = os.getcwd()
path = cwd + "\\" + type
sys.path.append(path)

from security import *

Obviously this is not working and I get a syntax error at runtime. So
without this functionality, how do I target modules to import in other
directories after program execution has begun?

Thanks

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


RE: Creating shortcuts?

2006-01-13 Thread Ron Griswold
Hi Roger,

Thank you, I will look into this.

Ron Griswold
Character TD
R!OT Pictures
[EMAIL PROTECTED]



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Of Roger Upole
Sent: Friday, January 13, 2006 4:59 AM
To: python-list@python.org
Subject: Re: Creating shortcuts?

On Windows, Pywin32 allows you to create and manipulate
shortcuts.  See \win32comext\shell\test\link.py for a small
class that wraps the required interfaces.
hth
Roger

"Ron Griswold" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi Folks,

Is it possible to create a shortcut to a file in Python? I need to do
this in both win32 and OSX. I've already got it covered in Linux by
system(ln...).

Thanks,

Ron Griswold
Character TD
R!OT Pictures
[EMAIL PROTECTED]



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

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


RE: Creating shortcuts?

2006-01-13 Thread Ron Griswold
Hi Dennis,

Yes, I am equating a unix soft link to a windows shortcut. Both act as
links to a file or directory. 

I have found that windows shortcuts do appear in linux dir listings with
a .lnk extension, however the file is meaningless to linux. On the other
hand, a linux soft link does not appear in a windows directory listing,
not that I really want it to.

As for os.link and os.symlink, these appear to be unix specific. It
would be nice if os.symlink, when run on windows, would create a
shortcut.

Thanks,

Ron Griswold
Character TD
R!OT Pictures
[EMAIL PROTECTED]


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Of Dennis Lee Bieber
Sent: Friday, January 13, 2006 12:26 AM
To: python-list@python.org
Subject: Re: Creating shortcuts?

On Thu, 12 Jan 2006 22:53:42 -0800, "Ron Griswold"
<[EMAIL PROTECTED]> declaimed the following in comp.lang.python:

> 
> Is it possible to create a shortcut to a file in Python? I need to do
> this in both win32 and OSX. I've already got it covered in Linux by
> system(ln...).
>

Are you equating a Windows "shortcut" to a Unix "link"? Soft
link,
at that, I suspect -- as a hard link can be done using os.link(), though
a soft link can be done with os.symlink(). Lets see if my terminology is
correct: a "hard link" is an additional directory entry pointing to a
pre-existing file (with a count of how many entries exist for the file);
a "soft link" is basically a special file that contains the full path to
the actual file (and hence, could cross file system boundaries).

I don't think Windows "shortcuts" are the same thing (as my
memory
struggles, I have vague inklings that NTFS actually supports Unix-like
links, but practically nothing uses them). At best, they may be similar
to a soft link, being a particular type of file, being that they are
files with a ".lnk" extension (and hidden by the OS normally)

 
-- 
 > == <
 >   [EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >  [EMAIL PROTECTED] |   Bestiaria Support Staff   <
 > == <
 >   Home Page: <
 >Overflow Page: <
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Re: Is 'everything' a refrence or isn't it?

2006-01-13 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:
...
> I think the difference in our perspectives is that you already
> *know* what a value is, not necessarily in a way that allows
> you to write a defintion, but certainly in a way that allows
> to work effectively with them.
> 
> As a Python beginner, I do not know, and I need something
> more than "it is something an object has".  I do NOT need
> eiher some formal specifcation, nor a metaphysical discussion
> that relates it to platonic ideals and other such concepts.
> 
> Surely there is some middle ground?

Well, see what you make of Steve Holden and Bengt Richter's
answers, and let us know if 1) it answers your question and
2) you can distill your new insight into a dozen words or so
for the language reference.

I'm still inclined to dispute the premise.  Your example
where you demonstrate the problem:

> I wanted to write a function that would dump the contents
> of any object (value and attributes), and got rather confused
> about values, types, repr's, etc.

In the light of the answers you're getting, you may be thinking
that this isn't a simple problem.  It isn't, in principle, it's
a huge bucket of worms.  But if you have a practical focus that
comes out of your actual application for this function, it could
be pretty trivial.  Your choice, and likewise for the notion of
value in general.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Desktop Framework?

2006-01-13 Thread [EMAIL PROTECTED]
Is there or should there be a Python Desktop Framework? It would be
great to have something like Turbogears for desktop apps.

I blogged a fews days ago about a Python Desktop Framework or (dare I
say it) Wizard:

   1. Quick to build an application - Minimal Input e.g. App Name and
Type
   2. Choice of GUI - TCL, WX, .Net WinForms, Wax etc
   3. Load/Save of Config - Native storage all worked out e.g home for
Unix, D and S for Windows
   4. Template Help File
   5. Standard Menus e.g File Help
   6. Dynamic Options Dlg based on Config file
   7. Py2exe etc native compilation script
   8. Installer script e.g Inno, Wix, Egg
   9. Basic Unit Tests
  10. GUI Tests e.g AutoIT

Today I was thinking about actually putting this together. Any
thoughts?

Thanks,
Davy Mitchell

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


Re: XEmacs python-mode question

2006-01-13 Thread skip

Thomas> I'm trying to customize the python interpreter that is used to
Thomas> execute my scripts from within WinXP, XEmacs, python-mode
Thomas> version $Revision4.70$, but cannot get it to work.

Thomas> The only thing that works is M-x customize-group python, and
Thomas> change the value of 'Python Command'.  However, this changes the
Thomas> interpreter for all buffers, but I want different buffers use
Thomas> different interpreters.  Is that possible?

Thomas,

py-python-command is not buffer local.  Try executing

(make-variable-buffer-local 'py-python-command)

and let me know if that allows your Local Variables setting to work.

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


Re: Hijacking threads

2006-01-13 Thread gene tani

Peter Hansen wrote:
> gene tani wrote:
> > Roy Smith wrote:
> >>Thanks for posting that URL; I hadn't seen the list before.
> [...]
> >
> > pls don't hijack threads
>
> Um, he didn't "hijack" it, he follow a tangent to the discussion and
> even changed the Subject line in a very appropriate manner, both of are
> completely acceptable netiquette and long-standing Usenet practices.
>
> (Rather like I'm doing here.)

Sorry, I was trying to be helpful.  One thing, i think it helps to
glance over rejected PEPs every once in a while to reinforce what's not
there
http://www.python.org/peps/

> 
> -Peter

Gene

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


Re: return values of os.system() on win32

2006-01-13 Thread rbt
Peter Hansen wrote:
> rbt wrote:
> 
>> Is it safe to say that any value returned by os.system() other than 0 
>> is an error?
>>
>> if os.system('winver') != 0:
>>  print "Winver failed!"
>> else:
>>  print "Winver Worked."
> 
> 
> According to the docs, assuming that *in general* would be an error, but 
> it's likely that for the sorts of cases you are talking about, it's true.
> 
> Ultimately, since the return code is generally under the control of the 
> application you're calling, it's absolutely possible (likely) that there 
> are many programs which do not work as you assume above, and probably a 
> large number which don't ever explicitly set the return value at all...
> 
> -Peter
> 

OK, thanks guys. That's helpful... this is more of an MS issue than a 
Python issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is there no post-pre increment operator in python

2006-01-13 Thread Fredrik Lundh
"gene tani" wrote:

> pls don't hijack threads

this is usenet, not gene tani's web board.

if you have trouble dealing with subthreads, get a better news reader.





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


Re: Newcomer question wrt variable scope/namespaces

2006-01-13 Thread Gary Duzan
Florian Daniel Otel wrote:
> 
> My problem: I just discovered (by mistake) that attempting to assign a
> value to a non-local dictionary/list member does NOT generate an "
> UnboundLocalError" exception and the assignment is preserved upon
> exiting that scope (i.e. function). This would "violate" the python
> scoping rules where a variable in a global scope can only be
> referenced to (and not assigned to)  -- unless declared as "global".

Right. However, assigning to a['foo'] modifies the object to which 
'a' refers, not the 'a' variable itself. The rule is limited to the 
rebinding of variables, not the modification of the objects to which 
they refer.

Gary Duzan
Motorola CHS

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


Re: how do "real" python programmers work?

2006-01-13 Thread Tom Anderson
On Fri, 13 Jan 2006, Roy Smith wrote:

> Mike Meyer <[EMAIL PROTECTED]> wrote:
>
>> we need a term for development environment built out of Unix tools
>
> We already have one.  The term is "emacs".

Emacs isn't built out of unix tools - it's a standalone program.

Ah, of course - to an true believer, emacs *is* the unix toolset.

:)

tom

-- 
NOW ALL ASS-KICKING UNTIL THE END
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do "real" python programmers work?

2006-01-13 Thread Tom Anderson
On Thu, 12 Jan 2006, Mike Meyer wrote:

> well, we need a term for development environment built out of Unix 
> tools

Disintegrated development environment? Differentiated development 
environment? How about just a development environment?

tom

-- 
NOW ALL ASS-KICKING UNTIL THE END
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flatten a level one list

2006-01-13 Thread Michael Spencer
> Michael Spencer wrote:
>>  result[ix::count] = input + [pad]*(maxlen-lengths[ix])

Peter Otten rewrote:
>  result[ix:len(input)*count:count] = input

Quite so. What was I thinking?


Michael

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


Re: return values of os.system() on win32

2006-01-13 Thread Peter Hansen
rbt wrote:
> Is it safe to say that any value returned by os.system() other than 0 is 
> an error?
> 
> if os.system('winver') != 0:
>  print "Winver failed!"
> else:
>  print "Winver Worked."

According to the docs, assuming that *in general* would be an error, but 
it's likely that for the sorts of cases you are talking about, it's true.

Ultimately, since the return code is generally under the control of the 
application you're calling, it's absolutely possible (likely) that there 
are many programs which do not work as you assume above, and probably a 
large number which don't ever explicitly set the return value at all...

-Peter

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


Re: New Python.org website ?

2006-01-13 Thread Tim Chase
>>In both Mozilla-suite (1.7) and FireFox (1.5), the links on the left
>>(the grey-backgrounded all-caps with the ">>" at the right) all
>>intrude into the body text.
> 
> 
> Looks fine here on Firefox 1.5 and Konqueror 3.4.3.

Just in case anybody is interested, I've posted screenshots of 
how it comes out here (minus the ugly colors when 24-bit images 
are reduced to 256-color GIF files) in both MozSuite and FF:

http://tim.thechases.com/pythonbeta/pythonbeta.html

I did try it both with and without JavaScript enabled (which 
occasionally alters the behaviors of sites when the webdev 
assumes that everybody runs with JS), but had no variance.

-tim








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


Re: Wats the code?

2006-01-13 Thread Peter Hansen
Kr z wrote:
> I wonder anyone knows the line of Python codes to generate 1000 threads 
> concurrently?

It's roughly the same as the line of code that generates a single new 
thread, but with an appropriate loop from 1 to 1000 around it, and 
written with a full understanding of the problems involved in creating 
massive numbers of native OS threads and the likelihood that on most 
systems this will cause an application failure of some kind.

What are you actually trying to do?  Perhaps generators, "threadlets", 
Stackless Python, or other tools will be more appropriate.  It's very 
rare to encounter a situation where 1000 threads will be a good solution 
to the problem.

-Peter

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


XEmacs python-mode question

2006-01-13 Thread Thomas Heller
I'm trying to customize the python interpreter that is used to execute
my scripts from within WinXP, XEmacs, python-mode version
$Revision4.70$, but cannot get it to work.

The only thing that works is M-x customize-group python, and change the
value of 'Python Command'.  However, this changes the interpreter for
all buffers, but I want different buffers use different interpreters.
Is that possible?

What I tried so far:

Insert several variants of '#! py23.cmd' at the top of the buffer - no
effect.

Insert this into the buffer - no effect:
## Local Variables:
## py-python-command: "py23"
## End:

Execute "M-x set-variable py-python-command py23" - no effect.

Can anyone help?

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


Hijacking threads

2006-01-13 Thread Peter Hansen
gene tani wrote:
> Roy Smith wrote:
>>Thanks for posting that URL; I hadn't seen the list before.  
[...]
> 
> pls don't hijack threads

Um, he didn't "hijack" it, he follow a tangent to the discussion and 
even changed the Subject line in a very appropriate manner, both of are 
completely acceptable netiquette and long-standing Usenet practices.

(Rather like I'm doing here.)

-Peter

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


Re: return values of os.system() on win32

2006-01-13 Thread Jorge Godoy
rbt <[EMAIL PROTECTED]> writes:

> Is it safe to say that any value returned by os.system() other than 0 is an
> error?

I believe not.  That depends on the return/error code of the specific program
you ran.  

-- 
Jorge Godoy  <[EMAIL PROTECTED]>

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


return values of os.system() on win32

2006-01-13 Thread rbt
Is it safe to say that any value returned by os.system() other than 0 is 
an error?

if os.system('winver') != 0:
 print "Winver failed!"
else:
 print "Winver Worked."

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


Re: New Python.org website ?

2006-01-13 Thread Sybren Stuvel
Tim Chase enlightened us with:
> In both Mozilla-suite (1.7) and FireFox (1.5), the links on the left
> (the grey-backgrounded all-caps with the ">>" at the right) all
> intrude into the body text.

Looks fine here on Firefox 1.5 and Konqueror 3.4.3.

The site looks really nice! I think this is going to make a difference
in the amount of people taking Python seriously.

Does anybody know what kind of license covers the website?

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


Why is there no post-pre increment operator in python

2006-01-13 Thread gene tani

Roy Smith wrote:
> In article <[EMAIL PROTECTED]>,
>  "gene tani" <[EMAIL PROTECTED]> wrote:
>
> > http://zephyrfalcon.org/labs/python_pitfalls.html
>
> Thanks for posting that URL; I hadn't seen the list before.  Skimming over
> it, none of them really seemed noteworthy until I got to "5. Mutable
> default arguments", which rather shocked me.  Good stuff to know!

here's my full FAQ / gotcha list

http://www.ferg.org/projects/python_gotchas.html
http://zephyrfalcon.org/labs/python_pitfalls.html
http://zephyrfalcon.org/labs/beginners_mistakes.html
http://www.python.org/doc/faq/
http://diveintopython.org/appendix/abstracts.html
http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html
http://www.norvig.com/python-iaq.html
http://www.faqts.com/knowledge_base/index.phtml/fid/245
http://amk.ca/python/writing/warts

pls don't hijack threads

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


Re: Spanish Translation of any python Book?

2006-01-13 Thread gene tani

Olaf "El Blanco" wrote:
> Maybe there is someone that speak spanish. I need the best spanish book for
> learning python.
>

you should learn Chinese, Korean and Russian so you can read this many
times
http://diveintopython.org/#languages

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


Re: Unicode style in win32/PythonWin

2006-01-13 Thread Thomas Heller
"Robert" <[EMAIL PROTECTED]> writes:

> Thomas Heller schrieb:

>> So after these assignments:
>>
>>   ctypes.windll.user32.MessageBoxW.argtypes = (c_int, c_wchar_p,
>>c_wchar_p, c_int)
>>   ctypes.windll.user32.MessageBoxA.argtypes = (c_int, c_char_p,
>>c_char_p, c_int)
>>
>> both MessageBoxA and MessageBoxW can both be called with either ansi and
>> unicode strings, and should work correctly.  By default the conversion
>> is done with ('msbc', 'ignore'), but this can also be changed,
>> ctypes-wide, with a call to ctypes.set_conversion_mode(encoding,errors).
>
> That is a right style of functionality, consistency and duty-free
> default execution flow which python and pythonwin are lacking so far.
> Those have no prominent mode-setting function, the mode-_tuple_ etc. so
> far and/or defaults are set to break simple apps with common tasks.
>
> Only question: is there a reason to have 'ignore' instead of 'replace'
> as default? Wouldn't 'replace' deliver better indications (as for
> example every Webbrowser does on unknown unicode chars ; (and even
> mbcs_encode in 'strict'-mode) ). I can not see any advantage of
> 'ignore' vs. 'replace' when strict equality anyway has been given up

Hm, I don't know.  I try to avoid converting questionable characters at
all, if possible.  Then, it seems the error-mode doesn't seem to change
anything with "mbcs" encoding.  WinXP, Python 2.4.2 on the console:

>>> u"abc\u034adef".encode("mbcs", "ignore")
'abc?def'
>>> u"abc\u034adef".encode("mbcs", "strict")
'abc?def'
>>> u"abc\u034adef".encode("mbcs", "error")
'abc?def'
>>>

With "latin-1", it is different:

>>> u"abc\u034adef".encode("latin-1", "ignore")
'abcdef'
>>> u"abc\u034adef".encode("latin-1", "replace")
'abc?def'
>>> u"abc\u034adef".encode("latin-1", "strict")
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u034a' in 
position 3: ordinal not in range(256)
>>>

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


paypal SOAP API from ZSI or SOAPpy?

2006-01-13 Thread Chris Curvey
Anyone had any luck with this?  (Or can anyone just warn me off it
right now?)

I'm trying to just set up the service proxy via WSDL, and I'm getting
either a runaway process that's chewing up tons of memory or a very
quick stack trace.

I've tried both ZSI and SOAPpy (both stable and release candidate
versions)

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


Re: How to remove subset from a file efficiently?

2006-01-13 Thread AJL
On 12 Jan 2006 22:29:22 -0800
"Raymond Hettinger" <[EMAIL PROTECTED]> wrote:

> AJL wrote:
> > How fast does this run?
> >
> > a = set(file('PSP320.dat'))
> > b = set(file('CBR319.dat'))
> > file('PSP-CBR.dat', 'w').writelines(a.difference(b))
> 
> Turning PSP into a set takes extra time, consumes unnecessary memory,
> eliminates duplicates (possibly a bad thing), and loses the original
> input ordering (probably a bad thing).
> 
> To jam the action into a couple lines, try this:
> 
> b = set(file('CBR319.dat'))
> file('PSP-CBR.dat','w').writelines(itertools.ifilterfalse(b.__contains__,file('PSP320.dat')))
> 
> Raymond
> 

The OP said "assume machine has plenty memory". ;)

I saw some solutions that used sets and was wondering why they stopped
at using a set for the first file and not the second when the problem is
really a set problem but I can see the reasoning behind it now.

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


Re: flatten a level one list

2006-01-13 Thread Alex Martelli
Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
   ...
> I agree with Guido about the special case, but I disagree about the
> error message.  Not being able to use sum(L,"") reduces the
> orthogonality of sum for no good reason I could see.

Having sum(L,'') work but be O(N squared) would be an "attractive
nuisance" within the meaning of the law; it's bad enough that sum(L,[])
etc are that way, but at least beginners want to concatenate lists (or
tuples, arrays, etc) much less often than they want to concatenate
strings.  sum is meant to work on _numbers_ -- the reason it takes that
second optional parameter is essentially to be able to specify the
``type'' of numbers.  In retrospect it might have been better to have a
single argument (or interpret multiple ones like min or max do, maybe),
forcing the starting value to be integer 0.


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


  1   2   3   >