Re: I'm a newbie and I'm still stumped...

2015-08-03 Thread Dwight GoldWinde
Thank you, Emile, Paul, Terry, and Joel for your suggestions! And the
error persists.

Maybe my error is coming from running the old version (2.7.6) of Python,
but I can’t figure out why that would be happening???

I downloaded 3.4.3 again from the Python.org website for my Mac.
I inserted the "import sys" and did “print (sys.version)” into the code.

So here what the code is:

#!/usr/bin/env python3
import sys
print (sys.version)
word = input('Enter a word ')


Here are the results I got below, showing the same error. The first line
says, 
"2.7.6 (default, Sep 9 2014, 15:04:36)”. Does that mean I am running the
old Python? How could that be since I am SURE I downloaded 3.4.3 (it even
gives the folder name as “Python 3.4” in the Applications folder on my Mac.

2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
Enter a word serendipity
Traceback (most recent call last):
  File "test short.py", line 4, in 
word = input('Enter a word ')
  File "", line 1, in 
NameError: name 'serendipity' is not defined




Please help…

BIG SMILE...

Always, Dwight


www.3forliving.key.to (video playlist on YouTube)
www.couragebooks.key.to (all my books on Amazon)






#!/usr/bin/env python3
import sys
print (sys.version)
word = input('Enter a word ')


2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
Enter a word serendipity
Traceback (most recent call last):
  File "test short.py", line 3, in 
word = input('Enter a word ')
  File "", line 1, in 
NameError: name 'serendipity' is not defined





On 8/2/15, 12:30 AM, "Emile van Sebille"  wrote:

>On 7/30/2015 6:22 PM, Dwight GoldWinde wrote:
>> I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner
>>2 as
>> my editor.
>>
>> Here¹s the code:
>> #!/usr/bin/env python3
>> word = (input('Enter a word Œ))
>>
>> When running this inside of Coderunner, I get the follow error, after
>> entering the word Œserendipity¹:
>>
>> Enter a word serendipity
>> Traceback (most recent call last):
>>File "test short.py", line 2, in 
>>  word = (input('Enter a word '))
>>File "", line 1, in 
>> NameError: name 'serendipity' is not defined
>
>I'd look at which python is actually running (sys.version):
>
>Python 3.4.0 (default, Apr 11 2014, 13:05:11)
>[GCC 4.8.2] on linux
>Type "help", "copyright", "credits" or "license" for more information.
> >>> word = (input('enter a word '))
>enter a word test
> >>>
>emile@emile-OptiPlex-9010:~$ 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.
> >>> word = (input('enter a word '))
>enter a word test
>Traceback (most recent call last):
>
>
>Emile
>   File "", line 1, in 
>   File "", line 1, in 
>NameError: name 'test' is not defined
> >>>
>
>
>
>-- 
>https://mail.python.org/mailman/listinfo/python-list


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


Re: I'm a newbie and I'm still stumped...

2015-08-03 Thread Paul Rubin
Dwight GoldWinde  writes:
> word = input('Enter a word ')

Use raw_input instead of input.  In python 2.x, input treats the stuff
you enter as a Python expression instead of a string.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and I'm still stumped...

2015-08-03 Thread Dave Farrance
Dwight GoldWinde  wrote:

>Here are the results I got below, showing the same error. The first line
>says, 
>"2.7.6 (default, Sep 9 2014, 15:04:36)”. Does that mean I am running the
>old Python? How could that be since I am SURE I downloaded 3.4.3 (it even
>gives the folder name as “Python 3.4” in the Applications folder on my Mac.

Yes, that's Python2.  I've never used MAC OS, but I understand that it
has the BASH shell, so you can use "which" try to figure out where
python is being found on the path:

$ echo $PATH

$ which python

Use the above to also check for the position of python2 and python3.

You can check for aliases and links with the "type" and "file" commands.
Do this for python, python2 and python3:

$ type $(which python)

$ file $(which python)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and I'm still stumped...

2015-08-03 Thread Dwight GoldWinde


On 8/3/15, 4:55 PM, "Dwight GoldWinde"  wrote:

>Okay, thank you, Dave, so I got the following info:
>type $(which python3)
>/Library/Frameworks/Python.framework/Versions/3.4/bin/python3 is
>/Library/Frameworks/Python.framework/Versions/3.4/bin/python3
>
>
>But I can¹t figure out what short of ³usr² statement (e.g. #!/usr/bin/env
>python3) I need to point it there. Whatever I tried, still gives me
>version 2.
>
>???
>
>Dwight
>
>On 8/3/15, 4:27 PM, "Dave Farrance"  wrote:
>
>>Dwight GoldWinde  wrote:
>>
>>>Here are the results I got below, showing the same error. The first line
>>>says, 
>>>"2.7.6 (default, Sep 9 2014, 15:04:36)². Does that mean I am running the
>>>old Python? How could that be since I am SURE I downloaded 3.4.3 (it
>>>even
>>>gives the folder name as ³Python 3.4² in the Applications folder on my
>>>Mac.
>>
>>Yes, that's Python2.  I've never used MAC OS, but I understand that it
>>has the BASH shell, so you can use "which" try to figure out where
>>python is being found on the path:
>>
>>$ echo $PATH
>>
>>$ which python
>>
>>Use the above to also check for the position of python2 and python3.
>>
>>You can check for aliases and links with the "type" and "file" commands.
>>Do this for python, python2 and python3:
>>
>>$ type $(which python)
>>
>>$ file $(which python)
>>-- 
>>https://mail.python.org/mailman/listinfo/python-list


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


Re: I'm a newbie and I'm still stumped...

2015-08-03 Thread Jussi Piitulainen
Dwight GoldWinde quotes himself:
>
>> Okay, thank you, Dave, so I got the following info: type $(which
>> python3)
>> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 is
>> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
>>
>> But I can¹t figure out what short of ³usr² statement
>> (e.g. #!/usr/bin/env python3) I need to point it there. Whatever I
>> tried, still gives me version 2.

How are you launching your script? If your method involves clicking some
pretty picture or something similar, you may be bypassing /usr/bin/env
altogether and relying on some association of file types in Mac OS. Then
you need to investigate file properties in Finder, or something like
that. It should be safe to change the association for that individual
script but not necessarily for all files with the same extension.

If your method is to type "python scriptname" at the shell prompt, you
are definitely bypassing /usr/bin/env and specifying the default python
as the one to use. Solution: type "python3 scriptname" instead. (A more
advanced solution: make scriptname executable and type "./scriptname"
instead. This one uses /usr/bin/env to find the interpreter.)

(You could try "#!/usr/bin/env aintgotnosuch" as your script's hashbang
line to see if it even matters what that line says. Check first that you
don't happen to have a program named "aintgotnosuch" in your path.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 May Become Relevant Now

2015-08-03 Thread Jean-Michel Pichavant
- Original Message -
> From: "Mark Lawrence" 
> To: python-list@python.org
> Sent: Monday, 3 August, 2015 2:25:08 AM
> Subject: Python 3 May Become Relevant Now
> 
> rr should have a field day with this one
> http://nafiulis.me/python-3-may-become-relevant-now.html
> 
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

"The problem was with a function (buried deep in the source code as one of many 
decorators) that usually returned a  list  but under a certain circumstances, 
it returned  None" [...] "I'm not saying that the person who originally wrote 
the code is a bad programmer. I'll leave that up to you. What I am saying is 
that python allows you to make such silly mistakes."


I do this all the time ... :(

Well not exactly, with lists I'm trying to return an empty list but I may 
return None in certain situations, most of the time when a method cannot do its 
job because of missing data but this particular method does not know if it's 
expected or not, so it returns "None" like to tell the caller, "can't do it, 
deal with it".

I really prefer to handle errors with a :

if foo() is not None:
  ...


than a try expect stupid block.

But if I get things right, with python 3.5 type hint checker, I'd be screwed, 
as it is spefificaly designed to track this kind of "problem".
What's the use of None then ? Any method returning None can only return None or 
suffer the type checker retribution.

I don't get it.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 May Become Relevant Now

2015-08-03 Thread Ian Kelly
On Mon, Aug 3, 2015 at 1:58 AM, Jean-Michel Pichavant
 wrote:
> But if I get things right, with python 3.5 type hint checker, I'd be screwed, 
> as it is spefificaly designed to track this kind of "problem".
> What's the use of None then ? Any method returning None can only return None 
> or suffer the type checker retribution.
>
> I don't get it.

This is where you would use optional types. Optional[List[X]] is a
shorthand for the type Union[List[X], None].

In fact static type checking can be quite useful in this sort of case.
If you return Optional[List[X]] in one place, and you have some other
method that takes in the value but simply indicates that it takes
List[X], then the static checker will flag that as an error, and
you'll know that a part of your code likely isn't handling the None
case correctly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 May Become Relevant Now

2015-08-03 Thread Chris Angelico
On Mon, Aug 3, 2015 at 7:58 PM, Jean-Michel Pichavant
 wrote:
> But if I get things right, with python 3.5 type hint checker, I'd be screwed, 
> as it is spefificaly designed to track this kind of "problem".
> What's the use of None then ? Any method returning None can only return None 
> or suffer the type checker retribution.

1) Python 3.5 will not include a type checker. All it'll include is
enough stubs that your code will run correctly; plus it has a set of
specifications for how third-party checkers should be advised, which
means you'll be able to use any such checker with the same code. But
nothing will happen till you actually run such a checker.

2) Since "returns X or None" is such a common thing, it's very easy to
spell. More complicated things are possible, too, but less cleanly.
Python still allows you to return anything from anything, and that
isn't changing; but there are a number of common cases - for instance,
this function might always return a number, or maybe it'll always
return a dictionary that maps strings to integers. Those are easily
spelled.

So no, a method that can return None is most definitely *not* required
to return None in all cases. Although you may find that some linters
and code style guides object to code like this:

def some_function(some_arg):
if some_condition:
return some_expression

where one branch has an explicit 'return' and another doesn't. That's
a quite reasonable objection, and an explicit "return None" at the end
will suppress the warning, by being more explicit that this might
return this or that.

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


Optimal solution for coloring logging output

2015-08-03 Thread c.buhtz
I don't want to ask how to do this because there are so many
"solutions" about it.


There are so much different and part of unpythontic solutions I can not
decide myself. What do you (as real pythontics) think about that.
Which of the solutions fit to concepts of Python and its logging
package?

Coloring means here not only the message itself. The (levelname) should
be included in the coloring.
For myself coloring the (levelname) would be enough to avoid to much
color in the output.

1.
The solution itself shouldn't care about plattform differences because
there are still some packages which are able to offer
plattform-independent console-coloring. Which would you prefere? ;)

2.
Some solutions derive from StreamHandler or much more bad hacking the
emit() function. I think both of them are not responsible for how the
output should look or be presented.

3.
How to present the output is IMO the responsibility of a Formater, isn't
it? So I should derive from the Formater.

What do you as Pythonics think of that? ;)
-- 
-BEGIN PGP PUBLIC KEY BLOCK-
Version: GnuPG v1

mQENBFQIluABCACfPwAhRAwFD3NXgv5CtVUGSiqdfJGVViVBqaKd+14E0pASA0MU
G0Ewj7O7cGy/ZIoiZ0+lIEZmzJKHfuGwYhXjR/PhnUDrQIHLBvh9WuD6JQuULXfH
kXtVm/i9wm76QAcvr2pwYgNzhcJntUHl2GcgnInYbZDeVmg+p9yIPJjuq73/lRS3
0/McgNoFOBhKK/S6STQuFyjr9OyJyYd1shoM3hmy+kg0HYm6OgQBJNg92WV9jwGe
GzlipvEp2jpLwVsTxYir2oOPhfd9D1fC9F/l/3gXbfjd5GIIVrZFq2haZmoVeJ33
LJxo3RA5Tf9LoUeels1b4s9kFz6h7+AHERUpABEBAAG0IUNocmlzdGlhbiBCdWh0
eiA8YnVodHpAcG9zdGVvLmRlPokBPgQTAQIAKAUCVAiW4AIbAwUJAeEzgAYLCQgH
AwIGFQgCCQoLBBYCAwECHgECF4AACgkQZLsXsAdRqOxNUAf/V/hDA5zGDpySuCEj
DhjiVRK74J9Wd8gfH0WAf1Co5HZ24wZH8rgOIVIgXw8rWkOw/VA6xfdfT+64xjTY
Fhkpbrk199nDzp72F7Jc4NC+x8xac2e3rK5ifSWhZx7L5A32pGYE+d16m3EEqImK
D4gcZl38x9zdUnD4hHyXkIPz1uCfuMuGgWEnaUk4Wbj41CBZr3O0ABue6regV15U
jaes8r+B8iCcY+0yP2kse+3iaCaMqNv5FgQZ9+b2Cql8pFkZJVtBVUw4GW3DWZJi
du0O/YrC9TgS+xY9ht/MD2qSHwjcK1sdImjqBO7xP8TIOwKeYyDvGKnSO3EJ/sSA
UPGEPrkBDQRUCJbgAQgA0k/Qg67CCUJE2/zuxBEoK4wLJpDRJzh8CQPZpjWx8VP0
KL892jwfxymXn8KNhuy1SgCBFSeV9jg4VZNWDlUGJc2lo82ajr9PzIsrQwu4lf0B
zrUWV5hWepKu/kb8uSjx58YYfx0SFz4+9akX3Wwu9TUHntzL5Gk3Q26nnsr1xEJ+
VEumvCH9AE0Tk0K7dQpJ2/JcLuO+uhrpd/lHFDYVN5NsG3P015uFOkDI6N/xNFCj
v95XNR93QlfKpK3qWlFGescfG+o/7Ub6s67/i/JoNbw0XgPEHmQfXpD7IHO4cu+p
+ETb11cz+1mmi96cy98ID+uTiToJ8G//yD9rmtyxoQARAQABiQElBBgBAgAPBQJU
CJbgAhsMBQkB4TOAAAoJEGS7F7AHUajs6sQH/iKs6sPc0vkRJLfbwrijZeecwCWF
blo/jzIQ8jPykAj9SLjV20Xwqg3XcJyko8ZU6/zuRJq9xjlv9pZr/oVudQAt6v+h
2Cf4rKEjmau483wjMV2xjTXQhZi9+ttDbia4fgdmGtKsOicn5ae2fFXcXNPu3RiW
sZKifWdokA6xqMW6iIG9YjjI5ShxngHWp2xfPscBFMDRtFOMags/Yx+YvwoyEZ4A
dURYMFHFqpwILEc8hIzhRg1gq40AHbOaEdczS1Rr3T7/gS6eBs4u6HuY5g2Bierm
lLjpspFPjMXwJAa/XLOBjMF2vsHPrZNcouNKkumQ36yq/Pm6DFXAseQDxOk=
=PGP9
-END PGP PUBLIC KEY BLOCK-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and you helped me find the answer...

2015-08-03 Thread Dwight Hotmail
Thank you, Jussi.

Problem finally solved.

I am using Coderunner 2 as my editor. It has a language setting. I had set
it as Python instead of Python 3.

Duh!

Thank you again, everyone!


With appreciation,

Dwight

dwi...@goldwinde.com
www.goldwinde.com

Author of the book, "Courage: the Choice that Makes the Difference--Your
Key to a Thousand Doors"

You can find all my books at http://www.couragebooks.key.to/

1-206-923-9554 (USA Telephone)
1-206-350-0129 (voice mail and fax U.S.A.)
86-153-9867-5712 (China Telephone)
goldwindedwight (Skype)
goldwinde (Wechat)
+8615398675712 (Whatsapp)
www.3forliving.key.to (daily living video playlist)
http://www.couragebooks.key.to/ (my books)



On 8/3/15, 5:49 PM, "Jussi Piitulainen"  wrote:

>Dwight GoldWinde quotes himself:
>>
>>> Okay, thank you, Dave, so I got the following info: type $(which
>>> python3)
>>> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 is
>>> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
>>>
>>> But I can¹t figure out what short of ³usr² statement
>>> (e.g. #!/usr/bin/env python3) I need to point it there. Whatever I
>>> tried, still gives me version 2.
>
>How are you launching your script? If your method involves clicking some
>pretty picture or something similar, you may be bypassing /usr/bin/env
>altogether and relying on some association of file types in Mac OS. Then
>you need to investigate file properties in Finder, or something like
>that. It should be safe to change the association for that individual
>script but not necessarily for all files with the same extension.
>
>If your method is to type "python scriptname" at the shell prompt, you
>are definitely bypassing /usr/bin/env and specifying the default python
>as the one to use. Solution: type "python3 scriptname" instead. (A more
>advanced solution: make scriptname executable and type "./scriptname"
>instead. This one uses /usr/bin/env to find the interpreter.)
>
>(You could try "#!/usr/bin/env aintgotnosuch" as your script's hashbang
>line to see if it even matters what that line says. Check first that you
>don't happen to have a program named "aintgotnosuch" in your path.)
>-- 
>https://mail.python.org/mailman/listinfo/python-list


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


FW: I'm a newbie and I'm still stumped...

2015-08-03 Thread Dwight Hotmail
On 8/3/15, 4:07 PM, "Dwight GoldWinde"  wrote:

>Thank you, Paul.
>
>But does this mean I am not using Python 3.4?
>
>BIG SMILE...
>
>Always, Dwight
>
>
>www.3forliving.key.to (video playlist on YouTube)
>www.couragebooks.key.to (all my books on Amazon)
>
>
>
>
>
>
>On 8/3/15, 3:14 PM, "Paul Rubin"  wrote:
>
>>Dwight GoldWinde  writes:
>>> word = input('Enter a word ')
>>
>>Use raw_input instead of input.  In python 2.x, input treats the stuff
>>you enter as a Python expression instead of a string.
>>-- 
>>https://mail.python.org/mailman/listinfo/python-list


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


Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Joonas Liik
I have this feeling that you would get a lot more useful anwsers if
you were to describe your actual problem in stead of what you think
the solution is. There might be other, better solutions but since we
know so little about what you are doing we will likely never find them
by just guessing..
-- 
https://mail.python.org/mailman/listinfo/python-list


how to determine for using c extension or not ?

2015-08-03 Thread umedoblock
Hello everyone.

I use bisect module.
bisect module developer give us c extension as _bisect.

If Python3.3 use _bisect, _bisect override his functions in bisect.py.

now, I use id() function to determine for using c extension or not.

>>> >>> import bisect
>>> >>> id(bisect.bisect)
139679893708880
>>> >>> import _bisect
>>> >>> id(_bisect.bisect)
139679893708880

they return 139679893708880 as id.
so i believe that i use c extension.

My check is correct ? right ?
or you have more good idea ?
-- 
https://mail.python.org/mailman/listinfo/python-list


how to determine for using c extension or not ?

2015-08-03 Thread Hideyuki YASUDA
Hello everyone.

I use bisect module.
bisect module developer give us c extension as _bisect.

If Python3.3 use _bisect, _bisect override his functions in bisect.py.

now, I use id() function to determine for using c extension or not.

>>> import bisect
>>> id(bisect.bisect)
139679893708880
>>> import _bisect
>>> id(_bisect.bisect)
139679893708880

they return 139679893708880 as id.
so i believe that i use c extension.

My check is correct ? right ?
or you have more good idea ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Optimal solution for coloring logging output

2015-08-03 Thread Jean-Michel Pichavant
 Original Message -
> From: "c buhtz" 
> To: python-list@python.org
> Sent: Monday, 3 August, 2015 11:13:37 AM
> Subject: Optimal solution for coloring logging output
> 
> I don't want to ask how to do this because there are so many
> "solutions" about it.
> 
> 
> There are so much different and part of unpythontic solutions I can
> not
> decide myself. What do you (as real pythontics) think about that.
> Which of the solutions fit to concepts of Python and its logging
> package?
> 
> Coloring means here not only the message itself. The (levelname)
> should
> be included in the coloring.
> For myself coloring the (levelname) would be enough to avoid to much
> color in the output.
> 
> 1.
> The solution itself shouldn't care about plattform differences
> because
> there are still some packages which are able to offer
> plattform-independent console-coloring. Which would you prefere? ;)
> 
> 2.
> Some solutions derive from StreamHandler or much more bad hacking the
> emit() function. I think both of them are not responsible for how the
> output should look or be presented.
> 
> 3.
> How to present the output is IMO the responsibility of a Formater,
> isn't
> it? So I should derive from the Formater.
> 
> What do you as Pythonics think of that? ;)

This is more or less how it could be done:

1/ use the module "curses" to get terminal colors (the doc suggests to use the 
"Console" moduel on windows)
2/ write a logging Formatter that will replace DEBUG/INFO/ERROR message by 
their colored version.


import curses
import logging
import string
import re

curses.setupterm()
class ColorFormat:
#{ Foregroung colors
BLACK = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_BLACK)
RED = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_RED)
GREEN = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_GREEN)
YELLOW = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_YELLOW)
BLUE = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_BLUE)
MAGENTA = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_MAGENTA)
CYAN = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_CYAN)
WHITE = curses.tparm(curses.tigetstr('setaf'), 9) # default white is 7, 
the 9 is a better white
#{ Backgrounds colors
BG_BLACK = curses.tparm(curses.tigetstr('setab'), curses.COLOR_BLACK)
BG_RED = curses.tparm(curses.tigetstr('setab'), curses.COLOR_RED)
BG_GREEN = curses.tparm(curses.tigetstr('setab'), curses.COLOR_GREEN)
BG_YELLOW = curses.tparm(curses.tigetstr('setab'), curses.COLOR_YELLOW)
BG_BLUE = curses.tparm(curses.tigetstr('setab'), curses.COLOR_BLUE)
BG_MAGENTA = curses.tparm(curses.tigetstr('setab'), 
curses.COLOR_MAGENTA)
BG_CYAN = curses.tparm(curses.tigetstr('setab'), curses.COLOR_CYAN)
BG_WHITE = curses.tparm(curses.tigetstr('setab'), curses.COLOR_WHITE) 
#{ Format codes
BOLD = curses.tparm(curses.tigetstr('bold'), curses.A_BOLD)
UNDERLINE = curses.tparm(curses.tigetstr('smul'), curses.A_UNDERLINE)
BLINK = curses.tparm(curses.tigetstr('blink'), curses.A_BLINK)
NO_FORMAT = curses.tparm(curses.tigetstr('sgr0'), curses.A_NORMAL)
NO_COLOR = curses.tigetstr('sgr0')
#}

