Re: Share Code: Laptop Lid State

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 4:05 AM, Devyn Collier Johnson
 wrote:
>
> On 07/30/2013 12:00 PM, Chris Angelico wrote:
>>
>> On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
>>  wrote:
>>>
>>> Aloha everyone!
>>>
>>> I attached a script that I thought I could share with everyone for
>>> your
>>> help. This Python3 script only works on Unix systems. It prints the
>>> current
>>> state of the lid. This can be used to make a script that performs some
>>> action when the lid is closed or open. The script is licensed under
>>> LGPLv3
>>> and I will soon upload it to my Launchpad account. Enjoy!
>>
>> There's... no Python code in that. Why not simply
>> open("/proc/acpi/button/lid/LID/state") and read from it, instead of
>> using cat and awk?
>>
>> ChrisA
>
> The script returns either "open" or "close" instead of printing the whole
> file contents. I thought some people would find it useful (^_^;).

Not having a Linux laptop handy I can't test it, but my point is that
text parsing of that nature can be done directly by Python. You can
snip out the "open" or "close" easily with one, maybe two lines of
code at the most, and that without dropping to a shell, a completely
superfluous 'cat' process, and awk. You then capture the STDOUT of
that and promptly print it to your own STDOUT. Why not either do it
truly in Python, or do it directly in a shell script and skip the
Python interpreter?

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


Re: RE Module Performance

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 6:45 AM, Steven D'Aprano
 wrote:
> if you care about minimizing every possible byte, you should
> use a low-level language like C. Then you can give every character 21
> bits, and be happy that you don't waste even one bit.

Could go better! Since not every character has been assigned, and some
are specifically banned (eg U+FFFE and U+D800-U+DFFF), you could cut
them out of your representation system and save memory!

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


Re: RE Module Performance

2013-07-31 Thread Antoon Pardon
Op 31-07-13 05:30, Michael Torrie schreef:
> On 07/30/2013 12:19 PM, Antoon Pardon wrote:
>> So? Why are you making this a point of discussion? I was not aware that
>> the pro and cons of various editor buffer implemantations was relevant
>> to the point I was trying to make.
> 
> I for one found it very interesting.  In fact this thread caused me to
> wonder how one actually does create an efficient editor.  Off the
> original topic true, but still very interesting.
> 

Yes, it can be interesting. But I really think if that is what you want
to discuss, it deserves its own subject thread.

-- 
Antoon Pardon

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


Re: PEP8 79 char max

2013-07-31 Thread llanitedave
It's not just the number of characters, it's the size and the font.  Even 
fixed-width fonts differ greatly in their readability.  

I can handle different line widths just fine up til about 120 or so without 
losing the flow of the program, but some fonts simply make it more difficult at 
any width.

I've tried many, but for some reason I keep coming back to Courier10 at 10 
points.  I'm almost embarrassed that my choice is such an old and primitive 
font, but that's how my brain works.

In my experience, if code is well-spaced, well-commented, and broken up into 
logical groups with appropriate blank spaces, line length can be about 3/4 the 
width of whatever editor is being used.  And most editors are wide enough to 
easily accommodate over 100 characters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-31 Thread Antoon Pardon
Op 30-07-13 21:09, wxjmfa...@gmail.com schreef:
> Matable, immutable, copyint + xxx, bufferint, O(n) 
> Yes, but conceptualy the reencoding happen sometime, somewhere.

Which is a far cry from your previous claim that it happened
every time you enter a char.

This of course make your case harder to argue. Because the
impact of something that happens sometime, somewhere is
vastly less than something that happens everytime you enter
a char.

> The internal "ucs-2" will never automagically be transformed
> into "ucs-4" (eg).

It will just start producing wrong results when someone starts
using characters that don't fit into ucs-2.


 timeit.timeit("'a'*1 +'€'")
> 7.087220684719967
 timeit.timeit("'a'*1 +'z'")
> 1.5685214234430873
 timeit.timeit("z = 'a'*1; z = z +'€'")
> 7.169538866162213
 timeit.timeit("z = 'a'*1; z = z +'z'")
> 1.5815893830557286
 timeit.timeit("z = 'a'*1; z += 'z'")
> 1.606955741596181
 timeit.timeit("z = 'a'*1; z += '€'")
> 7.160483334521416
> 
> 
> And do not forget, in a pure utf coding scheme, your
> char or a char will *never* be larger than 4 bytes.
> 
 sys.getsizeof('a')
> 26
 sys.getsizeof('\U000101000')
> 48

Nonsense.

>>> sys.getsizeof('a'.encode('utf-8'))
18




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


Re: Python script help

2013-07-31 Thread cool1574
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)
p.s: can I set a destination folder for the downloads?

urllib.urlopen("http://";)

possible_urls = re.findall(r'\S+:\S+', text)

import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-31 Thread wxjmfauth
FSR:
===

The 'a' in 'a€' and 'a\U0001d11e:

>>> ['{:#010b}'.format(c) for c in 'a€'.encode('utf-16-be')]
['0b', '0b0111', '0b0010', '0b10101100']
>>> ['{:#010b}'.format(c) for c in 'a\U0001d11e'.encode('utf-32-be')]
['0b', '0b', '0b', '0b0111',
'0b', '0b0001', '0b11010001', '0b0000']

Has to be done.

sys.getsizeof('a€')
42
sys.getsizeof('a\U0001d11e')
48
sys.getsizeof('aa')
27


Unicode/utf*


i) ("primary key") Create and use a unique set of encoded
code points.
ii) ("secondary key") Depending of the wish,
memory/performance: utf-8/16/32

Two advantages at the light of the above example:
iii) The "a" has never to be reencoded.
iv) An "a" size never exceeds 4 bytes.

Hard job to solve/satisfy i), ii), iii) and iv) at the same time.
Is is possible? ;-) The solution is in the problem.

jmf

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


Re: RE Module Performance

2013-07-31 Thread Antoon Pardon
Op 31-07-13 10:32, wxjmfa...@gmail.com schreef:
> Unicode/utf*
> 
>
> i) ("primary key") Create and use a unique set of encoded
> code points.

FSR does this.

>>> st1 = 'a€'
>>> st2 = 'aa'
>>> ord(st1[0])
97
>>> ord(st2[0])
97
>>>

> ii) ("secondary key") Depending of the wish,
> memory/performance: utf-8/16/32

Whose wish? I don't know any language that allows the
programmer choose the internal representation of its
strings. If it is the designers choice FSR does this,
if it is the programmers choice, I don't see why
this is necessary for compliance.

> Two advantages at the light of the above example:
> iii) The "a" has never to be reencoded.

FSR: check. Using a container with wider slots is not a reëncoding.
If such widening is encoding then your 'choice' between utf-8/16/32
implies that it will also have to reencode when it changes from
utf-8 to utf-16 or utf-32.

> iv) An "a" size never exceeds 4 bytes.

FSR: check.

> Hard job to solve/satisfy i), ii), iii) and iv) at the same time.
> Is is possible? ;-) The solution is in the problem.

Mayby you should use bytes or bytearrays if that is really what you want.

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


Re: Python descriptor protocol (for more or less structured data)

2013-07-31 Thread CWr
Peter, thanks for your response.
Sure, you are right when you say that's easier to use standard attribute 
assigning via __init__.

But my intention was:
- reducing the complexiticity of __init__
- avoiding boiler-plates (mostly property descriptors inside of the main class)
- creating instances (for complex data strings) only if they will be needed, 
otherwise use default instances (descriptors) 
- make it prossible that the data structure can be used in static context - 
like MyClass.attr - to get default values

Standard procedure:

>>>class C:
>>>def __init__(self, one, two=None, three=None, four=None, five=None, ...):
>>>if not two is None:
>>>self.two = Value(two)
>>>else:
>>>self.two = Value(self.DEFAULT_4_TWO)
>>>...

vs:

>>>class C:
>>>
>>>two = MyDescriptor('default for two')
>>>
>>>def __init__(self, one, two=None, three=None, four=None, five=None, ...):
>>>self.one = one
>>>if not two is None:
>>>self.two = two
>>>...

Probably it will be necessary to set the attribute at first access. 
Alternatively it may be possible to observe the descriptor til an attribute 
will be setted e.g. instance.attr.value = 'whatever'. At this point a new 
instance (like Value) should be created on obj.__dict__.

It's the procedure what I'm looking for. ;)

Kind Regards,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Frank Millman
Hi all

I don't know if this question is more appropriate for the psycopg2 list, but 
I thought I would ask here first.

I have some binary data (a gzipped xml object) that I want to store in a 
database. For PostgreSQL I use a column with datatype 'bytea', which is 
their recommended way of storing binary strings.

I use psycopg2 to access the database. It returns binary data in the form of 
a python 'memoryview'.

My problem is that, after a roundtrip to the database and back, the object 
no longer compares equal to the original.

>>> memoryview(b'abcdef') == b'abcdef'
True
>>> cur.execute('create table fmtemp (code int, xml bytea)')
>>> cur.execute('insert into fmtemp values (%s, %s)', (1, b'abcdef'))
>>> cur.execute('select * from fmtemp where code =1')
>>> row = cur.fetchone()
>>> row
(1, )
>>> row[1] == b'abcdef'
False
>>> row[1].tobytes() == b'abcdef'
True
>>>

Using MS SQL Server and pyodbc, it returns a byte string, not a memoryview, 
and it does compare equal with the original.

I can hack my program to use tobytes(), but it would add complication, and 
it would be database-specific. I would prefer a cleaner solution.

Does anyone have any suggestions?

Versions - Python: 3.3.2  PostgreSQL: 9.2.4  psycopg2: 2.5

Frank Millman



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


Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Antoine Pitrou
Frank Millman  chagford.com> writes:
> 
> I have some binary data (a gzipped xml object) that I want to store in a 
> database. For PostgreSQL I use a column with datatype 'bytea', which is 
> their recommended way of storing binary strings.
> 
> I use psycopg2 to access the database. It returns binary data in the form of 
> a python 'memoryview'.
> 
[...]
> 
> Using MS SQL Server and pyodbc, it returns a byte string, not a memoryview, 
> and it does compare equal with the original.
> 
> I can hack my program to use tobytes(), but it would add complication, and 
> it would be database-specific. I would prefer a cleaner solution.

Just cast the result to bytes (`bytes(row[1])`). It will work both with bytes
and memoryview objcts.

Regards

Antoine.


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


Re: Is it that easy to install Python ?

2013-07-31 Thread santiago . diez
OK thanks for your answers.
So Python is not a daemon. Is it?
Does it have a config file?

Actually, each site on the web server is jailed in a chrooted environment.
In the chrooted environment, Python appears to be in /usr/bin/python.

If I give developers write access to a folder like 
/usr/lib/python/dist-packages/ (in the chrooted environment), will this be 
sufficient?

Regards
Santiago

PS: Thanks for all your opinions about how one should install Python but that 
wasn't the purpose of this thread. Most programs on my servers are compiled. 
Period.
-- 
http://mail.python.org/mailman/listinfo/python-list


Repository of non-standard modules.

2013-07-31 Thread Gabor Urban
Hi,

I am to start a new free-time project in the next couple of weeks. I am
ready to use open accessible Python modules not wanting to reinvent the
weel :-)
Is there any repository where I can find Python modules not being part of
the standard distribution?

I have some hits by Google but that seems to be far from complete.

Thanks in advance,

Gabor Urban

-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-31 Thread Tim Chase
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?

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)

which does give some modest readability benefits, but at a creation
cost I personally am unwilling to pay.

-tkc



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


Re: Repository of non-standard modules.

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 11:53 AM, Gabor Urban  wrote:
> Hi,
>
> I am to start a new free-time project in the next couple of weeks. I am
> ready to use open accessible Python modules not wanting to reinvent the weel
> :-)
> Is there any repository where I can find Python modules not being part of
> the standard distribution?

Check out the Python Package Index:

http://pypi.python.org/

Lots of stuff there, not all of it actively developed.

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


Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Frank Millman

"Antoine Pitrou"  wrote in message 
news:loom.20130731t114936-...@post.gmane.org...
> Frank Millman  chagford.com> writes:
>>
>> I have some binary data (a gzipped xml object) that I want to store in a
>> database. For PostgreSQL I use a column with datatype 'bytea', which is
>> their recommended way of storing binary strings.
>>
>> I use psycopg2 to access the database. It returns binary data in the form 
>> of
>> a python 'memoryview'.
>>
> [...]
>>
>> Using MS SQL Server and pyodbc, it returns a byte string, not a 
>> memoryview,
>> and it does compare equal with the original.
>>
>> I can hack my program to use tobytes(), but it would add complication, 
>> and
>> it would be database-specific. I would prefer a cleaner solution.
>
> Just cast the result to bytes (`bytes(row[1])`). It will work both with 
> bytes
> and memoryview objcts.
>
> Regards
>
> Antoine.
>

Thanks for that, Antoine. It is an improvement over tobytes(), but i am 
afraid it is still not ideal for my purposes.

At present, I loop over a range of columns, comparing 'before' and 'after' 
values, without worrying about their types. Strings are returned as str, 
integers are returned as int, etc. Now I will have to check the type of each 
column before deciding whether to cast to 'bytes'.

Can anyone explain *why* the results do not compare equal? If I understood 
the problem, I might be able to find a workaround.

Frank



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


importing modules

2013-07-31 Thread syed khalid
I am attempting to import modules from Shogun to python from a non-standard
python directory ie from my /home/xxx directory. is there a way on ubuntu
to selectively some modules, scripts, data  from one directory and others
modules, scripts from another directory. In other words, is there a file(s)
that provide pointers to where these modules are located.

regards

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


Re: email 8bit encoding

2013-07-31 Thread Antoon Pardon

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'

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


Re: import syntax

2013-07-31 Thread Chris Angelico
On Mon, Jul 29, 2013 at 11:37 PM, Joshua Landau  wrote:
> 2d) Realise that the slow part is not what you thought it was

This step is mandatory.

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


Re: Prime number generator

2013-07-31 Thread Ian Kelly
On Tue, Jul 30, 2013 at 4:58 AM, Albert van der Horst
 wrote:
> Notice that all values from i on are possibly present.
> So you are better off with a list indexed by forthcoming i's and
> each item containing a list of primes. What you do then, more or less,
> is keep track of all dividers of primes to be.
> This promises to be reasonable efficient.
> I've done a similar thing in Forth.

What do you do when you get up into the billions?  It seems
inefficient to keep a mostly empty billion-element list hanging
around.

> There is an unpleasant fact about this kind of generators.
> If you want to go unbounded, you've no choice but remember all
> primes. If you go bounded, you need to remember 168 up til 1M,
> say sqrt(limit)/log(limit). This dramatic difference (and the lack
> of processors) leads one quickly to decide for some upper bound.

Actually, take a look at the generator that I posted in this thread,
which avoids this.  It is unbounded but gets away with only
remembering sqrt(N) primes by recursively regenerating the primes
already seen as needed.  Thus it only uses (2 * N**(1/2) + 4 *
N**(1/4) 8 * N**(1/8) + ...) / log(N) extra memory, which I believe is
O(sqrt(N)).
-- 
http://mail.python.org/mailman/listinfo/python-list


Lambda function Turing completeness

2013-07-31 Thread Musical Notation
Is it possible to write a Turing-complete lambda function (which does not 
depend on named functions) in Python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Script that converts between indentation and curly braces in Python code

2013-07-31 Thread Musical Notation
Is there any script that converts indentation in Python code to curly braces? 
The indentation is sometime lost when I copy my code to an application or a 
website.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Joel Goldstick
On Tue, Jul 30, 2013 at 11:45 PM, Musical Notation
 wrote:
> Is there any script that converts indentation in Python code to curly braces? 
> The indentation is sometime lost when I copy my code to an application or a 
> website.

I guess you could google that.

What do you mean that indentation is 'sometimes' lost when copying.  I
think you should walk down that path to understand why you are losing
your indentation.  It could be you are using tabs instead of spaces
for indentation.  It could also be that you are inserting your code
directly into HTML which of course will eat the extra whitespace.
That problem can be solved with  tags, or maybe even  (but
I am not sure about that)

If you are copying code to a website like stack exchange you need to
precede each line of code with  (2 I think!) spaces.  They use
markdown.

If you wanted to add in curly braces, I am guesses the only purpose
for this would be that you would convert them back to proper
indentation in the copied to environment.  So then you have to figure
out a way to do that.



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



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Beth McNany
from __future__ import braces ;)

ok, ok, if you *really* want it, you could keep track of how many leading
spaces there are (you are using spaces, right?), and insert an open bracket
where that number increases and a closing bracket where it decreases.  Of
course, as with all parsing problems, this is oversimplification... if you
have multi-line statements you'll need to check for those (if line starts
with """ or ''', ends with \, or if there's an unclosed bracket or
paren...) - but that'd be a reasonable place to start if you're only doing
short code snippets.

Also, I have to ask, how to you intend this to be used?  If there's no
indentation it will still be difficult to read, and your readers will then
have the problem of figuring out which curly braces to remove (for simple
code this might be easy, but for longer things you'd probably want an
automated way to re-indent, and a simple search-and-replace will screw up
any dictionaries, for instance).

-beth

On Tue, Jul 30, 2013 at 11:45 PM, Musical Notation <
musicdenotat...@gmail.com> wrote:

> Is there any script that converts indentation in Python code to curly
> braces? The indentation is sometime lost when I copy my code to an
> application or a website.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-31 Thread Neil Cerutti
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?
>
> 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)
>
> which does give some modest readability benefits, but at a
> creation cost I personally am unwilling to pay.

I'm actually OK with the creation cost, but not the maintenance cost.

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


Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Antoine Pitrou
Frank Millman  chagford.com> writes:
> 
> Thanks for that, Antoine. It is an improvement over tobytes(), but i am 
> afraid it is still not ideal for my purposes.

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.

For example, the standard sqlite3 module returns bytes for BLOB columns,
and str for TEXT columns:
http://docs.python.org/3.4/library/sqlite3.html#introduction

> Can anyone explain *why* the results do not compare equal? If I understood 
> the problem, I might be able to find a workaround.

Well, under recent Python versions, they should compare equal:

Python 3.2.3 (default, Oct 19 2012, 19:53:16) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> memoryview(b"abc") == b"abc"
True


Regards

Antoine.


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


Re: Lambda function Turing completeness

2013-07-31 Thread Schneider

On Wed 31 Jul 2013 08:53:26 AM CEST, Musical Notation wrote:

Is it possible to write a Turing-complete lambda function (which does not 
depend on named functions) in Python?


what should a sinlge Turing-complete lambda function be?
For me, a programming language can be Turing-complete or a function can 
be universal,  e.g. like an interpreter for a  programming language.


bg,
Johannes

--
GLOBE Development GmbH
Königsberger Strasse 260
48157 MünsterGLOBE Development GmbH
Königsberger Strasse 260
48157 Münster
0251/5205 390
--
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Neil Hodgson

Musical Notation:


Is there any script that converts indentation in Python code to curly braces?
The indentation is sometime lost when I copy my code to an application or a 
website.


   pindent.py in the Tools/Scripts directory of Python installations 
does something similar by adding or removing comments that look like


# end if

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


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

2013-07-31 Thread Serhiy Storchaka

31.07.13 06:45, Musical Notation написав(ла):

Is there any script that converts indentation in Python code to curly braces? 
The indentation is sometime lost when I copy my code to an application or a 
website.


Look at the pindent.py script.

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


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

2013-07-31 Thread Musical Notation
On Jul 31, 2013, at 19:27, IshIsh  wrote:

> Try from __future__ import braces as the first line of a source file (or 
> typing it in an interactive session), and watch the interpreter's 
> response...
"SyntaxError: not a chance" I already know that.-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Frank Millman

"Antoine Pitrou"  wrote in message 
news:loom.20130731t150154-...@post.gmane.org...
> Frank Millman  chagford.com> writes:
>>
>> Thanks for that, Antoine. It is an improvement over tobytes(), but i am
>> afraid it is still not ideal for my purposes.
>
> 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'll try it, and see what they say.

> For example, the standard sqlite3 module returns bytes for BLOB columns,
> and str for TEXT columns:
> http://docs.python.org/3.4/library/sqlite3.html#introduction
>
>> Can anyone explain *why* the results do not compare equal? If I 
>> understood
>> the problem, I might be able to find a workaround.
>
> Well, under recent Python versions, they should compare equal:
>
> Python 3.2.3 (default, Oct 19 2012, 19:53:16)
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 memoryview(b"abc") == b"abc"
> True
>

I am using Python 3.3.2.

If I try your example above, it does work.

However, for some reason, after a round-trip to the server, they do not 
compare equal.

See my original post for a full example.

Frank



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


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

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 1:39 PM, Beth McNany  wrote:
> ok, ok, if you *really* want it, you could keep track of how many leading
> spaces there are (you are using spaces, right?), and insert an open bracket
> where that number increases and a closing bracket where it decreases.  Of
> course, as with all parsing problems, this is oversimplification... if you
> have multi-line statements you'll need to check for those (if line starts
> with """ or ''', ends with \, or if there's an unclosed bracket or paren...)
> - but that'd be a reasonable place to start if you're only doing short code
> snippets.
>

Since the braced version won't run anyway, how about a translation like this:

def foo():
print("""Hello,
world!""")
for i in range(5):
foo()
return 42

-->

0-def foo():
4-print("""Hello,
0-world!""")
4-for i in range(5):
8-foo()
4-return 42

That's a simple translation that guarantees safe round-tripping, and
you can probably do it with a one-liner fwiw... let's see...

# Assumes spaces OR tabs but not both
# Can't see an easy way to count leading spaces other than:
# len(s)-len(s.lstrip())
code = '\n'.join("%d-%s"%(len(s)-len(s.lstrip()),s.lstrip()) for s in
code.split('\n'))

# Recreates with spaces, choose tabs for the multiplication if you prefer
code = '\n'.join(' '*int(s.split('-',1)[0])+s.split('-',1)[1] for s in
code.split('\n'))

These would be better done in a couple of lines, but I like doing
one-liners just for fun. :)

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


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

2013-07-31 Thread Rotwang

On 31/07/2013 14:55, Chris Angelico wrote:

[...]


Since the braced version won't run anyway, how about a translation like this:

def foo():
 print("""Hello,
world!""")
 for i in range(5):
 foo()
 return 42

-->

0-def foo():
4-print("""Hello,
0-world!""")
4-for i in range(5):
8-foo()
4-return 42

That's a simple translation that guarantees safe round-tripping, and
you can probably do it with a one-liner fwiw... let's see...

# Assumes spaces OR tabs but not both
# Can't see an easy way to count leading spaces other than:
# len(s)-len(s.lstrip())


How about len(s.expandtabs()) - len(s.lstrip()) instead?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Neil Cerutti
On 2013-07-31, Frank Millman  wrote:
>
> "Antoine Pitrou"  wrote in message 
> news:loom.20130731t114936-...@post.gmane.org...
>> Frank Millman  chagford.com> writes:
>>>
>>> I have some binary data (a gzipped xml object) that I want to store in a
>>> database. For PostgreSQL I use a column with datatype 'bytea', which is
>>> their recommended way of storing binary strings.
>>>
>>> I use psycopg2 to access the database. It returns binary data
>>> in the form of a python 'memoryview'.
>>>
>> [...]
>>>
>>> Using MS SQL Server and pyodbc, it returns a byte string, not
>>> a memoryview, and it does compare equal with the original.
>>>
>>> I can hack my program to use tobytes(), but it would add
>>> complication, and it would be database-specific. I would
>>> prefer a cleaner solution.
>>
>> Just cast the result to bytes (`bytes(row[1])`). It will work
>> both with bytes and memoryview objcts.
>
> Thanks for that, Antoine. It is an improvement over tobytes(),
> but i am afraid it is still not ideal for my purposes.
>
> At present, I loop over a range of columns, comparing 'before'
> and 'after' values, without worrying about their types. Strings
> are returned as str, integers are returned as int, etc. Now I
> will have to check the type of each column before deciding
> whether to cast to 'bytes'.
>
> 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.

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


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

2013-07-31 Thread Joel Goldstick
So, why do you want to do this?  As has been pointed out, its a
difficult and likely sizable task to build such a parser.  In the end
you get something that isn't a computer language -- even tho it looks
like one.  And it also is probably just as big a job to convert it
back to python.  So, what is the point?

Pardon me for making assumptions, but this seems to be a variation on
the theme of 'I don't like python, it doesn't have curly braces'.  So
if you need curly braces, you have many other languages to choose
from.  Python isn't one of them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-31 Thread Michael Torrie
On 07/31/2013 01:23 AM, Antoon Pardon wrote:
> Op 31-07-13 05:30, Michael Torrie schreef:
>> On 07/30/2013 12:19 PM, Antoon Pardon wrote:
>>> So? Why are you making this a point of discussion? I was not aware that
>>> the pro and cons of various editor buffer implemantations was relevant
>>> to the point I was trying to make.
>>
>> I for one found it very interesting.  In fact this thread caused me to
>> wonder how one actually does create an efficient editor.  Off the
>> original topic true, but still very interesting.
>>
> 
> Yes, it can be interesting. But I really think if that is what you want
> to discuss, it deserves its own subject thread.

Subject lines can and should be changed to reflect the ebbs and flows of
the discussion.

In fact this thread's subject should have been changed a long time ago
since the original topic was RE module performance!
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 3:07 PM, Rotwang  wrote:
>> # Assumes spaces OR tabs but not both
>> # Can't see an easy way to count leading spaces other than:
>> # len(s)-len(s.lstrip())
>
>
> How about len(s.expandtabs()) - len(s.lstrip()) instead?

Still comes to the same thing. The only diff is that tabs get treated
as eight spaces instead of one (and the bug that a tab elsewhere in
the line will result in indentation, which is fixed by lstripping the
tab-expanded form). It won't perfectly round-trip with a mixture of
tabs and spaces; as it is, you can pick one or the other and run with
it. Anyway, the main point is that indentation will work. Sure you
might have ugly narrow code, but it'll run with one-space indents.

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


Re: binary key in dictionary

2013-07-31 Thread John Gordon
In <9004a556-958f-4d1d-81a7-4d1b73134...@googlegroups.com> cerr 
 writes:

> Traceback (most recent call last):
>   File "gateway.py", line 2485, in 
> main()
>   File "gateway.py", line 2459, in main
> cloud_check()
>   File "gateway.py", line 770, in cloud_check
> gnstr_dict[src] = gn_from_cloud(curr_mac)
>   File "gateway.py", line 2103, in gn_from_cloud
> tmpgndict[binmac] += "HELLO"
> KeyError: '\x04\xeeu'

You're not assigning to tmpgndict[binmac]; you're appending to it.  This
requires that tmpgndict[binmac] already exists, which it does not.

Make sure that tmpgndict[binmac] exists before you try appending to it.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: RE Module Performance

2013-07-31 Thread Michael Torrie
On 07/31/2013 02:32 AM, wxjmfa...@gmail.com wrote:
> Unicode/utf*

Why do you keep using the terms "utf" and "Unicode" interchangeably?
-- 
http://mail.python.org/mailman/listinfo/python-list


script to Login a website

2013-07-31 Thread wachkama

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

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


Re: how to package embedded python?

2013-07-31 Thread David M. Cotter
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)

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


Re: script to Login a website

2013-07-31 Thread John Gordon
In  wachk...@gmail.com 
writes:

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

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.

Is this correct?

If so, that raises the question of how to handle multiple usernames and
passwords.  Do you just want to use one, or are you supposed to use them
all somehow?

Anyway, to begin to solve your problem, I'd copy just the file-reading code
into a separate program and add plenty of print statements to make sure it
works correctly.  Once you have that fixed, then you can worry about the
web login stuff.

And when you read the contents of each file, be aware that the newlines
at the end of each line are included.  If you don't want these, be sure
to call the rstrip() method to remove traling whitespace.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: PEP8 79 char max

2013-07-31 Thread Grant Edwards
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.

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

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

-- 
Grant Edwards   grant.b.edwardsYow! I am NOT a nut
  at   
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-31 Thread Grant Edwards
On 2013-07-31, Neil Cerutti  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?
>>
>> 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)
>>
>> which does give some modest readability benefits, but at a
>> creation cost I personally am unwilling to pay.
>
> I'm actually OK with the creation cost, but not the maintenance cost.

In my experience, aligning columns in large tables reduces maintence
cost by making it much easier/faster to see what you've got and by
providing a way to visually "prompt" you for the correct value in the
correct place when you add new lines.

-- 
Grant Edwards   grant.b.edwardsYow! hubub, hubub, HUBUB,
  at   hubub, hubub, hubub, HUBUB,
  gmail.comhubub, hubub, hubub.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it that easy to install Python ?

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 4:08 AM,   wrote:
> OK thanks for your answers.
> So Python is not a daemon. Is it?

No.

> Does it have a config file?

Not as such.  Arbitrary site-specific customization can be done by
creating a sitecustomize module, but this is not standard.  There are
also some environment variables that you may want to consider setting
in the system profile, but none are required or generally recommended:

http://docs.python.org/2/using/cmdline.html#environment-variables

> Actually, each site on the web server is jailed in a chrooted environment.
> In the chrooted environment, Python appears to be in /usr/bin/python.
>
> If I give developers write access to a folder like 
> /usr/lib/python/dist-packages/ (in the chrooted environment), will this be 
> sufficient?

I don't have experience with this, but it seems to me that you should
place the standard library and site-packages in the chrooted
/usr/lib/python2.7 and then set the PYTHONHOME environment variable to
/usr/lib.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it that easy to install Python ?

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 10:44 AM, Ian Kelly  wrote:
> and then set the PYTHONHOME environment variable to /usr/lib.

Rather, just /usr.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: script to Login a website

2013-07-31 Thread wachkama
On Wednesday, July 31, 2013 12:21:59 PM UTC-4, John Gordon wrote:
> In  wachk...@gmail.com 
> writes:
> 
> 
> 
> > 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 ?
> 
> 
> 
> 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.
> 
> 
> 
> Is this correct?
> 
> 
> 
> If so, that raises the question of how to handle multiple usernames and
> 
> passwords.  Do you just want to use one, or are you supposed to use them
> 
> all somehow?
> 
> 
> 
> Anyway, to begin to solve your problem, I'd copy just the file-reading code
> 
> into a separate program and add plenty of print statements to make sure it
> 
> works correctly.  Once you have that fixed, then you can worry about the
> 
> web login stuff.
> 
> 
> 
> And when you read the contents of each file, be aware that the newlines
> 
> at the end of each line are included.  If you don't want these, be sure
> 
> to call the rstrip() method to remove traling whitespace.
> 
> 
> 
> -- 
> 
> John Gordon   A is for Amy, who fell down the stairs
> 
> gor...@panix.com  B is for Basil, assaulted by bears
> 
> -- Edward Gorey, "The Gashlycrumb Tinies"

Hi John 
let me answer your questions 
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 ?

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


Re: Repository of non-standard modules.

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 5:02 AM, Chris Angelico  wrote:
> On Wed, Jul 31, 2013 at 11:53 AM, Gabor Urban  wrote:
>> Hi,
>>
>> I am to start a new free-time project in the next couple of weeks. I am
>> ready to use open accessible Python modules not wanting to reinvent the weel
>> :-)
>> Is there any repository where I can find Python modules not being part of
>> the standard distribution?
>
> Check out the Python Package Index:
>
> http://pypi.python.org/

There's also the somewhat prettier crate.io.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda function Turing completeness

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 12:53 AM, Musical Notation
 wrote:
> Is it possible to write a Turing-complete lambda function (which does not 
> depend on named functions) in Python?

Yes, lambda functions are Turing-complete.  You can get anonymous
recursion by defining the function to take a recursive function
argument and then passing it to itself.  For example, this will
(inefficiently) give you the 13th Fibonacci number:

(lambda f, n: f(f, n))(lambda f, n: n if n < 2 else f(f, n-2) + f(f, n-1), 13)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-31 Thread Marcelo MD
>
> In my experience, aligning columns in large tables reduces maintence
> cost by making it much easier/faster to see what you've got and by
> providing a way to visually "prompt" you for the correct value in the
> correct place when you add new lines.
>
>
Works great until one of the values changes in size. Say:
bla = (
1.0, 1.1, 1.2,
2.0, 2.1, 2.2,
3.0, 2.1, 3.2,
)

And one day you have to change '2.1' to '2.0':
bla = (
1.0, 1.1, 1.2,
2.0, 2.0, 2.2,
3.0, 2.1, 3.2,
)

If this happens more than once ( or twice, because I'm patient =)),
maintaining the alignment becomes a chore. So I only align columns if I'm
typing a table I know won't change.


-- 
Marcelo Mallmann Dias
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python descriptor protocol (for more or less structured data)

2013-07-31 Thread Terry Reedy

On 7/31/2013 5:16 AM, CWr wrote:

Peter, thanks for your response.
Sure, you are right when you say that's easier to use standard attribute 
assigning via __init__.

But my intention was:
- reducing the complexiticity of __init__
- avoiding boiler-plates (mostly property descriptors inside of the main class)
- creating instances (for complex data strings) only if they will be needed, 
otherwise use default instances (descriptors)
- make it prossible that the data structure can be used in static context - 
like MyClass.attr - to get default values

Standard procedure:


class C:


DEFAULT_4_TWO =  # for following code to work


def __init__(self, one, two=None, three=None, four=None, five=None, ...):
if not two is None:


"if two is not None:"  reads better and is the preferred form.
'is not' is a single comparison operator, just like '!=' and 'not in'. 
The current CPython AST or peephole optimizer happens to notice that the 
'is' operator followed by the 'not' operator can be replaced by the 'is 
not' operator, but this is not guaranteed for all implementations.



self.two = Value(two)
else:
self.two = Value(self.DEFAULT_4_TWO)


self.two = Value(two if two is not None else self.DEFAULT_4_TWO)

There is no need to introduce the new name DEFAULT_4_TWO. It is a 
symptom of using the wrong namespace to get the default.


class C:
two = 
def __init__(self, two=None):
self.two = Value(two if two is not None else C.two)

--
Terry Jan Reedy

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


ImportError: No module named appengine.ext

2013-07-31 Thread Jaiky
hey learning python 

problem facing is under when typing on interpreter


>>> from google.appengine.ext import db
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named appengine.ext


what to do please help .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread Terry Reedy

On 7/31/2013 9:07 AM, Antoine Pitrou wrote:

Frank Millman  chagford.com> writes:


Thanks for that, Antoine. It is an improvement over tobytes(), but i am
afraid it is still not ideal for my purposes.


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


--
Terry Jan Reedy

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


Re: PEP8 79 char max

2013-07-31 Thread Skip Montanaro
=> Works great until one of the values changes in size.

Slightly off-topic, but still sort of related (talking about the size
of things), I started picking 1e+30 as my "really big" some time back
because the repr of 1e+99 required more than a glance when it appeared
in printed output:

>>> repr(1e+30)
'1e+30'
>>> repr(1e+99)
'9.9997e+98'

This problem was fixed in 2.7 (and presumably in 3.something as well),
but it used to be a problem. :-)

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


Re: PEP8 79 char max

2013-07-31 Thread Neil Cerutti
On 2013-07-31, Marcelo MD  wrote:
>> In my experience, aligning columns in large tables reduces
>> maintence cost by making it much easier/faster to see what
>> you've got and by providing a way to visually "prompt" you for
>> the correct value in the correct place when you add new lines.
>
> Works great until one of the values changes in size. Say:
> bla = (
> 1.0, 1.1, 1.2,
> 2.0, 2.1, 2.2,
> 3.0, 2.1, 3.2,
> )
>
> And one day you have to change '2.1' to '2.0':
> bla = (
> 1.0, 1.1, 1.2,
> 2.0, 2.0, 2.2,
> 3.0, 2.1, 3.2,
> )
>
> If this happens more than once ( or twice, because I'm patient =)),
> maintaining the alignment becomes a chore. So I only align columns if I'm
> typing a table I know won't change.

Yes, that was my exprience, too.

Besides, after studying The Pragmatic Programmer I removed nearly
all the tables from my code and reference them (usually with csv
module) instead.

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


Re: PEP8 79 char max

2013-07-31 Thread Tim Chase
On 2013-07-31 16:32, Grant Edwards wrote:
> On 2013-07-31, Tim Chase  wrote:
> > 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.

As mentioned by Marcelo, when they can vary in length, maintaining is
a pain.  Even if your editor supports aligning (like vim with Dr.
Chip's align.vim plugin).  If I have a table of greater dimensions, I
tend to refactor into a more readable+maintainable scheme, whether
using dicts or named tuples and then break out the rows onto their own
lines:

  from collections import namedtuple
  Descriptor = namedtuple("Descriptor", ["name", "value",
  "description"])
  for name, value, description in (
  Descriptor(
name="cost",
value=42,
description="How much it cost",
),
  Descriptor(
name="status",
value=3141,
description="Status code from ISO-3.14159",
),
  ):
do_something(name, value)
print(description)

Using a namedtuple, if you forget one of the fields (or add an
extra, or misspell one), it yells at you:

  TypeError: __new__() takes exactly 4 arguments (2 given)
  TypeError: __new__() takes exactly 4 arguments (6 given)
  TypeError: __new__() got an unexpected keyword argument 'nmae'

There is redundancy of the kwarg params, but this can be skipped
if you prefer DRY code to more readable code.

Doing this also has the benefit that, when diffing, you don't get
noise when columns are merely adjusted visually.

-tkc







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


Re: PEP8 79 char max

2013-07-31 Thread Grant Edwards
On 2013-07-31, Neil Cerutti  wrote:

> Besides, after studying The Pragmatic Programmer I removed nearly
> all the tables from my code and reference them (usually with csv
> module) instead.

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

-- 
Grant Edwards   grant.b.edwardsYow! Spreading peanut
  at   butter reminds me of
  gmail.comopera!!  I wonder why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-31 Thread Tim Chase
On 2013-07-31 16:32, Grant Edwards wrote:
> On 2013-07-31, Tim Chase  wrote:  
> > 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.  

As mentioned by Marcelo, when they can vary in length, maintaining is
a pain.  Even if your editor supports aligning (like vim with Dr.
Chip's align.vim plugin).  If I have a table of greater dimensions, I
tend to refactor into a more readable+maintainable scheme, whether
using dicts or named tuples and then break out the rows onto their own
lines:

  from collections import namedtuple
  Descriptor = namedtuple("Descriptor", ["name", "value", "description"])
  for name, value, description in (
  Descriptor(
name="cost",
value=42,
description="How much it cost",
),
  Descriptor(
name="status",
value=3141,
description="Status code from ISO-3.14159",
),
  ):
do_something(name, value)
print(description)

Using a namedtuple, if you forget one of the fields (or add an
extra, or misspell one), it yells at you:

  TypeError: __new__() takes exactly 4 arguments (2 given)
  TypeError: __new__() takes exactly 4 arguments (6 given)
  TypeError: __new__() got an unexpected keyword argument 'nmae'

There is redundancy of the kwarg params, but this can be skipped
if you prefer DRY code to more readable code.

Doing this also has the benefit that, when diffing, you don't get
noise when columns are merely adjusted visually.

-tkc







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


Re: ImportError: No module named appengine.ext

2013-07-31 Thread Chris “Kwpolska” Warrick
On Wed, Jul 31, 2013 at 7:51 PM, Jaiky  wrote:
> hey learning python
>
> problem facing is under when typing on interpreter
>
>
 from google.appengine.ext import db
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named appengine.ext
>
>
> what to do please help .
> --
> http://mail.python.org/mailman/listinfo/python-list

You do not have the Google AppEngine packages installed on your
system.  You may want to get the AppEngine SDK or the AppEngine
development server.
-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named appengine.ext

2013-07-31 Thread John Gordon
In <719f0bd8-cddc-4b28-97ee-08b56d359...@googlegroups.com> Jaiky 
 writes:

> >>> from google.appengine.ext import db
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named appengine.ext

> what to do please help .

Has the Google App Engine library been installed on your system?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: ImportError: No module named appengine.ext

2013-07-31 Thread Jaiky
you mean to say SDK for python ?/

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


Using system python vs. updated/current version

2013-07-31 Thread memilanuk
Hello there,

What would be considered the correct/best way to run a current release
of python locally vs. the installed system version?  On openSUSE 12.3,
the repos currently have 2.7.3 and 3.3.0.  As far as I know, I'm not
really hitting any limitations with the existing versions - my skills
just aren't that far along - so its not a burning 'need' but I'm still
curious/interested in the topic.

Also... in some places in the 'Net I see references to installing
everything 'locally' via pip, etc. in virtualenvs and not touching the
system installed version of python... yet most linux distros seem to
have many/most such packages available in their package repos, which
seems like it'd be easier to install via the package manager and let it
keep things updated.  Could someone touch on what they feel the pros and
cons would be either way?

Thanks,

Monte

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


Editing tabular data [was: PEP8 79 char max]

2013-07-31 Thread Skip Montanaro
> 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.

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


RE: PEP8 79 char max

2013-07-31 Thread Prasad, Ramit
Grant Edwards wrote:
> On 2013-07-31, Neil Cerutti  wrote:
> 
> > Besides, after studying The Pragmatic Programmer I removed nearly
> > all the tables from my code and reference them (usually with csv
> > module) instead.
> 
> 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).
> 
> --
> Grant Edwards   grant.b.edwardsYow! Spreading peanut
>   at   butter reminds me of
>   gmail.comopera!!  I wonder why?
> --

True, but a CSV file is easy to edit in something like a spreadsheet
application (LibreOffice/MS Office); alignment becomes automatic
then.


Ramit





This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-31 Thread Neil Cerutti
On 2013-07-31, Grant Edwards  wrote:
> On 2013-07-31, Neil Cerutti  wrote:
>> Besides, after studying The Pragmatic Programmer I removed
>> nearly all the tables from my code and reference them (usually
>> with csv module) instead.
>
> 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).

Yes, but it is much easier to manipulate and view. I often still
edit the tables with Vim, but when I just want to view them I can
open them with Excel and get a very attractive display or
printout with minimal effort.

If it turns out I need to convert the table to some new format,
tools are abundant.

A couple of big wins:

It turned out later that some other entity needed the same data.

It has allowed me to add functionality to my program without even
editing the program.

Wouldn't be cool to add a new instruction by to my assembler,
including documentation, merely by editing a csv file? (I admit
that would need quite a bit of engineering to work, but it would
be cool.)

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


Re: PEP8 79 char max

2013-07-31 Thread Grant Edwards
On 2013-07-31, Neil Cerutti  wrote:
> On 2013-07-31, Grant Edwards  wrote:
>> On 2013-07-31, Neil Cerutti  wrote:
>>> Besides, after studying The Pragmatic Programmer I removed
>>> nearly all the tables from my code and reference them (usually
>>> with csv module) instead.
>>
>> 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).
>
> Yes, but it is much easier to manipulate and view. I often still
> edit the tables with Vim, but when I just want to view them I can
> open them with Excel and get a very attractive display or
> printout with minimal effort.

If you're good at Excel.  I use a spreadsheet at most a few times a
year, and it has been many years since I've used Excel.  I find that
doing _anything_ with Excel generally involves at least an hour of
hairpulling and swearing.  Libreoffice isn't much better.

> If it turns out I need to convert the table to some new format,
> tools are abundant.

True.

> A couple of big wins:
>
> It turned out later that some other entity needed the same data.

It would save the two seconds it takes to extract the lines from the
Python file.

> It has allowed me to add functionality to my program without even
> editing the program.

Now you're playing with semantics.  If I have a bunch of lines
containing values separated by commas, and I'm editting them, then it
makes no difference to me which file they're in -- I'm still adding
functionality be editing a table of data.

> Wouldn't be cool to add a new instruction by to my assembler,
> including documentation, merely by editing a csv file? (I admit
> that would need quite a bit of engineering to work, but it would
> be cool.)

Yes, that's cool, and that's pretty much how it works.  Those csv
lines just happen to be in the same file as the rest of the assembler
source rather than in a second file.

-- 
Grant Edwards   grant.b.edwardsYow! Hello?  Enema Bondage?
  at   I'm calling because I want
  gmail.comto be happy, I guess ...
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Grant Edwards
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...

-- 
Grant Edwards   grant.b.edwardsYow! I haven't been married
  at   in over six years, but we
  gmail.comhad sexual counseling every
   day from Oral Roberts!!
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Neil Cerutti
On 2013-07-31, Rhodri James  wrote:
> On Wed, 31 Jul 2013 19:39:29 +0100, 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.
>
> There's nothing foolproof about using a spreadsheet!

I edit csv files using Excel all the time. But I don't use it to
edit my hand-created data files. It does too much meddling.

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


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

2013-07-31 Thread Rhodri James

On Wed, 31 Jul 2013 19:39:29 +0100, 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.


There's nothing foolproof about using a spreadsheet!

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


pcurl and network connection's problem

2013-07-31 Thread sam319
I am having problems with pycurl in my threads , when i run it , it does 
correctly but some times the connection has been established but nothing will 
be downloaded and the threads stay alive without doing any thing (especially 
when the network's speed is slow and has aborted status) .

i can't use TIMEOUT  because i don't have the max time for downloading 

how can i solve this problem in python
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Using system python vs. updated/current version

2013-07-31 Thread Prasad, Ramit
memilanuk wrote:
> Hello there,
> 
> What would be considered the correct/best way to run a current release
> of python locally vs. the installed system version?  On openSUSE 12.3,
> the repos currently have 2.7.3 and 3.3.0.  As far as I know, I'm not
> really hitting any limitations with the existing versions - my skills
> just aren't that far along - so its not a burning 'need' but I'm still
> curious/interested in the topic.

You should be able to install both Python 2 and 3 in most modern
Linux distributions (at the same time). I would not change the system
Python version.

If you are not blocked from running Python 3 by some necessary
dependency then you should use it. Otherwise, use the most
recent Python version you can. 

> 
> Also... in some places in the 'Net I see references to installing
> everything 'locally' via pip, etc. in virtualenvs and not touching the
> system installed version of python... yet most linux distros seem to
> have many/most such packages available in their package repos, which
> seems like it'd be easier to install via the package manager and let it
> keep things updated.  Could someone touch on what they feel the pros and
> cons would be either way?

Virtual envs are great if you work on multiple projects and want to 
keep each project's dependencies separate and manageable. This
will let you change dependencies to a newer version based on project 
rather than having to change the dependency for all projects.

Not to mention this also allows you to install packages on hosts
that you do not have access to install them to the system
packages directory.

On a personal machine, I would install some things like pip/virtualenv 
(/numpy maybe) to system packages directory but keep most packages in 
a project specific directory (i.e. virtualenv).


> 
> Thanks,
> 
> Monte



This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-07-31 Thread Neil Cerutti
On 2013-07-31, Grant Edwards  wrote:
> On 2013-07-31, Neil Cerutti  wrote:
>> On 2013-07-31, Grant Edwards  wrote:
>>> On 2013-07-31, Neil Cerutti  wrote:
 Besides, after studying The Pragmatic Programmer I removed
 nearly all the tables from my code and reference them (usually
 with csv module) instead.
>>>
>>> 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).
>>
>> Yes, but it is much easier to manipulate and view. I often still
>> edit the tables with Vim, but when I just want to view them I can
>> open them with Excel and get a very attractive display or
>> printout with minimal effort.
>
> If you're good at Excel.  I use a spreadsheet at most a few times a
> year, and it has been many years since I've used Excel.  I find that
> doing _anything_ with Excel generally involves at least an hour of
> hairpulling and swearing.  Libreoffice isn't much better.
>
>> If it turns out I need to convert the table to some new format,
>> tools are abundant.
>
> True.
>
>> A couple of big wins:
>>
>> It turned out later that some other entity needed the same
>> data.
>
> It would save the two seconds it takes to extract the lines
> from the Python file.

...assuming I'm not creating a maintenance problem by duplicating
the table. Most likely you would end up externalizing the table
at that point, right?

>> It has allowed me to add functionality to my program without
>> even editing the program.
>
> Now you're playing with semantics.  If I have a bunch of lines
> containing values separated by commas, and I'm editting them,
> then it makes no difference to me which file they're in -- I'm
> still adding functionality be editing a table of data.

The separation of data and program is more distinct in my
version, but you're right, of course. An internal representation
in addition has the advantage of being able to directly use
Python identifiers and expressions, too. But if you take
advantage of those features when the time comes to externalize
your data it's more work.

The only cost you pay more than what I've already spent at that
point is whatever time you spent creating the non-external
version to begin with.

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


RE: pcurl and network connection's problem

2013-07-31 Thread Prasad, Ramit
sam319 wrote:
> I am having problems with pycurl in my threads , when i run it , it does 
> correctly but some times the
> connection has been established but nothing will be downloaded and the 
> threads stay alive without
> doing any thing (especially when the network's speed is slow and has aborted 
> status) .
> 
> i can't use TIMEOUT  because i don't have the max time for downloading
> 
> how can i solve this problem in python

So you want to wait hours/days/years for a failed download? You should always 
set a 
timeout that is sane. If you anticipate network slowness, then set your timeout 
to 
something larger like 2-3 minutes. IIRC, the timeout only affects connection
establishment so that will not help out your use case but I want to emphasize
that you always want a timeout to be set. 

Pycurl has an option for LOW_SPEED_LIMIT/LOW_SPEED_TIME which should allow you 
to set 
a minimum transfer speed which will abort the transfer. This should solve your 
problem
where the connection is created but nothing is being downloaded.

See: 
http://stackoverflow.com/questions/4960021/handle-pycurl-hang-on-twitter-streaming-api


Ramit



This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Skip Montanaro
>> 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 really love Emacs, however...  One of the traders here where I work
(who shall not be named) had a space-delimited data file with hundreds
of rows and 50 or so columns.  I could never get him to edit it in any
kind of spreadsheet or put it in a database (expecting him to master
SQL would have been pointless - I would have had to write a GUI tool
for him).  He always modified it in Emacs, and would delete columns,
add extra spaces, fragmentary rows, etc.  He'd edit this file late at
night, the automated processes the next morning would crap out, and I
would scramble to try and find and fix the problem before the market
opened.

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.

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


Re: RE Module Performance

2013-07-31 Thread wxjmfauth
Le mercredi 31 juillet 2013 07:45:18 UTC+2, Steven D'Aprano a écrit :
> On Tue, 30 Jul 2013 12:09:11 -0700, wxjmfauth wrote:
> 
> 
> 
> > And do not forget, in a pure utf coding scheme, your char or a char will
> 
> > *never* be larger than 4 bytes.
> 
> > 
> 
>  sys.getsizeof('a')
> 
> > 26
> 
>  sys.getsizeof('\U000101000')
> 
> > 48
> 
> 
> 
> Neither character above is larger than 4 bytes. You forgot to deduct the 
> 
> size of the object header. Python is a high-level object-oriented 
> 
> language, if you care about minimizing every possible byte, you should 
> 
> use a low-level language like C. Then you can give every character 21 
> 
> bits, and be happy that you don't waste even one bit.
> 
> 
> 
> 
> 
> -- 
> 
> Steven

... char never consumes or requires more than 4 bytes ...

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


Re: Using system python vs. updated/current version

2013-07-31 Thread memilanuk
On 07/31/2013 12:17 PM, Prasad, Ramit wrote:
> You should be able to install both Python 2 and 3 in most modern
> Linux distributions (at the same time). I would not change the system
> Python version.

I hadn't really planned on mucking with the system python... I recall
from a long while back (on Mac OSX) as that being a Bad Thing ;)

But that is kind of (one of) the question(s) here... I presume it is
'possible' to run a local version of python, installed in the user's
home directory... just curious if its worth the hassle.

> If you are not blocked from running Python 3 by some necessary
> dependency then you should use it. Otherwise, use the most
> recent Python version you can. 

Are there any significant flaws with v.3.3.0 that would necessitate
upgrading to the most recent version (3.3.2?)

The only 'dependency' I have as far as 2.7.x is concerned is that I've
become rather accustomed to using spyder (IDE)... which at this point
doesn't support python3 - definitely a bummer.

> On a personal machine, I would install some things like pip/virtualenv 
> (/numpy maybe) to system packages directory but keep most packages in 
> a project specific directory (i.e. virtualenv).

What about larger gui toolkits like PyQt?  Some material I browsed
(skimmed) indicated that it wasn't quite as simple to run straight from
a virtualenv...?

How much of a pain are virtualenvs when working from an IDE?


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


Re: Using system python vs. updated/current version

2013-07-31 Thread Terry Reedy

On 7/31/2013 2:35 PM, memilanuk wrote:

Hello there,

What would be considered the correct/best way to run a current release
of python locally vs. the installed system version?  On openSUSE 12.3,
the repos currently have 2.7.3  and 3.3.0


released April 2012. 2.7.5 100+?? bug fixes.
and released Sept 2012, fewer bug fixes.


 As far as I know, I'm not
really hitting any limitations with the existing versions


Quite possible. However, anyone using Idle should get the latest 
versions since there have been many Idle fixes since last September.


--
Terry Jan Reedy

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


Re: script to Login a website

2013-07-31 Thread Joel Goldstick
On Wed, Jul 31, 2013 at 11:33 AM,   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
>
I think you will note that login_data is overwritten each password
loop.  In the end of all of the above you have the last users followed
by a newline, followed by the last pass_list
You might want to think about putting the code below in a function
that can be called after print login_data above if you want to check
each username and password combination.


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

I don't think the above line provides login_data as specified by the
spec:   http://docs.python.org/2/library/urllib2.html#module-urllib2

It looks like data needs to be tuples

> response.read()
> print response.headers
> print response.getcode()
>
> --

Once you correct the top of your code I recommend Requests module
since its easier to understand, simpler, and better documented than
the standard url stuff.  You can find it at
http://docs.python-requests.org/en/latest/

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



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-31 Thread Wanderer
On Wednesday, July 31, 2013 2:39:29 PM UTC-4, 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.
> 
> 
> 
> Skip

Has anyone tried Pyspread?

http://manns.github.io/pyspread/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 9:15 PM,   wrote:
> ... char never consumes or requires more than 4 bytes ...
>

The integer 5 should be able to be stored in 3 bits.

>>> sys.getsizeof(5)
14

Clearly Python is doing something really horribly wrong here. In fact,
sys.getsizeof needs to be changed to return a float, to allow it to
more properly reflect these important facts.

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


Re: Using system python vs. updated/current version

2013-07-31 Thread Terry Reedy

On 7/31/2013 4:19 PM, memilanuk wrote:


Are there any significant flaws with v.3.3.0 that would necessitate
upgrading to the most recent version (3.3.2?)


Go to the overview page http://docs.python.org/3/index.html
and click on  'What's new in Python 3.3' to get to
http://docs.python.org/3/whatsnew/3.3.html
Click the 'changelog' link at the end of the first sentence.
http://docs.python.org/3.3/whatsnew/changelog.html
Browse through the 3.3.1 and 3.3.2 sections for bug fixes.
Decide if any of the entries are relevant to you.

--
Terry Jan Reedy

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


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

2013-07-31 Thread Skip Montanaro
> Has anyone tried Pyspread?

I have not.

I have a fundamental problem with spreadsheets, the extremely narrow view
of the workspace. There was a piece on NPR the other day about some errors
in some modeling applications. I missed most of it (does someone have a
link? I'm on my phone right now), but the expert commentator was saying
that they are working on standard structures for these sorts of complex
modeling simulations. I think they will need more than that. Something like
pyspread might allow you to mix structured and object oriented programming
with the convenience if a spreadsheet.

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


Re: Using system python vs. updated/current version

2013-07-31 Thread alex23

On 1/08/2013 4:35 AM, memilanuk wrote:

Also... in some places in the 'Net I see references to installing
everything 'locally' via pip, etc. in virtualenvs and not touching the
system installed version of python... yet most linux distros seem to
have many/most such packages available in their package repos, which
seems like it'd be easier to install via the package manager and let it
keep things updated.  Could someone touch on what they feel the pros and
cons would be either way?


Generally, if your OS installs a version of Python by default you should 
leave it alone because the OS itself is dependent on it. Updating to 
newer versions of Python or installed libraries can introduce version 
conflict errors in system-level apps, which is a bad thing.


Similarly, using the system install & libraries ties you to those 
versions. This may not be an issue if you're just scripting a few helper 
tools for your system, but it's an unnecessary hinderance if you're 
developing independent applications.


Tools like virtualenv or zc.buildout provide a handy way of sandboxing 
the dependencies of individual applications. They let you build more 
than one app in parallel and not let the dependencies of one interfere 
with the others. Of equal importance is their use in deploying to other 
machines. With virtualenv, you can create a list of installed libraries 
with:


pip freeze > requirements.txt

To ensure a target machine has all of the dependencies your application 
needs you can then do:


pin install -r requirements.txt

So: for simple scripts, just go with the system install. For serious 
development work, I highly recommend using virtualenv or zc.buildout to 
contain each development environment.

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


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

2013-07-31 Thread Chris Angelico
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

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


Re: Using system python vs. updated/current version

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 7:35 PM, memilanuk  wrote:
> Also... in some places in the 'Net I see references to installing
> everything 'locally' via pip, etc. in virtualenvs and not touching the
> system installed version of python... yet most linux distros seem to
> have many/most such packages available in their package repos, which
> seems like it'd be easier to install via the package manager and let it
> keep things updated.  Could someone touch on what they feel the pros and
> cons would be either way?

I personally like to compile some things from source (CPython, Pike,
etc - though not everything, I use a prepackaged PostgreSQL, for
instance). There's no harm in installing a new CPython on a Linux box
- just type 'sudo make altinstall' (or however you become root), and
it'll give you a binary called python3.4 or whatever version, without
touching your system Python. That lets you run as many versions as you
like, in parallel, though you may have issues running 3.3.0 and 3.3.2
(but there should be no reason to do so - just use 3.3.2).

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


Re: Python script help

2013-07-31 Thread alex23

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.


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


Re: Lambda function Turing completeness

2013-07-31 Thread Steven D'Aprano
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)



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


Re: Problem with psycopg2, bytea, and memoryview

2013-07-31 Thread dieter
"Frank Millman"  writes:

> ...
> At present, I loop over a range of columns, comparing 'before' and 'after' 
> values, without worrying about their types. Strings are returned as str, 
> integers are returned as int, etc. Now I will have to check the type of each 
> column before deciding whether to cast to 'bytes'.

Of course, you could implement your own "equality" function ("my_equal")
and replace "a == b" by "my_equal(a, b)".

In "my_equal", you could encapsulate whatever logic is necessary
for a reliable equality check.

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


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

2013-07-31 Thread Steven D'Aprano
On Wed, 31 Jul 2013 10:45:36 +0700, Musical Notation wrote:

> Is there any script that converts indentation in Python code to curly
> braces? The indentation is sometime lost when I copy my code to an
> application or a website.

Complain to the website or application that it is throwing away 
significant data. If you had a website that turned this paragraph into 
this:

"Complaintothewebsiteorapplicationthatitisthrowingawaysignificantdata.Ifyouhadawebsitethatturnedthisparagraphintothis"

you would rightly complain about the bug, or stop using the website. 
Throwing away indentation is no different.


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


Re: Unexpected results comparing float to Fraction

2013-07-31 Thread Steven D'Aprano
On Wed, 31 Jul 2013 15:23:21 -0500, Tony the Tiger wrote:

> On Mon, 29 Jul 2013 15:43:24 +, Steven D'Aprano wrote:
> 
>> Am I the only one who is surprised by this?
> 
> Most likely.
> 
> Floats aren't precise enough to be equal to a (true) fraction.
> float(1/3) is cut short somewhere by the computer, a (true) fraction of
> one third is not, it goes on forever.

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.

but comparing a float to a Fraction does the conversion the other way, 
the float is up-cast to an exact Fraction, then compared.


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


Oddity with 'yield' as expression - parentheses demanded

2013-07-31 Thread Chris Angelico
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?

[1] 
http://docs.python.org/3.3/reference/expressions.html#grammar-token-yield_expression

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


Re: Unexpected results comparing float to Fraction

2013-07-31 Thread Chris Angelico
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?

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