Re: Cleaning up conditionals

2017-01-03 Thread Chris Angelico
On Tue, Jan 3, 2017 at 6:35 PM, Deborah Swanson
 wrote:
> I think I'm right that core python sequences can't be indexed in any
> fashion by strings, because strings aren't iterable. I suppose it might
> be possible for strings to be iterable in some sort of ascii char code
> order, but that seems like it could get real whacky very fast, and not
> terribly useful.

It's not because they're not iterable, but because there's a
fundamental difference between a key-value pair (dict) and a sequence.
You can combine the two in several different ways, none of which is
the "one most obvious". Python's OrderedDict retains the order of its
keys; in contrast, a namedtuple is a "record" type with a fixed set of
keys that correspond to positions in the record. In your case, I think
a namedtuple would be a good fit, but there's no general concept of
indexing a sequence with strings.

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


RE: Cleaning up conditionals

2017-01-03 Thread Deborah Swanson
Chris Angelico wrote, on January 03, 2017 12:14 AM
> 
> On Tue, Jan 3, 2017 at 6:35 PM, Deborah Swanson 
>  wrote:
> > I think I'm right that core python sequences can't be 
> indexed in any 
> > fashion by strings, because strings aren't iterable. I suppose it 
> > might be possible for strings to be iterable in some sort of ascii 
> > char code order, but that seems like it could get real whacky very 
> > fast, and not terribly useful.
> 
> It's not because they're not iterable, but because there's a 
> fundamental difference between a key-value pair (dict) and a 
> sequence. You can combine the two in several different ways, 
> none of which is the "one most obvious". Python's OrderedDict 
> retains the order of its keys; in contrast, a namedtuple is a 
> "record" type with a fixed set of keys that correspond to 
> positions in the record. In your case, I think a namedtuple 
> would be a good fit, but there's no general concept of 
> indexing a sequence with strings.
> 
> ChrisA

I hope I can get to namedtuples tomorrow, they do sound like an
excellent data structure for the purpose of using field titles as
subscripts. I'd never heard of them before, so I'm looking forward to
finding out what they are and how they work.

OrderedDict is the new development I'd read about, but I think the key
order is just the order keys were added to the dict. The nice thing
about that though is when you loop over a dict you will always get the
key/value pairs in the same order, where with the standard dict they
come out in arbitrary order. Very disconcerting if you're watching the
loop as it progresses over muiltiple executions. I imagine you could
sort an OrderedDict so the keys originally added randomly would be put
into some kind of good order.


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


Re: Cleaning up conditionals

2017-01-03 Thread Chris Angelico
On Tue, Jan 3, 2017 at 8:18 PM, Deborah Swanson
 wrote:
> OrderedDict is the new development I'd read about, but I think the key
> order is just the order keys were added to the dict. The nice thing
> about that though is when you loop over a dict you will always get the
> key/value pairs in the same order, where with the standard dict they
> come out in arbitrary order. Very disconcerting if you're watching the
> loop as it progresses over muiltiple executions. I imagine you could
> sort an OrderedDict so the keys originally added randomly would be put
> into some kind of good order.

If you want a "SortedDict", you can get that fairly easily just by
iterating over sorted(d) rather than simply d. You can also subclass
the dictionary and change how it iterates, if you like.

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-03 Thread smitty1e
On Monday, January 2, 2017 at 6:39:03 AM UTC-5, Antonio Caminero Garcia wrote:
> Hello, I am having a hard time deciding what IDE or IDE-like code editor 
> should I use. This can be overwhelming.
> 
> So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, IntelliJ 
> with Python plugin. 
> 
> The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, 
> Pycharm) is that they look like a space craft dashboard and that unwarranted 
> resources consumption and the unnecessary icons. I want my IDE to be 
> minimalistic but powerful. My screen should be mostly “made of code” as 
> usually happens in Vim, Sublime or Atom. However, Pycharm is really cool and 
> python oriented.
> 
> The problem with Vim is the learning curve, so I know the very basic stuff, 
> but obviously not enough for coding and I do not have time to learn it, it is 
> a pity because there are awesome plugins that turns Vim into a lightweight 
> powerful IDE-like. So now it is not an option but I will reconsider it in the 
> future, learning little by little. Also, I am not very fan GUI guy if the 
> task can be accomplished through the terminal. However, I don’t understand 
> why people underrate GUIs, that said I normally use shortcuts for the most 
> frequent tasks and when I have to do something that is not that frequent then 
> I do it with the mouse, for the latter case in vim you would need to look for 
> that specific command every time. 
> 
> Sublime is my current and preferred code editor. I installed Anaconda, Git 
> integration and a couple of additional plugins that make sublime very 
> powerful. Also, what I like about sublime compared to the full featured IDEs, 
> besides the minimalism, is how you can perform code navigation back and forth 
> so fast, I mean this is something that you can also do with the others but 
> for some subjective reason I specifically love how sublime does it. The code 
> completion in sublime I do not find it very intelligence, the 
> SublimeCodeIntel is better than the one that Anaconda uses but the 
> completions are not as verbose as in the IDEs.
> 
> Now, I am thinking about giving a try to Visual Studio Code Edition (take a 
> look, it sounds good 
> https://marketplace.visualstudio.com/items?itemName=donjayamanne.python). I 
> need an editor for professional software development. What would you 
> recommend to me?

I am told that means other than Emacs exist to edit code and interact with 
systems, but I don't worry about them.

Happy New Year,
Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


pip install -r requirements.txt fails with Python 3.6 on Windows 10

2017-01-03 Thread Uri Even-Chen
(.venv) C:\Uri\Speedy Net\Git\speedy-net [public]>pip install -r
requirements.txt
Requirement already satisfied: Django==1.10.4 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 2))
Requirement already satisfied: django-crispy-forms==1.6.1 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 3))
Requirement already satisfied: django-debug-toolbar==1.6 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 4))
Requirement already satisfied: django-environ==0.4.1 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 5))
Requirement already satisfied: django-friendship==1.5.0 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 6))
Requirement already satisfied: django-modeltranslation==0.12 in
c:\uri\speedy net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 7))
Requirement already satisfied: factory-boy==2.8.1 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 8))
Requirement already satisfied: Faker==0.7.7 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 9))
Collecting Pillow==3.4.2 (from -r requirements.txt (line 10))
  Using cached Pillow-3.4.2.tar.gz
Requirement already satisfied: python-dateutil==2.6.0 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 11))
Collecting rules==1.2 (from -r requirements.txt (line 12))
  Using cached rules-1.2.tar.gz
Requirement already satisfied: six==1.10.0 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 13))
Collecting sorl-thumbnail==12.4a1 (from -r requirements.txt (line 14))
  Using cached sorl_thumbnail-12.4a1-py2.py3-none-any.whl
Requirement already satisfied: sqlparse==0.2.2 in c:\uri\speedy
net\git\speedy-net [public]\.venv\lib\site-packages (from -r
requirements.txt (line 15))
Installing collected packages: Pillow, rules, sorl-thumbnail
  Running setup.py install for Pillow ... error
Complete output from command "c:\uri\speedy net\git\speedy-net
[public]\.venv\scripts\python.exe" -u -c "import setuptools,
tokenize;__file__='C:\\Users\\Uri\\AppData\\Local\\Temp\\pip-build-3dj7ngjs\\Pillow\\setup.py';f=getattr(tokenize,
'open', open)(__file__);code=f.read().replace('\r\n',
'\n');f.close();exec(compile(code, __file__, 'exec'))" install --record
C:\Users\Uri\AppData\Local\Temp\pip-1464cmd1-record\install-record.txt
--single-version-externally-managed --compile --install-headers
"c:\uri\speedy net\git\speedy-net
[public]\.venv\include\site\python3.6\Pillow":
Single threaded build for windows
running install
running build
running build_py
creating build
creating build\lib.win32-3.6
creating build\lib.win32-3.6\PIL
copying PIL\BdfFontFile.py -> build\lib.win32-3.6\PIL
copying PIL\BmpImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\BufrStubImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\ContainerIO.py -> build\lib.win32-3.6\PIL
copying PIL\CurImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\DcxImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\DdsImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\EpsImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\ExifTags.py -> build\lib.win32-3.6\PIL
copying PIL\features.py -> build\lib.win32-3.6\PIL
copying PIL\FitsStubImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\FliImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\FontFile.py -> build\lib.win32-3.6\PIL
copying PIL\FpxImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\FtexImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\GbrImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\GdImageFile.py -> build\lib.win32-3.6\PIL
copying PIL\GifImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\GimpGradientFile.py -> build\lib.win32-3.6\PIL
copying PIL\GimpPaletteFile.py -> build\lib.win32-3.6\PIL
copying PIL\GribStubImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\Hdf5StubImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\IcnsImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\IcoImagePlugin.py -> build\lib.win32-3.6\PIL
copying PIL\Image.py -> build\lib.win32-3.6\PIL
copying PIL\ImageChops.py -> build\lib.win32-3.6\PIL
copying PIL\ImageCms.py -> build\lib.win32-3.6\PIL
copying PIL\ImageColor.py -> build\lib.win32-3.6\PIL
copying PIL\ImageDraw.py -> build\lib.win32-3.6\PIL
copying PIL\ImageDraw2.py -> build\lib.win32-3.6\PIL
copying PIL\ImageEnhance.py -> build\lib.win32-3.6\PIL
copying PIL\ImageFile.py -> build\lib.win32-3.6\PIL
copying PIL\ImageFilter.py -> build\lib.win32-3.6\PIL
copying PIL\ImageFon

Numpy error

2017-01-03 Thread jorge . conrado



Hi,


I alredy used Python and now I have the message:

import numpy as np
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/__init__.py", 
line 153, in 

from . import add_newdocs
  File 
"/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/add_newdocs.py", 
line 13, in 

from numpy.lib import add_newdoc
  File 
"/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/lib/__init__.py", 
line 18, in 

from .polynomial import *
  File 
"/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/lib/polynomial.py", 
line 19, in 

from numpy.linalg import eigvals, lstsq, inv
  File 
"/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/linalg/__init__.py", 
line 50, in 

from .linalg import *
  File 
"/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/linalg/linalg.py", 
line 29, in 

from numpy.linalg import lapack_lite, _umath_linalg
ImportError: 
/home/conrado/Canopy/appdata/canopy-1.5.5.3123.rh5-x86_64/lib/libgfortran.so.3: 
version `GFORTRAN_1.4' not found (required by /lib64/liblapack.so.3)



I did:  pip istall --user numpy


Requirement already satisfied: numpy in 
/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.0-py2.7-linux-x86_64.egg



What can I do to solve this message.


Thanks,


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


Screwing Up looping in Generator

2017-01-03 Thread Sayth Renshaw
Hi

This is simple, but its getting me confused.

I have a csv writer that opens a file and loops each line of the file for each 
file and then closes, writing one file.

I want to alter the behaviour to be a written file for each input file. I saw a 
roundrobin example however it failed for me as you cannot get len(generator) to 
use a while loop on.
it exhausts

should I use the same for again after the with open?

rootobs in this code is my generator and I am already looping it however 
def data_attr(roots):
"""Get the root object and iter items."""
for file in rootobs:
base = os.path.basename(file.name)
write_to = os.path.join("output", os.path.splitext(base)[0] + ".csv")
with open(write_to, 'w', newline='') as csvf:
race_writer = csv.writer(csvf, delimiter=',')
race_writer.writerow(
["meet_id", "meet_venue", "meet_date", "meet_rail",
 ...
 # other categories here
 ...
"jockeysurname", "jockeyfirstname"])
for xml_data in roots:
...
# parsing code
for noms in race_child:
if noms.tag == 'nomination':
race_writer.writerow(
[meet_id, meet_venue, meet_date,
 ...
#parsing info removed
noms.get("jockeyfirstname")])

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


Re: trouble with cmd.Cmd and prompting

2017-01-03 Thread Peter Otten
Cameron Simpson wrote:

> On 03Jan2017 00:14, Dennis Lee Bieber  wrote:
>>On Tue, 3 Jan 2017 11:33:15 +1100, Cameron Simpson 
>>declaimed the following:
>>>I'm using cmd.Cmd to write a little FTP-like command line to interface to
>>>a storage system of mine and encountering weird behaviour. When I enter a
>>>command the next prompt appears _before_ the associated operation runs,
>>>or so it appears.
>>
>>>Has anyone seen this kind of thing before?
>>
>>Haven't used the module but there is something I find intriguing in the
>>help system
>>-=-=-=-=-
>> Cmd.precmd(line)
>>Hook method executed just before the command line is interpreted, but
>>after the input prompt is generated and issued.
>>-=-=-=-=-
>>"... AFTER the input prompt is ... issued"
>>
>>I don't know, but that sure sounds to me like the cmd object tends to
>>process one line behind... Though that behavior is not shown in the turtle
>>example in the help system.
> 
> Hmm. Interesting. I had read that text to imply (based on what I imagined
> _should_ happen) that the flow of control went:
> 
>   cmdloop:
> issue prompt>
> line=input()  # or readline
> line=precmd(line)
> stop=onecmd(line) # which calls do_blah...
> stop=postcmd(stop,line)
> if stop:
>   break
> 
> but your reading of it suggests that this is possible:
> 
>   issue prompt>
>   cmdloop:
> line=input()  # or readline
> issue prompt>
> line=precmd(line)
> stop=onecmd(line) # which calls do_blah...
> stop=postcmd(stop,line)
> if stop:
>   break
> 
> The text for Cmd.cmdloop starts with this:
> 
>   Repeatedly issue a prompt, accept input, parse an initial prefix off the
>   received input, and dispatch to action methods, passing them the
>   remainder of the line as argument.
> 
> which argues for the former, and was what I naively expected.
> 
> I guess I'd better dig out the source; I dislike going that far, not
> merely out of laziness, but also because the source is not the spec.
> 
> Thanks for the suggestion,
> Cameron Simpson 

I don't believe Dennis' reading of the docs is correct, and the relevant 
part of the source (Python 3.4) does not show anything to support it:

while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
if self.use_rawinput:
try:
line = input(self.prompt)
except EOFError:
line = 'EOF'
else:
self.stdout.write(self.prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line.rstrip('\r\n')
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()

Is there something asynchronous in your command? Perhaps you can post a 
minimal runnable example that shows the odd behaviour.

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


Re: learning and experimenting python.

2017-01-03 Thread Wildman via Python-list
On Mon, 02 Jan 2017 20:25:25 -0800, Ethan Furman wrote:

> On 01/02/2017 09:53 AM, Wildman via Python-list wrote:
> 
> [rude ascii art omitted]
> 
> That is a completely inappropriate response.

Yes it was.  I tend to get upset when told to shut up and
go away for no good reason.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip install -r requirements.txt fails with Python 3.6 on Windows 10

2017-01-03 Thread INADA Naoki
Pillow 3.4.2 provides binary wheel for Python 3.5, but not for 3.6.

So your pip can just install wheel on Python 3.5, but it is required to build
on Python 3.6.  And your machine doesn't have zlib which is required
to build Pillow.

Easiest solution may just update your requirements to Pillow==4.0.0.
Pillow 4.0.0 provides binary wheel for Python 3.6, from 2017-01-02.
https://pypi.python.org/pypi/Pillow/4.0.0


On Tue, Jan 3, 2017 at 10:19 PM, Uri Even-Chen  wrote:
> (.venv) C:\Uri\Speedy Net\Git\speedy-net [public]>pip install -r
> requirements.txt
> Requirement already satisfied: Django==1.10.4 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 2))
> Requirement already satisfied: django-crispy-forms==1.6.1 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 3))
> Requirement already satisfied: django-debug-toolbar==1.6 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 4))
> Requirement already satisfied: django-environ==0.4.1 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 5))
> Requirement already satisfied: django-friendship==1.5.0 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 6))
> Requirement already satisfied: django-modeltranslation==0.12 in
> c:\uri\speedy net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 7))
> Requirement already satisfied: factory-boy==2.8.1 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 8))
> Requirement already satisfied: Faker==0.7.7 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 9))
> Collecting Pillow==3.4.2 (from -r requirements.txt (line 10))
>   Using cached Pillow-3.4.2.tar.gz
> Requirement already satisfied: python-dateutil==2.6.0 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 11))
> Collecting rules==1.2 (from -r requirements.txt (line 12))
>   Using cached rules-1.2.tar.gz
> Requirement already satisfied: six==1.10.0 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 13))
> Collecting sorl-thumbnail==12.4a1 (from -r requirements.txt (line 14))
>   Using cached sorl_thumbnail-12.4a1-py2.py3-none-any.whl
> Requirement already satisfied: sqlparse==0.2.2 in c:\uri\speedy
> net\git\speedy-net [public]\.venv\lib\site-packages (from -r
> requirements.txt (line 15))
> Installing collected packages: Pillow, rules, sorl-thumbnail
>   Running setup.py install for Pillow ... error
> Complete output from command "c:\uri\speedy net\git\speedy-net
> [public]\.venv\scripts\python.exe" -u -c "import setuptools,
> tokenize;__file__='C:\\Users\\Uri\\AppData\\Local\\Temp\\pip-build-3dj7ngjs\\Pillow\\setup.py';f=getattr(tokenize,
> 'open', open)(__file__);code=f.read().replace('\r\n',
> '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record
> C:\Users\Uri\AppData\Local\Temp\pip-1464cmd1-record\install-record.txt
> --single-version-externally-managed --compile --install-headers
> "c:\uri\speedy net\git\speedy-net
> [public]\.venv\include\site\python3.6\Pillow":
> Single threaded build for windows
> running install
> running build
> running build_py
> creating build
> creating build\lib.win32-3.6
> creating build\lib.win32-3.6\PIL
> copying PIL\BdfFontFile.py -> build\lib.win32-3.6\PIL
> copying PIL\BmpImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\BufrStubImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\ContainerIO.py -> build\lib.win32-3.6\PIL
> copying PIL\CurImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\DcxImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\DdsImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\EpsImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\ExifTags.py -> build\lib.win32-3.6\PIL
> copying PIL\features.py -> build\lib.win32-3.6\PIL
> copying PIL\FitsStubImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\FliImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\FontFile.py -> build\lib.win32-3.6\PIL
> copying PIL\FpxImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\FtexImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\GbrImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\GdImageFile.py -> build\lib.win32-3.6\PIL
> copying PIL\GifImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\GimpGradientFile.py -> build\lib.win32-3.6\PIL
> copying PIL\GimpPaletteFile.py -> build\lib.win32-3.6\PIL
> copying PIL\GribStubImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\Hdf5StubImagePlugin.py -> build\lib.win32-3.6\PIL
> copying PIL\Icns

Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-03 Thread Tim Johnson
* Antonio Caminero Garcia  [170102 20:56]:
> Guys really thank you for your answers. Basically now I am more
> emphasizing in learning in depth a tool and get stick to it so I
> can get a fast workflow. Eventually I will learn Vim and its
> python developing setup, I know people who have been programming
> using Vim for almost 20 years and they did not need to change
> editor (that is really awesome). 

 Bye the way, one thing I like about the GUI based vim is that it
 supports tabs, where emacs does not.

 And check out the vim plugins for python

 Good Luck!
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Numpy error

2017-01-03 Thread Deborah Swanson
> ImportError: 
> /home/conrado/Canopy/appdata/canopy-1.5.5.3123.rh5-x86_64/lib/
> libgfortran.so.3: 
> version `GFORTRAN_1.4' not found (required by /lib64/liblapack.so.3)

Looks like you need to install the 'GFORTRAN_1.4' plugin into Canopy. I
don't know where you'll find it, but Canopy's main website would be a
good place to start. Or google "GFORTRAN_1.4 Canopy download".