def setFormat(attributeList):
_set = '' # avoid collision with the builtin set type
for attribute in attributeList:
_set += getattr(ColorFormat, attribute, '')
return _set

class ColorFormatter(logging.Formatter):
def format(self, record):
parameters = record.__dict__.copy()
parameters['message'] = record.getMessage()

# 
--
# Log Level Format : %(levelname)
# 
--
fmt = self._fmt
pattern = r'(%\(levelname\)(?:-?\d+)?s)'
if record.levelno <= logging.DEBUG:
fmt = re.sub(pattern, setFormat(['BLUE']) + r'\1' + 
 setFormat(['NO_COLOR']), fmt)
elif record.levelno <= logging.INFO:
fmt = re.sub(pattern, setFormat(['CYAN']) + r'\1' + 
 setFormat(['NO_COLOR']), fmt)
elif record.levelno <= logging.WARNING:
fmt = re.sub(pattern, setFormat(['MAGENTA']) + r'\1' + 
 setFormat(['NO_COLOR']), fmt)
elif record.levelno <= logging.ERROR:
fmt = re.sub(pattern, setFormat(['RED','BOLD']) + r'\1' 
+ 
 setFormat(['NO_COLOR']), fmt)
else:
 

Re: Optimal solution for coloring logging output

2015-08-03 Thread Karim



