PyGObject 3.11.2 released

2013-11-18 Thread Simon Feltman
I am pleased to announce version 3.11.2 of the Python bindings for
GObject. This is the second alpha release of the 3.11.x series for GNOME 3.12.

An important change with this release is deprecation messages are
emitted when using positional arguments with overridden initializers.
Positional arguments will continue to be supported for the remainder
of the 3.x series but also updating to use keyword arguments is
compatible with prior releases. Please see the following wiki and bug
report for rational:

 https://wiki.gnome.org/PyGObject/InitializerDeprecations
 https://bugzilla.gnome.org/show_bug.cgi?id=705810

Download

The new release is available from ftp.gnome.org:

 https://download.gnome.org/sources/pygobject/3.11/pygobject-3.11.2.tar.xz
(669K)
 sha256sum: 1c606b1a98e6574218f0aa78e803c18b56c35020fa08bd1fbc3db4b720ec5a13

What’s new since PyGObject 3.11.2
=
- gkt-demo: Change main info/source notebook into a GtkStack
- Add deprecation warnings and cleanup class initializer overrides (#705810)
- Fix dir method for static GParamSpec in Python 3
- Remove overzealous argument checking for callback userdata (#711173)

About PyGObject
===
GObject is a object system used by GTK+, GStreamer and other libraries.

PyGObject provides a convenient wrapper for use in Python programs when
accessing GObject libraries.

Like the GObject library itself PyGObject is licensed under the GNU
LGPL, so is suitable for use in both free software and proprietary
applications. It is already in use in many applications ranging from
small single purpose scripts up to large full featured applications.

PyGObject now dynamically accesses any GObject libraries that uses
GObject Introspection. It replaces the need for separate modules such as
PyGTK, GIO and python-gnome to build a full GNOME 3.0 application. Once
new functionality is added to gobject library it is instantly available
as a Python API without the need for intermediate Python glue.
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] iPOPO 0.5.5

2013-11-18 Thread Thomas Calmant
===
iPOPO 0.5.4
===

iPOPO v0.5.5 has been released !

About iPOPO
===

iPOPO is a service-oriented component model (SOCM) framework for Python, 
inspired from the Java project iPOJO and from the OSGi specification.

What's new in 0.5.5
===

Major change : the iPOPO project is now released under the Apache License 2.0 
(instead of GPLv3).

This version introduces the iPOPO handlers: they allow to create new decorators 
and to add some behavior to components instances.

New features:

Added a context pelix.utilities.use_service(bundle_context, 
service_reference), like the use_ipopo(bundle_context) added in the previous 
release
Added iPOPO handlers
get_*_service_reference*() methods have a default LDAP filter set to None. 
Only the service specification is required, event if set to None.
Added the ConfigurationAdmin service : a white board pattern persistent 
configuration service
Added the FileInstall service : watches for changes in folders

You can take a look at the documentation at https://ipopo.coderxpress.net/

Feel free to send feedback on your experience of Pelix/iPOPO, via the mailing 
lists:

User list : http://groups.google.com/group/ipopo-users
Development list : http://groups.google.com/group/ipopo-dev

Have fun !
Thomas
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


devpi-{server,client}-1.2.1: bug fixes + refinement to test

2013-11-18 Thread holger krekel
devpi-1.2.1: bug fixes and improved test command
==

The devpi-{server,client}-1.2.1 releases bring important
bug fixes and refinements.  See Changelog below.

For getting started with deploying your own pypi server
on a laptop or on  company server and for using the 
devpi workflow tool (optional), see:

http://doc.devpi.net

If you want to upgrade an existing installation, you should 
be able to execute::

$ pip install -U devpi
$ devpi-server --upgrade-state [--serverdir YOUR_SERVER_DIR]

Have fun,

holger krekel

Changelog 1.2.1
--

devpi-server:

- fix an import issue for doc files which were wrongly tied to a newer
  version of a base index. now version auto detection for storing
  doc files only works within a stage.  Thanks Laurent Brack for bringing
  it up and providing the repo.

- fix issue66: api endpoints now also respect --outside-url setting
  so that you can serve devpi from a subpath.  Thanks for Fabian
  Snovna for reporting and analysis.

- fix issue63: skip egg links that go to a directory (this requires
  doing a SVN checkout which devpi-server does not do).  Thanks
  Ken Jung for analyzing the problem.

- fix issue68: don't derive metadata from filename but instead
  look it up in metadata or submitted form.

- fix cache-invalidation when normalized_project_name != real_name
  (e.g. for Django but also many others). addresses issue59.

- add newline to simple list output for better human readability of the
  page (thanks Brandon Maister)

- make xmlrpc calls to pypi's changelog API use requests sessions 
  so that http proxies are respected there as well (fixes issue58).
  thanks to riehlm for identifying the problem and testing the fix.

- internally refactor and consolidate mocking against requests library

- --upgrade-state will upgrade now between major.minor/major.minor+1 changes.

devpi-client:

- fix python -m devpi invocation. Thanks Sebastian Ralph.

- fix issue66: devpi use user/index can now switch between URLs
  if user/index is mounted on a subpath.

- fix issue71: allow pip/setuptools like requirements specs
  with the test subcommand, e.g.  devpi test 'pkg=1.0'.
  Thanks Sebastian Rahlf for the PR.


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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: When to use assert

2013-11-18 Thread Robert Day


On 17/11/13 13:33, Roy Smith wrote:
Every once in a while, I'll get into a situation where something is 
happening that I just can't understand. If a given pice of code is 
being called, there's NO WAY the program should be exhibiting the 
behavior it's exhibiting. But, there's also NO WAY that piece of code 
can't be getting called. So, I stick assert 0 in the code an re-run 
the program to see if I get an AssertionError. If I do, then I know 
the code is being run. If I don't then I know it's not. Either way, I 
know more about what's going on than I did before. Once I know what's 
going on, I remove the assert. 


Are assertions the right thing in that case? I'm becoming more and more 
inclined to the idea that if you want to know whether code is getting 
run, you should put a debug log in, and leave it in. That way it's 
easier to track down the next bug (I don't know about others, but when I 
write buggy code I go all-out and put lots of bugs in rather than just one).


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


UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128)

2013-11-18 Thread Hoàng Tuấn Việt
Hi all,

 

I use Python telnetlib on Windows 7 32 bit. Here is my code:

 


def telnet(self, host, os, username, password):

connection = telnetlib.Telnet(host)

connection.read_until('login: ')

connection.write(username + '\r')

connection.read_until('assword: ')

connection.write(password + '\r')

connection.read_until('', timeout = TIMEOUT)

   return connection

 

I can run the program in Eclipse and telnet successfully to a Windows host.

 

But when I export to .exe file:

 


from distutils.core import setup

import py2exe

 

setup(

options = {

py2exe:{

packages: ['wx.lib.pubsub'],

dll_excludes: [MSVCP90.dll, HID.DLL, w9xpopen.exe],

}

},

console = [{'script': ‘my_program.py'}]

)

 

and run the programe, I encounter this error:

 


UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: 
ordinal not in range(128)

 

at line:

 


connection.write(username + '\r')

 

I have debugged and searched the Internet hard but found no solution yet.

 

I think it is because of ‘\r’.

 

Do you have any idea?

 

Viet

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


pypix

2013-11-18 Thread Ajay Kumar


Hi Guys, i have created a site for Python Tutorials. here is the link 
http://pypix.com/python/get-started-python-web-development/ . I would like to 
have your opinion like what tutorials would you love to see.
Thanks-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128)

2013-11-18 Thread Terry Reedy

On 11/17/2013 11:55 PM, Hoàng Tuấn Việt wrote:

Hi


I use Python telnetlib on Windows 7 32 bit. Here is my code:


To better help us help you, what exact version of Python?
Please post plain text without html.
Please post programs single spaced with just occasional blank lines.

--
Terry Jan Reedy


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


Re: Oh look, another language (ceylon)

2013-11-18 Thread wxjmfauth
character
Satisfied Interfaces: ComparableCharacter, EnumerableCharacter, 
OrdinalOther
A 32-bit Unicode character.
Satisfied Interfaces: Category, CloneableListElement, CollectionElement,
ComparableString, CorrespondenceInteger,Element, IterableElement,Null,
ListCharacter, RangedInteger,String, SummableString


string
Satisfied Interfaces: Category, CloneableListElement, CollectionElement,
ComparableString, CorrespondenceInteger,Element, IterableElement,Null,
ListCharacter, RangedInteger,String, SummableString
A string of characters. Each character in the string is a 32-bit Unicode
character. The internal UTF-16 encoding is hidden from clients.
A string is a Category of its Characters, and of its substrings:


Clean. Far, far away from a unicode handling which may require
18 bytes (!) more to encode a non ascii n-chars string than a
ascii n-chars string.
(With performances following expectedly globally the same logic)

 sys.getsizeof('a')
26
 sys.getsizeof('\U0001d11e')
44


jmf

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


Re: When to use assert

2013-11-18 Thread Oscar Benjamin
On 17 November 2013 13:33, Roy Smith r...@panix.com wrote:

 So, I stick assert 0 in the code an re-run the program to see if I get
 an AssertionError.  If I do, then I know the code is being run.  If I
 don't then I know it's not.  Either way, I know more about what's going
 on than I did before.  Once I know what's going on, I remove the assert.

If the program is invoked from a terminal I would probably go with
'import pdb; pdb.set_trace()' rather than 'assert 0'. Then you can
check much more than whether or not the code is being executed. It's a
bit more to type but I type it so often that I can now type it *really
fast*.


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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Mark Lawrence

On 18/11/2013 09:44, wxjmfa...@gmail.com wrote:

character
Satisfied Interfaces: ComparableCharacter, EnumerableCharacter, 
OrdinalOther
A 32-bit Unicode character.
Satisfied Interfaces: Category, CloneableListElement, CollectionElement,
ComparableString, CorrespondenceInteger,Element, IterableElement,Null,
ListCharacter, RangedInteger,String, SummableString


string
Satisfied Interfaces: Category, CloneableListElement, CollectionElement,
ComparableString, CorrespondenceInteger,Element, IterableElement,Null,
ListCharacter, RangedInteger,String, SummableString
A string of characters. Each character in the string is a 32-bit Unicode
character. The internal UTF-16 encoding is hidden from clients.
A string is a Category of its Characters, and of its substrings:


Clean. Far, far away from a unicode handling which may require
18 bytes (!) more to encode a non ascii n-chars string than a
ascii n-chars string.
(With performances following expectedly globally the same logic)


sys.getsizeof('a')

26

sys.getsizeof('\U0001d11e')

44


jmf



In [3]: sys.getsizeof(1)
Out[3]: 14

What a disaster, 13 bytes wasted storing 1.  I'll just rush off to the 
bug tracker and raise an issue to get the entire Cpython core rewritten 
before Armaggeddon strikes.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: When to use assert

2013-11-18 Thread Mark Lawrence

On 18/11/2013 09:50, Oscar Benjamin wrote:

On 17 November 2013 13:33, Roy Smith r...@panix.com wrote:


So, I stick assert 0 in the code an re-run the program to see if I get
an AssertionError.  If I do, then I know the code is being run.  If I
don't then I know it's not.  Either way, I know more about what's going
on than I did before.  Once I know what's going on, I remove the assert.


If the program is invoked from a terminal I would probably go with
'import pdb; pdb.set_trace()' rather than 'assert 0'. Then you can
check much more than whether or not the code is being executed. It's a
bit more to type but I type it so often that I can now type it *really
fast*.


Oscar



If I used something that often I'd either cut and paste it or have a key 
combination set up to insert it automatically.  Or get my man to type it 
up for me :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Chris Angelico
On Mon, Nov 18, 2013 at 8:44 PM,  wxjmfa...@gmail.com wrote:
 string
 Satisfied Interfaces: Category, CloneableListElement, CollectionElement,
 ComparableString, CorrespondenceInteger,Element, IterableElement,Null,
 ListCharacter, RangedInteger,String, SummableString
 A string of characters. Each character in the string is a 32-bit Unicode
 character. The internal UTF-16 encoding is hidden from clients.
 A string is a Category of its Characters, and of its substrings:

I'm trying to figure this out. Reading the docs hasn't answered this.
If each character in a string is a 32-bit Unicode character, and (as
can be seen in the examples) string indexing and slicing are
supported, then does string indexing mean counting from the beginning
to see if there were any surrogate pairs?

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


Re: Python Beginner

2013-11-18 Thread ngangsia akumbo
On Monday, November 18, 2013 5:42:22 AM UTC+1, Terry Reedy wrote:
 On 11/17/2013 11:02 PM, ngangsia akumbo wrote:
 
 
 
  Cameroon is a third world country, the IT skills of the people here
 
  is far from attaining any legitimacy.
 
 
 
  Many people are doing business here just like in the days of the
 
  Roman empire when computers had not been invented.
 
 
 
  We have many companies needing skills professionals to solve their IT
 
  problems which they can't find and always have to hire from abroad.
 
 
 
  Talking about problem in IT you can think of the most basic problem.
 
 
 
  Taxation, databases, accounting, simple apps for businesses ,
 
  tracking systems, bookkeeping, Mobil apps for city direction, etc,
 
  which i can't identify all being a python beginner.
 
 
 
 To find (free) business software written in Python, search at
 
 https://pypi.python.org/pypi
 
 sourceforge.net
 
 or you favorite search engine.
 
 
 
 Perhaps you can learn to use and adapt a few to solve local business 
 
 problems.
 
 
 
  We don't even have a University that offer a full flesh computer
 
  science course
 
 
 
 The phrase you are looking for is 'full-fledged'. 'Fledge' has the same 
 
 root as 'fly' and it means 'develop the feathers needed to fly' (for a 
 
 young bird). So a full-fledged computer science course would be one that 
 
 teaches you all the skills you need to 'fly' on your own.
 
 
 
 -- 
 
 Terry Jan Reedy

not 'full-fledged' but a uni that offers a complete program on CS
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Beginner

2013-11-18 Thread ngangsia akumbo
On Saturday, November 16, 2013 11:41:31 PM UTC+1, Chris Angelico wrote:
 On Sun, Nov 17, 2013 at 9:25 AM, ngangsia akumbo ngang...@gmail.com wrote:
 
  I am called Richard m from western Africa, Cameroon. It was a pleasure for 
  me to join this group.
 
 
 
 Hi! Welcome!
 
 
 
  secondly, i wihs to start a small company after learning how to code
 
 
 
  I am learning python very broadly, meaning i am not concentrating on a 
  single section. I wish to know the language and be able to apply it to any 
  location in the field of tech.
 
 
 
  i Need some advise on how, and what python can help me setup a business?
 
 
 
 Frankly, my advice to you is: Don't. You've been writing code for a
 
 few months, that's great; but starting a company is a completely
 
 different thing to do.
 
 
 
 I would recommend that you primarily code purely for pleasure - that
 
 way, if you mess something up, you don't lose money. And then if you
 
 want to go professional, get a salaried job at someone else's company,
 
 rather than starting your own. It's a HUGE job to run your own
 
 company, and that's not something your Python coding skill will help
 
 with. Tax, legal requirements, profitability... headaches you don't
 
 need.
 
 
 
 Now, if you're already experienced at running a business, and want to
 
 know what Python can do to make your life easier... that we can
 
 answer! There are all sorts of automation and convenience jobs you can
 
 do with Python. But that's quite different from what I think you're
 
 asking here.
 
 
 
 ChrisA

I HAVE NOT HEARD FROM YOU

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


Re: When to use assert

2013-11-18 Thread Tim Chase
On 2013-11-18 09:50, Oscar Benjamin wrote:
 If the program is invoked from a terminal I would probably go with
 'import pdb; pdb.set_trace()' rather than 'assert 0'. Then you can
 check much more than whether or not the code is being executed.
 It's a bit more to type but I type it so often that I can now type
 it *really fast*.

I do this so much that on my main development machines, I have a line
in my vimrc file

  nnoremap leaderp oimport pdb; pdb.set_trace()esc
  nnoremap leaderP Oimport pdb; pdb.set_trace()esc

which maps the the leader key (defaults to \) followed by p/P to
insert the pdb line below/above the current line.  Saves bunches of
time  hassle.  I'm sure it's equally easy in other quality editors.

-tkc



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


Re: RapydScript : Python to Javascript translator

2013-11-18 Thread Salvatore DI DIO

 
 I don't know about other people here, but I'm a bit leery of just
 
 downloading Windows binaries from people and running them. Is your
 
 source code available? Is this an open source / free project?
 
 
 
 ChrisA

You are completly right :-)
Here is the source code :

