How to install googleapp engine on ubuntu 12.04 already downloads google_appengine_1.8.2.zip

2013-08-01 Thread Jaiky
How to install googleapp engine on ubuntu 12.04 

already did:
downloaded google_appengine_1.8.2.zip
unziped it 


now?/ please help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Script that converts between indentation and curly braces in Python code

2013-08-01 Thread IshIsh
from __future__ import braces is just an easter egg... ...and shouldn't 
it better state from __past__ import braces ;-)


Anyway, as far as I know the IPython interpreter can recognize lines 
ending in ‘:’ and indent the next line, while also un-indenting 
automatically after ‘raise’ or ‘return’.


=> sas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using system python vs. updated/current version

2013-08-01 Thread Ben Last
> From: memilanuk 
> How much of a pain are virtualenvs when working from an IDE?
>

That depends on the IDE. I use PyCharm, and it has support for setting up
multiple Python virtualenvs, and associated different projects with
different virtualenvs, as well as tracking the packages installed per
virtualenv, etc.

I personally never touch the system Python install (I run ubuntu) because I
can never be sure what other OS systems rely on them. I use virtualenvs for
all development.

b
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with psycopg2, bytea, and memoryview

2013-08-01 Thread Frank Millman

"Neil Cerutti"  wrote in message 
news:b5sk3cfkiq...@mid.individual.net...
> On 2013-07-31, Frank Millman  wrote:
>>
>>
>> Can anyone explain *why* the results do not compare equal? If I
>> understood the problem, I might be able to find a workaround.
>
> A memoryview will compare equal to another object that supports
> the buffer protocol when the format and shape are also equal. The
> database must be returning chunks of binary data in a different
> shape or format than you are writing it.
>
> Perhaps psycopg2 is returning a chunk of ints when you have
> written a chunk of bytes. Check the .format and .shape members of
> the return value to see.
>
 x = memoryview(b"12345")
 x.format
> 'B'
 x.shape
> (5,)
 x == b"12345"
> True
>
> My guess is you're getting format "I" from psycopg2. Hopefully
> there's a way to coerce your desired "B" format interpretation of
> the raw data using psycopg2's API.
>

Thanks very much for the explanation, Neil.

I tried what you suggested, and the object returned by psycopg2 has a format 
of 'c' and a shape of (5,).

I don't know what it means, but luckily I have found a workaround. I 
enquired on the psycopg2 list, and someone explained how I can create an 
extension that forces it to return 'bytes' instead of a 'memoryview'. I 
tested it and it works. Problem solved :-)

For the record, I passed on the suggestion from Antoine and Terry that they 
change their program to return 'bytes'. It will be interesting to see if 
anyone responds.

Thanks again to all for your help.

Frank



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


Re: Unexpected results comparing float to Fraction

2013-08-01 Thread Oscar Benjamin
On 1 August 2013 07:32, Chris Angelico  wrote:
> On Thu, Aug 1, 2013 at 7:20 AM, Steven D'Aprano
>  wrote:
>> I know this, and that's not what surprised me. What surprised me was that
>> Fraction converts the float to a fraction, then compares. It surprises me
>> because in other operations, Fractions down-cast to float.
>>
>> Adding a float to a Fraction converts the Fraction to the nearest float,
>> then adds:
>>
>> py> 1/3 + Fraction(1, 3)
>> 0.
>
> Hmm. This is the one that surprises me. That would be like the
> addition of a float and an int resulting in an int (at least in C; in
> Python, where floats have limited range and ints have arbitrary
> precision, the matter's not quite so clear-cut). Perhaps this needs to
> be changed?

The Python numeric tower is here:
http://docs.python.org/3/library/numbers.html#module-numbers

Essentially it says that
Integral < Rational < Real < Complex
and that numeric coercions in mixed type arithmetic should go from
left to right which makes sense mathematically in terms of the
subset/superset relationships between the numeric fields.

When you recast this in terms of Python's builtin/stdlib types it becomes
int < Fraction < {float, Decimal} < complex
and taking account of boundedness and imprecision we find that the
only subset/superset relationships that are actually valid are
int < Fraction
and
float < complex
In fact Fraction is a superset of both float and Decimal (ignoring
inf/nan/-0 etc.). int is not a subset of float, Decimal or complex.
float is a superset of none of the types. Decimal is a superset of
float but the tower places them on the same level.

The real dividing line between {int, Fraction} and {float, Decimal,
complex} is about (in)exactness. The numeric tower ensures the
property that inexactness is contagious which I think is a good thing.
This is not explicitly documented anywhere. PEP 3141 makes a dangling
reference to an Exact ABC as a superclass of Rational but this is
unimplemented anywhere AFAICT:
http://www.python.org/dev/peps/pep-3141/

The reason contagious inexactness is a good thing is the same as
having contagious quite NaNs. It makes it possible to rule out inexact
computations playing a role in the final computed result. In my
previous post I asked what the use case is for mixing floats and
Rationals in computation. I have always considered this to be
something that I wanted to avoid and I'm glad that contagious
inexactness helps me to avoid mixing floats into exact computations.


Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unexpected results comparing float to Fraction

2013-08-01 Thread Chris Angelico
On Thu, Aug 1, 2013 at 10:44 AM, Oscar Benjamin
 wrote:
> The real dividing line between {int, Fraction} and {float, Decimal,
> complex} is about (in)exactness. The numeric tower ensures the
> property that inexactness is contagious which I think is a good thing.

*nods slowly*

That does make sense, albeit a little oddly. So when you're sorting
out different integer sizes (C's short/int/long, Py2's int/long), you
go to the "better" one, but when working with inexact types, you go to
the "worse" one. But I can see the logic in it.

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


Python and PyQt (Windows) - AttributeError: 'module' object has not attribute run

2013-08-01 Thread alesssia
I developed a python3-PyQt4 application (I’m a newbie!) on a 32-bit Linux 
platform, and I’m experiencing some problems when testing it on Windows 
platforms (Windows 7 and 8, both 64-bit).

I have a module called Pmc.py that contains two methods: run and main, but only 
the former is used in the PyQt main class. I import the module using the 
following statement:

  import Pmc

and I call the function run with the following instruction:

  self.results = Pmc.run(self.p, self.m)

obtaining this error:

  AttributeError: 'module' object has not attribute run

After some tests, I discovered that renaming Pmc.py in pmc.py solves my issue. 
No problems are present when using Linux both 32 and 64 bit. 
I’m using python 3.3 and PyQt 4. 

What am I missing?

Thanks in advance,
Alessia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python script help

2013-08-01 Thread Alister
On Thu, 01 Aug 2013 10:57:01 +1000, alex23 wrote:

> On 31/07/2013 6:15 PM, cool1...@gmail.com wrote:
>> Here are some scripts, how do I put them together to create the script
>> I want? (to search a online document and download all the links in it)
> 
> 1. Think about the requirements.
> 2. Write some code.
> 3. Test it.
> 4. Repeat until requirements are met.
> 
>> p.s: can I set a destination folder for the downloads?
> 
> Yes.
> 
> Show us you're actively trying to solve this yourself rather than just
> asking us to write the code for you.

alternatively i can provide a quotation to produce a product to your 
specification.
(My rates are extremely high)



-- 
Hand me a pair of leather pants and a CASIO keyboard -- I'm living for 
today!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and PyQt (Windows) - AttributeError: 'module' object has not attribute run

2013-08-01 Thread Dave Angel
alesssia wrote:

> I developed a python3-PyQt4 application (I’m a newbie!) on a 32-bit Linux 
> platform, and I’m experiencing some problems when testing it on Windows 
> platforms (Windows 7 and 8, both 64-bit).
>
> I have a module called Pmc.py that contains two methods: run and main, but 
> only the former is used in the PyQt main class. I import the module using the 
> following statement:
>
>   import Pmc
>
> and I call the function run with the following instruction:
>
>   self.results = Pmc.run(self.p, self.m)
>
> obtaining this error:
>
>   AttributeError: 'module' object has not attribute run

When quoting something from your tests, please don't paraphrase or
shorten.  The actual error traceback starts with a line "Traceback (..."
and is several lines long, and the line you did quote is missing some
quotes and uses the word 'not' when i.t was originally 'no'.

In this case, it doesn't matter, but frequently it will.

>
> After some tests, I discovered that renaming Pmc.py in pmc.py

I don't know what that means. Strictly speaking I think that means you
edited the content of pmc.py and renamed its use of the string to
something else.  But I think you're trying to say you renamed Pmc.py to
pmc.py.  That seems backwards to me.  The reverse is more likely to fix
the problem.

> solves my issue. No problems are present when using Linux both 32 and
> 64 bit. 
> I’m using python 3.3 and PyQt 4. 
>
> What am I missing?

Linux is sensitive to case, while Windows is not.  Windows does, however
preserve the case when you look a the directory, either manually with
DIR, or via some Python function.

My guess is that somehow when the zip file was extracted, the case of
this file was not preserved, and it came out  pmc.py.

My suggestion is to simply use all lower-case for your filenames, and
change the references within your source to

   import pmc
   self.results = pmc.run

Pep-8 recommends that you use an uppercase leading letter to indicate a
class name.  So a class of the "same" name as the file would be
 obj = pmc.Pmc(args)

Another possibility is that you have both a pmc.py  AND a Pmc.py. 
That's not legal in Windows, at least if they're in the same directory. 
And it's not advisable in Windows, if they're even in the same project.


-- 
DaveA


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


Re: script to Login a website

2013-08-01 Thread Dave Angel
wachk...@gmail.com wrote:

> On Wednesday, July 31, 2013 12:21:59 PM UTC-4, John Gordon wrote:

 
>> 
>> How is the data in 'users.txt' and 'password.txt' organized?  Given the
>> 
>> filenames, I would expect that 'users.txt' contains one username on each
>> 
>> line, and 'password.txt' contains one password on each line, with the
>> 
>> first username belonging with the first password, the second username
>> 
>> belonging with the second password, and so on.
>> 
 

> the user.txt file has one user name on each line and so does the 
> password.txt. with this in mind each user will attempt to log in with all the 
> passwords on password.txt file. when it gets to the end of the line it will 
> go to the next user in users.txt and do the same i.e attempt to log in with 
> all the passwords in the file.
> So to your second question I will use all the users one after the other 
> attempting to log in.
> I am able to get each user to use "x" number of passwords in the password.txt 
> that part works fine. The login section is where I am stuck ?

My guess is you've got a nested loop, with the outer loop going through
the user file, and the inner loop going through the password file.

You're attempting to do readline() or equivalent from the password
file in the inner loop, and once you've gone through the outer loop
once, there is nothing left in the password file.

userfile = open("user.txt")
passwordfile = open("password.txt")

for user in  userfile:
  for password in passwordfile:
process this user/pw combination


If that's your logic, simply move the open line for password.txt into
the outer loop, so it gets reopened each time.

You could also do a seek() to get to the beginning of the file each
time, or you could preread all the passwords into a list, or ...

Please note that the buggy googlegroups has totally messed up your
quoting.  Either restrict the quoting to a couple of lines, or remove
all those extra blank lines.

-- 
DaveA

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


Re: Best Python book(s) for a pre-teen?

2013-08-01 Thread beliavsky
On Tuesday, February 18, 2003 2:27:58 PM UTC-5, Mike Silva wrote:
> Hi all,
> 
> My son is 11 and wants to try programming, partly because it's what I
> do for a living.  Even though I don't (yet?) use or even know Python,
> through some unexplainable thought process I've decided it would be a
> good language to start him off with.

The Art of Problem Solving site, geared toward the best U.S. junior high and 
high school math students, offers a 10-week "Introduction to Programming" class 
http://www.artofproblemsolving.com/School/classlist.php that uses Python. There 
are weekly lectures in an online classroom and graded homework assignments. My 
10yo boy is taking the class. But he tells me JavaScript is his favorite 
language :).

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


Re: script to Login a website

2013-08-01 Thread wachkama
On Wednesday, July 31, 2013 11:33:25 AM UTC-4, wach...@gmail.com wrote:
> I have created a script to log in a website. It gets its username and 
> password from two files, then log's in with this credentials. My code is not 
> showing me what username it is using to login from the file. And I am not 
> sure if it is even opening up the url and prompting for login. I am stuck can 
> someone help me ?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> import urllib, urllib2
> 
> 
> 
> user = open ('users.txt' , 'r')
> 
> password = open ('password.txt' , 'r')
> 
> 
> 
> for users in user:
> 
> password.seek(0)
> 
> for pass_list in password:
> 
> login_data = users + '\n' + pass_list
> 
> print login_data
> 
>
> 
> base_url = 'http://mysite.com'   
> 
> #login action we want to post data to 
> 
> response = urllib2.Request(base_url) 
> 
> login_action = '/auth/login'   
> 
> login_action = base_url + login_action
> 
> response = urllib2.urlopen(login_action, login_data)
> 
> response.read()
> 
> print response.headers
> 
> print response.getcode()


This is how my out put looks like when I run the script

us...@mymail.com
Password1

us...@mymail.com
Password2

us...@mymail.com
Password3

us...@mymail.com
Password4

us...@mymail.com
Password1

us...@mymail.com
Password2

us...@mymail.com
Password3

us...@mymail.com
Password4

us...@mymail.com
Password1

us...@mymail.com
Password2

us...@mymail.com
Password3

us...@mymail.com
Password4

us...@mymail.com
Password1

us...@mymail.com
Password2

us...@mymail.com
Password3

us...@mymail.com
Password4

Date: Thu, 01 Aug 2013 13:45:07 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
Set-Cookie: PHPSESSID=3523t5l1vhqisaabfss8ra5tv5; path=/
Cache-Control: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

200


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


RE: sqlite3 version lacks instr

2013-08-01 Thread Fábio Santos
I'm not sure but it seems like you could use operator.__contains__ . it
might be faster.
On 28 Jul 2013 20:18, "Peter Otten" <__pete...@web.de> wrote:

> Joseph L. Casale wrote:
>
> >> Has anyone encountered this and utilized other existing functions
> >> within the shipped 3.6.21 sqlite version to accomplish this?
> >
> > Sorry guys, forgot about create_function...
>
> Too late, I already did the demo ;)
>
> >>> import sqlite3
> >>> db = sqlite3.connect(":memory:")
> >>> cs = db.cursor()
> >>> cs.execute('select instr("the quick brown fox",
> "brown")').fetchone()[0]
> Traceback (most recent call last):
>   File "", line 1, in 
> sqlite3.OperationalError: no such function: instr
> >>> def instr(a, b):
> ... return a.find(b) + 1 # add NULL-handling etc.
> ...
> >>> db.create_function("instr", 2, instr)
> >>> cs.execute('select instr("the quick brown fox",
> "brown")').fetchone()[0]
> 11
> >>> cs.execute('select instr("the quick brown fox", "red")').fetchone()[0]
> 0
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editing tabular data [was: PEP8 79 char max]

2013-08-01 Thread Neil Cerutti
On 2013-08-01, Chris Angelico  wrote:
> On Wed, Jul 31, 2013 at 8:02 PM, Grant Edwards  
> wrote:
>> On 2013-07-31, Skip Montanaro  wrote:
 I don't understand.  That just moves them to a different
 file -- doesn't it?  You've still got to deal with editing a
 large table of data (for example when I want to add
 instructions to your assembler).
>>>
>>> My guess is it would be more foolproof to edit that stuff
>>> with a spreadsheet.
>>
>> Many years ago, I worked with somebody who used a spreadsheet
>> like that.  I tried it and found it to be way too cumbersome.
>> The overhead involved of putting tables in to slew of
>> different files and starting up LibreOffice to edit/view them
>> is huge compared to just editing them with emacs in a file
>> along with the source code.  Maybe my computer is too
>> old/slow.  Maybe it's just due to how bad I am at
>> Excel/LibreOffice...
>
> I'm glad someone else feels that way!
>
> At work, we have a number of CSV files (at my boss's
> insistence; I would much rather they be either embedded in the
> source, or in some clearer and simpler format) which I like to
> manipulate in SciTE, rather than OO/LibreOffice. (I'll not
> distinguish those two. Far as I'm concerned, they're one
> product with two names.) My boss can't understand why I do
> this. I can't understand why he objects to having to edit code
> files to alter internal data. I have pointed him to [1] but to
> no avail.
>
> The one thing I would do, though, is align with tabs rather
> than spaces. That gives you an 8:1 (if you keep your tabs at
> eight, which I do) improvement in maintainability, because
> edits that don't cross a boundary don't require fiddling with
> the layout.
>
> [1] http://thedailywtf.com/Articles/Soft_Coding.aspx