On 03/08/2015 14:47, Jean-Michel Pichavant wrote:

te a logging Formatter that will re

Thank you Jean-Michel useful example

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


how to determine for using c extension or not ?

2015-08-03 Thread umedoblock
Hello everyone.

I use bisect module.
bisect module developer give us c extension as _bisect.

If Python3.3 use _bisect, _bisect override his functions in bisect.py.

now, I use id() function to determine for using c extension or not.

>>> import bisect
>>> id(bisect.bisect)
139679893708880
>>> import _bisect
>>> id(_bisect.bisect)
139679893708880

they return 139679893708880 as id.
so i believe that i use c extension.

My check is correct ? right ?
or you have more good idea ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to determine for using c extension or not ?

2015-08-03 Thread Joel Goldstick
On Mon, Aug 3, 2015 at 9:08 AM, umedoblock  wrote:
> Hello everyone.
>
> I use bisect module.
> bisect module developer give us c extension as _bisect.
>
> If Python3.3 use _bisect, _bisect override his functions in bisect.py.
>
> now, I use id() function to determine for using c extension or not.
>
 import bisect
 id(bisect.bisect)
> 139679893708880
 import _bisect
 id(_bisect.bisect)
> 139679893708880
>
> they return 139679893708880 as id.
> so i believe that i use c extension.
>
> My check is correct ? right ?
> or you have more good idea ?
> --
> https://mail.python.org/mailman/listinfo/python-list

I don't know the answer to your question, but repeating it will not
help you get an answer more quickly.  This is a voluntary mailing
list.  If someone can help you, you will probably see a response
within a few hours or a few days.

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


Re: how to determine for using c extension or not ?

2015-08-03 Thread Skip Montanaro
id() tells you nothing about the nature of the function. Use the
inspect.isbuiltin():

>>> import bisect
>>> bisect.bisect

>>> import inspect
>>> def foo(): pass
...
>>> inspect.isbuiltin(foo)
False
>>> inspect.isbuiltin(bisect.bisect)
True

It's perhaps a bit poorly named, but "builtin" functions are those not
written in Python. That is, those written in C or C++.

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


Re: how to determine for using c extension or not ?

2015-08-03 Thread Steven D'Aprano
On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote:

> Hello everyone.
> 
> I use bisect module.

You asked the same question FOUR times. Have patience. Your question goes
all over the world, people may be asleep, or working, or just not know the
answer. If you ask a question, and get no answers, you should wait a full
day before asking again.


> bisect module developer give us c extension as _bisect.
> 
> If Python3.3 use _bisect, _bisect override his functions in bisect.py.

So does Python 2.7.


> now, I use id() function to determine for using c extension or not.

The id() function doesn't tell you where objects come from or what language
they are written in. But they will tell you if two objects are the same
object.

 import bisect
 id(bisect.bisect)
