XML Pickle with PyGraphLib - Problems

2005-09-05 Thread Mike P.
Hi all,

I'm working on a simulation (can be considered a game) in Python where I
want to be able to dump the simulation state to a file and be able to load
it up later. I have used the standard Python pickle module and it works fine
pickling/unpickling from files.

However, I want to be able to use a third party tool like an XML editor (or
other custom tool) to setup the initial state of the simulation, so I have
been playing around with the gnosis set of tools written by David Mertz. In
particular I have been using the gnosis.xml.pickle module. Anyway, this
seems to work fine for most data structures, however I have problems getting
it to work with pygraphlib version 0.6.0.1 (from sourceforge). My simulation
needs to store data in a set of graphs, and pygraphlib seems like a nice
simple python graph library, that I found easy to use.

Anyway, the problem is that I can successfully pickle to XML a data
structure containing a pygraphlib graph, but I have trouble
reloading/unpickling the very same data structure that was produced by the
XML pickle module. I get an XMLUnpicklingError. Anyone have any ideas?

Here's some output from the interactive prompt of a small example which
demonstrates the error:

==
C:\home\src>python
ActivePython 2.4 Build 244 (ActiveState Corp.) based on
Python 2.4 (#60, Feb  9 2005, 19:03:27) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pygraphlib import pygraph
>>> graph = pygraph.DGraph()
>>> graph.add_edge('Melbourne', 'Sydney')
>>> graph.add_edge('Melbourne', 'Brisbane')
>>> graph.add_edge('Melbourne', 'Adelaide')
>>> graph.add_edge('Adelaide', 'Perth')
>>> print graph
DGraph: 5 nodes, 4 edges
>>> graph
DGraph: 5 nodes, 4 edges
Melbourne -> ['Sydney', 'Brisbane', 'Adelaide']
Brisbane -> []
Perth -> []
Sydney -> []
Adelaide -> ['Perth']
>>> import gnosis.xml.pickle
>>> file = open('graph.xml', 'w')
>>> gnosis.xml.pickle.dump(graph, file)
>>> file.close()
>>> f2 = open('graph.xml', 'r')
>>> g2 = gnosis.xml.pickle.load(f2)
Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\Lib\site-packages\gnosis\xml\pickle\_pickle.py", line
152, in load
return parser(fh, paranoia=paranoia)
  File "C:\Python24\lib\site-packages\gnosis\xml\pickle\parsers\_dom.py",
line 42, in thing_from_dom
return _thing_from_dom(minidom.parse(fh),None,paranoia)
  File "C:\Python24\lib\site-packages\gnosis\xml\pickle\parsers\_dom.py",
line 175, in _thing_from_dom
container = unpickle_instance(node, paranoia)
  File "C:\Python24\lib\site-packages\gnosis\xml\pickle\parsers\_dom.py",
line 59, in unpickle_instance
raw = _thing_from_dom(node, _EmptyClass(), paranoia)
  File "C:\Python24\lib\site-packages\gnosis\xml\pickle\parsers\_dom.py",
line 234, in _thing_from_dom
node_val = unpickle_instance(node, paranoia)
  File "C:\Python24\lib\site-packages\gnosis\xml\pickle\parsers\_dom.py",
line 95, in unpickle_instance
raise XMLUnpicklingError, \
gnosis.xml.pickle.XMLUnpicklingError: Non-DictType without setstate violates
pickle protocol.(PARANOIA setting may be too high)
>>>
===

I find it strange that:
a) the standard pickle/unpickle works
b) the xml pickle dumps the file but the xml unpickle can't load it.

I'm guessing the problem lies somewhere with implementing __setstate__ and
__getstate__ for pygraphlib (I don't know much about this - haven't used
them before). However, I am a bit reluctant to go in and start playing
around with the internals pygraphlib, as I was hoping to just use it, and
ignore the internal implementation (as you would with any library). Funny
how the standard pickle module doesn't need to do this.

Another thing I tried was the generic xml marshaller (xml.marshal.generic)
that comes with PyXML 0.8.4 (for Python 2.4 on windows).
This also fails but for different reasons. The marshaller doesn't support
the boolean and set types which are part of Python 2.4 and are used in
pygraphlib.
I get errors of the form:

AttributeError: Marshaller instance has no attribute 'tag_bool'
AttributeError: Marshaller instance has no attribute 'm_Set'

Again strange given that bool and sets should be supported in Python 2.4.

Anyway, back to my question - does anyone have any suggestions as to where I
could proceed next? I was hoping to be able to XML Pickle/Unpickle Python
data structures containing graphs from pygraphlib fairly easily without
having to stuff around in the internals of third party libraries.
It would be nice if I could just concentrate on my application logic :-)

Any ideas?

Cheers.

Mike P.



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


Re: is dict.copy() a deep copy or a shallow copy

2005-09-05 Thread Alex
Thanks max,
Now it's much clearer. I made the following experiment
>>>#1
>>> D={'a':1, 'b':2}
>>> D
{'a': 1, 'b': 2}
>>> E=D.copy()
>>> E
{'a': 1, 'b': 2}
>>> D['a']=3
>>> D
{'a': 3, 'b': 2}
>>> E
{'a': 1, 'b': 2}
>>>#2
>>> D={'a':[1,3], 'b':[2,4]}
>>> D
{'a': [1, 3], 'b': [2, 4]}
>>> E=D.copy()
>>> E
{'a': [1, 3], 'b': [2, 4]}
>>> D['a'][0]=9
>>> D
{'a': [9, 3], 'b': [2, 4]}
>>> E
{'a': [9, 3], 'b': [2, 4]}
>>>#3
>>> import copy
>>> F=copy.deepcopy(D)
>>> D
{'a': [9, 3], 'b': [2, 4]}
>>> F
{'a': [9, 3], 'b': [2, 4]}
>>> D['a'][0]=7
>>> D
{'a': [7, 3], 'b': [2, 4]}
>>> F
{'a': [9, 3], 'b': [2, 4]}
>>>

A shallow copy of an object is a copy of the first-level data members
and if one of the members is a pointer, then only the pointer value is
copied, not the structure pointed to by the pointer. The original
object and its shallow copy share the memory space occupied by these
structures.
A deep copy of an object is a copy of everything (including the
structures pointe to by the pointers). The original object and its deep
copy do not share any memory space.

In #1 no pointers are involved so changing a value affects only D but
not E.

In #2 D['a'] and E['a'] are pointers that both point to the same memory
space. Changing that memory space doesn't change the pointers
themsleves.

In #3 a deepcopy makes sure that a copy is made not just of the
pointers but also of the things pointed to.

So the lesson to be learned is that if you make a copy of a dictionary
whose values are pointers to other structures then a deepcopy prevents
a coupling between a the original and the copy. 

Alex

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


wxImage can't read tif file? (WxPython)

2005-09-05 Thread James Hu
Hi, all gurus,

I am working on a small project, which needs to display 16 bit tiff image on
screen directly, I use wxStaticBitmap to do that, and I can show png and jpg
file on the screen without any problem. (converting from tiff to png first
is not option though). However, when I try to read tiff file, nothing
there,(the program is running without error) of course, the tiff is OK, I
can open it with IrFanView. where output.tif is about 640K, a little larger
than output.png(450K), the document says wxImage can open tif!
OR is there other way to show 16 bit tiff on windows with wxPython?
Another thing: how can I call the static methods like wxImage::FindHandler,
it always complains no matter what I use "image.FindHandler() or
wxImage.FindHandler()"

Any help will be apprecaited greatly!!!

James

the codes:

#image=wx.Image('output.png',wxBITMAP_TYPE_PNG)  #Can see,
image=wx.Image('output.tif',wxBITMAP_TYPE_TIF)   #can't see, still black as
the empty bitmap
bmp = image.ConvertToBitmap()
bmp.SetHeight(self.bmpHeight)
bmp.SetWidth(self.bmpWidth)
self.staticBitmap1.SetBitmap(bmp)   #staticBitmap1 already defined/created
before


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


Re: pain

2005-09-05 Thread Steve Holden
Peter Hansen wrote:
> Steve Holden wrote:
> 
>>and the day managers stop being ignorant we'll all be able to fly around 
>>on pigs. Not wishing to offend the pigs, of course.
>>
>>still-working-for-myself-ly y'rs  - steve
> 
> 
> What Steve means here, of course, is that he is his own manager.
> 
> ;-)
> 
Right. This means I get to make fun of my own pointy hair.

at-least-as-long-as-i-still-have-hair-ly y'rs  -steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: Python Doc Problem Example: os.system

2005-09-05 Thread Robert Wierschke
Xah Lee schrieb:
> Python Doc Problem Example: os.system
> 
> Xah Lee, 2005-09
> 
> today i'm trying to use Python to call shell commands. e.g. in Perl
> something like
> 
> output=qx(ls)
> 
> in Python i quickly located the the function due to its
> well-named-ness:
> 
> import os
> os.system("ls")
> 
> 
> however, according to the doc
> http://www.python.org/doc/2.4/lib/os-process.html the os.system()
> returns some esoteric unix thing, not the command output. The doc
> doesn't say how to get the output of the command.
> 

The os.popen(...) function will return a file like object, so you can 
use a read() - method of these object to get the called programms output.

hope that helps - I' m very new to python

The documentation may be not well for all circumstances but the fine 
thing is: the documentation is part of the code itself - inform of the 
docstrings - and this is a very good approach. The bad thing is the 
person who wrote the docstring was documenting his/her own code and not 
code of other programmers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mod_python: what's going on here?

2005-09-05 Thread Olivier
Robert J. Hansen a écrit :

 > Does anyone have any experience with mod_python on OS X/Apache
 > environments?  Can anyone shed some light on 500s that don't leave
 > traces in the error logs, or what precise incantation I need to make
 > mod_python start serving up scripts?



Here is a setup that works for me on 10.3, with Apache2 2.54, python 
2.4.1 and mod_python 3.1.4, all installed from source. This should 
probably work also with your python from fink.

Apache2:
./configure --enable-mods-shared=all  --enable-so

Python:
./configure

mod_python:
./configure --enable-so


 > Also, if this is not appropriate for this group, does anyone know of a
 > Python group for which this is more appropriate?


The mod_python mailing list ? At http://www.modpython.org/ .

Regards,

 Olivier

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Szabolcs Nagy
with the current syntax L[i:i+1] returns [L[i]], with nxlist it returns
L[i+1] if i<0.

L=range(10)
L[1:2]==[L[1]]==[1]
L[-2:-1]==[L[-2]]==[8]

L=nxlist(range(10))
L[1:2]==[L[1]]==[1]
L[-2:-1]==[L[-1]]==[9] # not [L[-2]]

IMHO in this case current list slicing is more consistent.

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


warning when doubly liked list is defined globally

2005-09-05 Thread chand
Hi.,

In my api.py file 'g_opt_list' is defined globally
g_opt_list =[[],[],[],[],[],[],[]]

when I run the py file, I am getting the Following Error

SyntaxWarning: name 'g_opt_list' is used prior to global declaration

Please let me know how to remove this error

Here is the code which gives the error...

Let me know exact reason for this Error and how to remove this
warning..

import os,sys,re,string,math
from xml.dom import minidom, Node
from Layer import Layer
from LMessage import *
from Param import *
from Message import *
from message_mapping import *
from protocol_mapping import *
from symbol_mapping import *
from opt_list_mapping import *
g_del_opt_list =[[],[],[],[],[],[],[]]
sflag = 0
index=0
del_index=0
radflag = 0
depth = 0
xmlflag = 0
opt_param_list = []
del_opt_param_list = []
#g_opt_list = []
MTAS_HOME="/home/chandras/XML_FILES/"
SIG_STANDARD_HOME = "/home/chandras/SIGNALLING_STANDARD/ANSI_SS7/"
symbols=['(',')','{','}','[',']','.']
reverse_symbols=['<','>','~']
layers=['MTP3','SCCP','IOS','CDTAPM2','CDTAPC2','ISUP','IS-41D-SQA']
GUI_API_COMMAND_LIST = [
"NEW",
"ADD_OPTIONAL_PARAM",
"DELETE_OPTIONAL_PARAM",
"DELETE_LAYER",
"RENAME"
]
BASE2 = "01"
BASE10 = "0123456789"
BASE16 = "0123456789ABCDEF"

Message_obj = Message()
filename =""
buffer = []
#LIST = []
def Process_GUI_Command(arg):
global Message_obj
global filename
print "### COMMAND ###", arg[0]
save_fd = os.dup(1)
if arg[0] ==  "DELETE_OPTIONAL_PARAM":
out_file = file('/tmp/te6.txt', 'w+')
elif arg[0] ==  "ADD_OPTIONAL_PARAM":
out_file = file('/tmp/te3.txt', 'w+')
else :
out_file = file('/tmp/te.txt', 'w+')
os.dup2(out_file.fileno(), sys.stdout.fileno())


if  arg[0]  ==  "NEW" :
global g_opt_list
Message_obj = Message()
layerList = listLayers("ANSI_Layers")
layerList = str(layerList)
layerList = layerList.replace(",","")
for i in range(0,len(g_opt_list)):
g_opt_list[i] = []
os.dup2(save_fd, 1)
return layerList


  elifarg[0]  ==   "ADD_OPTIONAL_PARAM" :
