Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Steven D'Aprano
On Sunday 18 September 2016 15:59, Thorsten Kampe wrote:

> * Martin Schöön (17 Sep 2016 20:20:12 GMT)
>> 
>> Den 2016-09-17 skrev Kouli :
>> > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.
>> >
>> > Kouli
>> >
>> > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu  wrote:
>> >> Hi, I want to convert strings in which the characters with accents
>> >> should be converted to the ones without accents. Here is my current
>> >> code.
>> 
>> Side note from Sweden. Å, ä and ö are not accented characters in our
>> language. They are characters of their own.
> 
> I think he meant diacritics.

It doesn't matter whether you call them "accent" like most people do, or 
"diacritics" as linguists do. Either way, in some languages they are an 
integral part of the letter, like the horizonal stroke in English t or the 
vertical bar in English p and b, and in some languages they are modifiers, 
where there are rules that tell you how to write them without the modifier.

In English, i is a letter with a dot diacritic, sometimes called the "tittle". 
But unlike Turkish, we don't have a dotless i, ı, and to add to the confusion 
when we capitalise i we get I with no dot instead of İ. Dropping the dot, or 
adding one when you shouldn't, can *literally* get you killed:

http://gizmodo.com/382026/a-cellphones-missing-dot-kills-two-people-puts-three-
more-in-jail

http://www.theinquirer.net/inquirer/news/1017243/cellphone-localisation-glitch


As far as I know, no natural language has a dotted capital J, but there is a 
dotless ȷ although I'm not sure what language it is from. (Possibly just used 
in mathematics?)



-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Steven D'Aprano
On Sunday 18 September 2016 13:30, Peng Yu wrote:

> On Sat, Sep 17, 2016 at 3:20 PM, Martin Schöön 
> wrote:
>> Den 2016-09-17 skrev Kouli :
>>> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.
> 
> I don't find a way to make it print oe for ö. Could anybody please
> advise what is the correct way to do it?

In general, there is no One Correct Way to translate accented characters into 
ASCII. It depends on the language, and the word.

For instance, in English ö will usually be translated into just o with no 
accent. We usually write coöperate and zoölogy as cooperate and zoology, or 
sometimes with a hyphen co-operate, but never cooeperate or zooelogy. But if 
the word is derived from German, or words that *look* like they might be 
German, we do sometimes use oe: Roentgen rays (an old term for x-rays) after 
Wilhelm Röntgen, for instance.

But in other languages the rules will be different. How, for example, should 
one translate an Estonian word containing ö into Turkish, but using ASCII 
letters only? I have no idea. But in both languages, and unlike German, ö is 
*not* considered an o-with-an-accent, but a distinct letter of the alphabet.

https://en.wikipedia.org/wiki/Diaeresis_%28diacritic%29


As far as Python goes, if all you want to do is replace ö with oe and Ö into OE 
(or perhaps you should use Œ and œ?) then you can use str.replace or 
string.translate:

mystring.replace("Ö", "OE").replace("ö", "oe")




-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


Re: How to convert 'ö' to 'oe' or 'o' (or other si =?utf-8?Q?milar_things)_in_a_string??=

2016-09-17 Thread Thorsten Kampe
* Martin Schöön (17 Sep 2016 20:20:12 GMT)
> 
> Den 2016-09-17 skrev Kouli :
> > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.
> >
> > Kouli
> >
> > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu  wrote:
> >> Hi, I want to convert strings in which the characters with accents
> >> should be converted to the ones without accents. Here is my current
> >> code.
> 
> Side note from Sweden. Å, ä and ö are not accented characters in our 
> language. They are characters of their own.

I think he meant diacritics.

Thorsten

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


Re: how to automate java application in window using python

2016-09-17 Thread Steven D'Aprano
On Sunday 18 September 2016 14:53, Lawrence D’Oliveiro wrote:

> On Sunday, September 18, 2016 at 4:11:49 PM UTC+12, Gregory Ewing wrote:
>> The term "automation" is frequently used in the Windows world to mean
>> programming something that you would otherwise do manually through a GUI...
> 
> Which is not something that GUIs are designed for. Therefore it is at best an
> unreliable exercise, at worst futile.

Cheese is not designed to be grated and put on spaghetti. Therefore grating 
cheese is at best an unreliable exercise, at worst futile.

Can you see the fallacy in your assertion yet? Do I have to spell it out for 
you?

In any case, there are many software applications for automating GUI apps. 
Contrary to your assertion, it works reliably.

https://duckduckgo.com/?q=gui+automation&ia=web

It would be astonishing if it didn't -- after all, GUI apps interact with the 
user not by magic, but via an event queue of mouse movements, clicks, key 
presses, etc. This queue is entirely under the control of the computer, which 
means a program can simulate a user moving the mouse, clicking, pressing keys, 
etc. There's no magic here.




-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


Re: Is the content available in the html doc available in help()?

2016-09-17 Thread eryk sun
On Sun, Sep 18, 2016 at 3:26 AM, Steve D'Aprano
 wrote:
> help() does *not* return the same documentation as on the website. The
> website usually includes a lot more detail.
>
> The help() function introspects the python source code and formats the
> docstrings found, so it will often be very much smaller.

help() also uses a topics dict, from pydoc_data.topics, which gets
extracted when building the .rst docs. Check help('topics') and
help('keywords'). There's also help('symbols'), which lists the
punctuation symbols that help maps to various topics. For example,
help('**') gets mapped to help('POWER') and also prints a list of
related topics for the user, which includes "EXPRESSIONS" and
"OPERATORS" in this case.

Obviously modules in the standard library are documented in much more
detail in the python.org docs. pydoc_data would be gargantuan
otherwise. But I think there's actually enough info available in
help() that someone proficient in another language could use it to get
started programming in Python without any other documentation,
tutorials, or books.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-17 Thread Lawrence D’Oliveiro
On Sunday, September 18, 2016 at 4:11:49 PM UTC+12, Gregory Ewing wrote:
> The term "automation" is frequently used in the Windows world to mean
> programming something that you would otherwise do manually through a GUI...

Which is not something that GUIs are designed for. Therefore it is at best an 
unreliable exercise, at worst futile.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread eryk sun
On Sun, Sep 18, 2016 at 3:55 AM, Chris Angelico  wrote:
> On Sun, Sep 18, 2016 at 1:16 PM, Lawrence D’Oliveiro
>  wrote:
>> On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote:
>>> However, I see that MicroPython [1] has been ported to 16-bit
>>> PIC microcontrollers. An int should be 16-bit in that case.
>>>
>>> [1]: https://github.com/micropython/micropython
>>
>> From the readme: “MicroPython implements the entire Python 3.4 syntax...”
>>
>> Darn. I don’t know whether to applaud or grit my teeth...
>
> What do you mean? It's not perfectly up-to-date with respect to
> CPython, but most alternate implementations lag a bit.
>
> However, it doesn't appear to have an 'itemsize' on its array.
>
 a=array.array("l", (0,))
 dir(a)
> ['append', 'extend']
>
> Not sure what that means about its sizes.

MicroPython's array and struct modules use a common mp_binary_get_size function:

https://github.com/micropython/micropython/blob/v1.8.4/py/binary.c#L37

The array module uses native ("@") sizes, so the size of "i" and "I"
is sizeof(int).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-17 Thread Gregory Ewing

Lawrence D’Oliveiro wrote:

On Friday, September 16, 2016 at 10:22:34 PM UTC+12, Christian Gollwitzer
wrote:


"How do I automate a Java application using Python?"


Which is really a meaningless question. “Automation” is what computer
programs do.


It's not meaningless. The term "automation" is frequently
used in the Windows world to mean programming something that
you would otherwise do manually through a GUI, and that's
clearly the sense in which it's being used here.

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


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Chris Angelico
On Sun, Sep 18, 2016 at 1:16 PM, Lawrence D’Oliveiro
 wrote:
> On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote:
>> However, I see that MicroPython [1] has been ported to 16-bit
>> PIC microcontrollers. An int should be 16-bit in that case.
>>
>> [1]: https://github.com/micropython/micropython
>
> From the readme: “MicroPython implements the entire Python 3.4 syntax...”
>
> Darn. I don’t know whether to applaud or grit my teeth...

What do you mean? It's not perfectly up-to-date with respect to
CPython, but most alternate implementations lag a bit.

However, it doesn't appear to have an 'itemsize' on its array.

>>> a=array.array("l", (0,))
>>> dir(a)
['append', 'extend']

Not sure what that means about its sizes.

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


Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Chris Angelico
On Sun, Sep 18, 2016 at 1:08 PM, Peng Yu  wrote:
> The manual says the following.
>
> "The trace function is invoked (with event set to 'call') whenever a
> new local scope is entered; it should return a reference to a local
> trace function to be used that scope, or None if the scope shouldn’t
> be traced."
>
> It means that one can not somehow settrace in one line and expect to
> get the trace function being called in the next line.
>
> So something like `set -v` in bash sounds not possible. Is it so?

Can you predict in advance that you might be using this? If so, you
can define a trace function, and then activate and deactivate it on
command (in any way you like).

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


Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Steve D'Aprano
On Sun, 18 Sep 2016 07:19 am, Thomas 'PointedEars' Lahn wrote:

> AFAIK, “ä”, “ö”, and “ü” are not accented characters in any natural
> language, but characters of their own (umlauts).


Are you saying that English is not a natural language?





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Peng Yu
On Sat, Sep 17, 2016 at 3:20 PM, Martin Schöön  wrote:
> Den 2016-09-17 skrev Kouli :
>> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.

I don't find a way to make it print oe for ö. Could anybody please
advise what is the correct way to do it?

==> main.py <==
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import sys
from unidecode import unidecode
print unidecode(sys.argv[1].decode('utf-8'))


==> main.sh <==
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

./main.py Schöön

$ ./main.sh
Schoon

>> Kouli
>>
>> On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu  wrote:
>>> Hi, I want to convert strings in which the characters with accents
>>> should be converted to the ones without accents. Here is my current
>>> code.
>
> Side note from Sweden. Å, ä and ö are not accented characters in our
> language. They are characters of their own. If you want to look up
> someone called Öhman in the phone directory you go to the Ö section
> not the O section.
>
> Related anecdote from Phoenix AZ. By now you have noticed my family
> name: Schöön. On airline tickets and boarding passes in the U.S. it
> gets spelled Schoeoen. This landed me in a special security check
> once. After a while the youngish lady performing the search started
> to look like 1+1 did not sum up to 2. She looked at my passport
> and boarding pass again and asked why I was there with her. I pointed
> at another young lady, the one that 'scrutinized' passports and
> boarding passes while chatting with a friend and said "She told me
> to go over here." "Wait here, I have to talk to my supervisor."
>
> A few minutes passed (I was alone in the enhances security check
> throughout...) and then "I am sorry but you should not have had
> to go through here. There was a mistake."
>
> So there you are: If you are a middle aged, caucasian guy with
> a passport from northern Europe and no 'funny' letters in your name
> your are not a threat in the eyes of TSA in Arizona.
>
> Sorry for wasting the bandwidth.
>
> /Martin
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is the content available in the html doc available in help()?

2016-09-17 Thread Steve D'Aprano
On Sun, 18 Sep 2016 10:50 am, Peng Yu wrote:

> Hi, I want to get the same content as the html doc from help(). I am
> not sure if this is possible (as I tried help(inspect) which does not
> give the same content). Could anybody confirm if there is a way to get
> the same content from help()? Thanks.
> 
> https://docs.python.org/2/library/inspect.html


help() does *not* return the same documentation as on the website. The
website usually includes a lot more detail.

The help() function introspects the python source code and formats the
docstrings found, so it will often be very much smaller.

If you want a copy of the actual Python docs from the website, use a
third-party downloader to mirror the docs.python.org site. (On Linux, you
can use wget.) But before you do that, which is considered a bit rude, have
you checked *both* the Download and Documentation pages on the website to
see if there is a link to download the documentation?

Or you can get the .rst files from Python's source repository, then use
Sphinx to compile the .rst files to HTML.

If you are using Linux, your package manager (such as yum, apt-get or
similar) may have a package for the Python docs. Try `yum install
python-docs` or similar.