https://github.com/charleslaw/rapydscript_online

You can see other demos here :

http://salvatore.pythonanywhere.com/RapydScript

The official site of RapydScript :

http://rapydscript.pyjeon.com/

e assumptions before testing :

Here is the official site:

http://rapydscript.pyjeon.com/ 

Regards 

Salvatore




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


Re: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128)

2013-11-18 Thread Fabio Zadrozny
On Mon, Nov 18, 2013 at 2:55 AM, Hoàng Tuấn Việt viet...@viettel.com.vnwrote:

 Hi all,



 I use Python telnetlib on Windows 7 32 bit. Here is my code:



 def *telnet*(*self*, host, os, username, password):

 connection = telnetlib.Telnet(host)

 connection.read_until(*'login: '*)

 connection.write(username + *'\r'*)

 connection.read_until(*'assword: '*)

 connection.write(password + *'\r'*)

 connection.read_until(*''*, timeout = TIMEOUT)

return connection



 I can run the program in Eclipse and telnet successfully to a Windows host.



 But when I export to .exe file:



 from distutils.core import setup

 import py2exe



 setup(

 options = {

 *py2exe*:{

 *packages*: [*'wx.lib.pubsub'*],

 *dll_excludes*: [*MSVCP90.dll*, *HID.DLL*,
 *w9xpopen.exe*],

 }

 },

 console = [{*'script'*: *‘my_program.py'*}]

 )



 and run the programe, I encounter this error:



 UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0:
 ordinal not in range(128)



 at line:



 connection.write(username + '\r')



 I have debugged and searched the Internet hard but found no solution yet.



 I think it is because of ‘\r’.



 Do you have any idea?



 Viet

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


You should be able to reproduce the same behavior on PyDev if in your run
configuration you select the encoding of the console to be ascii (run  run
configurations  select run configuration  common  set encoding to
us-ascii).

My guess is that you have the problem because the username has non-ascii
chars -- and you're receiving it as an unicode and not a string... so, you
have to do encode it properly to a string before writing to the connection
(i.e.: username.encode('utf-8') + '\r' -- although the encoding may have to
be a different one and not utf-8).

Cheers,

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


Re: Unicode stdin/stdout

2013-11-18 Thread Robin Becker

On 15/11/2013 18:16, random...@fastmail.us wrote:

Of course, the real solution to this issue is to replace sys.stdout on
windows with an object that can handle Unicode directly with the
WriteConsoleW function - the problem there is that it will break code
that expects to be able to use sys.stdout.buffer for binary I/O. I also
wasn't able to get the analogous stdin replacement class to work with
input() in my attempts.


I started to use this on my windows installation


#c:\python33\lib\site-packages\sitecustomize.py
import sys, codecs
sys.stdout = codecs.getwriter(utf-8)(sys.stdout.detach())
sys.stderr = codecs.getwriter(utf-8)(sys.stderr.detach())

which makes them writable with any unicode; after many years I am quite used to 
garbage appearing in the windows console.


Unfortunately the above doesn't go into virtual environments, but I assume a 
hacked site.py could do that.

--
Robin Becker

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


Source code of Python to Javascsript translator

2013-11-18 Thread Salvatore DI DIO


 I don't know about other people here, but I'm a bit leery of just

 downloading Windows binaries from people and running them. Is your

 source code available? Is this an open source / free project?



 ChrisA

You are completly right :-)
Here is the source code :

https://github.com/charleslaw/rapydscript_online

You can see other demos here :

http://salvatore.pythonanywhere.com/RapydScript

The official site of RapydScript :

http://rapydscript.pyjeon.com/

e assumptions before testing :

Here is the official site:

http://rapydscript.pyjeon.com/

Regards

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


Re: If you continue being rude i will continue doing this

2013-11-18 Thread YBM

You are the one being rude, Nikos.

Moreover you are a nut, installing pygeoip works fine
for me:

# pip install pygeoip
Downloading/unpacking pygeoip
  Downloading pygeoip-0.3.0.tar.gz (97Kb): 97Kb downloaded
  Running setup.py egg_info for package pygeoip

Installing collected packages: pygeoip
  Running setup.py install for pygeoip

Successfully installed pygeoip
Cleaning up...

you've probably completely messed up your system, as you
are completely incompetent as a UNIX/Linux admin and broke
your system.



Le 17/11/2013 23:31, Ferrous Cranus a écrit :

==
root@secure [~/distribute-0.6.49]# pip install pygeoip
Downloading/unpacking pygeoip
Downloading pygeoip-0.3.0.tar.gz (97kB): 97kB downloaded
Running setup.py egg_info for package pygeoip
Traceback (most recent call last):
File string, line 16, in module
File /usr/lib/python3.3/encodings/ascii.py, line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
1098: ordinal not in range(128)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File string, line 16, in module

File /usr/lib/python3.3/encodings/ascii.py, line 26, in decode

return codecs.ascii_decode(input, self.errors)[0]

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
1098: ordinal not in range(128)
==



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


Re: Automation

2013-11-18 Thread Neil Cerutti
On 2013-11-16, Larry Hudson org...@yahoo.com wrote:
 However, that's just a side comment.  I wanted to mention my
 personal peeve...

 I notice it's surprisingly common for people who are native
 English-speakers to use 'to' in place of 'too' (to little, to
 late.), your in place of you're (Your an idiot!) and
 'there' in place of 'their' (a foot in there mouth.)  There are
 similar mis-usages, of course, but those three seem to be the
 most common.

 Now, I'm a 76-year-old curmudgeon and maybe overly sensitive,
 but I felt a need to vent a bit.

The cases where written and spoken English diverge are hotbets of
word usage problems. I'm glad the issue doesn't exist for
programming languages, which thankfully don't really have a
colloquial or spoken version.

Written English probably changes much slower than spoken English,
and we have the curmudgeon's to thank.

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Ian Kelly
On Nov 18, 2013 3:06 AM, Chris Angelico ros...@gmail.com wrote:

 I'm trying to figure this out. Reading the docs hasn't answered this.
 If each character in a string is a 32-bit Unicode character, and (as
 can be seen in the examples) string indexing and slicing are
 supported, then does string indexing mean counting from the beginning
 to see if there were any surrogate pairs?

The string reference says:

Since a String has an underlying UTF-16 encoding, certain operations are
expensive, requiring iteration of the characters of the string. In
particular, size requires iteration of the whole string, and get(), span(),
and segment() require iteration from the beginning of the string to the
given index.

The get and span operations appear to be equivalent to indexing and slicing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode stdin/stdout

2013-11-18 Thread Robin Becker

On 18/11/2013 11:47, Robin Becker wrote:
...

#c:\python33\lib\site-packages\sitecustomize.py
import sys, codecs
sys.stdout = codecs.getwriter(utf-8)(sys.stdout.detach())
sys.stderr = codecs.getwriter(utf-8)(sys.stderr.detach())


it seems that the above needs extra stuff to make some distutils logging work 
etc etc; so now I'm using sitecustomize.py containing


import sys, codecs
sys.stdout = codecs.getwriter(utf-8)(sys.stdout.detach())
sys.stdout.encoding = 'utf8'
sys.stderr = codecs.getwriter(utf-8)(sys.stderr.detach())
sys.stderr.encoding = 'utf8'

--
Robin Becker

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Chris Angelico
On Mon, Nov 18, 2013 at 11:29 PM, Ian Kelly ian.g.ke...@gmail.com wrote:

 On Nov 18, 2013 3:06 AM, Chris Angelico ros...@gmail.com wrote:

 I'm trying to figure this out. Reading the docs hasn't answered this.
 If each character in a string is a 32-bit Unicode character, and (as
 can be seen in the examples) string indexing and slicing are
 supported, then does string indexing mean counting from the beginning
 to see if there were any surrogate pairs?

 The string reference says:

 Since a String has an underlying UTF-16 encoding, certain operations are
 expensive, requiring iteration of the characters of the string. In
 particular, size requires iteration of the whole string, and get(), span(),
 and segment() require iteration from the beginning of the string to the
 given index.

 The get and span operations appear to be equivalent to indexing and slicing.

Right, that's what I was looking for and didn't find. (I was searching
the one-page reference manual rather than reading in detail.) So, yes,
they're O(n) operations. Thanks for hunting that down.

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


Re: [Python-ideas] Unicode stdin/stdout

2013-11-18 Thread Nick Coghlan
On 18 Nov 2013 22:36, Robin Becker ro...@reportlab.com wrote:

 On 18/11/2013 11:47, Robin Becker wrote:
 ...

 #c:\python33\lib\site-packages\sitecustomize.py
 import sys, codecs
 sys.stdout = codecs.getwriter(utf-8)(sys.stdout.detach())
 sys.stderr = codecs.getwriter(utf-8)(sys.stderr.detach())

 
 it seems that the above needs extra stuff to make some distutils logging
work etc etc; so now I'm using sitecustomize.py containing

 import sys, codecs
 sys.stdout = codecs.getwriter(utf-8)(sys.stdout.detach())
 sys.stdout.encoding = 'utf8'
 sys.stderr = codecs.getwriter(utf-8)(sys.stderr.detach())
 sys.stderr.encoding = 'utf8'

Note that calling detach() on the standard streams isn't officially
supported, since it breaks the shadow streams saved in sys.__stderr__, etc.

Cheers,
Nick.


 --
 Robin Becker

 ___
 Python-ideas mailing list
 python-id...@python.org
 https://mail.python.org/mailman/listinfo/python-ideas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0: ordinal not in range(128)

2013-11-18 Thread Colin J. Williams

On 17/11/2013 11:55 PM, Hoàng Tuấn Việt wrote:

Hi all,

I use Python telnetlib on Windows 7 32 bit. Here is my code:

def*telnet*(/self/, host, os, username, password):

 connection = telnetlib.Telnet(host)

 connection.read_until(/'login: '/)

connection.write(username + /'\r'/)

 connection.read_until(/'assword: '/)

 connection.write(password + /'\r'/)

 connection.read_until(/''/, timeout = TIMEOUT)

returnconnection

I can run the program in Eclipse and telnet successfully to a Windows host.

But when I export to .exe file:

fromdistutils.core importsetup

importpy2exe

setup(

 options = {

/py2exe/:{

/packages/: [/'wx.lib.pubsub'/],

/dll_excludes/: [/MSVCP90._dll_/, /HID.DLL/, /w9xpopen.exe/],

 }

 },

 console = [{/'script'/: /‘my_program.py'/}]

)

and run the programe, I encounter this error:

UnicodeDecodeError: 'ascii' codec can't decodee byte 0xff in position 0:
ordinal not in range(128)

at line:

connection.write(username + '\r')

I have debugged and searched the Internet hard but found no solution yet.

I think it is because of ‘\r’.

Do you have any idea?

Viet


What about:
   connection.write(username, ' r') ?

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Steven D'Aprano
On Mon, 18 Nov 2013 21:04:41 +1100, Chris Angelico wrote:

 On Mon, Nov 18, 2013 at 8:44 PM,  wxjmfa...@gmail.com wrote:
 string
 Satisfied Interfaces: Category, CloneableListElement,
 CollectionElement, ComparableString,
 CorrespondenceInteger,Element, IterableElement,Null,
 ListCharacter, RangedInteger,String, SummableString A string of
 characters. Each character in the string is a 32-bit Unicode character.
 The internal UTF-16 encoding is hidden from clients. A string is a
 Category of its Characters, and of its substrings:
 
 I'm trying to figure this out. Reading the docs hasn't answered this. If
 each character in a string is a 32-bit Unicode character, and (as can be
 seen in the examples) string indexing and slicing are supported, then
 does string indexing mean counting from the beginning to see if there
 were any surrogate pairs?

I can't figure out what that means, since it contradicts itself. First it 
says *every* character is 32-bits (presumably UTF-32), then it says that 
internally it uses UTF-16. At least one of these statements is wrong. 
(They could both be wrong, but they can't both be right.)

Unless they have done something *really* clever, the language designers 
lose a hundred million points for screwing up text strings. There is 
*absolutely no excuse* for a new, modern language with no backwards 
compatibility concerns to choose one of the three bad choices:

* choose UTF-16 or UTF-8, and have O(n) primitive string operations (like 
Haskell and, apparently, Ceylon);

* or UTF-16 without support for the supplementary planes (which makes it 
virtually UCS-2), like Javascript;

* choose UTF-32, and use two or four times as much memory as needed.


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


Re: Python Beginner

2013-11-18 Thread Mark Lawrence

On 18/11/2013 10:18, ngangsia akumbo wrote:

On Saturday, November 16, 2013 11:41:31 PM UTC+1, Chris Angelico wrote:

On Sun, Nov 17, 2013 at 9:25 AM, ngangsia akumbo ngang...@gmail.com wrote:


I am called Richard m from western Africa, Cameroon. It was a pleasure for me 
to join this group.




Hi! Welcome!




secondly, i wihs to start a small company after learning how to code







I am learning python very broadly, meaning i am not concentrating on a single 
section. I wish to know the language and be able to apply it to any location in 
the field of tech.







i Need some advise on how, and what python can help me setup a business?




Frankly, my advice to you is: Don't. You've been writing code for a

few months, that's great; but starting a company is a completely

different thing to do.



I would recommend that you primarily code purely for pleasure - that

way, if you mess something up, you don't lose money. And then if you

want to go professional, get a salaried job at someone else's company,

rather than starting your own. It's a HUGE job to run your own

company, and that's not something your Python coding skill will help

with. Tax, legal requirements, profitability... headaches you don't

need.



Now, if you're already experienced at running a business, and want to

know what Python can do to make your life easier... that we can

answer! There are all sorts of automation and convenience jobs you can

do with Python. But that's quite different from what I think you're

asking here.



ChrisA


I HAVE NOT HEARD FROM YOU



Please don't shout.  Please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent the double 
spaced lines we see above, thanks.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Chris Angelico
On Tue, Nov 19, 2013 at 12:31 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Unless they have done something *really* clever, the language designers
 lose a hundred million points for screwing up text strings. There is
 *absolutely no excuse* for a new, modern language with no backwards
 compatibility concerns to choose one of the three bad choices:

Yeah, but this compiles to JS, so it does have that backward compat
issue - unless it's going to represent a Ceylon string as something
other than a JS string (maybe an array of integers??), which would
probably cost even more.

You're absolutely right, except in the premise that Ceylon is a new
and unshackled language. At least this way, if anyone actually
implements Ceylon directly in the browser, it can use something
smarter as its backend, without impacting code in any way (other than
performance). I'd much rather they go for O(n) string primitives than
maintaining the user-visible UTF-16 bug.

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


Re: Source code of Python to Javascsript translator

2013-11-18 Thread Mark Lawrence

On 18/11/2013 11:45, Salvatore DI DIO wrote:




I don't know about other people here, but I'm a bit leery of just

downloading Windows binaries from people and running them. Is your

source code available? Is this an open source / free project?



ChrisA


You are completly right :-)
Here is the source code :

https://github.com/charleslaw/rapydscript_online

You can see other demos here :

http://salvatore.pythonanywhere.com/RapydScript

The official site of RapydScript :

http://rapydscript.pyjeon.com/

e assumptions before testing :

Here is the official site:

http://rapydscript.pyjeon.com/

Regards

Salvatore



Would you please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing above, thanks.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: If you continue being rude i will continue doing this

2013-11-18 Thread Antoon Pardon
Please try to restrain yourself.

I understand the urge to vent your frustration but it will
accomplish nothing. We are all frustrated by Nikos's behaviour
but we all rely on each other not to increase that frustration
through responding to his threads and thus prolonging their
duration.

-- 
Antoon Pardon

Op 18-11-13 10:31, YBM schreef:
 You are the one being rude, Nikos.
 
 Moreover you are a nut, installing pygeoip works fine
 for me:
 
 # pip install pygeoip
 Downloading/unpacking pygeoip
   Downloading pygeoip-0.3.0.tar.gz (97Kb): 97Kb downloaded
   Running setup.py egg_info for package pygeoip
 
 Installing collected packages: pygeoip
   Running setup.py install for pygeoip
 
 Successfully installed pygeoip
 Cleaning up...
 
 you've probably completely messed up your system, as you
 are completely incompetent as a UNIX/Linux admin and broke
 your system.
 
 
 
 Le 17/11/2013 23:31, Ferrous Cranus a écrit :
 ==
 root@secure [~/distribute-0.6.49]# pip install pygeoip
 Downloading/unpacking pygeoip
 Downloading pygeoip-0.3.0.tar.gz (97kB): 97kB downloaded
 Running setup.py egg_info for package pygeoip
 Traceback (most recent call last):
 File string, line 16, in module
 File /usr/lib/python3.3/encodings/ascii.py, line 26, in decode
 return codecs.ascii_decode(input, self.errors)[0]
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
 1098: ordinal not in range(128)
 Complete output from command python setup.py egg_info:
 Traceback (most recent call last):

 File string, line 16, in module

 File /usr/lib/python3.3/encodings/ascii.py, line 26, in decode

 return codecs.ascii_decode(input, self.errors)[0]

 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
 1098: ordinal not in range(128)
 ==

 

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


Doc generation from annotated source code

2013-11-18 Thread Laszlo Nagy
I just started rewritting my project from python 2 to python 3. I 
noticed that there are these new parameter and return value annotations. 
I have docstrings everywhere in my project, but I plan to convert many 
of them into annotations. The question is: what kind of auto documenting 
system should I use for this? Previously I have used Sphinx. Is it okay 
to use that for python 3 source code? Is there a better alternative?


Thanks

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Setting longer default decimal precision

2013-11-18 Thread Kay Y. Jheallee

Using 1/3 as an example,

 1./3
0.
 print %.50f % (1./3)
0.1482961625624739099293947219848633
 print %.50f % (10./3)
3.33348136306995002087205648422241210938
 print %.50f % (100./3)
33.33570180911920033395290374755859375000

which seems to mean real (at least default) decimal precision
is limited to double, 16 digit precision (with rounding error).
Is there a way to increase the real precision, preferably as
the default?
For instance, UBasic uses a Words for fractionals, f, 
Point(f) system, where Point(f) sets the decimal display 
precision, .1^int(ln(65536^73)/ln(10)), with the last few digits 
usually garbage.
Using 90*(pi/180)*180/pi as an example to highlight the 
rounding error (4 = UBasic's f default value):


 Point(2)=.1^09: 89.99306
 Point(3)=.1^14: 89.99944
 Point(4)=.1^19: 89.9998772
 Point(5)=.1^24: 89.9217
 Point(7)=.1^33: 89.99823
Point(10)=.1^48: 89.7686
Point(11)=.1^52: 
89.9632


If not in the core program, is there a higher decimal precision 
module that can be added?


--
Kill Hector dead, because Desi sent Milli.
--
https://mail.python.org/mailman/listinfo/python-list


HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-18 Thread Logan Owen
Hello everyone,

I was hoping for some advice in dealing with an edge case related to
Python's HTTP Header handling.  Python is correctly assuming that the
HTTP header field name (eg Content-Type) is case insensitive, but I have
a webservice I am interacting with that does not follow the standards. 
I am passing in the header SOAPAction and do_request of
AbstractHTTPHandler is applying title() to the string, leading to the
field name being Soapaction, which the server does not recognize.

So my question is, what does everyone suggest is the best solution for
being able to pass a case sensitive header to the server?

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Piet van Oostrum
Chris Angelico ros...@gmail.com writes:

 On Mon, Nov 18, 2013 at 11:29 PM, Ian Kelly ian.g.ke...@gmail.com wrote:

 On Nov 18, 2013 3:06 AM, Chris Angelico ros...@gmail.com wrote:

 I'm trying to figure this out. Reading the docs hasn't answered this.
 If each character in a string is a 32-bit Unicode character, and (as
 can be seen in the examples) string indexing and slicing are
 supported, then does string indexing mean counting from the beginning
 to see if there were any surrogate pairs?

 The string reference says:

 Since a String has an underlying UTF-16 encoding, certain operations are
 expensive, requiring iteration of the characters of the string. In
 particular, size requires iteration of the whole string, and get(), span(),
 and segment() require iteration from the beginning of the string to the
 given index.

 The get and span operations appear to be equivalent to indexing and slicing.

 Right, that's what I was looking for and didn't find. (I was searching
 the one-page reference manual rather than reading in detail.) So, yes,
 they're O(n) operations. Thanks for hunting that down.

 ChrisA

It would be so much better to use the Flexible String Representation.
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Oh look, another language (ceylon)

2013-11-18 Thread Steven D'Aprano
On Mon, 18 Nov 2013 13:31:33 +, Steven D'Aprano wrote:

 On Mon, 18 Nov 2013 21:04:41 +1100, Chris Angelico wrote:
 
 On Mon, Nov 18, 2013 at 8:44 PM,  wxjmfa...@gmail.com wrote:
 string
 Satisfied Interfaces: Category, CloneableListElement,
 CollectionElement, ComparableString,
 CorrespondenceInteger,Element, IterableElement,Null,
 ListCharacter, RangedInteger,String, SummableString A string of
 characters. Each character in the string is a 32-bit Unicode
 character. The internal UTF-16 encoding is hidden from clients. A
 string is a Category of its Characters, and of its substrings:
 
 I'm trying to figure this out. Reading the docs hasn't answered this.
 If each character in a string is a 32-bit Unicode character, and (as
 can be seen in the examples) string indexing and slicing are supported,
 then does string indexing mean counting from the beginning to see if
 there were any surrogate pairs?
 
 I can't figure out what that means, since it contradicts itself. First
 it says *every* character is 32-bits (presumably UTF-32), then it says
 that internally it uses UTF-16. At least one of these statements is
 wrong. (They could both be wrong, but they can't both be right.)

Mystery solved: characters are only 32-bits in isolation, when plucked 
out of a string.

http://ceylon-lang.org/documentation/tour/language-module/
#characters_and_character_strings

Ceylon strings are arrays of UTF-16 characters. However, the language 
supports characters in the Supplementary Multilingual Plane by having 
primitive string operations walk the string a code point at a time. When 
you extract a character out of the string, Ceylon gives you four bytes. 
Presumably, if you do something like like this:

# Python syntax, not Ceylon
mystring = a\U0010
c = mystring[0]
d = mystring[1]

c will consist of bytes  0061 and d will consist of the surrogate 
pair DBFF DFFF (the UTF-16BE encoding of code point U+10, modulo big-
endian versus little-ending). Or possibly the UTF-32 encoding, 0010 .

I suppose that's not terrible, except for the O(n) string operations 
which is just dumb. Yes, it's better than buggy, broken strings. But 
still dumb, because those aren't the only choices. For example, for the 
sake of an extra two bytes at the start of each string, they could store 
a flag and a length:

- one bit to flag whether the string contained any surrogate pairs or 
not; if not, string ops could assume two-bytes per char and be O(1), if 
the flag was set it could fall back to the slower technique;

- 15 bits for a length.

15 bits give you a maximum length of 32767. There are ways around that. 
E.g. a length of 0 through 32766 means exactly what it says; a length of 
32767 means that the next two bytes are part of the length too, giving 
you a maximum of 4294967295 characters per string. That's an 8GB string. 
Surely big enough for anyone :-)

That gives you O(1) length for *any* string, and O(1) indexing operations 
for those that are entirely in the BMP, which will be most strings for 
most people. It's not 1970 anymore, it's time for strings to be treated 
more seriously and not just as dumb arrays of char. Even back in the 
1970s Pascal had a length byte. It astonishes me that hardly any low-
level language follows their lead.



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


Re: If you continue being rude i will continue doing this

2013-11-18 Thread Piet van Oostrum
Ferrous Cranus nikos.gr...@gmail.com writes:

 No i haven't broke it at all.
 Everything work as they should.

 The refusal of 'pygeoip' to install turned out to be the local setting in my 
 new VPS.

 So i have changes it to:

 export LANG = en_US.UTF-8

 and then 'pip install pygeoip' was successful. 

 Trying to figure out how to install-setup EPEL repository along with
 python3  python3-pip and 2 extra modules my script needed in my new
 VPS have costed 4-5 of my life and of my mental health, while if you
 just helped a bit these would have been done in a couple of hours.

How could anyone have known that this was the problem? AFIAK you didn't even 
tell about the VPS. And moreover this wasn't a Python problem, so off topic 
here.
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Setting longer default decimal precision

2013-11-18 Thread Steven D'Aprano
On Mon, 18 Nov 2013 14:14:33 +, Kay Y. Jheallee wrote:

 Using 1/3 as an example,

[snip examples]

 which seems to mean real (at least default) decimal precision is limited
 to double, 16 digit precision (with rounding error).

That's because Python floats actually are implemented as C doubles. And 
no, they're not configurable.

However, Python also has a Decimal class, which (unlike floats) are 
actually decimal rather than binary, and include configurable precision. 
There is a performance hit -- prior to Python version 3.3, Decimal was 
quite slow, but in 3.3 they got a major speed increase and are now nearly 
as fast as floats.

An example:

py import decimal
py x = decimal.Decimal(1)/3
py decimal.getcontext().prec = 50
py y = decimal.Decimal(1)/3
py print(x, y)
0. 
0.33



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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Steven D'Aprano
On Wed, 13 Nov 2013 14:33:27 -0500, Neal Becker wrote:

 http://ceylon-lang.org/documentation/1.0/introduction/


I must say there are a few questionable design choices, in my opinion, 
but I am absolutely in love with the following two features:


1) variables are constant by default;

2) the fat arrow operator.


By default, variables can only be assigned to once, and then not re-
bound:

String bye = Adios;//a value
bye = Adeu;  //compile error

variable Integer count = 0;  //a variable
count = 1; //allowed


(I'm not sure how tedious typing variable will get, or whether it will 
encourage a more functional-programming approach. But I think that's a 
very exciting idea and kudos to the Ceylon developers for running with 
it!)


Values can be recalculated every time they are used, sort of like mini-
functions, or thunks:

String name { return firstName +   + lastName; } 

Since this is so common in Ceylon, they have syntactic sugar for it, the 
fat arrow:

String name = firstName +   + lastName;


If Python steals this notation, we could finally bring an end to the 
arguments about early binding and late binding of default arguments:


def my_function(a=[early, binding, happens, once],
b=[late, binding, happens, every, time]
):
...


Want!

These two features alone may force me to give Ceylon a try.




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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Mark Lawrence

On 18/11/2013 14:31, Piet van Oostrum wrote:

Chris Angelico ros...@gmail.com writes:


On Mon, Nov 18, 2013 at 11:29 PM, Ian Kelly ian.g.ke...@gmail.com wrote:


On Nov 18, 2013 3:06 AM, Chris Angelico ros...@gmail.com wrote:


I'm trying to figure this out. Reading the docs hasn't answered this.
If each character in a string is a 32-bit Unicode character, and (as
can be seen in the examples) string indexing and slicing are
supported, then does string indexing mean counting from the beginning
to see if there were any surrogate pairs?


The string reference says:

Since a String has an underlying UTF-16 encoding, certain operations are
expensive, requiring iteration of the characters of the string. In
particular, size requires iteration of the whole string, and get(), span(),
and segment() require iteration from the beginning of the string to the
given index.

The get and span operations appear to be equivalent to indexing and slicing.


Right, that's what I was looking for and didn't find. (I was searching
the one-page reference manual rather than reading in detail.) So, yes,
they're O(n) operations. Thanks for hunting that down.

ChrisA


It would be so much better to use the Flexible String Representation.



I agree but approximately 0.000142857% of the world population 
disagrees.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: [Python-ideas] Unicode stdin/stdout

2013-11-18 Thread Victor Stinner
Why do you need to force the UTF-8 encoding? Your locale is not
correctly configured?

It's better to set PYTHONIOENCODING rather than replacing
sys.stdout/stderr at runtime.

There is an open issue to add a TextIOWrapper.set_encoding() method:
http://bugs.python.org/issue15216

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


Building a tree-based readline completer

2013-11-18 Thread roey . katz
Hello all, for my project[1] I am trying to build a replacement completer for 
python's Cmd class which accepts a tree of command and option names[2].  I've 
been trying all sorts of approaches (like the ARLCompleter mention here: 
https://sites.google.com/site/xiangyangsite/home/technical-tips/software-development/python/python-readline-completions),
 but so far am up for a loss as to how to get this done.  

Can anyone help me out here?  I've placed a bounty on this with BountySource:  
https://www.bountysource.com/issues/1319877-implement-a-generalized-completer-function-validator-and-filename-completer.

Thanks!
- Roey Katz
Bywaf developer 


(1) Bywaf, a command-line tool and framework for bypassing web application 
firewalls and more:  https://www.owasp.org/index.php/OWASP_Bywaf_Project

(2) What I'm looking for is a completer which accepts a tree of commands and 
option names.  Option names complete with a '=', and commands and sub-commands 
complete with a ' ', as in this hypothetical example:

 comTAB PRESSED
command com2
 commTAB PRESSED
 command TAB PRESSED
 command OPTTAB PRESSED
OPTION_1 OPTION_2
 command OPTION_1TAB PRESSED
 command OPTION_1=TAB PRESSED
 command OPTION_1=


Ideally, I'd like to be able to pass in a dictionary tree of commands and 
options, for example:

params_tree = { 
  'command': {
  'OPTION_1=':None,
  'OPTION_2=':None,
  }
  'com2': None,
}

Where '=' indicates an option name.   An example of a more general tree, with 
more special symbols, would look like this:


# dictionary passed into the general completer function
params_tree = {

   # tab-complete 'quit'
   'quit':None,

   # tab-complete TARGET_IP, and allow any string as its value
'TARGET_IP=': '*',  

# tab-complete drive.  
'drive': {

# tab-complete car, truck, bike and also allow any other string.
'VEHICLE=': ('car', 'truck, 'bike', '*'),  

   # tab-complete hard disk, sd card and remote share.
'SAVE=': ('hard disk', 'sd card', 'remote share') 
},

# tab-complete eat
'eat': {

# tab-complete FRUIT=, then tab-complete 'apple' or 'pear'.  At the 
end of a successful completion, an additonal tab results in an offer to 
insert a comma and complete additional items
'FRUIT=+': ('apple', 'pear'),   

# tab-complete FRUIT=, then tab-complete 'water' or 'juice'.  At the 
end of a successful completion, an additonal tab results in an offer to 
insert a comma and complete additional items
'DRINK=+': ('water', 'juice')
},

# tab-complete cat, then tab-complete filenames.  At the end of a 
successful completion, close the quote, then upon another tab, offer to 
complete with a comma, allowing for completion of additional items
'cat': 'FILE=/+'  
}

Notes:

An element in this dictionary can take None, a string, a tuple or a dictionary 
of more elements.

  *  =' indicates that this is a plugin option.
  *  /' indicates this plugin option should complete beginning with the path 
specified after the =, provided that this path meets security guidelines (i.e. 
it resolves to a path under a specific directory). A plugin option named 
FILENAME marked in this way shall complete to FILENAME= instead of FILENAME=.
  *  + indicates that this option can be specified more than once. Multiple 
values will be collected into a list instead of a string.
  *  a * indicates that this option accepts any single value. User can 
specify any number of options, but only one of command from the same level


Additionally, the tree completer should should support escaping characters and 
nested quoted strings (alternating single- and double-quotes), and all in 
Unicode.

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


Re: Unicode stdin/stdout

2013-11-18 Thread Robin Becker

On 18/11/2013 15:25, Victor Stinner wrote:

Why do you need to force the UTF-8 encoding? Your locale is not
correctly configured?

It's better to set PYTHONIOENCODING rather than replacing
sys.stdout/stderr at runtime.

There is an open issue to add a TextIOWrapper.set_encoding() method:
http://bugs.python.org/issue15216

Victor

well reportlab does all sorts of character sets and languages; if I put in a 
quick print to try and debug stuff I prefer that it create some output rather 
than create an error of its own. In the real world it's not possible always to 
know what the output contains (especially in error cases) so having any 
restriction on the allowed textual outputs is a bit constraining.


The utf8 encoding should allow any unicode to be properly encoded, rendering is 
another issue and I expect some garbage when things are going wrong.


I think you are right and I should use PYTHONIOENCODING to set this up. In the 
codec writer approach I think it's harder to get interactive behaviour working 
properly (the output seems to be buffered differently). My attempts to make 
windows xp use code page 65001 everywhere have been fairly catastrophic eg 
non-booting :(

--
Robin Becker

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


Is curses module thread-safe?

2013-11-18 Thread Grant Edwards
I'm working on a program that uses the curses module, and I'd like to
use multiple threads (using the threading module).  Is the curses module
in the standard library usable from multile threads?

I found a discussion from about 15 years ago that indicated it wasn't
at that time.  The example being discussed was that when one thread
calls a blocking getch(), the GIL isn't released and wall threads stop.
The suggesting work-around was to wrap the call to getch() with a
select() on sys.stdin.  Is that still an issue?


If two threads call addstr() simultaneously is it handled properly?

Or do all curses calls need to be made by a single thread?

-- 
Grant Edwards   grant.b.edwardsYow! It don't mean a
  at   THING if you ain't got
  gmail.comthat SWING!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building a tree-based readline completer

2013-11-18 Thread xDog Walker
On Monday 2013 November 18 07:47, roey.k...@gmail.com wrote:
 I am trying to build a replacement completer for python's Cmd class

These related packages may be of interest:

 http://pypi.python.org/pypi/rl
 http://pypi.python.org/pypi/kmd

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.

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


Re: Automation

2013-11-18 Thread Grant Edwards
On 2013-11-16, Larry Hudson org...@yahoo.com wrote:

 And yes, people can _easily_ tell the difference between errors
 caused by being lazy/sloppy and errors caused by writing in a second
 language.

 Not to start another flame-war (I hope), but our Greek friend is a
 good example of that.  It's not surprising he has so much trouble
 with his code.

 However, that's just a side comment.  I wanted to mention my personal
 peeve...

 I notice it's surprisingly common for people who are native
 English-speakers to use 'to' in place of 'too' (to little, to late.),
 your in place of you're (Your an idiot!) and 'there' in place of
 'their' (a foot in there mouth.) There are similar mis-usages, of
 course, but those three seem to be the most common.

And I'm convinced that the more proficient the typist, the more often
one makes those sorts of mistakes when composing text.  If you've got
to hunt and peck on the keyboard, then you've got to actually think
about how each word is spelled, and you realize which one you're
actually typing.  If you're a proficient touch typist (and are typing
something on-the-fly rather than transcribing), I think the sound of
the word is more directly connected to the fingers without benefit of
grammatical conext invervening to choose the correct homonym.

I don't make those mistakes typing on a phone (where I have to
actually think about the act of typing), but I do make them with a
regular keyboard, where I don't have to think about mechanics of
typing the words.

OTOH, maybe that's just me...

-- 
Grant Edwards   grant.b.edwardsYow! I am having FUN...
  at   I wonder if it's NET FUN or
  gmail.comGROSS FUN?
-- 
https://mail.python.org/mailman/listinfo/python-list


Byteorder of audioop functions

2013-11-18 Thread Michael Schwarz
Hi

Is the byteorder (or endianness) of the functions in the audioop module 
somewhere specified or does anyone know how it behaves on different systems?

On my little-endian system it matches the system's endianness:

 import sys, audioop
 sys.byteorder
'little'
 audioop.lin2lin(b'\xff', 1, 2)
b'\x00\xff'

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


Re: Building a tree-based readline completer

2013-11-18 Thread roey . katz
Thank you.  In looking over these classes, I see though that even them, I would 
run against the same limitations, though.  

- Roey 

On Monday, November 18, 2013 11:41:20 AM UTC-5, xDog Walker wrote:
 On Monday 2013 November 18 07:47, roey wrote:
 
  I am trying to build a replacement completer for python's Cmd class
 
 
 
 These related packages may be of interest:
 
 
 
  http://pypi.python.org/pypi/rl
 
  http://pypi.python.org/pypi/kmd
 
 
 
 -- 
 
 Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
 
 strainers.

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


Re: Building a tree-based readline completer

2013-11-18 Thread roey . katz
On Monday, November 18, 2013 11:54:43 AM UTC-5, roey  wrote:
 Thank you.  In looking over these classes, I see though that even them, I 
 would run against the same limitations, though.  
 
 
 
 - Roey 
 
 
 
 On Monday, November 18, 2013 11:41:20 AM UTC-5, xDog Walker wrote:
 
  On Monday 2013 November 18 07:47, roey wrote:
 
  
 
   I am trying to build a replacement completer for python's Cmd class
 
  
 
  
 
  
 
  These related packages may be of interest:
 
  
 
  
 
  
 
   http://pypi.python.org/pypi/rl
 
  
 
   http://pypi.python.org/pypi/kmd
 
  
 
  
 
  
 
  -- 
 
  
 
  Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
 
  
 
  strainers.

*even with them
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building a tree-based readline completer

2013-11-18 Thread Mark Lawrence

On 18/11/2013 16:55, roey.k...@gmail.com wrote:

On Monday, November 18, 2013 11:54:43 AM UTC-5, roey  wrote:

Thank you.  In looking over these classes, I see though that even them, I would 
run against the same limitations, though.



- Roey



On Monday, November 18, 2013 11:41:20 AM UTC-5, xDog Walker wrote:


On Monday 2013 November 18 07:47, roey wrote:







I am trying to build a replacement completer for python's Cmd class















These related packages may be of interest:















  http://pypi.python.org/pypi/rl







  http://pypi.python.org/pypi/kmd















--







Yonder nor sorghum stenches shut ladle gulls stopper torque wet







strainers.


*even with them



Would you please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing above, thanks.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Program Translation - Nov. 14, 2013

2013-11-18 Thread E.D.G.
Terry Reedy tjre...@udel.edu wrote in message 
news:mailman.2820.1384745298.18130.python-l...@python.org...



A couple of sentences of follow-up would have been sufficient.


  The experience that I have had over the years with Newsgroup posting 
is that it is generally better to try to be polite and answer as many 
questions as possible even when that results in more information being 
posted than might be necessary.  Hopefully a discussion will then end 
quietly on a pleasant note.


  That approach seems to usually produce good results.  Quite often 
people who are happy with the tone of the public Newsgroup discussion will 
send along some valuable information by E-mail.  And that has been happening 
with this present discussion that will now continue in only the Fortran 
Newsgroup.


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


Re: Program Translation - Nov. 14, 2013

2013-11-18 Thread E.D.G.
Joel Goldstick joel.goldst...@gmail.com wrote in message 
news:mailman.2792.1384709379.18130.python-l...@python.org...


That being said, I'm guessing that this thing is used in some academic

setting.  If that's true, why not get a student (who will be much more
versed in modern programming languages and techniques) to document and
rewrite the code.  When you start off with the requirement that the


  True BASIC appears to do calculations at a speed that is probably 
somewhere in the Fortran range.  And as I stated, since someone volunteered 
to do some modernization work he gets to select whatever language he 
prefers.  Also as I stated, I am now starting some discussions with 
scientists who actually use these types of data on a regular basis in order 
to get some input from them.  Perhaps they might want to have some of their 
own programmers modernize the code.


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


Re: Program Translation - Nov. 14, 2013

2013-11-18 Thread Joel Goldstick
On Mon, Nov 18, 2013 at 12:15 PM, E.D.G. edgrs...@ix.netcom.com wrote:
 Terry Reedy tjre...@udel.edu wrote in message
 news:mailman.2820.1384745298.18130.python-l...@python.org...


 A couple of sentences of follow-up would have been sufficient.


   The experience that I have had over the years with Newsgroup posting
 is that it is generally better to try to be polite and answer as many
 questions as possible even when that results in more information being
 posted than might be necessary.  Hopefully a discussion will then end
 quietly on a pleasant note.

   That approach seems to usually produce good results.  Quite often
 people who are happy with the tone of the public Newsgroup discussion will
 send along some valuable information by E-mail.  And that has been happening
 with this present discussion that will now continue in only the Fortran
 Newsgroup.

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

This is just plain senseless.  Is the op a Bot?

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


Re: Building a tree-based readline completer

2013-11-18 Thread xDog Walker
On Monday 2013 November 18 09:13, Mark Lawrence wrote:
 On 18/11/2013 16:55, roey.k...@gmail.com wrote:
  On Monday, November 18, 2013 11:54:43 AM UTC-5, roey  wrote:
  Thank you.  In looking over these classes, I see though that even them,
[snip]

 Would you please read and action this
 https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the
 double line spacing above, thanks.

I am going to prevent seeing your repetition of each of these messages 
by killfiling you.


 --
 Python is the second best programming language in the world.
 But the best has yet to be invented.  Christian Tismer

You sig is, imho, nonsensical.


 Mark Lawrence

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.


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


Re: sendmail library ?!

2013-11-18 Thread Grant Edwards
On 2013-11-18, Tim Roberts t...@probo.com wrote:
 Tamer Higazi th9...@googlemail.com wrote:

I am looking for a python library that does mailing directly through
sendmail.

When I look into the docs, I see only an smtlip library but nothing
that could serve with sendmail or postfix.

Any ideas ?!

 Remember that
import smtplib
s = smtplib.SMTP(localhost)
 usually communicates directly with the local server, whether it be sendmail
 or postfix or whatever.

It's not uncommon for a machine that doesn't receive mail to have
sendmail/postfix/whatever installed for the purpose of sending mail
only. In that case, there might not be anybody listening on
(localhost,smtp). The traditional way to send mail on a Unix system is
to invoke the 'sendmail' command with appropriate command-line
arguments and then shove the message into sendmail's stdin.  

It's pretty trivial -- here's a simple sendmail library:

def sendmail(frm,to,msg):
with os.popen(sendmail -f '%s' '%s' % (frm,to), w) as p:
p.write(msg)

That works on my system, but YMMV. You might like more options (like
automagically parsing frm/to address from msg headers or whatnot), and
those are left as an exercise for the reader.

-- 
Grant Edwards   grant.b.edwardsYow! Did an Italian CRANE
  at   OPERATOR just experience
  gmail.comuninhibited sensations in
   a MALIBU HOT TUB?
-- 
https://mail.python.org/mailman/listinfo/python-list


Glade Survey

2013-11-18 Thread Juan Pablo Ugarte

Hello everybody!

We (Glade Developers) are conducting a user survey which will help us take 
informed decisions to improve the overall developer experience.

So please take a few minutes to complete the survey, we appreciate it!

https://glade.gnome.org/registration.html


Cheers

Juan Pablo, on behalf of the Glade team



What is Glade?

Glade is a RAD tool to enable quick  easy development of user
interfaces for the GTK+ [1] toolkit and the GNOME [2] desktop
environment.

The user interfaces designed in Glade are saved as XML, and by using the
GtkBuilder [3] GTK+ object these can be loaded by applications
dynamically as needed.

By using GtkBuilder, Glade XML files can be used in numerous programming
languages [4] including C, C++, C#, Vala, Java, Perl, Python,and others.

Glade is Free Software released under the GNU GPL License [5]

[1] http://www.gtk.org/
[2] http://www.gnome.org/
[3] http://library.gnome.org/devel/gtk/stable/GtkBuilder.html
[4] http://www.gtk.org/language-bindings.php
[5] http://www.fsf.org/licensing/licenses/gpl.html





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


Re: Byteorder of audioop functions

2013-11-18 Thread Serhiy Storchaka

18.11.13 18:51, Michael Schwarz написав(ла):

Is the byteorder (or endianness) of the functions in the audioop module 
somewhere specified or does anyone know how it behaves on different systems?

On my little-endian system it matches the system's endianness:


It always matches the system's endianness.


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


Re: The Name of Our Religion Is Islam

2013-11-18 Thread John Ladasky
On Monday, November 18, 2013 8:52:06 AM UTC-8, BV BV wrote:
 The Name of Our Religion Is Islam

Incorrect.  The name of YOUR religion is apparently Spam.

I have been flagging your posts.  They do not belong in comp.lang.python.  
Please find a forum which discusses religion.  Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Wing IDE 5.0 released

2013-11-18 Thread Wingware

Hi,

Wingware has released version 5.0 of Wing IDE, our integrated development
environment designed specifically for the Python programming language.

Wing IDE provides a professional quality code editor with vi, emacs, and 
other
key bindings, auto-completion, call tips, refactoring, context-aware 
auto-editing,
a powerful graphical debugger, version control, unit testing, search, 
and many

other features.  For details see http://wingware.com/

This new major release includes:

* Now runs native on OS X
* Draggable tools and editors
* Configurable toolbar and editor  project context menus
* Optionally opens a different sets of files in each editor split
* Lockable editor splits
* Optional Python Turbo completion (context-appropriate completion 
on all non-symbol keys)

* Sharable color palettes and syntax highlighting configurations
* Auto-editing is on by default (except some operations that have a 
learning curve)

* Named file sets
* Sharable launch configurations
* Asynchronous I/O in Debug Probe and Python Shell
* Expanded and rewritten tutorial
* Preliminary support for Python 3.4

For details see http://wingware.com/wingide/whatsnew

For a complete change log see 
http://wingware.com/pub/wingide/5.0.0/CHANGELOG.txt


Free trial: http://wingware.com/wingide/trial
Downloads: http://wingware.com/downloads
Feature matrix: http://wingware.com/wingide/features
More information: http://wingware.com/
Sales: http://wingware.com/store/purchase
Upgrades: https://wingware.com/store/upgrade

Questions?  Don't hesitate to email us at supp...@wingware.com.

Thanks,

--

Stephan Deibel
Wingware | Python IDE
Advancing Software Development

www.wingware.com
--
https://mail.python.org/mailman/listinfo/python-list


Why do only callable objects get a __name__?

2013-11-18 Thread John Ladasky
A few days ago, I asked about getting the original declared name of a function 
or method, and learned about the __name__ attribute.

https://groups.google.com/forum/#!topic/comp.lang.python/bHvcuXgvdfA

Of course, I have used __name__ for years in the common expression if __name__ 
== __main__) to determine whether a particular module is being run or merely 
imported.  But until recently, I never went deeper than that.

I just created an object using collections.namedtuple, and was surprised to 
discover that it didn't have a __name__ -- even though something that behaves 
like __name__ is clearly accessible and printable.  Here's some minimal Python 
3.3.2 code and output:

=

from collections import namedtuple

MyNamedTupleClass = namedtuple(ANamedTuple, (foo, bar))
nt = MyNamedTupleClass(1,2)
print(nt)
print(type(nt))
# print(nt.__name__) # this would raise an AttributeError
print(type(nt).__name__) # this is the desired output

=

ANamedTuple(foo=1, bar=2)
class '__main__.ANamedTuple'
ANamedTuple

=

As you can see, I snooped around in the object's type.  I found that the type, 
rather than the object itself, had the __name__ I was seeking.  I then read the 
Python docs concerning __name__ and found that this attribute is restricted to 
callable objects.  

This leads me to ask two questions:  

1. WHY do only callable objects get a __name__?  A __name__ would seem to be a 
useful feature for other types.  Clearly, whoever implemented namedtuple 
thought it was useful to retain and display that information as a part of the 
string representation of the namedtuple (and I agree).

2. If I created a superclass of namedtuple which exposed 
type(namedtuple).__name__ in the namespace of the namedtuple itself, would I be 
doing anything harmful?

Thanks as always for your insights.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Doc generation from annotated source code

2013-11-18 Thread Johannes Findeisen
On Mon, 18 Nov 2013 14:46:46 +0100
Laszlo Nagy wrote:

 I just started rewritting my project from python 2 to python 3. I 
 noticed that there are these new parameter and return value annotations. 
 I have docstrings everywhere in my project, but I plan to convert many 
 of them into annotations. The question is: what kind of auto documenting 
 system should I use for this? Previously I have used Sphinx. Is it okay 
 to use that for python 3 source code? Is there a better alternative?

The Python docs on http://docs.python.org/3/ are generated using Sphinx
so it seems OK to do so for Python 3... ;)

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Dave Angel
On 18 Nov 2013 14:30:54 GMT, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

- 15 bits for a length.


15 bits give you a maximum length of 32767. There are ways around 
that. 
E.g. a length of 0 through 32766 means exactly what it says; a 
length of 
32767 means that the next two bytes are part of the length too, 
giving 
you a maximum of 4294967295 characters per string. That's an 8GB 
string. 

Surely big enough for anyone :-)


If you use nearly all of the possible 2 byte values then adding 2 
more bytes won't give you anywhere near 4 bI'll ion characters. 
You're perhaps thinking of bringing in four more bytes when the 
length exceeds 32k.


--
DaveA

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


Re: Why do only callable objects get a __name__?

2013-11-18 Thread John Ladasky
On Monday, November 18, 2013 12:13:42 PM UTC-8, I wrote:

 2. If I created a superclass of namedtuple which exposed 
 type(namedtuple).__name__ in the namespace of the namedtuple itself, would I 
 be doing anything harmful?

Sigh.  Of course, that should read subclass, not superclass.  Because I was 
thinking of a type being, in a sense, higher up the object hierarchy than an 
instance, I accidentally reached for the wrong word.


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


Re: Why do only callable objects get a __name__?

2013-11-18 Thread Ian Kelly
On Mon, Nov 18, 2013 at 1:13 PM, John Ladasky
john_lada...@sbcglobal.net wrote:
 A few days ago, I asked about getting the original declared name of a 
 function or method, and learned about the __name__ attribute.

 https://groups.google.com/forum/#!topic/comp.lang.python/bHvcuXgvdfA

 Of course, I have used __name__ for years in the common expression if 
 __name__ == __main__) to determine whether a particular module is being run 
 or merely imported.  But until recently, I never went deeper than that.

 I just created an object using collections.namedtuple, and was surprised to 
 discover that it didn't have a __name__ -- even though something that behaves 
 like __name__ is clearly accessible and printable.  Here's some minimal 
 Python 3.3.2 code and output:

 =

 from collections import namedtuple

 MyNamedTupleClass = namedtuple(ANamedTuple, (foo, bar))
 nt = MyNamedTupleClass(1,2)
 print(nt)
 print(type(nt))
 # print(nt.__name__) # this would raise an AttributeError
 print(type(nt).__name__) # this is the desired output

 =

 ANamedTuple(foo=1, bar=2)
 class '__main__.ANamedTuple'
 ANamedTuple

 =

 As you can see, I snooped around in the object's type.  I found that the 
 type, rather than the object itself, had the __name__ I was seeking.  I then 
 read the Python docs concerning __name__ and found that this attribute is 
 restricted to callable objects.

 This leads me to ask two questions:

 1. WHY do only callable objects get a __name__?  A __name__ would seem to be 
 a useful feature for other types.  Clearly, whoever implemented namedtuple 
 thought it was useful to retain and display that information as a part of the 
 string representation of the namedtuple (and I agree).