Thanks for that link. Good food for thought.

Here's an excerpt from one of my more questionable tables:

Attribute, Description, Fund, Amount
AFSO,Air Force Special Ops Command,,
CSEN,English Proficiency Met,,
CSMT,Math Proficiency Met,,
GBFP,MBA Full Program,,
GBMP,MBA Prereq Met,,
GCEC,Continuing Education Civilian Tuition Rate,,
GCEM,Continuing Education Military Tuition Rate,,
GCFP,MCA Prereq Needed,,
GCMP,MCE Prereq Met,,
GCRT,Certificate Student,,
GE25,25% to XCompany,,
GE40,40% to XCompany,,
GEMP,Employee,Fac,100%
GI03,CISSP Scholarship,CISSP,1500
GIHR,Grad In-House Recruiting,,
GRMS,Graduate Military Scholarship,Milit,1200

It lists all the student atributes, a description, what fund that
attribute requires, if any, and what amount. A tiny amount of DSL
is involved, with Faculty Scholarship paying 100% of tuition
instead of a fixed number. Another _ (not shown above), which
means the fund takes an arbitrary amount determined by a person
we have to literally query to discover.

I think I can see the potential problems. Two special codes for
amount is managable, but the more special cases I end up creating
the more of a mess I get. Plus, I haven't really documented the
file.

Most of the information is irrelevant, though I do like receiving
an exception when Admissions tries to sneak in a new attribute
without telling me.

If I instead had a function that handled only the interesting
attributes it might be pretty small. I'll have to think on this.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: script to Login a website

2013-08-01 Thread Dave Angel
wachk...@gmail.com wrote:

> On Wednesday, July 31, 2013 11:33:25 AM UTC-4, wach...@gmail.com wrote:
>> I have created a script to log in a website. It gets its username and 
>> password from two files, then log's in with this credentials. My code is not 
>> showing me what username it is using to login from the file. And I am not 
>> sure if it is even opening up the url and prompting for login. I am stuck 
>> can someone help me ?
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> import urllib, urllib2
>> 
>> 
>> 
>> user = open ('users.txt' , 'r')
>> 
>> password = open ('password.txt' , 'r')
>> 
>> 
>> 
>> for users in user:
>> 
>> password.seek(0)
>> 
>> for pass_list in password:
>> 
>> login_data = users + '\n' + pass_list
>> 
>> print login_data

Please ignore myearlier post, as I somehow missed your post where you
showed the code.

Anyway, your problem is that you print the login_data, but you don't act
on it.  You should make the call to the login function right after the
print statement, rather than after the loops are done.  At that point,
all you have is the last user name and password.

All the following code should be moved to a function, and called from
the same level as the print.

>> 
>>
>> 
>> base_url = 'http://mysite.com'   
>> 
>> #login action we want to post data to 
>> 
>> response = urllib2.Request(base_url) 
>> 
>> login_action = '/auth/login'   
>> 
>> login_action = base_url + login_action
>> 
>> response = urllib2.urlopen(login_action, login_data)
>> 
>> response.read()
>> 
>> print response.headers
>> 
>> print response.getcode()
>
=
-- 
DaveA

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-01 Thread Gilles
On Wed, 24 Jul 2013 10:38:52 -0400, Kevin Walzer 
wrote:
>> Thanks. hMailServer was one of the apps I checked, and I was just
>> making sure there weren't something simpler, considering my needs,
>> ideally something like Mongoose MTA.
>>
>> Regardless, because of the SPAM anti-measures mentioned above, it
>> seems like I was over-optimistic about running an MTA and sending
>> e-mails from my home computer :-/
>>
>
>The reason I mentioned hMailServer is that I host my own mail server for 
>my business--I have a static IP address, and correctly configured 
>DNS--and so I'm able to send out large batches of e-mails to customers 
>from my network without being blocked by my ISP. I'm running a Mac 
>server so my mail system is the typical Unix setup (Postfix, etc.), but 
>hMailServer was the closest thing I've found for Windows.
>
>Configuring your own server isn't cheap in terms of time even if you use 
>FOSS components, and your ISP may charge more for a static IP, so I 
>completely understand if you don't want to go that route.

Thanks for the infos. Indeed, it seems like hMailServer is one of the
few good MTAs for Windows.

I already have a static IP, so the issue is more that remote MTAs
might not accept connections from MTAs running on users' PC instead of
ISP's.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python book(s) for a pre-teen?

2013-08-01 Thread ishish

Am 01.08.2013 14:11, schrieb beliav...@aol.com:

On Tuesday, February 18, 2003 2:27:58 PM UTC-5, Mike Silva wrote:

Hi all,

My son is 11 and wants to try programming, partly because it's what 
I
do for a living.  Even though I don't (yet?) use or even know 
Python,
through some unexplainable thought process I've decided it would be 
a

good language to start him off with.


The Art of Problem Solving site, geared toward the best U.S. junior
high and high school math students, offers a 10-week "Introduction to
Programming" class
http://www.artofproblemsolving.com/School/classlist.php that uses
Python. There are weekly lectures in an online classroom and graded
homework assignments. My 10yo boy is taking the class. But he tells 
me

JavaScript is his favorite language :).


I would have a look at this one: 
http://www.cosc.canterbury.ac.nz/csclub/book.pdf. If you like it you can 
still buy the print version.


sas
--
http://mail.python.org/mailman/listinfo/python-list


Best practice for connections and cursors

2013-08-01 Thread Joseph L. Casale
I posted this to the sqlite list but I suspect there are more C oriented users 
on
that list than Python, hopefully someone here can shed some light on this one.

I have created a python module that I import within several other modules that
simply opens a connection to an sqlite file and defines several methods which
each open a cursor before they either select or insert data.

As the module opens a connection, wherever I import it I call a commit against
the connection after invoking any methods that insert or change data.

Seems I've made a proper mess, one of the modules causes a 5 second delay
at import (big indicator there) and one of the modules calls a method that 
yields
data while calling other methods as it iterates. Each of these methods opens its
own cursor. One of which during some processing calls another method which
opens a cursor and creates a temp table and this corrupts the top level cursor
and causes its yield to exit early.

If I open a debugger just as the top level method begins to yield, I can pull 
all
the expected records. It seems to be one of the nested methods that leverages
the singleton connection to the sqlite db, once it opens its own cursor and 
creates
a temp table, things go south. Comment out its cursor and code and things work.

A bit vague I know, but does anyone see the obvious mistake? I assumed the 
module
setting up a singleton connection was a perfectly viable way to accomplish this?

Thanks!
jlc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: email 8bit encoding

2013-08-01 Thread rurpy
On 07/29/2013 02:52 PM, Antoon Pardon wrote:
> Op 29-07-13 01:41, ru...@yahoo.com schreef:
>> How, using Python-3.3's email module, do I "flatten" (I think
>> that's the right term) a Message object to get utf-8 encoded
>> body with the headers:
>>   Content-Type: text/plain; charset=UTF-8
>>   Content-Transfer-Encoding: 8bit
>> when the message payload was set to a python (unicode) string?
>>
> 
> I am just trying out some things for my self on python 3.2 so
> be sure to test this out but you could try the following.
> 
> msg.set_charset('utf-8')
> msg['Content-Transfer-Encoding'] = '8bit'

You can do that but the problem occurs when you call 
email.generator.flatten (or it is called on your behalf by 
somthing like smtplib.send_message) with such a message.  
flatten always assumes a 7bit encoding and uses the ascii 
codec to encode the message resulting in a UnicodeEncode 
exception when it hits an 8 bit character.  So gymnastics 
like W. Trevor King implemented are necessary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best practice for connections and cursors

2013-08-01 Thread Neil Cerutti
On 2013-08-01, Joseph L. Casale  wrote:
> A bit vague I know, but does anyone see the obvious mistake? I
> assumed the module setting up a singleton connection was a
> perfectly viable way to accomplish this?

My one db application started out creating a new connection to
the db (sqlite3) for every select and insert. When I converted it
to maintaining it's own single connection and creating new
cursors instead it was a huge speed increase. So I too am
interested in the answers you'll hopefully be getting. I have no
plans for utilizing concurrent access to the db, but maybe I'll
want to someday.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to package embedded python?

