pytest-2.6.2: fixes and freeze support

2014-09-05 Thread holger krekel
pytest-2.6.2: few fixes and cx_freeze support
===

pytest is a mature Python testing tool with more than a 1100 tests
against itself, passing on many different interpreters and platforms.
This release is drop-in compatible to 2.5.2 and 2.6.X.  It also
brings support for including pytest with cx_freeze or similar
freezing tools into your single-file app distribution.  For details
see the CHANGELOG below.

See docs at:

http://pytest.org

As usual, you can upgrade from pypi via::

pip install -U pytest

Thanks to all who contributed, among them:

Floris Bruynooghe
Benjamin Peterson
Bruno Oliveira

have fun,
holger krekel

2.6.2
---

- Added function pytest.freeze_includes(), which makes it easy to embed
  pytest into executables using tools like cx_freeze.
  See docs for examples and rationale. Thanks Bruno Oliveira.

- Improve assertion rewriting cache invalidation precision.

- fixed issue561: adapt autouse fixture example for python3.

- fixed issue453: assertion rewriting issue with __repr__ containing
  \n{, \n} and \n~.

- fix issue560: correctly display code if an else: or finally: is
  followed by statements on the same line.

- Fix example in monkeypatch documentation, thanks t-8ch.

- fix issue572: correct tmpdir doc example for python3.

- Do not mark as universal wheel because Python 2.6 is different from
  other builds due to the extra argparse dependency.  Fixes issue566.
  Thanks sontek.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Python Crypto Singature do not support Android???

2014-09-05 Thread Frank Liou
I use Privatekey sign a signature by android 

and then send to python 

python can't use public key to verify

and 

python signature result all is number

but 

android is number and english words

is that no support??
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Crypto Singature do not support Android???

2014-09-05 Thread Chris Angelico
On Fri, Sep 5, 2014 at 5:02 PM, Frank Liou fk2654159...@gmail.com wrote:
 I use Privatekey sign a signature by android

 and then send to python

 python can't use public key to verify

 and

 python signature result all is number

 but

 android is number and english words

 is that no support??

It would help if you showed us (a) the code, (b) the two different
results, and (c) what you're expecting to see.

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


Re: Python Crypto Singature do not support Android???

2014-09-05 Thread Frank Liou
Sorry!!

here is my code

python :

msg = '123'
msg = msg.encode('utf-8')
digest = SHA.new(msg).digest()
signature = APP_key_Private.sign(digest, '')

signature like: 
(331360957518977045630977695238805536647918381415993574748735382369846464411185614465200440681176208702632880466448650921484169461348176316490985530702996236304709994452069542950422484358331316454332743470132105629096577439312314814238554088472504815623363978006284897433036223490623530076474911740732410,)


and android :

InputStream inPrivate = getResources().getAssets().open(PR1.pem);
PrivateKey privateKey = RSAUtils.loadPrivateKey(inPrivate);
Log.d(privateKey--,privateKey.toString());

 byte[] a = Sign.digest(123.getBytes());
  String test_a_to64  = Base64.encodeToString(a,Base64.DEFAULT);
  Log.d(X--,test_a_to64);
  Log.d(sdfgserthwrthhsrethwegerg--,Arrays.toString(a));

String sdf = Sign.sign(a,privateKey);
 Log.d(0--,Arrays.toString(sdf.getBytes()));

Android like:


[34, 68, 28, 72, -43, 7, -64, -127, -119, -44, 61, -53, -22, 112, -74, -122, 
-19, -127, -120, -43, 1, -55, 66, -47, -63, -128, 104, -97, 104, 65, -48, -120, 
-50, 117, 85, 86, -33, 37, -77, -26, -46, -59, -43, -42, -79, -9, -78, -26, 
-25, 5, 4, -104, 95, -120, -73, 123, 70, -11, 56, -10, -99, -126, -30, -3, -63, 
42, 45, 33, 36, 23, -52, 10, -4, -17, 8, 82, -61, 74, 43, -5, 44, 29, 127, 78, 
100, -88, -24, -61, -24, 3, -105, 4, 117, 71, 41, 74, 99, 23, 68, 112, -8, 
-105, 67, -68, -115, -27, -24, 114, -108, 28, 15, -85, -77, 49, -110, -10, -83, 
-58, -27, 34, 90, -52, 71, -72, 73, -5, -2, -56]



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


Run an http server on Apache without wsgi?

2014-09-05 Thread Frank Millman
Hi all

My AccInABox project runs an http server. Previously I used the cherry.py 
wsgiserver, but I have now switched to asyncio.

I tried to use the wsgi interface, but I have a particular requirement and 
found that wsgi got in the way, so I dropped it and now handle all requests 
directly.

Now the question arises, what if someone wants to run my program under 
Apache or nginx? I have had some feedback from a sysadmin, whose main 
concern is how to deploy my program, which is something I have not given 
serious thought to.

If the answer is that I really should be using wsgi, I will explain my 
specific requirement in more detail, and see if anyone can suggest a 
workaround.

But at this stage, I would like to discuss whether it is possible to avoid 
using wsgi. Should I be looking at FastCGI, or is that now considered 
outdated?

I would appreciate any pointers or links to get me started.

Thanks

Frank Millman



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


Re: Python Crypto Singature do not support Android???

2014-09-05 Thread Chris Angelico
On Fri, Sep 5, 2014 at 5:23 PM, Frank Liou fk2654159...@gmail.com wrote:
 here is my code

 python :

 msg = '123'
 msg = msg.encode('utf-8')
 digest = SHA.new(msg).digest()
 signature = APP_key_Private.sign(digest, '')

That code is incomplete, I can't run it. Ditto your Java code. But
what seems to be happening is that you're getting data back in two
very different formats, plus you're generating one signature based on
a UTF-8 stream and one based on a Base-64 stream. Start by writing
*simple* code that does what you want, and then porting that to the
other language exactly.

Also, please don't use Google Groups, or if you must, please remember
to include context.

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


Re: How to turn a string into a list of integers?

2014-09-05 Thread cl
Joshua Landau jos...@landau.ws wrote:
 On 3 September 2014 15:48,  c...@isbd.net wrote:
  Peter Otten __pete...@web.de wrote:
   [ord(c) for c in This is a string]
  [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103]
 
  There are other ways, but you have to describe the use case and your Python
  version for us to recommend the most appropriate.
 
  That looks OK to me.  It's just for outputting a string to the block
  write command in python-smbus which expects an integer array.
 
 Just be careful about Unicode characters.

I have to avoid them completely because I'm sending the string to a
character LCD with a limited 8-bit only character set.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


reading file in for loop

2014-09-05 Thread loial
If I read a file using a for loop, as follows, is the file left open if I 
execute a break in the for loop?


for line in open(myFile).readlines():

if something:
break


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


Re: reading file in for loop

2014-09-05 Thread Chris Angelico
On Fri, Sep 5, 2014 at 8:20 PM, loial jldunn2...@gmail.com wrote:
 If I read a file using a for loop, as follows, is the file left open if I 
 execute a break in the for loop?


 for line in open(myFile).readlines():

 if something:
 break

It'll be closed when the object expires. With CPython, that's probably
going to happen fairly soon, but it's not guaranteed in any way. If
you want to be sure it's closed, use a 'with' statement - look it up
in the docs.

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


Re: reading file in for loop

2014-09-05 Thread Peter Otten
loial wrote:

 If I read a file using a for loop, as follows, is the file left open if I
 execute a break in the for loop?
 
 
 for line in open(myFile).readlines():
 
 if something:
 break

Whether the file is left open has nothing to do with how you leave the loop. 
The way you wrote it (readlines() reads all lines into a list and there is 
no reference to the file object left) CPython will close the file before you 
enter the loop:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type help, copyright, credits or license for more information.
 for line in open(tmp.txt).readlines():
... raw_input(you are here)
... break
... 
you are here
[1]+  Angehalten  python
$ lsof *

Other implementations take a bit more time:

$ jython
my variable $jythonHome masks earlier declaration in same scope at 
/usr/bin/jython line 15.
Jython 2.5.3 (, Nov 21 2013, 23:15:42) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_65
Type help, copyright, credits or license for more information.
 for line in open(tmp.txt): pass

... 
 
[2]+  Angehalten  jython
$ lsof *
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFFNODE NAME
java9396 x   34r   REG   8,23   17 5906455 tmp.txt
$ 


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


“Eric Python 3 ( 2) IDE” Tech.Doc: How useful?

2014-09-05 Thread Pietro Moras
So to schedule my next year's “free” (in all senses) activity, I'd appreciate 
your remarks about your perceived practical usefulness of the Tech. 
Documentation of Eric advanced Python IDE, as available at URL:  
http://eric-ide.python-projects.org/eric-documentation.html 
For private answers:  [Studio-PM at hotmail dot com]. Critical remarks 
welcome too. Thanks. - P.M.-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Raspberry pi, python and robotics

2014-09-05 Thread BartC



Gregory Ewing greg.ew...@canterbury.ac.nz wrote in message
news:c6nv2hf8q6...@mid.individual.net...

Rob Gaddi wrote:

otherwise getting up and
running will cost you a solid $1200 just in gear.


While having fancy gear certainly helps, it's not
*strictly* necessary. When I first started dabbling
in electronics, the most sophisticated piece of
equipment I had was an analog multimeter.

It got me through a lot of projects, including a
couple of homebrew computers. It's surprising how
much you can deduce about what's happening in a
digital circuit by watching a needle bouncing
around!


I also used LEDs (even showing complex signals, as they will dim in
different ways, or you could sometimes view them through a flipped mirror to
show the patterns).

Sometimes I fed a digital output to the video input of my TV (it was 5V to
1V, some care was needed), and the waveform became visible, although
unsynchronised to anything. With one line representing about 50us, you could
get a lot of clues about what was going on. (What I never tried with a TV,
because I later had a scope, was to arrange for the line-sync to trigger
some repeatable event I was trying to monitor. By using it as the /reset
signal of a microprocessor for example.)

Anyway, there were all sorts of tricks. I didn't have a proper knowledge of
(analogue) electronics either, just enough to get by, or picked up what I
needed as I went. (You tended to copy or adapt someone else's circuits.)

Besides, a normal non-storage oscilloscope wasn't directly useful for the
complex non-repeating signals you get with computer boards.

--
Bartc 


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


Re: I have tried and errored a reasonable amount of times

2014-09-05 Thread Grant Edwards
On 2014-09-05, Denis McMahon denismfmcma...@gmail.com wrote:
 On Thu, 04 Sep 2014 21:42:56 +1000, Chris Angelico wrote:
 On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon denismfmcma...@gmail.com 
 wrote:
 On Wed, 03 Sep 2014 07:16:34 +, Steven D'Aprano wrote:

 Who uses + for disjunction (∨ OR) and concatenation for conjunction
 (∧ AND)? That's crazy notation.

 The way I was taught it in the mid 1980s, a.b === a and b, a+b === a
 or b.
 
 The middle dot is another notation for multiplication, as is abuttal
 (not actually concatenation, in this context). So they're all saying
 the same thing: boolean 'and' is multiplication, boolean 'or' is
 addition.

 Yes Chris, I know that. I was responding to Stephen's statement that 
 using + for or was crazy notation, and pointing out that 30 years
 ago, that's what UK colleges were teaching!

AFAIK, that's the standard notation in both CS and EE university
classes in the US also: + for 'or' and dot or abuttal for 'and'.

Well, it was 30 years ago...

-- 
Grant Edwards   grant.b.edwardsYow! But was he mature
  at   enough last night at the
  gmail.comlesbian masquerade?
-- 
https://mail.python.org/mailman/listinfo/python-list


My backwards logic

2014-09-05 Thread Seymore4Head
I'm still doing practice problems.  I haven't heard from the library
on any of the books I have requested.

http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

This is not a hard problem, but it got me to thinking a little.  A
prime number will divide by one and itself.  When setting up this
loop, if I start at 2 instead of 1, that automatically excludes one of
the factors.  Then, by default, Python goes to the chosen count and
not through the count, so just the syntax causes Python to rule out
the other factor (the number itself).

So this works:
while True:
a=random.randrange(1,8)
print (a)
for x in range(2,a):
if a%x==0:
print (Number is not prime)
break
wait = input ( *40  + Wait)

But, what this instructions want printed is This is a prime number
So how to I use this code logic NOT print (not prime) and have the
logic print This number is prime

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


Re: I have tried and errored a reasonable amount of times

2014-09-05 Thread Marko Rauhamaa
Grant Edwards invalid@invalid.invalid:

 Who uses + for disjunction (∨ OR) and concatenation for
 conjunction (∧ AND)? That's crazy notation.

 AFAIK, that's the standard notation in both CS and EE university
 classes in the US also: + for 'or' and dot or abuttal for 'and'.

Besides, it's no crazier for Boolean algebra than real algebra. For some
reason, mathematicians use + for addition and concatenation for
multiplication...


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


Re: My backwards logic

2014-09-05 Thread MRAB

On 2014-09-05 17:48, Seymore4Head wrote:

I'm still doing practice problems.  I haven't heard from the library
on any of the books I have requested.

http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

This is not a hard problem, but it got me to thinking a little.  A
prime number will divide by one and itself.  When setting up this
loop, if I start at 2 instead of 1, that automatically excludes one of
the factors.  Then, by default, Python goes to the chosen count and
not through the count, so just the syntax causes Python to rule out
the other factor (the number itself).

So this works:
while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 wait = input ( *40  + Wait)

But, what this instructions want printed is This is a prime number
So how to I use this code logic NOT print (not prime) and have the
logic print This number is prime


Look for a factor. If you don't find one, it's a prime number.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Storing instances using jsonpickle

2014-09-05 Thread MRAB

On 2014-09-04 06:17, Chris Angelico wrote:

On Thu, Sep 4, 2014 at 9:39 AM, MRAB pyt...@mrabarnett.plus.com wrote:

I occasionally think about a superset of JSON, called, say, pyson ...
ah, name already taken! :-(


While I'm somewhat sympathetic to the concept, there are some parts of
your description that I disagree with. Am I misreading something? Are
there typos in the description and I'm making something out of
nothing?


It would add tuples, delimited by (...), which are not used otherwise (no
expressions):

() = ()
(0, ) = (0)


This seems odd. Part of JSON's convenience is that it's a subset of
JavaScript syntax, so you can just plop a block of JSON into a REPL
and it'll decode correctly. With PyON (or whatever you call it), it'd
be nice to have the same correspondence; for a start, I would strongly
encourage the trailing comma is permitted rule (so [1,2,3,] is
equivalent to [1,2,3]), and then I'd have the default encoding for a
single-element tuple include that trailing comma. If (0) is a
one-element tuple, you end up with a subtle difference between a PyON
decode and the Python interpreter, which is likely to cause problems.
It might even be worth actually mandating (not just encouraging) that
one-element tuples have the trailing comma, just to prevent that.


[snip]

JSON has 'true' and 'false'.

Python has 'True' and 'False'.

Therefore, if you want it to be able to drop it into Python's REPL, it
won't be compatible with JSON anyway! (Well, not unless you define
'true' and 'false' first.)

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


Re: My backwards logic

2014-09-05 Thread Bob Gailer
Bob gailer
On Sep 5, 2014 12:51 PM, Seymore4Head Seymore4Head@hotmail.invalid
wrote:

 I'm still doing practice problems.  I haven't heard from the library
 on any of the books I have requested.


http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

 This is not a hard problem, but it got me to thinking a little.  A
 prime number will divide by one and itself.  When setting up this
 loop, if I start at 2 instead of 1, that automatically excludes one of
 the factors.  Then, by default, Python goes to the chosen count and
 not through the count, so just the syntax causes Python to rule out
 the other factor (the number itself).

 So this works:
 while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
   else:
   print ...
 wait = input ( *40  + Wait)

 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the
 logic print This number is prime

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


Re: My backwards logic

2014-09-05 Thread Ethan Furman

On 09/05/2014 09:48 AM, Seymore4Head wrote:

I'm still doing practice problems.  I haven't heard from the library
on any of the books I have requested.

http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

This is not a hard problem, but it got me to thinking a little.  A
prime number will divide by one and itself.  When setting up this
loop, if I start at 2 instead of 1, that automatically excludes one of
the factors.  Then, by default, Python goes to the chosen count and
not through the count, so just the syntax causes Python to rule out
the other factor (the number itself).

So this works:
while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 wait = input ( *40  + Wait)

But, what this instructions want printed is This is a prime number
So how to I use this code logic NOT print (not prime) and have the
logic print This number is prime


Python's 'for' loop has a handy 'else' extension which is perfect for the 
search-type of 'for' loop:

   while True:
a=random.randrange(1,8)
print (a)
for x in range(2,a):
if a%x==0:
print (Number is not prime)
break
else:
print (Number is prime)
wait = input ( *40  + Wait)

Note the two lines I added after the 'break' and before the 'wait'.

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


Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 9:48 AM, Seymore4Head Seymore4Head@hotmail.invalid
wrote:

 I'm still doing practice problems.  I haven't heard from the library
 on any of the books I have requested.


 http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

 This is not a hard problem, but it got me to thinking a little.  A
 prime number will divide by one and itself.  When setting up this
 loop, if I start at 2 instead of 1, that automatically excludes one of
 the factors.  Then, by default, Python goes to the chosen count and
 not through the count, so just the syntax causes Python to rule out
 the other factor (the number itself).

 So this works:
 while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 wait = input ( *40  + Wait)

 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the
 logic print This number is prime


One neat feature of Python is the for...else function. The code inside the
else block will run only if the loop ran to completion (untested code
follows):

while True:
a=random.randrange(1,8)
print (a)
for x in range(2,a):
if a%x==0:
print (Number is not prime)
break
else:
print(Number is prime)
wait = input ( *40  + Wait)


Depending on how advanced you want to get (I know you are relatively new to
Python), another decent way would be to extract the prime check to a
function, and return the result, and print based on that result (again,
untested code):

def isPrime(number):
for x in range(2,a):
if a%x==0:
return False
return True

while True:
a=random.randrange(1,8)
print (a)
if isPrime(a):
print(Number is prime)
else:
print(Number is not prime)
wait = input ( *40  + Wait)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread John Gordon
In 1enj0att6bkrnvb81rhma5dbuk3h28a...@4ax.com Seymore4Head 
Seymore4Head@Hotmail.invalid writes:

 I'm still doing practice problems.  I haven't heard from the library
 on any of the books I have requested.

 http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

 This is not a hard problem, but it got me to thinking a little.  A
 prime number will divide by one and itself.  When setting up this
 loop, if I start at 2 instead of 1, that automatically excludes one of
 the factors.  Then, by default, Python goes to the chosen count and
 not through the count, so just the syntax causes Python to rule out
 the other factor (the number itself).

 So this works:
 while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 wait = input ( *40  + Wait)

 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the
 logic print This number is prime


There are two basic tactics you can use:

1. Initialize an isprime flag to True at the top of the while loop.  
   In the for loop, replace the print statement with a statement that
   sets isprime to False.  After the for loop, insert a check on isprime,
   and print This number is prime if isprime is still True.

2. Create a separate function just for testing if a number is prime, which
   returns True or False.  Then call that function within your while loop.

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

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


Re:My backwards logic

2014-09-05 Thread Dave Angel
Seymore4Head Seymore4Head@Hotmail.invalid Wrote in message:
 I'm still doing practice problems.  I haven't heard from the library
 on any of the books I have requested.
 
 http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html
 
 This is not a hard problem, but it got me to thinking a little.  A
 prime number will divide by one and itself.  When setting up this
 loop, if I start at 2 instead of 1, that automatically excludes one of
 the factors.  Then, by default, Python goes to the chosen count and
 not through the count, so just the syntax causes Python to rule out
 the other factor (the number itself).
 
 So this works:
 while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 wait = input ( *40  + Wait)
 
 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the
 logic print This number is prime
 
 

The traditional way of telling whether something happened in a
 loop is to set a flag to False outside the loop,  and
 conditionally set it to True in the if test. Then after the loop,
 check your flag.

Python however has a better way. You can put an else clause on the
 for loop:


 for x in range(2,a):
if a%x==0:
   print (Number is not prime)
   break
  else:
print (Number is prime)

The else clause fires if no break executed. 

There are also ways to do it using not, any, and a list
 comprehension, no explicit loop at all.

-- 
DaveA

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


Re: My backwards logic

2014-09-05 Thread Ian Kelly
On Fri, Sep 5, 2014 at 11:08 AM, Ethan Furman et...@stoneleaf.us wrote:
 Python's 'for' loop has a handy 'else' extension which is perfect for the
 search-type of 'for' loop:

while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 else:
 print (Number is prime)
 wait = input ( *40  + Wait)

 Note the two lines I added after the 'break' and before the 'wait'.

Also note that this construct tends to be particularly sensitive to
indentation. If you accidentally indent the else block one level too
many (which your editor may well do for you to helpfully match it up
with the if), then you'll get a completely different result.

I would not worry about the else clause as a beginner, as it's
relatively unique to Python and tends to be somewhat confusing. Use a
flag or refactor the function instead.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
MRAB pyt...@mrabarnett.plus.com:

 Therefore, if you want it to be able to drop it into Python's REPL, it
 won't be compatible with JSON anyway! (Well, not unless you define
 'true' and 'false' first.)

Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by
requiring the parser to heuristically support 5 encoding systems.

Thus, ast.literal_eval() is superior to anything JSON has to offer.


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


Re: Storing instances using jsonpickle

2014-09-05 Thread Ned Batchelder

On 9/5/14 1:16 PM, Marko Rauhamaa wrote:

MRAB pyt...@mrabarnett.plus.com:


Therefore, if you want it to be able to drop it into Python's REPL, it
won't be compatible with JSON anyway! (Well, not unless you define
'true' and 'false' first.)


Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by
requiring the parser to heuristically support 5 encoding systems.


I don't understand how JSON has flopped?  The parser may be a bit more 
complex (but not much, it isn't hard to examine the first few bytes), 
but you're using off-the-shelf parsers anyway, so why are you concerned 
by this?




Thus, ast.literal_eval() is superior to anything JSON has to offer.


Marko




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

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


Re: My backwards logic

2014-09-05 Thread Juan Christian
I made this code just for fun and learning, it's working, but would this be
a good approach? Thanks.

import sys


def prime_checker(start = 1, stop = 1):
for number in range(start, stop + 1):
divisors = [(number % x) for x in range(1, number + 1)]
print({n} prime? {r}.format(n = number, r = (divisors.count(0) == 2)))


if __name__ == '__main__':
prime_checker(int(sys.argv[1]), int(sys.argv[2]))


On Fri, Sep 5, 2014 at 2:17 PM, Ian Kelly ian.g.ke...@gmail.com wrote:

 On Fri, Sep 5, 2014 at 11:08 AM, Ethan Furman et...@stoneleaf.us wrote:
  Python's 'for' loop has a handy 'else' extension which is perfect for the
  search-type of 'for' loop:
 
 while True:
  a=random.randrange(1,8)
  print (a)
  for x in range(2,a):
  if a%x==0:
  print (Number is not prime)
  break
  else:
  print (Number is prime)
  wait = input ( *40  + Wait)
 
  Note the two lines I added after the 'break' and before the 'wait'.

 Also note that this construct tends to be particularly sensitive to
 indentation. If you accidentally indent the else block one level too
 many (which your editor may well do for you to helpfully match it up
 with the if), then you'll get a completely different result.

 I would not worry about the else clause as a beginner, as it's
 relatively unique to Python and tends to be somewhat confusing. Use a
 flag or refactor the function instead.
 --
 https://mail.python.org/mailman/listinfo/python-list

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


Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 05 Sep 2014 10:08:18 -0700, Ethan Furman et...@stoneleaf.us
wrote:

On 09/05/2014 09:48 AM, Seymore4Head wrote:
 I'm still doing practice problems.  I haven't heard from the library
 on any of the books I have requested.

 http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

 This is not a hard problem, but it got me to thinking a little.  A
 prime number will divide by one and itself.  When setting up this
 loop, if I start at 2 instead of 1, that automatically excludes one of
 the factors.  Then, by default, Python goes to the chosen count and
 not through the count, so just the syntax causes Python to rule out
 the other factor (the number itself).

 So this works:
 while True:
  a=random.randrange(1,8)
  print (a)
  for x in range(2,a):
  if a%x==0:
  print (Number is not prime)
  break
  wait = input ( *40  + Wait)

 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the
 logic print This number is prime

Python's 'for' loop has a handy 'else' extension which is perfect for the 
search-type of 'for' loop:

while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 else:
 print (Number is prime)
 wait = input ( *40  + Wait)

Note the two lines I added after the 'break' and before the 'wait'.

I had already tried this one.
The solution I want should only print:
This number is prime

Adding else causes the program to also print This number is not
prime

I also tried the flag=True suggestion, but never got one that worked.
I am unsure when to use flag=True and flag==True 
Then there is flag=True and flag==True

What I really wanted was something like:
if !(a%x==0)

BTW since I am getting no grade, I much prefer the answer than a hint.
The best hint IMO is to tell me how you would do it.

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


Re: How to turn a string into a list of integers?

2014-09-05 Thread Kurt Mueller
Am 05.09.2014 um 10:42 schrieb c...@isbd.net:

 Joshua Landau jos...@landau.ws wrote:
 On 3 September 2014 15:48,  c...@isbd.net wrote:
 Peter Otten __pete...@web.de wrote:
 [ord(c) for c in This is a string]
 [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103]
 
 There are other ways, but you have to describe the use case and your Python
 version for us to recommend the most appropriate.
 
 That looks OK to me.  It's just for outputting a string to the block
 write command in python-smbus which expects an integer array.
 
 Just be careful about Unicode characters.
 
 I have to avoid them completely because I'm sending the string to a
 character LCD with a limited 8-bit only character set.


Could someone please explain the following behavior to me:
Python 2.7.7, MacOS 10.9 Mavericks

 import sys
 sys.getdefaultencoding()
'ascii'
 [ord(c) for c in 'AÄ']
[65, 195, 132]
 [ord(c) for c in u'AÄ']
[65, 196]

My obviously wrong understanding:
‚AÄ‘ in ‚ascii‘ are two characters
 one with ord A=65 and
 one with ord Ä=196 ISO8859-1 depends on code table
 —- why [65, 195, 132]
u’AÄ’ is an Unicode string
 —- why [65, 196]

It is just the other way round as I would expect.



Thank you
-- 
Kurt Mueller, kurt.alfred.muel...@gmail.com

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


Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
Ned Batchelder n...@nedbatchelder.com:

 I don't understand how JSON has flopped? The parser may be a bit more
 complex (but not much, it isn't hard to examine the first few bytes),
 but you're using off-the-shelf parsers anyway, so why are you
 concerned by this?

There are occasions where you need to take shortcuts. Say you need to
glean information from JSON with bash, grep, awk or straight C. If JSON
was fixed to UTF-8, that would be quite feasible. Being as it is, you
are bound to 3rd-party libraries.

That alone invites ad-hoc encodings. For example, I have run into
asterisked JSON, libraries that limit themselves to UTF-8.

Compare that with HTTP, SMTP, or even XML(!). They fix the encoding to
the bit. No need for completely unnecessary options.


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


Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 10:44 AM, Seymore4Head Seymore4Head@hotmail.invalid
wrote:

 On Fri, 05 Sep 2014 10:08:18 -0700, Ethan Furman et...@stoneleaf.us
 wrote:

 On 09/05/2014 09:48 AM, Seymore4Head wrote:
  I'm still doing practice problems.  I haven't heard from the library
  on any of the books I have requested.
 
 
 http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html
 
  This is not a hard problem, but it got me to thinking a little.  A
  prime number will divide by one and itself.  When setting up this
  loop, if I start at 2 instead of 1, that automatically excludes one of
  the factors.  Then, by default, Python goes to the chosen count and
  not through the count, so just the syntax causes Python to rule out
  the other factor (the number itself).
 
  So this works:
  while True:
   a=random.randrange(1,8)
   print (a)
   for x in range(2,a):
   if a%x==0:
   print (Number is not prime)
   break
   wait = input ( *40  + Wait)
 
  But, what this instructions want printed is This is a prime number
  So how to I use this code logic NOT print (not prime) and have the
  logic print This number is prime
 
 Python's 'for' loop has a handy 'else' extension which is perfect for the
 search-type of 'for' loop:
 
 while True:
  a=random.randrange(1,8)
  print (a)
  for x in range(2,a):
  if a%x==0:
  print (Number is not prime)
  break
  else:
  print (Number is prime)
  wait = input ( *40  + Wait)
 
 Note the two lines I added after the 'break' and before the 'wait'.

 I had already tried this one.
 The solution I want should only print:
 This number is prime

 Adding else causes the program to also print This number is not
 prime


If you do not want it to print the Number is not prime, just remove the
print(Number is not prime) line.


 I also tried the flag=True suggestion, but never got one that worked.
 I am unsure when to use flag=True and flag==True
 Then there is flag=True and flag==True


Generally, you would want to use:

flag = False

 before the loop, and

flag = True

inside the loop (once you know the number is not prime). After the loop,
you would typically just use:

if flag: # This could be if flag == True:, however the plain if flag:
is more Pythonic.

print(Number is prime)


The = operator is assignment - storing a new value.
The == operator is for equality checking. The inverse is the !=
operator which checks for inequality.

What I really wanted was something like:
 if !(a%x==0)


In this case, that will not work, as you only know that the number is prime
after checking all the values, which means after the loop has completed.

Ignoring the fact that it would not function for this use case, the proper
Python syntax for that would be one of:

   - if a%x != 0: # Probably the clearest for this case.
   - if not (a%x==0):
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to turn a string into a list of integers?

2014-09-05 Thread Chris “Kwpolska” Warrick
On Sep 5, 2014 7:57 PM, Kurt Mueller kurt.alfred.muel...@gmail.com
wrote:
 Could someone please explain the following behavior to me:
 Python 2.7.7, MacOS 10.9 Mavericks

  import sys
  sys.getdefaultencoding()
 'ascii'
  [ord(c) for c in 'AÄ']
 [65, 195, 132]
  [ord(c) for c in u'AÄ']
 [65, 196]

 My obviously wrong understanding:
 ‚AÄ‘ in ‚ascii‘ are two characters
  one with ord A=65 and
  one with ord Ä=196 ISO8859-1 depends on code table
  —- why [65, 195, 132]
 u’AÄ’ is an Unicode string
  —- why [65, 196]

 It is just the other way round as I would expect.

Basically, the first string is just a bunch of bytes, as provided by your
terminal — which sounds like UTF-8 (perfectly logical in 2014).  The second
one is converted into a real Unicode representation. The codepoint for Ä is
U+00C4 (196 decimal). It's just a coincidence that it also matches latin1
aka ISO 8859-1 as Unicode starts with all 256 latin1 codepoints. Please
kindly forget encodings other than UTF-8.

BTW: ASCII covers only the first 128 bytes.

--
Chris “Kwpolska” Warrick http://chriswarrick.com/
Sent from my Galaxy S3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread Ethan Furman

On 09/05/2014 10:17 AM, Ian Kelly wrote:


I would not worry about the else clause as a beginner, as it's
relatively unique to Python and tends to be somewhat confusing. Use a
flag or refactor the function instead.


I don't disagree with this, but early exposure to for..else is for search loops is a good thing.  I still get tripped 
up by this as I didn't learn it that way.


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


Re: My backwards logic

2014-09-05 Thread MRAB

On 2014-09-05 18:35, Juan Christian wrote:

I made this code just for fun and learning, it's working, but would this
be a good approach? Thanks.

import sys


def prime_checker(start = 1, stop = 1):


In Python, the standard is to use a half-open range.


for number in range(start, stop + 1):
divisors = [(number % x) for x in range(1, number + 1)]
print({n} prime? {r}.format(n = number, r = (divisors.count(0) == 
2)))


You want to know only whether it's prime, so why continue looking after
finding a factor?


if __name__ == '__main__':
prime_checker(int(sys.argv[1]), int(sys.argv[2]))


[snip]

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


Re: Anyway to reduce size of pdf using python script.

2014-09-05 Thread kekeje
On Friday, February 1, 2013 8:03:41 PM UTC-5, access...@gmail.com wrote:
 I have a batch file that exports ArcGIS pdf maps to a directory. I would like 
 to include a step in the script where the pdf file is reduced in size instead 
 of manually opening each file in Acrobat X Pro after the script has run and 
 doing it there.
 
 
 
 Can this be done using python scripting or does the automation stop at 
 exporting the map?
 
 
 
 Thanks



Have you found the solution? I am having exactly the same problem and happen to 
see your post here. Please let me know how you did it, thanks! 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to turn a string into a list of integers?

2014-09-05 Thread Kurt Mueller

Am 05.09.2014 um 20:25 schrieb Chris “Kwpolska” Warrick kwpol...@gmail.com:
 On Sep 5, 2014 7:57 PM, Kurt Mueller kurt.alfred.muel...@gmail.com wrote:
  Could someone please explain the following behavior to me:
  Python 2.7.7, MacOS 10.9 Mavericks
 
   import sys
   sys.getdefaultencoding()
  'ascii'
   [ord(c) for c in 'AÄ']
  [65, 195, 132]
   [ord(c) for c in u'AÄ']
  [65, 196]
 
  My obviously wrong understanding:
  ‚AÄ‘ in ‚ascii‘ are two characters
   one with ord A=65 and
   one with ord Ä=196 ISO8859-1 depends on code table
   —- why [65, 195, 132]
  u’AÄ’ is an Unicode string
   —- why [65, 196]
 
  It is just the other way round as I would expect.
 
 Basically, the first string is just a bunch of bytes, as provided by your 
 terminal — which sounds like UTF-8 (perfectly logical in 2014).  The second 
 one is converted into a real Unicode representation. The codepoint for Ä is 
 U+00C4 (196 decimal). It's just a coincidence that it also matches latin1 aka 
 ISO 8859-1 as Unicode starts with all 256 latin1 codepoints. Please kindly 
 forget encodings other than UTF-8.

So:
‘AÄ’ is an UTF-8 string represented by 3 bytes:
A - 41   - 65  first byte decimal
Ä - c384 - 195 and 132 second and third byte decimal

u’AÄ’ is an Unicode string represented by 2 bytes?:
A - U+0041 - 65 first byte decimal, 00 is omitted or not yielded by ord()?
Ä - U+00C4 - 196 second byte decimal, 00 is ommited or not yielded by ord()?


 BTW: ASCII covers only the first 128 bytes.

ACK
-- 
Kurt Mueller, kurt.alfred.muel...@gmail.com

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


Re: Anyway to reduce size of pdf using python script.

2014-09-05 Thread Tim
On Friday, February 1, 2013 8:03:41 PM UTC-5, access...@gmail.com wrote:
 I have a batch file that exports ArcGIS pdf maps to a directory. I would like 
 to include a step in the script where the pdf file is reduced in size instead 
 of manually opening each file in Acrobat X Pro after the script has run and 
 doing it there.
 
 Can this be done using python scripting or does the automation stop at 
 exporting the map?
 
 Thanks

I don't have a definitive answer but I use qpdf to optimize my pdf files. 
Whether that reduces the size I'm not sure. http://qpdf.sourceforge.net/

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


Re: My backwards logic

2014-09-05 Thread Juan Christian
What's [snip] ??


On Fri, Sep 5, 2014 at 3:48 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 On 2014-09-05 18:35, Juan Christian wrote:

 I made this code just for fun and learning, it's working, but would this
 be a good approach? Thanks.

 import sys


 def prime_checker(start = 1, stop = 1):


 In Python, the standard is to use a half-open range.

  for number in range(start, stop + 1):
 divisors = [(number % x) for x in range(1, number + 1)]
 print({n} prime? {r}.format(n = number, r =
 (divisors.count(0) == 2)))

  You want to know only whether it's prime, so why continue looking after
 finding a factor?


 if __name__ == '__main__':
 prime_checker(int(sys.argv[1]), int(sys.argv[2]))

  [snip]

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

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


Re: My backwards logic

2014-09-05 Thread Mark Lawrence

On 05/09/2014 20:34, Juan Christian wrote:

What's [snip] ??



As in cut out or chopped out such that some of the original text has 
been removed.  And please don't top post here, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: My backwards logic

2014-09-05 Thread Paul Rubin
Juan Christian juan0christ...@gmail.com writes:
  I made this code just for fun and learning, it's working, but would
  this be a good approach? Thanks. ...
  ** ** for number in range(start, stop + 1):
  ** ** ** ** divisors = [(number % x) for x in range(1, number + 1)]
  ** ** ** ** ** ** print({n} prime? {r}.format(n = number, r =
  (divisors.count(0) == 2)))

1. Mathematically it's better to stop checking once you've gone past
the square root of the number, since if n = p*q and is composite,
then at least one of p,q will be = sqrt(n).

2. As a program design matter, it's generally preferable for functions
like this to not print the answer.  They should just return a value, in
this case a bool indicating whether the number is prime.  That makes it
easier to re-use the function, to wrap it in a unit test framework, etc.
If you want to print the result, then call the function and have the
caller print the returned value.

3. As a simple optimization, once you have checked that the number is
not divisible by 2, you don't have to check for other even divisors.
So just check for 2, then the odd numbers 3,5,7...

This is a little bit fancy but I like to use itertools for these
sorts of problems:

  from itertools import chain, takewhile, count

  def is_prime(n):
  if n  2: return False
  candidates = chain([2], count(3,2))
  return all(n%d!=0 for d in takewhile(lambda d: d*d=n, candidates))

If you're not familiar with those functions, chain concatenates
two sequences, and count(n,i) gives an increasing sequence starting
with n and incrementing by i.  So chain([2], count(3,2)) gives
the unending sequence [2, 3, 5, 7, 9, ...] which is the numbers
you want to check against.  Then the takewhile expression chops
that sequence once it gets past sqrt(n), and all returns true iff
all of the candidate divisors fail to divide the number.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to turn a string into a list of integers?

2014-09-05 Thread Kurt Mueller
Am 05.09.2014 um 21:16 schrieb Kurt Mueller kurt.alfred.muel...@gmail.com:
 Am 05.09.2014 um 20:25 schrieb Chris “Kwpolska” Warrick kwpol...@gmail.com:
 On Sep 5, 2014 7:57 PM, Kurt Mueller kurt.alfred.muel...@gmail.com wrote:
 Could someone please explain the following behavior to me:
 Python 2.7.7, MacOS 10.9 Mavericks
 
 import sys
 sys.getdefaultencoding()
 'ascii'
 [ord(c) for c in 'AÄ']
 [65, 195, 132]
 [ord(c) for c in u'AÄ']
 [65, 196]
 
 My obviously wrong understanding:
 ‚AÄ‘ in ‚ascii‘ are two characters
 one with ord A=65 and
 one with ord Ä=196 ISO8859-1 depends on code table
 —- why [65, 195, 132]
 u’AÄ’ is an Unicode string
 —- why [65, 196]
 
 It is just the other way round as I would expect.
 
 Basically, the first string is just a bunch of bytes, as provided by your 
 terminal — which sounds like UTF-8 (perfectly logical in 2014).  The second 
 one is converted into a real Unicode representation. The codepoint for Ä is 
 U+00C4 (196 decimal). It's just a coincidence that it also matches latin1 
 aka ISO 8859-1 as Unicode starts with all 256 latin1 codepoints. Please 
 kindly forget encodings other than UTF-8.
 
 So:
 ‘AÄ’ is an UTF-8 string represented by 3 bytes:
 A - 41   - 65  first byte decimal
 Ä - c384 - 195 and 132 second and third byte decimal
 
 u’AÄ’ is an Unicode string represented by 2 bytes?:
 A - U+0041 - 65 first byte decimal, 00 is omitted or not yielded by ord()?
 Ä - U+00C4 - 196 second byte decimal, 00 is ommited or not yielded by ord()?

After reading the ord() manual:
The second case should read:
u’AÄ’ is an Unicode string represented by 2 unicode characters:
If Python was built with UCS2 Unicode, then the character’s code point must
be in the range [0..65535, 16 bits, U-..U-]
A - U+0041 -  65 first  character decimal (code point)
Ä - U+00C4 - 196 second character decimal (code point)


Am I right now?

-- 
Kurt Mueller, kurt.alfred.muel...@gmail.com

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


Re: Storing instances using jsonpickle

2014-09-05 Thread Ned Batchelder

On 9/5/14 2:04 PM, Marko Rauhamaa wrote:

Ned Batchelder n...@nedbatchelder.com:


I don't understand how JSON has flopped? The parser may be a bit more
complex (but not much, it isn't hard to examine the first few bytes),
but you're using off-the-shelf parsers anyway, so why are you
concerned by this?


There are occasions where you need to take shortcuts. Say you need to
glean information from JSON with bash, grep, awk or straight C. If JSON
was fixed to UTF-8, that would be quite feasible. Being as it is, you
are bound to 3rd-party libraries.

That alone invites ad-hoc encodings. For example, I have run into
asterisked JSON, libraries that limit themselves to UTF-8.

Compare that with HTTP, SMTP, or even XML(!). They fix the encoding to
the bit. No need for completely unnecessary options.


I see what you mean about JSON, but you are mistaken about HTTP and XML. 
Neither of them dictates the encoding of the data, and both of them 
offer ways to declare the encoding.  This means XML parsers must be 
prepared for many different encodings.





Marko




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

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


Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
Ned Batchelder n...@nedbatchelder.com:

 I see what you mean about JSON, but you are mistaken about HTTP and
 XML. Neither of them dictates the encoding of the data, and both of
 them offer ways to declare the encoding. This means XML parsers must
 be prepared for many different encodings.

You can rest assured that the line

   GET / HTTP/1.1CRLF

is strictly 8-bit ASCII.

I was intentionally exaggerating about XML, but I have yet to encounter
non-UTF-8 XML in the wild.


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


Re: My backwards logic

2014-09-05 Thread Ian Kelly
On Fri, Sep 5, 2014 at 11:44 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 BTW since I am getting no grade, I much prefer the answer than a hint.
 The best hint IMO is to tell me how you would do it.

from math import ceil, sqrt

def is_prime(n):
if n  2:
return False
if n % 2 == 0:
return n == 2
return all(n % x != 0 for x in range(3, int(sqrt(n)) + 1, 2))

while True:
n = int(input(Enter a number: ))
if is_prime(n):
print({} is prime..format(n))
else:
print({} is not prime..format(n))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

I'm still doing practice problems.  I haven't heard from the library
on any of the books I have requested.

http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html

This is not a hard problem, but it got me to thinking a little.  A
prime number will divide by one and itself.  When setting up this
loop, if I start at 2 instead of 1, that automatically excludes one of
the factors.  Then, by default, Python goes to the chosen count and
not through the count, so just the syntax causes Python to rule out
the other factor (the number itself).

So this works:
while True:
a=random.randrange(1,8)
print (a)
for x in range(2,a):
if a%x==0:
print (Number is not prime)
break
wait = input ( *40  + Wait)

But, what this instructions want printed is This is a prime number
So how to I use this code logic NOT print (not prime) and have the
logic print This number is prime

I am sure this has already been done, but after it was pointed out
that you don't need to test for any number that multiplies by 2 it
made me think again.

If you start with the list [3,5,7] and step through the list of all
remaining odd numbers (step 2), and start appending numbers that won't
divide by numbers already appended in the list, that would seem like a
pretty efficient way to find all prime numbers.

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


Re: O'Reilly Python Certification

2014-09-05 Thread julian
On Wednesday, September 3, 2014 5:53:12 PM UTC-4, jaron...@gmail.com wrote:
 Ethan, Steve, Tim, and others:
 
 
 
 I'm thinking of taking the program. How long, in hours, does it take to 
 complete all four Python courses?

I'm currently taking the first out of four modules. I have extensive PHP 
knowledge and I also have a certification by Zend so programming is not new to 
me. I've never done anything at all with Python.

I've already completed 12 out of the 16 lessons and so far the reading has 
taken me from 15 to 30 minutes and the code assignments no more than 10. There 
was one exception that took me 30 minutes as I wasn't sure what the hell they 
were asking (it was a very obscure and useless algorithm which hasn't been the 
case on any of the other assignments). On top of that you have to answer 2 
quizzes and each quiz usually has 2 questions (no more than 5). Those usually 
take 1 to 3 minutes max as they are mostly syntax or concepts but not coding. 

As I said, this is only true for the first module as I haven't taken the others 
yet. But if you already know programming and have a few years of coding 
experience you will breeze through the first module in probably 3 days 
(assuming you only do that). The syllabus for the other modules suggests (to 
me) that going so fast would not be that easy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 2:49 PM, Seymore4Head Seymore4Head@hotmail.invalid
wrote:

 On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:

 I'm still doing practice problems.  I haven't heard from the library
 on any of the books I have requested.
 
 
 http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html
 
 This is not a hard problem, but it got me to thinking a little.  A
 prime number will divide by one and itself.  When setting up this
 loop, if I start at 2 instead of 1, that automatically excludes one of
 the factors.  Then, by default, Python goes to the chosen count and
 not through the count, so just the syntax causes Python to rule out
 the other factor (the number itself).
 
 So this works:
 while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 wait = input ( *40  + Wait)
 
 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the
 logic print This number is prime

 I am sure this has already been done, but after it was pointed out
 that you don't need to test for any number that multiplies by 2 it
 made me think again.

 If you start with the list [3,5,7] and step through the list of all
 remaining odd numbers (step 2), and start appending numbers that won't
 divide by numbers already appended in the list, that would seem like a
 pretty efficient way to find all prime numbers.


To be correct, you only need to check for n being divisible by primes less
than sqrt(n). For example, the following code will produce a list of primes
from 2 to 1000 (the result will be in the primes list):

import math
primes = [2]
for i in range(3, 1000):
end = math.sqrt(i)
for x in primes:
if x  end: # Once x is larger than the sqrt(i), we know it must be
prime, so we can early exit.
#print(i, is a prime number)
primes.append(i)
break
if (i % x) == 0:
#print(i, is a composite number)
break
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Storing instances using jsonpickle

2014-09-05 Thread Irmen de Jong
On 5-9-2014 19:16, Marko Rauhamaa wrote:

 Thus, ast.literal_eval() is superior to anything JSON has to offer.

Incidentally,

I've made a serialization library based on Python's literal expressions.
It uses ast.literal_eval() to deserialize, and a bit of custom code to 
serialize Python
objects:   https://pypi.python.org/pypi/serpent


Irmen

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


Re: My backwards logic

2014-09-05 Thread Ian Kelly
On Fri, Sep 5, 2014 at 3:49 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I am sure this has already been done, but after it was pointed out
 that you don't need to test for any number that multiplies by 2 it
 made me think again.

 If you start with the list [3,5,7] and step through the list of all
 remaining odd numbers (step 2), and start appending numbers that won't
 divide by numbers already appended in the list, that would seem like a
 pretty efficient way to find all prime numbers.

Indeed, this type of algorithm is known as a sieve. For a (literally)
classical example, see
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

It's a nice way to find all the prime numbers up to a given limit, or
it can be modified to run indefinitely high, but it's not very
efficient for determining the primality of a single number.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 5 Sep 2014 15:14:41 -0700, Chris Kaynor
ckay...@zindagigames.com wrote:

On Fri, Sep 5, 2014 at 2:49 PM, Seymore4Head Seymore4Head@hotmail.invalid
wrote:

 On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:

 I'm still doing practice problems.  I haven't heard from the library
 on any of the books I have requested.
 
 
 http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html
 
 This is not a hard problem, but it got me to thinking a little.  A
 prime number will divide by one and itself.  When setting up this
 loop, if I start at 2 instead of 1, that automatically excludes one of
 the factors.  Then, by default, Python goes to the chosen count and
 not through the count, so just the syntax causes Python to rule out
 the other factor (the number itself).
 
 So this works:
 while True:
 a=random.randrange(1,8)
 print (a)
 for x in range(2,a):
 if a%x==0:
 print (Number is not prime)
 break
 wait = input ( *40  + Wait)
 
 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the
 logic print This number is prime

 I am sure this has already been done, but after it was pointed out
 that you don't need to test for any number that multiplies by 2 it
 made me think again.

 If you start with the list [3,5,7] and step through the list of all
 remaining odd numbers (step 2), and start appending numbers that won't
 divide by numbers already appended in the list, that would seem like a
 pretty efficient way to find all prime numbers.


To be correct, you only need to check for n being divisible by primes less
than sqrt(n). For example, the following code will produce a list of primes
from 2 to 1000 (the result will be in the primes list):

import math
primes = [2]
for i in range(3, 1000):
end = math.sqrt(i)
for x in primes:
if x  end: # Once x is larger than the sqrt(i), we know it must be
prime, so we can early exit.
#print(i, is a prime number)
primes.append(i)
break
if (i % x) == 0:
#print(i, is a composite number)
break

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


Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 5 Sep 2014 16:35:18 -0600, Ian Kelly ian.g.ke...@gmail.com
wrote:

On Fri, Sep 5, 2014 at 3:49 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I am sure this has already been done, but after it was pointed out
 that you don't need to test for any number that multiplies by 2 it
 made me think again.

 If you start with the list [3,5,7] and step through the list of all
 remaining odd numbers (step 2), and start appending numbers that won't
 divide by numbers already appended in the list, that would seem like a
 pretty efficient way to find all prime numbers.

Indeed, this type of algorithm is known as a sieve. For a (literally)
classical example, see
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

It's a nice way to find all the prime numbers up to a given limit, or
it can be modified to run indefinitely high, but it's not very
efficient for determining the primality of a single number.

That is a pretty nice example.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread Chris Angelico
On Sat, Sep 6, 2014 at 3:44 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 BTW since I am getting no grade, I much prefer the answer than a hint.
 The best hint IMO is to tell me how you would do it.

But for your own learning, it's still better for you to do things
yourself. Giving you the answer doesn't teach you nearly as
effectively as giving you a hint and having you work out the answer
yourself.

But telling you how we'd do it can be useful too, especially when we
get down to the detaily bits where there are lots of ways to do
things. For instance, there's been a suggestion made a few times to
break the primality test out into a function... but compare these two:

def isprime(n):
   Return True iff n is prime

def find_factor(n):
Return a factor of n, or None if n is prime

Aside from inverting the truth value, these are both tests of
primality - you can write if isprime(n): or if find_factor(n): and
they'll both work. (The latter is actually iscomposite.) But the
second function is giving you a bit more information - it tells you
what factor it found.

As a general rule, try to avoid throwing information away. To prove
that n is composite, your function found a factor. Returning that,
rather than a boolean value, might make your function more useful; and
it's zero cost, because you know that factors of a number will never
be zero.

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


Re: Storing instances using jsonpickle

2014-09-05 Thread Chris Angelico
On Sat, Sep 6, 2014 at 3:04 AM, MRAB pyt...@mrabarnett.plus.com wrote:
 JSON has 'true' and 'false'.

 Python has 'True' and 'False'.

 Therefore, if you want it to be able to drop it into Python's REPL, it
 won't be compatible with JSON anyway! (Well, not unless you define
 'true' and 'false' first.)

This is a new spec, so I guess the question is whether it's primarily
JSON with some more features or subset of Python syntax in the same
way that JSON is a subset of JS. If it's the former, then yes, it'd
use true and false, and you'd have to define them; but if the
latter, the spec would simply use True and False. But being able
to guarantee that JSON decodes correctly with this parser (ie make it
a guaranteed superset of JSON) would be of value.

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


Re: My backwards logic

2014-09-05 Thread Rustom Mody
On Saturday, September 6, 2014 1:37:57 AM UTC+5:30, Paul Rubin wrote:
 Juan Christian  writes:
   I made this code just for fun and learning, it's working, but would
   this be a good approach? Thanks. ...
   ** ** for number in range(start, stop + 1):
   ** ** ** ** divisors = [(number % x) for x in range(1, number + 1)]
   ** ** ** ** ** ** print({n} prime? {r}.format(n = number, r =
   (divisors.count(0) == 2)))

 1. Mathematically it's better to stop checking once you've gone past
 the square root of the number, since if n = p*q and is composite,
 then at least one of p,q will be = sqrt(n).

 2. As a program design matter, it's generally preferable for functions
 like this to not print the answer.  They should just return a value, in
 this case a bool indicating whether the number is prime.  That makes it
 easier to re-use the function, to wrap it in a unit test framework, etc.
 If you want to print the result, then call the function and have the
 caller print the returned value.

Hoo boy! And we come full circle

 3. As a simple optimization, once you have checked that the number is
 not divisible by 2, you don't have to check for other even divisors.
 So just check for 2, then the odd numbers 3,5,7...

 This is a little bit fancy but I like to use itertools for these
 sorts of problems:

   from itertools import chain, takewhile, count

   def is_prime(n):
   if n  2: return False
   candidates = chain([2], count(3,2))
   return all(n%d!=0 for d in takewhile(lambda d: d*d=n, candidates))

Paul's suggestions without the fancy -- no sqrt stop, no generators, no 
itertools
etc -- (all to be learnt at their time of course!)


First of all I make for myself a closed range

 def crange(a,b) : return range(a,b+1)

Check it

 crange(1,10)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Now for divisors of a number

 def divisors(n): return [fact for fact in crange(1,n) if n%fact == 0]

Check it

 divisors(4)
[1,2,4]

 divisors(7)
[1, 7]

So now a prime is a number n whose divisors are only 1 and n

 def is_prime(n): return divisors(n) == [1,n]

 is_prime(2)
True
 is_prime(3)
True
 is_prime(4)
False
 is_prime(5)
True
 is_prime(6)
False
 is_prime(7)
True

So collecting the code together

 def crange(a,b): return range(a,b+1)
 def divisors(n): return [fact for fact in crange(1,n) if n%fact == 0]
 def is_prime(n): return divisors(n) == [1,n]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread Juan Christian
@Mark Lawrence: Sorry to ask, but what do you mean by don't top post here,
thanks., I'm not familiar with mailing lists, so I may be doing something
wrong and I don't know.


On Fri, Sep 5, 2014 at 4:54 PM, Mark Lawrence breamore...@yahoo.co.uk
wrote:

 On 05/09/2014 20:34, Juan Christian wrote:

 What's [snip] ??


 As in cut out or chopped out such that some of the original text has been
 removed.  And please don't top post here, thanks.

 --
 My fellow Pythonistas, ask not what our language can do for you, ask
 what you can do for our language.

 Mark Lawrence

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

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


Re: My backwards logic

2014-09-05 Thread Rustom Mody
On Saturday, September 6, 2014 7:25:10 AM UTC+5:30, Juan Christian wrote:
 @Mark Lawrence: Sorry to ask, but what do you mean by don't top post here, 
 thanks., I'm not familiar with mailing lists, so I may be doing something 
 wrong and I don't know.


Maybe better to say use this
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

rather than to say dont use

http://en.wikipedia.org/wiki/Posting_style#Top-posting

Also read
https://wiki.python.org/moin/GoogleGroupsPython
-- 
https://mail.python.org/mailman/listinfo/python-list


Posting style: interleaved responses (was: My backwards logic)

2014-09-05 Thread Ben Finney
Juan Christian juan0christ...@gmail.com writes:

 @Mark Lawrence: Sorry to ask, but what do you mean by don't top post
 here, thanks., I'm not familiar with mailing lists, so I may be doing
 something wrong and I don't know.

Please post your responses interleaved with the quoted material to
which you're responding. See the article on “interleaved style”
URL:https://en.wikipedia.org/wiki/Posting_style#Interleaved_style. And
trim any quoted material to which you're not responding, so your message
only contains relevant material.

-- 
 \“Human reason is snatching everything to itself, leaving |
  `\   nothing for faith.” —Bernard of Clairvaux, 1090–1153 CE |
_o__)  |
Ben Finney

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


Re: Posting style: interleaved responses (was: My backwards logic)

2014-09-05 Thread Juan Christian
On Fri, Sep 5, 2014 at 11:37 PM, Ben Finney ben+pyt...@benfinney.id.au
wrote:

 Juan Christian juan0christ...@gmail.com writes:

  @Mark Lawrence: Sorry to ask, but what do you mean by don't top post
  here, thanks., I'm not familiar with mailing lists, so I may be doing
  something wrong and I don't know.

 Please post your responses interleaved with the quoted material to
 which you're responding. See the article on “interleaved style”
 URL:https://en.wikipedia.org/wiki/Posting_style#Interleaved_style. And
 trim any quoted material to which you're not responding, so your message
 only contains relevant material.

 --
  \“Human reason is snatching everything to itself, leaving |
   `\   nothing for faith.” —Bernard of Clairvaux, 1090–1153 CE |
 _o__)  |
 Ben Finney

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


Like that? I'm using gmail so it automatically put the text in the [...]
icon.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-05 Thread Dave Angel
Seymore4Head Seymore4Head@Hotmail.invalid Wrote in message:
 On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:
 

 
 If you start with the list [3,5,7] and step through the list of all
 remaining odd numbers (step 2), and start appending numbers that won't
 divide by numbers already appended in the list, that would seem like a
 pretty efficient way to find all prime numbers.
 
 

Yes, that's a well known optimization.  In addition,  you can stop
 once you reach the square root of the target.  No point in
 dividing by the higher numbers in the list,  since if the result
 comes out even, you'd have already exited the loop.


-- 
DaveA

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


Re: Posting style: interleaved responses (was: My backwards logic)

2014-09-05 Thread Zachary Ware
On Fri, Sep 5, 2014 at 10:06 PM, Juan Christian
juan0christ...@gmail.com wrote:
 On Fri, Sep 5, 2014 at 11:37 PM, Ben Finney ben+pyt...@benfinney.id.au
 wrote:

 Juan Christian juan0christ...@gmail.com writes:

  @Mark Lawrence: Sorry to ask, but what do you mean by don't top post
  here, thanks., I'm not familiar with mailing lists, so I may be doing
  something wrong and I don't know.

 Please post your responses interleaved with the quoted material to
 which you're responding. See the article on “interleaved style”
 URL:https://en.wikipedia.org/wiki/Posting_style#Interleaved_style. And
 trim any quoted material to which you're not responding, so your message
 only contains relevant material.

 --
  \“Human reason is snatching everything to itself, leaving |
   `\   nothing for faith.” —Bernard of Clairvaux, 1090–1153 CE |
 _o__)  |
 Ben Finney

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


 Like that?

Almost.  I left your entire message intact up to this point so you can
see what you sent, though you may need to click the [...] to expand it
[1].  (Normally, I would edit out everything but the actual message
I'm replying to (Like that?) and some context from Ben's message.)

 I'm using gmail so it automatically put the text in the [...]
 icon.

Gmail (which I also use) requires a little bit of extra effort to
abide by proper mailing list etiquette; in particular, you should
always expand the [...]-hidden text and edit out what you don't need
to send such as signatures and footers from the message you're
replying to.  Then add your replies immediately after the text you're
actually responding to, like I've done with this paragraph and my
previous one.  It's also best to choose plain text mode from the
little menu at lower-right (choose that before you actually edit the
message at all, though, or set it as the default.  Changing it
mid-message causes havoc with the formatting).

It's at least a step up from a certain other Google interface to this
list, and I think I speak for everyone in saying thank you for being
willing to learn proper etiquette :)

-- 
Zach

[1] Or look here:
https://mail.python.org/pipermail/python-list/2014-September/678058.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to turn a string into a list of integers?

2014-09-05 Thread Steven D'Aprano
Chris Angelico wrote:

 On Fri, Sep 5, 2014 at 12:09 PM, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Thu, Sep 4, 2014 at 6:12 PM, Chris Angelico ros...@gmail.com wrote:
 If it's a Unicode string (which is the default in Python 3), all
 Unicode characters will work correctly.

 Assuming the library that needs this is expecting codepoints and will
 accept integers greater than 255.
 
 They're still valid integers. It's just that someone might not know
 how to work with them. Everyone has limits - I don't think repr()
 would like to be fed Graham's Number, for instance, but we still say
 that it accepts integers :)

If you can fit Graham's Number into memory, repr() will happily deal with
it. Although, it might take a while to print out...

[...]
 I just don't like people talking about Unicode characters being
 somehow different from normal text or something, and being something
 that you need to be careful of. It's not that there are some
 characters that behave nicely, and then other ones (Unicode ones)
 that don't.

Behave nicely depends on what behaviour you're expecting.

There is a sense in which Unicode is different from ASCII text. ASCII is a 7
bit character set. In principle, you could have different implementations
of ASCII but in practice it's been so long since any machine you're likely
to come across uses anything but exactly a single 8-bit byte for each ASCII
character that we might as well say that ASCII has a single implementation:

* 1 byte code units, fixed width characters 

That is, every character takes exactly one 8-bit byte.

(Reminder: byte does not necessarily mean 8 bits.)

Unicode, on the other hand, has *at least* nine different implementations
which you are *likely* to come across:

* UTF-8 has 1-byte code units, variable width characters: every character
takes between 1 and 4 bytes;

* UTF-8 with a so-called Byte Order Mark at the beginning of the file;

* UTF-16-BE has 2-byte code units, variable width characters: every
character takes either 2 or 4 bytes;

* UTF-16-LE is the same, but the bytes are in opposite order;

* UTF-16 with a Byte Order Mark at the beginning of the file;

* UTF-32-BE has 4-byte code units, fixed width characters; every character
takes exactly 4 bytes;

* UTF-32-LE is the same, but the bytes are in opposite order;

* UTF-32 with a Byte Order Mark at the beginning of the file;

* UCS-2 is a subset of Unicode with 2-byte code units, fixed width
characters; every character takes exactly 2 bytes (UCS-2 is effectively
UTF-16-BE for characters in the Basic Multilingual Plane).

Plus various more obscure or exotic encodings.

So, while it is not *strictly* correct to say that ASCII character 'A' is
always the eight bits 0101, the exceptions are so rare that there might
as well not be any. But the Unicode character 'A' could be:

0101
0101 
 0101
0101   
   0101


and possibly more.


-- 
Steven

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


Re: How to turn a string into a list of integers?

2014-09-05 Thread Steven D'Aprano
Kurt Mueller wrote:

 Could someone please explain the following behavior to me:
 Python 2.7.7, MacOS 10.9 Mavericks
 
 import sys
 sys.getdefaultencoding()
 'ascii'

That's technically known as a lie, since if it were *really* ASCII it
would refuse to deal with characters with the high-bit set. But it doesn't,
it treats them in an unpredictable and implementation-dependent manner.

 [ord(c) for c in 'AÄ']
 [65, 195, 132]

In this case, it looks like your terminal is using UTF-8, so the character Ä
is represented in memory by bytes 195, 132:

py u'Ä'.encode('utf-8')
'\xc3\x84'
py for c in u'Ä'.encode('utf-8'):
... print ord(c)
...
195
132

If your terminal was set to use a different encoding, you probably would
have got different results. When you type whatever key combination you used
to get Ä, your terminal receives the bytes 195, 132, and displays Ä. But
when Python processes those bytes, it's not expecting arbitrary Unicode
characters, it's expecting ASCII-ish bytes, and so treats it as two bytes
rather than a single character:

py 'AÄ'
'A\xc3\x84'

That's not *really* ASCII, because ASCII doesn't include anything above 127,
but we can pretend that ASCII plus arbitrary bytes between 128 and 256 is
just called ASCII. The important thing here is that although your terminal
is interpreting those two bytes \xc3\x84 (decimal 195, 132) as the
character Ä, it isn't anything of the sort. It's just two arbitrary bytes.

 [ord(c) for c in u'AÄ']
 [65, 196]

Here, you have a proper Unicode string, so Python is expecting to receive
arbitrary Unicode characters and can treat the two bytes 195, 132 as Ä, and
that character has ordinal value 196:

py ord(uÄ)
196



 My obviously wrong understanding:
 ‚AÄ‘ in ‚ascii‘ are two characters
  one with ord A=65 and
  one with ord Ä=196 ISO8859-1 depends on code table

As soon as you start talking about code tables, *it isn't ASCII anymore*.
(Technically, ASCII *is* a code table, but it's one that only covers 127
different characters.)

When you type AÄ on your keyboard, or paste them, or however they were
entered, the *actual bytes* the terminal receives will vary, but regardless
of how they vary, the terminal *almost certainly* will interpret the first
byte (or possibly more than one byte, who knows?) as the ASCII character A.

(Most, but not all, code pages agree that byte 65 is A, 66 is B, and so on.)

The second (third? fifth?) byte, and possibly subsequent bytes, will
*probably* be displayed by the terminal as Ä, but Python only sees the raw
bytes. The important thing here is that unless you have some bizarre and
broken configuration, Python can correctly interpret the A as A, but what
you get for the Ä depends on the interaction of keyboard, OS, terminal and
the phase of the moon.

  —- why [65, 195, 132]

Since Python is expecting to interpret those bytes as an ASCII-ish byte
string, it grabs the raw bytes and ends up (in your case) with 65, 195,
132, or 'A\xc3\x84', even though your terminal displays it as AÄ.

This does not happen with Unicode strings.

 u’AÄ’ is an Unicode string
  —- why [65, 196]

In this case, Python knows that you are dealing with a Unicode string, and Ä
is a valid character in Unicode. Python deals with the internal details of
converting from whatever-damn-bytes your terminal sends it, and ends up
with a string of characters A followed by Ä.

If you could peer under the hood, and see what implementation Python uses to
store that string, you would see something version dependent. In Python
2.7, you would see an object more or less something vaguely like this:

[object header containing various fields]
[length = 2]
[array of bytes = 0x0041 0x00C4]


That's for a so-called narrow build of Python. If you have a wide build,
it will something like this:

[object header containing various fields]
[length = 2]
[array of bytes = 0x0041 0x00C4]

In Python 3.3, narrow builds and wide builds are gone, and you'll have
something conceptually like this:

[object header containing various fields]
[length = 2]
[tag = one byte per character]
[array of bytes = 0x41 0xC4]

Some other implementations of Python could use UTF-8 internally:

[object header containing various fields]
[length = 2]
[array of bytes = 0x41 0xC3 0x84]


or even something more complex. But the important thing is, regardless of
the internal implementation, Python guarantees that a Unicode string is
treated as a fixed array of code points. Each code point has a value
between 0 and, not 127, not 255, not 65535, but 1114111.


-- 
Steven

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


Re: Run an http server on Apache without wsgi?

2014-09-05 Thread dieter
Frank Millman fr...@chagford.com writes:

 My AccInABox project runs an http server. Previously I used the cherry.py 
 wsgiserver, but I have now switched to asyncio.

 I tried to use the wsgi interface, but I have a particular requirement and 
 found that wsgi got in the way, so I dropped it and now handle all requests 
 directly.

 Now the question arises, what if someone wants to run my program under 
 Apache or nginx?

There are various ways to interface Apache and Python: among
others cgi, fcgi, wsgi. There also used to be mod_python
which allowed to run Python directly inside an Apache process - however,
this module is no longer supported.

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


[issue21951] tcl test change crashes AIX

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The patch can be simpler. And there is yet one similar bug, for unicode strings.

--
Added file: http://bugs.python.org/file36544/asobj_empty_sequence_2.patch

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



[issue20912] [zipfile.py]: Make zip directory attributes more friendly for MS-Windows

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If there are no objections I'll commit the patch soon.

--

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



[issue21228] Missing enumeration of HTTPResponse Objects methods of urllib.request.urlopen's http.client.HTTPResponse?

2014-09-05 Thread Martin Panter

Martin Panter added the comment:

With this patch, there is no longer any implication that the returned object 
implements the “addinfourl” interface. Perhaps that should be added back. Or 
maybe add it to the HTTPResponse class documentation itself? There is a comment 
that says the methods are there “for compatibility with old-style urllib 
responses”, although it seems to me they also make the class compatible with 
Python 3’s new “urllib”:

http://hg.python.org/cpython/file/c499cc2c4a06/Lib/http/client.py#l772

It is good to document the “msg” attribute and its inconsistency, since I have 
found this is required to implement your own BaseHandler.default_open(). 
However I’m not so sure if it is necessary to document the “url” attribute. Why 
not encourage using geturl() instead, since it is already documented, at least 
for non-HTTP responses?

I also saw a comment against the “msg” attribute which mentions deprecating 
something, but it is not clear what:
http://hg.python.org/cpython/file/c499cc2c4a06/Lib/urllib/request.py#l1187

--

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



[issue22215] embedded NUL character exceptions

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If there are no objections I'll commit the patch soon.

--

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



[issue18960] First line can be executed twice

2014-09-05 Thread Roundup Robot

Roundup Robot added the comment:

New changeset dd1e21f17b1c by Serhiy Storchaka in branch '2.7':
Issue #1: Backported fixes from Python 3 (issue #18960).
http://hg.python.org/cpython/rev/dd1e21f17b1c

--

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



[issue22221] ast.literal_eval confused by coding declarations

2014-09-05 Thread Roundup Robot

Roundup Robot added the comment:

New changeset dd1e21f17b1c by Serhiy Storchaka in branch '2.7':
Issue #1: Backported fixes from Python 3 (issue #18960).
http://hg.python.org/cpython/rev/dd1e21f17b1c

--
nosy: +python-dev

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



[issue22226] Refactor dict result handling in Tkinter

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If there are no objections I'll commit the patch soon.

--

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



[issue22221] ast.literal_eval confused by coding declarations

2014-09-05 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 13cd8ea4cafe by Serhiy Storchaka in branch '3.4':
Issue #1: Add tests for compile() with source encoding cookie.
http://hg.python.org/cpython/rev/13cd8ea4cafe

New changeset 9d335a54d728 by Serhiy Storchaka in branch 'default':
Issue #1: Add tests for compile() with source encoding cookie.
http://hg.python.org/cpython/rev/9d335a54d728

--

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



[issue22219] python -mzipfile fails to add empty folders to created zip

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If there are no objections I'll commit the patch soon.

--

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



[issue15513] Correct __sizeof__ support for pickle

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If there are no objections I'll commit the patch soon.

--

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



[issue22221] ast.literal_eval confused by coding declarations

2014-09-05 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

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



[issue22215] embedded NUL character exceptions

2014-09-05 Thread STINNER Victor

STINNER Victor added the comment:

 If there are no objections I'll commit the patch soon.

Replacing TypeError with ValueError is fine. TypeError was a bad choice. If an 
application relies on TypeError to check for null character, it's easy to 
replace except TypeError: with except (TypeError, ValueError): to stay 
compatible with Python  3.5.

Instead of NUL character (and NUL byte), I had prefer null character (and 
null byte):
http://en.wikipedia.org/wiki/Null_character

I talking about the error message because you changed it in a few places.

--
nosy: +haypo

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



[issue22215] embedded NUL character exceptions

2014-09-05 Thread STINNER Victor

STINNER Victor added the comment:

You may also take a look at these 2 issues: #13617 and #21147 (not directly 
related to this oe).

--

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



[issue5309] distutils doesn't parallelize extension module compilation

2014-09-05 Thread Jonas Wagner

Changes by Jonas Wagner jonas.wag...@epfl.ch:


--
nosy: +Sjlver

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



[issue5309] distutils doesn't parallelize extension module compilation

2014-09-05 Thread Jonas Wagner

Jonas Wagner added the comment:

Is there a reason this has not landed? The patch works perfectly for me, except 
for one issue:

@@ -268,6 +275,9 @@
 if self.undef:
 self.undef = self.undef.split(',')
 
+if self.parallel:
+self.parallel = int(self.parallel)
+
 if self.swig_opts is None:
 self.swig_opts = []
 else:

If self.parallel is True, this will set self.parallel to 1, causing it to use 
one worker instead of n (where n is the number of processors).

An updated patch is attached.

--
Added file: http://bugs.python.org/file36545/build_ext_parallel4.patch

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



[issue22215] embedded NUL character exceptions

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Victor. Here is a patch which is synchronized with the tip and 
addresses your comment about a null character.

--
Added file: 
http://bugs.python.org/file36546/valueerror_embedded_nul_character_2.patch

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



[issue13617] Reject embedded null characters in wchar* strings

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Could you please answer my comments Victor?

--
versions: +Python 3.4, Python 3.5 -Python 3.2, Python 3.3

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



[issue5309] distutils doesn't parallelize extension module compilation

2014-09-05 Thread Stefan Behnel

Stefan Behnel added the comment:

Yes, please. The sequential build in distutils is very annoying.

(too late for Py3.4, though, I guess...)

--
nosy: +scoder
versions: +Python 3.5 -Python 3.4

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



[issue21147] sqlite3 doesn't complain if the request contains a null character

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Added a comment on Rietveld.

--
components: +Extension Modules
nosy: +serhiy.storchaka
stage:  - needs patch
type:  - behavior
versions: +Python 2.7, Python 3.4

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



[issue22220] Ttk extensions test failure

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Looks as all builds since #415 are successful.

--

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



[issue22340] Fix Python 3 warnings in Python 2 tests

2014-09-05 Thread STINNER Victor

New submission from STINNER Victor:

Running Python 2 test suite with python -3 -Wd displays a lot of 
DeprecationWarning warnings. Just one example:

/home/haypo/prog/python/2.7/Lib/test/test_ssl.py:2368: DeprecationWarning: 
urllib.urlopen() has been removed in Python 3.0 in favor of urllib2.urlopen()

Attached patch fix most of them (maybe all).

--
components: Tests
files: fix_py3k_warn.patch
keywords: patch
messages: 226418
nosy: haypo
priority: normal
severity: normal
status: open
title: Fix Python 3 warnings in Python 2 tests
versions: Python 2.7
Added file: http://bugs.python.org/file36547/fix_py3k_warn.patch

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



[issue22341] Python 3 crc32 documentation clarifications

2014-09-05 Thread Martin Panter

New submission from Martin Panter:

This is regarding the Python 3 documentation for binascii.crc32(), 
https://docs.python.org/dev/library/binascii.html#binascii.crc32. It 
repeatedly recommends correcting the sign by doing crc32()  0x, but it 
is not immediately clear why. Only after reading the Python 2 documentation 
does one realise that the value is always unsigned for Python 3, so you only 
really need the workaround if you want to support earlier Pythons.

I also suggest documenting the initial CRC input value, which is zero. 
Suggested wording:

binascii.crc32(data[, crc])
Compute CRC-32, the 32-bit checksum of “data”, starting with the given “crc”. 
The default initial value is zero. The algorithm is consistent with the ZIP 
file checksum. Since the algorithm is designed for use as a checksum algorithm, 
it is not suitable for use as a general hash algorithm. Use as follows:

print(binascii.crc32(bhello world))
# Or, in two pieces:
crc = binascii.crc32(bhello, 0)
crc = binascii.crc32(b world, crc)
print('crc32 = {:#010x}'.format(crc))

I would simply drop the notice box with the workaround, because I gather that 
the Python 3 documentation generally omits Python 2 details. (There are no “new 
in version 2.4 tags” for instance.) Otherwise, clarify if “packed binary 
format” is a reference to the “struct” module, or something else.

Similar fixes are probably appropriate for zlib.crc32() and zlib.alder32().

Also, what is the relationship between binascii.crc32() and zlib.crc32()? I 
vaguely remember reading that “zlib” is not always available, so I tend to use 
“binascii” instead. Is there any advantage in using the “zlib” version? The 
“hashlib” documentation points to “zlib” without mentioning “binascii” at all.

--
assignee: docs@python
components: Documentation
messages: 226419
nosy: docs@python, vadmium
priority: normal
severity: normal
status: open
title: Python 3 crc32 documentation clarifications
versions: Python 3.4

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



[issue21866] zipfile.ZipFile.close() doesn't respect allowZip64

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Benjamin for explanation.

Here is a patch which adds all three required checks in the close() method and 
adds a check for files count in write methods. Implementing other checks in 
write methods is too laborious.

As far as test_zipfile64 is disabled, for manual testing you need temporary 
comment out the support.requires() statement and run only selected tests:

./python -m test.regrtest -v -m OtherTests test_zipfile64

--
keywords: +patch
stage: needs patch - patch review
Added file: http://bugs.python.org/file36548/zipfile64_additional_checks.patch

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



[issue22340] Fix Python 3 warnings in Python 2 tests

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Why test_support.check_py3k_warnings is not used in test_calltips.py? Or may be 
change the test to 1+0, 1//0 or 1.0/0.0?

--
nosy: +serhiy.storchaka, terry.reedy

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



[issue13968] Support recursive globs

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Could you make a review Nick?

--

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



[issue22187] commands.mkarg() buggy in East Asian locales

2014-09-05 Thread mirabilos

mirabilos added the comment:

Just for the record, please do not assume all shells behave like GNU bash.

--
nosy: +mirabilos

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



[issue5309] distutils doesn't parallelize extension module compilation

2014-09-05 Thread Jonas Wagner

Jonas Wagner added the comment:

With this patch, and on Ubuntu 14.04, occasionally modules fail to build with 
the following error:

*** WARNING: renaming _testbuffer since importing it failed: dlopen: cannot 
load any more object with static TLS

I'm not 100% sure if this is really due to the patch... but I've never seen it 
before. I'll try investigate a bit more.

--

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



[issue22342] Fix typo in PEP 380 -- Syntax for Delegating to a Subgenerator

2014-09-05 Thread Gael Robin

New submission from Gael Robin:

The first line of the Refactoring Principle subsection of the Rationale section 
contains the following typo :

It should be possible to take an section of code

should be

It should be possible to take a section of code

--
assignee: docs@python
components: Documentation
messages: 226425
nosy: Gael.Robin, docs@python
priority: normal
severity: normal
status: open
title: Fix typo in PEP 380 -- Syntax for Delegating to a Subgenerator
type: enhancement

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



[issue22187] commands.mkarg() buggy in East Asian locales

2014-09-05 Thread R. David Murray

R. David Murray added the comment:

That is true, but sh-alikes (posix standard) are the only ones we support in 
commands.  subprocess (which commands was folded in to in python3) also 
supports windows cmd to the extent we've managed, but that's all we are 
committed to support.

--

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



[issue22302] Windows os.path.isabs UNC path bug

2014-09-05 Thread Steve Dower

Steve Dower added the comment:

Antoine almost certainly thought about this with pathlib and may know about the 
change, or at least have some decent context on it.

I'm more inclined to think that os.path.isabs(r\\server) should also return 
False, since it's not a path that can be opened directly unless you add more 
path before or after it.

Indeed, pathlib seems to support my understanding:

 Path('//server').is_absolute()
False
 Path('//server/share').is_absolute()
True
 Path('//server/share/').is_absolute()
True
 Path('//server/share/file').is_absolute()
True

If the regression appeared in 3.4, it should be easy enough to look at what 
changed.

--
nosy: +pitrou, steve.dower

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



[issue22299] resolve() on Windows makes some pathological paths unusable

2014-09-05 Thread Steve Dower

Steve Dower added the comment:

Patch attached. (Kinda feel like this was too simple...)

--
keywords: +patch
Added file: http://bugs.python.org/file36549/22299_1.patch

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



[issue22302] Windows os.path.isabs UNC path bug

2014-09-05 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Under Windows, pathlib's absolute means a fully qualified path as defined in 
http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx

 PureWindowsPath(c:).is_absolute()
False
 PureWindowsPath(/).is_absolute()
False
 PureWindowsPath(c:/).is_absolute()
True

The fact that //server isn't considered absolute is a bug in pathlib, since 
//server/ is:

 PureWindowsPath(//foo).is_absolute()
False
 PureWindowsPath(//foo/).is_absolute()
True

I agree that it's not really important, since both aren't actual paths (in the 
sense that they may not point to anything, AFAIK).

--

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



[issue22302] Windows os.path.isabs UNC path bug

2014-09-05 Thread Steve Dower

Steve Dower added the comment:

My experience says the main reason people want to know whether the path is 
absolute is to figure out whether to do `Path.cwd() / path` or not. According 
to that MSDN page, they shouldn't because the path starts with // (that is, 
the last character and the existence of the share name are irrelevant here).

Both pathlib and ntpath are reasonably consistent in determining the drive of 
the path:
 splitdrive('server\\')[0]
'server\\'
 splitdrive('server')[0]
''
 Path('server\\').parts[0]
'server'
 Path('server').parts[0]
'\\'

I assume the bug in the last statement is what Antoine is referring to.

The difference in results then comes from how they determine roots.
 splitdrive('server\\')[1]
''
 splitdrive('server')[1]
'server'
 Path('//server/').root
'\\'
 Path('//server').root
'\\'

Pathlib always has a root, but splitdrive doesn't.

I'm not sure exactly which one to fix where, but hopefully that helps someone 
else figure it out.

--

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



[issue22299] resolve() on Windows makes some pathological paths unusable

2014-09-05 Thread eryksun

eryksun added the comment:

It should only skip _ext_to_normal for an already extended path, i.e. a path 
that starts with ext_namespace_prefix. Otherwise it needs to call 
_ext_to_normal. For example:

Strip the prefix in this case:

 os.path._getfinalpathname('C:\\Windows')   
'?\\C:\\Windows'

but not in this case:

 
os.path._getfinalpathname(r'\\?\GLOBALROOT\Device\HarddiskVolume1\Windows')
'?\\C:\\Windows'

--

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



[issue22302] Windows os.path.isabs UNC path bug

2014-09-05 Thread Steve Dower

Steve Dower added the comment:

Just did a double-take, but that output for Path('server\\').parts[0] is 
actually correct...

 Path('server\\').parts[0]
'server'
 print(Path('server\\').parts[0])
\\server\\

--

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



[issue22299] resolve() on Windows makes some pathological paths unusable

2014-09-05 Thread Steve Dower

Steve Dower added the comment:

Ah, thought it was too simple. I didn't realise that _getfinalpathname adds the 
prefix.

New patch soon.

--

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



[issue22302] Windows os.path.isabs UNC path bug

2014-09-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It looks to me that rather handling of //server/ is buggy than //server. 
//server is just the same as /server or ///server. But //server/ looks 
as an UNC path with empty () mount point. This is invalid path and we can't 
create valid path from this path by adding components. Perhaps 
PureWindowsPath(//server/) should raise an exception.

--
nosy: +serhiy.storchaka

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



[issue22299] resolve() on Windows makes some pathological paths unusable

2014-09-05 Thread Steve Dower

Steve Dower added the comment:

Strips the prefix if it wasn't in the original path - otherwise, keeps it.

--
Added file: http://bugs.python.org/file36550/22299_2.patch

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



  1   2   >