Decorators inside of class and decorator parameters

2007-01-13 Thread MR
Hello All,

I have a question about decorators, and I think an illustration would
be helpful. Consider the following simple class:

#begin code
class Foo:
def fooDecorator(f):
print "fooDecorator"

def _f(self, *args, **kw):
return f(self, *args, **kw)

return _f

@fooDecorator
def fooMethod(self):
print "fooMethod"

f = Foo()
f.fooMethod()
#end of code

This code runs, and actually serves my purpose. However, I'm a little
confused about three things and wanted to try and work through them
while I had the time to do so. I believe all of my confusion is related
to the parameters related to the fooDecorator:

-how I would pass arguments into the fooDecorator if I wanted to (my
various attempts have failed)
-what the difference is between decorating with @fooDecorator versus
@fooDecorator()
-why does this code even work, because the first argument to
fooDecorator isn't self

I'm searched the net and read the PEPs that seemed relevant, but I
didn't see much about decorators inside of a class like this. Can
anyone comment on any of these three things?

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


Re: Decorators inside of class and decorator parameters

2007-01-14 Thread MR
Thanks so much for your reply.  You've definitely helped me a great
deal on this. Your comment about the difference between define time and
instantiation time cleared things up more than anything, and that also
helped clear up the confusion I was having about "self".

I think the places I've seen decorators called like fooDecorator() must
be using some default arguments in the function signature...so that
part makes a lot more sense now too.

Thanks again!


Gabriel Genellina wrote:
> "MR" <[EMAIL PROTECTED]> escribió en el mensaje
> news:[EMAIL PROTECTED]
>
> > I have a question about decorators, and I think an illustration would
> > be helpful. Consider the following simple class:
> >
> > #begin code
> > class Foo:
> >def fooDecorator(f):
> >print "fooDecorator"
> >
> >def _f(self, *args, **kw):
> >return f(self, *args, **kw)
> >
> >return _f
> >
> >@fooDecorator
> >def fooMethod(self):
> >print "fooMethod"
> >
> > f = Foo()
> > f.fooMethod()
> > #end of code
> >
> > This code runs, and actually serves my purpose. However, I'm a little
> > confused about three things and wanted to try and work through them
> > while I had the time to do so. I believe all of my confusion is related
> > to the parameters related to the fooDecorator:
>
> [I reordered your questions to make the answer a bit more clear]
>
> > -why does this code even work, because the first argument to
> > fooDecorator isn't self
>
> fooDecorator is called when the class is *defined*, not when it's
> instantiated. `self` has no meaning inside it, neither the class to which it
> belongs (Foo does not even exist yet).
> At this time, fooDecorator is just a simple function, being collected inside
> a namespace in order to construct the Foo class at the end. So, you get
> *exactly* the same effect if you move fooDecorator outside the class.
>
> > -how I would pass arguments into the fooDecorator if I wanted to (my
> > various attempts have failed)
>
> Once you move fooDecorator outside the class, and forget about `self` and
> such irrelevant stuff, it's just a decorator with arguments.
> If you want to use something like this:
>@fooDecorator(3)
>def fooMethod(self):
> that is translated to:
>fooMethod = fooDecorator(3)(fooMethod)
> That is, fooDecorator will be called with one argument, and the result must
> be a normal decorator - a function accepting a function an an argument and
> returning another function.
>
> def outerDecorator(param):
>   def fooDecorator(f):
> print "fooDecorator"
>
> def _f(self, *args, **kw):
> print "decorated self=%s args=%s kw=%s param=%s" % (self, args, kw,
> param)
> kw['newparam']=param
> return f(self, *args, **kw)
>
> return _f
>   return fooDecorator
>
> This is the most direct way of doing this without any help from other
> modules - see this article by M. Simoniato
> http://www.phyast.pitt.edu/~micheles/python/documentation.html for a better
> way using its decorator factory.
>
> > -what the difference is between decorating with @fooDecorator versus
> > @fooDecorator()
> Easy: the second way doesn't work :)
> (I hope reading the previous item you can answer this yourself)
>
> > I'm searched the net and read the PEPs that seemed relevant, but I
> > didn't see much about decorators inside of a class like this. Can
> > anyone comment on any of these three things?
> As said in the beginning, there is no use for decorators as methods (perhaps
> someone can find a use case?)
> If you move the example above inside the class, you get exactly the same
> results.
> 
> HTH,
> 
> -- 
> Gabriel Genellina

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


Re: Decorators inside of class and decorator parameters

2007-01-14 Thread MR
Wow. Really neat stuff there. memoize seems especially cool since you
can get lots of nice dynamic programming benefits "for free" (sorry if
I just stated the obvious, but I thought was was especially cool.)


Michele Simionato wrote:
> Gabriel Genellina wrote:
> > see this article by M. Simoniato
> > http://www.phyast.pitt.edu/~micheles/python/documentation.html for a better
> > way using its decorator factory.
>
> Actually the name is Simionato ;)
> I have just released version 2.0, the new thing is an update_wrapper
> function similar to the one
> in the standard library, but with the ability to preserve the signature
> on demand. For instance
>
> def traced(func):
>def wrapper(*args, **kw):
>print 'calling %s with args %s, %s' % (func, args, kw)
>return func(*args, **kw)
>   return update_wrapper(wrapper, func, create=False)
>
> works exactly as functools.update_wrapper (i.e. copies__doc__,
> __module__,etc. from func to wrapper without
> preserving the signature), whereas update_wrapper(wrapper, func,
> create=True) creates a new wrapper
> with the right signature before copying the attributes.
> 
>  Michele Simionato

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


Re: Is there a better algorithm?

2009-01-02 Thread mr
As has been noted, the best is to fix the input to be regular-3-
tuples. For the fun of it, here's another variation of a solution:

tuples = [(1, 2), (3, 4, 5), (6, 7)]

def triple_or_pair(seq):
u = None
try:
k, u, v = seq
except ValueError:
k, v = seq
return k, u, v

for k, u, v in [ triple_or_pair(seq) for seq in tuples ]:
print k, u, v
--
http://mail.python.org/mailman/listinfo/python-list


Re: Installation of Py3.0rc1 fails on Mac OS X with bad locale

2008-11-08 Thread mr
On Nov 1, 4:40 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
>
> It would be best if a Mac user could propose a patch for that problem
> before the release of Python 3.0.

Not sure if this would qualify as a patch, but a workaround that seems
to be working for me is to change the bash environment's default
locale setting -- to a value acceptable to py3.

I did this by adding the following line to /etc/profile:

export LC_ALL="en_US.UTF-8"

Presumably, other valid values should also work correctly.

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


Re: ValueError: unknown locale: UTF-8

2008-06-02 Thread mr
On Jun 1, 8:43 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > ValueError: unknown locale: UTF-8
>
> > This is on open bug or is there more to it?
>
> Do you have an environment variable set who is named
> either LANG or starts with LC_?

Actually, yes:

LC_CTYPE=UTF-8

where is it coming from? This is basically on a clean new machine...
who might be setting it? It is coming from a program elsewhere on the
system? How should python code deal with this?

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


Differences of "!=" operator behavior in python3 and python2 [ bug? ]

2013-05-12 Thread Mr. Joe
I seem to stumble upon a situation where "!=" operator misbehaves in
python2.x. Not sure if it's my misunderstanding or a bug in python
implementation. Here's a demo code to reproduce the behavior -
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function

class DemoClass(object):
def __init__(self, val):
self.val = val

def __eq__(self, other):
return self.val == other.val

x = DemoClass('a')
y = DemoClass('a')

print("x == y: {0}".format(x == y))
print("x != y: {0}".format(x != y))
print("not x == y: {0}".format(not x == y))
"""

In python3, the output is as expected:
"""
x == y: True
x != y: False
not x == y: False
"""

In python2.7.3, the output is:
"""
x == y: True
x != y: True
not x == y: False
"""
Which is not correct!!

Thanks in advance for clarifications.
Regards,
TB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-14 Thread Mr. Joe
Sorry for digging this old topic back. I see that my "'property' does not
play well with polymorphic code" comment generated some controversy. So
here's something in my defense:

Here's the link to stackoveflow topic I am talking about:

http://stackoverflow.com/questions/237432/python-properties-and-inheritance

The solution that fits my taste:
http://stackoverflow.com/a/14349742

A related blogpost:

http://requires-thinking.blogspot.com/2006/03/note-to-self-python-properties-are-non.html

Yes, I like decorators and descriptors. I also like the ability to create a
"virtual property" in a python class by binding a bunch of methods as
setter/getter. But I find the implementation of this "virtual property
feature" a bit awkward sometimes - every time I need to override a
getter/setter in a child class, I need to decorate them again. Some of you
may like this "explicitness", but I don't.

To Steven D'Aprano: Seriously, what's all the bashing in your last reply
about? You dissected my "thank-you reply" more strictly than the python
interpreter checking for syntax errors. Not in a mood for fight, but I find
your opinions about "bug finding time", "hacks" and "stackoverflow" quite
silly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-15 Thread Mr. Joe
On Wed, May 15, 2013 at 12:15 PM, dieter  wrote:
>
>   If Python would automatically redecorate overridden methods in a derived
>   class, I would have no control over the process. What if I need
>   the undecorated method or a differently decorated method (an
>   uncached or differently cached method, in my case)?
>

On a second thought, I am convinced by your argument.

> Your getter/setter use case can quite easily be solved
> with a class "DelayedMethodAccessor":
>
>   class DelayedMethodAccess(object):
> """
> def __init__(self, name): self.__name = name
> def __call__(self, inst, *args, **kw):
>   return getattr(inst, self.__name)(*args, **kw)
>
> You can then use:
>
>prop = property(DelayedMethodAccess(""), ...)
>
> Or define a new decorator "property_by_name" and then
> use
>
>prop = property_by_name("", ...)
>
> Of course, this requires that the property name and the getter/setter
names
> differ, but this should be naturally enough.
>
>
> Python's current behavior is very natural once you know that
> decorators are just syntactic sugar and
>
>@
>def ...
>
> simply means:
>
>def ...
>f = (f)
>
> True, this is no perfect fit for all use cases - but
> such a fit (if it existed at all) would have to be so complex
> that only experts could understand it.

Thanks for these really nice patterns. They fits my problem very well.
-- 
http://mail.python.org/mailman/listinfo/python-list


New Python implementation

2021-02-11 Thread Mr Flibble


Hi!

I am starting work on creating a new Python implementation from scratch using 
"neos" my universal compiler that can compile any programming language.  I 
envision this implementation to be significantly faster than the currently extant Python 
implementations (which isn't a stretch given how poorly they perform).

Sample neos session (parsing a fibonacci program, neoscript rather than Python 
in this case):

neos 1.0.0.0 ED-209
] help
h(elp)
s(chema)Load language schema
l(oad)  Load program
list List program
c(ompile)Compile program
r(un)Run program
![]  Evaluate expression (enter interactive 
mode if expression omitted)
: Input (as stdin)
q(uit)   Quit neos
lc   List loaded concept libraries
t(race) <0|1|2|3|4|5> [] Compiler trace
m(etrics)Display metrics for running programs
] lc
[neos.core] (file:///D:\code\neos\build\win32\vs2019\x64\Release\core.ncl)
  [neos.boolean]
  [neos.language]
  [neos.logic]
  [neos.math]
  [neos.module]
  [neos.object]
  [neos.string]
[neos.math.universal] 
(file:///D:\code\neos\build\win32\vs2019\x64\Release\core.math.universal.ncl)
] s neoscript
Loading schema 'neoscript'...
Language: Default neoGFX scripting language
Version: 1.0.0
Copyright (C) 2019 Leigh Johnston
neoscript] l examples/neoscript/fibonacci.neo
neoscript] list
File 'examples/neoscript/fibonacci.neo':
-- neoscript example: Fibonacci

