Aloha! Check out the Betabots!

2013-10-01 Thread Devyn Collier Johnson

Aloha Python Fans!

   Did you all miss me? I have been busy working on my Python-based 
chatbots called the Betabots. I mentioned this mailing list and thanked 
the Python mailing list in the documentation like I said I would. I just 
released v0.8a. Enjoy! Thanks for all the past help everyone.


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Am I not seeing the Error?

2013-08-13 Thread Devyn Collier Johnson


On 08/13/2013 04:50 AM, Steven D'Aprano wrote:

On Tue, 13 Aug 2013 09:19:07 +0100, Joshua Landau wrote:


On 12 August 2013 16:47, Roy Smith r...@panix.com wrote:

I can't quite sort out the multiple quoting levels, but somebody said:


Programming like that is called trolling. A programmer that uses
trolling is called a troll. A troll can also refer to such a line of
code itself. My scripts contain a lot of trolls. It is easier for me
to read trolls than typical coding styles.

Please tell me this is all just an elaborate joke.

That was the OP (Devyn Collier Johnson, devyncjohn...@gmail.com) and
I, too, am hoping this is an elaborate joke. However, see
http://bazaar.launchpad.net/~devyncjohnson-d/neobot/trunk/view/head:/

lib/beta_engine.

I am struggling to see what the punchline is...


If Artificial Intelligence code is hard to write, it damn well should be
hard to read too. Otherwise, how will people know how brilliant you are?

But seriously... I don't know what language Devyn is writing in Python,
but I've seen code like that before. Mostly code written back in the
early to mid 1980s. I may have even written some of it myself :-)

Anyway, I don't think we should badger Devyn, we're not his dad and we're
not the code police. All we can do is continue to demonstrate good,
idiomatic, *working* Python code, and hopefully he will learn to write
the same.


I now see why this programming style is called trolling. It brings the 
worst out of people (^u^). Can I have the number for the coding police, 
I want to turn myself in (^u^).


For me, this style is easier to read. I have tried the typical style, 
but I find this one to be easier.


Good thing no one knows my address. A mob might show up at my door (^u^).

Once I have the next version of my chatbot released, I will tell you all 
so you can see it work.


Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Am I not seeing the Error?

2013-08-12 Thread Devyn Collier Johnson


On 08/10/2013 10:47 PM, Chris Angelico wrote:

On Sun, Aug 11, 2013 at 3:43 AM, Roy Smith r...@panix.com wrote:

In article mailman.452.1376188442.1251.python-l...@python.org,
  Chris Angelico ros...@gmail.com wrote:


When you get a syntax error you can't understand, look at the previous
line of code. Perhaps something there is incomplete; maybe you have
mismatched parentheses, so this line is considered to be part of the
same expression.

Next thing to do is split it into more lines. Why is all that in a single
line?

Also, try reformatting the code in a tool like emacs or eclipse which
does syntax coloring and auto indenting.  Often, if you're missing some
piece of punctuation, it will become obvious when your tool tries to
indent things in some unexpected way.  Or suddenly starts coloring all
of your program text as if it were a string literal :-)

Agreed. Though I've had some odd issues with SciTE in that way; I
think its Python handling may have bugs in it here and there. But 95%
of the time it's helpful.

ChrisA


Thanks everyone. Unfortunately, I have not found the problem yet. I use 
the Geany IDE which has syntax highlighting, but nothing wrong is seen. 
None of the suggestions helped. The lines before this one set variables. 
The lines further up appear fine. I will keep looking. If I ever 
figure it out, I will share with all of you.


As for the code being one line, my style of coding is very different 
from others. I try to keep similar or related tasks on one line. 
Programming like that is called trolling. A programmer that uses 
trolling is called a troll. A troll can also refer to such a line of 
code itself. My scripts contain a lot of trolls. It is easier for me to 
read trolls than typical coding styles. (Yes, I am a weird troll (^u^))


Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Am I not seeing the Error?

2013-08-12 Thread Devyn Collier Johnson


On 08/12/2013 09:20 AM, Zachary Ware wrote:

On Mon, Aug 12, 2013 at 7:33 AM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

On 08/10/2013 10:47 PM, Chris Angelico wrote:

On Sun, Aug 11, 2013 at 3:43 AM, Roy Smith r...@panix.com wrote:

In article mailman.452.1376188442.1251.python-l...@python.org,
   Chris Angelico ros...@gmail.com wrote:


When you get a syntax error you can't understand, look at the previous
line of code. Perhaps something there is incomplete; maybe you have
mismatched parentheses, so this line is considered to be part of the
same expression.

Next thing to do is split it into more lines. Why is all that in a
single
line?

Also, try reformatting the code in a tool like emacs or eclipse which
does syntax coloring and auto indenting.  Often, if you're missing some
piece of punctuation, it will become obvious when your tool tries to
indent things in some unexpected way.  Or suddenly starts coloring all
of your program text as if it were a string literal :-)

Agreed. Though I've had some odd issues with SciTE in that way; I
think its Python handling may have bugs in it here and there. But 95%
of the time it's helpful.

ChrisA


Thanks everyone. Unfortunately, I have not found the problem yet. I use the
Geany IDE which has syntax highlighting, but nothing wrong is seen. None of
the suggestions helped. The lines before this one set variables. The lines
further up appear fine. I will keep looking. If I ever figure it out, I
will share with all of you.

As for the code being one line, my style of coding is very different from
others. I try to keep similar or related tasks on one line. Programming like
that is called trolling. A programmer that uses trolling is called a troll.
A troll can also refer to such a line of code itself. My scripts contain a
lot of trolls. It is easier for me to read trolls than typical coding
styles.

Obviously not, since you can't find the syntax error.  If you replace
each semicolon in that line with a newline, the syntax error will be
immediately obvious.  I'll even give you a hint: it's on the third
line.


Zachary, are you, Ned, and Terry trying to say the syntax should be

job = multiprocessing.Process(func1(), func2())

not

job = multiprocessing.Process(func1(); func2())

DCJ

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


Re: Am I not seeing the Error?

2013-08-12 Thread Devyn Collier Johnson


On 08/12/2013 12:56 PM, Joel Goldstick wrote:

On Mon, Aug 12, 2013 at 11:47 AM, Roy Smith r...@panix.com wrote:

I can't quite sort out the multiple quoting levels, but somebody said:


Programming like that is called trolling. A programmer that uses
trolling is called a troll. A troll can also refer to such a line
of code itself. My scripts contain a lot of trolls. It is easier
for me to read trolls than typical coding styles.

Please tell me this is all just an elaborate joke.

I was thinking something similar Roy.  Devyn, you may think you code
differently, but you don't.  You have a half of dozen people trying to
show you how your style causes confusion between what you think you
are writing and what you actually coded.  There is plenty of room in
coding for personal expression, but what you call 'trolling' is not
that.  If you like semicolons, use another language that needs them.
I think you think it is some version of premature optimization.  Since
you are a novice at the language, stick with the standards, and learn
to embrace them.  Ultimately standard coding styles has nothing to do
with code optimization.  It has to do with readability.  Although this
is a small example, you can see that if several people get involved
debugging it, the first thing that gets in the way is your
non-standard coding style.  If you want to code alone your whole life,
do as you like.  But the time spent reading and fixing code in the
lifetime of any useful software system is greater than the time spent
creating the original code.

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





I know using semicolons will not optimize the code, but it is actually 
easier for me to read. I can handle such code better than spacing it out.


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


Am I not seeing the Error?

2013-08-10 Thread Devyn Collier Johnson
I am checking my 1292-line script for syntax errors. I ran the following 
commands in a terminal to check for errors, but I do not see the error.


collier@Nacho-Laptop:/media/collier/AI/Pysh$ python3 -m py_compile 
./beta_engine

  File ./beta_engine, line 344
JOB_WRITEURGFILES = 
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID); 
write2file(SENTEMPPATH, ''); write2file(INPUTMEM, '')); 
JOB_WRITEURGFILES.start()

^
SyntaxError: invalid syntax
collier@Nacho-Laptop:/media/collier/AI/Pysh$ pylint ./beta_engine
No config file found, using default configuration
* Module beta_engine
E:344,0: invalid syntax


Here is line 344:

JOB_WRITEURGFILES = 
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID); 
write2file(SENTEMPPATH, ''); write2file(INPUTMEM, '')); 
JOB_WRITEURGFILES.start()


The ENGINEPID is a variable containing a string. My write2file function is

def write2file(openfile, WRITE):
with open(openfile, 'rw') as file:
file.write(WRITE)


Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Python3 Multiprocessing

2013-08-09 Thread Devyn Collier Johnson

Aloha!

   I need a command that will make threads created by 
multiprocessing.Process() wait for each other to complete. For 
instance, I want to do something like this:


job1 = multiprocessing.Process(CMD1())
job2 = multiprocessing.Process(CMD2())

jobs1.start(); jobs2.start()

PY_FUNC()

The command PY_FUNC() depends on the end result of the actions of 
CMD1() and CMD2(). I need some kind of wait command for the two threads 
that will not let the script continue until job1 and job2 are complete. 
Is this possible in Python3?



Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python3 Multiprocessing

2013-08-09 Thread Devyn Collier Johnson


On 08/09/2013 03:44 PM, MRAB wrote:

On 09/08/2013 20:30, Devyn Collier Johnson wrote:

Aloha!

 I need a command that will make threads created by
multiprocessing.Process() wait for each other to complete. For
instance, I want to do something like this:

job1 = multiprocessing.Process(CMD1())
job2 = multiprocessing.Process(CMD2())

jobs1.start(); jobs2.start()

PY_FUNC()

The command PY_FUNC() depends on the end result of the actions of
CMD1() and CMD2(). I need some kind of wait command for the two threads
that will not let the script continue until job1 and job2 are complete.
Is this possible in Python3?


Possibly you mean .join:

jobs1.start()
jobs2.start()

jobs1.join()
jobs2.join()



Thanks MRAB! That is easy. I always (incorrectly) thought the join() 
command got two threads and made them one. I did not know it made the 
script wait for the threads.


Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson


On 08/05/2013 10:19 PM, MRAB wrote:

On 06/08/2013 03:00, Devyn Collier Johnson wrote:

I am wanting to sort a plain text file alphanumerically by the lines. I
have tried this code, but I get an error. I assume this command does not
accept newline characters.


   file = open('/home/collier/pytest/sort.TXT', 'r').read()


That returns the file as a single string.


   print(file)
z
c
w
r
h
s
d


   file.sort() #The first blank line above is from the file. I do not
know where the second comes from.
Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Strings don't have a sort method.


I had the parameters (key=str.casefold, reverse=True), but I took those
out to make sure the error was not with my parameters.

Specifically, I need something that will sort the lines. They may
contain one word or one sentence with punctuation. I need to reverse the
sorting ('z' before 'a'). The case does not matter ('a' = 'A').

I have also tried this without success:

   file.sort(key=str.casefold, reverse=True)
Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Try this:

lines = open('/home/collier/pytest/sort.TXT', 'r').readlines()
lines.sort()


Actually, a more Pythonic way these days is to use the 'with' statement:

with open('/home/collier/pytest/sort.TXT') as file:
lines = file.readlines()

lines.sort()



Thanks! That works well. After I run your command, I run

print(''.join(lines))

to get the sorted output. Even the parameters work without issues.

lines.sort(reverse=True, key=str.casefold)


Mahalo,

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


Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson


On 08/05/2013 10:19 PM, MRAB wrote:

On 06/08/2013 03:00, Devyn Collier Johnson wrote:

I am wanting to sort a plain text file alphanumerically by the lines. I
have tried this code, but I get an error. I assume this command does not
accept newline characters.


   file = open('/home/collier/pytest/sort.TXT', 'r').read()


That returns the file as a single string.


   print(file)
z
c
w
r
h
s
d


   file.sort() #The first blank line above is from the file. I do not
know where the second comes from.
Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Strings don't have a sort method.


I had the parameters (key=str.casefold, reverse=True), but I took those
out to make sure the error was not with my parameters.

Specifically, I need something that will sort the lines. They may
contain one word or one sentence with punctuation. I need to reverse the
sorting ('z' before 'a'). The case does not matter ('a' = 'A').

I have also tried this without success:

   file.sort(key=str.casefold, reverse=True)
Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Try this:

lines = open('/home/collier/pytest/sort.TXT', 'r').readlines()
lines.sort()


Actually, a more Pythonic way these days is to use the 'with' statement:

with open('/home/collier/pytest/sort.TXT') as file:
lines = file.readlines()

lines.sort()



Thanks! That works well. After I run your command, I run

print(''.join(lines))

to get the sorted output. Even the parameters work without issues.

lines.sort(reverse=True, key=str.casefold)


Mahalo,

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


Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson


On 08/05/2013 11:49 PM, alex23 wrote:

On 6/08/2013 1:12 PM, Joshua Landau wrote:

Because it's bad to open files without a with unless you know what
you're doing, use a with:

 with open('/home/collier/pytest/__sort.TXT') as file:
 sorted(file, key=str.casefold, reverse=True)


Shouldn't that be:

with open('/home/collier/pytest/__sort.TXT') as file:
data = file.readlines()
sorted(data, key=str.casefold, reverse=True)

I'm tempted to say HINT #5: don't provide a solution without testing 
it first but that would be pretty obnoxious.
I tried Joshua's suggestion in Python3.3 and it worked. What version of 
Python are you using?


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


Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson


On 08/05/2013 11:12 PM, Joshua Landau wrote:
On 6 August 2013 03:00, Devyn Collier Johnson devyncjohn...@gmail.com 
mailto:devyncjohn...@gmail.com wrote:


I am wanting to sort a plain text file alphanumerically by the
lines. I have tried this code, but I get an error. I assume this
command does not accept newline characters.


HINT #1: Don't assume that without a reason. It's wrong.

 file = open('/home/collier/pytest/sort.TXT', 'r').read()


HINT #2: Don't lie. file is not a file so you probably shouldn't 
call it one. It's the contents of a file object.


 print(file)
z
c
w
r
h
s
d


 file.sort() #The first blank line above is from the file. I do
not know where the second comes from.
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


HINT #3: *Read*. What does it say?

AttributeError: 'str' object has no attribute 'sort'

Probably your problem, then, is that a 'str' object has no attribute 
'sort'. That's what it says.


file is a 'str' object. You are accessing the 'sort' attribute 
which it doesn't have.


I had the parameters (key=str.casefold, reverse=True), but I took
those out to make sure the error was not with my parameters.


HINT #4: Don't just guess what the problem is. The answer is in the error.

Specifically, I need something that will sort the lines. They may
contain one word or one sentence with punctuation. I need to
reverse the sorting ('z' before 'a'). The case does not matter
('a' = 'A').

I have also tried this without success:

 file.sort(key=str.casefold, reverse=True)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'




So you want to sort your string by lines. Rather than trying to abuse 
a .sort attribute that patently doesn't exist, just use sorted OR 
convert to a list first.


sorted(open('/home/collier/pytest/sort.TXT'), key=str.casefold, 
reverse=True)


Because it's bad to open files without a with unless you know what 
you're doing, use a with:


with open('/home/collier/pytest/sort.TXT') as file:
sorted(file, key=str.casefold, reverse=True)


Thanks for the advice Joshua. I find these tips very useful. However, 
how would I close the files, or would they close after the with 
construct is complete?


Mahalo,

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


Re: Sort lines in a plain text file alphanumerically

2013-08-06 Thread Devyn Collier Johnson


On 08/06/2013 06:52 AM, Chris Angelico wrote:

On Tue, Aug 6, 2013 at 11:38 AM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

 with open('/home/collier/pytest/sort.TXT') as file:
 sorted(file, key=str.casefold, reverse=True)


Thanks for the advice Joshua. I find these tips very useful. However, how
would I close the files, or would they close after the with construct is
complete?


That's the whole point of 'with'. It calls open(), then calls
__enter__, and it guarantees to call __exit__ before executing any
code following the with block. With a file object, __exit__ will close
the file.

ChrisA


Thanks! Now I see why using with is a better way to write the code.

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


Sort lines in a plain text file alphanumerically

2013-08-05 Thread Devyn Collier Johnson
I am wanting to sort a plain text file alphanumerically by the lines. I 
have tried this code, but I get an error. I assume this command does not 
accept newline characters.



 file = open('/home/collier/pytest/sort.TXT', 'r').read()
 print(file)
z
c
w
r
h
s
d


 file.sort() #The first blank line above is from the file. I do not 
know where the second comes from.

Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'

I had the parameters (key=str.casefold, reverse=True), but I took those 
out to make sure the error was not with my parameters.


Specifically, I need something that will sort the lines. They may 
contain one word or one sentence with punctuation. I need to reverse the 
sorting ('z' before 'a'). The case does not matter ('a' = 'A').


I have also tried this without success:

 file.sort(key=str.casefold, reverse=True)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Share Code: Laptop Lid State

2013-07-30 Thread Devyn Collier Johnson

Aloha everyone!

   I attached a script that I thought I could share with everyone for 
your help. This Python3 script only works on Unix systems. It prints the 
current state of the lid. This can be used to make a script that 
performs some action when the lid is closed or open. The script is 
licensed under LGPLv3 and I will soon upload it to my Launchpad account. 
Enjoy!


Mahalo,

devyncjohn...@gmail.com
#!/usr/bin/env python3
#Made by Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS 
devyncjohn...@gmail.com

#   LGPLv3 - 2013. (Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS)©
#This program is free software: you can redistribute it and/or modify it under 
the terms of the GNU General Public License as
#published by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.
#   This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU 
General Public License for more details.
#You should have received a copy of the GNU General Public License along with 
this program. If not, see http://www.gnu.org/licenses/.

import subprocess; print(subprocess.getoutput('cat 
/proc/acpi/button/lid/LID/state | awk \'{ print $2 }\''))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code: Laptop Lid State

2013-07-30 Thread Devyn Collier Johnson


On 07/30/2013 12:00 PM, Chris Angelico wrote:

On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

Aloha everyone!

I attached a script that I thought I could share with everyone for your
help. This Python3 script only works on Unix systems. It prints the current
state of the lid. This can be used to make a script that performs some
action when the lid is closed or open. The script is licensed under LGPLv3
and I will soon upload it to my Launchpad account. Enjoy!

There's... no Python code in that. Why not simply
open(/proc/acpi/button/lid/LID/state) and read from it, instead of
using cat and awk?

ChrisA
The script returns either open or close instead of printing the 
whole file contents. I thought some people would find it useful (^_^;).


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


Re: Critic my module

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 06:58 AM, Schneider wrote:

Hi,

lets uses the ls example:
the way you do it now implies, that you search your PATH variable 
until it finds a
program called 'ls'. So if we are able to change the PATH variable, 
and put out own
'ls' somewhere in the (new) paths, calling you ls() will execute 
whatever we want our

own  ls' to do.

Second remark: if the behavior of some tools is changed (for examples 
with using aliases)
we cannot expect the called tool (in the example: 'ls') to give the 
same output on

every system.

this can be avoided (mostly) by ensuring that the right program (in 
the example /bin/ls) is called, and not only ls.


bg,
Johannes

On 07/26/2013 12:39 PM, Devyn Collier Johnson wrote:


On 07/25/2013 09:58 AM, Schneider wrote:

Hi,

nice idea.

mybe -  for security reasons - you should ensure, that the right 
tool is called and not some tool put the path with the same name.


bg,
Johannes

Devyn Collier Johnson devyncjohn...@gmail.comOn Thu 25 Jul 2013 
03:24:30 PM CEST, Devyn Collier Johnson wrote:

Aloha Python Users!

   I made a Python3 module that allows users to use certain Linux
shell commands from Python3 more easily than using os.system(),
subprocess.Popen(), or subprocess.getoutput(). This module (once
placed with the other modules) can be used like this

import boash; boash.ls()

   I attached the module. I plan to release it on the Internet soon,
but feel free to use it now. It is licensed under LGPLv3.

   The name comes from combining Boa with SHell. Notice that the
module's name almost looks like BASH, a common Linux shell. The Boa
is a constrictor snake. This module makes Unix shells easier to use
via Python3. This brings the system shell closer to the Python shell.


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com






--
GLOBE Development GmbH
Königsberger Strasse 260
48157 MünsterGLOBE Development GmbH
Königsberger Strasse 260
48157 Münster
0251/5205 390


What do you mean by that Schneider?

Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com





Thanks, good point. I will fix that. BTW, we bottom post on this mailing 
list.


Mahalo,

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


Re: FSR and unicode compliance - was Re: RE Module Performance

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 08:06 AM, Heiko Wundram wrote:

Am 29.07.2013 13:43, schrieb wxjmfa...@gmail.com:

3.2

timeit.timeit(r = dir(list))

22.300465007102908

3.3

timeit.timeit(r = dir(list))

27.13981129541519

For the record, I do not put your example to contradict
you. I was expecting such a result even before testing.

Now, if you do not understand why, you do not understand.
There nothing wrong.


Please give a single *proof* (not your gut feeling) that this is 
related to the FSR, and not rather due to other side-effects such as 
changes in how dir() works or (as Chris pointed out) due to more 
members on the list type in 3.3. If you can't or won't give that 
proof, there's no sense in continuing the discussion.


Wow! The RE Module thread I created is evolving into Unicode topics. 
That thread grew up so fast!


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


Re: Critic my module

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 02:36 PM, Lele Gaifax wrote:

This thread did not mention alternative and existing modules with
(almost) the same goal, two come to mind:

* https://pypi.python.org/pypi/sh
* https://pypi.python.org/pypi/sarge

bye, lele.
Thanks everyone for the feedback. Clearly, I should stop my project. I 
will work on something else now (^u^)!


Mahalo,

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


PEP8 79 char max

2013-07-29 Thread Devyn Collier Johnson
In Python programming, the PEP8 recommends limiting lines to a maximum 
of 79 characters because There are still many devices around that are 
limited to 80 character lines 
(http://www.python.org/dev/peps/pep-0008/#code-lay-out). What devices 
cannot handle 80 or more characters on a line? Would following this 
recommendation improve script performance?


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


import syntax

2013-07-29 Thread Devyn Collier Johnson

The PEP8 recommends importing like this:

import os
import re

not like this:

import os, re

Why is that? Is there a performance advantage to one of the styles?


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: import syntax

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 04:20 PM, Tim Chase wrote:

On 2013-07-29 16:09, Dave Angel wrote:

On 07/29/2013 03:48 PM, Devyn Collier Johnson wrote:

The PEP8 recommends importing like this:

import os
import re

not like this:

import os, re

I got a bit further, and if I'm only using a couple of functions
from the import, I'll list them in the comment.

If I just plan to use a small subset, I tend to reach for the

   from sys import stdout, stderr, exit

sort of syntax.  I find it makes my code read a bit more cleanly than
having to type sys.stderr.write(...) everywhere but is still pretty
readable.

-tkc



So, there are no advantages or disadvantages when disregarding readability?

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


Re: PEP8 79 char max

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 04:08 PM, Joel Goldstick wrote:

On Mon, Jul 29, 2013 at 3:43 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

In Python programming, the PEP8 recommends limiting lines to a maximum of 79
characters because There are still many devices around that are limited to
80 character lines (http://www.python.org/dev/peps/pep-0008/#code-lay-out).
What devices cannot handle 80 or more characters on a line?

well, punch cards ;)
  Would following

this recommendation improve script performance?

Not performance, but human readability

Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list



So, I can have a script with large lines and not negatively influence 
performance on systems that do not use punch cards?


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


Has anyone gotten Pyglet to work

2013-07-29 Thread Devyn Collier Johnson
I tried Pyglet in a Python3 and a Python2 script, but both fail. The 
error code is below and the script is attached. The 'boot.ogg' file is 
Ubuntu's default bootup sound. I got my code from this link 
(http://guzalexander.com/2012/08/17/playing-a-sound-with-python.html).


collier@Nacho-Laptop:~$ ./pyglet.py
Traceback (most recent call last):
  File ./pyglet.py, line 2, in module
import pyglet
  File /home/collier/pyglet.py, line 3, in module
song = pyglet.media.load('./boot.ogg')
AttributeError: 'module' object has no attribute 'media'


Mahalo,

DCJ
#!/usr/bin/env python
import pyglet
song = pyglet.media.load('./boot.ogg')
song.play()
pyglet.app.run()
-- 
http://mail.python.org/mailman/listinfo/python-list


Bitwise Operations

2013-07-29 Thread Devyn Collier Johnson
On Python3, how can I perform bitwise operations? For instance, I want 
something that will 'and', 'or', and 'xor' a binary integer.


Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Has anyone gotten Pyglet to work

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 05:08 PM, Gary Herron wrote:

On 07/29/2013 01:56 PM, Devyn Collier Johnson wrote:
I tried Pyglet in a Python3 and a Python2 script, but both fail. The 
error code is below and the script is attached. The 'boot.ogg' file 
is Ubuntu's default bootup sound. I got my code from this link 
(http://guzalexander.com/2012/08/17/playing-a-sound-with-python.html).


collier@Nacho-Laptop:~$ ./pyglet.py
Traceback (most recent call last):
  File ./pyglet.py, line 2, in module
import pyglet
  File /home/collier/pyglet.py, line 3, in module
song = pyglet.media.load('./boot.ogg')
AttributeError: 'module' object has no attribute 'media'


Mahalo,

DCJ




You appear to have confused Python by having a module named pyglet AND 
a local file named pyglet.py.


This when you say import pyglet, you are not getting the pyglet 
module, but instead your own file pyglet.py, which of course, has 
nothing named media in it.


Rename your file and try again.

P.S.  It is a common newbie error to hide a system file like this and 
suffer the consequence.  We've all done it -- at least once. :^) )




Duh, thanks for the tip (^u^), but I still get an error (different 
error). NOTE: this is all python2.7 code because Pyglet supposedly has 
issues with Python3.


collier@Nacho-Laptop:~$ pip install pyglet
Downloading/unpacking pyglet
  Downloading pyglet-1.1.4.tar.gz (2.9MB): 2.9MB downloaded
  Running setup.py egg_info for package pyglet
...Blah
...Blah
Installing collected packages: pyglet
  Running setup.py install for pyglet
Successfully installed pyglet
Cleaning up...
collier@Nacho-Laptop:~/pytest$ ./pymedia.py
Traceback (most recent call last):
  File ./pymedia.py, line 3, in module
song = pyglet.media.load('./boot.ogg')
  File 
/usr/local/lib/python2.7/dist-packages/pyglet/media/__init__.py, line 
1386, in load

source = _source_class(filename, file)
  File /usr/local/lib/python2.7/dist-packages/pyglet/media/riff.py, 
line 202, in __init__

'AVbin is required to decode compressed media')
pyglet.media.riff.WAVEFormatException: AVbin is required to decode 
compressed media

AL lib: ReleaseALC: 1 device not closed
collier@Nacho-Laptop:~/pytest$ ls
boot.ogg  pymedia.py



Mahalo,

DCJ
#!/usr/bin/env python
import pyglet
song = pyglet.media.load('./boot.ogg')
song.play()
pyglet.app.run()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 05:42 PM, Steven D'Aprano wrote:

On Mon, 29 Jul 2013 16:24:51 -0400, Devyn Collier Johnson wrote:


So, I can have a script with large lines and not negatively influence
performance on systems that do not use punch cards?

You'll negatively influence anyone who has to read, or edit, your code.
Very likely including you.

But no, there's no meaningful performance difference based on line
length. Interpreting the source code is not meaningfully affected by line
length, and by the time the code is compiled and then run, line length is
irrelevant.



Evidently, it is personal preference. I prefer to read computer code 
like a book (yes, I am a weirdo (^u^)). The only time I exced 79 
characters is when I write a set of commands that perform similar tasks. 
I do not make too many lines over 79 char. Thanks everyone for the 
comments and feedback.


Mahalo,

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


Re: import syntax

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 06:37 PM, Joshua Landau wrote:
On 29 July 2013 21:23, Devyn Collier Johnson devyncjohn...@gmail.com 
mailto:devyncjohn...@gmail.com wrote:



On 07/29/2013 04:20 PM, Tim Chase wrote:

On 2013-07-29 16:09, Dave Angel wrote:

On 07/29/2013 03:48 PM, Devyn Collier Johnson wrote:

The PEP8 recommends importing like this:

import os
import re

not like this:

import os, re

I got a bit further, and if I'm only using a couple of
functions
from the import, I'll list them in the comment.

If I just plan to use a small subset, I tend to reach for the

   from sys import stdout, stderr, exit

sort of syntax.  I find it makes my code read a bit more
cleanly than
having to type sys.stderr.write(...) everywhere but is still
pretty
readable.

-tkc


So, there are no advantages or disadvantages when disregarding
readability?


Sure, just as one light is no brighter or dimmer than another when 
disregarding luminosity.


As people have said, it improves diffs as well. It flows quicker into 
the from module import things form (which I oft prefer), too.


When asking these questions, ask yourself why would it *compile* 
differently? It wouldn't. Plus, premature optimisation is the root of 
all evil.


1) Write your code
2) If it's slow:
2a) Do you have time? If so:
2b) Is it important to speed up, or is the slowness not worth spending 
the hours fixing?