> 139679893708880
 import _bisect
 id(_bisect.bisect)
> 139679893708880
> 
> they return 139679893708880 as id.
> so i believe that i use c extension.

Correct.

Also, you can do this:


py> import bisect
py> bisect.__file__ 
'/usr/local/lib/python2.7/bisect.pyc'
py> bisect.bisect.__module__  # Where does the bisect file come from?
'_bisect'
py> import _bisect
py> _bisect.__file__
'/usr/local/lib/python2.7/lib-dynload/_bisect.so'

So you can see that _bisect is a .so file (on Linux; on Windows it will be
a .dll file), which means written in C.


-- 
Steven

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


Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Steven D'Aprano
On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote:

> Well, I have at least some non-zero chance of reading and writing JSON
> or XML by hand.  Can the same be said for a sqlite database?


Real programmers edit their SQL databases directly on the hard drive platter
using a magnetised needle and a steady hand.


-- 
Steven

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


Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Chris Angelico
On Mon, Aug 3, 2015 at 11:38 PM, Steven D'Aprano  wrote:
> On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote:
>
>> Well, I have at least some non-zero chance of reading and writing JSON
>> or XML by hand.  Can the same be said for a sqlite database?
>
>
> Real programmers edit their SQL databases directly on the hard drive platter
> using a magnetised needle and a steady hand.

REAL programmers use emacs, with the C-x M-x M-butterfly command.

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


Re: how to determine for using c extension or not ?

2015-08-03 Thread umedoblock

sorry, Joel, Skip, Steven, and python-list members.

I think that I don't sent my mail to python-list@python.org or I don't 
have correct mail setting.


so I send many mails.

sorry... I should wait a day to get answer, sorry.

On 2015年08月03日 22:36, Steven D'Aprano wrote:

On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote:


Hello everyone.

I use bisect module.


You asked the same question FOUR times. Have patience. Your question goes
all over the world, people may be asleep, or working, or just not know the
answer. If you ask a question, and get no answers, you should wait a full
day before asking again.



bisect module developer give us c extension as _bisect.

If Python3.3 use _bisect, _bisect override his functions in bisect.py.


So does Python 2.7.



now, I use id() function to determine for using c extension or not.


The id() function doesn't tell you where objects come from or what language
they are written in. But they will tell you if two objects are the same
object.


import bisect
id(bisect.bisect)

139679893708880

import _bisect
id(_bisect.bisect)

139679893708880

they return 139679893708880 as id.
so i believe that i use c extension.


Correct.

Also, you can do this:


py> import bisect
py> bisect.__file__
'/usr/local/lib/python2.7/bisect.pyc'
py> bisect.bisect.__module__  # Where does the bisect file come from?
'_bisect'
py> import _bisect
py> _bisect.__file__
'/usr/local/lib/python2.7/lib-dynload/_bisect.so'

So you can see that _bisect is a .so file (on Linux; on Windows it will be
a .dll file), which means written in C.




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


Re: how to determine for using c extension or not ?

2015-08-03 Thread Joel Goldstick
On Mon, Aug 3, 2015 at 10:01 AM, umedoblock  wrote:
> sorry, Joel, Skip, Steven, and python-list members.
>
> I think that I don't sent my mail to python-list@python.org or I don't have
> correct mail setting.
>
> so I send many mails.
>
> sorry... I should wait a day to get answer, sorry.
>
>
> On 2015年08月03日 22:36, Steven D'Aprano wrote:
>>
>> On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote:
>>
>>> Hello everyone.
>>>
>>> I use bisect module.
>>
>>
>> You asked the same question FOUR times. Have patience. Your question goes
>> all over the world, people may be asleep, or working, or just not know the
>> answer. If you ask a question, and get no answers, you should wait a full
>> day before asking again.
>>
>>
>>> bisect module developer give us c extension as _bisect.
>>>
>>> If Python3.3 use _bisect, _bisect override his functions in bisect.py.
>>
>>
>> So does Python 2.7.
>>
>>
>>> now, I use id() function to determine for using c extension or not.
>>
>>
>> The id() function doesn't tell you where objects come from or what
>> language
>> they are written in. But they will tell you if two objects are the same
>> object.
>>
>> import bisect
>> id(bisect.bisect)
>>>
>>> 139679893708880
>>
>> import _bisect
>> id(_bisect.bisect)
>>>
>>> 139679893708880
>>>
>>> they return 139679893708880 as id.
>>> so i believe that i use c extension.
>>
>>
>> Correct.
>>
>> Also, you can do this:
>>
>>
>> py> import bisect
>> py> bisect.__file__
>> '/usr/local/lib/python2.7/bisect.pyc'
>> py> bisect.bisect.__module__  # Where does the bisect file come from?
>> '_bisect'
>> py> import _bisect
>> py> _bisect.__file__
>> '/usr/local/lib/python2.7/lib-dynload/_bisect.so'
>>
>> So you can see that _bisect is a .so file (on Linux; on Windows it will be
>> a .dll file), which means written in C.
>>
>>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Welcome to the mailing list, and as I see above, you got a good answer.

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


Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Mark Lawrence

On 02/08/2015 21:58, Joonas Liik wrote:

I have this feeling that you would get a lot more useful anwsers if
you were to describe your actual problem in stead of what you think
the solution is. There might be other, better solutions but since we
know so little about what you are doing we will likely never find them
by just guessing..



+1

--
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: Optimal solution for coloring logging output

2015-08-03 Thread Mark Lawrence

On 03/08/2015 10:13, c.bu...@posteo.jp wrote:

I don't want to ask how to do this because there are so many
"solutions" about it.


There are so much different and part of unpythontic solutions I can not
decide myself. What do you (as real pythontics) think about that.
Which of the solutions fit to concepts of Python and its logging
package?

Coloring means here not only the message itself. The (levelname) should
be included in the coloring.
For myself coloring the (levelname) would be enough to avoid to much
color in the output.

1.
The solution itself shouldn't care about plattform differences because
there are still some packages which are able to offer
plattform-independent console-coloring. Which would you prefere? ;)

2.
Some solutions derive from StreamHandler or much more bad hacking the
emit() function. I think both of them are not responsible for how the
output should look or be presented.

3.
How to present the output is IMO the responsibility of a Formater, isn't
it? So I should derive from the Formater.

What do you as Pythonics think of that? ;)



I'd go for this https://pypi.python.org/pypi/colorlog as recommended on 
a couple of answers on the stackoverflow thread you've referenced.


A slight aside, we're "Pythonistas", not "pythontics" or "Pythonics " :)


Should we subclass Pythonista into Pythonista2 and Pythonista3 so that 
people can show their preferred version?



--
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: Most Pythonic way to store (small) configuration

2015-08-03 Thread Mark Lawrence

On 03/08/2015 14:38, Steven D'Aprano wrote:

On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote:


Well, I have at least some non-zero chance of reading and writing JSON
or XML by hand.  Can the same be said for a sqlite database?


Real programmers edit their SQL databases directly on the hard drive platter
using a magnetised needle and a steady hand.



I'd stick with SQLiteStudio or something similar if I were you.  The 
last time I tried the above, having consumed 10 bottles of Newcastle 
Brown, the results were disastrous.  I pricked my finger.


--
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: how to determine for using c extension or not ?

2015-08-03 Thread umedoblock

normal, no change
>>> import bisect
>>> bisect.bisect.__module__
'_bisect'

I change from "from _bisect import *" to "pass" in bisect.py

>>> import bisect
>>> bisect.bisect.__module__
'bisect'

bisect.bisect.__module__ return different results.
they are '_bisect' and 'bisect'.

I know that c extension document recomended us to use _ for c extension 
name  prefix.


I use "bisect.bisect.__module__" sentence to determine for using c 
extension or not.


thanks.

On 2015年08月03日 23:11, Joel Goldstick wrote:

On Mon, Aug 3, 2015 at 10:01 AM, umedoblock  wrote:

sorry, Joel, Skip, Steven, and python-list members.

I think that I don't sent my mail to python-list@python.org or I don't have
correct mail setting.

so I send many mails.

sorry... I should wait a day to get answer, sorry.


On 2015年08月03日 22:36, Steven D'Aprano wrote:


On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote:


Hello everyone.

I use bisect module.



You asked the same question FOUR times. Have patience. Your question goes
all over the world, people may be asleep, or working, or just not know the
answer. If you ask a question, and get no answers, you should wait a full
day before asking again.



bisect module developer give us c extension as _bisect.

If Python3.3 use _bisect, _bisect override his functions in bisect.py.



So does Python 2.7.



now, I use id() function to determine for using c extension or not.



The id() function doesn't tell you where objects come from or what
language
they are written in. But they will tell you if two objects are the same
object.


import bisect
id(bisect.bisect)


139679893708880


import _bisect
id(_bisect.bisect)


139679893708880

they return 139679893708880 as id.
so i believe that i use c extension.



Correct.

Also, you can do this:


py> import bisect
py> bisect.__file__
'/usr/local/lib/python2.7/bisect.pyc'
py> bisect.bisect.__module__  # Where does the bisect file come from?
'_bisect'
py> import _bisect
py> _bisect.__file__
'/usr/local/lib/python2.7/lib-dynload/_bisect.so'

So you can see that _bisect is a .so file (on Linux; on Windows it will be
a .dll file), which means written in C.




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


Welcome to the mailing list, and as I see above, you got a good answer.



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


Re: how to determine for using c extension or not ?

2015-08-03 Thread Oscar Benjamin
On Mon, 3 Aug 2015 at 15:58 umedoblock  wrote:

>
> I use "bisect.bisect.__module__" sentence to determine for using c
> extension or not.
>
>
Why do you want to know if it uses the C extension? It shouldn't really
matter.

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


Parsing multipart HTTP response

2015-08-03 Thread Gilles Lenfant
Hi,

I searched without succeeding a Python resource that is capable of parsing an 
HTTP multipart/mixed response stream, preferably as a generator that yields 
headers + content for each part.

Google and friends didn't find or I didn't use the appropriate term.

Any hint will be appreciated.
--
Gilles Lenfant
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parsing multipart HTTP response

2015-08-03 Thread Gilles Lenfant
Le lundi 3 août 2015 17:01:40 UTC+2, Gilles Lenfant a écrit :
> Hi,
> 
> I searched without succeeding a Python resource that is capable of parsing an 
> HTTP multipart/mixed response stream, preferably as a generator that yields 
> headers + content for each part.
> 
> Google and friends didn't find or I didn't use the appropriate term.
> 
> Any hint will be appreciated.
> --
> Gilles Lenfant

Ah, aiohttp does something similar to what I need but requires Python 3.3 + 
when I'm stuck with Pyton 2.7 on that project.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parsing multipart HTTP response

2015-08-03 Thread Mark Lawrence

On 03/08/2015 16:01, Gilles Lenfant wrote:

Hi,

I searched without succeeding a Python resource that is capable of parsing an 
HTTP multipart/mixed response stream, preferably as a generator that yields 
headers + content for each part.

Google and friends didn't find or I didn't use the appropriate term.

Any hint will be appreciated.
--
Gilles Lenfant



Hardly my field but how about:-

https://pypi.python.org/pypi/requests-toolbelt/0.3.1
https://pypi.python.org/pypi/multipart/

--
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: Python 3 May Become Relevant Now

2015-08-03 Thread Rick Johnson
On Sunday, August 2, 2015 at 9:45:51 PM UTC-5, Chris Angelico wrote:
> How do you know it was written today, if you didn't click it?

Because i possess skills you can hardly fathom. There are always
loopholes; back doors; knot holes; key holes; cracks; crevices;
tells; Freudian slips; little white lies; and yes, even arthropods
creeping and crawling in dark corners fitted with multiple visual
sensors -- all one need do is discover them, and then *EXPLOIT* them!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to determine for using c extension or not ?

2015-08-03 Thread Marco Buttu

On 03/08/2015 15:30, Skip Montanaro wrote:

id() tells you nothing about the nature of the function. Use the
inspect.isbuiltin():
...
It's perhaps a bit poorly named, but "builtin" functions are those not
written in Python. That is, those written in C or C++.


I think in the documentation there is an inconsistency about the term 
builtin. The "Built-in Functions" documentation says: """The Python 
interpreter has a number of functions and types built into it that are 
*always available*. They are listed here in

alphabetical order""".

https://docs.python.org/3/library/functions.html

The functions in the documentation list, are the same functions we get 
from the `builtins` module.


So, in the documentation we use the term built-in to indicate functions 
always available, whose names live in the builtin namespace.
Sometimes, as mentioned by Skip, we say that the term "buit-in function" 
is also referred to a function written in C:


https://docs.python.org/3/library/types.html#types.BuiltinFunctionType

By using the same word (built-in) to indicate either objects written in 
C or objects who live in the builtin namespace could be a bit muddler.



--
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbu...@oa-cagliari.inaf.it

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


Re: Python 3 May Become Relevant Now

2015-08-03 Thread Chris Angelico
On Tue, Aug 4, 2015 at 1:42 AM, Rick Johnson
 wrote:
> On Sunday, August 2, 2015 at 9:45:51 PM UTC-5, Chris Angelico wrote:
>> How do you know it was written today, if you didn't click it?
>
> Because i possess skills you can hardly fathom. There are always
> loopholes; back doors; knot holes; key holes; cracks; crevices;
> tells; Freudian slips; little white lies; and yes, even arthropods
> creeping and crawling in dark corners fitted with multiple visual
> sensors -- all one need do is discover them, and then *EXPLOIT* them!

And you trust these more than you trust HTTP. Weird.

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


Re: Parsing multipart HTTP response

2015-08-03 Thread Gilles Lenfant
Le lundi 3 août 2015 17:39:57 UTC+2, Mark Lawrence a écrit :
> On 03/08/2015 16:01, Gilles Lenfant wrote:
> > Hi,
> >
> > I searched without succeeding a Python resource that is capable of parsing 
> > an HTTP multipart/mixed response stream, preferably as a generator that 
> > yields headers + content for each part.
> >
> > Google and friends didn't find or I didn't use the appropriate term.
> >
> > Any hint will be appreciated.
> > --
> > Gilles Lenfant
> >
> 
> Hardly my field but how about:-
> 
> https://pypi.python.org/pypi/requests-toolbelt/0.3.1
> https://pypi.python.org/pypi/multipart/
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Thanks Mark,

"multipart" is close to what I need and will give me some inpiration. 
Unfortunately, it works for multipart/form-data server-side handling, when I'm 
searching for a multipart/mixed client side handling of a response. In 
addition, it does not yield the headers specific to each data chunk from the 
response, and I need those headers.

To be more specific, I'm buiding with the excellent "requests" lib and Python 
2.7 (sorry, I can't go to Python 3.x at the moment) a client library for the 
documents database MarkLogic 8 that provides some APIs with multipart/mixed 
responses like this one:

http://docs.marklogic.com/REST/POST/v1/eval

In other words I need something that may be used like this :

response = requests.post(some_uri, params=some_params, stream=True)
if response.headers['content-type'].startswith('multipart/mixed'):
boundary = parse_boundary(response.headers['content-type'])

generator = iter_multipart_response(response, boundary)
for part_headers, part_body in generator:
# I'm consuming parsed headers and bodies from response
# In my application code

Cheers
-- 
Gilles Lenfant
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to determine for using c extension or not ?

2015-08-03 Thread Terry Reedy

On 8/3/2015 9:08 AM, umedoblock wrote:

Posting three times under two different names is not polite.  Please to 
not  repeat.



I use bisect module.
bisect module developer give us c extension as _bisect.


We call that a C accelerator.


If Python3.3 use _bisect, _bisect override his functions in bisect.py.


An accelerator may override either some or all functions.
In this case, Lib/bisect.py ends with

try:
from _bisect import *
except ImportError:
pass

For CPython, I expect that all 4 similar functions (and two synonyms) 
get replaced.



now, I use id() function to determine for using c extension or not.


You should not care.  If you think there is an undocumented difference 
in behavior, ask here if it is a bug.


I expect that that test/test_bisect.py runs the same tests on both 
versions.  We have a test helper function for such situations.  It 
blocks the import of the accelerator so that the Python version can be 
tested.



import bisect
id(bisect.bisect)

139679893708880

import _bisect
id(_bisect.bisect)

139679893708880

they return 139679893708880 as id.
so i believe that i use c extension.


The bisect and _bisect modules are different objects.  Since they and 
their global namespace exist simultaneously, then yes, the above says 
that both have the name 'bisect' bound to the C-coded built-in version.


--
Terry Jan Reedy

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


Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Larry Hudson via Python-list

On 08/02/2015 01:58 PM, Joonas Liik wrote:

I have this feeling that you would get a lot more useful anwsers if
you were to describe your actual problem in stead of what you think
the solution is. There might be other, better solutions but since we
know so little about what you are doing we will likely never find them
by just guessing..

Sorry if I wasn't clear.  This is not _my_ problem, this was intended to re-state the OP's 
fundamental problem.  And the quoted text was the OP's original message.  I felt that most 
(anyway many) responders here were missing this point.


This is what I saw as the OP's underlying problem, but as I also said in my message, my 
interpretation certainly could be wrong.:-)


 -=- Larry -=-

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


Re: Usage of P(C)ython Logo for Coffee Mug

2015-08-03 Thread deus ex
Ok great thanks for help, so for non-commercial use it looks ok!

Dex

2015-07-29 21:36 GMT+02:00 Zachary Ware :

> On Wed, Jul 29, 2015 at 2:01 PM, Terry Reedy  wrote:
> > On 7/29/2015 11:55 AM, Laura Creighton wrote:
> >> We have SVG versions here:
> >> https://www.python.org/community/logos/
> >
> > See Guidelines for Use near the bottom, which as an *ask first* link if
> in
> > doubt.  Given that your coffee cup would be suitable for use while
> > programming Python, I would expect no difficultly.
>
> See also http://www.cafepress.com/pydotorg (linked from the logo page
> linked above), which includes coffee mugs for both logo styles.
>
> --
> Zach
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and I'm stumped...

2015-08-03 Thread josephbigler
On Saturday, August 1, 2015 at 11:59:14 AM UTC-4, Dwight GoldWinde wrote:
> Please help.
> 
> 
> I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 as 
> my editor.
> 
> 
> Here's the code:
> 
> #!/usr/bin/env python3
> word = (input('Enter a word '))
> 
> 
> When running this inside of Coderunner, I get the follow error, after 
> entering the word 'serendipity':
> 
> 
> 
> Enter a word serendipity
> 
> Traceback (most recent call last):
> 
>   File "test short.py", line 2, in 
> 
> word = (input('Enter a word '))
> 
>   File "", line 1, in 
> 
> NameError: name 'serendipity' is not defined

If you want to run this in Python 3, try this


CodeRunner->Preferences->Languages->Run Command

edit "python $filename" to "python3 $filename"

It appears coderunner 2 is using Python 2.7.1  

Here's where I found the answer, from someone who had a similar issue.  Please 
let us know either way if it solved the problem.

http://stackoverflow.com/questions/19797616/coderunner-uses-old-2-71-version-of-python-instead-of-3-2-on-osx-10-7-5


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


How to import a function from another module...

2015-08-03 Thread Dwight GoldWinde
I am trying to import a function defined in another module.

The code is this:

name = 'Jim'
sex = 'm'
coach = 'Dwight'
import importlib
sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be
your coach today.'
importlib.import_module ('humprint', 'Macintosh
HD/Users/dwightgoldwindex/Documents/Active Information/ACL/Testing
Code/Simulate typing.py')

The response and error message I receive is this:

Traceback (most recent call last):
File "Intro.py", line 7, in 
importlib.import_module ('humprint', 'Macintosh
HD/Users/dwightgoldwindex/Documents/Active Information/ACL/Testing
Code/Simulate typing.py')
File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/_
_init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 2249, in _gcd_import
File "", line 2199, in _sanity_check
SystemError: Parent module 'Macintosh
HD/Users/dwightgoldwindex/Documents/Active Information/ACL/Testing
Code/Simulate typing.py' not loaded, cannot perform relative import

How can I change my code to have the import work properly?


Thank you.

BIG SMILE...

Always, Dwight


www.3forliving.key.to (video playlist on YouTube)
www.couragebooks.key.to (all my books on Amazon)



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


Re: How to import a function from another module...

2015-08-03 Thread Steven D'Aprano
On Tue, 4 Aug 2015 09:57 am, Dwight GoldWinde wrote:

> I am trying to import a function defined in another module.

You can't use spaces in the name of importable Python modules: change the
name from "Simulate typing.py" to "simulate_python.py". You can use spaces
in file names if they are only used as a runnable script and not imported.

Then use this:

from simulate_python import humprint

There's no need to use importlib.

You may need to arrange for the simulate_python file to be placed somewhere
in the Python search path. Do you need help with that?

What you are trying to do with importlib is fight the language. Your life
will be much simpler if you work within the parameters of how the language
is designed to work.



-- 
Steven

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