Re: subprocess startup error

2016-02-27 Thread Terry Reedy

On 2/26/2016 9:49 AM, Oscar Benjamin wrote:

On 26 February 2016 at 13:30, Peter Otten <__pete...@web.de> wrote:

Shweta Dinnimani wrote:


hello, I'm begineer to python programming.. I had installed python 3.5.1
version on my windows 7 system. I was fine earlier and now when i was
trying the programs on string i'm facing the subprocess startup error.
IDLE is not connecting. And python shell is also not opening. I tried
uninstalling and installing the python shell but Im facing the
problem.Please do help me


What do you mean by 'python shell' and how do you uninstall and install it?


forgot to mention..

i saved my file as string.py since than i'm facing this error


Rename that file to something that does not clash with the module names in
the standard library, mystring.py for example, and IDLE should work again.


It's ridiculous that it's this easy to accidentally crash IDLE and the
Python shell.


I agree and hope to fix this for IDLE before the next round of releases. 
Any Python app that does *not* want to import non-stdlib files on 
startup must remove '' from sys.path.  Console python should not be 
affected by files in the current working directory.


--
Terry Jan Reedy

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


Re: subprocess startup error

2016-02-27 Thread Terry Reedy

On 2/26/2016 10:08 AM, Wolfgang Maier wrote:

On 26.02.2016 15:57, Emile van Sebille wrote:

On 2/26/2016 6:49 AM, Oscar Benjamin wrote:

On 26 February 2016 at 13:30, Peter Otten <__pete...@web.de> wrote:

Shweta Dinnimani wrote:

i saved my file as string.py since than i'm facing this error


Rename that file to something that does not clash with the module
names in
the standard library, mystring.py for example, and IDLE should work
again.


It's ridiculous that it's this easy to accidentally crash IDLE and the
Python shell.


I don't think there's a way to protect against it -- how could you work
on string.py otherwise?



Emitting a warning message in such situations is being discussed in
http://bugs.python.org/issue23809 though it is not a very lively
discussion.


This is a separate issue of user code importing a user's own file 
instead of an stdlib file.



--
Terry Jan Reedy

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


Re: Bug in Python?

2016-02-27 Thread Terry Reedy

On 2/26/2016 6:07 PM, eryk sun wrote:

  On Fri, Feb 26, 2016 at 4:08 PM, Sven R. Kunze  wrote:

Python sometimes seems not to hop back and forth between C and Python code.
Can somebody explain this?


Normally a C extension would call PySequence_SetItem, which would call
the type's sq_ass_item, which for MyList is slot_sq_ass_item. The
latter function bridges the CPython and Python sides by binding and
calling the overridden __setitem__ method.  However, the _heapq
extension module uses `PyList_SET_ITEM(heap, 0, lastelt)`. This macro
expands to `((PyListObject *)(heap))->ob_item[0] = lastelt`. This
directly modifies the internal ob_item array of the list, so the
overridden __setitem__ method is never called. I presume it was
implemented like this with performance in mind, but I don't know
whether or not that justifies the loss of generality.


In other words, when that doc says *list*, it means a *list*.

"To create a heap, use a list initialized to [], or you can transform a 
populated list into a heap via function heapify()."


Note: when the doc says 'dict' rather than 'dictionary' or 'mapping', it 
is pretty obvious it means builtin dict.  It may sometimes say 'dict or 
dict subclass'.  Ditto for 'str' versus 'string' or 'text'.  However, 
'list' (Python builtin) and generic 'list are easy to confuse.  In this 
case, 'initialized to []' is a hint.  However, the doc could be made 
clearer. How about


"A heap must be an instance of *list* (and not a subclass thereof).  To 
create a heap, start with [] or transform an existing list into a heap 
via function heapify()."


*list* means to display it blue, linked to the list class.


--
Terry Jan Reedy

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


{off topic] Re: Bug in Python?

2016-02-27 Thread Terry Reedy

On 2/26/2016 9:21 PM, mentific...@gmail.com wrote:

On Friday, February 26, 2016 at 2:09:07 PM UTC-8, Sven R. Kunze wrote:

Hi everybody,

I recognized the following oddity (background story:
http://srkunze.blogspot.com/2016/02/lets-go-down-rabbit-hole.html).

Python sometimes seems not to hop back and forth between C and Python code.
[...]


http://srkunze.blogspot.com/2016/02/lets-go-down-rabbit-hole.html ?

If there are too many bugs in Python,


As it turns out, there was no bug, just a misunderstanding of heapq and 
its doc.



you could switch to Perl (Perl6 just came out :-)
especially for artificial intelligence (Strong AI)
and for webservers running a "Ghost" AI Mind. See

http://www.sourcecodeonline.com/details/ghost_perl_webserver_strong_ai.html

or you could use "AI Steps" to code Strong AI in Python.

Arthur


For those who don't know, Arthur has be working on and promoting on his 
'AI Mind' project for at least a decade, probably more.  AFAIK, it has 
been a few years since his last off-topic response like this.  Arthur, 
please promote you once-Forth, now Perl project elsewhere.  Everyone 
else, please don't respond further on python-list.


--
Terry Jan Reedy

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


Re: The Real-Time Use of Python in Data Science World!

2016-02-27 Thread Steven D'Aprano
On Sat, 27 Feb 2016 06:47 am, Joel Goldstick wrote:

> On Fri, Feb 26, 2016 at 2:35 PM, Anita Goyal 
> wrote:
> 
>> This course will help you to expertise the usage of Python in Data
>> Science world.
[...]

> Second post by this person.  Both advertising classes for a fee.  Is this
> proper posting?  I tend to think it is spam


That's a tricky one. It's on-topic and reasonable honest (no obfuscated
text, and although they don't explicitly state there is a fee it should be
obvious that most courses that aren't labelled as free do cost money). It
is advertising, but advertising isn't necessarily evil. And it's being sent
to a public list, rather than spammed out to millions of individual email
addresses.

I think it's in a grey area, but so long as the sender doesn't abuse the
privilege by flooding the group with advertising, it falls just slightly on
the "acceptable" side of the line. But I wouldn't be surprised if some
people disagree. I think it would be more acceptable to me if the sender
labelled the subject line as "Advertising".



-- 
Steven

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


Redmonk popularity rankings place Python at #4

2016-02-27 Thread Steven D'Aprano
The latest popularity rankings from Redmonk are available, based on the
number of projects on Github and posts on Stackoverflow, and Python comes
in at #4, just behind Javascript, Java and PHP, and just ahead of C#, C++
and Ruby.

http://redmonk.com/sogrady/2016/02/19/language-rankings-1-16/



-- 
Steven

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


Error in Tree Structure

2016-02-27 Thread subhabangalore
I was trying to implement the code, 

import nltk
import nltk.tag, nltk.chunk, itertools
def ieertree2conlltags(tree, tag=nltk.tag.pos_tag):
words, ents = zip(*tree.pos())
iobs = []
prev = None
for ent in ents:
if ent == tree.node:
iobs.append('O')
prev = None
elif prev == ent:
 iobs.append('I-%s' % ent)
else:
 iobs.append('B-%s' % ent)
 prev = ent
words, tags = zip(*tag(words))
return itertools.izip(words, tags, iobs)

def ieer_chunked_sents(tag=nltk.tag.pos_tag):
for doc in ieer.parsed_docs():
tagged = ieertree2conlltags(doc.text, tag)
yield nltk.chunk.conlltags2tree(tagged)


from chunkers import ieer_chunked_sents, ClassifierChunker
from nltk.corpus import treebank_chunk
ieer_chunks = list(ieer_chunked_sents())
chunker = ClassifierChunker(ieer_chunks[:80])
print chunker.parse(treebank_chunk.tagged_sents()[0])
score = chunker.evaluate(ieer_chunks[80:])
print score.accuracy()

It is running fine. 
But as I am trying to rewrite the code as,
chunker = ClassifierChunker(list1),
where list1 is same value as,
ieer_chunks[:80]
only I am pasting the value as 
[Tree('S', [Tree('LOCATION', [(u'NAIROBI', 'NNP')]), (u',', ','), 
Tree('LOCATION', [(u'Kenya', 'NNP')]), (u'(', '('), Tree('ORGANIZATION', 
[(u'AP', 'NNP')]), (u')', ')'), (u'_', 'NNP'), Tree('CARDINAL', [(u'Thousands', 
'NNP')]), (u'of', 'IN'), (u'laborers,', 'JJ'), (u'students', 'NNS'), (u'and', 
'CC'), (u'opposition', 'NN'), (u'politicians', 'NNS'), (u'on', 'IN'), 
Tree('DATE', [(u'Saturday', 'NNP')]), (u'protested', 'VBD'), (u'tax', 'NN'), 
(u'hikes', 'NNS'), (u'imposed', 'VBN'), (u'by', 'IN'), (u'their', 'PRP$'), 
(u'cash-strapped', 'JJ'), (u'government,', 'NN'), (u'which', 'WDT'), (u'they', 
'PRP'), (u'accused', 'VBD'), (u'of', 'IN'), (u'failing', 'VBG'), (u'to', 'TO'), 
(u'provide', 'VB'), (u'basic', 'JJ'), (u'services.', 'NN'),(u'(cm-kjd)', 
'NN')])]
the value of whole list directly I am getting syntax error.
I tried to paste it in Python IDE outside code there also it is giving syntax 
error. 
If I do not paste the value and and rename ieer_chunks[:80] as list1 there is 
no error.
I may be doing some problem while copying the value and pasting it. 
But I did not change anything there.

Is it any error in Python part or in NLTK part? 

Thanks in advance.
If any one may guide me what is the error I am doing and how may I solve it.


 

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


Lookahead while doing: for line in fh.readlines():

2016-02-27 Thread Veek. M
I want to do something like:

#!/usr/bin/env python3

fh = open('/etc/motd')
for line in fh.readlines():
print(fh.tell())

why doesn't this work as expected.. fh.readlines() should return a 
generator object and fh.tell() ought to start at 0 first.

Instead i get the final count repeated for the number of lines.

What i'm trying to do is lookahead:
#!whatever

fh = open(whatever)
for line in fh.readlines():
x = fh.tell()
temp = fh.readline()
fh.seek(x)

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


[Off-topic] Requests author discusses MentalHealthError exception

2016-02-27 Thread Steven D'Aprano
The author of Requests, Kenneth Reitz, discusses his recent recovery from a
MentalHealthError exception.

http://www.kennethreitz.org/essays/mentalhealtherror-an-exception-occurred

Although the connection to Python is only quite slim, I found it fascinating
to read.



-- 
Steven

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


Re: Bug in Python?

2016-02-27 Thread Steven D'Aprano
On Sat, 27 Feb 2016 07:55 pm, Terry Reedy wrote:

> In other words, when that doc says *list*, it means a *list*.
> 
> "To create a heap, use a list initialized to [], or you can transform a
> populated list into a heap via function heapify()."
[...]
> "A heap must be an instance of *list* (and not a subclass thereof).  To
> create a heap, start with [] or transform an existing list into a heap
> via function heapify()."

I think that's a sad decision. heapq ought to be able to handle any list
subclass, not just actual lists. Preferably it ought to handle duck-typed
lists too, anything with a list-like interface. It is okay if the optimized
C version only works with actual lists, and falls back to a slower Python
version for anything else.



-- 
Steven

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


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Steven D'Aprano
On Thu, 25 Feb 2016 06:30 pm, Chris Angelico wrote:

> On Thu, Feb 25, 2016 at 5:50 PM, Steven D'Aprano
>  wrote:
>>
>> # Read a chunk of bytes/characters from an open file.
>> def chunkiter(f, delim):
>> buffer = []
>> b = f.read(1)
>> while b:
>> buffer.append(b)
>> if b in delim:
>> yield ''.join(buffer)
>> buffer = []
>> b = f.read(1)
>> if buffer:
>> yield ''.join(buffer)
> 
> How bad is it if you over-read? 

Pretty bad :-)

Ideally, I'd rather not over-read at all. I'd like the user to be able to
swap from "read N bytes" to "read to the next delimiter" (and possibly
even "read the next line") without losing anything.


If there's absolutely no other way to speed this up by at least a factor of
ten, I'll consider reading into a buffer and losing the ability to mix
different kinds of reads.




-- 
Steven

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


Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-02-27 Thread Mark Lawrence

On 27/02/2016 09:37, Steven D'Aprano wrote:

The author of Requests, Kenneth Reitz, discusses his recent recovery from a
MentalHealthError exception.

http://www.kennethreitz.org/essays/mentalhealtherror-an-exception-occurred

Although the connection to Python is only quite slim, I found it fascinating
to read.



Thanks for the link even if it did touch an extremely raw nerve.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Steven D'Aprano
On Thu, 25 Feb 2016 06:37 pm, Wolfgang Maier wrote:

> On 25.02.2016 07:50, Steven D'Aprano wrote:
>> I have a need to read to an arbitrary delimiter, which might be any of a
>> (small) set of characters. For the sake of the exercise, lets say it is
>> either ! or ? (for example).
>>
> 
> You are not alone with your need.
> 
> http://bugs.python.org/issue1152248 discusses the problem and has some
> code snippets that you may be interested in. While there is no trivial
> solution there are certainly faster ways than your first attempt.

Wow. Ten years and still no solution :-(

Thanks for finding the issue, but the solutions given don't suit my use
case. I don't want an iterator that operates on pre-read blocks, I want
something that will read a record from a file, and leave the file pointer
one entry past the end of the record.

Oh, and records are likely fairly short, but there may be a lot of them.


-- 
Steven

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


Everything good about Python except GUI IDE?

2016-02-27 Thread wrong . address . 1
I have some VB forms with more than a hundred objects. If I cannot drag and 
drop text boxes, list boxes, labels, etc., it will be too much work to create 
that with several lines of code for each object. 

Isn't there any good GUI IDE like Visual Basic? I hope there are some less well 
known GUI IDEs which I did not come across. Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error in Tree Structure

2016-02-27 Thread Steven D'Aprano
On Sat, 27 Feb 2016 08:17 pm, subhabangal...@gmail.com wrote:

> Is it any error in Python part or in NLTK part?

Neither.

Any time you think there is an error in Python, it is 99.9% sure that the
error is in your code, not Python.

If the error is a SyntaxError, that is 99.9%.

> If any one may guide me what is the error I am doing and how may I solve
> it.

Look at the SyntaxError traceback and read what it says. Does it tell you
what the error is? Does it use a ^ as an arrow to point to the error, or
immediately after the error?

Chances are, the error is that you have added or deleted a bracket or
parenthesis somewhere. Dealing with nested lists like this is usually
awful, because they are unreadable. Can you avoid copying and pasting the
nested list?

If not, try re-formatting it so you can at least read it:

# Unreadable, bad:
thelist = [Tree('S', [Tree('LOCATION', [(u'NAIROBI', 'NNP')]), (u',', ','),
Tree('LOCATION', [(u'Kenya', 'NNP')]), (u'(', '('), Tree('ORGANIZATION',
[(u'AP', 'NNP')]), (u')', ')'), (u'_', 'NNP'), Tree('CARDINAL',
[(u'Thousands', 'NNP')]), (u'of', 'IN'), (u'laborers,', 'JJ'),
(u'students', 'NNS'), (u'and', 'CC'), (u'opposition', 'NN'),
(u'politicians', 'NNS'), (u'on', 'IN'), Tree('DATE',
[(u'Saturday', 'NNP')]), (u'protested', 'VBD'), (u'tax', 'NN'),
(u'hikes', 'NNS'), (u'imposed', 'VBN'), (u'by', 'IN'), (u'their', 'PRP$'),
(u'cash-strapped', 'JJ'), (u'government,', 'NN'), (u'which', 'WDT'),
(u'they', 'PRP'), (u'accused', 'VBD'), (u'of', 'IN'), (u'failing', 'VBG'),
(u'to', 'TO'), (u'provide', 'VB'), (u'basic', 'JJ'), (u'services.', 'NN'),
(u'(cm-kjd)', 'NN')])]


# Slightly more readable, good:
thelist = [
  Tree('S', [
Tree(
'LOCATION', [
(u'NAIROBI', 'NNP')
]
), 
(u',', ','), 
Tree(
'LOCATION', [
(u'Kenya', 'NNP')
]
), 
(u'(', '('), 
Tree(
'ORGANIZATION', [
(u'AP', 'NNP')
]
   ),
(u')', ')'), 
(u'_', 'NNP'), 
Tree(
'CARDINAL', [
(u'Thousands', 'NNP')
]
), 
(u'of', 'IN'), 
(u'laborers,', 'JJ'), 
(u'students', 'NNS'), 
(u'and', 'CC'), 
(u'opposition', 'NN'), 
(u'politicians', 'NNS'), 
(u'on', 'IN'), 
Tree(
'DATE', [
(u'Saturday', 'NNP')
]
), 
(u'protested', 'VBD'), 
(u'tax', 'NN'), 
(u'hikes', 'NNS'), 
(u'imposed', 'VBN'), 
(u'by', 'IN'), 
(u'their', 'PRP$'), 
(u'cash-strapped', 'JJ'), 
(u'government,', 'NN'), 
(u'which', 'WDT'), 
(u'they', 'PRP'), 
(u'accused', 'VBD'), 
(u'of', 'IN'), 
(u'failing', 'VBG'), 
(u'to', 'TO'), 
(u'provide', 'VB'), 
(u'basic', 'JJ'), 
(u'services.', 'NN'), 
(u'(cm-kjd)', 'NN')
]
  )   
  ]



If you format your giant list so you can see the structure, then you will
likely find where there is a problem. Perhaps you have:

- missing or too many [ ( ) or ]

- a missing or extra comma

- a missing or extra quotation marks

- unexpected symbols like  inside the list




-- 
Steven

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Steven D'Aprano
On Sat, 27 Feb 2016 10:18 pm, wrong.addres...@gmail.com wrote:

> I have some VB forms with more than a hundred objects.


https://www.appnovation.com/sites/default/files/attachments/yourproduct.jpg

Your users probably hate you... 

*wink*



-- 
Steven

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


Re: Lookahead while doing: for line in fh.readlines():

2016-02-27 Thread Terry Reedy

On 2/27/2016 4:39 AM, Veek. M wrote:

I want to do something like:

#!/usr/bin/env python3

fh = open('/etc/motd')
for line in fh.readlines():
 print(fh.tell())

why doesn't this work as expected.. fh.readlines() should return a
generator object and fh.tell() ought to start at 0 first.


Not after you have already read some data.  Readlines() reads the entire 
file and splits it into lines.  readline reads at least a single block. 
 Reading a single byte or character at a time looking for /n would be 
too slow, so even after readline, the file pointer will be somewhere 
past the end of the last line returned.



Instead i get the final count repeated for the number of lines.

What i'm trying to do is lookahead:
#!whatever

fh = open(whatever)
for line in fh.readlines():
 x = fh.tell()
 temp = fh.readline()
 fh.seek(x)




--
Terry Jan Reedy

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


Re: Bug in Python?

2016-02-27 Thread Terry Reedy

On 2/27/2016 4:44 AM, Steven D'Aprano wrote:

On Sat, 27 Feb 2016 07:55 pm, Terry Reedy wrote:


In other words, when that doc says *list*, it means a *list*.

"To create a heap, use a list initialized to [], or you can transform a
populated list into a heap via function heapify()."

[...]

"A heap must be an instance of *list* (and not a subclass thereof).  To
create a heap, start with [] or transform an existing list into a heap
via function heapify()."


I think that's a sad decision. heapq ought to be able to handle any list
subclass, not just actual lists. Preferably it ought to handle duck-typed
lists too, anything with a list-like interface. It is okay if the optimized
C version only works with actual lists, and falls back to a slower Python
version for anything else.


Propose that on the tracker, after checking previous issues.

--
Terry Jan Reedy

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Rustom Mody
On Saturday, February 27, 2016 at 4:49:21 PM UTC+5:30, wrong.a...@gmail.com 
wrote:
> I have some VB forms with more than a hundred objects. If I cannot drag and 
> drop text boxes, list boxes, labels, etc., it will be too much work to create 
> that with several lines of code for each object. 
> 
> Isn't there any good GUI IDE like Visual Basic? I hope there are some less 
> well known GUI IDEs which I did not come across. Thanks.

Good... I do not know [Do not know much of the area]

However there is glade, qtdesigner, wxglade for gtk, qt and wx.

How full-featured/bug-free etc I cannot say.

If you find that they just dont match up to what windows has on offer, I 
wont be surprised :-(
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Chris Angelico
On Sat, Feb 27, 2016 at 10:18 PM,   wrote:
> I have some VB forms with more than a hundred objects. If I cannot drag and 
> drop text boxes, list boxes, labels, etc., it will be too much work to create 
> that with several lines of code for each object.
>
> Isn't there any good GUI IDE like Visual Basic? I hope there are some less 
> well known GUI IDEs which I did not come across. Thanks.

Sounds like the advantage lies with Python here...

Don't make a UI by dragging and dropping that many widgets.

If it takes "several lines of code" for each object, it might be worth
creating a utility function. For example, a database form might
include a good number of fields with associated labels; you could
create a function that creates (in a single line) a label and its
input field. Or create a list and iterate over it, creating all the
widgets as you step through the loop. That's the advantage of code -
you can't easily create reusable 'clumps' with a drag-and-drop
builder, but in code, it's the exact same thing as any other form of
code reuse.

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


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Chris Angelico
On Sat, Feb 27, 2016 at 8:49 PM, Steven D'Aprano  wrote:
> On Thu, 25 Feb 2016 06:30 pm, Chris Angelico wrote:
>
>> On Thu, Feb 25, 2016 at 5:50 PM, Steven D'Aprano
>>  wrote:
>>>
>>> # Read a chunk of bytes/characters from an open file.
>>> def chunkiter(f, delim):
>>> buffer = []
>>> b = f.read(1)
>>> while b:
>>> buffer.append(b)
>>> if b in delim:
>>> yield ''.join(buffer)
>>> buffer = []
>>> b = f.read(1)
>>> if buffer:
>>> yield ''.join(buffer)
>>
>> How bad is it if you over-read?
>
> Pretty bad :-)
>
> Ideally, I'd rather not over-read at all. I'd like the user to be able to
> swap from "read N bytes" to "read to the next delimiter" (and possibly
> even "read the next line") without losing anything.

If those are the *only* two operations, you should be able to maintain
your own buffer. Something like this:

class ChunkIter:
def __init__(self, f, delim):
self.f = f
self.delim = re.compile("["+delim+"]")
self.buffer = ""
def read_to_delim(self):
"""Return characters up to the next delim, or remaining chars,
or "" if at EOF"""
while "delimiter not found":
*parts, self.buffer = self.delim.split(self.buffer, 1)
if parts: return parts[0]
b = self.f.read(256)
if not b: return self.buffer
self.buffer += b
def read(self, nbytes):
need = nbytes - len(self.buffer)
if need > 0: self.buffer += self.f.read(need)
ret, self.buffer = self.buffer[:need], self.buffer[need:]
return ret

It still might over-read from the underlying file, but those extra
chars will be available to the read(N) function.

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


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Chris Angelico
On Sat, Feb 27, 2016 at 11:17 PM, Chris Angelico  wrote:
>> Ideally, I'd rather not over-read at all. I'd like the user to be able to
>> swap from "read N bytes" to "read to the next delimiter" (and possibly
>> even "read the next line") without losing anything.
>
> If those are the *only* two operations, you should be able to maintain
> your own buffer.

And, I started out by thinking "to next delimiter" and "next line"
were the same thing with different delimiters, but then went and coded
the delimiter so that wouldn't work. Whatevs. If those are the only
*three* operations, the same class with one more method could do it.

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread BartC

On 27/02/2016 11:18, wrong.addres...@gmail.com wrote:

I have some VB forms with more than a hundred objects. If I cannot drag and 
drop text boxes, list boxes, labels, etc., it will be too much work to create 
that with several lines of code for each object.

Isn't there any good GUI IDE like Visual Basic? I hope there are some less well 
known GUI IDEs which I did not come across. Thanks.


All the dialog boxes I've ever created (if that's what you mean by 
forms), have been done by writing code. Never with drag and drop.


Provided you know what to write in those few lines (which would be the 
stumbling block for me), then a few hundred lines of script code isn't a 
lot. And Python is a scripting language.


And once one form or part of one is done, you might able to just copy 
and adapt the code instead of having to write everything from scratch.


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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread MWS



On Saturday 27 February 2016 04:48 PM, wrong.addres...@gmail.com wrote:

I have some VB forms with more than a hundred objects. If I cannot drag and 
drop text boxes, list boxes, labels, etc., it will be too much work to create 
that with several lines of code for each object.

Isn't there any good GUI IDE like Visual Basic? I hope there are some less well 
known GUI IDEs which I did not come across. Thanks.

Hello,

I too faced such a problem, being familiar with basic i too found it 
difficult to transition from designer to text only, but i found the 
solution, i.e. qt, try pyqt, for desigining try qt creator, i don't know 
if qt designer is still installable but qt creator is. you can easily 
design your forms and generate python code and then integrate them with 
your program. a little commandline stuff, but you can always batch it up.


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


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Dan Sommers
On Sat, 27 Feb 2016 21:40:17 +1100, Steven D'Aprano wrote:

> Thanks for finding the issue, but the solutions given don't suit my
> use case. I don't want an iterator that operates on pre-read blocks, I
> want something that will read a record from a file, and leave the file
> pointer one entry past the end of the record.

A file is a stream of bytes, but you want to view it as a stream of
records.  It sounds like you want an abstraction layer, and it sounds
like you also want to let the file leak through that layer when it's
convenient.  (Yes, I spun that horribly on purpose, and I understand the
use case of imposing some structure on part of a file, and possibly a
different structure on a different part of a file.  MIME messages and
literate programming files spring to mind.)

Perhaps (as I think ChrisA suggested), you could provide your own
buffering/chunking layer between your application and the file itself,
and never let the application see the file directly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Serhiy Storchaka

On 27.02.16 11:49, Steven D'Aprano wrote:

On Thu, 25 Feb 2016 06:30 pm, Chris Angelico wrote:

How bad is it if you over-read?


Pretty bad :-)

Ideally, I'd rather not over-read at all. I'd like the user to be able to
swap from "read N bytes" to "read to the next delimiter" (and possibly
even "read the next line") without losing anything.


If there's absolutely no other way to speed this up by at least a factor of
ten, I'll consider reading into a buffer and losing the ability to mix
different kinds of reads.


If the file is buffered, you can use Chris's receipt, but with peek(). 
Otherwise you should fall back to slow one-byte read.


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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Dietmar Schwertberger

On 27.02.2016 12:18, wrong.addres...@gmail.com wrote:

Isn't there any good GUI IDE like Visual Basic? I hope there are some less well 
known GUI IDEs which I did not come across. Thanks.


As of today, there's no Python GUI builder comparable to VB 6.

There are some like QtDesigner or wxGlade, but they either don't 
generate Python code directly or they can only be used if you know the 
underlying toolkit good enough to create the GUI yourself. You may try 
out some, but I can almost guarantee you that you will come to the same 
result.

If you want a GUI, create it yourself using either wxPython or PyQt.

For engineering applications that's probably the weakest point that 
Python has.

It's holding back a lot of people...

Well, for most measurement or control software a GUI is not really 
needed, but still people want it.



Regards,

Dietmar

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


Re: Error in Tree Structure

2016-02-27 Thread Rustom Mody
On Saturday, February 27, 2016 at 2:47:53 PM UTC+5:30, subhaba...@gmail.com 
wrote:
> I was trying to implement the code, 
> 
> import nltk
> import nltk.tag, nltk.chunk, itertools
> def ieertree2conlltags(tree, tag=nltk.tag.pos_tag):
> words, ents = zip(*tree.pos())
> iobs = []
> prev = None
> for ent in ents:
> if ent == tree.node:
> iobs.append('O')
> prev = None
> elif prev == ent:
>  iobs.append('I-%s' % ent)
> else:
>  iobs.append('B-%s' % ent)
>  prev = ent
> words, tags = zip(*tag(words))
> return itertools.izip(words, tags, iobs)
> 
> def ieer_chunked_sents(tag=nltk.tag.pos_tag):
> for doc in ieer.parsed_docs():
> tagged = ieertree2conlltags(doc.text, tag)
> yield nltk.chunk.conlltags2tree(tagged)
> 
> 
> from chunkers import ieer_chunked_sents, ClassifierChunker
> from nltk.corpus import treebank_chunk
> ieer_chunks = list(ieer_chunked_sents())
> chunker = ClassifierChunker(ieer_chunks[:80])
> print chunker.parse(treebank_chunk.tagged_sents()[0])
> score = chunker.evaluate(ieer_chunks[80:])
> print score.accuracy()
> 
> It is running fine. 
> But as I am trying to rewrite the code as,
> chunker = ClassifierChunker(list1),
> where list1 is same value as,
> ieer_chunks[:80]
> only I am pasting the value as 
> [Tree('S', [Tree('LOCATION', [(u'NAIROBI', 'NNP')]), (u',', ','), 
> Tree('LOCATION', [(u'Kenya', 'NNP')]), (u'(', '('), Tree('ORGANIZATION', 
> [(u'AP', 'NNP')]), (u')', ')'), (u'_', 'NNP'), Tree('CARDINAL', 
> [(u'Thousands', 'NNP')]), (u'of', 'IN'), (u'laborers,', 'JJ'), (u'students', 
> 'NNS'), (u'and', 'CC'), (u'opposition', 'NN'), (u'politicians', 'NNS'), 
> (u'on', 'IN'), Tree('DATE', [(u'Saturday', 'NNP')]), (u'protested', 'VBD'), 
> (u'tax', 'NN'), (u'hikes', 'NNS'), (u'imposed', 'VBN'), (u'by', 'IN'), 
> (u'their', 'PRP$'), (u'cash-strapped', 'JJ'), (u'government,', 'NN'), 
> (u'which', 'WDT'), (u'they', 'PRP'), (u'accused', 'VBD'), (u'of', 'IN'), 
> (u'failing', 'VBG'), (u'to', 'TO'), (u'provide', 'VB'), (u'basic', 'JJ'), 
> (u'services.', 'NN'),(u'(cm-kjd)', 'NN')])]
> the value of whole list directly I am getting syntax error.

Dunno how literally you intend this but there is a "" near the end 
of the list. Intended?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove the line numbers from the file in python

2016-02-27 Thread Ganesh Pal
Thanks it works fine :)


On Fri, Feb 26, 2016 at 5:01 PM, Peter Heitzer
 wrote:
> Ganesh Pal  wrote:
>>what would be the easiest way to remove the lines in the leading
>>numbers 1.e 1 ,2, 19  from this file  using python ?
> import sys,re
> for line in sys.stdin:
> print re.sub('^\d+','',line).rstrip()
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread BartC

On 25/02/2016 06:50, Steven D'Aprano wrote:

I have a need to read to an arbitrary delimiter, which might be any of a
(small) set of characters. For the sake of the exercise, lets say it is
either ! or ? (for example).




# Read a chunk of bytes/characters from an open file.
def chunkiter(f, delim):
 buffer = []
 b = f.read(1)
 while b:
 buffer.append(b)
 if b in delim:
 yield ''.join(buffer)
 buffer = []
 b = f.read(1)
 if buffer:
 yield ''.join(buffer)


At first sight, it's not surprising it's slow when you throw in 
generators and whatnot in there.


However those aren't the main reasons for the poor speed. The limiting 
factor here is reading one byte at a time. Just a loop like this:


   while f.read(1):
  pass

without doing anything else, seems to take most of the time. (3.6 
seconds, compared with 5.6 seconds of your readchunks() on a 6MB version 
of your test file, on Python 2.7. readlines() took about 0.2 seconds.)


Any faster solutions would need to read more than one byte at a time.

(This bottleneck occurs in C too if you try and do read a file using 
only fgetc(), compared with any buffered solutions.)


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


list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Ganesh Pal
Iam on python 2.6 and Linux , I need  input on the below program ,
here is the spinet of my program


filename='/tmp2/2.txt'

def check_file():
"""
 Run the command parallel on all the machines , if there is a
file named /tmp/file2.txt  extract file2.txt

"""
global filename
baddr = ''
cmd = ("run_al_paral 'ls -al %s'" % (filename))
print(cmd)
stdout, stderr, exitcode = run(cmd)
print(stdout)
lines = stdout.strip().split('\n')
print(lines)
for line in lines:
if 'exited' in lines:
continue

file = lines[0].split()[9][6:]
break
print file
return file

def main():
functions = [check_file]
for func in functions:
try:
func()
except Exception as e:
return False
if __name__ == '__main__':
  main()



1.If the file is present in any one of the machine the program works
fine , example if the file is in machine4 it works fine,


machine-4# touch /tmp2/2.txt
machine-4# python c_4.py
run_al_parall 'ls -al /tmp2/2.txt'
machine-4: -rw-r--r-- 1 root  wheel  0 Feb 27 08:15 /tmp2/2.txt
gpal-machine-2 exited with status 1
gpal-machine-5 exited with status 1
gpal-machine-3 exited with status 1
gpal-machine-1 exited with status 1

['machine-4: -rw-r--r-- 1 root  wheel  0 Feb 27 08:15 /tmp2/2.txt',
'gpal-machine-2 exited with status 1', 'gpal-machine-5 exited with
status 1', 'gpal-machine-3 exited with status 1', 'gpal-machine-1
exited with status 1']
2.txt


2. But if the file is not present we get index out of range error , do
we need to fix this or its expected ? or its ok.

machine-4# python c_4.py
isi_for_array 'ls -al /tmp2/2.txt'
machine-2 exited with status 1
machine-1 exited with status 1
machine-4 exited with status 1
machine-5 exited with status 1
machine-3 exited with status 1

['machine-2 exited with status 1', 'machine-1 exited with status 1',
'machine-4 exited with status 1', 'machine-5 exited with status 1',
'machine-3 exited with status 1']
ERROR:root:list index out of range

3. Any other tips to improve the program

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


Re: list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Ganesh Pal
changed baddr="" to file ="" in the example program , sorry for the typo

> filename='/tmp2/2.txt'
>
> def check_file():
> """
>  Run the command parallel on all the machines , if there is a
> file named /tmp/file2.txt  extract file2.txt
>
> """
> global filename
> file = ''
> cmd = ("run_al_paral 'ls -al %s'" % (filename))
> print(cmd)
> stdout, stderr, exitcode = run(cmd)
> print(stdout)
> lines = stdout.strip().split('\n')
> print(lines)
> for line in lines:
> if 'exited' in lines:
> continue
>
> file = lines[0].split()[9][6:]
> break
> print file
> return file
>
> def main():
> functions = [check_file]
> for func in functions:
> try:
> func()
> except Exception as e:
> return False
> if __name__ == '__main__':
>   main()
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Joel Goldstick
On Sat, Feb 27, 2016 at 12:01 PM, Ganesh Pal  wrote:

> changed baddr="" to file ="" in the example program , sorry for the typo
>
> > filename='/tmp2/2.txt'
> >
> > def check_file():
>

don't use global filename.  just pass filename into check_file
def check_file(filename):

> > """
> >  Run the command parallel on all the machines , if there is a
> > file named /tmp/file2.txt  extract file2.txt
> >
> > """
> > global filename
> > file = ''
> > cmd = ("run_al_paral 'ls -al %s'" % (filename))
> > print(cmd)
> > stdout, stderr, exitcode = run(cmd)
>
what is run(...)

> > print(stdout)
> > lines = stdout.strip().split('\n')
> > print(lines)
> > for line in lines:
> > if 'exited' in lines:
> > continue
> >
> > file = lines[0].split()[9][6:]
> > break
> > print file
> > return file
> >
> > def main():
> > functions = [check_file]
> > for func in functions:
> > try:
> > func()
> > except Exception as e:
>
not a good idea to have catchall exception

> > return False
> > if __name__ == '__main__':
> >   main()
> >
> --
>
copy and paste your traceback

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



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


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Marko Rauhamaa
Dennis Lee Bieber :

> On Sat, 27 Feb 2016 21:40:17 +1100, Steven D'Aprano 
> declaimed the following:
>>Thanks for finding the issue, but the solutions given don't suit my
>>use case. I don't want an iterator that operates on pre-read blocks, I
>>want something that will read a record from a file, and leave the file
>>pointer one entry past the end of the record.
>>
>>Oh, and records are likely fairly short, but there may be a lot of them.
>
>   Considering that most of the world has settled on the view that
> files are just linear streams (curse you, UNIX) anything working with
> "records" has to build the concept on top of the stream. Either by
> making records "fixed width" (allowing for fast random access:
> recNum*recLen => seek position), though likely giving up the stream
> access... Or by wrapping the stream with something that does
> parsing/buffering.

It may be instructive to see how the Linux/UNIX utility head(1)
operates. It actually reads its input greedily but once it has seen
enough, it uses lseek(2) to move the seek position back.

Not all file-like objects can seek so head(1) may fail to operate as
advertised:


$ seq 1 >/tmp/data.txt
$ {
> head -n 5 >/dev/null
> head -n 5
> }  head -n 5 >/dev/null
> head -n 5
> }

1861
1862
1863
1864
$



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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread wrong . address . 1
On Saturday, 27 February 2016 18:08:36 UTC+2, Dietmar Schwertberger  wrote:
> On 27.02.2016 12:18, wrong.addres...@gmail.com wrote:
> > Isn't there any good GUI IDE like Visual Basic? I hope there are some less 
> > well known GUI IDEs which I did not come across. Thanks.
> 
> As of today, there's no Python GUI builder comparable to VB 6.
> 

Thanks for stating this clearly. Everyone here has been trying to show me 
various ways to do the kind of things I will want to, but nobody clearly admits 
the limitations I will have to accept if I start with Python.

I am starting to wonder if VB.net would be a better solution for the time 
being. I have learnt enough VB.net to manage my work but it is bloated and 
Microsoft dependent.

> There are some like QtDesigner or wxGlade, but they either don't 
> generate Python code directly or they can only be used if you know the 
> underlying toolkit good enough to create the GUI yourself. You may try 
> out some, but I can almost guarantee you that you will come to the same 
> result.
> If you want a GUI, create it yourself using either wxPython or PyQt.

I will check it. I got the impression that you can create a GUI but that has to 
be converted to Python, and then you need a wrapper to put these forms in, and 
then they can be compiled or converted to *.exe with py2exe. Not a good way for 
development/debugging.

> 
> For engineering applications that's probably the weakest point that 
> Python has.
> It's holding back a lot of people...
> 
> Well, for most measurement or control software a GUI is not really 
> needed, but still people want it.
> 

In the 1980s everyone was happy with inputs from the command line on a line 
editor, but today people expect GUIs with graphics and often even animations.

It is surprising that a language which seems very popular does not have GUI 
development infrastructure in place these many years after it got into common 
use.

> 
> Regards,
> 
> Dietmar

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Chris Angelico
On Sun, Feb 28, 2016 at 5:13 AM,   wrote:
> In the 1980s everyone was happy with inputs from the command line on a line 
> editor, but today people expect GUIs with graphics and often even animations.
>
> It is surprising that a language which seems very popular does not have GUI 
> development infrastructure in place these many years after it got into common 
> use.

There IS development infrastructure for building GUIs. It's just that
the best way to build a cross-platform GUI is code, not drag-and-drop.
There are a number of ways to build a GUI in Python (wxPython,
PyGTK/PyGObject, PyQt, Tkinter), and some of those have drag-and-drop
builders, but not all. Even back in the 90s, when "cross-platform"
wasn't a big thing, it was possible to build a window layout using
code instead of the builder, and there were a number of situations
when that was better (I gave the example of a database form; one of my
projects was a generic table editing tool, and what it did was ask the
database for a list of columns, and create label+entry field for each
one - purely under script control).

It's worth noting, too, that the language and the GUI toolkits are
independent (only one of the ones I mentioned is even packaged with
Python, and it's an optional part); and, thanks to code, the GUI
toolkits and GUI builders are also independent. You can pick up a
third-party window builder, and as long as it emits valid Python code,
it'll work.

I've written huge numbers of Python scripts and applications, and I
don't think I've ever built a GUI in Python for anything other than
testing.

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Marko Rauhamaa
wrong.addres...@gmail.com:

> In the 1980s everyone was happy with inputs from the command line on a
> line editor, but today people expect GUIs with graphics and often even
> animations.

I don't know who these "people" are, but GUIs certainly have their uses.
If you are doing your work professionally, I suppose product management
tells you what features are needed in the product.

> It is surprising that a language which seems very popular does not
> have GUI development infrastructure in place these many years after it
> got into common use.

It's suprprising that there don't seem to be good GUI applications in
existence. Web apps are notoriously bad. (My relatively small
experiences with GUI development suggest GUI builders are to blame for
the bad GUIs much of the time.)


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


Re: The Real-Time Use of Python in Data Science World!

2016-02-27 Thread Marco Buttu

On 27/02/2016 10:13, Steven D'Aprano wrote:


I think it would be more acceptable to me if the sender
labelled the subject line as "Advertising".


+1

--
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbu...@oa-cagliari.inaf.it

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


How to optimize operations

2016-02-27 Thread II DK projektai
Hello,

Do you ever question how effectively you can use your video surveillance system 
in search of "uninvited guests", "unpaid client", "person damaged the vehicle" 
or simply to get information about the guest arriving in real time? Or maybe 
your company needs the number plate recognition systems? Or maybe you have some 
thoughts that no one has not realized due to high prices and expensive 
solutions?

If you are applicable to these issues, we advance that you familiarize yourself 
with the automatic license plate recognition system capabilities by visiting 
our website or ask a question by Email.

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Marco Kaulea
Hi,

Haven't tried it myself, but pyforms[1] might suit your needs.

- Marco

[1] http://pyforms.readthedocs.org/en/latest/

On Sat, Feb 27, 2016 at 12:18 PM,  wrote:

> I have some VB forms with more than a hundred objects. If I cannot drag
> and drop text boxes, list boxes, labels, etc., it will be too much work to
> create that with several lines of code for each object.
> Isn't there any good GUI IDE like Visual Basic? I hope there are some less
> well known GUI IDEs which I did not come across. Thanks.
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Dietmar Schwertberger

On 27.02.2016 19:13, wrong.addres...@gmail.com wrote:

I am starting to wonder if VB.net would be a better solution for the time 
being. I have learnt enough VB.net to manage my work but it is bloated and 
Microsoft dependent.

I would recommend the Python option...


I will check it. I got the impression that you can create a GUI but that has to 
be converted to Python, and then you need a wrapper to put these forms in, and 
then they can be compiled or converted to *.exe with py2exe. Not a good way for 
development/debugging.
For PyQt with Qt Designer the development flow looks like e.g. 
https://nikolak.com/pyqt-qt-designer-getting-started/
For non-trivial GUIs you will probably find it easier to create the GUI 
in Python code yourself. But maybe the created Python code will show you 
how to use PyQt in the beginning.


You will find many "Getting started with..." for both PyQt and wxPython.

For either GUI toolkit, you should get a book - either "wxPython in 
Action" or "Rapid GUI Programming with Python and Qt" (or both).


For both toolkits the electronic documentation is not for Python but for 
C++.
For wxPython you get a .chm help file, which contains all documentation 
in one file and a wxPython demo which contains a browser and example 
code for almost all GUI components.
For PyQt the documentation is online. While it is quite complete, I 
always have difficulties to find the information I'm looking for...


wxPython is currently not really an option for Python 3, but this will 
change very soon. (Well, it can be used with Python 3 already, but for a 
beginner I would recommend to start with the so called "classic" version 
for Python 2, especially as the included demo will be the main source of 
information.)



For debugging you just run the interpreter with the .py file. It's 
reasonably simple to debug with e.g. WingIDE.
When you create a GUI in Python code, it's often the easiest way to 
explore properties and methods of the GUI classes from the debugger prompt.



Regards,

Dietmar

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


Re: How to optimize operations

2016-02-27 Thread Joel Goldstick
On Sat, Feb 27, 2016 at 10:32 AM, II DK projektai  wrote:

> Hello,
>
> Do you ever question how effectively you can use your video surveillance
> system in search of "uninvited guests", "unpaid client", "person damaged
> the vehicle" or simply to get information about the guest arriving in real
> time? Or maybe your company needs the number plate recognition systems? Or
> maybe you have some thoughts that no one has not realized due to high
> prices and expensive solutions?
>
> If you are applicable to these issues, we advance that you familiarize
> yourself with the automatic license plate recognition system capabilities
> by visiting our website or ask a question by Email.
>
> DKprojektai
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Normally this stuff annoys me, but I got a laugh from this one.  I really
want to visit the website ;)  I wonder where it is?  I wonder if i am
applicable

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Anthony Papillion
I would absolutely recommend you take a look at the Qt stuff.  Very modern, 
easy to use,  and free for non-commercial products.  

Anthony 

On February 27, 2016 5:18:57 AM CST, wrong.addres...@gmail.com wrote:
>I have some VB forms with more than a hundred objects. If I cannot drag
>and drop text boxes, list boxes, labels, etc., it will be too much work
>to create that with several lines of code for each object. 
>
>Isn't there any good GUI IDE like Visual Basic? I hope there are some
>less well known GUI IDEs which I did not come across. Thanks.
>-- 
>https://mail.python.org/mailman/listinfo/python-list

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread BartC

On 27/02/2016 16:35, BartC wrote:

On 25/02/2016 06:50, Steven D'Aprano wrote:

I have a need to read to an arbitrary delimiter, which might be any of a
(small) set of characters. For the sake of the exercise, lets say it is
either ! or ? (for example).



However those aren't the main reasons for the poor speed. The limiting
factor here is reading one byte at a time. Just a loop like this:

while f.read(1):
   pass

without doing anything else, seems to take most of the time. (3.6
seconds, compared with 5.6 seconds of your readchunks() on a 6MB version
of your test file, on Python 2.7. readlines() took about 0.2 seconds.)

Any faster solutions would need to read more than one byte at a time.


I've done some more test using Python 3.4, with the same 200,000 line 
6MB test file:


0.25 seconds   Scan the file with 'for line in f'
2.25 seconds   Scan the file with your readlines() routine
4.0  seconds   Scan the file with your readchunks() routine
0.65 seconds   Scan the file with using a buffer

This latter test uses a 64-byte buffer, reading not more than an extra 
63 bytes, but resetting the file position to just past the end of of 
each identified chunk so that any subsequent read works as expected.


This test (the code is too untidy to post) only checks for two specific 
delimiters (not an arbitrary string fill of them). (It also counts EOF 
as a valid delimiter so counts one more chunk.)


Increasing the buffer size doesn't help, and beyond 256 bytes slowed 
things down (for this input) as it spends too long rereading data.


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


Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread BartC

On 27/02/2016 20:03, BartC wrote:

On 27/02/2016 16:35, BartC wrote:



Any faster solutions would need to read more than one byte at a time.


I've done some more test using Python 3.4, with the same 200,000 line
6MB test file:

0.25 seconds   Scan the file with 'for line in f'
2.25 seconds   Scan the file with your readlines() routine


That's not right. 0.25 seconds was for readlines(). 2.25 for a f.read(1) 
loop.



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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Mark Lawrence

On 27/02/2016 17:57, Marco Kaulea wrote:

Hi,

Haven't tried it myself, but pyforms[1] might suit your needs.

- Marco

[1] http://pyforms.readthedocs.org/en/latest/



PyForms 0.1.3 last updated on pypi 2016-01-17 and it's 2.7 only, just 
awesome, not.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread MRAB

On 2016-02-27 20:52, Mark Lawrence wrote:

On 27/02/2016 17:57, Marco Kaulea wrote:

Hi,

Haven't tried it myself, but pyforms[1] might suit your needs.

- Marco

[1] http://pyforms.readthedocs.org/en/latest/



PyForms 0.1.3 last updated on pypi 2016-01-17 and it's 2.7 only, just
awesome, not.

It's a little ambiguous. It says "Pyforms is a Python 2.7.x and 3.x 
cross-enviroment framework", but the Requirements list Python 2.7 only.


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


Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-02-27 Thread Ethan Furman

On 02/27/2016 01:37 AM, Steven D'Aprano wrote:


Although the connection to Python is only quite slim, I found it fascinating
to read.


Thanks to you and Kenneth for sharing that.

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Dietmar Schwertberger

On 27.02.2016 19:51, Dietmar Schwertberger wrote:

You will find many "Getting started with..." for both PyQt and wxPython.
P.S.: I forgot to mention that both toolkits have very helpful mailing 
lists.


The toolkits have different licenses. With wxPython you don't need to 
worry. For PyQt you should check which versions and licenses of PyQt and 
Qt are applicable and whether they are OK for your purpose.


Regards,

Dietmar

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


Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-02-27 Thread Jason Friedman
Yes, thank you for sharing.

Stories from people we know, or know of, leads to normalization:
mental illness is a routine illness like Type I diabetes or
appendicitis.

On Sat, Feb 27, 2016 at 2:37 AM, Steven D'Aprano  wrote:
> The author of Requests, Kenneth Reitz, discusses his recent recovery from a
> MentalHealthError exception.
>
> http://www.kennethreitz.org/essays/mentalhealtherror-an-exception-occurred
>
> Although the connection to Python is only quite slim, I found it fascinating
> to read.
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Gordon Levi
wrong.addres...@gmail.com wrote:

>On Saturday, 27 February 2016 18:08:36 UTC+2, Dietmar Schwertberger  wrote:
>> On 27.02.2016 12:18, wrong.addres...@gmail.com wrote:
>> > Isn't there any good GUI IDE like Visual Basic? I hope there are some less 
>> > well known GUI IDEs which I did not come across. Thanks.
>> 
>> As of today, there's no Python GUI builder comparable to VB 6.
>> 
>
>Thanks for stating this clearly. Everyone here has been trying to show me 
>various ways to do the kind of things I will want to, but nobody clearly 
>admits the limitations I will have to accept if I start with Python.
>
>I am starting to wonder if VB.net would be a better solution for the time 
>being. I have learnt enough VB.net to manage my work but it is bloated and 
>Microsoft dependent.

When I moved from VB "Classic" to new a language I chose Java. The
Netbeans IDE includes a drag and drop WYSIWYG form designer similar
to, but slightly better than, VB6
. Alas, thick
desktop applications are rapidly becoming out of date.

When I chose Java it was the most popular language for commercial
programming apart from .NET. I was subsequently tempted to move to
Python because I have been programming for the Raspberry Pi and Python
is the language of choice for the Pi. In addition I find Python more
readable than Java. I have been deterred because, like VB, there are
two distinct flavours and, unlike VB, there is no IDE with a form
designer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Steven D'Aprano
On Sat, 27 Feb 2016 11:07 pm, Chris Angelico wrote:

>> Isn't there any good GUI IDE like Visual Basic? I hope there are some
>> less well known GUI IDEs which I did not come across. Thanks.
> 
> Sounds like the advantage lies with Python here...
> 
> Don't make a UI by dragging and dropping that many widgets.


And later, in another post:

> the best way to build a cross-platform GUI is code, not drag-and-drop.


I think that's out-and-out wrong, and harmful to the developer community. I
think that we're stuck in the equivalent of the pre-WYSIWYG days of word
processing: you can format documents as nicely as you like, but you have to
use a separate mode to see it.

Drag-and-drop GUI builders have the same advantages over code as Python has
over languages with distinct compile/execute steps: rapid development,
prototyping, exploration and discovery. Of course, any decent modern
builder won't limit you to literally drag-and-drop, but will offer
functionality like duplicating elements, aligning them, magnetic guides,
etc.

GUI elements are by definition graphical in nature, and like other graphical
elements, manipulation by hand is superior to command-based manipulation.
Graphical interfaces for manipulating graphics have won the UI war so
effectively that some people have forgotten there ever was a war. Can you
imagine using Photoshop without drag and drop?

And yet programming those graphical interfaces is an exception. There, with
very few exceptions, we still *require* a command interface. Not just a
command interface, but an *off-line* command interface, where you batch up
all your commands then run them at once, as if we were Neanderthals living
in a cave.

An effective and modern GUI builder UI should be programmable without
requiring programming. About thirty years ago Apple came up with the ideal
mix of graphical and programmatic development for its Hypercard product.
You built applications by dragging and dropping widgets on the screen, or
by copying and pasting them from a library of pre-made widgets. 

(By 2016 standards the UI of Hypercard would seem a bit old fashioned and
primitive -- black and white, bitmapped graphics, no magnetic guides
or "replicate" command, etc -- but it was the mid 80s. A modern GUI builder
wouldn't have those limitations.)

Hypercard let you create a place widgets by hand using the mouse, or by
running a one-line command in the "Message Box" (a simple command
interpreter), and for complex tasks, or by writing a script and executing
it. You didn't have to script the *entire* application, just as much or as
little as needed scripting.

Python would be especially well-suited to this, being an interpreter. Why
should I have to batch up all the GUI elements and run them all at once to
see what my application looks like? Why can't I add elements interactively?

I've made a number of attempts to get into GUI development in Python, and
every time I flounder at the lousy state of the art in GUI builder tools.
Yes, the widget set is fantastic. But putting the GUIs together is
primitive beyond words.

Hypercard, bless Bill Atkinson, is long gone but not forgotten. But today it
lives on in the guise of LiveCode:

http://livecode.com/


If only I could get the Linux installer to actually, you know, *work*.


-- 
Steven

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


Re: Everything good about Python except GUI IDE?

2016-02-27 Thread Rustom Mody
On Sunday, February 28, 2016 at 12:04:52 PM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 27 Feb 2016 11:07 pm, Chris Angelico wrote:
> 
> >> Isn't there any good GUI IDE like Visual Basic? I hope there are some
> >> less well known GUI IDEs which I did not come across. Thanks.
> > 
> > Sounds like the advantage lies with Python here...
> > 
> > Don't make a UI by dragging and dropping that many widgets.
> 
> 
> And later, in another post:
> 
> > the best way to build a cross-platform GUI is code, not drag-and-drop.
> 
> 
> I think that's out-and-out wrong, and harmful to the developer community. I
> think that we're stuck in the equivalent of the pre-WYSIWYG days of word
> processing: you can format documents as nicely as you like, but you have to
> use a separate mode to see it.
> 
> Drag-and-drop GUI builders have the same advantages over code as Python has
> over languages with distinct compile/execute steps: rapid development,
> prototyping, exploration and discovery. Of course, any decent modern
> builder won't limit you to literally drag-and-drop, but will offer
> functionality like duplicating elements, aligning them, magnetic guides,
> etc.
> 
> GUI elements are by definition graphical in nature, and like other graphical
> elements, manipulation by hand is superior to command-based manipulation.
> Graphical interfaces for manipulating graphics have won the UI war so
> effectively that some people have forgotten there ever was a war. Can you
> imagine using Photoshop without drag and drop?
> 
> And yet programming those graphical interfaces is an exception. There, with
> very few exceptions, we still *require* a command interface. Not just a
> command interface, but an *off-line* command interface, where you batch up
> all your commands then run them at once, as if we were Neanderthals living
> in a cave.
> 
> An effective and modern GUI builder UI should be programmable without
> requiring programming. About thirty years ago Apple came up with the ideal
> mix of graphical and programmatic development for its Hypercard product.
> You built applications by dragging and dropping widgets on the screen, or
> by copying and pasting them from a library of pre-made widgets. 
> 
> (By 2016 standards the UI of Hypercard would seem a bit old fashioned and
> primitive -- black and white, bitmapped graphics, no magnetic guides
> or "replicate" command, etc -- but it was the mid 80s. A modern GUI builder
> wouldn't have those limitations.)
> 
> Hypercard let you create a place widgets by hand using the mouse, or by
> running a one-line command in the "Message Box" (a simple command
> interpreter), and for complex tasks, or by writing a script and executing
> it. You didn't have to script the *entire* application, just as much or as
> little as needed scripting.
> 
> Python would be especially well-suited to this, being an interpreter. Why
> should I have to batch up all the GUI elements and run them all at once to
> see what my application looks like? Why can't I add elements interactively?
> 
> I've made a number of attempts to get into GUI development in Python, and
> every time I flounder at the lousy state of the art in GUI builder tools.
> Yes, the widget set is fantastic. But putting the GUIs together is
> primitive beyond words.
> 
> Hypercard, bless Bill Atkinson, is long gone but not forgotten. But today it
> lives on in the guise of LiveCode:
> 
> http://livecode.com/
> 
> 
> If only I could get the Linux installer to actually, you know, *work*.
> 
> 
> -- 
> Steven


A sensible view
And more helpful than pretending that neanderthal == civilized

Chris: Is it easier to work out the best-lookkng colors with a color picker or 
with hacking through a million #rrggbb combos?

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