Re: Strange behavior with sort()

2014-02-26 Thread Larry Hudson
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: it doesn't work, the test always fails. Why ? Thx sort() sorts the sequence in pla

Re: Strange behavior with sort()

2014-02-26 Thread Gary Herron
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: Most such questions can be answered by printing out the values in question and observi

Re: Strange behavior with sort()

2014-02-26 Thread ast
Thanks for the very clear explanation -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior with sort()

2014-02-26 Thread Marko Rauhamaa
"ast" : > if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? The list.sort() method returns None. The builtin sorted() function returns a list: if sorted(box) == [1, 2, 3]: would work. Note that the list.sort() method is often preferred because

Re: Strange behavior with sort()

2014-02-26 Thread Lele Gaifax
"ast" writes: > If I write: > >box.sort() >if box == [1, 2, 3]: > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? Because very often methods **dont't** return the object they are applied (self that is).

Re: Strange behavior with sort()

2014-02-26 Thread Eduardo A . Bustamante López
On Thu, Feb 27, 2014 at 07:24:24AM +0100, ast wrote: > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Wh

Re: Strange behavior with sort()

2014-02-26 Thread Frank Millman
"ast" wrote in message news:530eda1d$0$2061$426a7...@news.free.fr... > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test alwa

Deepcopying a byte string is quicker than copying it - problem?

2014-02-26 Thread Frank Millman
Hi all I noticed this a little while ago, but dismissed it as a curiosity. On reflection, I decided to mention it here in case it indicates a problem. This is with python 3.3.2. C:\>python -m timeit -s "import copy" "copy.copy('a'*1000)" 10 loops, best of 3: 6.91 usec per loop C:\>python -

Strange behavior with sort()

2014-02-26 Thread ast
Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: it doesn't work, the test always fails. Why ? Thx -- https://mail.python.org/mailman/listinfo/python-list

Re: exec and locals

2014-02-26 Thread Chris Angelico
On Thu, Feb 27, 2014 at 3:47 PM, Steven D'Aprano wrote: > Guys, I know that exec is kinda dangerous and newbies should be > discouraged from throwing every string they see at it, but this isn't my > second day Python programming, and it's not an accident that Python > supports the dynamic compilat

Re: exec and locals

2014-02-26 Thread Steven D'Aprano
On Wed, 26 Feb 2014 23:20:10 -0500, Dave Angel wrote: > Before I would use exec, I'd look hard at either generating a > source file to import, Yes, I went through the process of pulling out the code into a separate module, but that just made more complexity and was pretty nasty. If the func

Re: exec and locals

2014-02-26 Thread Steven D'Aprano
On Thu, 27 Feb 2014 16:34:33 +1300, Gregory Ewing wrote: > Steven D'Aprano wrote: >> except SyntaxError: >> def inner(): >> # manually operate the context manager call context manager >> __enter__ >> try: >> try: >>

Re: python

2014-02-26 Thread prashanth B.G
Hi Karthik, Good that you have interest in switching to dev from admin stuff. Since you are already an admin , you wouldn't have problems with administrating an os (probabally weblogic deployment was on an ux/linux machine) or a database. The requirements that you see are a mix of dif

Re: exec and locals

2014-02-26 Thread Dave Angel
Steven D'Aprano Wrote in message: > On Wed, 26 Feb 2014 14:46:39 +0100, Peter Otten wrote: > >> Steven D'Aprano wrote: >> >>> I have to dynamically generate some code inside a function using exec, >>> but I'm not sure if it is working by accident or if I can rely on it. >>> >> I eventually set

Re: exec and locals

2014-02-26 Thread Dan Sommers
On Thu, 27 Feb 2014 00:25:45 +, Steven D'Aprano wrote: > By the way, if anyone cares what my actual use-case is, I have a > function that needs to work under Python 2.4 through 3.4, and it uses > a with statement. With statements are not available in 2.4 (or 2.5, > unless you give a from __fut

Re: exec and locals

2014-02-26 Thread Gregory Ewing
Steven D'Aprano wrote: except SyntaxError: def inner(): # manually operate the context manager call context manager __enter__ try: try: return something except: # Yes, a bare except. Catch EVERYTH

Re: Functions help

2014-02-26 Thread rurpy
On 02/25/2014 07:52 PM, Ethan Furman wrote: > On 02/23/2014 08:01 PM, ru...@yahoo.com wrote: >> On 02/23/2014 08:21 PM, Mark Lawrence wrote: >>> On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: > On 24/02/2014 11:09 AM, Mark Lawrence wrote: >>

Re: exec and locals

2014-02-26 Thread Steven D'Aprano
On Wed, 26 Feb 2014 14:00:59 +, Alister wrote: > On Wed, 26 Feb 2014 13:15:25 +, Steven D'Aprano wrote: > >> I have to dynamically generate some code inside a function using exec, >> but I'm not sure if it is working by accident or if I can rely on it. [...] > I have no idea but as exec

Re: exec and locals

2014-02-26 Thread Steven D'Aprano
On Wed, 26 Feb 2014 14:46:39 +0100, Peter Otten wrote: > Steven D'Aprano wrote: > >> I have to dynamically generate some code inside a function using exec, >> but I'm not sure if it is working by accident or if I can rely on it. >> >> Here is a trivial example: >> >> >> py> def spam(): >> ...

Re: Issue 7503

2014-02-26 Thread Ned Deily
In article , Mark Lawrence wrote: > I'm not sure where to flag this up so reckon here's as good a place as > any. I noticed this afternoon 26/02/2014 between 16:05 and 16:09 four > messages on the bug tracker mailing list about the subject issue, but > http://bugs.python.org/issue7503 has not

Re: Can global variable be passed into Python function?

2014-02-26 Thread MRAB
On 2014-02-26 10:59, Gregory Ewing wrote: Steven D'Aprano wrote: Standard Pascal? Who uses standard Pascal? I'm talking about MacPascal :-) Mac Pascal used @ for getting a pointer to a variable, if I remember rightly. So did Turbo Pascal. Delphi, which is what Turbo Pascal became, is the sam

Issue 7503

2014-02-26 Thread Mark Lawrence
I'm not sure where to flag this up so reckon here's as good a place as any. I noticed this afternoon 26/02/2014 between 16:05 and 16:09 four messages on the bug tracker mailing list about the subject issue, but http://bugs.python.org/issue7503 has not been updated yet and it's now 18:50. Tech

Re: Need help in writing some code so i can re-use it in every module or class

2014-02-26 Thread Jean-Michel Pichavant
- Original Message - > Hello Experts, > I have requirement, like i want to use below command in python > script. > --username --password arguments> > now my requirement is i want to write some class so i can re-use > " --username --password " part via > importing as module or clas

Re: python

2014-02-26 Thread Karthik Reddy
On Monday, February 24, 2014 2:01:11 PM UTC+5:30, Karthik Reddy wrote: > I worked as a weblogic administrator and now i am changing to development and > i am very much interested in python . please suggest me what are the > things i need to learn more rather than python to get an I.T job

EVOLUTIONISTS DESTROYED IN 5 SECONDS

2014-02-26 Thread Thrinaxodon
= >BREAKING NEWS!!! = > THRINAXODON FOUND 300 FOSSILS FROM DEVONIAN STRATA FROM GREENLAND LAST TUESDAY, ONE WAS A COMPLETE HUMAN PELVIS! > THRINAXODON ALSO FOUND 6 PRIMITIVE STONE TOOLS FROM THE SITE, AS WELL AS CHARCOAL! > PETER NYIKOS WAS FORCED TO ACCEPT THAT

Re: python

2014-02-26 Thread Rodrick Brown
L > On Feb 25, 2014, at 8:27 PM, Karthik Reddy wrote: > > Thank you, > > but from by reaserch i got these requirements .. > > Python, django, Twisted, MySQL, PyQt, PySide, xPython. > > *Technical proficiency with Python and Django. > *Technical proficiency in JavaScript. > *Experience with

Re: Python : parsing the command line options using optparse

2014-02-26 Thread rodperson
On 2014-02-26 04:30, Ganesh Pal wrote: On Tue, Feb 25, 2014 at 9:55 PM, Peter Otten <__pete...@web.de> wrote: As you are just starting I recommend that you use argparse instead of optparse. I would love to use argparse but the script that I plan to write has to run on host machines that Py

Need help in writing some code so i can re-use it in every module or class

2014-02-26 Thread Unix SA
Hello Experts, I have requirement, like i want to use below command in python script. --username --password now my requirement is i want to write some class so i can re-use " --username --password " part via importing as module or class .. and re-use that in other module or classes .. so

Re: exec and locals

2014-02-26 Thread Alister
On Wed, 26 Feb 2014 13:15:25 +, Steven D'Aprano wrote: > I have to dynamically generate some code inside a function using exec, > but I'm not sure if it is working by accident or if I can rely on it. > > Here is a trivial example: > > > py> def spam(): > ... exec( """x = 23""" ) > ...

Re: exec and locals

2014-02-26 Thread Peter Otten
Peter Otten wrote: > Steven D'Aprano wrote: > >> I have to dynamically generate some code inside a function using exec, >> but I'm not sure if it is working by accident or if I can rely on it. >> >> Here is a trivial example: >> >> >> py> def spam(): >> ... exec( """x = 23""" ) >> ...

Re: exec and locals

2014-02-26 Thread Peter Otten
Steven D'Aprano wrote: > I have to dynamically generate some code inside a function using exec, > but I'm not sure if it is working by accident or if I can rely on it. > > Here is a trivial example: > > > py> def spam(): > ... exec( """x = 23""" ) > ... return x > ... > py> spam() > 23

Re: Python : parsing the command line options using optparse

2014-02-26 Thread Ganesh Pal
On Wed, Feb 26, 2014 at 4:57 PM, Peter Otten <__pete...@web.de> wrote: > > If you stick with optparse just pass the options without '=' > > -qXOR > > and > > -q XOR > > should both work. > > Thanks Peter and Simon for the hints it worked : ) without ' =' # Python corrupt.py -o INODE -p /ifs/

Re: exec and locals

2014-02-26 Thread Chris Angelico
On Thu, Feb 27, 2014 at 12:15 AM, Steven D'Aprano wrote: > py> def spam(): > ... exec( """x = 23""" ) > ... return x > ... > py> spam() > 23 > > > (My real example is more complex than this.) > > According to the documentation of exec, I don't think this should > actually work, and yet it

exec and locals

2014-02-26 Thread Steven D'Aprano
I have to dynamically generate some code inside a function using exec, but I'm not sure if it is working by accident or if I can rely on it. Here is a trivial example: py> def spam(): ... exec( """x = 23""" ) ... return x ... py> spam() 23 (My real example is more complex than this.)

Re: Python : parsing the command line options using optparse

2014-02-26 Thread Peter Otten
Ganesh Pal wrote: > On Tue, Feb 25, 2014 at 9:55 PM, Peter Otten <__pete...@web.de> wrote: > >>As you are just starting I recommend that you use argparse instead of > optparse. > > I would love to use argparse but the script that I plan to write has to > run on host machines that Python 2.6 >

Re: Can global variable be passed into Python function?

2014-02-26 Thread Gregory Ewing
Steven D'Aprano wrote: Standard Pascal? Who uses standard Pascal? I'm talking about MacPascal :-) Mac Pascal used @ for getting a pointer to a variable, if I remember rightly. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Python : parsing the command line options using optparse

2014-02-26 Thread sffjunkie
On Wednesday, 26 February 2014 09:30:21 UTC, Ganesh Pal wrote: > Here is what is happening ( only short hand with -) > > # python-5.py -p=/ifs/1.txt -q=XOR  -f=1234 -n=1 -l > > Usage: python-5.py [options] > python-5.py: error: option -q: invalid choice: '=XOR' (choose from 'XOR', > 'ADD', > >

Re: Functions help

2014-02-26 Thread Mark Lawrence
On 26/02/2014 02:06, Cameron Simpson wrote: On 24Feb2014 13:59, Mark Lawrence wrote: On 24/02/2014 04:01, ru...@yahoo.com wrote: On 02/23/2014 08:21 PM, Mark Lawrence wrote: On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: On 24/02/2014 11:09 AM, M

Re: Python : parsing the command line options using optparse

2014-02-26 Thread Ganesh Pal
On Tue, Feb 25, 2014 at 9:55 PM, Peter Otten <__pete...@web.de> wrote: >As you are just starting I recommend that you use argparse instead of optparse. I would love to use argparse but the script that I plan to write has to run on host machines that Python 2.6 I have freebsd clients with py