Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

2013-07-19 Thread Jake Angulo
On Thu, Jul 18, 2013 at 2:36 PM, Aseem Bansal  wrote:

> I wanted to do a little project for learning Python. I thought a chat
> system will be good as it isn't something that I have ever done.
> ...
> I wanted to know what will I need?
> 1 learn network/socket programming


I was actually expecting somebody to mention Twisted :)
(or Tornado)

You'll find it easy to use any of these frameworks to power the back-end
chat engine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

2013-07-19 Thread Chris Angelico
On Fri, Jul 19, 2013 at 5:10 PM, Jake Angulo  wrote:
> On Thu, Jul 18, 2013 at 2:36 PM, Aseem Bansal  wrote:
>>
>> I wanted to do a little project for learning Python. I thought a chat
>> system will be good as it isn't something that I have ever done.
>> ...
>>
>> I wanted to know what will I need?
>> 1 learn network/socket programming
>
>
> I was actually expecting somebody to mention Twisted :)
> (or Tornado)
>
> You'll find it easy to use any of these frameworks to power the back-end
> chat engine.

For something this simple, what do they offer above the basic socket
module? I know that sounds critical but it's not meant to be; I've
never looked into either, as I've grown up using the BSD socket APIs
(in C, 80x86 assembly, C++, REXX, Java, Pike, and Python, on DOS (I
think), OS/2, Windows, and Linux... and possibly other
languages/platforms that I've now forgotten), and am comfortable with
them; but for someone who hasn't been in networking for two decades,
is there a noteworthy ease-of-starting difference? Bear in mind that
use of a framework locks you in to that framework and its ecosystem
(so, most likely, language), while grokking sockets themselves gives
you the freedom to move as required.

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


Re: Stack Overflow moderator “animuson”

2013-07-19 Thread Jake Angulo
On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:

> A moderator who calls himself “animuson” on Stack Overflow doesn’t
> want to face the truth. He has deleted all my postings regarding Python
> regular expression matching being extremely slow compared to Perl.
> Additionally my account has been suspended for 7 days. Such a dickwad.
>
>
The OP meant to post:

A moderator who calls himself MatsDtroll on Stack Overflow doesn’t want to
face the truth. He has deleted all my postings regarding Perl regular
expression matching being extremely slow compared to Bash regex.
Additionally my account has been suspended for 7 days. Such a dickwad.
-- 
http://mail.python.org/mailman/listinfo/python-list


KeyboardInterrupt in Subproccesses

2013-07-19 Thread Matthew Lefavor
All:

I am maintaining a program in Python 2 and need to send it a
KeyboardInterrupt to close it. Unfortunately, the program is used as a
subprocess in a wrapper subprocess, and so I cannot just directly press
CTL-C; I have to use a signal.

When I run the program "bare" (not in a subprocess), I have found that
raising a SIGINT (kill -2) raises a KeyboardInterrupt in the program. But
when I run the program in the wrapper process, kill -2 no longer has any
effect (whether it is raised by the wrapper or externally).

Why is that the case? Does Python's interpretation of SIGINT as a
KeyboardInterrupt only obtain when the program is run in a terminal? Is
there something else I'm missing?

Bonus points: Is this behavior the same for Python 3?

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


Messages to Python-List aren't posting

2013-07-19 Thread Matthew Lefavor
All:

I've been having trouble with all three Python mailing lists (python-list,
python-dev, python-ideas). This has been going on for about a month.
Whenever I post, it takes hours for my messages to be posted on the list. I
first thought it was an issue with my work email server, but moving to
gmail has had no effect.

Is there some obscure setting I am missing? Has anybody else had this
problem?

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


Re: Messages to Python-List aren't posting

2013-07-19 Thread Chris Angelico
On Fri, Jul 19, 2013 at 6:30 AM, Matthew Lefavor  wrote:
> All:
>
> I've been having trouble with all three Python mailing lists (python-list,
> python-dev, python-ideas). This has been going on for about a month.
> Whenever I post, it takes hours for my messages to be posted on the list. I
> first thought it was an issue with my work email server, but moving to gmail
> has had no effect.
>
> Is there some obscure setting I am missing? Has anybody else had this
> problem?

This just came through, timestamped 11.5 hours ago. I don't usually
have this problem. Looking at your Received headers, in reverse order:

Date: Thu, 18 Jul 2013 16:30:51 -0400 - timestamp of your mail
Thu, 18 Jul 2013 13:30:51 -0700 (PDT) - you posted it via HTTP
Thu, 18 Jul 2013 22:31:39 +0200 (CEST) - it reached python.org
Fri, 19 Jul 2013 09:56:14 +0200 (CEST) - it began delivery to my address
Fri, 19 Jul 2013 00:56:15 -0700 (PDT) - it reached gmail and me.

So the big delay is somewhere within python.org. Since this does NOT
happen to everyone, I would be looking for something like:
* Moderation requirements (does your message not comply with spec?)
* Spam greylisting
* Slow/glitchy DNS when attempting to verify your message

Most likely I think is moderation, given the extreme length of time.
Something would have to be pretty glitchy to lag your mail out for
half a day in spam filtering. It's possible, I guess, though. I've no
idea what anti-spam features the list is using.

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


Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

2013-07-19 Thread Jorgen Grahn
On Thu, 2013-07-18, Chris Angelico wrote:
...
> You can certainly do your server-side programming directly in Python;
> in fact, I recommend it for this task. There's no reason to use HTTP,
> much less a web framework (which usually consists of a structured way
> to build HTML pages, plus a bunch of routing and stuff, none of which
> you need). All you need is a simple structure for separating one
> message from another.

> I would recommend either going MUD/TELNET style
> and ending each message with a newline, or prefixing each message with
> its length in octets. Both ways work very nicely; newline-termination
> allows you to use a MUD client for debugging, which I find very
> convenient

It's definitely the way to go.  It's not just MUDs -- a lot of
Internet protocols work that way.  Netcat is one popular client for
talking to/debugging/testing such servers.  No doubt MUD clients too,
but last time I did such stuff was in 1993, and I think I used telnet
...

In fact, I'd design the protocol before starting to write code.  Or
better, steal some existing chat protocol.  Like a subset of IRC.


There's also another question in the original posting that bothers me:
paraphrased "do I need to learn database programming to manage users"?
No!  Unix does fine with plain-text files.

Managing credentials (understanding cryptography, setting up a support
organization for resetting lost passwords ...) is non-trivial though,
so try to do without such things at first.  It's not obvious that you
should need an account for an experimental chat, anyway.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

2013-07-19 Thread Chris Angelico
On Fri, Jul 19, 2013 at 9:25 PM, Jorgen Grahn  wrote:
> On Thu, 2013-07-18, Chris Angelico wrote:
> ...
>> You can certainly do your server-side programming directly in Python;
>> in fact, I recommend it for this task. There's no reason to use HTTP,
>> much less a web framework (which usually consists of a structured way
>> to build HTML pages, plus a bunch of routing and stuff, none of which
>> you need). All you need is a simple structure for separating one
>> message from another.
>
>> I would recommend either going MUD/TELNET style
>> and ending each message with a newline, or prefixing each message with
>> its length in octets. Both ways work very nicely; newline-termination
>> allows you to use a MUD client for debugging, which I find very
>> convenient
>
> It's definitely the way to go.  It's not just MUDs -- a lot of
> Internet protocols work that way.  Netcat is one popular client for
> talking to/debugging/testing such servers.  No doubt MUD clients too,
> but last time I did such stuff was in 1993, and I think I used telnet

Yeah. As I mentioned, I'm a MUDder with tens of thousands of online
hours on Threshold RPG[1], and have written several MUD clients; in
fact, I'm right now working on Gypsum (fun fun). The most common
internet protocols all:
* Involve a well-known TCP port and a single socket connection (apart from FTP)
* Begin with a one-line (usually) greeting from the server
* Have a line-based request-and-response system
* Have normal lines divided into "command" and "parameters" as per
shell commands
* (Usually) have an easy way to recognize success/failure, even
without understanding the whole response
* Are human-readable to the extreme
* Rely on lower-level protocols for encryption (eg TLS)

The mail trilogy (SMTP, POP, IMAP) are all like this, with the caveat
that IMAP tags commands and responses (so the second word, not the
first, is the command). FTP is almost there, apart from its secondary
data channel. MUDs are definitely right there. And when I started
putting together some networking facilities at work, I naturally
gravitated to this kind of system. Even when it's a purely internal
protocol, I like being able to just telnet/netcat to the service and
operate everything manually. To date, I think I've implemented five or
six such protocols within the suite at work, with only a couple of
systems done differently (one of them uses a PHP client, for
hysterical raisins, so it's done over HTTP).

Plus, it's great to be able to break out the MUD client at work
without getting in trouble for playing games on company time :)

ChrisA

[1] http://www.thresholdrpg.com/ if you'd like to join me! You'll be
made very welcome!
-- 
http://mail.python.org/mailman/listinfo/python-list


Designing a Pythonic search DSL for SQL and NoSQL databases

2013-07-19 Thread Alec Taylor
Dear Python community,

I am analysing designing an abstraction layer over a select few NoSQL
and SQL databases.

Specifically:

- Redis, Neo4j, MongoDB, CouchDB
- PostgreSQL

Being inexperienced; it is hard to know a nice way of abstracting search.

For conciseness in my explanation, think of `Table` as being table,
object, entity or key; and `name` as being name or type.

Maybe `res = Table.name.search()`

Or on multiple `Table`:
`res = AbstractDB().AbstractSearch(
 )`

Then: `res.paginate(limit=25, offset=5)`

Or if you want all: `res.all()`

And additionally borrow/alias from a relevant subset of PEP249, e.g.:
`fetchone` and `fetchmany`

Will open-source this once it's of sufficient functionality.

What do you think?

Advice on better design; or just feedback on what I've mentioned?

Thanks,

Alec Taylor

PS: I am using Bottle. You'll note that some of the syntax I've
references is inspired from web2py's DAL and ODMG.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Designing a Pythonic search DSL for SQL and NoSQL databases

2013-07-19 Thread Roy Smith
In article ,
 Alec Taylor  wrote:

> Dear Python community,
> 
> I am analysing designing an abstraction layer over a select few NoSQL
> and SQL databases.
> 
> Specifically:
> 
> - Redis, Neo4j, MongoDB, CouchDB
> - PostgreSQL

This isn't really a Python question.

Before you even begin to think about "how to do this in Python", you 
need to think about "how to do this at all".  You've got a huge range of 
storage paradigms there.  Redis is basically a key-value store.  Mongo 
does documents.  Postgres does relations.  I'm not familiar with Neo and 
Couch, but I assume they also have their own interesting ways of storing 
things.

You need to figure out what it means to abstract search over such a 
diverse range of technologies.  I honestly don't think it's possible, 
but maybe you've got some good ideas.  In any case, you need to figure 
that part out before you even begin to think about how to implement it 
in any particular language.
-- 
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


Re: Messages to Python-List aren't posting

2013-07-19 Thread Skip Montanaro
> Date: Thu, 18 Jul 2013 16:30:51 -0400 - timestamp of your mail
> Thu, 18 Jul 2013 13:30:51 -0700 (PDT) - you posted it via HTTP
> Thu, 18 Jul 2013 22:31:39 +0200 (CEST) - it reached python.org
> Fri, 19 Jul 2013 09:56:14 +0200 (CEST) - it began delivery to my address
> Fri, 19 Jul 2013 00:56:15 -0700 (PDT) - it reached gmail and me.
>
> So the big delay is somewhere within python.org. Since this does NOT
> happen to everyone, I would be looking for something like:
> * Moderation requirements (does your message not comply with spec?)
> * Spam greylisting
> * Slow/glitchy DNS when attempting to verify your message
>
> Most likely I think is moderation, given the extreme length of time.
> Something would have to be pretty glitchy to lag your mail out for
> half a day in spam filtering. It's possible, I guess, though. I've no
> idea what anti-spam features the list is using.

Python.org runs Mailman 2.1.something.  In addition to all the various
front-end filters running in the Postfix SMTP daemon (which trap most
spam), SpamBayes is used as a last check to score messages intended
for delivery to most mailing lists hosted on mail.python.org. It
leaves two headers behind as proof of its existence.  Here are those
headers for Matthew's message that started this thread:

X-Spam-Status: OK 0.017
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06;
'problem?': 0.07; 'subject:posting': 0.09; 'python': 0.11;
'posted': 0.15; 'effect.': 0.16; 'missing?': 0.16; 'python-dev,':
0.16; 'server,': 0.19; 'all:': 0.24; "i've": 0.25; 'message-
id:@mail.gmail.com': 0.30; 'obscure': 0.31; 'lists': 0.32;
'trouble': 0.34; 'anybody': 0.35; 'but': 0.35;
'received:google.com': 0.35; 'there': 0.35; 'subject:List': 0.36;
'list.': 0.37; 'gmail': 0.38; 'to:addr:python-list': 0.38;
'issue': 0.38; 'moving': 0.39; 'to:addr:python.org': 0.39;
'mailing': 0.39; 'first': 0.61; 'hours': 0.66

so SpamBayes thought it looked fine.  Had it been marked as "UNSURE"
or "SPAM" in the status header, Mailman would have held it for
moderator attention.  It is possible it was held by Mailman for some
other reason.  Some obvious reasons: sender isn't subscribed, message
had too many recipients, python-list@python.org was BCC'd (implicit
destination). If you message was held by Mailman, moderator overload
is the most likely cause of the delay.  It's also possible Mailman got
overwhelmed, but I've seen no postmaster messages suggesting there
were any systemic problems.

BTW, although SpamBayes serves as a last resort for mail arriving via
SMTP, it is the only line of defense for mail gatewayed from Usenet.
I'm sure I can dredge up the code I wrote for that if anyone wants it
for another application.

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


Ouija board

2013-07-19 Thread MoneyMaker
ouija board
the world's most dangerous game?? Buy your game here. good selection and the 
best price
http://horrorhorrorhorror.webs.com/ouija-board
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-19 Thread Novocastrian_Nomad
On Friday, July 19, 2013 7:22:48 AM UTC-6, 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')


Try DATA = re.sub(r'[(,\\)]', '', '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 're.sub('', '♔', PTRNPRS, flags=re.I); DATA = 
re.sub('', '♕', DATA, flags=re.I); DATA = 
re.sub('', '♖', DATA, flags=re.I); DATA = 
re.sub('', '♗', DATA, flags=re.I); DATA = 
re.sub('', '♘', DATA, flags=re.I); DATA = 
re.sub('', '♙', DATA, flags=re.I); DATA = 
re.sub('', '♚', DATA, flags=re.I); DATA = 
re.sub('', '♛', DATA, flags=re.I); DATA = 
re.sub('', '♜', DATA, flags=re.I); DATA = 
re.sub('', '♝', DATA, flags=re.I); DATA = 
re.sub('', '♞', DATA, flags=re.I); PTRNPRS = 
re.sub('', '♟', 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: Messages to Python-List aren't posting

2013-07-19 Thread Matthew Lefavor
(Sorry to reply-all, but in this case I think the direct messages will get
to people on this thread 12 hours earlier than the others.)

Well, I have had this problem with both my work email (matthew dot lefavor
_at_ nasa dpt gov) and my Gmail account. Since this doesn't happen to all
users (nor all Gmail users, for that matter), the only thing that's
constant here is that it's my name (well, and my password, but one would
hope that passwords aren't relevant here). Is it possible that the name
"Matthew Lefavor" has been added to a greylist or something?

One relevant piece of information: I have subscribed and unsubscribed to
different combinations of these lists several times over the past year, and
particularly over the past few months (as I was trying to manage the flow
of emails to my filter-less work inbox.) Could that sort of behavior
associate my name with malicious intent?

Matthew Lefavor


On Fri, Jul 19, 2013 at 9:29 AM, Skip Montanaro  wrote:

> > Date: Thu, 18 Jul 2013 16:30:51 -0400 - timestamp of your mail
> > Thu, 18 Jul 2013 13:30:51 -0700 (PDT) - you posted it via HTTP
> > Thu, 18 Jul 2013 22:31:39 +0200 (CEST) - it reached python.org
> > Fri, 19 Jul 2013 09:56:14 +0200 (CEST) - it began delivery to my address
> > Fri, 19 Jul 2013 00:56:15 -0700 (PDT) - it reached gmail and me.
> >
> > So the big delay is somewhere within python.org. Since this does NOT
> > happen to everyone, I would be looking for something like:
> > * Moderation requirements (does your message not comply with spec?)
> > * Spam greylisting
> > * Slow/glitchy DNS when attempting to verify your message
> >
> > Most likely I think is moderation, given the extreme length of time.
> > Something would have to be pretty glitchy to lag your mail out for
> > half a day in spam filtering. It's possible, I guess, though. I've no
> > idea what anti-spam features the list is using.
>
> Python.org runs Mailman 2.1.something.  In addition to all the various
> front-end filters running in the Postfix SMTP daemon (which trap most
> spam), SpamBayes is used as a last check to score messages intended
> for delivery to most mailing lists hosted on mail.python.org. It
> leaves two headers behind as proof of its existence.  Here are those
> headers for Matthew's message that started this thread:
>
> X-Spam-Status: OK 0.017
> X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06;
> 'problem?': 0.07; 'subject:posting': 0.09; 'python': 0.11;
> 'posted': 0.15; 'effect.': 0.16; 'missing?': 0.16; 'python-dev,':
> 0.16; 'server,': 0.19; 'all:': 0.24; "i've": 0.25; 'message-
> id:@mail.gmail.com': 0.30; 'obscure': 0.31; 'lists': 0.32;
> 'trouble': 0.34; 'anybody': 0.35; 'but': 0.35;
> 'received:google.com': 0.35; 'there': 0.35; 'subject:List': 0.36;
> 'list.': 0.37; 'gmail': 0.38; 'to:addr:python-list': 0.38;
> 'issue': 0.38; 'moving': 0.39; 'to:addr:python.org': 0.39;
> 'mailing': 0.39; 'first': 0.61; 'hours': 0.66
>
> so SpamBayes thought it looked fine.  Had it been marked as "UNSURE"
> or "SPAM" in the status header, Mailman would have held it for
> moderator attention.  It is possible it was held by Mailman for some
> other reason.  Some obvious reasons: sender isn't subscribed, message
> had too many recipients, python-list@python.org was BCC'd (implicit
> destination). If you message was held by Mailman, moderator overload
> is the most likely cause of the delay.  It's also possible Mailman got
> overwhelmed, but I've seen no postmaster messages suggesting there
> were any systemic problems.
>
> BTW, although SpamBayes serves as a last resort for mail arriving via
> SMTP, it is the only line of defense for mail gatewayed from Usenet.
> I'm sure I can dredge up the code I wrote for that if anyone wants it
> for another application.
>
> Skip
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-19 Thread John Gordon
In  Devyn Collier Johnson 
 writes:

> 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')

If your actual use-case is this simple, you might want to use one of the
built-in string functions such as strip() or translate().

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Share Code Tips

2013-07-19 Thread Joel Goldstick
On Fri, Jul 19, 2013 at 9:51 AM, Devyn Collier Johnson <
devyncjohn...@gmail.com> wrote:

> 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 ' re.sub('', '♔', PTRNPRS, flags=re.I); DATA =
> re.sub('', '♕', DATA, flags=re.I); DATA =
> re.sub(''**, '♖', DATA, flags=re.I); DATA =
> re.sub(''**, '♗', DATA, flags=re.I); DATA =
> re.sub(''**, '♘', DATA, flags=re.I); DATA =
> re.sub('', '♙', DATA, flags=re.I); DATA =
> re.sub('', '♚', DATA, flags=re.I); DATA =
> re.sub('', '♛', DATA, flags=re.I); DATA =
> re.sub(''**, '♜', DATA, flags=re.I); DATA =
> re.sub(''**, '♝', DATA, flags=re.I); DATA =
> re.sub(''**, '♞', DATA, flags=re.I); PTRNPRS =
> re.sub('', '♟', 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
>

I'm guessing you may be posting with html.  So all your code runs together.

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


Re: Messages to Python-List aren't posting

2013-07-19 Thread Chris Angelico
On Sat, Jul 20, 2013 at 12:57 AM, Skip Montanaro  wrote:
>> One relevant piece of information: I have subscribed and unsubscribed to
>> different combinations of these lists several times over the past year, and
>> particularly over the past few months (as I was trying to manage the flow of
>> emails to my filter-less work inbox.) Could that sort of behavior associate
>> my name with malicious intent?
>
> I wouldn't think so.  More likely, you might have made a mistake in
> your configuration parameters.  You might want to double-check your
> python-l...@.python.org subscription information in Mailman to make
> sure you haven't inadvertently done something.  If the problem
> persists, send a note to postmas...@python.org describing the problem,
> and include a message (with all its headers intact) that demonstrates
> the problem, as Chris did with the timestamps.

I agree with Skip. It's most likely to be a misconfiguration
somewhere. The postmaster will either know immediately what's wrong,
or be easily able to find out.

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


Re: Messages to Python-List aren't posting

2013-07-19 Thread Skip Montanaro
> Is it possible that the name "Matthew
> Lefavor" has been added to a greylist or something?

That's not how greylisting works.  Greylisting is a scheme used to
eliminate spam.  The server knows what email addresses it's received
mail from in the last little while (say, the last month).  When it
gets a message purporting to be from someone not in its little
database (say, u...@somewhere.com) it responds with a "try later"
message.  Legitimate mail will be delayed for a few minutes.  The
sending SMTP server will try again, and the message will be accepted
by the receiving server. That server will also record
u...@somewhere.com as a "known" address.  The theory behind
greylisting is that a spambot either won't come back and retry sending
(it's going millions of messages to flood the net with, and can't be
bothered to retry mail) or will be found and shut off by ISPs before
the delay period expires.

> One relevant piece of information: I have subscribed and unsubscribed to
> different combinations of these lists several times over the past year, and
> particularly over the past few months (as I was trying to manage the flow of
> emails to my filter-less work inbox.) Could that sort of behavior associate
> my name with malicious intent?

I wouldn't think so.  More likely, you might have made a mistake in
your configuration parameters.  You might want to double-check your
python-l...@.python.org subscription information in Mailman to make
sure you haven't inadvertently done something.  If the problem
persists, send a note to postmas...@python.org describing the problem,
and include a message (with all its headers intact) that demonstrates
the problem, as Chris did with the timestamps.

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


Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
On Fri, 19 Jul 2013 10:21:10 -0400, Joel Goldstick wrote:

>  class="gmail_quote">
[snip 70-odd lines of HTML...]

> I'm guessing you may be posting with html.  So all your code runs
> together.
> --  dir="ltr"> Joel Goldstickhttp://joelgoldstick.com
>  


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



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


Re: Designing a Pythonic search DSL for SQL and NoSQL databases

2013-07-19 Thread Alec Taylor
Hmm, looking at the capabilities of Redis; you're likely right.

Would welcome discussion on the implementability and usefulness of a
central search abstraction to the other stores mentioned.

One thing could be that using the paradigm the database was made for
is better than any advantages abstracting their differences creates.

On Fri, Jul 19, 2013 at 10:49 PM, Roy Smith  wrote:
> In article ,
>  Alec Taylor  wrote:
>
>> Dear Python community,
>>
>> I am analysing designing an abstraction layer over a select few NoSQL
>> and SQL databases.
>>
>> Specifically:
>>
>> - Redis, Neo4j, MongoDB, CouchDB
>> - PostgreSQL
>
> This isn't really a Python question.
>
> Before you even begin to think about "how to do this in Python", you
> need to think about "how to do this at all".  You've got a huge range of
> storage paradigms there.  Redis is basically a key-value store.  Mongo
> does documents.  Postgres does relations.  I'm not familiar with Neo and
> Couch, but I assume they also have their own interesting ways of storing
> things.
>
> You need to figure out what it means to abstract search over such a
> diverse range of technologies.  I honestly don't think it's possible,
> but maybe you've got some good ideas.  In any case, you need to figure
> that part out before you even begin to think about how to implement it
> in any particular language.
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-19 Thread Steven D'Aprano
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.




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


Re: Messages to Python-List aren't posting

2013-07-19 Thread Steven D'Aprano
On Fri, 19 Jul 2013 09:57:47 -0500, Skip Montanaro wrote:

>> Is it possible that the name "Matthew Lefavor" has been added to a
>> greylist or something?
> 
> That's not how greylisting works.  Greylisting is a scheme used to
> eliminate spam.  The server knows what email addresses it's received
> mail from in the last little while (say, the last month).  When it gets
> a message purporting to be from someone not in its little database (say,
> u...@somewhere.com) it responds with a "try later" message.  Legitimate
> mail will be delayed for a few minutes.  The sending SMTP server will
> try again, and the message will be accepted by the receiving server.
> That server will also record u...@somewhere.com as a "known" address. 
> The theory behind greylisting is that a spambot either won't come back
> and retry sending (it's going millions of messages to flood the net
> with, and can't be bothered to retry mail) or will be found and shut off
> by ISPs before the delay period expires.


Greylisting is great, but there are a couple of quirks, as the company I 
work for discovered the hard way. Some ISPs don't follow the rules. I'm 
not talking about dinky little ISPs run by some guy in a basement, I'm 
talking some of the biggest ISPs in Australia like Optus or Bigpond. They 
either completely ignore the "try later" message, and report it as a hard 
failure, or they wait a full day before trying again instead of a few 
minutes. Or, if they do try again, they try again from a different mail 
server, so the greylisting software sees a different sender/server 
combination, and greylists that as well.

Admittedly, this was a few years back that we ran into this problem, and 
since then we've just routinely whitelisted email from Optus and Bigpond, 
curse their black souls for making spam prevention just that little bit 
harder. So I suppose it's possible that they've stopped being bad actors 
and started following the standards correctly.

No really, stop laughing, it is technically possible.



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


Re: Messages to Python-List aren't posting

2013-07-19 Thread Matthew Lefavor
Well, it seems like the last message I posted did post in time. I'll keep
tabs on the issue and email the postmaster if it persists.

Matthew Lefavor


On Fri, Jul 19, 2013 at 11:00 AM, Chris Angelico  wrote:

> On Sat, Jul 20, 2013 at 12:57 AM, Skip Montanaro  wrote:
> >> One relevant piece of information: I have subscribed and unsubscribed to
> >> different combinations of these lists several times over the past year,
> and
> >> particularly over the past few months (as I was trying to manage the
> flow of
> >> emails to my filter-less work inbox.) Could that sort of behavior
> associate
> >> my name with malicious intent?
> >
> > I wouldn't think so.  More likely, you might have made a mistake in
> > your configuration parameters.  You might want to double-check your
> > python-l...@.python.org subscription information in Mailman to make
> > sure you haven't inadvertently done something.  If the problem
> > persists, send a note to postmas...@python.org describing the problem,
> > and include a message (with all its headers intact) that demonstrates
> > the problem, as Chris did with the timestamps.
>
> I agree with Skip. It's most likely to be a misconfiguration
> somewhere. The postmaster will either know immediately what's wrong,
> or be easily able to find out.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Messages to Python-List aren't posting

2013-07-19 Thread Chris Angelico
On Sat, Jul 20, 2013 at 2:31 AM, Steven D'Aprano
 wrote:
> Admittedly, this was a few years back that we ran into this problem, and
> since then we've just routinely whitelisted email from Optus and Bigpond,
> curse their black souls for making spam prevention just that little bit
> harder. So I suppose it's possible that they've stopped being bad actors
> and started following the standards correctly.
>
> No really, stop laughing, it is technically possible.

Once you've worked in networking long enough, you cease to be
surprised when things go right. Anything is possible... even
standards-compliant behaviour.

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


Re: Find and Replace Simplification

2013-07-19 Thread Serhiy Storchaka

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.



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


Re: Find and Replace Simplification

2013-07-19 Thread 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. :-)

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


Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-19 Thread wxjmfauth
Le mercredi 10 juillet 2013 11:00:23 UTC+2, Steven D'Aprano a écrit :
> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
> 
> 
> 
> > A moderator who calls himself “animuson” on Stack Overflow doesn’t want
> 
> > to face the truth. He has deleted all my postings regarding Python
> 
> > regular expression matching being extremely slow compared to Perl.
> 
> 
> 
> That's by design. We don't want to make the same mistake as Perl, where 
> 
> every problem is solved by a regular expression:
> 
> 
> 
> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
> 
> 
> 
> so we deliberately make regexes as slow as possible so that programmers 
> 
> will look for a better way to solve their problem. If you check the 
> 
> source code for the re engine, you'll find that for certain regexes, it 
> 
> busy-waits for anything up to 30 seconds at a time, deliberately wasting 
> 
> cycles.
> 
> 
> 
> The same with Unicode. We hate French people, you see, and so in an 
> 
> effort to drive everyone back to ASCII-only text, Python 3.3 introduces 
> 
> some memory optimizations that ensures that Unicode strings work 
> 
> correctly and are up to four times smaller than they used to be. You 
> 
> should get together with jmfauth, who has discovered our dastardly plot 
> 
> and keeps posting benchmarks showing how on carefully contrived micro-
> 
> benchmarks using a beta version of Python 3.3, non-ASCII string 
> 
> operations can be marginally slower than in 3.2.
> 
> 
> 
> 
> 
> > Additionally my account has been suspended for 7 days. Such a dickwad.
> 
> 
> 
> I cannot imagine why he would have done that.
> 
> 
> 
> 
> 
> -- 
> 
> Steven

This Flexible String Representation is a dream case study.
Attempting to optimize a subset of character is a non sense.

If you are a non-ascii user, such a mechanism is irrelevant,
because per definition you do not need it. Not only it useless,
it is penalizing, just by the fact of its existence. [*]

Conversely (or identically), if you are an ascii user, same situation,
it is irrelevant, useless and penalizing.

Practically, and today, all coding schemes we have
(including the endorsed Unicode utf transformers) work
with a unique set of of encoded code points. If you
wish to take the problem from the other side, it is
because one can only work properly with a unique set
of code points that so many coding schemes exist!

Question: does this FSR use internally three coding
schemes because it splits Unicode in three groups or
does it split Unicode in three subsets to have the joyce
to use three coding schemes?

About "micro benchmarks". What to say, they appear
practivally every time you use non ascii.

And do not forget memory. The €uro just become expensive.

>>> sys.getsizeof('$')
26
>>> sys.getsizeof('€')
40

I do not know. When an €uro char need 14 bytes more that
a dollar, I belong to those who thing there is a problem
somewhere.

This FSR is a royal gift for those who wish to teach Unicode
and the coding of characters.

jmf

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


Topic Modeling LDA Gensim

2013-07-19 Thread subhabangalore
Dear Group,

I am trying to use Gensim for Topic Modeling with LDA.

I have trained LDA but now I want to test it with new documents.


Should I use 

doc_lda = lda[doc_bow]

or is it something else?

If any one of the esteemed members of the group can kindly suggest?

Thanking in Advance,
Regards,
Subhabrata
-- 
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:




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


I'm guessing you may be posting with html.  So all your code runs
together.
--  Joel Goldstickhttp://joelgoldstick.com
 


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: Stack Overflow moderator “animuson”

2013-07-19 Thread Chris Angelico
On Sat, Jul 20, 2013 at 4:54 AM,   wrote:
> And do not forget memory. The €uro just become expensive.
>
 sys.getsizeof('
> )
> 26
 sys.getsizeof('€')
> 40
>
> I do not know. When an €uro char need 14 bytes more that
> a dollar, I belong to those who thing there is a problem
> somewhere.

Oh, I totally agree. But it's not just the Euro symbol that's
expensive. Look how much I have to pay for a couple of square
brackets!

>>> sys.getsizeof((1))
14
>>> sys.getsizeof([1])
40

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


Re: Stack Overflow moderator “animuson”

2013-07-19 Thread Dave Angel

On 07/19/2013 06:35 PM, Chris Angelico wrote:

On Sat, Jul 20, 2013 at 4:54 AM,   wrote:

And do not forget memory. The €uro just become expensive.


sys.getsizeof('

)
26

sys.getsizeof('€')

40

I do not know. When an €uro char need 14 bytes more that
a dollar, I belong to those who thing there is a problem
somewhere.


Oh, I totally agree. But it's not just the Euro symbol that's
expensive. Look how much I have to pay for a couple of square
brackets!


sys.getsizeof((1))

14

sys.getsizeof([1])

40



And look how much a comma costs us (on 64bit 3.3):

>>> sys.getsizeof((1))
28
>>> sys.getsizeof((1,))
64
>>> sys.getsizeof([1])
80

;-)


--
DaveA

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


Re: Share Code Tips

2013-07-19 Thread Dave Angel

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


On 07/19/2013 01:59 PM, Steven D'Aprano 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.



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.
"""

--
DaveA

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


Re: Share Code Tips

2013-07-19 Thread Chris Angelico
On Sat, Jul 20, 2013 at 8:10 AM, Devyn Collier Johnson
 wrote:
>
> On 07/19/2013 12:19 PM, Steven D'Aprano wrote:
>>
>> On Fri, 19 Jul 2013 10:21:10 -0400, Joel Goldstick wrote:
>>
>>> >> class="gmail_quote">
>>
>> [snip 70-odd lines of HTML...]
>>
>>> I'm guessing you may be posting with html.  So all your code runs
>>> together.
>>> -- >> dir="ltr"> Joel Goldstickhttp://joelgoldstick.com
>>>  
>>
>>
>> My irony meter didn't merely explode, it actually vaporized.
>>
>>
>>
> What is the issue with my email? Should I resend it?

Either your lines are insanely long (and got wrapped by the mailer),
or your multi-line functions lost their internal line breaks. Joel
suggested that you may have been posting HTML mail (you're not),
implying that it's worse than plain text mail (it is), and himself
posted in HTML (that's irony).

ChrisA
(This is a parenthesis.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread Chris Angelico
On Sat, Jul 20, 2013 at 8:08 AM, 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.

Case insensitivity is a *hard* problem. Don't fool yourself that you
can do it with a simple line of code and have it 'just work'. All
you'll have is something that works "most of the time", and then
breaks on certain input. As Steven said, using casefold() rather than
lower() will help, but that's still not perfect. The simplest and
safest way to solve Unicode capitalization issues is to declare that
your protocol is case sensitive. I have a brother who couldn't
understand why Unix file systems have to be case sensitive (why would
anyone ever want to have "readme" and "README" in the same directory,
after all?), until I explained how majorly hard it is with i18n, and
how it suddenly becomes extremely unsafe for your *file system* to get
this wrong.

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


Re: Find and Replace Simplification

2013-07-19 Thread Dave Angel

On 07/19/2013 05:44 PM, Devyn Collier Johnson wrote:


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?



Read what you're quoting from.  The translate() method does just that. 
And maketrans() is the way to build a translate table.


On an Intel processor, the xlat instruction does a translate for one 
character, and adding a REP in front of it does it for an entire buffer. 
 No idea if Python takes advantage of that, however.





--
DaveA

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


Python testing tools

2013-07-19 Thread cutems93
I am currently doing some research on testing software for Python. I found that 
there are many different types of testing tools. These are what I've found.

1.Unit test 
2.Mock test
3.Fuzz test
4.Web test
5.Acceptance/business logic test
6.GUI test
7.Source code checking
8.Code coverage
9.Continuous integration
10.Automatic test runners
11.Test fixtures

I know web and GUI testing tools are for specific uses. For instance, if you 
are not working with GUI or web pages, you don't need those testing tools. 
Other than these two, do you use all of the other nine testing tools? I think 
many of you are using unit testing tools, such as unittest and doctest, and 
source code checking tools, like pylint or pychecker. Do you guys use 
#2,3,5,8,9,10 and 11 often?

Thanks!

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


how: embed + extend to control my running app?

2013-07-19 Thread David M. Cotter
i'd like my app to be "available" to python while it's running.

for example, say my app is "FooBar.app".

when my FooBar.app is running, now there is a python interface available to 
python, and the user can write python scripts to make use of it.

with their scripts, they can control my running application

when FooBar.app is NOT running, perhaps making use of any of the python 
functions of "FooBar.app" would either return an error, or possibly launch 
"FooBar.app"?  or do nothing since it's not running?

can boost::python help with this?

i've never worked with extending or embedding python, so any help would be 
super great
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-19 Thread Kevin Walzer

On 7/10/13 3:55 AM, Mats Peterson wrote:

A moderator who calls himself “animuson� on Stack Overflow doesn’t
want to face the truth. He has deleted all my postings regarding Python
regular expression matching being extremely slow compared to Perl.
Additionally my account has been suspended for 7 days. Such a dickwad.

Mats



And we should care because...?

--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
-- 
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:


 


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


Re: Share Code Tips

2013-07-19 Thread Chris Angelico
On Sat, Jul 20, 2013 at 11:04 AM, Devyn Collier Johnson
 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:
>>
>>
>>  
>>>
>>>
>>> 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how: embed + extend to control my running app?

2013-07-19 Thread Chris Angelico
On Sat, Jul 20, 2013 at 9:52 AM, David M. Cotter  wrote:
> i'd like my app to be "available" to python while it's running.
>
> for example, say my app is "FooBar.app".
>
> when my FooBar.app is running, now there is a python interface available to 
> python, and the user can write python scripts to make use of it.
>
> with their scripts, they can control my running application
>
> when FooBar.app is NOT running, perhaps making use of any of the python 
> functions of "FooBar.app" would either return an error, or possibly launch 
> "FooBar.app"?  or do nothing since it's not running?

Interfacing C and Python like you suggest can't be done with
embedding, because that requires that your app be already running, and
probably not by having your code run as a pure module. In fact, I
would actually suggest that you devise a separate protocol between
your app and the Python script, and run them as separate processes.
That way, they run independently, and you may (platform-specific code
required here though) be able to invoke your app; most importantly,
you'll be able to cleanly handle multiple Python scripts trying to
control you simultaneously.

What platforms are you aiming at? If it's just for Unix-like ones, the
easiest way is probably to create a Unix domain socket, which the
Python program can write to and/or read from. With a protocol based
around simple operations like that, your Python module need not even
involve C code - it simply opens a socket file and uses standard I/O
methods on it. Alternatively, you may want to consider a TCP socket,
which would let you split the client and server across a network, or
possibly direct shared memory access.

The world's your oyster. What kind of sauce would you like it with?

ChrisA
-- 
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 Dave Angel

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




 



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.


--
DaveA

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


Re: Understanding other people's code

2013-07-19 Thread David Hutto
I forgot to mention idle.   It can step through another's code and show
you a step-by-step insructional, of what the code does.



On Tue, Jul 16, 2013 at 8:05 PM, David Hutto  wrote:

> Any program, to me, is just like speaking english. The class, or function
> name might not fully mesh with what your cognitive structure assumes it to
> be.read through the imports first, and see the classes and functions come
> alive with experience comes intuition of what it does, and the instances
> that can be utilized with it. The term RTFM, and google always comes to
> mind as well.
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
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.



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


Re: Share Code Tips

2013-07-19 Thread David Hutto
Just use an explanatory user tip that states it should be case sensitive,
just like with most sites, or apps.


On Fri, Jul 19, 2013 at 9:13 PM, Chris Angelico  wrote:

> On Sat, Jul 20, 2013 at 11:04 AM, Devyn Collier Johnson
>  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:
> >>
> >>
> >>  
> >>>
> >>>
> >>> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread David Hutto
Just use an explanatory user tip that states it should be case sensitive,
just like with most sites, or apps.


On Fri, Jul 19, 2013 at 10:21 AM, Joel Goldstick
wrote:

>
>
>
> On Fri, Jul 19, 2013 at 9:51 AM, Devyn Collier Johnson <
> devyncjohn...@gmail.com> wrote:
>
>> 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 '> re.sub('', '♔', PTRNPRS, flags=re.I); DATA =
>> re.sub('', '♕', DATA, flags=re.I); DATA =
>> re.sub(''**, '♖', DATA, flags=re.I); DATA =
>> re.sub(''**, '♗', DATA, flags=re.I); DATA =
>> re.sub(''**, '♘', DATA, flags=re.I); DATA =
>> re.sub('', '♙', DATA, flags=re.I); DATA =
>> re.sub('', '♚', DATA, flags=re.I); DATA =
>> re.sub('', '♛', DATA, flags=re.I); DATA =
>> re.sub(''**, '♜', DATA, flags=re.I); DATA =
>> re.sub(''**, '♝', DATA, flags=re.I); DATA =
>> re.sub(''**, '♞', DATA, flags=re.I); PTRNPRS =
>> re.sub('', '♟', 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
>>
>
> I'm guessing you may be posting with html.  So all your code runs together.
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread David Hutto
And also don't forget special char, or that it can bbe var char, or char in
the DB lookup in boolean with the username.


On Fri, Jul 19, 2013 at 11:43 PM, David Hutto wrote:

> Just use an explanatory user tip that states it should be case sensitive,
> just like with most sites, or apps.
>
>
> On Fri, Jul 19, 2013 at 10:21 AM, Joel Goldstick  > wrote:
>
>>
>>
>>
>> On Fri, Jul 19, 2013 at 9:51 AM, Devyn Collier Johnson <
>> devyncjohn...@gmail.com> wrote:
>>
>>> 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 '>> re.sub('', '♔', PTRNPRS, flags=re.I); DATA =
>>> re.sub('', '♕', DATA, flags=re.I); DATA =
>>> re.sub(''**, '♖', DATA, flags=re.I); DATA =
>>> re.sub(''**, '♗', DATA, flags=re.I); DATA =
>>> re.sub(''**, '♘', DATA, flags=re.I); DATA =
>>> re.sub('', '♙', DATA, flags=re.I); DATA =
>>> re.sub('', '♚', DATA, flags=re.I); DATA =
>>> re.sub('', '♛', DATA, flags=re.I); DATA =
>>> re.sub(''**, '♜', DATA, flags=re.I); DATA =
>>> re.sub(''**, '♝', DATA, flags=re.I); DATA =
>>> re.sub(''**, '♞', DATA, flags=re.I); PTRNPRS =
>>> re.sub('', '♟', 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
>>>
>>
>> I'm guessing you may be posting with html.  So all your code runs
>> together.
>>
>> --
>> Joel Goldstick
>> http://joelgoldstick.com
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
>
> --
> Best Regards,
> David Hutto
> *CEO:* *http://www.hitwebdevelopment.com*
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
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.



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


Re: Share Code Tips

2013-07-19 Thread David Hutto
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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-19 Thread Stefan Behnel
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


Re: Share Code Tips

2013-07-19 Thread David Hutto
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 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*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread David Hutto
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 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 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*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code Tips

2013-07-19 Thread David Hutto
32 if you count black, and white.


On Sat, Jul 20, 2013 at 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 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 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*
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-19 Thread David Hutto
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  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*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-19 Thread David Hutto
This is using 3.2, which shouldn't be far off, the latest I could get on
ubuntu.

david@david:~$ python3.2
Python 3.2.3 (default, Apr 10 2013, 05:29:11)
[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)


On Sat, Jul 20, 2013 at 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 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*
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-19 Thread David Hutto
Just get a good dictionary, and distutils I believe, someone a little bit
more experienced in these should be along soon, or use the manual, and docs.



On Sat, Jul 20, 2013 at 12:52 AM, David Hutto wrote:

> This is using 3.2, which shouldn't be far off, the latest I could get on
> ubuntu.
>
> david@david:~$ python3.2
> Python 3.2.3 (default, Apr 10 2013, 05:29:11)
> [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)
>
>
> On Sat, Jul 20, 2013 at 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 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*
>>
>
>
>
> --
> Best Regards,
> David Hutto
> *CEO:* *http://www.hitwebdevelopment.com*
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-- 
http://mail.python.org/mailman/listinfo/python-list