global g_opt_list
global layers
global index
message_name = ""
layer_name   = arg[1]
#print "Layer Name", layer_name
for layer in layers:
if layer == layer_name:
if
OPT_LIST_MAPPING.has_key(layer_name):
index =
OPT_LIST_MAPPING[layer_name]
break if arg[2] != 'Null':
optional_parameter_name =
str(arg[2]).replace("+",",")
for symbol in reverse_symbols:
if symbol in optional_parameter_name:
if
SYMBOL_REVERSE_MAPPING.has_key(symbol):
old_symbol =
SYMBOL_REVERSE_MAPPING[symbol]
optional_parameter_name
=optional_parameter_name.replace(symbol,old_symbol)


Message_obj.AddParam(message_name,layer_name,optional_parameter_name )
else : optional_parameter_name= 'Null'

add_delete_flag = 0
  param_name = optional_parameter_name
show_opts(layer_name,add_delete_flag,param_name)
if int(add_delete_flag) == 0:
add_delete_flag = 0
if  optional_parameter_name != "Null":
optList =
Message_obj.showOptionalParameters(layer_name,add_delete_flag,optional_parameter_name)

g_opt_list[int(index)].append(optional_parameter_name)
for i in g_opt_list[int(index)]:
if
g_opt_list[int(index)].count(i) == 1:
optList =
Message_obj.showOptionalParameters(layer_name,add_delete_flag,i)

displayoptparams(optList,layer_name,0,"Null")
i= "Null"
optional_parameter_name = "Null"
add_delete_flag = 1

os.dup2(save_fd, 1)
else:
print "Invalid Option"


def  show_opts(layer_name,add_delete_flag,param_name):
global index
global g_opt_list
#param_name = "Null"
List =
Message_obj.showOptionalParameters(layer_name,add_delete_flag,"Null")
if (len(List)== 0)  :
return "None"

displayoptparams(List,layer_name,add_delete_flag,Message_obj._message_name)
if param_name == 'Null':
for i in g_opt_list[int(index)]:

Re: Online Modification of Python Code

2005-09-05 Thread malv
I wrote a module testalgo.py with some functions to be modified.
After modification I typed to the interactive shell:
>>>import testalgo
>>>reload(testalgo)
... and things seem to workout as you suggested. At least I modified
some quickie print statements to check. I use eric3 and nothing in this
IDE seems to interfere with the process.
I hadn't thought about doing it this way.
(I have in fact an extensive driver/command infrastructure in place)

I seem to recall a post by Diez Roggish that reload() doesn't always
work as it should. Any news on this? At least im my preliminary test it
works.
Thank you Dennis!

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


Re: Assigning 'nochage' to a variable.

2005-09-05 Thread [EMAIL PROTECTED]
Thanks for the suggestions, although I'll probably continue to use:

 var1 = 17
 var1 = func1(var1)
 print var1

and have func1 return the input value if no change is required.
It's *almost* as nice as if there was a Nochange value available..

BR /CF

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


sslerror: (8, 'EOF occurred in violation of protocol')

2005-09-05 Thread Robert
I'm using the https-protocol. On my systems and network everything works ok.
But on some connections from some other users' computers/network I get this
error (Python 2.3.5 on Windows):

Traceback (most recent call last):
  File "", line 1, in ?
  File "ClientCookie\_urllib2_support.pyo", line 524, in open
  File "ClientCookie\_urllib2_support.pyo", line 424, in http_response
  File "ClientCookie\_urllib2_support.pyo", line 541, in error
  File "urllib2.pyo", line 306, in _call_chain
  File "ClientCookie\_urllib2_support.pyo", line 185, in http_error_302
  File "ClientCookie\_urllib2_support.pyo", line 518, in open
  File "urllib2.pyo", line 326, in open
  File "urllib2.pyo", line 306, in _call_chain
  File "ClientCookie\_urllib2_support.pyo", line 759, in https_open
  File "ClientCookie\_urllib2_support.pyo", line 608, in do_open
  File "httplib.pyo", line 712, in endheaders
  File "httplib.pyo", line 597, in _send_output
  File "httplib.pyo", line 564, in send
  File "httplib.pyo", line 985, in connect
  File "socket.pyo", line 73, in ssl
sslerror: (8, 'EOF occurred in violation of protocol')


The target-server is always the same and ok. but different
client-OS(Windows)/proxies/firewalls/routers are in use.
What is the nature of this error? How is it possible that an EOF in
ssl-connections (during connect?) occures?
What can be done to handle/circumvent that problem?

Robert


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


Re: Online Modification of Python Code

2005-09-05 Thread malv
Hi Robert:
(1) Things are not that simple. In fact in setting up a run, extensive
database backup is already involved. Subsequently, data structures are
built at runtime of typically 0.5Gbytes. Although saving this should
work, it would require quite some debug/verification to check out the
validity. Many data structures intervene. Dennis' suggestion worked
fine so I'm happy to be able to leave everything else 'untouched'.

(2) As to your VB question. I have been 'forced' to do a lot of VB
related to M$ Access db  work. VB is 100% integrated in M$'s Visual IDE
and allows you to change 'on the fly' almost anything in the code, even
in the midst of a debug breakpoint stop. This is very, very handy. It
would be a very valuable addition to Python, though it's not very clear
to me how this could be implemented without a specific IDE. (Don't
switch to VB for this though. Python is much cooler).

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


Optional algol syntax style

2005-09-05 Thread Sokolov Yura
I think, allowing to specify blocks with algol style (for-end, if-end, 
etc) will allow to write easy php-like templates
and would attract new web developers to python (as php and ruby do).
It can be straight compilled into Python bytecode cause there is 
one-to-one transformation.
So this:
# -*- syntax-style: algol -*-
class asd:
def __init__(self,a):
   if a:
  for i in xrange(100):
 pass
  else:
 while false:
pass
 else:
pass
 end
  end
   else:
  self.a=None
   end
end
end
is equivalent for:
class asd:
def __init__(self,a):
   if a:
  for i in xrange(100):
 pass
  else:
 while false:
pass
 else:
pass
   else:
  self.a=None
but could be written as:

# -*- syntax-style: algol -*-
class asd: def __init__(self,a): if a: for i in xrange(100): pass; else: 
while false: pass; else: pass; end; end; end; end;

which is easier to embed into http template (php and ruby shows it).

And, maybe, there can web syntax - equivalent for php and ruby template:
<%# -*- syntax: web -*-%>
<%# -*- command: print -*- %>
<%
def print_all(l):%>
<%
for k in l:%>
#{k.name}#{k.surname}
<%end%>

<%end
# -*- command: yield -*-
def yield_all(l):%>
<%
for k in l:%>
#{k.name}#{k.surname}
<%end%>

<%end
# -*- command: S.write -*-
def write_all(S,l):%>
<%
for k in l:%>
#{k.name}#{k.surname}
<%end%>

<%end%>

will be translated as it were written:
def print_all(l):
print (r"")
for k in l:
   print (r""+`k.name`+ r""+`k.surname`+ r"")
# or print (r""+str(k.name)+ r""+str(k.surname)+ 
r"")
print (r"")
def yield_all(l):
yield (r"")
for k in l:
   yield (r""+`k.name`+ r""+`k.surname`+ r"")
yield (r"")
def write_all(S.l):
S.write (r"")
for k in l:
   S.write (r""+`k.name`+ r""+`k.surname`+ 
r"")
S.write (r"")

I offer to include it into iterpretter, so we can leave another 
compilation stage, as it exists with popular
template libraries, which compile their template files into bytecode (or 
python source)

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


Re: time.mktime problem

2005-09-05 Thread Edvard Majakari
"McBooCzech" <[EMAIL PROTECTED]> writes:


> ===snip===
> Values 100-1899 are always illegal.
> .
> .
> strptime(string[, format])
> .
> .
> The default values used to fill in any missing data are:
> (1900, 1, 1, 0, 0, 0, 0, 1, -1)
> ===snip===
>
> BTW, check the following code:
>>>import datetime, time
>>>print time.gmtime(time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))
> (1901, 12, 13, 20, 45, 52, 4, 347, 0)
>
> but (1900, 1, 1, 0, 0, 0, 0, 1, -1) is (IMHO) expected Hmmm. But I
> am just a newbie!!! :)

You are comparing apples and oranges here. You checked documentation of
strptime, and the problem is in the use of time.mktime(). 

The point: time.mktime() returns Epoch time (seconds since 1970) and you are
passing it a tuple which is (way before) 1970. There is no such thing as
negative epoch. It is like computing packaging day of milk which hasn't been
milked from the cow yet :)

I really wonder what version of Python you are running:

>>> import datetime, time
>>> print time.gmtime(time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))
Traceback (most recent call last):
  File "", line 1, in ?
OverflowError: mktime argument out of range

Python 2.3 and 2.4 both give the same error. As for the python version 2.2, no
datetime module was implemented.

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression unicode character class trouble

2005-09-05 Thread Diez B. Roggisch
Steven Bethard wrote:
> I'd use something like r"[^_\d\W]", that is, all things that are neither 
> underscores, digits or non-alphas.  In action:
> 
> py> re.findall(r'[^_\d\W]+', '42badger100x__xxA1BC')
> ['badger', 'x', 'xxA', 'BC']
> 
> HTH,

Seems so, great!

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


Re: Online Modification of Python Code

2005-09-05 Thread Diez B. Roggisch
> 
> I seem to recall a post by Diez Roggish that reload() doesn't always
> work as it should. Any news on this? At least im my preliminary test it
> works.

Read the docs on reload:

http://www.python.org/doc/current/lib/built-in-funcs.html

"""

If a module is syntactically correct but its initialization fails,  the 
first import statement for it does not bind its name  locally, but does 
store a (partially initialized) module object in  sys.modules. To reload 
the module you must first  import it again (this will bind the name to 
the partially  initialized module object) before you can reload() it.

When a module is reloaded, its dictionary (containing the module's 
global variables) is retained. Redefinitions of names will override  the 
old definitions, so this is generally not a problem. If the new  version 
of a module does not define a name that was defined by the  old version, 
the old definition remains. This feature can be used  to the module's 
advantage if it maintains a global table or cache of  objects -- with a 
try statement it can test for the  table's presence and skip its 
initialization if desired:


try:
 cache
except NameError:
 cache = {}


It is legal though generally not very useful to reload built-in or 
dynamically loaded modules, except for sys,  __main__ and __builtin__. 
In  many cases, however, extension modules are not designed to be 
initialized more than once, and may fail in arbitrary ways when  reloaded.

If a module imports objects from another module using from  ... import 
..., calling reload() for  the other module does not redefine the 
objects imported from it --  one way around this is to re-execute the 
from statement,  another is to use import and qualified names 
(module.name) instead.

If a module instantiates instances of a class, reloading the module 
that defines the class does not affect the method definitions of the 
instances -- they continue to use the old class definition. The  same is 
true for derived classes.
"""

So - expect strange things to happen, sometimes.

I personally _never_ felt the need for reload - after all, writing more 
than totally trivial crap on the commandline justifies a small 
testscript - which I then just execute on the commandline.

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


Job Offer in Paris, France : R&D Engineer (Plone)

2005-09-05 Thread Huron
Hi all,

Sopinspace, Society For Public Information Spaces (specialized in Web-based
citizen public debate and collaborative initiatives) is looking for a new
developer / R&D engineer with strong Plone focus.
The position is located in Paris, France (11eme).

All details (in french) can be found here :
http://www.sopinspace.com/company/poste_ing.pdf 
contact : emploi <*at*> sopinspace <-dot-> com

Best,

--
Raphaël Badin
Sopinspace, Society for Public Information Spaces
4, passage de la Main d'Or, F-75011 Paris, France

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


Re: warning when doubly liked list is defined globally

2005-09-05 Thread Fredrik Lundh
"chand" <[EMAIL PROTECTED]> wrote:

> In my api.py file 'g_opt_list' is defined globally
> g_opt_list =[[],[],[],[],[],[],[]]
>
> when I run the py file, I am getting the Following Error
>
> SyntaxWarning: name 'g_opt_list' is used prior to global declaration
>
> Please let me know how to remove this error

you left out the line number from that error message, and the code you
posted doesn't even compile:

  File "chand.py", line 67
elifarg[0]  ==   "ADD_OPTIONAL_PARAM" :
  ^
IndentationError: unindent does not match any outer indentation level

(from what I can tell, you never assign to g_opt_list in that script, so it
sure looks like you didn't post the right version of your program.  but
instead of reposting the code, look at the line Python told you to look
at; if you cannot figure out how to fix that, try to reduce the script to
a few lines before posting the code)

 



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


Re: Job Offer in Paris, France : R&D Engineer (Plone)

2005-09-05 Thread Paul Rubin
Huron <[EMAIL PROTECTED]> writes:
> Sopinspace, Society For Public Information Spaces (specialized in Web-based
> citizen public debate and collaborative initiatives) is looking for a new
> developer / R&D engineer with strong Plone focus.
> The position is located in Paris, France (11eme).
> 
> All details (in french) can be found here :
> http://www.sopinspace.com/company/poste_ing.pdf contact : emploi
> <*at*> sopinspace <-dot-> com

Since you're posting in English, is there any point in responding
to it in English, and are non-Europeans eligible?  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: What is the role of F in dict(E, **F)

2005-09-05 Thread Marc Boeren


> As I understand update() is used to merge two dictionaries, 
> for example
> >>> D={'a':1, 'b':2}
> >>> E={'b':4,'c':6}
> >>> D.update(E)
> >>> D
> {'a': 1, 'c': 6, 'b': 4}
> >>>
> 
> But what is the role of **F?


>>> D={'a':1, 'b':2}
>>> E={'b':4,'c':6}
>>> D.update(E, a=3)
>>> D
{'a': 3, 'c': 6, 'b': 4}


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


Re: warning when doubly liked list is defined globally

2005-09-05 Thread Daniel Dittmar
chand wrote:
> Hi.,
> 
> In my api.py file 'g_opt_list' is defined globally
> g_opt_list =[[],[],[],[],[],[],[]]
> 
> when I run the py file, I am getting the Following Error
> 
> SyntaxWarning: name 'g_opt_list' is used prior to global declaration

g_del_opt_list =[[],[],[],[],[],[],[]]
#g_opt_list = []

It seems that your variable names got mixed up.

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


Re: Assigning 'nochage' to a variable.

2005-09-05 Thread [EMAIL PROTECTED]
Oh, right I see you also thought of that.
(Sorry, didnt read your entire mail.)

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


Re: dual processor

2005-09-05 Thread Nick Craig-Wood
Jeremy Jones <[EMAIL PROTECTED]> wrote:
>  One Python process will only saturate one CPU (at a time) because
>  of the GIL (global interpreter lock).

I'm hoping python won't always be like this.

If you look at another well known open source program (the Linux
kernel) you'll see the progression I'm hoping for.  At the moment
Python is at the Linux 2.0 level.  Its supports multiple processors,
but has a single lock (Python == Global Interpreter Lock, Linux == Big
Kernel Lock).

Linux then took the path of splitting the BKL into smaller and smaller
locks, increasing the scalability over multiple processors.
Eventually by 2.6 we now have a fully preempt-able kernel, lock-less
read-copy-update etc.

Splitting the GIL introduces performance and memory penalties.  Its
been tried before in python (I can't find the link at the moment -
sorry!).  Exactly the same complaint was heard when Linux started
splitting its BKL.

However its crystal clear now the future is SMP.  Modern chips seem to
have hit the GHz barrier, and now the easy meat for the processor
designers is to multiply silicon and make multiple thread / core
processors all in a single chip.

So, I believe Python has got to address the GIL, and soon.

A possible compromise (also used by Linux) would be to have two python
binaries.  One with the BKL which will be faster on uniprocessor
machines, and one with a system of fine grained locking for
multiprocessor machines.  This would be selected at compile time using
C Macro magic.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Online Modification of Python Code

2005-09-05 Thread malv
Diez,

You are quite right on using module.name when importing module objects.
This happened to be the way I ran my initial successful tests. Later I
modified things by using 'import * from algotest' and my modifications
stopped from coming through.

In my case reload comes in very handy. I can see your point about
testscripts in software development. However this particular project is
in a stage where code writing became  now somewhat insignificant
relative to mathematical algorithm development and simultion. Very
quick turnaroud is of prime importance. A testscript wouldn't test
anything without going through a complete setup cycle involving several
stage chains. So online localized modification comes in very handy (of
course you could always goof up in syntax in a modifying a statement -
too bad!)

Diez, thank you very much!

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


simple question: $1, $2 in py ?

2005-09-05 Thread es_uomikim
Hi,

I have one small simple question, that I didn't found answer in 
google's. It's kind of begginers question because I'm a one. ; )

I wanned to ask how to use scripts with vars on input like this:

$ echo "something" | ./my_script.py

or:

$ ./my_scripy.py var1 var2


As far as I understand there's no $1, $2... etc stuff right ?

Sorry for a silly question.

greetz,
T




-- 
"Przyjacielu, lepiej nas dobrze wypieprz zamiast prawić nam kazania. 
Nawrócić nas nie zdołasz..." Marquis Donatien Alphonse François de Sade
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple question: $1, $2 in py ?

2005-09-05 Thread Diez B. Roggisch
> 
> As far as I understand there's no $1, $2... etc stuff right ?

Yes - but there is sys.argv

Try this


import this

print sys.argv


and invoke it as script with args. Make also sure to checkout modules 
optparse and getopt to deal with the options.

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


Re: dual processor

2005-09-05 Thread Alan Kennedy
[Jeremy Jones]
>> One Python process will only saturate one CPU (at a time) because
>> of the GIL (global interpreter lock).

[Nick Craig-Wood]
> I'm hoping python won't always be like this.

Me too.

> However its crystal clear now the future is SMP.

Definitely.

> So, I believe Python has got to address the GIL, and soon.

I agree.

I note that PyPy currently also has a GIL, although it should hopefully 
go away in the future.

"""
Armin and Richard started to change genc so that it can handle the
new external objects that Armin had to introduce to implement
threading in PyPy. For now we have a simple GIL but it is not
really deeply implanted in the interpreter so we should be able to
change that later. After two days of hacking the were finished.
Despite that it is still not possible to translate PyPy with
threading because we are missing dictionaries with int keys on the
RPython level.
"""

http://codespeak.net/pipermail/pypy-dev/2005q3/002287.html

The more I read about such global interpreter locks, the more I think 
that the difficulty in getting rid of them lies in implementing portable 
and reliable garbage collection.

Read this thread to see what Matz has to say about threading in Ruby.

http://groups.google.com/group/comp.lang.ruby/msg/dcf5ca374e6c5da8

One of these years I'm going to have to set aside a month or two to go 
through and understand the cpython interpreter code, so that I have a 
first-hand understanding of the issues.

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


error when parsing xml

2005-09-05 Thread Odd-R.
I use xml.dom.minidom to parse some xml, but when input
contains some specific caracters(æ, ø and å), I get an
UnicodeEncodeError, like this:

UnicodeEncodeError: 'ascii' codec can't encode character
u'\xe6' in position 604: ordinal not in range(128).

How can I avoid this error?


All help much appreciated!


-- 
Har du et kjøleskap, har du en TV
så har du alt du trenger for å leve

-Jokke & Valentinerne
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python logo

2005-09-05 Thread Joal Heagney
Tim Churches wrote:
> Fredrik Lundh wrote:
> 
>>Tim Churches wrote:
>>
>>
>>
>>>PPS Emerson's assertion might well apply not just to Python logos, but
>>>also, ahem, to certain aspects of the Python standard library.
>>
>>
>>you've read the python style guide, I presume?
>>
>>http://www.python.org/peps/pep-0008.html
> 
> 
> A Foolish Consistency is the Hobgoblin of Little Minds.
>  --often ascribed to Ralph Waldo Emerson but
>in fact due to[1] G. van Rossum and B Warsaw.
> 
> [1] The convention that quotes are ascribed to those who first used them
> is, of course, a foolish consistency.
> 
> Tim C

+1 QOTW

:)

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


Problem with: urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

2005-09-05 Thread Josef Cihal
Hi,

I get an error, when I am trying to download URL with using Cookies.
Where is the Problem?

Thank u very much for all ideas!!!

sincerely

Josef


import os, cookielib, urllib2
cj = cookielib.MozillaCookieJar()
os.environ["http_proxy"] = "http://proxy.irm.at:1234";
os.environ['HOME']= r"C:\tmp\COOKIE"
#
cj.load(os.path.join(os.environ["HOME"], "cookies.txt"))
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
r = opener.open("http://brokerjet.ecetra.com/at/news/?/";)

Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Programme\Python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
  File "C:\Programme\Python24\lib\urllib2.py", line 376, in _open
'_open', req)
  File "C:\Programme\Python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
  File "C:\Programme\Python24\lib\urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "C:\Programme\Python24\lib\urllib2.py", line 996, in do_open
raise URLError(err)
urllib2.URLError: 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Warning when doubly linked list is defined gloablly

2005-09-05 Thread chand
Hi All..,


Sorry for mailing the code which does't even compile !!

Please find below the code which compiles. Please let me know how to
resolve this warning message..!!
SyntaxWarning: name 'g_opt_list' is used prior to global declaration


import os,sys,re,string,math
from xml.dom import minidom, Node
from Layer import Layer
from LMessage import *
from Param import *
from Message import *
#from message_mapping import *
#from protocol_mapping import *
#from symbol_mapping import *
#from opt_list_mapping import *
g_del_opt_list =[[],[],[],[],[],[],[]]
sflag = 0
index=0
del_index=0
radflag = 0
depth = 0
xmlflag = 0
opt_param_list = []
del_opt_param_list = []
#g_opt_list = []
MTAS_HOME="/home/chandras/XML_FILES/"
SIG_STANDARD_HOME = "/home/chandras/SIGNALLING_STANDARD/ANSI_SS7/"
reverse_symbols=['<','>','~']
layers=['MTP3','SCCP','IOS','CDTAPM2','CDTAPC2','ISUP','IS-41D-SQA']
GUI_API_COMMAND_LIST = [
"NEW",
"ADD_OPTIONAL_PARAM",
"DELETE_OPTIONAL_PARAM",
"DELETE_LAYER",
"RENAME"
]

BASE2 = "01"
BASE10 = "0123456789"
BASE16 = "0123456789ABCDEF"

Message_obj = Message()
filename =""
buffer = []
#LIST = []
def Process_GUI_Command(arg):
global Message_obj
global filename
print "### COMMAND ###", arg[0]
save_fd = os.dup(1)
if arg[0] ==  "DELETE_OPTIONAL_PARAM":
out_file = file('/tmp/te6.txt', 'w+')
elif arg[0] ==  "ADD_OPTIONAL_PARAM":
out_file = file('/tmp/te3.txt', 'w+')
else :
out_file = file('/tmp/te.txt', 'w+')
os.dup2(out_file.fileno(), sys.stdout.fileno())

if  arg[0]  ==  "NEW" :
global g_opt_list
Message_obj = Message()
layerList = listLayers("ANSI_Layers")
layerList = str(layerList)
layerList = layerList.replace(",","")
for i in range(0,len(g_opt_list)):
g_opt_list[i] = []
os.dup2(save_fd, 1)
return layerList

elifarg[0]  ==   "ADD_OPTIONAL_PARAM" :
global g_opt_list
global layers
global index
message_name = ""
layer_name   = arg[1]
#print "Layer Name", layer_name
for layer in layers:
if layer == layer_name:
if
OPT_LIST_MAPPING.has_key(layer_name):
index =
OPT_LIST_MAPPING[layer_name]
break

if arg[2] != 'Null':
optional_parameter_name =
str(arg[2]).replace("+",",")
for symbol in reverse_symbols:
if symbol in optional_parameter_name:
if
SYMBOL_REVERSE_MAPPING.has_key(symbol):
old_symbol =
SYMBOL_REVERSE_MAPPING[symbol]
optional_parameter_name
= optional_parameter_name.replace(symbol,old_symbol)

Message_obj.AddParam(message_name,layer_name,
optional_parameter_name )
else : optional_parameter_name= 'Null'

add_delete_flag = 0

param_name = optional_parameter_name
show_opts(layer_name,add_delete_flag,param_name)
if int(add_delete_flag) == 0:
add_delete_flag = 0
if  optional_parameter_name != "Null":
optList =
Message_obj.showOptionalParameters(layer_name,add_delete_flag,optional_parameter_name)

g_opt_list[int(index)].append(optional_parameter_name)
for i in g_opt_list[int(index)]:
if
g_opt_list[int(index)].count(i) == 1:
optList =
Message_obj.showOptionalParameters(layer_name,add_delete_flag,i)

displayoptparams(optList,layer_name,0,"Null")
i= "Null"
optional_parameter_name = "Null"
add_delete_flag = 1
os.dup2(save_fd, 1)

else:
print "Invalid Option"


def  show_opts(layer_name,add_delete_flag,param_name):
global index
global g_opt_list
#param_name = "Null"
List =
Message_obj.showOptionalParameters(layer_name,add_delete_flag,"Null")
if (len(List)== 0)  :
return "None"

displayoptparams(List,layer_name,add_delete_flag,Message_obj._message_name)
if param_name == 'Null':
for i in g_opt_list[int(index)]:
if g_opt_list[int(index)].count(i) == 1:
optList =
Me

Re: Assigning 'nochage' to a variable.

2005-09-05 Thread Bengt Richter
On 5 Sep 2005 02:19:05 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>Thanks for the suggestions, although I'll probably continue to use:
>
> var1 = 17
> var1 = func1(var1)
> print var1
>
>and have func1 return the input value if no change is required.
>It's *almost* as nice as if there was a Nochange value available..
>
>BR /CF
>
This seems to me a tiny snippet from a larger context, like maybe
simulating tranfer of info between circuits attached to a bus.
Posting tiny excerpts can only get you help with that, which in
the larger context might be fine or not, but no one can say ;-)

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


Re: Controlling memory allocation

2005-09-05 Thread Tommy . Ryding
Hello.
I have done the thing you are requesting. You can easily create your
own memory pool and have Python to use it.

I added some rows to Pyconfig.h:

#ifdef malloc
#undef malloc
#endif /*malloc*/
#define malloc  Python_malloc

Then I have some overhead in my own Python_malloc(size_t nBytes)

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


Re: simple question: $1, $2 in py ?

2005-09-05 Thread es_uomikim
Diez B. Roggisch wrote:
>>
>> As far as I understand there's no $1, $2... etc stuff right ?
> 
> 
> Yes - but there is sys.argv
> 

Oh, yes. Right : )
It feels that I miss-looked it.

thank You very much for an advice : )
greetz,
T


-- 
"Przyjacielu, lepiej nas dobrze wypieprz zamiast prawić nam kazania. 
Nawrócić nas nie zdołasz..." Marquis Donatien Alphonse François de Sade
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python logo

2005-09-05 Thread Fredrik Lundh
Tim Churches wrote:

>>> also, ahem, to certain aspects of the Python standard library.
>>
>> you've read the python style guide, I presume?
>>
>> http://www.python.org/peps/pep-0008.html
>
> A Foolish Consistency is the Hobgoblin of Little Minds.
> --often ascribed to Ralph Waldo Emerson but
>   in fact due to[1] G. van Rossum and B Warsaw.
>
> [1] The convention that quotes are ascribed to those who first used them
> is, of course, a foolish consistency.

in case you really got that backwards, I should probably point out that
the style guide reference was in response to the "certain aspects of the
python standard library" part of your post,  not the "emerson said this"
part.

 



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


Re: error when parsing xml

2005-09-05 Thread Fredrik Lundh
Odd-R. wrote:

> I use xml.dom.minidom to parse some xml, but when input
< contains some specific caracters(æ, ø and å), I get an
> UnicodeEncodeError, like this:
>
> UnicodeEncodeError: 'ascii' codec can't encode character
> u'\xe6' in position 604: ordinal not in range(128).
>
> How can I avoid this error?

if you're getting this on the way in, something is broken (posting a short
self-contained test program will help us figure out what's wrong).

if you're getting this on the way out, the problem is that you're trying to
print Unicode strings to an ASCII device.  use the "encode" method to
convert the string to the encoding you want to use, or use codecs.open
to open an encoded stream and print via that one instead.

more reading (google for "python unicode" if you want more):

http://www.jorendorff.com/articles/unicode/python.html
http://effbot.org/zone/unicode-objects.htm
http://www.amk.ca/python/howto/unicode

 



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

Re: Optional algol syntax style

2005-09-05 Thread Mikael Olofsson
Sokolov Yura wrote:
> I think, allowing to specify blocks with algol style (for-end, if-end, 
> etc) will allow to write easy php-like templates
> and would attract new web developers to python (as php and ruby do).
> It can be straight compilled into Python bytecode cause there is 
> one-to-one transformation.
 > [snip details]

Standard answer to this kind of question:

You can already do that in Python. It's spelled #end.

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


Re: simple question: $1, $2 in py ?

2005-09-05 Thread Laszlo Zsolt Nagy

>Oh, yes. Right : )
>It feels that I miss-looked it.
>
>thank You very much for an advice : )
>  
>
Also try the OptParse module.

http://www.python.org/doc/2.4/lib/module-optparse.html

It handles the GNU/POSIX syntax very well.

  Les

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


Re: Job Offer in Paris, France : R&D Engineer (Plone)

2005-09-05 Thread Huron
> Since you're posting in English, is there any point in responding
> to it in English, and are non-Europeans eligible?

I'm afraid not. The team is too small to welcome remote work at the present
time ... I was posting in english mainly to avoid beeing flag as spam ...
and because I though I might be a good thing to let the community know that
they are such profile wanted.

- RB

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


Has anybody tried to make a navigation like Google?

2005-09-05 Thread Lad
Hi,
I would like to make in my web application a similar navigation like
Google uses, I mean  at the bottom of each page there are numbers of
returned pages after you search query.
Has anyone tried that? Is there an algorithm for that? I do not want to
re-invent the wheel.
Thank you for help
La.

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


Re: error when parsing xml

2005-09-05 Thread Diez B. Roggisch

if you're getting this on the way in, something is broken (posting a short
self-contained test program will help us figure out what's wrong).


Or he tries to pass a unicode object to parseString.


Regards,

Diez
# -*- coding: utf-8 -*-
import xml.dom.minidom


dom3 = xml.dom.minidom.parseString(u'wir hoffen ihr habt den sommer 
schšn verbracht some more data')
print dom3
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: dual processor

2005-09-05 Thread Scott David Daniels
Nick Craig-Wood wrote:
> Splitting the GIL introduces performance and memory penalties
> However its crystal clear now the future is SMP.  Modern chips seem to
> have hit the GHz barrier, and now the easy meat for the processor
> designers is to multiply silicon and make multiple thread / core
> processors all in a single chip.
> So, I believe Python has got to address the GIL, and soon.
However, there is no reason to assume that those multiple cores must
work in the same process.  One of the biggest issues in running python
in multiple simultaneously active threads is that the Python opcodes
themselves are no longer indivisible.  Making a higher level language
that allows updates work with multiple threads involves lots of
coordination between threads simply to know when data structures are
correct and when they are in transition.

Even processes sharing some memory (in a "raw binary memory" style) are
easier to write and test.  You'd lose too much processor to coordination
effort which was likely unnecessary.  The simplest example I can think
of is decrementing a reference count.  Only one thread can be allowed to
DECREF at any given time for fear of leaking memory, even though it will
most often turn out the objects being DECREF'ed by distinct threads are
themselves distinct.

In short, two Python threads running simultaneously cannot trust that
any basic Python data structures they access are in a consistent state
without some form of coordination.

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


error when parsing xml

2005-09-05 Thread Albert Leibbrandt
>> I use xml.dom.minidom to parse some xml, but when input
>> contains some specific caracters(æ, ø and å), I get an
>> UnicodeEncodeError, like this:
>>
>> UnicodeEncodeError: 'ascii' codec can't encode character
>> u'\xe6' in position 604: ordinal not in range(128).
>>
>> How can I avoid this error?
>>
>>
>> All help much appreciated!

I have found that some people refuse to stick to standards, so whenever I
parse XML files I remove any characters that fall in the range 
<= 0x1f
>= 0xf0

Hope it helps.

Regards
Albert


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


Re: python logo

2005-09-05 Thread Tim Churches
Fredrik Lundh wrote:

>Tim Churches wrote:
>
>  
>
also, ahem, to certain aspects of the Python standard library.


>>>you've read the python style guide, I presume?
>>>
>>>http://www.python.org/peps/pep-0008.html
>>>  
>>>
>>A Foolish Consistency is the Hobgoblin of Little Minds.
>>--often ascribed to Ralph Waldo Emerson but
>>  in fact due to[1] G. van Rossum and B Warsaw.
>>
>>[1] The convention that quotes are ascribed to those who first used them
>>is, of course, a foolish consistency.
>>
>>
>
>in case you really got that backwards, I should probably point out that
>the style guide reference was in response to the "certain aspects of the
>python standard library" part of your post,  not the "emerson said this"
>part.
>  
>
I was indulging in the leg pulling which your reply invited, Fred. I 
think we both agree that the minor inconsistencies in various aspects of 
the Python standard library are of no consequence to anyone except the 
pathologically pedantic.

Tim C

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


Re: error when parsing xml

2005-09-05 Thread Odd-R.
On 2005-09-05, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Odd-R. wrote:
>
>> I use xml.dom.minidom to parse some xml, but when input
>< contains some specific caracters(æ, ø and å), I get an
>> UnicodeEncodeError, like this:
>>
>> UnicodeEncodeError: 'ascii' codec can't encode character
>> u'\xe6' in position 604: ordinal not in range(128).
>>
>> How can I avoid this error?
>
> if you're getting this on the way in, something is broken (posting a short
> self-contained test program will help us figure out what's wrong).

This is retrieved through a webservice and stored in a variable test




]>
æøå

printing this out yields no problems, so the trouble seems to be when executing
the following:

doc = minidom.parseString(test)

Then I get this error:

File "C:\Plone\Python\lib\site-packages\_xmlplus\dom\minidom.py", line 1918, in 
parseString
   return expatbuilder.parseString(string)
File "C:\Plone\Python\lib\site-packages\_xmlplus\dom\expatbuilder.py", line 
940, in parseString
   return builder.parseString(string)
File "C:\Plone\Python\lib\site-packages\_xmlplus\dom\expatbuilder.py", line 
223, in parseString
parser.Parse(string, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 157-159: 
ordinal not in range(128)


In the top of the file, I have put this statement: # -*- coding: utf-8 -*-

> if you're getting this on the way out, the problem is that you're trying to
> print Unicode strings to an ASCII device.  use the "encode" method to
> convert the string to the encoding you want to use, or use codecs.open
> to open an encoded stream and print via that one instead.

Can you give an example of how this is done?

Thanks again for all help!

-- 
Har du et kjøleskap, har du en TV
så har du alt du trenger for å leve

-Jokke & Valentinerne
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Has anybody tried to make a navigation like Google?

2005-09-05 Thread Sybren Stuvel
Lad enlightened us with:
> I would like to make in my web application a similar navigation like
> Google uses, I mean  at the bottom of each page there are numbers of
> returned pages after you search query.  Has anyone tried that? Is
> there an algorithm for that? I do not want to re-invent the wheel.

Isn't that just dividing the number of results by the number of
results per page? That would give you the number of pages...

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


Re: error when parsing xml

2005-09-05 Thread Fredrik Lundh
Odd-R. wrote:

> This is retrieved through a webservice and stored in a variable test
>
> 
> 
> 
> ]>
> æøå
>
> printing this out yields no problems, so the trouble seems to be when 
> executing
< the following:
>
> doc = minidom.parseString(test)

unless we have a cut-and-paste problem here, that looks like invalid XML;
the header says UTF-8, but the test element contains ISO-8859-1 text.

try changing "utf-8" to "iso-8859-1" to see if that helps.

and you really need to fix the originating system, to make sure that the en-
coding header matches the encoding used for the content.

 



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

Re: Job Offer in Paris, France : R&D Engineer (Plone)

2005-09-05 Thread Bengt Richter
On 05 Sep 2005 03:06:34 -0700, Paul Rubin  wrote:

>Huron <[EMAIL PROTECTED]> writes:
>> Sopinspace, Society For Public Information Spaces (specialized in Web-based
>> citizen public debate and collaborative initiatives) is looking for a new
>> developer / R&D engineer with strong Plone focus.
>> The position is located in Paris, France (11eme).
>> 
>> All details (in french) can be found here :
>> http://www.sopinspace.com/company/poste_ing.pdf contact : emploi
>> <*at*> sopinspace <-dot-> com
>
>Since you're posting in English, is there any point in responding
>to it in English, and are non-Europeans eligible?  

It says, "bonne maîtrise de l'anglais écrit et parlé (toute autre langue sera 
un plus)"
so good mastery of English written and spoken is the main language requirement 
(stated, that is ;-)
But "capacité de dialoguer avec des usagers non techniques et tous les membres 
de l'équipe"
probably means French too ;-)

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

Re: Possible improvement to slice opperations.

2005-09-05 Thread Magnus Lycka
Ron Adam wrote:
> Slicing is one of the best features of Python in my opinion, but
> when you try to use negative index's and or negative step increments
> it can be tricky and lead to unexpected results.

Hm... Just as with positive indexes, you just need to understand
the concept properly.

> This topic has come up fairly often on comp.lang.python, and often 
> times, the responses include:
> 
> * Beginners should avoid negative extended slices.
> 
> * Slices with negative step increments are for advanced
>   python programmers.

I certainly wouldn't respond like that...

> * It's not broke if you look at it in a different way.
> 
> * You should do it a different way.

Those are correct, but need to be complemented with helpful
explanations. It's often like this, that we think things seem
strange, because we don't see it right. We need a new perspective.
For instance, it took me a long time to understand OOP, but once
the concept was clear, things fell into place. Often, we fail to
see things due to preconceptions that mislead us. Like Yoda said:
"You need to unlearn what you have learnt."

> - Extended slices with negative values return values that
>   have less items than currently.
> 
> - Slices with negative step values return entirely different
>   results.

Over my dead body! ;) Honestly, I can't imagine you'll get agreement
over such a change.

> REVERSE ORDER STEPPING
> --
> When negative steps are used, a slice operation
> does the following.  (or the equivalent)
> 
>1. reverse the list
>2. cut the reversed sequence using start and stop
>3. iterate forward using the absolute value of step.

I think you are looking at this from the wrong perspective.

Whatever sign c has:
For s[a:b:c], a is the index for the first item to include,
b is the item after the last to include (just like .end() in
C++ iterators for instance), and c describes the step size.

To get a non-empty result, you obviously must have a > b iff
c < 0.

a defaults to 0, b defaults to None (which represents the
item beyond the end of the sequence) and c defaults to 1.

This is basically all you need to understand before you use
a or b < 0. There are no special cases or exceptions.

The concept of negative indices are completely orthogonal
to the concept of slicing today. You can learn and
understand them independently, and will automatically
be able to understand how to use the concepts together,
iff you actually understood both concepts correctly.

>1. cut sequence using start and stop.
>2  reverse the order of the results.
>3. iterate forward using the absolute value of step.

With this solution, you suddenly have two different cases
to consider. You're suggesting that with c < 0, a should be
the end, and b should be the start. Now, it's no longer
obvious whether a or b should be excluded from the result.
I'm pretty sure the number of bugs and questions regarding
negative slices would grow quite a lot.

> CURRENT INDEXING
> 
> 
> Given a range [a,b,c]:
> 
>   Positive indexing
> 
>   | a | b | c |
>   +---+---+---+
>   0   1   2   3
> 
>   Current negative indexing.
> 
>   | a | b | c |
>   +---+---+---+
>  -3  -2  -1  -0

Almost right, there's no such thing as -0 in Python.
It's more like this:
 >   Current negative indexing.
 >
 >   | a | b | c |
 >   +---+---+---+
 >  -3  -2  -1  None