2c) Profile it to see what's actually slow
2d) Realise that the slow part is not what you thought it was
2e) Fix the bit that's slow (and nothing else)
2f) Repeat from 2
3) Write some more code

Joshua, nice work-flow instructions.

Mahalo,

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


Re: Bitwise Operations

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 05:53 PM, Grant Edwards wrote:

On 2013-07-29, Devyn Collier Johnson devyncjohn...@gmail.com wrote:


On Python3, how can I perform bitwise operations? For instance, I want
something that will 'and', 'or', and 'xor' a binary integer.

http://www.google.com/search?q=python+bitwise+operations

I understand the symbols. I want to know how to perform the task in a 
script or terminal. I have searched Google, but I never saw a command. 
Typing 101  010 or x = (int(101, 2)  int(010, 2)) only gives errors.


Mahalo,

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


Re: Has anyone gotten Pyglet to work

2013-07-29 Thread Devyn Collier Johnson
Thanks everyone for your help. I installed AVbin v10. I no longer get 
Python errors, but no sound is produced.  This is now an AVbin problem 
that I must figure out. At least I am done with the Python issues.


For those of you that need AVbin: 
http://avbin.github.io/AVbin/Home/Home.html



Mahalo,

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


Re: Bitwise Operations

2013-07-29 Thread Devyn Collier Johnson


On 07/29/2013 07:41 PM, Ethan Furman wrote:

On 07/29/2013 04:34 PM, Devyn Collier Johnson wrote:


On 07/29/2013 05:53 PM, Grant Edwards wrote:

On 2013-07-29, Devyn Collier Johnson devyncjohn...@gmail.com wrote:


On Python3, how can I perform bitwise operations? For instance, I want
something that will 'and', 'or', and 'xor' a binary integer.

http://www.google.com/search?q=python+bitwise+operations

I understand the symbols. I want to know how to perform the task in a 
script or terminal. I have searched Google, but I
never saw a command. Typing 101  010 or x = (int(101, 2)  
int(010, 2)) only gives errors.


x = (int('101', 2)  int('010', 2))

Notice the quotes.

In the future you'll better answers quicker if you tell us what you 
did (such as your example above) as well as the errors.


--
~Ethan~
Thanks Ethan for the code help and the tip. I need to get out of that 
habit of not including errors. This code works well, thanks! I cannot 
believe I was that close to the solution!


Now here is something that confuses me, the binary numbers are numbers 
not strings, so why are they put in quotes as if they are strings?



Mahalo,

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


Cross-Platform Python3 Equivalent to notify-send

2013-07-27 Thread Devyn Collier Johnson
Linux systems with the proper software can use the notify-send 
command. Is there a cross-platform Python3 equivalent?


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-Platform Python3 Equivalent to notify-send

2013-07-27 Thread Devyn Collier Johnson


On 07/27/2013 07:30 AM, Chris “Kwpolska” Warrick wrote:

On Sat, Jul 27, 2013 at 12:58 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

Linux systems with the proper software can use the notify-send command. Is
there a cross-platform Python3 equivalent?

Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list

You already asked this on Thursday.  And the answer is probably “no”.  Creating

Under X11-based systems, you would have to call the dbus notification
APIs and pray that the user has something to handle it running (KDE,
GNOME Shell, XFCE4’s notification daemon).  Under Mac OS X 10.7 and
further, you need to work with some system APIs, and that may not be
easy, but possible (eg. https://github.com/alloy/terminal-notifier for
Ruby).

But Windows?  GOOD LUCK!  The following options exist, none of which
is easy to implement, and one of which is not usable with most
clients:

a) Toast Notifications in Windows 8/Server 2012, which is not a
popular platform and may require quite a lot of magic in terms of
coding and else (VS2012);
b) Create a tray icon and do a balloon (2000 and up?, definitely in XP);
c) Create your very own Windows toast notifications framework.

That really sucks. I was hoping Python had some way of doing that. All 
that it needs to do is display a little box at one of the corners of the 
screen. I thought someone would have implemented something by now. Thank 
you anyway.


Mahalo,

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


Re: Critic my module

2013-07-27 Thread Devyn Collier Johnson


On 07/26/2013 10:48 PM, Steven D'Aprano wrote:

As requested, some constructive criticism of your module.

On Thu, 25 Jul 2013 09:24:30 -0400, Devyn Collier Johnson wrote:


#!/usr/bin/python3
#Made by Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS

What's NCLA, Linux+, LPIC-1, DCTS? Do these mean anything? Are we
supposed to know what they mean?

Made by has no legal significance. You probably want:

Copyright © 2013 Devyn Collier Johnson.



#Made using the Geany IDE

Nobody gives a monkey's toss what editor you used to type up the module.
You might as well mention the brand of monitor you used, or whether the
keyboard is Dvorak or Qwerty.



#LGPLv3

You can't just drop in a mention of LGPLv3 and expect it to mean
anything. You actually have to obey the licence yourself, and that
includes *actually including the licence in your work*. (You're
technically in violation of the licence at the moment, however since the
only person whose copyright you are infringing is yourself, it doesn't
matter. However anyone else using your code is at risk.)

http://www.gnu.org/licenses/gpl-howto.html

In the case of the LGPL, you have to include the text of *both* the GPL
and the LGPL, not just one.




import re, sys, subprocess, platform
def grep(regex,textf):
#Sample Command: grep.grep(^x,dir()) #Syntax:
boash.grep(regexp_string,list_of_strings_to_search)

Comments using # are only of use to people reading the source code. If
you want comments to be available at the interactive prompt, you should
write them as doc strings:

def grep(regex, textf):
 This string is a docstring.

 Sample command: ...
 Blah blah blah
 

Then, at the interactive prompt, the user can say:

help(boash.grep)

to read the docstring.



version = '0.2a'

That's quite useless, since it is a local variable invisible outside of
the function.

Also, why would you bother giving every individual function a version
number? That's rather pointless. The user cannot pick and choose function
A with version number 0.6 and function B with version number 0.7 if the
module provides versions 0.7 of both.



expr = re.compile(regex)
match = re.findall(expr, textf)
if match != None:
print(match)

When comparing with None, it is preferred to use is and is not rather
than equality tests.



def ls():
version = '0.3'
print(subprocess.getoutput('ls'))
def dir():
version = '0.3'
print(subprocess.getoutput('dir'))

A blank line or two between functions does wonders for readability. There
is no prize for conserving newlines.

You might like to read PEP 8, the Python style guide. It is optional, but
still makes a very good guide.

http://www.python.org/dev/peps/pep-0008/



def bash(*arg):
version = '0.3'
print(subprocess.getoutput(arg))
def shell(*arg):
version = '0.3'
print(subprocess.getoutput(arg))

bash is not a synonym for shell. The shell might be sh, csh, bash, or
any one of many other shells, all of which are slightly (or not so
slightly) different.



def clear_bash_history():
version = '0.3'
print(subprocess.getoutput('history -c'))

[...]

Do you really need ten aliases for 'history -c'?

If you want to define aliases for a function, don't recreate the entire
function ten times. Start with defining the function once, then:

clear_bash_hist = clear_hist = clear_history = clear_bash_history

etc. But really, having ten names for the one function just confuses
people, who then wonder what subtle difference there is between
delete_history and clear_history.


def firefox():
version = '0.3'
print(subprocess.Popen('(firefox )'))

Is Firefox really so important that it needs a dedicated command?

What about Debian users? Doesn't Iceweasel get a command?



def xterm():
version = '0.3'
print(subprocess.Popen('(xterm )'))

Surely the user already has an xterm open, if they are running this
interactively? Why not just use your xterm's new window or new tab
command?


[...delete more trivial calls to subprocess...]


def repeat_cmd():
version = '0.3'
print(subprocess.Popen('!!'))

[... delete two exact copies of this function...]


def ejcd():
version = '0.3'
print(subprocess.Popen('eject cdrom1'))

[... delete FOURTEEN exact copies of this function...]

Really? Is anyone going to type eject_disc_tray instead of eject?


I think that will do.

This doesn't really do anything except define a large number of trivial
wrappers to commands already available in the shell. Emphasis on the
*trivial* -- with the exception of the grep wrapper, which is all of four
lines (ignoring the useless internal version number), every single one of
these wrapper functions is a one-liner.[1] In other words, you're not
adding any value to the shell commands by wrapping them in Python. There
are plenty of big, complex shell commands that take a plethora of options
and could do

Re: Critic my module

2013-07-27 Thread Devyn Collier Johnson


On 07/26/2013 10:48 PM, Steven D'Aprano wrote:

As requested, some constructive criticism of your module.

On Thu, 25 Jul 2013 09:24:30 -0400, Devyn Collier Johnson wrote:


#!/usr/bin/python3
#Made by Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS

What's NCLA, Linux+, LPIC-1, DCTS? Do these mean anything? Are we
supposed to know what they mean?

Made by has no legal significance. You probably want:

Copyright © 2013 Devyn Collier Johnson.



#Made using the Geany IDE

Nobody gives a monkey's toss what editor you used to type up the module.
You might as well mention the brand of monitor you used, or whether the
keyboard is Dvorak or Qwerty.



#LGPLv3

You can't just drop in a mention of LGPLv3 and expect it to mean
anything. You actually have to obey the licence yourself, and that
includes *actually including the licence in your work*. (You're
technically in violation of the licence at the moment, however since the
only person whose copyright you are infringing is yourself, it doesn't
matter. However anyone else using your code is at risk.)

http://www.gnu.org/licenses/gpl-howto.html

In the case of the LGPL, you have to include the text of *both* the GPL
and the LGPL, not just one.




import re, sys, subprocess, platform
def grep(regex,textf):
#Sample Command: grep.grep(^x,dir()) #Syntax:
boash.grep(regexp_string,list_of_strings_to_search)

Comments using # are only of use to people reading the source code. If
you want comments to be available at the interactive prompt, you should
write them as doc strings:

def grep(regex, textf):
 This string is a docstring.

 Sample command: ...
 Blah blah blah
 

Then, at the interactive prompt, the user can say:

help(boash.grep)

to read the docstring.



version = '0.2a'

That's quite useless, since it is a local variable invisible outside of
the function.

Also, why would you bother giving every individual function a version
number? That's rather pointless. The user cannot pick and choose function
A with version number 0.6 and function B with version number 0.7 if the
module provides versions 0.7 of both.



expr = re.compile(regex)
match = re.findall(expr, textf)
if match != None:
print(match)

When comparing with None, it is preferred to use is and is not rather
than equality tests.



def ls():
version = '0.3'
print(subprocess.getoutput('ls'))
def dir():
version = '0.3'
print(subprocess.getoutput('dir'))

A blank line or two between functions does wonders for readability. There
is no prize for conserving newlines.

You might like to read PEP 8, the Python style guide. It is optional, but
still makes a very good guide.

http://www.python.org/dev/peps/pep-0008/



def bash(*arg):
version = '0.3'
print(subprocess.getoutput(arg))
def shell(*arg):
version = '0.3'
print(subprocess.getoutput(arg))

bash is not a synonym for shell. The shell might be sh, csh, bash, or
any one of many other shells, all of which are slightly (or not so
slightly) different.



def clear_bash_history():
version = '0.3'
print(subprocess.getoutput('history -c'))

[...]

Do you really need ten aliases for 'history -c'?

If you want to define aliases for a function, don't recreate the entire
function ten times. Start with defining the function once, then:

clear_bash_hist = clear_hist = clear_history = clear_bash_history

etc. But really, having ten names for the one function just confuses
people, who then wonder what subtle difference there is between
delete_history and clear_history.


def firefox():
version = '0.3'
print(subprocess.Popen('(firefox )'))

Is Firefox really so important that it needs a dedicated command?

What about Debian users? Doesn't Iceweasel get a command?



def xterm():
version = '0.3'
print(subprocess.Popen('(xterm )'))

Surely the user already has an xterm open, if they are running this
interactively? Why not just use your xterm's new window or new tab
command?


[...delete more trivial calls to subprocess...]


def repeat_cmd():
version = '0.3'
print(subprocess.Popen('!!'))

[... delete two exact copies of this function...]


def ejcd():
version = '0.3'
print(subprocess.Popen('eject cdrom1'))

[... delete FOURTEEN exact copies of this function...]

Really? Is anyone going to type eject_disc_tray instead of eject?


I think that will do.

This doesn't really do anything except define a large number of trivial
wrappers to commands already available in the shell. Emphasis on the
*trivial* -- with the exception of the grep wrapper, which is all of four
lines (ignoring the useless internal version number), every single one of
these wrapper functions is a one-liner.[1] In other words, you're not
adding any value to the shell commands by wrapping them in Python. There
are plenty of big, complex shell commands that take a plethora of options
and could do

Re: Critic my module

2013-07-27 Thread Devyn Collier Johnson


On 07/27/2013 09:35 AM, Dave Angel wrote:

On 07/27/2013 09:19 AM, Devyn Collier Johnson wrote:




SNIP


About the aliases, I have tried setting pwd() as an alias for
os.getcwd(), but I cannot type pwd() and get the desired output.
Instead, I must type pwd. I tested this in Guake running Python3.3.

  os.getcwd()
'/home/collier'
  pwd = os.getcwd()
  pwd()
Traceback (most recent call last):
   File stdin, line 1, in module
TypeError: 'str' object is not callable
  pwd
'/home/collier'
  pwd() = os.getcwd()
   File stdin, line 1
SyntaxError: can't assign to function call


How could I make pwd() work?


Don't call getcwd() when making the alias.  You want it to be called 
when USING the alias.


pwd = os.getcwd#creates the alias

pwd() #runs the alias




Thanks! It works!

 pwd = os.getcwd
 pwd()
'/home/collier'


Mahalo, Dave!


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


Re: Critic my module

2013-07-27 Thread Devyn Collier Johnson


On 07/27/2013 10:33 AM, Dave Angel wrote:

On 07/27/2013 08:56 AM, Devyn Collier Johnson wrote:




SNIP

Somehow during this thread, you have changed your purpose for this 
library.  It used to be a library that Python programmers could import 
and use.  And now, it's a shell replacement?  The user runs the Python 
interpreter, and types the line   import boash   to get started.




Yeah, I have a VERY BAD habit of treating bash and the Linux shell (or
any/all shells) as the same thing. I know they are all very different,
but for some reason I still keep calling all shells in general BASH.


I seem to recall that BASH is an acronym, for Bourne Again SHell.



I will be sure to create aliases. I make alias commands so that it is
easier to guess or remember a command. For instance, a Python user my
want to clear the shell's history, but can only remember one form of the
command or must guess. On my Ubuntu system, I have set up numerous shell
aliases. I am addicted to aliases.


Nothing wrong with aliases.  But how does your user create his own 
aliases?  That's much more important than having yours available. 
Remember that any new globals he defines are lost when he exits the 
interpreter (or crashes).




I still need to add the other browsers. Do very many people use 
Iceweasel?


I did not notice that I have print(subprocess.Popen('(xterm )'))
instead of subprocess.Popen('(xterm )'). The worst computer errors
are ID-10-T errors.

True, the user my have Xterm open, but what if they use Guake (like me)
or Pterm, EvilVTE, Valaterm, Gnome-Terminal, Konsole, etc.?


Exactly.  If they're using a terminal with tabs, they might want to 
create a new tab, not a new instance of the terminal.  Or if they're 
running screen or the equivalent, they want the new terminal to show 
up on their (remote) console.




How could I add security and convenience? Okay, I will try to add wget.
Are there any other shell commands that anyone feels I should add?


How about tab?  The command-completion and filename-completion and 
parameter-completion logic of a good shell is extremely complex, and 
very useful.




The point of this module is to allow Linux shell users to use Python3 as
a regular shell. Instead of using CSH, Bash, Tcsh, FISH, etc., users
could use Python3 and import this module. Python is more powerful than
any shell, so I want to make it easier for anyone to use Python as the
default shell. For instance, instead of typing print(os.getcwd()) to
get the current working directory, users could type boash.ls(). I hope
that is easier to remember than print(os.getcwd()).


It's easier, but doesn't begin to do the same thing.

As for using this INSTEAD of csh, bash, etc., that might be likely 
once it gets beyond 10% of the usefulness.  Right now, it's at about 
0.01% And any habits a user gets within this environment have to be 
unlearned when he returns to a standard shell.


Back in the early days of MSDOS, the FORMAT command didn't require you 
to specify a drive letter.  So people could intend to format their 
floppy, and actually trash their hard disk.  So I had colleagues who 
put a FORMAT.BAt command on their path which hard-wired the A: 
parameter. Now what happens to one of those folks when he goes to 
another machine which doesn't have that batch file?  Ouch!  Instead I 
wrote a batch file that checked to make sure you had the A: 
parameter.  Rapidly, my fingers learned that  FORMAT A:  was the valid 
syntax, and pretty soon the batch file was unnecessary (for me).


If I were going to define a dozen aliases for other people to use, I'd 
make them something like:


def clear_hist():
print The function you want is probably   clear_history()



As for the print()
command, I do not like how os.getcwd() has single quotes around the
output.


Those quotes come from the Python interpreter, not from getcwd().


Plus, Linux shell do not print output with quotes.

I want to make this a very useful and popular module, so I will use the
suggestions and add more useful wrappers. Would it help if I made a
Youtube video showing how this module can be used?

I will post the next version on this mailing list for another review.
Thanks everyone, and thanks a lot Steven D'Aprano!



Have you figured out how you're going to do things like cd (os.chdir), 
which have to remember state?  And how to pass the new current 
directory to the shell that launched Python?


Have you looked at ipython (ipython.org) ?  At least from there, you 
can get command completion with tab, one-third of the bash 
functionality. So if you type  boash.cle   then tab  it'll fill in 
the rest.





Thanks! I will look into IPython. I am familiar with it already. Yes, I 
have two purposes for the module, but after reading these suggestions I 
have modified my goal and purpose to achieve the goal of making a useful 
and popular Python3 module. The whole point of my boash project is to 
make a useful module. How can I make this module useful? I

Re: Cross-Platform Python3 Equivalent to notify-send

2013-07-27 Thread Devyn Collier Johnson


On 07/27/2013 12:06 PM, Chris Angelico wrote:

On Sat, Jul 27, 2013 at 4:59 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:

On Sat, 27 Jul 2013 08:22:00 -0400, Devyn Collier Johnson wrote:

That really sucks. I was hoping Python had some way of doing that. All
that it needs to do is display a little box at one of the corners of the
screen. I thought someone would have implemented something by now. Thank
you anyway.

If it's that simple, how about you do it? Won't take you more than, oh,
ten minutes, right?

*wink*

Don't underestimate the difficulty of trivial code when it has to work
on two dozens different platforms with different capabilities

That doesn't mean the question shouldn't be asked, of course. Steven
isn't (at least, I don't think he is!) scorning you for asking.
Sometimes the response is quite the opposite - that it's so utterly
trivial that there's no NEED for a library function! Never hurts to
throw the question out there...

ChrisA
I wanted to make a module (boash) that would be useful, but clearly it 
is not. Here, is a feature that is useful that no one has. This may be 
the module I decide to make. So, there is no cross-platform for such a 
command any where? Would this be a useful module?


I know Steven is not scorning me. He is making me think and I have an idea.


Mahalo,

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



Re: Critic my module

2013-07-27 Thread Devyn Collier Johnson


On 07/27/2013 11:14 AM, Jason Swails wrote:
You've gotten plenty of good advice from people discussing the coding 
and coding style itself, I'll provide some feedback from the vantage 
point of a perspective user.



On Thu, Jul 25, 2013 at 9:24 AM, Devyn Collier Johnson 
devyncjohn...@gmail.com mailto:devyncjohn...@gmail.com wrote:


Aloha Python Users!

   I made a Python3 module that allows users to use certain Linux
shell commands from Python3 more easily than using os.system(),
subprocess.Popen(), or subprocess.getoutput(). This module (once
placed with the other modules) can be used like this

import boash; boash.ls http://boash.ls()


I actually wrote a program recently in which I wanted access to unix 
ls command, and I wanted it to behave as close to the real, UNIX 
ls as possible.


This would seem like a perfect use-case for your module, but the 
problem is that the 'ls' command in your module does not behave much 
like the real 'ls' command.  You never let any of the 'system' 
commands in your module access any arguments.  More often than not, I 
use ls with several command-line arguments, like:


ls --color=auto -lthr dir_basename*/

Even if you're just spawning 'ls' directly, this is actually 
non-trivial to implement.  You need globbing on all non-option 
arguments, you may want to pass up the return code somehow, depending 
on what the user wants to do:


[bash ]$ ls nodir
ls: nodir: No such file or directory
[bash ]$ echo $?
1

Also, 'ls' in the terminal behaves like ls -C when called from your 
module.  In the framework of my program, my 'ls' command looks like this:


class ls(Action):
   
   Lists directory contents. Like UNIX 'ls'
   
   needs_parm = False
   def init(self, arg_list):
  from glob import glob
  self.args = []
  # Process the argument list to mimic the real ls as much as possible
  while True:
 try:
arg = arg_list.get_next_string()
if not arg.startswith('-'):
   # Glob this argument
   globarg = glob(arg)
   if len(globarg)  0:
  self.args.extend(globarg)
   else:
self.args.append(arg)
else:
 self.args.append(arg)
 except NoArgument:
break

   def __str__(self):
  from subprocess import Popen, PIPE
  process = Popen(['/bin/ls', '-C'] + self.args, stdout=PIPE, 
stderr=PIPE)

  out, err = process.communicate('')
  process.wait()
  return out + err

[I have omitted the Action base class, which processes the user 
command-line arguments and passes it to the init() method in arg_list 
-- this listing was just to give you a basic idea of the complexity of 
getting a true-er 'ls' command].


Your 'uname' command is likewise limited (and the printout looks strange:

 print(platform.uname())
('Linux', 'Batman', '3.3.8-gentoo', '#1 SMP Fri Oct 5 14:14:57 EDT 
2012', 'x86_64', 'AMD FX(tm)-6100 Six-Core Processor')


Whereas:

[bash $] uname -a
Linux Batman 3.3.8-gentoo #1 SMP Fri Oct 5 14:14:57 EDT 2012 x86_64 
AMD FX(tm)-6100 Six-Core Processor AuthenticAMD GNU/Linux


You may want to change that to:

def uname():
print(' '.join(platform.uname()))

Although again, oftentimes people want only something specific from 
uname (like -m or -n).


HTH,
Jason

For now, I will decide if it would be worth my time to make such a 
module seeing that many feel that it may not be useful. Thank you all 
for your feedback.


Mahalo,

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


Re: Cross-Platform Python3 Equivalent to notify-send

2013-07-27 Thread Devyn Collier Johnson


On 07/27/2013 11:59 AM, Steven D'Aprano wrote:

On Sat, 27 Jul 2013 08:22:00 -0400, Devyn Collier Johnson wrote:


On 07/27/2013 07:30 AM, Chris “Kwpolska” Warrick wrote:

On Sat, Jul 27, 2013 at 12:58 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

Linux systems with the proper software can use the notify-send
command. Is there a cross-platform Python3 equivalent?

[snip answer no]


That really sucks. I was hoping Python had some way of doing that. All
that it needs to do is display a little box at one of the corners of the
screen. I thought someone would have implemented something by now. Thank
you anyway.

If it's that simple, how about you do it? Won't take you more than, oh,
ten minutes, right?

*wink*

Don't underestimate the difficulty of trivial code when it has to work
on two dozens different platforms with different capabilities:

Windows XP, 2000, Vista, 7, 8 ...
Mac OS-X
FreeBSD, OpenBSD, Linux, running KDE (3 or 4?), Gnome (2 or 3?), Trinity,
RatPoison, XFCE, something else... or no window manager at all



Yeah, good point Steven. It seems like it would be easy, but I know it 
is not.


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


Re: Python Script Hashplings

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 09:54 AM, MRAB wrote:

On 25/07/2013 14:42, Devyn Collier Johnson wrote:

If I execute a Python3 script with this haspling (#!/usr/bin/python3.3)
and Python3.3 is not installed, but Python3.2 is installed, would the
script still work? Would it fall back to Python3.2?


Why don't you try it?

I hope Dihedral is listening. I would like to see another response 
from HIM.




Good point, but if it falls back to Python3.2, how would I know? Plus, I 
have Python3.3, 3.2, and 2.7 installed. I cannot uninstall them due to 
dependencies.


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


Re: Critic my module

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 09:58 AM, Schneider wrote:

Hi,

nice idea.

mybe -  for security reasons - you should ensure, that the right tool 
is called and not some tool put the path with the same name.


bg,
Johannes

On Thu 25 Jul 2013 03:24:30 PM CEST, Devyn Collier Johnson wrote:

Aloha Python Users!

   I made a Python3 module that allows users to use certain Linux
shell commands from Python3 more easily than using os.system(),
subprocess.Popen(), or subprocess.getoutput(). This module (once
placed with the other modules) can be used like this

import boash; boash.ls()

   I attached the module. I plan to release it on the Internet soon,
but feel free to use it now. It is licensed under LGPLv3.

   The name comes from combining Boa with SHell. Notice that the
module's name almost looks like BASH, a common Linux shell. The Boa
is a constrictor snake. This module makes Unix shells easier to use
via Python3. This brings the system shell closer to the Python shell.


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com






--
GLOBE Development GmbH
Königsberger Strasse 260
48157 MünsterGLOBE Development GmbH
Königsberger Strasse 260
48157 Münster
0251/5205 390


What do you mean by that Schneider?

Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Hashplings

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 10:01 AM, Matthew Lefavor wrote:
The answer is probably not. If you just want to use the latest 
version of Python 3 you have installed on your system, use: 
#!/usr/bin/python3. When you use the specific minor version numbers, 
they point to that specific minor version.


Actually, the preferred shebang line is of the form: #!/usr/bin/env 
python3. This way the end users can override the interpreter with, 
say, a virtualenv, rather than being stuck with the system default.



On Thu, Jul 25, 2013 at 9:54 AM, MRAB pyt...@mrabarnett.plus.com 
mailto:pyt...@mrabarnett.plus.com wrote:


On 25/07/2013 14:42, Devyn Collier Johnson wrote:

If I execute a Python3 script with this haspling
(#!/usr/bin/python3.3)
and Python3.3 is not installed, but Python3.2 is installed,
would the
script still work? Would it fall back to Python3.2?

Why don't you try it?


I hope Dihedral is listening. I would like to see another
response from HIM.


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







Thanks Matthew Lefavor! But specifically, why use #!/usr/bin/env 
python3 instead of #!/usr/bin/python3?


Mahalo,

DCJ

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


Re: Critic my module

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 10:09 AM, Alain Ketterlin wrote:

Devyn Collier Johnson devyncjohn...@gmail.com writes:


I made a Python3 module that allows users to use certain Linux
shell commands from Python3 more easily than using os.system(),
subprocess.Popen(), or subprocess.getoutput(). This module (once
placed with the other modules) can be used like this

Good, but I doubt it's really useful: I think nobody is going to add a
dependency on your module for, basically, one-line wrappers...

Here are a few comments:


def ls():
version = '0.3'
print(subprocess.getoutput('ls'))

version is local here, so basically your first statement is useless
(search for global in python's language ref).


def uname():
version = '0.3'
print(platform.uname())

I once learned: never print anything in a library function. This is a
bad thing to do, for a variety of reasons. For instance, stdout may be
redirected during this call...


def man(x):
version = '0.3'
print(subprocess.getoutput('man' + x))

getoutput is (essentially) Popen(...,shell=True), and the doc says:

the use of shell=True is strongly discouraged in cases where the
command string is constructed from external input

(for very good reasons)


def clear_bash_history():
version = '0.3'
print(subprocess.getoutput('history -c'))

Who told you subprocess will use bash? Again, the doc:

On Unix with shell=True, the shell defaults to /bin/sh.

All your uses of bash-isms may break (esp. !!)


def firefox():
version = '0.3'
print(subprocess.Popen('(firefox )'))

See section Replacing the os.spawn family in... the doc.


def go_back():
version = '0.3'
print(subprocess.Popen('cd !!:1'))

Hopeless. Have you tried this?


def reboot():
version = '0.3'
print(subprocess.Popen('shutdown -r now'))

What do you expect this to print? I mean, after shutdown/reboot.


version = '0.6b'

So, what's the version? 0.3 or 0.6b

(btw, are you sure this version is the same as the one you use in all
functions?).

-- Alain.


The version in each function is the version of that function if users 
want to know what version they are using. The last version is for the 
whole module. The module overall is version 0.6b. The module started 
with a few functions and as I increased the number of functions, I 
increased the module version number. It is a coincidence that all of the 
modules happen to have the same version number. I increase the version 
number after I work on a function. I cannot remember the command to 
print a module's/function's version number, but with that command, you 
could see the version of a particular function or module. No, I have not 
tried go_back(), thank you for catching that.


The main point of this is for shell users that are using Python and do 
not know some of the Python commands. This module would make Python more 
like a Linux shell. For instance, a shell user would type boash.uname() 
because they may not know they can type import platform; platform.uname().


I know that printing is not really the best of ideas, but how else can I 
make the output be displayed without quotes or newline marks?


Thank you very much Alain Ketterlin for your feedback!

Mahalo,

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


Re: Python Script Hashplings

2013-07-26 Thread Devyn Collier Johnson


On 07/26/2013 10:14 AM, Chris Angelico wrote:

On Fri, Jul 26, 2013 at 2:53 PM, MRAB pyt...@mrabarnett.plus.com wrote:

If you want to test what would happen if that version wasn't installed,
set the shebang line to a future version, such as Python 3.4. I doubt
you have that installed! :-)

Be careful, some people DO have a python3.4 binary :) Go for 3.5 for a
bit more reliability.

rosuav@sikorsky:~$ python3.4
3.4.0a0 (default:da7d97ca1ef6, Jul 13 2013, 14:05:08)
[GCC 4.7.2]

ChrisA


Thank you everyone for your comments and suggestions. I made a script to 
test the question. see for yourself:


SCRIPT:

#!/usr/bin/env python3.5
import sys; print(sys.version)


OUTPUT IN TERMINAL:

collier@Nacho-Laptop:~$ ./test.py
/usr/bin/env: python3.5: No such file or directory


Mahalo,

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


Critic my module

2013-07-25 Thread Devyn Collier Johnson

Aloha Python Users!

   I made a Python3 module that allows users to use certain Linux shell 
commands from Python3 more easily than using os.system(), 
subprocess.Popen(), or subprocess.getoutput(). This module (once placed 
with the other modules) can be used like this


import boash; boash.ls()

   I attached the module. I plan to release it on the Internet soon, 
but feel free to use it now. It is licensed under LGPLv3.


   The name comes from combining Boa with SHell. Notice that the 
module's name almost looks like BASH, a common Linux shell. The Boa is 
a constrictor snake. This module makes Unix shells easier to use via 
Python3. This brings the system shell closer to the Python shell.



Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
#!/usr/bin/python3
#Made by Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS
#Made using the Geany IDE
#LGPLv3
import re, sys, subprocess, platform
def grep(regex,textf):
#Sample Command: grep.grep(^x,dir())
#Syntax: boash.grep(regexp_string,list_of_strings_to_search)
version = '0.2a'
expr = re.compile(regex)
match = re.findall(expr, textf)
if match != None:
print(match)
def ls():
version = '0.3'
print(subprocess.getoutput('ls'))
def dir():
version = '0.3'
print(subprocess.getoutput('dir'))
def ll():
version = '0.3'
print(subprocess.getoutput('ls -l'))
def vdir():
version = '0.3'
print(subprocess.getoutput('ls -l'))
def uname():
version = '0.3'
print(platform.uname())
def cmd(*arg):
version = '0.3'
print(subprocess.getoutput(arg))
def command(*arg):
version = '0.3'
print(subprocess.getoutput(arg))
def man(x):
version = '0.3'
print(subprocess.getoutput('man' + x))
def apropos(*arg):
version = '0.3'
print(subprocess.getoutput('apropos' + arg))
def bash(*arg):
version = '0.3'
print(subprocess.getoutput(arg))
def shell(*arg):
version = '0.3'
print(subprocess.getoutput(arg))
def clear_bash_history():
version = '0.3'
print(subprocess.getoutput('history -c'))
def clear_bash_hist():
version = '0.3'
print(subprocess.getoutput('history -c'))
def clear_hist():
version = '0.3'
print(subprocess.getoutput('history -c'))
def clear_history():
version = '0.3'
print(subprocess.getoutput('history -c'))
def del_bash_hist():
version = '0.3'
print(subprocess.getoutput('history -c'))
def delete_bash_hist():
version = '0.3'
print(subprocess.getoutput('history -c'))
def del_hist():
version = '0.3'
print(subprocess.getoutput('history -c'))
def delete_history():
version = '0.3'
print(subprocess.getoutput('history -c'))
def delete_bash_history():
version = '0.3'
print(subprocess.getoutput('history -c'))
def delete_hist():
version = '0.3'
print(subprocess.getoutput('history -c'))
def firefox():
version = '0.3'
print(subprocess.Popen('(firefox )'))
def opera():
version = '0.3'
print(subprocess.Popen('(opera )'))
def arora():
version = '0.3'
print(subprocess.Popen('(arora )'))
def dolphin():
version = '0.3'
print(subprocess.Popen('(dolphin )'))
def nautilus():
version = '0.3'
print(subprocess.Popen('(nautilus )'))
def konqueror():
version = '0.3'
print(subprocess.Popen('(konqueror )'))
def smplayer():
version = '0.3'
print(subprocess.Popen('(smplayer )'))
def mplayer():
version = '0.3'
print(subprocess.Popen('(mplayer )'))
def vlc():
version = '0.3'
print(subprocess.Popen('(vlc )'))
def qvlc():
version = '0.3'
print(subprocess.Popen('(qvlc )'))
def nvlc():
version = '0.3'
jprint(subprocess.Popen('(nvlc )'))
def svlc():
version = '0.3'
print(subprocess.Popen('(svlc )'))
def rvlc():
version = '0.3'
print(subprocess.Popen('(rvlc )'))
def xterm():
version = '0.3'
print(subprocess.Popen('(xterm )'))
def geany():
version = '0.3'
print(subprocess.Popen('(geany )'))
def lsof():
version = '0.3'
print(subprocess.getoutput(lsof))
def free(*arg):
version = '0.3'
print(subprocess.getoutput('free' + arg))
def lsof(*arg):
version = '0.3'
print(subprocess.getoutput('lsof' + arg))
def pwd():
version = '0.3'
print(subprocess.getoutput('pwd'))
def getcwd():
version = '0.3'
print(subprocess.getoutput('pwd'))
def whoami():
version = '0.3'
print(subprocess.getoutput('whoami'))
def finger():
version = '0.3'
print(subprocess.getoutput('finger'))
def hostname():
version = '0.3'
print(subprocess.getoutput('hostname'))
def arch():
version = '0.3'
print

Re: PyGLet on Python 3

2013-07-25 Thread Devyn Collier Johnson


On 07/23/2013 02:24 AM, John Ladasky wrote:

On 07/21/2013 08:10 PM, Joseph Clark wrote:

John, have you taken a look at pyglet?  It's an alternative to pygame and I 
found it pretty slick once I got the hang of it.  There is a development 
version that's compatible with python 3 and I've never had a bug with it.  It 
wraps OpenGL itself so there are no additional dependencies.


// joseph w. clark , phd , visiting research associate
\\ university of nebraska at omaha - college of IST
  

Hi Joe,

Thanks for the PyGLet recommendation.  I like OpenGL.  Unfortunately, I can't seem to get 
PyGLet to work, even though the pyglet.org front page claims that the major 
1.2alpha1 release brings pyglet to Python 3.

I followed the links to this page:

https://code.google.com/p/pyglet/downloads/list?q=1.2alpha1

I installed pyglet on my Linux system's Python 3.3 using distutils, as I have 
done with many other packages.  But I can't run test.py, nor can I even get as 
far as importing pyglet from my Python 3.3 interpreter command line.  The 
obstacle is apparently Python 2.x-style print statements, which are found 
throughout tests.py and pyglet/__init__.py.

Does anyone know an efficient way around this problem?  Thanks!
I cannot get Pyglet to work. I successfully installed the module and it 
imports successfully, but a previously suggested command does not work. 
I use Python3.


 import pyglet
 pyglet.media.load('./boot.ogg', streaming=False).play()
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'module' object has no attribute 'media'

Mahalo,

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


Python Script Hashplings

2013-07-25 Thread Devyn Collier Johnson
If I execute a Python3 script with this haspling (#!/usr/bin/python3.3) 
and Python3.3 is not installed, but Python3.2 is installed, would the 
script still work? Would it fall back to Python3.2?


I hope Dihedral is listening. I would like to see another response from HIM.

Mahalo,

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


Cross-Platform Python3 Equivalent to notify-send

2013-07-25 Thread Devyn Collier Johnson
Linux systems with the proper software can use the notify-send 
command. Is there a cross-platform Python3 equivalent?


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-25 Thread Devyn Collier Johnson


On 07/25/2013 09:36 AM, Jeremy Sanders wrote:

wxjmfa...@gmail.com wrote:


Short example. Writing an editor with something like the
FSR is simply impossible (properly).

http://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Representations.html#Text-Representations

To conserve memory, Emacs does not hold fixed-length 22-bit numbers that are
codepoints of text characters within buffers and strings. Rather, Emacs uses a
variable-length internal representation of characters, that stores each
character as a sequence of 1 to 5 8-bit bytes, depending on the magnitude of
its codepoint[1]. For example, any ASCII character takes up only 1 byte, a
Latin-1 character takes up 2 bytes, etc. We call this representation of text
multibyte.

...

[1] This internal representation is based on one of the encodings defined by
the Unicode Standard, called UTF-8, for representing any Unicode codepoint, but
Emacs extends UTF-8 to represent the additional codepoints it uses for raw 8-
bit bytes and characters not unified with Unicode.



Jeremy


Wow! The thread that I started has changed a lot and lived a long time. 
I look forward to its first birthday (^u^).


Devyn Collier Johnson
--
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-23 Thread Devyn Collier Johnson


On 07/23/2013 01:19 AM, David Hutto wrote:
Devyn, are you just trying to use this in an application? Would a 
browser based web app work. I ask because there will still be some 
sort of DB interaction, so could it be an option to go with a browser 
command?



On Mon, Jul 22, 2013 at 8:37 PM, alex23 wuwe...@gmail.com 
mailto:wuwe...@gmail.com wrote:


On 20/07/2013 10:25 PM, Devyn Collier Johnson wrote:

I have not heard of Pyaudio; I will look into that. As
for Pygame, I have not been able to find any good
documentation for
playing audio files. Plus, I recently learned that Pygame is
not Python3
compatible.


Another option would be Pyglet, which uses the cross-platform
binary AVBin to provide sound support. It may not provide as much
control as PyAudio, but given your example usage it might be a bit
more straightforward:

   pyglet.media.load('boot.ogg', streaming=False).play()

http://www.pyglet.org/doc/programming_guide/simple_audio_playback.html

The latest development release provides support for Python 3:

https://code.google.com/p/pyglet/downloads/list?q=1.2alpha1
-- 
http://mail.python.org/mailman/listinfo/python-list





--
Best Regards,
David Hutto
/*CEO:*/ _http://www.hitwebdevelopment.com_




I will be playing an ogg file as a bootup sound for a chatbot that runs 
in a terminal. There are no web-applications. I will be looking into the 
different suggestions that I was offered. So far, Pyglet seems to be the 
best. Once I have officially decided and implemented an idea, I will 
share my choice with everyone.


Mahalo,
DCJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-22 Thread Devyn Collier Johnson


On 07/21/2013 10:10 AM, Stefan Behnel wrote:

Devyn Collier Johnson, 20.07.2013 14:25:

On 07/20/2013 12:21 AM, Stefan Behnel wrote:

Devyn Collier Johnson, 20.07.2013 03:06:

I am making a chatbot that I host on Launchpad.net/neobot. I am currently
converting the engine from BASH code to Python3. I need to convert this for
cross-platform compatibility. I do not need to use Mplayer; I just show the
below code to give others a better idea what I am doing. I would prefer to
be Python3 independent; I do not want to use the system shell. I am fine
with using Python3 modules like Pygame (if there is a py3 module). As long
as the code is fast, efficient, and simple without depending on the system
shell or external apps, that would be nice. I also need the code to execute
while the rest of the script continues running.

  jobs = multiprocessing.Process(SEND = subprocess.getoutput('mplayer
-nogui -nolirc -noar -quiet ./conf/boot.ogg')) #Boot sound#

Well, since you mentioned it already, have you actually looked at pygame?
It should be able to do what you want. There's also pyaudio, which is more
specialised to, well, audio. A web search for python and ogg might provide
more.

Thanks Stefan! I have not heard of Pyaudio; I will look into that. As for
Pygame, I have not been able to find any good documentation for playing
audio files.

A quick duckduckgo search gave me this, at least:

http://www.pygame.org/docs/ref/mixer.html



Plus, I recently learned that Pygame is not Python3 compatible.

Looks like it's your lucky day:

http://www.pygame.org/wiki/FrequentlyAskedQuestions#Does%20Pygame%20work%20with%20Python%203?

Stefan



Thanks!

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


Re: Play Ogg Files

2013-07-22 Thread Devyn Collier Johnson


On 07/21/2013 01:50 AM, Chris Angelico wrote:

On Sun, Jul 21, 2013 at 3:39 PM, David Hutto dwightdhu...@gmail.com wrote:

With linux you can have your package listed in synaptic, and can use with a
sudo apt-get install whatever ogg player like ogg123, and windows I don't
work with that much, but I'm pretty sure I've played .wav files from the
command line before while working with cross platform just for practice, so
with python 3 you can use what's available in the system with an if command.

Correction: With Debian-based Linux distributions, you can etc etc -
aptitude is Debian's package manager, it's not something you'll find
on other Linuxes. And the exact packages available depend on your
repositories; again, most Debian-derived Linux distros will most
likely have ogg123, but it's not guaranteed. However, it's reasonably
likely that other package managers and repositories will have what
you're looking for.

ChrisA
Good point, Chris. I do not want to make coding specifically for each 
package manager for many of the different distros. I follow the KISS 
princlple (Keep It Simple Stupid) when programming. Making a 
cross-platform/universal way to play an ogg file is better than being 
specific for each individual system.


Remember KISS.

Mahalo,

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


Re: Share Code Tips

2013-07-20 Thread Devyn Collier Johnson


On 07/19/2013 09:51 PM, Dave Angel wrote:

On 07/19/2013 09:04 PM, Devyn Collier Johnson wrote:




 snip



Chris Angelico said that casefold is not perfect. In the future, I want
to make the perfect international-case-insensitive if-statement. For
now, my code only supports a limited range of characters. Even with
casefold, I will have some issues as Chris Angelico mentioned. Also, ß
is not really the same as ss.



Sure, the casefold() method has its problems.  But you're going to 
avoid using it till you can do a perfect one?


Perfect in what context?  For case sensitively comparing people's 
names in a single language in a single country?  Perhaps that can be 
made perfect.  For certain combinations of language and country.


But if you want to compare words in an unspecified language with an 
unspecified country, it cannot be done.


If you've got a particular goal in mind, great.  But as a library 
function, you're better off using the best standard method available, 
and document what its limitations are.  One way of documenting such is 
to quote the appropriate standards, with their caveats.



By the way, you mentioned earlier that you're restricting yourself to 
Latin characters.  The lower() method is inadequate for many of those 
as well.  Perhaps you meant ASCII instead.


Of course not, Dave; I will implement casefold. I just plan to not stop 
there. My program should not come across unspecified languages. Yeah, I 
meant ASCII, but I was unaware that lower() had some limitation on Latin 
letters.


Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-20 Thread Devyn Collier Johnson


On 07/19/2013 11:44 PM, Steven D'Aprano wrote:

On Fri, 19 Jul 2013 21:04:55 -0400, Devyn Collier Johnson wrote:


In the future, I want to
make the perfect international-case-insensitive if-statement. For now,
my code only supports a limited range of characters. Even with casefold,
I will have some issues as Chris Angelico mentioned.

There are hundreds of written languages in the world, with thousands of
characters, and most of them have rules about case-sensitivity and
character normalization. For example, in Greek, lowercase Σ is σ except
at the end of a word, when it is ς.

≻≻≻ 'Σσς'.upper()
'ΣΣΣ'
≻≻≻ 'Σσς'.lower()
'σσς'
≻≻≻ 'Σσς'.casefold()
'σσσ'


So in this case, casefold() correctly solves the problem, provided you
are comparing modern Greek text. But if you're comparing text in some
other language which merely happens to use Greek letters, but doesn't
have the same rules about letter sigma, then it will be inappropriate. So
you cannot write a single perfect case-insensitive comparison, the best
you can hope for is to write dozens or hundreds of separate case-
insensitive comparisons, one for each language or family of languages.

For an introduction to the problem:

http://www.w3.org/International/wiki/Case_folding

http://www.unicode.org/faq/casemap_charprop.html





Also, ß is not really the same as ss.

Sometimes it is. Sometimes it isn't.



Wow, my if-statement is so imperfect! Thankfully, only English people 
will talk to an English chatbot (I hope), so for my use of the code, it 
will work.

Do the main Python3 developers plan to do something about this?

Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-20 Thread Devyn Collier Johnson


On 07/19/2013 11:18 PM, Steven D'Aprano wrote:

On Fri, 19 Jul 2013 18:08:43 -0400, Devyn Collier Johnson wrote:


As for the case-insensitive if-statements, most code uses Latin letters.
Making a case-insensitive-international if-statement would be
interesting. I can tackle that later. For now, I only wanted to take
care of Latin letters. I hope to figure something out for all
characters.

As I showed, even for Latin letters, the trick of if astring.lower() ==
bstring.lower() doesn't *quite* work, although it can be close enough
for some purposes. For example, some languages treat accents as mere
guides to pronunciation, so ö == o, while other languages treat them as
completely different letters. Same with ligatures: in modern English, æ
should be treated as equal to ae, but in Old English, Danish, Norwegian
and Icelandic it is a distinct letter.

Case-insensitive testing may be easier in many non-European languages,
because they don't have cases.

A full solution to the problem of localized string matching requires
expert knowledge for each language, but a 90% solution is pretty simple:

astring.casefold() == bstring.casefold()

or before version 3.3, just use lowercase. It's not a perfect solution,
but it works reasonably well if you don't care about full localization.



Thanks for the tips. I am learning a lot from this mailing list. I hope 
my code helped some people though.


Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-20 Thread Devyn Collier Johnson


On 07/19/2013 09:13 PM, Chris Angelico wrote:

On Sat, Jul 20, 2013 at 11:04 AM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

On 07/19/2013 07:09 PM, Dave Angel wrote:

On 07/19/2013 06:08 PM, Devyn Collier Johnson wrote:


On 07/19/2013 01:59 PM, Steven D'Aprano wrote:


  snip


As for the case-insensitive if-statements, most code uses Latin letters.
Making a case-insensitive-international if-statement would be
interesting. I can tackle that later. For now, I only wanted to take
care of Latin letters. I hope to figure something out for all characters.


Once Steven gave you the answer, what's to figure out?  You simply use
casefold() instead of lower().  The only constraint is it's 3.3 and later,
so you can't use it for anything earlier.

http://docs.python.org/3.3/library/stdtypes.html#str.casefold


str.casefold()
Return a casefolded copy of the string. Casefolded strings may be used for
caseless matching.

Casefolding is similar to lowercasing but more aggressive because it is
intended to remove all case distinctions in a string. For example, the
German lowercase letter 'ß' is equivalent to ss. Since it is already
lowercase, lower() would do nothing to 'ß'; casefold() converts it to ss.

The casefolding algorithm is described in section 3.13 of the Unicode
Standard.

New in version 3.3.



Chris Angelico said that casefold is not perfect. In the future, I want to
make the perfect international-case-insensitive if-statement. For now, my
code only supports a limited range of characters. Even with casefold, I will
have some issues as Chris Angelico mentioned. Also, ß is not really the
same as ss.

Well, casefold is about as good as it's ever going to be, but that's
because the perfect international-case-insensitive comparison is a
fundamentally impossible goal. Your last sentence hints as to why;
there is no simple way to compare strings containing those characters,
because the correct treatment varies according to context.

Your two best options are: Be case sensitive (and then you need only
worry about composition and combining characters and all those
nightmares - the ones you have to worry about either way), or use
casefold(). Of those, I prefer the first, because it's safer; the
second is also a good option.

ChrisA
Thanks everyone (especially Chris Angelico and Steven D'Aprano) for all 
of your helpful suggests and ideas. I plan to implement casefold() in 
some of my programs.


Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-20 Thread Devyn Collier Johnson


On 07/20/2013 12:21 AM, Stefan Behnel wrote:

Devyn Collier Johnson, 20.07.2013 03:06:

I am making a chatbot that I host on Launchpad.net/neobot. I am currently
converting the engine from BASH code to Python3. I need to convert this for
cross-platform compatibility. I do not need to use Mplayer; I just show the
below code to give others a better idea what I am doing. I would prefer to
be Python3 independent; I do not want to use the system shell. I am fine
with using Python3 modules like Pygame (if there is a py3 module). As long
as the code is fast, efficient, and simple without depending on the system
shell or external apps, that would be nice. I also need the code to execute
while the rest of the script continues running.

 jobs = multiprocessing.Process(SEND = subprocess.getoutput('mplayer
-nogui -nolirc -noar -quiet ./conf/boot.ogg')) #Boot sound#

Well, since you mentioned it already, have you actually looked at pygame?
It should be able to do what you want. There's also pyaudio, which is more
specialised to, well, audio. A web search for python and ogg might provide
more.

Stefan


Thanks Stefan! I have not heard of Pyaudio; I will look into that. As 
for Pygame, I have not been able to find any good documentation for 
playing audio files. Plus, I recently learned that Pygame is not Python3 
compatible.


Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-20 Thread Devyn Collier Johnson


On 07/20/2013 12:26 AM, David Hutto wrote:
I didn't see that this was for a chess game. That seems more point and 
click. Everyone can recognize a bishop from a queen, or a rook from a 
pawn. So why would case sensitivity matter other than the 16 pieces on 
the board? Or am I misunderstanding the question?




On Sat, Jul 20, 2013 at 12:22 AM, David Hutto dwightdhu...@gmail.com 
mailto:dwightdhu...@gmail.com wrote:


It seems that you could use import re, in my mind's pseudo code,
to compile a translational usage of usernames/passwords that could
remain case sensitive by using just the translational
dictionaries, and refining with data input tests/unit tests.


On Sat, Jul 20, 2013 at 12:15 AM, David Hutto
dwightdhu...@gmail.com mailto:dwightdhu...@gmail.com wrote:

It seems, without utilizing this, or googling, that a case
sensitive library is either developed, or could be implemented
by utilizing case sensitive translation through a google
translation page using an urlopener, and placing in the data
to be processed back to the boolean value. Never attempted,
but the algorithm seems simpler than the dozens of solutions
method.




-- 
Best Regards,

David Hutto
/*CEO:*/ _http://www.hitwebdevelopment.com_




--
Best Regards,
David Hutto
/*CEO:*/ _http://www.hitwebdevelopment.com_


In the email, I am sharing various code snippets to give others ideas 
and inspiration for coding. I that particular snippet, I am giving 
Python3 programmers the idea of making chess tags on a HTML or XML 
interpreter. It would be neat to type a tag that would generate chess 
pieces instead of remembering the HTML ASCII code.


From my understanding, that email is not being displayed correctly. Are 
all of the lines run together?


Thank you for asking. I want everyone to understand the purpose of the 
email and that particular snippet. Remember, assumption is the lowest 
form of knowledge.


Mahalo,
DCJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-20 Thread Devyn Collier Johnson


On 07/20/2013 07:16 AM, Joshua Landau wrote:

On 19 July 2013 18:29, Serhiy Storchaka storch...@gmail.com wrote:

19.07.13 19:22, Steven D'Aprano написав(ла):


I also expect that the string replace() method will be second fastest,
and re.sub will be the slowest, by a very long way.


The string replace() method is fastest (at least in Python 3.3+). See
implementation of html.escape() etc.

def escape(s, quote=True):
 if quote:
 return s.translate(_escape_map_full)
 return s.translate(_escape_map)

I fail to see how this supports the assertion that str.replace() is
faster. However, some quick timing shows that translate has a very
high penalty for missing characters and is a tad slower any way.

Really, though, there should be no reason for .translate() to be
slower than replace -- at worst it should just be reduce(lambda s,
ab: s.replace(*ab), mapping.items()¹, original_str) and end up the
*same* speed as iterated replace. But the fact that it doesn't have to
re-build the string every replace means that theoretically it should
be a lot faster.

¹ I realise this won't actually work for several reasons, and doesn't
support things like passing in lists as mappings, but you could
trivially support the important builtin types² and fall back to the
original for others, where the pure-python __getitem__ is going to be
the slowest part anyway.

² List, tuple, dict, str, bytes -- so basically just mappings and
ordered iterables
Thanks Joshua Landau! str.replace() does appear to be best, so that is 
the suggestion that I will implement.


Mahalo,

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


Re: Play Ogg Files

2013-07-20 Thread Devyn Collier Johnson


On 07/20/2013 12:39 AM, David Hutto wrote:

you could use , and I think its

david@david:~$ python
Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type help, copyright, credits or license for more information.
 import subprocess
 subprocess.call(['espeak', 'word_spoken'], stdin=None, 
stdout=None, stderr=None, shell=False)




This is on ubuntu linux, using espeak.
this is on ubun


On Sat, Jul 20, 2013 at 12:21 AM, Stefan Behnel stefan...@behnel.de 
mailto:stefan...@behnel.de wrote:


Devyn Collier Johnson, 20.07.2013 03:06:
 I am making a chatbot that I host on Launchpad.net/neobot. I am
currently
 converting the engine from BASH code to Python3. I need to
convert this for
 cross-platform compatibility. I do not need to use Mplayer; I
just show the
 below code to give others a better idea what I am doing. I would
prefer to
 be Python3 independent; I do not want to use the system shell. I
am fine
 with using Python3 modules like Pygame (if there is a py3
module). As long
 as the code is fast, efficient, and simple without depending on
the system
 shell or external apps, that would be nice. I also need the code
to execute
 while the rest of the script continues running.

 jobs = multiprocessing.Process(SEND =
subprocess.getoutput('mplayer
 -nogui -nolirc -noar -quiet ./conf/boot.ogg')) #Boot sound#

Well, since you mentioned it already, have you actually looked at
pygame?
It should be able to do what you want. There's also pyaudio, which
is more
specialised to, well, audio. A web search for python and ogg might
provide
more.

Stefan


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




--
Best Regards,
David Hutto
/*CEO:*/ _http://www.hitwebdevelopment.com_


Where did Espeak come from? This is about playing an ogg file using 
Python3 code.


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


List as Contributor

2013-07-20 Thread Devyn Collier Johnson
Many users on here have answered my questions and given me ideas and 
suggestions for code that I am using in my open-source GPLv3 chatbot. 
When I release the next update (that will be in a month or two), does 
anyone that has contributed helpful ideas want to be listed as a 
contributor under the heading Gave Suggestions/Ideas? The chatbot, 
named Neobot, is hosted on Launchpad (Neobot is buggy right now).  
https://launchpad.net/neobot


For those of you that want to be listed, email me with your name as you 
want it displayed and your email or other contact information if you 
want. Once I release version 0.8, I will inform this mailing list.


Moderators: Would you like me to list the email address of this mailing 
list as a contributor?



Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-20 Thread Devyn Collier Johnson


On 07/20/2013 07:48 AM, Serhiy Storchaka wrote:

19.07.13 21:08, Skip Montanaro написав(ла):
Serhiy The string replace() method is fastest (at least in Python 
3.3+). See

Serhiy implementation of html.escape() etc.
I trust everybody knows by now that when you want to use regular
expressions you should shell out to Perl for the best performance. :-)


If you want to use regular expressions Python is not the best choice. 
But if you want to use Python regular expressions sometimes are the 
best choice.




That is an interesting concept. (^u^)

Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Find and Replace Simplification

2013-07-19 Thread Devyn Collier Johnson
I have some code that I want to simplify. I know that a for-loop would 
work well, but can I make re.sub perform all of the below tasks at once, 
or can I write this in a way that is more efficient than using a for-loop?


DATA = re.sub(',', '', 'DATA')
DATA = re.sub('\'', '', 'DATA')
DATA = re.sub('(', '', 'DATA')
DATA = re.sub(')', '', 'DATA')
--
http://mail.python.org/mailman/listinfo/python-list


Share Code Tips

2013-07-19 Thread Devyn Collier Johnson

Aloha Python Users!

I have some coding tips and interesting functions that I want to share 
with all of you. I want to give other programmers ideas and inspiration. 
It is all Python3; most of it should work in Python2. I am a Unix/Linux 
person, so some of these will only work on Unix systems. Sorry Microsuck 
users :-D ;-)


All of the below Python3 code came from Neobot v0.8dev. I host an 
artificial intelligence program on Launchpad (LP Username: 
devyncjohnson-d). I have not released my Python version yet. The current 
version of Neobot (v0.7a) is written in BASH and Python3.


To emulate the Linux shell's date command, use this Python

function def DATE(): print(time.strftime(%a %B %d %H:%M:%S %Z %Y))

Want an easy way to clear the terminal screen? Then try this:

def clr(): os.system(['clear','cls'][os.name == 'nt'])

Here are two Linux-only functions:

def GETRAM(): print(linecache.getline('/proc/meminfo', 
1).replace('MemTotal:', '').strip()) #Get Total RAM in kilobytes#
def KDE_VERSION(): print(subprocess.getoutput('kded4 --version | awk -F: 
\'NR == 2 {print $2}\'').strip()) ##Get KDE version##


Need a case-insensitive if-statement? Check this out:

if 'YOUR_STRING'.lower() in SOMEVAR.lower():

Have a Python XML browser and want to add awesome tags? This code would 
see if the code to be parsed contains chess tags. If so, then they are 
replaced with chess symbols. I know, many people hate trolls, but trolls 
are my best friends. Try this:


if 'chess_'.lower() in PTRNPRS.lower(): DATA = 
re.sub('chess_white_king/', '♔', PTRNPRS, flags=re.I); DATA = 
re.sub('chess_white_queen/', '♕', DATA, flags=re.I); DATA = 
re.sub('chess_white_castle/', '♖', DATA, flags=re.I); DATA = 
re.sub('chess_white_bishop/', '♗', DATA, flags=re.I); DATA = 
re.sub('chess_white_knight/', '♘', DATA, flags=re.I); DATA = 
re.sub('chess_white_pawn/', '♙', DATA, flags=re.I); DATA = 
re.sub('chess_black_king/', '♚', DATA, flags=re.I); DATA = 
re.sub('chess_black_queen/', '♛', DATA, flags=re.I); DATA = 
re.sub('chess_black_castle/', '♜', DATA, flags=re.I); DATA = 
re.sub('chess_black_bishop/', '♝', DATA, flags=re.I); DATA = 
re.sub('chess_black_knight/', '♞', DATA, flags=re.I); PTRNPRS = 
re.sub('chess_black_pawn/', '♟', DATA, flags=re.I)


For those of you making scripts to be run in a terminal, try this for a 
fancy terminal prompt:


INPUTTEMP = input('User ≻≻≻')


I may share more code later. Tell me what you think of my coding style 
and tips.



Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Play Ogg Files

2013-07-19 Thread Devyn Collier Johnson

Aloha Python programmers!

I am making a chatbot that I host on Launchpad.net/neobot. I am 
currently converting the engine from BASH code to Python3. I need to 
convert this for cross-platform compatibility. I do not need to use 
Mplayer; I just show the below code to give others a better idea what I 
am doing. I would prefer to be Python3 independent; I do not want to use 
the system shell. I am fine with using Python3 modules like Pygame (if 
there is a py3 module). As long as the code is fast, efficient, and 
simple without depending on the system shell or external apps, that 
would be nice. I also need the code to execute while the rest of the 
script continues running.


jobs = multiprocessing.Process(SEND = subprocess.getoutput('mplayer 
-nogui -nolirc -noar -quiet ./conf/boot.ogg')) #Boot sound#


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread Devyn Collier Johnson


On 07/19/2013 12:19 PM, Steven D'Aprano wrote:

On Fri, 19 Jul 2013 10:21:10 -0400, Joel Goldstick wrote:


div dir=ltrbrdiv class=gmail_extrabrbrdiv
class=gmail_quote

[snip 70-odd lines of HTML...]


I#39;m guessing you may be posting with html.  So all your code runs
together.
br clear=all/divdiv class=gmail_extrabr-- brdiv
dir=ltr divJoel Goldstickbr/diva href=http://
joelgoldstick.com target=_blankhttp://joelgoldstick.com/a
br/div /div/div


My irony meter didn't merely explode, it actually vaporized.




What is the issue with my email? Should I resend it?

Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-19 Thread Devyn Collier Johnson


On 07/19/2013 12:22 PM, Steven D'Aprano wrote:

On Fri, 19 Jul 2013 09:22:48 -0400, Devyn Collier Johnson wrote:


I have some code that I want to simplify. I know that a for-loop would
work well, but can I make re.sub perform all of the below tasks at once,
or can I write this in a way that is more efficient than using a
for-loop?

DATA = re.sub(',', '', 'DATA')
DATA = re.sub('\'', '', 'DATA')
DATA = re.sub('(', '', 'DATA')
DATA = re.sub(')', '', 'DATA')


I don't think you intended to put DATA in quotes on the right hand side.
That makes it literally the string D A T A, so all those replacements are
no-ops, and you could simplify it to:

DATA = 'DATA'

But that's probably not what you wanted.

My prediction is that this will be by far the most efficient way to do
what you are trying to do:

py DATA = Hello, 'World'()
py DATA.translate(dict.fromkeys(ord(c) for c in ,'()))
'Hello World'

That's in Python 3 -- in Python 2, using translate will still probably be
the fastest, but you'll need to call it like this:

import string
DATA.translate(string.maketrans(, ), ,'())

I also expect that the string replace() method will be second fastest,
and re.sub will be the slowest, by a very long way.

As a general rule, you should avoiding using regexes unless the text you
are searching for actually contains a regular expression of some kind. If
it's merely a literal character or substring, standard string methods
will probably be faster.


Oh, and a tip for you:

- don't escape quotes unless you don't need to, use the other quote.

s = '\''  # No, don't do this!
s = '  # Better!

and vice versa.




Thanks for finding that error; DATA should not be in quotes. I cannot 
believe I missed that. Good eye Steven!


Using the replace command is a brilliant idea; I will implement that 
where ever I can. I am wanting to perform all of the replaces at once. 
Is that possible?


Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread Devyn Collier Johnson


On 07/19/2013 01:59 PM, Steven D'Aprano wrote:

On Fri, 19 Jul 2013 09:51:23 -0400, Devyn Collier Johnson wrote:


def KDE_VERSION():
 print(subprocess.getoutput('kded4 --version | awk -F:
 \'NR == 2 {print $2}\'').strip()) ##Get KDE version##

I run KDE 3, and the above does not work for me.

*half a wink*

By the way, a comment that doesn't tell you anything that you don't
already know is worse than useless. The function is called KDE_VERSION,
what else would it do other than return the KDE version?


x += 1  # add 1 to x

Worse than just being useless, redundant comments are dangerous, because
as a general rule comments that don't say anything useful eventually
become out-of-date, they become *inaccurate* rather than *redundant*, and
that's worse than being useless.



Need a case-insensitive if-statement? Check this out:

if 'YOUR_STRING'.lower() in SOMEVAR.lower():

Case-insensitivity is very hard. Take German for example:

STRASSE - straße

Or Turkish:

İ - i
I - ı


In Python 3.3, you should use casefold rather than lowercase or uppercase:

if some_string.casefold() in another_string.casefold(): ...


but even that can't always take into account localised rules, e.g. in
German, you should not convert SS to ß for placenames or person names, so
for example Herr Meißner and Herr Meissner are two different people. This
is one of the motivating reasons for introducing the uppercase ß.

http://opentype.info/blog/2011/01/24/capital-sharp-s/



Steven, thanks for your interesting comments. Your emails are very 
insightful.


As for the KDE function, I should fix that. Thank you for catching that. 
Notice that the shell command in the function is kded4. That would 
only check the version for the KDE4 series. The function will only work 
for KDE4 users. As for the comment, you would be amazed with the people 
that ask me what does this do?. These people are redundant (^u^).


As for the case-insensitive if-statements, most code uses Latin letters. 
Making a case-insensitive-international if-statement would be 
interesting. I can tackle that later. For now, I only wanted to take 
care of Latin letters. I hope to figure something out for all characters.


Thank you for your reply. I found it to be very helpful.

Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread Devyn Collier Johnson


On 07/19/2013 07:09 PM, Dave Angel wrote:

On 07/19/2013 06:08 PM, Devyn Collier Johnson wrote:


On 07/19/2013 01:59 PM, Steven D'Aprano wrote:


 snip


As for the case-insensitive if-statements, most code uses Latin letters.
Making a case-insensitive-international if-statement would be
interesting. I can tackle that later. For now, I only wanted to take
care of Latin letters. I hope to figure something out for all 
characters.




Once Steven gave you the answer, what's to figure out?  You simply use 
casefold() instead of lower().  The only constraint is it's 3.3 and 
later, so you can't use it for anything earlier.


http://docs.python.org/3.3/library/stdtypes.html#str.casefold


str.casefold()
Return a casefolded copy of the string. Casefolded strings may be used 
for caseless matching.


Casefolding is similar to lowercasing but more aggressive because it 
is intended to remove all case distinctions in a string. For example, 
the German lowercase letter 'ß' is equivalent to ss. Since it is 
already lowercase, lower() would do nothing to 'ß'; casefold() 
converts it to ss.


The casefolding algorithm is described in section 3.13 of the Unicode 
Standard.


New in version 3.3.


Chris Angelico said that casefold is not perfect. In the future, I want 
to make the perfect international-case-insensitive if-statement. For 
now, my code only supports a limited range of characters. Even with 
casefold, I will have some issues as Chris Angelico mentioned. Also, ß 
is not really the same as ss.


Mahalo,
DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Play Ogg Files

2013-07-19 Thread Devyn Collier Johnson

Aloha Python programmers!

I am making a chatbot that I host on Launchpad.net/neobot. I am 
currently converting the engine from BASH code to Python3. I need to 
convert this for cross-platform compatibility. I do not need to use 
Mplayer; I just show the below code to give others a better idea what I 
am doing. I would prefer to be Python3 independent; I do not want to use 
the system shell. I am fine with using Python3 modules like Pygame (if 
there is a py3 module). As long as the code is fast, efficient, and 
simple without depending on the system shell or external apps, that 
would be nice. I also need the code to execute while the rest of the 
script continues running.


jobs = multiprocessing.Process(SEND = subprocess.getoutput('mplayer 
-nogui -nolirc -noar -quiet ./conf/boot.ogg')) #Boot sound#


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-16 Thread Devyn Collier Johnson


Am 07/12/2013 07:16 PM, schrieb MRAB:

On 12/07/2013 23:16, Tim Delaney wrote:

On 13 July 2013 03:58, Devyn Collier Johnson devyncjohn...@gmail.com
mailto:devyncjohn...@gmail.com wrote:


Thanks for the thorough response. I learned a lot. You should write
articles on Python.
I plan to spend some time optimizing the re.py module for Unix
systems. I would love to amp up my programs that use that module.


If you are finding that regular expressions are taking too much time,
have a look at the https://pypi.python.org/pypi/re2/ and
https://pypi.python.org/pypi/regex/2013-06-26 modules to see if they
already give you enough of a speedup.


FYI, you're better off going to http://pypi.python.org/pypi/regex
because that will take you to the latest version.

Thank you everyone for the suggestions. I have not tried them yet.

Devyn Collier Johnson
--
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-15 Thread Devyn Collier Johnson


On 07/14/2013 02:17 PM, 8 Dihedral wrote:

On Saturday, July 13, 2013 1:37:46 PM UTC+8, Steven D'Aprano wrote:

On Fri, 12 Jul 2013 13:58:29 -0400, Devyn Collier Johnson wrote:




I plan to spend some time optimizing the re.py module for Unix systems.
I would love to amp up my programs that use that module.



In my experience, often the best way to optimize a regex is to not use it

at all.



[steve@ando ~]$ python -m timeit -s import re \


-s data = 'a'*100+'b' \
if re.search('b', data): pass

10 loops, best of 3: 2.77 usec per loop



[steve@ando ~]$ python -m timeit -s data = 'a'*100+'b' \


if 'b' in data: pass

100 loops, best of 3: 0.219 usec per loop



In Python, we often use plain string operations instead of regex-based

solutions for basic tasks. Regexes are a 10lb sledge hammer. Don't use

them for cracking peanuts.







--

Steven

OK, lets talk about the indexed search algorithms of
a character streamor strig which can be buffered and
indexed randomly for RW operations but faster in sequential
block RW operations after some pre-processing.

This was solved long time ago in the suffix array or
suffix tree part and summarized in the famous BWT paper in 199X.

Do we want volunteers to speed up
search operations in the string module in Python?

It would be nice if someone could speed it up.
--
http://mail.python.org/mailman/listinfo/python-list


Dihedral

2013-07-15 Thread Devyn Collier Johnson


On 07/15/2013 08:36 AM, Steven D'Aprano wrote:

On Mon, 15 Jul 2013 06:06:06 -0400, Devyn Collier Johnson wrote:


On 07/14/2013 02:17 PM, 8 Dihedral wrote:

[...]

Do we want volunteers to speed up
search operations in the string module in Python?

It would be nice if someone could speed it up.

Devyn,

8 Dihedral is our resident bot, not a human being. Nobody knows who
controls it, and why they are running it, but we are pretty certain that
it is a bot responding mechanically to keywords in people's posts.

It's a very clever bot, but still a bot. About one post in four is
meaningless jargon, the other three are relevant enough to fool people
into thinking that maybe it is a human being. It had me fooled for a long
time.



Wow! Our mailing list has a pet bot. I bet other mailing lists are so 
jealous of us. Who ever created Dihedral is a genius!


Artificial Intelligence developers put chatbots on mailing lists so that 
the program can learn. I use Python3 to program AI applications. If you 
see my Launchpad account, you will see my two AI projects - Neobot and 
Novabot. (https://launchpad.net/neobot Neo and Nova are still unstable) 
AI developers let their bots loose on the Internet to learn from people. 
Dihedral is learning from us. Dihedral only responses when it feels it 
has sufficient knowledge on the topic. Chatbots want to appear human. 
That is their goal. We should feel honored that Dihedral's botmaster 
feels that this mailinglist would benefit the development of Dihedral's 
knowledge.


Devyn Collier Johnson
--
http://mail.python.org/mailman/listinfo/python-list


Question about mailing list rules

2013-07-12 Thread Devyn Collier Johnson
Am I allowed to ask questions like Here is my code. How can I optimize 
it? on this mailing list?


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


RE Module Performance

2013-07-12 Thread Devyn Collier Johnson
I recently saw an email in this mailing list about the RE module being 
made slower. I no long have that email. However, I have viewed the 
source for the RE module, but I did not see any code that would slow 
down the script for no valid reason. Can anyone explain what that user 
meant or if I missed that part of the module?


Can the RE module be optimized in any way or at least the re.sub portion?

Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question about mailing list rules

2013-07-12 Thread Devyn Collier Johnson


On 07/12/2013 09:04 AM, Roy Smith wrote:

In article mailman.4621.1373613990.3114.python-l...@python.org,
  Chris Angelico ros...@gmail.com wrote:


On Fri, Jul 12, 2013 at 9:59 AM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

Am I allowed to ask questions like Here is my code. How can I optimize it?
on this mailing list?

Sure you can! And you'll get a large number of responses, not all of
which are directly to do with your question. :)

I assume the code in question _is_ written in Python, right?

If not, then the answer to how can I optimize it is obvious, isn't it?

Yeah, I should have been more specific and said Python.
--
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-12 Thread Devyn Collier Johnson
Could you explain what you mean? What and where is the new Flexible 
String Representation?


Devyn Collier Johnson


On 07/12/2013 05:23 AM, wxjmfa...@gmail.com wrote:

Le vendredi 12 juillet 2013 01:44:05 UTC+2, Devyn Collier Johnson a écrit :

I recently saw an email in this mailing list about the RE module being

made slower. I no long have that email. However, I have viewed the

source for the RE module, but I did not see any code that would slow

down the script for no valid reason. Can anyone explain what that user

meant or if I missed that part of the module?



Can the RE module be optimized in any way or at least the re.sub portion?



Mahalo,



Devyn Collier Johnson

devyncjohn...@gmail.com

--

I would not care too much about the performance
of re.

With the new Flexible String Representation, you
can use a logarithmic scale to compare re results.
To be honest, there is improvment if you are an
ascii user.

Am I the only one who tested this? Probably.

jmf




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


Re: Question about mailing list rules

2013-07-12 Thread Devyn Collier Johnson

I am going to love this mailing list even more.

Really, only Python code? I wanted to ask Python users about Perl! (^u^)

Devyn Collier Johnson


On 07/12/2013 03:26 AM, Chris Angelico wrote:

On Fri, Jul 12, 2013 at 9:59 AM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

Am I allowed to ask questions like Here is my code. How can I optimize it?
on this mailing list?

Sure you can! And you'll get a large number of responses, not all of
which are directly to do with your question. :)

I assume the code in question _is_ written in Python, right?

ChrisA


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


Re: Question about mailing list rules

2013-07-12 Thread Devyn Collier Johnson


On 07/12/2013 07:11 AM, Chris “Kwpolska” Warrick wrote:

On Fri, Jul 12, 2013 at 12:47 PM, Chris Angelico ros...@gmail.com wrote:

On Fri, Jul 12, 2013 at 8:44 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

I am going to love this mailing list even more.

Really, only Python code? I wanted to ask Python users about Perl! (^u^)

Devyn Collier Johnson

Heh. You'd be surprised what comes up. If it's at least broadly
related to Python (maybe you're comparing constructs in Python and
Perl??), it'll probably be accepted. And even stuff that's completely
off-topic does at times get discussed.

One small thing, though. Please avoid top-posting; the convention on
this list is to quote text above, and write yours underneath. Makes it
easier to follow the flow of conversation. Thanks!

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

One more thing Devyn should do is watch the “To:” field and make sure
it says python-list@python.org, because the above message was sent to
Chris only, and that is not what should happen most of the time.
Another option is to use Reply All, but it will make old Usenet hags
angry, because they would get two copies.

--
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html

Thank you and sorry about that.

Kwpolska, I noticed your email shows stop html mail at the bottom. I 
have Thunderbird setup to use HTML mail. Are my emails coming up as 
plain text or HTML on this mailing list?


Devyn Collier Johnson
--
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-12 Thread Devyn Collier Johnson


On 07/12/2013 12:21 PM, Chris Angelico wrote:

On Fri, Jul 12, 2013 at 8:45 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

Could you explain what you mean? What and where is the new Flexible String
Representation?

(You're top-posting again. Please put your text underneath what you're
responding to - it helps maintain flow and structure.)

Python versions up to and including 3.2 came in two varieties: narrow
builds (commonly found on Windows) and wide builds (commonly found on
Linux). Narrow builds internally represented Unicode strings in
UTF-16, while wide builds used UTF-32. This is a problem, because it
means that taking a program from one to another actually changes its
behaviour:

Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type help, copyright, credits or license for more information.

len(u\U00012345)

1

Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit
(Intel)] on win32

len(u\U00012345)

2

In fact, the narrow builds are flat-out buggy, because you can put
something in as a single character that simply isn't a single
character. You can then pull that out as two characters and make a
huge mess of things:


s=u\U00012345
s[0]

u'\ud808'

s[1]

u'\udf45'

*Any* string indexing will be broken if there is a single character

U+ ahead of it in the string.

Now, this problem is not unique to Python. Heaps of other languages
have the same issue, the same buggy behaviour, the same compromises.
What's special about Python is that it actually managed to come back
from that problem. (Google's V8 JavaScript engine, for instance, is
stuck with it, because the ECMAScript specification demands UTF-16. I
asked on an ECMAScript list and was told can't change that, it'd
break code. So it's staying buggy.)

There are a number of languages that take the Texan RAM-guzzling
approach of storing all strings in UTF-32; Python (since version 3.3)
is among a *very* small number of languages that store strings in
multiple different ways according to their content. That's described
in PEP 393 [1], titled Flexible String Representation. It details a
means whereby a Python string will be represented in, effectively,
UTF-32 with some of the leading zero bytes elided. Or if you prefer,
in either Latin-1, UCS-2, or UCS-4, whichever's the smallest it can
fit in. The difference between a string stored one-byte-per-character
and a string stored four-bytes-per-character is almost invisible to a
Python script; you can find out by checking the string's memory usage,
but otherwise you don't need to worry about it.

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600
32 bit (Intel)] on win32

sys.getsizeof(asdfasdfasdfasd)

40

sys.getsizeof(asdfasdfasdfasdf)

41

Adding another character adds another 1 byte. (There's quite a bit of
overhead for small strings - GC headers and such - but it gets dwarfed
by the actual content after a while.)


sys.getsizeof(\u1000sdfasdfasdfasd)

68

sys.getsizeof(\u1000sdfasdfasdfasdf)

70

Two bytes to add another character.


sys.getsizeof(\U00010001sdfasdfasdfasd)

100

sys.getsizeof(\U00010001sdfasdfasdfasdf)

104

Four bytes. It uses only what it needs.

Strings in Python are immutable, so there's no need to worry about
up-grading or down-grading a string; there are a few optimizations
that can't be done, but they're fairly trivial. Look, I'll pull a jmf
and find a microbenchmark that makes 3.3 look worse:

2.7.4:

timeit.repeat('a=uA*100; a+=u\u1000')

[0.8175005482540385, 0.789617954237201, 0.8152240019332098]

timeit.repeat('a=uA*100; a+=ua')

[0.8088905154146744, 0.8123691698246631, 0.8172558244134365]

3.3.0:

timeit.repeat('a=uA*100; a+=u\u1000')

[0.9623714745976031, 0.970628669281723, 0.9696310564468149]

timeit.repeat('a=uA*100; a+=ua')

[0.7017891938739922, 0.7024725209339522, 0.6989539173082449]

See? It's clearly worse on the newer Python! But actually, this is an
extremely unusual situation, and 3.3 outperforms 2.7 on the more
common case (where the two strings are of the same width).

Python's PEP 393 strings are following the same sort of model as the
native string type in a semantically-similar but
syntactically-different language, Pike. In Pike (also free software,
like Python), the string type can be indexed character by character,
and each character can be anything in the Unicode range; and just as
in Python 3.3, memory usage goes up by just one byte if every
character in the string fits inside 8 bits. So it's not as if this is
an untested notion; Pike has been running like this for years (I don't
know how long it's had this functionality, but it won't be more than
18 years as Unicode didn't have multiple planes until 1996), and
performance has been *just fine* for all that time. Pike tends to be
run on servers, so memory usage and computation speed translate fairly
directly into TPS. And there are some sizeable commercial entities
using and developing Pike, so if the flexible string representation
had