On the other hand, if you want help() to generate the documentation as a
HTML page, I don't think the help() function itself will do it, but the
pydoc module does. You can call pydoc from the shell prompt (NOT the Python
prompt, the shell):

pydoc --help


for details.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Lawrence D’Oliveiro
On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote:
> However, I see that MicroPython [1] has been ported to 16-bit
> PIC microcontrollers. An int should be 16-bit in that case.
> 
> [1]: https://github.com/micropython/micropython

From the readme: “MicroPython implements the entire Python 3.4 syntax...”

Darn. I don’t know whether to applaud or grit my teeth...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Peng Yu
The manual says the following.

"The trace function is invoked (with event set to 'call') whenever a
new local scope is entered; it should return a reference to a local
trace function to be used that scope, or None if the scope shouldn’t
be traced."

It means that one can not somehow settrace in one line and expect to
get the trace function being called in the next line.

So something like `set -v` in bash sounds not possible. Is it so?

On Sat, Sep 17, 2016 at 5:28 PM, Ned Batchelder  wrote:
> On Saturday, September 17, 2016 at 4:41:32 PM UTC-4, Peng Yu wrote:
>> > python -m trace -t yourprogram.py
>>
>> If I want to add some command in yourprogram.py to show the commands
>> used it instead of calling trace from the command line, can it be
>> done?
>
> I don't know of a way to do that, but it might be possible.
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread eryk sun
On Sun, Sep 18, 2016 at 12:17 AM, Lawrence D’Oliveiro
 wrote:
>
> why does the documentation suggest that “i” and “I” could have an item size 
> of 2?

SHRT_MAX <= INT_MAX <= LONG_MAX <= LLONG_MAX. short int and int  ("h"
and "i") are at least 16-bit. long int ("l") is at least 32-bit. long
long int ("q") is at least 64-bit.

AFAIK, however, an int is 32-bit on all platforms supported by
CPython. However, I see that MicroPython [1] has been ported to 16-bit
PIC microcontrollers. An int should be 16-bit in that case.

[1]: https://github.com/micropython/micropython
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is the content available in the html doc available in help()?

2016-09-17 Thread Peng Yu
Sorry. I am still referring to python2.

On Sat, Sep 17, 2016 at 8:45 PM, Lawrence D’Oliveiro
 wrote:
> On Sunday, September 18, 2016 at 12:51:11 PM UTC+12, Peng Yu wrote:
>> I want to get the same content as the html doc from help().
>
> ldo@theon:~> pydoc3 inspect
> Help on module inspect:
>
> NAME
> inspect - Get useful information from live Python objects.
>
> MODULE REFERENCE
> https://docs.python.org/3.5/library/inspect
>
> (etc etc etc)
>
> worked for me, and it’s for a more up-to-date version of Python as well...
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is the content available in the html doc available in help()?

2016-09-17 Thread Lawrence D’Oliveiro
On Sunday, September 18, 2016 at 12:51:11 PM UTC+12, Peng Yu wrote:
> I want to get the same content as the html doc from help().

ldo@theon:~> pydoc3 inspect
Help on module inspect:

NAME
inspect - Get useful information from live Python objects.

MODULE REFERENCE
https://docs.python.org/3.5/library/inspect

(etc etc etc)

worked for me, and it’s for a more up-to-date version of Python as well...
-- 
https://mail.python.org/mailman/listinfo/python-list


Official Python documentation lookup while programming (was: Is the content available in the html doc available in help()?)

2016-09-17 Thread Ben Finney
Peng Yu  writes:

> Hi, I want to get the same content as the html doc from help().

That's not what the ‘help’ function does, so I don't think that's
feasible.

Moreover, the Python interpreter does not have any notion of where the
HTML documentation is stored, nor how to access it, nor how to present
it.

So no, a Python interactive prompt does not natively have a way to do
what you're asking.

What you may like is to get your programming environment to present the
official Python documentation as part of that environment.

For example, the documentation is rendered to GNU Info format and
available to install from https://github.com/politza/python-info>,
which makes it immediately available in Info readers, such as the one
native to Emacs.

-- 
 \   “If you ever fall off the Sears Tower, just go real limp, |
  `\ because maybe you'll look like a dummy and people will try to |
_o__)catch you because, hey, free dummy.” —Jack Handey |
Ben Finney

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


Is the content available in the html doc available in help()?

2016-09-17 Thread Peng Yu
Hi, I want to get the same content as the html doc from help(). I am
not sure if this is possible (as I tried help(inspect) which does not
give the same content). Could anybody confirm if there is a way to get
the same content from help()? Thanks.

https://docs.python.org/2/library/inspect.html

-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Lawrence D’Oliveiro
On Saturday, September 17, 2016 at 3:47:15 PM UTC+12, I wrote:
> >>> a = array.array("I", (0,))
> >>> a.itemsize
> 4
> >>> a = array.array("L", (0,))
> >>> a.itemsize
> 8

Let me rephrase the question. It seems clear 
 that “l” and “L” are not be 
relied on. As far as I can tell, on all current Python implementations, “i” and 
“I” have item sizes of 4, while “q” and “Q” have item sizes of 8.

Can anybody offer any counterexamples? If not, why does the documentation 
suggest that “i” and “I” could have an item size of 2?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Ned Batchelder
On Saturday, September 17, 2016 at 4:41:32 PM UTC-4, Peng Yu wrote:
> > python -m trace -t yourprogram.py
> 
> If I want to add some command in yourprogram.py to show the commands
> used it instead of calling trace from the command line, can it be
> done?

I don't know of a way to do that, but it might be possible.

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


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Lawrence D’Oliveiro
On Saturday, September 17, 2016 at 11:54:10 PM UTC+12, Christian Heimes wrote:
>
> ... on Windows (32 and 64bit), a long is always 32bit and an array with
> datatype "L" has itemsize 4.

Ah, I forgot the LLP64 nonsense...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Marko Rauhamaa
Martin Schöön :
> Related anecdote from Phoenix AZ. By now you have noticed my family
> name: Schöön. On airline tickets and boarding passes in the U.S. it
> gets spelled Schoeoen.

Do Swedes do that German thing, too? If you have to write Finnish
without ä and ö, you simply leave out the dots. (On the other hand, if
you need š or ž and don't have them, you replace them with sh and zh.)


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


Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Peng Yu
> python -m trace -t yourprogram.py

If I want to add some command in yourprogram.py to show the commands
used it instead of calling trace from the command line, can it be
done?

-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Martin Schöön
Den 2016-09-17 skrev Kouli :
> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.
>
> Kouli
>
> On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu  wrote:
>> Hi, I want to convert strings in which the characters with accents
>> should be converted to the ones without accents. Here is my current
>> code.

Side note from Sweden. Å, ä and ö are not accented characters in our 
language. They are characters of their own. If you want to look up
someone called Öhman in the phone directory you go to the Ö section 
not the O section.

Related anecdote from Phoenix AZ. By now you have noticed my family
name: Schöön. On airline tickets and boarding passes in the U.S. it
gets spelled Schoeoen. This landed me in a special security check
once. After a while the youngish lady performing the search started
to look like 1+1 did not sum up to 2. She looked at my passport
and boarding pass again and asked why I was there with her. I pointed
at another young lady, the one that 'scrutinized' passports and
boarding passes while chatting with a friend and said "She told me
to go over here." "Wait here, I have to talk to my supervisor."

A few minutes passed (I was alone in the enhances security check
throughout...) and then "I am sorry but you should not have had
to go through here. There was a mistake."

So there you are: If you are a middle aged, caucasian guy with
a passport from northern Europe and no 'funny' letters in your name
your are not a threat in the eyes of TSA in Arizona.

Sorry for wasting the bandwidth.

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


Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Kouli
Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.

Kouli

On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu  wrote:
> Hi, I want to convert strings in which the characters with accents
> should be converted to the ones without accents. Here is my current
> code.
>
> 
>
> $ cat main.sh
> #!/usr/bin/env bash
> # vim: set noexpandtab tabstop=2:
>
> set -v
> ./main.py Förstemann
> ./main.py Frédér8ic@
>
> $ cat main.py
> #!/usr/bin/env python
> # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 
> fileencoding=utf-8:
>
> import sys
> import unicodedata
> print unicodedata.normalize('NFKD',
> sys.argv[1].decode('utf-8')).encode('ascii', 'ignore')
>
> 
>
> The complication is that some characters have more than one way of
> conversions. E.g., 'ö' can be converted to either 'oe' or 'o'. I want
> to get all the possible conversions of a string. Does anybody know a
> good way to do so? Thanks.
>
> --
> Regards,
> Peng
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Peng Yu
Hi, I want to convert strings in which the characters with accents
should be converted to the ones without accents. Here is my current
code.



$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
./main.py Förstemann
./main.py Frédér8ic@

$ cat main.py
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import sys
import unicodedata
print unicodedata.normalize('NFKD',
sys.argv[1].decode('utf-8')).encode('ascii', 'ignore')



The complication is that some characters have more than one way of
conversions. E.g., 'ö' can be converted to either 'oe' or 'o'. I want
to get all the possible conversions of a string. Does anybody know a
good way to do so? Thanks.

-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Expression can be simplified on list

2016-09-17 Thread Piet van Oostrum
Daiyue Weng  writes:

> Hi, I found that when I tried to make an equality test on empty like,
>
> if errors == []:
>
> PyCharm always warns me,
>
> Expression can be simplified.
>
> I am wondering what's wrong and how to fix this?
>
It is not wrong, but it can be simplified to just:

if errors:

This is quite usual in Python, but some people prefer the more elaborate form, 
or something like:

if len(errors) == 0:
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Ned Batchelder
On Saturday, September 17, 2016 at 2:37:42 AM UTC-4, Steve D'Aprano wrote:
> On Sat, 17 Sep 2016 12:31 pm, Peng Yu wrote:
> 
> > Hi, `set -v` in bash allows the print of the command before print the
> > output of the command.
> > 
> > I want to do the similar thing --- print a python command and then
> > print the output of the command. Is it possible with python?
> 
> 
> There is no built-in command for this, but it would be an interesting
> project for an advanced user to write a pre-processor that inserts calls to
> print after every line.

The trace module in the stdlib is little-known, but can do this.  This
will run your program and print each line before executing it:

python -m trace -t yourprogram.py

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


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Christian Heimes
On 2016-09-17 05:47, Lawrence D’Oliveiro wrote:
> >>> a = array.array("I", (0,))
> >>> a.itemsize
> 4
> >>> a = array.array("L", (0,))
> >>> a.itemsize
> 8
> 
> According to , the “minimum 
> size” should be 2 and 4 respectively. It further says:
> 
> The actual representation of values is determined by the machine
> architecture (strictly speaking, by the C implementation).
> The actual size can be accessed through the itemsize attribute.
> 
> Are there any C compilers still in common use where the values will not be 4 
> and 8, as above?

Yes, on Windows (32 and 64bit), a long is always 32bit and an array with
datatype "L" has itemsize 4.

Christian


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


Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Thorsten Kampe
* Thorsten Kampe (Sat, 17 Sep 2016 12:25:05 +0200)
> 
> * Peng Yu (Fri, 16 Sep 2016 21:31:37 -0500)
> > 
> > Hi, `set -v` in bash allows the print of the command before print the
> > output of the command.
> > 
> > I want to do the similar thing --- print a python command and then
> > print the output of the command. Is it possible with python?
> 
> Rather easily. I've implemented it some time ago like this:

Oops, I mixed it up with `set -x`, sorry.

Thorsten

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


Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Thorsten Kampe
* Peng Yu (Fri, 16 Sep 2016 21:31:37 -0500)
> 
> Hi, `set -v` in bash allows the print of the command before print the
> output of the command.
> 
> I want to do the similar thing --- print a python command and then
> print the output of the command. Is it possible with python?

Rather easily. I've implemented it some time ago like this:

"""
import sys

def _traceit(frame, event, arg):
if (frame.f_globals['__name__'] == '__main__' and
event in ['call', 'line']):

logger.debug('+[{lineno}]: {code}'.format(
lineno = frame.f_lineno,
code   = inspect.getframeinfo(frame).code_context
[0].rstrip()))
return _traceit

sys.settrace(_traceit)
"""

Thorsten

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