jorge.conr...@cptec.inpe.br wrote, on January 03, 2017 6:45 AM:
> 
> Hi,
> 
> 
> I alredy used Python and now I have the message:
> 
> import numpy as np
> Traceback (most recent call last):
>File "", line 1, in 
>File 
> "/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-
> packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/__init__.py", 
> line 153, in 
>  from . import add_newdocs
>File 
> "/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-
> packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/add_newdocs.py", 
> line 13, in 
>  from numpy.lib import add_newdoc
>File 
> "/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-
> packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/lib/__init__.py", 
> line 18, in 
>  from .polynomial import *
>File 
> "/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-
> packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/lib/polynomial.py", 
> line 19, in 
>  from numpy.linalg import eigvals, lstsq, inv
>File 
> "/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-
> packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/linalg/__ini
> t__.py", 
> line 50, in 
>  from .linalg import *
>File 
> "/home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-
> packages/numpy-1.8.0-py2.7-linux-x86_64.egg/numpy/linalg/linalg.py", 
> line 29, in 
>  from numpy.linalg import lapack_lite, _umath_linalg
> ImportError: 
> /home/conrado/Canopy/appdata/canopy-1.5.5.3123.rh5-x86_64/lib/
> libgfortran.so.3: 
> version `GFORTRAN_1.4' not found (required by /lib64/liblapack.so.3)
> 
> 
> I did:  pip istall --user numpy
> 
> 
> Requirement already satisfied: numpy in 
> /home/conrado/Enthought/Canopy_64bit/User/lib/python2.7/site-p
> ackages/numpy-1.8.0-py2.7-linux-x86_64.egg
> 
> 
> What can I do to solve this message.
> 
> 
> Thanks,
> 
> 
> Conrado
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Sayth Renshaw wrote, on January 03, 2017 6:54 AM
> 
> Hi
> 
> This is simple, but its getting me confused.
> 
> I have a csv writer that opens a file and loops each line of 
> the file for each file and then closes, writing one file.
> 
> I want to alter the behaviour to be a written file for each 
> input file. I saw a roundrobin example however it failed for 
> me as you cannot get len(generator) to use a while loop on. 
> it exhausts
> 
> should I use the same for again after the with open?
> 
> rootobs in this code is my generator and I am already looping 
> it however 
> def data_attr(roots):
> """Get the root object and iter items."""
> for file in rootobs:
> base = os.path.basename(file.name)
> write_to = os.path.join("output", 
> os.path.splitext(base)[0] + ".csv")
> with open(write_to, 'w', newline='') as csvf:
> race_writer = csv.writer(csvf, delimiter=',')
> race_writer.writerow(
> ["meet_id", "meet_venue", "meet_date", "meet_rail",
>  ...
>  # other categories here
>  ...
> "jockeysurname", "jockeyfirstname"])
> for xml_data in roots:
> ...
> # parsing code
> for noms in race_child:
> if noms.tag == 'nomination':
> race_writer.writerow(
> [meet_id, meet_venue, meet_date,
>  ...
> #parsing info removed
> noms.get("jockeyfirstname")])
> 
> Cheers
> Sayth

What's the code for your generator? And I don't see where you call
'next'.

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


Re: pip install -r requirements.txt fails with Python 3.6 on Windows 10

2017-01-03 Thread Uri Even-Chen
Thank you, I'll consider to update our requirements to latest versions of
all packages. Last time I checked in 22th December 2016 and all our
requirements were the latest versions. In the meantime we can keep using
Python 3.5. By the way, Travis CI tests passed with the same requirements
and Python 3.6 (and 3.5 and 3.4). How did it install the requirements
there? Does it depend on the operating system?

I see now that Python 3.6.0 was released on 2016-12-23.

By the way we use Ubuntu 16.04 in production with Python 3.5.2, so it's not
that important to support Python 3.6 right now. What are the reasons to
upgrade Python to 3.6?

Thanks,
Uri.


*Uri Even-Chen*
[image: photo] Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
  
    

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
> Sayth Renshaw wrote, on January 03, 2017 6:54 AM
> > 
> > Hi
> > 
> > This is simple, but its getting me confused.
> > 
> > I have a csv writer that opens a file and loops each line of
> > the file for each file and then closes, writing one file.
> > 
> > I want to alter the behaviour to be a written file for each
> > input file. I saw a roundrobin example however it failed for 
> > me as you cannot get len(generator) to use a while loop on. 
> > it exhausts
> > 
> > should I use the same for again after the with open?
> > 
> > rootobs in this code is my generator and I am already looping
> > it however 
> > def data_attr(roots):
> > """Get the root object and iter items."""
> > for file in rootobs:
> > base = os.path.basename(file.name)
> > write_to = os.path.join("output", 
> > os.path.splitext(base)[0] + ".csv")
> > with open(write_to, 'w', newline='') as csvf:
> > race_writer = csv.writer(csvf, delimiter=',')
> > race_writer.writerow(
> > ["meet_id", "meet_venue", "meet_date", "meet_rail",
> >  ...
> >  # other categories here
> >  ...
> > "jockeysurname", "jockeyfirstname"])
> > for xml_data in roots:
> > ...
> > # parsing code
> > for noms in race_child:
> > if noms.tag == 'nomination':
> > race_writer.writerow(
> > [meet_id, meet_venue, meet_date,
> >  ...
> > #parsing info removed
> > 
> noms.get("jockeyfirstname")])
> > 
> > Cheers
> > Sayth
> 
> What's the code for your generator? And I don't see where you 
> call 'next'.

I think you're expecting 

for file in rootobs

to get the next yield for you from rootobs, but unless someone corrects
me, I don't think you can expect a 'for' statement to do that. You need
to have a 'next' statement inside your for loop to get the next yield
from the generator.

But I might not understand exactly what you're asking.


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


Clickable hyperlinks

2017-01-03 Thread Deborah Swanson
Excel has a formula:

=HYPERLINK(url,description)

that will put a clickable link into a cell.

Does python have an equivalent function? Probably the most common use
for it would be output to the console, similar to a print statement, but
clickable.

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
> > Sayth Renshaw wrote, on January 03, 2017 6:54 AM
> > > 
> > > Hi
> > > 
> > > This is simple, but its getting me confused.
> > > 
> > > I have a csv writer that opens a file and loops each line of the 
> > > file for each file and then closes, writing one file.
> > > 
> > > I want to alter the behaviour to be a written file for each input 
> > > file. I saw a roundrobin example however it failed for me as you 
> > > cannot get len(generator) to use a while loop on. it exhausts
> > > 
> > > should I use the same for again after the with open?
> > > 
> > > rootobs in this code is my generator and I am already looping it 
> > > however def data_attr(roots):
> > > """Get the root object and iter items."""
> > > for file in rootobs:
> > > base = os.path.basename(file.name)
> > > write_to = os.path.join("output", 
> > > os.path.splitext(base)[0] + ".csv")
> > > with open(write_to, 'w', newline='') as csvf:
> > > race_writer = csv.writer(csvf, delimiter=',')
> > > race_writer.writerow(
> > > ["meet_id", "meet_venue", "meet_date", 
> "meet_rail",
> > >  ...
> > >  # other categories here
> > >  ...
> > > "jockeysurname", "jockeyfirstname"])
> > > for xml_data in roots:
> > > ...
> > > # parsing code
> > > for noms in race_child:
> > > if noms.tag == 'nomination':
> > > race_writer.writerow(
> > > [meet_id, meet_venue, 
> meet_date,
> > >  ...
> > > #parsing info removed
> > > 
> > noms.get("jockeyfirstname")])
> > > 
> > > Cheers
> > > Sayth
> > 
> > What's the code for your generator? And I don't see where you
> > call 'next'.
> 
> I think you're expecting 
> 
>   for file in rootobs
> 
> to get the next yield for you from rootobs, but unless 
> someone corrects me, I don't think you can expect a 'for' 
> statement to do that. You need to have a 'next' statement 
> inside your for loop to get the next yield from the generator.
> 
> But I might not understand exactly what you're asking.

You probably want something like :

for f in rootobs:
file = next
base = os.path.basename(file.name) 
   .
   .
   .
  (etc)

Notice I changed your iterating variable name to 'f', so you can use
'file' throughout your code after you get the next one from rootobs.

As written, you'll get a StopIteration exception when rootobs runs out
of files, which you can catch with a try/except. Or you can just let the
code end there if you're done.

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


Re: Clickable hyperlinks

2017-01-03 Thread Devin Jeanpierre
Sadly, no. :(  Consoles (and stdout) are just text, not hypertext. The way
to make an URL clickable is to use a terminal that makes URLs clickable,
and print the URL:

print("%s: %s" % (description, url))

-- Devin

On Tue, Jan 3, 2017 at 11:46 AM, Deborah Swanson 
wrote:

> Excel has a formula:
>
> =HYPERLINK(url,description)
>
> that will put a clickable link into a cell.
>
> Does python have an equivalent function? Probably the most common use
> for it would be output to the console, similar to a print statement, but
> clickable.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip install -r requirements.txt fails with Python 3.6 on Windows 10

2017-01-03 Thread breamoreboy
On Tuesday, January 3, 2017 at 8:08:37 PM UTC, Uri Even-Chen wrote:
> Thank you, I'll consider to update our requirements to latest versions of
> all packages. Last time I checked in 22th December 2016 and all our
> requirements were the latest versions. In the meantime we can keep using
> Python 3.5. By the way, Travis CI tests passed with the same requirements
> and Python 3.6 (and 3.5 and 3.4). How did it install the requirements
> there? Does it depend on the operating system?
> 
> I see now that Python 3.6.0 was released on 2016-12-23.
> 
> By the way we use Ubuntu 16.04 in production with Python 3.5.2, so it's not
> that important to support Python 3.6 right now. What are the reasons to
> upgrade Python to 3.6?
> 
> Thanks,
> Uri.
> 
> 
> *Uri Even-Chen*
> [image: photo] Phone: +972-54-3995700
> Website: http://www.speedysoftware.com/uri/en/
>   
>     
> 


Go here http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow to get what you need.

In all my years of downloading from this site I've never, ever had a problem.

Kindest regards.

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson

> > > Sayth Renshaw wrote, on January 03, 2017 6:54 AM
> > > > 
> > > > Hi
> > > > 
> > > > This is simple, but its getting me confused.
> > > > 
> > > > I have a csv writer that opens a file and loops each line of the
> > > > file for each file and then closes, writing one file.
> > > > 
> > > > I want to alter the behaviour to be a written file for 
> each input
> > > > file. I saw a roundrobin example however it failed for 
> me as you 
> > > > cannot get len(generator) to use a while loop on. it exhausts
> > > > 
> > > > should I use the same for again after the with open?
> > > > 
> > > > rootobs in this code is my generator and I am already looping it
> > > > however def data_attr(roots):
> > > > """Get the root object and iter items."""
> > > > for file in rootobs:
> > > > base = os.path.basename(file.name)
> > > > write_to = os.path.join("output", 
> > > > os.path.splitext(base)[0] + ".csv")
> > > > with open(write_to, 'w', newline='') as csvf:
> > > > race_writer = csv.writer(csvf, delimiter=',')
> > > > race_writer.writerow(
> > > > ["meet_id", "meet_venue", "meet_date", 
> > "meet_rail",
> > > >  ...
> > > >  # other categories here
> > > >  ...
> > > > "jockeysurname", "jockeyfirstname"])
> > > > for xml_data in roots:
> > > > ...
> > > > # parsing code
> > > > for noms in race_child:
> > > > if noms.tag == 'nomination':
> > > > race_writer.writerow(
> > > > [meet_id, meet_venue,
> > meet_date,
> > > >  ...
> > > > #parsing info removed
> > > > 
> > > noms.get("jockeyfirstname")])
> > > > 
> > > > Cheers
> > > > Sayth
> > > 
> > > What's the code for your generator? And I don't see where 
> you call 
> > > 'next'.
> > 
> > I think you're expecting
> > 
> > for file in rootobs
> > 
> > to get the next yield for you from rootobs, but unless
> > someone corrects me, I don't think you can expect a 'for' 
> > statement to do that. You need to have a 'next' statement 
> > inside your for loop to get the next yield from the generator.
> > 
> > But I might not understand exactly what you're asking.
> 
> You probably want something like :
> 
> for f in rootobs:
> file = next
> base = os.path.basename(file.name) 
>.
>.  
>.
>   (etc)
> 
> Notice I changed your iterating variable name to 'f', so you 
> can use 'file' throughout your code after you get the next 
> one from rootobs.
> 
> As written, you'll get a StopIteration exception when rootobs 
> runs out of files, which you can catch with a try/except. Or 
> you can just let the code end there if you're done.

Well rats, I'm embarrassed. It's been awhile since I've used a generator
and I forgot that you have to create the generator object first and use
it to call the next function. And I really don't think you can use a
generator as your range in a for loop. So I'd use a 'while True', and
break out of the loop when you hit the StopIteration exception:

files = rootobs()

while True:
  try: 
file = files.next()
  except StopIteration:
break

base = os.path.basename(file.name) 
   .
   .
   .
  (etc)

(Now I'm just going to shut up, until somebody else says something.)

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


RE: Re: Clickable hyperlinks

2017-01-03 Thread Deborah Swanson
Devin Jeanpierre wrote, on January 03, 2017 12:57 PM

>Sadly, no. :(  Consoles (and stdout) are just text, not hypertext. The
way to 
>make an URL clickable is to use a terminal that makes URLs clickable,
and  
>print the URL:
>
>
>print("%s: %s" % (description, url))
>
>
>
>
>-- Devin

I'm sorry, I should have said a GUI console because I wouldn't expect a
text-based console to produce clickable links. But it appears that a
simple GUI console can't do it either. I have 3 GUI consoles and in all
3, when I ask:

print("%s: %s" % ("python.org list",
"https://mail.python.org/mailman/listinfo/python-list";))

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

(Outlook made the url clickable here, the python GUI consoles just
output plain text.)

Pretty clearly the output is plain text because your format parameters
are %s. Maybe the trick, if there is one, is in a format parameter for
urls.



On Tue, Jan 3, 2017 at 11:46 AM, Deborah Swanson
 wrote:

Excel has a formula:

=HYPERLINK(url,description)

that will put a clickable link into a cell.

Does python have an equivalent function? Probably the most common use
for it would be output to the console, similar to a print statement, but
clickable.

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

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


RE: Clickable hyperlinks

2017-01-03 Thread Dan Strohl via Python-list
The best bet (unless you know that you are outputting to a specific place, like 
html or excel) is to always include the "https://"; or "http://"; since most of 
the consoles / terminals that support clickable links are parsing them based on 
"seeing" the initial "http://";.  If your output just looks like 
"mysite.com/coolpage.html", many systems will simply ignore them.

At one point I had made a class that you could pass the link to, and then you 
could request different output based on your needs... so basically something 
like:

>> url = url_class("mysite.com/coolpage.html")
>> print(url) 
"http://mysite.com/coolpage.html";)
>> print(url.plain)
"mysite.com/coolpage.html"
>> print(url.html('My Site"))
'http://mysite.com/coolpage.html";>My Site'

(or whatever... I think I actually just sub-classed url.parse or something)




-Original Message-
From: Python-list [mailto:python-list-bounces+d.strohl=f5@python.org] On 
Behalf Of Devin Jeanpierre
Sent: Tuesday, January 03, 2017 12:57 PM
To: pyt...@deborahswanson.net
Cc: comp.lang.python 
Subject: Re: Clickable hyperlinks

Sadly, no. :(  Consoles (and stdout) are just text, not hypertext. The way to 
make an URL clickable is to use a terminal that makes URLs clickable, and print 
the URL:

print("%s: %s" % (description, url))

-- Devin

On Tue, Jan 3, 2017 at 11:46 AM, Deborah Swanson 
wrote:

> Excel has a formula:
>
> =HYPERLINK(url,description)
>
> that will put a clickable link into a cell.
>
> Does python have an equivalent function? Probably the most common use 
> for it would be output to the console, similar to a print statement, 
> but clickable.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screwing Up looping in Generator

2017-01-03 Thread Matt Wheeler
On Tue, 3 Jan 2017 at 20:17 Deborah Swanson 
wrote:

> > What's the code for your generator? And I don't see where you
> > call 'next'.
>
> I think you're expecting
>
> for file in rootobs
>
> to get the next yield for you from rootobs, but unless someone corrects
> me, I don't think you can expect a 'for' statement to do that. You need
> to have a 'next' statement inside your for loop to get the next yield
> from the generator.
>

Yes, you absolutely can expect a for statement to do that. It will accept
any iterable as its `y`.

`for x in y: stuff(x)` is effectively syntactic sugar for:

iterator = iter(y)
while True:
try:
x = next(iterator)
except(StopIteration):
break
stuff(x)

Manually calling `next()` inside a `while True:` is quite an unusual thing
to do.

range() is not part of the for syntax at all, it's completely separate, it
simply returns an iterator which the for loop can use, like any other.
-- 

--
Matt Wheeler
http://funkyh.at
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Re: Clickable hyperlinks

2017-01-03 Thread Dan Strohl via Python-list
Keeping mind how this all works... 

Python is providing the data, the console/terminal/app handles how that data is 
displayed.   There is no specification for text output to be hyperlinked (that 
I know about at least), so while some apps may handle specific coding to tell 
them that "this text should be a hyperlink", most will either parse the text 
looking for hyper-linkable string, or more commonly, just output the text as 
text.

If you control the app that is displaying info to the user (such as using QT or 
another GUI tool), or generating html yourself, you can control if a text 
string is a hyperlink or not, and what to do with the hyperlink when clicked.  

So, if you want clickable links, you would need to find a console/terminal that 
supported them.

Some references:
https://opensource.com/life/15/11/top-open-source-terminal-emulators  (see 
Gnome)
http://unix.stackexchange.com/questions/63417/is-there-a-terminal-app-that-allows-filenames-to-be-clickable
http://superuser.com/questions/654116/configure-os-x-terminal-to-detect-urls-and-make-them-clickable
http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/url-launching.html


-Original Message-
From: Python-list [mailto:python-list-bounces+d.strohl=f5@python.org] On 
Behalf Of Deborah Swanson
Sent: Tuesday, January 03, 2017 1:35 PM
To: 'Devin Jeanpierre' 
Cc: 'comp.lang.python' 
Subject: RE: Re: Clickable hyperlinks

Devin Jeanpierre wrote, on January 03, 2017 12:57 PM

>Sadly, no. :(  Consoles (and stdout) are just text, not hypertext. The
way to 
>make an URL clickable is to use a terminal that makes URLs clickable,
and  
>print the URL:
>
>
>print("%s: %s" % (description, url))
>
>
>
>
>-- Devin

I'm sorry, I should have said a GUI console because I wouldn't expect a 
text-based console to produce clickable links. But it appears that a simple GUI 
console can't do it either. I have 3 GUI consoles and in all 3, when I ask:

print("%s: %s" % ("python.org list",
"https://mail.python.org/mailman/listinfo/python-list";))

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

(Outlook made the url clickable here, the python GUI consoles just output plain 
text.)

Pretty clearly the output is plain text because your format parameters are %s. 
Maybe the trick, if there is one, is in a format parameter for urls.



On Tue, Jan 3, 2017 at 11:46 AM, Deborah Swanson  
wrote:

Excel has a formula:

=HYPERLINK(url,description)

that will put a clickable link into a cell.

Does python have an equivalent function? Probably the most common use for it 
would be output to the console, similar to a print statement, but clickable.

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

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


Re: pip install -r requirements.txt fails with Python 3.6 on Windows 10

2017-01-03 Thread Terry Reedy

On 1/3/2017 3:07 PM, Uri Even-Chen wrote:

What are the reasons to upgrade Python to 3.6?


The same as for any new version:
New features  -- see What's New in 3.6.
New bug fixes.
New performance improvements.

Reasons against:
The effort to make sure all dependencies are available for 3.6*
Possible regressions.

* For Windows, any of the 381 wheels available from 
http://www.lfd.uci.edu/~gohlke/pythonlibs/
should be available in 3.6 versions (unless there was a major problem in 
recompiling).


--
Terry Jan Reedy

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


Re: Screwing Up looping in Generator

2017-01-03 Thread Matt Wheeler
On Tue, 3 Jan 2017 at 21:46 Matt Wheeler  wrote:

> range() is not part of the for syntax at all, it's completely separate, it
> simply returns an iterator which the for loop can use, like any other.
>

*iterable
-- 

--
Matt Wheeler
http://funkyh.at
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screwing Up looping in Generator

2017-01-03 Thread Terry Reedy

On 1/3/2017 3:53 PM, Deborah Swanson wrote:


I think you're expecting

for file in rootobs

to get the next yield for you from rootobs, but unless
someone corrects me, I don't think you can expect a 'for'
statement to do that. You need to have a 'next' statement
inside your for loop to get the next yield from the generator.


As I read this, out of context, it is wrong.  It it very unusual to call 
next on the current iterator (here next(rootobs)), inside a for loop.



You probably want something like :

for f in rootobs:
file = next


This is definitely wrong, as it makes 'find' an alias for the next() 
function.



base = os.path.basename(file.name)


and file.name will be an AttributeError.

---
If one wants to iterate through files and lines within files, which I 
believe I saw in this thread, one should have a for loop within a for loop.


--
Terry Jan Reedy

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


How Best to Coerce Python Objects to Integers?

2017-01-03 Thread breamoreboy
Hi all, I'd suggest that this 
http://blog.pyspoken.com/2017/01/02/how-best-to-coerce-python-objects-to-integers/
 is not one of the greatest articles ever written about Python exception 
handling.  Other opinions are welcome.

Kindest regards.

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Terry Reedy
> 
> On 1/3/2017 3:53 PM, Deborah Swanson wrote:
> 
> >> I think you're expecting
> >>
> >>for file in rootobs
> >>
> >> to get the next yield for you from rootobs, but unless someone 
> >> corrects me, I don't think you can expect a 'for' statement to do 
> >> that. You need to have a 'next' statement inside your for 
> loop to get 
> >> the next yield from the generator.
> 
> As I read this, out of context, it is wrong.  It it very 
> unusual to call 
> next on the current iterator (here next(rootobs)), inside a for loop.
> 
> > You probably want something like :
> >
> > for f in rootobs:
> > file = next
> 
> This is definitely wrong, as it makes 'find' an alias for the next() 
> function.
> 
> > base = os.path.basename(file.name)
> 
> and file.name will be an AttributeError.
> 
> ---
> If one wants to iterate through files and lines within files, which I 
> believe I saw in this thread, one should have a for loop 
> within a for loop.
> 
> -- 
> Terry Jan Reedy

Yes, my first attempts were screwups. I didn't remember generator usage
correctly, but I believe my last answer was correct:

...you have to create the generator object first and use it to call the
next function. And I really don't think you can use a generator as your
range in a for loop. So I'd use a 'while True', and break out of the
loop when you hit the StopIteration exception:

files = rootobs()

while True:
  try: 
file = files.next()
  except StopIteration:
break

base = os.path.basename(file.name) 
   .
   .
   .
  (etc)

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


Re: Screwing Up looping in Generator

2017-01-03 Thread Chris Angelico
On Wed, Jan 4, 2017 at 8:19 AM, Deborah Swanson
 wrote:
> while True:
>   try:
> file = files.next()
>   except StopIteration:
> break

Small side point: Try to avoid calling a generator object's .next()
method directly. Normally, when you _do_ want to do this, you should
be calling next(files). In Python 3, the magic method is now
__next__(), which emphasizes that it's for defining, not calling.

As others have pointed out, though, the for loop is the correct tool
for this job.

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


Re: Clickable hyperlinks

2017-01-03 Thread Tim Chase
On 2017-01-03 11:46, Deborah Swanson wrote:
> Excel has a formula:
> 
> =HYPERLINK(url,description)
> 
> that will put a clickable link into a cell.
> 
> Does python have an equivalent function? Probably the most common
> use for it would be output to the console, similar to a print
> statement, but clickable.

Depends on what you're outputting.  In your context, you're creating
content (and metadata) for a cell in an Excel workbook.

If that's the case you might have to use something like the xlwt
module to create an Excel-style worksheet and adjust the properties
of the cell to include the hyperlink property.

Or you can write out a .csv file with a hyperlink in a cell, which I
believe Excel can interpret as a hyperlink.

Or write an HTML document with the corresponding HTML  tag in it.

Or you can just print it to stdout as normal as some terminals detect
them and auto-linkify them.

But you have to specify where you want this link to appear to know
how to solve the problem.

-tkc



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


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Chris Angelico
On Wed, Jan 4, 2017 at 8:41 AM,   wrote:
> Hi all, I'd suggest that this 
> http://blog.pyspoken.com/2017/01/02/how-best-to-coerce-python-objects-to-integers/
>  is not one of the greatest articles ever written about Python exception 
> handling.  Other opinions are welcome.
>

"""
So there you have it. I’m happy with this function. It feels
bulletproof. It contains a naked except, but that only covers one
simple line of code that’s unlikely to hide anything nasty.
"""

Yep! It's perfect. He has successfully made a function that won't leak
any exceptions. Congratulations!

The novice believes that the first priority is to stop the program
from crashing. The expert understands that crashing (especially with
an exception, but even a segfault) is actually very helpful and
useful.

I love the logic that a bare 'except' is okay as long as it's only
covering one single line of code. There's almost enough truth in that
to be meaningful, while still completely missing the point that a
NameError is almost certainly a bug no matter where it crops up.

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


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Ethan Furman

On 01/03/2017 01:41 PM, breamore...@gmail.com wrote:


Hi all, I'd suggest that this [1] is not one of the greatest articles
 ever written about Python exception handling.  Other opinions are welcome.


Aside from calling "except Exception" a "naked except" I think it's decent.  He 
walks through the problem, explains the rationale, and only has one line of code guarded by the 
except clause.

--
~Ethan~

[1] 
http://blog.pyspoken.com/2017/01/02/how-best-to-coerce-python-objects-to-integers/
--
https://mail.python.org/mailman/listinfo/python-list


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Chris Angelico
On Wed, Jan 4, 2017 at 9:42 AM, Ethan Furman  wrote:
> Aside from calling "except Exception" a "naked except"

If you read the comments, you'll see that he originally had an actual
bare except clause, but then improved the code somewhat in response to
a recommendation that SystemExit etc not be caught.

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Chris Angelico wrote, on January 03, 2017 2:31 PM
> 
> On Wed, Jan 4, 2017 at 8:19 AM, Deborah Swanson 
>  wrote:
> > while True:
> >   try:
> > file = files.next()
> >   except StopIteration:
> > break
> 
> Small side point: Try to avoid calling a generator object's 
> .next() method directly. Normally, when you _do_ want to do 
> this, you should be calling next(files). In Python 3, the 
> magic method is now __next__(), which emphasizes that it's 
> for defining, not calling.
> 
> As others have pointed out, though, the for loop is the 
> correct tool for this job.
> 
> ChrisA

Ok, I learned how to use generators in Python 2.7.8, which may be
different from Python 3 for generators. But I learned from MIT's online
introduction to python course, and they certainly seem to know python
well. So what is the correct way to call the generator's next yield in
Python 3? We only learned to use the next function. If you don't use the
next function, what do you use?

And yes, we usually used for loops for generators, unless you don't know
when the generator will be exhausted. As in this case, where the number
of files the generator can provide is unknown. Then we used the while
True, break on StopIteration method.

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


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Ethan Furman

On 01/03/2017 02:47 PM, Chris Angelico wrote:

On Wed, Jan 4, 2017 at 9:42 AM, Ethan Furman wrote:



Aside from calling "except Exception" a "naked except"


If you read the comments, you'll see that he originally had an actual
bare except clause, but then improved the code somewhat in response to
a recommendation that SystemExit etc not be caught.


I did read the comments and noticed the reasons for the improved code; fixing the article 
to not use the "naked except" phrase would be another improvement.

And, of course, whether or not "except Exception" is too broad depends on the 
use-case.

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


Re: Clickable hyperlinks

2017-01-03 Thread Grant Edwards
On 2017-01-03, Deborah Swanson  wrote:

> I'm sorry, I should have said a GUI console because I wouldn't expect a
> text-based console to produce clickable links.

What's a "GUI console"?

-- 
Grant Edwards   grant.b.edwardsYow! I want you to MEMORIZE
  at   the collected poems of
  gmail.comEDNA ST VINCENT MILLAY
   ... BACKWARDS!!

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
 

-Original Message-
From: Matt Wheeler [mailto:m...@funkyhat.org] 
Sent: Tuesday, January 03, 2017 1:47 PM
To: pyt...@deborahswanson.net; Sayth Renshaw; python-list@python.org
Subject: Re: Screwing Up looping in Generator


On Tue, 3 Jan 2017 at 20:17 Deborah Swanson 
wrote:

> What's the code for your generator? And I don't see where you
> call 'next'.

I think you're expecting

for file in rootobs

to get the next yield for you from rootobs, but unless someone corrects
me, I don't think you can expect a 'for' statement to do that. You need
to have a 'next' statement inside your for loop to get the next yield
from the generator.




Yes, you absolutely can expect a for statement to do that. It will
accept any iterable as its `y`. 
 
>> And here is someone correcting me, which I sort of suspected there
might be. Yes, 
>> range is an iterator, but I didn't know a generator could also be
used as an iterator.  
>> Makes perfect sense though, a generator does dispense its yields in
the sequence 
>> defined by the generator.


`for x in y: stuff(x)` is effectively syntactic sugar for:


iterator = iter(y)
while True:
try:
x = next(iterator)
except(StopIteration):
break
stuff(x)

Manually calling `next()` inside a `while True:` is quite an unusual
thing to do. 
 
>> And you don't need to do it very often. The only use case I know is
this one, where the number of yields the generator can output is unknown
(here, the number of files the generator can access is unknown). You
might recall that the original poster wanted to use a while, but didn't
know how to terminate it. At least that's how I interpreted what he was
saying.


range() is not part of the for syntax at all, it's completely separate,
it simply returns an iterator which the for loop can use, like any
other. 
--  
 
>> I see that now, I just didn't know a generator could be used as an
iterator.

--
Matt Wheeler
http://funkyh.at

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


Re: Simulating int arithmetic with wrap-around

2017-01-03 Thread Paul Rubin
Steve D'Aprano  writes:
> Again, assume both operands are in range for an N-bit signed integer. What's
> a good way to efficiently, or at least not too inefficiently, do the
> calculations in Python?

My first thought is towards the struct module, especially if you want to
handle a bunch of such integers at the same time.  Or maybe the array
module or some combination.  Or a C extension.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-03 Thread Erik

Hi.

On 03/01/17 19:46, Deborah Swanson wrote:

Excel has a formula:


When you start a new topic on the list, could you please write a new 
message rather than replying to an existing message and changing the 
title/subject?


For those reading the list in a threaded email client, this message is 
shown as a continuation of your "Cleaning up conditionals" thread, and 
that whole thread in turn shows up as a continuation of the "mentor 
training python Romania with certification" discussion (which you had 
presumably "reply"ed to originally) ...


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


RE: Clickable hyperlinks

2017-01-03 Thread Deborah Swanson
Grant Edwards wrote, on January 03, 2017 3:13 PM
> 
> On 2017-01-03, Deborah Swanson  wrote:
> 
> > I'm sorry, I should have said a GUI console because I 
> wouldn't expect 
> > a text-based console to produce clickable links.
> 
> What's a "GUI console"?
> 
> -- 
> Grant Edwards   grant.b.edwardsYow! I 
> want you to MEMORIZE
>   at   the 
> collected poems of
>   gmail.comEDNA ST 
> VINCENT MILLAY

The GUI consoles I have are in Pycharm, the IDLE that comes with
Anaconda, and Spyder. PyCharm and IDLE both ask for internet access when
I open them, so they're capable of opening links, but whether that means
their output space is capable of handling clickable links I don't know.

I do know printing a full url with the %s specifier or entering a url
and clicking enter just gives you the plain text url. Obviously, not all
GUI consoles are enabled recognize and make clickable links from
correctly formatted urls.

I was hoping there was some functionality in python to make clickable
links. Could be a package, if the core language doesn't have it.

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


Re: Cleaning up conditionals

2017-01-03 Thread Paul Rubin
"Deborah Swanson"  writes:
> I'm still wondering if these 4 lines can be collapsed to one or two
> lines.

In the trade that's what we call a "code smell", a sign that code
(even if it works) should probably be re-thought after taking a step
back to understand what it is really trying to do.

What you seem to want is to take two strings, and if exactly one of them
is empty, then change the empty one to be the same as the non-empty one.
Leaving aside the subscripts and just calling them x and y,

   x, y = x or y, y or x

is a concise way to do it.

That's also smelly since 1) it's overly cute, and 2) it's not clear to
me why you'd want to do this operation.  It seems like an odd thing to
want so maybe there's some different way to solve the surrounding
problem.  If you want to describe the actual application and context
where this appears, that might get some helpful comments.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screwing Up looping in Generator

2017-01-03 Thread Chris Angelico
On Wed, Jan 4, 2017 at 10:05 AM, Deborah Swanson
 wrote:
> Ok, I learned how to use generators in Python 2.7.8, which may be
> different from Python 3 for generators. But I learned from MIT's online
> introduction to python course, and they certainly seem to know python
> well. So what is the correct way to call the generator's next yield in
> Python 3? We only learned to use the next function. If you don't use the
> next function, what do you use?

The built-in next function, not the next method.

# don't do this
gen.next()

# do this
next(gen)

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


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Steve D'Aprano
On Wed, 4 Jan 2017 09:47 am, Chris Angelico wrote:

> On Wed, Jan 4, 2017 at 9:42 AM, Ethan Furman  wrote:
>> Aside from calling "except Exception" a "naked except"
> 
> If you read the comments, you'll see that he originally had an actual
> bare except clause, but then improved the code somewhat in response to
> a recommendation that SystemExit etc not be caught.

But why? That makes no sense. If his intention is to return None on failure,
no matter what happens, then he *should* catch SystemExit. Otherwise:

class Unint:
def __int__(self):
raise SystemExit

int_or_else(Unint)


will exit instead of returning None. Surely that's not what he wants, given
that he wants to cover up other programming errors like NameError and
TypeError?

The problem here is not so much the use of try...except but the *intention*
that "Anything whatsoever should be coerced to int". If you have something
like:

left_margin = int_or_else(ftp_server)

that's surely a programming error that needs fixing, rather than something
that should just return a default value.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Screwing Up looping in Generator

2017-01-03 Thread Erik

Hi,

On 03/01/17 22:14, Deborah Swanson wrote:

...you have to create the generator object first and use it to call the
next function. And I really don't think you can use a generator as your
range in a for loop. So I'd use a 'while True', and break out of the
loop when you hit the StopIteration exception:

files = rootobs()

while True:
  try:
file = files.next()
  except StopIteration:
break

base = os.path.basename(file.name)
   .
   .
   .
  (etc)


What you have done there is taken an understanding of the underlying 
machinery that allows the 'for' loop to be syntactic sugar over any 
iterable and spelled it out, instead of just using 'for'! Without all 
that, your example is:


for file in rootobs():
  base = os.path.basename(file.name)
  .
  .
  .
  (etc)

[In fact, the machinery would also cope with the return value from 
rootobs() being an iterable but not an iterator by using "files = 
iter(rootobjs)"].




You seem to be reading up on how the stuff works under the covers (i.e., 
from the point of view of an implementer of a class or library) and then 
suggesting that that's what the *caller* of that class or library needs 
to do. They don't - for a caller, 'for x in seq:' is all they need to 
know - the mechanics are handled by the interpreter coupled with the 
dunder methods that the class may implement.



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


Hey, I'm new to python so don't judge.

2017-01-03 Thread cr2001
Im doing a new task from my teacher but i can't seem to find what is wrong with 
this code. Can anyone help?

#mynumber.py
# this game uses a home made function
import random

#think of a number
computer_number = number.randint(1,100)

#create the function is_same()
def is_same(target, number:
if target == number:
result="win"
elif target > number:
result="low"
else:
result="high"
return result

# start the game
print("hello. \nI have thought of a number between 1 and 100.")

#collect the user's guess as an interger
guess = int(input("Can you guess it? "))
#Use our function
higher_or_lower = is_same(computer_number, guess)
#run the game untill the user is correct
while higher_or_lower != "win"
if higher_or_lower == "to low"
 guess = int(input("Sorry, you are too low. Try again."))
else:
guess = int(input("Sorry your are too high. Try again."))

higher_or_lower = is_same(computer_number, guess)

#end of game
input("Correct!\nWell Done\n\n\nPress RETURN to exit.")




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


Re: Screwing Up looping in Generator

2017-01-03 Thread Erik

On 03/01/17 23:05, Deborah Swanson wrote:

And yes, we usually used for loops for generators, unless you don't know
when the generator will be exhausted. As in this case, where the number
of files the generator can provide is unknown. Then we used the while
True, break on StopIteration method.


Out of interest, *why* was it deemed necessary to do something different 
if you don't know how many items the generator will generate? Was any 
rationale given for that?


for x in foo:
  bar(x)

... where foo is any iterable (something that has a __iter__ method 
defined - including generators) will just bind each value in turn to 'x' 
and will exit when the StopIteration exception is raised under the 
covers by the iterator that is iterating over the iterable.


Some generators are infinite (and their iterator will never raise a 
StopIteration exception).


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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Chris Angelico
On Wed, Jan 4, 2017 at 10:49 AM,   wrote:
> Im doing a new task from my teacher but i can't seem to find what is wrong 
> with this code. Can anyone help?
>
> #mynumber.py
> # this game uses a home made function
> import random
>
> #think of a number
> computer_number = number.randint(1,100)

What's wrong is that you aren't showing us the exception you get on
this line. *Copy and paste* that exception - the whole thing. It's
very helpful.

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


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Chris Angelico
On Wed, Jan 4, 2017 at 10:39 AM, Steve D'Aprano
 wrote:
> The problem here is not so much the use of try...except but the *intention*
> that "Anything whatsoever should be coerced to int". If you have something
> like:
>
> left_margin = int_or_else(ftp_server)
>
> that's surely a programming error that needs fixing, rather than something
> that should just return a default value.

Agreed. There are certainly times when you want to say "coerce any
*string* to an int", and there are times when you want to say "coerce
any string to int or None" (maybe you want to take the average of a
whole lot of values, ignoring the ones that say "N/A"), but I don't
know of any time I want to say "coerce any programming error to int or
None", unless you count the exit code of a process.

I used the word "improved" rather loosely.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Erik

On 03/01/17 23:56, Chris Angelico wrote:

On Wed, Jan 4, 2017 at 10:49 AM,   wrote:

#think of a number
computer_number = number.randint(1,100)


What's wrong is that you aren't showing us the exception you get on
this line. *Copy and paste* that exception - the whole thing. It's
very helpful.


I doubt it's getting that far (I can see at least one syntax error in 
the code pasted).


cr2001: I echo Chris's sentiment though - what is the error you are 
seeing (in it's entirety)?


E.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
When i check the code it comes up with invalid syntax and my writing line gets 
re directed here

def is_same(target, number:
if target == number:
result="win"
elif target > number:
result="low"
else:
result="high"
return result
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-03 Thread Dietmar Schwertberger

On 02.01.2017 12:38, Antonio Caminero Garcia wrote:

The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, 
Pycharm) is that they look like a space craft dashboard and that unwarranted 
resources consumption and the unnecessary icons.
You did not try Wing IDE? It looks less like a spacecraft. Maybe you 
like it.
Maybe the difference is that Wing is from Python people while the ones 
you listed are from Java people.
For something completely different (microcontroller programming in C) I 
just switched to a Eclipse derived IDE and I don't like it too much as 
the tool does not focus on the problem scope.


From your posts I'm not sure whether you want an editor or an IDE, 
where for me the main difference is the debugger and code completion.
I would not want to miss the IDE features any more, even though in my 
first 15 years of Python I thought that a debugger is optional with 
Python ...


Regards,

Dietmar

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Chris Angelico
On Wed, Jan 4, 2017 at 11:03 AM, Erik  wrote:
> I doubt it's getting that far (I can see at least one syntax error in the
> code pasted).

True true. In any case, the point is to copy and paste the error
message. Callum, please, copy and paste it.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 1:03:18 PM UTC+13, Erik wrote:
> On 03/01/17 23:56, Chris Angelico wrote:
> > On Wed, Jan 4, 2017 at 10:49 AM,   wrote:
> >> #think of a number
> >> computer_number = number.randint(1,100)
> >
> > What's wrong is that you aren't showing us the exception you get on
> > this line. *Copy and paste* that exception - the whole thing. It's
> > very helpful.
> 
> I doubt it's getting that far (I can see at least one syntax error in 
> the code pasted).
> 
> cr2001: I echo Chris's sentiment though - what is the error you are 
> seeing (in it's entirety)?
> 
> E.

My apologizes but i'm quite new and would need instructions to what information 
you need me to get.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Erik

On 03/01/17 22:47, Chris Angelico wrote:

On Wed, Jan 4, 2017 at 9:42 AM, Ethan Furman  wrote:

Aside from calling "except Exception" a "naked except"


If you read the comments, you'll see that he originally had an actual
bare except clause, but then improved the code somewhat in response to
a recommendation that SystemExit etc not be caught.


But, as stated at the top of the article, his brief was: "The strings 
come from a file that a human has typed in, so even though most of the 
values are good, a few will have errors ('25C') that int() will reject.".


What he *should* have done is just validated his input strings before 
presenting the string to int() - i.e., process the input with knowledge 
that is specific to the problem domain before calling the 
general-purpose function.


He mentions temperature sensors, so perhaps stripping a trailing 'c' or 
'C' is a reasonable thing to do (or even, if there's a trailing 'f' or 
'F', performing a numerical conversion after the value is known).


Instead, he tried to patch around int() rejecting the strings. And then 
decided that he'd patch around int() rejecting things that weren't even 
strings even though that's not what the function has (apparently) been 
specified to receive.


The "bulletproof" result will convert "25C" to None even though 25 is 
probably a reasonable result for that string in his domain problem domain.


E.



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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Erik

Hi Callum,

On 04/01/17 00:02, Callum Robinson wrote:
> When i check the code it comes up with invalid syntax and my writing 
line gets re directed here

>
> def is_same(target, number:
> if target == number:
> result="win"
> elif target > number:
> result="low"
> else:
> result="high"
> return result

OK, good. That implies it's something wrong with the function definition 
('def'). Look at that very carefully :)   (*)


E.

(*) My emoticon may give you a hint ...
--
https://mail.python.org/mailman/listinfo/python-list


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Steve D'Aprano
On Wed, 4 Jan 2017 10:09 am, Ethan Furman wrote:

> And, of course, whether or not "except Exception" is too broad depends on
> the use-case.

I'm having trouble thinking of *any* use-case where this would be useful.
His intention, it seems, is to write a function which simply cannot fail,
presumably so that he can write code which consumes the output and just
keeps going no matter what he throws at it:

graph = make_graph()
incoming_data = [1, 12, 7, "hello", None, [], {}, 5]
for obj in incoming_data:
graph.draw_point(int_or_else(obj))


But of course that's impossible:

class Evil:
def __int__(self):
os.abort()

Or for that matter:

class Evil:
def __int__(self):
time.sleep(2147483647)



So his code still can fail under some circumstances. And so it should. Why
is my input data including such evil objects? I should find out why. I'm
having trouble seeing how it could be anything but a programming bug.


He gives the rationale for this function:

A scenario that’s more realistic than the Unintable class might
be a class that wraps an industrial sensor. Calling int() on an
instance normally returns a value representing pressure or
temperature. However, it might reasonably raise a
SensorNotReadyError.

Okay. Let's suppose it can return either an integer as a string, some
arbitrary non-numeric string to indicate a sensor error, or raises
SensorNotReadyError. Then this would be an appropriate function to use:

def int_or_else(value):
try:
return int(value)
except ValueError:
assert isinstance(value, str)
# consider logging the error?
return None
except SensorNotReadyError:
return None


Now when he connects up to the sensor and starts reading values, it will
work, but if his input gets contaminated with arbitrary junk objects (a
sign of a programming bug in his code) he will find out about it.


One possible use-case might be something like Excel, where there are two
data types: numbers, and text, and numeric operations on text will just
skip them altogether. If you were to build an object-oriented spreadsheet,
where the cells can contain any object not just numbers and text, then you
could potentially have a situation like:

Column A
Row 1:  1
Row 2:  ftp_server()
Row 3:  2
Row 4:  3
Row 5:  =sum(A1:A4)

and you (arguably) want the result to be 6 rather than some error. Or do
you? I can make a good case for skipping text cells, as Excel does, but I'm
not sure that ftp_server should be skipped. So I'll count that as a
use-case, but a dubious one.

Another possible use-case might be the REPL for an interpreter, where you
want the REPL to keep going no matter what exceptions take place. But I
don't think this is the right way to do that, and it's not how the Python
REPL works either.

Other than that, I'm not seeing any use-case where this sort of thing is
anything but a bad idea.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 1:17:11 PM UTC+13, Chris Angelico wrote:
> On Wed, Jan 4, 2017 at 11:03 AM, Erik  wrote:
> > I doubt it's getting that far (I can see at least one syntax error in the
> > code pasted).
> 
> True true. In any case, the point is to copy and paste the error
> message. Callum, please, copy and paste it.
> 
> ChrisA

I'm sorry if I'm doing something wrong but all that is happening is when i try 
to run it a popup says Invalid syntax
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 1:26:26 PM UTC+13, Erik wrote:
> Hi Callum,
> 
> On 04/01/17 00:02, Callum Robinson wrote:
>  > When i check the code it comes up with invalid syntax and my writing 
> line gets re directed here
>  >
>  > def is_same(target, number:
>  > if target == number:
>  > result="win"
>  > elif target > number:
>  > result="low"
>  > else:
>  > result="high"
>  > return result
> 
> OK, good. That implies it's something wrong with the function definition 
> ('def'). Look at that very carefully :)   (*)
> 
> E.
> 
> (*) My emoticon may give you a hint ...

I feel like im missing something so blatantly obvious. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 1:26:26 PM UTC+13, Erik wrote:
> Hi Callum,
> 
> On 04/01/17 00:02, Callum Robinson wrote:
>  > When i check the code it comes up with invalid syntax and my writing 
> line gets re directed here
>  >
>  > def is_same(target, number:
>  > if target == number:
>  > result="win"
>  > elif target > number:
>  > result="low"
>  > else:
>  > result="high"
>  > return result
> 
> OK, good. That implies it's something wrong with the function definition 
> ('def'). Look at that very carefully :)   (*)
> 
> E.
> 
> (*) My emoticon may give you a hint ...

I forgot a bloody bracket xD

and now theirs a new error ill try to figure this out on my own.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Erik

Hi Callum,

On 04/01/17 00:30, Callum Robinson wrote:

I feel like im missing something so blatantly obvious.


That's because you are ;). I don't want to come across as patronising, 
but I want you to see it for yourself, so, here's a function definition 
similar to yours that doesn't have the same syntax error that yours does:


def foo(spam, ham):
if spam == ham:
return "same"
return "different"

See the difference?

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Erik

On 04/01/17 00:32, Callum Robinson wrote:

I forgot a bloody bracket xD


Cool, you got it ;) It's the sort of thing your brain will see instantly 
once you've done it a few times :D



and now theirs a new error ill try to figure this out on my own.


You need to look back to Chris's original reply, I suspect (his reply 
was pointing out a runtime issue that will happen once the syntax issue 
is resolved) ...


E.

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


RE: Clickable hyperlinks

2017-01-03 Thread Deborah Swanson
Erik wrote, on January 03, 2017 3:30 PM
> To: python-list@python.org
> Subject: Re: Clickable hyperlinks
> 
> Hi.
> 
> On 03/01/17 19:46, Deborah Swanson wrote:
> > Excel has a formula:
> 
> When you start a new topic on the list, could you please write a new 
> message rather than replying to an existing message and changing the 
> title/subject?
> 
> For those reading the list in a threaded email client, this 
> message is 
> shown as a continuation of your "Cleaning up conditionals" 
> thread, and 
> that whole thread in turn shows up as a continuation of the "mentor 
> training python Romania with certification" discussion (which you had 
> presumably "reply"ed to originally) ...
> 
> Thanks. E.

Certainly. I've been on many other lists before (but none since about
2011), and no one complained of or even mentioned this problem. But if
it's a problem with some email readers now, I can easily just start a
new message.  Just being lazy and following old habits, I guess. ;)

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


RE: Clickable hyperlinks

2017-01-03 Thread Steve D'Aprano
On Wed, 4 Jan 2017 10:32 am, Deborah Swanson wrote:


> The GUI consoles I have are in Pycharm, the IDLE that comes with
> Anaconda, and Spyder. PyCharm and IDLE both ask for internet access when
> I open them, so they're capable of opening links, but whether that means
> their output space is capable of handling clickable links I don't know.
> 
> I do know printing a full url with the %s specifier or entering a url
> and clicking enter just gives you the plain text url. Obviously, not all
> GUI consoles are enabled recognize and make clickable links from
> correctly formatted urls.
> 
> I was hoping there was some functionality in python to make clickable
> links. Could be a package, if the core language doesn't have it.

Unfortunately there is no such thing as an application-
independent "clickable link".

Excel can make clickable links, because it only has to deal with a single
suite of related applications: Excel, Word, and the rest of Microsoft
Office. Likewise LibreOffice.

But Python has to deal with an infinite number of potential or hypothetical
consoles, and there is no standard for "clickable links" that all, or even
most, consoles understand.

Python can't force the console to treat something as a clickable link, if
the console has no capacity for clickable links. Nor can Python predict
what format the console uses to recognise a link.

The best you can do is to experiment with a couple of simple formats and see
which, if any, your console understands:

# HTML
http://www.example.com";>Example.

# URL in angle brackets
Example 

# URL alone
http://www.example.com

# I can't remember what these are called
http://www.example.com>

# Markup
[Example](http://www.example.com)

# Rest
`Example `_





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Terry Reedy

On 1/3/2017 7:02 PM, Callum Robinson wrote:

When i check the code it comes up with invalid syntax and my writing line gets 
re directed here

def is_same(target, number:
if target == number:
result="win"
elif target > number:
result="low"
else:
result="high"
return result


When I paste this into a file in IDLE and try to run the file, 'if' is 
highlighted in red.  This means that there is an error somewhere at or 
before the 'if'.



--
Terry Jan Reedy

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Erik wrote, on January 03, 2017 3:45 PM
> 
> Hi,
> 
> On 03/01/17 22:14, Deborah Swanson wrote:
> > ...you have to create the generator object first and use it to call 
> > the next function. And I really don't think you can use a 
> generator as 
> > your range in a for loop. So I'd use a 'while True', and 
> break out of 
> > the loop when you hit the StopIteration exception:
> >
> > files = rootobs()
> >
> > while True:
> >   try:
> > file = files.next()
> >   except StopIteration:
> > break
> >
> > base = os.path.basename(file.name)
> >.
> >.
> >.
> >   (etc)
> 
> What you have done there is taken an understanding of the underlying 
> machinery that allows the 'for' loop to be syntactic sugar over any 
> iterable and spelled it out, instead of just using 'for'! Without all 
> that, your example is:
> 
> for file in rootobs():
>base = os.path.basename(file.name)
>.
>.
>.
>(etc)
> 
> [In fact, the machinery would also cope with the return value from 
> rootobs() being an iterable but not an iterator by using "files = 
> iter(rootobjs)"].
> 
> 
> 
> You seem to be reading up on how the stuff works under the 
> covers (i.e., 
> from the point of view of an implementer of a class or 
> library) and then 
> suggesting that that's what the *caller* of that class or 
> library needs 
> to do. They don't - for a caller, 'for x in seq:' is all they need to 
> know - the mechanics are handled by the interpreter coupled with the 
> dunder methods that the class may implement.
> 
> 
> E.

Ok, I'm in complete agreement with everything you said up to the last
paragraph, which I don't disagree with, I just don't see your point.

If you've read my last few posts you'll have seen me acknowledging that
normally a for loop is used, but a while and break on StopIteration is a
method that's useful when the output of the generator is unknown.

I haven't read through much documentation on generators, but I have
taken a course from MIT, in which a Computer Science professor gave us
several methods for working with generators, of which the while and
break on StopIteration method is one.  The original poster wanted to use
a while, and seemed to be saying he didn't know how many files the
generator he has would yield, so that was why I recommended the while
loop. Normally I would use a for loop too.
D.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Steve D'Aprano
On Wed, 4 Jan 2017 11:16 am, Callum Robinson wrote:

> My apologizes but i'm quite new and would need instructions to what
> information you need me to get.


Do you know how to copy and paste from the terminal window?

Somewhere on the screen you see something like:


x = 23 + )
 ^
SyntaxError: invalid syntax



You should copy and paste *all* of the error message, as much as you can
see.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Erik wrote, on January 03, 2017 3:53 PM
> 
> On 03/01/17 23:05, Deborah Swanson wrote:
> > And yes, we usually used for loops for generators, unless you don't 
> > know when the generator will be exhausted. As in this case, 
> where the 
> > number of files the generator can provide is unknown. Then 
> we used the 
> > while True, break on StopIteration method.
> 
> Out of interest, *why* was it deemed necessary to do 
> something different 
> if you don't know how many items the generator will generate? Was any 
> rationale given for that?
> 
> for x in foo:
>bar(x)
> 
> ... where foo is any iterable (something that has a __iter__ method 
> defined - including generators) will just bind each value in 
> turn to 'x' 
> and will exit when the StopIteration exception is raised under the 
> covers by the iterator that is iterating over the iterable.
> 
> Some generators are infinite (and their iterator will never raise a 
> StopIteration exception).
> 
> E.

The main reason you might want to catch the StopIteration exception is
to do something else before your code simply stops running. If all
you're doing is run a generator til it's out of gas, and that's all you
want it to do, then there's no need to catch anything. There's lots of
situations where this is exactly what you want. It might even be the
most frequent use of generators, though I wouldn't know. 

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 1:45:22 PM UTC+13, Erik wrote:
> Hi Callum,
> 
> On 04/01/17 00:30, Callum Robinson wrote:
> > I feel like im missing something so blatantly obvious.
> 
> That's because you are ;). I don't want to come across as patronising, 
> but I want you to see it for yourself, so, here's a function definition 
> similar to yours that doesn't have the same syntax error that yours does:
> 
> def foo(spam, ham):
>  if spam == ham:
>  return "same"
>  return "different"
> 
> See the difference?
> 
> E.

I've figured out that out but I have a new issue. I like what you are doing 
making me figure this out as it helps me remember. I'll post the new code and 
the issue. If you could give me a hint that would be great. 

--
Issue
--

Traceback (most recent call last):
  File "D:/Python/random.py", line 6, in 
computer_number = number.randint(1, 100)
NameError: name 'number' is not defined


-
Here is the most recent code
-


# mynumber.py
# this game uses a home made function
import random

#think of a number
computer_number = number.randint(1, 100)

#create the function is_same()
def is_same(target, number):
if target == number:
result="Win"
elif target > number:
result="Low"
else:
result="High"
return result

# start the game
print("hello. \nI have thought of a number between 1 and 100.")

#collect the user's guess as an interger
guess = int(input("Can you guess it? "))
#Use our function
higher_or_lower = is_same(computer_number, guess)
#run the game untill the user is correct
while higher_or_lower != "win":
if higher_or_lower == "low":
 guess = int(input("Sorry, you are too low. Try again."))
else:
guess = int(input("Sorry your are too high. Try again."))

higher_or_lower = is_same(computer_number, guess)

#end of game
input("Correct!\nWell Done\n\n\nPress RETURN to exit.")




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


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Steve D'Aprano
On Wed, 4 Jan 2017 11:22 am, Erik wrote:

> On 03/01/17 22:47, Chris Angelico wrote:
>> On Wed, Jan 4, 2017 at 9:42 AM, Ethan Furman  wrote:
>>> Aside from calling "except Exception" a "naked except"
>>
>> If you read the comments, you'll see that he originally had an actual
>> bare except clause, but then improved the code somewhat in response to
>> a recommendation that SystemExit etc not be caught.
> 
> But, as stated at the top of the article, his brief was: "The strings
> come from a file that a human has typed in, so even though most of the
> values are good, a few will have errors ('25C') that int() will reject.".

Right. And from there he starts worrying about the case where the inputs
aren't strings at all, or they're weird exotic objects with nasty __int__
methods. That's overkill and can only hide programming errors.


> What he *should* have done is just validated his input strings before
> presenting the string to int() - i.e., process the input with knowledge
> that is specific to the problem domain before calling the
> general-purpose function.

That's the Look Before You Leap solution. But in this case, given the
scenario described (a text file with a few typos), the best way is to ask
for forgiveness rather than permission:

def int_or_else(value):
try:
return int(value)
else ValueError:
pass


Why is this better? In the given scenario, errors are rare. Most values are
good, with only a few typos, so it is wasteful to parse the string twice,
once to validate it and once to generate the int. Besides, there's probably
no Python code you can write which will validate an int as fast as the
int() function itself.


[...]
> Instead, he tried to patch around int() rejecting the strings. And then
> decided that he'd patch around int() rejecting things that weren't even
> strings even though that's not what the function has (apparently) been
> specified to receive.

Indeed.


Another thought: if he is receiving human generated input, there is an
argument to be made for accepting "look alikes" -- e.g. maybe the data was
entered by Aunt Tilly, who was a typist in the 1960s and can't break the
habit of using l or I interchangeably for 1, and O for 0.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Steve D'Aprano
On Wed, 4 Jan 2017 12:04 pm, Callum Robinson wrote:

> Traceback (most recent call last):
>   File "D:/Python/random.py", line 6, in 
> computer_number = number.randint(1, 100)
> NameError: name 'number' is not defined


That's exactly what we need to see! The full traceback, thank you!

You're asking Python to get the variable "number", and call the randint
method. But:

- you don't have a variable called "number";

NameError: name 'number' is not defined


- and even if you did, that's not how you get a random number. What you want
is:

computer_number = random.randint(1, 100)






-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Clickable hyperlinks

2017-01-03 Thread Michael Torrie
On 01/03/2017 04:32 PM, Deborah Swanson wrote:
> The GUI consoles I have are in Pycharm, the IDLE that comes with
> Anaconda, and Spyder. PyCharm and IDLE both ask for internet access when
> I open them, so they're capable of opening links, but whether that means
> their output space is capable of handling clickable links I don't know.

Hmm I still don't understand what you mean by "GUI console."  Just
because a program asks for internet access does not mean anything about
whether or not your python program can display a clickable link in a
console window.  Besides that, a clickable link would probably ask the
OS to open it with the default application, not cause your program to
access the internet.

The standard out pipe (where stuff goes when you call print() or write
to sys.stdout) from a python program usually goes to a console or a
terminal emulator.  PyCharm and IDLE both provide windows to display
this output (they emulate a terminal). But maybe you're misunderstanding
what this actually is.  These windows just display a stream of bytes
that come out of your program.  Certain escape codes can be emitted that
can instruct the console or terminal emulator to do things like set text
color or display text at a certain position. But there's certainly no
special way to instruct the terminal emulator to make a section of text
into a hyperlink.  Maybe if hyperlinks had existed years ago when
terminal escape codes were being defined we'd have a "hyperlink" code
that all consoles and terminals would understand.  A few years ago I saw
some proposals to add an escape code to the ANSI scheme that would
encode hyperlinks, but nothing ever came of it because, honestly, it
would be too much hassle to roll this out to ever terminal emulator out
there (to say nothing of real terminals).

> I do know printing a full url with the %s specifier or entering a url
> and clicking enter just gives you the plain text url. Obviously, not all
> GUI consoles are enabled recognize and make clickable links from
> correctly formatted urls.

On my Linux machine, the terminal emulators I've used all make a regular
url printed out into a clickable link (or at least a right-clickable
link).  This is just something they try to do with all things that look
like urls.  Sometimes it's helpful, often it's annoying.

> I was hoping there was some functionality in python to make clickable
> links. Could be a package, if the core language doesn't have it.

No, there is not.  If you made a full GUI app using a toolkit like GTK
or Qt, you can indeed place hyperlinks on your forms and the operating
system will automatically connect them to the web browser.  But not in
text-mode terminal apps.

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


Re: Screwing Up looping in Generator

2017-01-03 Thread Erik

Hi,

On 04/01/17 01:12, Deborah Swanson wrote:

The main reason you might want to catch the StopIteration exception is
to do something else before your code simply stops running. If all
you're doing is run a generator til it's out of gas, and that's all you
want it to do, then there's no need to catch anything.


Ah! OK, I see where the lines are being crossed now ;) Although 
StopIteration is an exception, it is something that the 'for/iter' 
machinery handles for you under the covers. Each 'for' statement 
effectively has a 'try' block around it that catches 'StopIteration' and 
just terminates that particular 'for' loop and continues on with the 
remainder of your script.


Raising a 'StopIteration' is an internal mechanism used to determine 
when an iterator (i.e., the thing a 'for' loop is looping over) has 
exhausted itself. It's not something a regular user is ever expected to 
know about let alone catch.


When execution falls out of the bottom of a generator, StopIteration is 
raise (compared to a regular function or method returning 'None').


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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 2:16:08 PM UTC+13, Steve D'Aprano wrote:
> On Wed, 4 Jan 2017 12:04 pm, Callum Robinson wrote:
> 
> > Traceback (most recent call last):
> >   File "D:/Python/random.py", line 6, in 
> > computer_number = number.randint(1, 100)
> > NameError: name 'number' is not defined
> 
> 
> That's exactly what we need to see! The full traceback, thank you!
> 
> You're asking Python to get the variable "number", and call the randint
> method. But:
> 
> - you don't have a variable called "number";
> 
> NameError: name 'number' is not defined
> 
> 
> - and even if you did, that's not how you get a random number. What you want
> is:
> 
> computer_number = random.randint(1, 100)
> 
> 
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

Hey man thanks, the sad thing is i have no idea why i put that in. I must be 
having a terrible day.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screwing Up looping in Generator

2017-01-03 Thread Sayth Renshaw
So can I call the generator twice and receive the same file twice in 2 for 
loops?

Once to get the files name and the second to process?

 for file in rootobs: 
base = os.path.basename(file.name) 
write_to = os.path.join("output", os.path.splitext(base)[0] + ".csv") 
with open(write_to, 'w', newline='') as csvf: 
for file in rootobs:
  # create and write csv

Cheers

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 12:49:28 PM UTC+13, Callum Robinson wrote:
> Im doing a new task from my teacher but i can't seem to find what is wrong 
> with this code. Can anyone help?
> 
> #mynumber.py
> # this game uses a home made function
> import random
> 
> #think of a number
> computer_number = number.randint(1,100)
> 
> #create the function is_same()
> def is_same(target, number:
> if target == number:
> result="win"
> elif target > number:
> result="low"
> else:
> result="high"
> return result
> 
> # start the game
> print("hello. \nI have thought of a number between 1 and 100.")
> 
> #collect the user's guess as an interger
> guess = int(input("Can you guess it? "))
> #Use our function
> higher_or_lower = is_same(computer_number, guess)
> #run the game untill the user is correct
> while higher_or_lower != "win"
> if higher_or_lower == "to low"
>  guess = int(input("Sorry, you are too low. Try again."))
> else:
> guess = int(input("Sorry your are too high. Try again."))
> 
> higher_or_lower = is_same(computer_number, guess)
> 
> #end of game
> input("Correct!\nWell Done\n\n\nPress RETURN to exit.")

Hey again, i'm sorry for bothering you with so many questions i just did not 
want to keep asking my teacher who is on holiday these.

I have another issue where the code runs but i can guess every number from 
1-100 but it always says Sorry your are too high. Try again. I don't understand 
what i have done to cause this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: trouble with cmd.Cmd and prompting

2017-01-03 Thread Cameron Simpson

On 03Jan2017 16:57, Peter Otten <__pete...@web.de> wrote:

Cameron Simpson wrote:

On 03Jan2017 00:14, Dennis Lee Bieber  wrote:

On Tue, 3 Jan 2017 11:33:15 +1100, Cameron Simpson 
declaimed the following:

I'm using cmd.Cmd to write a little FTP-like command line to interface to
a storage system of mine and encountering weird behaviour. When I enter a
command the next prompt appears _before_ the associated operation runs,

[...]

Haven't used the module but there is something I find intriguing in the
help system
-=-=-=-=-
Cmd.precmd(line)
   Hook method executed just before the command line is interpreted, but
after the input prompt is generated and issued.
-=-=-=-=-
"... AFTER the input prompt is ... issued"

[...]

I don't believe Dennis' reading of the docs is correct, and the relevant
part of the source (Python 3.4) does not show anything to support it:

[... code that runs as I had imagined ...]

Is there something asynchronous in your command? Perhaps you can post a
minimal runnable example that shows the odd behaviour.


In the commands themselves? No, but the storage system has lots of asynchronous 
activity.


I'm bothered by the fact that an empty command also shows this behaviour.

I will try to get a minimal example others can run.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Screwing Up looping in Generator

2017-01-03 Thread Sayth Renshaw
On Wednesday, 4 January 2017 12:36:10 UTC+11, Sayth Renshaw  wrote:
> So can I call the generator twice and receive the same file twice in 2 for 
> loops?
> 
> Once to get the files name and the second to process?
> 
>  for file in rootobs: 
> base = os.path.basename(file.name) 
> write_to = os.path.join("output", os.path.splitext(base)[0] + ".csv") 
> with open(write_to, 'w', newline='') as csvf: 
> for file in rootobs:
>   # create and write csv
> 
> Cheers
> 
> Sayth

I just need it to write after each file however the 

with open(#file) as csvf:

Keeps it all open until every file processed in an output file with the name of 
the first file in the generator.

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-03 Thread Cameron Simpson

On 03Jan2017 12:57, Steve D'Aprano  wrote:

I dislike the Unix-style Vim/Emacs text editors, I prefer a traditional
GUI-based editor. So my "IDE" is:
- Firefox, for doing searches and looking up documentation;
- an GUI programmer's editor, preferably one with a tab-based
 interface, such as geany or kate;
- a tab-based terminal.


"traditional GUI-based editor"

For those of us who spent a lot of our earlier time on terminals (actual 
physical terminals) we consider GUIs "new fangled".


Just narking,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Chris Angelico wrote, on January 03, 2017 3:35 PM
> 
> On Wed, Jan 4, 2017 at 10:05 AM, Deborah Swanson 
>  wrote:
> > Ok, I learned how to use generators in Python 2.7.8, which may be 
> > different from Python 3 for generators. But I learned from MIT's 
> > online introduction to python course, and they certainly 
> seem to know 
> > python well. So what is the correct way to call the 
> generator's next 
> > yield in Python 3? We only learned to use the next function. If you 
> > don't use the next function, what do you use?
> 
> The built-in next function, not the next method.
> 
> # don't do this
> gen.next()
> 
> # do this
> next(gen)
> 
> ChrisA

You speak the truth! I never doubted, but since I still have 2.7.8 on my
system  I decided to try it out.

For a simple little Fibbonacci number generator:

def genFib (): 
fibn_1 = 1 #fib(n-1) 
fibn_2 = 0 #fib(n-2) 
while True: 
# fib(n) = fib(n-1) + fib(n-2) 
next = fibn_1 + fibn_2 
yield next 
fibn_2 = fibn_1 
fibn_1 = next

and at the console:

>>> fib = genFib()
>>> fib.next()

2.7.8 works, and cranks out as many Fibbonacci numbers as you could
want.

But in 3.4.3 you get:

Traceback (most recent call last):
  File "", line 1, in 
fib.next()
AttributeError: 'generator' object has no attribute 'next'

Then, going the other way, next(fib) works in both versions.  


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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread MRAB

On 2017-01-04 01:37, Callum Robinson wrote:

On Wednesday, January 4, 2017 at 12:49:28 PM UTC+13, Callum Robinson wrote:

Im doing a new task from my teacher but i can't seem to find what is wrong with 
this code. Can anyone help?

#mynumber.py
# this game uses a home made function
import random

#think of a number
computer_number = number.randint(1,100)

#create the function is_same()
def is_same(target, number:
if target == number:
result="win"
elif target > number:
result="low"
else:
result="high"
return result

# start the game
print("hello. \nI have thought of a number between 1 and 100.")

#collect the user's guess as an interger
guess = int(input("Can you guess it? "))
#Use our function
higher_or_lower = is_same(computer_number, guess)
#run the game untill the user is correct
while higher_or_lower != "win"
if higher_or_lower == "to low"
 guess = int(input("Sorry, you are too low. Try again."))
else:
guess = int(input("Sorry your are too high. Try again."))

higher_or_lower = is_same(computer_number, guess)

#end of game
input("Correct!\nWell Done\n\n\nPress RETURN to exit.")


Hey again, i'm sorry for bothering you with so many questions i just did not 
want to keep asking my teacher who is on holiday these.

I have another issue where the code runs but i can guess every number from 
1-100 but it always says Sorry your are too high. Try again. I don't understand 
what i have done to cause this.


What values can 'is_same' return?

Which of those values are you checking for in the loop?

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


Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Erik

On 04/01/17 01:10, Steve D'Aprano wrote:

On Wed, 4 Jan 2017 11:22 am, Erik wrote:

What he *should* have done is just validated his input strings before
presenting the string to int() - i.e., process the input with knowledge
that is specific to the problem domain before calling the
general-purpose function.


That's the Look Before You Leap solution. But in this case, given the
scenario described (a text file with a few typos), the best way is to ask
for forgiveness rather than permission:


Yes, probably, in this case ;)

OK, in the case where the function you're calling is sane (and Python's 
int() is - it won't blindly accept "0x101" as a hex value, for example) 
then it's probably right that leaping first and then, on failure, 
processing the value and leaping again is the right thing to do.


[I tend to work in an environment where things I'm calling may not be 
sane (and in some cases I may never know), so I will usually consider 
LBYL as a way of CMA ;)].


In this whole discussion there has been no mention of what happens when 
the function returns None, though.



Another thought: if he is receiving human generated input, there is an
argument to be made for accepting "look alikes" -- e.g. maybe the data was
entered by Aunt Tilly, who was a typist in the 1960s and can't break the
habit of using l or I interchangeably for 1, and O for 0.


Sure - and that's what I meant by processing the string according to his 
problem "domain". If he has Aunt Tillys doing his data input, then l->1 
and 0->O may be a reasonable thing (I recently did a project where 
things like converting Icelandic's Eth and Thorn runic letters to 'D' 
and 'P' - though morally wrong ;) - was a reasonable character 
translation because that's what people actually typed in).


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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Sayth Renshaw wrote, on January 03, 2017 5:36 PM
> 
> So can I call the generator twice and receive the same file 
> twice in 2 for loops?
> 
> Once to get the files name and the second to process?
> 
>  for file in rootobs: 
> base = os.path.basename(file.name) 
> write_to = os.path.join("output", 
> os.path.splitext(base)[0] + ".csv") 
> with open(write_to, 'w', newline='') as csvf: 
> for file in rootobs:
>   # create and write csv
> 
> Cheers
> 
> Sayth

I don't see why not, if you let the first one run to completion and then
do it again a second time. Assuming your generator doesn't somehow
delete or modify the file specifications as it yields them. It would be
helpful to see the code for rootobs, if you have it.
D.

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


Re: Screwing Up looping in Generator

2017-01-03 Thread Sayth Renshaw
Untested as i wrote this in notepad at work but, if i first use the generator 
to create a set of filenames and then iterate it then call the generator anew 
to process file may work?

Good idea or better available?

def get_list_of_names(generator_arg):
name_set = set()
for name in generator_arg:
base = os.path.basename(name.name)
filename = os.path.splitext(base)[0]
name_set.add(filename)
return name_set



 for file_name in name_set: 
 directory = "output"
 with open(os.path.join(directory, filename, 'w', newline='') as csvf: 
for file in rootobs: 
  # create and write csv 

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Sayth Renshaw wrote, on January 03, 2017 5:55 PM
> 
> On Wednesday, 4 January 2017 12:36:10 UTC+11, Sayth Renshaw  wrote:
> > So can I call the generator twice and receive the same file 
> twice in 2 
> > for loops?
> > 
> > Once to get the files name and the second to process?
> > 
> >  for file in rootobs: 
> > base = os.path.basename(file.name) 
> > write_to = os.path.join("output", 
> os.path.splitext(base)[0] + ".csv") 
> > with open(write_to, 'w', newline='') as csvf: 
> > for file in rootobs:
> >   # create and write csv
> > 
> > Cheers
> > 
> > Sayth
> 
> I just need it to write after each file however the 
> 
> with open(#file) as csvf:
> 
> Keeps it all open until every file processed in an output 
> file with the name of the first file in the generator.
> 

In that case, I think you just need to devise your output file name
scheme, and it looks like you want to use 'os.path.splitext(base)[0] +
".csv")'. Then  output each file in the same for loop, before you go
back for another input file. Just read in the file, do whatever you want
to it, and then write it to the new file name, all in the same loop.

I don't see any need to loop through rootobs a second time.


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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 3:05:48 PM UTC+13, MRAB wrote:
> On 2017-01-04 01:37, Callum Robinson wrote:
> > On Wednesday, January 4, 2017 at 12:49:28 PM UTC+13, Callum Robinson wrote:
> >> Im doing a new task from my teacher but i can't seem to find what is wrong 
> >> with this code. Can anyone help?
> >>
> >> #mynumber.py
> >> # this game uses a home made function
> >> import random
> >>
> >> #think of a number
> >> computer_number = number.randint(1,100)
> >>
> >> #create the function is_same()
> >> def is_same(target, number:
> >> if target == number:
> >> result="win"
> >> elif target > number:
> >> result="low"
> >> else:
> >> result="high"
> >> return result
> >>
> >> # start the game
> >> print("hello. \nI have thought of a number between 1 and 100.")
> >>
> >> #collect the user's guess as an interger
> >> guess = int(input("Can you guess it? "))
> >> #Use our function
> >> higher_or_lower = is_same(computer_number, guess)
> >> #run the game untill the user is correct
> >> while higher_or_lower != "win"
> >> if higher_or_lower == "to low"
> >>  guess = int(input("Sorry, you are too low. Try again."))
> >> else:
> >> guess = int(input("Sorry your are too high. Try again."))
> >>
> >> higher_or_lower = is_same(computer_number, guess)
> >>
> >> #end of game
> >> input("Correct!\nWell Done\n\n\nPress RETURN to exit.")
> >
> > Hey again, i'm sorry for bothering you with so many questions i just did 
> > not want to keep asking my teacher who is on holiday these.
> >
> > I have another issue where the code runs but i can guess every number from 
> > 1-100 but it always says Sorry your are too high. Try again. I don't 
> > understand what i have done to cause this.
> >
> What values can 'is_same' return?
> 
> Which of those values are you checking for in the loop?

I'm sorry but i do not completely understand what you are stating
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Erik

On 04/01/17 02:24, Callum Robinson wrote:

On Wednesday, January 4, 2017 at 3:05:48 PM UTC+13, MRAB wrote:

What values can 'is_same' return?

Which of those values are you checking for in the loop?


I'm sorry but i do not completely understand what you are stating


You need to think about the specific things (their type, their exact 
values) that your functions might return. Printing some trace output is 
a classic way of debugging your program. If, after this line:


 higher_or_lower = is_same(computer_number, guess)

... you added:

print (higher_or_lower)

... what values do you then see being output? How will those values be 
processed by the conditions you see that work on the "higher_or_lower" 
variable?


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


Re: Clickable hyperlinks

2017-01-03 Thread David
On 4 January 2017 at 11:50, Deborah Swanson  wrote:
> Erik wrote, on January 03, 2017 3:30 PM
>>
>> When you start a new topic on the list, could you please write a new
>> message rather than replying to an existing message and changing the
>> title/subject?
>>
> Certainly. I've been on many other lists before (but none since about
> 2011), and no one complained of or even mentioned this problem. But if
> it's a problem with some email readers now, I can easily just start a
> new message.  Just being lazy and following old habits, I guess. ;)

To be clear, the problem is not "with some email readers".

The problem is that it breaks the thread management features that are
built into every email message, making it impossible to display threads
correctly.

As can be seen here for example:
https://mail.python.org/pipermail/python-list/2017-January/thread.html

Note how most threads start in the leftmost column and replies are indented.
But this does not occur where you began the new subject: "Clickable hyperlinks".

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


RE: Screwing Up looping in Generator

2017-01-03 Thread Deborah Swanson
Erik wrote, on January 03, 2017 5:26 PM
> Hi,
> 
> On 04/01/17 01:12, Deborah Swanson wrote:
> > The main reason you might want to catch the StopIteration 
> exception is 
> > to do something else before your code simply stops running. If all 
> > you're doing is run a generator til it's out of gas, and that's all 
> > you want it to do, then there's no need to catch anything.
> 
> Ah! OK, I see where the lines are being crossed now ;) Although 
> StopIteration is an exception, it is something that the 'for/iter' 
> machinery handles for you under the covers. Each 'for' statement 
> effectively has a 'try' block around it that catches 
> 'StopIteration' and 
> just terminates that particular 'for' loop and continues on with the 
> remainder of your script.
> 
> Raising a 'StopIteration' is an internal mechanism used to determine 
> when an iterator (i.e., the thing a 'for' loop is looping over) has 
> exhausted itself. It's not something a regular user is ever 
> expected to 
> know about let alone catch.
> 
> When execution falls out of the bottom of a generator, 
> StopIteration is 
> raise (compared to a regular function or method returning 'None').
> 
> E.

Looks like those MIT professors knew what they were teaching us after
all! Sneaky, but they never once hinted that this was any deep dark
secret. Just a way to deal with generators that will stop after a finite
and unknown number of yields, and you want your code to keep going after
the generator quits. I thought I was just regurgitating a standard
approach, and surprised to get so much push back on it. 

Seems like python uses a lot of its external functionality (what we
normally code with) for internal behavior too. In this case, and for
empty returns, they're raising exceptions, catching them and then doing
what they want to. I suppose, if you don't want the method returning
None, you could catch that exception and return something else. Or
return nothing at all, which is what I usually want to do when those
pesky Nones crop up.  But I'm not entirely sure how you would make it
return nothing at all.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Callum Robinson
On Wednesday, January 4, 2017 at 3:35:53 PM UTC+13, Erik wrote:
> On 04/01/17 02:24, Callum Robinson wrote:
> > On Wednesday, January 4, 2017 at 3:05:48 PM UTC+13, MRAB wrote:
> >> What values can 'is_same' return?
> >>
> >> Which of those values are you checking for in the loop?
> >
> > I'm sorry but i do not completely understand what you are stating
> 
> You need to think about the specific things (their type, their exact 
> values) that your functions might return. Printing some trace output is 
> a classic way of debugging your program. If, after this line:
> 
>   higher_or_lower = is_same(computer_number, guess)
> 
> ... you added:
> 
> print (higher_or_lower)
> 
> ... what values do you then see being output? How will those values be 
> processed by the conditions you see that work on the "higher_or_lower" 
> variable?
> 
> E.

I did it and this is what it states when i run it

hello. 
I have thought of a number between 1 and 100.
Can you guess it?
5
Low
Sorry , you are too high. Try again. 

Does this mean the number i entered is to low but the code is still stating it 
is to high?
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Clickable hyperlinks

2017-01-03 Thread Deborah Swanson
Steve D'Aprano wrote, on January 03, 2017 4:56 PM

> On Wed, 4 Jan 2017 10:32 am, Deborah Swanson wrote:
> 
> 
> > The GUI consoles I have are in Pycharm, the IDLE that comes with 
> > Anaconda, and Spyder. PyCharm and IDLE both ask for internet access 
> > when I open them, so they're capable of opening links, but whether 
> > that means their output space is capable of handling 
> clickable links I 
> > don't know.
> > 
> > I do know printing a full url with the %s specifier or 
> entering a url 
> > and clicking enter just gives you the plain text url. 
> Obviously, not 
> > all GUI consoles are enabled recognize and make clickable 
> links from 
> > correctly formatted urls.
> > 
> > I was hoping there was some functionality in python to make 
> clickable 
> > links. Could be a package, if the core language doesn't have it.
> 
> Unfortunately there is no such thing as an application- 
> independent "clickable link".

I'm getting that.
 
> Excel can make clickable links, because it only has to deal 
> with a single suite of related applications: Excel, Word, and 
> the rest of Microsoft Office. Likewise LibreOffice.
> 
> But Python has to deal with an infinite number of potential 
> or hypothetical consoles, and there is no standard for 
> "clickable links" that all, or even most, consoles understand.
> 
> Python can't force the console to treat something as a 
> clickable link, if the console has no capacity for clickable 
> links. Nor can Python predict what format the console uses to 
> recognise a link.
> 
> The best you can do is to experiment with a couple of simple 
> formats and see which, if any, your console understands:
> 
> # HTML
> http://www.example.com";>Example.
> 
> # URL in angle brackets
> Example 
> 
> # URL alone
> http://www.example.com
> 
> # I can't remember what these are called http://www.example.com>
> 
> # Markup
> [Example](http://www.example.com)
> 
> # Rest
> `Example `_
> 
> 
> 
> 
> 
> -- 
> Steve
> "Cheer up," they said, "things could be worse." So I cheered 
> up, and sure enough, things got worse.

I tried all of your examples in IDLE, and they all get syntax errors.
I'd expect the same from PyCharm, though I didn't try it.

I think I need to write a class to do it in a particular application,
preferably in PyCharm, though I'd need some kind of internet access
engine to do it anywhere. I can look up how Firefox does it, pretty sure
I have that somewhere. Maybe there's a way...

Maybe it's a stupid idea, but originally I wanted to output links and
click on them while I was still debugging in PyCharm, without having to
save the csv and reopen it in Excel, to see what was in a listing* while
I was still debugging. PyCharm does have links in its console output
that take you to positions in the code when you click on them, so it
seems like all the basic infrastructure is there. I just have to figure
out how to do it for internet urls that I output.

* listing is a real estate listing with a url, part of a project I'm
working on, in case you haven't read the "Cleaning up conditionals"
thread.

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Erik

On 04/01/17 02:47, Callum Robinson wrote:

On Wednesday, January 4, 2017 at 3:35:53 PM UTC+13, Erik wrote:
I did it and this is what it states when i run it

hello.
I have thought of a number between 1 and 100.
Can you guess it?
5
Low
Sorry , you are too high. Try again.

Does this mean the number i entered is to low but the code is still stating it 
is to high?


The last code you posted will return "low", "high" or "win" from the 
"is_same()" function. How does that relate to the "Low" that you are now 
printing?


You must have changed something. If you are testing strings as return 
values then they must be _exactly_ the same - including case and spaces etc.


Always remember that your computer is an idiot. It's the fastest idiot 
that you'll ever know, and it could become your best friend. But it IS 
an idiot ;)


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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Steven D'Aprano
On Wednesday 04 January 2017 13:24, Callum Robinson wrote:

> On Wednesday, January 4, 2017 at 3:05:48 PM UTC+13, MRAB wrote:
>> On 2017-01-04 01:37, Callum Robinson wrote:
>> > On Wednesday, January 4, 2017 at 12:49:28 PM UTC+13, Callum Robinson
>> > wrote:
>> >> Im doing a new task from my teacher but i can't seem to find what is
>> >> wrong with this code. Can anyone help?
>> >>
>> >> #mynumber.py
>> >> # this game uses a home made function
>> >> import random
>> >>
>> >> #think of a number
>> >> computer_number = number.randint(1,100)
>> >>
>> >> #create the function is_same()
>> >> def is_same(target, number:
>> >> if target == number:
>> >> result="win"
>> >> elif target > number:
>> >> result="low"
>> >> else:
>> >> result="high"
>> >> return result
>> >>
>> >> # start the game
>> >> print("hello. \nI have thought of a number between 1 and 100.")
>> >>
>> >> #collect the user's guess as an interger
>> >> guess = int(input("Can you guess it? "))
>> >> #Use our function
>> >> higher_or_lower = is_same(computer_number, guess)
>> >> #run the game untill the user is correct
>> >> while higher_or_lower != "win"
>> >> if higher_or_lower == "to low"
>> >>  guess = int(input("Sorry, you are too low. Try again."))
>> >> else:
>> >> guess = int(input("Sorry your are too high. Try again."))
>> >>
>> >> higher_or_lower = is_same(computer_number, guess)
>> >>
>> >> #end of game
>> >> input("Correct!\nWell Done\n\n\nPress RETURN to exit.")
>> >
>> > Hey again, i'm sorry for bothering you with so many questions i just did
>> > not want to keep asking my teacher who is on holiday these.
>> >
>> > I have another issue where the code runs but i can guess every number from
>> > 1-100 but it always says Sorry your are too high. Try again. I don't
>> > understand what i have done to cause this.
>> >
>> What values can 'is_same' return?
>> 
>> Which of those values are you checking for in the loop?
> 
> I'm sorry but i do not completely understand what you are stating

That's okay, you're still learning :-)

We've all been where you are, even if some of us have forgotten what its like.


Look at your is_same() function. It can return three different things, which 
gets stored in the higher_or_lower variable:

- "win"
- "low"
- "high"


But now look at how you check the result:

while higher_or_lower != "win"
if higher_or_lower == "to low"
guess = int(input("Sorry, you are too low. Try again."))
else:
guess = int(input("Sorry your are too high. Try again."))


I see a typo that will prevent your code from running: you are missing a colon 
after the first line, it should say:

while higher_or_lower != "win":

Likewise for the "if ..." line, it also needs to end with a colon.

So the first thing is that when asking for help, be *extra careful* that the 
code you show us is the same as the code you are actually running. (Otherwise 
we waste our time trying to debug code that you aren't even using!) You should 
always COPY AND PASTE your code, not retype it.

But let's assume that your actual code does include the needed colons, so it 
will run. What values do you check for?

- "to low"

and that's it. Look again at the values that higher_or_lower can actually be. 
Is there any way that higher_or_lower gets the value "to low"?

No. Remember that Python can't read your mind and realise that when you check 
for "to low", you actually mean just "low". So there is no way that the first 
if... clause will be triggered, so it always falls through to the else clause 
and prints "Sorry your are too high. Try again."

(P.S. you mean "Sorry you are too high", not "your are".)



-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Steven D'Aprano
On Wednesday 04 January 2017 12:25, Callum Robinson wrote:

> Hey man thanks, the sad thing is i have no idea why i put that in. I must be
> having a terrible day.

Don't worry about it. The difference between a beginner and an expert is *not* 
that experts make fewer mistakes, but that experts know how to fix those 
mistakes so quickly that they don't even notice them.

I know people who are seemingly incapable of typing more than three words in 
the row without two typos, but they manage to be excellent programmers. They'll 
typo some code:

comptuer_number = number.radnint(1, 100)

try to run it, realise their mistake and fix it:

comptuer_number = random.radnint(1, 100)


then run it again and realise there is at least one more mistake, and fix it:

comptuer_number = random.randint(1, 100)


and then a third time:

computer_number = random.randint(1, 100)


while a beginner is still puzzling over their first mistake. Don't stress about 
it, it is all just part of the learning process. All code starts off full of 
bugs.




-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson

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


RE: Clickable hyperlinks

2017-01-03 Thread Deborah Swanson
David wrote, on January 03, 2017 6:36 PM
> 
> On 4 January 2017 at 11:50, Deborah Swanson 
>  wrote:
> > Erik wrote, on January 03, 2017 3:30 PM
> >>
> >> When you start a new topic on the list, could you please 
> write a new 
> >> message rather than replying to an existing message and 
> changing the 
> >> title/subject?
> >>
> > Certainly. I've been on many other lists before (but none 
> since about 
> > 2011), and no one complained of or even mentioned this 
> problem. But if 
> > it's a problem with some email readers now, I can easily 
> just start a 
> > new message.  Just being lazy and following old habits, I guess. ;)
> 
> To be clear, the problem is not "with some email readers".

Actually it is, or at least it doesn't happen in all email readers.
Mine, for instance, never breaks up threads.
 
> The problem is that it breaks the thread management features 
> that are built into every email message, making it impossible 
> to display threads correctly.

Again, I think this is in some modern email readers. Apparently older
ones were more robust.

> As can be seen here for example: 
> https://mail.python.org/pipermail/python->
list/2017-January/thread.html
> 
> Note how most threads start in the leftmost column and 
> replies are indented. But this does not occur where you began 
> the new subject: "Clickable hyperlinks".

Yes, pipermail does seem to have a few bugs, this is the second one I've
seen.
 
> Thanks.

I did say in the message you're replying to that I will try to remember
to start new threads with brand new messages. (Even though I think
pipermail's behavior is a bug, that's what many people read the list
from.)

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


Re: Clickable hyperlinks

2017-01-03 Thread Michael Torrie
On 01/03/2017 08:28 PM, Deborah Swanson wrote:
> I think you're making this too complicated. I meant a console in a GUI
> application.

Ahh. Well, a "console in a GUI application" is whatever you make it[1].
There's no single "GUI console" hence my confusion and the confusion
expressed by the other poster.  I was under the impression you are
talking about printing something to standard out with, for example,
print().  Is this so, or are you using a GUI toolkit to construct your
application.  What GUI toolkit are you using?  As I said, in Qt or GTK
there are various ways to display hyperlinks.  For example, Qt lets you
place a hyperlink in a form, or inside of a text entry/display widget.

I still get the impression that you're working with standard out, using
print(). If so, then no, there's not going to be a way to force the OS
to make the output clickable, at least on Windows.

> Not true. Pycharm uses links in it's console output, they just aren't
> internet links. They link back to lines of code being referred to.

I think the problem here is the terminology with specific meaning in
Windows and Linux.  I'm referring to either the Win32 console window
(which is where cmd.exe runs), or a terminal emulator in Linux, which is
where you can interact with the bash shell and run command-line
programs.  When people normally run python apps that are not graphical,
they normally do it from the Windows console (via cmd.exe) or in Linux
from Bash running in a terminal emulator.  Graphical apps do their own
thing as far as displaying data and making windows with clickable links
in them.

[1] PyCharm and IDLE make "console" windows that are really normal GUI
windows and they direct the output from Python apps there. They may also
choose to display clickable links for things like errors. But once the
app is run outside of PyCharm, the output of the app would go to either
a Windows console window, or a terminal in Linux.  If you wanted your
app to make it's own window and display clickable links, you're back to
looking at a GUI toolkit (which is what PyCharm and IDLE are built with)
like Qt, GTK, Tk, wxWidgets, or something else.


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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-03 Thread Steven D'Aprano
On Wednesday 04 January 2017 12:10, Cameron Simpson wrote:

> On 03Jan2017 12:57, Steve D'Aprano  wrote:
>>I dislike the Unix-style Vim/Emacs text editors, I prefer a traditional
>>GUI-based editor. So my "IDE" is:
>>- Firefox, for doing searches and looking up documentation;
>>- an GUI programmer's editor, preferably one with a tab-based
>>  interface, such as geany or kate;
>>- a tab-based terminal.
> 
> "traditional GUI-based editor"
> 
> For those of us who spent a lot of our earlier time on terminals (actual
> physical terminals) we consider GUIs "new fangled".
> 
> Just narking,
> Cameron Simpson 


Heh, GUI editors have been around since at least 1984, if not older, which 
makes them older than half the programmers in the world.

I'm not sure what an *un*traditional GUI-based editor would look like. Maybe 
one that used a ribbon-based interface, like MS Office? Or perhaps Leo?

http://leoeditor.com/

[My resolution for 2017: stop talking about Leo and actually download the damn 
thing and try it out.]



-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson

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


RE: Clickable hyperlinks

2017-01-03 Thread Steven D'Aprano
On Wednesday 04 January 2017 14:04, Deborah Swanson wrote:

> Steve D'Aprano wrote, on January 03, 2017 4:56 PM
[...]
>> Python can't force the console to treat something as a
>> clickable link, if the console has no capacity for clickable
>> links. Nor can Python predict what format the console uses to
>> recognise a link.
>> 
>> The best you can do is to experiment with a couple of simple
>> formats and see which, if any, your console understands:
>> 
>> # HTML
>> http://www.example.com";>Example.
>> 
>> # URL in angle brackets
>> Example 
>> 
>> # URL alone
>> http://www.example.com
>> 
>> # I can't remember what these are called 
>> http://www.example.com>
>> 
>> # Markup
>> [Example](http://www.example.com)
>> 
>> # Rest
>> `Example `_
[...]

> I tried all of your examples in IDLE, and they all get syntax errors.
> I'd expect the same from PyCharm, though I didn't try it.

Syntax errors? How can you get syntax errors from *output* text?

The above are just text, no different from:

Hello World!


Of course you have to put quotes around them to enter them in your source code. 
We don't expect this to work:

print(Hello World!)


you have to use a string literal with quotes:

print('Hello World!')


Same for all of the above.

py> print('http://www.example.com";>Example.')
http://www.example.com";>Example.


That's the Python interactive interpreter (with a custom prompt, I prefer "py>" 
rather than the default ">>>"). Or I can do this from the operating system's 
shell prompt:

steve@runes:~$ python -c "print 'http://www.example.com'"
http://www.example.com


If I do this in GNOME Terminal 2.30.2, the URL http... is a clickable link. But 
that's specific to the terminal. Other terminals may or may not recognise it.




-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson

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


Re: Clickable hyperlinks

2017-01-03 Thread Michael Torrie
On 01/03/2017 08:46 PM, Deborah Swanson wrote:
> Actually it is, or at least it doesn't happen in all email readers.
> Mine, for instance, never breaks up threads.

Mine doesn't either, which illustrates the issue. This  message, for
example appears under a long thread that started out life as "mentor
training python Romania with certification" and then changed to
"Cleaning up conditionals" and then changed to "Clickable hyperlinks."
All in one thread. My client doesn't break them up because they all tie
together via the message-id header.

And most of us would not like our client to break a thread just because
the subject changes. Often in long conversations there are twists and
turns in the discussion and sometimes side-paths are explored, and the
subject often is changed to reflect this.  With a truly threaded email
reader (one that shows a tree of messages, not just chronological
order), this works out very well.  So if a discussion has a natural
evolution into various other topics, it is often considered okay to just
change the subject but continue the thread. Other times, it's better to
start a new thread.  Where that line is is hard to say!

> I did say in the message you're replying to that I will try to remember
> to start new threads with brand new messages. (Even though I think
> pipermail's behavior is a bug, that's what many people read the list
> from.)

Sounds good.

I don't know of anyone that reads on the pipermail archive, except in
response to web searches.  Most people use clients of some kind, NNTP or
email.  And those that group messages according to message-id (most
clients except for ones that try to be smart like Gmail web or Outlook)
will show all the topics I mentioned before as one giant thread, which
is by design (that's what message-id headers are for).

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


Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Erik

On 04/01/17 03:25, Steven D'Aprano wrote:

On Wednesday 04 January 2017 12:25, Callum Robinson wrote:


Hey man thanks, the sad thing is i have no idea why i put that in. I must be
having a terrible day.


Don't worry about it. The difference between a beginner and an expert is *not*
that experts make fewer mistakes, but that experts know how to fix those
mistakes so quickly that they don't even notice them.


Hmm. An expert at what? Telling a beginner how to spell something is not 
the same as coaxing that same beginner to think about something or 
approach a problem from a particular angle and come to their own 
solution. We all could have told him the answer up-front. What has that 
achieved?


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


  1   2   >