Re: Simple question

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 3:55 PM, John Ladasky
 wrote:
> Shush!  That's one of Python's most closely-guarded secrets!  Every 
> politician on Earth will want to learn to program in Python after seeing that!
>

Not really, the legal profession has known about this for centuries.

(Princess Zara, presenting Sir Bailey Barre, Q.C., M.P.)
 A complicated gentleman allow to present,
 Of all the arts and faculties the terse embodiment,
 He's a great arithmetician who can demonstrate with ease
 That two and two are three or five or anything you please;
 An eminent Logician who can make it clear to you
 That black is white--when looked at from the proper point of view;
 A marvelous Philologist who'll undertake to show
 That "yes" is but another and a neater form of "no.

>From Gilbert & Sullivan's "Utopia, Ltd", dating back to 1893. Python 2
continues this excellent tradition of permitting truth to be redefined
at will, but Python 3 adopts the view of the narrow-minded pedant who
still believes that two and two makes four. It's an opinionated
language, and that helps you to avoid weirdnesses :)

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


Re: socket issue with recv()

2014-08-23 Thread dieter
Arthur Clarck  writes:
> ...
> The problem I have now is the following.
> I have a script to connect to some telecom service.
> The script is forking (parent/child)
> The child is only reading what comes from the remote server.
> Here the problematic code:
>
> total = ''
> while True:
>data = s.recv(1024)
>total += data
>if (data == ''):
>   print 'remote site is closed'
>   s.close()
>   sys.exit()
>
> What is happening is that I got some datas from the remote site,
> Something like 'Contacting BH: ...'
> But directly followed by 'remote site is closed.

Some services (such as older HTTP 1.0 services) are designed
for "one command per connection" mode. This means, they answer
a signle command and then close the connection.

>From what you describe, your service might belong to this class.
In this case, you would need to open a new connection whenever
you detect that the old connection was closed.

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


Re: Simple question

2014-08-23 Thread John Ladasky
On Saturday, August 23, 2014 6:10:29 AM UTC-7, explode...@gmail.com wrote:
> Can some one explain why this happens:
> 
> True, False = False, True
> 
> print True, False
> 
> False True

Shush!  That's one of Python's most closely-guarded secrets!  Every politician 
on Earth will want to learn to program in Python after seeing that!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the output in reference of descriptor.

2014-08-23 Thread luofeiyu

let me paste it again to make my question more clear:

>>>c2.d
__get__() is called <__main__.C2 object at 0x0297BE10> 


<__main__.C object at 0x0297BBA8>

>>> c2.d.a
__get__() is called <__main__.C2 object at 0x0297BE10> 


__getattribute__() is called
'abc'

Why the result of c2.d.a  is not :

__get__() is called <__main__.C2 object at 0x0297BE10> 


<__main__.C object at 0x0297BBA8>
__getattribute__() is called
'abc'

Why the` return self` in the __get__ method in class C  does not work? 
Why there is no <__main__.C object at 0x0297BBA8>  in the output?



and the source code are:


|class C(object):
a = 'abc'
def __getattribute__(self, *args, **kwargs):
print("__getattribute__() is called")
return object.__getattribute__(self, *args, **kwargs)
def __getattr__(self, name):
print("__getattr__() is called ")
return name + " from getattr"
def __get__(self, instance, owner):
print("__get__() is called", instance, owner)
return self
def foo(self, x):
print(x)


class C2(object):
d = C()


|


On 8/23/2014 12:10 PM, Ian Kelly wrote:
On Thu, Aug 21, 2014 at 7:25 PM, luofeiyu > wrote:

> >>> c2.d.a
> __get__() is called <__main__.C2 object at 0x0297BE10> 

> C2'>
> __getattribute__() is called
> 'abc'
>
> Why the result of c2.d.a  is not :
>
> __get__() is called <__main__.C2 object at 0x0297BE10> 

> C2'>
> __getattribute__() is called
> 'abc'

As far as I can tell you pasted the same output twice, so I don't 
understand what it is that you're asking.







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


Re: ANN: binario - simple work with binary files

2014-08-23 Thread Rustom Mody
On Saturday, August 23, 2014 9:54:05 PM UTC+5:30, Алексей Саскевич wrote:
> binario is the Python package that lets an application read/write primitive 
> data types from an underlying input/output file as binary data.

> Package on PyPI: https://pypi.python.org/pypi/binario
> Package on GitHub: https://github.com/asaskevich/binario
> Docs: http://binarios-docs.readthedocs.org/en/latest/

> Package still in Alpha, and I need some help with testing, new features and 
> docs :)

Any advantage of binario over construct?

http://construct.readthedocs.org/en/latest/basics.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why can not initialize the class?

2014-08-23 Thread Michael Torrie
On 08/23/2014 11:25 AM, CHIN Dihedral wrote:
> Well, an object in python can add
> properties in the run-time to evolve
> steadily and stealthly.
> 
> Those unnessary set-get-C++ methods
> are not very important in PYTHON.

That's the most coherent thing I've seen from Dihedral in years!



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


Re: why the attribute be deleted still in dir(man)?

2014-08-23 Thread Ned Batchelder

On 8/23/14 7:44 PM, luofeiyu wrote:

Think for your  remark " You didn't delete the name property, which is
part of the class, not the instance."
I fix my codes to get the target done.

class Person(object):
def addProperty(self, attribute):
   getter = lambda self: self._getProperty(attribute)
   setter = lambda self, value: self._setProperty(attribute,
value)
   deletter = lambda self:self.delProperty(attribute)
   setattr(self.__class__, attribute,
property(fget=getter,fset=setter,fdel=deletter,doc="Auto-generated method"))
 def _setProperty(self, attribute, value):
   setattr(self, '_' + attribute, value.title())
 def _getProperty(self, attribute):
return getattr(self, '_' + attribute)
 def delProperty(self,attribute):
delattr(self,'_' + attribute)
delattr(self.__class__, attribute)

I am so happy .



Seriously, you should listen to the people here advising you to simplify 
this.  This is a lot of complexity to do not very much.


Why not just:

p = Person()
p.foo = 17

What is the point of dynamically defining properties that simply front 
attributes with a slightly different name?  Just use an attribute.


--
Ned Batchelder, http://nedbatchelder.com

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


Re: why the attribute be deleted still in dir(man)?

2014-08-23 Thread luofeiyu
Think for your  remark " You didn't delete the name property, which is 
part of the class, not the instance."

I fix my codes to get the target done.

class Person(object):
   def addProperty(self, attribute):
  getter = lambda self: self._getProperty(attribute)
  setter = lambda self, value: self._setProperty(attribute, 
value)

  deletter = lambda self:self.delProperty(attribute)
  setattr(self.__class__, attribute, 
property(fget=getter,fset=setter,fdel=deletter,doc="Auto-generated method"))

def _setProperty(self, attribute, value):
  setattr(self, '_' + attribute, value.title())
def _getProperty(self, attribute):
   return getattr(self, '_' + attribute)
def delProperty(self,attribute):
   delattr(self,'_' + attribute)
   delattr(self.__class__, attribute)

I am so happy .



> >>> man.delProperty("name")
> >>> man.name 
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 4, in 
>   File "", line 12, in _getProperty
> AttributeError: 'Person' object has no attribute '_name'
> >>> dir(man)
> ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', 
'__eq__', '__form
> at__', '__ge__', '__getattribute__', '__gt__', '__hash__', 
'__init__', '__le__',
>  '__lt__', '__module__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__
> repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'__weakref_
> _', '_getProperty', '_setProperty', 'addProperty', 'delProperty', 
'name']


You deleted the _name attribute where you're storing the value of the 
name property. You didn't delete the name property, which is part of 
the class, not the instance.





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


Re: why the attribute be deleted still in dir(man)?

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 9:35 AM, luofeiyu  wrote:
> dear ChrisA ,dynamic is python feature, it is to create descriptor in run
> time ,
> that is the meaning in the codes,and maybe it is a bug:
>
> the attribute  can be displayed  in dir(man)  after be deleted.

Then you don't need descriptors at all. Like I said, read up on doing
classes Python's way. You don't need properties, just use normal
attributes.

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


Re: why the attribute be deleted still in dir(man)?

2014-08-23 Thread luofeiyu
dear ChrisA ,dynamic is python feature, it is to create descriptor in 
run time ,

that is the meaning in the codes,and maybe it is a bug:

the attribute  can be displayed  in dir(man)  after be deleted.




On 8/24/2014 6:56 AM, Chris Angelico wrote:

On Sun, Aug 24, 2014 at 8:49 AM, luofeiyu  wrote:

class Person(object):
def addProperty(self, attribute):
   getter = lambda self: self._getProperty(attribute)
   setter = lambda self, value: self._setProperty(attribute,
value)
   deletter = lambda self:self.delProperty(attribute)
   setattr(self.__class__, attribute,
property(fget=getter,fset=setter,fdel=deletter,doc="Auto-generated method"))
def _setProperty(self, attribute, value):
  setattr(self, '_' + attribute, value.title())
   def _getProperty(self, attribute):
 return getattr(self, '_' + attribute)
   def delProperty(self,attribute):
 delattr(self,'_' + attribute)

Look. Forget properties. Python is not Java or C++, and you almost
never need this kind of thing. Read up a tutorial on doing classes
Python's way, and you'll find that all this sort of thing just doesn't
matter. You've come here with a significant number of questions about
properties, and it looks as if you're trying to do everything through
them - which is utterly and completely useless, especially when you
use properties to be as dynamic as you're doing. Just don't do it.

ChrisA


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


Re: why the attribute be deleted still in dir(man)?

2014-08-23 Thread Ian Kelly
On Sat, Aug 23, 2014 at 4:49 PM, luofeiyu  wrote:
>
> class Person(object):
>def addProperty(self, attribute):
>   getter = lambda self: self._getProperty(attribute)
>   setter = lambda self, value: self._setProperty(attribute,
value)
>   deletter = lambda self:self.delProperty(attribute)
>   setattr(self.__class__, attribute,
property(fget=getter,fset=setter,fdel=deletter,doc="Auto-generated method"))
>def _setProperty(self, attribute, value):
>  setattr(self, '_' + attribute, value.title())
>   def _getProperty(self, attribute):
> return getattr(self, '_' + attribute)
>   def delProperty(self,attribute):
> delattr(self,'_' + attribute)

Unless you're going to have the property actually do something, this is
silly and useless.  Just use a normal attribute.

Even if this is really what you want to do, it's bad design. The class
defines the instances. You shouldn't have an instance method modifying the
structure of other instances of the class.

> >>> man.delProperty("name")
> >>> man.name
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 4, in 
>   File "", line 12, in _getProperty
> AttributeError: 'Person' object has no attribute '_name'
> >>> dir(man)
> ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
'__form
> at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__',
'__le__',
>  '__lt__', '__module__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__
> repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
'__weakref_
> _', '_getProperty', '_setProperty', 'addProperty', 'delProperty', 'name']

You deleted the _name attribute where you're storing the value of the name
property. You didn't delete the name property, which is part of the class,
not the instance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with decimals

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 8:47 AM, Joshua Landau  wrote:
> On 23 August 2014 23:31, Chris Angelico  wrote:
>> On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau  wrote:
>>> So for one "import math" should never go inside a function; you should
>>> hoist it to the top of the file with all the other imports.
>>
>> I'd say "never" is too strong (there are times when it's right to put
>> an import inside a function), but yes, in this case it should really
>> be at the top of the function.
>
> But do any of them apply to "import math"?

Yep. If you have only one function that will ever use it, and that
function often won't ever be called, then putting the import inside
the function speeds up startup. Anything that cuts down on I/O can
give a dramatic performance improvement.

Oh, and when I said "top of the function", what I really meant was
"top of the file", but I think (hope!) people figured that out. Sorry
for the braino.

>> However, you won't need the import at all if you let the formatting
>> function do the rounding for you.
>
> Can that floor?

I'm not sure, dig into the format spec and see! But was flooring
actually a critical part of the problem, or is another sort of
rounding just as good?

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


Re: why the attribute be deleted still in dir(man)?

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 8:49 AM, luofeiyu  wrote:
> class Person(object):
>def addProperty(self, attribute):
>   getter = lambda self: self._getProperty(attribute)
>   setter = lambda self, value: self._setProperty(attribute,
> value)
>   deletter = lambda self:self.delProperty(attribute)
>   setattr(self.__class__, attribute,
> property(fget=getter,fset=setter,fdel=deletter,doc="Auto-generated method"))
>def _setProperty(self, attribute, value):
>  setattr(self, '_' + attribute, value.title())
>   def _getProperty(self, attribute):
> return getattr(self, '_' + attribute)
>   def delProperty(self,attribute):
> delattr(self,'_' + attribute)

Look. Forget properties. Python is not Java or C++, and you almost
never need this kind of thing. Read up a tutorial on doing classes
Python's way, and you'll find that all this sort of thing just doesn't
matter. You've come here with a significant number of questions about
properties, and it looks as if you're trying to do everything through
them - which is utterly and completely useless, especially when you
use properties to be as dynamic as you're doing. Just don't do it.

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


Re: Global indent

2014-08-23 Thread Marko Rauhamaa
Anders Wegge Keller :

>  Curiously enough, even today the same lousy kind of connections
> prevail. We still have a sizeable modem bank at my job. We still do
> our remote support over a telnet/ssh session. And we still are unable
> to reliable get the connection speeds[2], that would make anything
> with a GUI remotely pleasant.

I do emacs over SSH terminal connections all the time both for business
and pleasure. I have occasionally even run the SSH connection (and
emacs) from my cell phone.

The connections aren't all that lousy, but I wouldn't run X11 over them.
Rdesktop is ok but not nearly as convenient as a terminal connection.


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


why the attribute be deleted still in dir(man)?

2014-08-23 Thread luofeiyu

class Person(object):
   def addProperty(self, attribute):
  getter = lambda self: self._getProperty(attribute)
  setter = lambda self, value: self._setProperty(attribute, 
value)

  deletter = lambda self:self.delProperty(attribute)
  setattr(self.__class__, attribute, 
property(fget=getter,fset=setter,fdel=deletter,doc="Auto-generated method"))

   def _setProperty(self, attribute, value):
 setattr(self, '_' + attribute, value.title())
  def _getProperty(self, attribute):
return getattr(self, '_' + attribute)
  def delProperty(self,attribute):
delattr(self,'_' + attribute)

>>> man=Person()
>>> dir(man)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__form
at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__le__',
 '__lt__', '__module__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__
repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'__weakref_

_', '_getProperty', '_setProperty', 'addProperty', 'delProperty']
>>> man.addProperty("name")
>>> man.name="john"
>>> dir(man)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__form
at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__le__',
 '__lt__', '__module__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__
repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'__weakref_
_', '_getProperty', '_name', '_setProperty', 'addProperty', 
'delProperty', 'name

']
>>> man.name
'John'
>>> man.delProperty("name")
>>> man.name
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in 
  File "", line 12, in _getProperty
AttributeError: 'Person' object has no attribute '_name'
>>> dir(man)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__form
at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__le__',
 '__lt__', '__module__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__
repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'__weakref_

_', '_getProperty', '_setProperty', 'addProperty', 'delProperty', 'name']


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


Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 23:31, Chris Angelico  wrote:
> On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau  wrote:
>> So for one "import math" should never go inside a function; you should
>> hoist it to the top of the file with all the other imports.
>
> I'd say "never" is too strong (there are times when it's right to put
> an import inside a function), but yes, in this case it should really
> be at the top of the function.

But do any of them apply to "import math"?

> However, you won't need the import at all if you let the formatting
> function do the rounding for you.

Can that floor?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with decimals

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau  wrote:
> So for one "import math" should never go inside a function; you should
> hoist it to the top of the file with all the other imports.

I'd say "never" is too strong (there are times when it's right to put
an import inside a function), but yes, in this case it should really
be at the top of the function.

However, you won't need the import at all if you let the formatting
function do the rounding for you.

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


Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 22:52:09 +0100, Joshua Landau 
wrote:

>On 23 August 2014 18:47, Seymore4Head  wrote:
>> Anyone care to suggest what method to use to fix the decimal format?
>
>It sounds like you want a primer on floating point. The documentation
>of the decimal module is actually a good read, although I don't doubt
>there are even better resources somewhere:
>
>https://docs.python.org/3/library/decimal.html
>
>Note that you probably also want to use the decimal module, seeing as
>it's good at storing decimals.
>
>Finally, look at "moneyfmt" in the decimal docs:
>
>https://docs.python.org/3/library/decimal.html#recipes

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


Re: Global indent

2014-08-23 Thread Anders Wegge Keller
On Sun, 24 Aug 2014 00:56:11 +1000
Steven D'Aprano  wrote:

> Despite my comments, I don't actually have any objection to people who
> choose to use Emacs, or Vim, or edit their text files by poking the hard
> drive platter with a magnetised needle if they prefer :-) But I do think
> it's silly of them to claim that Emacs has no learning curve, or to fail to
> recognise how unfamiliar and different the UIs are compared to nearly
> everything else a computer user is likely to be familiar with in 2014.

 Really, they don't! At least not for the people, for whom they are
necessary tools. When I started in my present job, "remote access" was
a dial-up modem, that could do 2400 baud, if you were lucky[1]. With such a
shitty connection, a text-only editor is indisputably the right thing. 

 Curiously enough, even today the same lousy kind of connections prevail. We
still have a sizeable modem bank at my job. We still do our remote support
over a telnet/ssh session. And we still are unable to reliable get the 
connection speeds[2], that would make anything with a GUI remotely
pleasant. 

 So emacs and vim still have their niches. Those of us, who are old enough
to have started our first job in a glorified teletype, OR have to support
systems that are only reachable over RFC-1149 quality datalinks, belong
there. The rest of you would probably be better off with something nicer.

1. Meaning a real switched landline all the way from Denmark to Tokyo.
Ending up with two satellite up/down-links was a killer.

2. We have an installation in the Philippines, where we ended up installing a
   satellite uplink. It feels like we have doubled the connectivity of the
   entire Manilla area by doing so. And it's still painfully slow.

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


Re: Global indent

2014-08-23 Thread Rustom Mody
On Sunday, August 24, 2014 2:27:56 AM UTC+5:30, Joshua Landau wrote:

> Ay, so is any editor with an API. I use Sublime mostly because it's
> pretty, fast and has a Python-based API. The only actual feature it
> has that some others don't is multiple selections, and even then a lot
> do.

You mean this?
http://emacsrocks.com/e13.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 22:13, Seymore4Head  wrote:
> def make_it_money(number):
> import math
> return '
> + str(format(math.floor(number * 100) / 100, ',.2f'))

So for one "import math" should never go inside a function; you should
hoist it to the top of the file with all the other imports.

You then have

def make_it_money(number):
return '$' + str(format(math.floor(number * 100) / 100, ',.2f'))

Consider the

'$' + STUFF

This takes your formatted string (something like '12.43') and adds a
"$" to the front.

So then consider

str(format(math.floor(number * 100) / 100, ',.2f'))

The first thing to note is that format is defined like so:

help(format)
#>>> Help on built-in function format in module builtins:
#>>>
#>>> format(...)
#>>> format(value[, format_spec]) -> string
#>>>
#>>> Returns value.__format__(format_spec)
#>>> format_spec defaults to ""
#>>>

format returns a string, so the str call is unneeded.

You then consider that format takes two arguments:

math.floor(number * 100) / 100

and

',.2f'

Looking at the (well hidden ;P) documentation
(https://docs.python.org/3/library/string.html#formatspec) you find:

"The ',' option signals the use of a comma for a thousands separator.
For a locale aware separator, use the 'n' integer presentation type
instead."

and

"The precision is a decimal number indicating how many digits should
be displayed after the decimal point for a floating point value
formatted with'f' and 'F', or before and after the decimal point for a
floating point value formatted with 'g' or 'G'."

So this says "two decimal places with a comma separator."

Then consider

math.floor(number * 100) / 100

This takes a number, say 12345.6789, multiplies it by 100, to say
1234567.89, floors it, to say 1234567 and then divides by 100, to say,
12345.67.

In other words it floors to two decimal places. The one thing to note
is that binary floating point doesn't divide exactly by 100, so this
might not actually give a perfect answer. It'll probably be "good
enough" for your purposes though.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 18:47, Seymore4Head  wrote:
> Anyone care to suggest what method to use to fix the decimal format?

It sounds like you want a primer on floating point. The documentation
of the decimal module is actually a good read, although I don't doubt
there are even better resources somewhere:

https://docs.python.org/3/library/decimal.html

Note that you probably also want to use the decimal module, seeing as
it's good at storing decimals.

Finally, look at "moneyfmt" in the decimal docs:

https://docs.python.org/3/library/decimal.html#recipes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head
 wrote:

>I am trying to do this example:
>http://openbookproject.net/pybiblio/practice/wilson/loan.php
>The instructions warn that floating point math can get messy so I
>cheated a little bit to get me going.
>
>I made my program work by using numbers that wouldn't get messy.
>Instead of using 6% interest I used 10 and instead of using 12 months,
>I used 10.
>
>I managed to get it working and formatted just like they wanted it,
>but now I want to try to use any numbers.  It has been hard to figure
>out which method to use.
>
>Here is the working program.
>
>import sys
>count = 0
>payment = 0
>borrowed = 100
>rate = 10
>term = 10
>interest=borrowed*rate*.01 #(*1)
>balance = borrowed + interest
>print ("Loan calculator")
>print ("")
>print ("Amount borrowed: ", borrowed)
>print ("Interest rate: ", rate)
>print ("Term: (months)", term)
>print ("")
>print ("Amount borrowed:" , borrowed)
>print ("Total interest paid:" , interest)
>print ("")
>print ("")
>print ("Amount  Remaining")
>print ("Pymt#PaidBalance")
>print ("-   --   --")
>while count <=term:
>
>
>print (repr(count).rjust(3), repr(payment).rjust(13),
>repr(balance).rjust(14))
>
>
>payment = (borrowed + interest)/term
>balance = balance - payment
>count = count + 1
>
>What should I use to make the formatting come out correctly when the
>program prints "payment" and "balance" using decimal format?
>
>If you change the "rate" from 10 to 6 and the "term" from 10 to 12,
>the screen gets very messy.
>
>Anyone care to suggest what method to use to fix the decimal format?

OK  I found the answer to my own question after getting search tips
here.

I found this function that I will be saving for later.
def make_it_money(number):
import math
return '$' + str(format(math.floor(number * 100) / 100, ',.2f'))

(I still need more practice to find out how it does what it does, but
I like the end result)

So I changed the line in question to:
 print (repr(count).rjust(3), make_it_money(payment).rjust(13),
make_it_money(balance).rjust(14))

So..now changing the rate from 10 to 6 and the term from 10 to 12
works fine.

I would still like to see other solutions if anyone wants to offer.

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


Re: string encoding regex problem

2014-08-23 Thread Peter Otten
Philipp Kraus wrote:

> I have create a short script:
> 
> -
> #!/usr/bin/env python
> 
> import re, urllib2
> 
> 
> def URLReader(url) :
> f = urllib2.urlopen(url)
> data = f.read()
> f.close()
> return data
> 
> 
> print re.match( "\.*\<\/small\>",
> URLReader("http://sourceforge.net/projects/boost/";) )
> -
> 
> Within the data the string "boost_1_56_0.tar.gz" should
> be machted, but I get always a None result on the re.match, re.search
> returns also a None.

>>> help(re.match)
Help on function match in module re:

match(pattern, string, flags=0)
Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found.

As the string doesn't start with your regex re.match() is clearly wrong, but 
re.search() works for me:

>>> import re, urllib2
>>> 
>>> 
>>> def URLReader(url) :
... f = urllib2.urlopen(url)
... data = f.read()
... f.close()
... return data
... 
>>> data = URLReader("http://sourceforge.net/projects/boost/";)
>>> re.search("\.*\<\/small\>", data)
<_sre.SRE_Match object at 0x7f282dd58718>
>>> _.group()
'boost_1_56_pdf.7z'


> I have tested the regex under http://regex101.com/ with the HTML code
> and on the page the regex is matched.
> 
> Can you help me please to fix the problem, I don't understand that the
> match returns None


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


Re: Global indent

2014-08-23 Thread Joshua Landau
On 23 August 2014 17:17, Christian Gollwitzer  wrote:
> Am 23.08.14 16:19, schrieb Joshua Landau:
>>
>> On 23 August 2014 10:41, Christian Gollwitzer  wrote:
>>>
>>> Sometimes I impress my colleagues with what they call "magic", i.e.
>>> creating
>>> special repeated lists of numbers by a few keystrokes in gvim, and that
>>> has
>>> triggered the request from them to learn a bit of (g)vim.
>>
>>
>> I have yet to be truly impressed by Vim, in that Sublime Text with a
>> few extensions seems to do the same things just as easily. I find that
>> Vim and Emacs users consistently underrate the powers of these
>> editors, presumably because they've never put nearly as much effort
>> into them as they have into their Vim or Emacs.
>
>
> I never looked into Sublime, because it costs money. But no doubt it is a
> powerful editor, judging from comments of other people.

Ay, so is any editor with an API. I use Sublime mostly because it's
pretty, fast and has a Python-based API. The only actual feature it
has that some others don't is multiple selections, and even then a lot
do.

My point is more about how using Emacs or Vim and having a powerful
editor is mostly the symptom of the same thing, not a causal relation.

>> For example, to make a numbered list in (my) Sublime Text (fully
>> custom shortcuts ahead):
>>
>> [ ... some keystrokes ...]
>
> I'd actually do this in gvim to put numbers at each line:
>
> - Select text (by mouse, or v + cursor movements)
> - ! awk '{print NR ". " $0}'
>
> Yes, it is cheating, it pipes the selected text through an external tool.
> But why should I do the tedious exercise of constructing an editor macro,
> when an external tool like awk can do the same so much easier?

Because it normally happens more like this:

Move to copy something that I wish to postfix with a number
Ctrl-d a few times to select copies of that fragment
Write $ and select it
Press Ctrl-e to turn "$"s into numbers

Luckily that one doesn't happen too often either because numbering
things sequentially is better left to loops. The key binding is
primarily used for evaluating snippets of code inline.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python vs C++

2014-08-23 Thread Terry Reedy

On 8/23/2014 10:21 AM, Rustom Mody wrote:


Wordperfect was one of the best wysiwyg editors Ive used.
One could use it in normal (1-screen) mode
Or one could split the screen and see the formattings in the lower window
along withe the formatted in the upper.


I wrote at least two books with Wordperfect. Seeing the formatting code 
was essential to get the detail correct. Word, and even OO and LO are 
downgrades in this respect. At least with LO, one can get or enable 
saving as flat xml and edit at that level.



Which is to say I believe weve not the heard the last of finding the
best mix between WYSIWYG and coded-text+compile


I'd like to have side-by-side windows with LO.

--
Terry Jan Reedy

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


Re: string encoding regex problem

2014-08-23 Thread Philipp Kraus

Hi,

On 2014-08-16 09:01:57 +, Peter Otten said:


Philipp Kraus wrote:

The code works till last week correctly, I don't change the pattern. 


Websites' contents and structure change sometimes.

My question is, can it be a problem with string encoding? 


Your regex is all-ascii. So an encoding problem is very unlikely.

found = re.search( "href=\"/projects/boost/files/latest/download\?source=files\" 
title=\"/boost/(.*)",

data)



Did I mask the question mark and quotes
correctly?


Yes.

A quick check...

data = 
urllib.urlopen("http://sourceforge.net/projects/boost/files/boost/";).read() 

re.compile("/projects/boost/files/latest/download\?source=files.*?>").findall(data) 

['/projects/boost/files/latest/download?source=files" 
title="/boost-docs/1.56.0/boost_1_56_pdf.7z:  released on 2014-08-14 
16:35:00 UTC">']


...reveals that the matching link has "/boost-docs/" in its title, so the
 site contents probably did change. 


I have create a short script:

-
#!/usr/bin/env python

import re, urllib2


def URLReader(url) :
   f = urllib2.urlopen(url)
   data = f.read()
   f.close()
   return data


print re.match( "\.*\<\/small\>", 
URLReader("http://sourceforge.net/projects/boost/";) )

-

Within the data the string "boost_1_56_0.tar.gz" should 
be machted, but I get always a None result on the re.match, re.search 
returns also a None.
I have tested the regex under http://regex101.com/ with the HTML code 
and on the page the regex is matched.


Can you help me please to fix the problem, I don't understand that the 
match returns None


Thanks

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


Re: Working with decimals

2014-08-23 Thread Mark Lawrence

On 23/08/2014 20:48, Seymore4Head wrote:


Thanks for the links.   The python-course looks like a beginner start.
It raises one more question.

Some have suggested using strings.  I understand that strings and
numbers are not the same thing.  I know that converting numbers to
strings can be useful for display, but you would think that there
would be enough demand for a built in set of instructions that handle
money calculations accurately.



The joys of floating point numbers (you're calling them decimals) on 
computers.  Search the archives of this list and you'll find loads of 
references which will explain them far better than I can.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Global indent

2014-08-23 Thread Tim Chase
On 2014-08-23 15:19, Joshua Landau wrote:
> I have yet to be truly impressed by Vim, in that Sublime Text with a
> few extensions seems to do the same things just as easily

Can it be run remotely in a tmux session which can be accessed via
SSH from multiple machines? ;-)

Using the command-line:  it's a terminal condition.

-tkc





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


Re: Python code to distinguish between data having, 2 different formats, in a given cell(MS Excel).

2014-08-23 Thread Denis McMahon
On Sat, 23 Aug 2014 11:56:29 -0700, Ed Joz wrote:

> Please suggest a sample python code.

while program result not correct:
fix program

Note - we are not here to write your code for you, but we will try and 
help you develop your own code to do what you want.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global indent

2014-08-23 Thread Tim Chase
On 2014-08-23 19:31, Steven D'Aprano wrote:
> Sorry, but I have no idea what you mean by "orthogonal set of verbs
> and nouns in an editing language". Can you explain?

In the context of vi/vim, an "orthogonal set of verbs and nouns in an
editing language" mean that you have a collection of verbs
(such as d=delete, v=visual/highlight, y=yank/copy, c=change, zf=fold,
gU=transform-to-uppercase, gu=transform-to-lowercase, g~=swap-case,
g?=ROT13, "="=reformat, etc) and nouns (often called "motions" as most
of them can be used to move the cursor in normal-mode) such as
b=back, }=next-paragraph-boundary, {=previous-paragraph-boundary,
"*"=next-match-of-the-word-under-the-cursor, etc.

They're orthogonal because learning a new verb allows you to apply it
to all of the nouns/motions you already know; and learning a new
noun/motion lets you use it with any of the verbs you know.  And you
can prefix any command (verb+noun) with a count which increases the
power further.

Thus, learning one new thing has a multiplying effect.

> I find that between find/replace and Block Selection editing, I
> can't really say I've missed either the lack of editing macros or
> these orthogonal verbs, whatever they are. Occasionally I move a
> large editing job into Python, but I wouldn't want to learn a
> separate language for that.

Much of the power comes in the repeatability of last action.  Once
the editor understands that your last action meant
"transform-to-uppercase from the cursor to the end of the line", you
can move anywhere else in the document and instruct the editor to do
the same thing with a single command (in vi/vim, that's the period).
Drew Neil's _Practical Vim_ spends quite a bit of ink covering the
implications of repeatability.

[from another message from Steven]
> When I'm programming, actual fingers on keys is just a small
> proportion of the time spent. Most of my time is reading, thinking
> and planning, with typing and editing a distant fourth, and I not
> only don't mind moving off the keyboard onto the mouse, but
> actually think that's a good thing to shift my hands off the
> keyboard and use a different set of muscles. So I'm not especially
> receptive to arguments that Vim or Emacs will make me more
> productive.

I agree that a much smaller percentage of my time is spent actually
entering text and a far greater amount of time is spent navigating
(reading/thinking/planning) the document.  Most vi/vim users spend
their time in normal mode where that navigation is quick and can all
be done from a keyboard.  I find that 


[and from yet another message from Steven]
> You need a tutorial for a text editor???
> 
> If that's supposed to prove how easy Emacs is, you have failed
> miserably.

Indeed, both vim and emacs provide tutorials precisely because they
are NOT so easy to get started with.  But while I might not need
instruction for a hand-saw to remove a small tree, if I had multiple
trees to cut down, I might want a chainsaw and seek to read the
instructions to get the most out of my investment.  And if I had a
LOT of trees to cut down, I might make a major investment
https://www.youtube.com/watch?v=LYKg0gbRFns and read the heck out of
the instructions.

I happen to use vi/vim because it works just about everywhere (and
even comes installed from the factory on most *nix-likes), but as long
as people are using an editor that is sufficient to meet their needs,
I'm content to live in amicable harmony.  It's when your needs exceed
what your editor can provide that I start to recommend
editor-shopping.  I can't help you if you choose something other than
Vim, but I can encourage complainers to use a more powerful editor.

[and yet one other message from Steven]
> Besides, the standard text editor is ed:

THERE is the truth ;-)  (and...it's far more powerful than Notepad)

-tkc






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


Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 20:24:41 +0100, Mark Lawrence
 wrote:

>On 23/08/2014 20:07, Seymore4Head wrote:
>>
>> Funny, I though using the web would be better than a book.  I don't
>> think so anymore.  Using the web, it is hard to find square one
>> tutorial text.
>>
>
>Try typing something like "python string formatting tutorial" into your 
>favourite search engine and you'll find things like 
>https://docs.python.org/3/tutorial/inputoutput.html or 
>http://www.python-course.eu/python3_formatted_output.php
>
Thanks for the links.   The python-course looks like a beginner start.
It raises one more question.

Some have suggested using strings.  I understand that strings and
numbers are not the same thing.  I know that converting numbers to
strings can be useful for display, but you would think that there
would be enough demand for a built in set of instructions that handle
money calculations accurately.


>For a generalised list try this 
>https://wiki.python.org/moin/BeginnersGuide/Programmers
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with decimals

2014-08-23 Thread Mark Lawrence

On 23/08/2014 20:07, Seymore4Head wrote:


Funny, I though using the web would be better than a book.  I don't
think so anymore.  Using the web, it is hard to find square one
tutorial text.



Try typing something like "python string formatting tutorial" into your 
favourite search engine and you'll find things like 
https://docs.python.org/3/tutorial/inputoutput.html or 
http://www.python-course.eu/python3_formatted_output.php


For a generalised list try this 
https://wiki.python.org/moin/BeginnersGuide/Programmers


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Working with decimals

2014-08-23 Thread Joel Goldstick
On Sat, Aug 23, 2014 at 3:07 PM, Seymore4Head
 wrote:
> On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick
>  wrote:
>
>>On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head
>> wrote:
>>> I am trying to do this example:
>>> http://openbookproject.net/pybiblio/practice/wilson/loan.php
>>> The instructions warn that floating point math can get messy so I
>>> cheated a little bit to get me going.
>>>
>>> I made my program work by using numbers that wouldn't get messy.
>>> Instead of using 6% interest I used 10 and instead of using 12 months,
>>> I used 10.
>>>
>>> I managed to get it working and formatted just like they wanted it,
>>> but now I want to try to use any numbers.  It has been hard to figure
>>> out which method to use.
>>>
>>You need to learn about string formatting.  Here is a good link:
>>http://mkaz.com/2012/10/10/python-string-format/
>>
> Thanks.  I will give that a try.
>
>>> Here is the working program.
>>>
>>> import sys
>>> count = 0
>>> payment = 0
>>> borrowed = 100
>>> rate = 10
>>> term = 10
>>> interest=borrowed*rate*.01 #(*1)
>>> balance = borrowed + interest
>>> print ("Loan calculator")
>>> print ("")
>>> print ("Amount borrowed: ", borrowed)
>>> print ("Interest rate: ", rate)
>>> print ("Term: (months)", term)
>>> print ("")
>>> print ("Amount borrowed:" , borrowed)
>>> print ("Total interest paid:" , interest)
>>> print ("")
>>> print ("")
>>> print ("Amount  Remaining")
>>> print ("Pymt#PaidBalance")
>>> print ("-   --   --")
>>> while count <=term:
>>>
>>>
>>> print (repr(count).rjust(3), repr(payment).rjust(13),
>>> repr(balance).rjust(14))
>>>
>>>
>>I don't understand why you are using repr(..)  It is not necessary.
>>
> Would you please change the line to something you feel that is more
> appropriate?  That was the first command I stumbled on that I could
> use to get the column spacing correctly.
> I have contacted my local library to get a couple of books on Python,
> but at the moment all I have is the web.
>
> Funny, I though using the web would be better than a book.  I don't
> think so anymore.  Using the web, it is hard to find square one
> tutorial text.
>

You should go to python.org and take a look at the tutorial.  There
are lots of references to other sites there as well
>
>>> payment = (borrowed + interest)/term
>>> balance = balance - payment
>>> count = count + 1
>>>
>>> What should I use to make the formatting come out correctly when the
>>> program prints "payment" and "balance" using decimal format?
>>>
>>> If you change the "rate" from 10 to 6 and the "term" from 10 to 12,
>>> the screen gets very messy.
>>>
>>> Anyone care to suggest what method to use to fix the decimal format?
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>
> I would rather just use Usenet for the moment.  Until the group gets
> tired of nursing the rookie.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python code to distinguish between data having, 2 different formats, in a given cell(MS Excel).

2014-08-23 Thread Mark Lawrence

On 23/08/2014 19:56, Ed Joz wrote:

I got an excel sheet having,2 blocks of data in 2 different formats, in any 
given cell.

Lets take cell A1 for example, 1st block has font = Arial, character size =10 
2nd block has font = Times New Roman, character size = 16 OR **no data**

sample: "abcd123

PQRS456"

A python code need to be developed. It should check every cell, and print the data 
whose, font = Times New Roman & character size = 16 .If the cell is not having 
any data in that format, '0' should be printed.The data can be printed into a 
notepad.

Please suggest a sample python code.



Start here http://www.python-excel.org/

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick
 wrote:

>On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head
> wrote:
>> I am trying to do this example:
>> http://openbookproject.net/pybiblio/practice/wilson/loan.php
>> The instructions warn that floating point math can get messy so I
>> cheated a little bit to get me going.
>>
>> I made my program work by using numbers that wouldn't get messy.
>> Instead of using 6% interest I used 10 and instead of using 12 months,
>> I used 10.
>>
>> I managed to get it working and formatted just like they wanted it,
>> but now I want to try to use any numbers.  It has been hard to figure
>> out which method to use.
>>
>You need to learn about string formatting.  Here is a good link:
>http://mkaz.com/2012/10/10/python-string-format/
>
Thanks.  I will give that a try.

>> Here is the working program.
>>
>> import sys
>> count = 0
>> payment = 0
>> borrowed = 100
>> rate = 10
>> term = 10
>> interest=borrowed*rate*.01 #(*1)
>> balance = borrowed + interest
>> print ("Loan calculator")
>> print ("")
>> print ("Amount borrowed: ", borrowed)
>> print ("Interest rate: ", rate)
>> print ("Term: (months)", term)
>> print ("")
>> print ("Amount borrowed:" , borrowed)
>> print ("Total interest paid:" , interest)
>> print ("")
>> print ("")
>> print ("Amount  Remaining")
>> print ("Pymt#PaidBalance")
>> print ("-   --   --")
>> while count <=term:
>>
>>
>> print (repr(count).rjust(3), repr(payment).rjust(13),
>> repr(balance).rjust(14))
>>
>>
>I don't understand why you are using repr(..)  It is not necessary.
>
Would you please change the line to something you feel that is more
appropriate?  That was the first command I stumbled on that I could
use to get the column spacing correctly.
I have contacted my local library to get a couple of books on Python,
but at the moment all I have is the web.

Funny, I though using the web would be better than a book.  I don't
think so anymore.  Using the web, it is hard to find square one
tutorial text.


>> payment = (borrowed + interest)/term
>> balance = balance - payment
>> count = count + 1
>>
>> What should I use to make the formatting come out correctly when the
>> program prints "payment" and "balance" using decimal format?
>>
>> If you change the "rate" from 10 to 6 and the "term" from 10 to 12,
>> the screen gets very messy.
>>
>> Anyone care to suggest what method to use to fix the decimal format?
>> --
>> https://mail.python.org/mailman/listinfo/python-list

I would rather just use Usenet for the moment.  Until the group gets
tired of nursing the rookie.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python vs C++

2014-08-23 Thread Terry Reedy

On 8/23/2014 8:38 AM, Rustom Mody wrote:


WYSIWYG editors allow that -- can make a huge difference to beginners
who find music hard to read.

Here's an example I typed out in the wysiwig editor nted
https://vimeo.com/16894001 ¹


"Awww, snap!
This video can’t be played with your current setup"

How informative. At least we try to do better with Python exception 
messages.


--
Terry Jan Reedy


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


Python code to distinguish between data having, 2 different formats, in a given cell(MS Excel).

2014-08-23 Thread Ed Joz
I got an excel sheet having,2 blocks of data in 2 different formats, in any 
given cell.

Lets take cell A1 for example, 1st block has font = Arial, character size =10 
2nd block has font = Times New Roman, character size = 16 OR **no data**

sample: "abcd123

PQRS456"

A python code need to be developed. It should check every cell, and print the 
data whose, font = Times New Roman & character size = 16 .If the cell is not 
having any data in that format, '0' should be printed.The data can be printed 
into a notepad.

Please suggest a sample python code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with decimals

2014-08-23 Thread Joel Goldstick
On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head
 wrote:
> I am trying to do this example:
> http://openbookproject.net/pybiblio/practice/wilson/loan.php
> The instructions warn that floating point math can get messy so I
> cheated a little bit to get me going.
>
> I made my program work by using numbers that wouldn't get messy.
> Instead of using 6% interest I used 10 and instead of using 12 months,
> I used 10.
>
> I managed to get it working and formatted just like they wanted it,
> but now I want to try to use any numbers.  It has been hard to figure
> out which method to use.
>
You need to learn about string formatting.  Here is a good link:
http://mkaz.com/2012/10/10/python-string-format/

> Here is the working program.
>
> import sys
> count = 0
> payment = 0
> borrowed = 100
> rate = 10
> term = 10
> interest=borrowed*rate*.01 #(*1)
> balance = borrowed + interest
> print ("Loan calculator")
> print ("")
> print ("Amount borrowed: ", borrowed)
> print ("Interest rate: ", rate)
> print ("Term: (months)", term)
> print ("")
> print ("Amount borrowed:" , borrowed)
> print ("Total interest paid:" , interest)
> print ("")
> print ("")
> print ("Amount  Remaining")
> print ("Pymt#PaidBalance")
> print ("-   --   --")
> while count <=term:
>
>
> print (repr(count).rjust(3), repr(payment).rjust(13),
> repr(balance).rjust(14))
>
>
I don't understand why you are using repr(..)  It is not necessary.

> payment = (borrowed + interest)/term
> balance = balance - payment
> count = count + 1
>
> What should I use to make the formatting come out correctly when the
> program prints "payment" and "balance" using decimal format?
>
> If you change the "rate" from 10 to 6 and the "term" from 10 to 12,
> the screen gets very messy.
>
> Anyone care to suggest what method to use to fix the decimal format?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Working with decimals

2014-08-23 Thread Seymore4Head
I am trying to do this example:
http://openbookproject.net/pybiblio/practice/wilson/loan.php
The instructions warn that floating point math can get messy so I
cheated a little bit to get me going.

I made my program work by using numbers that wouldn't get messy.
Instead of using 6% interest I used 10 and instead of using 12 months,
I used 10.

I managed to get it working and formatted just like they wanted it,
but now I want to try to use any numbers.  It has been hard to figure
out which method to use.

Here is the working program.

import sys
count = 0
payment = 0
borrowed = 100
rate = 10
term = 10
interest=borrowed*rate*.01 #(*1)
balance = borrowed + interest
print ("Loan calculator")
print ("")
print ("Amount borrowed: ", borrowed)
print ("Interest rate: ", rate)
print ("Term: (months)", term)
print ("")
print ("Amount borrowed:" , borrowed)
print ("Total interest paid:" , interest)
print ("")
print ("")
print ("Amount  Remaining")
print ("Pymt#PaidBalance")
print ("-   --   --")
while count <=term:


print (repr(count).rjust(3), repr(payment).rjust(13),
repr(balance).rjust(14))


payment = (borrowed + interest)/term
balance = balance - payment
count = count + 1

What should I use to make the formatting come out correctly when the
program prints "payment" and "balance" using decimal format?

If you change the "rate" from 10 to 6 and the "term" from 10 to 12,
the screen gets very messy.

Anyone care to suggest what method to use to fix the decimal format?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why can not initialize the class?

2014-08-23 Thread CHIN Dihedral
On Saturday, August 23, 2014 7:29:44 AM UTC+8, luofeiyu wrote:
> One final version:
> 
> 
> 
> class Contact(object):
> 
>  def __init__(self, email="haha@haha"):
> 
>  self.email = email
> 
>  def _get_email(self):
> 
>  return self._the_secret_private_email
> 
>  def _set_email(self, value):
> 
>  self.self._the_secret_private_email = value
> 
>  email = property(_get_email, _set_email)
> 
> 
> 
> contact = Contact()
> 
> print(contact.email)
> 
> 
> 
> There is a little mistake here. It is
> 
> 
> 
> self._the_secret_private_email = value
> 
> 
> 
> not
> 
> 
> 
> self.self._the_secret_private_email = value
> 
> 
> 
> think for your demo .The value in `def _set_email(self, value):` is the value 
> of self.email .

Well, an object in python can add
properties in the run-time to evolve
steadily and stealthly.

Those unnessary set-get-C++ methods
are not very important in PYTHON.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global indent [levity]

2014-08-23 Thread Peter Pearson
On Sat, 23 Aug 2014 19:08:10 +1000, Steven D'Aprano wrote:
> Marko Rauhamaa wrote:
>> Rob Gaddi :
>> 
>>> Emacs and vim both have huge learning curves
>> 
>> Really now?
>> 
>> When you start emacs, it advises you to start the builtin tutorial.
>
> You need a tutorial for a text editor???

Did you ever watch a bar scene in a cowboy western, and suddenly
there's a loud noise, and a shout in a growly voice, and you just
know that a brawl is about to break out?

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python vs C++

2014-08-23 Thread Marko Rauhamaa
mm0fmf :

> On 22/08/2014 18:16, Marko Rauhamaa wrote:
>> SCons gives you the power of Python. Don't use that
>> power except in utmost need.
>
> Ah, you've seen our build system at work!

Where I've used SCons, I've striven to make the SConscript files obvious
to a casual visitor, who might not even know Python. Adding one more
file in the right spot should be possible just from the looks of the
SConscript file.

A SConscript file should *not* involve programming, even if it means
some redundancy. Don't create libraries. Don't create your own rules.
Keep it simple, keep it plain.

A colleague had to deal with a different SCons setup that had reached
self-awareness. It knew what needed to be built without specific
instructions before you, the developer, knew it yourself. The developers
no longer had any idea how it worked nor did they dream of touching the
code. Not a good place to be.


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


Re: Python vs C++

2014-08-23 Thread mm0fmf

On 22/08/2014 18:16, Marko Rauhamaa wrote:

SCons gives you the power of Python. Don't use that
power except in utmost need.


Ah, you've seen our build system at work!

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


ANN: binario - simple work with binary files

2014-08-23 Thread bwatas
binario is the Python package that lets an application read/write primitive 
data types from an underlying input/output file as binary data.

Package on PyPI: https://pypi.python.org/pypi/binario
Package on GitHub: https://github.com/asaskevich/binario
Docs: http://binarios-docs.readthedocs.org/en/latest/

Package still in Alpha, and I need some help with testing, new features and 
docs :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global indent

2014-08-23 Thread Christian Gollwitzer

Am 23.08.14 16:19, schrieb Joshua Landau:

(Since this is already an editor war...)

On 23 August 2014 10:41, Christian Gollwitzer  wrote:

Sometimes I impress my colleagues with what they call "magic", i.e. creating
special repeated lists of numbers by a few keystrokes in gvim, and that has
triggered the request from them to learn a bit of (g)vim.


I have yet to be truly impressed by Vim, in that Sublime Text with a
few extensions seems to do the same things just as easily. I find that
Vim and Emacs users consistently underrate the powers of these
editors, presumably because they've never put nearly as much effort
into them as they have into their Vim or Emacs.


I never looked into Sublime, because it costs money. But no doubt it is 
a powerful editor, judging from comments of other people.




For example, to make a numbered list in (my) Sublime Text (fully
custom shortcuts ahead):

Alt-1 Alt-0 Alt-0   to repeat the next command 100 times


> [ ... some keystrokes ...]


Ctrl-Shift-qto repeat macro

Compare with Vim:
http://stackoverflow.com/questions/4224410/macro-for-making-numbered-lists-in-vim



I'd actually do this in gvim to put numbers at each line:

- Select text (by mouse, or v + cursor movements)
- ! awk '{print NR ". " $0}'

Yes, it is cheating, it pipes the selected text through an external 
tool. But why should I do the tedious exercise of constructing an editor 
macro, when an external tool like awk can do the same so much easier?


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


Re: Global indent

2014-08-23 Thread Christian Gollwitzer

Hi Steven,

I agree with all you said.

Am 23.08.14 16:56, schrieb Steven D'Aprano:

Christian Gollwitzer wrote:

There are ways to put these editors into Beginner's mode, for vim there
is "evim", and for sure emacs has something similar, where the editor
behaves more like you expect. In evim, this means you can't go to
command mode, and you need to use the menus and toolbars to save/load
text. But if you do that, you also loose the functionality that comes
from the command mode - it's actually better to recommend Notepad++ or
kate.


I'm especially annoyed and/or amused by the tendency of many people to
assume that there are only three editors: Emacs, Vim (one of which is used
by all right-thinking people, the other being sent by the Devil to tempt us
from righteousness) and Notepad (which is used only by the most primitive,
deprived savages who are barely capable of bashing out "Hello World" using
one finger).


Just in case that was misleading: Notepad++ is a different editor than 
Notepad:


http://notepad-plus-plus.org/

This one I actually recommend to people on Windows, who ask me, which 
editor should they use.


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


Re: Global indent

2014-08-23 Thread Seymore4Head
On Fri, 22 Aug 2014 14:19:29 -0400, Seymore4Head
 wrote:

>Is there a way to indent everything again?
>
>Say I have a while statement with several lines of code and I want to
>add a while outside that.  That means indenting everything.  Is there
>a global way to do that?

I did two things.  I decided to skip trying a second level of while
loops for the moment.

I also took a block of text and highlighted it and then pushed tab. It
worked.

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


Re: Global indent

2014-08-23 Thread Steven D'Aprano
Christian Gollwitzer wrote:

> Am 23.08.14 11:08, schrieb Steven D'Aprano:
>> This is the moment that I decide to give up on Emacs and take up
>> something trivial in comparison, like being a Soyuz pilot, если вы
>> знаете, что я имею в виду.
> 
> Well done, Steve! This is the exact reason that I do not recommend gvim
> to anybody, who asks me an editor question, though I use it myself for
> practically any text editing task.  (I'm pretty sure you did that C-f
> ... thing on purpose to make your point clear. and that you actually
> understand it was meant to represent pressing Ctrl-key).

Of course I did, but only because I've been a Linux user and programmer for
about 15 years now. Except for Emacs, the rest of the world says Ctrl-F (or
Command-F if you have a Mac), and use it to mean Find. Emacs is a universe
of its own, but you can hardly be a Linux programmer without coming across
Emacs terminology enough to at least recognise it.


> There are ways to put these editors into Beginner's mode, for vim there
> is "evim", and for sure emacs has something similar, where the editor
> behaves more like you expect. In evim, this means you can't go to
> command mode, and you need to use the menus and toolbars to save/load
> text. But if you do that, you also loose the functionality that comes
> from the command mode - it's actually better to recommend Notepad++ or
> kate.

Despite my comments, I don't actually have any objection to people who
choose to use Emacs, or Vim, or edit their text files by poking the hard
drive platter with a magnetised needle if they prefer :-) But I do think
it's silly of them to claim that Emacs has no learning curve, or to fail to
recognise how unfamiliar and different the UIs are compared to nearly
everything else a computer user is likely to be familiar with in 2014.

I'm especially annoyed and/or amused by the tendency of many people to
assume that there are only three editors: Emacs, Vim (one of which is used
by all right-thinking people, the other being sent by the Devil to tempt us
from righteousness) and Notepad (which is used only by the most primitive,
deprived savages who are barely capable of bashing out "Hello World" using
one finger). Besides, ed is the one true editor *wink*

My own feeling is that Emacs and/or Vim very likely are extraordinarily
powerful, and for those who want to take the time and effort to become
proficient they can probably solve certain editing tasks more quickly than
I can. But that's okay: I suspect that they're optimizing for the wrong
things, or at least things for which I personally have no interest in
optimizing: while they can probably replace the third letter of every
second word in all sentences beginning with W ten times faster than I can,
that's hardly a bottleneck in my world. I've watched touch-typing Vim
users, and they can pound the keys much faster than me, but that seems to
mean that they just make mistakes faster than me. (Possibly unfair, since
everyone probably loses accuracy when being watched. But still, it's the
only data I have.)

When I'm programming, actual fingers on keys is just a small proportion of
the time spent. Most of my time is reading, thinking and planning, with
typing and editing a distant fourth, and I not only don't mind moving off
the keyboard onto the mouse, but actually think that's a good thing to
shift my hands off the keyboard and use a different set of muscles. So I'm
not especially receptive to arguments that Vim or Emacs will make me more
productive.

But, to each their own.



-- 
Steven

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


Re: Global indent

2014-08-23 Thread Rustom Mody
On Saturday, August 23, 2014 2:38:10 PM UTC+5:30, Steven D'Aprano wrote:
> Marko Rauhamaa wrote:

> > Rob Gaddi :
> >> Emacs and vim both have huge learning curves
> > Really now?
> > When you start emacs, it advises you to start the builtin tutorial.

> You need a tutorial for a text editor???

> If that's supposed to prove how easy Emacs is, you have failed miserably.
> Any application which requires a tutorial should consider it a UI failure.
> Ideally applications should be "intuitive" in the sense that all features
> should be self-explanatory, obvious, and easily discovered. Of course, the
> more complex the application, the less this is likely to be true, but every
> feature that requires explanation is a feature that is begging for
> improvement.

> > That's how I learned it in the 1980's and didn't experience any learning
> > curve.

> No learning curve at all? That means one of two things:

> - either you *instantly* intuited every single Emacs feature the moment you
> started the application; or

> - Emacs has no features at all.

> I'm pretty sure neither of those is the case :-)

> > Nowadays, emacs has a GUI that makes you productive immediately without
> > any keyboard commands. I have seen complete newbies adopt emacs without
> > any kind of duress or hardship.

> I just started up emacs, and got a GUI window with an abstract picture of a
> gnu and a bunch of instructions which I didn't get a chance to read. I
> clicked on the text, and the instructions disappeared. I don't know how to
> get them back. They were replaced with what looks like a blank page ready
> to type into, except it starts with this ominous warning:

> ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
> ;; If you want to create a file, visit that file with C-x C-f,
> ;; then enter the text in that file's own buffer.

> Why would I be writing notes I don't want to save? If I did, wouldn't I, you
> know, just *not save them* instead of write them in a special buffer
> (whatever that is!)?

> Lisp evaluation? I don't have any speech impediments, thank you very much.

> Okay, so let's try creating a file, using those instructions. I dutifully
> type C-x C-f and, apart from "C-x C-f" appearing on the screen, nothing
> happens. I wait a while in case it's just slow.

> Ah, silly me, I need to *enter* the command to make it happen. So I press
> Enter. Nothing happens except the cursor moves down a line.

> Perhaps Emacs has frozen? The blinking cursor is still blinking, so that's
> unlikely.

> Okay, let's click the blank page icon, the universal symbol for creating a
> new, blank document. That at least is recognisable.

> Well, that's just bizarre. I expected a new document. Instead, I got a
> message in the status bar at the bottom of the page, saying:

> Find file: /home/steve/

> and the blinking cursor. I don't want to find a file, and if I did I would
> use my computer's Find or Search application, not a text editor. So still
> no new document I can type into.

> When all else fails, use the menus. So I try the File menu. It's a bit
> disconcerting that, alone of all the applications I've used on eight
> different platforms (Windows 95, 98, XP, Classic Mac, Mac OS X, Linux with
> Gnome, KDE and Xfce window managers), the mouse pointer points the other
> way when over a menu, but hey, I'm a sophisticated user and I refuse to be
> put off by such a minor, albeit gratuitous, difference. But there is no New
> Document command, and I am stymied again.

> I shall not be defeated by a mere text editor. I click the New Document icon
> again, hoping that what failed last time will succeed this time. But at
> least I am not entirely insane, for although I did not get a new document,
> at least something different occurred: an error message appeared in the
> status bar:

> Command attempted to use minibuffer while in minibuffer

> This is the moment that I decide to give up on Emacs and take up something
> trivial in comparison, like being a Soyuz pilot, если вы знаете, что я имею
> в виду.

emacs = Editor for Middle Aged Computer Scientists - Generally Not Used

vi = a program with two modes -- one in which it beeps and the other in
which it corrupts your file
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global indent

2014-08-23 Thread Gene Heskett
On Saturday 23 August 2014 06:17:24 alister did opine
And Gene did reply:
> On Sat, 23 Aug 2014 18:19:21 +1000, Steven D'Aprano wrote:
> > Rob Gaddi wrote:
> >> Emacs and vim both have huge learning curves that I've decided
> >> aren't worth climbing.
> > 
> > In my opinion, they are designed for people willing and able to
> > commit to memory dozens, even hundreds, of obscure key sequences to
> > get the simplest thing done. They are not designed for easy
> > exploration of the application: you either know the command that you
> > want, or you're stuck.
> > 
> > Besides, the standard text editor is ed:
> > 
> > http://www.gnu.org/fun/jokes/ed-msg.html
> > 
> >> Notepad++ is an excellent GUI text editor for Windows.
> >> Geany is nearly as good, and runs on anything.
> > 
> > I have never used Notepad++, but I can give Geany good reviews. It's
> > nearly as good as kate in KDE 3, and much better than kate in KDE 4.
> 
> I'll give Geany another thumbs up

I would too, but for the code carving I do, gedit has syntax highlighters 
for calling attention to GCode formatting mistakes, Geany doesn't.  It 
does look like a capable editor, but it just doesn't fit my instant needs.

> it is quite well featured but still light weight (i tend to do my
> personal work on a netbook so I don't have much in the way of
> resources)
> 
> for the original problem Shift & Cursor UP/Down to highlight the block
> then Ctrl-I to indent or Ctrl-u to unindent.


Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python vs C++

2014-08-23 Thread Rustom Mody
On Saturday, August 23, 2014 7:32:12 PM UTC+5:30, Ian wrote:
> On Sat, Aug 23, 2014 at 6:38 AM, Rustom Mody  wrote:
> > Here is an example (not identical but analogous to) where markup+compile is
> > distinctly weaker than wysiwyg:
> > You can use lilypond to type music and the use a midi player to play it
> > But lilypond does not allow playing and seeing-in-realtime
> > WYSIWYG editors allow that -- can make a huge difference to beginners
> > who find music hard to read.

> I don't know how fast lilypond is, but perhaps one could write an
> editor that wraps lilypond and invokes it in realtime to show the
> output in an adjacent panel, perhaps with a brief delay when the
> user stops typing.

Yes.
Wordperfect was one of the best wysiwyg editors Ive used.
One could use it in normal (1-screen) mode
Or one could split the screen and see the formattings in the lower window
along withe the formatted in the upper.

Which is to say I believe weve not the heard the last of finding the 
best mix between WYSIWYG and coded-text+compile

This the same as what you are saying because if one
writes the editor to wrap lilypond and show in another window
the next step is to allow editing in either windows and have the app
keep them in sync
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python vs C++

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 12:02 AM, Ian Kelly  wrote:
> I don't know how fast lilypond is, but perhaps one could write an editor
> that wraps lilypond and invokes it in realtime to show the output in an
> adjacent panel, perhaps with a brief delay when the user stops typing.

You theoretically could, but it'd be a bit awkward in places. It's not
hard for a small textual change to result in a large visual change (eg
if you use relative notes and add/remove an octave shift - it'll shift
every subsequent note in the staff, which might mean more/less ledger
lines needed, which will affect how much vertical space the staff
needs, which will affect pagination...), so it'd often make for rather
nasty flicker. Better to keep it explicit.

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


Re: Global indent

2014-08-23 Thread Joshua Landau
(Since this is already an editor war...)

On 23 August 2014 10:41, Christian Gollwitzer  wrote:
> Sometimes I impress my colleagues with what they call "magic", i.e. creating
> special repeated lists of numbers by a few keystrokes in gvim, and that has
> triggered the request from them to learn a bit of (g)vim.

I have yet to be truly impressed by Vim, in that Sublime Text with a
few extensions seems to do the same things just as easily. I find that
Vim and Emacs users consistently underrate the powers of these
editors, presumably because they've never put nearly as much effort
into them as they have into their Vim or Emacs.

For example, to make a numbered list in (my) Sublime Text (fully
custom shortcuts ahead):

Alt-1 Alt-0 Alt-0   to repeat the next command 100 times
Enter   to insert 100 new lines, so 101 in total
Ctrl-A  to select all text (can be done more fancily, but
keep this simple for now)
Ctrl-l  to select lines (creates multiple selections),
ignoring the blank end of selection
$:  to write some text
Ctrl-Shift-Home to select to beginning of line
Ctrl-e  to replace $ with consecutive numbers (also
supports using Python's {} with all of its formatting options)

With an increment function and macros:

1:  to write some text
Ctrl-q  to start macro recording
Ctrl-d  to duplicate line (and select it)
Leftto go to start of selection
INCREMENT   to increment number (emulated by evaluating
"1+number" with Python [1, +, Ctrl-left, Shift-Home, Ctrl-Shift-e])
Ctrl-q  to finish macro recording
Alt-1 Alt-0 Alt-0   to repeat the next command 100 times
Ctrl-Shift-qto repeat macro

Compare with Vim:
http://stackoverflow.com/questions/4224410/macro-for-making-numbered-lists-in-vim
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python vs C++

2014-08-23 Thread Ian Kelly
On Sat, Aug 23, 2014 at 6:38 AM, Rustom Mody  wrote:
> Here is an example (not identical but analogous to) where markup+compile
is
> distinctly weaker than wysiwyg:
>
> You can use lilypond to type music and the use a midi player to play it
> But lilypond does not allow playing and seeing-in-realtime
>
> WYSIWYG editors allow that -- can make a huge difference to beginners
> who find music hard to read.

I don't know how fast lilypond is, but perhaps one could write an editor
that wraps lilypond and invokes it in realtime to show the output in an
adjacent panel, perhaps with a brief delay when the user stops typing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple question

2014-08-23 Thread ElChino

 wrote:


Can some one explain why this happens:
True, False = False, True
print True, False
False True


I assume the value of True and False can be falsified. Like the 'None'
object can be. So swapping their values and printing them is similar to:
 a = 0
 b = 1
 a, b = b, a
 print a, b

Except that True/False are initialised built-ins.


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


Re: Simple question

2014-08-23 Thread Peter Otten
explodeandr...@gmail.com wrote:

> Can some one explain why this happens:
> True, False = False, True
> print True, False
> False True

You are using Python 2 where True/False are names that can be rebound. This 
is for backwards compatibility as Python didn't always have booleans and 
people made their own with

True = 1
False = 0

or similar.

In Python 3 True and False are keywords:

>>> True = False
  File "", line 1
SyntaxError: can't assign to keyword


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


Re: Simple question

2014-08-23 Thread Chris Angelico
On Sat, Aug 23, 2014 at 11:10 PM,   wrote:
> Can some one explain why this happens:
> True, False = False, True
> print True, False
> False True

Well, the first line changes the meanings of the names "True" and
"False", but doesn't change the things they point to. Those things
describe themselves the same way. Here's another thing you can do that
will look the same:

a, b = False, True
print a, b
False True

Fortunately, newer versions of Python don't let you reassign True and False.

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


Simple question

2014-08-23 Thread explodeandroid
Can some one explain why this happens:
True, False = False, True
print True, False
False True
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python vs C++

2014-08-23 Thread Chris Angelico
On Sat, Aug 23, 2014 at 10:38 PM, Rustom Mody  wrote:
> Here is an example (not identical but analogous to) where markup+compile is
> distinctly weaker than wysiwyg:
>
> You can use lilypond to type music and the use a midi player to play it
> But lilypond does not allow playing and seeing-in-realtime
>
> WYSIWYG editors allow that -- can make a huge difference to beginners
> who find music hard to read.

I don't buy that it's weaker. In fact, I'd say this proves that markup
is distinctly better - just a little harder to do "Hello, world" in.

At best, the simple GUI makes it easier to do something
straight-forward, and then basically lets you drop to the more
complicated form. At worst, it makes it easier to do the very simple,
and nearly impossible to do the more complicated.

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


Re: Python vs C++

2014-08-23 Thread Rustom Mody
On Saturday, August 23, 2014 3:19:37 AM UTC+5:30, Chris Angelico wrote:
> On Sat, Aug 23, 2014 at 7:38 AM, Michael Torrie  wrote:
> > On 08/22/2014 02:06 PM, Marko Rauhamaa wrote:
> >> I tend to think the opposite: C++ barely has a niche left. I definitely
> >> wouldn't want to use C++ very far from its (very narrow) sweet spot.
> > I agree that it's niche is narrowing.  But it's still pretty wide and
> > widely used.  Many adobe products are C++, for example.  OpenOffice and
> > LibreOffice is C++.  You could argue that's because they are old
> > projects and were started in C++. But honestly if you were
> > reimplementing OpenOffice today what would you choose?  Python would be
> > appropriate for certain aspects of OO, such as parts of the UI, macros,
> > filters, etc. ...

> Frankly, I wouldn't write OO in anything, because I think the entire
> concept of a WYSIWYG editor is flawed. Much better to use markup and
> compile it. But if I were to write something like that, probably what
> I'd do would be to write a GUI widget in whatever lowish-level
> language is appropriate (probably C, with most GUI toolkits), and then
> use a high level language (probably Python or Pike) to build the
> application. I'm not familiar with all of OO/LO's components, but I
> believe that model will probably work for all of them (the document
> editor, obviously; the presentation editor might be done a bit
> differently, but it'd still work this way; the spreadsheet quite
> possibly doesn't even need a custom widget; etc).

Here is an example (not identical but analogous to) where markup+compile is 
distinctly weaker than wysiwyg:

You can use lilypond to type music and the use a midi player to play it
But lilypond does not allow playing and seeing-in-realtime

WYSIWYG editors allow that -- can make a huge difference to beginners
who find music hard to read.

Here's an example I typed out in the wysiwig editor nted
https://vimeo.com/16894001 ¹

Many more examples like this on the musescore site eg
http://musescore.com/user/19710/scores/261621

I believe that in a like way an app like Word that has a full (Turing complete)
language -- VBA -- is more powerful than an offline tool like lilypond

¹ No I dont enjoy clickety-click when a typewriter would work better.
I know a musician friend who has worked out the best combo: type in
with a cheap midi connected keyboard, then use Sibelius.
I believe its only a question of time before musescore like wysiwyg editors
will be able to do that
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global indent

2014-08-23 Thread mm0fmf

On 22/08/2014 20:46, Seymore4Head wrote:

http://gvim.en.softonic.com/   Has a snazzy look, but I think it is not
compatible with Windows so it looks like I might have to try Emacs.


Others will disagree but I find keeping Windows and *nix separate helps 
me a lot.


So I'll use emacs on Linux for C++/Python/Tcl and VisualStudio / 
NotePad++ on Windows. Using Windows style editors on Windows just seems 
to be easier, whenever I try emacs on Windows it doesn't feel right and 
I start thinking more about the editor and less about what is being edited.


You may be comfortable with emacs on Windows but part of my job is 
producing C++ and C# code for Windows so VisualStudio is the order of 
the day and so using NotePad++ for Python works for me.


YMMV

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


Re: Global indent

2014-08-23 Thread alister
On Sat, 23 Aug 2014 18:19:21 +1000, Steven D'Aprano wrote:

> Rob Gaddi wrote:
> 
>> Emacs and vim both have huge learning curves that I've decided aren't
>> worth climbing.
> 
> In my opinion, they are designed for people willing and able to commit
> to memory dozens, even hundreds, of obscure key sequences to get the
> simplest thing done. They are not designed for easy exploration of the
> application: you either know the command that you want, or you're stuck.
> 
> Besides, the standard text editor is ed:
> 
> http://www.gnu.org/fun/jokes/ed-msg.html
> 
> 
>> Notepad++ is an excellent GUI text editor for Windows.
>> Geany is nearly as good, and runs on anything.
> 
> I have never used Notepad++, but I can give Geany good reviews. It's
> nearly as good as kate in KDE 3, and much better than kate in KDE 4.

I'll give Geany another thumbs up

it is quite well featured but still light weight (i tend to do my 
personal work on a netbook so I don't have much in the way of resources)

for the original problem Shift & Cursor UP/Down to highlight the block 
then Ctrl-I to indent or Ctrl-u to unindent.


-- 
Is it weird in here, or is it just me?
-- Steven Wright
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global indent

2014-08-23 Thread Christian Gollwitzer

Am 23.08.14 11:08, schrieb Steven D'Aprano:

I just started up emacs, and got a GUI window with an abstract picture of a
gnu and a bunch of instructions which I didn't get a chance to read. I
clicked on the text, and the instructions disappeared. I don't know how to
get them back. They were replaced with what looks like a blank page ready
to type into, except it starts with this ominous warning:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.


> [...] (lots of frustrating user experience deleted)

>

This is the moment that I decide to give up on Emacs and take up something
trivial in comparison, like being a Soyuz pilot, если вы знаете, что я имею
в виду.


Well done, Steve! This is the exact reason that I do not recommend gvim 
to anybody, who asks me an editor question, though I use it myself for 
practically any text editing task.  (I'm pretty sure you did that C-f 
... thing on purpose to make your point clear. and that you actually 
understand it was meant to represent pressing Ctrl-key).


There are ways to put these editors into Beginner's mode, for vim there 
is "evim", and for sure emacs has something similar, where the editor 
behaves more like you expect. In evim, this means you can't go to 
command mode, and you need to use the menus and toolbars to save/load 
text. But if you do that, you also loose the functionality that comes 
from the command mode - it's actually better to recommend Notepad++ or kate.


Sometimes I impress my colleagues with what they call "magic", i.e. 
creating special repeated lists of numbers by a few keystrokes in gvim, 
and that has triggered the request from them to learn a bit of (g)vim. 
But when they asked me, which editor they should use, I pointed them to 
kate.


Christian


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


Re: Global indent

2014-08-23 Thread Steven D'Aprano
Dan Stromberg wrote:

> The first time I saw vi, I hated it.  I thought "Why would anyone
> actually choose such a terrible editor?"
> 
> But then I was forced to use vi for a while,  and I'm glad I was.  I
> choose it over other editors now.  vi/vim give you a pretty much
> orthogonal set of verbs and nouns in an editing language.

Sorry, but I have no idea what you mean by "orthogonal set of verbs and
nouns in an editing language". Can you explain?


> When I have to use editors that make you arrow-key around or click
> with a mouse, I feel like it's painfully slow - especially if I need
> to do the same thing 5 times in a row.  Sure, some editors let you
> define macros - vi/vim do that too. But AFAIK, only vi/vim allow you
> to define a repeatable action without forethought.

I find that between find/replace and Block Selection editing, I can't really
say I've missed either the lack of editing macros or these orthogonal
verbs, whatever they are. Occasionally I move a large editing job into
Python, but I wouldn't want to learn a separate language for that.



-- 
Steven

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


Re: Global indent

2014-08-23 Thread Marko Rauhamaa
Steven D'Aprano :

> Marko Rauhamaa wrote:
>> When you start emacs, it advises you to start the builtin tutorial.
>
> You need a tutorial for a text editor???
>
> If that's supposed to prove how easy Emacs is, you have failed
> miserably.

You see, I tend to read even the assembly instructions of Ikea furniture
and the user manual of a dryer.

More frustrating than having to read a well-thought-out manual is

 * not being able to accomplish something

 * not having any manual

For example, I never "got" Eclipse despite having to use it for two
years.

>> That's how I learned it in the 1980's and didn't experience any
>> learning curve.
>
> No learning curve at all? That means one of two things:
>
> - either you *instantly* intuited every single Emacs feature the
> moment you started the application; or

No, I just worked through the tutorial. It was fascinating and only took
a couple of hours IIRC. That's the way learned almost everything
(including Python).

> I just started up emacs, [...]
> Well, that's just bizarre.

I'm not making you use emacs, you know.


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


Re: proposed syntax for multiline anony-functions (hopefully?)

2014-08-23 Thread Steven D'Aprano
Travis Griggs wrote:

> I do not like the python lambda. For two reasons.
> 
> One: In a language that sought to be approachable by simple people (i.e.
> non computer science graduates who would use it in addition to their
> scientific/education background), I can’t believe they threw in a 6
> character  phonetic description of a greek character to imply “fragment of
> code expression to be executed in a removed context”. Show a subset of
> keyword.kwlist to a non-comp-sci guy and tell me if when they see the
> ‘lambda’ betwixt the others, they don’t stop and think “huh, one of these
> is not like the others”.

Ha :-)

The reason lambda is called lambda is that a Lisp fan added it, way back in
the early days of Python, and Guido didn't notice until it was added. In
functional programming circles, lambda comes from the lambda calculus, a
branch of pure mathematics.

But I'm not concerned about the name "lambda". It's no more jargon
than "closure", "coroutine", "continuation", "class" [hmmm, what's with all
the C words?] or "comprehension". And besides, now as an English speaker,
you get to feel the tiniest glimpse of what it is like to be a non-English
speaking programmer forced to use these mysterious keywords `if`, `return`,
`while`, `raise` and similar.


> Personally, I don’t think the desire to use lines as statement boundaries
> (something I like a lot) and at the same time to tersely pack multiple
> statements into a deferred code fragment, are reconcilable. And I don’t
> think there’s critical mass desire for them. So this subject will continue
> to resurface regularly. 

Agreed!



-- 
Steven

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


Re: Global indent

2014-08-23 Thread Steven D'Aprano
Marko Rauhamaa wrote:

> Rob Gaddi :
> 
>> Emacs and vim both have huge learning curves
> 
> Really now?
> 
> When you start emacs, it advises you to start the builtin tutorial.

You need a tutorial for a text editor???

If that's supposed to prove how easy Emacs is, you have failed miserably.
Any application which requires a tutorial should consider it a UI failure.
Ideally applications should be "intuitive" in the sense that all features
should be self-explanatory, obvious, and easily discovered. Of course, the
more complex the application, the less this is likely to be true, but every
feature that requires explanation is a feature that is begging for
improvement.


> That's how I learned it in the 1980's and didn't experience any learning
> curve.

No learning curve at all? That means one of two things:

- either you *instantly* intuited every single Emacs feature the moment you
started the application; or

- Emacs has no features at all.

I'm pretty sure neither of those is the case :-)


> Nowadays, emacs has a GUI that makes you productive immediately without
> any keyboard commands. I have seen complete newbies adopt emacs without
> any kind of duress or hardship.

I just started up emacs, and got a GUI window with an abstract picture of a
gnu and a bunch of instructions which I didn't get a chance to read. I
clicked on the text, and the instructions disappeared. I don't know how to
get them back. They were replaced with what looks like a blank page ready
to type into, except it starts with this ominous warning:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

Why would I be writing notes I don't want to save? If I did, wouldn't I, you
know, just *not save them* instead of write them in a special buffer
(whatever that is!)?

Lisp evaluation? I don't have any speech impediments, thank you very much.

Okay, so let's try creating a file, using those instructions. I dutifully
type C-x C-f and, apart from "C-x C-f" appearing on the screen, nothing
happens. I wait a while in case it's just slow.

Ah, silly me, I need to *enter* the command to make it happen. So I press
Enter. Nothing happens except the cursor moves down a line.

Perhaps Emacs has frozen? The blinking cursor is still blinking, so that's
unlikely.

Okay, let's click the blank page icon, the universal symbol for creating a
new, blank document. That at least is recognisable.

Well, that's just bizarre. I expected a new document. Instead, I got a
message in the status bar at the bottom of the page, saying:

Find file: /home/steve/

and the blinking cursor. I don't want to find a file, and if I did I would
use my computer's Find or Search application, not a text editor. So still
no new document I can type into.

When all else fails, use the menus. So I try the File menu. It's a bit
disconcerting that, alone of all the applications I've used on eight
different platforms (Windows 95, 98, XP, Classic Mac, Mac OS X, Linux with
Gnome, KDE and Xfce window managers), the mouse pointer points the other
way when over a menu, but hey, I'm a sophisticated user and I refuse to be
put off by such a minor, albeit gratuitous, difference. But there is no New
Document command, and I am stymied again.

I shall not be defeated by a mere text editor. I click the New Document icon
again, hoping that what failed last time will succeed this time. But at
least I am not entirely insane, for although I did not get a new document,
at least something different occurred: an error message appeared in the
status bar:

Command attempted to use minibuffer while in minibuffer

This is the moment that I decide to give up on Emacs and take up something
trivial in comparison, like being a Soyuz pilot, если вы знаете, что я имею
в виду.



-- 
Steven

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


Re: socket issue with recv()

2014-08-23 Thread Marko Rauhamaa
Arthur Clarck :

> What is happening is that I got some datas from the remote site,
> Something like 'Contacting BH: ...'
> But directly followed by 'remote site is closed.

This works:


#!/usr/bin/env python3

import sys, socket, os

def main():
s = socket.socket()
s.connect(("mail.python.org", 25))
if os.fork() > 0:
s.close()
os.wait()
os._exit(0)
while True:
data = s.recv(50)
sys.stderr.write("{}\n".format(repr(data)))
if not data:
break

if __name__ == "__main__":
main()



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


Re: socket issue with recv()

2014-08-23 Thread Arthur Clarck
I forgot to mention that with this code:

total = '' 
while True: 
   data = s.recv(1024) 
   total += data 
   if (total != ''): 
  print total 
  total = ''
 
Everything is fine.
I am still looping but I get the complete data flow sent by the remote server.
The data flow is not corrupted with extra characters.
But I do not detect the closing of the socket on the remote server.
Why is recv not blocking !!!


Le samedi 23 août 2014 10:23:14 UTC+2, Arthur Clarck a écrit :
> Hello,
> 
> 
> 
> I am starting socket scripting with python.
> 
> I do understand from the doc that a socket is bmocking by default.
> 
> I wrote 2 basics script to verify this behaviour.
> 
> 
> 
> my "tcp_server.py":
> 
> 
> 
> 
> 
> import socket, sys
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
> 
> 
> HOST = '192.168.0.103'
> 
> PORT = 1060
> 
> 
> 
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> 
> s.bind((HOST, PORT))
> 
> while True:
> 
>s.listen(1)
> 
>print 'Listening at', s.getsockname()
> 
>sc, sockname = s.accept()
> 
>print 'We have accepted a connection from', sockname
> 
>print 'Socket connects', sc.getsockname(), 'and', sc.getpeername()
> 
>while True:
> 
>   data = sc.recv(1024)
> 
>   if data:
> 
>  print 'Got from client:', repr(data)
> 
>  data = ''
> 
>   else:
> 
>  #raise EOFError('socket closed')
> 
>  print 'socket closed by remote client'
> 
>  sc.close()
> 
>  sys.exit()
> 
> 
> 
> 
> 
> and my "tcp_client.py"
> 
> 
> 
> import socket, sys, time
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
> 
> 
> HOST = '192.168.0.103'
> 
> PORT = 1060
> 
> 
> 
> s.connect((HOST, PORT))
> 
> print 'Client has been assigned socket name', s.getsockname()
> 
> while True:
> 
>data = raw_input('cmd:')
> 
>if (data == '\x05'):
> 
>   print 'closing socket and exit'
> 
>   s.close()
> 
>   sys.exit()
> 
>s.sendall(data)
> 
> 
> 
> When both are running everything what I type in the client is received by the 
> server.
> 
> When nothing is sent from the client the server is waiting (socket is 
> blocking)
> 
> for next datas.
> 
> If I close the client with Ctrl-E (or a kill) the socket on the server is 
> getting a null value and the server exit.
> 
> So everything is fine. And everything is clear in my mind.
> 
> 
> 
> The problem I have now is the following.
> 
> I have a script to connect to some telecom service.
> 
> The script is forking (parent/child)
> 
> The child is only reading what comes from the remote server.
> 
> Here the problematic code:
> 
> 
> 
> total = ''
> 
> while True:
> 
>data = s.recv(1024)
> 
>total += data
> 
>if (data == ''):
> 
>   print 'remote site is closed'
> 
>   s.close()
> 
>   sys.exit()
> 
> 
> 
> What is happening is that I got some datas from the remote site,
> 
> Something like 'Contacting BH: ...'
> 
> But directly followed by 'remote site is closed.
> 
> And if I remove the 2 lines (s.close;sys.exit) my script is looping
> 
> So it means data=='' 
> 
> This makes no sense at all.
> 
> Why is the socket not waiting for the next datas flow ??
> 
> Why is the socket not blocking ?
> 
> 
> 
> 
> 
> With Perl I just have to write:
> 
> 
> 
>   while (sysread($socket,$data,1024)){
> 
>  syswrite(STDOUT,$data)
> 
>   }
> 
> 
> 
> And it works perfectly.
> 
> 
> 
> Any hint about what I missed in Python ?
> 
> 
> 
> kr,
> 
> Arthur.
-- 
https://mail.python.org/mailman/listinfo/python-list


socket issue with recv()

2014-08-23 Thread Arthur Clarck
Hello,

I am starting socket scripting with python.
I do understand from the doc that a socket is bmocking by default.
I wrote 2 basics script to verify this behaviour.

my "tcp_server.py":


import socket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

HOST = '192.168.0.103'
PORT = 1060

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
while True:
   s.listen(1)
   print 'Listening at', s.getsockname()
   sc, sockname = s.accept()
   print 'We have accepted a connection from', sockname
   print 'Socket connects', sc.getsockname(), 'and', sc.getpeername()
   while True:
  data = sc.recv(1024)
  if data:
 print 'Got from client:', repr(data)
 data = ''
  else:
 #raise EOFError('socket closed')
 print 'socket closed by remote client'
 sc.close()
 sys.exit()


and my "tcp_client.py"

import socket, sys, time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

HOST = '192.168.0.103'
PORT = 1060

s.connect((HOST, PORT))
print 'Client has been assigned socket name', s.getsockname()
while True:
   data = raw_input('cmd:')
   if (data == '\x05'):
  print 'closing socket and exit'
  s.close()
  sys.exit()
   s.sendall(data)

When both are running everything what I type in the client is received by the 
server.
When nothing is sent from the client the server is waiting (socket is blocking)
for next datas.
If I close the client with Ctrl-E (or a kill) the socket on the server is 
getting a null value and the server exit.
So everything is fine. And everything is clear in my mind.

The problem I have now is the following.
I have a script to connect to some telecom service.
The script is forking (parent/child)
The child is only reading what comes from the remote server.
Here the problematic code:

total = ''
while True:
   data = s.recv(1024)
   total += data
   if (data == ''):
  print 'remote site is closed'
  s.close()
  sys.exit()

What is happening is that I got some datas from the remote site,
Something like 'Contacting BH: ...'
But directly followed by 'remote site is closed.
And if I remove the 2 lines (s.close;sys.exit) my script is looping
So it means data=='' 
This makes no sense at all.
Why is the socket not waiting for the next datas flow ??
Why is the socket not blocking ?


With Perl I just have to write:

  while (sysread($socket,$data,1024)){
 syswrite(STDOUT,$data)
  }

And it works perfectly.

Any hint about what I missed in Python ?

kr,
Arthur.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global indent

2014-08-23 Thread Steven D'Aprano
Rob Gaddi wrote:

> Emacs and vim both have huge learning curves that I've decided aren't
> worth climbing.  

In my opinion, they are designed for people willing and able to commit to
memory dozens, even hundreds, of obscure key sequences to get the simplest
thing done. They are not designed for easy exploration of the application:
you either know the command that you want, or you're stuck.

Besides, the standard text editor is ed:

http://www.gnu.org/fun/jokes/ed-msg.html


> Notepad++ is an excellent GUI text editor for Windows. 
> Geany is nearly as good, and runs on anything.

I have never used Notepad++, but I can give Geany good reviews. It's nearly
as good as kate in KDE 3, and much better than kate in KDE 4.


-- 
Steven

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


Re: Global indent

2014-08-23 Thread Steven D'Aprano
Seymore4Head wrote:

> Is there a way to indent everything again?
> 
> Say I have a while statement with several lines of code and I want to
> add a while outside that.  That means indenting everything.  Is there
> a global way to do that?

In kwrite, kate, geany, and any other sensible editor, you select the text
you want to indent and press the tab key.

If your editor is not sensible, it may replace the entire block of text with
a single tab. In that case, hit Ctrl-Z, or Undo from the Edit menu, and
your text will be returned. In that case, check the menu commands offered
by your editor, especially the Edit and Tools menu (if it has a Tools
menu). In kwrite, I find Indent and Unindent commands under Tools. In
geany, I find Increase Indent and Decrease Indent under Edit>Commands
submenu.

(In case your editor is not only not sensible, but out-and-out
microcephalic, I suggest you try it on a sample piece of text first, in
case it does not allow you to undo.)



-- 
Steven

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


Re: Python vs C++

2014-08-23 Thread Chris Angelico
On Sat, Aug 23, 2014 at 5:36 PM, Paul Rudin  wrote:
> I'm unconvinced is that e.g. LaTeX is inherently more "expert" that Word
> for simple document preparation. It's mostly a question of familiarity.

I think LaTeX probably is, in the same way that PhotoShop or Gimp is
more expert than a simple paint program, but something like ReST
should be easy for anyone to work with... and it'd require less
familiarity than Word does before you get to call yourself an expert.

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


Re: Why can not initialize the class?

2014-08-23 Thread luofeiyu



You can copy it into vim,and input  :%<  ,the codes  will be changed 
into well formatted.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: proposed syntax for multiline anony-functions (hopefully?)

2014-08-23 Thread Marko Rauhamaa
Dan Stromberg :

> Please don't add multiline lambdas to Python.

Agree.

> Multiline lambdas give rise (in a big way) to the
> computer-language-equivalent of run-on sentences.

Lambdas are perfect in Scheme because they are idiomatic in it. They
carry a visual meaning and flow nicely with the parentheses and the
indentation.

Multiline lambdas would look out of place in Python. Also, they don't
buy you anything functionality-wise or expressivity-wise.

Lambdas are visually absolutely horrible in Java (which doesn't need
them) and C++ (which is in dire need of them).

However, it would appear lambdas are all in the rage among programming
languages, and I could think of far worse fads (XML, shudder). So it may
be that Python will eventually have to give in to multiline lambdas
because of the marketing pressure.


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


Re: Why can not initialize the class?

2014-08-23 Thread luofeiyu
I edit it in the vim in well formatted form,when copied into email ,the 
format changed ,i don't know why.

My email editor is thunderbird, you can try it as i say.

I didn't mean to .


By posting code with an extra indent, you make it imposible to run by 
just cutting and pasting. You should already know that.




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


Re: Python vs C++

2014-08-23 Thread Paul Rudin
Chris Angelico  writes:

> On Sat, Aug 23, 2014 at 3:56 PM, dieter  wrote:
>> Chris Angelico  writes:
>>> Frankly, I wouldn't write OO in anything, because I think the entire
>>> concept of a WYSIWYG editor is flawed.
>>
>> That would limit (so called) office applications to experts only.
>> But the success of these applications relies on the fact, that
>> even a complete novice can immediately use them. For "non-experts"
>> WYSIWYG editors are important.
>
> People say that. But WYSIWYG editors are the primary cause of
> frustrated yelling from the far end of the house, in my experience. I
> think they're an attractive nuisance. They're complicated to get right
> ("pure" WYSIWYG is useless, so you have to balance the visual benefit
> of being close to the result against the utility of seeing some of the
> non-printing information), and non-modular. With a text editor +
> compiler concept (whether the compiler's language is as big and
> complex as LaTeX or as simple as ReST), you can change editors without
> breaking anything. You don't like Libre Office Writer? Tough, there's
> no real alternative if you want to work on LO files.
>

The other problem is that because people are so used to using Word for
all text preparation we end up with Word files being used to carry
content for which plain text is just fine and would be preferable.

The conflation of text editing / word processing / desk top publishing
is problematic on a lot of levels.

I'm unconvinced is that e.g. LaTeX is inherently more "expert" that Word
for simple document preparation. It's mostly a question of familiarity.

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


Re: Python vs C++

2014-08-23 Thread Marko Rauhamaa
Chris Angelico :

> I'm just saying that callbacks are inherently restrictive in a
> language without first-class functions.

You don't have to go that far to have great callback support. C# (and
Delphi) show a great model that I wish C++ had adopted from the
beginning. C++ could have declared that a function pointer contains the
function pointer plus the (optional) this pointer. That would have dealt
with the whole (important) issue.

> So I'm not sure why you have further issue with C++; C's way of doing
> callbacks works fine in C++, and there's not going to be anything
> better.

Well, C++11 brings in the lambda (http://www.cprogramming.com/c++11/c++11-lambda-closures.html>):

   One of the biggest beneficiaries of lambda functions are, no doubt,
   power users of the standard template library algorithms package.
   Previously, using algorithms like for_each was an exercise in
   contortions.


Using void pointers in C++ is like sacrificing to the idols.


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