using neos.string;
using neos.stream;

import fn to_string(x : i32) -> string;
import fn to_integer(s : string) -> i32;
import proc input(s : out string);
import proc print(s : in string);

-- functions are pure
def fn add(x, y : i32) -> i32
{
return x + y;
}
def fn fib(x : i32) -> i32
{
if (x < 2)
return 1;
else
return add(fib(x-1), fib(x-2));
}

-- procedures are impure
def proc main()
s : string;
{
print("Enter a positive "
"integer: ");
input(s);
print("Fibonacci(" + s + ") = " + to_string(fib(to_integer(s))) + "\n");
}
neoscript] t 1
neoscript] c
folding: string.utf8() <- string.utf8.character.alpha()
folded: string.utf8() <- string.utf8.character.alpha() = string.utf8(g)
folding: string.utf8(g) <- string.utf8.character.alpha()
folded: string.utf8(g) <- string.utf8.character.alpha() = string.utf8(gn)
folding: string.utf8(gn) <- string.utf8.character.alpha()
folded: string.utf8(gn) <- string.utf8.character.alpha() = string.utf8(gni)
folding: string.utf8(gni) <- string.utf8.character.alpha()
folded: string.utf8(gni) <- string.utf8.character.alpha() = string.utf8(gnir)
folding: string.utf8(gnir) <- string.utf8.character.alpha()
folded: string.utf8(gnir) <- string.utf8.character.alpha() = string.utf8(gnirt)
folding: string.utf8(gnirt) <- string.utf8.character.alpha()
folded: string.utf8(gnirt) <- string.utf8.character.alpha() = 
string.utf8(gnirts)
folding: string.utf8(gnirts) <- string.utf8.character.period()
folded: string.utf8(gnirts) <- string.utf8.character.period() = 
string.utf8(gnirts.)
folding: string.utf8(gnirts.) <- string.utf8.character.alpha()
folded: string.utf8(gnirts.) <- string.utf8.character.alpha() = 
string.utf8(gnirts.s)
folding: string.utf8(gnirts.s) <- string.utf8.character.alpha()
folded: string.utf8(gnirts.s) <- string.utf8.character.alpha() = 
string.utf8(gnirts.so)
folding: string.utf8(gnirts.so) <- string.utf8.character.alpha()
folded: string.utf8(gnirts.so) <- string.utf8.character.alpha() = 
string.utf8(gnirts.soe)
folding: string.utf8(gnirts.soe) <- string.utf8.character.alpha()
folded: string.utf8(gnirts.soe) <- string.utf8.character.alpha() = 
string.utf8(gnirts.soen)
folding: source.package.name() <- string.utf8(gnirts.soen)
folded: source.package.name() <- string.utf8(gnirts.soen) = 
source.package.name(neos.string)
folding: source.package.import() <- source.package.name(neos.string)
folded: source.package.import() <- source.package.name(neos.string) = 
source.package.import(neos.string)
folding: source.package.import(neos.string) <- 
source.package.import(neos.string)
folding: string.utf8() <- string.utf8.character.alpha()
folded: string.utf8() <- string.utf8.character.alpha() = string.utf8(g)
folding: string.utf8(g) <- string.utf8.character.alpha()
folded: string.utf8(g) <- string.utf8.character.alpha() = string.utf8(gn)
folding: string.utf8(gn) <- string.utf8.character.alpha()
folded: string.utf8(gn) <- string.utf8.character.alpha() = string.utf8(gni)
folding: string.utf8(gni) <- string.utf8.character.alpha()
folded: string.utf8(gni) <- string.utf8.character.alpha() = string.utf8(gnir)
folding: string.utf8(gnir) <- string.utf8.character.alpha()
folded: string.utf8(gnir) <- string.utf8.character.alpha() = string.utf8(gnirt)
folding: string.utf8(gnirt) <- string.utf8.character.alpha()
folded: 

Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 15:13, Chris Angelico wrote:

On Thu, Feb 11, 2021 at 11:36 PM Mr Flibble
 wrote:



Hi!

I am starting work on creating a new Python implementation from scratch using 
"neos" my universal compiler that can compile any programming language.


Is it your intention to support all of Python's syntax and semantics,


Yes.


or is this an unrelated language with mandatory strict type tags and a
severely restricted set of data types? For instance, can your neos
compile this code?


No. The neos universal compiler itself is language agnostic: a pre-requisite 
for the requirement to be able to compile any programming language.



def power():
 return (2**3**4**2) % 10

from time import time
start = time()
print(power())
time = time() - start
print("Took %s seconds" % time)

On my system, I get this from CPython 3.10:
176561152
Took 0.1589798927307129 seconds

And this from PyPy:
176561152
Took 0.0233387947083 seconds


I envision this implementation to be significantly faster than the currently 
extant Python implementations (which isn't a stretch given how poorly they 
perform).


Riight, yep, all existing Python implementations are terribly
slow. Go ahead then; run the code above, show me a better time, and of
course compare to what a recent off-the-shelf CPython can do on the
same hardware. Then see how PyPy performs at the same job.


You are timing the arithmetic library rather than the interpreter.




Sample neos session (parsing a fibonacci program, neoscript rather than Python 
in this case):


Is neoscript an intermediate language like RPython, used only to
implement the compiler, or are you actually transforming Python code
into neoscript?


neoscript is the neos reference language (i.e. not an intermediate language) 
and will be unrelated to the Python implementation.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 16:31, Dan Stromberg wrote:

On Thu, Feb 11, 2021 at 4:35 AM Mr Flibble 
wrote:



Hi!

I am starting work on creating a new Python implementation from scratch
using "neos" my universal compiler that can compile any programming
language.  I envision this implementation to be significantly faster than
the currently extant Python implementations (which isn't a stretch given
how poorly they perform).



I'd like to encourage you to give this a go.  It's a huge task, but it's
needed.


Actually it is a relatively small task due to the neos universal compiler's 
architectural design.  If it was a large task I wouldn't be doing it.



You may be interested in the approaches of Pypy, Cython, Shedskin and
Nuitka.


I am not particularly interested in any of the existing implementations as they 
bear no relation to the design of my language agnostic universal compiler, 
runtime, VM and JIT; the only use they will have will be to disambiguate 
certain Python language constructs that I cannot disambiguate from 
documentation alone: this is a natural consequence of Python not being 
standardized; those steering the language need to grow a pair and get Python 
standardized preferably as an ISO Standard.



Pypy is a Python written in RPython, where RPython is a restricted subset
of Python 2.  It can translate RPython to C, or JIT compile pretty full
Python code - 2.x or 3.x.  It has trouble with C extension modules, as the
CPython API for extension modules is pretty leaky. CFFI appears to be the
big hope of fixing this problem, but most C extension modules still use the
CPython C extension Module API.


RPython doesn't interest me. neos will be using libffi for FFI.



Cython transpiles a Python-like language to C.  It allows you to intermix
Python datatypes and C datatypes; the more you use C datatypes, the faster
the result is.  It can be slower if you aren't careful with your type
conversions, but it can be faster if used well.  It has a really nice
--annotate option that shows how close to C your program is, line by line.


I don't agree with the concept of delivering C compilers to end users. The only 
compilers I think end users should be running are GPU shader compilers and 
byecode/JIT compilers such as neos.



Shedskin transpiles an implicitly static subset of Python 2 to C++.  It's a
great tool, but sadly it is unlikely to make the jump from Python 2 to
Python 3, and Python 3 is definitely the future of Python.


Not interested in that (see previous answer replacing "C" with "C++").



Nuitka is a Python -> C/C++ transpiler.  I know little about it, but it
sounds kind of like what you're proposing.  It's been focusing on
compatibility first, followed by performance.


Bears no relation to neos architecture.



Good luck!


Thanks for the sentiment but I am not relying on luck.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 18:03, Chris Angelico wrote:


In any case, it's not Python if it can't handle arbitrarily large
numbers. Python is an excellent language for mathematics.


I am also creating Ada and Haskell implementations which have a similar 
requirement.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 18:06, Chris Angelico wrote:

On Fri, Feb 12, 2021 at 5:01 AM Mr Flibble
 wrote:


On 11/02/2021 16:31, Dan Stromberg wrote:

On Thu, Feb 11, 2021 at 4:35 AM Mr Flibble 
wrote:



Hi!

I am starting work on creating a new Python implementation from scratch
using "neos" my universal compiler that can compile any programming
language.  I envision this implementation to be significantly faster than
the currently extant Python implementations (which isn't a stretch given
how poorly they perform).



I'd like to encourage you to give this a go.  It's a huge task, but it's
needed.


Actually it is a relatively small task due to the neos universal compiler's 
architectural design.  If it was a large task I wouldn't be doing it.



You may be interested in the approaches of Pypy, Cython, Shedskin and
Nuitka.


I am not particularly interested in any of the existing implementations as they 
bear no relation to the design of my language agnostic universal compiler, 
runtime, VM and JIT; the only use they will have will be to disambiguate 
certain Python language constructs that I cannot disambiguate from 
documentation alone: this is a natural consequence of Python not being 
standardized; those steering the language need to grow a pair and get Python 
standardized preferably as an ISO Standard.



You keep insulting Python and the Python devs. Put up or shut up -
show some actual code before you make too many boasts.

Python DOES have a strong language specification. Its semantics are
documented. If you find places where the documentation is lacking,
point them out specifically, don't FUD your way through.


For a language to transition from "toy" status it has to be formally 
standardized.  It is unacceptable to define a language in terms of a particular 
implementation. A git repo of Source code and associated observable dynamic behaviour 
when that code is compiled and ran is a poor substitute for an official ISO Standard.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 18:24, Paul Bryan wrote:

On Thu, 2021-02-11 at 17:56 +, Mr Flibble wrote:


Actually it is a relatively small task due to the neos universal
compiler's architectural design.  If it was a large task I wouldn't
be doing it.


When do you estimate this task will be completed?


I am not particularly interested in any of the existing
implementations as they bear no relation to the design of my language
agnostic universal compiler, runtime, VM and JIT; the only use they
will have will be to disambiguate certain Python language constructs
that I cannot disambiguate from documentation alone: this is a
natural consequence of Python not being standardized; those steering
the language need to grow a pair and get Python standardized
preferably as an ISO Standard.


I take it you don't hope to receive any support from those you're
insulting by such a statement?


Thanks for the sentiment but I am not relying on luck.


By your conduct so far, I think you will also not be relying on the
goodwill of this community.


Personally I prefer telling it like it is (i.e. the truth) rather than walking 
on eggshells.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 21:13, Dan Stromberg wrote:

Does your project have a name yet?  I'd like to follow it through google
alerts or an announcement mailing list.


"neos" - https://neos.dev/ https://github.com/i42output/neos

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 22:25, Dan Stromberg wrote:

On Thu, Feb 11, 2021 at 2:00 PM Mr Flibble 
wrote:


On 11/02/2021 21:13, Dan Stromberg wrote:

Does your project have a name yet?  I'd like to follow it through google
alerts or an announcement mailing list.


"neos" - https://neos.dev/ https://github.com/i42output/neos



Pypi already appears to have another project named neos:
https://pypi.org/project/neos/


neos isn't a Python package so that isn't a problem.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 23:12, Greg Ewing wrote:

On 12/02/21 11:33 am, Mr Flibble wrote:

neos isn't a Python package so that isn't a problem.


It might be a bit confusing if it ever becomes part of the
wider Python ecosystem, though.

 Python is but one language that neos will implement.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-11 Thread Mr Flibble

On 11/02/2021 23:05, Paul Rubin wrote:

Mr Flibble  writes:

"neos" - https://neos.dev/ https://github.com/i42output/neos


Good luck, let us know when it is done.  What is there doesn't look like
a credible start so far, but maybe you will surprise us.  Have you
actually written any code in the languages you say you are going to
support?  E.g. Ada, Haskell, Rust.  I'd agree that Python is fairly
simple compared to those.


Not credible? On what do you base that analysis?

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-12 Thread Mr Flibble

On 12/02/2021 02:45, Terry Reedy wrote:

On 2/11/2021 5:33 PM, Mr Flibble wrote:

On 11/02/2021 22:25, Dan Stromberg wrote:

On Thu, Feb 11, 2021 at 2:00 PM Mr Flibble 
wrote:


On 11/02/2021 21:13, Dan Stromberg wrote:

Does your project have a name yet?  I'd like to follow it through google
alerts or an announcement mailing list.


"neos" - https://neos.dev/ https://github.com/i42output/neos



Pypi already appears to have another project named neos:
https://pypi.org/project/neos/


neos isn't a Python package so that isn't a problem.


Since it obviously is a Python package, as in importable into a Python program, 
why do you deny it?


You are mistaken: it isn't a Python package and it isn't importable into a 
Python program.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-12 Thread Mr Flibble

On 12/02/2021 00:15, Alan Gauld wrote:

On 11/02/2021 12:30, Mr Flibble wrote:


I am starting work on creating a new Python implementation
from scratch using "neos" my universal compiler that can
compile any programming language.


Can i clarify that?
Are you saying that you are going to recompile the existing
C code for pyhton using yoour universal compiler and the
resulting binary file will be a new implementation of
the interpreter that you expect to be faster?


Nope.



That's what it sounds like to me.
In which case the question is not whether you can write a
better interpreter than CPython but whether you can write
a better compiler than GNU/MING/VC etc


See previous answer.



While a universal compiler is  certainly an interesting
and challenging project I'm not sure how much it tells us
about existing Python implementations.


The two things are unrelated; however it is well known that Python is slow.



On the other hand, if you are planning on rewriting the
existing interpreter in something other than C, what
is that something?


Nope.




Sample neos session (parsing a fibonacci program,
neoscript rather than Python in this case):


I'm not sure what relevance this has unless you want
to rewrite Python in neoscript? Or are you translating
the C into neoscript and then compiling it? But in a
later response you seem to say neoscript was not involved?

Slightly confused...



The neos Python implementation will consist of a schema file which describes 
the language plus any Python-specific semantic concepts that don't generalize 
to more than one language.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 13/02/2021 00:01, Alan Gauld wrote:

On 12/02/2021 21:46, Mr Flibble wrote:


The neos Python implementation will consist of a schema file
which describes the language plus any Python-specific semantic concepts


So the schema file is some kind of formal grammar definition of
the language?

And you "compile" this directly into machine code?
Is that the idea?

So when you say you have a universal compiler for any language
what you mean is that you can produce a compiler/interpreter
for any language from a language definition/schema. Is that it?

I'm still not sure I understand what exactly you are proposing
to do. What the final output looks like?

I'm assuming it's a new executable interpreter that can run any
valid python code. Is that correct?


It is a universal *compiler* so it compiles the python code to byte code and 
then optionally to machine code via a JIT which is then executed.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 13/02/2021 18:11, Alan Gauld wrote:

On 13/02/2021 16:09, Mr Flibble wrote:

On 13/02/2021 00:01, Alan Gauld wrote:

I'm assuming it's a new executable interpreter that can run any
valid python code. Is that correct?


It is a universal *compiler* so it compiles the python code to byte code
and then optionally to machine code via a JIT which is then executed.


OK, sorry for being dense, but just to be absolutely clear.

You are going to create a Python compiler that will take existing
Python code and output a byte code file. (I assume the byte code
is not standard Python byte code?) And I assume the execution
environment for the bytecode is part of your neos system?


No neos is not a Python compiler: it is a *universal* compiler that can compile 
any programming language describable by a schema file and any language-specific 
semantic concepts.  The byte code will be proprietary, yes, and will be 
executed by neos and/or JITed.



If that's correct, then how do you propose to deal with
regular Python byte code? And what would the Python disassembler
produce - Python assembler instructions or neos?


The neos Python implementation will not be dealing with Python byte code in any 
form whatsoever.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 13/02/2021 23:30, Igor Korot wrote:

Hi,
But most importantly - what is the reason for this ?
I mean - what problems the actual python compiler produce?

Thank you.


I am creating neos as I need a performant scripting engine for my other major project 
"neoGFX" and I want to be able to support multiple popular scripting languages 
including Python.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 14/02/2021 00:19, Chris Angelico wrote:

On Sun, Feb 14, 2021 at 11:14 AM Mr Flibble
 wrote:


On 13/02/2021 23:30, Igor Korot wrote:

Hi,
But most importantly - what is the reason for this ?
I mean - what problems the actual python compiler produce?

Thank you.


I am creating neos as I need a performant scripting engine for my other major project 
"neoGFX" and I want to be able to support multiple popular scripting languages 
including Python.



Until you have actually produced a (mostly) compatible Python
implementation, can you please stop making these repeated and baseless
jabs at CPython's performance? You keep stating or hinting that
CPython is somehow unnecessarily slow, but unless you have some code
to back your claims, this is nothing but mudslinging.

CPython is not as slow as you might think. And PyPy is highly
efficient at what it does well. Show us that you can do better than
these before you call them slow.

At the absolute least, show that you have something that can run Python code.


It isn't just me that is saying CPython is egregiously slow: it is at the 
bottom of the list as far as performance is concerned. Python is undoubtedly 
the biggest contributor to climate change of all the programming languages in 
mainstream use today.

See: 
https://thenewstack.io/which-programming-languages-use-the-least-electricity/

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 14/02/2021 00:51, Ned Batchelder wrote:

On Saturday, February 13, 2021 at 7:19:58 PM UTC-5, Chris Angelico wrote:

On Sun, Feb 14, 2021 at 11:14 AM Mr Flibble
 wrote:


On 13/02/2021 23:30, Igor Korot wrote:

Hi,
But most importantly - what is the reason for this ?
I mean - what problems the actual python compiler produce?

Thank you.


I am creating neos as I need a performant scripting engine for my other major project 
"neoGFX" and I want to be able to support multiple popular scripting languages 
including Python.


Until you have actually produced a (mostly) compatible Python
implementation, can you please stop making these repeated and baseless
jabs at CPython's performance? You keep stating or hinting that
CPython is somehow unnecessarily slow, but unless you have some code
to back your claims, this is nothing but mudslinging.

CPython is not as slow as you might think. And PyPy is highly
efficient at what it does well. Show us that you can do better than
these before you call them slow.

At the absolute least, show that you have something that can run Python code.

ChrisA


The OP has been making these claims on IRC for a while (at least two years). He 
has never cared to substantiate them, or even participate in a civil and 
detailed discussion.  He is either 1) smarter than all of us, or 2) woefully 
under-informed, or 3) trolling.  Our best course is to ignore him until he has 
code we can try.


I am sure you are most annoyed that you can't ban me from Usenet, dear, like 
you banned me from IRC. You need to grow the fuck up.

Your use of the words "all of us" is disingenuous, try "me" instead.  "All of 
us" includes people as smart as me but can't be arsed fixing the Python space because they can just 
about live with the status quo.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 14/02/2021 03:35, Paul Rubin wrote:

Mr Flibble  writes:

I am creating neos as I need a performant scripting engine for my
other major project "neoGFX" and I want to be able to support multiple
popular scripting languages including Python.


Is something wrong with Guile for that purpose?  If yes, maybe you are
setting yourself up for the exact same obstacles ;-).


NIH.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 14/02/2021 02:54, Mark Lawrence wrote:

On Sunday, February 14, 2021 at 2:18:03 AM UTC, Mr Flibble wrote:

On 14/02/2021 00:51, Ned Batchelder wrote:
  

The OP has been making these claims on IRC for a while (at least two years). He 
has never cared to substantiate them, or even participate in a civil and 
detailed discussion. He is either 1) smarter than all of us, or 2) woefully 
under-informed, or 3) trolling. Our best course is to ignore him until he has 
code we can try.

I am sure you are most annoyed that you can't ban me from Usenet, dear, like 
you banned me from IRC. You need to grow the fuck up.


I take it that you didn't write "How to win friends and influence people"?  I 
don't suppose that the moderators will actually wake up and remove you from the mailing 
lists asap.


I see you are just as prickly as Ned, Mark. May I suggest that you too grow a 
pair? I am not on the mailing list BTW; e-mail lists are an outmoded concept 
much like CPython.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 14/02/2021 00:52, Alan Gauld wrote:

On 14/02/2021 00:07, Mr Flibble wrote:

On 13/02/2021 18:11, Alan Gauld wrote:



You are going to create a Python compiler that will take existing
Python code and output a byte code file.


No neos is not a Python compiler: it is a *universal* compiler that
can compile any programming language describable by a schema file


Yes, I understand that, but from the perspective of this list
what you are doing is providing a tool (a combination of neos
and a schema) that will take in Python source code and spit out
neos byte code. So, to all intents and purposes it is a Python
compiler (albeit capable of more when needed).


If that's correct, then how do you propose to deal with
regular Python byte code? And what would the Python disassembler
produce - Python assembler instructions or neos?


The neos Python implementation will not be dealing
with Python byte code in any form whatsoever.


Ok  but what do you do with the disassembler module?
Will it read neos byte code instead of the Python codes?
Also what about tools that work at the byte code level,
I assume they will not work with neos either?
That might include the profiler and debugger for example?


neos will include a language agnostic disassembler and debugger.



Also what would happen with the interactive prompt (>>>)
I'm assuming you'd expect users to continue using the CPython
interpreter and only compile the source after it was working
there? Like turning on the optimiser in a traditional
compiled language like C.


neos will include support for interactive sessions; no reason to use CPython at 
all.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-13 Thread Mr Flibble

On 14/02/2021 03:26, Grant Edwards wrote:

On 2021-02-14, Ned Batchelder  wrote:

On Saturday, February 13, 2021 at 7:19:58 PM UTC-5, Chris Angelico wrote:


At the absolute least, show that you have something that can run Python code.


The OP has been making these claims on IRC for a (at least two
years). He has never cared to substantiate them, or even participate
in a civil and detailed discussion.  He is either 1) smarter than
all of us, or 2) woefully under-informed, or 3) trolling.


He posts using the name of a hand-puppet. I think that provides a bit
of a clue as to which of the 3 is most likely. And it's not even a
_real_ hand-puppet: it's a computer-generated hologram of a hand
hand-puppet.


lulz. If I am a troll then Elon Musk is also a troll.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Sketch

2021-02-13 Thread Mr Flibble

CPython *is* the dead parrot.

It's time for Python to evolve out of the primordial soup.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: Sketch

2021-02-13 Thread Mr Flibble

On 14/02/2021 05:04, Mark Lawrence wrote:

On Sunday, February 14, 2021 at 5:01:46 AM UTC, Mr Flibble wrote:

CPython *is* the dead parrot.

It's time for Python to evolve out of the primordial soup.

/Flibble

--
😎


Says the bloke(?) who doesn't use mailing lists but does get here 
https://mail.python.org/pipermail/python-list/2021-February/900797.html


I am using Usenet, dear. Apparently posts to comp.lang.python are copied to the 
mailing list which you worship like a god.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: Sketch

2021-02-14 Thread Mr Flibble

On 14/02/2021 09:10, Michał Jaworski wrote:

Wow, that thread is entertaining. It seems that neos is one of it’s kind. What 
I hope is that it will support TempleOS.

Going back going back to your original question Mr. Fibble. If ISO standard is 
what you really need to finish your project you can always take up this 
challenge and standardize the language yourself. From what I’ve learned already 
you have enough skills, experience and perseverance to complete such endeavor 
single-handedly.


If I standardized the language myself I couldn't call it "Python" as fixing 
Python requires changing it such as to make it unrecognisable as Python.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: Sketch

2021-02-14 Thread Mr Flibble

On 14/02/2021 09:10, Michał Jaworski wrote:

Wow, that thread is entertaining. It seems that neos is one of it’s kind. What 
I hope is that it will support TempleOS.

Going back going back to your original question Mr. Fibble. If ISO standard is 
what you really need to finish your project you can always take up this 
challenge and standardize the language yourself. From what I’ve learned already 
you have enough skills, experience and perseverance to complete such endeavor 
single-handedly.


Ah yes, the good old TempleOS equivalence ploy: typically used by backseat 
programmers and/or trolls to dismiss projects or project authors they deem to 
have no value based on subjective hyperbole rather than valid criticism based 
on objective fact. Usually they lack the skill to embark on such a project 
themselves so their invective tends to stem from feelings of inadequacy.

Make yourself a cup of tea, dear.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Mr Flibble

On 14/02/2021 21:14, Chris Green wrote:

What's the easiest way to change the first occurrence of a specified
character in a string?


By using a grown up (i.e. non-toy) programming language.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: New Python implementation

2021-02-14 Thread Mr Flibble

On 14/02/2021 23:00, Christian Gollwitzer wrote:

Am 14.02.21 um 11:12 schrieb Paul Rubin:

Christian Gollwitzer  writes:

He wants that neoGFX is scriptable in Python, but instead of linking
with CPython, he will write his own Python implementation instead,
because CPython is slow/not clean/ whatever. He doesn't seem to
understand that this is an enormous task on its own, because the
interesting part of a scripting language is the standard library with
many decade-years of work.


I wonder how big an issue the stdlib really is.  Lots of it is written
in Python and can port to another interpreter.  Lots more is CPython C
API bindings to external C libraries (e.g. OpenSSL) so porting those
would be a matter of rebinding those libraries to libffi in the cases
where that hasn't been done already.


I'm not saying that it is unfeasible or very difficult. I'm saying that it is a lot of work, and for a single 
developer who has this as a side project / support for his graphics engine and who wants to beat existing 
implementations wrt. speed, I'm saying it is going to take a lot of time. It'definitely impossible by 
"defining a few JSON schema files", as Leigh claims with his "universal compiler". There 
definitely IS a lot of stuff in a baseline CPython interpreter - a (seemingly) simple thing like 
"print" will have an implementation of 1000 lines in C with all the formatting library, file I/O 
etc. Arbitrary precision integers - another library, networking - yet another and so on.


There will only be one schema file and it is will be a relatively small task which certainly isn't 
"impossible": I should have a working implementation by the summer.  As far as arbitrary 
precision integers are concerned I am well on the way to completing the "neonumeral" 
library (which also has arbitrary precision floats).

As far as the standard library is concerned: that is already in Python so I 
should be able to support it with little effort; the only thing requiring more 
work would be the built-ins.




CPython really is pretty slow, maybe because it uses so much boxed data,
derps around with refcounts all the time, suffers memory fragmentation
from not having a relocating GC, etc.  And that is before we even
mention the GIL.


I don't argue with that. CPython is slow. But I'm arguing that you can't make 
it faster by multiple orders of magnitude unless you change the language. For 
numerical code, straight-forward C is usually 100x to 1000x faster than Python, 
and you can reach the same performance by giving up dynamic typing - Cython 
demonstrates this quite convincingly. If you don't want static typing (with 
types close to the machine like fixed-width integers) than you'll have to 
resort to a LOT of black magic to even come close (PyPy, modern JS engines, 
)


I believe PyPy is only 4x faster than CPython on average and comes nowhere near 
close to JS JIT engines performance-wise.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


neoPython : Fastest Python Implementation: Coming Soon

2021-05-05 Thread Mr Flibble

neoPython : Fastest Python Implementation: Coming Soon

Message ends.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: neoPython : Fastest Python Implementation: Coming Soon

2021-05-05 Thread Mr Flibble

On 05/05/2021 17:02, Chris Angelico wrote:

On Thu, May 6, 2021 at 2:01 AM Mr Flibble
 wrote:


neoPython : Fastest Python Implementation: Coming Soon

Message ends.

/Flibble



My breath: not being held.

Message ends.


Why? The currently extant Python implementations contribute to climate change as 
they are so inefficient; CPython is so egregious it is best called a bag of 
shite. Making a faster implementation isn't in the least bit a stretch.


Message ends.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: neoPython : Fastest Python Implementation: Coming Soon

2021-05-05 Thread Mr Flibble

On 05/05/2021 17:02, Chris Angelico wrote:

On Thu, May 6, 2021 at 2:01 AM Mr Flibble
 wrote:


neoPython : Fastest Python Implementation: Coming Soon

Message ends.

/Flibble



My breath: not being held.

Message ends.


Why? The currently extant Python implementations are so inefficient they 
contribute to climate change; CPython is particularly egregious. Making a faster 
implementation isn't in the least bit a stretch.


Message ends.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: neoPython : Fastest Python Implementation: Coming Soon

2021-05-05 Thread Mr Flibble

On 05/05/2021 17:33, Mark Lawrence wrote:

On Wednesday, May 5, 2021 at 4:57:13 PM UTC+1, Mr Flibble wrote:

neoPython : Fastest Python Implementation: Coming Soon

Message ends.

/Flibble

--
😎

Dedicated to you and all like you https://www.youtube.com/watch?v=X15PsqN0DHc


ORLY? If anyone is thick around here it is the typical Python user such as 
yourself.

/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Re: neoPython : Fastest Python Implementation: Coming Soon

2021-05-05 Thread Mr Flibble

On 05/05/2021 17:36, Igor Korot wrote:

Hi,

On Wed, May 5, 2021 at 11:27 AM Mr Flibble <
flib...@i42.invalidwibblegrok.co.uk> wrote:


On 05/05/2021 17:02, Chris Angelico wrote:

On Thu, May 6, 2021 at 2:01 AM Mr Flibble
 wrote:


neoPython : Fastest Python Implementation: Coming Soon

Message ends.

/Flibble



My breath: not being held.

Message ends.


Why? The currently extant Python implementations are so inefficient they
contribute to climate change; CPython is particularly egregious. Making a
faster
implementation isn't in the least bit a stretch.

Message ends.



Why do you use {C}Python in the first place if its so inefficient?
Why not use C or even Assembly?

And "coming soon" - is a little weird.
Why not say "coming 10 May 2021 at 23:59:59"?

/Message ends.

Thank you.


But I don't use Python, I use C++ (probably the best programming language in the 
world).


/Flibble

--
😎
--
https://mail.python.org/mailman/listinfo/python-list


Python doesn't work

2021-05-30 Thread Mr . Incognito
   Hello

   I downloaded the latest versioon of Python and tried to open several .py
   files, but it doesn't open. It opens for a sec, then closes itself. I
   tried uninstalling and reinstalling, but it doesn't work.



   I hope you can help me!





   Saadetud Windows 10 rakendusest [1]Meil



References

   Visible links
   1. https://go.microsoft.com/fwlink/?LinkId=550986
-- 
https://mail.python.org/mailman/listinfo/python-list


Looking for the best way to make this

2016-10-05 Thread mr . marydavid
http://www.qualicode.com/EN/images/ScheduleGrid.png

looking to add schedule like that to my software trying with Qt but not sure 
how to .

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


Re: Looking for the best way to make this

2016-10-05 Thread mr . marydavid
Here is another example 
http://www.codetwo.com/media/images/exchange-sync-screencast-5.jpg 
-- 
https://mail.python.org/mailman/listinfo/python-list


Meta classes - real example

2016-10-17 Thread Mr. Wrobel

Hi,

I am looking for an example of metaclass usage. Especially I am 
interestet in manipulating instance variables, for example:


My class:
class MrMeta(type):
pass

class Mr(object):
__metaclass__ = MrMeta

def __init__(self):
self.imvariable = 'Zmienna self'

def aome method(self):
print 'I am in instance'

So in general, I would like to create a mechanism, that is changing 
value for self.imvariable to capital letters and this should be included 
in my metaclass called MrMeta(type).


Can you guide me please?

Thanks!
Mr. Wrobel
--
https://mail.python.org/mailman/listinfo/python-list


Re: Meta classes - real example

2016-10-17 Thread Mr. Wrobel

W dniu 17.10.2016 o 18:16, Chris Angelico pisze:

On Tue, Oct 18, 2016 at 3:03 AM, Mr. Wrobel  wrote:

Hi,

I am looking for an example of metaclass usage. Especially I am interestet
in manipulating instance variables, for example:

My class:
class MrMeta(type):
pass

class Mr(object):
__metaclass__ = MrMeta

def __init__(self):
self.imvariable = 'Zmienna self'

def aome method(self):
print 'I am in instance'

So in general, I would like to create a mechanism, that is changing value
for self.imvariable to capital letters and this should be included in my
metaclass called MrMeta(type).

Can you guide me please?


Are you sure you can't just use a descriptor, such as @property?

class Mr(object):
@property
def imvariable(self):
return self._imvariable
@imvariable.setter
def imvariable(self, value):
self._imvariable = str(value).upper()

ChrisA


Hi,

I am sure that I can do that with setter/getter, but I want to be closer 
to black magic, that is why I wanted to inlcude Metaclasses.


I know how to acomplish that for class variables, but don;t have any 
idea how to instance.


Mr. Wrobel
--
https://mail.python.org/mailman/listinfo/python-list


Re: Meta classes - real example

2016-10-17 Thread Mr. Wrobel

W dniu 17.10.2016 o 23:23, Ethan Furman pisze:

On 10/17/2016 09:23 AM, Mr. Wrobel wrote:

W dniu 17.10.2016 o 18:16, Chris Angelico pisze:

On Tue, Oct 18, 2016 at 3:03 AM, Mr. Wrobel wrote:



I am looking for an example of metaclass usage. Especially I am
interestet
in manipulating instance variables, for example:

My class:
class MrMeta(type):
pass

class Mr(object):
__metaclass__ = MrMeta

def __init__(self):
self.imvariable = 'Zmienna self'

def aome method(self):
print 'I am in instance'

So in general, I would like to create a mechanism, that is changing
value
for self.imvariable to capital letters and this should be included
in my
metaclass called MrMeta(type).

Can you guide me please?


Are you sure you can't just use a descriptor, such as @property?

class Mr(object):
@property
def imvariable(self):
return self._imvariable
@imvariable.setter
def imvariable(self, value):
self._imvariable = str(value).upper()


I am sure that I can do that with setter/getter, but I want to be
closer to black magic, that is why I wanted to inlcude Metaclasses.

I know how to acomplish that for class variables, but don;t have any
idea how to instance.


Metaclasses work on the class level, not the instance level.  The only*
influnce a metaclass is going to have on instances is changes it makes
while it's creating the class.

For example, MrMeta could set descriptors in Mr when it is creating the
Mr class; it could even put it's own __init__ in the class; but to
affect things like instance variables that are added in methods -- well,
it is possible, but it is *a lot* of work.

--
~Ethan~

* Okay, somebody prove me wrong!  :)


Ok,so in general, we could say that using Metclasses is ok for 
manipulating __new__ but not that what is setting by __init__. Am I right?


MrWrobel
--
https://mail.python.org/mailman/listinfo/python-list


Re: Meta classes - real example

2016-10-20 Thread Mr. Wrobel

W dniu 18.10.2016 o 16:42, Ethan Furman pisze:

On 10/17/2016 11:44 PM, Mr. Wrobel wrote:


Ok,so in general, we could say that using Metclasses is ok for
manipulating __new__ but not that what is setting by __init__. Am I
right?


No and yes.

In this code (python 2 syntax):

#untested
class Wonderful(object):

__metaclass__ = SomeMetaClass
diamond = Sparkly(7)
club = 9

def display(self):
print "I'm an instance!"

The metaclass controls what happens when Wonderful is created:

- it can add the name 'diamond' to the Sparkly descriptor;
-  it can change/remove/add other attributes such as club, spade, or
whatever;
- it can wrap methods such as display to pre- or post-process calls to it
- etc.

Once the class (Wonderful, in this example) has been created:

- x = Wonderful()  # metaclass not called
- x.display()  # metaclass not called
- x.diamond# metaclass not called

- list(Wonderful)  # metaclass called (e.g. SomeMetaClass.__iter__(cls) )
   # where cls = Wonderful


Check out http://stackoverflow.com/a/35730545/208880 for a simple
demonstration of a metaclass.

--
~Ethan~

Thank you Ethan!
--
https://mail.python.org/mailman/listinfo/python-list


[Theory] How to speed up python code execution / pypy vs GPU

2016-11-05 Thread Mr. Wrobel

Hi,

Some skeptics asked my why there is a reason to use Python against of 
any other "not interpreted" languages, like objective-C. As my 
explanation, I have answered that there is a a lot of useful APIs, 
language is modern, has advanced objective architecture, and what is the 
most important - it is  dynamic and support is simply great.


However the same skeptics told my that, ok we believe that it is true, 
however the code execution is much slower than any other compiled language.


I must tell you that is the reason I started to dig into internet and 
searching some methods to speed up python's code.


1. What I have found is modified python interpreter - pypy  - 
http://pypy.org that does not require any different approach to develop 
your code.


2. And: Gpu based computing powered by Nvidia (NumbaPro compiler): 
https://developer.nvidia.com/how-to-cuda-python


Do you have any experience in that areas, and maybe some benchmarks 
showing advantage of using these technologies?


Cheers,
Marcin
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Theory] How to speed up python code execution / pypy vs GPU

2016-11-05 Thread Mr. Wrobel

W dniu 05.11.2016 o 22:17, Ben Bacarisse pisze:

Steve D'Aprano  writes:


On Sun, 6 Nov 2016 04:10 am, Mr. Wrobel wrote:


Hi,

Some skeptics asked my why there is a reason to use Python against of
any other "not interpreted" languages, like objective-C.


Here's the "Hello World" program in Python:

--- cut ---

print("Hello World")

--- cut ---



Here's the same program in Objective C:

--- cut ---

#import 

int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello, World!");
[pool drain];
return 0;
}

--- cut ---

Which would you rather write?


That's a rather odd comparison.  Why not

  #import 

  int main()
  {
printf("Hello world\n");
return 0;
  }

?  It's decades since I wrote any Objective-C (and then not much) but I
think this is the closest comparison.


Wel, indeed. However the most important is second part of my question.

What do you think about using GPU processing or pypy?
--
https://mail.python.org/mailman/listinfo/python-list


Metaclasses - magic functions

2016-12-20 Thread Mr. Wrobel

Hi,

Quick question, can anybody tell me when to use __init__ instead of 
__new__ in meta programming?


I see that __new__ can be used mostly when I want to manipulate with 
class variables that are stored into dictionary.


But when to use __init__? Any example?

Thanx,
M
--
https://mail.python.org/mailman/listinfo/python-list


Re: Metaclasses - magic functions

2016-12-23 Thread Mr. Wrobel

W dniu 21.12.2016 o 02:51, Ethan Furman pisze:

On 12/20/2016 03:39 PM, Ben Finney wrote:

"Mr. Wrobel" writes:



Quick question, can anybody tell me when to use __init__ instead of
__new__ in meta programming?


Use ‘__new__’ to do the work of *creating* one instance from nothing;
allocating the storage, determining the type, etc. — anything that will
be *the same* for every instance. ‘__new__’ is the constructor.

Use ‘__init__’ to do the work of *configuring* one instance, after it
already exists. Any attributes that are special to an instance should be
manipulated in the ‘__init__’ method. ‘__init__’ is the initialiser.


That sounds like general object creation/class advice, which as a general
guideline is okay, but don't feel like it's the most important thing.

I only use `__new__` when the object being created is (or is based on)
an immutable type; otherwise I use `__init__`.  Likewise, if I'm using
`__new__` then I do all my configuration in `__new__` unless I have a
really good reason not to (such as making it easier for subclasses to
modify/skip `__init__`).

As far as metaclasses go... the only time I recall writing an `__init__`
for a metaclass was to strip off the extra arguments so `type.__init__`
wouldn't fail.

--
~Ethan~
Hi,thanx for answers, let's imagine that we want to add one class 
attribute for newly created classess with using __init__ in metaclass, 
here's an example:


#!/usr/bin/env python

class MetaClass(type):
# __init__ manipulation:

def __init__(cls, name, bases, dct):
dct['added_in_init'] = 'test'
super(MetaClass, cls).__init__(name, bases, dct)

class BaseClass(object):
__metaclass__ = MetaClass

class NewBaseClass(BaseClass):
pass

print("Lets print attributes added in __init__ in base classes:")

print(BaseClass.added_in_init)

print(NewBaseClass.added_in_init)

after running it: AttributeError: type object 'BaseClass' has no 
attribute 'added_in_init'


Adding the same in __new__ works. Can anyone explain me please what's wrong?

Cheers,
M



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


Re: Metaclasses - magic functions

2016-12-23 Thread Mr. Wrobel

W dniu 23.12.2016 o 15:14, Ian Kelly pisze:
(...)


cls.added_in_init = 'test'



Man, you are awsome genius! Finally somebody was able to explain me what 
is the power of __new__ and difference between __init__ !!!


So what I wanted to achieve was adding some new attributes to the class 
instances (objects) like this:



#!/usr/bin/env python

class MetaClass(type):
# __init__ manipulation:

def __init__(cls, name, bases, dct):
cls.added_in_init = 'test'
super(MetaClass, cls).__init__(name, bases, dct)

class BaseClass(object):
__metaclass__ = MetaClass

class NewBaseClass(BaseClass):
def __init__(self):
self.inst_attr = self.added_in_init


print("Lets print attributes added in __init__ in base classes:")


b = NewBaseClass()
print(b.added_in_init)

print(b.inst_attr)


And finally it works!

Man I owe you a galaxy of thanks, because I was so frustrated! The 
examples taken from internet never explained me it in so clearly like 
you did!


Really, really thank you!!!
--
https://mail.python.org/mailman/listinfo/python-list


Re: Your IDE's?

2019-03-27 Thread Mr Zaug
On Monday, March 25, 2019 at 5:38:41 PM UTC-4, John Doe wrote:
> What is your favorite Python IDE?

"Your IDE's?" is not a question, nor is any word in English made plural with an 
apostrophe  s.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Resources related with web security

2019-11-26 Thread Mr. Gentooer
> > On Mon, 25 Nov 2019 21:25:12 + (UTC), Pycode 
> > declaimed the following:
> > 
> > comp.lang.python gmane.comp.python.general

how do you access these in a reasonable way?

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


Re: Python Resources related with web security

2019-11-26 Thread Mr. Gentooer
On Tue, Nov 26, 2019 at 03:29:48PM -0500, Joel Goldstick wrote:
> On Tue, Nov 26, 2019 at 2:23 PM Mr. Gentooer  wrote:
> >
> > > > On Mon, 25 Nov 2019 21:25:12 + (UTC), Pycode 
> > > > declaimed the following:
> > > >
> > > > comp.lang.python gmane.comp.python.general
> >
> > how do you access these in a reasonable way?
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> I'm thinking this is a troll or a turing machine experiment?

why would I be a troll? I have never used usenet. I am honestly and
genuinely curious.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: gmail access with python!

2005-01-30 Thread Mr Follower
Did you try the CVS version of libgmail? While none of the "release
versions" (i.e. up 0.0.8) currently work, as of a week ago the CVS
version handled the two recent modifications to Gmail.
--Phil. (Author libgmail)

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


py_compile vs. IndentationError

2005-03-26 Thread Mr. Magoo
Why does py_compile print IndentationError in a different format than 
SyntaxError? It makes it harder to parse the output in a non-python 
program.

Sorry: IndentationError: ('unindent does not match any outer indentation 
level', ('foo.py', 19, 17, '\t\t\t return 0.0  \n'))

instead of 

   File "foo.py", line 19
zreturn 0.0

for example.

Is there a way for me to wrap this up in a script and transform the 
output on the way out?

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


How to get TabError?

2005-03-27 Thread Mr. Magoo
Can someone provide a snippet which, when run, generates a TabError?

I can only seem to get SyntaxError and IndentationError.

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


Re: How to get TabError?

2005-03-27 Thread Mr. Magoo
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> "Mr. Magoo" wrote:
> 
> > Can someone provide a snippet which, when run, generates a TabError?
> >
> > I can only seem to get SyntaxError and IndentationError.
> 
> $ python -c "print repr(open('test.py').read())"
> 'if 1:\n\tprint "hello"\nprint "goodbye"\n'
> 
> $ python test.py
> hello
> goodbye
> 
> $ python -t test.py
> test.py: inconsistent use of tabs and spaces in indentation
> hello
> goodbye
> 
> $ python -tt test.py
>   File "test.py", line 3
> print "goodbye"
>   ^
> TabError: inconsistent use of tabs and spaces in indentation
> 
>  


Thanks.

Is there a reason (good or otherwise :-) why py_compile dumps this and 
IndentationError in a different format than SyntaxError?

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


Re: How to get TabError?

2005-03-27 Thread Mr. Magoo
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> $ python -t test.py
> test.py: inconsistent use of tabs and spaces in indentation
> hello
> goodbye

On more question. When using py_compile from with a script, is there any 
way to force the -t flag?

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


Generate config file from template using Python search and replace.

2015-11-28 Thread Mr Zaug
I need to generate a config file based on an existing "template" file. I need 
to replace a set of strings with other strings globally in the generated file.

Here is a snippet of the template file, where CONTENT_PATH and DAMPATH are two 
"placeholders" or variables. There are several other such placeholders.

  $include "_dispatcher_publish_filters.any"
  /1000 { /type "allow"  /glob "* /CONTENT_PATH/*.html*" }
  /1001 { /type "allow"  /glob "POST /DAMPATH/www/*.html *" }

The script's user will be asked to type in unique values when prompted for 
DAMPATH or CONTENT_PATH.

Since I know the variables themselves are not going to change (because the 
contents of the template file don't spontaneously change) should I be using 
regex to search for them or is there a better way? I was planning on using 
re.sub but I don't know whether that's the best way. Here's what my script 
looks like today.

from sys import argv
import re
from os.path import exists

script, template_file = argv
print "Opening the template file..."

in_file = open(template_file)
lines = in_file.readlines()

print "What is the serial number of the site?",
_NNN = raw_input()

print "What is the brand, or product name?",
_BRAND = raw_input()

print "What is the content path?",
_CONTENT_PATH = raw_input()

out_file = open(_nnn + _brand + "_farm.any", 'w')

for line in lines:
   re.sub('NNN', _NNN, line)
   re.sub('BRAND, _BRAND', line)
   re.sub('CONTENT_PATH', _CONTENT_PATH, line)

out_file.close()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate config file from template using Python search and replace.

2015-11-28 Thread Mr Zaug
I should mention the template file is small, just 98 lines long and the working 
config file will be the same size.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate config file from template using Python search and replace.

2015-11-29 Thread Mr Zaug
When I run this script on OS X El Capitan, I see,
  
  # permission sensitive cache
  $include "_dispatcher_shared_auth-checker: 

Was I supposed to incorporate it into the script I posted?
-- 
https://mail.python.org/mailman/listinfo/python-list


I can't understand re.sub

2015-11-29 Thread Mr Zaug
I need to use re.sub to replace strings in a text file. I can't seem to 
understand how to use the re module to this end.

result = re.sub(pattern, repl, string, count=0, flags=0);

I think I understand that pattern is the regex I'm searching for and repl is 
the thing I want to substitute for whatever pattern finds but what is string?

The items I'm searching for are few and they do not change. They are 
"CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template 
file. They do not appear together on any line and they only appear once on each 
line.

This should be simple, right?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I can't understand re.sub

2015-11-29 Thread Mr Zaug
Thanks. That does help quite a lot.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I can't understand re.sub

2015-11-29 Thread Mr Zaug
On Sunday, November 29, 2015 at 8:12:25 PM UTC-5, Rick Johnson wrote:
> On Sunday, November 29, 2015 at 3:37:34 PM UTC-6, Mr Zaug wrote:
> 
> > The items I'm searching for are few and they do not change. They are 
> > "CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template 
> > file. They do not appear together on any line and they only appear once on 
> > each line. This should be simple, right?
> 
> Yes. In fact so simple that string methods and a "for loop" will suffice. 
> Using regexps for this tasks would be like using a dump truck to haul a 
> teaspoon of salt.

I rarely get a chance to do any scripting so yeah, I stink at it.

Ideally I would have a script that will spit out a config file such as 
087_pre-prod_snakeoil_farm.any and not need to manually rename said output file.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate config file from template using Python search and replace.

2015-11-29 Thread Mr Zaug
On Sunday, November 29, 2015 at 5:50:51 PM UTC-5, Peter Otten wrote:
> Mr Zaug wrote:
> 
> > When I run this script on OS X El Capitan, I see,
> >   
> >   # permission sensitive cache
> >   $include "_dispatcher_shared_auth-checker:
> > 
> > Was I supposed to incorporate it into the script I posted?
> 
> Are you referring to my post? I'm sorry, I can't make sense of your 
> question.

Yes. The snippet you posted went way over my head. When I ran it, it printed 

# permission sensitive cache 
  $include "_dispatcher_shared_auth-checker: 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate config file from template using Python search and replace.

2015-11-29 Thread Mr Zaug
On Sunday, November 29, 2015 at 5:50:51 PM UTC-5, Peter Otten wrote:
> Mr Zaug wrote:
> 
> > When I run this script on OS X El Capitan, I see,
> >   
> >   # permission sensitive cache
> >   $include "_dispatcher_shared_auth-checker:
> > 
> > Was I supposed to incorporate it into the script I posted?
> 
> Are you referring to my post? I'm sorry, I can't make sense of your 
> question.

I seem to be heading in this direction.

#!/usr/bin/env python
import re
from os.path import exists

script, template_file = argv
print "Opening the template file..."

with open (template_file, "r") as a_string:
data=a_string.read().replace('BRAND', 'Fluxotine')
print(data)

So now the challenge is to use the read().replace magic for multiple values.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate config file from template using Python search and replace.

2015-11-30 Thread Mr Zaug
On Monday, November 30, 2015 at 4:14:48 AM UTC-5, Peter Otten wrote:
> Mr Zaug wrote:
> 
> > On Sunday, November 29, 2015 at 5:50:51 PM UTC-5, Peter Otten wrote:
> >> Mr Zaug wrote:
> >> 
> >> > When I run this script on OS X El Capitan, I see,
> >> >   
> >> >   # permission sensitive cache
> >> >   $include "_dispatcher_shared_auth-checker:
> >> > 
> >> > Was I supposed to incorporate it into the script I posted?
> >> 
> >> Are you referring to my post? I'm sorry, I can't make sense of your
> >> question.
> > 
> > Yes. The snippet you posted went way over my head. When I ran it, it
> > printed
> > 
> > # permission sensitive cache
> >   $include "_dispatcher_shared_auth-checker:
> 
> It's hard to tell from that problem description what might have gone wrong. 
> However:
> 
> In your template file you have to enclose all words you want to replace in 
> braces ("you have foo options" becomes "you have {foo} options"), to replace 
> all literal { with {{ and all literal } with }}.
> 
> Did you do that?

Yup, I sure did. So here is my current script. The only remaining task now is 
figuring out how to write the contents to a new file.

#!/usr/bin/env python
import os
import sys

script, template_file = sys.argv
print "Opening the template file..."

print "What is the serial number of the site?",
nnn = raw_input()

print "What is the brand, or product name?",
brand = raw_input()

print "What is the (fqdn) ServerName?",
server_name = raw_input()

print "What is the content path?",
content_path = raw_input()

print "What is the DAM path?",
dampath = raw_input()

print "Which environment is this for?",
env = raw_input()

print "What is the cache document root?",
cache_docroot = raw_input()

with open (template_file, "r") as a_string:
data=a_string.read().replace('{SERVER_NAME}', 
server_name).replace('{BRAND}', brand).replace('{CONTENT_PATH}', 
content_path).replace('{DAMPATH}', dampath).replace('{ENV}', 
env).replace('{CACHE_DOCROOT}', cache_docroot)

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


Re: Generate config file from template using Python search and replace.

2015-12-01 Thread Mr Zaug
Oh, that's much easier to read. Thanks!


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


Re: Generate config file from template using Python search and replace.

2015-12-01 Thread Mr Zaug
Actually, I don't understand what you mean by "all other braces." What braces 
are you talking about? The placeholders in the template file (the file being 
read in) have braces around them but they are not escaped. 

Also, do I really need curly braces to tell Python what my placeholders are?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate config file from template using Python search and replace.

2015-12-01 Thread Mr Zaug
That makes sense. 

So I still can't see how to write the string object to a file whist naming the 
file with whatever values I provided for the NNN and BRAND variables.

Printing the contents of the string object is working with all the expected 
substitutions. Do I need to convert the string object into a file before I 
write it? Or do I need to open a new file and somehow stuff the string object 
into it?

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


Re: Generate config file from template using Python search and replace.

2015-12-01 Thread Mr Zaug
Ye, this does work. Many thanks!

filename = "{NNN}_{BRAND}_farm.any".format(BRAND=brand, NNN=nnn)
with open(filename, "w") as outstream:
outstream.write(data)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can I trust downloading Python?

2013-09-11 Thread Mr. Roboto
On Saturday, September 7, 2013 9:17:46 PM UTC-4, Aaron Martin wrote:
> Hi, I am thinking about getting a software but it requires python, so that 
> brought up a few questions. Is it safe do download python, and does it come 
> with spam or advertisements? If it doesn't then should I get the latest 
> version? I mostly want to know if it is safe to download, because most of the 
> time downloading free stuff off the internet comes with spam and all that, so 
> I want to know if I can trust downloading it.

Hope others find this article helpful and relevant:

http://www.eweek.com/developer/open-source-python-code-sets-new-standard-for-quality-study.html/?kc=EWKNLEAU09102013BESTOF2&dni=77668545&rni=22939981

A development testing company (Coverity) reports that the core Python platform 
has a very low number of source code defects and its developers effect repairs 
to known flaws very readily, as compared to other open-source projects.  I 
can't attest to the validity of the claim (one way or the other), but it is 
something worth noting
-- 
https://mail.python.org/mailman/listinfo/python-list


numpy array product driving me mad

2015-03-20 Thread Mr. Twister
Hi everyone.

Hope you can help me overcome this "noob" issue.

I have two numpy arrays:

>>> P
array([[[ 2,  3],
[33, 44],
[22, 11],
[ 1,  2]]])
>>> R
array([0, 1, 2, 3])

the values of these may of course be different. The important fact is that:

>>> P.shape
(1, 4, 2)
>>> R.shape
(4,)

where the number 4 in the shape of both P and R may be another number as well
(same on both).


What I'd like to get is a new array Q with same shape as P so that the nth pair
of Q is the nth pair of P multiplied by the nth element of R. I.e., in the above
case it should produce:

>>> Q
array([[[ 0,  0],
[33, 44],
[44, 22],
[ 3,  6]]])


Is there a direct, single expression command to get this result? I have tried
all I could imagine, including .T, extend_dims, h/vstack, repeat..., so far with
no success.

Please, any help will be welcomed.

Thanks.

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


Re: numpy array product driving me mad

2015-03-20 Thread Mr. Twister
>> I think that you want 
>>
>> P * R[;,None]
> 
> Sorry, I meant 
> 
> P * R[:, None]
> 
> Manolo

Muchísimas gracias, Manolo. Eres un genio y me has ayudado mucho. Te debo una.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-29 Thread mr . smittye
On Wednesday, March 25, 2015 at 4:39:40 AM UTC-7, Marko Rauhamaa wrote:
> A lot of discussion was generated by the good, old fibonacci sequence. I
> have yet to find practical use for fibonacci numbers. However, the
> technique behind a sudoku solver come up every now and again in
> practical situations.
> 
> I post below a sudoku solver. I eagerly await neater implementations (as
> well as bug reports).
> 
> Usage:
> 
> ./sudoku.py  
> 
> sudoku.dat:
> 
> 7 . . . . . 6 . .
> . 2 . 8 . 6 . 7 .
> . . . 4 3 . . 9 .
> 5 1 . . . . 4 . 3
> . . 9 . . . . 1 .
> . . . . 4 2 . . 5
> . . . 9 . . . . 8
> . . 6 . . . . 5 .
> . . . . . . . 6 .
> 
> 
> output:
> 
> 7 8 4 2 9 5 6 3 1
> 9 2 3 8 1 6 5 7 4
> 6 5 1 4 3 7 8 9 2
> 5 1 8 6 7 9 4 2 3
> 2 4 9 3 5 8 7 1 6
> 3 6 7 1 4 2 9 8 5
> 1 7 5 9 6 3 2 4 8
> 8 3 6 7 2 4 1 5 9
> 4 9 2 5 8 1 3 6 7
> 
> 
> 
> sudoku.py:
> 
> #!/usr/bin/env python3
> 
> import sys
> 
> M = 3
> N = M * M
> Q = N * N
> 
> candidates = list(range(1, N + 1))
> 
> def main():
> board = []
> for n in sys.stdin.read().split():
> try:
> board.append(int(n))
> except ValueError:
> board.append(None)
> solve(board)
> 
> def solve(board, slot=0):
> if slot == Q:
> report(board)
> elif board[slot] is None:
> for candidate in candidates:
> if good(board, slot, candidate):
> board[slot] = candidate
> solve(board, slot + 1)
> board[slot] = None
> else:
> solve(board, slot + 1)
> 
> def good(board, slot, candidate):
> (shelf, row), (stack, col) = (divmod(x, M) for x in divmod(slot, N))
> for i in range(M):
> for j in range(M):
> if candidate in (board[(i * M + j) * N + stack * M + col],
>  board[(shelf * M + row) * N + i * M + j],
>  board[(shelf * M + i) * N + stack * M + j]):
> return False
> return True
> 
> def report(board):
> print("\n".join(
> " ".join(str(board[row * N + col])
>  for col in range(N))
> for row in range(N)))
> print()
> 
> if __name__ == '__main__':
> main()
> 
> 
> 
> Marko

You say "neater implementation"
I'll send you to the code-golf site: 
http://codegolf.stackexchange.com/a/446/38632 this is brute force. There are 
some really good implementations in other languages that arent brute force. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-02 Thread Mr. Joe
Is there any way to raise the original exception that made the call to
__getattr__? I seem to stumble upon a problem where multi-layered attribute
failure gets obscured due to use of __getattr__. Here's a dummy code to
demonstrate my problems:
"""
import traceback


class BackupAlphabet(object):
pass


class Alphabet(object):
@property
def a(self):
return backupalphabet.a


def __getattr__(self, name):
if name == "b":
return "banana"

raise AttributeError(
"'{0} object has no attribute '{1}'"
.format(self.__class__.__name__, name))


alphabet = Alphabet()
backupalphabet = BackupAlphabet()

print(alphabet.a)
print(alphabet.b)
"""

Running the above code produces this:
"""
Traceback (most recent call last):
  File "example.py", line 26, in 
print(alphabet.a)
  File "example.py", line 20, in __getattr__
.format(self.__class__.__name__, name))
AttributeError: 'Alphabet object has no attribute 'a'
"""

While it's easy enough to identify the problem here, the traceback is
rather unhelpful in complex situations. Any comments?

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


Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-03 Thread Mr. Joe
Thanks for clearing up. Developers of python should address this issue, in
my opinion. 3.4/3.5 maybe, but better late than never.

Recently, I've been beaten back for using some exotic features of python.
One is this[ Took me hours to get to the bottom ]. The other one is
'property' decorator. I was using it extensively until I needed to make a
child class. Then I came to know that 'property' does not play well
with polymorphic code. :( I resorted to some lambda hacks learned from
stackoverflow.com to solve the problem. I know that it's the correct way
for decorators to work, but still, it would be nice to have a language
level solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Problems with WX and program loop...

2006-01-11 Thread Mr BigSmoke
Hi everybody... I have an app that has to controll some ascii files
every 10/30 seconds... I was planning to have an GUI using wxpython.
The problems is that i wasn't able to manage my application loop and
the wxApp loop, so my interface is always freezing...
My app do something like this:
- creates a new wx and wxframe instance
- loads some configuration info
- starts looping every 30 seconds (while True: sleep(30); do something,
bla,bla)
- update some labels and textboxes on my frame...

On every loop step, if i find some info in those ascii files i want to
change some labels on my wxFrame... But my frame just freezes...
because of the loop.

Any hint?

I'll post some of the code down here...

"
...
loadSystemConfiguration() # Carico la configurazione delle tag
dell'intero sistema
self.loadMonitorConfiguration() # Carico le configurazioni del
monitor
# monitorGUI.monitorGUI is my wxFrame class...
self.mG = monitorGUI.monitorGUI(None, app_path, screen_dx=1024,
screen_dy=768)
self.mG.Show()

self.monitorize = True
while self.monitorize:
time.sleep(30)
<<>>
if something:
  self.mG.status.SetValue("Registering new event...")
  self.mG.Update()

"

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


Re: Problems with WX and program loop...

2006-01-12 Thread Mr BigSmoke
Great! 
Tnx!!

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


About Embedding PyWin or wxPython

2006-07-24 Thread Mr. Roboto

Folks:  I want to embark on a project to add Python (actually, wxPython
or PythonWin) to a new Windows app I want to start writing soon.
Essentially, I want to take VB6 (or pos Delphi) and construct the app
framework/core functionality using one of those languages, then extend
the app w/ Python, the same way one can extend the MS Office apps
using VBA.  The core Python docs provide the fundamental info one
needs to get started.  But, I've been looking for some pointers to
articles/web pages that will bootstrap the effort, so I won't have to
completely reinvent the wheel.  So far, the c.l.p ngroup traffic (and
the web in general) that speaks to this subject is apparently pretty
sparse.  Since I'm a one-man show, it would be helpful if anyone could
offer pointers to sites/pages/books that address some of these issues:

1)  To COM or not ?  From an implementation standpoint, it seems
worthwhile to build the host app as a series of COM objects, which
could then be ref'd/manipulated via external Python code.  Not sure if
this makes sense from a performance-perspective, but I doubt the apps
I'm thinking about (mostly desk accessory utils kinda, sorta) are
going to be compute-intensive at all.

2)  SWIG or not ?  Have never used it, but know that SWIG has been
ref'd many times in the ngroup as an tool for facilitating the use of
Python as an embedded language.  Is SWIG worth the effort for a
relatively small (<10 KLOC) app ?

3)  Handling exceptions.  I want to start from Day One with a sensible
approach to debugging and testing both host objects and external
scripts.

4)  Deployment.  Size (30 - 50MB for wxPython or PyWin alone) and a
silent install of either pkg prior to installing the host app.

Regardless of the conversation in this group, I plan to get started in
the next few days.  This is how I'm currently looking at the above
issues:

1)  COM:  Yes, since COM seems like an easy fit w/o writing lotsa
glue code because of built-in support via PyWin

2)  SWIG:  Not for a 1st cut, at least not to get one's feet wet, so
to speak

3)  Exceptions:  No clue.  Need to closely read Extending/Embedding
Python for more guidance

4) Deployment: Bite the disk space bullet and use PyWin or wxPython as
is

Anyway, that's the beginning of the conversation.  If you have any
observations or suggestions, please feel free.  Later...MR

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


Re: About Embedding PyWin or wxPython

2006-07-25 Thread Mr. Roboto
Steve:  Thanx for reminding me.  I have that book around here
*someplace*.  Never finished it, but will dig it out pronto.  As you
so aptly point out, I want to develop more than experiment and who
better to learn from than the author of PyWin itself

Steve Holden wrote:
> You almost certainly would regard a copy of Hammind and Robinson's
> "Python Programming on Win32" as remarkable value for money. It's an
> axcellent book, and even has examples fo how you can make a VBA
> application scriptable in Python.
>
> If you are more interested in developing functionality that
> experimenting, buying that book would save to a huge amount of time.
> 
> regards
>   Steve

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


Re: About Embedding PyWin or wxPython

2006-07-25 Thread Mr. Roboto
Simon:  Good idea, but I'm not yet .NET-compatible and can't handle
that learning curve in addition to everything else.  IronPython is an
option I hadn't considered, but yours is a good idea for the next
project

Simon Hibbs wrote:
> Have you considered IronPython?
>
> This is of course only an option if you're prepared to code in VB.NET
> or C# instead of VB6 or Delphi, but it would provide seamless
> integratioon between your Python code and the rest of your app and
> would not require an external graphics library - although you would
> need to distribute the .NET and IronPython runtimes.

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


Re: About Embedding PyWin or wxPython

2006-07-25 Thread Mr. Roboto
Phillipe:  Actually, it's not performance of the core app that concerns
me.  I'm thinking more about UI/form *design* productivity.  I've done
a lot of Access work over the years and while the stand-alone VB form
designer isn't quite as thorough, it's still one of the slickest out
there.  Unfortunately, there's no designer for PyWin and wxPython's
XRC is nice but not in the same league as what can be done w/ Delphi
or VB.  Yes, I'm aware that wxWidgets has a real form designer, but
that's yet another story, for another day.

Making XRC into a more fully-featured tool (more on par w/ the
aforementioned) is a way nice project unto itself, but not right now.
However, the desk accessory I've mentioned is an excellent 1st step
towards *possibly* doing something much bigger

Philippe Martin wrote:
> Do you have major performances issues ? why not write everything in
> Python/WxPython ?
>
>
> I used to write my applications in VB6 with python com objects ... and
> decided there was no gain there.
> 
> Regards,
> 
> Philippe

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


Re: Py2exe for packaging installers?

2006-07-28 Thread Mr BigSmoke
>
> However, it's not platform independant -- it'll be for windows only.
>

Yeah, u'll have to use py2exe similars for mac (should be py2app, if i
remember right). py2exe is a Python distutils extension which
converts python scripts into executable windows programs

cheers

Fabio

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


Re: War chest for writing web apps in Python?

2006-07-28 Thread Mr BigSmoke
For IDEs i recommend Wing IDE (its really good but comercial.. :(  ),
pydev for eclipse and also SPE.

For GUI designer... it depends of wich kind of app u'll develop.

For web apps try cherrypy.. it's wonderfull and simple... U can also
try zope and plone (the they are less simple)

cheers

Fabio




Vincent Delporte wrote:
> Hello
>
> I'm thinking of using Python to build the prototype for a business web
> appplication. The development and test machine is XP, while ultimate
> deployment will be on a shared Unix web host.
>
> What would you recommend I get, besides the Python engine itself? Good
> IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools?
> 
> Thank you.

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


"running" code on client side with cherrypy?

2006-08-10 Thread Mr BigSmoke
Hi All,
I'm developing a website to handle some code/application version
control on a intranet. I'm using cherrypy and pysvn. Everything runs
quite good but i want the user to be able to checkout some projects
from the server. The user(on the client side) selects a folder in his
machine (i.e.: C:\Project1) and the server should checkout
(download/copy) all the project selected to the client machine. But
what happens is that the webserver shckout the project on the same
folder selected by the user  but at server side. Everything works if
the user gives a network path (like \\pcname\sharedFolder). Any hint?

tnx!

Fabio

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


Re: "running" code on client side with cherrypy?

2006-08-10 Thread Mr BigSmoke
Tnx Jay... as i supposed there's no easy solution... I just thought
that, maybe, being on an intranet there was a possible solution...
About pysvn a tortoise... i do use tortoiseSVN and t works really
really fine.. we (developers) use it, but i'm writting server for
"normal" users that can checkout our applications releases... I'll try
some other solution... thanks very much!
cheers

Fabio


jay graves wrote:
> Mr BigSmoke wrote:
> > Hi All,
> > I'm developing a website to handle some code/application version
> > control on a intranet. I'm using cherrypy and pysvn. Everything runs
> > quite good but i want the user to be able to checkout some projects
> > from the server. The user(on the client side) selects a folder in his
> > machine (i.e.: C:\Project1) and the server should checkout
> > (download/copy) all the project selected to the client machine. But
> > what happens is that the webserver shckout the project on the same
> > folder selected by the user  but at server side. Everything works if
> > the user gives a network path (like \\pcname\sharedFolder). Any hint?
>
> The folder is created on the server because that is where the CherryPy
> code is running.  It's not running on the client.  Security concerns
> dictate that this will never work the way you want.  It's a fundamental
> restriction of the web.
> How would the user feel if they accidentally selected 'C:\windows\' as
> the download path and their computer got messed up? ;-)  Or more
> likely, a spyware website could download a trojan to your computer when
> you thought your were downloading a movie.   When this kind of thing
> happens today it's considered an exploit.
>
> The reason that the UNC path works is that you are on an intranet and
> the target PC has a shared folder.  If you are actually signed on the
> the web server and you open a CMD prompt you could key an equivalent
> copy command and it would work.  CherryPy is just doing the same thing.
>  But if your CheryPy app was exposed to the internet and I was running
> it and asked to save the code to \\jgraves\share it would not work
> because your intranet does not have a machine named 'jgraves'
> (presumably).
>
> I think the best that you could do would be to give a link to a zip
> file and let the user choose the path they want to unzip to once they
> have downloaded the file.
>
> As for working with SVN, I really like TortoiseSVN but you would have
> to install it on all machines which is what you are trying to avoid (I
> think.)
> 
> Sorry to be the bearer of bad news.
> 
> ...
> jay graves

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


Simple Char-I/O Dialogs for Win32 and DOS

2006-06-14 Thread Mr Roboto
Folks:

I've already searched the group and have determined there *are*
char I/O based input systems, ala NCURSES, that are
Python-compatible (ie. PyNCurses, UrWid, etc.)  What I *need* is
something that does simple dialogs under char-I/O Win32 and DOS
w/ very little fuss or muss.  At most, I need one or two dialog
boxes to boot my little app/util *AND* hope upon hope I don't
need port something (which would take more days than I have
*and* would also require a non-trivial support effort from a
one-man show: *me*) and can simply grab something (open-source)
off-the-shelf.  I don't need a dialog/forms designer, no
database access, just a basic dialog box to get input from a
couple of text boxes, check boxes, etc.

Does such an animal exist and can someone offer a link to the
kit ?  TIAMR

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


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-15 Thread Mr Roboto
Jarek Zgoda wrote:
> nikie napisa³(a):
>
> > If you want to *buy* VS 2003, you could still purchase a 1-year MSDN
> > Pro Subscription. The price difference isn't *that* big compared to a
> > single-user license of VS, and it automatically includes past VS
> > versions (everything from VC++ 6.0 and upwards, IIRC).
>
> This doesn't make building Python exension libraries any easier.
>
> In some cases, you can still build Python extension with MinGW. I didn't
> try this with anything more complicated than linking to libxml2, but
> still, it's some workaround. Not sure about the performace of such
> build, though.
>
> --
> Jarek Zgoda
> http://jpa.berlios.de/

I haven't personally tried a Python compile w/ this, but I'll
share it in hopes that it'll help:  one can download a free copy
of Visual C++ 2K5 *Express* from microsoft itself.  If you're
interested, try:

http://msdn.microsoft.com/vstudio/express/visualc/default.aspx

It's legal, free (no registration, no BS.)  HTHMR

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


[Q] About an Installer Script for PyWin

2006-08-25 Thread Mr. Roboto
I need PyWin under the covers, that is, to install it as part of an
application, but in such a way that it isn't visible to users.  I'm
concerned about a so-called "power-user", seeing the Python directory
and/or the corresponding entry in the 'Add/Remove Programs' list,
breaking my app by uninstalling what he/she thinks is removing an
'unnecessary program.'

Unfortunately, I don't see any installer scripts, like for Inno Setup
or NSIS in the source archive I just downloaded from SourceForge.
I'd love to volunteer to do something like this for the larger
community of Pythonista, but I can't find any info (via Google) about
this.  AFAIK, the critical info is related to the registry settings
for the Win32-related elements.  I'm especially concerned about
installation of the COM infrastructure, as getting the other registry
settings is mostly tedious (but doable), trial-and-error exports from
the Registry.  The rest "should" be simply a matter of creating the
primary directory structure and copying the archive files to it.

Does anyone have pointers ?  TIA

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


calling python from C#...

2006-01-22 Thread Mr BigSmoke
Hi everybody,
I need write an application in c#, but i wnat to use some functions
that i have already written in python. Is there an "easy" way to call
my python code from c#? I must use COM or there are other ways? And, if
COM is the only way, where can i find some tutorials or examples? I've
never wrote com server and i really don't know where and how to
start
tnx
Fabio

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


Re: calling python from C#...

2006-01-22 Thread Mr BigSmoke
I use python for .NET in some applications... I've always used it for
using c# code from python (but i had some problems using it with py2exe
and win2000).  I'll try using it the other way (c# calling python).
I also thought about trying ironpython, but it's too young for my work
projects...
The COM aproach seemed more stable to me what do u think?

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


Re: Data Crunching and Charting....

2006-01-28 Thread Mr BigSmoke
Hi Tom.

I had more or less the same problem about 1 year and a half ago...
Since then i've tried either Matplotlib and chaco. I've started using
matplotlib but for some features reason i've decided to use only chaco.
Chaco is really cool but has some neg. points:
- documentation is not really detailed and there are really few
examples
- not supported anymore (at least i've never found any place supporting
it.. if anyone know bout any support tell me!!)
- sometimes it's really hard to look into it's code to extend some
classes...

The data i have to plot goes from very few curves and ticks to about
10/12 curves, 15000 ticks and range from -1 to 10+ in Y axis.

Th plotting speed is good... but more data u plot, more problem u get!!
Like, zooming feature is not very "solid", and get's worse with tons of
data..., some features are missing (or at least i've never found them!!
I'd be very happy if someone says that i'm wrong and shoe me them!!),
like showing the values of th curvers when i pass the mouse on it, of
the highlighting a point in the curve if i clck on it!!

Fabio Pliger


[EMAIL PROTECTED] wrote:
> Hi all.
>
> Question: I have a project nearly complete written in VB.Net using
> charts from 3rd party vendors...expensive, yes, fast, not really. The
> data I am plotting is about 30 columns by 3000-9000 rows, all in a tab
> delimited file(43 files total). My question is whether or not I can
> accomplish the same in Python utilizing Matplotlib or Chaco for
> plotting, at a much faster speed. In my app it takes a while to loop
> through all the rows/columns to plot the data. Im just curious whether
> there may be a big boost in performance using python. Also I use
> spreadsheet style grids for displaying data. I was looking at the grid
> control for wxpython and that seems a nice fit. Anyone with experience
> with it have any opinions, Id appreciate them. Alot of the programming
> I do deals with crunching data and charting it. Sometimes I wonder
> whether python would be a much better canidate for this type of work
> rather than what Im using now.
> 
> 
> Thanks.
> 
> 
> Tom

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


Re: Data Crunching and Charting....

2006-01-29 Thread Mr BigSmoke
Great!! I kept looking enthought site everyday for 2/3 months about one
year ago... but it always had old chaco versions, no news... Then i
posted questions about it here at comp.lang.python and some people said
the project had been abbandoned... Great to know that it's not true!!
TNX VERY MUCH!!

Fabio Pliger

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


Using CHACO and UNICODE

2006-02-21 Thread Mr BigSmoke
I'm using chaco in an application that draw some grafs and plot. I
really NEED to write unicode strings as a title (PlotTitle) and
labels(PlotLabels) i my axis. The problem is that chat (and it's
traits) only allow ascii strings... In the old version of chaco i
created a new myPlotLabel class, derived from PlotLabel that alowed me
to write unicode strings... but with the last version of Chaco i wasn't
able to do that yet!! Someone can help me? Please, it's really
important for me...

Thanks, FP

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


including directories with py2exe

2006-02-26 Thread Mr BigSmoke
Hi All
how do i include directories into my project when using py2exe? I have
a module that has it's images directory and when it's searches it (into
../dist/library.zip/.../mymodule/) it generates an error because the
directory wasn't imported...
tnx

Fabio

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


How to use TLS lite

2007-06-08 Thread Mr SZ
I'm using tls lite to send mail using gmail's smtp.This is what I've done:

from tlslite.api import *
import tlslite.integration.SMTP_TLS
connection= tlslite.integration.SMTP_TLS.SMTP_TLS('smtp.gmail.com',587)
connection.set_debuglevel(1)
msg = "Subject:Testing \n Hello"
connection.starttls('[EMAIL PROTECTED]','password')
connection.sendmail("[EMAIL PROTECTED]","[EMAIL PROTECTED]",msg)

In return this is what I get:

[EMAIL PROTECTED]:~/Desktop$ python smtp2.py
send: 'STARTTLS\r\n'
reply: '503 5.5.1 EHLO/HELO first m75sm2193378wrm\r\n'
reply: retcode (503); Msg: 5.5.1 EHLO/HELO first m75sm2193378wrm
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-mx.google.com at your service, [59.93.118.190]\r\n'
reply: '250-SIZE 28311552\r\n'
reply: '250-8BITMIME\r\n'
reply: '250-STARTTLS\r\n'
reply: '250 ENHANCEDSTATUSCODES\r\n'
reply: retcode (250); Msg: mx.google.com at your service, [59.93.118.190]
SIZE 28311552
8BITMIME
STARTTLS
ENHANCEDSTATUSCODES
send: 'mail FROM:<[EMAIL PROTECTED]> size=23\r\n'
reply: '530 5.7.0 Must issue a STARTTLS command first m75sm2193378wrm\r\n'
reply: retcode (530); Msg: 5.7.0 Must issue a STARTTLS command first 
m75sm2193378wrm
send: 'rset\r\n'
reply: '250 2.1.0 Flushed m75sm2193378wrm\r\n'
reply: retcode (250); Msg: 2.1.0 Flushed m75sm2193378wrm
Traceback (most recent call last):
  File "smtp2.py", line 7, in 
connection.sendmail("[EMAIL PROTECTED]","[EMAIL PROTECTED]",msg)
  File "/usr/lib/python2.5/smtplib.py", line 684, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, '5.7.0 Must issue a STARTTLS command first 
m75sm2193378wrm', '[EMAIL PROTECTED]')

Where am I going wrong?



" life isn't heavy enough,it flies away and floats far above action"
  
-
How would you spend $50,000 to create a more sustainable environment in 
Australia?  Go to Yahoo!7 Answers and share your idea.-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   >