2013-08-01 Thread CM
On Wednesday, July 31, 2013 11:47:19 AM UTC-4, David M. Cotter wrote:
> okay, well that might turn out to be useful, except i don't quite know how to 
> use it, and there are no "from scratch" instructions.
> 
> 
> 
> i managed to download "py2exe-0.6.9.zip" and unzip it, but how does one 
> "install" this package?  (yes, still a newb at that)

What's your OS?  For Windows there is an exe that installs it.  Did you 
download that?

Or you could, in the command line, do:

cd c:\some_folder\the_py2exe_folder
python setup.py install 

(The Python site has a huge page of details on that route. 
http://docs.python.org/2/install/)

Or you could probably get away with just moving the py2exe folder to 
Python27\site-packages (or whatever Python you have)

Or you could first install pip (recommended!) and then just:
pip install py2exe
(http://dubroy.com/blog/so-you-want-to-install-a-python-package)

> then, once installed, how do i say "include the entire world" instead of just 
> "mymodule" ?  cuz the point of embedding python on my app is that the 
> end-user can run any script at all, not just one module.

I don't know.  As I understand it, py2exe will pull whatever is needed in 
Python to run your module.  If your module requires all of Python, I guess that 
will work.  I think regardless of the module, even if it is a "Hello, World" 
program, py2exe has to include the Python interpreter.  

Unfortunately, and surprisingly, the py2exe site is still down.  Odd.  If it 
returns, that should help.  There is also a py2exe users mailing list that you 
could find by Googling for it.



In terms of
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python script help

2013-08-01 Thread cool1574


I know I should be testing out the script myself but I did, I tried and since I 
am new in python and I work for a security firm that ask me to scan hundreds of 
documents a day for unsafe links (by opening them) I thought writing a script 
will be much easier. I do not know how to combine those three scripts together 
(the ones I wrote in my previous replay) that is why I cam to here for help. 
please help me build a working script that will do the job.
Thanks in advance.
you can contact me at cool1...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda function Turing completeness

2013-08-01 Thread Ian Kelly
On Wed, Jul 31, 2013 at 11:55 PM, Steven D'Aprano
 wrote:
> On Wed, 31 Jul 2013 13:53:26 +0700, Musical Notation wrote:
>
>> Is it possible to write a Turing-complete lambda function (which does
>> not depend on named functions) in Python?
>
>
> lambda s: eval(s)

eval is a named function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-08-01 Thread Joshua Landau
On 31 July 2013 17:32, Grant Edwards  wrote:

> On 2013-07-31, Tim Chase  wrote:
> > On 2013-07-31 07:16, Joshua Landau wrote:
> >> On 30 July 2013 18:52, Grant Edwards wrote:
> >>> I also find intializers for tables of data to be much more easily
> >>> read and maintained if the columns can be aligned.
> >>
> >> Why do you have tables in your Python code?
>
> For example: if you're writing an assembler, you usually have a table
> of mnemonics/opcodes/instruction-format/addressing-modes.


Why are you writing an assembler?


>  > I've had occasion to write things like:
> >
> >   for name, value, description in (
> >   ("cost", 42, "How much it cost"),
> >   ("status", 3141, "Status code from ISO-3.14159"),
> >   ...
> >   ):
> > do_something(name, value)
> > print(description)
> >
> > I interpret Grant's statement as wanting the "table" to look like
> >
> >   for name, value, description in (
> >   ("cost",   42,   "How much it cost"),
> >   ("status", 3141, "Status code from ISO-3.14159"),
> >   ...
> >   ):
> > do_something(name, value)
> > print(description)
>
> Exactly.  When you have more than about 5 columns and 10 rows, having
> things aligned makes it far, far, easier to maintain.


Honestly I've never had to do something like this. If it got that large,
though, I'd factor it out into it's own file and possibly take the advice
from others on this list by making it a CSV.

That said for someone like me the very tiny frequency I'd have to do such a
thing would pale in comparison to the other costs and benefits of variable
with fonts.


>  > which does give some modest readability benefits, but at a creation
> > cost I personally am unwilling to pay.
>
> It only gets typed once, it gets read hundreds or thousands of times.
> Optimize the common case.
>

PEP 8, under the things-not-to-do section, says:

· More than one space around an assignment (or other) operator to align
it with another.

Yes:
x = 1
y = 2
long_variable = 3

No:
x = 1
y = 2
long_variable = 3

I assume similar applies here. Obviously PEP 8 isn't a rule but it's a
rough stab at general consensus.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to use Python to open Unread message(s) in specific Outlook folder, clicking a hyperlink within the email message to a secure login window, entering password to download .csv file, run Excel macro

2013-08-01 Thread hambergcfa
Entire Project
I am very new to Python and realize my subject line is more than a mouthful and 
the best way to tackle this project may be to break it down into smaller 
projects; but I wanted to let you know what my entire project is in the event 
there is/are shortcuts or more reliable ways to go about what I'm trying to 
accomplish.

Details
Every morning I receive three emails (three different subject lines) in the 
same Sub-Folder ("POINT") under Folder ("Reports") in my Inbox in Outlook.  
Each email has two secure hyperlinks, one provides me with a site to register 
and the other provides a window for me to enter my password to download a .csv 
file.

Is there code that will open the "Unread" emails in the "POINT" folder, click 
the appropriate hyperlink, enter my password (the same for all emails), and 
download the .csv file and then run an Excel macro?  I've already created the 
Excel macro, one for each of the different files I'm downloading.

I have no idea where to begin with Outlook and have reservations as to whether 
or not this is even possible. 

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


How do I deal with packet data

2013-08-01 Thread Pacopag
Hi.

I have the hex stream of a packet that a program sent over the network.  Now I 
want to view the data in the packet.  I'm pretty sure the data was just a 
string (or at least contains a string), but when I decode it I just get 
gibberish.

For example, the packet is sent something like this

import socket

s = socket.socket()
s.connect(hostname,port)
data = "HeresAStringToSend"
s.send(data)
# I'm not worried about receiving yet.  
# I just want to know the anatomy of a sent packet.


Then I use a packet sniffer to look at the packet that was sent; this is just a 
string of hex.  Then I isolate the data part of the packet.  Let's say the data 
part of the hex string is in a variable called hexdata.

If I do,

print hexdata.decode("hex")

all I get is gibberish.  Looking at the individual bytes in the hex data, they 
map to strange or invalid ascii codes (e.g. less than 32 or greater than 127).

I'm new to all this socket/packet stuff, so I don't really know what the 
s.send(data) method does to the data before sending it.

Any help or insight would be great.  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Oddity with 'yield' as expression - parentheses demanded

2013-08-01 Thread Ian Kelly
On Thu, Aug 1, 2013 at 12:25 AM, Chris Angelico  wrote:
> Was playing around with yield inside a lambda and ran into a distinct oddity.
>
> Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600
> 32 bit (Intel)] on win32
 foo=lambda x: yield(x)
> SyntaxError: invalid syntax
 def foo(x):
> return yield(x)
> SyntaxError: invalid syntax
 def foo(x):
> x=yield(x)
> return x
 foo=lambda x: (yield x)
>
> If yield is an expression, why does it need extra parentheses around
> it? [1] suggest that "(yield x)" is an expression that can elide the
> parens only when it "is the sole expression on the right hand side of
> an assignment statement", and presumably there's a similar rule
> allowing the non-expression form "yield x" to omit the parens. Why is
> this so? Why is it not simply an expression on its own?

yield was a statement before it became an expression, and the syntax
"yield x, y, z" was (and still is) perfectly legal, with all three
expressions (technically a single tuple expression) being governed by
the yield.  That is to say, "yield x, y, z" and "yield (x, y, z)" are
semantically equivalent.  When it became an expression, in order to
preserve this equivalence, that meant that the yield expression needed
to bind even less tightly than the comma.  In terms of the grammar,
yield needed to take an expression_list, not just an expression.

There are only three places in the grammar where expression_lists are
used without enclosing them in brackets:  expression statements (in
this case analogous to the yield statement), the return statement (not
normally used to return a value in a generator), and the assignment
statements.  So for consistency and clarity the rules for
parenthesizing yield statements are basically adopted from the
existing rules for parenthesizing expression_lists.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use Python to open Unread message(s) in specific Outlook folder, clicking a hyperlink within the email message to a secure login window, entering password to download .csv file, run Excel m

2013-08-01 Thread Chris Angelico
On Thu, Aug 1, 2013 at 6:31 PM,   wrote:
> Details
> Every morning I receive three emails (three different subject lines) in the 
> same Sub-Folder ("POINT") under Folder ("Reports") in my Inbox in Outlook.  
> Each email has two secure hyperlinks, one provides me with a site to register 
> and the other provides a window for me to enter my password to download a 
> .csv file.
>
> Is there code that will open the "Unread" emails in the "POINT" folder, click 
> the appropriate hyperlink, enter my password (the same for all emails), and 
> download the .csv file and then run an Excel macro?  I've already created the 
> Excel macro, one for each of the different files I'm downloading.

Okay, taking a few steps back here.

1) You receive an email
2) That email has two URLs in it ("secure hyperlinks" means they begin
https:// ?)
3) You choose one of them as being "appropriate" - is it always the second?
4) You download the document at that URL, which requires a password
5) You then run some sort of alteration on the resulting CSV file.

Please correct me on anything I've misunderstood.

Python can certainly do all of these steps, with the possible
exception of fetching the email. Dividing the problem up into separate
steps will make the solving of it easier.

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


Re: Oddity with 'yield' as expression - parentheses demanded

2013-08-01 Thread Chris Angelico
On Thu, Aug 1, 2013 at 6:35 PM, Ian Kelly  wrote:
> yield was a statement before it became an expression, and the syntax
> "yield x, y, z" was (and still is) perfectly legal, with all three
> expressions (technically a single tuple expression) being governed by
> the yield.  That is to say, "yield x, y, z" and "yield (x, y, z)" are
> semantically equivalent.  When it became an expression, in order to
> preserve this equivalence, that meant that the yield expression needed
> to bind even less tightly than the comma.  In terms of the grammar,
> yield needed to take an expression_list, not just an expression.
>
> There are only three places in the grammar where expression_lists are
> used without enclosing them in brackets:  expression statements (in
> this case analogous to the yield statement), the return statement (not
> normally used to return a value in a generator), and the assignment
> statements.  So for consistency and clarity the rules for
> parenthesizing yield statements are basically adopted from the
> existing rules for parenthesizing expression_lists.

Ahh, right. That makes good sense.

If this were being created anew now, would yield be made to bind more
tightly than the comma? That would mean that

yield x, y, z# Yield a tuple

would need to be written as:

yield (x, y, z)

which wouldn't, in my opinion, be a bad thing. (It'd probably catch a
few people out, but a linter could notice that a tuple is being
created and ignored.) So this is a bit of a wart, but it's for
backward compatibility. Right?

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


Does Python 'enable' poke and hope programming?

2013-08-01 Thread CM
(My subject line is meant to be tongue and cheek inflammatory)

I've been thinking about why programming for me often feels like ice skating 
uphill.  I think part of the problem, maybe the biggest part, is what now 
strikes me as a Very Bad Habit, which is "poke and hope" (trial and error) 
programming (of several names this page provided, I kind of like that one):

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

It seems that if I can make a change to the code and then immediately test it 
by running the Python interpreter and finding out, in a few seconds, if it 
worked, I am going to be *much* more likely to use this trial-and-error 
approach than if I had to use a compiled language, since compiling takes so 
long.  E.g. "Oh, that doesn't work?  Maybe if I add this...no.  OK, what about 
if I increment that?  No...OK, wait, maybe this...AH!  That worked."  
(obviously it is not quite that uninformed all the time).

Instead, with a compiled language, because of the pain of having to wait for 
the newest version to compile, one would be encouraged to get the mechanism of 
how something works *clear* and robustly represented in one's mind (or on scrap 
paper/notes document) prior to testing through compiling and running.

Basically this amounts to:  with an interpreted language (so of course this is 
not really just about Python--I just think in terms of Python), it's easier to 
be mentally lazy.  But, ironically, being lazy winds up creating *way* more 
work ultimately, since one winds up programming in this terribly inefficient 
way, and progress proceeds at an, at times, evolutionary (slow!) pace.

And of course I am not really blaming it on Python or any interpreted language; 
I am blaming it fully on my own lame habits and attitude.

I'm sick of this in my own work, and want to avoid this trap as much as I can 
from now on.

Thoughts?


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


Re: Does Python 'enable' poke and hope programming?

2013-08-01 Thread Neil Cerutti
On 2013-08-01, CM  wrote:
> http://en.wikipedia.org/wiki/Programming_by_permutation
>
> It seems that if I can make a change to the code and then
> immediately test it by running the Python interpreter and
> finding out, in a few seconds, if it worked, I am going to be
> *much* more likely to use this trial-and-error approach than if
> I had to use a compiled language, since compiling takes so
> long.  E.g. "Oh, that doesn't work?  Maybe if I add this...no.
> OK, what about if I increment that?  No...OK, wait, maybe
> this...AH!  That worked."  (obviously it is not quite that
> uninformed all the time).
>
> Instead, with a compiled language, because of the pain of
> having to wait for the newest version to compile, one would be
> encouraged to get the mechanism of how something works *clear*
> and robustly represented in one's mind (or on scrap paper/notes
> document) prior to testing through compiling and running.

With a big project running all tests for a Python program could
be just as time consuming. If I were using a compiler for my
programs compiling would still be virtually instantaneous.

> I'm sick of this in my own work, and want to avoid this trap as
> much as I can from now on.

When I "know", for example. that it's an off-by-one error, I'm
pretty guilty of just making the change and re-running the test.
I think it's cool! If my test sucks, then I wasted my time, of
course.

As I said, I disagree that the speed of using an interpreter is
the main issue. Changing certain things, even big things, in a
Python program is often much easier than changing something in ,
say, a C program, due to Duck-Typing and dynamic typing. So
experimentation is easier thanks to more maleable code.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use Python to open Unread message(s) in specific Outlook folder, clicking a hyperlink within the email message to a secure login window, entering password to download .csv file, run Excel m

2013-08-01 Thread hambergcfa
On Thursday, August 1, 2013 1:47:37 PM UTC-4, Chris Angelico wrote:
> On Thu, Aug 1, 2013 at 6:31 PM,   wrote:
> 
> > Details
> 
> > Every morning I receive three emails (three different subject lines) in the 
> > same Sub-Folder ("POINT") under Folder ("Reports") in my Inbox in Outlook.  
> > Each email has two secure hyperlinks, one provides me with a site to 
> > register and the other provides a window for me to enter my password to 
> > download a .csv file.
> 
> >
> 
> > Is there code that will open the "Unread" emails in the "POINT" folder, 
> > click the appropriate hyperlink, enter my password (the same for all 
> > emails), and download the .csv file and then run an Excel macro?  I've 
> > already created the Excel macro, one for each of the different files I'm 
> > downloading.
> 
> 
> 
> Okay, taking a few steps back here.
> 
> 
> 
> 1) You receive an email
> 
> 2) That email has two URLs in it ("secure hyperlinks" means they begin
> 
> https:// ?)
> 
> 3) You choose one of them as being "appropriate" - is it always the second?
> 
> 4) You download the document at that URL, which requires a password
> 
> 5) You then run some sort of alteration on the resulting CSV file.
> 
> 
> 
> Please correct me on anything I've misunderstood.
> 
> 
> 
> Python can certainly do all of these steps, with the possible
> 
> exception of fetching the email. Dividing the problem up into separate
> 
> steps will make the solving of it easier.
> 
> 
> 
> ChrisA

Thanks a lot ChrisA!  You are correct with everything except that the login 
hyperlink is always the first link and the second one is the link to register.
-- 
http://mail.python.org/mailman/listinfo/python-list


Building python 2.7.5 with VS2012 - Regression test failures

2013-08-01 Thread thakur . gautam
I managed to build a 64bit version of Python 2.7.5 from sources with VS2012 on 
Windows 8 following the wiki on modifying the build files as advised for 
VS2010. I ran the python regression tests on the build and it cleared most of 
the tests and skipped a few. 

It hanged when trying to run the following tests,
- test_tuple
- test_list
- test_userlist
- test_asyncore
- test_gdb
The system would become unresponsive and I would need to force shutdown and 
restart.

It failed the following tests,
- test_socket
  [it failed only for two tests, test_connect & test_create_connection, the 
issue
   seems to be around this - AssertionError: 10061 != 107] 
- test_asynchat 
  [all errors were with respect to Errno 10035 & WSAEWOULDBLOCK]
- test_ssl 
  [it skipped stating "DLL load failed: %1 is not a valid Win32 application"]

For the following I got warnings,
- test_site [warning - modified sys.path]
- test_distutils [warning - modified os.environ]

I think test_socket and test_asynchat are to do with error codes returned as 
per errnomodule.c. Fixing this should be enough.

I would really appreciate any help/advise on how to deal with the above errors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-01 Thread Chris Angelico
On Thu, Aug 1, 2013 at 6:57 PM, CM  wrote:
> It seems that if I can make a change to the code and then immediately test it 
> by running the Python interpreter and finding out, in a few seconds, if it 
> worked, I am going to be *much* more likely to use this trial-and-error 
> approach than if I had to use a compiled language, since compiling takes so 
> long.  E.g. "Oh, that doesn't work?  Maybe if I add this...no.  OK, what 
> about if I increment that?  No...OK, wait, maybe this...AH!  That worked."  
> (obviously it is not quite that uninformed all the time).


I would say that, often, that's a fine way to do things. With two very
similar languages I work with (Python and Pike), there's a slight
difference in the interpretation of a range subscript:

Pike v7.8 release 700 running Hilfe v3.5 (Incremental Pike Frontend)
> "Hello, world!"[..5];
(1) Result: "Hello,"
> "Hello, world!"[5..];
(2) Result: ", world!"

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600
32 bit (Intel)] on win32
>>> "Hello, world!"[:5]
'Hello'
>>> "Hello, world!"[5:]
', world!'

Python counts the boundaries between characters, Pike counts the
characters themselves. So using the same number on different sides of
the colon yields the exact same string in Python, but in Pike, both
strings contain the indexed character. Both ways make sense, and the
easiest way to make sure I haven't mucked something up - in either
language - is to try it.

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


Re: How to use Python to open Unread message(s) in specific Outlook folder, clicking a hyperlink within the email message to a secure login window, entering password to download .csv file, run Excel m

2013-08-01 Thread Chris Angelico
On Thu, Aug 1, 2013 at 7:08 PM,   wrote:
>> 1) You receive an email
>>
>> 2) That email has two URLs in it ("secure hyperlinks" means they begin
>>
>> https:// ?)
>>
>> 3) You choose one of them as being "appropriate" - is it always the second?
>>
>> 4) You download the document at that URL, which requires a password
>>
>> 5) You then run some sort of alteration on the resulting CSV file.
>>
>>
>>
>> Please correct me on anything I've misunderstood.
>>
>>
>>
>> Python can certainly do all of these steps, with the possible
>>
>> exception of fetching the email. Dividing the problem up into separate
>>
>> steps will make the solving of it easier.
>>
>>
>>
>> ChrisA
>
> Thanks a lot ChrisA!  You are correct with everything except that the login 
> hyperlink is always the first link and the second one is the link to register.


Okay!

(Digression: You seem to be using Google Groups. Please read
http://wiki.python.org/moin/GoogleGroupsPython before posting further,
to avoid antagonizing the list's best responders.)

The first step is to figure out how to retrieve the email. You may
want to tweak your setup to make this easier. The next thing I'd do
would be to port the macro to Python. Everything in between is fairly
easy.

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


Re: PEP8 79 char max

2013-08-01 Thread Steven D'Aprano
On Thu, 01 Aug 2013 18:21:32 +0100, Joshua Landau wrote:

> On 31 July 2013 17:32, Grant Edwards  wrote:
> 
>> On 2013-07-31, Tim Chase  wrote:
>> > On 2013-07-31 07:16, Joshua Landau wrote:
>> >> On 30 July 2013 18:52, Grant Edwards wrote:
>> >>> I also find intializers for tables of data to be much more easily
>> >>> read and maintained if the columns can be aligned.
>> >>
>> >> Why do you have tables in your Python code?
>>
>> For example: if you're writing an assembler, you usually have a table
>> of mnemonics/opcodes/instruction-format/addressing-modes.
> 
> 
> Why are you writing an assembler?


Maybe he's (re-)creating PyPy :-)


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


Re: Python and PyQt (Windows) - AttributeError: 'module' object has not attribute run

2013-08-01 Thread alesssia
>> After some tests, I discovered that renaming Pmc.py in pmc.py 
> I don't know what that means.

I simply renamed Pmc.py to pmc.py, using a lower case instead of an upper case. 
Of course, I also changed lines referencing to 'Pmc' (upper case) to 'pmc' 
(lover case) in the source code. This allows my program to work.

> My guess is that somehow when the zip file was extracted, the case of 
> this file was not preserved, and it came out  pmc.py.

The zip was not extracted because there was no zip. I copied the code from my 
computer to a USB pen drive and ran the code from there.


> My suggestion is to simply use all lower-case for your filenames

What surprised me is that Windows was unable of holding upper case, so I 
thought there was something else.  Yet, it seems that this behaviour does not 
surprise anyone else. Then, I'll simply changes all my source file names, 
despite I felt it silly...

Thanks,
Alessia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Oddity with 'yield' as expression - parentheses demanded

2013-08-01 Thread Terry Reedy

On 8/1/2013 1:58 PM, Chris Angelico wrote:

On Thu, Aug 1, 2013 at 6:35 PM, Ian Kelly  wrote:

yield was a statement before it became an expression, and the syntax
"yield x, y, z" was (and still is) perfectly legal, with all three
expressions (technically a single tuple expression) being governed by
the yield.  That is to say, "yield x, y, z" and "yield (x, y, z)" are
semantically equivalent.  When it became an expression, in order to
preserve this equivalence, that meant that the yield expression needed
to bind even less tightly than the comma.  In terms of the grammar,
yield needed to take an expression_list, not just an expression.

There are only three places in the grammar where expression_lists are
used without enclosing them in brackets:  expression statements (in
this case analogous to the yield statement), the return statement (not
normally used to return a value in a generator), and the assignment
statements.  So for consistency and clarity the rules for
parenthesizing yield statements are basically adopted from the
existing rules for parenthesizing expression_lists.


Ahh, right. That makes good sense.

If this were being created anew now, would yield be made to bind more
tightly than the comma?


As a statement (which is the primary use of yield), yield is like 
return, except that the execution frame is not discarded. So I think it 
should bind like return, which is very loosely.



--
Terry Jan Reedy

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


Re: PEP8 79 char max

2013-08-01 Thread Grant Edwards
On 2013-08-01, Joshua Landau  wrote:
> On 31 July 2013 17:32, Grant Edwards  wrote:
>
>> On 2013-07-31, Tim Chase  wrote:
>> > On 2013-07-31 07:16, Joshua Landau wrote:
>> >> On 30 July 2013 18:52, Grant Edwards wrote:
>> >>> I also find intializers for tables of data to be much more easily
>> >>> read and maintained if the columns can be aligned.
>> >>
>> >> Why do you have tables in your Python code?
>>
>> For example: if you're writing an assembler, you usually have a table
>> of mnemonics/opcodes/instruction-format/addressing-modes.
>
> Why are you writing an assembler?

I got tired of hand assembling (and disassembling) code for a custom
microprocessor, so I wrote an assembler and a disassembler.

-- 
Grant Edwards   grant.b.edwardsYow! I smell like a wet
  at   reducing clinic on Columbus
  gmail.comDay!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: script to Login a website

2013-08-01 Thread wachkama
On Wednesday, July 31, 2013 11:33:25 AM UTC-4, wach...@gmail.com wrote:
> I have created a script to log in a website. It gets its username and 
> password from two files, then log's in with this credentials. My code is not 
> showing me what username it is using to login from the file. And I am not 
> sure if it is even opening up the url and prompting for login. I am stuck can 
> someone help me ?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> import urllib, urllib2
> 
> 
> 
> user = open ('users.txt' , 'r')
> 
> password = open ('password.txt' , 'r')
> 
> 
> 
> for users in user:
> 
> password.seek(0)
> 
> for pass_list in password:
> 
> login_data = users + '\n' + pass_list
> 
> print login_data
> 
>
> 
> base_url = 'http://mysite.com'   
> 
> #login action we want to post data to 
> 
> response = urllib2.Request(base_url) 
> 
> login_action = '/auth/login'   
> 
> login_action = base_url + login_action
> 
> response = urllib2.urlopen(login_action, login_data)
> 
> response.read()
> 
> print response.headers
> 
> print response.getcode()

That defiantly Got me my results. Thank you. I put the code in login code into 
the loop and that has given me my expected results.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I deal with packet data

2013-08-01 Thread Dave Angel
Pacopag wrote:

> Hi.
>
> I have the hex stream of a packet that a program sent over the network.  Now 
> I want to view the data in the packet.  I'm pretty sure the data was just a 
> string (or at least contains a string), but when I decode it I just get 
> gibberish.
>
> For example, the packet is sent something like this
>
> import socket
>
> s = socket.socket()
> s.connect(hostname,port)
> data = "HeresAStringToSend"
> s.send(data)
> # I'm not worried about receiving yet.  
> # I just want to know the anatomy of a sent packet.
>
>
> Then I use a packet sniffer to look at the packet that was sent; this is just 
> a string of hex.

What packet sniffer was that?  Why not use wireshark, and eliminate the
middleman?  If you're using some other tool, how have you decided you
even have the right packet(s)?

>  Then I isolate the data part of the packet.  Let's say the data part
> of the hex string is in a variable called hexdata.

So you've analyzed the header of the packet, and identified where the
data part is?  Have you seen where the host IP address is, and the port
number?  Do they fit the pattern?

>
> If I do,
>
> print hexdata.decode("hex")
>
> all I get is gibberish.  Looking at the individual bytes in the hex data, 
> they map to strange or invalid ascii codes (e.g. less than 32 or greater than 
> 127).
>
> I'm new to all this socket/packet stuff, so I don't really know what the 
> s.send(data) method does to the data before sending it.
>
> Any help or insight would be great.  Thanks.

What OS are you using?  There are differences in Windows, for example,
but someone else would have to help you there.

If it were my problem, I'd be using Wireshark, which can not only
display the data for each packet, but show how multiple packets relate
to each other.

-- 
DaveA

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


PEP8 revised: max line lengths

2013-08-01 Thread Terry Reedy

Newly revised this morning:
http://www.python.org/dev/peps/pep-0008/#maximum-line-length
summary:
72 for text block (comments, triple-quoted strings)
79 for normal code
99 for code that is really more readable with extra

The diff with all the changes is here
http://hg.python.org/peps/rev/fb24c80e9afb
--
Terry Jan Reedy

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


Re: PEP8 79 char max

2013-08-01 Thread Grant Edwards
On 2013-08-01, Grant Edwards  wrote:
> On 2013-08-01, Joshua Landau  wrote:
>> On 31 July 2013 17:32, Grant Edwards  wrote:
>>
>>> On 2013-07-31, Tim Chase  wrote:
>>> > On 2013-07-31 07:16, Joshua Landau wrote:
>>> >> On 30 July 2013 18:52, Grant Edwards wrote:
>>> >>> I also find intializers for tables of data to be much more easily
>>> >>> read and maintained if the columns can be aligned.
>>> >>
>>> >> Why do you have tables in your Python code?
>>>
>>> For example: if you're writing an assembler, you usually have a table
>>> of mnemonics/opcodes/instruction-format/addressing-modes.
>>
>> Why are you writing an assembler?
>
> I got tired of hand assembling (and disassembling) code for a custom
> microprocessor, so I wrote an assembler and a disassembler.

FWIW, 250 lines of Python gets you a pretty decent 2-pass absolute
assembler with full arithmetic expression support (including
user-defined symbols).  That 250 lines includes the "table" that
defines the individual instructions.  

And yes, the columns in that table are aligned using spaces. ;)

-- 
Grant Edwards   grant.b.edwardsYow! I just had a NOSE
  at   JOB!!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-01 Thread Dave Angel
CM wrote:

  
> what now strikes me as a Very Bad Habit, which is "poke and hope"
>  (trial and error) programming (of several names this page provided, I kind 
> of like that one):
>

I recall when a "compile" took up to two days, before we got the punched
paper tape to begin testing.  If we wanted to "poke", it was done in
hex.

Once we got a local assembler/linker up and working, and
(incremental) turnarounds were under 5 minutes, we thought we were in
heaven.  But the discipline of having to think it through was very good
for us, in the long run.

-- 
DaveA

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


Re: PEP8 revised: max line lengths

2013-08-01 Thread Terry Reedy

On 8/1/2013 3:52 PM, Terry Reedy wrote:

Newly revised this morning:
http://www.python.org/dev/peps/pep-0008/#maximum-line-length
summary:
72 for text block (comments, triple-quoted strings)
79 for normal code
99 for code that is really more readable with extra

Or maybe not for stdlib. Guido think this is too 'loose'.



The diff with all the changes is here
http://hg.python.org/peps/rev/fb24c80e9afb



--
Terry Jan Reedy

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


Re: PEP8 revised: max line lengths

2013-08-01 Thread Tim Chase
On 2013-08-01 15:52, Terry Reedy wrote:
> Newly revised this morning:
> http://www.python.org/dev/peps/pep-0008/#maximum-line-length
>
> The diff with all the changes is here
> http://hg.python.org/peps/rev/fb24c80e9afb

Just a quick spelling fix of

   s/experimants/experiments/

at http://hg.python.org/peps/rev/fb24c80e9afb#l1.396

:-)

-tkc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to install googleapp engine on ubuntu 12.04 already downloads google_appengine_1.8.2.zip

2013-08-01 Thread Jai
got answer 

 downloaded google_appengine_1.8.2.zip
unziped it 
command path-to-/dev_appserver.py   path-to/application-diectory that it 
-- 
http://mail.python.org/mailman/listinfo/python-list


Logging help

2013-08-01 Thread Joseph L. Casale
I have a couple handlers applied to a logger for a file and console destination.
Default levels have been set for each, INFO+ to console and anything to file.

How does one prevent logging.exception from going to a specific handler when
it falls within the desired levels?

Thanks,
jlc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 revised: max line lengths

2013-08-01 Thread Terry Reedy

On 8/1/2013 4:22 PM, Tim Chase wrote:

On 2013-08-01 15:52, Terry Reedy wrote:

Newly revised this morning:
http://www.python.org/dev/peps/pep-0008/#maximum-line-length

The diff with all the changes is here
http://hg.python.org/peps/rev/fb24c80e9afb


Just a quick spelling fix of

s/experimants/experiments/

at http://hg.python.org/peps/rev/fb24c80e9afb#l1.396

:-)


Already patched in repository but after the nightly rebuild of the web 
pages. I found 3 more and fixed them.


--
Terry Jan Reedy

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


Re: PEP8 revised: max line lengths

2013-08-01 Thread Dave Angel
Terry Reedy wrote:


>>>
>>> The diff with all the changes is here
>>> http://hg.python.org/peps/rev/fb24c80e9afb
>>

Just out of curiosity, where is "coding cookie" defined?  I found enough
distant references to decide it was supposed to mean the coding line
(line 2, typically in Unix).  But I originally thought it meant the BOM.

It must have a different name in the reference, but i can't seem to find
it right now.  If indeed it has a different name, then Pep8 should use
that name.



--
DaveA


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


Re: Python and PyQt (Windows) - AttributeError: 'module' object has not attribute run

2013-08-01 Thread Dave Angel
alesssia wrote:

   

>> My guess is that somehow when the zip file was extracted, the case of 
>> this file was not preserved, and it came out  pmc.py.
>
> The zip was not extracted because there was no zip. I copied the code from my 
> computer to a USB pen drive and ran the code from there.

That's probably where you lost the case distinction.  The FAT file
system doesn't really support lowercase, except with 'extended
attributes', and probably your Linux system didn't create those in a way
that Windows was happy with.

If I had to get files between the two, I'd either use Linux tools to do
the transfer (eg. scp or ftp), or I'd zip the files and just transfer
the zip.

>
>
>> My suggestion is to simply use all lower-case for your filenames
>
> What surprised me is that Windows was unable of holding upper case, so I 
> thought there was something else.  Yet, it seems that this behaviour does not 
> surprise anyone else. Then, I'll simply changes all my source file names, 
> despite I felt it silly...
>

It can hold uppercase;  in fact, it's lower case that's "new".  But
because it's "case - preserving" rather than "case -sensitive",
sometimes it's a mess.

-- 
DaveA


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


Re: PyQt5 and virtualenv problem

2013-08-01 Thread D. Xenakis
Any advice?Plz?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 revised: max line lengths

2013-08-01 Thread Roy Smith
In article ,
 Terry Reedy  wrote:

> Newly revised this morning:
> http://www.python.org/dev/peps/pep-0008/#maximum-line-length
> summary:
> 72 for text block (comments, triple-quoted strings)
> 79 for normal code
> 99 for code that is really more readable with extra

And the people did rejoice and did feast upon the lambs and toads and 
tree-sloths and fruit-bats and orangutans and breakfast cereals.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-01 Thread Sam Whitehead
I find myself doing this a lot with libraries whose documentation encourages an 
understanding based on intuition, rather than one based on formal concepts. 
When doing more 'pure' stuff with mostly the standard library, not so much. 

Most imperative languages let their users get kind of loose with data design, 
but I don't feel like Python is especially bad in this regard. Mostly I feel 
like it depends on how well the programmer understands the software they're 
working with. And that sense, Python tries to help by encouraging readability.

In a sense, you could see almost all computer programming as "poke and hope", 
though. The variation lies in the size of the poke and the uncertainty of the 
hope.
-- 
http://mail.python.org/mailman/listinfo/python-list


Having troubles with list methods

2013-08-01 Thread Adam Sweiger
The code: pastebin.com/MyrLB704

I'm working on this program in my Python book, and for some reason it doesn't 
seem to be working.

I've read my code, it seems fine to me. Here's what the book says:

The High Scores program uses list methods to create and maintain a list of the 
user's best scores for a computer game. The program uses a simple, menu-driven 
interface. The user has a few choices. He or she can add a new score, delete a 
score, sort the scores, or quit the program.

When I run my code, it just keeps printing the same thing infinitely.

Any help?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Having troubles with list methods

2013-08-01 Thread Sam Whitehead
Your indentation is such that the first print statement is the only thing 
inside the while loop.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Having troubles with list methods

2013-08-01 Thread Adam Sweiger
On Thursday, August 1, 2013 8:11:42 PM UTC-5, Sam Whitehead wrote:
> Your indentation is such that the first print statement is the only thing 
> inside the while loop.

I corrected the indentation and it works perfectly now. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best practice for connections and cursors

2013-08-01 Thread Ian Kelly
On Thu, Aug 1, 2013 at 6:49 PM, Dennis Lee Bieber  wrote:
> On Thu, 1 Aug 2013 15:05:08 +, "Joseph L. Casale"
>  declaimed the following:
>
>>
>>As the module opens a connection, wherever I import it I call a commit against
>>the connection after invoking any methods that insert or change data.
>>
>
> You probably should NOT be opening connections /during/ the import
> operation... For one thing, if it is a module level connection, multiple
> imports are replacing earlier connections with their fresh one.

That's not true.  Multiple imports of the same module will only
execute the module-level code the first time.

I agree though that simply importing the module should not trigger a
connection to be opened.  That should be an explicit step.

Speaking to the OP:  personally, I don't like the approach of putting
data access methods at the module level to begin with.  I'd rather use
a class.  Just because it makes sense to have a singleton connection
now doesn't mean it will always make sense as your application grows.
In fact, the conflict you describe where one cursor is interfering
with another cursor suggests that you may already be at the point of
needing multiple connections.  The operation that is creating a temp
table and messing things up should ideally be pulling an unused
connection from a pool, so as to avoid potentially contaminating a
connection that may already be in use elsewhere in the code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-01 Thread Vito De Tullio
CM wrote:

> Basically this amounts to:  with an interpreted language (so of course
> this is not really just about Python--I just think in terms of Python),
> it's easier to be mentally lazy.  But, ironically, being lazy winds up
> creating *way* more work ultimately, since one winds up programming in
> this terribly inefficient way, and progress proceeds at an, at times,
> evolutionary (slow!) pace.

you have found repl are cool :D

-- 
By ZeD

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


Re: PEP8 revised: max line lengths

2013-08-01 Thread Steven D'Aprano
On Thu, 01 Aug 2013 20:51:43 -0400, Roy Smith wrote:

> In article ,
>  Terry Reedy  wrote:
> 
>> Newly revised this morning:
>> http://www.python.org/dev/peps/pep-0008/#maximum-line-length summary:
>> 72 for text block (comments, triple-quoted strings) 79 for normal code
>> 99 for code that is really more readable with extra
> 
> And the people did rejoice and did feast upon the lambs and toads and
> tree-sloths and fruit-bats and orangutans and breakfast cereals.

Except on Python-Dev, where feedback on allowing longer lines is almost 
entirely negative. The consensus seems to be, if you have a line of code 
that is more than 79 characters, and less than 100 characters, and there 
is no clean way to break it over multiple lines, then it is acceptable to 
not break it.


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


Re: PEP8 revised: max line lengths

2013-08-01 Thread Terry Reedy

On 8/1/2013 7:33 PM, Dave Angel wrote:

Terry Reedy wrote:




The diff with all the changes is here
http://hg.python.org/peps/rev/fb24c80e9afb




Just out of curiosity, where is "coding cookie" defined?  I found enough
distant references to decide it was supposed to mean the coding line
(line 2, typically in Unix).  But I originally thought it meant the BOM.

It must have a different name in the reference, but i can't seem to find
it right now.  If indeed it has a different name, then Pep8 should use
that name.


http://bugs.python.org/issue18628

--
Terry Jan Reedy

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


Re: PEP8 revised: max line lengths

2013-08-01 Thread Dave Angel
Terry Reedy wrote:

> On 8/1/2013 7:33 PM, Dave Angel wrote:
>> Terry Reedy wrote:
>>
>>
>
> The diff with all the changes is here
> http://hg.python.org/peps/rev/fb24c80e9afb

>>
>> Just out of curiosity, where is "coding cookie" defined?  I found enough
>> distant references to decide it was supposed to mean the coding line
>> (line 2, typically in Unix).  But I originally thought it meant the BOM.
>>
>> It must have a different name in the reference, but i can't seem to find
>> it right now.  If indeed it has a different name, then Pep8 should use
>> that name.
>
> http://bugs.python.org/issue18628
>

Thanks for the mention in the issue report.

-- 
Signature file not found

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


Re: Problem with psycopg2, bytea, and memoryview

2013-08-01 Thread Frank Millman

"Terry Reedy"  wrote in message 
news:ktbj9i$4au$1...@ger.gmane.org...
> On 7/31/2013 9:07 AM, Antoine Pitrou wrote:
>>
>> I would suggest asking the psycopg2 project why they made this choice, 
>> and
>> if they would reconsider. Returning a memoryview doesn't make much sense 
>> IMHO.
>
> I agree.
> "memoryview objects allow Python code to access the internal data of an 
> object that supports the buffer protocol without copying."
> Example: the binary image data of an image object.
> They are not intended to be a standalone objects when there is an obvious 
> alternative (in this case, bytes).

For the record, I forwarded this to the psycopg2 list, and got the following 
reply from Daniele Varrazzo -


Hi Frank, thank you for forwarding the thread.

Until a not very long time ago, this was exactly the case: upon
reading bytea we were handed over some data to pass to a libpq
function to decode. The resulting decoded string was to be released by
PQfreemem, and the memoryview was the right object to reconcile the
lifetime of the python object with this deallocation requirement.
Later things have changed: because of the change in bytea format in
PostgreSQL 9.0 (the new format was the default and wasn't handled by
libpq < 9.0, which created widespread problems) we wrote our own
parser. As a consequence the memoryview is not really needed anymore,
but we preferred to avoid breaking programs already using the current
interface.

So yes: bytes (and str on Py2) is definitely a better object to get in
Python. It is already on the list of what I want in a version that
would break compatibility in order to gain feature or improve the
adapter in other ways (e.g. psycopg3).


Frank



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


Re: Editing tabular data

2013-08-01 Thread Ben Finney
Skip Montanaro  writes:

> I really love Emacs, however... […]
>
> This is clearly a case where choosing the proper tool is important. I
> agree that using a spreadsheet to edit a 3x5 CSV file is likely
> overkill (might just as well use Notepad or TextEdit), but tabular
> data are tabular data, no matter how they might be delimited, and if
> there are many of those little data critters, there are better tools
> than a text editor (or Python IDE) for maintaining them.

It seems an obvious thing for powerful text editors like Emacs and Vim
to have a third-party mode for editing CSV data with a tabular
interface.

Indeed, such modes exist; one that I found immediately for Emacs is
http://www.emacswiki.org/emacs/csv-mode.el>. Has anyone got a good
Emacs mode for editing CSV data as a table and saving it back to CSV
data?

-- 
 \  “Isn't it enough to see that a garden is beautiful without |
  `\  having to believe that there are fairies at the bottom of it |
_o__) too?” —Douglas Adams |
Ben Finney

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