Re: C++ code generation

2010-03-16 Thread Stefan Behnel

CHEN Guang, 17.03.2010 02:54:

- Original Message -
From: "Dan Goodman"


I'm doing some C++ code generation using Python, and would be interested
in any comments on the approach I'm taking.


PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++)


It would be nice if you could start reading the posts before you answer, 
and then try to give an answer that fits the question.


Stefan

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


Re: import antigravity

2010-03-16 Thread Stefan Behnel

Michael Rudolf, 17.03.2010 00:48:

Am 16.03.2010 21:44, schrieb Mark Lawrence:

Who actually *IS* running the time machine? Are there any bugs??


My is. And as I'm a lazy hacker: sure. there are bugs. lets just call
them features and move on. nothing to see here ;)


I'll know it, I'll just know it!

Stefan

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


Re: C-API PyObject_Call

2010-03-16 Thread Stefan Behnel

moerchendiser2k3, 16.03.2010 19:25:

Hi, currently I am not at home, I will post some stuff when I am back.
Just the note: I throw an exception with the C API.

Looks like that


PyObject *result = PyObject_Call(my_isntance, "", NULL);
if(result==NULL)
{
 PyErr_Print(); //when this happens, the traceback is correct with
information about the file/line
 return;
}

if(!PyXYZ_Check(result))
{
 PyErr_SetString(PyExc_TypeError, "Wrong type, ");
 PyErr_Print(); //missing information of the file/line.
 return;
}

Well, I expect, that there are no information about the line/file, so
I know something is missing, but what is missing?


Two solutions here:

1) put the line number information into the message string when you raise 
the exception


2) use Cython instead of plain C, as Cython will automatically generate 
readable stack traces for you, also for non-Python functions.


Stefan

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


Re: Converting Python CGI to WSGI scripts

2010-03-16 Thread John Nagle

Sebastian Bassi wrote:

On Tue, Mar 16, 2010 at 2:18 PM,   wrote:

I have a few dozen simple Python CGI scripts.
Are there any advantages or disadvantages to rewriting these CGI scripts as
WSGI scripts?


It depends of the script. WSGI should be faster since you don't start
a Python instance for each call (as in CGI).


   It's almost always faster.  But be careful about global state.
Remember that WSGI/FCGI programs are really functions, called
over and over with a new transaction on each call.  So your
function has to be reusable.

   Things like initializing global variables at program load time,
rather than when the main function is called, may give trouble.
Also, be careful about leaving files, database connections, and
sockets open after the main function returns.

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


Re: Dynamic Class Creation

2010-03-16 Thread Josh English
Chris,

Thanks. This worked for the attributes, but I think the tactic is
still misleading. There are child elements I can't quite determine how
to deal with:


Analog Science Fiction and Fact
Analog
Science Fiction
First Contact
Hard Science Fiction

Stanley Schmidt, Editor
267 Broadway, 4th Floor
New York, NY 10007-2352

http://www.analogsf.com


A child element with text and an attribute or two, for example, pose a
problem. I can call Market.title but should I try Market.title.field
or Market.title_field.

Multiple elements, such as keywords, are allowed in xml but harder to
map to the object. I don't know if I want to go create a list and
methods for accessing those keywords as a list, or redefine the rules
of my XML to not allow multiple child elements with the same tag. I
can't decide.

Then the address is a bit of a bear.

In short, I have to figure out the whole object interface to the XML
and how I want that to work.

Thanks for the suggestion. It is undeniably clever.

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


Re: to pass self or not to pass self

2010-03-16 Thread Patrick Maupin
On Mar 16, 1:59 pm, Jason Tackaberry  wrote:
> Why not create the bound methods at instantiation time, rather than
> using the descriptor protocol which has the overhead of creating a new
> bound method each time the method attribute is accessed?

Well, for one thing, Python classes are open.  They can be added to at
any time.  For another thing, you might not ever use most of the
methods of an instance, so it would be a huge waste to create those.

Also, this area has been optimized for normal usage patterns quite
heavily, to the point where attempted "optimizations" can lead to
results that are, on the surface, quite counterintuitive.

For example, if you want to take the length of a lot of different
strings, you might think you could save time by binding a local
variable to str.__len__ and using that on the strings.  Here is an
example:

>>> def a(s, count, lenfunc):
... for i in xrange(count):
...z = lenfunc(s)
...
>>> a('abcdef', 1, len)
>>> a('abcdef', 1, str.__len__)

Running cPython 2.6 on my machine, len() runs about 3 times faster
than str.__len__().  The overhead of checking that an object is usable
with a particular class method far outweighs the cost of creating the
bound method!

So, one thought for the OP.  Whenever I have a dictionary that
contains class methods in it, if I'm going to use it heavily, I often
recode it to create the dictionary at object creation time with bound
methods in it.

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


Re: to pass self or not to pass self

2010-03-16 Thread Steven D'Aprano
On Wed, 17 Mar 2010 15:57:17 +1100, Lie Ryan wrote:

> Most people probably would never need to use
> descriptor protocol directly, since the immediate benefit of descriptor
> protocol are property(), classmethod(), and instancemethod() decorators
> which, without descriptor protocol, would never become a possibility.


There's an instancemethod decorator? Where?

Are you thinking of staticmethod? "instancemethod", if you mean what I 
think you mean, doesn't need a decorator because it is the default 
behaviour for new-style classes.


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


Re: Converting Python CGI to WSGI scripts

2010-03-16 Thread Sebastian Bassi
On Tue, Mar 16, 2010 at 2:18 PM,   wrote:
> I have a few dozen simple Python CGI scripts.
> Are there any advantages or disadvantages to rewriting these CGI scripts as
> WSGI scripts?

It depends of the script. WSGI should be faster since you don't start
a Python instance for each call (as in CGI).

-- 
Sebastián Bassi. Diplomado en Ciencia y Tecnología.

Curso de Python en un día: http://bit.ly/cursopython
Python for Bioinformatics: http://tinyurl.com/biopython

Non standard disclaimer: READ CAREFULLY. By reading this email,
you agree, on behalf of your employer, to release me from all
obligations and waivers arising from any and all NON-NEGOTIATED
agreements, licenses, terms-of-service, shrinkwrap, clickwrap,
browsewrap, confidentiality, non-disclosure, non-compete and
acceptable use policies ("BOGUS AGREEMENTS") that I have
entered into with your employer, its partners, licensors, agents and
assigns, in perpetuity, without prejudice to my ongoing rights and
privileges. You further represent that you have the authority to release
me from any BOGUS AGREEMENTS on behalf of your employer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: to pass self or not to pass self

2010-03-16 Thread Lie Ryan
On 03/17/2010 05:59 AM, Jason Tackaberry wrote:
> On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote:
>> Answer here:
>>
>> http://wiki.python.org/moin/FromFunctionToMethod
> 
> I have a sense I used to know this once upon a time, but the question
> came to my mind (possibly again) and I couldn't think of an answer:
> 
> Why not create the bound methods at instantiation time, rather than
> using the descriptor protocol which has the overhead of creating a new
> bound method each time the method attribute is accessed?

Because people wanted it like so. There was once, a time when python
doesn't have the descriptor protocol (old-style classes) and many people
feels that a high-level language like python should provide some
additional hooks for customizing attribute access which the existing
solutions like __getattr__ and __setattr__ couldn't easily provide. The
result is new-style class. Most people probably would never need to use
descriptor protocol directly, since the immediate benefit of descriptor
protocol are property(), classmethod(), and instancemethod() decorators
which, without descriptor protocol, would never become a possibility.
-- 
http://mail.python.org/mailman/listinfo/python-list


Data entry Work available

2010-03-16 Thread pothuri ramesh
Data entry works Available At
No need to pay DEposite

http://trading7000.blogspot.com/




Adposting Jobs Availble

http://trading7000.blogspot.com/



No need to work Hard
Earn Money From Home
7000 in Minutes

http://trading7000.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: highlight words by regex in pdf files using python

2010-03-16 Thread Patrick Maupin
On Mar 4, 6:57 pm, Peng Yu  wrote:
> I don't find a general pdf library in python that can do any
> operations on pdfs.
>
> I want to automatically highlight certain words (using regex) in a
> pdf. Could somebody let me know if there is a tool to do so in python?

The problem with PDFs is that they can be quite complicated.  There is
the outer container structure, which isn't too bad (unless the
document author applied encryption or fancy multi-object compression),
but then inside the graphics elements, things could be stored as
regular ASCII, or as fancy indexes into font-specific tables.  Not
rocket science, but the only industrial-strength solution for this is
probably reportlab's pagecatcher.

I have a library which works (primarily with the outer container) for
reading and writing, called pdfrw.  I also maintain a list of other
PDF tools at http://code.google.com/p/pdfrw/wiki/OtherLibraries  It
may be that pdfminer (link on that page) will do what you want -- it
is certainly trying to be complete as a PDF reader.  But I've never
personally used pdfminer.

One of my pdfrw examples at http://code.google.com/p/pdfrw/wiki/ExampleTools
will read in preexisting PDFs and write them out to a reportlab
canvas.  This works quite well on a few very simple ASCII PDFs, but
the font handling needs a lot of work and probably won't work at all
right now on unicode.  (But if you wanted to improve it, I certainly
would accept patches or give you commit rights!)

That pdfrw example does graphics reasonably well.  I was actually
going down that path for getting better vector graphics into rst2pdf
(both uniconvertor and svglib were broken for my purposes), but then I
realized that the PDF spec allows you to include a page from another
PDF quite easily (the spec calls it a form xObject), so you don't
actually need to parse down into the graphics stream for that.  So,
right now, the best way to do vector graphics with rst2pdf is either
to give it a preexisting PDF (which it passes off to pdfrw for
conversion into a form xObject), or to give it a .svg file and invoke
it with -e inkscape, and then it will use inkscape to convert the svg
to a pdf and then go through the same path.

HTH,
Pat
-- 
http://mail.python.org/mailman/listinfo/python-list


Web Hosting Python 3

2010-03-16 Thread hidura
Hello list, i am in a project what need hosting, who give hosting to  
python3?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C-API PyObject_Call

2010-03-16 Thread moerchendiser2k3
At first thanks for your answers!!!

On 16 Mrz., 21:16, Carl Banks  wrote:
> Here you raise an exception with a C statement,
> and catch and print it in the very next line.  The exception doesn't
> exit from Python code so there are no lines to print.

Exactly, I dont expect any line/file information. I am just looking
forward for a solution how to solve that. I would like to avoid
the use of the debugger in this case.

My ideas:

1. I thought the return value might contain any information where it
is from.
2. Otherwise it would be cool if there are any information available
in which line, file
the last called function/method exited.

Bye, moerchendiser2k3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime string conversion error

2010-03-16 Thread Gabriel Genellina
En Tue, 16 Mar 2010 20:31:11 -0300, Josh English  
 escribió:



On Mar 16, 11:56 am, Jordan Apgar  wrote:


here's what I'm doing:
date = "2010-03-16 14:46:38.409137"
 olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f")



Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on
the other).

When I have a script as simple as this:

import datetime

datetime.datetime.strptime('2010-09-14', "%Y-%m-%d")


Running this script brings up a calendar, believe it or not. The
calendar displays March 2010, and shows the 22nd as a holiday. When I
dismiss the dialog box I get:
Traceback (most recent call last):
  File "strptimetest.py", line 3, in 
datetime.datetime.strptime('2010-09-14', "%Y-%m-%d")
  File "C:\Python25\lib\_strptime.py", line 272, in 
_TimeRE_cache = TimeRE()
  File "C:\Python25\lib\_strptime.py", line 191, in __init__
self.locale_time = LocaleTime()
  File "C:\Python25\lib\_strptime.py", line 74, in __init__
self.__calc_weekday()
  File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday
a_weekday = [calendar.day_abbr[i].lower() for i in range(7)]
AttributeError: 'module' object has no attribute 'day_abbr'


I'd say you have a calendar.py script somewhere along your sys.path, that  
shadows the calendar module in the standard library.


--
Gabriel Genellina

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


Re: Exiting gracefully from ThreadingTCPServer

2010-03-16 Thread Gabriel Genellina
En Fri, 12 Mar 2010 12:15:16 -0300, Pete Emerson   
escribió:



I'm trying to get threading going for the first time in python, and
I'm trying to modify code I found so that I can have the server close
the TCP connections and exit gracefully. Two problems:


Which Python version?


1) While the KeyboardInterrupt works, if I make more than 0 curls to
the server and then quit, I can't run it again right away and get
this:
socket.error: [Errno 48] Address already in use

Not all of my connections are closing properly. How do I fix this?

2) curling localhost:8080/quit does show the "Quitting" output that I
expect, but doesn't quit the server until I manually control-c it.


On Python 2.6, you should call the shutdown() method (from another  
thread!) instead of simply server_close()
See this recipe [1] -- just look at the main() function (disregard all the  
previous details); it runs the server(s) in their own thread, the main  
thread just sits and waits for KeyboardInterrupt or SystemExit.