Of course, [a,b,c][None] won't work, since it would
access beyond the list. It actually returns a TypeError
rather than an IndexError, and you might argue whether this
is the right thing to do. No big deal in my opinion. For
slices, None works as intended, giving the default in all
three positions. Thid means that if you want a negative
index that might be "-0" for the slice end, you simply
write something like

seq[start:end or None]

> Accessing a range at the end of a list numerically
> becomes inconvenient when negative index's are used
> as the '-0'th position can not be specified numerically
> with negative values.

But None works as is...

> ONES BASED NEGATIVE INDEXING
> 
> Making negative index's Ones based, and selecting
> individual item to the left of negative index's would enable
> addressing the end of the list numerically.
> 
>   Ones based negative index's.
> 
>   | a | b | c |
>   +---+---+---+
>  -4  -3  -2  -1

Right. 0-based positive indices, and 1-based negative indices, but
you don't actually get the indexed value, but the one before...
I fear that your cure is worse then the "disease".

Today, a[x:x+1 or None] is always the same as [a[n]] for cases
where the latter doesn't yield an exception. With your change,
it won't be. That's not an improvement in my mind.

>a[-3:-2] -> b  # item between index's
But a[-3] -> a! Shrug!

> The '~' is the binary not symbol which when used
> with integers returns the two's compliment. This
> works nice with indexing from the end of a list
> because convieniently ~0 

Re: error when parsing xml

2005-09-05 Thread Diez B. Roggisch
Odd-R. wrote:
> This is retrieved through a webservice and stored in a variable test
> 
> 
> 
> 
> ]>
> æøå
> 
> printing this out yields no problems, so the trouble seems to be when 
> executing
> the following:
> 
> doc = minidom.parseString(test)

You need to do

doc = minidom.parseString(test.encode("utf-8"))

The reason is simple: test is not a string, but a unicode object. 
XML-Parsers work with strings - thus passing a unicode object to them 
will convert it - with the default encoding, which is ascii. BTW, I used 
  encode("utf-8") because the header of your documnet says so. If it 
were latin1, you'd need that. There is plenty of unicode-related 
material out there - use google to search this NG or the web.

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


Re: error when parsing xml

2005-09-05 Thread Diez B. Roggisch
> I have found that some people refuse to stick to standards, so whenever I
> parse XML files I remove any characters that fall in the range 
> <= 0x1f
> 
>>= 0xf0

Now of what help shall that be? Get rid of all accented characters? 
Sorry, but that surely is the dumbest thing to do here - and has 
_nothing_ to do with standards! Charactersets with codepoints > 128 are 
pretty common and well standarized, just not "ascii". I suggset you read 
up on the topic of unicode & encodings a bit - and then fix some code of 
yours...

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


Re: Warning when doubly linked list is defined gloablly

2005-09-05 Thread Peter Otten
chand wrote:

> Sorry for mailing the code which does't even compile !!

You probably missed that other hint where Fredrik Lunddh told you to
somewhat reduce the script's size.

> Please find below the code which compiles. Please let me know how to
> resolve this warning message..!!
> SyntaxWarning: name 'g_opt_list' is used prior to global declaration

This warning occurs if a global variable is used before it is declared as
such:

>>> def f():
... v = 42
... global v
...
:1: SyntaxWarning: name 'v' is assigned to before global declaration

This kind of code is dangerous because a casual reader might think that v is
a local variable. You can avoid the warning -- and the source of confusion
-- by moving the declaration to before the variable's first usage (I prefer
the top of the function):

>>> def f():
... global v
... v = 42
...

In your script things are even more messed up. You declare g_opt_list twice:

>>> def f():
... global v
... v = 42
... global v
...
:1: SyntaxWarning: name 'v' is assigned to before global declaration

Now that you understand the cause of the warning it is time to proceed to
yet another effbot hint: You never rebind the global variable g_opt_list
and therefore do not need the 

global g_opt_list

statement at all.

Peter

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


epydoc CLI and many files

2005-09-05 Thread Laszlo Zsolt Nagy
Hello,

I have a problem under Windows. I use the cli.py program included with 
epydoc. I wrote a small program that lists all of my modules after the 
cli. Something like this:

cli.py  --html  --inheritance=grouped module1.py module2.py module3.py 
..

The problem is that now I have so many modules that the shell (cmd.exe) 
cannot interpret this as a one command. It truncates the command line 
and gives me and error message. (cli.py does not start). Unfortunately, 
I cannot split the documentation into parts, because there are many 
crossreferences. How to overcome this problem?

  Les

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


newbie Q: mouse clicks don't seem to get trapped

2005-09-05 Thread mitsura
Hi,

I want to display a window containing an image and when I move the
mouse over the image and click on the left Mb, I want to get the
position of the mouse on the image.
I listed the code to view the image below (so far so good) but for some
reason the EVT_LEFT_DOWN/UP does not work.

Any idea what might be wrong?

With kind regards,

Kris



"
class DisplayPicture(wx.Frame):
  cD = 0
  # bmp = stream that contains the picture (not a filename!)
  # w,h: widht, height of the picture
  def __init__(self, parent, id, title, bmp, w, h):
 wxFrame.__init__(self,parent,wxID_ANY, title, size = ( w, h),
style=wxDEFAULT_FRAME_STYLE)


 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
 self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)

 Panel=wx.Panel(self)
 wx.StaticBitmap(Panel, -1, bmp, (5, 5) )

 self.Show()
 
  def OnLeftClick(self, event):
  print "ok" 
"

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


Re: Proposal: add sys to __builtins__

2005-09-05 Thread Sybren Stuvel
Rick Wotnaz enlightened us with:
> That is, a reference to xxx.func(), without a previous import of xxx
> *could* be resolvable automatically, at least for those modules that
> can be found in a standard location.

-1 on that one. If I want to use a module, I'll write an import
statement for it. Those import statements make it very easy to get an
overview of the modules in use.

Automatically importing modules has the counter-effect of not
generating errors when they should be. Someone could have a class
stored in a variable 'os' and call a function on it. If this person
forgets to assign a value to 'os', an error message should be given
instead of importing the 'os' module.

Another issue is speed. If every reference in the form xxx.yyy has to
trigger an import when xxx isn't known, it will probably slow down
programs quite badly.

A programming language should not be ambiguous. The choice between
importing a module and calling a function should not depend on the
availability of a (local) variable.

> I don't see why it would be impossible to make that happen
> automatically, provided the module to be imported was recognized
> (through some undefined magic).

The question is not if it's possible or not - in principle, everything
is possible. The question is if it is desirable.

> A developer would most likely want to set up the imports properly,
> and to know when they were not correctly set up instead of having
> Python fix things quietly.

Yep.

> But *could* it be done? I'd think so. 

Sure.

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Scott David Daniels
Magnus Lycka wrote:
> Ron Adam wrote:
>> ONES BASED NEGATIVE INDEXING

I think Ron's idea is taking off from my observation that if one's
complement, rather than negation, was used to specify measure-from-
right, we would have a simple consistent system (although I also
observed it is far too late to do that to Python now).  Using such
a system should not define things as below:

>>   | a | b | c |
>>   +---+---+---+
>>  -4  -3  -2  -1
but rather use a form like:
 >>   | a | b | c |
 >>   +---+---+---+
 >>  ~3  ~2  ~1  ~0

>> The '~' is the binary not symbol which when used
>> with integers returns the two's compliment. 
Actually, the ~ operator is the one's complement operator.

 > For calculated values on the slice borders, you still
 > have -1 as end value.
But if you are defining the from-right as ones complement,
you use one's complement on the calculated values and
all proceeds happily.  Since this could happen in Python,
perhaps we should call it Pythoñ.

>>a[1:~1] -> center, one position from both ends.
> 
> This is just a convoluted way of writing a[1:-2], which
> is exactly the same as you would write today.

Actually, a[1 : -1] is how you get to drop the first and
last characters today.  I suspect you knew this and were
just a bit in a hurry criticizing a lame-brained scheme.

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


Re: epydoc CLI and many files

2005-09-05 Thread Sybren Stuvel
Laszlo Zsolt Nagy enlightened us with:
> I wrote a small program that lists all of my modules after the 
> cli. Something like this:
>
> cli.py  --html  --inheritance=grouped module1.py module2.py module3.py 
> ..
>
> The problem is that now I have so many modules that the shell
> (cmd.exe) cannot interpret this as a one command.

Edit cli.py to get the list of modules from a call to glob.glob() or
stdin, instead of the commandline.

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


Re: Proposal: add sys to __builtins__

2005-09-05 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>,
 Rick Wotnaz <[EMAIL PROTECTED]> wrote:

> Michael Hoffman <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]: 
> 
> > What would people think about adding sys to __builtins__ so that
> > "import sys" is no longer necessary? This is something I must
> > add to every script I write that's not a one-liner since they
> > have this idiom at the bottom:
> > 
> > if __name__ == "__main__":
> >  sys.exit(main(sys.argv[1:]))
> > 
> > [...]
> > 
> > In short, given the wide use of sys, its unambiguous nature, and
> > the fact that it really is built-in already, although not
> > exposed as such, I think we would be better off if sys were
> > always allowed even without an import statement.
> 
> +1 here. As far as I'm concerned, both os and sys could be special-
> cased that way. That said, I would guess the likelihood of that 
> happening is 0.

While I'm mildly uncomfortable with the precedent that would be set by 
including the contents of "sys" as built-ins, I must confess my 
objections are primarily aesthetic:  I don't want to see the built-in 
namespace any more cluttered than is necessary -- or at least, any more 
than it already is.

But "os" is another matter -- the "os" module contains things which 
might well not be present in an embedded Python environment (e.g., file 
and directory structure navigation, stat).  Do you really want to force 
everyone to deal with that?  Is it so much more work to add "import os" 
to those Python programs that require it?

Of course, you might counter "why should we force everybody else to type 
`import os' just in case somebody wants to imbed Python?"  But then, why 
don't we just include the whole standard library in __builtins__?  Or, 
since that would be too much, maybe we survey the user community and 
include the top fifteen most included modules!  Where do you draw the 
line?  Do you really want to hard-code user opinions into the language?

Right now, we have a nice, simple yet effective mechanism for 
controlling the contents of our namespaces.  I don't think this would be 
a worthwhile change.  -1.

-M

-- 
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error when parsing xml

2005-09-05 Thread Richard Brodie

> > I have found that some people refuse to stick to standards, so whenever I
> > parse XML files I remove any characters that fall in the range
> > <= 0x1f
> >
> >>= 0xf0
>
> Now of what help shall that be? Get rid of all accented characters?
> Sorry, but that surely is the dumbest thing to do here - and has
> _nothing_ to do with standards!

Earlier versions of the Microsoft XML parser accept invalid characters
(e.g. most of those < 0x1f). Sadly, you do find files in the wild that need
to have these stripped before feeding them to a conforming parser.
One can be too enthusiastic about the process, though.


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


Re: simple question: $1, $2 in py ?

2005-09-05 Thread es_uomikim
Laszlo Zsolt Nagy wrote:

> Also try the OptParse module.
> 
> http://www.python.org/doc/2.4/lib/module-optparse.html
> 
> It handles the GNU/POSIX syntax very well.
> 
>  Les
> 

Oh thanx, that could be really helpfull : )

btw there was a great artist/photographer named: Laszlo Moholy-Nagy - 
simillar to You : )

greetz,
T


-- 
"Przyjacielu, lepiej nas dobrze wypieprz zamiast prawić nam kazania. 
Nawrócić nas nie zdołasz..." Marquis Donatien Alphonse François de Sade
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Job Offer in Paris, France : R&D Engineer (Plone)

2005-09-05 Thread Huron

> It says, "bonne maîtrise de l'anglais écrit et parlé (toute autre langue
> sera un plus)" so good mastery of English written and spoken is the main
> language requirement (stated, that is ;-) But "capacité de dialoguer avec
> des usagers non techniques et tous les membres de l'équipe" probably means
> French too ;-)

quite a good deduction ;-)

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


How to use the OS's native file selector in Tkinter

2005-09-05 Thread copx
Hi,

I would like to use the native file selector of the "host OS" for the "Open 
File" function of my Python/Tkinter app. Could anyone tell me how to do 
this?
My primary target platform is Windows. So a Windows-only solution would be 
ok (IIRC Linux doesn't even have a "native file selector").

copx


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


Re: Controlling memory allocation

2005-09-05 Thread cwoolf
Good to know that works :)

Did you also do the same for free and realloc to keep up with your
accounting?

The more I thought about it, the more I realized that calls to other
library functions could cause address space expansion if that code
internally called malloc or mmap.

See, I can use the OS to limit stack and data segment growth, but on OS
X/Darwin, it seems malloc uses mmap instead of brk to get more memory,
so setting a ulimit on the data segment doesn't work, because
technically the data segment doesn't grow during a malloc.  Setting a
ulimit on the RSS (resident set size) doesn't work either as that limit
seems to only limit the number of pages the process is allowed to touch
(keep resident in memory) and the address range is still allowed to
expand.

Chad

[EMAIL PROTECTED] wrote:
> Hello.
> I have done the thing you are requesting. You can easily create your
> own memory pool and have Python to use it.
>
> I added some rows to Pyconfig.h:
>
> #ifdef malloc
> #undef malloc
> #endif /*malloc*/
> #define malloc  Python_malloc
> 
> Then I have some overhead in my own Python_malloc(size_t nBytes)

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


Dr. Dobb's Python-URL! - weekly Python news and links (Sep 5)

2005-09-05 Thread Diez B. Roggisch
QOTW:  "You can lead an idiot to idioms, but you can't make him
think ;-)" -- Steve Holden 

"A foolish consistency is the hobgoblin of little minds." -- Ralph
Waldo Emerson (used by Tim Churches, and also found in
http://www.python.org/peps/pep-0008.html)


PyPy has come a long way - and made great progress with release 0.7:
http://groups.google.com/group/comp.lang.python/msg/5f12849e4c28fc6c 

Processing large XML files can be tedious, especially when using DOM.
Jog shows ways to do so, and ElementTree is as usual amongst the best,
both api- and performance-wise:
http://groups.google.com/group/comp.lang.python/msg/b1b259c448a867e9

Date processing is often way more difficult than one thinks - in
languages that don't have a rich date api like python,  that is:
http://groups.google.com/group/comp.lang.python/msg/9d125ca55b83b17a

Not exactly new, these new-style classes. But you can always find nifty
details you didn't know about:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/3fa6468b47d5334c/8118bfd6cf266c13#8118bfd6cf266c13

Congratulations to SpamBayes contributors on the announcement that
*Personal Computer World* awarded that project its "Editors' Choice"
award, besting competitors including products from Symantec, McAfee,
and so on:
http://pcw.co.uk

There is always room for new syntax proposals, like a "isa" keyword to
sugar isinstance - and while it's unlikely to become part of the
language, discussing it produces nice insights:
http://groups.google.com/group/comp.lang.python/msg/36b504905a36155d

Often requested, but never realized: a yield to yield them all.
Apparently this won't change soon, but yield itself is going to become
an expression: 
http://groups.google.com/group/comp.lang.python/msg/d66f346c98b8eac6

Using struct to marshal C-structures is easy - dealing with pointers
in them, too:
http://groups.google.com/group/comp.lang.python/msg/13eb61975154a25d



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
   

Re: Magic Optimisation

2005-09-05 Thread Paul McGuire
I still think there are savings to be had by looping inside the
try-except block, which avoids many setup/teardown exception handling
steps.  This is not so pretty in another way (repeated while on
check()), but I would be interested in your timings w.r.t. your current
code.

def loop(self):
self_pool_popleft = self.pool.popleft
self_pool_append = self.pool.append
self_call_exit_funcs = self.call_exit_funcs
check = self.pool.__len__
while check() > 0:
try:
while check() > 0:
task = self_pool_popleft()
task.next()
self_pool_append(task)
except StopIteration:
self_call_exit_funcs(task) 

-- Paul

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


Re: Magic Optimisation

2005-09-05 Thread Paul McGuire
Raymond Hettinger posted this recipe to the Python Cookbook.  I've not
tried it myself, but it sounds like what you're looking for.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940

-- Paul

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


Re: DrPython debugger

2005-09-05 Thread Pandiani
Thanks for repy.
However, I found SimpleDebugger 0.5 from sourceforge.net as plugin for
drPython but I'm getting error message because DrPython cannot load
module drPythonChooser and it seems that the module is removed from
latest version of drPython. Or maybe I wasn't able to figure out how to
install it...:)

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


Re: Has anybody tried to make a navigation like Google?

2005-09-05 Thread Will McGugan
Lad wrote:
> Hi,
> I would like to make in my web application a similar navigation like
> Google uses, I mean  at the bottom of each page there are numbers of
> returned pages after you search query.
> Has anyone tried that? Is there an algorithm for that? I do not want to
> re-invent the wheel.
> Thank you for help

I did something like that recently.

http://www.foodfileonline.com

Its not so complicated, you just need to know how many search results 
you have returned and how many are shown on each page. You will also 
need a search page that can start at a particular position in the results.


Will McGugan
--
http://www.kelpiesoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Has anybody tried to make a navigation like Google?

2005-09-05 Thread Mike C. Fletcher
Lad wrote:

>Hi,
>I would like to make in my web application a similar navigation like
>Google uses, I mean  at the bottom of each page there are numbers of
>returned pages after you search query.
>Has anyone tried that? Is there an algorithm for that? I do not want to
>re-invent the wheel.
>Thank you for help
>La.
>  
>
First the assumptions:

* We'll assume you're using SQL queries against a database
* You don't want to have to produce the whole result-set across the
  database interface, but you don't mind producing them on the
  database side
* You want precise values (Google's aren't precise measures of
  number of records)
  o If you don't, you can use whatever estimation mechanism you
like to get the total instead of a second query
* You have a complete ordering of records (if not then your results
  will randomly shuffle themselves as the user pages through)

Given that:

* You need to construct a query that produces (just) a count of all
  records in the set
* You then need a query that is parameterised to return a subset of
  the records in the set
  o offset -- count of records from the start of the set
  o limit -- number of records to display on any given page

Now, when you want to retrieve the records:

def search( self ):
"""Perform the search, retrieve records and total"""
self.records = self.SEARCH_QUERY(
connection,
whatToSelect = self.whatToSelectSubset,
limits = self.calculateLimits(),
orders = self.calculateOrders(),
wheres = self.calculateWheres(),
**self.queryParameters
)
for record in self.SEARCH_QUERY(
connection,
whatToSelect = self.whatToSelectCount,
limits = "",
orders = "",
wheres = self.calculateWheres(),
**self.queryParameters
):
self.total = record[0]

In that code the SEARCH_QUERY is a PyTable SQLQuery object, it just 
takes care of the cross-database substitution operations.  The code to 
handle the whatToSelect determination looks like this (by default):

keyColumnName = common.StringProperty(
"keyColumnName", """Column name used to count total number of 
columns""",
#define keyColumnName on Search!,
)
whatToSelectSubset = common.StringProperty(
"whatToSelectSubset", """What to select in the subset-of-records 
query""",
defaultValue = "*",
)
whatToSelectCount = common.StringProperty(
"whatToSelectCount", """What to select in the count-of-records 
query""",
defaultFunction = lambda prop,client: """COUNT(DISTINCT( %s 
))"""%(client.keyColumnName),
)

the wheres are the natural WHERE clauses you want to apply to the query 
(i.e. the search terms).  The orders are normally a default set of 
fields with the ability for the user to move any field to the front of 
the set via UI interactions.  The "limits" are actually both limits and 
orders in this example, since they are tied together as the paging 
functionality:

def calculateLimits( self ):
"""Calculate the limit/offset clauses for a select"""
return """LIMIT %s OFFSET %s"""%( self.limit, self.offset )

Just for completeness, here's an example of a SEARCH_QUERY:

SEARCH_QUERY = sqlquery.SQLQuery("""SELECT
%(whatToSelect)s
FROM
voip.voicemail JOIN  voip.voipfeature USING (voipfeature_id) 
JOIN voip.voipaccount USING (voipaccount_id)
%(wheres)s
%(orders)s
%(limits)s
""")

The UI then offers the user the ability to increase offset (page 
forward), decrease offset (page backward), and re-sort (change the 
ordering fields).  You disable the paging if you've reached either end 
of the record-set (offset<0 offset >= total-1), obviously.

Anyway, hope that helps,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: 'isa' keyword

2005-09-05 Thread Rocco Moretti
Colin J. Williams wrote:
> Rocco Moretti wrote:
> 
>> Terry Hancock wrote:
>>
>>> On Thursday 01 September 2005 07:28 am, Fuzzyman wrote:
>>>
 What's the difference between this and ``isinstance`` ?
>>>
>>> I must confess that an "isa" operator sounds like it would
>>> have been slightly nicer syntax than the isinstance() built-in
>>> function. But not enough nicer to change, IMHO.
>>
>> Especially conidering that checking parameters with "isinstance" is 
>> considered bad form with Python's duck typing.
> 
> Could you elaborate on that please?

I'm not sure if you're familiar with duck typing or not, so I'll 
summarize it briefly. (More detail can be found by others in the c.l.py 
archive.)

"Duck typing" takes its name from the expression "If it looks like a 
duck, walks like a duck, and quacks like a duck, it's a duck." That is, 
the essence of an object is not its provenance, but its behaviour. This 
arises in part from Python being dynamically typed - you don't have to 
match the type of an object in order to pass it as a parameter.

For example, say you had a function:

def fun(alist):
 for item in alist:
 doworkon(item)

The intended use of the function is for it to be passed a list, but you 
don't have to pass a list - it works just fine with a tuple, an 
iterator, a generator, a file object, a dictionary, or in fact any user 
defined class - all that's needed is for an appropriately defined 
__iter__ or __getitem__ member.

Now if you use isinstance, you mess that up:

def boring(alist):
 if isinstance(alist, list):
 for item in alist:
 doworkon(item)
 else:
 raise TypeError

This will only work with a bona fide list, and choke on the other 
objects - even objects intended by the programmer to act like a list.

Python functions are much more flexible if you don't go checking if an 
object is of a particular type. It makes things like using proxies, 
wrappers and mock objects much easier.

Best practices in Python call for using a parameter and catching when it 
doesn't behave properly, not prophylactically checking types. Python 
programmers can go months to years without using isinstance. It doesn't 
make sense to make it any easier.

P.S. In the OP's case, where it was desired to distinguish between being 
passed a string and being passed a list of strings, the approach used is 
probably sub-optimal. It would likely be better to have the function 
always take a "list", and convert all the fun('string') calls to 
fun(['string']) calls.
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting the bytes or percent uploaded/downloaded through FTP?

2005-09-05 Thread Nainto
Hi, I'm just wondering if there is any way to get the number of bytes,
or the percentage, that have been uploaded/downloaded when
uploading/downloading a file throught ftp in Python. I have searched
Google many times but could find nothing.

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


Re: Proposal: add sys to __builtins__

2005-09-05 Thread Rick Wotnaz
"Michael J. Fromberger"
<[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> In article <[EMAIL PROTECTED]>,
>  Rick Wotnaz <[EMAIL PROTECTED]> wrote:
> 
>> Michael Hoffman <[EMAIL PROTECTED]> wrote in
>> news:[EMAIL PROTECTED]: 
>> 
>> > What would people think about adding sys to __builtins__ so
>> > that "import sys" is no longer necessary? This is something I
>> > must add to every script I write that's not a one-liner since
>> > they have this idiom at the bottom:
>> > 
>> > if __name__ == "__main__":
>> >  sys.exit(main(sys.argv[1:]))
>> > 
>> > [...]
>> > 
>> > In short, given the wide use of sys, its unambiguous nature,
>> > and the fact that it really is built-in already, although not
>> > exposed as such, I think we would be better off if sys were
>> > always allowed even without an import statement.
>> 
>> +1 here. As far as I'm concerned, both os and sys could be
>> special- cased that way. That said, I would guess the
>> likelihood of that happening is 0.
> 
> While I'm mildly uncomfortable with the precedent that would be
> set by including the contents of "sys" as built-ins, I must
> confess my objections are primarily aesthetic:  I don't want to
> see the built-in namespace any more cluttered than is necessary
> -- or at least, any more than it already is.
> 
> But "os" is another matter -- the "os" module contains things
> which might well not be present in an embedded Python
> environment (e.g., file and directory structure navigation,
> stat).  Do you really want to force everyone to deal with that? 
> Is it so much more work to add "import os" to those Python
> programs that require it? 
> 
> Of course, you might counter "why should we force everybody else
> to type `import os' just in case somebody wants to imbed
> Python?"  But then, why don't we just include the whole standard
> library in __builtins__?  Or, since that would be too much,
> maybe we survey the user community and include the top fifteen
> most included modules!  Where do you draw the line?  Do you
> really want to hard-code user opinions into the language? 
> 
> Right now, we have a nice, simple yet effective mechanism for 
> controlling the contents of our namespaces.  I don't think this
> would be a worthwhile change.  -1.
> 

You're right that there is no necessity for such a change. I was 
not actually talking about importing *any* module in every case, 
but rather about importing, say, 'sys' when, for example, sys.argv 
appeared in the code and no import had been specified. In another 
post I go into a little more detail about what I meant, but in any 
case I did not and do not think it's necessary. I have no problem 
keying in the import statement and the current system works fine. 
It could be argued that it would be convenient in the case of quick 
utility code not to have to import well-known modules explicitly, 
and it could be argued that 'sys' in particular contains much that 
is so seemingly fundamental that it could be built in. I'd not 
argue that it should be split out if it were already built in; it 
seems to be borderline standard as it is. I suppose it's a C 
mindset talking, there.

When I'm cobbling together a Q&D script, my routine often involves 
running it once and then going back in and inserting the single 
import line that I forgot. It's a minor annoyance, because it seems 
clear to me that the needed information is actually available to 
Python when it kicks out its NameError. But it *is* minor, and I am 
not seriously proposing a change to Python in this regard.

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


Dr. Dobb's Python-URL! - weekly Python news and links (Sep 5)

2005-09-05 Thread Diez B. Roggisch
QOTW:  "You can lead an idiot to idioms, but you can't make him
think ;-)" -- Steve Holden 

"A foolish consistency is the hobgoblin of little minds." -- Ralph
Waldo Emerson (used by Tim Churches, and also found in
http://www.python.org/peps/pep-0008.html)


PyPy has come a long way - and made great progress with release 0.7:
http://groups.google.com/group/comp.lang.python/msg/5f12849e4c28fc6c 

Processing large XML files can be tedious, especially when using DOM.
Jog shows ways to do so, and ElementTree is as usual amongst the best,
both api- and performance-wise:
http://groups.google.com/group/comp.lang.python/msg/b1b259c448a867e9

Date processing is often way more difficult than one thinks - in
languages that don't have a rich date api like python,  that is:
http://groups.google.com/group/comp.lang.python/msg/9d125ca55b83b17a

Not exactly new, these new-style classes. But you can always find nifty
details you didn't know about:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/3fa6468b47d5334c/8118bfd6cf266c13#8118bfd6cf266c13

Congratulations to SpamBayes contributors on the announcement that
*Personal Computer World* awarded that project its "Editors' Choice"
award, besting competitors including products from Symantec, McAfee,
and so on:
http://pcw.co.uk

There is always room for new syntax proposals, like a "isa" keyword to
sugar isinstance - and while it's unlikely to become part of the
language, discussing it produces nice insights:
http://groups.google.com/group/comp.lang.python/msg/36b504905a36155d

Often requested, but never realized: a yield to yield them all.
Apparently this won't change soon, but yield itself is going to become
an expression: 
http://groups.google.com/group/comp.lang.python/msg/d66f346c98b8eac6

Using struct to marshal C-structures is easy - dealing with pointers
in them, too:
http://groups.google.com/group/comp.lang.python/msg/13eb61975154a25d



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
   

Re: Getting the bytes or percent uploaded/downloaded through FTP?

2005-09-05 Thread Benji York
[EMAIL PROTECTED] wrote:
> Hi, I'm just wondering if there is any way to get the number of bytes,
> or the percentage, that have been uploaded/downloaded when
> uploading/downloading a file throught ftp in Python. I have searched
> Google many times but could find nothing.

If you're using urllib you can do something like this:

def reporter(block, block_size, total_size):
 left = total_size - block * block_size
 sys.stderr.write('\r')
 sys.stderr.write('Downloading %s: ' % file_name)
 if left > 0: # the estimate is a bit rough, so we fake it a little
 sys.stderr.write('%sK left.' % (left/1024))
 else:
 sys.stderr.write('done.')

 # it's possible that this line is shorter than the previous,
 # so we need to "erase" any leftovers
 sys.stderr.write(' '*10)
 sys.stderr.write('\b'*10)

import urllib
urllib.urlretrieve(url, destination, reporter)
sys.stderr.write('\n')
--
Benji York

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


Re: How to use the OS's native file selector in Tkinter

2005-09-05 Thread jepler
tkFileDialog.Open is a wrapper around tk's tk_getOpenFile.

tk_getOpenFile uses the native dialog on Windows, via the GetOpenFileName()
win32 API call, at least in Tk versions 8.2 and newer.

Jeff


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

Re: DrPython debugger

2005-09-05 Thread Franz Steinhaeusler
On 5 Sep 2005 07:36:18 -0700, "Pandiani" <[EMAIL PROTECTED]> wrote:

>Thanks for repy.
>However, I found SimpleDebugger 0.5 from sourceforge.net as plugin for
>drPython but I'm getting error message because DrPython cannot load
>module drPythonChooser and it seems that the module is removed from
>latest version of drPython. Or maybe I wasn't able to figure out how to
>install it...:)

Sorry for the misinformation.
This SimpleDebugger is out of date for a longer time.

Maybe you make a bug report about this?


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


Re: Getting the bytes or percent uploaded/downloaded through FTP?

2005-09-05 Thread Nainto
Thanks, Benji but I need to be able to get the bytes and/or percent of
a download too. :-(

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


Re: 'isa' keyword

2005-09-05 Thread D H
Colin J. Williams wrote:
> Could you elaborate on that please?

See my earlier post in this thread, this link:
http://www.canonical.org/~kragen/isinstance/
-- 
http://mail.python.org/mailman/listinfo/python-list


command line path

2005-09-05 Thread mclaugb
I am trying to pass the name of several files to a python script as command 
line arguments.  When i type in


python ImportFiles_test.py C:\Program Files\National Instruments\LabVIEW 
7.1\project\calibration\FREQUENCY_
13.CSV

The following error results:

C:\Program Traceback (most recent call last):
  File "C:\Documents and Settings\bm304.BRYANPC\My 
Documents\Python\ImportFiles_test.py", line 10, in ?
input = open(file1, 'rb');
IOError: [Errno 2] No such file or directory: 'C:\\Program'

I debugged a little and what is happening is the space in "c:\Program Files" 
and "...\National Instruments..\" is being parsed as separate arguments and 
i only wish for them to be parsed as one.

How do I get pass a path string containing spaces?

Regards,
Bryan 


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


logging into one file problem

2005-09-05 Thread Maksim Kasimov

hello

in my modules, I'm using logging module, doing thus (there is a few modules):


in module1.py:
hdl = logging.StreamHandler()
fmt = logging.Formatter("%(name)s:\t%(levelname)s:\t%(asctime)s:\t%(message)s")
hdl.setFormatter(fmt)
log = logging.getLogger('module1')
log.addHandler(hdl)



In script, which is uses these modules, I'm doing in a similar way:


in script.py:
hdl = logging.StreamHandler()
fmt = logging.Formatter("%(name)s:\t%(levelname)s:\t%(asctime)s:\t%(message)s")
hdl.setFormatter(fmt)
log = logging.getLogger('script')
log.addHandler(hdl)



Than, to direct all output into one log-file I'm doing like this:

script.py >> script.log 2>&1


All works as expected - all output in one file (script.log), but only until 
syslog will rotate script.log, than output to log-file stops.

How to avoid this situation?

i can't using something like this:

hdl = logging.FileHandler('script.log')

because modules are used in other scripts, and log output of each application 
must be in different files.

and doing in script.py like this:

module.hdl = hdl
module.log = log

will works, but it is very inconvenient, because in main script, i'm not 
importing all the modules (some modules imported by other modules).


thanks for help.

Python 2.2.3
FreeBSD


-- 
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: command line path

2005-09-05 Thread Diez B. Roggisch
> 
> I debugged a little and what is happening is the space in "c:\Program Files" 
> and "...\National Instruments..\" is being parsed as separate arguments and 
> i only wish for them to be parsed as one.
> 
> How do I get pass a path string containing spaces?

Surround it with double quotes. This is no python issue, it's part of 
your shell. Under unix (or cygwin) , you could also use '\ ' to escape 
the single spaces.

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


Re: command line path

2005-09-05 Thread Lee Harr
On 2005-09-05, mclaugb <[EMAIL PROTECTED]> wrote:
> I am trying to pass the name of several files to a python script as command 
> line arguments.  When i type in
>
>
> python ImportFiles_test.py C:\Program Files\National Instruments\LabVIEW 
> 7.1\project\calibration\FREQUENCY_
> 13.CSV
>
> The following error results:
>
> C:\Program Traceback (most recent call last):
>   File "C:\Documents and Settings\bm304.BRYANPC\My 
> Documents\Python\ImportFiles_test.py", line 10, in ?
> input = open(file1, 'rb');
> IOError: [Errno 2] No such file or directory: 'C:\\Program'
>
> I debugged a little and what is happening is the space in "c:\Program Files" 
> and "...\National Instruments..\" is being parsed as separate arguments and 
> i only wish for them to be parsed as one.
>
> How do I get pass a path string containing spaces?
>


Try quotes ...

python "ImportFiles_test.py C:\Program Files\National Instruments\LabVIEW 
7.1\project\calibration\FREQUENCY_13.CSV"

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Steve Holden
Scott David Daniels wrote:
> Magnus Lycka wrote:
[...]
>>>The '~' is the binary not symbol which when used
>>>with integers returns the two's compliment. 
> 
> Actually, the ~ operator is the one's complement operator.
> 
Actually the two are exactly the same thing. Could we argue about 
substantive matters, please? ;-)

>  > For calculated values on the slice borders, you still
>  > have -1 as end value.
> But if you are defining the from-right as ones complement,
> you use one's complement on the calculated values and
> all proceeds happily.  Since this could happen in Python,
> perhaps we should call it Pythoñ.
> 
:-) And how would that be pronounced? I understood that "ñ" would only 
appear between two vowels.
> 
>>>   a[1:~1] -> center, one position from both ends.
>>
>>This is just a convoluted way of writing a[1:-2], which
>>is exactly the same as you would write today.
> 
It does have the merit (if you think of it as a merit) of allowing 
someone to write

 a[n, ~n]

to remove n characters from each end of the string. Frankly I'd rather 
deal with the Python that exists now than wrap my head around this 
particular suggestion.
> 
> Actually, a[1 : -1] is how you get to drop the first and
> last characters today.  I suspect you knew this and were
> just a bit in a hurry criticizing a lame-brained scheme.
> 
Yes, I've been surprised how this thread has gone on and on.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


improvements for the logging package

2005-09-05 Thread Rotem
Hi,

while working on something in my current project I have made several
improvements to the logging package in Python, two of them are worth
mentioning:
1. addition of a logging record field %(function)s, which results in
the name
of the entity which logged the record. My version even deduces the
class name in the case which the logger is a bound method, and assuming
the name of the "self" variable is indeed "self".

This ability can be turned off, for performance reasons, and is useful
for debugging phases.

2. log coloring formatter (useful for console output) - support for log
lines like BLUE<>, etc.

Now, I asked several friends of mine who program in Python often, and
they told me they could use these features very much.

I'm taking a risk here, that maybe someone already proposed this in
this group, but I'll ask either way:
Has anyone thought of posting a PEP about this? Do you think I should?

I have made a great use of the logging package, and would certainly
like to see it evolve and include more features.

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Ron Adam
Scott David Daniels wrote:

> Magnus Lycka wrote:
> 
>> Ron Adam wrote:
>>
>>> ONES BASED NEGATIVE INDEXING
> 
> 
> I think Ron's idea is taking off from my observation that if one's
> complement, rather than negation, was used to specify measure-from-
> right, we would have a simple consistent system (although I also
> observed it is far too late to do that to Python now).  Using such
> a system should not define things as below:

I didn't start with your observation in mind, but it ended up there 
because the only way to extend the indexes past the last item is to not 
use 0 along with negative index's.  And once that's done the '~' forms 
"just work" without any additional changes.  ;-)

Yes, it may be too late for changing Python's built in indexing. And it 
may also be that the majority may rather use it as is, rather than 
change it to fix this edge case.


>>>   | a | b | c |
>>>   +---+---+---+
>>>  -4  -3  -2  -1
> 
> but rather use a form like:
>  >>   | a | b | c |
>  >>   +---+---+---+
>  >>  ~3  ~2  ~1  ~0
> 
>>> The '~' is the binary not symbol which when used
>>> with integers returns the two's compliment. 
> 
> Actually, the ~ operator is the one's complement operator.

Yes, thanks, my mistake.


>  > For calculated values on the slice borders, you still
>  > have -1 as end value.
> But if you are defining the from-right as ones complement,
> you use one's complement on the calculated values and
> all proceeds happily.  Since this could happen in Python,
> perhaps we should call it Pythoñ.
> 
>>>a[1:~1] -> center, one position from both ends.
>>
>>
>> This is just a convoluted way of writing a[1:-2], which
>> is exactly the same as you would write today.
> 
> 
> Actually, a[1 : -1] is how you get to drop the first and
> last characters today.  I suspect you knew this and were
> just a bit in a hurry criticizing a lame-brained scheme.
> 
> -Scott David Daniels
> [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


xmlrcp register classes

2005-09-05 Thread Sergio Rua
Hello,

I have a structured program with several classes which I would like to
export using a xmlrpc server. I'm doing this

Server = SimpleXMLRPCServer (('127.0.0.1',8080))

Server.register_instance(MyClass1())
Server.register_instance(MyClass2())
Server.register_instance(MyClass3())

What is seems to happen is that only the last class I register it is the
only one being exported. How can I register all the classes? Thanks.

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


Re: xmlrcp register classes

2005-09-05 Thread Brian Quinlan
Sergio Rua wrote:
> Server = SimpleXMLRPCServer (('127.0.0.1',8080))
> 
> Server.register_instance(MyClass1())
> Server.register_instance(MyClass2())
> Server.register_instance(MyClass3())
> 
> What is seems to happen is that only the last class I register it is the
> only one being exported. How can I register all the classes? Thanks.

class MyCombinedClass(MyClass1, MyClass2, MyClass3):
 pass

Server.register_instance(MyCombinedClass())

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Fredrik Lundh
Steve Holden wrote:

> Yes, I've been surprised how this thread has gone on and on.

it's of course a variation of

"You can lead an idiot to idioms, but you can't make him
think ;-)"

as long as you have people that insist that their original misunderstandings
are the only correct way to model the real world, and that all observed
inconsistencies in their models are caused by bugs in the real world, you'll
end up with threads like this.

 



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


Re: Getting the bytes or percent uploaded/downloaded through FTP?

2005-09-05 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Thanks, Benji but I need to be able to get the bytes and/or percent of
> a download too. :-(
> 
The only way I can think of to get the size of the file you're about to 
download is using the FTP object's .dir() method. If you have the Tools 
directory (standard on Windows, with source on other platforms) you can 
take a look at the ftpmirror script - a fairly recent version can be seen at

 http://weblog.cs.uiowa.edu/python-2.3.1/Tools/scripts/ftpmirror.py

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: newbie Q: mouse clicks don't seem to get trapped

2005-09-05 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Hi,
> 
> I want to display a window containing an image and when I move the
> mouse over the image and click on the left Mb, I want to get the
> position of the mouse on the image.
> I listed the code to view the image below (so far so good) but for some
> reason the EVT_LEFT_DOWN/UP does not work.
> 
> Any idea what might be wrong?
> 
> With kind regards,
> 
> Kris
> 
> 
> 
> "
> class DisplayPicture(wx.Frame):
>   cD = 0
>   # bmp = stream that contains the picture (not a filename!)
>   # w,h: widht, height of the picture
>   def __init__(self, parent, id, title, bmp, w, h):
>wxFrame.__init__(self,parent,wxID_ANY, title, size = ( w, h),
> style=wxDEFAULT_FRAME_STYLE)
> 
> 
>  self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
>  self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)
> 
>  Panel=wx.Panel(self)
>  wx.StaticBitmap(Panel, -1, bmp, (5, 5) )
> 
>  self.Show()
>  
>   def OnLeftClick(self, event):
> print "ok" 
> "
> 
Without actually running the code (so this may not help), have you 
considered binding the events to the panel rather than the frame?

In other words, change

  self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
  self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)

  Panel=wx.Panel(self)

to

  Panel=wx.Panel(self)

  Panel.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
  Panel.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: Getting the bytes or percent uploaded/downloaded through FTP?

2005-09-05 Thread Fredrik Lundh
Steve Holden wrote:

> The only way I can think of to get the size of the file you're about to
> download is using the FTP object's .dir() method. If you have the Tools
> directory (standard on Windows, with source on other platforms) you can
> take a look at the ftpmirror script - a fairly recent version can be seen at
>
> http://weblog.cs.uiowa.edu/python-2.3.1/Tools/scripts/ftpmirror.py

to handle arbitrary servers, you also need a flexibel LIST response
parser; see:

http://cr.yp.to/ftpparse.html

python bindings:

http://c0re.23.nu/c0de/ftpparsemodule/

and

http://effbot.org/downloads/#ftpparse

 



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


Re: dual processor

2005-09-05 Thread Nick Craig-Wood
Scott David Daniels <[EMAIL PROTECTED]> wrote:
>  Nick Craig-Wood wrote:
> > Splitting the GIL introduces performance and memory penalties
> > However its crystal clear now the future is SMP.  Modern chips seem to
> > have hit the GHz barrier, and now the easy meat for the processor
> > designers is to multiply silicon and make multiple thread / core
> > processors all in a single chip.
> > So, I believe Python has got to address the GIL, and soon.
>  However, there is no reason to assume that those multiple cores must
>  work in the same process.

No of course not.  However if they aren't then you've got the horrors
of IPC to deal with!  Which is difficult to do fast and portably. Much
easier to communicate with another thread, especially with the lovely
python threading primitives.

>  One of the biggest issues in running python in multiple
>  simultaneously active threads is that the Python opcodes themselves
>  are no longer indivisible.  Making a higher level language that
>  allows updates work with multiple threads involves lots of
>  coordination between threads simply to know when data structures
>  are correct and when they are in transition.

Sure!  No one said it was easy.  However I think it can be done to all
of python's native data types, and in a way that is completely
transparent to the user.

>  Even processes sharing some memory (in a "raw binary memory" style) are
>  easier to write and test.  You'd lose too much processor to coordination
>  effort which was likely unnecessary.  The simplest example I can think
>  of is decrementing a reference count.  Only one thread can be allowed to
>  DECREF at any given time for fear of leaking memory, even though it will
>  most often turn out the objects being DECREF'ed by distinct threads are
>  themselves distinct.

Yes locking is expensive.  If we placed a lock in every python object
that would bloat memory usage and cpu time grabbing and releasing all
those locks.  However if it meant your threaded program could use 90%
of all 16 CPUs, rather than 100% of one I think its obvious where the
payoff lies.

Memory is cheap.  Multiple cores (SMP/SMT) are everywhere!

>  In short, two Python threads running simultaneously cannot trust
>  that any basic Python data structures they access are in a
>  consistent state without some form of coordination.

Aye, lots of locking is needed.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible improvement to slice opperations.

2005-09-05 Thread Ron Adam
Szabolcs Nagy wrote:

> with the current syntax L[i:i+1] returns [L[i]], with nxlist it returns
> L[i+1] if i<0.
> 
> L=range(10)
> L[1:2]==[L[1]]==[1]
> L[-2:-1]==[L[-2]]==[8]
> 
> L=nxlist(range(10))
> L[1:2]==[L[1]]==[1]
> L[-2:-1]==[L[-1]]==[9] # not [L[-2]]
> 
> IMHO in this case current list slicing is more consistent.


Your second case should be:
L[-3:-2]==[L[-2]]==[8]

The single index is also the right side index of the range selection 
ending in the same position just as with positive number the single 
index is the left side index of a range starting in the same position.

So for positive indexing...
L[n1:n2]==[L[n1]]==first value of selection from left

and negative indexing...
L[n1:n2]==[L[n2]]==first value of selection from right


Currently for negative values...

L[n1:n2]==[L[n2-1]]==first value of selection from right


The symmetry is easier to see when using the '~' values.

LL=list(range(10))
Lx=nxlist(range(10))

LL[ 1: 2]==[LL[ 1]]==[1]
Lx[~2:~1]==[Lx[~1]]==[8]


Cheers,
Ron

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Ron Adam
Magnus Lycka wrote:

> Ron Adam wrote:
> 
>> Slicing is one of the best features of Python in my opinion, but
>> when you try to use negative index's and or negative step increments
>> it can be tricky and lead to unexpected results.
> 
> 
> Hm... Just as with positive indexes, you just need to understand
> the concept properly.
> 
>> This topic has come up fairly often on comp.lang.python, and often 
>> times, the responses include:
>>
>> * Beginners should avoid negative extended slices.
>>
>> * Slices with negative step increments are for advanced
>>   python programmers.
> 
> 
> I certainly wouldn't respond like that...
> 
>> * It's not broke if you look at it in a different way.
>>
>> * You should do it a different way.
> 
> 
> Those are correct, but need to be complemented with helpful
> explanations. It's often like this, that we think things seem
> strange, because we don't see it right. We need a new perspective.
> For instance, it took me a long time to understand OOP, but once
> the concept was clear, things fell into place. Often, we fail to
> see things due to preconceptions that mislead us. Like Yoda said:
> "You need to unlearn what you have learnt."

To me, seeing a lot responses of this sort is an indicator it needs to 
be simplified/or that something isn't right about them.  They shouldn't 
be that difficult to use or explain.

>> - Extended slices with negative values return values that
>>   have less items than currently.
>>
>> - Slices with negative step values return entirely different
>>   results.
> 
> 
> Over my dead body! ;) Honestly, I can't imagine you'll get agreement
> over such a change.

Yet, your description of how it works below is closer to what I'm 
proposing than how they currently work.


>> REVERSE ORDER STEPPING
>> --
>> When negative steps are used, a slice operation
>> does the following.  (or the equivalent)
>>
>>1. reverse the list
>>2. cut the reversed sequence using start and stop
>>3. iterate forward using the absolute value of step.
> 
> 
> I think you are looking at this from the wrong perspective.
> 
> Whatever sign c has:
> For s[a:b:c], a is the index for the first item to include,
> b is the item after the last to include (just like .end() in
> C++ iterators for instance), and c describes the step size.

Yes, and that is how it "should" work.  But

With current slicing and a negative step...

[   1   2   3   4   5   6   7   8   9  ]
  -9  -8  -7  -6  -5  -4  -3  -2  -1  -0

r[-3:]  ->  [7, 8, 9]# as expected
r[-3::-1] ->  [7, 6, 5, 4, 3, 2, 1, 0]   # surprise

The seven is include in both cases, so it's not a true inverse selection 
either.

In most cases, negative step (or stride) values are used
to reverse the whole lists, so this issue doesn't come up.



> To get a non-empty result, you obviously must have a > b iff
> c < 0.
> 
> a defaults to 0, b defaults to None (which represents the
> item beyond the end of the sequence) and c defaults to 1.
> 
> This is basically all you need to understand before you use
> a or b < 0. There are no special cases or exceptions.

See above. ;-)


> The concept of negative indices are completely orthogonal
> to the concept of slicing today. You can learn and
> understand them independently, and will automatically
> be able to understand how to use the concepts together,
> iff you actually understood both concepts correctly.

It's easy to think you understand something when you don't. I spend 
quite a while figuring this out, And am sure about how it works. If 
there are issues with this, then it will probably be in how I describe 
it, what words or terminology is used, and weather or not it's the 
proper approach.

There are actually two distinct proposals here, not just one.

 1. Fixing negative strides so they return the slice indexed as you 
say they should.

 2. Using base one negative index's and picking item from the right 
of negative index's instead of the right.


They don't both need to implemented, Item 1 could be fixed in 2.5.

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


Re: xmlrcp register classes

2005-09-05 Thread Sergio Rua
Hello,

> class MyCombinedClass(MyClass1, MyClass2, MyClass3):
> pass
> 
> Server.register_instance(MyCombinedClass())

That was easy :) Thanks a lot.

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


Re: simple question: $1, $2 in py ?

2005-09-05 Thread Lee Harr
On 2005-09-05, es_uomikim <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have one small simple question, that I didn't found answer in 
> google's. It's kind of begginers question because I'm a one. ; )
>
> I wanned to ask how to use scripts with vars on input like this:
>
> $ echo "something" | ./my_script.py
>
> or:
>
> $ ./my_scripy.py var1 var2
>
>
> As far as I understand there's no $1, $2... etc stuff right ?
>


Others answered about commandline args... You can also read
from stdin to get the piped input:



# pi.py
import sys
i = sys.stdin.read()
print "Your input: ", i


> echo "something" | python pi.py
Your input:  something




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


Newbie: Datetime, "Prog. in Win32", and how Python thinks

2005-09-05 Thread Max Yaffe
Dear Group,

First of all, thanks for all the postings about Datetime.  They've
helped alot.

I'm a newbie to Python (albeit very experienced in programming C & OO)
and trying to use "Programming in Win32"  by Hammond  & Robinson [H&R]
to learn it.  This may be a mistake since I think it refers to Python
1.5.2 while I'm trying to use Python 2.4.x.  Anyway...

1) H&R import a module "dates' which has been dropped.  They use
sec2asc which is also m.i.a.  I assume that the code should be adapted
to use module datetime.  Is that correct?

2) Is there any list of dead modules & names from previous revs?  Is
there any list of currently recommended modules?

3) I was able to import datetime & get a dir(datetime) to work.
Great.  But where is the actual code to datetime?  I can't find a
module named datetime.py in the library.  I grepped for datetime in
the library & found plenty of references to it but no module
definition.  Where is it defined?

4) How does the python interpreter resolve the statement "import
datatime"?

Thanks,
Max


Code don't lie.   Manuals Lie.   I'm highly suspicious of browsers.

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Ron Adam
Fredrik Lundh wrote:

> Steve Holden wrote:
> 
> 
>>Yes, I've been surprised how this thread has gone on and on.
> 
> 
> it's of course a variation of
> 
> "You can lead an idiot to idioms, but you can't make him
> think ;-)"
> 
> as long as you have people that insist that their original misunderstandings
> are the only correct way to model the real world, and that all observed
> inconsistencies in their models are caused by bugs in the real world, you'll
> end up with threads like this.
> 
>  

Ok, -1 from both Fredrik and Steven

No problem,

But I think you are mistaken that I don't understand how slicing works. 
(IMHO of course) ;-)


A more valid argument against this would be that more users may prefer 
the current zero based, select to the right, indexing than have to 
remember to subtract one from negative index's or use '~'.

I'm completely aware of that, and don't argue that that viewpoint is valid.

It also has backwards compatibility issues as well.  Which is probably 
enough in itself to kill it as a PEP.


However, I would like the inverse selection of negative strides to be 
fixed if possible.  If you could explain the current reason why it does 
not return the reverse order of the selected range.  I would appreciated it.

Cheers,
Ron








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


Re: dual processor

2005-09-05 Thread Paul Rubin
Nick Craig-Wood <[EMAIL PROTECTED]> writes:
> >  of is decrementing a reference count.  Only one thread can be allowed to
> >  DECREF at any given time for fear of leaking memory, even though it will
> >  most often turn out the objects being DECREF'ed by distinct threads are
> >  themselves distinct.
> 
> Yes locking is expensive.  If we placed a lock in every python object
> that would bloat memory usage and cpu time grabbing and releasing all
> those locks.  However if it meant your threaded program could use 90%
> of all 16 CPUs, rather than 100% of one I think its obvious where the
> payoff lies.

Along with fixing the GIL, I think PyPy needs to give up on this
BASIC-style reference counting and introduce real garbage collection.
Lots of work has been done on concurrent GC and the techniques for it
are reasonably understood by now, especially if there's no hard
real-time requirement.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Job Offer in Paris, France : R&D Engineer (Plone)

2005-09-05 Thread Paul Rubin
Huron <[EMAIL PROTECTED]> writes:
> > Since you're posting in English, is there any point in responding
> > to it in English, and are non-Europeans eligible?
> 
> I'm afraid not. The team is too small to welcome remote work at the present
> time ... 

Working remotely hadn't occurred to me ;-).  I was wondering 

1) whether there would be legal or procedural obstacles for a
non-European wanting to work in Paris for a while; and

2) whether it was mandatory to be able to speak and write in French (I
can do so, but very badly for now).  I'm sure you will get lots of
good French-speaking candidates though.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >