Tuesday, January 14, 2014

comp.lang.python - 26 new messages in 8 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* What's correct Python syntax? - 11 messages, 7 authors
http://groups.google.com/group/comp.lang.python/t/02a96ec3e80cc46a?hl=en
* L[:] - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8c4883bbe077624c?hl=en
* Stopping a wsgiref server programmatically - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/328f0f5cec49a402?hl=en
* استفتاء 2014 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/35fa341527d91fef?hl=en
* a web UI to invoke a python script at server side - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/bd4bc127b47ab4c2?hl=en
* plotting slows down - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/22f280b151f3c221?hl=en
* Python Fast I/o - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/e8fecf663243d747?hl=en
* efficient way to process data - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f7c2c58424bf2b3e?hl=en

==============================================================================
TOPIC: What's correct Python syntax?
http://groups.google.com/group/comp.lang.python/t/02a96ec3e80cc46a?hl=en
==============================================================================

== 1 of 11 ==
Date: Tues, Jan 14 2014 2:02 am
From: Igor Korot


Hi, Rustom,

On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody <rustompmody@gmail.com> wrote:
> On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote:
>>
>> What if I want field 2 and field 3? ("seq 200" and "length 30")
>
> Wee you did say:
>
>> I'm interesred in only one element, so why should care about everything else?
>
> So its not clear what you want!

Sorry, I thought it would be easier to ask this way. Guess not.

I am actually looking for a way to get a result from split which is
sliced the way I want. Like in my example above.
I mean I can probably make more variable by creating a tuple, but why?
What is the purpose if I want only couple elements out of split.
Doing it Perl way does not help:

C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> test = "I,like,my,chocolate"
>>> print test.split(',')[2,3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not tuple

I can do it this way:

>>> testlist = test.split(',')
>>> print testlist[2]
my

but it will needlessly creates a list on which I will access by the index.

Why? All I need is couple of values out of n-dimensional list (array).

>
> Do you want a one-liner? You could use a regular expression.
> [You will very soon find that the world divides between the regular and the
> irregular folks!]
>
> Or you want some other perl-ism? You need to say what...

Well is there a Python way to do what I want?
I mention Perl only because I'm familiar with the language and this is
easy in it to do that.

Thank you.

>
> Or maybe you just want to use scapy instead of tcpdump?
> --
> https://mail.python.org/mailman/listinfo/python-list




== 2 of 11 ==
Date: Tues, Jan 14 2014 2:03 am
From: Igor Korot


Sorry, that was sent to Mark directly.
Resending to the list.


---------- Forwarded message ----------
From: Igor Korot <ikorot01@gmail.com>
Date: Tue, Jan 14, 2014 at 1:50 AM
Subject: Re: What's correct Python syntax?
To: Mark Lawrence <breamoreboy@yahoo.co.uk>


Hi, Mark,

On Tue, Jan 14, 2014 at 1:37 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> On 14/01/2014 09:25, Igor Korot wrote:
>>
>> Hi, Rustom,
>>
>> On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody <rustompmody@gmail.com>
>> wrote:
>>>
>>> On Tuesday, January 14, 2014 2:16:56 PM UTC+5:30, Igor Korot wrote:
>>>>
>>>> Hi, ALL,
>>>> I'm trying to process a file which has following lines:
>>>>
>>>> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30
>>>>
>>>> (this is the text file out of tcpdump)
>>>>
>>>>
>>>> Now I can esily split the line twice: once by ':' symbol to separate
>>>> address and the protocol information and the second time by ',' to get
>>>> information about the protocol.
>>>> However, I don't need all the protocol info. All I'm interested in is
>>>> the last field, which is length.
>>>>
>>>>
>>>>
>>>> Is there a way to write something like this:
>>>>
>>>>
>>>> for data in f:
>>>> (address,traffic) = string.split(data, ':')
>>>> length = string.split(traffic, ',')[3]
>>>>
>>>>
>>>>
>>>> I'm interesred in only one element, so why should care about everything
>>>> else?
>>>> This can be easily done in Perl, but I'm stuck with Python now. ;-)
>>>
>>>
>>>
>>>>>> data="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200,
>>>>>> length 30"
>>>>>> (add,traff) = data.split(':')
>>>>>> add
>>>
>>> '192.168.1.6 > 192.168.1.7'
>>>>>>
>>>>>> traff
>>>
>>> ' ICMP echo request, id 100, seq 200, length 30'
>>>>>>
>>>>>> lenn = traff.split(',')
>>>>>> lenn = traff.split(',')[3]
>>>>>> lenn
>>>
>>> ' length 30'
>>
>>
>> What if I want field 2 and field 3? ("seq 200" and "length 30")
>>
>> Thank you.
>>
>>>>>>
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>
>
> Please do a little work before asking such a trivial question, it's hardly
> difficult from the interactive interpreter, particularly when you already
> have an example to start with.

C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> test = "I,like,my,chocolate"
>>> print test.split(',')[2,3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not tuple

Like I said, I'm more used to Perl, but need to work with Python for a moment.

Thank you.

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




== 3 of 11 ==
Date: Tues, Jan 14 2014 2:16 am
From: Rustom Mody


On Tuesday, January 14, 2014 3:32:24 PM UTC+5:30, Igor Korot wrote:
> Hi, Rustom,

> On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody wrote:
> > On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote:
> >> What if I want field 2 and field 3? ("seq 200" and "length 30")
> > Wee you did say:
> >> I'm interesred in only one element, so why should care about everything else?
> > So its not clear what you want!

> Sorry, I thought it would be easier to ask this way. Guess not.

> I am actually looking for a way to get a result from split which is
> sliced the way I want. Like in my example above.
> I mean I can probably make more variable by creating a tuple, but why?
> What is the purpose if I want only couple elements out of split.
> Doing it Perl way does not help:

> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python
> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> test = "I,like,my,chocolate"
> >>> print test.split(',')[2,3]

You want this?

>>> test = "I,like,my,chocolate"
>>> test.split(',')
['I', 'like', 'my', 'chocolate']
>>> test.split(',')[2:4]
['my', 'chocolate']


> Well is there a Python way to do what I want?


Well I for one still dont get what you want!!

Heres a python one-liner using regexps
>>> r=r'(.*) +> +(.*):.*length (\d*)'
>>> re.findall(r,data)
[('192.168.1.6', '192.168.1.7', '30')]

Note: I am NOT suggesting you use regexps. Just that they will do what you want if you are so inclined




== 4 of 11 ==
Date: Tues, Jan 14 2014 2:35 am
From: Igor Korot


Hi, Rustom,

On Tue, Jan 14, 2014 at 2:16 AM, Rustom Mody <rustompmody@gmail.com> wrote:
> On Tuesday, January 14, 2014 3:32:24 PM UTC+5:30, Igor Korot wrote:
>> Hi, Rustom,
>
>> On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody wrote:
>> > On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote:
>> >> What if I want field 2 and field 3? ("seq 200" and "length 30")
>> > Wee you did say:
>> >> I'm interesred in only one element, so why should care about everything else?
>> > So its not clear what you want!
>
>> Sorry, I thought it would be easier to ask this way. Guess not.
>
>> I am actually looking for a way to get a result from split which is
>> sliced the way I want. Like in my example above.
>> I mean I can probably make more variable by creating a tuple, but why?
>> What is the purpose if I want only couple elements out of split.
>> Doing it Perl way does not help:
>
>> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python
>> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
>> (Intel)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> test = "I,like,my,chocolate"
>> >>> print test.split(',')[2,3]
>
> You want this?
>
>>>> test = "I,like,my,chocolate"
>>>> test.split(',')
> ['I', 'like', 'my', 'chocolate']
>>>> test.split(',')[2:4]
> ['my', 'chocolate']

Yup, thats it.
Now 2 and 4 - it's a starting point and ending point, right?

Thank you.
>
>
>> Well is there a Python way to do what I want?
>
>
> Well I for one still dont get what you want!!
>
> Heres a python one-liner using regexps
>>>> r=r'(.*) +> +(.*):.*length (\d*)'
>>>> re.findall(r,data)
> [('192.168.1.6', '192.168.1.7', '30')]
>
> Note: I am NOT suggesting you use regexps. Just that they will do what you want if you are so inclined
> --
> https://mail.python.org/mailman/listinfo/python-list




== 5 of 11 ==
Date: Tues, Jan 14 2014 2:51 am
From: Rustom Mody


On Tuesday, January 14, 2014 4:05:27 PM UTC+5:30, Igor Korot wrote:
> Hi, Rustom,
>
>
>
> On Tue, Jan 14, 2014 at 2:16 AM, Rustom Mody wrote:
> > You want this?
> >
> >>>> test = "I,like,my,chocolate"
> >>>> test.split(',')
> > ['I', 'like', 'my', 'chocolate']
> >>>> test.split(',')[2:4]
> > ['my', 'chocolate']
>
>
> Yup, thats it.
> Now 2 and 4 - it's a starting point and ending point, right?

In python ranges are usually lo-inclusive hi-exclusive.
Slices are one case of this

See explanations:
http://docs.python.org/2/tutorial/introduction.html#strings
and
http://stackoverflow.com/questions/509211/pythons-slice-notation

Neat theoretical explanation
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html




== 6 of 11 ==
Date: Tues, Jan 14 2014 2:59 am
From: Alister


On Tue, 14 Jan 2014 00:46:56 -0800, Igor Korot wrote:

> Hi, ALL,
> I'm trying to process a file which has following lines:
>
> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30
>
> (this is the text file out of tcpdump)
>
> Now I can esily split the line twice: once by ':' symbol to separate
> address and the protocol information and the second time by ',' to get
> information about the protocol.
> However, I don't need all the protocol info. All I'm interested in is
> the last field, which is length.
>
> Is there a way to write something like this:
>
> for data in f:
> (address,traffic) = string.split(data, ':')
> length = string.split(traffic, ',')[3]
>
> I'm interesred in only one element, so why should care about everything
> else?
> This can be easily done in Perl, but I'm stuck with Python now. ;-)
>
> Thank you.

Am I missing something obvious here?
just split on ','

field [0] will contain a mix of data but who cares? you don't want it
anyway (you can always process it again afterwards.

>>> a='192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200,
length 30'
>>> data=a.split(',')
>>> data
['192.168.1.6 > 192.168.1.7: ICMP echo request', ' id 100', ' seq 200', '
length 30']
>>> data[3]
' length 30'



--
It's not against any religion to want to dispose of a pigeon.
-- Tom Lehrer, "Poisoning Pigeons in the Park"




== 7 of 11 ==
Date: Tues, Jan 14 2014 3:33 am
From: Peter Otten <__peter__@web.de>


Igor Korot wrote:

> I am actually looking for a way to get a result from split which is
> sliced the way I want. Like in my example above.
> I mean I can probably make more variable by creating a tuple, but why?
> What is the purpose if I want only couple elements out of split.
> Doing it Perl way does not help:
>
> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python
> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> test = "I,like,my,chocolate"
>>>> print test.split(',')[2,3]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: list indices must be integers, not tuple
>
> I can do it this way:
>
>>>> testlist = test.split(',')
>>>> print testlist[2]
> my
>
> but it will needlessly creates a list on which I will access by the index.
>
> Why? All I need is couple of values out of n-dimensional list (array).

Python has no dedicated syntax for picking arbitrary items from a list
If you are only concerned about printing use format():

>>> items = ["alpha", "beta", "gamma", "delta"]
>>> print "{1} {3} {0}".format(*items)
beta delta alpha

If you want to work with the values use operator.itemgetter():

>>> from operator import itemgetter
>>> itemgetter(1, 0, -1)(items)
('beta', 'alpha', 'delta')







== 8 of 11 ==
Date: Tues, Jan 14 2014 4:19 am
From: Ned Batchelder


On 1/14/14 6:33 AM, Peter Otten wrote:
> Python has no dedicated syntax for picking arbitrary items from a list
> If you are only concerned about printing use format():
>
>>>> >>>items = ["alpha", "beta", "gamma", "delta"]
>>>> >>>print "{1} {3} {0}".format(*items)
> beta delta alpha

.format also supports item access directly:

>>> items = ["alpha", "beta", "gamma", "delta"]
>>> print "{0[1]} {0[3]} {0[0]}".format(items)
beta delta alpha

It's clunkier in this example, but if you have more than one value being
formatted, this (and the "{0.foo}" syntax) can make digging into nested
data more convenient.

--
Ned Batchelder, http://nedbatchelder.com





== 9 of 11 ==
Date: Tues, Jan 14 2014 5:34 am
From: Roy Smith


In article <mailman.5437.1389689219.18130.python-list@python.org>,
Igor Korot <ikorot01@gmail.com> wrote:

> Hi, ALL,
> I'm trying to process a file which has following lines:
>
> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30
>
> (this is the text file out of tcpdump)
>
> Now I can esily split the line twice: once by ':' symbol to separate
> address and the protocol information and the second time by ',' to get
> information about the protocol.
> However, I don't need all the protocol info. All I'm interested in is
> the last field, which is length.

One possibility would be to forget about all the punctuation and just
use "length " (note the trailing space) as the split delimiter:

>>> line = '192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq
200, length 30'
>>> line.split('length ')
'30'

this will only work if you're sure that "length " can never appear
anywhere else in the line. Another, perhaps more idiomatic, way would
be:

>>> _, length = line.split('length ')
>>> print length
30

What's happening here is split() is returning a list of two items, which
you then unpack into two variables, "_" and "length". It's common to
unpack unwanted fields into "_", as a hint (to the reader) that it's
unused.




== 10 of 11 ==
Date: Tues, Jan 14 2014 5:47 am
From: Roy Smith


In article <mailman.5443.1389693753.18130.python-list@python.org>,
Igor Korot <ikorot01@gmail.com> wrote:

> I can do it this way:
>
> >>> testlist = test.split(',')
> >>> print testlist[2]
> my
>
> but it will needlessly creates a list on which I will access by the index.

Stop worrying about needlessly creating lists. Write the code in a way
that works and is easy to understand. If it turns out that it's not
running fast enough, then you can go back and optimize.

BTW, for those of you into code golf:

>>> line = '192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq
200, length 30'

>>> dict((k,int(v)) for k,v in (s.split() for s in line.split(', ')[1:]))
{'length': 30, 'id': 100, 'seq': 200}




== 11 of 11 ==
Date: Tues, Jan 14 2014 5:58 am
From: Dennis Lee Bieber


On Tue, 14 Jan 2014 02:02:24 -0800, Igor Korot <ikorot01@gmail.com>
declaimed the following:

>C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python
>Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
>(Intel)] on win32
>Type "help", "copyright", "credits" or "license" for more information.
>>>> test = "I,like,my,chocolate"
>>>> print test.split(',')[2,3]

So close, as long as you want a contiguous range of parts.

>>> "I,like,my,chocolate".split(",")[2:3]
['my']
>>> "I,like,my,chocolate".split(",")[2:4]
['my', 'chocolate']
>>> "I,like,my,chocolate".split(",")[1:-1]
['like', 'my']
>>>

For arbitrary items, as long as you don't ask for something higher than
in the split..

>>> splt = "I,like,my,dark,chocolate".split(",")
>>> splt
['I', 'like', 'my', 'dark', 'chocolate']
>>> [splt[i] for i in (1, 3, 0, 2, 4)]
['like', 'dark', 'I', 'my', 'chocolate']
>>>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/






==============================================================================
TOPIC: L[:]
http://groups.google.com/group/comp.lang.python/t/8c4883bbe077624c?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 14 2014 2:42 am
From: Albert-Jan Roskam


On 1/13/2014 4:00 AM, Laszlo Nagy
wrote:
>
>> Unless L is aliased, this is silly code.
> There is another use case. If you intend to modify a
list within a for
> loop that goes over the same list, then you need to
iterate over a copy.
> And this cannot be called an "alias" because it has no
name:

for i in somelist: creates a second reference to somelist
that somewhere in the loop code has a name, so it is
effectively an 'alias'. The essential point is that there
are two access paths to the same object.

> for idx,item in enumerate(L[:]):
>     # do something with L here,
including modification

The copy is only needed in the above if one inserts or
deletes. But if one inserts or deletes more than one item,
one nearly always does better to iterate through the
original and construct a new list with new items added and
old items not copied.


====> Hi, first, thank you all for your replies -much appreciated!
Terry, this would be making a shallow copy, right? If so, then "list(L)" is slightly nicer IMHO, but that's probably a matter of taste (however, I don't like copy.copy, even though that's perhaps most clear --oh well nitpicking ;-)

I also found that item assignment ([1] below) is much faster than using the more standard (I think) .append ([2]).
# [1]
for idx,item in enumerate(L[:]):
if some_condition:
L[idx] = foobarify(item)
# [2]
L2 = []
for idx,item in enumerate(L):
if some_condition:
L2.append(foobarify(item))
else:
L2.append(item)







==============================================================================
TOPIC: Stopping a wsgiref server programmatically
http://groups.google.com/group/comp.lang.python/t/328f0f5cec49a402?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 14 2014 3:21 am
From: Gilles Lenfant


Hi,

I made a small / minimal wsgiref HTTP server dedicated to unittest stubs (testing custom REST client and other likes) that works pretty good in a separate thread.

https://gist.github.com/glenfant/7369894

Feel free to reuse it in your own unittest stubs/mocks.

But it only works like a charm in an Unix box, due to the use of a control pipe ( https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L118 ) that's checked with select.select ( https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L133 ) and can be stopped on request when writing in that pipe ( https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L173 ).

Is there a volunteer with a Windows box for helping me to get it fixed. Note: I have no windows box to experiment alternate.

Many thanks by advance.
--
Gilles Lenfant





==============================================================================
TOPIC: استفتاء 2014
http://groups.google.com/group/comp.lang.python/t/35fa341527d91fef?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 14 2014 4:51 am
From: essd


استفتاء 2014
استفتاء الدستور 2014
معرفة اللجنة الانتخابية 2014
معرفه اللجنه الانتخابيه 2014
معرفة اللجنة الانتخابية للدستور 2014
استفتاء دستور 2014
موقع استفتاء الدستور 2014
لجان الاستفتاء 2014
لجان استفتاء الدستور 2014 corvette
لجان استفتاء 2014
موقع اللجنة العليا للانتخابات اعرف مكان لجنتك الانتخابية فى الاستفتاء على دستور 2014
اعرف مقر لجنتك الانتخابية عن طريق الرقم القومى
اعرف مكان لجنتك الانتخابية فى الاستفتاء على مشروع دستور مصر 2014
مكان اللجان للوافدين للاستفتاء على دستور 2014فى جميع المحافظات
اعرف دائرتك الانتخابية بالرقم القومى
معرفة اللجنة الانتخابية بالرقم القومى من على موقع اللجنة العليا للانتخابات 2014
اكتب الرقم القومي واعرف لجنتك الانتخابية فى الاستفتاء على الدستور
معرفة اللجنة الإنتخابية بالرقم القومي 2014 – إعرف لجنتك الإنتخابية للإستفتاء على الدستور
اعرف مكان لجنتك الانتخابية بالرقم القومي من موقع اللجنة العليا للانتخابات
اللجنة العليا للانتخابات لجنتك فى استفتاء الدستور 2014
لجنة الاستفتاء على الدستور الجديد 2014
معرفة اللجنة الانتخابية 2014 – اعرف لجنتك الانتخابية
لجان الانتخابات بالرقم القومى لاستفتاء الدستور 2014
اعرف لجنتك الإنتخابية بالرقم القومي 2014
الاستعلام عن مقر اللجنة الانتخابية للاستفتاء علي الدستور الجديد 2014

http://natigaas7ab.com/?p=5458




==============================================================================
TOPIC: a web UI to invoke a python script at server side
http://groups.google.com/group/comp.lang.python/t/bd4bc127b47ab4c2?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Jan 14 2014 4:20 am
From: Frank Cui


Hey guys,
I'm working on to provide a lightweight web UI for providing an interface to invoke a python script(a sequential script which could involve some system calls) at the server side. The UI should collect some parameters for input into this python script, and conversely the output of the script needs to be returned to the web client side.
I haven't done much web programming before, can you provide some hints on how this is usually implemented ?
ThanksFrank



== 2 of 2 ==
Date: Tues, Jan 14 2014 5:22 am
From: Jean-Michel Pichavant



----- Original Message -----

> Hey guys,

> I'm working on to provide a lightweight web UI for providing an
> interface to invoke a python script(a sequential script which could
> involve some system calls) at the server side. The UI should collect
> some parameters for input into this python script, and conversely
> the output of the script needs to be returned to the web client
> side.

> I haven't done much web programming before, can you provide some
> hints on how this is usually implemented ?

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

Hi Frank,

Have a look at http://flask.pocoo.org/
This is a micro web framework.

Build your "hello world" web app, once it's working, look at the flask tutorial, you won't use the database but it'll give you a good overview of how things are organized.

Flask support python 3 but your web server may not. You may need to stick with python 2.

JM


-- IMPORTANT NOTICE:

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.





==============================================================================
TOPIC: plotting slows down
http://groups.google.com/group/comp.lang.python/t/22f280b151f3c221?hl=en
==============================================================================

== 1 of 4 ==
Date: Tues, Jan 14 2014 5:04 am
From: Norman Elliott


@Dave, no problem. I am using gedit to write the files and have it set to translate tabs into 4 spaces which is what was recommended to me as the right amount of indenting for python scripts.

On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott wrote:
> First let me say I have not done much python programming!
>
> I am running Python 2.7.3.
>
> I am trying to use python as a front end to a simple oscilloscope.
>
> Ultimately I intend to use it with my micropython board.
>
>
>
> At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data.
>
>
>
> Each time it goes through the outer loop it gets slower and slower.
>
> I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds.
>
> Can anyone explain what I am doing wrong please?
>
> Here is the code:
>
> [code]
>
> #!/usr/bin/python
>
> from graphics import *
>
> import random
>
> import time
>
>
>
> xpos=1200
>
> ypos=400
>
> ypnt=ypos/2
>
> pos=1
>
> #setBackground("white")
>
> def main():
>
> win = GraphWin("My Circle", xpos, ypos)
>
> # win.setBackGround('white')
>
> for y in range(1,5):
>
> cir2 = Circle(Point(xpos/2,20), 10)
>
> cir2.setFill("white")
>
> cir2.draw(win)
>
> message = Text(Point(win.getWidth()/2, 20), y)
>
> message.draw(win)
>
> j = random.randint(1,ypos)
>
> for x in range(1,xpos):
>
> updown = random.randint(0,1)
>
> if updown:
>
> j=j+1
>
> else:
>
> j=j-1
>
> if j <1:
>
> j=ypos/2
>
> if j>ypos-1:
>
> j=ypos/2
>
> win.plot(x,j,"red")
>
> time.sleep(.0001)
>
>
>
> main()
>
> time.sleep(5)
>
> [/code]





== 2 of 4 ==
Date: Tues, Jan 14 2014 5:15 am
From: Rustom Mody


On Tuesday, January 14, 2014 6:34:43 PM UTC+5:30, Norman Elliott wrote:
> @Dave, no problem. I am using gedit to write the files and have it set to translate tabs into 4 spaces which is what was recommended to me as the right amount of indenting for python scripts.

Dunno what you mean by 'translate'
If that means actually replace the characters, then that will cause minimum problems

However it can also mean that gedit sets tabstops at 4 character intervals
Which will mean you will see 4 characters (in gedit) and everyone else will see a
tab. This is a recipe for trouble.




== 3 of 4 ==
Date: Tues, Jan 14 2014 5:36 am
From: Chris Angelico


On Wed, Jan 15, 2014 at 12:15 AM, Rustom Mody <rustompmody@gmail.com> wrote:
> However it can also mean that gedit sets tabstops at 4 character intervals
> Which will mean you will see 4 characters (in gedit) and everyone else will see a
> tab. This is a recipe for trouble.

Not a recipe for trouble normally, it's just that some people's
clients can't see them. So keep using tabs if you want to, but be
prepared to search-and-replace them to spaces prior to posting code.
Though I think the fault is with the client(s) that can't see tabs,
and they're the ones that ought to be fixed.

ChrisA




== 4 of 4 ==
Date: Tues, Jan 14 2014 5:48 am
From: Dennis Lee Bieber


On Tue, 14 Jan 2014 04:39:11 -0500 (EST), Dave Angel <davea@davea.name>
declaimed the following:


>I just went to my Linux box and fired up thunderbird. When it
> reads the same message from gmane, it gets the tabs. So
> apparently it's this Android Newsgroups Reader that's buggy.
>

Perhaps even more than you think... Your responses are showing up here
with a 1-space hanging indent; as if it considers the space when
word-wrapping to be the beginning of a word, rather than the end of a word.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/






==============================================================================
TOPIC: Python Fast I/o
http://groups.google.com/group/comp.lang.python/t/e8fecf663243d747?hl=en
==============================================================================

== 1 of 4 ==
Date: Tues, Jan 14 2014 5:50 am
From: Ayushi Dalmia


I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file.

Presently I am using this:

with open('index.txt','w') as f:
f.write("".join(data))
f.close()

where data is a list of strings which I want to dump into the index.txt file




== 2 of 4 ==
Date: Tues, Jan 14 2014 6:03 am
From: Chris Angelico


On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia
<ayushidalmia2604@gmail.com> wrote:
> I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file.
>
> Presently I am using this:
>
> with open('index.txt','w') as f:
> f.write("".join(data))
> f.close()

with open('index.txt','w') as f:
for hunk in data:
f.write(hunk)

You don't need to f.close() - that's what the 'with' block guarantees.
Iterating over data and writing each block separately means you don't
have to first build up a 200MB string. After that, your performance is
going to be mainly tied to the speed of your disk, not anything that
Python can affect.

ChrisA




== 3 of 4 ==
Date: Tues, Jan 14 2014 6:24 am
From: Ayushi Dalmia


On Tuesday, January 14, 2014 7:33:08 PM UTC+5:30, Chris Angelico wrote:
> On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia
>
> <ayushidalmia2604@gmail.com> wrote:
>
> > I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file.
>
> >
>
> > Presently I am using this:
>
> >
>
> > with open('index.txt','w') as f:
>
> > f.write("".join(data))
>
> > f.close()
>
>
>
> with open('index.txt','w') as f:
>
> for hunk in data:
>
> f.write(hunk)
>
>
>
> You don't need to f.close() - that's what the 'with' block guarantees.
>
> Iterating over data and writing each block separately means you don't
>
> have to first build up a 200MB string. After that, your performance is
>
> going to be mainly tied to the speed of your disk, not anything that
>
> Python can affect.
>
>
>
> ChrisA

Thanks for the tip on the closing of the file. I did not know that with ensures closing of the file after iteration is over.

Which is more fast?
Creating a 200 Mb string and then dumping into a file or dividing the 200 Mb string into chunks and then writing those chunks. Won't writing the chunks call more i/o operation?




== 4 of 4 ==
Date: Tues, Jan 14 2014 6:32 am
From: Chris Angelico


On Wed, Jan 15, 2014 at 1:24 AM, Ayushi Dalmia
<ayushidalmia2604@gmail.com> wrote:
> On Tuesday, January 14, 2014 7:33:08 PM UTC+5:30, Chris Angelico wrote:
>> On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia
>>
>> <ayushidalmia2604@gmail.com> wrote:
>>
>> > I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file.
>>
>> >
>>
>> > Presently I am using this:
>>
>> >
>>
>> > with open('index.txt','w') as f:
>>
>> > f.write("".join(data))
>>
>> > f.close()
>>
>>
>>
>> with open('index.txt','w') as f:
>>
>> for hunk in data:
>>
>> f.write(hunk)
>>
>>
>>
>> You don't need to f.close() - that's what the 'with' block guarantees.
>>
>> Iterating over data and writing each block separately means you don't
>>
>> have to first build up a 200MB string. After that, your performance is
>>
>> going to be mainly tied to the speed of your disk, not anything that
>>
>> Python can affect.
>>
>>
>>
>> ChrisA

Your quoted text is becoming double spaced, because of bugs in the
Google Groups client. Please either edit this before posting, or
switch to a better newsreader, or use the mailing list:

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

Thanks!

> Which is more fast?
> Creating a 200 Mb string and then dumping into a file or dividing the 200 Mb string into chunks and then writing those chunks. Won't writing the chunks call more i/o operation?
>

When you're writing two hundred megabytes, the number of I/O
operations is dominated by that. You have to write that many sectors,
and nothing can change that. Joining your list of strings before
writing incurs the cost of building up a single 200MB string, but even
that is likely to be insignificant in the scheme of things (if you
have the memory available, it won't take very long compared to the
time it takes to write to the disk). Python will buffer its writes, so
you don't have to worry about the details. It's going to do the right
thing for you; you can concentrate on making your code look right.

ChrisA





==============================================================================
TOPIC: efficient way to process data
http://groups.google.com/group/comp.lang.python/t/f7c2c58424bf2b3e?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Jan 14 2014 6:18 am
From: Larry Martell


On Mon, Jan 13, 2014 at 11:32 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell <larry.martell@gmail.com> wrote:
>> Thanks. Unfortunately this has been made a low priority task and I've
>> been put on to something else (I hate when they do that).
>
> Ugh, I know that feeling all too well! Life's better when you're
> unemployed, and you can choose the interesting problems to work on.
> Apart from the "has to be in MySQL" restriction (dodged now that the
> work's all being done in Python anyway), yours is _definitely_ an
> interesting problem.

if you're interested in what the application is, this is data
collected with an electron microscope from semiconductor wafers as
they are being manufactured. The x and y are the position on the wafer
that the data was collected, in microns. If 2 data points are
collected within 1 micron of each other they need to be combined when
being analyzed.




== 2 of 2 ==
Date: Tues, Jan 14 2014 6:26 am
From: Chris Angelico


On Wed, Jan 15, 2014 at 1:18 AM, Larry Martell <larry.martell@gmail.com> wrote:
> if you're interested in what the application is, this is data
> collected with an electron microscope from semiconductor wafers as
> they are being manufactured. The x and y are the position on the wafer
> that the data was collected, in microns. If 2 data points are
> collected within 1 micron of each other they need to be combined when
> being analyzed.

As far as I'm concerned, you won geek cred the moment you said
"electron microscope", and "semiconductor wafers as they are being
manufactured" is just gravy I don't suppose you want to hire another
programmer? :)

Do you actually mean here that the two points need to be within 1
micron, or that data gets combined if it's nearby in *either*
coordinate? There are libraries for figuring out if two things are
near each other - I'm not 100% sure, but you might be able to do this
inside PostgreSQL (though that just gets back to the previous rule:
can't move off MySQL). Treat every data point as a circle or square,
and then look for overlap.

ChrisA




==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate