Re: Chanelling Guido - dict subclasses

2014-01-14 Thread F
I can't speak for Guido but I think it is messy and unnatural and will lead to 
user frustration.
 As a user, I would expect a dict to take any hashable as key and any object as 
value when using one. I would probably just provide a __getitem__ method in a 
normal class in your case. 

This said I have overriden dict before, but my child class only added to dict, 
I didn't change it's underlying behaviour so you can use my class(es) as a 
vanilla dict everywhere, which enforcing types would have destroyed.



On 01:27 15/01 , Steven D'Aprano wrote:
>Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread 
>discussion involving at least two PEPs, about bytes/str compatibility. 
>But I don't want to talk about that. (Oh gods, I *really* don't want to 
>talk about that...)
>
>In the midst of that discussion, Guido van Rossum made a comment about 
>subclassing dicts:
>
>[quote]
>From: Guido van Rossum 
>Date: Tue, 14 Jan 2014 12:06:32 -0800
>Subject: Re: [Python-Dev] PEP 460 reboot
>
>Personally I wouldn't add any words suggesting or referring 
>to the option of creation another class for this purpose. You 
>wouldn't recommend subclassing dict for constraining the 
>types of keys or values, would you?
>[end quote]
>
>https://mail.python.org/pipermail/python-dev/2014-January/131537.html
>
>This surprises me, and rather than bother Python-Dev (where it will 
>likely be lost in the noise, and certain will be off-topic), I'm hoping 
>there may be someone here who is willing to attempt to channel GvR. I 
>would have thought that subclassing dict for the purpose of constraining 
>the type of keys or values would be precisely an excellent use of 
>subclassing.
>
>
>class TextOnlyDict(dict):
>def __setitem__(self, key, value):
>if not isinstance(key, str):
>raise TypeError
>super().__setitem__(key, value)
># need to override more methods too
>
>
>But reading Guido, I think he's saying that wouldn't be a good idea. I 
>don't get it -- it's not a violation of the Liskov Substitution 
>Principle, because it's more restrictive, not less. What am I missing?
>
>
>-- 
>Steven 
>

-- 
yrNews Usenet Reader for iOS
http://appstore.com/yrNewsUsenetReader

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


Re: Fwd: What's correct Python syntax?

2014-01-14 Thread Larry Hudson

On 01/14/2014 02:03 AM, Igor Korot wrote:
[snip]


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 "", line 1, in 
TypeError: list indices must be integers, not tuple



Try again...  but use a colon not a comma, [2:3]

Two additional comments:
(1)  test.split(',')[2:3] will give you ["my"] only.  The slicing syntax starts with the first 
index and goes up to but NOT INCLUDING the second.  In this case it is the same as the single 
index, [2].  You want either [2:4] or [2:], or even [2:500].  Any value >= the length of the 
list (or whatever sequence) is acceptable as the ending index in a slice.  It's probably not a 
good idea to use a value like this, but it does work.  And obviously, don't try to read with an 
out-of-bounds index, but it does work as the _ending_ index in a slice.


(2)  A comma-separated list of data items IS a tuple, even without the usual enclosing 
parenthesis.  That is your error here -- [2,3] is the same as [(2,3)], which is a tuple.


 -=- Larry -=-

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


Re: python-list@python.org

2014-01-14 Thread MRAB

On 2014-01-15 01:25, Florian Lindner wrote:

Am Dienstag, 14. Januar 2014, 17:00:48 schrieb MRAB:

On 2014-01-14 16:37, Florian Lindner wrote:
> Hello!
>
> I'm using python 3.2.3 on debian wheezy. My script is called from my mail 
delivery agent (MDA) maildrop (like procmail) through it's xfilter directive.
>
> Script works fine when used interactively, e.g. ./script.py < testmail but 
when called from maildrop it's producing an infamous UnicodeDecodeError:
>
> File "/home/flindner/flofify.py", line 171, in main
>   mail = sys.stdin.read()
> File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode
>   return codecs.ascii_decode(input, self.errors)[0]
>
> Exception for example is always like
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: 
ordinal not in range(128)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: 
ordinal not in range(128)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: 
ordinal not in range(128)
>
> I read mail from stdin "mail = sys.stdin.read()"
>
> Environment when called is:
>
> locale.getpreferredencoding(): ANSI_X3.4-1968
> environ["LANG"]: C
>
> System environment when using shell is:
>
> ~ % echo $LANG
> en_US.UTF-8
>
> As far as I know when reading from stdin I don't need an decode(...) call, 
since stdin has a decoding. I also tried some decoding/encoding stuff but changed 
nothing.
>
> Any ideas to help me?
>
When run from maildrop it thinks that the encoding of stdin is ASCII.


Well, true. But what encoding does maildrop actually gives me? It obviously 
does not inherit LANG or is called from the MTA that way. I also tried:


locale.getpreferredencoding() said "ANSI_X3.4-1968", which is ASCII
(ask Wikipedia if you want to know why it's called that!).


 inData = codecs.getreader('utf-8')(sys.stdin)
 mail = inData.read()

Failed also. But I'm not exactly an encoding expert.


Try:

sys.stdin = codecs.getreader('utf-8')(sys.stdin.detach())

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


Re: Chanelling Guido - dict subclasses

2014-01-14 Thread Terry Reedy

On 1/14/2014 8:27 PM, Steven D'Aprano wrote:


In the midst of that discussion, Guido van Rossum made a comment about
subclassing dicts:

 [quote]
 From: Guido van Rossum 
 Date: Tue, 14 Jan 2014 12:06:32 -0800
 Subject: Re: [Python-Dev] PEP 460 reboot

 Personally I wouldn't add any words suggesting or referring
 to the option of creation another class for this purpose. You
 wouldn't recommend subclassing dict for constraining the
 types of keys or values, would you?
 [end quote]

https://mail.python.org/pipermail/python-dev/2014-January/131537.html

This surprises me,


I was slightly surprised too. I understand not wanting to add a subclass 
to stdlib, but I believe this was about adding words to the doc. Perhaps 
he did not want to over-emphasize one particular possible subclass by 
putting the words in the doc.


--
Terry Jan Reedy

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


Re: Python 3.x adoption

2014-01-14 Thread MRAB

On 2014-01-15 02:55, Steven D'Aprano wrote:

On Tue, 14 Jan 2014 20:33:50 +0100, Staszek wrote:


Hi

What's the problem with Python 3.x?


Nothing.


It was first released in 2008,


That was only five years ago.

I know that to young kids today who change their iPhone every six months,
five years sounds like a lot, but in the world of mature software, five
years is a blink of the eye. People still use Fortran code that is 30
years old. I know of at least one person supporting a Python 1.5 system,
which is about 15 years old. RedHat is still providing commercial support
for Python 2.3, and their Python 2.7 commercial support won't end until
2023 or 2024.



but web hosting companies still seem to offer Python 2.x rather.

For example, Google App Engine only offers Python 2.7.

What's wrong?...


Hosting companies are conservative. Just look at how many still offer old
versions of PHP. These guys offer PHP 5.2 to 5.5:

http://www.a2hosting.com/php-hosting

WordPress will run on PHP 4.1!

So it is no surprise that Python hosting companies still mostly provide
2.7.


Not to mention Windows XP, which is only now being dropped by Microsoft.

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


Re: extracting string.Template substitution placeholders

2014-01-14 Thread Eric S. Johansson


On 1/13/2014 2:24 AM, Steven D'Aprano wrote:

On Sun, 12 Jan 2014 10:08:31 -0500, Eric S. Johansson wrote:


Now just walk the template for $ signs. Watch out for $$ which escapes
the dollar sign. Here's a baby parser:

found a different way

import string
cmplxstr="""a simple $string a longer $string a $last line"""
nst=string.Template(cmplxstr)

identifiers = {}

while True:
try:
result = nst.substitute(identifiers)
except KeyError, error:
print error
identifiers[error[0]] = "x"
else:
break
print "loop done"

 --
at the end I only care about the keys in identifier which I fill in 
after user interaction.


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


Re: Python 3.x adoption

2014-01-14 Thread Steven D'Aprano
On Tue, 14 Jan 2014 20:33:50 +0100, Staszek wrote:

> Hi
> 
> What's the problem with Python 3.x? 

Nothing.

> It was first released in 2008, 

That was only five years ago.

I know that to young kids today who change their iPhone every six months, 
five years sounds like a lot, but in the world of mature software, five 
years is a blink of the eye. People still use Fortran code that is 30 
years old. I know of at least one person supporting a Python 1.5 system, 
which is about 15 years old. RedHat is still providing commercial support 
for Python 2.3, and their Python 2.7 commercial support won't end until 
2023 or 2024.


> but web hosting companies still seem to offer Python 2.x rather.
> 
> For example, Google App Engine only offers Python 2.7.
> 
> What's wrong?...

Hosting companies are conservative. Just look at how many still offer old 
versions of PHP. These guys offer PHP 5.2 to 5.5:

http://www.a2hosting.com/php-hosting

WordPress will run on PHP 4.1!

So it is no surprise that Python hosting companies still mostly provide 
2.7.



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


Re: dictionary with tuples

2014-01-14 Thread YBM

Le 14/01/2014 23:00, Tobiah a écrit :

On 01/14/2014 01:21 PM, YBM wrote:

Le 14/01/2014 22:10, Igor Korot a écrit :

Hi, ALL,
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.

dict = {}
dict[(1,2)] = ('a','b')
dict[(3,4)] = ('c','d')
for (key1,key2),(value1,value2) in dict:

... print key1, " ", key2
... print value1, " ", value2
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: 'int' object is not iterable




What am I doing wrong?


for ... in dict:

is a way to iterate through dictionnary items,

what you want to do can be done so:

for (key1,key2),(value1,value2) in dict.items():





But it's (key1, value1), (key2, value2)


No. Try it.

key1 key2 are the members of every tuple key.
value1, value2 are the members of every tuple value.

 >>> d={ (1,2):('a','b'), (3,4):('c','d') }
 >>> for (key1,key2),(value1,value2) in d.items():
 ... print key1,key2,value1,value2
 ...
 1 2 a b
 3 4 c d



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


Re: Chanelling Guido - dict subclasses

2014-01-14 Thread Ned Batchelder

On 1/14/14 8:27 PM, Steven D'Aprano wrote:

Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread
discussion involving at least two PEPs, about bytes/str compatibility.
But I don't want to talk about that. (Oh gods, I *really* don't want to
talk about that...)

In the midst of that discussion, Guido van Rossum made a comment about
subclassing dicts:

 [quote]
 From: Guido van Rossum 
 Date: Tue, 14 Jan 2014 12:06:32 -0800
 Subject: Re: [Python-Dev] PEP 460 reboot

 Personally I wouldn't add any words suggesting or referring
 to the option of creation another class for this purpose. You
 wouldn't recommend subclassing dict for constraining the
 types of keys or values, would you?
 [end quote]

https://mail.python.org/pipermail/python-dev/2014-January/131537.html

This surprises me, and rather than bother Python-Dev (where it will
likely be lost in the noise, and certain will be off-topic), I'm hoping
there may be someone here who is willing to attempt to channel GvR. I
would have thought that subclassing dict for the purpose of constraining
the type of keys or values would be precisely an excellent use of
subclassing.


class TextOnlyDict(dict):
 def __setitem__(self, key, value):
 if not isinstance(key, str):
 raise TypeError
 super().__setitem__(key, value)
 # need to override more methods too


But reading Guido, I think he's saying that wouldn't be a good idea. I
don't get it -- it's not a violation of the Liskov Substitution
Principle, because it's more restrictive, not less. What am I missing?




One problem with it is that there are lots of ways of setting values in 
the dict, and they don't use your __setitem__:


>>> tod = TextOnlyDict()
>>> tod.update({1: "haha"})
>>>

This is what you're getting at with your "need to override more methods 
too", but it turns out to be a pain to override enough methods.


I don't know if that is what Guido was getting at, I suspect he was 
talking at a more refined "principles of object design" level rather 
than "dicts don't happen to work that way" level.


Also, I've never done it, but I understand that deriving from 
collections.MutableMapping avoids this problem.


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

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


Chanelling Guido - dict subclasses

2014-01-14 Thread Steven D'Aprano
Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread 
discussion involving at least two PEPs, about bytes/str compatibility. 
But I don't want to talk about that. (Oh gods, I *really* don't want to 
talk about that...)

In the midst of that discussion, Guido van Rossum made a comment about 
subclassing dicts:

[quote]
From: Guido van Rossum 
Date: Tue, 14 Jan 2014 12:06:32 -0800
Subject: Re: [Python-Dev] PEP 460 reboot

Personally I wouldn't add any words suggesting or referring 
to the option of creation another class for this purpose. You 
wouldn't recommend subclassing dict for constraining the 
types of keys or values, would you?
[end quote]

https://mail.python.org/pipermail/python-dev/2014-January/131537.html

This surprises me, and rather than bother Python-Dev (where it will 
likely be lost in the noise, and certain will be off-topic), I'm hoping 
there may be someone here who is willing to attempt to channel GvR. I 
would have thought that subclassing dict for the purpose of constraining 
the type of keys or values would be precisely an excellent use of 
subclassing.


class TextOnlyDict(dict):
def __setitem__(self, key, value):
if not isinstance(key, str):
raise TypeError
super().__setitem__(key, value)
# need to override more methods too


But reading Guido, I think he's saying that wouldn't be a good idea. I 
don't get it -- it's not a violation of the Liskov Substitution 
Principle, because it's more restrictive, not less. What am I missing?


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


Re: python-list@python.org

2014-01-14 Thread Florian Lindner
Am Dienstag, 14. Januar 2014, 17:00:48 schrieb MRAB:
> On 2014-01-14 16:37, Florian Lindner wrote:
> > Hello!
> >
> > I'm using python 3.2.3 on debian wheezy. My script is called from my mail 
> > delivery agent (MDA) maildrop (like procmail) through it's xfilter 
> > directive.
> >
> > Script works fine when used interactively, e.g. ./script.py < testmail but 
> > when called from maildrop it's producing an infamous UnicodeDecodeError:
> >
> > File "/home/flindner/flofify.py", line 171, in main
> >   mail = sys.stdin.read()
> > File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode
> >   return codecs.ascii_decode(input, self.errors)[0]
> >
> > Exception for example is always like
> >
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: 
> > ordinal not in range(128)
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: 
> > ordinal not in range(128)
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: 
> > ordinal not in range(128)
> >
> > I read mail from stdin "mail = sys.stdin.read()"
> >
> > Environment when called is:
> >
> > locale.getpreferredencoding(): ANSI_X3.4-1968
> > environ["LANG"]: C
> >
> > System environment when using shell is:
> >
> > ~ % echo $LANG
> > en_US.UTF-8
> >
> > As far as I know when reading from stdin I don't need an decode(...) call, 
> > since stdin has a decoding. I also tried some decoding/encoding stuff but 
> > changed nothing.
> >
> > Any ideas to help me?
> >
> When run from maildrop it thinks that the encoding of stdin is ASCII.

Well, true. But what encoding does maildrop actually gives me? It obviously 
does not inherit LANG or is called from the MTA that way. I also tried:

inData = codecs.getreader('utf-8')(sys.stdin)   


 
mail = inData.read()


 

Failed also. But I'm not exactly an encoding expert.

Regards,
Florian

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


Re: dictionary with tuples

2014-01-14 Thread emile

On 01/14/2014 02:00 PM, Tobiah wrote:

On 01/14/2014 01:21 PM, YBM wrote:

Le 14/01/2014 22:10, Igor Korot a écrit :

Hi, ALL,
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.

dict = {}
dict[(1,2)] = ('a','b')
dict[(3,4)] = ('c','d')
for (key1,key2),(value1,value2) in dict:

... print key1, " ", key2
... print value1, " ", value2
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: 'int' object is not iterable




What am I doing wrong?


for ... in dict:

is a way to iterate through dictionnary items,

what you want to do can be done so:

for (key1,key2),(value1,value2) in dict.items():





But it's (key1, value1), (key2, value2)



No it isn't.  :)

Emile


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


Re: What's correct Python syntax?

2014-01-14 Thread emile

On 01/14/2014 02:05 PM, Terry Reedy wrote:

On 1/14/2014 3:46 AM, 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



However, I don't need all the protocol info. All I'm interested in is
the last field, which is length.


To directly extract only the needed info:

 >>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200,
length 30"
 >>> s[s.rindex(' ')+1:]
'30'


Any particular reason to prefer that over:

>>> s.split()[-1]
'30'

Is it a length of s and speed or rindex over build and toss the list 
kind of thing?


Emile




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


Re: L[:]

2014-01-14 Thread Terry Reedy

On 1/14/2014 5:42 AM, Albert-Jan Roskam wrote:


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)


[1] *is* the standard way to selectively replace items.


# [2]
L2 = []
for idx,item in enumerate(L):
if some_condition:
L2.append(foobarify(item))
else:
L2.append(item)


--
Terry Jan Reedy

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


Re: What's correct Python syntax?

2014-01-14 Thread Terry Reedy

On 1/14/2014 3:46 AM, 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



However, I don't need all the protocol info. All I'm interested in is
the last field, which is length.


To directly extract only the needed info:

>>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, 
length 30"

>>> s[s.rindex(' ')+1:]
'30'

--
Terry Jan Reedy

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


Re: dictionary with tuples

2014-01-14 Thread Tobiah

On 01/14/2014 01:21 PM, YBM wrote:

Le 14/01/2014 22:10, Igor Korot a écrit :

Hi, ALL,
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.

dict = {}
dict[(1,2)] = ('a','b')
dict[(3,4)] = ('c','d')
for (key1,key2),(value1,value2) in dict:

... print key1, " ", key2
... print value1, " ", value2
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: 'int' object is not iterable




What am I doing wrong?


for ... in dict:

is a way to iterate through dictionnary items,

what you want to do can be done so:

for (key1,key2),(value1,value2) in dict.items():





But it's (key1, value1), (key2, value2)
--
https://mail.python.org/mailman/listinfo/python-list


Re: python adsl script

2014-01-14 Thread Adnan Sadzak
Hi,

You need to find out what communication type your router supports (most use
telnet, ssh, or http). It is easy to implement
solution using any of these protocols. If You have problems in
implementation, maybe we can help You, but will not write code for You.

For password..khm...as Denis says use google.
You can start with some questions to yourself and google:  What password?
Bios, boot loader, OS...?
No1 will do this for You and this is not list for that type of questions.

Cheers




On Tue, Jan 14, 2014 at 6:27 PM, ngangsia akumbo  wrote:

> what about a python script that can retrieve my entire isp setting from my
> adsl router.
>
> Any ideas
>
> Also my grand mother forget her computer password, she can only login
> through the guest account. what about a script that can solve that problem.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter GUI Error

2014-01-14 Thread Christian Gollwitzer

Am 14.01.14 22:27, schrieb Lewis Wood:

Also anyone know how to create an entry box for Tkinter where you can only 
enter in 2 digits?

You must use a validator to achieve this. This is a more advanced topic 
though. A validator is a function that is called whenever the user keys 
something in - even by copy/pasting - and has to decide, whether this 
change is accepted or not. It is relatively easy to annoy your users if 
the validator is not written carefully. For instance, you must always 
accept th eempty string, otherwise the users won't be able to delete 
everything - very annoying behaviour.


See for example this SO question

http://stackoverflow.com/questions/4140437/python-tkinter-interactively-validating-entry-widget-content

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


Re:dictionary with tuples

2014-01-14 Thread Dave Angel
 Igor Korot  Wrote in message:
> Hi, ALL,
> 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.
 dict = {}
 dict[(1,2)] = ('a','b')
 dict[(3,4)] = ('c','d')
 for (key1,key2),(value1,value2) in dict:
> ... print key1, " ", key2
> ... print value1, " ", value2
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: 'int' object is not iterable

> 
> What am I doing wrong?
> 
> Thank you.
> 

Two things.   You really shouldn't shadow a builtin with your own
 locals,  though it hasn't hurt you this time. Next time pick a
 different name than dict.

Your real problem is that you're trying to iterate over items, 
 but forgot to use that method. The for loop line should
 end

 in dict.items () :


You may be confused,  since it's different in python 3.x

-- 
DaveA



Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

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


Re: setup.py issue - some files are included as intended, but one is not

2014-01-14 Thread Ethan Furman

On 01/14/2014 01:26 PM, Dan Stromberg wrote:

On Sat, Jan 11, 2014 at 2:04 PM, Dan Stromberg  wrote:

Hi folks.

I have a setup.py problem that's driving me nuts.


Anyone?  I've received 0 responses.


I have no answer, but forwarding to Distutils (hopefully it's an appropriate 
topic ;)



I have a treap.py file that tries to "import * from pyx_treap.so", and
failing that, it'll "import * from py_treap.py" (sans extensions of
course).  Naturally, all 3 of these should be included - although in
the case of pyx_treap.so, it probably should be a .c that's included.

It is also intended to include nest.py, which has a simple form.

Well, treap.py, nest.py and pyx_treap.c are included fine, but I can't
seem to get py_treap.py to be included for some reason.

I get no errors during "python setup.py sdist upload", but upon
"python $(which pip) install treap", I get:
$ sudo /usr/bin/python $(which pip) install treap
Downloading/unpacking treap
   Running setup.py egg_info for package treap

 file py_treap.py (for module py_treap) not found
Installing collected packages: treap
   Running setup.py install for treap
 file py_treap.py (for module py_treap) not found
 file py_treap.py (for module py_treap) not found

 file py_treap.py (for module py_treap) not found
 file py_treap.py (for module py_treap) not found
Successfully installed treap
Cleaning up...

And it's not successfully installed - py_treap.py is missing.  The pyx
code does its job, so the problem is masked, other than the messages
above, and the absence of py_treap.py from
/usr/local/lib/python2.7/dist-packages

I can clearly see py_treap.py in ./dist/treap-1.35.tar.gz - it's at
least getting packaged up that much.  It's not listed in
/usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/SOURCES.txt
, but I can see it in
/usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/top_level.txt
.

My setup.py is at:
http://stromberg.dnsalias.org/svn/treap/trunk/setup.py

I've tried that setup.py and several variations on that theme, but
none seem to include py_treap.py .

Please make some suggestions?  How can I get py_treap.py included in
the pip install?

Thanks!

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


Re: Tkinter GUI Error

2014-01-14 Thread Lewis Wood
Also anyone know how to create an entry box for Tkinter where you can only 
enter in 2 digits?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: setup.py issue - some files are included as intended, but one is not

2014-01-14 Thread Dan Stromberg
On Sat, Jan 11, 2014 at 2:04 PM, Dan Stromberg  wrote:
> Hi folks.
>
> I have a setup.py problem that's driving me nuts.

Anyone?  I've received 0 responses.

> I have a treap.py file that tries to "import * from pyx_treap.so", and
> failing that, it'll "import * from py_treap.py" (sans extensions of
> course).  Naturally, all 3 of these should be included - although in
> the case of pyx_treap.so, it probably should be a .c that's included.
>
> It is also intended to include nest.py, which has a simple form.
>
> Well, treap.py, nest.py and pyx_treap.c are included fine, but I can't
> seem to get py_treap.py to be included for some reason.
>
> I get no errors during "python setup.py sdist upload", but upon
> "python $(which pip) install treap", I get:
> $ sudo /usr/bin/python $(which pip) install treap
> Downloading/unpacking treap
>   Running setup.py egg_info for package treap
>
> file py_treap.py (for module py_treap) not found
> Installing collected packages: treap
>   Running setup.py install for treap
> file py_treap.py (for module py_treap) not found
> file py_treap.py (for module py_treap) not found
>
> file py_treap.py (for module py_treap) not found
> file py_treap.py (for module py_treap) not found
> Successfully installed treap
> Cleaning up...
>
> And it's not successfully installed - py_treap.py is missing.  The pyx
> code does its job, so the problem is masked, other than the messages
> above, and the absence of py_treap.py from
> /usr/local/lib/python2.7/dist-packages
>
> I can clearly see py_treap.py in ./dist/treap-1.35.tar.gz - it's at
> least getting packaged up that much.  It's not listed in
> /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/SOURCES.txt
> , but I can see it in
> /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/top_level.txt
> .
>
> My setup.py is at:
> http://stromberg.dnsalias.org/svn/treap/trunk/setup.py
>
> I've tried that setup.py and several variations on that theme, but
> none seem to include py_treap.py .
>
> Please make some suggestions?  How can I get py_treap.py included in
> the pip install?
>
> Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: dictionary with tuples

2014-01-14 Thread YBM

Le 14/01/2014 22:10, Igor Korot a écrit :

Hi, ALL,
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.

dict = {}
dict[(1,2)] = ('a','b')
dict[(3,4)] = ('c','d')
for (key1,key2),(value1,value2) in dict:

... print key1, " ", key2
... print value1, " ", value2
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: 'int' object is not iterable




What am I doing wrong?


for ... in dict:

is a way to iterate through dictionnary items,

what you want to do can be done so:

for (key1,key2),(value1,value2) in dict.items():



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


Re: dictionary with tuples

2014-01-14 Thread MRAB

On 2014-01-14 21:10, Igor Korot wrote:

Hi, ALL,
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.

dict = {}
dict[(1,2)] = ('a','b')
dict[(3,4)] = ('c','d')
for (key1,key2),(value1,value2) in dict:

... print key1, " ", key2
... print value1, " ", value2
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: 'int' object is not iterable




What am I doing wrong?

Thank you.


When you iterate over a dict it yields the only the keys, not the keys
and values. Try iterating over dict.items() instead.

By the way, try not to use names such as 'dict' that are the names of
built-in classes.
--
https://mail.python.org/mailman/listinfo/python-list


Re: dictionary with tuples

2014-01-14 Thread Tim Chase
On 2014-01-14 13:10, Igor Korot wrote:
> Hi, ALL,
> 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.
> >>> dict = {}
> >>> dict[(1,2)] = ('a','b')
> >>> dict[(3,4)] = ('c','d')
> >>> for (key1,key2),(value1,value2) in dict:
> 
> What am I doing wrong?

You should iterate over either dict.items() or dict.iteritems()

Also, it's bad practice to shadow the builtin "dict()", so I'd choose
another name:

  d = {}
  d[(1, 2)] = ('a', 'b')
  d[(3, 4)] = ('c', 'd')
  for (k1, k2), (v1, v2) in d.iteritems():
do_something(k1, k2, v1, v2)

-tkc


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


Re: dictionary with tuples

2014-01-14 Thread Larry Martell
On Tue, Jan 14, 2014 at 2:10 PM, Igor Korot  wrote:
> Hi, ALL,
> 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.
 dict = {}
 dict[(1,2)] = ('a','b')
 dict[(3,4)] = ('c','d')
 for (key1,key2),(value1,value2) in dict:
> ... print key1, " ", key2
> ... print value1, " ", value2
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: 'int' object is not iterable

>
> What am I doing wrong?

You need to iterate over dict.items()
-- 
https://mail.python.org/mailman/listinfo/python-list


dictionary with tuples

2014-01-14 Thread Igor Korot
Hi, ALL,
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.
>>> dict = {}
>>> dict[(1,2)] = ('a','b')
>>> dict[(3,4)] = ('c','d')
>>> for (key1,key2),(value1,value2) in dict:
... print key1, " ", key2
... print value1, " ", value2
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not iterable
>>>

What am I doing wrong?

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


setup.py install and compile errors

2014-01-14 Thread David

How does a setup script conditionally change what modules are installed based 
on version?


Background:

  I have a python2.x/3.x module that puts 3.3-only code in submodules.  When 
the module imports those submodules using an older python version, the compiler 
raises SyntaxErrors in the submodule which show as import errors in the module, 
get caught and ignored.  The features in the submodule won't be available, but 
they wont stop the module from functioning.  The problem syntax to be masked is 
the 'yield from' expression.

Problem:

  Thie above works, resulting in a functioning module under a range of python 
versions, but older versions want to compile all .py modules as part of 
setup.py install, and that produces ugly install messages, with stack-traces.  
I would like to avoid the ugliness.

  I can add python code to setup.py, before the setup(...) call, but it is 
unclear what will be available to that code, at that time.  I can test for 
whether setup.py is being run in install mode using "if 'install' in 
sys.argv:", and delete the offending .py submodules, but can I assume that the 
dir holding setup.py is the current dir during install?  Does the MANIFEST need 
to be altered, also, to match the changed file collection?

Alternatively, I could alter the MANIFEST.in to add 'prune..' statements, but 
is that file even used as part of install?

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


Re: fork seems to make urlopen into a black hole?

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 7:04 AM, BobAalsma  wrote:
> A program took much too long to check some texts collected from web pages.
> As this could be made parallel easily, I put in fork.

Rather than using the low-level fork() function, you may find it
easier to manage things if you use the multiprocessing module. I don't
know if it'll help in this specific case, but if nothing else, it'll
be easier to see what's going on.

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


fork seems to make urlopen into a black hole?

2014-01-14 Thread BobAalsma
A program took much too long to check some texts collected from web pages.
As this could be made parallel easily, I put in fork.
And the result seems to be that the program simply stops in the line with 
urlopen. Any suggestions?

Relevant part:

try:
print 'urlopen by', kind_nummer, '- before'
extern_adres = urlopen(adres).geturl()
print 'urlopen by', kind_nummer, '- after'
except IOError:
tekst_string = 'URL "' + adres +'" geeft IO Error'
print tekst_string, 'door', kind_nummer
bloklijst_verslag.append(tekst_string + '\n')
tekst_string = '\t Deze pagina wordt overgeslagen\n'
bloklijst_verslag.append(tekst_string + '\n')
adres = ''
except:
fout = sys.exc_info()[:2]
tekst_string = 'URL "' + adres + '" geeft fout ' + fout
print tekst_string, 'door', kind_nummer
bloklijst_verslag.append(tekst_string + '\n')
tekst_string = '\t Deze pagina wordt overgeslagen\n'
bloklijst_verslag.append(tekst_string + '\n')
adres = ''
else:
print 'urlopen by', kind_nummer, '- else'
if extern_adres != adres:
tekst_string = '\t redirect naar ' + extern_adres
bloklijst_verslag.append(tekst_string + '\n')

>From this block, the only response seen is the first print statement ("url 
>open by  - before") and then nothing else seems to happen in that child.
This happens for all children: the expected number of children is reached and 
they all reach (only) this point.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Printer list value problem

2014-01-14 Thread Mark Lawrence

On 14/01/2014 19:54, Mike wrote:

El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB  escribió:

On 2014-01-14 19:24, Mike wrote:


Hello,



I confudsed,need printer the value of list (this is reaer from csv) . The 
reader is ok, but my problem is in the print moment because printer only the 
last value. For example my csv is:







[]



us...@example.com;user1;lastName;Name



us...@example.com;user2;lastName;Name



[]







But when execute the script I view the print is only the last user







[]



ca us...@example.com displayName 'user2' sn 'lastName' cn 'Name'



[]







And I need the next printer







[]



ca us...@example.com displayName 'User1' sn ''lastName" cn 'Name'



ca us...@example.com displayName 'User2' sn ''lastName" cn 'Name'



[]







My script is







[]



#!/usr/bin/python



import csv



with open ('users.csv', 'rb') as f:







  reader = csv.reader (f, delimiter=';' ) #delimiter tabulador



  for row in reader:







  mail = row [0]



  name = row [3]



  lastname = row [2]








This line is indented the same amount as the 'for' loop, which means

that it will be executed after the loop has finished.




  print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)






You don't need to close the file here because the 'with' statement will

do that for you.




f.close()



[]











Thanks.






Hello MRAB,
I remove the "f.close" and after execute the script but still i have the same 
result (print the last row)

Thanks



Your print statement needs to be inside the for loop, you currently have 
it after the loop has finished.


Would you also please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing above, thanks.


--
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: Printer list value problem

2014-01-14 Thread Mike
El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB  escribió:
> On 2014-01-14 19:24, Mike wrote:
> 
> > Hello,
> 
> > I confudsed,need printer the value of list (this is reaer from csv) . The 
> > reader is ok, but my problem is in the print moment because printer only 
> > the last value. For example my csv is:
> 
> >
> 
> > []
> 
> > us...@example.com;user1;lastName;Name
> 
> > us...@example.com;user2;lastName;Name
> 
> > []
> 
> >
> 
> > But when execute the script I view the print is only the last user
> 
> >
> 
> > []
> 
> > ca us...@example.com displayName 'user2' sn 'lastName' cn 'Name'
> 
> > []
> 
> >
> 
> > And I need the next printer
> 
> >
> 
> > []
> 
> > ca us...@example.com displayName 'User1' sn ''lastName" cn 'Name'
> 
> > ca us...@example.com displayName 'User2' sn ''lastName" cn 'Name'
> 
> > []
> 
> >
> 
> > My script is
> 
> >
> 
> > []
> 
> > #!/usr/bin/python
> 
> > import csv
> 
> > with open ('users.csv', 'rb') as f:
> 
> >
> 
> >  reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
> 
> >  for row in reader:
> 
> >
> 
> >  mail = row [0]
> 
> >  name = row [3]
> 
> >  lastname = row [2]
> 
> >
> 
> 
> 
> This line is indented the same amount as the 'for' loop, which means
> 
> that it will be executed after the loop has finished.
> 
> 
> 
> >  print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)
> 
> >
> 
> You don't need to close the file here because the 'with' statement will
> 
> do that for you.
> 
> 
> 
> > f.close()
> 
> > []
> 
> >
> 
> >
> 
> > Thanks.
> 
> >

Hello MRAB,
I remove the "f.close" and after execute the script but still i have the same 
result (print the last row)

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


Re: Python 3.x adoption

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 6:33 AM, Staszek  wrote:
> What's the problem with Python 3.x? It was first released in 2008, but
> web hosting companies still seem to offer Python 2.x rather.
>
> For example, Google App Engine only offers Python 2.7.
>
> What's wrong?...

There's nothing wrong with Python 3, but as Skip says, it takes time
for people to migrate.

Most cheap web hosts don't offer Python _at all_, but those that do
have the choice of which version(s) to provide. It may be possible to
call up either a 2.x or a 3.x by looking for "python" or "python3" -
give it a try.

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


Re: Python 3.x adoption

2014-01-14 Thread Skip Montanaro
> What's the problem with Python 3.x? It was first released in 2008, but
> web hosting companies still seem to offer Python 2.x rather.
>
> For example, Google App Engine only offers Python 2.7.
>
> What's wrong?...

What makes you think anything's wrong? Major changes to any
established piece of software takes a fairly long while to infiltrate.
Lots of COBOL and Fortran 77 still running out there. I imagine there
are still more than a few DOS and Windows 3.1 boxes as well. Why
should adoption of Python 3.x be any different?

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


Re: Printer list value problem

2014-01-14 Thread Tim Chase
On 2014-01-14 11:24, Mike wrote:
> Hello,
> I confudsed,need printer the value of list (this is reaer from
> csv) . The reader is ok, but my problem is in the print moment
> because printer only the last value. For example my csv is:
> 
> []
> us...@example.com;user1;lastName;Name
> us...@example.com;user2;lastName;Name
> []
> 
> But when execute the script I view the print is only the last user
> with open ('users.csv', 'rb') as f:
> 
> reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
> for row in reader:
> 
> mail = row [0]
> name = row [3]
> lastname = row [2]
> 
> print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)

This print needs to be at the same indentation as the previous bit.


> f.close()

This .close() is superfluous--the "with" takes care of that for you.

I'd also unpack the row as I iterate to make it easier to read.  That
would make the final look something like

  with open("users.csv", "rb") as f:
reader = csv.reader(f, delimiter=';')
for mail, _, lastname, name in reader:
  print "ca {} displayName '{}' sn '{}'".format(
mail, name, lastname)

-tkc



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


Re: Printer list value problem

2014-01-14 Thread MRAB

On 2014-01-14 19:24, Mike wrote:

Hello,
I confudsed,need printer the value of list (this is reaer from csv) . The 
reader is ok, but my problem is in the print moment because printer only the 
last value. For example my csv is:

[]
us...@example.com;user1;lastName;Name
us...@example.com;user2;lastName;Name
[]

But when execute the script I view the print is only the last user

[]
ca us...@example.com displayName 'user2' sn 'lastName' cn 'Name'
[]

And I need the next printer

[]
ca us...@example.com displayName 'User1' sn ''lastName" cn 'Name'
ca us...@example.com displayName 'User2' sn ''lastName" cn 'Name'
[]

My script is

[]
#!/usr/bin/python
import csv
with open ('users.csv', 'rb') as f:

 reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
 for row in reader:

 mail = row [0]
 name = row [3]
 lastname = row [2]



This line is indented the same amount as the 'for' loop, which means
that it will be executed after the loop has finished.


 print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)


You don't need to close the file here because the 'with' statement will
do that for you.


f.close()
[]


Thanks.



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


Python 3.x adoption

2014-01-14 Thread Staszek
Hi

What's the problem with Python 3.x? It was first released in 2008, but
web hosting companies still seem to offer Python 2.x rather.

For example, Google App Engine only offers Python 2.7.

What's wrong?...

-- 
http://people.eisenbits.com/~stf/
http://www.eisenbits.com/

OpenPGP: 80FC 1824 2EA4 9223 A986  DB4E 934E FEA0 F492 A63B
-- 
https://mail.python.org/mailman/listinfo/python-list


Printer list value problem

2014-01-14 Thread Mike
Hello,
I confudsed,need printer the value of list (this is reaer from csv) . The 
reader is ok, but my problem is in the print moment because printer only the 
last value. For example my csv is:

[]
us...@example.com;user1;lastName;Name
us...@example.com;user2;lastName;Name
[]

But when execute the script I view the print is only the last user

[]
ca us...@example.com displayName 'user2' sn 'lastName' cn 'Name'
[]

And I need the next printer

[]
ca us...@example.com displayName 'User1' sn ''lastName" cn 'Name'
ca us...@example.com displayName 'User2' sn ''lastName" cn 'Name'
[]

My script is 

[]
#!/usr/bin/python
import csv
with open ('users.csv', 'rb') as f:

reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
for row in reader:

mail = row [0]
name = row [3]
lastname = row [2]

print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)

f.close()
[]


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


On how to use cxFreeze

2014-01-14 Thread eneskristo
For the first time in my life as a novice Python developer, I need to convert a 
python file to a .exe (AKA freeze it). Have been having a lot of problems in 
finding a proper guide, and have come here to ask for your help humbly. I am 
willing to provide any data if needed. Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter GUI Error

2014-01-14 Thread Lewis Wood
I cannot say how grateful I am to find such a community willing to help <3 
Thanks to everyone posting, learned a lot of new stuff :) Never knew you could 
just bring a local var into a def block using global inside of the function. 
Again, thanks for taking your time to help out newbies to programming such as 
myself.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Encoding trouble when script called from application

2014-01-14 Thread Peter Otten
Florian Lindner wrote:

> Hello!
> 
> I'm using python 3.2.3 on debian wheezy. My script is called from my mail
> delivery agent (MDA) maildrop (like procmail) through it's xfilter
> directive.
> 
> Script works fine when used interactively, e.g. ./script.py < testmail but
> when called from maildrop it's producing an infamous UnicodeDecodeError:
> 
> File "/home/flindner/flofify.py", line 171, in main
>  mail = sys.stdin.read()
> File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode
>  return codecs.ascii_decode(input, self.errors)[0]
> 
> Exception for example is always like
> 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869:
> ordinal not in range(128) UnicodeDecodeError: 'ascii' codec can't decode
> byte 0xc3 in position 1176: ordinal not in range(128) UnicodeDecodeError:
> 'ascii' codec can't decode byte 0x8c in position 846: ordinal not in
> range(128)
> 
> I read mail from stdin "mail = sys.stdin.read()"
> 
> Environment when called is:
> 
> locale.getpreferredencoding(): ANSI_X3.4-1968
> environ["LANG"]: C
> 
> System environment when using shell is:
> 
> ~ % echo $LANG
> en_US.UTF-8
> 
> As far as I know when reading from stdin I don't need an decode(...) call,
> since stdin has a decoding. I also tried some decoding/encoding stuff but
> changed nothing.
> 
> Any ideas to help me?

I known nothing about maildrop, but found

> add "import LANG" to .maildropfilter.

in this thread:



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


Re: python adsl script

2014-01-14 Thread Stephane Wirtel


+1

> On 14 janv. 2014, at 06:30 PM, Denis McMahon  wrote:
> 
>> On Tue, 14 Jan 2014 09:27:07 -0800, ngangsia akumbo wrote:
>> 
>> what about a python script that can retrieve my entire isp setting from
>> my adsl router.
> 
>> Any ideas
> 
> This is probably possible using telnet, so it should be possible to do it 
> over a socket interface, yes.
> 
>> Also my grand mother forget her computer password, she can only login
>> through the guest account. what about a script that can solve that
>> problem.
> 
> We are not your familiy's tech support group. Nor will we write your code 
> from scratch for you.
> 
> I suggest you learn to google. There are plenty of tools out there that 
> can be used to reset passwords on various operating systems.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: wx (not responding)

2014-01-14 Thread ngangsia akumbo
On Tuesday, January 14, 2014 4:56:42 PM UTC+1, cassiope wrote:
> On Tue, 14 Jan 2014 07:26:10 -0800, ngangsia akumbo wrote:

 
> Not sure whether your wx version might have a 'Mainloop'.

I think is ok now thanks

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


Re: python adsl script

2014-01-14 Thread Denis McMahon
On Tue, 14 Jan 2014 09:27:07 -0800, ngangsia akumbo wrote:

> what about a python script that can retrieve my entire isp setting from
> my adsl router.

> Any ideas

This is probably possible using telnet, so it should be possible to do it 
over a socket interface, yes.

> Also my grand mother forget her computer password, she can only login
> through the guest account. what about a script that can solve that
> problem.

We are not your familiy's tech support group. Nor will we write your code 
from scratch for you.

I suggest you learn to google. There are plenty of tools out there that 
can be used to reset passwords on various operating systems.

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


python adsl script

2014-01-14 Thread ngangsia akumbo
what about a python script that can retrieve my entire isp setting from my adsl 
router.

Any ideas

Also my grand mother forget her computer password, she can only login through 
the guest account. what about a script that can solve that problem.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread Norman Elliott
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]

Okay, maybe I misunderstood what it was doing. I have checked and I will do a 
find and replace of the tabs with 4 spaces in future. 
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Python Events Calendar - Please submit your 2014 events

2014-01-14 Thread M.-A. Lemburg
[Please help spread the word by forwarding to other relevant mailing lists,
 user groups, etc. world-wide; thanks :-)]


ANNOUNCING

 Python Events Calendars - Please submit your 2014 events

   maintained by the Python Software Foundation (PSF)
and a group of volunteers


INTRODUCTION

As some of you may know, the PSF has put together a team of volunteers
who are maintaining a central Python events calendar. We currently have
two calendars in place:

 * Python Events Calendar - meant for conferences and larger gatherings
   focusing on Python or a related technology (in whole or in part)

 * Python User Group Calendar - meant for user group events and other
   smaller local events

The calendars are displayed on http://pycon.org/ and in a smaller
version in the sidebar of the http://python.org/ website.

You can subscribe to the calendars using iCal and RSS feeds and
also embed the calendar widgets on your sites. Please see our wiki
page for details:

https://wiki.python.org/moin/PythonEventsCalendar

The calendars are open to the world-wide Python community, so you
can have local user group events, as well as regional and international
conference events added to the calendars.


NEWS

Created in Oct 2012, the project has been proven to be a success as
you can see in the past events listed in the calendars.

We would like to encourage everyone to submit their 2014 events,
so that the Python community can get a better overview over what's
happening in Python land.


ADDING EVENTS

If you want to have entries added to those calendars, please write
to eve...@python.org and include the following information:

 * Name of the event
 * Type of the event (conference, bar camp, user group, etc)
 * Focus on Python and approximate size
 * URL
 * Location and country
 * Date and time (if relevant)

For recurring events, please also include a description of the
recurrence in a way that's compatible and supported by Google
calendars.


MORE INFORMATION

More information on the calendars, the URLs, feed links, IDs, embedding,
etc. is available on the wiki:

https://wiki.python.org/moin/PythonEventsCalendar

Enjoy,
-- 
Marc-Andre Lemburg
Director
Python Software Foundation
http://www.python.org/psf/
-- 
https://mail.python.org/mailman/listinfo/python-list


python-list@python.org

2014-01-14 Thread MRAB

On 2014-01-14 16:37, Florian Lindner wrote:

Hello!

I'm using python 3.2.3 on debian wheezy. My script is called from my mail 
delivery agent (MDA) maildrop (like procmail) through it's xfilter directive.

Script works fine when used interactively, e.g. ./script.py < testmail but when 
called from maildrop it's producing an infamous UnicodeDecodeError:

File "/home/flindner/flofify.py", line 171, in main
  mail = sys.stdin.read()
File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]

Exception for example is always like

UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: 
ordinal not in range(128)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: 
ordinal not in range(128)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: 
ordinal not in range(128)

I read mail from stdin "mail = sys.stdin.read()"

Environment when called is:

locale.getpreferredencoding(): ANSI_X3.4-1968
environ["LANG"]: C

System environment when using shell is:

~ % echo $LANG
en_US.UTF-8

As far as I know when reading from stdin I don't need an decode(...) call, 
since stdin has a decoding. I also tried some decoding/encoding stuff but 
changed nothing.

Any ideas to help me?


When run from maildrop it thinks that the encoding of stdin is ASCII.

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


Re: efficient way to process data

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 3:23 AM, Larry Martell  wrote:
>> 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.
>
> Thanks! You made my day. I showed this to my wife and she asked "Is that 
> good?"

Heh! Geek language can be a bit weird at times. Of course, it's not a
dream job if things like this get tantalizingly dangled in front of
you and then taken away as you're given something less fun and more
urgent to do...

>> 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?
>
> Either coordinate.

Okay, so the code I put together earlier in the thread is correct.

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


Encoding trouble when script called from application

2014-01-14 Thread Florian Lindner
Hello!

I'm using python 3.2.3 on debian wheezy. My script is called from my mail 
delivery agent (MDA) maildrop (like procmail) through it's xfilter directive.

Script works fine when used interactively, e.g. ./script.py < testmail but when 
called from maildrop it's producing an infamous UnicodeDecodeError:

File "/home/flindner/flofify.py", line 171, in main
 mail = sys.stdin.read()
File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode
 return codecs.ascii_decode(input, self.errors)[0]

Exception for example is always like

UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: 
ordinal not in range(128) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: 
ordinal not in range(128)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: 
ordinal not in range(128)

I read mail from stdin "mail = sys.stdin.read()"

Environment when called is:

locale.getpreferredencoding(): ANSI_X3.4-1968
environ["LANG"]: C

System environment when using shell is:

~ % echo $LANG
en_US.UTF-8

As far as I know when reading from stdin I don't need an decode(...) call, 
since stdin has a decoding. I also tried some decoding/encoding stuff but 
changed nothing.

Any ideas to help me?

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


Re: efficient way to process data

2014-01-14 Thread Larry Martell
On Tue, Jan 14, 2014 at 7:26 AM, Chris Angelico  wrote:
> On Wed, Jan 15, 2014 at 1:18 AM, Larry Martell  
> 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.

Thanks! You made my day. I showed this to my wife and she asked "Is that good?"

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

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


Re: wx (not responding)

2014-01-14 Thread Frank Miles
On Tue, 14 Jan 2014 07:26:10 -0800, ngangsia akumbo wrote:

> When i run this code on my pc it actually runs but signals that the app is 
> not responding.

[snip most of the code]-

> def main():
> ex = wx.App()
> Example(None)
> ex.Mainloop()
> 
> 
> if __name__ == "__main__":
> main()

When I tried to run it I got a 
"AttributeError: 'App' object has no attribute 'Mainloop'

Not sure whether your wx version might have a 'Mainloop'.
-- 
https://mail.python.org/mailman/listinfo/python-list


wx (not responding)

2014-01-14 Thread ngangsia akumbo
When i run this code on my pc it actually runs but signals that the app is not 
responding.


import wx

class Example(wx.Frame):

def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
  

self.InitUI()



def InitUI(self):

 
 menubar = wx.MenuBar()
 fileMenu = wx.Menu()
 fitem = fileMenu.Append(wx.ID_EXIT, 'QUIT', 'Quit application')
 menubar.Append(fileMenu, '&File')

 self.Bind(wx.EVT_MENU, self.OnQuit, fitem)


 self.SetSize((300, 200))
 self.SetTitle('Simple menu')
 self.Center()
 self.Show(True)



def OnQuit(self, e):
self.Close()



def main():
ex = wx.App()
Example(None)
ex.Mainloop()


if __name__ == "__main__":
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Fast I/o

2014-01-14 Thread Tim Chase
On 2014-01-14 05:50, Ayushi Dalmia 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()
> 
> where data is a list of strings which I want to dump into the
> index.txt file -- 

Most file-like objects should support a writelines() method which
takes an iterable and should save you the trouble of joining all the
content (and as Chris noted, you don't need the .close() since the
with handles it) so the whole thing would condense to:

  with open('index.txt', 'w') as f:
f.writelines(data)

-tkc


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


Re: Python Fast I/o

2014-01-14 Thread Roy Smith
In article <53affb01-0c5e-46e3-9ff7-27a529db6...@googlegroups.com>,
 Ayushi Dalmia  wrote:

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

This sounds like a simple experiment to try.  Write it both ways, time 
each one, and report your results back to the group.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Fast I/o

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 1:24 AM, Ayushi Dalmia
 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
>>
>>  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: efficient way to process data

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 1:18 AM, Larry Martell  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Fast I/o

2014-01-14 Thread 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
> 
>  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?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: efficient way to process data

2014-01-14 Thread Larry Martell
On Mon, Jan 13, 2014 at 11:32 AM, Chris Angelico  wrote:
> On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell  
> 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Fast I/o

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia
 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Fast I/o

2014-01-14 Thread 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread Roy Smith
In article ,
 Igor Korot  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}
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 12:15 AM, Rustom Mody  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread Roy Smith
In article ,
 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.

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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a web UI to invoke a python script at server side

2014-01-14 Thread 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread 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]

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


a web UI to invoke a python script at server side

2014-01-14 Thread 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   -- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread 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

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


Re: What's correct Python syntax?

2014-01-14 Thread Peter Otten
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 "", line 1, in 
> 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')



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


Stopping a wsgiref server programmatically

2014-01-14 Thread 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread 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"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: L[:]

2014-01-14 Thread 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)


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


Re: What's correct Python syntax?

2014-01-14 Thread Igor Korot
Hi, Rustom,

On Tue, Jan 14, 2014 at 2:16 AM, Rustom Mody  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread Igor Korot
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]
Traceback (most recent call last):
  File "", line 1, in 
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: What's correct Python syntax?

2014-01-14 Thread Igor Korot
Sorry, that was sent to Mark directly.
Resending to the list.


-- Forwarded message --
From: Igor Korot 
Date: Tue, Jan 14, 2014 at 1:50 AM
Subject: Re: What's correct Python syntax?
To: Mark Lawrence 


Hi, Mark,

On Tue, Jan 14, 2014 at 1:37 AM, Mark Lawrence  wrote:
> On 14/01/2014 09:25, Igor Korot wrote:
>>
>> Hi, Rustom,
>>
>> On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody 
>> 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 "", line 1, in 
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread Jussi Piitulainen
Chris Angelico writes:

> Alternatively, you can split on the space and take just the very
> last word:
> 
> for data in f:
> length = data.split(" ")[-1]
> # process length

Also, data.rsplit(' ', 1) will split data in two at the last space.

help(str.rsplit)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread Rustom Mody
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!

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

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


Re: What's correct Python syntax?

2014-01-14 Thread Mark Lawrence

On 14/01/2014 09:25, Igor Korot wrote:

Hi, Rustom,

On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody  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.


--
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:plotting slows down

2014-01-14 Thread Dave Angel
 Steven D'Aprano  Wrote in message:
> On Mon, 13 Jan 2014 08:26:11 -0500, Dave Angel wrote:
> 
>> norman.elli...@gmail.com Wrote in message:
> 
>>> [code]
>>> #!/usr/bin/python
>>> from graphics import *
>> 
>> First things first. what operating system are you using,  and
>>  where did you get the mysterious graphics. py?  Thanks for telling us
>>  python 2.7.3
>> 
>> Next, please repost any source code with indentation preserved.
> 
> He did. If you look at the original message as posted to python-
> l...@python.org and comp.lang.python, e.g. here:
> 
> https://mail.python.org/pipermail/python-list/2014-January/664430.html
> 
> you will see that the message is correctly indented with tabs.
> 
>>  Your message shows it all flushed to the left margin,  probably due to
>>  posting in html mode. Use text mode here.
> 
> Looks like perhaps Gmane is stripping tabs from their mirror. You should 
> report that as a bug to them.
> 
> 
> 

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.
 

-- 
DaveA



Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

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


Re: plotting slows down

2014-01-14 Thread Dave Angel
 Norman Elliott  Wrote in message:
> 
> I cannot see how to change from html to text mode in chromium or within the 
> group.
> 

You already did post in text mode, my error. The new newsreader
 I'm using apparently eats tabs.

-- 
DaveA



Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

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


Re: What's correct Python syntax?

2014-01-14 Thread Igor Korot
Hi, Rustom,

On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's correct Python syntax?

2014-01-14 Thread Chris Angelico
On Tue, Jan 14, 2014 at 7:46 PM, Igor Korot  wrote:
> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30
>
> However, I don't need all the protocol info. All I'm interested in is
> the last field, which is length.

You can split on any string. If you're confident that this is the only
instance of the word "length", you can split on that:

for data in f:
# This will throw an exception if there's no " length "
# or if there are two of them. This means you're safe;
#  if anything unexpected happens, you'll know.
_, length = data.split(" length ")
# process length

Alternatively, you can split on the space and take just the very last word:

for data in f:
length = data.split(" ")[-1]
# process length

Either way, the length will be a string. If you need it as an integer,
just do this:

length = int(length)

>From there, you can do whatever analysis you need.

Hope that helps!

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


Re: What's correct Python syntax?

2014-01-14 Thread Rustom Mody
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'
>>> 
-- 
https://mail.python.org/mailman/listinfo/python-list


What's correct Python syntax?

2014-01-14 Thread Igor Korot
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.
-- 
https://mail.python.org/mailman/listinfo/python-list