Re: Regular expressions

2015-11-03 Thread Christian Gollwitzer

Am 04.11.15 um 04:48 schrieb Steven D'Aprano:

On Wednesday 04 November 2015 11:33, ru...@yahoo.com wrote:


Not quite.  Core language concepts like ifs, loops, functions,
variables, slicing, etc are the socket wrenches of the programmer's
toolbox.  Regexs are like an electric impact socket wrench.  You can do
the same work without it, but in many cases it's slower. But you have to
learn the other hand tools first in order to really use the electric
driver properly (understanding torques, direction of threads, etc), lest
you wonder why you're breaking off so many bolts with the torque of the
impact drive.


I consider regexs more fundemental


I'm sure that there are people who consider the International Space Station
more fundamental than the lever, the wedge and the hammer, but they would be
wrong too.

Given primitives for branching, loops and variables, you can build support
for regexes. Given regexes, how would you build support for variables?

Of course, you could easily prove me wrong.


You *know* that they are not equivalent, I assume? regexes are 
equivalent to finite state machines, which are less powerful than Turing 
machines, and even less powerful than stack machines. You can't even 
construct a regexp which validates, if parentheses are balanced.


What rurpy meant, was that regexes can surface to a computer user 
earlier than variables and branches; a user who does not go into the 
depth to actually program the machine, might still encounter them in a 
text editor or database engine. Even some web forms allow some limited 
form, like e.g. the DVD rental here or Google.


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


Re: Python PNG Viewer(Browser Based)

2015-11-03 Thread Ben Finney
Arshpreet Singh  writes:

> On Tuesday, 3 November 2015 21:32:03 UTC+5:30, Chris Warrick  wrote:
> > Your problem is lack of basic understanding of the Internet. 
>
> Yes That's true at some level.

More specifically, your problem is not “how do I do this with Python?”
but rather “what is a web page?”.

So, the research you need to do is not Python-specific, instead you need
to learn about the structure of web pages and web applications.

> My present working system shows me list of all files (PNGs, JPGs, txt,
> SVGs) in browser, when I click on file it opens it and show contents
> of it.

You are directing your web browser to visit a folder on your local file
system. It is obliging you by presenting a directory of local files.

Instead, you need to learn how to author web pages.

There are countless resources for learning about generating a web page
from scratch. You could learn a lot from the Wikibooks project
https://en.wikibooks.org/wiki/Authoring_Webpages>.

You'll also need to appreciate that developing web pages is a *very*
extensive topic. You might need nothing more than to create simple
static pages; you don't need Python at all for that. You might need a
powerful Web programming framework, Python has excellent support for
that https://wiki.python.org/moin/WebFrameworks>.

Without you learning the very basics of web sites, though, you won't get
much use from Python-specific knowledge about web frameworks.

Good hunting!

-- 
 \  “Ridicule is the only weapon which can be used against |
  `\   unintelligible propositions.” —Thomas Jefferson, 1816-07-30 |
_o__)  |
Ben Finney

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


Re: Python PNG Viewer(Browser Based)

2015-11-03 Thread Arshpreet Singh
On Tuesday, 3 November 2015 21:32:03 UTC+5:30, Chris Warrick  wrote:
> On 3 November 2015 at 12:54, Arshpreet Singh  wrote:
> > Hello Everyone,
> >
> > I am looking for Browser-based PNG file viewer written in
> > Python.(Flask framework preferably)
> >
> > Following project(Flask-Based) provides many things(File manager as
> > well as file viewer)  but it does not support PNG files.
> >
> > https://github.com/vmi356/filemanager
> >
> > Any idea if I have to write my own browser based PNG viewer from
> > scratch(Using PIL or other required library)
> >
> > On the other side if I have to write only Desktop-based only two lines
> > are enough to do many things:
> >
> > Like,
> >
> > from PIL import Image
> > f = Image.open("file.png").show()
> >
> >
> > But I am not getting right sense that how to make possible using 
> > Python+Flask.
> >
> > Hope I am able to tell my problem?
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> Your problem is lack of basic understanding of the Internet. 

Yes That's true at some level.

>Because
> EVERY graphical web browser supports PNG files NATIVELY. With a single
>  tag.

That is easily understandable. 
 
> Just figure out where to add the PNG handler code and read any random
> "how to add images to a webpage" tutorial.
> You might need a new template and some code that is aware of the file
> being an image. But absolutely no PNG viewer is necessary.

My present working system shows me list of all files (PNGs, JPGs, txt, SVGs) in 
browser, when I click on file it opens it and show contents of it. but PNG and 
JPGs are not working. Surely handling one PNG file is easy but no idea how to 
solve multiple file situation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expressions

2015-11-03 Thread Nobody
On Wed, 04 Nov 2015 14:23:04 +1100, Steven D'Aprano wrote:

>> Its very name indicates that its default mode most certainly is regular
>> expressions.
> 
> I don't even know what grep stands for.

>From the ed command "g /re/p" (where "re" is a placeholder for an
arbitrary regular expression). Tests all lines ("g" for global) against
the specified regexp and prints ("p") any which match.

> But I think what Michael may mean is that if you "grep foo", no regex
> magic takes place since "foo" contains no metacharacters.

At least the GNU version will treat the input as a regexp regardless of
whether it contains only literal characters. I.e. "grep foo" and
"grep [f][o][o]" will both construct the same state machine then process
the input with it.

You need to actually use -F to change the matching algorithm.

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


Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
On Wednesday 04 November 2015 11:33, ru...@yahoo.com wrote:

>> Not quite.  Core language concepts like ifs, loops, functions,
>> variables, slicing, etc are the socket wrenches of the programmer's
>> toolbox.  Regexs are like an electric impact socket wrench.  You can do
>> the same work without it, but in many cases it's slower. But you have to
>> learn the other hand tools first in order to really use the electric
>> driver properly (understanding torques, direction of threads, etc), lest
>> you wonder why you're breaking off so many bolts with the torque of the
>> impact drive.
> 
> I consider regexs more fundemental

I'm sure that there are people who consider the International Space Station 
more fundamental than the lever, the wedge and the hammer, but they would be 
wrong too.

Given primitives for branching, loops and variables, you can build support 
for regexes. Given regexes, how would you build support for variables?

Of course, you could easily prove me wrong. All you would need to do to 
demonstrate that regexes are more fundamental than branching, loops and 
variables would be to demonstrate that the primitive operations available in 
commonly used CPUs are regular expressions, and that (for example) C's for 
loop and if...else are implemented in machine code as regular expressions, 
rather than the other way around.



-- 
Steve

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


Re: Regular expressions

2015-11-03 Thread Michael Torrie
On 11/03/2015 08:23 PM, Steven D'Aprano wrote:
>>> Grep can use regular expressions (and I do so with it regularly), but
>>> it's default mode is certainly not regular expressions ...
>>
>> Its very name indicates that its default mode most certainly is regular
>> expressions.
> 
> I don't even know what grep stands for. 
> 
> But I think what Michael may mean is that if you "grep foo", no regex magic 
> takes place since "foo" contains no metacharacters.

More likely I just don't know what I'm talking about.  I must have been
thinking about something else (shell globbing perhaps).

Certainly most of the times I've seen grep used, it's to look for a word
with no special metacharacters, as you say. Still a valid RE of course.
 But I have learned to night I don't need to resort to grep -e to use
regular expressions.  At least with GNU grep, that's the default.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
On Wednesday 04 November 2015 03:56, Tim Chase wrote:

> Or even more valuable to me:
> 
>   with open(..., newline="strip") as f:
> assert all(not line.endswith(("\n", "\r")) for line in f)

# Works only on Windows text files.
def chomp(lines):
for line in lines:
yield line.rstrip('\r\n')


Better would be this:

def chomp(lines):
for line in lines:
yield line.rstrip()  # remove all trailing whitespace


with open(...) as f:
for line in chomp(f): ...


-- 
Steve

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


Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
On Wednesday 04 November 2015 03:20, Chris Angelico wrote:

> On Wed, Nov 4, 2015 at 3:10 AM, Seymore4Head
>  wrote:
>> Yes I knew that -1 represents the end character.  It is not a question
>> of trying to accomplish anything.  I was just practicing with regex
>> and wasn't sure how to express a * since it was one of the
>> instructions.
> 
> In that case, it's nothing to do with ending a string. 

Seymore never said anything about ending a string.


> What you really
> want to know is: How do you match a '*' using a regular expression?

He may want to know that too, but that's not what he asked for. He asked how 
to match an asterisk at the end of the line.


> Which is what MRAB answered, courtesy of a working crystal ball: You
> use '\*'. Everything about the end of the string is irrelevant.

Not at all -- matching "\*" will find lines *beginning* with an asterisk if 
you use re.match, and lines containing an asterisk *anywhere* in the line if 
you use re.search.

I say "line" because the most common use for re.match and re.search is to 
match against a single line of text, but of course regexes can operate on 
multiline blocks of text, with or without multiline mode turned on.

And calling it "a working crystal ball" is somewhat of an exaggeration. The 
plain English meaning of Seymore's plain English question is easily 
understood: he wants to know how to match an asterisk at the end of the 
line, just like he said :-P


> (So,
> too, are all the comments about using [-1] or string methods. But we
> weren't to know that.)

If MRAB could understand what he wanted, I'm sure most others could have 
too.



-- 
Steve

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


Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
On Wednesday 04 November 2015 13:55, Dan Sommers wrote:

> On Tue, 03 Nov 2015 19:04:23 -0700, Michael Torrie wrote:
> 
>> On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote:
>>> I consider regexs more fundemental.  One need not even be a programmer
>>> to use them: consider grep, sed, a zillion editors, database query
>>> languages, etc.
>> 
>> Grep can use regular expressions (and I do so with it regularly), but
>> it's default mode is certainly not regular expressions ...
> 
> Its very name indicates that its default mode most certainly is regular
> expressions.

I don't even know what grep stands for. 

But I think what Michael may mean is that if you "grep foo", no regex magic 
takes place since "foo" contains no metacharacters.




-- 
Steven

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


Re: Regular expressions

2015-11-03 Thread Chris Angelico
On Wed, Nov 4, 2015 at 2:12 PM, Tim Chase  wrote:
> It's not as helpful as one might hope because you're stuck using a
> fixed regexp rather than an arbitrary regexp, but if you have a
> particular regexp you search for frequently, you can index it.
> Otherwise, you'd be doing full table-scans (or at least a full scan
> of whatever subset the active non-regexp'ed index yields) which can
> be pretty killer on performance.

If the regex anchors the start of the string, you can generally use an
index to save at least some effort. Otherwise, you're relying on some
kind of alternate indexing style, such as:

http://www.postgresql.org/docs/current/static/pgtrgm.html

which specifically mentions regex searches as being indexable.

Some more info, including 'explain' results:

http://www.depesz.com/2013/04/10/waiting-for-9-3-support-indexing-of-regular-expression-searches-in-contribpg_trgm/

But this kind of thing isn't widely supported across databases.

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


Re: Unbuffered stderr in Python 3

2015-11-03 Thread Steven D'Aprano
On Wednesday 04 November 2015 09:25, Terry Reedy wrote:

> On 11/3/2015 10:42 AM, Chris Angelico wrote:
>> On Wed, Nov 4, 2015 at 2:00 AM, Random832  wrote:
>>> Nobody  writes:
>>>
 It's probably related to the fact that std{in,out,err} are Unicode
 streams.
>>>
>>> There's no fundamental reason a Unicode stream should have to be line
>>> buffered. If it's "related", it's only in that an oversight was made in
>>> the course of making that change.
> 
> The current behavior is not an 'oversight'.  I was considered, decided,
> and revisited in https://bugs.python.org/issue13601.  Guido:
> "Line-buffering should be good enough since in practice errors messages
> are always terminated by a newline."  If not, print(part_line,
> file=sys.stderr, flush=True) works for the unusual case.

This is one of the offending line from our code base:

print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr)

So that ought to be terminated by a newline. And yet, the stderr output 
doesn't show up until the program exits.




-- 
Steve

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


Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 19:04, Michael Torrie wrote:
> Grep can use regular expressions (and I do so with it regularly),
> but it's default mode is certainly not regular expressions, and it
> is still very powerful.

I suspect you're thinking of `fgrep` (AKA "grep -F") which uses fixed
strings rather than regular expressions.  By default, `grep` certainly
does use regular expressions:

  tim@linux$ seq 5 | grep "1*"
  tim@bsd$ jot 5 | grep "1*"

will output the entire input, not just lines containing a "1"
followed by an asterisk.

> I've never used regular expressions in a database query language;
> until this moment I didn't know any supported such things in their
> queries.  Good to know.  How you would index for regular
> expressions in queries I don't know.

At least PostgreSQL allows for creating indexes on a particular
regular expression.  E.g. (shooting from the hip so I might have
missed something):

  CREATE TABLE contacts (
   -- ...
   phonenumber VARCHAR(15),
   -- ...
   )
  CREATE INDEX contacts_just_phone_digits_idx
   ON contacts((regexp_replace(phonenumber, '[^0-9]', '')));

  INSERT INTO contacts(..., phonenumber, ...)
   VALUES (..., '800-555-1212', ...)

  SELECT *
  FROM contacts
  WHERE -- should use contacts_just_phone_digits_idx
   regexp_replace(phonenumber, '[^0-9]', '') = '8005551212';

It's not as helpful as one might hope because you're stuck using a
fixed regexp rather than an arbitrary regexp, but if you have a
particular regexp you search for frequently, you can index it.
Otherwise, you'd be doing full table-scans (or at least a full scan
of whatever subset the active non-regexp'ed index yields) which can
be pretty killer on performance.

You'd have to research on other DB engines.

-tkc




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


Re: Regular expressions

2015-11-03 Thread Dan Sommers
On Tue, 03 Nov 2015 19:04:23 -0700, Michael Torrie wrote:

> On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote:
>> I consider regexs more fundemental.  One need not even be a programmer
>> to use them: consider grep, sed, a zillion editors, database query 
>> languages, etc.
> 
> Grep can use regular expressions (and I do so with it regularly), but
> it's default mode is certainly not regular expressions ...

Its very name indicates that its default mode most certainly is regular
expressions.

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


Re: Regular expressions

2015-11-03 Thread Michael Torrie
On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote:
> I consider regexs more fundemental.  One need not even be a programmer
> to use them: consider grep, sed, a zillion editors, database query 
> languages, etc.

Grep can use regular expressions (and I do so with it regularly), but
it's default mode is certainly not regular expressions, and it is still
very powerful.  I've never used regular expressions in a database query
language; until this moment I didn't know any supported such things in
their queries.  Good to know.  How you would index for regular
expressions in queries I don't know.

> When there is a mini-language explicitly developed for describing
> string patterns, why, except is very simple cases, would one not
> take advantage of it?  

Mainly because the programming language itself often can do it just as
cleanly and just as fast (slicing, string methods, etc).  I certainly
programmed for many years without needing regular expressions in my
small projects.  In fact, REs are a bit of a pain to use in, say, C or
C++, requiring a library.  With Python they are much more readily
accessible so I use them much more.

But honestly it wasn't until college when I learned about finite state
automata that I really grasped what regular expressions were and how to
use them.

> Beyond trivial operations a regex, although
> terse (overly perhaps), is still likely to be more understandable 
> more maintainable than bunch of ad-hoc code.  And the relative ease 
> of expressing complex patterns means one is more likely to create
> more specific patterns, resulting in detecting unexpected input 
> earlier than with ad-hoc code. 

Maybe, maybe not.  Using Python string class methods is probably more
clear when such methods are sufficient.

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


Re: Creating PST files using Python

2015-11-03 Thread rurpy--- via Python-list
I should have checked the web site before posting, it
appears that both libpst and libpff only read pst files,
no write.  Sorry for the noise.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating PST files using Python

2015-11-03 Thread rurpy--- via Python-list
On 11/03/2015 12:09 PM, Anthony Papillion wrote:
> Does anyone know of a module that allows the wiring of Outlook PST
> files using Python? I'm working on a project that will require me to
> migrate 60gb of maildir mail (multiple accounts) to Outlook.

I used libpst (http://www.five-ten-sg.com/libpst/) a few years ago
successfully but I was going in the other direction (outlook -> maildir)
so not sure if it does writing of pst files. 
At the time I also looked into libpff which (from my notes, I don't
remember much of this work) was newer but the documentation was pretty
thin and it wasn't worth the time to figure out how to use it.
Of course things may have changed since then...

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


Re: Regular expressions

2015-11-03 Thread rurpy--- via Python-list
On Monday, November 2, 2015 at 9:38:24 PM UTC-7, Michael Torrie wrote:
> On 11/02/2015 09:23 PM, rurpy--- via Python-list wrote:
> >> My completely unsolicited advice is that regular expressions shouldn't be
> >> very high on the list of things to learn.  They are very useful, and very
> >> tricky and prone many problems that can and should be learned to be
> >> resolved with much simpler methods.  If you really want to learn regular
> >> expressions, that's great but the problem you posed is not one for which
> >> they are the best solution.  Remember simpler is better than complex.
> > 
> > Regular expressions should be learned by every programmer or by anyone
> > who wants to use computers as a tool.  They are a fundamental part of
> > computer science and are used in all sorts of matching and searching 
> > from compilers down to your work-a-day text editor.
> > 
> > Not knowing how to use them is like an auto mechanic not knowing how to 
> > use a socket wrench.
> 
> Not quite.  Core language concepts like ifs, loops, functions,
> variables, slicing, etc are the socket wrenches of the programmer's
> toolbox.  Regexs are like an electric impact socket wrench.  You can do
> the same work without it, but in many cases it's slower. But you have to
> learn the other hand tools first in order to really use the electric
> driver properly (understanding torques, direction of threads, etc), lest
> you wonder why you're breaking off so many bolts with the torque of the
> impact drive.

I consider regexs more fundemental.  One need not even be a programmer
to use them: consider grep, sed, a zillion editors, database query 
languages, etc.

When there is a mini-language explicitly developed for describing
string patterns, why, except is very simple cases, would one not
take advantage of it?  Beyond trivial operations a regex, although
terse (overly perhaps), is still likely to be more understandable 
more maintainable than bunch of ad-hoc code.  And the relative ease 
of expressing complex patterns means one is more likely to create
more specific patterns, resulting in detecting unexpected input 
earlier than with ad-hoc code. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expressions

2015-11-03 Thread rurpy--- via Python-list
On 11/03/2015 12:15 AM, Steven D'Aprano wrote:
> On Tue, 3 Nov 2015 03:23 pm, rurpy wrote:
> 
>> Regular expressions should be learned by every programmer or by anyone
>> who wants to use computers as a tool.  They are a fundamental part of
>> computer science and are used in all sorts of matching and searching
>> from compilers down to your work-a-day text editor.
> 
> You are absolutely right.
> 
> If only regular expressions weren't such an overly-terse, cryptic
> mini-language, with all but no debugging capabilities, they would be great.
> 
> If only there wasn't an extensive culture of regular expression abuse within
> programming communities, they would be fine.
> 
> All technologies are open to abuse. But we don't say:
> 
>   Some people, when confronted with a problem, think "I know, I'll use
>   arithmetic." Now they have two problems.
> 
> because abuse of arithmetic is rare. It's hard to misuse it, and while
> arithmetic can be complicated, it's rare for programmers to abuse it. But
> the same cannot be said for regexes -- they are regularly misused, abused,
> and down-right hard to use right even when you have a good reason for using
> them:
> 
> http://www.thedailywtf.com/articles/Irregular_Expression
> 
> http://blog.codinghorror.com/regex-use-vs-regex-abuse/
> 
> http://psung.blogspot.com.au/2008/01/wonderful-abuse-of-regular-expressions.html

Thanks for pointing out three cases of misuse of regexes out of the
approximately 37500 [*] uses of regexes in the wild. I hope you're
not dumb enough to think that constitutes significant evidence.

Even worse, of the three only one was a real example. One of the others
was machine-generated code, the other was a "look what you can do with
regexes" example, not serious code.

Here is an example of "abusing" python

  https://benkurtovic.com/2014/06/01/obfuscating-hello-world.html

I wouldn't use this as evidence that Python is to be avoided.

> If there is one person who has done more to create a regex culture, it is
> Larry Wall, inventor of Perl. Even Larry Wall says that regexes are
> overused and their syntax is harmful, and he has recreated them for Perl 6:
> 
> http://www.perl.com/pub/2002/06/04/apo5.html

You really should have read beyond the first paragraph. He proposes
fixing regexes by adding even more special character combinations and
making regexes even *more* powerful. (He turned them into full-blown
parsers.)

Nowhere does he advocate not using, or avoiding if possible, regexes
as is the mantra in this list.

Here is Larry's "recreation" that you are touting:

  http://design.perl6.org/S05.html

Please explain to us how you think this "fix" addresses the complaints
you and other Python anti-regexers have about regexes.

I hope you also noted Larry's tongue-in-cheek writing style. Right after
pointing out that some claim Perl is hard to read due largely to regex
syntax, he writes:

  "Funny that other languages have been borrowing Perl's regular
  expressions as fast as they can..."

So I don't think you can claim Larry Wall as a supporter of this list's
anti-regex attitude beyond some superficial verbiage taken out of context.

> Oh, and the icing on the cake, regexes can be a security vulnerability too:
> https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS

And here is a list of CVEs involving Python. There are (at time of
writing) 190 of them.

  http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=python

So if a security vulnerability is reason not to use regexes, we should
all be *running* from Python. I sure you'll point out that most have
been fixed.

But you failed to point out that same is true of regex engines. From
your source:

  "Notice, that not all algorithms are naïve, and actually Regex
  algorithms can be written in an efficient way."

And in fact, again, had you looked beyond a headline that suited your
purpose, you could have tried the "Evil Regexes" noted in that source
and discovered none of them are a DoS in Python.

Even were that not true, normal practice applies: if the input is
untrusted then sanitize it, or mitigate the threat by imposing a timeout,
etc. Not exactly a problem or solution unique to regexes. And common
sense should tell you that since there are a lot of "try a regex" web
sites, this is not a problem without a solution.

And *certainly* not a reason not to use them in the *far* more common
case when they *are* trusted because you are in control of them,

Finally, preemptively, I'll repeat I acknowledge regexs are not the
the optimum solution in every case where they could be used. But they
are very useful when one passes the border of the trivial; and they are
nowhere near as bad as routinely portrayed here.


[*] Yes, I made that number up.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating PST files using Python

2015-11-03 Thread Cameron Simpson

On 04Nov2015 09:12, Chris Angelico  wrote:

On Wed, Nov 4, 2015 at 6:09 AM, Anthony Papillion
 wrote:

Does anyone know of a module that allows the wiring of Outlook PST files using 
Python? I'm working on a project that will require me to migrate 60gb of 
maildir mail (multiple accounts) to Outlook.


*wince*

I don't, but if there is such a thing, it'll probably be mentioned here:
https://pypi.python.org

But be careful. My gut feeling is that the format will be different in
every version of Outlook, so you'll need something exactly matching
it.


Microsoft have a page here:

 https://msdn.microsoft.com/en-us/library/ff385210%28v=office.12%29.aspx

which purports to document the PST format. There are links to the document 
sections and also to PDFs.


It seems to be a simple and understandable format of a mere 190 pages. Yes, I 
am joking, though not about the page count; it seems like an obscene and 
totally nuts way to store email. IIRC, M$ LookOut! doesn't even use 
Message-IDs, but some proprietry scheme.



Since you're migrating your mail *to* Outlook, I'd look for some means
of importing mail. Worst case, you could create a bunch of files in
the maildir layout,


The OP has these I think.


spin up an off-the-shelf POP3 server, and tell
Outlook to read it all.

Personally, though, I'd refuse the job altogether. Creating a 60GB
blob of mail is going to cause nothing but pain. That might even be
beyond Outlook's current hard limit - I don't know. Bad, bad idea.


It is a very strange request. But very corporate/government in mindset.

Alas, I cannot help to the with any tools or module for his task.

Cheers,
Cameron Simpson 

Microsoft Mail: as far from RFC-822 as you can get and still pretend to care.
   - Abby Franquemont-Guillory 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expressions

2015-11-03 Thread Robin Koch

Am 03.11.2015 um 05:23 schrieb ru...@yahoo.com:


Of course there are people who misuse regexes.


/^1?$|^(11+?)\1+$/

There are? 0:-)

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


Re: Unbuffered stderr in Python 3

2015-11-03 Thread Terry Reedy

On 11/3/2015 10:42 AM, Chris Angelico wrote:

On Wed, Nov 4, 2015 at 2:00 AM, Random832  wrote:

Nobody  writes:


It's probably related to the fact that std{in,out,err} are Unicode
streams.


There's no fundamental reason a Unicode stream should have to be line
buffered. If it's "related", it's only in that an oversight was made in
the course of making that change.


The current behavior is not an 'oversight'.  I was considered, decided, 
and revisited in https://bugs.python.org/issue13601.  Guido: 
"Line-buffering should be good enough since in practice errors messages 
are always terminated by a newline."  If not, print(part_line, 
file=sys.stderr, flush=True) works for the unusual case.



Yep. Unicode *input* streams need to be buffered, but *output* can
always be insta-flushed. The only significance of Unicode to output is
that a single character may cause multiple bytes to be output; and
since output can block for even a single byte, it should be no
different.

+1 for making sys.stderr unbuffered.


-
Terry Jan Reedy

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


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Grant Edwards
On 2015-11-03, Tim Chase  wrote:

[re. iterating over lines in a file]

> I can't think of more than 1-2 times in my last 10+ years of
> Pythoning that I've actually had potential use for the newlines,

If you can think of 1-2 times when you've been interating over the
lines in a file and wanted to see the EOL markers, then that's 1-2
times more than I've ever wanted to see them since I started using
Python 16 years ago...

-- 
Grant Edwards   grant.b.edwardsYow! !  Up ahead!  It's a
  at   DONUT HUT!!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating PST files using Python

2015-11-03 Thread Chris Angelico
On Wed, Nov 4, 2015 at 6:09 AM, Anthony Papillion
 wrote:
> Does anyone know of a module that allows the wiring of Outlook PST files 
> using Python? I'm working on a project that will require me to migrate 60gb 
> of maildir mail (multiple accounts) to Outlook.
>

*wince*

I don't, but if there is such a thing, it'll probably be mentioned here:

https://pypi.python.org

But be careful. My gut feeling is that the format will be different in
every version of Outlook, so you'll need something exactly matching
it.

Since you're migrating your mail *to* Outlook, I'd look for some means
of importing mail. Worst case, you could create a bunch of files in
the maildir layout, spin up an off-the-shelf POP3 server, and tell
Outlook to read it all.

Personally, though, I'd refuse the job altogether. Creating a 60GB
blob of mail is going to cause nothing but pain. That might even be
beyond Outlook's current hard limit - I don't know. Bad, bad idea.

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


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 11:39, Ian Kelly wrote:
> >> because I have countless loops that look something like
> >>
> >>   with open(...) as f:
> >> for line in f:
> >>   line = line.rstrip('\r\n')
> >>   process(line)  
> >
> > What would happen if you read a file opened like this without
> > iterating over lines?  
> 
> I think I'd go with this:
> 
> >>> def strip_newlines(iterable):  
> ... for line in iterable:
> ... yield line.rstrip('\r\n')
> ...

Behind the scenes, this is what I usually end up doing, but the
effective logic is the same.  I just like the notion of being able to
tell open() that I want iteratation to happen over the *content* of
the lines, ignoring the new-line delimiters.

I can't think of more than 1-2 times in my last 10+ years of
Pythoning that I've actually had potential use for the newlines,
usually on account of simply feeding the entire line back into some
filelike.write() method where I wanted the newlines in the resulting
file. But even in those cases, I seem to recall stripping off the
arbitrary newlines (LF vs. CR/LF) and then adding my own known line
delimiter.

-tkc



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


Re: Modern recommended exception handling practices?

2015-11-03 Thread Paul Rubin
Chris Angelico  writes:
> Aside from string exceptions and the "except Type, e:" syntax, I would
> agree with you. Actually, I can't think of any "obsolete
> exception-handling practices" in any language. 

I'd say that context managers are a big recent improvement in Python
over dealing with a lot of exceptions explicitly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unbuffered stderr in Python 3

2015-11-03 Thread Random832
George Trojan  writes:
> This does set line buffering, but does not change the behaviour:

The opposite of line buffering is not no buffering, but full
(i.e. block) buffering, that doesn't get flushed until it runs
out of space. TextIOWrapper has its own internal buffer, and its
design apparently doesn't contemplate the possibility of using
it with a raw FileIO object (which may mean that the posted code
isn't guaranteed to work) or disabling buffering.

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


Creating PST files using Python

2015-11-03 Thread Anthony Papillion
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Does anyone know of a module that allows the wiring of Outlook PST files using 
Python? I'm working on a project that will require me to migrate 60gb of 
maildir mail (multiple accounts) to Outlook.

Thanks
Anthony
- --
Sent from my Android device with K-9 Mail. Please excuse my brevity.

-BEGIN PGP SIGNATURE-
Version: APG v1.1.1

iQJJBAEBCgAzBQJWOQZSLBxBbnRob255IFBhcGlsbGlvbiA8YW50aG9ueUBjYWp1
bnRlY2hpZS5vcmc+AAoJEAKK33RTsEsVwdgP/1f15VCI0GKkM54ram8oL3Bh2e5s
PqxhS/qe+9pYwYZrt+Dj2EENtpdwVQxIin67WxsruE1hOYcrrZiURiCaav8aL//3
zMiBwtEIHrYZ+0s54rfQTx1eltlET3c9O/Hehh69TtuLWiCYp1fKUW7pJEV2ZnqV
jLoGLeQ1BkXCukVeRVm8W8q7aBycF9jLP/Hg7r7p7g1RUYoIfUCOd0833AAHrbb4
CpSgvsztUfK7mJR9yxcWl4QPFTq3wpZA9MnXqnS/+UxqLSVRJp66omYn31w1AqQA
7XTuP3TQ4GjhPJC6uGiQUNQslBWj5FYRUQxlH/CzUFMeLpbK+ruG8K3QyNG8tFpj
TdUNxeWeRl+Sf5elgDYDe4Farn82ZborOlZmMspy/S87tENDgs1rND9/wIgnXtrt
g7sK3eVkmbBXkIqA9xXwkmx5GyHn3+o5a8JhFihePy5XnvlfAsnhjzsogTN3pYdO
YSKqR76cTTLzYuOjiF61DIgY1R/HqUsiloGiVXjfghV+ADcFLhADIJGa7wKwSItv
TjZmUKjF2U7CaNqn6mTR83VdtOymeoQyTZw9sB0WmsVVjVinOuExyy3qa9D3E07D
yfaa/RVgGLw6ygq/8JTXQx8B8xJ5lOl7KBxVNqaS9Kwx14F3aQdrDqvZRDCpU7U5
X/FC8f6YIksLIX7y
=254i
-END PGP SIGNATURE-

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


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Ian Kelly
On Tue, Nov 3, 2015 at 11:33 AM, Ian Kelly  wrote:
> On Tue, Nov 3, 2015 at 9:56 AM, Tim Chase  
> wrote:
>> Or even more valuable to me:
>>
>>   with open(..., newline="strip") as f:
>> assert all(not line.endswith(("\n", "\r")) for line in f)
>>
>> because I have countless loops that look something like
>>
>>   with open(...) as f:
>> for line in f:
>>   line = line.rstrip('\r\n')
>>   process(line)
>
> What would happen if you read a file opened like this without
> iterating over lines?

I think I'd go with this:

>>> def strip_newlines(iterable):
... for line in iterable:
... yield line.rstrip('\r\n')
...
>>> list(strip_newlines(['one\n', 'two\r', 'three']))
['one', 'two', 'three']

Or if I care about optimizing the for loop (but we're talking about
file I/O, so probably not), this might be faster:

>>> import operator
>>> def strip_newlines(iterable):
... return map(operator.methodcaller('rstrip', '\r\n'), iterable)
...
>>> list(strip_newlines(['one\n', 'two\r', 'three']))
['one', 'two', 'three']

Then the iteration is just:
for line in strip_newlines(f):
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Ian Kelly
On Tue, Nov 3, 2015 at 9:56 AM, Tim Chase  wrote:
> On 2015-11-03 16:35, Peter Otten wrote:
>> I wish there were a way to prohibit such files. Maybe a special
>> value
>>
>> with open(..., newline="normalize") f:
>> assert all(line.endswith("\n") for line in f)
>>
>> to ensure that all lines end with "\n"?
>
> Or even more valuable to me:
>
>   with open(..., newline="strip") as f:
> assert all(not line.endswith(("\n", "\r")) for line in f)
>
> because I have countless loops that look something like
>
>   with open(...) as f:
> for line in f:
>   line = line.rstrip('\r\n')
>   process(line)

What would happen if you read a file opened like this without
iterating over lines?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unbuffered stderr in Python 3

2015-11-03 Thread George Trojan




 Forwarded Message 
Subject:Re: Unbuffered stderr in Python 3
Date:   Tue, 03 Nov 2015 18:03:51 +
From:   George Trojan 
To: python-list@python.org



On 11/03/2015 05:00 PM, python-list-requ...@python.org wrote:

On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote:


In Python 2, stderr is unbuffered.

In most other environments (the shell, C...) stderr is unbuffered.

It is usually considered a bad, bad thing for stderr to be buffered. What
happens if your application is killed before the buffer fills up? The
errors in the buffer will be lost.

So how come Python 3 has line buffered stderr? And more importantly, how
can I turn buffering off?

It's probably related to the fact that std{in,out,err} are Unicode
streams.

> type(sys.stderr)

> type(sys.stderr.buffer)

> type(sys.stderr.buffer.raw)


It appears that you can turn it off with:

sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
or:
sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach())

This results in a sys.stderr which appears to work and whose
.line_buffering property is False.



This does set line buffering, but does not change the behaviour:

(devenv-3.4.1) dilbert@gtrojan> cat x.py
import sys
import time
if sys.version>'3':
import io
sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach())
#sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
print(sys.stderr.line_buffering)
sys.stderr.write('a')
time.sleep(10)

This is python2.7.5. a is printed before ^C.

(devenv-3.4.1) dilbert@gtrojan> /bin/python x.py
a^CTraceback (most recent call last):

Here buffer is flushed on close, after typing ^C.//

(devenv-3.4.1) dilbert@gtrojan> python x.py
False
^CaTraceback (most recent call last):

George

Found it. write_through must be set to True.

(devenv-3.4.1) dilbert@gtrojan> cat x.py
import sys
import time
if sys.version>'3':
import io
sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach(), 
write_through=True)

#sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
print(sys.stderr.line_buffering)
sys.stderr.write('a')
time.sleep(10)
(devenv-3.4.1) dilbert@gtrojan> python x.py
False
a^CTraceback (most recent call last):

/

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


cvxopt install problem

2015-11-03 Thread Ek Esawi
Hi All—





I needed to install cvxopt on a 64 bit W7. I found out that cvxopt is
incompatible with a 64 bit. It only compatible with a 32 bit which can be
installed on a 64 bit computer and it works. I stumbled on this on another
discussion group posting. The suggestion was to install python 32 bit on a
64 bit computer, then download cvxopt and install it via conda.



Here is the suggestion from the posting  [If you are using Windows, an easy
solution could be the Anaconda distribution (http://continuum.io/downloads).
Select and install the 32 bit version. It will be easier to install the
cvxopt package. Search it in the binstar repository (
https://binstar.org/search?q=cvxopt). Open a console terminal and install
it (e. g. "conda install -chttps://conda.binstar.org/omnia cvxopt").?]



I did everything except the last command to install cvxopt, that’s “conda
install -chttps://conda.binstar.org/omnia cvxopt".

Here is the command I used:

conda install c:/Users/eesawi0001/Downloads/cvxopt-1.1.7-py34.tar

I kept getting invalid syntax



Any help is greatly appreciated.


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


Re: Unbuffered stderr in Python 3

2015-11-03 Thread George Trojan

On 11/03/2015 05:00 PM, python-list-requ...@python.org wrote:

On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote:


In Python 2, stderr is unbuffered.

In most other environments (the shell, C...) stderr is unbuffered.

It is usually considered a bad, bad thing for stderr to be buffered. What
happens if your application is killed before the buffer fills up? The
errors in the buffer will be lost.

So how come Python 3 has line buffered stderr? And more importantly, how
can I turn buffering off?

It's probably related to the fact that std{in,out,err} are Unicode
streams.

> type(sys.stderr)

> type(sys.stderr.buffer)

> type(sys.stderr.buffer.raw)


It appears that you can turn it off with:

sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
or:
sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach())

This results in a sys.stderr which appears to work and whose
.line_buffering property is False.



This does set line buffering, but does not change the behaviour:

(devenv-3.4.1) dilbert@gtrojan> cat x.py
import sys
import time
if sys.version>'3':
import io
sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach())
#sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
print(sys.stderr.line_buffering)
sys.stderr.write('a')
time.sleep(10)

This is python2.7.5. a is printed before ^C.

(devenv-3.4.1) dilbert@gtrojan> /bin/python x.py
a^CTraceback (most recent call last):

Here buffer is flushed on close, after typing ^C.

(devenv-3.4.1) dilbert@gtrojan> python x.py
False
^CaTraceback (most recent call last):

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


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Peter Otten
Tim Chase wrote:

> On 2015-11-03 16:35, Peter Otten wrote:
>> I wish there were a way to prohibit such files. Maybe a special
>> value
>> 
>> with open(..., newline="normalize") f:
>> assert all(line.endswith("\n") for line in f)
>> 
>> to ensure that all lines end with "\n"?
> 
> Or even more valuable to me:
> 
>   with open(..., newline="strip") as f:
> assert all(not line.endswith(("\n", "\r")) for line in f)
> 
> because I have countless loops that look something like
> 
>   with open(...) as f:
> for line in f:
>   line = line.rstrip('\r\n')
>   process(line)

Indeed. It's obvious now you're saying it...

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


pybabel extraction mess

2015-11-03 Thread Nagy László Zsolt
If I have a large project with multiple directories, then I may want to
assign different translation domains for different subpackages.

Suppose I have this directory structure:

main
   |
   |--- sub1
   |
   |--- sub2
|
| sub2.1
|
| sub2.2

There are python source files in subpackages, and also at upper level
packages. Some examples:

main/test1.py
main/sub1/test2.py
main/sub2/test3.py
main/sub2/sub2.1/test4.py
main/sub2/sub2.2/test5.py



I cannot find out how to run pybabel so that messages from different
subdirectories gets extracted into different catalog files. The main
problem is that pybabel expects a directory. Let's say that I want to
have a different domain for main/sub2/sub2.1, and another domain for
everything else.

I can extract messages from main/sub/sub2.1 with "pybabel extract
main/sub/sub2.1", but I'm not able to extract all the others into a
different pot file. Simply because "pybabel extract main" will extract
all messages from main/sub2/sub2.1 again. There is no way to extract
from a list of files. Just from directories. It does not seem possible
to specify disjunct sets of files for message catalogs.

For a small project, this is not a problem. If I have at least one file
at the main level, then all other files MUST be bound to the same
domain, because the top level file can only be extracted by giving the
top directory to pybabel, but that will also extract everything else
from the whole project.

I would really like to divide messages into different domains. But how?
Is there a way to run pybabel programatically on a list of source files?

Thanks,

   Laszlo


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


CherryPy cpstats and ws4py

2015-11-03 Thread Israel Brewster
I posted this to the CherryPy and ws4py mailing lists, but in the week since I 
did that I've only gotten two or three views on each list, and no responses, so 
as a last-ditch effort I thought I'd post here. Maybe someone with more general 
python knowledge than me can figure out the traceback and from there a solution.

Is it possible to use ws4py in conjunction with the cpstats CherryPy tool? I 
have a CherryPy (3.8.0) web app that uses web sockets via ws4py. Tested and 
working. I am now trying to get a little more visibility into the functioning 
of the server, so to that end I enabled the cpstats tool by adding the 
following line to my '/' configuration:

tools.cpstats.on=True

Unfortunately, as soon as I do that, attempts to connect a web socket start 
failing with the following traceback:

[28/Oct/2015:08:18:48]  
Traceback (most recent call last):
  File 
"/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py",
 line 104, in run
hook()
  File 
"/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py",
 line 63, in __call__
return self.callback(**self.kwargs)
  File "build/bdist.macosx-10.10-intel/egg/ws4py/server/cherrypyserver.py", 
line 200, in upgrade
ws_conn = get_connection(request.rfile.rfile)
  File "build/bdist.macosx-10.10-intel/egg/ws4py/compat.py", line 43, in 
get_connection
return fileobj._sock
AttributeError: 'KnownLengthRFile' object has no attribute '_sock'
[28/Oct/2015:08:18:48] HTTP 
Request Headers:
  PRAGMA: no-cache
  COOKIE: autoTabEnabled=true; fleetStatusFilterCompany=7H; 
fleetStatusFilterLocation=ALL; fleetStatusRefreshInterval=5; inputNumLegs=5; 
session_id=5c8303896aff419c175c79dfadbfdc9d75e6c45a
  UPGRADE: websocket
  HOST: flbubble.ravnalaska.net:8088
  ORIGIN: http://flbubble.ravnalaska.net
  CONNECTION: Upgrade
  CACHE-CONTROL: no-cache
  SEC-WEBSOCKET-VERSION: 13
  SEC-WEBSOCKET-EXTENSIONS: x-webkit-deflate-frame
  USER-AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) 
AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7
  SEC-WEBSOCKET-KEY: Szh6Uoe+WzqKR1DgW8JcXA==
  Remote-Addr: 10.9.1.59
[28/Oct/2015:08:18:48] HTTP 
Traceback (most recent call last):
  File 
"/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py",
 line 661, in respond
self.hooks.run('before_request_body')
  File 
"/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py",
 line 114, in run
raise exc
AttributeError: 'KnownLengthRFile' object has no attribute '_sock'

Disable tools.cpstats.on, and the sockets start working again. Is there some 
way I can fix this so I can use sockets as well as gather stats from my 
application? Thanks.

---
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
---

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


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 16:35, Peter Otten wrote:
> I wish there were a way to prohibit such files. Maybe a special
> value
> 
> with open(..., newline="normalize") f: 
> assert all(line.endswith("\n") for line in f)
> 
> to ensure that all lines end with "\n"?

Or even more valuable to me:

  with open(..., newline="strip") as f:
assert all(not line.endswith(("\n", "\r")) for line in f)

because I have countless loops that look something like

  with open(...) as f:
for line in f:
  line = line.rstrip('\r\n')
  process(line)

-tkc




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


Re: Detection of a specific sound

2015-11-03 Thread Joel Goldstick
On Tue, Nov 3, 2015 at 11:23 AM, Ian Kelly  wrote:

> On Tue, Nov 3, 2015 at 7:45 AM, William Ray Wing  wrote:
> >
> >> On Oct 25, 2015, at 8:17 PM, Montana Burr 
> wrote:
> >>
> >> I'm looking for a library that will allow Python to listen for the
> shriek of a smoke alarm. Once it detects this shriek, it is to notify
> someone. Ideally, specificity can be adjusted for the user's environment.
> For example, I expect to need moderate specificity as I live in a quiet
> neighborhood, but an apartment dweller might need more.
> >>
> >> I'm thinking of recording a smoke alarm and having the program try to
> find the recorded sound in the stream from the microphone.
> >>
> >
> > I’ve been watching this thread and finally decided to jump in.
>
> I love how in the past 24 hours five more people have piled onto this
> thread even though the OP hasn't posted any followup since the
> original question nine days ago.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Sometimes (maybe most times) the follow on discussion goes off on
insightful tangents that may have little to do with the OP.

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


Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Jussi Piitulainen
Peter Otten writes:
> Jussi Piitulainen wrote:
>> Peter Otten writes:
>> 
>>> If a "line" is defined as a string that ends with a newline
>>>
>>> def ends_in_asterisk(line):
>>> return False
>>>
>>> would also satisfy the requirement. Lies, damned lies, and specs ;)
>> 
>> Even if a "line" is defined as a string that comes from reading
>> something like a file with default options, a line may end in
>> an asterisk.
>  
> Note that the last line from the file is not a line as defined by me
> in the above post ;)

Noted.

> [ line.endswith('*') for line in StringIO('rivi*\nrivi*\nrivi*') ]
>> [False, False, True]
>
> I wish there were a way to prohibit such files. Maybe a special value
>
> with open(..., newline="normalize") f: 
> assert all(line.endswith("\n") for line in f)
>
> to ensure that all lines end with "\n"?

I'd like that. It should be the default.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python PNG Viewer(Browser Based)

2015-11-03 Thread marco . nawijn
On Tuesday, November 3, 2015 at 12:55:09 PM UTC+1, Arshpreet Singh wrote:
> Hello Everyone,
> 
> I am looking for Browser-based PNG file viewer written in
> Python.(Flask framework preferably)
> 
> Following project(Flask-Based) provides many things(File manager as
> well as file viewer)  but it does not support PNG files.
> 
> https://github.com/vmi356/filemanager
> 
> Any idea if I have to write my own browser based PNG viewer from
> scratch(Using PIL or other required library)
> 
> On the other side if I have to write only Desktop-based only two lines
> are enough to do many things:
> 
> Like,
> 
> from PIL import Image
> f = Image.open("file.png").show()
> 
> 
> But I am not getting right sense that how to make possible using Python+Flask.
> 
> Hope I am able to tell my problem?

Well, if you only want to open the PNG file in the webbrowser
(in contrast of serving them over the internet), you can do it
in two lines too:

import webbrowser
webbrowser.open('file.png')

But this is probably not what you want.

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


Re: Detection of a specific sound

2015-11-03 Thread Ian Kelly
On Tue, Nov 3, 2015 at 7:45 AM, William Ray Wing  wrote:
>
>> On Oct 25, 2015, at 8:17 PM, Montana Burr  wrote:
>>
>> I'm looking for a library that will allow Python to listen for the shriek of 
>> a smoke alarm. Once it detects this shriek, it is to notify someone. 
>> Ideally, specificity can be adjusted for the user's environment. For 
>> example, I expect to need moderate specificity as I live in a quiet 
>> neighborhood, but an apartment dweller might need more.
>>
>> I'm thinking of recording a smoke alarm and having the program try to find 
>> the recorded sound in the stream from the microphone.
>>
>
> I’ve been watching this thread and finally decided to jump in.

I love how in the past 24 hours five more people have piled onto this
thread even though the OP hasn't posted any followup since the
original question nine days ago.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expressions

2015-11-03 Thread Chris Angelico
On Wed, Nov 4, 2015 at 3:10 AM, Seymore4Head
 wrote:
> Yes I knew that -1 represents the end character.  It is not a question
> of trying to accomplish anything.  I was just practicing with regex
> and wasn't sure how to express a * since it was one of the
> instructions.

In that case, it's nothing to do with ending a string. What you really
want to know is: How do you match a '*' using a regular expression?
Which is what MRAB answered, courtesy of a working crystal ball: You
use '\*'. Everything about the end of the string is irrelevant. (So,
too, are all the comments about using [-1] or string methods. But we
weren't to know that.)

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


Re: Regular expressions

2015-11-03 Thread Seymore4Head
On Tue, 3 Nov 2015 10:34:12 -0500, Joel Goldstick
 wrote:

>On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head 
>wrote:
>
>> On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase
>>  wrote:
>>
>> >On 2015-11-02 20:09, Seymore4Head wrote:
>> >> How do I make a regular expression that returns true if the end of
>> >> the line is an asterisk
>> >
>> >Why use a regular expression?
>> >
>> >  if line[-1] == '*':
>> >yep(line)
>> >  else:
>> >nope(line)
>> >
>> >-tkc
>> >
>> >
>> Because that is the part of Python I am trying to learn at the moment.
>>
>
>Are we to infer that you were aware of doing the   if line[-1] == '*': ...
>, but just wanted to learn how to do the same thing with regex? Or that you
>heard about regexes and thought that would be the way to solve your puzzle?
>
>> Thanks
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
Yes I knew that -1 represents the end character.  It is not a question
of trying to accomplish anything.  I was just practicing with regex
and wasn't sure how to express a * since it was one of the
instructions.

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


Re: Python PNG Viewer(Browser Based)

2015-11-03 Thread Chris Warrick
On 3 November 2015 at 12:54, Arshpreet Singh  wrote:
> Hello Everyone,
>
> I am looking for Browser-based PNG file viewer written in
> Python.(Flask framework preferably)
>
> Following project(Flask-Based) provides many things(File manager as
> well as file viewer)  but it does not support PNG files.
>
> https://github.com/vmi356/filemanager
>
> Any idea if I have to write my own browser based PNG viewer from
> scratch(Using PIL or other required library)
>
> On the other side if I have to write only Desktop-based only two lines
> are enough to do many things:
>
> Like,
>
> from PIL import Image
> f = Image.open("file.png").show()
>
>
> But I am not getting right sense that how to make possible using Python+Flask.
>
> Hope I am able to tell my problem?
> --
> https://mail.python.org/mailman/listinfo/python-list

Your problem is lack of basic understanding of the Internet. Because
EVERY graphical web browser supports PNG files NATIVELY. With a single
 tag.

Just figure out where to add the PNG handler code and read any random
“how to add images to a webpage” tutorial.
You might need a new template and some code that is aware of the file
being an image. But absolutely no PNG viewer is necessary.

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: LU decomposition

2015-11-03 Thread Oscar Benjamin
On 1 November 2015 at 10:04, gers antifx  wrote:
>
> I have to write a LU-decomposition. My Code worked so far but (I want to 
> become better:) ) I want to ask you, if I could write this LU-decomposition 
> in a better way?
>
> def LU(x):
> L = np.eye((x.shape[0]))
> n = x.shape[0]
> for ii in range(n-1):
> for ll in range(1+ii,n):
> factor = float(x[ll,ii])/x[ii,ii]
> L[ll,ii] = factor
> for kk in range(0+ii,n):
> x[ll,kk] = x[ll,kk] - faktor*x[ii,kk]
> LU = np.dot(L,x)

You're using ii and ll, kk etc. This is common practise in Matlab code
because Matlab uses i as sqrt(-1) but this is spelled 1j in Python so
we don't have that problem. In this sort of context it would be more
natural to use simply i, j, k in Python.

Another is that you're not checking for divide by zero in
float(x[ll,ii])/x[ii,ii]. Are you sure that it will not be zero? What
happens if e.g. x[0, 0] is zero? This is where you'll need to use
pivoting which complicates the algorithm a bit.

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


Re: Detection of a specific sound

2015-11-03 Thread William Ray Wing

> On Oct 25, 2015, at 8:17 PM, Montana Burr  wrote:
> 
> I'm looking for a library that will allow Python to listen for the shriek of 
> a smoke alarm. Once it detects this shriek, it is to notify someone. Ideally, 
> specificity can be adjusted for the user's environment. For example, I expect 
> to need moderate specificity as I live in a quiet neighborhood, but an 
> apartment dweller might need more.
> 
> I'm thinking of recording a smoke alarm and having the program try to find 
> the recorded sound in the stream from the microphone.
> 

I’ve been watching this thread and finally decided to jump in.

First off, we REALLY need to know a bit more about what you are trying to 
accomplish, in what sort of environment, and under what constraints (legal and 
otherwise).  That last bit is crucial.  Is this simply a heads up e-mail 
message to be sent or is it a way of notifying a backup (second tier) 
monitoring service.  Is it for your personal use, or do you expect to sell it 
(again crucial).  Does the computer you expect to run this on have a good UPS 
system (in a typical fire, AC power frequently fails early, sometimes it is the 
*cause* of the fire).  How are you going to get that notification out?  Does 
your network have battery backup?  Are you going to buy a station-service cell 
phone transmitter? If you are thinking of sending a cell phone msg, how do you 
guarantee the receiver is on?  LOTS of issues here.  Then, having said that, 
and in no particular order:

1) the sounders in most smoke alarms use over-driven pizeo-electric 
annunciators, their output has a VERY complex frequency spectrum with LOTS of 
harmonics.  Spectral analysis (combined with threshold analysis) MIGHT be a 
good way to go, but doing so in real time with Python would consume most, if 
not all the resources of the host computer;

2) You would (personal opinion), be much better off using hardwired or 
semi-hardwired detection.  There are several ways to go, including a detector 
microphone and transmitter such as is used to run a remote doorbell system 
(mount the microphone next to the smoke detector, then tap into the doorbell 
receiver box). These have adjustable sensitivity and would basically be a 
threshold detector.  Alternatively, almost all smoke detectors these days are 
designed to be chained to each other via three-wire (plus ground) AC wiring.  
Two of the wires carry power, the third triggers all the detectors in the 
system to sound when if of them sound.  Don’t try to tap the signal wire 
(liability issues), but you could add another detector to the system which 
would act as your monitor if you tap *its* driver output.

3) Finally, how do you guarantee the computer on which the program is to run 
will be up at all times?  Does it auto-restart after a power failure, does the 
program auto-reload as part of the boot-up sequence, and finally, is the 
program going to have absolutely bullet proof error recovery?

-Bill





> Any help is greatly appreciated!
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Unbuffered stderr in Python 3

2015-11-03 Thread Chris Angelico
On Wed, Nov 4, 2015 at 2:00 AM, Random832  wrote:
> Nobody  writes:
>
>> It's probably related to the fact that std{in,out,err} are Unicode
>> streams.
>
> There's no fundamental reason a Unicode stream should have to be line
> buffered. If it's "related", it's only in that an oversight was made in
> the course of making that change.

Yep. Unicode *input* streams need to be buffered, but *output* can
always be insta-flushed. The only significance of Unicode to output is
that a single character may cause multiple bytes to be output; and
since output can block for even a single byte, it should be no
different.

+1 for making sys.stderr unbuffered.

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


Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Peter Otten
Jussi Piitulainen wrote:

> Peter Otten writes:
> 
>> If a "line" is defined as a string that ends with a newline
>>
>> def ends_in_asterisk(line):
>> return False
>>
>> would also satisfy the requirement. Lies, damned lies, and specs ;)
> 
> Even if a "line" is defined as a string that comes from reading
> something like a file with default options, a line may end in
> an asterisk.
 
Note that the last line from the file is not a line as defined by me in the 
above post ;)

 [ line.endswith('*') for line in StringIO('rivi*\nrivi*\nrivi*') ]
> [False, False, True]

I wish there were a way to prohibit such files. Maybe a special value

with open(..., newline="normalize") f: 
assert all(line.endswith("\n") for line in f)

to ensure that all lines end with "\n"?


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


Re: Regular expressions

2015-11-03 Thread Joel Goldstick
On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head 
wrote:

> On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase
>  wrote:
>
> >On 2015-11-02 20:09, Seymore4Head wrote:
> >> How do I make a regular expression that returns true if the end of
> >> the line is an asterisk
> >
> >Why use a regular expression?
> >
> >  if line[-1] == '*':
> >yep(line)
> >  else:
> >nope(line)
> >
> >-tkc
> >
> >
> Because that is the part of Python I am trying to learn at the moment.
>

Are we to infer that you were aware of doing the   if line[-1] == '*': ...
, but just wanted to learn how to do the same thing with regex? Or that you
heard about regexes and thought that would be the way to solve your puzzle?

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



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


Re: Regular expressions

2015-11-03 Thread Jussi Piitulainen
Peter Otten writes:

> If a "line" is defined as a string that ends with a newline
>
> def ends_in_asterisk(line):
> return False
>
> would also satisfy the requirement. Lies, damned lies, and specs ;)

Even if a "line" is defined as a string that comes from reading
something like a file with default options, a line may end in
an asterisk.

>>> [ line.endswith('*') for line in StringIO('rivi*\nrivi*\nrivi*') ]
[False, False, True]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unbuffered stderr in Python 3

2015-11-03 Thread Random832
Nobody  writes:

> It's probably related to the fact that std{in,out,err} are Unicode
> streams. 

There's no fundamental reason a Unicode stream should have to be line
buffered. If it's "related", it's only in that an oversight was made in
the course of making that change.

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


Re: Detection of a specific sound

2015-11-03 Thread Random832
Dennis Lee Bieber  writes:

> If a fire did occur, and the inspectors find traces of wiring
> going into what was supposed to be a stand-alone detector there is
> a risk that it will be concluded that the detector had been
> tampered with and may not have been functional... And that could
> lead to all sorts of liability problems.

What about a *second* smoke detector?

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


Re: Regular expressions

2015-11-03 Thread Grant Edwards
On 2015-11-03, Tim Chase  wrote:
> On 2015-11-02 20:09, Seymore4Head wrote:
>> How do I make a regular expression that returns true if the end of
>> the line is an asterisk
>
> Why use a regular expression?
>
>   if line[-1] == '*':

Why use a negative index and then a compare?

if line.endswith('*'):

If you want to know if a string ends with something, just ask it!

;)

-- 
Grant Edwards   grant.b.edwardsYow! RELATIVES!!
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Detection of a specific sound

2015-11-03 Thread alister
On Tue, 03 Nov 2015 09:03:14 -0500, Dennis Lee Bieber wrote:

> On Tue, 3 Nov 2015 08:50:34 + (UTC), alister
>  declaimed the following:
> 
>>Personally I would forget trying to analyse sound & see if there is any
>>way to get an input signal direct from the alarm (even if that is as
>>crude as taking a tap from the siren feed wires)
>>
>>This application sounds far to critical for anything else.
> 
>   A direct line is what I'd recommend too -- but I'm going to be 
paranoid
> today:
> 
>   If a fire did occur, and the inspectors find traces of wiring 
going
> into what was supposed to be a stand-alone detector there is a risk that
> it will be concluded that the detector had been tampered with and may
> not have been functional... And that could lead to all sorts of
> liability problems.
> 
>   I don't know if anyone makes a model that falls between (common)
> stand-alone and full monitored (tied to burglar alarm system with a
> service provider responding to triggers). Something of a monitored type
> (hence designed to be wired to central panel) but without the outside
> monitoring agency.
> 
> 
>   Barring that... if the detectors are all close in pitch, a PLL 
circuit
> fed from the microphone, using the "locked" signal to indicate when the
> alarm is chirping -- gives a simple on/off digital signal for the
> computer (the computer may be needed to ensure the chirps are at an
> expected rate and not stray whistles). Beyond that, FFT to look for
> spectral signature of chirps.

I would hope that most fire alarm systems (except domestic type smoke 
detectors) would have some relay outputs or telephone dialler options 
which would be legitimate locations to connect extra equipment.

The op probably needs to provide more information on the exact set-up 
intended.



-- 
 __
/ Gold's Law:  \
|  |
\ If the shoe fits, it's ugly. /
 --
   \
\
.--.
   |o_o |
   |:_/ |
  //   \ \
 (| | )
/'\_   _/`\
\___)=(___/

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


Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-02 22:17, Seymore4Head wrote:
> On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase
>  wrote:
> 
> >On 2015-11-02 20:09, Seymore4Head wrote:
> >> How do I make a regular expression that returns true if the end
> >> of the line is an asterisk
> >
> >Why use a regular expression?
> >
> Because that is the part of Python I am trying to learn at the
> moment. Thanks

Ah, well that's an entirely different problem-space, so then you
would want to use MRAB's answer

  r = re.compile(r"\*$")

-tkc



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


Re: venv issues

2015-11-03 Thread Nicholas Cole
On Tue, Nov 3, 2015 at 1:59 PM, Chris Angelico  wrote:
> On Tue, Nov 3, 2015 at 9:32 PM, Nicholas Cole  wrote:
>> Logging in as a different user and creating a venv works perfectly, so
>> it's clearly a config issue somewhere, but I've tried removing
>> ~/.bashrc and ~/.bash_profile and that doesn't help.
>
> What happens if you create a brand new user, then copy in all
> dot-files and directories from your current one? Does it exhibit the
> same problem?

No. And that helped me find the problem.  I had an old

.pydistutils.cfg

file with a line:

install_lib = ~/Library/Python/$py_version_short/lib/python/site-packages

That completely upset the venv.

(whether it should have done or not, I don't know. I would have
expected venv to ignore pydistutils.cfg)

Thank you both for your help!

Best,

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


Re: venv issues

2015-11-03 Thread Peter Otten
Nicholas Cole wrote:

> I'm using python3.5 (installed from binaries) on the latest OS X.
> 
> I have a curious issue with virtual environments on this machine (but
> not on my other machine).
> 
> 
> $ python3.5 -m venv testenv
> $ source testenv/bin/activate
> (testenv)$ python -m pip
> /private/tmp/testenv/bin/python: No module named pip
> $
> 
> Logging in as a different user and creating a venv works perfectly, so
> it's clearly a config issue somewhere, but I've tried removing
> ~/.bashrc and ~/.bash_profile and that doesn't help.

Does 

$ which python3.5

(before sourcing bin/activate) point to the same python for both users?

> 
> The sys.path for that venv is: ['',
> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-
darwin',
> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-
dynload',
> '/private/tmp/testenv/lib/python3.5/site-packages']
> 
> I'm sure I'm overlooking something obvious, but can anyone suggest what?
> 
> Nicholas


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


Re: Regular expressions

2015-11-03 Thread Peter Otten
Tim Chase wrote:

> On 2015-11-03 10:25, Peter Otten wrote:
>> >>> How do I make a regular expression that returns true if the end
>> >>> of the line is an asterisk
>> >> 
>> >> Why use a regular expression?
>> >> 
>> >>   if line[-1] == '*':
>> >> yep(line)
>> >>   else:
>> >> nope(line)
>> 
>> Incidentally the code example has two "problems", too.
>> 
>> - What about the empty string?
> 
> Good catch: .endswith() works better.
> 
>> - What about lines with a trailing "\n", i. e. as they are usually
>> delivered when iterating over a file?
> 
> Then your string *doesn't* end with a "*", but rather with a
> newline. ;-)
> 
> Though according to the OP's specs, the following function would work
> too:
> 
>   def ends_in_asterisk(s):
> return True
> 
> It *does* return True if the line ends in an asterisk (no requirement
> to make the function return False under any other conditions).

If a "line" is defined as a string that ends with a newline

def ends_in_asterisk(line):
return False

would also satisfy the requirement. Lies, damned lies, and specs ;)

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


Re: venv issues

2015-11-03 Thread Chris Angelico
On Tue, Nov 3, 2015 at 9:32 PM, Nicholas Cole  wrote:
> Logging in as a different user and creating a venv works perfectly, so
> it's clearly a config issue somewhere, but I've tried removing
> ~/.bashrc and ~/.bash_profile and that doesn't help.

What happens if you create a brand new user, then copy in all
dot-files and directories from your current one? Does it exhibit the
same problem?

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


Re: venv issues

2015-11-03 Thread Nicholas Cole
On Tue, Nov 3, 2015 at 12:27 PM, Wolfgang Maier
 wrote:
> On 03.11.2015 11:32, Nicholas Cole wrote:
>>
>> I'm using python3.5 (installed from binaries) on the latest OS X.
>>
>> I have a curious issue with virtual environments on this machine (but
>> not on my other machine).
>>
>>
>> $ python3.5 -m venv testenv
>> $ source testenv/bin/activate
>> (testenv)$ python -m pip
>> /private/tmp/testenv/bin/python: No module named pip
>> $
>>
>> Logging in as a different user and creating a venv works perfectly, so
>> it's clearly a config issue somewhere, but I've tried removing
>> ~/.bashrc and ~/.bash_profile and that doesn't help.
>>
>> The sys.path for that venv is: ['',
>> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
>> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
>>
>> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
>>
>> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
>> '/private/tmp/testenv/lib/python3.5/site-packages']
>>
>
> Is there something special about your /private/tmp folder? In other words,
> do things work if you create a venv in a different place.
> If you go to /private/tmp/testenv/lib/python3.5/site-packages is there a pip
> folder and what are its permission settings?

/private/tmp/testenv/lib/python3.5/site-packages

is completely empty.

There's nothing special about that folder, though. The problem exists
everywhere.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python error

2015-11-03 Thread Terry Reedy

On 11/3/2015 8:07 AM, Ruud van Rooijen wrote:

my code:

from tkinter import *

window = Tk()
label = Label(window, text="miniproject A1")
label.pack()
window.mainloop()


given error:

C:\Users\Ruud\Python35\Scripts\python.exe


Based on the below, python.exe should be in
C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32
_tkinter should then be in
C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32\DLLs

If you moved it, that is your problem.

If you have two python installations, with a second one in
C:\Users\Ruud\Python35, then python.exe should be in that directory, NOT 
scripts.



C:/Users/Ruud/PycharmProjects/School/project.py


I know essentially nothing about PyCharm, even if it is compatible with 
tkinter.



Traceback (most recent call last):

   File "C:/Users/Ruud/PycharmProjects/School/project.py", line 3, in 

 window = Tk()

   File 
"C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32\Lib\tkinter\__init__.py",
line 1867, in __init__

 self.tk = _tkinter.create(screenName, baseName, className,
interactive, wantobjects, useTk, sync, use)

_tkinter.TclError: Can't find a usable init.tcl in the following directories:

 C:/Users/Ruud/AppData/Local/Programs/Python/Python35-32/lib/tcl8.6
C:/Users/Ruud/Python35/lib/tcl8.6 C:/Users/Ruud/lib/tcl8.6
C:/Users/Ruud/Python35/library C:/Users/Ruud/library
C:/Users/Ruud/tcl8.6.4/library C:/Users/tcl8.6.4/library


With a screwed up installation, or pair of installations, it looks 
'everyplace' but the right place.



This probably means that Tcl wasn't installed properly.



i have repaired python several times and i can't find an answer online...
please help


python.exe in scripts is not properly installed.

--
Terry Jan Reedy

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


python error

2015-11-03 Thread Ruud van Rooijen
my code:

from tkinter import *

window = Tk()
label = Label(window, text="miniproject A1")
label.pack()
window.mainloop()


given error:

C:\Users\Ruud\Python35\Scripts\python.exe
C:/Users/Ruud/PycharmProjects/School/project.py

Traceback (most recent call last):

  File "C:/Users/Ruud/PycharmProjects/School/project.py", line 3, in 

window = Tk()

  File 
"C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32\Lib\tkinter\__init__.py",
line 1867, in __init__

self.tk = _tkinter.create(screenName, baseName, className,
interactive, wantobjects, useTk, sync, use)

_tkinter.TclError: Can't find a usable init.tcl in the following directories:

C:/Users/Ruud/AppData/Local/Programs/Python/Python35-32/lib/tcl8.6
C:/Users/Ruud/Python35/lib/tcl8.6 C:/Users/Ruud/lib/tcl8.6
C:/Users/Ruud/Python35/library C:/Users/Ruud/library
C:/Users/Ruud/tcl8.6.4/library C:/Users/tcl8.6.4/library




This probably means that Tcl wasn't installed properly.


i have repaired python several times and i can't find an answer online...
please help


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


Re: Regular expressions

2015-11-03 Thread Denis McMahon
On Mon, 02 Nov 2015 22:17:49 -0500, Seymore4Head wrote:

> On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase
>  wrote:
> 
>>On 2015-11-02 20:09, Seymore4Head wrote:

>>> How do I make a regular expression that returns true if the end of the
>>> line is an asterisk

>>Why use a regular expression?

> Because that is the part of Python I am trying to learn at the moment.

The most important thing to learn about regular expressions is when to 
use them and when not to use them.

Returning true if the last character in a string is an asterisk is almost 
certainly a brilliant example of when not to use a regular expression. 
Here are some timings I tested:

#!/usr/bin/python

import re

import timeit

patt = re.compile("\*$")

start_time = timeit.default_timer()
for i in range(100):
x = re.match("\*$", "test 1")
elapsed = timeit.default_timer() - start_time
print "re, false", elapsed

start_time = timeit.default_timer()
for i in range(100):
x = re.match("\*$", "test *")
elapsed = timeit.default_timer() - start_time
print "re, true", elapsed

start_time = timeit.default_timer()
for i in range(100):
x = patt.match("test 1")
elapsed = timeit.default_timer() - start_time
print "compiled re, false", elapsed

start_time = timeit.default_timer()
for i in range(100):
x = patt.match("test *")
elapsed = timeit.default_timer() - start_time
print "compiled re, true", elapsed

start_time = timeit.default_timer()
for i in range(100):
x = "test 1"[-1] == "*"
elapsed = timeit.default_timer() - start_time
print "char compare, false", elapsed

start_time = timeit.default_timer()
for i in range(100):
x = "test *"[-1] == "*"
elapsed = timeit.default_timer() - start_time
print "char compare, true", elapsed

RESULTS:

re, false 2.4701731205
re, true 2.42048001289
compiled re, false 0.875837087631
compiled re, true 0.876382112503
char compare, false 0.26283121109
char compare, true 0.263465881348

The compiled re is about 3 times as fast as the uncompiled re. The 
character comparison is about 3 times as fast as the compiled re.

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


Re: venv issues

2015-11-03 Thread Wolfgang Maier

On 03.11.2015 11:32, Nicholas Cole wrote:

I'm using python3.5 (installed from binaries) on the latest OS X.

I have a curious issue with virtual environments on this machine (but
not on my other machine).


$ python3.5 -m venv testenv
$ source testenv/bin/activate
(testenv)$ python -m pip
/private/tmp/testenv/bin/python: No module named pip
$

Logging in as a different user and creating a venv works perfectly, so
it's clearly a config issue somewhere, but I've tried removing
~/.bashrc and ~/.bash_profile and that doesn't help.

The sys.path for that venv is: ['',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
'/private/tmp/testenv/lib/python3.5/site-packages']



Is there something special about your /private/tmp folder? In other 
words, do things work if you create a venv in a different place.
If you go to /private/tmp/testenv/lib/python3.5/site-packages is there a 
pip folder and what are its permission settings?


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


Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 10:25, Peter Otten wrote:
> >>> How do I make a regular expression that returns true if the end
> >>> of the line is an asterisk
> >> 
> >> Why use a regular expression?
> >> 
> >>   if line[-1] == '*':
> >> yep(line)
> >>   else:
> >> nope(line)
> 
> Incidentally the code example has two "problems", too.
> 
> - What about the empty string?

Good catch: .endswith() works better.

> - What about lines with a trailing "\n", i. e. as they are usually
> delivered when iterating over a file?

Then your string *doesn't* end with a "*", but rather with a
newline. ;-)

Though according to the OP's specs, the following function would work
too:

  def ends_in_asterisk(s):
return True

It *does* return True if the line ends in an asterisk (no requirement
to make the function return False under any other conditions).

-tkc





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


Python PNG Viewer(Browser Based)

2015-11-03 Thread Arshpreet Singh
Hello Everyone,

I am looking for Browser-based PNG file viewer written in
Python.(Flask framework preferably)

Following project(Flask-Based) provides many things(File manager as
well as file viewer)  but it does not support PNG files.

https://github.com/vmi356/filemanager

Any idea if I have to write my own browser based PNG viewer from
scratch(Using PIL or other required library)

On the other side if I have to write only Desktop-based only two lines
are enough to do many things:

Like,

from PIL import Image
f = Image.open("file.png").show()


But I am not getting right sense that how to make possible using Python+Flask.

Hope I am able to tell my problem?
-- 
https://mail.python.org/mailman/listinfo/python-list


venv issues

2015-11-03 Thread Nicholas Cole
I'm using python3.5 (installed from binaries) on the latest OS X.

I have a curious issue with virtual environments on this machine (but
not on my other machine).


$ python3.5 -m venv testenv
$ source testenv/bin/activate
(testenv)$ python -m pip
/private/tmp/testenv/bin/python: No module named pip
$

Logging in as a different user and creating a venv works perfectly, so
it's clearly a config issue somewhere, but I've tried removing
~/.bashrc and ~/.bash_profile and that doesn't help.

The sys.path for that venv is: ['',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
'/private/tmp/testenv/lib/python3.5/site-packages']

I'm sure I'm overlooking something obvious, but can anyone suggest what?

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


Re: Puzzled

2015-11-03 Thread Michiel Overtoom

> On 03 Nov 2015, at 05:46, Michael Torrie  wrote:
> Sometimes on Windows you can double-click a python file and it will run.

The first thing I do on Windows after installing Python: edit the registry
so that the 'open' key is changed to 'run', and 'edit with IDLE' becomes 'open'.

I like to see my scripts in IDLE before I run them ;-)

Greetings,

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


Re: Regular expressions

2015-11-03 Thread Peter Otten
Michael Torrie wrote:

> On 11/02/2015 07:42 PM, Tim Chase wrote:
>> On 2015-11-02 20:09, Seymore4Head wrote:
>>> How do I make a regular expression that returns true if the end of
>>> the line is an asterisk
>> 
>> Why use a regular expression?
>> 
>>   if line[-1] == '*':
>> yep(line)
>>   else:
>> nope(line)
> 
> Indeed, sometimes Jamie Zawinski's is often quite appropriate:
> 
> Some people, when confronted with a problem, think "I know, I'll use
> regular expressions." Now they have two problems.

Incidentally the code example has two "problems", too.

- What about the empty string?
- What about lines with a trailing "\n", i. e. as they are usually delivered
  when iterating over a file?

Below is a comparison of some of your options. The "one obvious way" 
line.rstrip("\n").endswith("*") is not included ;)

$ cat starry_table.py 
import re


def show_table(data, header):
rows = [header]
rows.extend([str(c) for c in row] for row in data)
widths = [max(len(row[i]) for row in rows) for i in range(len(header))]
template = "  ".join("{:%d}" % w for w in widths)
for row in rows:
print(template.format(*row))


def compare(sample_lines):
for line in sample_lines:
got_re = bool(re.compile("\*$").search(line))
got_re_M = bool(re.compile("\*$", re.M).search(line))
got_endswith = line.endswith("*")
got_endswith2 = line.endswith(("*", "*\n"))
got_substring = line[-1:] == "*"
try:
got_char = line[-1] == "*"
except IndexError:
got_char = "#exception"
results = (
got_re, got_re_M,
got_endswith, got_endswith2,
got_substring, got_char)
yield (
["", "X"][len(set(results)) > 1],
repr(line)) + results


SAMPLE = ["", "\n", "foo\n", "*\n", "*", "foo*", "foo*\n", "foo*\nbar"]
HEADER = [
"", "line", "regex", "re.M",
"endswith", 'endswith(("*", "*\\n"))',
"substring", "char"]

if __name__ == "__main__":
show_table(compare(SAMPLE), HEADER)


$ python3 starry_table.py 
   line regex  re.M   endswith  endswith(("*", "*\n"))  substring  char 
 
X  ''   False  False  False False   False  
#exception
   '\n' False  False  False False   False  
False 
   'foo\n'  False  False  False False   False  
False 
X  '*\n'True   True   False TrueFalse  
False 
   '*'  True   True   True  TrueTrue   True 
 
   'foo*'   True   True   True  TrueTrue   True 
 
X  'foo*\n' True   True   False TrueFalse  
False 
X  'foo*\nbar'  False  True   False False   False  
False 


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


Re: installer user interface glitch ?

2015-11-03 Thread alister
On Sun, 01 Nov 2015 08:24:22 -0800, rurpy wrote:

> On Sunday, November 1, 2015 at 8:52:55 AM UTC-7, Chris Angelico wrote:
>> On Mon, Nov 2, 2015 at 2:43 AM, rurpy--- via Python-list
>>  wrote:
>> > Why, oh why, do the python.org front page and other pages that offer
>> > a Windows download not say a word about it not running on Windows XP?
>> >
>> > Even if one is anal enough to go to the page about the 3.5 release.
>> >   https://www.python.org/downloads/release/python-350/
>> > a page with a lot of Windows-specific info, there is not a word about
>> > XP.
>> 
>> A partial answer to that is in PEP 11:
>> 
>> https://www.python.org/dev/peps/pep-0011/#microsoft-windows
>> 
>> Windows XP isn't special here. There's no mention of Python 2.7 not
>> working on Windows 95, because it's simply an unsupported operating
>> system. The only reason that people keep coming asking about XP and not
>> (say) Win2K is that there are a lot more XP boxes out there. Do the
>> other download pages need to stipulate which versions of which OSes
>> they support, or should that be left up to the installer?
> 
> I dont recall seeing anyone posting asking why they could not get Python
> to install on Windows 95 recently.  I only read this group
> intermittently but I have seen *many* posts asking why they couldnt
> install on XP.
> 
> You acknowledge yourself: "there are a lot more XP boxes out there."
> 
>> There *is* a plan to have the installer give a better error message for
>> this situation.
> 
> A better message from the installer is necessary but not sufficient.
> Don't make people go through the effort to download the whole thing, do
> their planning and preparations for using or upgrading Python only to
> discover at the last moment it wont work.
> 
> That is really shitty customer relations.
> 
> The reality is that people trying install Python-3.5 on XP *is* a
> problem.  Telling them they should have read some obscure release notes
> is not a solution.
> 
>> But I don't think the web site necessarily has to have noise about old
>> versions of OSes. Where would you draw the line?
> 
> I think my responses above answer that.

I would have to agree, at least in general

1) The web page should always list the Versions of Windows that ARE 
supported.

2) As support for Win XP has only just ceased it should be specifically 
mentioned for V3.5, I would see no need to continue with this for V3.6 +
Likewise Win95 2000 etc. should have been mentioned at the release when 
support was dropped & no further

As adding a "Not supported on Win XP or Win 7 Minimum" notice is such a 
minimal "Bug Fix" I don't see the issue. 



-- 
 _
< U.S. Postal Service >
 -
   \
\
.--.
   |o_o |
   |:_/ |
  //   \ \
 (| | )
/'\_   _/`\
\___)=(___/

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


Re: Detection of a specific sound

2015-11-03 Thread alister
On Mon, 02 Nov 2015 20:49:03 -0700, Michael Torrie wrote:

> On 10/25/2015 06:17 PM, Montana Burr wrote:
>> I'm looking for a library that will allow Python to listen for the
>> shriek of a smoke alarm. Once it detects this shriek, it is to notify
>> someone. Ideally, specificity can be adjusted for the user's
>> environment. For example, I expect to need moderate specificity as I
>> live in a quiet neighborhood, but an apartment dweller might need more.
>> 
>> I'm thinking of recording a smoke alarm and having the program try to
>> find the recorded sound in the stream from the microphone.
>> 
>> Any help is greatly appreciated!
> 
> At this point, from what you say, your problem is not a python one. It's
> a more general problem that you have to tackle.  In other words how are
> you going to identify this one sound amongst background noise?  Once you
> know that, then you can apply Python to the problem.
> 
> I suggest you spend some time exploring how you would actually go about
> recognizing a particular sound algorithmically.  Relevant tops of
> research include: digital signal processing and fourier analysis.
> 
> A quick google search reveals some info that may point you in the right
> direction:
> 
> https://blog.adafruit.com/2015/01/12/think-dsp-introduction-to-signal-
processing-using-python/
> http://samcarcagno.altervista.org/blog/basic-sound-processing-python/
> 
> I know very little about the subject, but if it were me, my naive
> approach would be to do fourier analysis on the sound you are trying to
> identify to pick out the sound's fingerprint (certain component
> waveforms that stand out), and then do the same analysis on your audio
> stream, looking for this footprint.

Personally I would forget trying to analyse sound & see if there is any 
way to get an input signal direct from the alarm (even if that is as 
crude as taking a tap from the siren feed wires) 

This application sounds far to critical for anything else.



-- 
 __
/ "Can't you just gesture hypnotically \
| and make him disappear?" |
|  |
| "It does not work that way. RUN!" -- |
| Hadji on metaphyics and Mandrake in  |
\ "Johnny Quest"   /
 --
   \
\
.--.
   |o_o |
   |:_/ |
  //   \ \
 (| | )
/'\_   _/`\
\___)=(___/

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


Re: Regular expressions

2015-11-03 Thread Nick Sarbicki
On Tue, Nov 3, 2015 at 7:15 AM, Steven D'Aprano  wrote:

> On Tue, 3 Nov 2015 03:23 pm, ru...@yahoo.com wrote:
>
> > Regular expressions should be learned by every programmer or by anyone
> > who wants to use computers as a tool.  They are a fundamental part of
> > computer science and are used in all sorts of matching and searching
> > from compilers down to your work-a-day text editor.
>
> You are absolutely right.
>
> If only regular expressions weren't such an overly-terse, cryptic
> mini-language, with all but no debugging capabilities, they would be great.
>
> If only there wasn't an extensive culture of regular expression abuse
> within
> programming communities, they would be fine.
>
> All technologies are open to abuse. But we don't say:
>
>   Some people, when confronted with a problem, think "I know, I'll use
>   arithmetic." Now they have two problems.
>
> because abuse of arithmetic is rare. It's hard to misuse it, and while
> arithmetic can be complicated, it's rare for programmers to abuse it. But
> the same cannot be said for regexes -- they are regularly misused, abused,
> and down-right hard to use right even when you have a good reason for using
> them:
>
> http://www.thedailywtf.com/articles/Irregular_Expression
>
> http://blog.codinghorror.com/regex-use-vs-regex-abuse/
>
>
> http://psung.blogspot.com.au/2008/01/wonderful-abuse-of-regular-expressions.html
>
>
> If there is one person who has done more to create a regex culture, it is
> Larry Wall, inventor of Perl. Even Larry Wall says that regexes are
> overused and their syntax is harmful, and he has recreated them for Perl 6:
>
> http://www.perl.com/pub/2002/06/04/apo5.html
>
> Oh, and the icing on the cake, regexes can be a security vulnerability too:
>
>
> https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


+1

I agree that regex is an entirely necessary part of a programmers toolkit,
but dear god some people need to be taught restraint. The majority of
people I talk about regex to have no idea when and where it shouldn't be
used.

As an example part of my job is bringing our legacy Python code into the
modern day, and one of the largest roadblocks is the amount of regex used.

Some is necessary.

Some can be replaced by an `if word in str` or something similarly basic.

Some spans hundreds of lines and causes acute alopecia.

Just yesterday I found a colleague trying to parse HTML with regex.

So yes, teach regex, but teach it after the basics, and please emphasise
when it is appropriate to use it.

Yes I am bitter.

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