Classes and functions are frequently kept in module namespaces, where
they are known by a specific name.  The intent is that the __name__
attribute should match that name by which it is commonly referred.

Specific instances are not typically widely referred to by set names
in this way.  They are more commonly stored in variables that are used
to hold a wide variety of objects.

In the namedtuple example that you give, it seems that you would want
the names of all instances of the ANamedTuple class to be the same
ANamedTuple, and I really don't see what the purpose of giving them
all the same name would be.

 2. If I created a superclass of namedtuple which exposed 
 type(namedtuple).__name__ in the namespace of the namedtuple itself, would I 
 be doing anything harmful?

Probably not.  But why not just invent your own name attribute rather
than shadow the one that Python designates for classes and functions?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building a tree-based readline completer

2013-11-18 Thread Dave Angel

On Mon, 18 Nov 2013 08:55:05 -0800 (PST), roey.k...@gmail.com wrote:

On Monday, November 18, 2013 11:54:43 AM UTC-5, roey  wrote:
 Thank you.  In looking over these classes, I see though that even 

them, I would run against the same limitations, though.

Please don't double space your quotes. And if googlegarbage is doing 
it for you, then use a less buggy way of posting.


--
DaveA

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


Re: Glade Survey

2013-11-18 Thread Gene Heskett
On Monday 18 November 2013 16:04:14 Juan Pablo Ugarte did opine:

 Hello everybody!
 
 We (Glade Developers) are conducting a user survey which will help us
 take informed decisions to improve the overall developer experience.
 
 So please take a few minutes to complete the survey, we appreciate it!
 
 https://glade.gnome.org/registration.html

Your certificate for https is invalid.  So I won't.
 
 
 Cheers
 
   Juan Pablo, on behalf of the Glade team
 
 
 
 What is Glade?
 
 Glade is a RAD tool to enable quick  easy development of user
 interfaces for the GTK+ [1] toolkit and the GNOME [2] desktop
 environment.
 
 The user interfaces designed in Glade are saved as XML, and by using the
 GtkBuilder [3] GTK+ object these can be loaded by applications
 dynamically as needed.
 
 By using GtkBuilder, Glade XML files can be used in numerous programming
 languages [4] including C, C++, C#, Vala, Java, Perl, Python,and others.
 
 Glade is Free Software released under the GNU GPL License [5]
 
 [1] http://www.gtk.org/
 [2] http://www.gnome.org/
 [3] http://library.gnome.org/devel/gtk/stable/GtkBuilder.html
 [4] http://www.gtk.org/language-bindings.php
 [5] http://www.fsf.org/licensing/licenses/gpl.html


Cheers, Gene
-- 
There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order.
-Ed Howdershelt (Author)

Communicate!  It can't make things any worse.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do only callable objects get a __name__?

2013-11-18 Thread John Ladasky
On Monday, November 18, 2013 12:43:28 PM UTC-8, Ian wrote:
 
 Classes and functions are frequently kept in module namespaces, where
 they are known by a specific name.  The intent is that the __name__
 attribute should match that name by which it is commonly referred.
 
 
 
 Specific instances are not typically widely referred to by set names
 
 in this way.  They are more commonly stored in variables that are used
 
 to hold a wide variety of objects.
 
 
 
 In the namedtuple example that you give, it seems that you would want
 the names of all instances of the ANamedTuple class to be the same
 ANamedTuple, and I really don't see what the purpose of giving them
 all the same name would be.

I am implementing a state machine.  The outputs of the various states in the 
machine have variable contents.  I started by making dictionaries for each 
state output, but I soon tired of the bracket-and-quote-mark syntax for 
referring to the contents of these state output dictionaries.  That's why I am 
switching to named tuples.  It doesn't affect the __name__ issue, since 
dictionaries also cannot be called.

I want to capture the names of the executed states in a record of the state 
machine's history.  This information is already encoded in the namedtuple's 
type.

  2. If I created a superclass of namedtuple which exposed 
  type(namedtuple).__name__ in the namespace of the namedtuple itself, would 
  I be doing anything harmful?
  
 Probably not.  

I just thought I would ask.

 But why not just invent your own name attribute rather
 than shadow the one that Python designates for classes and functions?

I will never write to this attribute, only read it.  And since the information 
I want is already there (albeit in a strange place), I am inclined to use it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do only callable objects get a __name__?

2013-11-18 Thread Terry Reedy

On 11/18/2013 3:13 PM, John Ladasky wrote:


Of course, I have used __name__ for years in the common expression if __name__ == 
__main__) to determine whether a particular module is being run or merely imported.


This true statement invalidates your subject line ;-). All modules have 
a __name__. The main module has the name (__name__) '__main__'. (A file 
named '__main__.py' also has special meaning. If one does 'python -m 
package' on a command line and 'package' is a directory with 
'__init__.py', 'package/__main__.py' is executed as the main module 
'__main__'.



1. WHY do only callable objects get a __name__?


Why do you think this? Is there a mistake in the doc?

--
Terry Jan Reedy

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


Re: Why do only callable objects get a __name__?

2013-11-18 Thread John Ladasky
On Monday, November 18, 2013 1:11:08 PM UTC-8, Terry Reedy wrote:
 On 11/18/2013 3:13 PM, John Ladasky wrote:
 
  Of course, I have used __name__ for years in the common expression if 
  __name__ == '__main__') to determine whether a particular module is being 
  run or merely imported.
 
 This true statement invalidates your subject line ;-). All modules have 
 a __name__. 

Yes, I thought about this before I posted.  I figured that, if I investigated 
further I would discover that there was a __main__ function that was being 
called.

  1. WHY do only callable objects get a __name__?
 
 Why do you think this? Is there a mistake in the doc?

Quote below from http://docs.python.org/3/reference/datamodel.html:

===

Callable types
These are the types to which the function call operation (see section Calls) 
can be applied:

User-defined functions
A user-defined function object is created by a function definition (see section 
Function definitions). It should be called with an argument list containing the 
same number of items as the function’s formal parameter list.

Special attributes:

Attribute   Meaning
__name__The function’s name Writable

===

Perhaps I'm inferring too much from slightly-vague documentation, and my recent 
experience with objects that cannot be called?  Or perhaps the information that 
I need to read is somewhere in the documentation other than where I have looked?

Still puzzling over this...  I can easily hack a solution as Terry suggested, 
but it's not elegant, and that kind of thing bugs me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] Pythonium Core 0.2.5

2013-11-18 Thread Amirouche Boubekki
2013/11/18 Amirouche Boubekki amirouche.boube...@gmail.com

 2013/11/17 Salvatore DI DIO salvatore.di...@gmail.com

 Are lists comprehensions are featured in Veloce ?


 Ah! Good question, I did not think about it can probably add it to Core.
 Thanks


It's done in last release, dubbed 0.3.0 just use pip to install it.

Also:

- fixed the test suite
- argument unpacking...
- generated code is now properly indented

I hope it's good enough.

Cheers,


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


Re: [Python-ideas] Unicode stdin/stdout

2013-11-18 Thread random832
On Mon, Nov 18, 2013, at 7:33, Robin Becker wrote:
 UTF-8 stuff

This doesn't really solve the issue I was referring to, which is that
windows _console_ (i.e. not redirected file or pipe) I/O can only
support unicode via wide character (UTF-16) I/O with a special function,
not via using byte-based I/O with the normal write function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: understanding someone else's program

2013-11-18 Thread Laurent Pointal
C. Ng wrote:

 Hi all,
 
 Please suggest how I can understand someone else's program where
 - documentation is sparse
 - in function A, there will be calls to function B, C, D and in those
 functions will be calls to functions R,S,T and so on so forth...
 making it difficult to trace what happens to a certain variable
 
 Am using ERIC4 IDE.

To help for documentation, you may test pycallgraph, eventually depgraph if 
there are multiple modules.


http://pycallgraph.slowchop.com/en/master/
http://www.tarind.com/depgraph.html

A+
Laurent.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: Doc generation from annotated source code

2013-11-18 Thread Ned Batchelder
On Monday, November 18, 2013 8:46:46 AM UTC-5, Laszlo Nagy wrote:
 I just started rewritting my project from python 2 to python 3. I 
 noticed that there are these new parameter and return value annotations. 
 I have docstrings everywhere in my project, but I plan to convert many 
 of them into annotations. The question is: what kind of auto documenting 
 system should I use for this? Previously I have used Sphinx. Is it okay 
 to use that for python 3 source code? Is there a better alternative?
 
 Thanks

If you don't know how to generate your docs yet, how have you decided that you 
want to change your docstrings into annotations?  Annotations have no standard 
semantics, so everyone using them is using them differently.

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


Re: Why do only callable objects get a __name__?

2013-11-18 Thread Steven D'Aprano
On Mon, 18 Nov 2013 12:13:42 -0800, John Ladasky wrote:

 I just created an object using collections.namedtuple, and was surprised
 to discover that it didn't have a __name__

I'm not sure why you're surprised. Most objects don't have names, 
including regular tuples:

py some_tuple = (23, 42)
py some_tuple.__name__
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'tuple' object has no attribute '__name__'



Remember, Python has two distinct concepts of names: the name that an 
object knows itself by, and the variable name that it is bound to. 
Objects may be bound to zero, one, or more variable names. Here are some 
examples of the later:

print 42  # zero name
x = 42  # one name
x = y = z = 42  # three names

It simply isn't practical or meaningful to go backwards from the object 
42 to the variable name(s) it is bound to -- in the first example, there 
is no variable name at all; in the third, there are three. Even if you 
wanted to do it, it would be a performance killer. So if you have any 
thought that the name of an object should be the name of the variable, 
scrub that from your head, it will never fly.

That leaves us with the name that objects know themselves by. For the 
rest of this post, any time I talk about a name, I always mean the name 
an object knows itself by, and never the variable name it is bound to (if 
there is such a variable name).

As a general rule, names aren't meaningful or useful for objects. To 
start with, how would you give it a name, what syntax would you use? What 
would you expect these examples to print?

import random
random.random().__name__

data = [23, 17, 99, 42]
print data[1].__name__


In general, objects are *anonymous* -- they have no inherent name. 
Instances come into being in all sorts of ways, they live, they die, 
they're garbage-collected by the compiler. They have no need for 
individual names, and no way to be given one.

But if you insist on giving them one, you can give it a go. But I 
guarantee that (1) you'll find it a lot less useful, and (2) a lot more 
inconvenient than you expected:

class NamedList(list):
def __new__(cls, name, *args):
obj = super(NamedList, cls).__new__(cls, *args)
obj.__name__ = name
return obj
def __init__(self, name, *args):
super(NamedList, self).__init__(*args)

py print NamedList(fred, [1, 2, 3, 4, 5]).__name__
fred


So it works, but what a drag, and you don't get much for the effort.

The three obvious exceptions are:

- modules
- classes/types
- functions/methods

In the first case, modules, there is an obvious interpretation of what 
the name ought to be: the filename minus the extension. Since the module 
knows where it came from, it can know it's own name:

py import re
py re.__name__
're'


Even if you bind the module object to a different variable name, it knows 
its own inherent name:

py import math as fibble
py print fibble.__name__
math


For functions and classes, such names are especially useful, for 
debugging and error messages:

py def one_over(x):
... return 1.0/x
...
py one_over(0)
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 2, in one_over
ZeroDivisionError: float division by zero


Notice the second last line, where it gives the function's name? That 
would be impossible if callables (functions, classes) didn't know their 
own name. You'd get something like:

File stdin, line 2, in function object at 0xb7ea7a04

which would be useless for debugging. So how fortunately that there is 
obvious and simple syntax for setting the name of functions and classes:

class This_Is_The_Class_Name:
def this_is_the_function_name(self): 
...



 -- even though something that
 behaves like __name__ is clearly accessible and printable.  Here's some
 minimal Python 3.3.2 code and output:
 
 =
 
 from collections import namedtuple
 
 MyNamedTupleClass = namedtuple(ANamedTuple, (foo, bar))

Here you define a class, called ANamedTuple. Unfortunately, it doesn't 
use the standard class syntax, a minor limitation and annoyance of 
namedtuples, and so you're forced to give the class name ANamedTuple 
explicitly as an argument to the function call. But the important thing 
here is that it is a class. 


 nt = MyNamedTupleClass(1,2)

nt, on the other hand, is a specific instance of that class. You might 
have hundreds, thousands, millions of such instances. Why would you want 
to name them all? What point of doing so is there? They have no need, and 
no benefit, to be given individual names. And consequent, when you ask 
the instance What's your name?, they respond I don't have one:

 # print(nt.__name__) # this would raise an AttributeError


However, when you ask the class ANamedTuple what its name it, it has a 
name, and can tell you:

 print(type(nt).__name__) # this is the desired output


If the instance nt claimed to be ANamedTuple, it 

Re: Oh look, another language (ceylon)

2013-11-18 Thread Tim Daneliuk

On 11/17/2013 04:33 PM, Gregory Ewing wrote:

Mark Lawrence wrote:


As a rule of thumb people don't like change?  This obviously assumes that 
language designers are people :)


That's probably true (on both counts).

I guess this means we need to encourage more
Pythoneers to become language designers!



Ahem, I already commented on this in some detail

   https://mail.python.org/pipermail/python-list/2004-September/241055.html

--

Tim Daneliuk tun...@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Chris Angelico
On Tue, Nov 19, 2013 at 1:30 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 I suppose that's not terrible, except for the O(n) string operations
 which is just dumb. Yes, it's better than buggy, broken strings. But
 still dumb, because those aren't the only choices. For example, for the
 sake of an extra two bytes at the start of each string, they could store
 a flag and a length:

True, but I suspect that _any_ variance from JS strings would have
significant impact on the performance of everything that crosses the
boundary. If anything, I'd be looking at a permanent 32-bit shim on
the string (rather than the 16-or-32-bit that you describe, or the
16-or-48-bit that Dave clarifies your theory as needing); that would
allow strings up to 2GB (31 bits of pure binary length), and exceeding
that could just raise a RuntimeError. Then, passing any string to a JS
method would simply mean trimming off the first two code units.

But the problem is also with strings coming back from JS. Every time
you get something crossing from JS to Ceylon, you have to walk it,
count up its length, and see if it has any surrogates (and somehow
deal with mismatched surrogates). Every string, even if all you're
going to do is give it straight back to JS in the next line of code.
Potentially quite expensive, and surprisingly so - as opposed to
simply saying string indexing can be slow on large strings, which
puts the cost against a visible line of code.

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


Re: Glade Survey

2013-11-18 Thread Chris Angelico
On Tue, Nov 19, 2013 at 8:04 AM, Gene Heskett ghesk...@wdtv.com wrote:
 On Monday 18 November 2013 16:04:14 Juan Pablo Ugarte did opine:

 Hello everybody!

 We (Glade Developers) are conducting a user survey which will help us
 take informed decisions to improve the overall developer experience.

 So please take a few minutes to complete the survey, we appreciate it!

 https://glade.gnome.org/registration.html

 Your certificate for https is invalid.  So I won't.

Invalid in what way? It looks fine to me. Or is it that you don't
trust its signer?

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


Re: Why do only callable objects get a __name__?

2013-11-18 Thread Steven D'Aprano
On Mon, 18 Nov 2013 13:02:26 -0800, John Ladasky wrote:

 I am implementing a state machine.  The outputs of the various states in
 the machine have variable contents.  I started by making dictionaries
 for each state output, but I soon tired of the bracket-and-quote-mark
 syntax for referring to the contents of these state output dictionaries.
  That's why I am switching to named tuples.  It doesn't affect the
 __name__ issue, since dictionaries also cannot be called.
 
 I want to capture the names of the executed states in a record of the
 state machine's history.  This information is already encoded in the
 namedtuple's type.


I find this rather confusing. Does every state have it's own unique 
namedtuple class?


state1 = namedtuple(State1, (x, y))(1, 2)
state2 = namedtuple(State2, (x, y))(5, 7)
state3 = namedtuple(State3, (x, y))(0, 2)
[...]

Seems excessive -- you're defining many classes, each one of which has 
only a single instance. I'd be more inclined to just use a class object 
directly, with a little helper function to handle the tedious bits:

def state(name, x, y):
class Inner(object):
pass
Inner.x = x
Inner.y = y
Inner.__name__ = Inner.name = name
return Inner


And in use:

py state1 = state('state1', 100, 101)
py state1
class '__main__.state1'
py state1.name
'state1'
py state1.x
100


But I don't really understand how you are using these state objects, so 
I'm not sure if this is appropriate or not.


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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Mark Lawrence

On 17/11/2013 22:48, Tim Daneliuk wrote:

On 11/17/2013 04:33 PM, Gregory Ewing wrote:

Mark Lawrence wrote:


As a rule of thumb people don't like change?  This obviously assumes
that language designers are people :)


That's probably true (on both counts).

I guess this means we need to encourage more
Pythoneers to become language designers!



Ahem, I already commented on this in some detail


https://mail.python.org/pipermail/python-list/2004-September/241055.html



Fantastic, very promising indeed.  I know it needs bringing up to date, 
but to make it fly can I safely assume that we'll be seeing a PEP fairly 
shortly?


As an aside, I noticed that the previous message was negative stride 
list slices, why do I have a strong sense of deja vu?


I refuse to mention another message that I noticed whilst browsing, on 
the grounds that I don't want to be accused of multiple manslaughter by 
way of causing heart attacks :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: RapydScript : Python to Javascript translator

2013-11-18 Thread Dan Stromberg
On Sun, Nov 17, 2013 at 11:16 AM, Salvatore DI DIO 
salvatore.di...@gmail.com wrote:

 Hello,

 If someone  is interested about a fast Python to Javascript translator
 (not a compiler like Brython which is another beast)

RapydScript is interesting.

Here's a comparison of several Python-in-a-browser technologies, including
RapydScript and RapydScript II:
http://stromberg.dnsalias.org/~dstromberg/pybrowser/python-browser.html
-- 
https://mail.python.org/mailman/listinfo/python-list


How can I get the variable to subtract the input please?

2013-11-18 Thread Ed Taylor
This will be very simple to most of you I guess but it's killing me!

print (Please type in your age)
age =  input ()
leave = 16
print (You have + leave - age + years left at school)

I want to have an input where the users age is inserted and then subtracted 
from the variable age which is set to 16 and the answer displayed as You have x 
years left at school.

Help much appreciated.

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


Re: sendmail library ?!

2013-11-18 Thread Dan Stromberg
On Tue, Nov 12, 2013 at 8:52 PM, Tamer Higazi th9...@googlemail.com wrote:

 Hi people!

 I am looking for a python library that does mailing directly through
 sendmail.


I use:
http://stromberg.dnsalias.org/svn/mailer/trunk/mailer.py
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I get the variable to subtract the input please?

2013-11-18 Thread Andrew Berg
On 2013.11.18 17:56, Ed Taylor wrote:
 This will be very simple to most of you I guess but it's killing me!
 
 print (Please type in your age)
 age =  input ()
 leave = 16
 print (You have + leave - age + years left at school)
 
 I want to have an input where the users age is inserted and then subtracted 
 from the variable age which is set to 16 and the answer displayed as You have 
 x years left at school.
 
 Help much appreciated.
 
 Thank you
 
You provided a short code snippet to help describe your problem, which is good, 
but you omitted what happened and what you expected. You
also didn't mention which version of Python you're using (I am going to assume 
some 3.x; if you are using 2.x, I *strongly* recommend
switching to 3.x unless you have a very compelling reason not to). If a 
traceback is printed, try to make sense of it, and if you can't,
post it in its entirety and ask us to explain it.
From what I can tell, you are trying to mix integers with strings. Python is 
strongly typed; it won't try to guess what you want when you
try to do things that make no sense for a given type. input() returns a string 
and you have defined leave as an integer. Using the +
operator to concatenate makes sense for strings, but it makes sense to do 
addition when dealing with number types like integers and floats.
If you try to do something silly like add a number to a string, Python will 
complain because it doesn't know what to do (and again, it won't
try to guess). With that in mind, rewrite the code so that you do number 
operations on numbers and string operations on strings.
Hint: there are builtin functions to cast between types.
Hint 2: it's a good idea to split up operations to separate lines so that it's 
easy to see which operation has a problem if there is one.

-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 10.0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I get the variable to subtract the input please?

2013-11-18 Thread alex23

On 19/11/2013 9:56 AM, Ed Taylor wrote:

This will be very simple to most of you I guess but it's killing me!

print (Please type in your age)
age =  input ()
leave = 16
print (You have + leave - age + years left at school)

I want to have an input where the users age is inserted and then subtracted 
from the variable age which is set to 16 and the answer displayed as You have x 
years left at school.

Help much appreciated.


Hey there,

When asking code questions, if you get a traceback it's often handy to 
include it so we can see exactly what problem you've hit.


Luckily, it's pretty obvious here:

1. input() binds a string to 'age', whereas 'leave' is an integer; you 
cannot subtract a string from an integer, you need to turn the string 
into an integer first. Try:


age = int(input())

2. With this done, you still have a similar issue: 'leave - age' 
produces an integer, and you cannot concatenate strings  integers. You 
can use string formatting to take care of this:


print(You have {} years left at school.format(leave - age))

There's a lot more to formatting than this, make sure to check out the 
docs for it:


http://docs.python.org/3.1/library/string.html#format-string-syntax

Hope this helps.

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Tim Daneliuk

On 11/18/2013 05:51 PM, Mark Lawrence wrote:

can I safely assume that we'll be seeing a PEP fairly shortly?



For Immediate Press Release:


We at TundraWare are now entering our 10th year of debate in the YAPDL
design as to what ought to be a statement and what ought to be a function.
The Statementists are currently winning 3 bouts to 2 over the
Functionists but there is much more gnashing of teeth and wringing of
hands to come. We remain true to the original vision of the language as
an unwanted appendage to Python which will promote fractionalisation and
thus improve opportunity for future billings.

We are also contemplating an offshoot language that melds the best of Java
into YAPDL.  Known as JAPDL (Jah.piddle) it is targeted particularly
to Rastafri programmers worldwide.  The primary contribution of JAPDL
to the language arts is the replacement of the  GIL (Global Interpreter Lock)
with the much simpler, DR (Dread Lock).

Tim Daneliuk tun...@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

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


Re: Building a tree-based readline completer

2013-11-18 Thread roey . katz
 On Mon, 18 Nov 2013 08:55:05 -0800 (PST), roey.k...@gmail.com wrote:
  On Monday, November 18, 2013 11:54:43 AM UTC-5, roey  wrote:
   Thank you.  In looking over these classes, I see though that even 
 them, I would run against the same limitations, though.
 Please don't double space your quotes. And if googlegarbage is doing 
 it for you, then use a less buggy way of posting.
 -- 
 DaveA

Alright.  Now, after the past three emails of going around my question, can 
anyone actually address it?

Thanks again!
- Roey
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I get the variable to subtract the input please?

2013-11-18 Thread Amit Saha
On Tue, Nov 19, 2013 at 9:56 AM, Ed Taylor edtaylo...@gmail.com wrote:
 This will be very simple to most of you I guess but it's killing me!

 print (Please type in your age)
 age =  input ()
 leave = 16
 print (You have + leave - age + years left at school)

 I want to have an input where the users age is inserted and then subtracted 
 from the variable age which is set to 16 and the answer displayed as You have 
 x years left at school.

I assume you are using Python 3. In that case, the input() function
always returns a string:

 age = input()
10
 age
'10'
 age - 10
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unsupported operand type(s) for -: 'str' and 'int'

And hence you cannot perform a subtraction operation. You will have to
convert the input into a data type such as an integer or a float and
then try to do any mathematical operation:

 int(age) - 10
0
 float(age)-10
0.0

Hope that helps.

Best,
Amit.


-- 
http://echorand.me
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Oh look, another language (ceylon)

2013-11-18 Thread Steven D'Aprano
On Tue, 19 Nov 2013 10:25:00 +1100, Chris Angelico wrote:

 But the problem is also with strings coming back from JS. 

Just because you call it a string in Ceylon, doesn't mean you have to 
use the native Javascript string type unchanged.

Since the Ceylon compiler controls what Javascript operations get called 
(the user never writes any Javascript directly), the compiler can tell 
which operations potentially add surrogates. Since strings are immutable 
in Ceylon, a slice of a BMP-only string is also BMP-only; concatenating 
two BMP-only strings gives a BMP-only string. I expect that uppercasing 
or lowercasing such strings will also keep the same invariant, but if 
not, well, you already have to walk the string to convert it, walking it 
again should be no more expensive.

The point is not that my off-the-top-of-my-head pseudo-implementation was 
optimal in all details, but that *text strings* should be decent data 
structures with smarts, not dumb arrays of variable-width characters. If 
that means avoiding dumb-array-of-char naive implementations, and writing 
your own, that's part of the compiler writers job.

Python strings can include null bytes, unlike C, even when built on top 
of C. They know their length, unlike C, even when built on top of C. Just 
because the native Java and Javascript string types doesn't do these 
things, doesn't mean that they can't be done in Javascript.


 - as opposed to simply saying string
 indexing can be slow on large strings, which puts the cost against a
 visible line of code.

For all we know, Ceylon already does something like this, but merely 
doesn't advertise the fact that while it *can* be slow, it can *also* be 
fast. It's an implementation detail, perhaps, much like string 
concatenation in Python officially requires building a new string, but in 
CPython sometimes it can append to the original string.


Still, given that Pike and Python have already solved this problem, and 
have O(1) string indexing operations and length for any Unicode string, 
SMP and BMP, it is a major disappointment that Ceylon doesn't.



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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Steven D'Aprano
On Mon, 18 Nov 2013 15:37:12 -0500, Dave Angel wrote:

 If you use nearly all of the possible 2 byte values then adding 2 more
 bytes won't give you anywhere near 4 bI'll ion characters. You're
 perhaps thinking of bringing in four more bytes when the length exceeds
 32k.

Yep, I screwed up. Thanks for the correction.


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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Chris Angelico
On Tue, Nov 19, 2013 at 1:13 PM, Steven D'Aprano st...@pearwood.info wrote:
 Still, given that Pike and Python have already solved this problem, and
 have O(1) string indexing operations and length for any Unicode string,
 SMP and BMP, it is a major disappointment that Ceylon doesn't.

And of course, the part that's solved here is not the O(1) string
indexing, but the fact that UTF-32 semantics with less memory usage
than UTF-16. It's easy to get perfect indexing semantics if you don't
mind how much space your strings take up.

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Chris Angelico
On Tue, Nov 19, 2013 at 1:13 PM, Steven D'Aprano st...@pearwood.info wrote:
 On Tue, 19 Nov 2013 10:25:00 +1100, Chris Angelico wrote:

 But the problem is also with strings coming back from JS.

 Just because you call it a string in Ceylon, doesn't mean you have to
 use the native Javascript string type unchanged.

Indeed not, but there are going to be many MANY cases where a JS
string has to become a Ceylon string and vice versa - a lot more often
than CPython drops to C. For instance, suppose you run your Ceylon
code inside a web browser. Pick up pretty much any piece of JavaScript
code from any web page - how much string manipulation does it do, and
how much does it call on various DOM methods? In CPython, only a small
number of Python functions will end up dropping to C APIs to do their
work (and most of those will have to do some manipulation along the
way somewhere - eg chances are print()/sys.stdout.write() will
eventually have to encode its output to 8-bit before passing it to
some byte-oriented underlying stream, so the actual representation of
a Python string doesn't matter); in browser-based work, that is
inverted.

However, Ceylon can actually be implemented on multiple backends (Java
and JavaScript listed). It's fully possible that an
application-oriented backend might use Pike-strings internally,
while a browser-oriented backend could still use the underlying
string representation. The questions are entirely of performance,
since it's been guaranteed already to have the same semantics.

I would really like to see JavaScript replaced in web browsers, since
the ECMAScript folks have stated explicitly (in response to a question
from me) that UTF-16 representation *must* stay, for backward compat.
JS is a reasonable language - it's not terrible - but it has a number
of glaring flaws. Ceylon could potentially be implemented in browsers,
using Pike-strings internally, and then someone could write a
JavaScript engine that compiles to Ceylon (complete with
bug-compatibility stupid-code that encodes all strings UTF-16 before
indexing into them). It would be an overall improvement, methinks.

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


Re: Oh look, another language (ceylon)

2013-11-18 Thread Rick Johnson
I've never *really* been crazy about the plus operator
concatenating strings anyhow, however, the semantics of +
seem to navigate the perilous waters of intuition far
better than *.

Addition of numeric types is well defined in maths:
Take N inputs values and *reduce* them into a single
value that represents the mathematical summation of
all inputs.

HOWEVER, 

Addition of strings (concatenation) requires
interpreting the statement as a more simplistic
joining process of : take N inputs and join them
together in a *linear fashion* until they become a
single value.

As you might already know the latter is a far less elegant
process, although the transformation remains sane. Even
though in the first case: with numeric addition, the
individual inputs are *sacrificed* to the god of maths; and
in the second case: for string addition, the individual
inputs are *retained*; BOTH implementations of the plus
operator expose a CONSISTENT interface -- and like any good
interface the dirty details are hidden from the caller!

INTERFACES ARE THE KEY TO CODE INTEGRITY and LONGEVITY!

HOWEVER, HOWEVER. O:-)

There is an inconsistency when applying the * operator
between numerics and strings. In the case of numerics the
rules are widely understood and quite logical, HOWEVER, in
the case of string products, not only are rules missing,
any attempt to create a rule is illogical, AND, we've broken
the consistency of the * interface!

py a * 4
''

Okay, that makes sense, but what about:

py a * 

That will haunt your nightmares!

But even the previous example, whilst quite logical, is
violating the contract of transformations and can ONLY
result in subtle bugs, language designer woes, and endless
threads on Pyhon-ideas that result in no elegant solution.

THERE EXISTS NO PATH TO ELEGANCE VIA GLUTTONY

Operator overloading must be restricted. Same goes for
syntactic sugars. You can only do SO much with a sugar
before it mutates into a salt.

TOO MUCH OF A GOOD THING... well, ya know!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Automation

2013-11-18 Thread David Robinow
On Mon, Nov 18, 2013 at 11:49 AM, Grant Edwards invalid@invalid.invalid wrote:
 ...
 I don't make those mistakes typing on a phone (where I have to
 actually think about the act of typing), but I do make them with a
 regular keyboard, where I don't have to think about mechanics of
 typing the words.

 OTOH, maybe that's just me...
It's me too. I certainly know the difference between 'there' and
'their', etc. but that fact is not always reflected in my typing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: grammar (was Re: Automation)

2013-11-18 Thread Mark Lawrence

On 16/11/2013 17:02, Paul Smith wrote:

On Sat, 2013-11-16 at 10:11 -0500, Roy Smith wrote:

In article mailman.2714.1384611545.18130.python-l...@python.org,
  William Ray Wing w...@mac.com wrote:


And my personal peeve -  using it's (contraction) when its (possessive)
should have been used; occasionally vice-versa.



And one of mine is when people write, Here, here! to signify
agreement.  What they really mean to write is, Hear, hear!, meaning,
Listen to what that person said.


The one that really irks me is people using loose when they mean
lose.  These words are not related, and they don't sound the same.
Plus this mistake is very common; I typically see it at least once a
day.



Somebody published a link to this poem some months back, I think it's 
worth repeating http://www.i18nguy.com/chaos.html


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Glade Survey

2013-11-18 Thread Juan Pablo Ugarte
On Mon, 2013-11-18 at 16:04 -0500, Gene Heskett wrote:
 On Monday 18 November 2013 16:04:14 Juan Pablo Ugarte did opine:
 
  Hello everybody!
  
  We (Glade Developers) are conducting a user survey which will help us
  take informed decisions to improve the overall developer experience.
  
  So please take a few minutes to complete the survey, we appreciate it!
  
  https://glade.gnome.org/registration.html
 
 Your certificate for https is invalid.  So I won't.

I do not have control over the web server at gnome, I only have access
to glade.gnome.org

It is true that it is not supplying owner information I guess it should
say GNOME Foundation, in any case gnome.org has they same problem so I
will contact the web administrators to notify them about the situation.

thanks

Juan Pablo


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


Re: Glade Survey

2013-11-18 Thread Gene Heskett
On Monday 18 November 2013 20:43:24 Chris Angelico did opine:

 On Tue, Nov 19, 2013 at 8:04 AM, Gene Heskett ghesk...@wdtv.com wrote:
  On Monday 18 November 2013 16:04:14 Juan Pablo Ugarte did opine:
  Hello everybody!
  
  We (Glade Developers) are conducting a user survey which will help us
  take informed decisions to improve the overall developer experience.
  
  So please take a few minutes to complete the survey, we appreciate
  it!
  
  https://glade.gnome.org/registration.html
  
  Your certificate for https is invalid.  So I won't.
 
 Invalid in what way? It looks fine to me. Or is it that you don't
 trust its signer?
 
 ChrisA

Firefox barked at me.  So I backed away.  And now it works.  Phase of moon 
sensitive?  Chew in wrong side of mouth?  Or you fixed it. :)

Cheers, Gene
-- 
There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order.
-Ed Howdershelt (Author)

If you give Congress a chance to vote on both sides of an issue, it
will always do it.
-- Les Aspin, D., Wisconsin
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Beginner

2013-11-18 Thread Gregory Ewing

On Monday, November 18, 2013 5:42:22 AM UTC+1, Terry Reedy wrote:


On 11/17/2013 11:02 PM, ngangsia akumbo wrote:



We don't even have a University that offer a full flesh computer
science course



The phrase you are looking for is 'full-fledged'.


He might have meant fully fleshed-out, i.e. complete.

Or it might be an adults-only computer science course. :-)

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


Re: [Python-ideas] Unicode stdin/stdout

2013-11-18 Thread Andrew Barnert
From: random...@fastmail.us random...@fastmail.us



 On Mon, Nov 18, 2013, at 7:33, Robin Becker wrote:
  UTF-8 stuff
 
 This doesn't really solve the issue I was referring to, which is that
 windows _console_ (i.e. not redirected file or pipe) I/O can only
 support unicode via wide character (UTF-16) I/O with a special function,
 not via using byte-based I/O with the normal write function.


The problem is that Windows 16-bit I/O doesn't fit into the usual io module 
hierarchy. Not because it uses an encoding of UTF-16 (although anyone familiar 
with ReadConsoleW/WriteConsoleW from other languages may be a bit confused that 
Python's lowest-level wrappers around them deal in byte counts instead of WCHAR 
counts), but because you have to use HANDLEs instead of fds. So, there are 
going to be some compromises and some complexity.

One possibility is to use as much of the io hierarchy as possible, but not try 
to make it flexible enough to be reusable for arbitrary HANDLEs: Add 
WindowsFileIO and WindowsConsoleIO classes that implement RawIOBase with a 
native HANDLE and ReadFile/WriteFile and ReadConsoleW/WriteConsoleW 
respectively. Both work in terms of bytes (which means WindowsConsoleIO.read 
has to //2 its argument, and write has to *2 the result). You also need a 
create_windows_io function that wraps a HANDLE by calling GetConsoleMode and 
constructing a WindowsConsoleIO or WindowsFileIO as appropriate, then creates a 
BufferedReader/Writer around that, then constructs a TextIOWrapper with UTF-16 
or the default encoding around that. At startup, you just do that for the three 
GetStdHandle handles, and that's your stdin, stdout, and stderr.

Besides not being reusable enough for people who want to wrap HANDLEs from 
other libraries or attach to new consoles from Python, it's not clear what 
fileno() should return. You could fake it and return the MSVCRT fds that 
correspond to the same files as the HANDLEs, but it's possible to end up with 
one redirected and not the other (e.g., if you detach the console), and I'm not 
sure what happens if you mix and match the two. A more correct solution would 
be to call _open_osfhandle on the HANDLE (and then keep track of the fact that 
os.close closes the HANDLE, or leave it up to the user to deal with bad handle 
errors?), but I'm not sure that's any better in practice. Also, should a 
console HANDLE use _O_WTEXT for its fd (in which case the user has to know that 
he has a _O_WTEXT handle even though there's no way to see that from Python), 
or not (in which case he's mixing 8-bit and 16-bit I/O on the same file)?

It might be reasonable to just not expose fileno(); most code that wants the 
fileno() for stdin is just going to do something Unix-y that's not going to 
work anyway (select it, tcsetattr it, pass it over a socket to another file, …).

A different approach would be to reuse as _little_ of io as possible, instead 
of as much: Windows stdin/stdout/stderr could each be custom TextIOBase 
implementations that work straight on HANDLEs and don't even support buffer (or 
detach), much less fileno. That exposes even less functionality to users, of 
course. It also means we need a parallel implementation of all the buffering 
logic. (On the other hand, it also leaves the door open to expose some Windows 
functionality, like async ReadFileEx/WriteFileEx, in a way that would be very 
hard through the normal layers…)


It shouldn't be too hard to write most of these via an extension module or 
ctypes to experiment with it. As long as you're careful not to mix 
winsys.stdout and sys.stdout (the module could even set sys.stdin, sys.stdout, 
sys.stderr=stdin, stdout, stderr at import time, or just del them, for a bit of 
protection), it should work.

It might be worth implementing a few different designs to play with, and 
putting them through their paces with some modules and scripts that do 
different things with stdio (including running the scripts with cmd.exe 
redirected I/O and with subprocess PIPEs) to see which ones have problems or 
limitations that are hard to foresee in advance.

If you have a design that you think sounds good, and are willing to experiment 
the hell out of it, and don't know how to get started but would be willing to 
debug and finish a mostly-written/almost-working implementation, I could slap 
something together with ctypes to get you started.
-- 
https://mail.python.org/mailman/listinfo/python-list


Cannot connect to Mysql database

2013-11-18 Thread Himanshu Garg
I have written the script as:

import os
import MySQLdb as mdb

os.chroot(/lxc/rootfs)
os.chdir(/)
con = mdb.connect(host=192.168.1.7, user=root, passwd=password)
print opened
con.close()

But when I execute, I get the following error:

File /usr/lib/python2.7/dist-packages/MySQLdb/__init__.py, line 80, in 
Connect
ImportError: No module named connections

I have checked there is a connections.py module in the above directory.  Also, 
when I run the script without doing chroot, it works perfectly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot connect to Mysql database

2013-11-18 Thread Chris Angelico
On Tue, Nov 19, 2013 at 5:03 PM, Himanshu Garg hgarg.in...@gmail.com wrote:
 I have written the script as:

 import os
 import MySQLdb as mdb

 os.chroot(/lxc/rootfs)
 os.chdir(/)
 con = mdb.connect(host=192.168.1.7, user=root, passwd=password)
 print opened
 con.close()

 But when I execute, I get the following error:

 File /usr/lib/python2.7/dist-packages/MySQLdb/__init__.py, line 80, in 
 Connect
 ImportError: No module named connections

 I have checked there is a connections.py module in the above directory.  
 Also, when I run the script without doing chroot, it works perfectly.

Do you have a full duplicate of your /usr/lib/python2.7 inside
/lxc/rootfs? It looks like the connect call is trying to import
something, and now that you're chrooted, it can't find it. The
solution might be to manually import a few more modules beforehand
(putting them into sys.modules means they don't need to come from the
file system), or to add more files to your chroot jail.

For a guess, I would try:

import MySQLdb.connections

above your chroot, and see if that helps.

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


  1   2   3   >