OSError: [WinError 10022] An invalid argument was supplied in udp python file

2015-01-10 Thread contro opinion
When i test an udp.py file on server and client in python34.


#!/usr/bin/env python
import socket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
MAX = 65535
PORT = 1060
if sys.argv[1:] == ['server']:
s.bind(('127.0.0.1', PORT))
print('Listening at', s.getsockname())
while True:
  data, address = s.recvfrom(MAX)
  print('The client at', address, 'says', repr(data))
  s.sendto('Your data was %d bytes' % len(data), address)
elif sys.argv[1:] == ['client']:
print('Address before sending:',s.getsockname())
s.sendto('This is my message',('127.0.0.1', PORT))
print('Address after sending',s.getsockname())
data, address = s.recvfrom(MAX)
print('The server', address, 'says', repr(data))
else:
  print('usage: udp_local.py server|client')


The command `python udp.py server`  get output:
Listening at ('127.0.0.1', 1060)

Why   `python udp.py client`  run failure:

Traceback (most recent call last):
  File "d://udp.py", line 15, in 
print('Address before sending:', s.getsockname())
OSError: [WinError 10022] An invalid argument was supplied
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Begginer Question , what i need for web app and site

2015-01-10 Thread memilanuk

On 01/09/2015 05:53 AM, meiry...@gmail.com wrote:

Hello all
coming from java and c++ now going with python
what setup do i need to run full python stack for web application .
what i need is web framework and back-end .
what usually be in the java world tomcat and servlets or jsp and pure java 
backend for processing data .
what will be the Equivalent in python world ?
Thanks!



http://www.fullstackpython.com/

--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com
--
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-10 Thread Chris Warrick
On Sat, Jan 10, 2015 at 2:02 AM, André Roberge  wrote:
> On Friday, 9 January 2015 19:09:15 UTC-4, stephen...@gmail.com  wrote:
>> One issue is the format returned for the calendar selection. For today, the 
>> string returned is "Fri Jan 9 2015". My script needs to convert the date to 
>> a datetime.date, and having the month returned as a string instead of an 
>> integer makes this harder.
>
> Would today's date be represented as the string "09.01.2015" useful to you? 
> (I found out how to do this.)  If so, I could perhaps add an argument like 
> numeric_format = True.

The correct way to handle this is to use cal.date.toPyDate(), which
helpfully returns a datetime.date object — and make this the default
output of the calendar function, because that’s the only useful output
for anyone asking for a date.

>>> date
'Sat Jan 10 2015'
>>> cal.date
PyQt4.QtCore.QDate(2015, 1, 10)
>>> cal.date.toPyDate()
datetime.date(2015, 1, 10)

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Non-unique dirs in sys.path

2015-01-10 Thread Terry Reedy

On 1/9/2015 8:14 AM, Gisle Vanem wrote:

I'm having some trouble understanding why my Python 2.7.9
has the '%PYTHONHOME%\lib\site-packages' listed multiple
times.

I cooked up this .bat file to demonstrate the issue:
   @echo off
   setlocal
   set PYTHONPATH=
   python -c "import sys; [sys.stdout.write('%%s\n' %% p) for (i,p) in
enumerate(sys.path)]" | sort --ignore-case

which produces:

   f:\Documents and Settings\Gisle
Vanem\Programdata\Python\Python27\site-packages
   f:\windows\system32\python27.zip<< !! doesn't exist, but okay.
   G:\Programfiler\Python27
   g:\Programfiler\Python27\DLLs
   g:\Programfiler\Python27\lib
   g:\Programfiler\Python27\lib\lib-tk
   g:\Programfiler\Python27\lib\plat-win
   g:\Programfiler\Python27\lib\site-packages   << !!
   g:\programfiler\python27\lib\site-packages   << !!
   ...

Why are these listed twice with different casing? One
would assume that Python on Win32 would be case-insensitive.
Some .pth-file to blame here?


To me, this is a bug, as it will, I believe, result in site-packages 
being searched twice before an import fails.


--
Terry Jan Reedy

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


Re: Why do the URLs of posts here change?

2015-01-10 Thread Terry Reedy

On 1/9/2015 7:04 AM, Skip Montanaro wrote:

Posts on this newsgroup/mailing list are archived on the web, but the URLs
seem to change, which leaves dead links if you search for things.


Steven,

It's a known issue, but one which appears to be somewhat unavoidable,
at least in Mailman 2.x. The problem is that every now and then,
postmas...@python.org gets a legitimate request from someone for a
message to be deleted from the list archive. The way this is done, is
that the message is removed from the underlying mbox file,


The post could be replaced by a placeholder "This message deleted'

 and the

archive regenerated. That changes the counter for every message after


A placeholder should avoid that.


that point - or maybe every message in the generated archive. (I have
no idea why the numerical basename of your subject message would have
changed so much. Maybe there is just a single ever incrementing
counter for a given Mailman installation.)


--
Terry Jan Reedy

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


Re: Decimals and other numbers

2015-01-10 Thread alister
On Fri, 09 Jan 2015 19:57:20 -0800, Devin Jeanpierre wrote:

> On Fri, Jan 9, 2015 at 7:05 PM, Gregory Ewing
>  wrote:
>> It's far from clear what *anything* multiplied by itself zero times
>> should be.
>>
>> A better way of thinking about what x**n for integer n means is this:
>> Start with 1, and multiply it by x n times. The result of this is
>> clearly 1 when n is 0, regardless of the value of x.
>>
>>> 5**4 = 5*5*5*5 = 625
>>
>> No:
>>
>> 5**4 = 1*5*5*5*5 5**3 = 1*5*5*5 5**2 = 1*5*5 5**1 = 1*5 5**0 = 1
> 
> I never liked that, it seemed too arbitrary. How about this explanation:
> 
> Assume that we know how to multiply a nonempty list numbers. so
> product([a]) == a, product([a, b]) = a * b, and so on.
> 
> def product(nums):
> if len(nums) == 0:
> return ???
> return reduce(operator.mul, nums)
> 
> It should be the case that given a list of factors A and B,
> product(A + B) == product(A) * product(B)   (associativity).
> We should let this rule apply even if A or B is the empty list,
> otherwise our rules are kind of stupid.
> 
> Therefore, product([] + X) == product([]) * product(X)
> But since [] + X == X, product([] + X) == product(X)
> 
> There's only one number like that: product([]) == 1
> 
> (Of course if you choose not to have the full associativity rule for
> empty products, then anything is possible.)
> 
> -- Devin

The general theory behind logarithms explains why it is excepted that any 
number raised to the power of 0 =1

take  X^3 * x^ 4 = X^7 achieved simply by adding the indices
if you wanted to do X *1 using the same method what would you need to add 
to the index of X (X^1 ) to get X (X^1) - Answer 0 therefore X^0 = 1

This theoretically works regardless of the  value of x you choose for the 
base , of course in practice it is not possible to work in a number base 
of 0 which is where things get into the indeterminate as it contradicts 
the other provable fact that ) * anything is 0.

These edge case contradictions can easily cause my brain into an in 
finite recursive loop.

it is as confusing as the concept that there are different values of 
infinity (some larger than others!)





-- 
Ya'll hear about the geometer who went to the beach to catch some
rays and became a tangent ?
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] ‘python-daemon’ version 2.0 released

2015-01-10 Thread Ben Finney
Howdy all,

I am pleased to announce the release of version 2.0 of the
‘python-daemon’ library.

The current release is always available at
https://pypi.python.org/pypi/python-daemon/>.

The project's forums and VCS are hosted at Alioth
https://alioth.debian.org/projects/python-daemon/>.


Significant changes since the previous version
==

* Supports Python 2 (version 2.7 or later) and Python 3 (version 3.2
  or later) with the same code base.

  This version drops support for Python earlier than Python 2.7.

  This constitutes a major re-write of large parts of the test suite,
  packaging code, and library code. Please test carefully and report any
  regressions from earlier versions.

* Full unit test coverage of all code branches.

* Add explicit credit for contributors.


What is the ‘python-daemon’ library?


‘python-daemon’ is a Python library to implement a well-behaved Unix
daemon process.

-- 
 \ “Capitalism is the astounding belief that the most wickedest of |
  `\men will do the most wickedest of things for the greatest good |
_o__)   of everyone.” —John Maynard Keynes |
Ben Finney 

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


Re: OSError: [WinError 10022] An invalid argument was supplied in udp python file

2015-01-10 Thread Kev Dwyer
contro opinion wrote:

> When i test an udp.py file on server and client in python34.
> 
> 
> #!/usr/bin/env python
> import socket, sys
> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> MAX = 65535
> PORT = 1060
> if sys.argv[1:] == ['server']:
> s.bind(('127.0.0.1', PORT))
> print('Listening at', s.getsockname())
> while True:
>   data, address = s.recvfrom(MAX)
>   print('The client at', address, 'says', repr(data))
>   s.sendto('Your data was %d bytes' % len(data), address)
> elif sys.argv[1:] == ['client']:
> print('Address before sending:',s.getsockname())
> s.sendto('This is my message',('127.0.0.1', PORT))
> print('Address after sending',s.getsockname())
> data, address = s.recvfrom(MAX)
> print('The server', address, 'says', repr(data))
> else:
>   print('usage: udp_local.py server|client')
> 
> 
> The command `python udp.py server`  get output:
> Listening at ('127.0.0.1', 1060)
> 
> Why   `python udp.py client`  run failure:
> 
> Traceback (most recent call last):
>   File "d://udp.py", line 15, in 
> print('Address before sending:', s.getsockname())
> OSError: [WinError 10022] An invalid argument was supplied


Hello,

According to 
http://stackoverflow.com/questions/15638214/socket-error-invalid-argument-supplied,
 the client socket doesn't have an address at time
when you call s.getsocketname.  This raises an exception on Windows.

Removing the 'Address before sending' line will prevent the error.

As you're using Python3, you'll find that passing strings to s.sendto raises
a TypeError; you'll need to encode the strings as bytes.

Hope that helps,

Kev

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


Re: Why do the URLs of posts here change?

2015-01-10 Thread Skip Montanaro
On Sat, Jan 10, 2015 at 3:41 AM, Terry Reedy  wrote:
> The post could be replaced by a placeholder "This message deleted'
>
>  and the
>>
>> archive regenerated. That changes the counter for every message after
>
>
> A placeholder should avoid that.

I suspect (though don't know for certain) that just regenerating the
archive without touching the mbox file will change the numbering.
Steven's original post mentioned two very different basenames (468598
and 481374). As I indicated in an earlier response, those might be
generated from an ever-growing counter, not just a shift as articles
slide one closer to the first one of the month.

So, you'd have to edit the mbox file carefully (might need to edit
headers) and also edit the generated HTML for the message. Neither is
an insurmountable task, but both are going to be more error-prone than
just cutting out an entire message and regenerating the archive.

I will pass along your suggestion to the postmaster folks (I don't get
involved that that level - it's mostly the folks who directly maintain
the Postfix setup who do this), though. They are a generally pretty
responsive bunch.

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


Python : writing to a file

2015-01-10 Thread Ganesh Pal
Please provide you input on the below questions:


(a) I was expecting  the string i.e day of week , example Saturday to be
written in the file. what Iam I missing in the below program  ?

Program:

#!/usr/bin/python

import time
f = open ('test_2.txt','w+b')
DAY = time.strftime("%A")
f.write(DAY)
f.close()

Throttling-1# cat test_2.txt

(b) Iam trying to generate a file in the below format ,

cluster1# cat test_2.txt

Saturday 0:05 0:10
Saturday 0:10 0:20
Saturday 0:20 0:30
Saturday 0:40 0:50
Saturday 0:60 0:70

(a) what is the easiest way to generate the above file fprmat ?

(b) how will I take care that the below format is repeated in the .txt file
  ( i.e column and row spacing)

DAY OF THE WEEK  [SPACE] START TIME [ SPACE] ENDTIME{SPACE]


(c) how do I  add START TIME [ SPACE] ENDTIME{SPACE] columns



Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Playing with threads

2015-01-10 Thread Ganesh Pal
Thanks I read subprocess module this answered most of my question ,thanks a
lot for the  replies

On Thu, Jan 8, 2015 at 9:46 AM, Terry Reedy  wrote:

> On 1/7/2015 9:00 PM, Ganesh Pal wrote:
>
>> Hi friends,
>>
>> I'm trying to use threads  to achieve the below work flow
>>
>> 1. Start a process , while its running grep for a string 1
>> 2. Apply the string 1 to the command in step 1 and exit step 2
>> 3. Monitor the stdout of step1 and print success if the is pattern  found
>>
>> Questions:
>>
>> 1. Can the above be achieved without threads ? I prefer keep ing code
>> simple  .threads can become confusion when this workflow grows larger
>>
>
> I do not understand the work flow either.  What I do know is that Idle
> Edit -> Find in Files is implemented in idlelib/grep.py and that the
> non-gui code could be copied and adapted to other purposes.
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python : writing to a file

2015-01-10 Thread Dave Angel

On 01/10/2015 10:14 AM, Ganesh Pal wrote:

Please provide you input on the below questions:



For each new thread, you should specify at a minimum your Python version 
and OS.  it frequently matters, and it's better to specify than to have 
everyone try to guess.  I'll assume Python 2.7 and Linux.




(a) I was expecting  the string i.e day of week , example Saturday to be
written in the file. what Iam I missing in the below program  ?

Program:

#!/usr/bin/python

import time
f = open ('test_2.txt','w+b')
DAY = time.strftime("%A")
f.write(DAY)
f.close()

Throttling-1# cat test_2.txt


Not to belabor the obvious, but did you run the program?  I'd add at 
least one print to a minimal program to make sure you ran the same 
program as you show, and you can also use that to inspect the contents 
of variables.


Works for me on ubuntu Python 2.7

Incidentally, I'd avoid using w+b.  Just use wb if you're creating a file.



(b) Iam trying to generate a file in the below format ,

cluster1# cat test_2.txt

Saturday 0:05 0:10
Saturday 0:10 0:20
Saturday 0:20 0:30
Saturday 0:40 0:50
Saturday 0:60 0:70

(a) what is the easiest way to generate the above file fprmat ?

(b) how will I take care that the below format is repeated in the .txt file
   ( i.e column and row spacing)

 DAY OF THE WEEK  [SPACE] START TIME [ SPACE] ENDTIME{SPACE]


(c) how do I  add START TIME [ SPACE] ENDTIME{SPACE] columns



The use the str.format method.

line = "{} {} {}\n".format(day, start, end)

The curlies specify where the various arguments will be placed, and the 
"\n" generates a newline at the end.


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


ftfy: fixes text for you

2015-01-10 Thread Mark Lawrence
I came across ftfy via this post 
http://ianozsvald.com/2015/01/10/a-first-approach-to-automatic-text-data-cleaning/ 
and thought others here might be interested in it, so here's the direct 
link http://ftfy.readthedocs.org/en/latest/.


--
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: [OT] x**y == y**x

2015-01-10 Thread Peter Pearson
On Fri, 09 Jan 2015 23:41:15 +0200, Marko Rauhamaa  wrote:
> Peter Pearson :
>
>> If you've never looked at the set of reals (x,y) satisfying x**y ==
>> y**x, it's worth a visit.
>
> Thanks, it was. The graph's something like this:
[snip]
>
> Where can I read more on the topic?

Sorry, I don't know.  One Phil Rust steered me to this problem in high
school (c. 1964), and I never got much traction on it until Prof. Alfred
Roch at EPFL pointed out (c. 1981) that it's revealing to think of
horizontal lines intersecting the graph of ln(x)/x.

If you like this sort of thing, here's another cute function that
the same Phil Rust called to my attention:
http://webpages.charter.net/curryfans/peter/XtoTheXtoTheX/ode_to_e.html

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python : writing to a file

2015-01-10 Thread Steven D'Aprano
Ganesh Pal wrote:

> Throttling-1# cat test_2.txt

Are you running these scripts as root? That could be a bad idea. If you have
a bug in your code, as often happens when coding, who knows what it might
do. E.g. if you put in the wrong pathname, you could overwrite important
files. You should always do your coding as a regular user, not root.


-- 
Steven

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


Re: ftfy: fixes text for you

2015-01-10 Thread Joel Goldstick
On Sat, Jan 10, 2015 at 10:50 AM, Mark Lawrence 
wrote:

> I came across ftfy via this post http://ianozsvald.com/2015/01/
> 10/a-first-approach-to-automatic-text-data-cleaning/ and thought others
> here might be interested in it, so here's the direct link
> http://ftfy.readthedocs.org/en/latest/.
>
> --
> 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
>

very interesting

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


PyWart: Poor Documentation Examples

2015-01-10 Thread Rick Johnson


EXAMPLE 1: "Reducing Comprehension" 
https://docs.python.org/2/howto/doanddont.html#using-the-batteries




#QUOTE: Python Docs#

# Another highly useful function is reduce() which can be  #
# used to repeatly apply a binary operation to a sequence, #
# reducing it to a single value. For example, compute a#
# factorial with a series of multiply operations:  #
#  #
# py> n = 4#
# py> import operator  #
# py> reduce(operator.mul, range(1, n+1))  #
# 24   #



Ignoring the obvious mis-spellings @_@...

How exactly does: assigning variables(n = 4),
arithmetic(n+1), and the "range" function going to help me
understand the usefulness of the reduce function? A much
better example would be:

py> import operator
py> reduce(operator.mul, [1,2,3,4])
24

At *LEAST* with that example the only potential unknown
might be "operator.mul". However, a wise teacher would
recognize that this is a fine "teaching example" of how
using the operator module can prevent duplicating code --
which would lead to a better example like:

py> def mul(x, y):
... return x*y
py> reduce(mul, [1,2,3,4])
24

FINALLY! An example that showcases a proper usage of the
the reduce function *WITHOUT* any superfluous distractions. However,
remembering that code re-use is a good thing, and that re-
inventing the wheel is a lot of work, we should mention that
the "mul" function should be replaced with "operator.mul"

Note: Be sure to check out the "operator" module for
pre-defined arithmetic functions like "operator.mul",
which would "reduce" (*wink*) the above code to this:

py> reduce(operator.mul, [1,2,3,4])
24



EXAMPLE 2: "The Fibonacci Phallus Extender".
https://docs.python.org/2/tutorial/controlflow.html#defining-functions


#
#   QUOTE: Python Docs  #
#
# We can create a function that writes the Fibonacci#
# series to an arbitrary boundary:  #
#   #
# py> def fib(n):# write Fibonacci series up to n   #
# ... """Print a Fibonacci series up to n."""   #
# ... a, b = 0, 1   #
# ... while a < n:  #
# ... print a,  #
# ... a, b = b, a+b #
# ...   #
# py> # Now call the function we just defined:  #
# ... fib(2000) #
# 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 #
#


No, No, *NO*! This is the most horrible example i have ever
encountered. Why would you introduction functions with an
example of calculating Fibonacci series? How are
"doc-strings" and "multiple assignment" and "loops" and
"conditions" the "print function" and "comments" going to
help me understand "defining a python function"?

Listen, if your primary goal is to teach, then *BEFORE* you
provide *ANY* examples of "defining functions", you should
*FIRST* explain what a function *IS* and *WHY* you would
want to use one.

Next we going to learn about defining functions, but
before we do, we need to understand *WHAT* a function
*IS* and *WHY* we should use them ...

[LAZY DOC WRITERS CAN INSERT EXTERNAL LINK HERE!]

Now that we've explained the *what* and *why* of functions,
we need to provide an example of the most *BASIC* of python
function definitions:

py> def add(x, y):
return x + y
py> add(1,1)
2

*SCHOOL-BELL-RINGS*

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


Re: PyWart: Poor Documentation Examples

2015-01-10 Thread Chris Angelico
On Sun, Jan 11, 2015 at 5:05 AM, Rick Johnson
 wrote:
> 
> EXAMPLE 1: "Reducing Comprehension" 
> https://docs.python.org/2/howto/doanddont.html#using-the-batteries
> 

1) Why are you focusing on the /2/ docs, rather than /3/?
2) Why are you ranting, rather than submitting docs patches?

Your school bell is muted.

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


[RELEASE] ‘python-daemon’ version 2.0.1 released

2015-01-10 Thread Ben Finney
Howdy all,

I am pleased to announce the release of version 2.0.1 of the
‘python-daemon’ library.

The current release is always available at
https://pypi.python.org/pypi/python-daemon/>.

The project's forums and VCS are hosted at Alioth
https://alioth.debian.org/projects/python-daemon/>.


Significant changes since the previous version
==

This is a bug fix release, addressing a packaging bug:

* Include the ‘version’ module with source distribution.

Many thanks to users who promptly reported this omission.


What is the ‘python-daemon’ library?


‘python-daemon’ is a Python library to implement a well-behaved Unix
daemon process.

-- 
 \   “It is wrong to think that the task of physics is to find out |
  `\ how nature *is*. Physics concerns what we can *say* about |
_o__) nature…” —Niels Bohr |
Ben Finney 

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


Re: PyWart: Poor Documentation Examples

2015-01-10 Thread Mark Lawrence

On 10/01/2015 18:26, Chris Angelico wrote:

On Sun, Jan 11, 2015 at 5:05 AM, Rick Johnson
 wrote:


EXAMPLE 1: "Reducing Comprehension" 
https://docs.python.org/2/howto/doanddont.html#using-the-batteries



1) Why are you focusing on the /2/ docs, rather than /3/?
2) Why are you ranting, rather than submitting docs patches?

Your school bell is muted.

ChrisA



Ooh, I say old chap, isn't that going a bit too far?  Users submitting 
patches, whatever next?


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


Syntax error

2015-01-10 Thread Abdul Abdul
Hello,

I have the following program that employs the dcm2jpg.exe software:

import os
os.system(“dcm2jpg.exe IM-0004-0004.dcm”)
exit

When I tried to run it, I got the following error:

SyntaxError: Non-ASCII character '\xe2' in file dicomjpg.py on line 2, but
no en
coding declared; see http://python.org/dev/peps/pep-0263/ for details

Why is that? How can this error be solved?

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


Re: Syntax error

2015-01-10 Thread Joel Goldstick
On Sat, Jan 10, 2015 at 4:36 PM, Abdul Abdul  wrote:
>
> Hello,
>
> I have the following program that employs the dcm2jpg.exe software:
>
> import os
> os.system(“dcm2jpg.exe IM-0004-0004.dcm”)
> exit
>
It may be that your actual code has ascii quote characters, but you
have sent your question as rtf.  Please copy your code and paste it in
message using text only mail.  If you are using curly quotes, its not
ascii

>
> When I tried to run it, I got the following error:
>
> SyntaxError: Non-ASCII character '\xe2' in file dicomjpg.py on line 2, but no 
> en
> coding declared; see http://python.org/dev/peps/pep-0263/ for details
>
> Why is that? How can this error be solved?
>
> Thanks.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



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


Re: Syntax error

2015-01-10 Thread Peter Otten
Abdul Abdul wrote:

> Hello,
> 
> I have the following program that employs the dcm2jpg.exe software:
> 
> import os
> os.system(“dcm2jpg.exe IM-0004-0004.dcm”)
> exit
> 
> When I tried to run it, I got the following error:
> 
> SyntaxError: Non-ASCII character '\xe2' in file dicomjpg.py on line 2, but
> no en
> coding declared; see http://python.org/dev/peps/pep-0263/ for details
> 
> Why is that? 

As the error message says, you are using non-ascii characters (the “ and ”) 
in your code.

> How can this error be solved?

But even if you were to read the linked document and would add the line

# -*- coding: utf-8 -*

at the beginning of your script you would run into the next SyntaxError.

You are trying to quote a string literal with

“...”

but Python only understands

"..."

or 

'...'

Change the os.system() call to

os.system("dcm2jpg.exe IM-0004-0004.dcm")

and your script should work.

An unrelated issue:

> exit

to call a function the () is required -- to end the script at an arbitrary 
point use

exit()

However, as execution also ends automatically when the last line of the 
script is reached it is better to remove the

> exit

line completely.

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


Re: Syntax error

2015-01-10 Thread Dave Angel

On 01/10/2015 04:36 PM, Abdul Abdul wrote:

Hello,

I have the following program that employs the dcm2jpg.exe software:

import os
os.system(“dcm2jpg.exe IM-0004-0004.dcm”)
exit

When I tried to run it, I got the following error:

SyntaxError: Non-ASCII character '\xe2' in file dicomjpg.py on line 2, but
no en
coding declared; see http://python.org/dev/peps/pep-0263/ for details

Why is that? How can this error be solved?



Peter and Joel have the answer exactly right.

But I'd point out that it's also very important to use the right editor 
for writing your programs.  In order to get those curly quotes, you 
probably used a word processor to write the file, then saved it as text. 
 Use a good text editor, and you're much less likely to have it change 
your keystrokes out from under you.


Similarly when posting here, use text mode in your email, not html.

here's what the html you posted looks like:

Hello,I have the following program=
 that employs the dcm2jpg.exe software:import osos.system(=E2=
=80=9Cdcm2jpg.exe IM-0004-0004.dcm=E2=80=9D)exitWhen I tr=
ied to run it, I got the following error:SyntaxError=
: Non-ASCII character '\xe2' in file dicomjpg.py on line 2, but no =
encoding declared; see http://python.org/dev/peps/pep-0263/"=
>http://python.org/dev/peps/pep-0263/ for 
detailsWhy=
 is that? How can this error be 
solved?Thanks.
div>


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


Re: PyWart: Poor Documentation Examples

2015-01-10 Thread Steven D'Aprano
Rick Johnson wrote:


> 
> EXAMPLE 1: "Reducing Comprehension"
> https://docs.python.org/2/howto/doanddont.html#using-the-batteries
> 
> 
> 
> 
> #QUOTE: Python Docs#
> 
> # Another highly useful function is reduce() which can be  #
> # used to repeatly apply a binary operation to a sequence, #
> # reducing it to a single value. For example, compute a#
> # factorial with a series of multiply operations:  #
> #  #
> # py> n = 4#
> # py> import operator  #
> # py> reduce(operator.mul, range(1, n+1))  #
> # 24   #
> 

> How exactly does: assigning variables(n = 4),
> arithmetic(n+1), and the "range" function going to help me
> understand the usefulness of the reduce function?

Obviously they don't, duh. They're mere incidentals.


> A much better example would be:
> 
> py> import operator
> py> reduce(operator.mul, [1,2,3,4])
> 24

"But Rick, my o-so-wise teacher, what's this stuff with the square brackets
and commas? And the round brackets (or parentheses as the Americans call
them)?"

At the point you are demonstrating reduce(), if the reader doesn't
understand or can't guess the meaning of "n = 4", "n+1" or range(), they
won't understand anything you say.

Teachers need to understand that education is a process of building upon
that which has come before. If the teacher talks down to the student by
assuming that the student knows nothing, and tries to go back to first
principles for every little thing, they will never get anywhere.

In this case, it is perfectly acceptable to assume that by the time the
beginner gets to a document about "Dos and Don'ts" they are comfortable
with such basic concepts as assigning values to variables "n=4",
addition "n+1", importing, and can interpret from the context that
operator.mul multiplies without needing to be explicitly told.

If you treat your readers as idiots, only idiots will read your writing.


> At *LEAST* with that example the only potential unknown
> might be "operator.mul". However, a wise teacher would
> recognize that this is a fine "teaching example" of how
> using the operator module can prevent duplicating code --

And the version on the docs demonstrates this by example, instead of
patronising the reader and treating them as an eight year old who needs to
have the most trivial things explained to them.


> which would lead to a better example like:
> 
> py> def mul(x, y):
> ... return x*y
> py> reduce(mul, [1,2,3,4])
> 24

"But Rick, my o-so-wise teacher! What is the meaning of 'def', 'return' and
the asterisk between the x and y? What's with the three dots and the
spaces?"



> FINALLY! An example that showcases a proper usage of the
> the reduce function *WITHOUT* any superfluous distractions.

Apart from having to define your own function. Given that this is a document
intended to show-case best practice (as in Do this, Don't do that) it is
completely inappropriate to encourage the reader to re-invent the wheel by
creating their own (slow) mul function instead of importing the (fast)
pre-built one in the operator module.


> However, 
> remembering that code re-use is a good thing, and that re-
> inventing the wheel is a lot of work, we should mention that
> the "mul" function should be replaced with "operator.mul"

No, we should not "mention" it as an aside. We should demonstrate best
practice from the start. Unless you are writing for beginners who haven't
been introduced to importing yet (in which case, why are you teaching them
reduce() so early?) there is no benefit at all in showing people how *not*
to do it, then jokingly give them a little nudge-nudge-wink-wink "by the
way, this is better" aside.


> Note: Be sure to check out the "operator" module for
> pre-defined arithmetic functions like "operator.mul",
> which would "reduce" (*wink*) the above code to this:
> 
> py> reduce(operator.mul, [1,2,3,4])
> 24
> 
> 
> 
> EXAMPLE 2: "The Fibonacci Phallus Extender".


And that's where I stopped reading. I'm sure it will be overflowing with
insights of your usual quality, but I hurt myself laughing so hard at your
wit ("ha ha, phallus, that means the D") that I simply couldn't continue.



-- 
Steven

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


Re: Syntax error

2015-01-10 Thread Steven D'Aprano
Abdul Abdul wrote:

> Hello,
> 
> I have the following program that employs the dcm2jpg.exe software:
> 
> import os
> os.system(“dcm2jpg.exe IM-0004-0004.dcm”)
> exit
> 
> When I tried to run it, I got the following error:
> 
> SyntaxError: Non-ASCII character '\xe2' in file dicomjpg.py on line 2, but
> no en
> coding declared; see http://python.org/dev/peps/pep-0263/ for details
> 
> Why is that? 

You have curly quotes “” instead of typewriter quotes "" in your source
code.


> How can this error be solved? 

Don't use Microsoft Office to write code. Use a programmer's text editor:


https://duckduckgo.com/?q=python+text+editors

If you absolutely must use MS Office, turn "Smart Quotes" off.



-- 
Steven

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


Help running python tests on MIPS

2015-01-10 Thread Ramesh
I am new to python.

I downloaded python 2.7.8 tarball, successfully cross compiled it, to make sure 
that the subsystems are correctly built, I tried running the python test 
scripts on the MIPS based target board. I hit the below error while I do so,

==
# /opt/Python-2.7.8/bin/python2.7 /opt/Python-2.7.8/lib/python2.7/test/test___al
l__.py
Traceback (most recent call last):
  File "/opt/Python-2.7.8/lib/python2.7/test/test___all__.py", line 3, in 

import unittest
  File "/opt/Python-2.7.8/lib/python2.7/unittest/__init__.py", line 58, in 

from .result import TestResult
  File "/opt/Python-2.7.8/lib/python2.7/unittest/result.py", line 9, in 
from . import util
  File "/opt/Python-2.7.8/lib/python2.7/unittest/util.py", line 2, in 
from collections import namedtuple, OrderedDict
  File "/opt/Python-2.7.8/lib/python2.7/collections.py", line 8, in 
from _collections import deque, defaultdict
ImportError: No module named _collections
# 
===

I tried setting PATH & PYTHONPATH, but it doesn't seem to fix the issue. Can 
someone please advice on what possibly is causing this problem / how to fix 
this?

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


Re: Generate jpg files using line length (pixels) and orientation (degrees)

2015-01-10 Thread Denis McMahon
On Fri, 09 Jan 2015 09:49:25 -0800, semeon.risom wrote:

> Thank you for the help btw. I think I'm close to a solution, but I'm
> having issue feeding the coordinates from my csv file into the formula.
> 
> This is the error I get:
> Traceback (most recent call last):
>   File "C:\Users\Owner\Desktop\Stimuli Generation\Coordinates\Generate_w
>   corr.py", line 68, in 
> makeimg(length, orientation)
>   File "C:\Users\Owner\Desktop\Stimuli Generation\Coordinates\Generate_w
>   corr.py", line 40, in makeimg
> orientation = orientation % 180
> TypeError: unsupported operand type(s) for %: 'list' and 'int'
 
 
> and here's the code:
> 
> from PIL import Image, ImageDraw from numpy import math
> 
> # import csv import csv f = open('C:\Users\Owner\DesktopStimuli
> Generation\Coordinates\file.csv', 'rb')
> rdr = csv.reader(f)
> f.seek(0)
> i = 0 a = []
> b = []
> for row in rdr:
> a.append(row[0]) 
> b.append(row[1])

This makes a and b both lists

Having read some other errors that you are having, you need to make sure 
that these items are numeric and not string data

for row in rdr:
a.append(int(row[0]))
b.append(int(row[1]))

> # using lists of values for length in [a]:
> for orientation in [b]:
> makeimg(length, orientation)

This puts list a inside another list, and puts list b inside another 
list, and then passes the whole of lists a and b in the first call to 
makeimg.

makeimg expects 2 integer parameters on each call, not two lists!

As you have already created lists, you don't need to wrap them inside 
another list.

# using lists of values 
for length in a:
for orientation in b:
makeimg(length, orientation)

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


Re: Can numpy do better than this?

2015-01-10 Thread Nobody
On Thu, 08 Jan 2015 09:56:50 -0800, Rustom Mody wrote:

> Given a matrix I want to shift the 1st column 0 (ie leave as is) 2nd by
> one place, 3rd by 2 places etc.
> 
> This code works.
> But I wonder if numpy can do it shorter and simpler.

def shiftcols(mat):
iy,ix = np.indices(mat.shape)
return mat[(iy+ix)%mat.shape[0],ix]

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


Re: PyWart: Poor Documentation Examples

2015-01-10 Thread Rustom Mody
On Sunday, January 11, 2015 at 8:02:50 AM UTC+5:30, Steven D'Aprano wrote:
> Rick Johnson wrote:
> 
> 
> > 
> > EXAMPLE 1: "Reducing Comprehension"
> > https://docs.python.org/2/howto/doanddont.html#using-the-batteries
> > 
> > 
> > 
> > 
> > #QUOTE: Python Docs#
> > 
> > # Another highly useful function is reduce() which can be  #
> > # used to repeatly apply a binary operation to a sequence, #
> > # reducing it to a single value. For example, compute a#
> > # factorial with a series of multiply operations:  #
> > #  #
> > # py> n = 4#
> > # py> import operator  #
> > # py> reduce(operator.mul, range(1, n+1))  #
> > # 24   #
> > 
> 
> > How exactly does: assigning variables(n = 4),
> > arithmetic(n+1), and the "range" function going to help me
> > understand the usefulness of the reduce function?
> 
> Obviously they don't, duh. They're mere incidentals.
> 
> 
> > A much better example would be:
> > 
> > py> import operator
> > py> reduce(operator.mul, [1,2,3,4])
> > 24
> 
> "But Rick, my o-so-wise teacher, what's this stuff with the square brackets
> and commas? And the round brackets (or parentheses as the Americans call
> them)?"
> 
> At the point you are demonstrating reduce(), if the reader doesn't
> understand or can't guess the meaning of "n = 4", "n+1" or range(), they
> won't understand anything you say.
> 
> Teachers need to understand that education is a process of building upon
> that which has come before. If the teacher talks down to the student by
> assuming that the student knows nothing, and tries to go back to first
> principles for every little thing, they will never get anywhere.
> 
> In this case, it is perfectly acceptable to assume that by the time the
> beginner gets to a document about "Dos and Don'ts" they are comfortable
> with such basic concepts as assigning values to variables "n=4",
> addition "n+1", importing, and can interpret from the context that
> operator.mul multiplies without needing to be explicitly told.
> 
> If you treat your readers as idiots, only idiots will read your writing.
> 
> 
> > At *LEAST* with that example the only potential unknown
> > might be "operator.mul". However, a wise teacher would
> > recognize that this is a fine "teaching example" of how
> > using the operator module can prevent duplicating code --
> 
> And the version on the docs demonstrates this by example, instead of
> patronising the reader and treating them as an eight year old who needs to
> have the most trivial things explained to them.
> 
> 
> > which would lead to a better example like:
> > 
> > py> def mul(x, y):
> > ... return x*y
> > py> reduce(mul, [1,2,3,4])
> > 24
> 
> "But Rick, my o-so-wise teacher! What is the meaning of 'def', 'return' and
> the asterisk between the x and y? What's with the three dots and the
> spaces?"
> 
> 
> 
> > FINALLY! An example that showcases a proper usage of the
> > the reduce function *WITHOUT* any superfluous distractions.
> 
> Apart from having to define your own function. Given that this is a document
> intended to show-case best practice (as in Do this, Don't do that) it is
> completely inappropriate to encourage the reader to re-invent the wheel by
> creating their own (slow) mul function instead of importing the (fast)
> pre-built one in the operator module.
> 
> 
> > However, 
> > remembering that code re-use is a good thing, and that re-
> > inventing the wheel is a lot of work, we should mention that
> > the "mul" function should be replaced with "operator.mul"
> 
> No, we should not "mention" it as an aside. We should demonstrate best
> practice from the start. Unless you are writing for beginners who haven't
> been introduced to importing yet (in which case, why are you teaching them
> reduce() so early?) there is no benefit at all in showing people how *not*
> to do it, then jokingly give them a little nudge-nudge-wink-wink "by the
> way, this is better" aside.
> 
> 
> > Note: Be sure to check out the "operator" module for
> > pre-defined arithmetic functions like "operator.mul",
> > which would "reduce" (*wink*) the above code to this:
> > 
> > py> reduce(operator.mul, [1,2,3,4])
> > 24
> > 
> > 
> > 
> > EXAMPLE 2: "The Fibonacci Phallus Extender".
> 
> 
> And that's where I stopped reading. I'm sure it will be overflow

Re: PyWart: Poor Documentation Examples

2015-01-10 Thread Devin Jeanpierre
On Sat, Jan 10, 2015 at 6:32 PM, Steven D'Aprano
 wrote:
> At the point you are demonstrating reduce(), if the reader doesn't
> understand or can't guess the meaning of "n = 4", "n+1" or range(), they
> won't understand anything you say.
>
> Teachers need to understand that education is a process of building upon
> that which has come before. If the teacher talks down to the student by
> assuming that the student knows nothing, and tries to go back to first
> principles for every little thing, they will never get anywhere.

Agree wholeheartedly. That said, I do think reduce(operator.mul, [1,
2, 3, 4]) actually _is_ a better example, since it cuts right to the
point.

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


Re: PyWart: Poor Documentation Examples

2015-01-10 Thread Ethan Furman
On 01/10/2015 06:32 PM, Steven D'Aprano wrote:
> 
> If you treat your readers as idiots, only idiots will read your writing.

Or the morbidly curious, which I presume covers your case (along with a handful 
of others ;) .

--
~Ethan~



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list