[1] http://code.activestate.com/recipes/577025

--
Gabriel Genellina

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


Re: How to handle file uploads with http.server

2010-03-16 Thread Gabriel Genellina
En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue   
escribió:



I have a basic http.server instance running (class
HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I
would like to upload files with multipart forms.

def do_POST(self):
ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
if ctype=='multipart/form-data':
print('parsing...')
query=cgi.parse_multipart(self.rfile, pdict)
print(query)

However the file never seems to finish being parsed. There are no errors,
but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict)


This may be related to this bug:

http://bugs.python.org/issue8077

reported last week by Mitchell L. Model in this thread:

http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/

--
Gabriel Genellina

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


Re: C++ code generation

2010-03-16 Thread CHEN Guang
PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++)
 
- Original Message - 
From: "Dan Goodman" 
To: 
Sent: Wednesday, March 17, 2010 9:00 AM
Subject: C++ code generation


> Hi all,
> 
> I'm doing some C++ code generation using Python, and would be interested 
> in any comments on the approach I'm taking.
> 
> Basically, the problem involves doing some nested loops and executing 
> relatively simple arithmetic code snippets, like:
> 
> for i in xrange(len(X)):
>   X[i] += 5
> 
> Actually they're considerably more complicated than this, but this gives 
> the basic idea. One way to get C++ code from this would be to use 
> Cython, but there are two problems with doing that. The first problem is 
> that the arithmetic code snippets are user-specified. What I want to do 
> is generate code, and then compile and run it using Scipy's weave 
> package. The second problem is that I have various different data 
> structures and the C++ code generated needs to be different for the 
> different structures (e.g. sparse or dense matrices).
> 
> So far what I've been doing is writing Python code that writes the C++ 
> code, but in a very non-transparent way. I like the idea of specifying 
> the C++ code using Python syntax, like in Cython. So the idea I came up 
> with was basically to abuse generators and iterators so that when you 
> write something like:
> 
> for x in X:
>...
> 
> it actually outputs some C++ code that looks like:
> 
> for(int i=0; i double &x = X[i];
> ...
> }
> 
> The ... in the Python code is only executed once because when X is 
> iterated over it only returns one value.
> 
> Here's the example I've written so far (complete code given below):
> 
> # initialisation code
> code = OutputCode()
> evaluate = Evaluator(code)
> X = Array(code, 'values')
> # specification of the C++ loop
> for x in X:
> evaluate('x += 5; x *= 2')
> # and show the output
> print code.code
> 
> It generates the following C++ code:
> 
> for(int values_index=0; values_index double &values = values_array[values_index];
> values += 5;
> values *= 2;
> }
> 
> OK, so that's an overview of the idea that I have of how to do it. Any 
> comments or suggestions on either the approach or the implementation?
> 
> Below is the complete code I've written for the example above (linewraps 
> aren't perfect but there's only a couple of lines to correct).
> 
> Thanks for any feedback,
> 
> Dan
> 
> import re, inspect
> 
> # We just use this class to identify certain variables
> class Symbol(str): pass
> 
> # This class is basically just a mutable string
> class OutputCode(object):
> def __init__(self):
> self.code = ''
> def __iadd__(self, code):
> self.code = self.code+code
> return self
> 
> # Iterating over instances of this class generates code
> # for iterating over a C++ array, it yields a single
> # Symbol object, the variable name of the value in the
> # array
> class Array(object):
> def __init__(self, code, name, dtype='double'):
> self.name = name
> self.dtype = dtype
> self.code = code
> def __iter__(self):
> def f():
> self.code += 'for(int {name}_index=0; 
> {name}_index<{name}_len; {name}_index++){{\n'.format(name=self.name)
> self.code += '{dtype} &{name} = 
> {name}_array[{name}_index];\n'.format(dtype=self.dtype, name=self.name)
> yield Symbol(self.name)
> self.code += '}\n'
> return f()
> 
> # Instances of this class generate C++ code from Python syntax
> # code snippets, replacing variable names that are a Symbol in the
> # namespace with the value of that Symbol.
> class Evaluator(object):
> def __init__(self, code):
> self.code = code
> def __call__(self, code):
> # The set of variables in the code snippet
> vars = re.findall(r'\b(\w+)\b', code)
> # Extract any names from the namespace of the calling frame
> frame = inspect.stack()[1][0]
> globals, locals = frame.f_globals, frame.f_locals
> values = {}
> for var in vars:
> if var in locals:
> values[var] = locals[var]
> elif var in globals:
> values[var] = globals[var]
> # Replace any variables whose values are Symbols with their values
> for var, value in values.iteritems():
> if isinstance(value, Symbol):
> code = re.sub(r'\b{var}\b'.format(var=var), str(value), 
> code)
> # Turn Python snippets into C++ (just a simplified version for now)
> code = code.replace(';', '\n')
> lines = [line.strip() for line in code.split('\n')]
> code = ''.join(line+';\n' for line in lines)
> self.code += code
> 
> if __name__=='__main__':
> code = OutputCode()
> evaluate = Evaluator(code)
> X = Array(code, 'values')
> for x in X:
> evaluate('x += 5; x *= 2')
> print code.code
> -- 
htt

Re: Python bindings tutorial

2010-03-16 Thread CHEN Guang

> Is there any tutorial how to write a bindings for a exe ( dos)
> program?
> I would like to run it from a Python directly
> ( using import command and a particular function from the binding)
> not using os.system command.
 
An example: PythoidC ( http://pythoidc.googlecode.com ), look at 
importTemplate.py-- 
http://mail.python.org/mailman/listinfo/python-list


C++ code generation

2010-03-16 Thread Dan Goodman

Hi all,

I'm doing some C++ code generation using Python, and would be interested 
in any comments on the approach I'm taking.


Basically, the problem involves doing some nested loops and executing 
relatively simple arithmetic code snippets, like:


for i in xrange(len(X)):
  X[i] += 5

Actually they're considerably more complicated than this, but this gives 
the basic idea. One way to get C++ code from this would be to use 
Cython, but there are two problems with doing that. The first problem is 
that the arithmetic code snippets are user-specified. What I want to do 
is generate code, and then compile and run it using Scipy's weave 
package. The second problem is that I have various different data 
structures and the C++ code generated needs to be different for the 
different structures (e.g. sparse or dense matrices).


So far what I've been doing is writing Python code that writes the C++ 
code, but in a very non-transparent way. I like the idea of specifying 
the C++ code using Python syntax, like in Cython. So the idea I came up 
with was basically to abuse generators and iterators so that when you 
write something like:


for x in X:
   ...

it actually outputs some C++ code that looks like:

for(int i=0; iThe ... in the Python code is only executed once because when X is 
iterated over it only returns one value.


Here's the example I've written so far (complete code given below):

# initialisation code
code = OutputCode()
evaluate = Evaluator(code)
X = Array(code, 'values')
# specification of the C++ loop
for x in X:
evaluate('x += 5; x *= 2')
# and show the output
print code.code

It generates the following C++ code:

for(int values_index=0; values_indexOK, so that's an overview of the idea that I have of how to do it. Any 
comments or suggestions on either the approach or the implementation?


Below is the complete code I've written for the example above (linewraps 
aren't perfect but there's only a couple of lines to correct).


Thanks for any feedback,

Dan

import re, inspect

# We just use this class to identify certain variables
class Symbol(str): pass

# This class is basically just a mutable string
class OutputCode(object):
def __init__(self):
self.code = ''
def __iadd__(self, code):
self.code = self.code+code
return self

# Iterating over instances of this class generates code
# for iterating over a C++ array, it yields a single
# Symbol object, the variable name of the value in the
# array
class Array(object):
def __init__(self, code, name, dtype='double'):
self.name = name
self.dtype = dtype
self.code = code
def __iter__(self):
def f():
self.code += 'for(int {name}_index=0; 
{name}_index<{name}_len; {name}_index++){{\n'.format(name=self.name)
self.code += '{dtype} &{name} = 
{name}_array[{name}_index];\n'.format(dtype=self.dtype, name=self.name)

yield Symbol(self.name)
self.code += '}\n'
return f()

# Instances of this class generate C++ code from Python syntax
# code snippets, replacing variable names that are a Symbol in the
# namespace with the value of that Symbol.
class Evaluator(object):
def __init__(self, code):
self.code = code
def __call__(self, code):
# The set of variables in the code snippet
vars = re.findall(r'\b(\w+)\b', code)
# Extract any names from the namespace of the calling frame
frame = inspect.stack()[1][0]
globals, locals = frame.f_globals, frame.f_locals
values = {}
for var in vars:
if var in locals:
values[var] = locals[var]
elif var in globals:
values[var] = globals[var]
# Replace any variables whose values are Symbols with their values
for var, value in values.iteritems():
if isinstance(value, Symbol):
code = re.sub(r'\b{var}\b'.format(var=var), str(value), 
code)

# Turn Python snippets into C++ (just a simplified version for now)
code = code.replace(';', '\n')
lines = [line.strip() for line in code.split('\n')]
code = ''.join(line+';\n' for line in lines)
self.code += code

if __name__=='__main__':
code = OutputCode()
evaluate = Evaluator(code)
X = Array(code, 'values')
for x in X:
evaluate('x += 5; x *= 2')
print code.code

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


Re: How to add a library path to pythonpath ?

2010-03-16 Thread Mark Hammond

On 17/03/2010 1:26 AM, Barak, Ron wrote:

Thanks for the suggestion Pable.
However, I really need the $PYTHONPATH to include this additional
library, so all Python scripts could use it.
In Windows I have defined PYTHONPATH as
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the
Windows registry I have
HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\/version/\PythonPath\ as
C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk;
However, even with all the above, the SVMInspecor modules are not found.


You need to create your own sub-key, with any name, under the PythonPath 
key and add your path there.  The reason is that Python only looks for 
that root key when it can't sniff the location of the library itself 
based on the location of the executable - and in most cases it can. 
Python does however enumerate and use the sub-keys in all cases.


HTH,

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


Re: import antigravity

2010-03-16 Thread Michael Rudolf

Am 16.03.2010 21:44, schrieb Mark Lawrence:

Who actually *IS* running the time machine?  Are there any bugs??


My is. And as I'm a lazy hacker: sure. there are bugs. lets just call 
them features and move on. nothing to see here ;)

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


Re: cycling through options

2010-03-16 Thread Gabriel Genellina
En Tue, 16 Mar 2010 11:30:51 -0300, Dieter Faulbaum  
 escribió:



is there a better way for cycling through all options than this:


(options, args) = parser.parse_args()
for opt in options.__dict__.keys():
 print opt, ":", options.__dict__[opt]


(I assume parser is an optparse.OptionParser instance)
You may rewrite it as:

for oname, ovalue in vars(options).iteritems():
  print oname, ":", ovalue

This assumes that the only instance attributes existing in 'options' are,  
uh, parsed options from the command line. I could not find such guarantee  
in the documentation. Another way would be to ask the parser about the  
options it knows of:


for oname in (o.dest for o in parser.option_list if o.dest):
  print oname, ":", getattr(options, oname, None)

--
Gabriel Genellina

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


Re: Conditional based on whether or not a module is being used

2010-03-16 Thread Aahz
In article <42062deb-785a-4955-9ce0-d9fb7a264...@j27g2000yqn.googlegroups.com>,
Vinay Sajip   wrote:
>
>I'm reviewing the documentation at the moment, as it happens, and it
>still seems hard to be able to put together a structure which is good
>for everyone. A full treatment, it seems to me, would talk a little
>about the detail of why things work as they do; but a lot of the time,
>people are just interested in getting going with the package, and less
>interested in the whys and wherefores. But for people trying to do more
>than the basics, that deeper understanding is sometimes necessary. The
>hard part is satisfying all audiences in one document!

Simple answer: don't

The main logging docs should be reference material, but the top of the
docs should link to a tutorial (or the other way around, but I think the
Python docs have generally preferred to make the primary doc reference).

Trying to make one page serve all documentation purposes rarely works.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional based on whether or not a module is being used

2010-03-16 Thread Aahz
In article ,
Pete Emerson   wrote:
>
>Excellent, this is what I finally discovered, although I was looking
>for 'foo' in sys.modules.keys(), which apparently isn't necessary.

Actually, `foo in sys.modules.keys()` is double-slow, because first the
dict must be scanned to create a list, and then the list must be scanned
linearly to test for foo.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: highlight words by regex in pdf files using python

2010-03-16 Thread Aahz
In article ,
Peng Yu   wrote:
>
>I don't find a general pdf library in python that can do any
>operations on pdfs.
>
>I want to automatically highlight certain words (using regex) in a
>pdf. Could somebody let me know if there is a tool to do so in python?

Did you Google at all?  "python pdf" finds this as the first link, though
I have no clue whether it does what you want:

http://pybrary.net/pyPdf/
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function that knows its argument's variable name

2010-03-16 Thread Phlip
> Yet, the answer to your question is not quite absolutely "no".  Python
> has lots of introspection capabilities, including, perhaps, getting at
> and parsing the original code to find the call.    But there's nothing
> direct for what you want.
>
> Gary Herron

Below my sig is one shot at it; which requires a lambda: for other
reasons. It's an assertion used with Django models.

You can search for the name of your trace method, instead of lambda,
using this brute-force technique.

And here's a nice thread on Greg's technique, from a very short time
ago:

  http://groups.google.com/group/comp.lang.python/msg/03dd85ce009044e9

--
  Phlip
  http://penbird.tumblr.com/

def assert_model_changes(self, mod, item, frum, too, lamb):
source = open(lamb.func_code.co_filename, 'r').readlines()
[lamb.func_code.co_firstlineno - 1]
source = source.replace('lambda:', '').strip()
model  = str(mod.__class__).replace("'>", '').split('.')[-1]

should = '%s.%s should equal `%s` before your activation line,
`%s`' % \
  (model, item, frum, source)

self.assertEqual(frum, mod.__dict__[item], should)
lamb()
mod = mod.__class__.objects.get(pk=mod.pk)

should = '%s.%s should equal `%s` after your activation line, `
%s`' % \
  (model, item, too, source)

self.assertEqual(too, mod.__dict__[item], should)
return mod
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime string conversion error

2010-03-16 Thread Josh English
On Mar 16, 11:56 am, Jordan Apgar  wrote:

> here's what I'm doing:
> date = "2010-03-16 14:46:38.409137"
>  olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f")
>

Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on
the other).

When I have a script as simple as this:

import datetime

datetime.datetime.strptime('2010-09-14', "%Y-%m-%d")


Running this script brings up a calendar, believe it or not. The
calendar displays March 2010, and shows the 22nd as a holiday. When I
dismiss the dialog box I get:
Traceback (most recent call last):
  File "strptimetest.py", line 3, in 
datetime.datetime.strptime('2010-09-14', "%Y-%m-%d")
  File "C:\Python25\lib\_strptime.py", line 272, in 
_TimeRE_cache = TimeRE()
  File "C:\Python25\lib\_strptime.py", line 191, in __init__
self.locale_time = LocaleTime()
  File "C:\Python25\lib\_strptime.py", line 74, in __init__
self.__calc_weekday()
  File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday
a_weekday = [calendar.day_abbr[i].lower() for i in range(7)]
AttributeError: 'module' object has no attribute 'day_abbr'


err... what? Is this an old weirdness I don't remember from the 2.5
series?

I can select dates in the calendar, but nothing dismisses it but the
close box.

Josh English
Incredibly Confused
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class inheritance

2010-03-16 Thread Robert Kern

On 2010-03-16 17:55 PM, JLundell wrote:

On Mar 16, 8:06 am, Robert Kern  wrote:

On 2010-03-16 07:35 AM, Dave Angel wrote:


Carl Banks wrote:

On Mar 15, 4:34 pm, JLundell  wrote:

It's also unfortunate that Python doesn't have an approximately-equal
operator; it'd come in handy for floating-point applications while
preserving hash. If only there were a ~=r ≈ operator I could
overload. And ~ is unary, so no joy.



One problem with it is that there's no way to make it universal;
different appiplications have different ideas of close. Conceivably
it could be usefully defined for a user type though..



Bacause of this problem almost no languages have an almost equal
operator. I'm curious what languages do, of if there are any with a
trinary operator that also takes a threshold.



Carl Banks



If I recall correctly, APL has a *fuzz* value, which is used in all(?)
comparisons. But I do not recall anything about how it was defined. I do
recall that you could change the threshold, and suspect it was relative
to the operands. For symmetry, it would probably have to be relative to
the average of the two values, or some such.


The problem is that frequently there is no system-wide fuzz value which is
appropriate for all comparisons in a given program. You need to choose the right
value for each comparison. Consequently, you might as well use a function
instead of an operator and a global variable.

--
Robert Kern



APL scaled their fuzz to the larger of the values being compared.


I know. My statement stands for relative fuzz values as well as it does for 
absolute fuzz values. :-)



In
my case, my domain permits me to use a constant fuzz; all my units are
the same (votes, as it happens). I've seen abs(a/b-1) used instead of
abs(a-b); obviously you'd need to treat comparison with zero
specially.


One usually uses a combination of relative and absolute tolerances to account 
for the case when the values are close to zero.



But yeah, it's really a domain-specific problem.


Right. And a single program might need to deal with multiple domains, so a 
single global setting to control a language feature is pretty fragile.


--
Robert Kern

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

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


Re: Function that knows its argument's variable name

2010-03-16 Thread Gregory Ewing

Helge Stenström wrote:


I want to write  function that prints a value of a variable, for
debugging. Like:

myVariable = "parrot"
otherVariable = "dead"

>

probe(myVariable)
probe(otherVariable)


Not exactly, but you can come close with a little hackery.

import sys

def print_var(name):
  print name, "=", sys._getframe(1).f_locals[name]

def f():
  fred = 42
  mary = "christmas"
  print_var("fred")
  print_var("mary")

f()

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


Re: class inheritance

2010-03-16 Thread JLundell
On Mar 16, 8:06 am, Robert Kern  wrote:
> On 2010-03-16 07:35 AM, Dave Angel wrote:
>
>
>
>
>
>
>
> > Carl Banks wrote:
> >> On Mar 15, 4:34 pm, JLundell  wrote:
> >>> It's also unfortunate that Python doesn't have an approximately-equal
> >>> operator; it'd come in handy for floating-point applications while
> >>> preserving hash. If only there were a ~=r ≈ operator I could
> >>> overload. And ~ is unary, so no joy.
>
> >> One problem with it is that there's no way to make it universal;
> >> different appiplications have different ideas of close. Conceivably
> >> it could be usefully defined for a user type though..
>
> >> Bacause of this problem almost no languages have an almost equal
> >> operator. I'm curious what languages do, of if there are any with a
> >> trinary operator that also takes a threshold.
>
> >> Carl Banks
>
> > If I recall correctly, APL has a *fuzz* value, which is used in all(?)
> > comparisons. But I do not recall anything about how it was defined. I do
> > recall that you could change the threshold, and suspect it was relative
> > to the operands. For symmetry, it would probably have to be relative to
> > the average of the two values, or some such.
>
> The problem is that frequently there is no system-wide fuzz value which is
> appropriate for all comparisons in a given program. You need to choose the 
> right
> value for each comparison. Consequently, you might as well use a function
> instead of an operator and a global variable.
>
> --
> Robert Kern
>

APL scaled their fuzz to the larger of the values being compared. In
my case, my domain permits me to use a constant fuzz; all my units are
the same (votes, as it happens). I've seen abs(a/b-1) used instead of
abs(a-b); obviously you'd need to treat comparison with zero
specially.

But yeah, it's really a domain-specific problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: passing a socket to a subprocess in windows

2010-03-16 Thread Gabriel Genellina
En Tue, 16 Mar 2010 14:10:16 -0300, Daniel Platz  
 escribió:



I have a problem with passing a socket to a subprocess in windows. It
works in Linux and for windows there is a workaround in the Python
doc. However, this workaround does not work. It was already noted by
other people and they Python issue tracker

http://bugs.python.org/issue5879


Unfortunately I cannot test it at this moment, but around line 360 in  
socketmodule.c:


#if defined(MS_WINDOWS) || defined(__BEOS__)
 ...
#define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */
#endif

you could try removing that #define NO_DUP and recompiling. socket.fromfd  
should appear, and hopefully socket objects can now be sent thru the  
multiprocessing connection.


(I cannot see how the example could have actually worked on Windows, maybe  
I'm missing something. Perhaps http://bugs.python.org/issue3125 broke  
this.)


--
Gabriel Genellina

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


Re: import antigravity

2010-03-16 Thread Mark Lawrence

Hans Mulder wrote:

Ulrich Eckhardt wrote:

Chris Rebert wrote:

You're a bit behind the times.
If my calculations are right, that comic is over 2 years old.


import timetravel


I think you mean:

from __future__ import timetravel


-- HansM


Taking 1984 into account surely it should be

from __past__ import __future__ as future

But the question is, have we yet got to 1984, are we currently there or 
have we already gone past it?  Who actually *IS* running the time 
machine?  Are there any bugs??


Regards.

Mark Lawrence.

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


Re: subtraction is giving me a syntax error

2010-03-16 Thread Benjamin Kaplan
On Tue, Mar 16, 2010 at 4:12 PM, Grant Edwards wrote:

> On 2010-03-16, Vito 'ZeD' De Tullio  wrote:
> > Grant Edwards wrote:
> >
> >>> As for not being able to see the difference between a hyphen and an
> >>> EN- dash, or minus sign, or whatever it is, yes but they are very
> >>> similar looking glyphs in virtually ever modern font. It would take a
> >>> good eye to see the difference between (say) ??? ??? and -.
> >>
> >> My point is that if it's an ASCII file,
> >
> > source files aren't (necessary) ASCII files
>
> OK, if it's a file with encoding , then characters that
> aren't part of  shouldn't be rendered according so some
> other arbitrary character set.  Illegal characters should be flagged
> and displayed in a manner that makes it obvious you have illegal
> characters in in the file.
>
> If the OP was using a source file with an encoding that isn't accepted
> by Python, then he needs to pick a source file encoding that is
> recognized by Python.
>
> Using a source file encoding where there are semantically _different_
> characters that render identically is just asking for pain...
>
>
>>> print u'\N{HYPHEN-MINUS}'
-
>>> print u'\N{MINUS SIGN}'
−
>>> print u'\N{SMALL HYPHEN-MINUS}'
﹣
>>> print u'\N{FIGURE DASH}'
‒
>>> print u'\N{EN DASH}'
–
>>> print u'\N{SMALL EM DASH}'
﹘
>>> print u'\N{EM DASH}'
—
>>> print u'\N{HORIZONTAL BAR}'
―


Good luck finding a character encoding where you can see the difference
between each of those in context. Do you program in a hex editor?


> --
> Grant Edwards   grant.b.edwardsYow! I guess you guys
> got
>  at   BIG MUSCLES from doing
> too
>  gmail.commuch STUDYING!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The first ASIC designed with MyHDL

2010-03-16 Thread Aahz
In article <4b9f7414$0$2887$ba620...@news.skynet.be>,
Jan Decaluwe   wrote:
>
>I am proud to report on the first ASIC product designed with MyHDL
>(afaik).
>
>http://www.jandecaluwe.com/hdldesign/digmac.html

Congrats!
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
>If Gerard's code works, I would consider it far superior to your code
>here.  Pythonic does not necessarily mean short and ugly

yes, I agree... and in my script i'm using something very like
Gerard's (thanks again, Gerard). I just posted the corrected version
of nn's because the original solved only half the problem.

thanks, all

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


Re: C-API PyObject_Call

2010-03-16 Thread Carl Banks
On Mar 16, 11:25 am, moerchendiser2k3  wrote:
> Hi, currently I am not at home, I will post some stuff when I am back.
> Just the note: I throw an exception with the C API.
>
> Looks like that
>
> PyObject *result = PyObject_Call(my_isntance, "", NULL);
> if(result==NULL)
> {
>     PyErr_Print(); //when this happens, the traceback is correct with
> information about the file/line
>     return;
>
> }
>
> if(!PyXYZ_Check(result))
> {
>     PyErr_SetString(PyExc_TypeError, "Wrong type, ");
>     PyErr_Print(); //missing information of the file/line.
>     return;
> }
>
> Well, I expect, that there are no information about the line/file, so
> I know something is missing, but what is missing?

Python tracebacks only contain line/file information about Python
files, not C files.  Here you raise an exception with a C statement,
and catch and print it in the very next line.  The exception doesn't
exit from Python code so there are no lines to print.

What line/file data you do expect to see?

If you want to see C line/file informnation you have to use a debugger
like gdb, as Steve Holden said.


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


Re: to pass self or not to pass self

2010-03-16 Thread Jonathan Gardner
On Tue, Mar 16, 2010 at 2:04 AM, Bruno Desthuilliers
 wrote:
> lallous a écrit :
>>
>> What is the difference between the reference in 'F' and 'func_tbl' ?
>
> Answer here:
>
> http://wiki.python.org/moin/FromFunctionToMethod
>

Among all the things in the Python language proper, this is probably
the most confusing thing for new programmers. Heck, even experienced
programmers get tangled up because they project how they think things
should work on to the Python model.

The second most confusing thing is probably how objects get instantiated.

-- 
Jonathan Gardner
jgard...@jonathangardner.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subtraction is giving me a syntax error

2010-03-16 Thread Grant Edwards
On 2010-03-16, Vito 'ZeD' De Tullio  wrote:
> Grant Edwards wrote:
>
>>> As for not being able to see the difference between a hyphen and an
>>> EN- dash, or minus sign, or whatever it is, yes but they are very
>>> similar looking glyphs in virtually ever modern font. It would take a
>>> good eye to see the difference between (say) ??? ??? and -.
>> 
>> My point is that if it's an ASCII file,
>
> source files aren't (necessary) ASCII files

OK, if it's a file with encoding , then characters that
aren't part of  shouldn't be rendered according so some
other arbitrary character set.  Illegal characters should be flagged
and displayed in a manner that makes it obvious you have illegal
characters in in the file.

If the OP was using a source file with an encoding that isn't accepted
by Python, then he needs to pick a source file encoding that is
recognized by Python.

Using a source file encoding where there are semantically _different_
characters that render identically is just asking for pain...

-- 
Grant Edwards   grant.b.edwardsYow! I guess you guys got
  at   BIG MUSCLES from doing too
  gmail.commuch STUDYING!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python bindings tutorial

2010-03-16 Thread Terry Reedy

On 3/16/2010 3:12 PM, Gabriel Genellina wrote:

En Tue, 16 Mar 2010 13:20:40 -0300, Johny  escribió:


Is there any tutorial how to write a bindings for a exe ( dos)
program?
I would like to run it from a Python directly
( using import command and a particular function from the binding)
not using os.system command.


Do you mean that you want to execute a particular function in the .exe
program?
That's not possible (ok, you *could* do that if you work hard enough,
but that's not how things are usually done)


If running a function within the .exe *is* what you want, then you 
should compile to .dll instead of .exe and use swig or ctypes to do the 
binding.





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


Re: Understanding the CPython dict implementation

2010-03-16 Thread Terry Reedy

On 3/16/2010 7:46 AM, Steven D'Aprano wrote:

On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote:


I found this PyCon2010 presentation to be excellent: The Mighty
Dictionary, Branden Craig Rhodes, 30 min.


Sorry,
http://pycon.blip.tv/file/3332763/

which plays fine in FF3.6 on windows



http://pycon.blip.tv/file/3264041/


wrong file number


Unfortunately, that clip seems to be unwatchable, at least for me. It
crashed the Netscape plugin in Konqueror, and crashed Firefox.


The flash version does not work for me. This is true of about 1/3 of the 
Pycon 2010 videos that I have tried. The .ogv version of this and all 
others that I have tried (hit Download under Comments) plays fine within 
FF3.6 on my windows xp machine. Perhaps there is a linux-specific bug, 
if that is what you are running under.


Terry Jan Reedy


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


Re: datetime string conversion error

2010-03-16 Thread MRAB

Jordan Apgar wrote:

Hey all,
I'm trying to convert a string to a date time object and all my fields
convert except for month which seems to default to january.

here's what I'm doing:
date = "2010-03-16 14:46:38.409137"
 olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f")

print date
print olddate

I get:
2010-03-16 14:46:38.409137
2010-01-16 14:46:38.409137

notice the 01 in the second date from what I could tell everything is
formatted correctly.


The problem seems to be related to your use of "%j", which parses the
day of the year.

If I use "%d" instead, which parses the day of the month (I think that's
what you intended!), then the month comes out as 3 as expected.
--
http://mail.python.org/mailman/listinfo/python-list


Re: import antigravity

2010-03-16 Thread Martin P. Hellwig

On 03/16/10 19:30, Hans Mulder wrote:

Ulrich Eckhardt wrote:

Chris Rebert wrote:

You're a bit behind the times.
If my calculations are right, that comic is over 2 years old.


import timetravel


I think you mean:

from __future__ import timetravel


-- HansM


Well according to Marty it is:
from __back_to_the_future import DeLorean

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


Re: import antigravity

2010-03-16 Thread Hans Mulder

Ulrich Eckhardt wrote:

Chris Rebert wrote:

You're a bit behind the times.
If my calculations are right, that comic is over 2 years old.


import timetravel


I think you mean:

from __future__ import timetravel


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


Re: subtraction is giving me a syntax error

2010-03-16 Thread Vito 'ZeD' De Tullio
Grant Edwards wrote:

>> As for not being able to see the difference between a hyphen and an
>> EN- dash, or minus sign, or whatever it is, yes but they are very
>> similar looking glyphs in virtually ever modern font. It would take a
>> good eye to see the difference between (say) ??? ??? and -.
> 
> My point is that if it's an ASCII file,

source files aren't (necessary) ASCII files

-- 
By ZeD

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


Re: datetime string conversion error

2010-03-16 Thread Jordan Apgar
On Mar 16, 3:07 pm, Christian Heimes  wrote:
> Jordan Apgar wrote:
> > Hey all,
> > I'm trying to convert a string to a date time object and all my fields
> > convert except for month which seems to default to january.
>
> > here's what I'm doing:
> > date = "2010-03-16 14:46:38.409137"
> >  olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f")
>
> > print date
> > print olddate
>
> > I get:
> > 2010-03-16 14:46:38.409137
> > 2010-01-16 14:46:38.409137
>
> > notice the 01 in the second date from what I could tell everything is
> > formatted correctly.
>
> %j is documtend as "Day of the year as a decimal number [001,366].". Did
> you mean %d instead?
>
> Christian

That fixed it, thank you

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


Re: Python bindings tutorial

2010-03-16 Thread Gabriel Genellina

En Tue, 16 Mar 2010 13:20:40 -0300, Johny  escribió:


Is there any tutorial how to write a bindings for a exe ( dos)
program?
I would like to run it from a Python directly
( using import command and a particular function from the binding)
 not using os.system command.


Do you mean that you want to execute a particular function in the .exe  
program?
That's not possible (ok, you *could* do that if you work hard enough, but  
that's not how things are usually done)


--
Gabriel Genellina

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


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread Michael Torrie
david jensen wrote:
> of course, changing nn's to:
> def getOutcomes(myList=[2,5,8,3,5]):
>low_id = int(myList[0]>myList[1])
>amountToShare = 2*myList[low_id]
>remainder = myList[not low_id]-myList[low_id]
>tail=list(myList[2:])
>outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+
> tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else
> [[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc
> in (1.0, 0.75, 0.5, 0.25, 0.0)]
>return outcomes
> 
> 
> works, just hides the ugliness in a more compact form

If Gerard's code works, I would consider it far superior to your code
here.  Pythonic does not necessarily mean short and ugly, nor does it
mean that you have to always use list comprehensions.   Having a
readable algorithm that's easy to follow in the future is a far better
way than trying to use python's cool features to compact the code to as
small and unreadable section as possible.

I used to use list comprehension all the time, but I've found that often
an explicit for loop is a much better solution in terms of
maintainability.  Especially when you start seeing nested comprehensions
such as you have here.

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


Re: datetime string conversion error

2010-03-16 Thread Christian Heimes
Jordan Apgar wrote:
> Hey all,
> I'm trying to convert a string to a date time object and all my fields
> convert except for month which seems to default to january.
> 
> here's what I'm doing:
> date = "2010-03-16 14:46:38.409137"
>  olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f")
> 
> print date
> print olddate
> 
> I get:
> 2010-03-16 14:46:38.409137
> 2010-01-16 14:46:38.409137
> 
> notice the 01 in the second date from what I could tell everything is
> formatted correctly.


%j is documtend as "Day of the year as a decimal number [001,366].". Did
you mean %d instead?

Christian

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


datetime string conversion error

2010-03-16 Thread Jordan Apgar
Hey all,
I'm trying to convert a string to a date time object and all my fields
convert except for month which seems to default to january.

here's what I'm doing:
date = "2010-03-16 14:46:38.409137"
 olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f")

print date
print olddate

I get:
2010-03-16 14:46:38.409137
2010-01-16 14:46:38.409137

notice the 01 in the second date from what I could tell everything is
formatted correctly.

thanks for the help.
~Jordan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: to pass self or not to pass self

2010-03-16 Thread Jason Tackaberry
On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote:
> Answer here:
> 
> http://wiki.python.org/moin/FromFunctionToMethod

I have a sense I used to know this once upon a time, but the question
came to my mind (possibly again) and I couldn't think of an answer:

Why not create the bound methods at instantiation time, rather than
using the descriptor protocol which has the overhead of creating a new
bound method each time the method attribute is accessed?

Cheers,
Jason.


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


Re: C-API PyObject_Call

2010-03-16 Thread moerchendiser2k3
Hi, currently I am not at home, I will post some stuff when I am back.
Just the note: I throw an exception with the C API.

Looks like that


PyObject *result = PyObject_Call(my_isntance, "", NULL);
if(result==NULL)
{
PyErr_Print(); //when this happens, the traceback is correct with
information about the file/line
return;
}

if(!PyXYZ_Check(result))
{
PyErr_SetString(PyExc_TypeError, "Wrong type, ");
PyErr_Print(); //missing information of the file/line.
return;
}

Well, I expect, that there are no information about the line/file, so
I know something is missing, but what is missing?

Bye, moerchendiser2k3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python bindings tutorial

2010-03-16 Thread Joaquin Abian
On Mar 16, 5:20 pm, Johny  wrote:
> Is there any tutorial how to write a bindings for a exe ( dos)
> program?
> I would like to run it from a Python directly
> ( using import command and a particular function from the binding)
>  not using os.system command.
> Thanks
> L.

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


Re: Python bindings tutorial

2010-03-16 Thread Joaquin Abian
On Mar 16, 5:20 pm, Johny  wrote:
> Is there any tutorial how to write a bindings for a exe ( dos)
> program?
> I would like to run it from a Python directly
> ( using import command and a particular function from the binding)
>  not using os.system command.
> Thanks
> L.

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


Converting Python CGI to WSGI scripts

2010-03-16 Thread python
I have a few dozen simple Python CGI scripts.

Are there any advantages or disadvantages to rewriting these CGI
scripts as WSGI scripts?

Apologies if my terminology is not correct ... when I say WSGI
scripts I mean standalone scripts like the following simplified
(as an example) template:

import sys
def application(environ, start_response):
output = 'Welcome to your mod_wsgi website! It
uses:\n\nPython %s' % sys.version
response_headers = [
('Content-Length', str(len(output))),
('Content-Type', 'text/plain'),
]
start_response('200 OK', response_headers)
return [output]

When I say script I don't mean classic WSGI application in the
sense of a .serve_forever() loop coordinating a bunch of related
scripts - I mean individual, standalone scripts.

Hope this makes sense :)

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


passing a socket to a subprocess in windows

2010-03-16 Thread Daniel Platz
Hello!

I have a problem with passing a socket to a subprocess in windows. It
works in Linux and for windows there is a workaround in the Python
doc. However, this workaround does not work. It was already noted by
other people and they Python issue tracker

http://bugs.python.org/issue5879
***
the example from

http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing

named "
# Example where a pool of http servers share a single listening socket
#
"
does not work on windows.

Reason:

s = socket.fromfd(fd, family, type_, proto)

in line 156 of reduction.py

fails, because fromfd is not available on windows. Sad thing:
reduction.py was put into processing.py exactly to solve that problem
(i.e. reduction.py is provided as workaround for socket.fromfd not
available on windows, from the documentation:
if sys.platform == 'win32':
import multiprocessing.reduction
# make sockets pickable/inheritable


the solution within processing was:

try:
fromfd = socket.fromfd
except AttributeError:
def fromfd(fd, family, type, proto=0):
s = socket._socket.socket()
_processing.changeFd(s, fd, family, type, proto)
return s

but: _multiprocessing has no longer a method changeFd.

Harald
***

Has someone information about this or can help me to solve the
problem.

Thanks in advance

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


Re: C-API PyObject_Call

2010-03-16 Thread Steve Holden
moerchendiser2k3 wrote:
> In one case I have to check the return value of PyObject_Call, and if
> its not of the correct return value,
> I throw an exception, but I just get a simple output:
> 
> TypeError: Expected an instance of XYZ, no int.
> 
> instead of
> 
> Traceback (most called...)
> TypeError: in line 3, file test.py: expected an instance of XYZ, no
> int...

Could we perhaps see a little bit more of the code? Are you throwing the
exception from within your C code or from the Python calling environment
with a raise statement?

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: equivalent of Ruby's Pathname?

2010-03-16 Thread Steve Holden
Phlip wrote:
> Chris Rebert wrote:
> 
>> The next closest thing would probably be the Python 
>> Cookbook:http://code.activestate.com/recipes/langs/python/
> 
> One thing I really like about ... my hacked version of path.py ... is
> path.cd( lambda: ... ). It works great inside fabfile.py to
> temporarily switch to a different folder:
> 
> sample_project = path('sample_project').abspath()
> 
> def run():
> sample_project.cd( lambda:
> _sh('python manage.py runserver 0.0.0.0:8000 --
> settings=test_settings') )
> 
> After the lambda runs, we exception-safely return to the home folder.
> 
> (BTW I'm aware that a fabfile.py command with only one statement will
> return to its shell and remain in the correct folder. It's just ...
> the thought!)
> 
> This be .cd():
> 
> class path:
> 
> def cd(self, block=None):
> previous = path(os.path.curdir).abspath()
> self.chdir()
> 
> if block:
> try:  block()
> finally:  previous.chdir()
> 
> That's based on Jason Orendoff's work at 
> http://www.jorendorff.com/articles/python/path
> 
Wouldn't this be better written as a context manager?

Be aware also that this won't work well in a multi-threaded environment
(assuming os.path.chdir is ultimately used to change directories)
because it effects the process's (globaL current directory.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
of course, changing nn's to:
def getOutcomes(myList=[2,5,8,3,5]):
   low_id = int(myList[0]>myList[1])
   amountToShare = 2*myList[low_id]
   remainder = myList[not low_id]-myList[low_id]
   tail=list(myList[2:])
   outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+
tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else
[[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc
in (1.0, 0.75, 0.5, 0.25, 0.0)]
   return outcomes


works, just hides the ugliness in a more compact form
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extract occurrence of regular expression from elements of XML documents

2010-03-16 Thread Martin Schmidt
On Tue, Mar 16, 2010 at 11:56 AM, Martin Schmidt
wrote:

> Thanks, Stefan.
> Actually I will have to run the searches I am interested in only a few
> times and therefore will drop performance concerns.
>
> Thanks for len(text.split()) .
> I will try it later.
>
> The text I am interested in is always in leaf elements.
>
> I have posted a concrete example incl. a representative XML file a few
> minutes ago.
> I hope this clarifies my problem.
>
> Rereading what I wrote sounds admittedly funnny.
> What I meant that I did not find a post that closely matches my problem (I
> know that the closeness needed in my case will seem excessive to more
> experienced Python/XML users).
>
> Best regards.
>
>   Martin
>
>
> P.S. Sorry for my late reply, but my Internet connection was down for a
> day.
>
>
>
>
>> -- Forwarded message --
>> From: Stefan Behnel 
>> To: python-list@python.org
>> Date: Tue, 16 Mar 2010 08:50:30 +0100
>> Subject: Re: extract occurrence of regular expression from elements of XML
>> documents
>> Martin Schmidt, 15.03.2010 18:16:
>>
>>> I have just started to use Python a few weeks ago and until last week I
>>> had
>>> no knowledge of XML.
>>> Obviously my programming knowledge is pretty basic.
>>> Now I would like to use Python in combination with ca. 2000 XML documents
>>> (about 30 kb each) to search for certain regular expression within
>>> specific
>>> elements of these documents.
>>>
>>
>> 2000 * 30K isn't a huge problem, that's just 60M in total. If you just
>> have to do it once, drop your performance concerns and just get a solution
>> going. If you have to do it once a day, take care to use a tool that is not
>> too resource consuming. If you have strict requirements to do it once a
>> minute, use a fast machine with a couple of cores and do it in parallel. If
>> you have a huge request workload and want to reverse index the XML to do all
>> sorts of sophisticated queries on it, use a database instead.
>>
>>
>>  I would then like to record the number of occurrences of the regular
>>> expression within these elements.
>>> Moreover I would like to count the total number of words contained within
>>> these,
>>>
>>
>> len(text.split()) will give you those.
>>
>> BTW, is it document-style XML (with mixed content as in HTML) or is the
>> text always withing a leaf element?
>>
>>
>>  and record the attribute of a higher level element that contains
>>> them.
>>>
>>
>> An example would certainly help here.
>>
>>
>>  I was trying to figure out the best way how to do this, but got
>>> overwhelmed
>>> by the available information (e.g. posts using different approaches based
>>> on
>>> dom, sax, xpath, elementtree, expat).
>>> The outcome should be a file that lists the extracted attribute, the
>>> number
>>> of occurrences of the regular expression, and the total number of words.
>>> I did not find a post that addresses my problem.
>>>
>>
>> Funny that you say that after stating that you were overwhelmed by the
>> available information.
>>
>>
>>  If someone could help me with this I would really appreciate it.
>>>
>>
>> Most likely, the solution with the best simplicity/performance trade-off
>> would be xml.etree.cElementTree's iterparse(), intercept on each interesting
>> tag name, and search its text/tail using the regexp. That's doable in a
>> couple of lines.
>>
>> But unless you provide more information, it's hard to give better advice.
>>
>> Stefan
>>
>>
>>
>>
>> -- Forwarded message --
>> From: Chris Rebert 
>> To: "Lawrence D'Oliveiro" 
>> Date: Tue, 16 Mar 2010 00:52:07 -0700
>> Subject: Re: import antigravity
>> On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro
>>  wrote:
>> > Subtle...
>>
>> You're a bit behind the times.
>> If my calculations are right, that comic is over 2 years old.
>>
>> Cheers,
>> Chris
>>
>>
>>
>> -- Forwarded message --
>> From: Stefan Behnel 
>> To: python-list@python.org
>> Date: Tue, 16 Mar 2010 08:51:58 +0100
>> Subject: Re: import antigravity
>> Lawrence D'Oliveiro, 16.03.2010 08:40:
>>
>>> Subtle...
>>>
>>
>> Absolutely.
>>
>>  Python 2.4.6 (#2, Jan 21 2010, 23:45:25)
>>  [GCC 4.4.1] on linux2
>>  Type "help", "copyright", "credits" or "license" for more information.
>>  >>> import antigravity
>>  Traceback (most recent call last):
>>File "", line 1, in ?
>>  ImportError: No module named antigravity
>>
>>
>> Stefan
>>
>>
>>
>> --
>>
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to add a library path to pythonpath ?

2010-03-16 Thread Steve Holden
Dave Angel wrote:
> Barak, Ron wrote:
>>  
>>> -Original Message-
>>> From: Dave Angel [mailto:da...@ieee.org]
>>> Sent: Tuesday, March 16, 2010 5:04 PM
>>> To: Barak, Ron
>>> Cc: Pablo Recio Quijano; python-list@python.org
>>> Subject: RE: How to add a library path to pythonpath ?
>>>
>>>
>>>
>>> Barak, Ron wrote:
>>>
 Thanks for the suggestion Pable.

 However, I really need the $PYTHONPATH to include this
   
>>> additional library, so all Python scripts could use it.
>>>
 In Windows I have defined PYTHONPATH as
 c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the
 Windows registry I have


   
>>> HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as
>>>
>>> C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn
>>>
 spector\lib\;C:\Python26\Lib\lib-tk;

 However, even with all the above, the SVMInspecor modules
   
>>> are not found.
>>>
   
>>> See my response at the end.  Top-posting makes for a very
>>> confusing thread.
>>>
 

 2010/3/16 Barak, Ron mailto:ron.ba...@lsi.com>>

 Hi,

 I'm trying to add a library path to my pythonpath, but
   
>>> seems it is not
>>>
 accepted -

 On Windows DOS window:

 C:\>echo %PYTHONPATH%
 c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\

 C:\>python -c "import sys ; print sys.path"
 ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs',
 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win',
 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\
 site-packages',
 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

 C:\>

 On Windows cygwin:

 $ echo $PYTHONPATH
 .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/

 $ python -c "import sys ; print sys.path"
 ['',

   
>>> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
>>>
 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs',
 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win',
 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26',
 'c:\\Python26\\lib\\site-packages',
 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

 $

 What am I doing wrong ?

 Thanks,
 Ron.



   
>>> In your original message, what you displayed worked exactly
>>> as expected.  As you didn't say what made you think something
>>> was wrong, I ignored the message.
>>>
>>> Now, you say that some modules are not found.  So how about
>>> giving some more specifics so someone can actually debug the
>>> problem.  Pick a particular module, tell us the complete path
>>> to that module, and show us both the sys.path strings (which
>>> look correct for the Windows case, and of course bogus for
>>> the cygwin case), as well as the offending import statement
>>> and its traceback.
>>>
>>> DaveA
>>> 
>>
>> Hi Dave,
>>
>> My Python is the Windows Python (I need this for wxPython):
>>
>> $ ls -ls `which python`
>> 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar  4 14:02 /usr/bin/python ->
>> /cygdrive/c/Python26/python.exe
>>
>> Here's a demo script:
>>
>> #!/usr/bin/env python
>>
>> import sys
>> print "\n",sys.path,"\n"
>>
>> from ErrorManager.ErrorManager import ErrorManager
>>
>> And it's run produces:
>>
>> $ python -u  tmp.py
>>
>> ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool',
>> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
>> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs',
>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win',
>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26',
>> 'c:\\Python26\\lib\\site-packages',
>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
>>
>> Traceback (most recent call last):
>>   File "tmp.py", line 6, in 
>> from ErrorManager.ErrorManager import ErrorManager
>> ImportError: No module named ErrorManager.ErrorManager
>>
>> $ ls -ls
>> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py
>>
>> 4 -rwxr-xr-x 1 rbarak  1843 Sep 21 19:16
>> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py
>>
>>
>> $ grep ErrorManager 
>> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/
>> ErrorManager/ErrorManager.py
>> class ErrorManager:
>>
>> $ echo $PYTHONPATH
>> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/
>>
>> Please let me know if the above is enough, or you'd like to see the
>> results from a Windows' DOS window.
>>
>> Thanks,
>> Ron.
>>
>>   
> Well, I pointed out that your cygwin path is bogus, so of course it
> won't work.  One of those entries is
> 
>'.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib'
> 
> I use Linux, and I use Windows.  But cygwin's glomming togethe

Re: Dynamic Class Creation

2010-03-16 Thread Chris Rebert
On Tue, Mar 16, 2010 at 9:49 AM, Jack Diederich  wrote:
> On Tue, Mar 16, 2010 at 2:18 AM, Chris Rebert  wrote:
>> On Mon, Mar 15, 2010 at 11:01 PM, Josh English
>>  wrote:

>>> What's the best way to create these helper methods?
>
> You can either define a catch-all __getattr__ method to look them up
> dynamically, or as Chris kinda-suggested write descriptors for the
> individual elements.
>
> class Market():
>  def __init__(self, elem):
>    self._elem = elem
>  def __getattr__(self, name):
>    try:
>      # I'm assuming this raises a KeyError when not found
>      return self._elem.get(name)
>    except KeyError:
>      return self._elem.find(name)
>  def __setitem__(self, name, value):

did you mean __setattr__ here?


> The getattr/setattr method is easier to understand and will handle
> arbitrary elements;  for the descriptors version you'll have to define
> one for each tag that might be used on the class.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 78, Issue 161

2010-03-16 Thread Martin Schmidt
Thanks, Stefan.
Actually I will have to run the searches I am interested in only a few times
and therefore will drop performance concerns.

Thanks for len(text.split()) .
I will try it later.

The text I am interested in is always in leaf elements.

I have posted a concrete example incl. a representative XML file a few
minutes ago.
I hope this clarifies my problem.

Rereading what I wrote sounds admittedly funnny.
What I meant that I did not find a post that closely matches my problem (I
know that the closeness needed in my case will seem excessive to more
experienced Python/XML users).

Best regards.

  Martin


P.S. Sorry for my late reply, but my Internet connection was down for a day.




> -- Forwarded message --
> From: Stefan Behnel 
> To: python-list@python.org
> Date: Tue, 16 Mar 2010 08:50:30 +0100
> Subject: Re: extract occurrence of regular expression from elements of XML
> documents
> Martin Schmidt, 15.03.2010 18:16:
>
>> I have just started to use Python a few weeks ago and until last week I
>> had
>> no knowledge of XML.
>> Obviously my programming knowledge is pretty basic.
>> Now I would like to use Python in combination with ca. 2000 XML documents
>> (about 30 kb each) to search for certain regular expression within
>> specific
>> elements of these documents.
>>
>
> 2000 * 30K isn't a huge problem, that's just 60M in total. If you just have
> to do it once, drop your performance concerns and just get a solution going.
> If you have to do it once a day, take care to use a tool that is not too
> resource consuming. If you have strict requirements to do it once a minute,
> use a fast machine with a couple of cores and do it in parallel. If you have
> a huge request workload and want to reverse index the XML to do all sorts of
> sophisticated queries on it, use a database instead.
>
>
>  I would then like to record the number of occurrences of the regular
>> expression within these elements.
>> Moreover I would like to count the total number of words contained within
>> these,
>>
>
> len(text.split()) will give you those.
>
> BTW, is it document-style XML (with mixed content as in HTML) or is the
> text always withing a leaf element?
>
>
>  and record the attribute of a higher level element that contains
>> them.
>>
>
> An example would certainly help here.
>
>
>  I was trying to figure out the best way how to do this, but got
>> overwhelmed
>> by the available information (e.g. posts using different approaches based
>> on
>> dom, sax, xpath, elementtree, expat).
>> The outcome should be a file that lists the extracted attribute, the
>> number
>> of occurrences of the regular expression, and the total number of words.
>> I did not find a post that addresses my problem.
>>
>
> Funny that you say that after stating that you were overwhelmed by the
> available information.
>
>
>  If someone could help me with this I would really appreciate it.
>>
>
> Most likely, the solution with the best simplicity/performance trade-off
> would be xml.etree.cElementTree's iterparse(), intercept on each interesting
> tag name, and search its text/tail using the regexp. That's doable in a
> couple of lines.
>
> But unless you provide more information, it's hard to give better advice.
>
> Stefan
>
>
>
>
> -- Forwarded message --
> From: Chris Rebert 
> To: "Lawrence D'Oliveiro" 
> Date: Tue, 16 Mar 2010 00:52:07 -0700
> Subject: Re: import antigravity
> On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro
>  wrote:
> > Subtle...
>
> You're a bit behind the times.
> If my calculations are right, that comic is over 2 years old.
>
> Cheers,
> Chris
>
>
>
> -- Forwarded message --
> From: Stefan Behnel 
> To: python-list@python.org
> Date: Tue, 16 Mar 2010 08:51:58 +0100
> Subject: Re: import antigravity
> Lawrence D'Oliveiro, 16.03.2010 08:40:
>
>> Subtle...
>>
>
> Absolutely.
>
>  Python 2.4.6 (#2, Jan 21 2010, 23:45:25)
>  [GCC 4.4.1] on linux2
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> import antigravity
>  Traceback (most recent call last):
>File "", line 1, in ?
>  ImportError: No module named antigravity
>
>
> Stefan
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic Class Creation

2010-03-16 Thread Jack Diederich
On Tue, Mar 16, 2010 at 2:18 AM, Chris Rebert  wrote:
> On Mon, Mar 15, 2010 at 11:01 PM, Josh English
>  wrote:
>> I have a large program with lots of data stored in XML. I'm upgrading
>> my GUI to use ObjectListView, but with my data in XML, I don't have
>> regular objects to interact with the OLV. I do have an XML validator
>> that defines the structure of the XML elements, and I'm trying to
>> dynamically create a class to wrap the XML element.
>>
>> So, an element like:
>>
>> 
>> Writers of the Future
>> 
>>
>> I want to create a class like:
>>
>> class Market(object):
>>    def __init__(self, elem):
>>        self._elem = elem
>>
>>    def get_code(self):
>>        return self._elem.get('code')
>>
>>    def set_code(self, value):
>>        self._elem.set('code', value)
>>
>>    def get_title(self):
>>        return self._elem.find('title').text
>>
>>    def set_title(self, value):
>>        node = self._elem.find('title')
>>        node.text = value
>>
>> Naturally, I don't want to hand code this for every interface but
>> would like to create them dynamically. (The laziness of programming, I
>> guess.)
>>
>> What's the best way to create these helper methods?

You can either define a catch-all __getattr__ method to look them up
dynamically, or as Chris kinda-suggested write descriptors for the
individual elements.

class Market():
  def __init__(self, elem):
self._elem = elem
  def __getattr__(self, name):
try:
  # I'm assuming this raises a KeyError when not found
  return self._elem.get(name)
except KeyError:
  return self._elem.find(name)
  def __setitem__(self, name, value):
 # like __getitem__ but for setting

Chris' property maker function is almost like a descriptor class (how
properties are implemented under the hood), here's a refactoring
[untested]

class ElemGetProperty():
def __init__(self, name):
  self.name = name
def __get__(self, ob, cls):
  return ob._elem.get(self.name)
def __set__(self, ob, val):
   ob._elem.set(self.name, val)

You could write one property class for each kind of element (get/find)
and then put them in your class like this

class Market():
code = ElemGetProperty('code')
title = ElemFindProeprty('title')

The getattr/setattr method is easier to understand and will handle
arbitrary elements;  for the descriptors version you'll have to define
one for each tag that might be used on the class.

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


Re: C-API PyObject_Call

2010-03-16 Thread moerchendiser2k3
In one case I have to check the return value of PyObject_Call, and if
its not of the correct return value,
I throw an exception, but I just get a simple output:

TypeError: Expected an instance of XYZ, no int.

instead of

Traceback (most called...)
TypeError: in line 3, file test.py: expected an instance of XYZ, no
int...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
Thanks Paul, but i don't immediately see how that helps (maybe I'm
just being dense)... nn's solution, though i initially thought it
worked, actually has a similar problem:

intended:
>>> print getOutcomes([3,4,5,5])
[[6, 1, 5, 5], [4.5, 2.5, 5, 5], [3, 4, 5, 5], [1.5, 5.5, 5, 5], [0,
7, 5, 5]]
>>> print getOutcomes([4,3,5,5])
[[7, 0, 5, 5], [5.5, 1.5, 5, 5], [4, 3, 5, 5], [2.5, 4.5, 5, 5], [1,
6, 5, 5]]

nn's solution:
>>> print getOutcomesNN([4,3,5,5])
[[6.0, 1.0, 5, 5], [4.5, 2.5, 5, 5], [3.0, 4.0, 5, 5], [1.5, 5.5, 5,
5], [0.0, 7.0, 5, 5]]


it's obvious why this is happening (the list comprehension assumes
that index 0 is, after all, index 0), but not immediately obvious how
to fix it, except by going with gerard's solution or doing what i did
in the beginning: flip them if they're in the wrong order, remember,
and flip them again at the end.

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


Re: web sound recording with python

2010-03-16 Thread S.Selvam
On Fri, Oct 9, 2009 at 1:10 PM, Michel Claveau - MVP
 wrote:

> Hi!
>
> On windows, you can record sound who play on the local sound-card.
> It is not really Python scripting, but Python can launch it.
>

Does python do not have support for voice recording ?


-- 
Regards,
S.Selvam

  " I am because we are "
-- 
http://mail.python.org/mailman/listinfo/python-list


Python bindings tutorial

2010-03-16 Thread Johny
Is there any tutorial how to write a bindings for a exe ( dos)
program?
I would like to run it from a Python directly
( using import command and a particular function from the binding)
 not using os.system command.
Thanks
L.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to add a library path to pythonpath ?

2010-03-16 Thread Dave Angel

Barak, Ron wrote:
  

-Original Message-
From: Dave Angel [mailto:da...@ieee.org]
Sent: Tuesday, March 16, 2010 5:04 PM
To: Barak, Ron
Cc: Pablo Recio Quijano; python-list@python.org
Subject: RE: How to add a library path to pythonpath ?



Barak, Ron wrote:


Thanks for the suggestion Pable.

However, I really need the $PYTHONPATH to include this
  

additional library, so all Python scripts could use it.


In Windows I have defined PYTHONPATH as
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the
Windows registry I have


  

HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as

C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn


spector\lib\;C:\Python26\Lib\lib-tk;

However, even with all the above, the SVMInspecor modules
  

are not found.

  

See my response at the end.  Top-posting makes for a very
confusing thread.




2010/3/16 Barak, Ron mailto:ron.ba...@lsi.com>>

Hi,

I'm trying to add a library path to my pythonpath, but
  

seems it is not


accepted -

On Windows DOS window:

C:\>echo %PYTHONPATH%
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\

C:\>python -c "import sys ; print sys.path"
['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs',
'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win',
'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\
site-packages',
'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

C:\>

On Windows cygwin:

$ echo $PYTHONPATH
.:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/

$ python -c "import sys ; print sys.path"
['',

  

'.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',


'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs',
'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win',
'c:\\Python26\\lib\\lib-tk', 'c:\\Python26',
'c:\\Python26\\lib\\site-packages',
'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

$

What am I doing wrong ?

Thanks,
Ron.



  

In your original message, what you displayed worked exactly
as expected.  As you didn't say what made you think something
was wrong, I ignored the message.

Now, you say that some modules are not found.  So how about
giving some more specifics so someone can actually debug the
problem.  Pick a particular module, tell us the complete path
to that module, and show us both the sys.path strings (which
look correct for the Windows case, and of course bogus for
the cygwin case), as well as the offending import statement
and its traceback.

DaveA



Hi Dave,

My Python is the Windows Python (I need this for wxPython):

$ ls -ls `which python`
1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar  4 14:02 /usr/bin/python -> 
/cygdrive/c/Python26/python.exe

Here's a demo script:

#!/usr/bin/env python

import sys
print "\n",sys.path,"\n"

from ErrorManager.ErrorManager import ErrorManager

And it's run produces:

$ python -u  tmp.py

['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', 
'.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 
'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 
'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 
'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 
'c:\\Python26\\lib\\site-packages', 
'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

Traceback (most recent call last):
  File "tmp.py", line 6, in 
from ErrorManager.ErrorManager import ErrorManager
ImportError: No module named ErrorManager.ErrorManager

$ ls -ls 
/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py
4 -rwxr-xr-x 1 rbarak  1843 Sep 21 19:16 
/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py

$ grep ErrorManager  /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/
ErrorManager/ErrorManager.py
class ErrorManager:

$ echo $PYTHONPATH
.:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/

Please let me know if the above is enough, or you'd like to see the results 
from a Windows' DOS window.

Thanks,
Ron.

  
Well, I pointed out that your cygwin path is bogus, so of course it 
won't work.  One of those entries is


   '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib'

I use Linux, and I use Windows.  But cygwin's glomming together has 
never made sense;  some things are Unix-like, and others are 
Windows-like.  So anything you do in that environment is beyond me.


If I had to guess, though I'd say you wanted to drop those first two 
characters from your PYTHONPATH.  If you really wanted two directories 
there, you should be separating them with semicolon (Windows rules), 
rather than colon (Linux rules).  First thing I'd do to test my theories 
is to print something like:

print sys.path[1]
print os.listdir(sys.path[1])
Does Python even see the cygwin view of the world ?

You also don't show the location of the module y

Re: C-API PyObject_Call

2010-03-16 Thread Stefan Behnel

moerchendiser2k3, 16.03.2010 12:52:

i have a serious problem and I am looking for a solution. I pass an
instance of a class from a file to PyObject_Call. When something
fails, I get a full traceback. If it succeeds, I get the return value.

Is it possible to get information from which line/file the return
value of PyObject_Call is?


Could you explain what you want to do with this information and in what 
cases you need it? Do you want to extract the information programmatically 
at runtime?


Stefan

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


Re: C-API PyObject_Call

2010-03-16 Thread Stefan Behnel

moerchendiser2k3, 16.03.2010 17:08:

But the stack is empty after PyObject_Call, isnt it?


I think Steve was expecting that you wanted to debug into your program, 
step into the call, and find the line yourself.


Stefan

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


Re: equivalent of Ruby's Pathname?

2010-03-16 Thread Phlip
Chris Rebert wrote:

> The next closest thing would probably be the Python 
> Cookbook:http://code.activestate.com/recipes/langs/python/

One thing I really like about ... my hacked version of path.py ... is
path.cd( lambda: ... ). It works great inside fabfile.py to
temporarily switch to a different folder:

sample_project = path('sample_project').abspath()

def run():
sample_project.cd( lambda:
_sh('python manage.py runserver 0.0.0.0:8000 --
settings=test_settings') )

After the lambda runs, we exception-safely return to the home folder.

(BTW I'm aware that a fabfile.py command with only one statement will
return to its shell and remain in the correct folder. It's just ...
the thought!)

This be .cd():

class path:

def cd(self, block=None):
previous = path(os.path.curdir).abspath()
self.chdir()

if block:
try:  block()
finally:  previous.chdir()

That's based on Jason Orendoff's work at 
http://www.jorendorff.com/articles/python/path

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C-API PyObject_Call

2010-03-16 Thread moerchendiser2k3
But the stack is empty after PyObject_Call, isnt it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to add a library path to pythonpath ?

2010-03-16 Thread Christian Heimes
Steve Holden schrieb:
> Barak, Ron wrote:
>> Hi,
>>
>> I'm trying to add a library path to my pythonpath, but seems it is not
>> accepted -
>>
>> On Windows DOS window:
>>
>> C:\>echo %PYTHONPATH%
>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\
>>  
> That looks like it should work. The only thing I notice is that I don't
> have a trailing backslash on my Windows PYTHONPATH. Could that be the
> problem?

Yes, that's definitely a major issue on Windows. Windows' stat() method
returns an error for paths with a trailing (back)slash. For example
_stat("C:\\Windows") works but _stat("C:\\Windows\\") sets errno to
ENOENT or ENOTDIR. I got bitten by the issue a couple of years ago as I
worked on pars of Python's import system.

Quoting Tim Peters: [1]

The Microsoft stat() function is extremely picky about
trailing (back)slashes.  For example, if you have a
directory c:/python, and pass "c:/python/" to the MS stat
(), it claims no such thing exists.  This isn't documented
by MS, but that's how it works:  a trailing (back)slash is
required if and only if the path passed in "is a root".  So
MS stat() doesn't understand "/python/", and doesn't
understand "d:" either.  The former doesn't tolerate a
(back)slash, while the latter requires one.


Christian

[1] http://mail.python.org/pipermail/python-bugs-list/2002-April/011099.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: affectation in if statement

2010-03-16 Thread samb
On Mar 16, 11:56 am, Jean-Michel Pichavant 
wrote:
> samb wrote:
> > Hi,
>
> > I've found a work around, inspired from Rob Williscroft :
>
> > class ReMatch(object):
> >     """
> >         Object to be called :
> >         1st time : do a regexp.match and return the answer (args:
> > regexp, line)
> >         2nd time : return the previous result (args: prev)
> >     """
> >     def __call__(self, regexp='', line='', prev=False):
> >         if prev:
> >             return self.prev_match
> >         self.prev_match = re.match(regexp, line)
> >         return self.prev_match
>
> > re_match = ReMatch()
>
> > if re_match(r'define\s+(\S+)\s*{$', line):
> >     m = re_match(prev=True)
> >     # do some logic with m
> > elif re_match(r'include\s+(\S+)$', line):
> >     m = re_match(prev=True)
> >     # do some logic with m
> > else
> >     # do some logic
>
> > Hope this is efficient ... I guess yes.
>
> > Cheers,
> > Sam
>
> What do you mean by efficient ? If you're talking about speed, make sure
> you care about it before doing some optimization.
> If you talk about readability then it is absolutely *not* efficient (to
> my humble opinion).
>
> define, include = re.match(r'define\s+(\S+)\s*{$', line),
> re.match(r'include\s+(\S+)$', line)
> if define:
>     # do some stuff
> elif include:
>     # do some other stuff
> else:
>     # hello world
>
> If you then have some speed problem with that script, you'll start
> caring about how to execute if faster by making sure that only necessary
> calls to re.match are done.
>
> match = re.match(r'(define)\s+(\S+)\s*{$', line) or
> re.match(r'(include)\s+(\S+)$', line) # note that the second operand is
> executed only if the first is None
>
> if match.group(1) == 'define':
>     # do some stuff with match.group(2)
>
> elif match.group(1) == 'include':
>     # do some other stuff with match.group(2)
>
> else:
>     # hello world
>
> JM

Hi,

Thanks Bruno for the simpler API!
And thanks Jean-Michel, your second suggestion is clearly the best I
see.

I meant efficient mainly in the readable aspect (important for future
maintenance) and secondary for speed of execution. For sure I didn't
want to run a regexp twice.

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


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread Paul Rubin
david jensen  writes:
> Obviously, i can just write the code again, in an else, switching
> indices 0 and 1. Or, I could just have a test at the beginning, switch
> them if they are in the order "big, small", and then switch them again
> at the end in a list comprehension. Both ideas seem terribly silly,
> and there must be an obvious way to do it that I'm not seeing.

Generally when faced with this kind of question, see if you can
use the built-in min and max functions:

def getOutcomes():
outcomes=[]
smaller = min(myList[0], myList[1])
bigger  = max(myList[0], myList[1])
amountToShare=2*smaller
remainder = bigger - smaller
...
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to add a library path to pythonpath ?

2010-03-16 Thread Barak, Ron


> -Original Message-
> From: Dave Angel [mailto:da...@ieee.org]
> Sent: Tuesday, March 16, 2010 5:04 PM
> To: Barak, Ron
> Cc: Pablo Recio Quijano; python-list@python.org
> Subject: RE: How to add a library path to pythonpath ?
>
>
>
> Barak, Ron wrote:
> > Thanks for the suggestion Pable.
> >
> > However, I really need the $PYTHONPATH to include this
> additional library, so all Python scripts could use it.
> >
> > In Windows I have defined PYTHONPATH as
> > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the
> > Windows registry I have
> >
> >
> HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as
> >
> C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn
> > spector\lib\;C:\Python26\Lib\lib-tk;
> >
> > However, even with all the above, the SVMInspecor modules
> are not found.
> >
> >
> See my response at the end.  Top-posting makes for a very
> confusing thread.
> > 
> >
> > 2010/3/16 Barak, Ron mailto:ron.ba...@lsi.com>>
> >
> > Hi,
> >
> > I'm trying to add a library path to my pythonpath, but
> seems it is not
> > accepted -
> >
> > On Windows DOS window:
> >
> > C:\>echo %PYTHONPATH%
> > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\
> >
> > C:\>python -c "import sys ; print sys.path"
> > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
> > 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs',
> > 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win',
> > 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\
> > site-packages',
> > 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
> >
> > C:\>
> >
> > On Windows cygwin:
> >
> > $ echo $PYTHONPATH
> > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/
> >
> > $ python -c "import sys ; print sys.path"
> > ['',
> >
> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
> > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs',
> > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win',
> > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26',
> > 'c:\\Python26\\lib\\site-packages',
> > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
> >
> > $
> >
> > What am I doing wrong ?
> >
> > Thanks,
> > Ron.
> >
> >
> >
> In your original message, what you displayed worked exactly
> as expected.  As you didn't say what made you think something
> was wrong, I ignored the message.
>
> Now, you say that some modules are not found.  So how about
> giving some more specifics so someone can actually debug the
> problem.  Pick a particular module, tell us the complete path
> to that module, and show us both the sys.path strings (which
> look correct for the Windows case, and of course bogus for
> the cygwin case), as well as the offending import statement
> and its traceback.
>
> DaveA

Hi Dave,

My Python is the Windows Python (I need this for wxPython):

$ ls -ls `which python`
1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar  4 14:02 /usr/bin/python -> 
/cygdrive/c/Python26/python.exe

Here's a demo script:

#!/usr/bin/env python

import sys
print "\n",sys.path,"\n"

from ErrorManager.ErrorManager import ErrorManager

And it's run produces:

$ python -u  tmp.py

['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', 
'.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 
'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 
'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 
'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 
'c:\\Python26\\lib\\site-packages', 
'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

Traceback (most recent call last):
  File "tmp.py", line 6, in 
from ErrorManager.ErrorManager import ErrorManager
ImportError: No module named ErrorManager.ErrorManager

$ ls -ls 
/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py
4 -rwxr-xr-x 1 rbarak  1843 Sep 21 19:16 
/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py

$ grep ErrorManager  /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/
ErrorManager/ErrorManager.py
class ErrorManager:

$ echo $PYTHONPATH
.:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/

Please let me know if the above is enough, or you'd like to see the results 
from a Windows' DOS window.

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


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
Thank you both very much!

Yeah: it was a total brainfart on my part: nn's solution should have
been obvious.

As the general solution, i like your approach, Gerard, but I think
I'll stick to nn's, the one i should have written.

Again, thank you both!

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


Re: class inheritance

2010-03-16 Thread Robert Kern

On 2010-03-16 07:35 AM, Dave Angel wrote:



Carl Banks wrote:

On Mar 15, 4:34 pm, JLundell  wrote:

It's also unfortunate that Python doesn't have an approximately-equal
operator; it'd come in handy for floating-point applications while
preserving hash. If only there were a ~=r ≈ operator I could
overload. And ~ is unary, so no joy.


One problem with it is that there's no way to make it universal;
different appiplications have different ideas of close. Conceivably
it could be usefully defined for a user type though..

Bacause of this problem almost no languages have an almost equal
operator. I'm curious what languages do, of if there are any with a
trinary operator that also takes a threshold.

Carl Banks


If I recall correctly, APL has a *fuzz* value, which is used in all(?)
comparisons. But I do not recall anything about how it was defined. I do
recall that you could change the threshold, and suspect it was relative
to the operands. For symmetry, it would probably have to be relative to
the average of the two values, or some such.


The problem is that frequently there is no system-wide fuzz value which is 
appropriate for all comparisons in a given program. You need to choose the right 
value for each comparison. Consequently, you might as well use a function 
instead of an operator and a global variable.


--
Robert Kern

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

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


RE: How to add a library path to pythonpath ?

2010-03-16 Thread Dave Angel



Barak, Ron wrote:

Thanks for the suggestion Pable.

However, I really need the $PYTHONPATH to include this additional library, so 
all Python scripts could use it.

In Windows I have defined PYTHONPATH as 
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the Windows 
registry I have

HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as 
C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk;

However, even with all the above, the SVMInspecor modules are not found.

  

See my response at the end.  Top-posting makes for a very confusing thread.



2010/3/16 Barak, Ron mailto:ron.ba...@lsi.com>>

Hi,

I'm trying to add a library path to my pythonpath, but seems it is not accepted 
-

On Windows DOS window:

C:\>echo %PYTHONPATH%
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\

C:\>python -c "import sys ; print sys.path"
['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst
em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l
ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\
site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

C:\>

On Windows cygwin:

$ echo $PYTHONPATH
.:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/

$ python -c "import sys ; print sys.path"
['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 
'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 
'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 
'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 
'c:\\Python26\\lib\\site-packages', 
'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

$

What am I doing wrong ?

Thanks,
Ron.


  
In your original message, what you displayed worked exactly as 
expected.  As you didn't say what made you think something was wrong, I 
ignored the message.


Now, you say that some modules are not found.  So how about giving some 
more specifics so someone can actually debug the problem.  Pick a 
particular module, tell us the complete path to that module, and show us 
both the sys.path strings (which look correct for the Windows case, and 
of course bogus for the cygwin case), as well as the offending import 
statement and its traceback.


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


cycling through options

2010-03-16 Thread Dieter Faulbaum

Hello,

is there a better way for cycling through all options than this:


(options, args) = parser.parse_args()
for opt in options.__dict__.keys():
 print opt, ":", options.__dict__[opt]


Thanks for any nicer solution

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


Re: How to add a library path to pythonpath ?

2010-03-16 Thread Steve Holden
Barak, Ron wrote:
> Hi,
> 
> I'm trying to add a library path to my pythonpath, but seems it is not
> accepted -
> 
> On Windows DOS window:
> 
> C:\>echo %PYTHONPATH%
> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\
>  
That looks like it should work. The only thing I notice is that I don't
have a trailing backslash on my Windows PYTHONPATH. Could that be the
problem?

regards
 Steve

> C:\>python -c "import sys ; print sys.path"
> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
> 'C:\\WINDOWS\\syst
> em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib',
> 'C:\\Python26\\l
> ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26',
> 'C:\\Python26\\lib\\
> site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
> 
> C:\>
> 
> On Windows cygwin:
> 
> $ echo $PYTHONPATH
> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/
> 
> $ python -c "import sys ; print sys.path"
> ['',
> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs',
> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win',
> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26',
> 'c:\\Python26\\lib\\site-packages',
> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
> 
> $
> 
> What am I doing wrong ?
> 
> Thanks,
> Ron.
> 
> 
>  
> 


-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread Gerard Flanagan

david jensen wrote:

... and of course i screwed up my outcomes... that should read
outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]]





abstracting the given algorithm:

def iterweights(N):
d = 1.0/(N-1)
for i in xrange(N):
yield i*d, (N-1-i)*d

def iterparts(x0, x1, N):
a = min(x0, x1)
b = max(x0, x1)
s = 2 * a
t = b - a
for m, n in iterweights(N):
if a == x0:
yield s*m, s*n+t
else:
yield s*n+t, s*m

for p in iterparts(2, 5, 5):
print p

print

for p in iterparts(5, 2, 5):
print p

(0.0, 7.0)
(1.0, 6.0)
(2.0, 5.0)
(3.0, 4.0)
(4.0, 3.0)

(7.0, 0.0)
(6.0, 1.0)
(5.0, 2.0)
(4.0, 3.0)
(3.0, 4.0)

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


RE: How to add a library path to pythonpath ?

2010-03-16 Thread Barak, Ron
Thanks for the suggestion Pable.

However, I really need the $PYTHONPATH to include this additional library, so 
all Python scripts could use it.

In Windows I have defined PYTHONPATH as 
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the Windows 
registry I have

HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as 
C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk;

However, even with all the above, the SVMInspecor modules are not found.

Bye,
Ron.


From: Pablo Recio Quijano [mailto:rikuthero...@gmail.com]
Sent: Tuesday, March 16, 2010 2:27 PM
To: python-list@python.org
Subject: Re: How to add a library path to pythonpath ?

You have to add yout path to the list:

import sys
sys.path.append(your_path)

Jus simple to add the element on the list :)

2010/3/16 Barak, Ron mailto:ron.ba...@lsi.com>>

Hi,

I'm trying to add a library path to my pythonpath, but seems it is not accepted 
-

On Windows DOS window:

C:\>echo %PYTHONPATH%
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\

C:\>python -c "import sys ; print sys.path"
['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst
em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l
ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\
site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

C:\>

On Windows cygwin:

$ echo $PYTHONPATH
.:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/

$ python -c "import sys ; print sys.path"
['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 
'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 
'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 
'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 
'c:\\Python26\\lib\\site-packages', 
'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

$

What am I doing wrong ?

Thanks,
Ron.



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




--
Pablo Recio Quijano

Estudiante de Ingeniería Informática (UCA)
Alumno colaborador del Departamento de Lenguajes y Sistemas Informáticos
Participante del IV Concurso Universitario de Software Libre
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C-API PyObject_Call

2010-03-16 Thread Steve Holden
moerchendiser2k3 wrote:
> Hi,
> 
> i have a serious problem and I am looking for a solution. I pass an
> instance of a class from a file to PyObject_Call. When something
> fails, I get a full traceback. If it succeeds, I get the return value.
> 
> Is it possible to get information from which line/file the return
> value of PyObject_Call is?
> 
> Thanks!!
> 
> moerchendiser2k3

You'll need to use a debugger like gdb that gives you access to the C
stack, I believe.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: subtraction is giving me a syntax error

2010-03-16 Thread Grant Edwards
On 2010-03-16, Steven D'Aprano  wrote:

>> Though it may not be Microsoft Word, I think I'd still maintain that
>> an editor where you can't see a ctrl-Z or tell the difference between
>> an ASCII minus and a windows-codepage-whatever isn't a very good
>> programmer's editor.
>
> Regarding ctrl-Z (or for that matter other control characters), I
> agree it's a lack.
>
> As for not being able to see the difference between a hyphen and an
> EN- dash, or minus sign, or whatever it is, yes but they are very
> similar looking glyphs in virtually ever modern font. It would take a
> good eye to see the difference between (say) ??? ??? and -.

My point is that if it's an ASCII file, then rendering \x96 as an
em-dash isn't correct.  I'd expect it to show up highlighted somehow
in hex or octal so that I know it's a non-ASCII character.

-- 
Grant Edwards   grant.b.edwardsYow! We are now enjoying
  at   total mutual interaction in
  gmail.coman imaginary hot tub ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting a timezone-less datetime to seconds since the epoch

2010-03-16 Thread Chris Rebert
On Tue, Mar 16, 2010 at 6:47 AM, Chris Withers  wrote:
> Hi All,
>
> We have a bunch of datetime objects that have tzinfo=None.
> We want to turn them into float timestamps in seconds since the epoch.
>
> Here's the first attempt:
>
> import time
> from datetime import datetime
> from unittest import TestCase
>
> def timestamp(dttm):
>    return time.mktime(dttm.timetuple())

from calendar import timegm

def timestamp(dttm):
return timegm(dttm.utctimetuple())
#the *utc*timetuple change is just for extra consistency
#it shouldn't actually make a difference here

And problem solved. As for what the problem was:

Paraphrasing the table I got added to the time module docs:
(http://docs.python.org/library/time.html)

To convert from struct_time in ***UTC***
to seconds since the epoch
use calendar.timegm()

To convert struct_time in ***local*** time
to seconds since the epoch
use time.mktime()

> I'd be *more* interested in knowing either why the timestamp function or the
> tests are wrong and how to correct them...

You used a function intended for local times on UTC time data, and
therefore got incorrect results.

Cheers,
Chris
--
Entering the workforce in 2012
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what's the diffence between "RECENT" and "UNSEEN" in imaplib?

2010-03-16 Thread Chris Rebert
On Tue, Mar 16, 2010 at 5:53 AM, freakrobot  wrote:
> When I work with the imaplib,
> there is a imap4.status(mailboxname, '(MESSAGES RECENT UNSEEN)')
> function.
>
> So I really wonder what's the difference between RECENT and UNSEEN
> conditions.
> And what kind of messages belong to RECENT condition?

A. Your question is not Python-specific and would better have been
asked somewhere more relevant.

B. RTFRFC: http://www.faqs.org/rfcs/rfc3501.html
"""
UNSEEN The number of messages which do not have the \Seen flag set.
[...]

\Seen
   Message has been read

\Recent
   Message is "recently" arrived in this mailbox. This session
is the first session to have been notified about this message; if the
session is read-write, subsequent sessions will not see \Recent set
for this message. This flag can not be altered by the client. If it is
not possible to determine whether or not this session is the first
session to be notified about a message, then that message SHOULD be
considered recent. If multiple connections have the same mailbox
selected simultaneously, it is undefined which of these connections
will see newly-arrived messages with \Recent set and which will see it
without \Recent set.
"""

Regards,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread nn


david jensen wrote:
> ... and of course i screwed up my outcomes... that should read
> outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]]

For starters:

def getOutcomes(myList=[2,5,8,3,5]):
   low_id = int(myList[0]>myList[1])
   amountToShare = 2*myList[low_id]
   remainder = myList[not low_id]-myList[low_id]
   tail=myList[2:]
   outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]
+ tail
 for perc in (1.0, 0.75, 0.5, 0.25, 0.0)]
   return outcomes
-- 
http://mail.python.org/mailman/listinfo/python-list


converting a timezone-less datetime to seconds since the epoch

2010-03-16 Thread Chris Withers

Hi All,

We have a bunch of datetime objects that have tzinfo=None.
We want to turn them into float timestamps in seconds since the epoch.

Here's the first attempt:

import time
from datetime import datetime
from unittest import TestCase

def timestamp(dttm):
return time.mktime(dttm.timetuple())

class Test(TestCase):

def check(self,*args):
epoch = datetime.utcfromtimestamp(0)
dt = datetime(*args)
actual = timestamp(dt)
d = dt - epoch
expected = d.seconds + 60*60*24*d.days
self.assertEquals(expected,actual,
'%s != %s (diff %s)'%(expected,actual,expected-actual))

def test_xmas(self):
self.check(2009, 12, 25, 1, 2, 3, 456789)

def test_midsummer(self):
self.check(2009, 6, 21, 2, 3, 4, 5678)

For me, test_midsummer fails. I'd be interested in knowing wheher both 
tests pass for other people.


I'd be *more* interested in knowing either why the timestamp function or 
the tests are wrong and how to correct them...


cheers,

Chris

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


Re: Build Python with XCode

2010-03-16 Thread Kevin Walzer

On 3/15/10 11:15 PM, moerchendiser2k3 wrote:

Hi,

I would like to build Python with Xcode (but without the makefile).
Does anyone know a link where I can get a real xcodeproj with the
current Py2.x sources?


Thanks in advance!! Bye, donnerCobra


I don't think one exists--I build my Python on OS Xwith configure, make 
etc.-- but you could try asking on the MacPython list.


--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
... and of course i screwed up my outcomes... that should read
outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]]



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


Re: Understanding the CPython dict implementation

2010-03-16 Thread Michiel Overtoom

On 16 Mar 2010, at 12:46 , Steven D'Aprano wrote:

> On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote:
> 
>> I found this PyCon2010 presentation to be excellent: The Mighty
>> Dictionary, Branden Craig Rhodes, 30 min.
>> http://pycon.blip.tv/file/3264041/
> 
> 
> Unfortunately, that clip seems to be unwatchable, at least for me. It 
> crashed the Netscape plugin in Konqueror, and crashed Firefox. When I 
> downloaded the ogv file, it crashed MPlayer and Kaffeine.

It played in VLC without problems.

Greetings,


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


Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread david jensen
Hi all,

This may be a complete brainfart, but it's been puzzling me for a day
or two (!).
Sorry for not describing "something" in the subject, but it's hard to
describe succinctly:

I have a short list of non-zero positive integers (say
myList=[2,5,8,3,5]). I need to return five lists of non-negative
numbers, such that for five different "share sizes", myList[0] and
myList[1] will share twice the smaller amount...

def getOutcomes():
outcomes=[]
if myList[0]<=myList[1]:
amountToShare=2*myList[0]
remainder=myList[1]-myList[0]
outcome.append((amountToShare, remainder)+myList[2:])   #
shares are (100%, 0)
outcome.append((amountToShare*0.75, remainder
+amountToShare*0.25)+myList[2:])   #shares are (75%, 25%), and exactly
the same for (50%,50%), (25%, 75%), and (0,100%)
...
...
return outcomes

i.e. for the above myList, outcomes=[[4,1,8,3,5], [3,2,8,3,5],
[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]]

if myList[0]>myList[1], i want exactly the opposite to happen (i.e.,
just switching what happens to positions 0 and 1)

Obviously, i can just write the code again, in an else, switching
indices 0 and 1. Or, I could just have a test at the beginning, switch
them if they are in the order "big, small", and then switch them again
at the end in a list comprehension. Both ideas seem terribly silly,
and there must be an obvious way to do it that I'm not seeing.

any help?

many thanks

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


what's the diffence between "RECENT" and "UNSEEN" in imaplib?

2010-03-16 Thread freakrobot
When I work with the imaplib,
there is a imap4.status(mailboxname, '(MESSAGES RECENT UNSEEN)')
function.

So I really wonder what's the difference between RECENT and UNSEEN
conditions.
And what kind of messages belong to RECENT condition?
Thank you~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class inheritance

2010-03-16 Thread Dave Angel



Carl Banks wrote:

On Mar 15, 4:34 pm, JLundell  wrote:
  

It's also unfortunate that Python doesn't have an approximately-equal
operator; it'd come in handy for floating-point applications while
preserving hash. If only there were a ~=r ≈ operator I could
overload. And ~ is unary, so no joy.



One problem with it is that there's no way to make it universal;
different appiplications have different ideas of close.  Conceivably
it could be usefully defined for a user type though..

Bacause of this problem almost no languages have an almost equal
operator.  I'm curious what languages do, of if there are any with a
trinary operator that also takes a threshold.

Carl Banks

  
If I recall correctly, APL has a *fuzz* value, which is used in all(?) 
comparisons. But I do not recall anything about how it was defined. I do 
recall that you could change the threshold, and suspect it was relative 
to the operands. For symmetry, it would probably have to be relative to 
the average of the two values, or some such.

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


Re: How to add a library path to pythonpath ?

2010-03-16 Thread Pablo Recio Quijano
You have to add yout path to the list:

import sys
sys.path.append(your_path)

Jus simple to add the element on the list :)

2010/3/16 Barak, Ron 

>  Hi,
>
> I'm trying to add a library path to my pythonpath, but seems it is not
> accepted -
>
> On Windows DOS window:
>
> C:\>echo %PYTHONPATH%
> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\
>
> C:\>python -c "import sys ; print sys.path"
> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
> 'C:\\WINDOWS\\syst
> em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib',
> 'C:\\Python26\\l
> ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26',
> 'C:\\Python26\\lib\\
> site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
>
> C:\>
>
> On Windows cygwin:
>
> $ echo $PYTHONPATH
> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/
>
> $ python -c "import sys ; print sys.path"
> ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib',
> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs',
> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win',
> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26',
> 'c:\\Python26\\lib\\site-packages',
> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
>
> $
>
> What am I doing wrong ?
>
> Thanks,
> Ron.
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Pablo Recio Quijano

Estudiante de Ingeniería Informática (UCA)
Alumno colaborador del Departamento de Lenguajes y Sistemas Informáticos
Participante del IV Concurso Universitario de Software Libre
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import antigravity

2010-03-16 Thread Alf P. Steinbach

* Ulrich Eckhardt:

Chris Rebert wrote:

You're a bit behind the times.
If my calculations are right, that comic is over 2 years old.


import timetravel


  C:\test> python
  Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)]
  on win32
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import time
  >>> time.altzone
  -7200
  >>> # hm.
  ...
  >>> _


Cheers,

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


How to add a library path to pythonpath ?

2010-03-16 Thread Barak, Ron
Hi,

I'm trying to add a library path to my pythonpath, but seems it is not accepted 
-

On Windows DOS window:

C:\>echo %PYTHONPATH%
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\

C:\>python -c "import sys ; print sys.path"
['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst
em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l
ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\
site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

C:\>

On Windows cygwin:

$ echo $PYTHONPATH
.:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/

$ python -c "import sys ; print sys.path"
['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 
'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 
'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 
'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 
'c:\\Python26\\lib\\site-packages', 
'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']

$

What am I doing wrong ?

Thanks,
Ron.


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


Re: import antigravity

2010-03-16 Thread Chris Rebert
On Tue, Mar 16, 2010 at 4:56 AM, Ulrich Eckhardt
 wrote:
> Chris Rebert wrote:
>> You're a bit behind the times.
>> If my calculations are right, that comic is over 2 years old.
>
> import timetravel
>
> Uli

So that's where Guido's been hiding his infamous time machine! Right
in plain sight!
It's so obvious in retrospect.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


The first ASIC designed with MyHDL

2010-03-16 Thread Jan Decaluwe

I am proud to report on the first ASIC product
designed with MyHDL (afaik).

http://www.jandecaluwe.com/hdldesign/digmac.html

--
Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com
Python as a HDL: http://www.myhdl.org
VHDL development, the modern way: http://www.sigasi.com
Analog design automation: http://www.mephisto-da.com
World-class digital design: http://www.easics.com
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >