Re: Web framework

2013-11-22 Thread Ben Finney
Renato Barbosa Pim Pereira renato.barbosa.pim.pere...@gmail.com
writes:

 I'm thinking of porting a Python application that uses numpy for web,
 basically would like to upload a user-defined data, perform the
 calculations with numpy and plot charts with the general structure of
 a site such as a blog for example

The “default” option is Django URL:https://www.djangoproject.com/, but
that only means there is a lot of community support for it — there are
plenty of other good options, as you've noticed.

 I have studied a bit of django and web2py, but I wonder if there is
 some better framework? or how to choose a particular framework over
 another?

This is a very vague question. You're best placed to know what it is you
want. What have you learned from your attempts to implement the site
already? What has gone wrong, what do you need that you would expect
from a better framework?

-- 
 \“Program testing can be a very effective way to show the |
  `\presence of bugs, but is hopelessly inadequate for showing |
_o__)  their absence.” —Edsger W. Dijkstra |
Ben Finney

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


Re: Dvalve! we called the heart of outsourcing world.

2013-11-22 Thread kevowen779
On Friday, 9 April 2010 23:14:16 UTC+2, Dvalve.com  wrote:
 Dvalve.com is an online talent workplace that helps companies hire and
 manage professionals online to get work done and grow their
 businesses. Dvalve matches employers with a ready and qualified
 workforce and rated, tested professionals with technical, marketing
 and business skills. Dvalve also provides the online workplace and
 tools to manage and pay remote professionals and teams online.
 Contractors and service providers around the world use Dvalve to meet
 employers and get paid for delivering great results.VISIT WWW.DVALVE.COM
 FOR YOUR OUTSOURCE  BUSINESS NEEDS, SEE HOW FAST YOUR JOBS DONE WITH
 QUALITY AND SECURITY.Dvalve a real virtual outsourcing ThinkTank.
 Waiting for your valued participation.DVALVE TEAM Welcomes
 freelancers, web designers. programmers, developers, designers,
 business guys and all corporate and IT peoples TO WORK WITH US Please
 Register as per your skills and wait for our Interview call. You can
 register as a Service Provider or as a Buyer Account. Buyer will get
 tie up Offers and providers will catch Jobs!.
 One dice for all.
 Regards
 Dvalve Team
 www.dvalve.com

You know your website doesn't work?

Do you have any contact details
-- 
https://mail.python.org/mailman/listinfo/python-list


What's wrong?New hand.Head first pythonchapter7/8 webapp -No such CGI script

2013-11-22 Thread 曹守正
My webapp is once good to use. Now I do not know what happened. It can not work.
when i type http://localhost:8080/cgi-bin/generate_list.py , 
http://localhost:8080/cgi-bin/generate_timing_data.py, or anything after 
cgi-bin in my chrome. It all turns out like Message: No such CGI script 
('/cgi-bin/generate_timing_data.py'). Error code explanation: 404 - Nothing 
matches the given URI.
I even download the webapp on http://www.headfirstlabs.com/books/hfpython/
Still it does not work.
(you can download the app on the website,that is chapter 8. And the app is in 
file webapp-chapter8) 
Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Traceback when using multiprocessing, less than helpful?

2013-11-22 Thread Mark Lawrence

On 22/11/2013 03:57, John Ladasky wrote:


...Richard submits his hack (his description) to Python 3.4 which pickles and 
passes the string.  When time permits, I'll try it out.  Or maybe I'll wait, since Python 
3.4.0 is still in alpha.



FTR beta 1 is due this Saturday 24/11/2013.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Web Page Parsing/Downloading

2013-11-22 Thread TheRandomPast
Hi. I'm self taught at Python and I used http://www.codecademy.com/ to learn 
which was great help i must say but now, I'm attempting it all on my own and 
need a little help? 

I have three scripts and this is what I'm trying to do with them;


Download from webpage
Parse Links from Page
Output summary of total links
Format a list of matched links
Parse and Print Email addresses
Crach Hash Passwords
Exception Handling
Parsing and Print links to image files/.doc 
Save file into specified folder and alert when files don't save

Can anyone help because I've become a little stuck? None of the scripts are 
running for me and I can't see where I'm having issues


WebPage script;
import sys, urllib
def getWebpage(url):
print '[*] getWebpage()'
url_file = urllib.urlopen(url)
page = url_file.read()
return page
def main():
sys.argv.append('http://www.funeralformyfat.tumblr.com')
if len(sys.argv) != 2:
print '[-] Usage: webpage_get URL'
return

print getWebpage(sys.argv[1])

if __name__ == '__main__':
main()

getLinks

def print_links(page):
print '[*] print_links()'
links = re.findall(r'\a.*href\=.*http\:.+', page)
links.sort()
print '[+]', str(len(links)), 'HyperLinks Found:'

for link in links:
print link

def main():
sys.argv.append('http://www.funeralformyfat.tumblr.com')
if len(sys.argv) != 2:
print '[-] Usage: webpage_getlinks URL'
return
page = webpage_get.wget(sys.argv[1])
print_links(page)

from os.path import join

directory = join('/home/', y, '/newdir/')
file_name = url.split('/')[-1]
file_name = join(directory, file_name)




if __name__ == '__main__':
main()

getParser 

 import md5

 oldpasswd_byuser=str(tom)
 oldpasswd_db=sha1$c60da$1835a9c3ccb1cc436ccaa577679b5d0321234c6f
 opw= md5.new(oldpasswd_byuser)
 #opw= md5.new(oldpasswd_byuser).hexdigest()
 if(opw ==  oldpasswd_db):
print same password
 else:
 print Invalid password

from email.parser import Parser


#headers = Parser().parse(open(messagefile, 'r'))


headers = Parser().parsestr('From: u...@example.com\n'
'To: someone_e...@example.com\n'
'Subject: Test message\n'
'\n'
'Body would go here\n')
print 'To: %s' % headers['to']
print 'From: %s' % headers['from']
print 'Subject: %s' % headers['subject']



Thanks for any help! 

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


Re: Web framework

2013-11-22 Thread David Froger
Hi,

 I'm thinking of porting a Python application that uses numpy for web,
 basically would like to upload a user-defined data, perform the
 calculations with numpy and plot charts with the general structure of a
 site such as a blog for example, I have studied a bit of django and
 web2py, but I wonder if there is some better framework? or how to choose
 a particular framework over another?

I've recently worked on the same kind of Python web application. I have a 
preference
for microframework, here is an explanation of what does micro mean:
http://flask.pocoo.org/docs/foreword/#what-does-micro-mean

And among all the good microframework available, I like Flask:
http://flask.pocoo.org
It has an excellent documentation, it is based on two great libraries: Werkzeug 
and
Jinja2, it has an extenstion system, it has active an has a growning
communinty ... and its written by Armin Ronacher!

Hope it helps.

David

 
 Since now, thanks
 -- 
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Method chaining

2013-11-22 Thread Steven D'Aprano
A frequently missed feature is the ability to chain method calls:

x = []
x.append(1).append(2).append(3).reverse().append(4)
= x now equals [3, 2, 1, 4]


This doesn't work with lists, as the methods return None rather than
self. The class needs to be designed with method chaining in mind before
it will work, and most Python classes follow the lead of built-ins like 
list and have mutator methods return None rather than self.

Here's a proof-of-concept recipe to adapt any object so that it can be 
used for chaining method calls:


class chained:
def __init__(self, obj):
self.obj = obj
def __repr__(self):
return repr(self.obj)
def __getattr__(self, name):
obj = getattr(self.obj, name)
if callable(obj):
def selfie(*args, **kw):
# Call the method just for side-effects, return self.
_ = obj(*args, **kw)
return self
return selfie
else:
return obj


chained([]).append(1).append(2).append(3).reverse().append(4)
= returns [3, 2, 1, 4]


Tested, and works, in CPython 2.4 through 2.7, 3.2 and 3.3, Jython 2.5, 
and IronPython 2.6.

See here for further discussion of the limitations:

http://code.activestate.com/recipes/578770-method-chaining/



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


Re: Method chaining

2013-11-22 Thread Chris Angelico
On Fri, Nov 22, 2013 at 10:26 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 if callable(obj):
 def selfie(*args, **kw):
 # Call the method just for side-effects, return self.
 _ = obj(*args, **kw)
 return self
 return selfie
 else:
 return obj

Nice piece of magic. One limitation not mentioned is that this
completely destroys the chance to have a method return anything _other
than_ self. Since this is intended for Python's convention of
mutators return None, I'd be inclined to check for a None return,
though that might still have some false positives.

def selfie(*args, **kw):
# Call the method for side-effects, return self if it
returns None.
_ = obj(*args, **kw)
if _ is None: return self
return _
return selfie

Either that, or manually identify a set of methods to wrap, which
could possibly be done fairly cleanly with a list of names passed to
__init__. That'd be more work, though.

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


Re: Web Page Parsing/Downloading

2013-11-22 Thread Chris Angelico
On Fri, Nov 22, 2013 at 9:10 PM, TheRandomPast wishingfor...@gmail.com wrote:
 Can anyone help because I've become a little stuck? None of the scripts are 
 running for me and I can't see where I'm having issues

I'm rather lost in what you're trying to accomplish here. The first
thing to do would be to separate out your three scripts and just look
at one at a time; then cut each one down to just what it really needs
to be doing. Once you've done that, you'll have a simple example - see
http://sscce.org/ for tips on that - and you can figure out what it's
doing wrong. If you can't figure it out on your own, the short example
will be far more suitable for posting here, along with its error
backtrace (if it's throwing one), than a more verbose program listing.

Two general points of advice. Firstly, if you're just starting out, I
strongly recommend you use Python 3 instead of Python 2. All sorts of
things have been improved, and it's far easier to learn on the new
version than to learn on the old and then have to change your habits
later.

And secondly, please read this and take note:
https://wiki.python.org/moin/GoogleGroupsPython - otherwise, you'll
find that a lot of people don't want to see your post. Best would be
to avoid Google Groups altogether, as it's very approximately the
worst newsgroup client I've ever seen posts from.

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


Re: Method chaining

2013-11-22 Thread Peter Otten
Steven D'Aprano wrote:

 A frequently missed feature is the ability to chain method calls:
 
 x = []
 x.append(1).append(2).append(3).reverse().append(4)
 = x now equals [3, 2, 1, 4]
 
 
 This doesn't work with lists, as the methods return None rather than
 self. The class needs to be designed with method chaining in mind before
 it will work, and most Python classes follow the lead of built-ins like
 list and have mutator methods return None rather than self.
 
 Here's a proof-of-concept recipe to adapt any object so that it can be
 used for chaining method calls:
 
 
 class chained:
 def __init__(self, obj):
 self.obj = obj
 def __repr__(self):
 return repr(self.obj)
 def __getattr__(self, name):
 obj = getattr(self.obj, name)
 if callable(obj):
 def selfie(*args, **kw):
 # Call the method just for side-effects, return self.
 _ = obj(*args, **kw)
 return self
 return selfie
 else:
 return obj
 
 
 chained([]).append(1).append(2).append(3).reverse().append(4)
 = returns [3, 2, 1, 4]
 
 
 Tested, and works, in CPython 2.4 through 2.7, 3.2 and 3.3, Jython 2.5,
 and IronPython 2.6.
 
 See here for further discussion of the limitations:
 
 http://code.activestate.com/recipes/578770-method-chaining/

Here's my take:

class Chained(object):
def __init__(self, value, method=None):
self.value = value
self.method = method
def __call__(self, *args, **kw):
result = self.method(*args, **kw)
if result is None:
result = self.value
return Chained(result)
def __getattr__(self, name):
return Chained(self.value, getattr(self.value, name))

if __name__ == __main__:
print(Chained([]).append(1).append(2).append(3).reverse().append(4).value)
print(Chained([]).append(1).extend([2,1,1]).count(1).value)

These things are nice to write as long as you omit the gory details, but 
personally I don't want to see the style it favours in my or other people's 
code.

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


Re: Method chaining

2013-11-22 Thread Terry Reedy

On 11/22/2013 6:26 AM, Steven D'Aprano wrote:

A frequently missed feature is the ability to chain method calls:

x = []
x.append(1).append(2).append(3).reverse().append(4)
= x now equals [3, 2, 1, 4]


This doesn't work with lists, as the methods return None


True for the 7 pure mutation methods but not for .copy, .count, .index, 
and .pop. The last both mutates and returns.


--
Terry Jan Reedy

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


Special Issue on Software Development Tools - High Visibility Fast Publication

2013-11-22 Thread Journal of Software Engineering and Applications
This message was sent to [python-list@python.org]. Unsubscribe  If you cannot read it, please click here. Special Issue on "Software Development Tools"  Submission Deadline: February 19th, 2014Dear ,Journal of Software Engineering and Applications (JSEA) is seeking papers for the upcoming special issue on "Software Development Tools". We would like to invite contributors like you to submit papers that may shed some light on this issue through our Paper Submission System.About Our JournalJSEA is an international, double-blind, peer-reviewed and open-access journal with both print and online versions. For more information about the journal, please visit: http://www.scirp.org/journal/jsea.Aims  Scope (not limited to): • Software requirements tools  • Software construction tools  • Software maintenance tools • Software configure management tools  • Software project management tools  • Software quality toolsOther Special Issues in JSEA • Cloud Computing  (Submission Deadline: November 29th, 2013)  • Programming Languages  (Submission Deadline: January 23rd, 2014)  • Software Analysis and Testing  (Submission Deadline: March 5th, 2014)  MoreGuest EditorProf. Janche Sang  (Cleveland State University, USA) JSEA Editorial Office E-mail: j...@scirp.org Place of Public Relation: Scientific Research Publishing Inc., P. O. BOX 54821, Irvine CA 92619-4821, USA. Place of Customer Service: Building 5, Headquarters Space of Optical Valley, Tangxun Lake North Street 38#, East Lake High-Tech Development Zone, Wuhan 430223, Hubei Province, China.-- 
https://mail.python.org/mailman/listinfo/python-list


Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Bharath Kummar
Hello Sir/Mam,

Could you please help me with my current research ?  Am implementing the
concept in python language.
My doubts are :
1)  Is it possible to Retrieve the address of a variable in python ?
2)  Is it possible to Delete the Address of the Variable and create a new
dynamic address inside the compiler/interpreter itself ?
3)  Is it easy to find the Binary equivalence of a given Alphanumeric
String ?
4)  Is it possible to count the number of 1's in the Binary equivalence ?

Could you PLEASE provide me with the codes (codes only for the asked
queries) ?
Your reply counts a lot for me and my research !  I love to explore more in
python.

Awaiting for your Response (Please reply ASAP).

Best,
Bharath
(+91 9025338332)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Having trouble setting up an extremely simple server...

2013-11-22 Thread Roy Smith
In article 528eec7a$0$29992$c3e8da3$54964...@news.astraweb.com,
 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 There are all sorts of things that you can do that don't make your code 
 wrong but do make it difficult to deal with. Why stop with semi-colons?
 
 import socket; pass; pass; pass; pass; pass;
 serverReady = ((True is True) is True) is True) is True);
 serverSock = socket .  \
 socket(
 socket .   \
AF_INET\
 ,  \
 socket.\
 SOCK_STREAM\
)  \
 ;

Steve, you're just worried about how readable some Python code is.  All 
I can say to that is #firstworldproblem.  There's bigger issues at stake 
here.

One thing to be aware of is that semicolons are valuable on the world 
punctuation spot market.  Somewhere, right now, in Greenwich or 
Stamford, or maybe Tribeca, in some hedge-fund sweat shop, there's a C++ 
programmer who can't afford to write a for(;;) loop because he doesn't 
have enough semicolons.  Why?  Because the world punctuation markets 
can't handle the added buy-side pressure from new Python programmers 
using the wrong punctuation.

Also, every semicolon we save can be broken down and res-used as TWO 
decimal points!  The Americans use the top part, most other places use 
the bottom part.  It's like a punctuation breeder reactor.  One piece 
goes in, and two come out.

So, really.  Cut it out with the semicolons.  If you won't do it for us, 
think of the hedge-fund coders.
-- 
https://mail.python.org/mailman/listinfo/python-list


Help me to print to screen as well as log

2013-11-22 Thread Himanshu Garg
I want that print hello should appear on screen as well as get saved in a log 
file.

How can I accomplish this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Roy Smith
In article mailman.3038.1385125611.18130.python-l...@python.org,
 Bharath Kummar bathubharat...@gmail.com wrote:
 
 Could you please help me with my current research ?  Am implementing the
 concept in python language.
 My doubts are :

[Note to readers of American/British English; Indian English uses 
doubt the same way we would use question]

 1)  Is it possible to Retrieve the address of a variable in python ?

No.  One of the fundamental concepts of Python is that it completely 
hides the physical memory.  Sure, at some point, when you write

x = 42

it allocates some piece of memory and puts the integer 42 into it, but 
all those details are hidden from you (and are implementation specific).


 3)  Is it easy to find the Binary equivalence of a given Alphanumeric
 String ?

I think what you're talking about is the ord() function.  Given a single 
character (i.e. a string of length 1), it returns the unicode value for 
that character.  Thus:

 ord('X')
88

You could iterate over the characters in a string to find that for each 
one:

 [ord(c) for c in My string]
[77, 121, 32, 115, 116, 114, 105, 110, 103]


 4)  Is it possible to count the number of 1's in the Binary equivalence ?

This is starting to sound like a homework problem, or possibly an 
interview question :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Steven D'Aprano
On Fri, 22 Nov 2013 18:22:29 +0530, Bharath Kummar wrote:

 1)  Is it possible to Retrieve the address of a variable in python ? 

No. Variables in Python are not at fixed addresses, like in Pascal or C, 
they are names in a namespace.

You can read this post for some more information about the difference 
between C variables and Python variables, and calling conventions across 
different languages:

https://mail.python.org/pipermail/tutor/2010-December/080505.html

It's a long post, but to summarise the part about variables:

In languages like Pascal or C, the compiler keeps a table mapping 
variable names to fixed memory addresses, like this:

Variable  Address
  ===
x 10234
y 10238
z 10242

The command x = 42 stores the value 42 into memory address 10234. If 
you ask the compiler for the address of x, it can say 10234. That's how 
variables work in languages like Pascal, C, Fortran, and similar.

With the Pascal or C style variable, the variable address exists even 
before you give it a value.

But languages like Python don't work that way. There is no table of 
variable:address available to the compiler, and variables don't have an 
address. Python's variables are *name bindings*, not fixed memory 
addresses. The Python runtime keeps a global dictionary which maps names 
to their values:

{'x': integer object 42,
 'y': string object 'hello world',
 'z': list object [1,2,3],
}

The general name for this is namespace. In Python you can access the 
global namespace with the globals() function, and a read-only copy of the 
local namespace with the locals() function.

Entries in the namespace cannot be blank. So names don't exist before 
they are bound to a value.


 2) 
 Is it possible to Delete the Address of the Variable and create a new
 dynamic address inside the compiler/interpreter itself ? 

I don't understand this question.

Since variables don't have addresses, you can't delete what doesn't exist.


 3)  Is it easy
 to find the Binary equivalence of a given Alphanumeric String ?

Which binary equivalence are you referring to? Again, I don't understand 
your question. I can do this:

py astring = 1234
py int(astring).to_bytes(4, 'big')
b'\x00\x00\x04\xd2'
py int(astring).to_bytes(4, 'little')
b'\xd2\x04\x00\x00'


Or I can do this:

py astring = Alpha1234 δθЖ∞
py astring.encode('utf-8')
b'Alpha1234 \xce\xb4\xce\xb8\xd0\x96\xe2\x88\x9e'


Or I can do this:

py import binascii
py binascii.hexlify(b'Hello World!')
b'48656c6c6f20576f726c6421'


And many other string - binary equivalences. Which ones did you have in 
mind?


 4)  Is it possible to count the number of 1's in the Binary equivalence
 ?

Of course. First decide which binary equivalence you want, then decide 
what you mean by count the number of 1s (do you mean the byte with 
value 1, or the ASCII code for 1, or the bit 1?), then count them.


 Could you PLEASE provide me with the codes (codes only for the asked
 queries) ?

If you explain your question in more detail, we can give more detailed 
answers.



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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread rusi
On Friday, November 22, 2013 6:22:29 PM UTC+5:30, Bharath Kummar wrote:
 Hello Sir/Mam, 
 Could you please help me with my current research ?  Am implementing the 
 concept in python language. 
 My doubts are :
 1)  Is it possible to Retrieve the address of a variable in python ?
 2)  Is it possible to Delete the Address of the Variable and create a new 
 dynamic address inside the compiler/interpreter itself ? 
 3)  Is it easy to find the Binary equivalence of a given Alphanumeric String ?
 4)  Is it possible to count the number of 1's in the Binary equivalence ? 
 Could you PLEASE provide me with the codes (codes only for the asked queries) 
 ? 
 Your reply counts a lot for me and my research !  I love to explore more in 
 python.

1) id will give you addresses.  Except that
   - not portable ie not guaranteed to be a m/c address
   - its of an object not a variable
   - if you are thinking C, its mostly useless

2) del will delete objects -- like free in C
   Except that like above, thinking in C will cause more problems than it solves

3,4 I cant make out what you mean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me to print to screen as well as log

2013-11-22 Thread Steven D'Aprano
On Fri, 22 Nov 2013 05:51:21 -0800, Himanshu Garg wrote:

 I want that print hello should appear on screen as well as get saved
 in a log file.
 
 How can I accomplish this?

print hello
logfile.write(hello\n)


Does that satisfy your need? If not, please explain in more detail what 
you are trying to do, what you have already tried, and what happened when 
you tried it.



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


Re: Having trouble setting up an extremely simple server...

2013-11-22 Thread Chris Angelico
On Sat, Nov 23, 2013 at 12:41 AM, Roy Smith r...@panix.com wrote:
 Also, every semicolon we save can be broken down and res-used as TWO
 decimal points!  The Americans use the top part, most other places use
 the bottom part.  It's like a punctuation breeder reactor.  One piece
 goes in, and two come out.

That's only the glyph, though. You can't do that with the codepoints -
all you end up with is a U+0003 'END OF TEXT' and a U+000B 'LINE
TABULATION', useful occasionally but hardly in great demand. No, once
you've broken the glyph apart, there's not a lot you can do with the
codepoint, and they end up filling the nuclear waste disposal caverns.
People keep coming up with schemes for utilizing waste U+0003s, but
there's a fundamental problem that text can only end once [1], and all
attempts to use U+0003 in commercial use resulted in the premature
termination of the text concerned. Of course, the FDA put an immediate
stop to that - so expensive to compensate the families of the
terminated text - so we're back where we started.

ChrisA

[1] As is stated in the Holy Writ, Hebrews 9:27: Just as text is
destined to end once, and after that to face judgment, so C strings
receive but a single NUL to terminate the strings of many.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me to print to screen as well as log

2013-11-22 Thread Peter Otten
Himanshu Garg wrote:

 I want that print hello should appear on screen as well as get saved in
 a log file.
 
 How can I accomplish this?

In Python 3 print() is a function -- you can replace it with a custom 
function that invokes the original print() twice.

In both Python 3 and Python 2 you can redirect sys.stdout/stderr to a custom 
object with a write() method.

If you are actually logging I suggest that you look into the logging package 
which allows multiple handlers, see

http://docs.python.org/3.3/howto/logging.html

You will need to replace your print() calls with

some_logger.info(message)

or similar.

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


Re: Method chaining

2013-11-22 Thread Steven D'Aprano
On Fri, 22 Nov 2013 13:08:03 +0100, Peter Otten wrote:

 These things are nice to write as long as you omit the gory details, but
 personally I don't want to see the style it favours in my or other
 people's code.

There's not really a lot of difference between:

obj = MyClass()
obj.spam()
obj.eggs()
obj.cheese()

and

obj = MyClass().spam().eggs().cheese()


except the first takes up a lot more vertical space. Chained method calls 
is idiomatic in some languages. If there is a problem with it, it is that 
it doesn't make it clear that each method call is being used only for its 
side-effects, rather than it being a series of distinct objects. But in 
my opinion that flaw is a very minor one.

The nice thing about using an explicit method chaining call rather than 
building your class to support it by default is that the initial call to 
the adaptor signals that everything that follows is called only for the 
side-effects.

obj = chained(MyClass()).spam().eggs().cheese()



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


Re: Method chaining

2013-11-22 Thread Steven D'Aprano
On Fri, 22 Nov 2013 07:34:53 -0500, Terry Reedy wrote:

 On 11/22/2013 6:26 AM, Steven D'Aprano wrote:
 A frequently missed feature is the ability to chain method calls:

 x = []
 x.append(1).append(2).append(3).reverse().append(4) = x now equals [3,
 2, 1, 4]


 This doesn't work with lists, as the methods return None
 
 True for the 7 pure mutation methods but not for .copy, .count, .index,
 and .pop. The last both mutates and returns.

Yes, that is correct. In this case, the assumption behind the chained 
adapter is that we don't care about the results of calling those methods, 
we only care about the mutation they cause. If that's not the case, then 
chained() isn't for us.


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


argparse feature request

2013-11-22 Thread Neal Becker
I use arparse all the time and find it serves my needs well.  One thing I'd 
like 
to see.  In the help message, I'd like to automatically add the default values.

For example, here's one of my programs:

 python3 test_freq3.py --help
usage: test_freq3.py [-h] [--size SIZE] [--esnodB ESNODB] [--tau TAU] [--trials 
TRIALS]
 [--training TRAINING] [--sps SPS] [--si SI] [--alpha ALPHA]
 [--range RANGE] [--dfunc {gradient,delay}]
 [--mod 
{gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}]
 [--sym-freq-err SYM_FREQ_ERR] [--calibrate [CALIBRATE]]

optional arguments:
  -h, --helpshow this help message and exit
  --size SIZE
  --esnodB ESNODB, -e ESNODB
  --tau TAU, -t TAU
  --trials TRIALS
  --training TRAINING
  --sps SPS
  --si SI
  --alpha ALPHA
  --range RANGE
  --dfunc {gradient,delay}
  --mod {gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}
  --sym-freq-err SYM_FREQ_ERR
  --calibrate [CALIBRATE], --with-calibrate [CALIBRATE], --enable-calibrate 
[CALIBRATE], --no-calibrate [CALIBRATE], --without-calibrate [CALIBRATE], --
disable-calibrate [CALIBRATE]

What I'd like to see is:

--size SIZE [2000]   the default value is displayed

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


Re: argparse feature request

2013-11-22 Thread Robert Kern

On 2013-11-22 14:56, Neal Becker wrote:

I use arparse all the time and find it serves my needs well.  One thing I'd like
to see.  In the help message, I'd like to automatically add the default values.

For example, here's one of my programs:

  python3 test_freq3.py --help
usage: test_freq3.py [-h] [--size SIZE] [--esnodB ESNODB] [--tau TAU] [--trials
TRIALS]
  [--training TRAINING] [--sps SPS] [--si SI] [--alpha 
ALPHA]
  [--range RANGE] [--dfunc {gradient,delay}]
  [--mod
{gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}]
  [--sym-freq-err SYM_FREQ_ERR] [--calibrate [CALIBRATE]]

optional arguments:
   -h, --helpshow this help message and exit
   --size SIZE
   --esnodB ESNODB, -e ESNODB
   --tau TAU, -t TAU
   --trials TRIALS
   --training TRAINING
   --sps SPS
   --si SI
   --alpha ALPHA
   --range RANGE
   --dfunc {gradient,delay}
   --mod {gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}
   --sym-freq-err SYM_FREQ_ERR
   --calibrate [CALIBRATE], --with-calibrate [CALIBRATE], --enable-calibrate
[CALIBRATE], --no-calibrate [CALIBRATE], --without-calibrate [CALIBRATE], --
disable-calibrate [CALIBRATE]

What I'd like to see is:

--size SIZE [2000]   the default value is displayed


Use formatter_class=argparse.ArgumentDefaultsHelpFormatter

http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter

E.g.

[git/mpstack]$ cat print_stacks.py
...
def main():
import argparse
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-p', '--percent', action='store_true', help='Show 
percentages.')

parser.add_argument('file', help='The sample file.')
...

[git/mpstack]$ python print_stacks.py -h
usage: print_stacks.py [-h] [-p] file

positional arguments:
  file   The sample file.

optional arguments:
  -h, --help show this help message and exit
  -p, --percent  Show percentages. (default: False)

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Ian Kelly
On Fri, Nov 22, 2013 at 7:13 AM, rusi rustompm...@gmail.com wrote:
 2) del will delete objects -- like free in C
Except that like above, thinking in C will cause more problems than it 
 solves

No, del will only delete name bindings.  Whether the bound object is
also deleted depends on whether it is still referenced, and the timing
by which the bound object may be deleted varies between
implementations.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Grant Edwards
On 2013-11-22, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 On Fri, 22 Nov 2013 18:22:29 +0530, Bharath Kummar wrote:

 1)  Is it possible to Retrieve the address of a variable in python ? 

 No. Variables in Python are not at fixed addresses, like in Pascal or C, 
 they are names in a namespace.

 You can read this post for some more information about the difference 
 between C variables and Python variables, and calling conventions across 
 different languages:

 https://mail.python.org/pipermail/tutor/2010-December/080505.html

 It's a long post, but to summarise the part about variables:

 In languages like Pascal or C, the compiler keeps a table mapping 
 variable names to fixed memory addresses, like this:

 Variable  Address
  ===
 x 10234
 y 10238
 z 10242

FWIW, that's only true for some sorts of variables.  Other variables
have an address that is relative to a stack or frame pointer.

-- 
Grant Edwards   grant.b.edwardsYow! PEGGY FLEMMING is
  at   stealing BASKET BALLS to
  gmail.comfeed the babies in VERMONT.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Method chaining

2013-11-22 Thread Peter Otten
Steven D'Aprano wrote:

 On Fri, 22 Nov 2013 13:08:03 +0100, Peter Otten wrote:
 
 These things are nice to write as long as you omit the gory details, but
 personally I don't want to see the style it favours in my or other
 people's code.
 
 There's not really a lot of difference 

That cuts both ways ;)

 between:
 
 obj = MyClass()
 obj.spam()
 obj.eggs()
 obj.cheese()
 
 and
 
 obj = MyClass().spam().eggs().cheese()
 
 
 except the first takes up a lot more vertical space. 

I've not yet run short of vertical space ;)

 Chained method calls is idiomatic in some languages. 

Languages with mutable objects?

 If there is a problem with it, it is that
 it doesn't make it clear that each method call is being used only for its
 side-effects, rather than it being a series of distinct objects. But in
 my opinion that flaw is a very minor one.
 
 The nice thing about using an explicit method chaining call rather than
 building your class to support it by default is that the initial call to
 the adaptor signals that everything that follows is called only for the
 side-effects.
 
 obj = chained(MyClass()).spam().eggs().cheese()

  obj = MyClass(); obj.spam(); obj.eggs(); obj.cheese()

OK, that one is disgusting...

Anyway, I'd like to see a sequence of method names taken from actual code 
that profits from this chaining pattern.

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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Ned Batchelder
On Friday, November 22, 2013 9:13:50 AM UTC-5, rusi wrote:
 On Friday, November 22, 2013 6:22:29 PM UTC+5:30, Bharath Kummar wrote:
  Hello Sir/Mam, 
  Could you please help me with my current research ?  Am implementing the 
  concept in python language. 
  My doubts are :
  1)  Is it possible to Retrieve the address of a variable in python ?
  2)  Is it possible to Delete the Address of the Variable and create a new 
  dynamic address inside the compiler/interpreter itself ? 
  3)  Is it easy to find the Binary equivalence of a given Alphanumeric 
  String ?
  4)  Is it possible to count the number of 1's in the Binary equivalence ? 
  Could you PLEASE provide me with the codes (codes only for the asked 
  queries) ? 
  Your reply counts a lot for me and my research !  I love to explore more in 
  python.
 
 1) id will give you addresses.  Except that
- not portable ie not guaranteed to be a m/c address
- its of an object not a variable
- if you are thinking C, its mostly useless
 
 2) del will delete objects -- like free in C
Except that like above, thinking in C will cause more problems than it 
 solves

Not true: del doesn't delete objects. It merely removes references to objects.  
Only if the object has no more references is the object deleted.

I tried my hand at explaining how names and values work in Python: 
http://nedbatchelder.com/text/names.html  Some people have found it helpful.

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


Re: What's wrong?New hand.Head first pythonchapter7/8 webapp -No such CGI script

2013-11-22 Thread 曹守正
在 2013年11月22日星期五UTC+8下午4时48分35秒,曹守正写道:
 My webapp is once good to use. Now I do not know what happened. It can not 
 work.
 
 when i type http://localhost:8080/cgi-bin/generate_list.py , 
 http://localhost:8080/cgi-bin/generate_timing_data.py, or anything after 
 cgi-bin in my chrome. It all turns out like Message: No such CGI script 
 ('/cgi-bin/generate_timing_data.py'). Error code explanation: 404 - Nothing 
 matches the given URI.
 
 I even download the webapp on http://www.headfirstlabs.com/books/hfpython/
 
 Still it does not work.
 
 (you can download the app on the website,that is chapter 8. And the app is in 
 file webapp-chapter8) 
 
 Thank you!



在 2013年11月22日星期五UTC+8下午4时48分35秒,曹守正写道:
 My webapp is once good to use. Now I do not know what happened. It can not 
 work.
 
 when i type http://localhost:8080/cgi-bin/generate_list.py , 
 http://localhost:8080/cgi-bin/generate_timing_data.py, or anything after 
 cgi-bin in my chrome. It all turns out like Message: No such CGI script 
 ('/cgi-bin/generate_timing_data.py'). Error code explanation: 404 - Nothing 
 matches the given URI.
 
 I even download the webapp on http://www.headfirstlabs.com/books/hfpython/
 
 Still it does not work.
 
 (you can download the app on the website,that is chapter 8. And the app is in 
 file webapp-chapter8) 
 
 Thank you!

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


Re: Method chaining

2013-11-22 Thread Antoon Pardon
Op 22-11-13 16:20, Peter Otten schreef:
 Steven D'Aprano wrote:
 
 On Fri, 22 Nov 2013 13:08:03 +0100, Peter Otten wrote:

 These things are nice to write as long as you omit the gory details, but
 personally I don't want to see the style it favours in my or other
 people's code.

 There's not really a lot of difference 
 
 That cuts both ways ;)
 
 between:

 obj = MyClass()
 obj.spam()
 obj.eggs()
 obj.cheese()

 and

 obj = MyClass().spam().eggs().cheese()


 except the first takes up a lot more vertical space. 
 
 I've not yet run short of vertical space ;)

Really? Then you must write only very short programs. Me I
continuously run out of vertical space. That is why I need
to use such tools as scroll bars.

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


Re: Help me to print to screen as well as log

2013-11-22 Thread Mark Lawrence

On 22/11/2013 14:15, Steven D'Aprano wrote:

On Fri, 22 Nov 2013 05:51:21 -0800, Himanshu Garg wrote:


I want that print hello should appear on screen as well as get saved
in a log file.

How can I accomplish this?


print hello
logfile.write(hello\n)


Does that satisfy your need? If not, please explain in more detail what
you are trying to do, what you have already tried, and what happened when
you tried it.



Fancy wasting vertical space like that, if you use a semi-colon you can 
save a whole lot of it like this


print hello;logfile.write(hello\n) # :)

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Method chaining

2013-11-22 Thread Steven D'Aprano
On Fri, 22 Nov 2013 16:20:03 +0100, Peter Otten wrote:

 Steven D'Aprano wrote:
 
 On Fri, 22 Nov 2013 13:08:03 +0100, Peter Otten wrote:
 
 These things are nice to write as long as you omit the gory details,
 but personally I don't want to see the style it favours in my or other
 people's code.
 
 There's not really a lot of difference
 
 That cuts both ways ;)

Actually, I was wrong. See below.

 between:
 
 obj = MyClass()
 obj.spam()
 obj.eggs()
 obj.cheese()
 
 and
 
 obj = MyClass().spam().eggs().cheese()
 
 
 except the first takes up a lot more vertical space.
 
 I've not yet run short of vertical space ;)

However, here is a real difference:

# With chaining
thing = func(MyClass().spam().eggs().cheese(), 
 MyClass().aardvark(),
 OtherClass().fe().fi().fo().fum(),
 )
do_stuff_with(thing)


versus:

# Without chaining
temp1 = MyClass()
temp1.spam()
temp1.eggs()
temp1.cheese()
temp2 = MyClass()
temp2.aardvark()
temp3 = OtherClass()
temp3.fe()
temp3.fi()
temp3.fo()
temp3.fum()
thing = func(temp1, temp2, temp3)
do_stuff_with(thing)


In this case the chained version doesn't obscure the intention of the 
code anywhere near as much as the unchained version and its plethora of 
temporary variables.


 Chained method calls is idiomatic in some languages.
 
 Languages with mutable objects?

Yes. It's a Design Pattern applicable to any language with mutator 
methods. Here are three examples in C#, Java and Ruby:

http://mrbool.com/fluent-interface-and-method-chaining-a-good-programming-approach/26365
http://www.infoq.com/articles/internal-dsls-java
http://blog.jayfields.com/2008/03/ruby-replace-temp-with-chain.html

although in fairness I wouldn't call it idiomatic in C# or Java.

Ruby 1.9 even added a new method to Object, tap, specifically to allow 
chaining of methods, which itself was copied from Ruby-On-Rails' 
returning helper. So I think it's fair to say that method chaining
for mutation is idiomatic in Ruby.

http://www.seejohncode.com/2012/01/02/ruby-tap-that/

http://blog.moertel.com/posts/2007-02-07-ruby-1-9-gets-handy-new-method-object-tap.html


This idea goes back to Smalltalk, and is essentially just a 
pipeline. Hardly something weird.

http://en.wikipedia.org/wiki/Method_chaining

(Technically, if the methods return self rather than None, it's method 
cascading. Chaining is any sequence of method calls, whether they return
self or something else.)

Dart includes syntax for method cascades, which I'm told looks like 
this:

x = SomeClass()
..spam()
..eggs()
..cheese()


The technique also comes with the blessing of Martin Fowler, where it
is an important part of fluent interfaces:

http://martinfowler.com/bliki/FluentInterface.html

Quote:

The common convention in the curly brace world is that modifier 
methods are void, which I like because it follows the principle 
of CommandQuerySeparation. This convention does get in the way of 
a fluent interface, so I'm inclined to suspend the convention for 
this case.


And last but not least, if you want to go all the way down to the lambda 
calculus and combinator theory, my selfie adapter function is just a 
form of the K-combinator (a.k.a. the Kestrel). So there's a deep and 
powerful mathematical pedigree to the idea, if that matters.



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


Why pickling (was: Traceback when using multiprocessing)

2013-11-22 Thread John Ladasky
On Thursday, November 21, 2013 8:24:05 PM UTC-8, Chris Angelico wrote:

 Oh, that part's easy. Let's leave the multiprocessing module out of it
 for the moment; imagine you spin up two completely separate instances
 of Python. Create some object in one of them; now, transfer it to the
 other. How are you going to do it?

For what definition of completely separate?

If I have two instances of the same version of the Python interpreter running 
on the same hardware, and the same operating system, I expect I would just copy 
a block of memory from one interpreter to the other, and then write some new 
pointers.  That kind of data sharing has to be the most common kind.  It's also 
the simplest.

I understand that pickling allows sharing of Python objects between Python 
interpreters even if those interpreters run on different CPU's with different 
memory architecture, different operating systems, etc.  It just seems like 
overkill to me to use pickling in the simple case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dvalve! we called the heart of outsourcing world.

2013-11-22 Thread John Ladasky
On Friday, November 22, 2013 12:44:38 AM UTC-8, kevow...@gmail.com wrote:

 You know your website doesn't work?
 Do you have any contact details

You're responding to a (spam!) post which is dated April 9, 2010 -- two and a 
half years ago.

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


Re: argparse feature request

2013-11-22 Thread Neal Becker
Robert Kern wrote:

 On 2013-11-22 14:56, Neal Becker wrote:
 I use arparse all the time and find it serves my needs well.  One thing I'd
 like
 to see.  In the help message, I'd like to automatically add the default
 values.

 For example, here's one of my programs:

   python3 test_freq3.py --help
 usage: test_freq3.py [-h] [--size SIZE] [--esnodB ESNODB] [--tau TAU]
 [--trials TRIALS]
   [--training TRAINING] [--sps SPS] [--si SI] [--alpha
   [ALPHA] --range RANGE] [--dfunc {gradient,delay}]
   [--mod
 {gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}]
   [--sym-freq-err SYM_FREQ_ERR] [--calibrate [CALIBRATE]]

 optional arguments:
-h, --helpshow this help message and exit
--size SIZE
--esnodB ESNODB, -e ESNODB
--tau TAU, -t TAU
--trials TRIALS
--training TRAINING
--sps SPS
--si SI
--alpha ALPHA
--range RANGE
--dfunc {gradient,delay}
--mod {gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}
--sym-freq-err SYM_FREQ_ERR
--calibrate [CALIBRATE], --with-calibrate [CALIBRATE], --enable-calibrate
 [CALIBRATE], --no-calibrate [CALIBRATE], --without-calibrate [CALIBRATE], --
 disable-calibrate [CALIBRATE]

 What I'd like to see is:

 --size SIZE [2000]   the default value is displayed
 
 Use formatter_class=argparse.ArgumentDefaultsHelpFormatter
 
 
http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter
 
 E.g.
 
 [git/mpstack]$ cat print_stacks.py
 ...
 def main():
  import argparse
  parser = argparse.ArgumentParser(
  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  parser.add_argument('-p', '--percent', action='store_true', help='Show
 percentages.')
  parser.add_argument('file', help='The sample file.')
 ...
 
 [git/mpstack]$ python print_stacks.py -h
 usage: print_stacks.py [-h] [-p] file
 
 positional arguments:
file   The sample file.
 
 optional arguments:
-h, --help show this help message and exit
-p, --percent  Show percentages. (default: False)
 

Thanks!  Almost perfect.  Problem is, I don't usually bother to add help='help 
me' options.  It seems that ArgumentDefaultsHelpFormatter doesn't do anything 
unless help='blah' option is used.  Not sure what to do about that.  Since
python test_freq3.py -h
produces useful messages without my adding help=... everywhere, it'd be nice
if ArgumentDefaultsHelpFormatter would work here.

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


Re: Method chaining

2013-11-22 Thread Wolfgang Maier
Steven D'Aprano steve+comp.lang.python at pearwood.info writes:

 # With chaining
 thing = func(MyClass().spam().eggs().cheese(), 
  MyClass().aardvark(),
  OtherClass().fe().fi().fo().fum(),
  )
 do_stuff_with(thing)
 
 versus:
 
 # Without chaining
 temp1 = MyClass()
 temp1.spam()
 temp1.eggs()
 temp1.cheese()
 temp2 = MyClass()
 temp2.aardvark()
 temp3 = OtherClass()
 temp3.fe()
 temp3.fi()
 temp3.fo()
 temp3.fum()
 thing = func(temp1, temp2, temp3)
 do_stuff_with(thing)
 

Another use case might be in comprehensions and generator expressions ??

thing = [MyClass().spam().eggs(x).cheese() for x in sequence]

where you can't use all those temporary assignments.

Best,
Wolfgang


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


Re: argparse feature request

2013-11-22 Thread Robert Kern

On 2013-11-22 16:52, Neal Becker wrote:

Robert Kern wrote:


On 2013-11-22 14:56, Neal Becker wrote:

I use arparse all the time and find it serves my needs well.  One thing I'd
like
to see.  In the help message, I'd like to automatically add the default
values.



What I'd like to see is:

--size SIZE [2000]   the default value is displayed


Use formatter_class=argparse.ArgumentDefaultsHelpFormatter


http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter



Thanks!  Almost perfect.  Problem is, I don't usually bother to add help='help
me' options.  It seems that ArgumentDefaultsHelpFormatter doesn't do anything
unless help='blah' option is used.  Not sure what to do about that.  Since
python test_freq3.py -h
produces useful messages without my adding help=... everywhere, it'd be nice
if ArgumentDefaultsHelpFormatter would work here.


Patches are welcome, I am sure. Implement a HelpFormatter that does what you 
want. _format_action() is where the relevant logic is. Try something like this, 
and modify to suit.



class BeckerDefaultFormatter(argparse.ArgumentDefaultsHelpFormatter):

def _format_action(self, action):
monkeypatched = False
if action.default is not None and action.help is None:
# Trick the default _format_action() method into writing out
# the defaults.
action.help = ' '
monkeypatched = True
formatted = super(BeckerDefaultFormatter, self)._format_action(action)
if monkeypatched:
action.help = None
return formatted

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Having trouble setting up an extremely simple server...

2013-11-22 Thread Jean-Michel Pichavant
- Original Message -
 Please help! I'm very
 new to networking, but I've been using Python for a while now, just
 recent;y getting into networking, trying to get things down.

Hi,

Nothing wrong with diving into the muddy waters of network programming.
If you like blue lagoons like me, there's a lot of high level remote 
protocols/network engines/web frameworks that allow you to code applications 
without caring about networking code.

Most of to more complex frameworks provide a simple way to write simple servers 
and clients. Be sure to check them out before writing your own (except for 
educational purpose) 

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: Method chaining

2013-11-22 Thread Wolfgang Maier
Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de writes:

 
 Steven D'Aprano steve+comp.lang.python at pearwood.info writes:
 
  # With chaining
  thing = func(MyClass().spam().eggs().cheese(), 
   MyClass().aardvark(),
   OtherClass().fe().fi().fo().fum(),
   )
  do_stuff_with(thing)
  
  versus:
  
  # Without chaining
  temp1 = MyClass()
  temp1.spam()
  temp1.eggs()
  temp1.cheese()
  temp2 = MyClass()
  temp2.aardvark()
  temp3 = OtherClass()
  temp3.fe()
  temp3.fi()
  temp3.fo()
  temp3.fum()
  thing = func(temp1, temp2, temp3)
  do_stuff_with(thing)
  
 
 Another use case might be in comprehensions and generator expressions ??
 
 thing = [MyClass().spam().eggs(x).cheese() for x in sequence]
 
 where you can't use all those temporary assignments.
 
 Best,
 Wolfgang
 
 

Thinking about this, you could define __call__ for your chained class to
return the wrapped object:

class chained:
def __init__(self, obj):
self.obj = obj
def __repr__(self):
return repr(self.obj)
def __getattr__(self, name):
obj = getattr(self.obj, name)
if callable(obj):
def selfie(*args, **kw):
# Call the method just for side-effects, return self.
_ = obj(*args, **kw)
return self
return selfie
else:
return obj
def __call__(self):
return self.obj

This would encourage its localized use on the fly as in:

thing = [MyClass().spam().eggs(x).cheese()() for x in sequence]

where the intention probably would be to generate a list of lists (or other
mutable objects), not of objects of class chained. Localizing the use of
chained also seems like a good idea to me as I do share Peter's worries
about coding style, while I also agree with you that such a class comes in
handy from time to time.


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


Re: argparse feature request

2013-11-22 Thread Neal Becker
Robert Kern wrote:

 On 2013-11-22 16:52, Neal Becker wrote:
 Robert Kern wrote:

 On 2013-11-22 14:56, Neal Becker wrote:
 I use arparse all the time and find it serves my needs well.  One thing I'd
 like
 to see.  In the help message, I'd like to automatically add the default
 values.
 
 What I'd like to see is:

 --size SIZE [2000]   the default value is displayed

 Use formatter_class=argparse.ArgumentDefaultsHelpFormatter


 
http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter
 
 Thanks!  Almost perfect.  Problem is, I don't usually bother to add
 help='help
 me' options.  It seems that ArgumentDefaultsHelpFormatter doesn't do anything
 unless help='blah' option is used.  Not sure what to do about that.  Since
 python test_freq3.py -h
 produces useful messages without my adding help=... everywhere, it'd be nice
 if ArgumentDefaultsHelpFormatter would work here.
 
 Patches are welcome, I am sure. Implement a HelpFormatter that does what you
 want. _format_action() is where the relevant logic is. Try something like
 this, and modify to suit.
 
 
 class BeckerDefaultFormatter(argparse.ArgumentDefaultsHelpFormatter):
 
  def _format_action(self, action):
  monkeypatched = False
  if action.default is not None and action.help is None:
  # Trick the default _format_action() method into writing out
  # the defaults.
  action.help = ' '
  monkeypatched = True
  formatted = super(BeckerDefaultFormatter,
  self)._format_action(action) if monkeypatched:
  action.help = None
  return formatted
 

Thanks!  Seems to work great.  It gave reasonable output for both case where I 
include 
help=...
and also without.

I have no idea how that above code works, but I guess as long as it works...

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


Re: How to install pip for python3 on OS X?

2013-11-22 Thread Travis Griggs

On Nov 20, 2013, at 6:01 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:

 On 20/11/2013 06:55, Travis Griggs wrote:
 OSX (Mavericks) has python2.7 stock installed. But I do all my own
 personal python stuff with 3.3. I just flushed my 3.3.2 install and
 installed the new 3.3.3. So I need to install pyserial again.
 
 Just idle curiosity but why do you have to do this?  On Windows I just whack 
 3.3.3 over the top of 3.3.2, job done.

I think in this case, it was a chance to clean house, and maybe up the “tools” 
game (e.g. use pip) instead of what I had been doing. So you’re correct. The 
flushing of 3.3.2 was more that I *wanted* to, instead of *needing* to.

(aside. I do not use GoogleGroups, but have been accused of somehow sending 
email that looks like I do. Does this email look like that?)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to install pip for python3 on OS X?

2013-11-22 Thread Travis Griggs

On Nov 19, 2013, at 11:27 PM, Ned Deily n...@acm.org wrote:

 In article 6856a21c-57e8-4cdd-a9e8-5dd738c36...@gmail.com,
 Travis Griggs travisgri...@gmail.com wrote:
 
 OSX (Mavericks) has python2.7 stock installed. But I do all my own personal 
 python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 
 3.3.3. So I need to install pyserial again. I can do it the way I've done it 
 before, which is:
 
 Download pyserial from pypi
 untar pyserial.tgz
 cd pyserial
 python3 setup.py install
 But I'd like to do like the cool kids do, and just do something like pip3 
 install pyserial. But it's not clear how I get to that point. And just that 
 point. Not interested (unless I have to be) in virtualenv 
 yet.-
 
 http://www.pip-installer.org/en/latest/installing.html
 
 # download and install setuptools
 curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
 python3 ez_setup.py
 # download and install pip
 curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
 python3 get-pip.py
 # use pip to install
 python3 -m pip install pyserial
 # Don't want it?
 python3 -m pip uninstall pyserial
 
 -- 
 Ned Deily,
 n...@acm.org

Ned,

Thank you! Belatedly. I’ve had some fires to put out at work. And have gotten 
back to this, and this is exactly what I was looking for. I added the 
additional step of:

cd /usr/local/bin
ln -s ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pip pip 

Works, like a charm.

(aside. I do not use GoogleGroups, but have been accused of somehow sending 
email that looks like I do. Does this email look like that?)

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


Re: How to install pip for python3 on OS X?

2013-11-22 Thread xDog Walker
On Friday 2013 November 22 12:10, Travis Griggs wrote:
 (aside. I do not use GoogleGroups, but have been accused of somehow sending
 email that looks like I do. Does this email look like that?)

No.

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.

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


Re: argparse feature request

2013-11-22 Thread Robert Kern

On 2013-11-22 18:15, Neal Becker wrote:

Robert Kern wrote:


On 2013-11-22 16:52, Neal Becker wrote:

Robert Kern wrote:


On 2013-11-22 14:56, Neal Becker wrote:

I use arparse all the time and find it serves my needs well.  One thing I'd
like
to see.  In the help message, I'd like to automatically add the default
values.



What I'd like to see is:

--size SIZE [2000]   the default value is displayed


Use formatter_class=argparse.ArgumentDefaultsHelpFormatter




http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter



Thanks!  Almost perfect.  Problem is, I don't usually bother to add
help='help
me' options.  It seems that ArgumentDefaultsHelpFormatter doesn't do anything
unless help='blah' option is used.  Not sure what to do about that.  Since
python test_freq3.py -h
produces useful messages without my adding help=... everywhere, it'd be nice
if ArgumentDefaultsHelpFormatter would work here.


Patches are welcome, I am sure. Implement a HelpFormatter that does what you
want. _format_action() is where the relevant logic is. Try something like
this, and modify to suit.


class BeckerDefaultFormatter(argparse.ArgumentDefaultsHelpFormatter):

  def _format_action(self, action):
  monkeypatched = False
  if action.default is not None and action.help is None:
  # Trick the default _format_action() method into writing out
  # the defaults.
  action.help = ' '
  monkeypatched = True
  formatted = super(BeckerDefaultFormatter,
  self)._format_action(action) if monkeypatched:
  action.help = None
  return formatted



Thanks!  Seems to work great.  It gave reasonable output for both case where I
include
help=...
and also without.

I have no idea how that above code works, but I guess as long as it works...


Just take a look at the implementation of HelpFormatter._format_action() and 
look for where my monkeypatch would change the logic. It took me just a few 
minutes to figure out how to do it in the first place. There really isn't 
anything tricky going on.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Periodic execution with asyncio

2013-11-22 Thread Tobias M.

Hello guys,

I am using the asyncio package (Codename 'Tulip'), which will be 
available in Python 3.4, for the first time.
I want the event loop to run a function periodically (e.g. every 2 
seconds). PEP 3156 suggests two ways to implement such a periodic call:


1. Using a callback that reschedules itself, using call_later().
2. Using a coroutine containing a loop and a sleep() call.

I implemented the first approach in a class with an easy to use 
interface. It can be subclassed and the run() method
can be overwritten to provide the code that will be called periodically. 
The interval is specified in the constructor and the task can be started 
and stopped:



import asyncio

class PeriodicTask(object):

def __init__(self, interval):
self._interval = interval
self._loop = asyncio.get_event_loop()

def _run(self):
self.run()
self._handler = self._loop.call_later(self._interval, self._run)

def run(self):
print('Hello World')

def start(self):
self._handler = self._loop.call_later(self._interval, self._run)

def stop(self):
self._handler.cancel()


To run this task and execute run() every 2 seconds you can do:

task = PeriodicTask(2)
task.start()
asyncio.get_event_loop().run_forever()


So far, this works for me. But as I have no experience with asynchronous 
IO I have two questions:


1. Is this a reasonable implementation or is there anything to improve?

2. How would you implement the second approach from the PEP (using a 
coroutine) with the same interface as my PeriodicTask above?


I tried the second approach but wasn't able to come up with a solution, 
as I was too confused by the concepts of coroutines, Tasks, etc.


Regards,
Tobias


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


Re: Why pickling (was: Traceback when using multiprocessing)

2013-11-22 Thread Chris Angelico
On Sat, Nov 23, 2013 at 3:38 AM, John Ladasky
john_lada...@sbcglobal.net wrote:
 On Thursday, November 21, 2013 8:24:05 PM UTC-8, Chris Angelico wrote:

 Oh, that part's easy. Let's leave the multiprocessing module out of it
 for the moment; imagine you spin up two completely separate instances
 of Python. Create some object in one of them; now, transfer it to the
 other. How are you going to do it?

 For what definition of completely separate?

 If I have two instances of the same version of the Python interpreter running 
 on the same hardware, and the same operating system, I expect I would just 
 copy a block of memory from one interpreter to the other, and then write some 
 new pointers.  That kind of data sharing has to be the most common kind.  
 It's also the simplest.

Okay, so you copy a block of memory. Now how are you going to
guarantee that you picked up everything that object references? Python
objects frequently reference other objects:

send_me = [1.0, 2.0, 3.0]

The block of memory might have the addresses of those three floats,
but that'll be invalid in the target. Somehow you need to package up
this object and everything else you need.

Ultimately, you need some system for turning a single object reference
(a pointer, if you like) into the entire package of information needed
to recreate that object on the other side. That's what pickling is.
It's a compact (with people to fight for its compactness, there's
current discussion elsewhere about that) format that can be easily
transferred around, which refcounted blocks of memory can't.

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


python for everyday tasks

2013-11-22 Thread koch . mate
Hello,

I'm about held a short course with the title indicated in the subjects. The 
students are very experienced programmers of our company, with deep knoledge on 
C, C++, C#, Perl and similar languages, but very limited, or absolutely no 
knowledge on python.

what would you teach to such a group in 5x1.5 hours? I'm looking for the most 
interesting, unique topics, emphesizing python's strong points. 

I have already a couple ideas:
 - a general intro about tuples, lists, dicts, sets, and working with these
 - functional programming tools, functools, itertools, lambda, map, filter
 - wsgi, pickle

I'd appreciate a lot if you could add some ideas

thanks, 
Mate
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Periodic execution with asyncio

2013-11-22 Thread Terry Reedy

On 11/22/2013 4:30 PM, Tobias M. wrote:


I am using the asyncio package (Codename 'Tulip'), which will be
available in Python 3.4, for the first time.


Great. New stuff, both behavior and API, needs to be 'exercised', 
especially by non-experts in the subject.  I have no experience with 
async stuff either.



I want the event loop to run a function periodically (e.g. every 2
seconds). PEP 3156 suggests two ways to implement such a periodic call:


The PEP is still the doc, and the Library Manual entry is a stub 
pointing back to it.

http://python.org/dev/peps/pep-3156/


1. Using a callback that reschedules itself, using call_later().
2. Using a coroutine containing a loop and a sleep() call.

I implemented the first approach in a class with an easy to use
interface. It can be subclassed and the run() method
can be overwritten to provide the code that will be called periodically.
The interval is specified in the constructor and the task can be started
and stopped:

import asyncio

class PeriodicTask(object):

 def __init__(self, interval):
 self._interval = interval
 self._loop = asyncio.get_event_loop()

 def _run(self):
 self.run()
 self._handler = self._loop.call_later(self._interval, self._run)

 def run(self):
 print('Hello World')

 def start(self):
 self._handler = self._loop.call_later(self._interval, self._run)

 def stop(self):
 self._handler.cancel()


To run this task and execute run() every 2 seconds you can do:

task = PeriodicTask(2)
task.start()
asyncio.get_event_loop().run_forever()



1. Is this a reasonable implementation or is there anything to improve?


It may be both reasonable and subject to change. Here is my version, 
with the following changes


* Make the task function a parameter 'func'.

* Rename start to _set to better describe what is does and call it in 
the _run function to not repeat the handler setting line. (If 'start' 
has any magic meaning, I am not aware of it. I am aware that there could 
be situations in which one would want a public method, to be called from 
other handlers. But that would be a different class ;-)


* Fully initialize the instance in __init__ by calling _set.

* Provide a clean way to stop the event loop without a traceback (or 
using Windows Task Manager.


* Comment out the stop method because it is useless in the current 
usage. I believe handler.cancel is only relevant after the handler is 
set and before it is fired. This can only be done from another handler.


import asyncio

class PeriodicTask(object):
 def __init__(self, func, interval):
 self.func = func
 self.interval = interval
 self._loop = asyncio.get_event_loop()
 self._set()
 def _set(self):
 self._handler = self._loop.call_later(self.interval, self._run)
 def _run(self):
 self.func()
 self._set()

## def stop(self):
## self._handler.cancel()

def f():
print('Hello World')

task = PeriodicTask(f, 2)
try:
asyncio.get_event_loop().run_forever()
except KeyboardInterrupt:
print('Loop stopped')


2. How would you implement the second approach from the PEP (using a
coroutine) with the same interface as my PeriodicTask above?


Theoretically, by Guido's rationale, that should be easier (for me, at 
least), since it would be more like the kind of Python code I already write.



I tried the second approach but wasn't able to come up with a solution,
as I was too confused by the concepts of coroutines, Tasks, etc.


I will try to look at the PEP and see how it works for me.

--
Terry Jan Reedy

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


find matching contiguous text

2013-11-22 Thread bruce
Hi.

I have a xpath test that generates the text/html between two xpath
functions, basically a chunk of HTML between two dom elements.

However, it's slow. As a test, I'd like to compare the speed if I get
all the HTML following a given element, and then get all the HTML
preceding a given element.. and then do a union/join/intersection of
the text between the two text segments.

I'm trying to find an efficient/effective approach to determining the
contiguous matching text, where the text starts with the 1st line in
the test from the following element test.

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


Re: Recursive generator for combinations of a multiset?

2013-11-22 Thread John O'Hagan
On Thu, 21 Nov 2013 12:59:26 -0800
Dan Stromberg drsali...@gmail.com wrote:

 On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan
 resea...@johnohagan.comwrote:
 
 
  Short story: the subject says it all, so if you have an answer
  already, fire away. Below is the long story of what I'm using it
  for, and why I think it needs to be recursive. It may even be of
  more general interest in terms of filtering the results of
  generators.
 
 
 I think you probably need permutations rather than combinations.
 
 Also, I think you'll need to form a word (partitioned off by spaces),
 and then check it against a set containing /usr/share/dict/words
 before recursing for the remainder of the sentence - this should
 speed things up a LOT.

Thanks for the reply. If I understand you correctly, you are suggesting
permuting the input _characters_ to form words and then seeing if
they exist, as opposed to my approach of combining known words and
seeing if they are anagrams. (Permutations of words would not help find
anagrams as they merely change the word order). Here is an attempt at
that:

def anagrams(partition, input_string):
Find anagrams which fit given partition of input string length
if not partition:
yield (), input_string
return
for words, checkstring in anagrams(partition[:-1], input_string):
for word in itertools.permutations(checkstring, partition[-1]):
word = ''.join(word)
if word in WORDS: #WORDS is collection of dictionary words
newstring = checkstring
for l in word:
newstring = newstring.replace(l, '' , 1)
yield words + (word,), newstring

There are two problems with this. If there are repeated characters in
the input, redundant results are produced; a multiset-permutation
algorithm would fix this. But the main problem is it is incredibly
slow: on my run-of-the-mill laptop, it chokes on anything longer than
about 10 characters, spending most of its time rejecting non-words.

Or have I misunderstood your suggestion?

Regards,

--

John

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


Re: Recursive generator for combinations of a multiset?

2013-11-22 Thread John O'Hagan
On Thu, 21 Nov 2013 18:14:41 -0800 (PST)
James hslee...@yahoo.com wrote:

 On Thursday, November 21, 2013 5:01:15 AM UTC-8, John O'Hagan wrote:

[...]

   On 21 November 2013 06:46, John O'Hagan 
  
   wrote:
  

[...]

  
def multicombs(it, r):
  
result = it[:r]
  
yield result
  
while 1:
  
for i in range(-1, -r - 1, -1):
  
rep = result[i]
  
if rep  it[i]:
  
break
  
else:
  
break
  
for j, n in enumerate(it):
  
if n  rep:
  
break
  
result = result[:i] + it[j:j - i]
  
yield result
  
   

[...]

  
  I neglected to mention that multicombs takes a sorted iterable;
  
  it doesn't work right otherwise. I'd forgotten that because my
  
  wordlists are guaranteed sorted by the way they're built. Sorry
  about
  
  that.
  
  
  
  In my use-case the first argument to multicombs is a tuple of words
  
  which may contain duplicates, and it produces all unique
  combinations
  
  of a certain length of those words, eg:
  
  
  
  list(multicombs(('cat', 'hat', 'in', 'the', 'the'), 3))
  
  
  
  [('cat', 'hat', 'in'), ('cat', 'hat', 'the'), ('cat', 'in', 'the'),
  
  ('cat', 'the', 'the'), ('hat', 'in', 'the'), ('hat', 'the', 'the'),
  
  ('in', 'the', 'the')]
  
  

[...]

  What I'm looking for is a recursive algorithm which does what
  
  multicombs does (order unimportant) so that I can apply a pruning
  
  shortcut like the one I used in the recursive cartesian product
  
  algorithm in my original post.
  
  
  
  Multiset combination algorithms seem pretty thin on the ground out
  
  there - as I said, I could only find a description of the procedure
  
  above, no actual code. The ones I did find are non-recursive. I'm
  
  hoping some combinatorics and/or recursion experts can offer
  advice. 
  
  

[...]

  
  John
 
 Could convert the following perl script to python?
 
 use Data::Dump qw(dump);
 dump combo([@ARGV], 3);
 
 sub combo {
 my ($t, $k) = @_;
 my @T = @$t;
 my @R = ();
 my %g = ();
 if ($k == 1) {
 for (@T) {
 push @R, $_ unless $g{$_}++;
 }
 } else {
 while (my $x = shift @T) {
 $p = combo([@T], $k-1);
 for (@{$p}) {
 my $q = $x.,.$_;
 push @R, $q unless $g{$q}++;
 }
 }
 }
 [@R];
 }
 
 $ prog.pl cat hat in the the
 [
   cat,hat,in,
   cat,hat,the,
   cat,in,the,
   cat,the,the,
   hat,in,the,
   hat,the,the,
   in,the,the,
 ]
 
 James


Thanks. Now I just have to learn Perl to understand what that
does! :)

Regards,

--

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


Re: Periodic execution with asyncio

2013-11-22 Thread Terry Reedy

On 11/22/2013 7:00 PM, Terry Reedy wrote:

On 11/22/2013 4:30 PM, Tobias M. wrote:


[snip callback versions by Tobias and me]


2. How would you implement the second approach from the PEP (using a
coroutine) with the same interface as my PeriodicTask above?


Theoretically, by Guido's rationale, that should be easier (for me, at
least), since it would be more like the kind of Python code I already
write.


I tried the second approach but wasn't able to come up with a solution,
as I was too confused by the concepts of coroutines, Tasks, etc.


I will try to look at the PEP and see how it works for me.


I was initially baffled also until I managed to assemble all the needed 
pieces.


import asyncio

def f():
print('Hello World')

@asyncio.coroutine
def g(func, interval):
while True:
yield from asyncio.sleep(interval)
func()

loop = asyncio.get_event_loop()

try:
loop.run_until_complete(asyncio.Task(g(f, 2)))
except KeyboardInterrupt:
print('Loop stopped')

I think Guido's point is that async generator version is quite similar 
to the 'normal' synchronous version.


import time

def f():
print('Hello World')

def h(func, interval):
while True:
time.sleep(interval)
func()

try:
h(f, 2))
except KeyboardInterrupt:
print('Loop stopped')

--
Terry Jan Reedy

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


Re: Suggest an open-source issue tracker, with github integration and kanban boards?

2013-11-22 Thread Alec Taylor
Miki: I would much prefer a Python implementation.

On Thu, Nov 21, 2013 at 4:07 AM, Miki Tebeka miki.teb...@gmail.com wrote:
 On Wednesday, November 20, 2013 6:36:56 AM UTC-8, Alec Taylor wrote:
 Anyway, here is the link: https://github.com/rauhryan/huboard
 I thought you wanted a Python bases solution.
 --
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


select.select()

2013-11-22 Thread Bhanu Karthik
please help me.. what does the following line do?

read_sockets,write_sockets,error_sockets = select.select(CONNECTION_LIST,[],[])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Denis McMahon
On Fri, 22 Nov 2013 18:22:29 +0530, Bharath Kummar wrote:

 Could you please help me with my current research ?  Am implementing the
 concept in python language.
 My doubts are :
 1)  Is it possible to Retrieve the address of a variable in python ?
 2)  Is it possible to Delete the Address of the Variable and create a
 new dynamic address inside the compiler/interpreter itself ?
 3)  Is it easy to find the Binary equivalence of a given Alphanumeric
 String ?
 4)  Is it possible to count the number of 1's in the Binary equivalence
 ?

 Could you PLEASE provide me with the codes (codes only for the asked
 queries) ?

The codes are:

1) 7373a28109a7c4473a475b2137aa92d5
2) f2fae9a4ad5ded75e4d8ac34b90d5c9c
3) 935544894ca6ad7239e0df048b9ec3e5
4) b1bc9942d029a4a67e4b368a1ff8d883

Please contact your local government eavesdropping agency for assistance 
on decoding the codes.

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


Re: python for everyday tasks

2013-11-22 Thread Steven D'Aprano
On Fri, 22 Nov 2013 15:59:19 -0800, koch.mate wrote:

 Hello,
 
 I'm about held a short course with the title indicated in the subjects.
 The students are very experienced programmers of our company, with deep
 knoledge on C, C++, C#, Perl and similar languages, but very limited, or
 absolutely no knowledge on python.
 
 what would you teach to such a group in 5x1.5 hours? I'm looking for the
 most interesting, unique topics, emphesizing python's strong points.
 
 I have already a couple ideas:
  - a general intro about tuples, lists, dicts, sets, and working with
  these - functional programming tools, functools, itertools, lambda,
  map, filter - wsgi, pickle


Do you have any system administrators in the audience? If so, I'd show 
the IPython shell, which includes a lot of custom magic to make it a 
powerful shell as easy to use as bash. For example, compare the regular 
Python REPL:

py import os, glob
py glob.glob(os.path.expanduser('~/lam*'))
['/home/steve/lambert.ods', '/home/steve/lambert.csv', '/home/steve/
lambertw.pdf', '/home/steve/lambert-v2.pdf', '/home/steve/lambert.txt']


with the IPython shell:

In [1]: ls ~/lam*
/home/steve/lambert.csv  /home/steve/lambert.txt /home/steve/
lambertw.pdf
/home/steve/lambert.ods  /home/steve/lambert-v2.pdf


You'll probably want to discuss the similarities and differences between 
Python and other languages. In my experience, the most confusing part of 
learning a new language is the things which are *almost* but not quite 
the same, rather than those which are radically different. When things 
are obviously different, you come in to it with no preconceived ideas.


* Python uses name binding, not variables at fixed locations;

* therefore there are no pointers (except under the hood, in the 
implementation);

* but you won't miss them. Honest.

* Python uses call by object sharing, which is exactly the same calling 
convention that the Java people call call by value and Ruby people call 
call by reference. Here's an opinionated post I wrote some years ago 
describing the differences:

https://mail.python.org/pipermail/tutor/2010-December/080505.html


* Python is not Java, and Java is not Python either:

http://dirtsimple.org/2004/12/python-is-not-java.html
http://dirtsimple.org/2004/12/java-is-not-python-either.html

* Everything in Python is an object. *Everything*. There is no 
distinction between boxed and unboxed integers, for example, they're all 
boxed.

* When I say everything, I mean it. Functions and methods are objects 
too. So are classes, and yes, that means that you can inspect the class 
of a class (the metaclass).

* Need high performance numeric computing? Python tools like numpy, 
pandas, nltk and others are rapidly becoming *the* standard tool for 
numeric and scientific computing:

http://blog.mikiobraun.de/2013/11/how-python-became-the-language-of-
choice-for-data-science.html

http://www.talyarkoni.org/blog/2013/11/18/the-homogenization-of-
scientific-computing-or-why-python-is-steadily-eating-other-languages-
lunch/


* Some terminology differences:

  - What some languages call members, or class variables and 
instance variables, Python usually calls class or instance 
attributes. (Although the documentation is a tad inconsistent
in this.) This makes sense: if a string variable is a 
variable holding a string, and an int variable is a variable
holding an int, then surely a class variable is a variable 
holding a class. (Remember what I said about classes being 
objects too?)

  - Python class methods are what Java calls static methods, and
Python static methods are kind of like functions only not.
(You'll probably never find a good use for static methods in 
Python.)

  - There are no procedures or void functions in Python, but 
there are functions which return None, which is as close as
you'll get to nil or null.

  - I already mentioned the pass by object sharing thing.

* The Zen of Python: at the interactive interpreter, type import this. 
It's not quite a joke and not quite serious, but a little of both, and it 
gives a good insight into what the Python core developers consider best 
practice.

* Note to Perl coders: you'll notice that Only One Way To Do It is NOT 
in there, and it never has been.

* Docstrings and doctest.

* Unittest is great for test-driven development.

* Python 3 (although not Python 2) is one of the few languages that get 
Unicode *right*. Strings in Python 3 are text, sequences of Unicode 
characters, not a thinly disguised blob of bytes. Starting with Python 
3.3, Python does away with the difference between narrow builds (which 
save memory at the expense of correctness) and wide builds (which give 
correct Unicode behaviour at the cost of memory). Instead, Python 3.3 now 
has optimized strings that use only as much memory as needed. Pure ASCII 
strings will use 1 byte per character, while Unicode strings use 1, 2 or 
4 bytes per character as needed. 

Re: Newbie - Trying to Help a Friend

2013-11-22 Thread Denis McMahon
On Wed, 20 Nov 2013 11:38:14 +, Duncan Booth wrote:

 Denis McMahon denismfmcma...@gmail.com wrote:

 1) Find all the numbers less than n that are not divisible by a, b, or
 c.

 ask the user for x;
 assign the value 0 to some other variable i;
 while i is not greater than than x do the following [
 if i is not divisible by a and i is not divisible by b and i is not
 divisible by c then display i to the user;
 add 1 to i;
 ]

 The question didn't ask to find all the numbers, it asked to count how
 many there are. 

My post was intended as a demonstration of how you can convert a problem 
into a sequence of steps that can then be programmed into a computer. Any 
resemblance to the posted question may have been accidental.

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


Re: select.select()

2013-11-22 Thread Roy Smith
In article b8d42424-e0ab-4595-9c87-25e5c1b53...@googlegroups.com,
 Bhanu Karthik bhanukarthik2...@gmail.com wrote:

 please help me.. what does the following line do?
 
 read_sockets,write_sockets,error_sockets = 
 select.select(CONNECTION_LIST,[],[])

This is a little tricky.

First,read the docs at http://docs.python.org/2/library/select.html.  
There's a lot of complicated stuff there, but just concentrate on the 
description of the select.select() call for now.

Imagine a process which has a lot of network connections open.  A great 
example would be something like a MUD (Multi User Dungeon).  You've got 
one server process(*) and a bunch of clients which have all made TCP 
connections over individual sockets.

Each client will be sending commands asynchronously, and the server 
needs to handle this.  You need some way to figure out which of those 
sockets have something that's been sent to you (which you need to 
process) and which are just sitting idle.  That's where select() comes 
in.  It gives you a way to say, Here's a list of sockets.  Sleep until 
one of them has something available for me to read, and let me know 
which one.

One bit of complication is that you can also check for sockets which are 
ready to be written on, and sockets which have some sort of error 
condition.  That's why the call returns a 3-tuple.  But, for now, let's 
just concentrate on reading.

Here's a very simplistic server which uses select():

import socket
import select

sock = socket.socket()
sock.bind(('localhost', 23000))
sock.listen(10)

# Accept four connections.
connections = []
for i in range(4):
s, addr = sock.accept()
print Got connection from %s % str(addr)
connections.append(s)

while True:
readable, _, _ = select.select(connections, [], [])
print ready for reading: %s % readable
for s in readable:
data = s.recv(1024)
print Read from %s: %s % (s, data)

You can write a little client which connects to this (I've got one I 
used for testing, but I'll leave it to you to write one yourself as an 
exercise).  Connect four clients, and have them send some input in 
random order.

Actually, this server has a bug (which you'll discover as soon as you 
close one of the four connection), but it should serve to illustrate the 
basic concept.


(*) I'm not sure if real MUDs are programmed this way, but it's a 
plausible architecture.  For simplicity sake, I'm assuming a 
single-threaded server.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Steven D'Aprano
On Sat, 23 Nov 2013 01:55:44 +, Denis McMahon wrote:

 On Fri, 22 Nov 2013 18:22:29 +0530, Bharath Kummar wrote:

 Could you PLEASE provide me with the codes (codes only for the asked
 queries) ?
 
 The codes are:
 
 1) 7373a28109a7c4473a475b2137aa92d5
 2) f2fae9a4ad5ded75e4d8ac34b90d5c9c
 3) 935544894ca6ad7239e0df048b9ec3e5
 4) b1bc9942d029a4a67e4b368a1ff8d883
 
 Please contact your local government eavesdropping agency for assistance
 on decoding the codes.

I'm not an expert on Indian English, but I understand that in that 
dialect it is grammatically correct to say the codes, just as in UK and 
US English it is grammatically correct to say the programs.

In other words, in UK/US English, code in the sense of programming code 
is an uncountable noun, like rice or air, while in Indian English it 
is a countable noun like cats or programs. We have to say give me two 
samples of code, or perhaps two code samples, while an Indian speaker 
might say give me two codes.

As this is an international forum, it behoves us all to make allowances 
for slight difference in dialect.

Aside: I love the fact that pea, as in green peas or black-eyed peas, is 
a back-formation from an uncountable noun. Originally English had the 
word pease, as in pease porridge hot from the nursery rhyme. Like 
wheat, rice, barley and others, You would have to say something like 
give me a grain of pease if you only wanted one. Eventually, people 
began to assume that pease, or peas, was the plural and therefore 
pea must be the singular. I look forward to the day that rice is the 
plural of ri :-)


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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Dave Angel
Try posting in text, as some of us see nothing in your message. This 
is a text newsgroup, not html.


Also make a subject line that summarizes your issue, not the urgency.

--
DaveA

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


Re: select.select()

2013-11-22 Thread Steven D'Aprano
On Fri, 22 Nov 2013 17:42:07 -0800, Bhanu Karthik wrote:

 please help me.. what does the following line do?
 
 read_sockets,write_sockets,error_sockets =
 select.select(CONNECTION_LIST,[],[])

The select.select function takes three arguments (plus an optional 
fourth):

select.select(read_list, write_list, exception_list)

Each list should a list of the file descriptors you want to wait for. On 
Windows, only sockets are valid file descriptors. On Unix or Linux, you 
can use sockets, open file objects, or low-level file descriptors.

In this case, you only pass CONNECTION_LIST, the others are empty lists 
[]. CONNECTION_LIST is probably a list of sockets to be read. When they 
are ready for reading, select() will return three lists:

read_sockets  - a list of the sockets open for reading

write_sockets and error_sockets should both be empty lists, since you 
didn't request any of those to be opened.



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


Re: python for everyday tasks

2013-11-22 Thread Ned Batchelder
On Friday, November 22, 2013 6:59:19 PM UTC-5, koch...@gmail.com wrote:
 Hello,
 
 I'm about held a short course with the title indicated in the subjects. The 
 students are very experienced programmers of our company, with deep knoledge 
 on C, C++, C#, Perl and similar languages, but very limited, or absolutely no 
 knowledge on python.
 
 what would you teach to such a group in 5x1.5 hours? I'm looking for the most 
 interesting, unique topics, emphesizing python's strong points. 
 
 I have already a couple ideas:
  - a general intro about tuples, lists, dicts, sets, and working with these
  - functional programming tools, functools, itertools, lambda, map, filter
  - wsgi, pickle
 
 I'd appreciate a lot if you could add some ideas
 
 thanks, 
 Mate

I gave a 45-minute presentation at the DevDays conference in 2009 to introduce 
programmers to Python.  The slides are here: 
http://nedbatchelder.com/text/devdays.html  Sorry there's no text to go with 
them.

They introduce the good points of Python, then go through two code exercises: 
Peter Norvig's spellchecker, which is great for showing off data structures; 
and a micro templating engine, which takes advantage of Python's dynamic nature.

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


Re: Recursive generator for combinations of a multiset?

2013-11-22 Thread MRAB

On 23/11/2013 00:58, John O'Hagan wrote:

On Thu, 21 Nov 2013 12:59:26 -0800
Dan Stromberg drsali...@gmail.com wrote:


On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan
resea...@johnohagan.comwrote:


 Short story: the subject says it all, so if you have an answer
 already, fire away. Below is the long story of what I'm using it
 for, and why I think it needs to be recursive. It may even be of
 more general interest in terms of filtering the results of
 generators.


I think you probably need permutations rather than combinations.

Also, I think you'll need to form a word (partitioned off by spaces),
and then check it against a set containing /usr/share/dict/words
before recursing for the remainder of the sentence - this should
speed things up a LOT.


Thanks for the reply. If I understand you correctly, you are suggesting
permuting the input _characters_ to form words and then seeing if
they exist, as opposed to my approach of combining known words and
seeing if they are anagrams. (Permutations of words would not help find
anagrams as they merely change the word order). Here is an attempt at
that:

def anagrams(partition, input_string):
 Find anagrams which fit given partition of input string length
 if not partition:
 yield (), input_string
 return
 for words, checkstring in anagrams(partition[:-1], input_string):
 for word in itertools.permutations(checkstring, partition[-1]):
 word = ''.join(word)
 if word in WORDS: #WORDS is collection of dictionary words
 newstring = checkstring
 for l in word:
 newstring = newstring.replace(l, '' , 1)
 yield words + (word,), newstring

There are two problems with this. If there are repeated characters in
the input, redundant results are produced; a multiset-permutation
algorithm would fix this. But the main problem is it is incredibly
slow: on my run-of-the-mill laptop, it chokes on anything longer than
about 10 characters, spending most of its time rejecting non-words.

Or have I misunderstood your suggestion?


If you want to know how to get unique permutations, have a look here:

http://mail.python.org/pipermail/python-ideas/2013-October/023610.html

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


Re: select.select()

2013-11-22 Thread Bhanu Karthik
On Friday, 22 November 2013 18:29:12 UTC-8, Steven D'Aprano  wrote:
 On Fri, 22 Nov 2013 17:42:07 -0800, Bhanu Karthik wrote:
 
 
 
  please help me.. what does the following line do?
 
  
 
  read_sockets,write_sockets,error_sockets =
 
  select.select(CONNECTION_LIST,[],[])
 
 
 
 The select.select function takes three arguments (plus an optional 
 
 fourth):
 
 
 
 select.select(read_list, write_list, exception_list)
 
 
 
 Each list should a list of the file descriptors you want to wait for. On 
 
 Windows, only sockets are valid file descriptors. On Unix or Linux, you 
 
 can use sockets, open file objects, or low-level file descriptors.
 
 
 
 In this case, you only pass CONNECTION_LIST, the others are empty lists 
 
 []. CONNECTION_LIST is probably a list of sockets to be read. When they 
 
 are ready for reading, select() will return three lists:
 
 
 
 read_sockets  - a list of the sockets open for reading
 
 
 
 write_sockets and error_sockets should both be empty lists, since you 
 
 didn't request any of those to be opened.
 
 
 
 
 
 
 
 -- 
 
 Steven

Thank you ,your message answered the question exactly.

instead of using select.select,can we do like below?

read_sockets=connection_list
write_sockets=[]
error_sockets=[]

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


Re: select.select()

2013-11-22 Thread Bhanu Karthik
On Friday, 22 November 2013 18:15:10 UTC-8, Roy Smith  wrote:
 In article b8d42424-e0ab-4595-9c87-25e5c1b53...@googlegroups.com,
 
  Bhanu Karthik bhanukarthik2...@gmail.com wrote:
 
 
 
  please help me.. what does the following line do?
 
  
 
  read_sockets,write_sockets,error_sockets = 
 
  select.select(CONNECTION_LIST,[],[])
 
 
 
 This is a little tricky.
 
 
 
 First,read the docs at http://docs.python.org/2/library/select.html.  
 
 There's a lot of complicated stuff there, but just concentrate on the 
 
 description of the select.select() call for now.
 
 
 
 Imagine a process which has a lot of network connections open.  A great 
 
 example would be something like a MUD (Multi User Dungeon).  You've got 
 
 one server process(*) and a bunch of clients which have all made TCP 
 
 connections over individual sockets.
 
 
 
 Each client will be sending commands asynchronously, and the server 
 
 needs to handle this.  You need some way to figure out which of those 
 
 sockets have something that's been sent to you (which you need to 
 
 process) and which are just sitting idle.  That's where select() comes 
 
 in.  It gives you a way to say, Here's a list of sockets.  Sleep until 
 
 one of them has something available for me to read, and let me know 
 
 which one.
 
 
 
 One bit of complication is that you can also check for sockets which are 
 
 ready to be written on, and sockets which have some sort of error 
 
 condition.  That's why the call returns a 3-tuple.  But, for now, let's 
 
 just concentrate on reading.
 
 
 
 Here's a very simplistic server which uses select():
 
 
 
 import socket
 
 import select
 
 
 
 sock = socket.socket()
 
 sock.bind(('localhost', 23000))
 
 sock.listen(10)
 
 
 
 # Accept four connections.
 
 connections = []
 
 for i in range(4):
 
 s, addr = sock.accept()
 
 print Got connection from %s % str(addr)
 
 connections.append(s)
 
 
 
 while True:
 
 readable, _, _ = select.select(connections, [], [])
 
 print ready for reading: %s % readable
 
 for s in readable:
 
 data = s.recv(1024)
 
 print Read from %s: %s % (s, data)
 
 
 
 You can write a little client which connects to this (I've got one I 
 
 used for testing, but I'll leave it to you to write one yourself as an 
 
 exercise).  Connect four clients, and have them send some input in 
 
 random order.
 
 
 
 Actually, this server has a bug (which you'll discover as soon as you 
 
 close one of the four connection), but it should serve to illustrate the 
 
 basic concept.
 
 
 
 
 
 (*) I'm not sure if real MUDs are programmed this way, but it's a 
 
 plausible architecture.  For simplicity sake, I'm assuming a 
 
 single-threaded server.

Thank you for your reply.your reply helped me figure out concept.
-- 
https://mail.python.org/mailman/listinfo/python-list


JSON translated into SQL by python

2013-11-22 Thread Aaron G.
I am new to programming python for JSON to SQL and I was wondering why this 
does not work. All the values for entering the DB are correct. The 
EnterpriseValue data is not entering the database.

 
#collect data from JSON source at Yahoo
url = [db, http://y.ahoo.it/wlB89;]
#check all sites
checkstatus(url[]);
#retrieve EnterpriseValue data from yahoo to DB
url = http://y.ahoo.it/wlB89;
data = helper.openJSON_URL(url)
#store data
curObservation = data[EnterpriseValue]

#connect to amazon and post data from Yahoo
conn = inti_psql_amazon(db name, db user, password, db source)
query = CREATE TABLE temp2 (ID int NOT NULL AUTO_INCREMENT, Enterprise_Value 
float, PRIMARY KEY(ID));
query = INSERT INTO TABLE temp2 (enterprise) VALUES(+ str(curObservation) 
+);   
do_query_amazon(conn, query)
close_psql_amazon(conn)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for everyday tasks

2013-11-22 Thread Dan Stromberg
Teach that Python emphasizes readability.  Perhaps talk about bugs /
lines_of_code being roughly a constant.  Then talk about the fact that
Python generally takes fewer lines of code to express the same thing.  This
implies fewer bugs for many projects.

Teach the fundamental types, with differences from other languages: int,
float (C double), decimal, maybe fractions.  Booleans.  lists, arrays,
dictionaries, sets, tuples, frozensets.

Teach that variables don't have a type, but values do.  Teach a = b.  Teach
a, b = b, a.  Teach that python is duck typed (dynamically typed), and
isn't manifestly or statically typed.  Provide definitions.  Discuss what
it means to be strongly typed, which doesn't mean what a lot of people
think it does: Python is strongly typed, the main exception being that you
can use almost anything in a boolean context.

Teach the control flow, with differences from other languages: while,
for/else, if/elif/else. break/continue, list comprehensions, and maybe
generator expressions.  Include things like enumerate() and iterators and
with statements.  Probably do yield too - it's not crucial to being
productive in python, but it's plenty useful; probably show how it can
generate powers of 2 forever or something.

Teach that python has builtins, not keywords - IOW, you can redefine list
or int, but you probably shouldn't.  pylint helps with this.

Teach classes with __init__.   Teach __str__, __repr__, and teach __cmp__
or __lt__ (depending on your python version), and perhaps some other magic
methods like (a subset of) emulating a container, or emulating a number.
Maybe talk about Python's stellar built in Timsort that was later adopted
by Java.

Teach pylint, including how to turn off unimportant warnings; I usually do
this in my code, but you can also use a pylintrc.  A short time talking
about pylint (or pychecker or pyflakes, and perhaps pep8 too) should help
them teach themselves quite a bit - think of these as expert systems about
how to write better python.  Personally, I use a pyflakes plugin in vim,
but my default make rule invokes pylint for the entire project, as well
as my automated tests one at a time.  Sometimes my default make rule does
pep8 too, but not always; pylint covers a lot of what pep8 does anyway.

Touch briefly on a cross-platform debugger like winpdb (it's cross-platform
despite the name) or pudb.  Some people will prefer to just do print
functions/statements (again depending on python version), but others will
really value the debugger, and some people will use some of both.

Stress the importance of automated tests relative to other languages.  IMO,
even with pylint, having plenty of good automated tests is crucial in a
large python project, especially if it's multi-programmer.

If you have time, provide some guidance about whether to use Python 2.x or
3.x.  IMO, projects that have their dependencies satisfied in 3.x (or have
no dependencies!), should use 3.x today.  Otherwise, use 2.x with from
__future__ imports where practical.

Talk about decorators.

If you have time, maybe talk about available interpreters: CPython 2.x,
CPython 3.x, Jython (python in java that can call java classes), Pypy
(python in python with a JIT), IronPython (IronPython lacks a standard
library for the most part, but lets you talk to .net classes).  Maybe also
talk about Python in the browser:
http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html .
There was a time when Jython could be used for in-browser-python by
generating .class files, but I don't think it can anymore, and java browser
plugins seem to be disappearing anyway; the world seems to be heading
toward javascript for in-browser, RIA.

Feel free to raid
http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/for slides.

HTH



On Fri, Nov 22, 2013 at 3:59 PM, koch.m...@gmail.com wrote:

 Hello,

 I'm about held a short course with the title indicated in the subjects.
 The students are very experienced programmers of our company, with deep
 knoledge on C, C++, C#, Perl and similar languages, but very limited, or
 absolutely no knowledge on python.

 what would you teach to such a group in 5x1.5 hours? I'm looking for the
 most interesting, unique topics, emphesizing python's strong points.

 I have already a couple ideas:
  - a general intro about tuples, lists, dicts, sets, and working with these
  - functional programming tools, functools, itertools, lambda, map, filter
  - wsgi, pickle

 I'd appreciate a lot if you could add some ideas

 thanks,
 Mate
 --
 https://mail.python.org/mailman/listinfo/python-list

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


Re: Recursive generator for combinations of a multiset?

2013-11-22 Thread Dan Stromberg
On Fri, Nov 22, 2013 at 4:58 PM, John O'Hagan resea...@johnohagan.comwrote:

 On Thu, 21 Nov 2013 12:59:26 -0800
 Dan Stromberg drsali...@gmail.com wrote:

  On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan
  resea...@johnohagan.comwrote:
 
  
   Short story: the subject says it all, so if you have an answer
   already, fire away. Below is the long story of what I'm using it
   for, and why I think it needs to be recursive. It may even be of
   more general interest in terms of filtering the results of
   generators.
  
 
  I think you probably need permutations rather than combinations.
 
  Also, I think you'll need to form a word (partitioned off by spaces),
  and then check it against a set containing /usr/share/dict/words
  before recursing for the remainder of the sentence - this should
  speed things up a LOT.

 Thanks for the reply. If I understand you correctly, you are suggesting
 permuting the input _characters_ to form words and then seeing if
 they exist, as opposed to my approach of combining known words and
 seeing if they are anagrams. (Permutations of words would not help find
 anagrams as they merely change the word order). Here is an attempt at
 that:


You've interpreted me correctly.

However, I was thinking about this in the back of my mind, and decided it
would probably be best to inhale /usr/share/dict/words (if on Linux), and
pull out words of the corrects lengths (as separated by the blanks) over
the correct (possible) alphabet, and permute Those, afterward checking if
they form good anagrams of the original sentence.  This would probably be
much faster, since English isn't that dense of a space.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for everyday tasks

2013-11-22 Thread Dan Stromberg
I almost forgot: Talk about pypi and pip (or similar) too.

On Fri, Nov 22, 2013 at 3:59 PM, koch.m...@gmail.com wrote:

 Hello,

 I'm about held a short course with the title indicated in the subjects.
 The students are very experienced programmers of our company, with deep
 knoledge on C, C++, C#, Perl and similar languages, but very limited, or
 absolutely no knowledge on python.

 what would you teach to such a group in 5x1.5 hours? I'm looking for the
 most interesting, unique topics, emphesizing python's strong points.

 I have already a couple ideas:
  - a general intro about tuples, lists, dicts, sets, and working with
 these
  - functional programming tools, functools, itertools, lambda, map, filter
  - wsgi, pickle

 I'd appreciate a lot if you could add some ideas

 thanks,
 Mate
 --
 https://mail.python.org/mailman/listinfo/python-list



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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-22 Thread Ian Kelly
On Fri, Nov 22, 2013 at 7:18 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 I'm not an expert on Indian English, but I understand that in that
 dialect it is grammatically correct to say the codes, just as in UK and
 US English it is grammatically correct to say the programs.

I wouldn't necessarily even consider it an Indian thing, as I've known
Americans to use the same phrase.


On Fri, Nov 22, 2013 at 8:47 PM, Dennis Lee Bieber
wlfr...@ix.netcom.com wrote:
 On 23 Nov 2013 02:18:03 GMT, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info declaimed the following:


Aside: I love the fact that pea, as in green peas or black-eyed peas, is
a back-formation from an uncountable noun. Originally English had the
word pease, as in pease porridge hot from the nursery rhyme. Like
wheat, rice, barley and others, You would have to say something like
give me a grain of pease if you only wanted one. Eventually, people
began to assume that pease, or peas, was the plural and therefore
pea must be the singular. I look forward to the day that rice is the
plural of ri :-)

 Rice is the plural of rouse

Not according to the dictionary.  But it does seem a more likely
candidate for a hypothetical back formation than ri, which perhaps
was your point.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python for everyday tasks

2013-11-22 Thread Chris Angelico
On Sat, Nov 23, 2013 at 5:28 PM, Dan Stromberg drsali...@gmail.com wrote:
 Teach that python has builtins, not keywords - IOW, you can redefine list or
 int, but you probably shouldn't.  pylint helps with this.

Well, Python has keywords, but uses builtins for many things that
other languages use keywords (or magic) for.

 None=1
SyntaxError: assignment to keyword
 list=[]
 del list

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


Re: select.select()

2013-11-22 Thread Chris Angelico
On Sat, Nov 23, 2013 at 1:15 PM, Roy Smith r...@panix.com wrote:
 (*) I'm not sure if real MUDs are programmed this way, but it's a
 plausible architecture.  For simplicity sake, I'm assuming a
 single-threaded server.

Yeah, they certainly can. That's effectively the way that I programmed
the MUD kernel that we used at work (not for games, but it's still
effectively a MUD), although I used async I/O facilities to abstract
away the actual select calls. It's as good as the multi-threaded model
(which is what I use in Minstrel Hall - every connection spawns a
thread, which does blocking reads and blocking writes; simplifies the
code when a command wants to delay the user, as it simply sleep()s),
and can often scale to more concurrent connections, although for the
bulk of servers that's not going to be an issue.

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


Re: JSON translated into SQL by python

2013-11-22 Thread Chris Angelico
On Sat, Nov 23, 2013 at 4:54 PM, Aaron G.
another.human.fac...@gmail.com wrote:
 query = INSERT INTO TABLE temp2 (enterprise) VALUES(+ str(curObservation) 
 +);

You just put the contents of curObservation into the query, as SQL
code. Is that really what you wanted to do? Most likely, you should be
using a parameterized query here; are you familiar with that concept?

You seem to have custom functions to do your database work here.
Without knowing what those functions do, it's hard for us to advise
further.

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


[issue19553] PEP 453: make install and make altinstall integration

2013-11-22 Thread Ned Deily

Ned Deily added the comment:

The proposed patch with minor changes is now pushed.  I believe all of the 
review points have either been resolved or are covered by separate pip issues 
with the exception of item 8.  For item 6 (permissions not being forced), I 
decided that there are so many other files that are also not having permissions 
forced that it is silly to single out ensurepip.  Issue15890 should cover a 
comprehensive solution for all files.  In the meantime, the solution remains to 
set umask appropriately (e.g. 022) before running make install or make 
altinstall.  I'm removing release blocker status and propose closing this 
issue once a decision about and/or home for item 8 is found.

--
priority: release blocker - 
resolution:  - fixed
stage: patch review - committed/rejected
status: open - pending

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19553
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

Victor, you can propose whatever you like for 3.5, but I'm not adding new
interpreter state two days before feature freeze when we don't have to.
Looking up the private CodecInfo attribute is still O(1) anyway.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18864] Implementation for PEP 451 (importlib.machinery.ModuleSpec)

2013-11-22 Thread Claudiu.Popa

Changes by Claudiu.Popa pcmantic...@gmail.com:


--
nosy: +Claudiu.Popa

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18864
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17457] Unittest discover fails with namespace packages and builtin modules

2013-11-22 Thread Claudiu.Popa

Claudiu.Popa added the comment:

Hello! Attached patch which uses ModuleSpec, tested with 
http://hg.python.org/features/pep-451/ repo.

--
Added file: http://bugs.python.org/file32771/unittest_discovery_spec2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17457
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19550] PEP 453: Windows installer integration

2013-11-22 Thread Ned Deily

Ned Deily added the comment:

If it is acceptable for the Remove option to be somewhat unpredictable in the 
case where pip or setuptools was already installed and not by the installer, 
would python -m pip uninstall --yes pip setuptools work?  If not, should a 
new issue be opened to find a solution?

--
nosy: +ned.deily

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19550
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19599] Failure of test_async_timeout() of test_multiprocessing_spawn: TimeoutError not raised

2013-11-22 Thread Richard Oudkerk

Changes by Richard Oudkerk shibt...@gmail.com:


--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19599
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19550] PEP 453: Windows installer integration

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

I think Off by default is a reasonable solution for the beta (and
even 3.4 final), but a separate issue explaining *why* it's off by
default would be good. I can then ping the pip folks to ask for
suggestions - if they come up with something workable, we may be able
to have it turned on by default in 3.4 final.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19550
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19557] ast - docs for every node type are missing

2013-11-22 Thread anatoly techtonik

anatoly techtonik added the comment:

Neither you nor docs answer the question when Assign node gets Tuple as 
argument, when List and when Subscript.

While it is obvious to you, I personally don't know what a Subscript is. This 
is the kind of stuff that I'd like to see documented.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19557
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19555] SO config var not getting set

2013-11-22 Thread STINNER Victor

STINNER Victor added the comment:

Test is failing on Windows:

http://buildbot.python.org/all/builders/x86%20Windows%20Server%202003%20%5BSB%5D%203.x/builds/1758/steps/test/logs/stdio

==
ERROR: test_SO_in_vars (test.test_sysconfig.TestSysConfig)
--
Traceback (most recent call last):
  File 
E:\Data\buildslave\cpython\3.x.snakebite-win2k3r2sp2-x86\build\lib\test\test_sysconfig.py,
 line 388, in test_SO_in_vars
self.assertIsNotNone(vars['SO'])
KeyError: 'SO'

==
FAIL: test_SO_value (test.test_sysconfig.TestSysConfig)
--
Traceback (most recent call last):
  File 
E:\Data\buildslave\cpython\3.x.snakebite-win2k3r2sp2-x86\build\lib\test\test_sysconfig.py,
 line 382, in test_SO_value
sysconfig.get_config_var('EXT_SUFFIX'))
AssertionError: None != '.pyd'

--
nosy: +haypo
resolution: fixed - 
status: closed - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19555
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17134] Use Windows' certificate store for CA certs

2013-11-22 Thread STINNER Victor

STINNER Victor added the comment:

The test is failing:

http://buildbot.python.org/all/builders/x86%20Windows%20Server%202003%20%5BSB%5D%203.x/builds/1758/steps/test/logs/stdio

==
FAIL: test_enum_certificates (test.test_ssl.BasicSocketTests)
--
Traceback (most recent call last):
  File 
E:\Data\buildslave\cpython\3.x.snakebite-win2k3r2sp2-x86\build\lib\test\test_ssl.py,
 line 553, in test_enum_certificates
self.assertIn(serverAuth, names)
AssertionError: '1.3.6.1.5.5.7.3.1' not found in {'1.3.6.1.5.5.7.3.3', 
'1.3.6.1.4.1.311.10.3.5', '2.16.840.1.113730.4.1', '2.16.840.1.113733.1.8.1'}

--

--
nosy: +haypo
resolution: fixed - 
status: closed - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17134
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

- switched to LookupError for the dedicated exception
- default value moved to a CodecInfo class attribute
- new private APIs guarded by PY_LIMITED_API
- used repr formatting where appropriate in the tests
- cleaned up the tests a bit by using encodings.normalize_encoding
- new test to ensure the codec output type checks are still exercised
- backwards compatibility tweaks for raw tuples returned from the codec 
registry lookup (uncovered by the full test suite run)

I'll be committing this version after a final local run of make test and a 
refleak check on test_codecs, test_charmapcodec and test_unicode (the latter 
two are the ones that found the backwards compatibility issue with the 
attribute lookup).

--
Added file: 
http://bugs.python.org/file32772/issue19619_blacklist_transforms_py34_postreview.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

Nick: I've had a look at your second patch. A couple of notes:

 * I think you should add the flag to the constructor of the CodecInfo
   tuple subclass and then set this in the resp. codecs. The extra
   constructor class method looks too much like a hack and is
   not needed.

 * The comment in codecs.h should read:

   
   Checks the encoding against a list of codecs which do not
   implement a str-bytes encoding before attempting the
   operation.

   Please note that these APIs are internal and should not
   be used in Python C extensions.
   

Regarding Victor's suggestion to use a separate registry dict
for this: I'm definitely -1 on this.

The black listing is a very special case only used for the
.encode()/.decode() methods and otherwise doesn't have anything to do
with the codecs sub-system. It doesn't make sense to change the design
of the registry just to implement this one special case.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19685] open() fails to autodetect utf-8 if LANG=C

2013-11-22 Thread Curtis Doty

New submission from Curtis Doty:

I first stumbled across this bug attempting to install use pip's cool editable 
mode:

$ pip install -e git+git://github.com/appliedsec/pygeoip.git#egg=pygeoip
Obtaining pygeoip from git+git://github.com/appliedsec/pygeoip.git#egg=pygeoip
  Cloning git://github.com/appliedsec/pygeoip.git to ./src/pygeoip
  Running setup.py egg_info for package pygeoip
Traceback (most recent call last):
  File string, line 16, in module
  File /home/curtis/python/3.3.3/lib/python3.3/encodings/ascii.py, line 
26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1098: 
ordinal not in range(128)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

  File string, line 16, in module

  File /home/curtis/python/3.3.3/lib/python3.3/encodings/ascii.py, line 26, 
in decode

return codecs.ascii_decode(input, self.errors)[0]

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1098: 
ordinal not in range(128)


Cleaning up...
Command python setup.py egg_info failed with error code 1 in 
/home/curtis/python/2013-11-20/src/pygeoip
Storing complete log in /home/curtis/.pip/pip.log


It turns out this is related to a local LANG=C environment. If I set 
LANG=en_US.UTF-8, the problem goes away. But it seems pip/python3 open() should 
be more intelligently handling this.

Worse, the file in this case 
https://github.com/appliedsec/pygeoip/blob/master/setup.py already has a source 
code decorator *declaring* it as utf-8.

Ugly workaround patch is to force pip to always use 8-bit encoding on setup.py:

--- pip.orig/req.py 2013-11-19 15:53:49.0 -0800
+++ pip/req.py  2013-11-20 16:37:23.642656132 -0800
@@ -281,7 +281,7 @@ def replacement_run(self):
 writer(self, ep.name, os.path.join(self.egg_info,ep.name))
 self.find_sources()
 egg_info.egg_info.run = replacement_run
-exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))
+exec(compile(open(__file__,encoding='utf_8').read().replace('\\r\\n', '\\n'), 
__file__, 'exec'))
 
 
 def egg_info_data(self, filename):
@@ -687,7 +687,7 @@ exec(compile(open(__file__).read().repla
 ## FIXME: should we do --install-headers here too?
 call_subprocess(
 [sys.executable, '-c',
- import setuptools; __file__=%r; 
exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 
'exec')) % self.setup_py]
+ import setuptools; __file__=%r; 
exec(compile(open(__file__,encoding='utf_8').read().replace('\\r\\n', '\\n'), 
__file__, 'exec')) % self.setup_py]
 + list(global_options) + ['develop', '--no-deps'] + 
list(install_options),
 
 cwd=self.source_dir, filter_stdout=self._filter_install,


But that only treats the symptom. Root cause appears to be in python3 as 
demonstrated by this simple script:

wrong-codec.py:
#! /bin/env python3
from urllib.request import urlretrieve
urlretrieve('https://raw.github.com/appliedsec/pygeoip/master/setup.py', 
filename='setup.py')

# if LANC=C then locale.py:getpreferredencoding()-'ANSI_X3.4-1968'
foo= open('setup.py')

# bang! ascii_decode() cannot handle the unicode
bar= foo.read()


This does not occur in python2. Is this bug in pip or python3?

--
components: Unicode
messages: 203673
nosy: GreenKey, ezio.melotti, haypo
priority: normal
severity: normal
status: open
title: open() fails to autodetect utf-8 if LANG=C
type: crash
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19685
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

On 22.11.2013 12:24, Marc-Andre Lemburg wrote:
 
 Nick: I've had a look at your second patch. A couple of notes:
 
  * I think you should add the flag to the constructor of the CodecInfo
tuple subclass and then set this in the resp. codecs. The extra
constructor class method looks too much like a hack and is
not needed.

Like this:

_is_text_encoding = True # Assume codecs are text encodings by default

def __new__(cls, encode, decode, streamreader=None, streamwriter=None,
incrementalencoder=None, incrementaldecoder=None, name=None,
_is_text_encoding=None):
self = tuple.__new__(cls, (encode, decode, streamreader, streamwriter))
self.name = name
self.encode = encode
self.decode = decode
self.incrementalencoder = incrementalencoder
self.incrementaldecoder = incrementaldecoder
self.streamwriter = streamwriter
self.streamreader = streamreader
if _is_text_encoding is not None:
self._is_text_encoding = _is_text_encoding
return self

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

- switched the private flag from being set in a class method to using a keyword 
only parameter to __init__
- updated the codecs.h comment as MAL suggested

--
Added file: 
http://bugs.python.org/file32773/issue19619_blacklist_transforms_py34_keyword_only_param.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread STINNER Victor

STINNER Victor added the comment:

If _is_text_encoding may change in Python 3.5, you should add a comment to warn 
users to not use it and explain its purpose, maybe with a reference to this 
issue.

--

We have talking about a very few codecs:

* base64: bytes = bytes
* bz2: bytes = bytes
* hex: bytes = bytes; decode supports also ASCII string (str) = bytes
* quopri: bytes = bytes
* rot_13: str = str
* uu: bytes = bytes
* zlib: bytes = bytes

I suppose that supporting ASCII string input to the hex decoder is a border 
effect of its implementation. I don't know if it is expected *for the codec*.

If we simplify the hex decoder to reject str types, all these codecs would have 
simply one type: same input and output type. Anyway, if you want something 
based on types, the special case for the hex decoder cannot be expressed with a 
type nor ABC. ASCII string is not a type.

So instead of  _is_text_encoding=False could be transform=bytes or 
transform=str. (I don't care of the name: transform_type, type, codec_type, 
data_type, etc.)

I know that bytes is not exact: bytearray, memoryview and any bytes-like object 
is accepted, but it is a probably enough for now.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

On 22.11.2013 12:43, STINNER Victor wrote:
 
 STINNER Victor added the comment:
 
 If _is_text_encoding may change in Python 3.5, you should add a comment to 
 warn users to not use it and explain its purpose, maybe with a reference to 
 this issue.

+1

 --
 
 We have talking about a very few codecs:
 
 * base64: bytes = bytes
 * bz2: bytes = bytes
 * hex: bytes = bytes; decode supports also ASCII string (str) = bytes
 * quopri: bytes = bytes
 * rot_13: str = str
 * uu: bytes = bytes
 * zlib: bytes = bytes
 
 I suppose that supporting ASCII string input to the hex decoder is a border 
 effect of its implementation. I don't know if it is expected *for the codec*.
 
 If we simplify the hex decoder to reject str types, all these codecs would 
 have simply one type: same input and output type. Anyway, if you want 
 something based on types, the special case for the hex decoder cannot be 
 expressed with a type nor ABC. ASCII string is not a type.
 
 So instead of  _is_text_encoding=False could be transform=bytes or 
 transform=str. (I don't care of the name: transform_type, type, codec_type, 
 data_type, etc.)
 
 I know that bytes is not exact: bytearray, memoryview and any bytes-like 
 object is accepted, but it is a probably enough for now.

I think it's better to go with something that's explicitly internal
now than to fix a public API in form of a constructor parameter
this late in the release process.

For 3.5 it may make sense to declare a few codec feature flags which
would then make lookups such as the one done for the blacklist easier
to implement and faster to check as well.

Such flags could provide introspection at a higher level than what
would be possible with type mappings (even though I still like the
idea of adding those to CodecInfo at some point).

One possible use for such flags would be to declare whether a
codec is reversible or not - in other words, whether .decode(.encode(x))
works for all possible inputs x. This flag could then be used to
quickly check whether a codec would fail on a Unicode str which
has non-Latin-1 code points or to create a list of valid encodings
for certain applications, e.g. a list which only contains reversible
Unicode encodings such as the UTF ones.

Anyway: Thanks to Nick for implementing this, to Serhiy for the black
list idea and Victor for the attribute idea :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19660] decorator syntax: allow testlist instead of just dotted_name

2013-11-22 Thread Eric V. Smith

Eric V. Smith added the comment:

While I think that the dotted_name restriction should be relaxed and it should 
instead be a style guide issue, I have to agree with Benjamin here: the 
difference in grammar complexity is zero and shouldn't drive the decision.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19660
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread STINNER Victor

STINNER Victor added the comment:

2013/11/22 Marc-Andre Lemburg rep...@bugs.python.org:
 Anyway: Thanks to Nick for implementing this, to Serhiy for the black
 list idea and Victor for the attribute idea :-)

In fact, the attribute idea comes from you :-)
http://bugs.python.org/issue7475#msg96374

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19686] possible unnecessary memoryview copies?

2013-11-22 Thread Stefan Krah

Stefan Krah added the comment:

David is correct:  No data is copied, but new memoryview objects with different 
shape and strides are created. That is relatively cheap.

--
nosy: +skrah
resolution:  - invalid
stage:  - committed/rejected
status: open - closed
type: enhancement - behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19686
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19553] PEP 453: make install and make altinstall integration

2013-11-22 Thread Donald Stufft

Donald Stufft added the comment:

I'm honestly not sure what to do about #8 on your list. It's sort of a really 
wierd edge case as far as pip is concerned right now because the support for 
the versioned commands and differing them is sort of a hack job while we wait 
for proper support from a PEP.

Probably long term wise once there's support for this in a PEP pip will gain 
some sort of regenerate scripts commands that could handle this case better.

I'm struggling to come up with a good solution in the interim though :(

--
status: pending - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19553
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

It turns out the codec cache and the refleak hunting mechanism in regrtest 
*really* don't like each other if you use closures to implement your test 
codecs :)

Anyway, the attached patch tweaks the tests to handle refleak hunting (and 
running the refleak hunter indicates there aren't any leaks). I'll be 
committing this one immediately after posting this.

And like MAL, I'm keen to stick with a fully private API at this point, as I 
believe we need to get the status quo clearly documented before we can start 
talking about making changes to the public APIs.

I think both this issue and issue 7475 show that until we have a common 
understanding amongst the core development team of what's possible now, it's 
hard to discuss:

- what's currently possible that we would like to deprecate? (opinions differ 
strongly on this one - MAL and I think the status quo is mostly OK, but could 
use some better type inference support, Victor would like to see support for 
anything beyond text encodings, binary transforms and text transforms 
deprecated)
- what's not possible that we would like to make possible? (e.g. removing 
cached codecs, removing search functions, reordering search functions, type 
inference through the codec machinery)
- what's already possible that we would like to make easier? (e.g. registering 
new codecs)

--
Added file: 
http://bugs.python.org/file32774/issue19619_blacklist_transforms_py34_refleak_hunting.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

Well, that patch minus the debugging print that was still in there :)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d68df99d7a57 by Nick Coghlan in branch 'default':
Issue #19619: Blacklist non-text codecs in method API
http://hg.python.org/cpython/rev/d68df99d7a57

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19619] Blacklist base64, hex, ... codecs from bytes.decode() and str.encode()

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

3.4 has been dealt with. A similar functional patch should work in 3.3, but the 
test changes will be different (since those test cases don't exist yet in 3.3, 
and the wrapping ones aren't relevant at all).

--
versions:  -Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19619
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7475] codecs missing: base64 bz2 hex zlib hex_codec ...

2013-11-22 Thread Nick Coghlan

Nick Coghlan added the comment:

The 3.4 portion of issue 19619 has been addressed, so removing it as a 
dependency again.

--
dependencies:  -Blacklist base64, hex, ... codecs from bytes.decode() and 
str.encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   3   4   >