Re: Is there a good process or library for validating changes to XML format?

2017-01-05 Thread Ramanathan Muthaiah
On Thursday, January 5, 2017 at 9:02:38 AM UTC+5:30, Sayth Renshaw wrote:
> Afternoon
> 
> Is there a good library or way I could use to check that the author of the 
> XML doc I am using doesn't make small changes to structure over releases?
> 
> Not fully over this with XML but thought that XSD may be what I need, if I 
> search "python XSD" I get a main result for PyXB and generateDS 
> (https://pythonhosted.org/generateDS/). 
> 
> Both seem to be libraries for generating bindings to structures for parsing 
> so maybe I am searching the wrong thing. What is the right thing to search?

[RM]: Have you tried 'xmllint' (though it's not Python library) ?

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


Re: Is there a good process or library for validating changes to XML format?

2017-01-05 Thread Sayth Renshaw
It definitely has more features than i knew http://xmlsoft.org/xmllint.html

Essentially thigh it appears to be aimed at checking validity and compliance of 
xml.
I why to check the structure of 1 xml file against the previous known structure 
to ensure there are no changes.

Cheers

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


Re: Clickable hyperlinks

2017-01-05 Thread Rhodri James

On 05/01/17 04:52, Deborah Swanson wrote:

My original question was in fact whether there was a way to make
clickable hyperlinks in a console. I was persuaded after about 10
replies that the answer was no,


Then you were persuaded wrong; the actual answer was "this isn't a 
meaningful question since it's based on incorrect assumptions." 
Translating that to "No" is just as much a mistake as translating it to 
"Yes."


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Python for WEB-page !?

2017-01-05 Thread Ionut Predoiu
Good afternoon,

I am a beginner in programming language. 
I want to know what version of Python I must to learn to use, beside of basic 
language, because I want to integrate in my site 1 page in which users to can 
made calculus based on my formulas already write behind (the users will only 
complete some field, and after push "Calculate" button will see the results in 
form of: table, graphic, and so on ...). 
Please take into account that behind will be more mathematical 
equations/formulas, so the speed I think must be take into account.

I waiting with higher interest your feedback.

Thanks to all members of community for support and advice.
Keep in touch.
Kind regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a good process or library for validating changes to XML format?

2017-01-05 Thread Rustom Mody
On Thursday, January 5, 2017 at 9:02:38 AM UTC+5:30, Sayth Renshaw wrote:
> Afternoon
> 
> Is there a good library or way I could use to check that the author of the 
> XML doc I am using doesn't make small changes to structure over releases?
> 
> Not fully over this with XML but thought that XSD may be what I need, if I 
> search "python XSD" I get a main result for PyXB and generateDS 
> (https://pythonhosted.org/generateDS/). 
> 
> Both seem to be libraries for generating bindings to structures for parsing 
> so maybe I am searching the wrong thing. What is the right thing to search?
> 

Know v little about this. Some links that you can chase:
http://diffxml.sourceforge.net/
http://stackoverflow.com/questions/1871076/are-there-any-free-xml-diff-merge-tools-available

And in python 
https://pypi.python.org/pypi/xmldiff
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python for WEB-page !?

2017-01-05 Thread Chris Angelico
On Thu, Jan 5, 2017 at 11:57 PM, Ionut Predoiu  wrote:
> I am a beginner in programming language.
> I want to know what version of Python I must to learn to use, beside of basic 
> language, because I want to integrate in my site 1 page in which users to can 
> made calculus based on my formulas already write behind (the users will only 
> complete some field, and after push "Calculate" button will see the results 
> in form of: table, graphic, and so on ...).
> Please take into account that behind will be more mathematical 
> equations/formulas, so the speed I think must be take into account.
>

Building a web site can be done with Flask, Django, aiohttp, or a
number of other frameworks. Generating graphs can be done with
matplotlib. Speed won't be a problem - a computer can do a LOT of
mathematical calculations in the time it takes to request something
over the internet.

Have fun exploring!

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


Re: Python for WEB-page !?

2017-01-05 Thread Uri Even-Chen
I recommend starting with Python 3, I also use it (3.5.2) for my Django
projects - Speedy Net and Speedy Match.

Uri.


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


On Thu, Jan 5, 2017 at 5:18 PM, Chris Angelico  wrote:

> On Thu, Jan 5, 2017 at 11:57 PM, Ionut Predoiu 
> wrote:
> > I am a beginner in programming language.
> > I want to know what version of Python I must to learn to use, beside of
> basic language, because I want to integrate in my site 1 page in which
> users to can made calculus based on my formulas already write behind (the
> users will only complete some field, and after push "Calculate" button will
> see the results in form of: table, graphic, and so on ...).
> > Please take into account that behind will be more mathematical
> equations/formulas, so the speed I think must be take into account.
> >
>
> Building a web site can be done with Flask, Django, aiohttp, or a
> number of other frameworks. Generating graphs can be done with
> matplotlib. Speed won't be a problem - a computer can do a LOT of
> mathematical calculations in the time it takes to request something
> over the internet.
>
> Have fun exploring!
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Forcing prompt to be on newline when embedding Python with stdin/out redirection

2017-01-05 Thread H Krishnan
Hi,

I am working on embedding Python in my application. I have redirected
sys.stdin and sys.stdout to call methods from a Qt TextEdit widget.
Everything works fine except that the Python prompt does not always come in
a new line:

>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']>>>

Why doesn't the prompt appear in a new line as with the default stdout?

Thanks,
Krishnan
-- 
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-05 Thread ArnoB



On 02-01-17 12:38, 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?


Hi Antonio,

Just an extra one in case you'll ever want to create
a nice GUI, then there's also QT Creator:
https://wiki.qt.io/QtCreator_and_PySide

A very simple but powerful interface a la XCode...

It integrates nicely with PySide:
https://wiki.qt.io/QtCreator_and_PySide

gr
Arno

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


[ANN] aioxmpp 0.7.2 released

2017-01-05 Thread Jonas Wielicki
Dear subscribers,

I am pleased to announce the release of aioxmpp 0.7.1 (footnote 1). The
current release can be obtained from GitHub [1] (check out the v0.6.0 tag or
the master branch) or PyPI [2]. The HTML documentation can be found at [3].
Examples can be found in the GitHub repository, in the examples subdirectory.


aioxmpp is a Python library based on asyncio. It implements the client side of
the XMPP protocol (RFC 6120 and others). For a more detailed description of
the package, please review the README of the package on GitHub [1] or on PyPI
[2]. For more information on XMPP, please see [8]. It is licensed under the
terms of the GNU Lesser General Public License Version 3.0 or later.


Version 0.7.2 is a bugfix release. The most severe issue which has been fixed 
is that message stanzas without from attribute caused the stream to crash. 
Other bugfixes included are listed in the changelog [9].


Bugs, feature requests, patches and questions can be directed to either the
aioxmpp mailing list [4], the GitHub issue tracker [5] or the XMPP Multi-User
chat [6], whatever floats your boat. Please direct security-relevant issue
reports directly to me (jo...@wielicki.name), preferrably encrypted using my
GPG public key [7].

best regards and happy-asyncio-ing,
Jonas Wielicki


footnote 1: 0.7.0 and 0.7.1 are functionally identical. I messed up the 0.7.0
release by forgetting to change the license in the setup.py to LGPLv3+, which
made PyPI show the incorrect GPLv3 license.


   [1]: https://github.com/horazont/aioxmpp
   [2]: https://pypi.python.org/pypi/aioxmpp
   [3]: https://docs.zombofant.net/aioxmpp/0.7/
   [4]: https://lists.zombofant.net/mailman/listinfo/aioxmpp-devel
   [5]: https://github.com/horazont/aioxmpp/issues
   [6]: aiox...@conference.zombofant.net
   [7]: https://sks-keyservers.net/pks/lookup?op=get&search=0xE5EDE5AC679E300F
AA5A 78FF 508D 8CF4 F355  F682 E5ED E5AC 679E 300F
   [8]: https://xmpp.org/
   [9]: https://docs.zombofant.net/aioxmpp/0.7/api/
changelog.html#version-0-7-2
-- 
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-05 Thread Chris Clark
I want an IDE that I can use at work and home, linux and dare I say windows.

Sublime, had to remove it from my work PC as it is not licensed.

Atom, loved it until it slowed down.

VIM, ok the best if you know vi inside out.

Any JAVA based IDE, just slows up on work PC's due to all the background stuff 
that corporates insist they run.

Why can not someone more clever than I fork DrPython and bring it up to date.

Its is fast, looks great and just does the job ?

Its wx, no idea if that is good or bad but it just works.



From: Python-list  on 
behalf of ArnoB 
Sent: 05 January 2017 17:32:33
To: python-list@python.org
Subject: Re: Choosing a Python IDE. what is your Pythonish recommendation? I do 
not know what to choose.



On 02-01-17 12:38, 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?

Hi Antonio,

Just an extra one in case you'll ever want to create
a nice GUI, then there's also QT Creator:
https://wiki.qt.io/QtCreator_and_PySide

A very simple but powerful interface a la XCode...

It integrates nicely with PySide:
https://wiki.qt.io/QtCreator_and_PySide

gr
Arno

--
https://mail.python.org/mailman/listinfo/python-list
This message is private and confidential and may also be legally privileged. If 
you have received this message in error, please email it back to the sender and 
immediately permanently delete it from your computer system. Please do not 
read, print, re-transmit, store or act in reliance on it or any attachments. 
British Airways may monitor email traffic data and also the content of emails, 
where permitted by law, for the purposes of security and staff training and in 
order to prevent or detect unauthorised use of the British Airways email 
system. Virus checking of emails (including attachments) is the responsibility 
of the recipient. British Airways Plc is a public limited company registered in 
England and Wales. Registered number: 177. Registered office: Waterside, PO 
Box 365, Harmondsworth, West Drayton, Middlesex, England, UB7 0GB. Additional 
terms and conditions are available on our website: www.ba.com
-- 
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-05 Thread Nathan Ernst
Have you looked into Visual Studio Code (https://code.visualstudio.com/)?
I've not used it extensively, and only on Windows, but it's an open source
IDE originated by MS that purportedly works on Windows, Linux & OS X.

It does have pretty decent Python support (haven't tried debugging, but
syntax highlighting works well).

There's also a really good vim extension available.

I tend to prefer vim (or vim extensions) when I can because even though I
probably know less than 10% of vim's capabilities, I'm more productive
using it. I also use the VsVim extension in full proper Visual Studio.

Regards,
Nate

On Thu, Jan 5, 2017 at 12:12 PM, Chris Clark  wrote:

> I want an IDE that I can use at work and home, linux and dare I say
> windows.
>
> Sublime, had to remove it from my work PC as it is not licensed.
>
> Atom, loved it until it slowed down.
>
> VIM, ok the best if you know vi inside out.
>
> Any JAVA based IDE, just slows up on work PC's due to all the background
> stuff that corporates insist they run.
>
> Why can not someone more clever than I fork DrPython and bring it up to
> date.
>
> Its is fast, looks great and just does the job ?
>
> Its wx, no idea if that is good or bad but it just works.
>
>
> 
> From: Python-list 
> on behalf of ArnoB 
> Sent: 05 January 2017 17:32:33
> To: python-list@python.org
> Subject: Re: Choosing a Python IDE. what is your Pythonish recommendation?
> I do not know what to choose.
>
>
>
> On 02-01-17 12:38, 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?
>
> Hi Antonio,
>
> Just an extra one in case you'll ever want to create
> a nice GUI, then there's also QT Creator:
> https://wiki.qt.io/QtCreator_and_PySide
>
> A very simple but powerful interface a la XCode...
>
> It integrates nicely with PySide:
> https://wiki.qt.io/QtCreator_and_PySide
>
> gr
> Arno
>
> --
> https://mail.python.org/mailman/listinfo/python-list
> This message is private and confidential and may also be legally
> privileged. If you have received this message in error, please email it
> back to the sender and immediately permanently delete it from your computer
> system. Please do not read, print, re-transmit, store or act in reliance on
> it or any attachments. British Airways may monitor email traffic data and
> also the content of emails, where permitted by law, for the purposes of
> security and staff training and in order to prevent or detect unauthorised
> use of the British Airways email system. Virus checking of emails
> (including attachments) is the responsibility of the recipient. British
> Airways Plc is a public limited company registered in England and Wales.
> Registered number: 177. Registered office: W

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

2017-01-05 Thread Marko Rauhamaa
Chris Clark :

> I want an IDE that I can use at work and home, linux and dare I say
> windows.

I use emacs for all of my typing, including Python programming (and
making this post).


Marko
-- 
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-05 Thread fpp
> On Thu, Jan 5, 2017 at 12:12 PM, Chris Clark 
> wrote: 
>> I want an IDE that I can use at work and home, linux and dare I say
>> windows.
>> Sublime, had to remove it from my work PC as it is not licensed.
>> Atom, loved it until it slowed down.
>> VIM, ok the best if you know vi inside out.
>> Any JAVA based IDE, just slows up on work PC's due to all the
>> background stuff that corporates insist they run.
>> Why can not someone more clever than I fork DrPython and bring it up
>> to date.
>> Its is fast, looks great and just does the job ?

I'm suprised no one in this rich thread has even mentioned SciTE :
http://www.scintilla.org/

Admittedly it's closer to an excellent code editor than a full-blown IDE.
But it's very lightweight and fast, cross-platform, has superb syntax 
coloring and UTF8 handling, and is highly configurable through its 
configuration file(s) and embedded LUA scripting.
It's also well maintained : version 1.0 came out in 1999, and the latest 
(3.7.2) is just a week old...

Its IDE side consists mostly of hotkeys to run the interpreter or 
compiler for the language you're editing, with the file in the current 
tab.
A side pane shows the output (prints, exceptions, errors etc.) of the 
running script.
A nice touch is that it understands these error messages and makes them 
clickable, taking you to the tab/module/line where the error occurred.
Also, it can save its current tabs (and their state) to a "session" file 
for later reloading, which is close to the idea of a "project" in most 
IDEs.
Oh, and it had multi-selection and multi-editing before most of the new 
IDEs out there :-)

Personally that's about all I need for my Python activities, but it can 
be customized much further than I have done : there are "hooks" for other 
external programs than compilers/interpreters, so you can also run a 
linter, debugger or cvs from the editor.

One word of warning: unlike most newer IDEs which tend to be shiny-shiny 
and ful of bells and whistles at first sight, out of the box SciTE is 
*extremely* plain looking (you could even say drab, or ugly :-).
It is up to you to decide how it should look and what it should do or 
not, through the configuration file.
Fortunately the documentation is very thorough, and there are a lot of 
examples lying around to be copy/pasted (like a dark theme, LUA scripts 
etc.).

Did I mention it's lightweight ? The archive is about 1.5 MB and it just 
needs unzipping, no installation. May be worth a look if you haven't 
tried it yet...
fp
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Clickable hyperlinks

2017-01-05 Thread Deborah Swanson
Terry Reedy wrote, on January 04, 2017 10:18 PM
> 
> On 1/5/2017 12:11 AM, Deborah Swanson wrote:
> > Terry Reedy wrote, on January 04, 2017 3:58 PM
> 
> >> To have a string interpreted as a clickable link, you send the
string to
> >> software capable of creating a clickable link, plus the information

> >> 'this is a clickable link'*.  There are two ways to tag a string as
a 
> >> link.  One is to use markup around the url in the string itself. 
> >> '' and html are example.  Python provides multiple to make
this 
> >> easy. The other is to tag the string with a separate argument.  
> >> Python provides tkinter, which wraps tk Text widgets, which have a 
> >> powerful tag system.  One can define a Link tag that will a) cause
text 
> >> to be displayed, for instance, blue and underlined and b) cause
clicks on
> >> the text to generate a web request.  One could then use
> >> mytext.insert('insert', 'http://www.example.com', Link) Browser 
> >> must do something similar when they encounter when they encounter 
> >> html link tags.
> >
> > I've actually moved on from my original question to one of opening a

> > url in a browser with python, which seems to be a much more easily 
> > achieved goal.
> 
> > But someone else mentioned tkinter, and I looked at it awhile ago
but 
> > haven't used it for anything. That really could be the way to go if 
> > you want to make clickable links, although you still need some kind
of 
> > internet engine to open the url in a browser.
> 
> IDLE allows a user to add help menu entries that, when clicked on,
open 
> either a local file or an internet url.  For instance, adding the pair

> 'Pillow' and "https://pillow.readthedocs.io/en/latest/"; in > the
Settings 
> dialog adda "Pillow" to the help menu (after the standard stuff). 
> Clicking on Help => Pillow opens 
> "https://pillow.readthedocs.io/en/latest/"; in the default browswer. 
> IDLE just used the webbrowser module to do this.  No use re-inventing 
> the wheel.  If instead "Pillow" were a link in text, the click handler

> should do something similar.

Yes, unless someone suggests something better, the webbrowser module
looks like the way to go for opening urls in a browser.
> 
> > You say, "There are two ways to tag a string as a link. One is to
use 
> > markup around the url in the string itself. '' and html are 
> > examples.  Python provides multiple ways to make this easy."
> >
> > Can you tell me where I'd begin to look for these? Are they in the 
> > core language, or in packages?
> 
> I was referring to using either % or .format string formatting.  Both 
> are in the core and described somewhere in the Library manual.  '%' 
> should be in the Symbols page of the Index and 'format' on 
> the 'F' page.
> 
> -- 
> Terry Jan Reedy

I looked up % in the Symbols page, but I didn't see any specifier
related to urls. It would be nice if there was something like a %u for
url format, but it isn't in there.

I also tried

print("http//python.org")
^
but got 'SyntaxError: invalid syntax', with the red arrow pointing at
the first angle bracket. I also tried

print("http//python.org")
^
and got the same syntax error, but I'm not sure if that's how you meant
html should be used.

I also tried to look up 'format', but there's no such entry in the
Index. There are a lot of entries that begin with 'format', but none of
them mention urls or anything link related. 'format_field()
(string.Formatter method)' looked like a possibility, but again, I
didn't see anything to format a link with. Maybe I didn't look hard
enough, or didn't see something that _would_ work.

As I've said, at this point I've moved on to directly opening a url in a
browser with the webbrowser module. All I originally wanted to do was be
able to open a url without leaving my IDE while I was debugging data
that has urls in it. Clickable links are really just eye candy that I
don't need if I can get the same result programmatically. But I was
curious whether there are any ways to tag a string as a link in a print
statement. If there are, I didn't find any, but thanks for your
suggestions!

Deborah

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


Re: Work between multiple processes

2017-01-05 Thread Irmen de Jong
On 4-1-2017 23:14, zxpat...@gmail.com wrote:
> Hi everyone,
> 
> I ran into a case that I need to create a work process of an application 
> (Jython so has to call using java.exe) which will collect the data based on 
> what main process indicates. 
> 
> (1) I tried multiprocessing package, no luck. Java.exe can't be called from 
> Process class?
> 
> (2) I tried subprocess. subprocess.communicate function will wait for the 
> work process to terminate so to return.
> 
>  
> either (1) or (2) doesn't work out well. Please suggest.  Global system queue?
> 
> Thanks,
> Patrick.
> 


Is it a requirement that the workdf process is also Jython?

If not: you could spawn a Python subprocess that hosts a Pyro4 daemon.
Utilizing the Pyrolite java client library you can call methods in it from the
java/jython side.  (Unfortunately it is not yet possible (due to jython
incompatibilities) to use the full Pyro4 library on the Jython side as well).
Not sure if it meets your set of requirements but have a look at
http://pythonhosted.org/Pyro4/
http://pythonhosted.org/Pyro4/pyrolite.html


Irmen

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


RE: Clickable hyperlinks

2017-01-05 Thread Deborah Swanson
Rhodri James wrote, on January 05, 2017 3:53 AM
> 
> On 05/01/17 04:52, Deborah Swanson wrote:
> > My original question was in fact whether there was a way to make 
> > clickable hyperlinks in a console. I was persuaded after about 10 
> > replies that the answer was no,
> 
> Then you were persuaded wrong; the actual answer was "this isn't a 
> meaningful question since it's based on incorrect assumptions." 
> Translating that to "No" is just as much a mistake as 
> translating it to 
> "Yes."
> 
> -- 
> Rhodri James *-* Kynesim Ltd

Actually, your statement "this isn't a meaningful question since it's
based on incorrect assumptions" is false. PyCharm outputs clickable
links to the console, but they aren't web links, they simply link to
lines of code. I'd seen that PyCharm can make links in the console that
aren't web enabled, so it seemed, and in fact it is, reasonable to
assume that it could be done for urls. I just wanted to know if anyone
knew how to do it.

Granted, the suggestion to use tkinter to enable the links came up much
later than in the first 10 or so replies, and since tkinter makes
clickable links possible, that's another reason my question wasn't based
on false assumptions. It simply appears that the early responders to my
question went off on a tangent of what is or is not technologically
possible, and all of the approaches under consideration were in fact
dead ends.

But clickable links turns out to be just eye candy, and the real result
I wanted, which is opening urls in a browser from my IDE, is much more
quickly and easily done programmatically. Although I didn't see this
before I asked my question, and only saw it after reading quite a few
replies.

Perhaps though, I should have said "I was persuaded after about 10
replies that that no one understood what I was asking." But that just
seemed plain rude, so I went with "the answer was no". 

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


Re: MySQL schema sync or diff

2017-01-05 Thread Chris Angelico
On Thu, Jan 5, 2017 at 11:02 AM, Charles Heizer  wrote:
> I have a MySQL database that is not managed (yet) and I would like to get an 
> output or diff against my new model file. I'm using flask-sqlalchemy.
>
> Are there any modules that would help me discover the differences so that I 
> can script a migration to begin using flask-migrate?

I'm not specifically aware of any such tool per se, but what you may
want to consider is a tool for generating models from existing tables.
Then you could diff the generated models against your hand-made ones,
and build your migrations from that. Expect a ton of noise, though.

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


Re: Python for WEB-page !?

2017-01-05 Thread Victor Porton
Ionut Predoiu wrote:

> I am a beginner in programming language.
> I want to know what version of Python I must to learn to use, beside of
> basic language, because I want to integrate in my site 1 page in which
> users to can made calculus based on my formulas already write behind (the
> users will only complete some field, and after push "Calculate" button
> will see the results in form of: table, graphic, and so on ...). Please
> take into account that behind will be more mathematical
> equations/formulas, so the speed I think must be take into account.

Consider PyPi. I never used it, but they say, it is faster than usual 
CPython interpreter.

> I waiting with higher interest your feedback.
> 
> Thanks to all members of community for support and advice.
> Keep in touch.
> Kind regards.

-- 
Victor Porton - http://portonvictor.org
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Forcing prompt to be on newline when embedding Python with stdin/out redirection

2017-01-05 Thread eryk sun
On Thu, Jan 5, 2017 at 7:09 AM, H Krishnan  wrote:
>
> I am working on embedding Python in my application.

You forgot to tell us the version of Python that you're embedding.

> I have redirected sys.stdin and sys.stdout to call methods from a Qt TextEdit
> widget. Everything works fine except that the Python prompt does not always
> come in a new line:
>
 dir()
> ['__builtins__', '__doc__', '__name__', '__package__']>>>
>
> Why doesn't the prompt appear in a new line as with the default stdout?

Are you using code.InteractiveConsole / code.interact?

If not, in what mode do you compile, Py_file_input ("exec") or
Py_single_input ("single")? The latter executes PRINT_EXPR:

>>> dis.dis(compile('1', '', 'single'))
  1   0 LOAD_CONST   0 (1)
  3 PRINT_EXPR
  4 LOAD_CONST   1 (None)
  7 RETURN_VALUE

PRINT_EXPR in turn calls sys.displayhook on the value it pops from the
stack. The default hook writes the repr of the value and a newline to
sys.stdout, and it also references the value as "_" in the builtins
module (2.x __builtin__).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python for WEB-page !?

2017-01-05 Thread Michael Torrie
On 01/05/2017 04:53 PM, Victor Porton wrote:
> Ionut Predoiu wrote:
> 
>> I am a beginner in programming language.
>> I want to know what version of Python I must to learn to use, beside of
>> basic language, because I want to integrate in my site 1 page in which
>> users to can made calculus based on my formulas already write behind (the
>> users will only complete some field, and after push "Calculate" button
>> will see the results in form of: table, graphic, and so on ...). Please
>> take into account that behind will be more mathematical
>> equations/formulas, so the speed I think must be take into account.
> 
> Consider PyPi. I never used it, but they say, it is faster than usual 
> CPython interpreter.

With respect, I don't think it's appropriate to direct a python beginner
to PyPi.  Far better to direct him to the relevant resources (like
Django) and focus him on the standard Python interpreter, hopefully
version 3.

Besides that, there's the old expression. Premature optimization is the
root of all evil.  Until Python is shown to be too slow for a given
task, it's premature to think about speedups like Cython or even PyPi.


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


Re: Python for WEB-page !?

2017-01-05 Thread Michael Torrie
On 01/05/2017 05:57 AM, Ionut Predoiu wrote:
> Good afternoon,
> 
> I am a beginner in programming language. I want to know what version
> of Python I must to learn to use, beside of basic language, because I
> want to integrate in my site 1 page in which users to can made
> calculus based on my formulas already write behind (the users will
> only complete some field, and after push "Calculate" button will see
> the results in form of: table, graphic, and so on ...). Please take
> into account that behind will be more mathematical
> equations/formulas, so the speed I think must be take into account.

While Python can do that, using a web framework to process HTTP requests
and generate HTML to display in the browser, I don't believe Python is
the appropriate language for the task at hand.  Most web sites that do
interactive formula calculations like you describe do it all in the
browser using Javascript.  No need to have a web server do all that
heavy lifting at all.  A simple html file would contain everything you need.

Even if you want to use Python to generate the web page and process
events, you'll still have to master Javascript at some point to make the
webpages more interactive.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Forcing prompt to be on newline when embedding Python with stdin/out redirection

2017-01-05 Thread H Krishnan
Thanks for your help.

>
> >
> > I am working on embedding Python in my application.
>
> You forgot to tell us the version of Python that you're embedding.
>
> I am using Python2.7.


> > I have redirected sys.stdin and sys.stdout to call methods from a Qt
> TextEdit
> > widget. Everything works fine except that the Python prompt does not
> always
> > come in a new line:
> >
>  dir()
> > ['__builtins__', '__doc__', '__name__', '__package__']>>>
> >
> > Why doesn't the prompt appear in a new line as with the default stdout?
>
> Are you using code.InteractiveConsole / code.interact?
>
> I am using code.InteractiveConsole().interact().


> If not, in what mode do you compile, Py_file_input ("exec") or
> Py_single_input ("single")? The latter executes PRINT_EXPR:
>
> >>> dis.dis(compile('1', '', 'single'))
>   1   0 LOAD_CONST   0 (1)
>   3 PRINT_EXPR
>   4 LOAD_CONST   1 (None)
>   7 RETURN_VALUE
>
> PRINT_EXPR in turn calls sys.displayhook on the value it pops from the
> stack. The default hook writes the repr of the value and a newline to
> sys.stdout, and it also references the value as "_" in the builtins
> module (2.x __builtin__).
>

I tried replacing sys.displayhook with a function that does not print
newline but the newline still got inserted. So, I am not sure where the
newline is coming from. In any case, I could override sys.displayhook to
add a newline at the end and that seems to resolve my problem.


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

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


Re: Python for WEB-page !?

2017-01-05 Thread breamoreboy
On Thursday, January 5, 2017 at 11:53:51 PM UTC, Victor Porton wrote:
> Ionut Predoiu wrote:
> 
> > I am a beginner in programming language.
> > I want to know what version of Python I must to learn to use, beside of
> > basic language, because I want to integrate in my site 1 page in which
> > users to can made calculus based on my formulas already write behind (the
> > users will only complete some field, and after push "Calculate" button
> > will see the results in form of: table, graphic, and so on ...). Please
> > take into account that behind will be more mathematical
> > equations/formulas, so the speed I think must be take into account.
> 
> Consider PyPi. I never used it, but they say, it is faster than usual 
> CPython interpreter.
> 

Really?  I'd strongly contrast the Python Package Index 
https://pypi.python.org/pypi with the Python implementation pypy at 
http://pypy.org/ :)

> -- 
> Victor Porton - http://portonvictor.org

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


Re: Forcing prompt to be on newline when embedding Python with stdin/out redirection

2017-01-05 Thread eryk sun
On Fri, Jan 6, 2017 at 1:06 AM, H Krishnan  wrote:
> I tried replacing sys.displayhook with a function that does not print
> newline but the newline still got inserted. So, I am not sure where the
> newline is coming from. In any case, I could override sys.displayhook to add
> a newline at the end and that seems to resolve my problem.

In Python 2 the newline is written depending on the value of
sys.stdout.softspace. sys.displayhook initially calls Py_FlushLine,
which resets the file's softspace to 0 via PyFile_SoftSpace and writes
a newline if the previous value was non-zero. Next displayhook writes
the repr, sets the softspace to 1 and calls Py_FlushLine again.

The result you're seeing could occur if your filelike object doesn't
have a dict or a property to allow setting the "softspace" attribute,
as the following toy example demonstrates:

import sys

class File(object):
def __init__(self, file):
self._file = file
self._sp_enabled = True
self.softspace = 0

def write(self, string):
return self._file.write(string)

def __getattribute__(self, name):
value = object.__getattribute__(self, name)
if name == 'softspace':
if not self._sp_enabled:
raise AttributeError
self._file.write('[get softspace <- %d]\n' % value)
return value

def __setattr__(self, name, value):
if name == 'softspace':
if not self._sp_enabled:
raise AttributeError
self._file.write('[set softspace -> %d]\n' % value)
object.__setattr__(self, name, value)

softspace enabled:

>>> sys.stdout = File(sys.stdout)
[set softspace -> 0]
[get softspace <- 0]
[set softspace -> 0]
>>> 42
[get softspace <- 0]
[set softspace -> 0]
42[get softspace <- 0]
[set softspace -> 1]
[get softspace <- 1]
[set softspace -> 0]

[get softspace <- 0]
[set softspace -> 0]

softspace disabled:

>>> sys.stdout._sp_enabled = False
>>> 42
42>>> 42
42>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Numpy error

2017-01-05 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-05 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


RE: Screwing Up looping in Generator

2017-01-05 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: Screwing Up looping in Generator

2017-01-05 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

2017-01-05 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: Clickable hyperlinks

2017-01-05 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


Clickable hyperlinks

2017-01-05 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: Clickable hyperlinks

2017-01-05 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: Re: Clickable hyperlinks

2017-01-05 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-allo
ws-filenames-to-be-clickable
http://superuser.com/questions/654116/configure-os-x-terminal-to-detect-urls-an
d-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: Screwing Up looping in Generator

2017-01-05 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: pip install -r requirements.txt fails with Python 3.6 on Windows

2017-01-05 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: Re: Clickable hyperlinks

2017-01-05 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: Screwing Up looping in Generator

2017-01-05 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: How Best to Coerce Python Objects to Integers?

2017-01-05 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-05 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-05 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: How Best to Coerce Python Objects to Integers?

2017-01-05 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-in 
tegers/

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


Re: Screwing Up looping in Generator

2017-01-05 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


Re: Clickable hyperlinks

2017-01-05 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-05 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: Screwing Up looping in Generator

2017-01-05 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: Screwing Up looping in Generator

2017-01-05 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: How Best to Coerce Python Objects to Integers?

2017-01-05 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-05 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: Screwing Up looping in Generator

2017-01-05 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: Cleaning up conditionals

2017-01-05 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: Clickable hyperlinks

2017-01-05 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: Clickable hyperlinks

2017-01-05 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: Screwing Up looping in Generator

2017-01-05 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


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

2017-01-05 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: Clickable hyperlinks

2017-01-05 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: Hey, I'm new to python so don't judge.

2017-01-05 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: Screwing Up looping in Generator

2017-01-05 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: How Best to Coerce Python Objects to Integers?

2017-01-05 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-05 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-05 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: Hey, I'm new to python so don't judge.

2017-01-05 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: Screwing Up looping in Generator

2017-01-05 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: How Best to Coerce Python Objects to Integers?

2017-01-05 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-05 Thread Dennis Lee Bieber
On Tue, 3 Jan 2017 16:02:15 -0800 (PST), Callum Robinson
 declaimed the following:

>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

Count your parentheses... You should have the same number of ) as you
have (

--
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

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


Re: Simulating int arithmetic with wrap-around

2017-01-05 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-05 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-05 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: Hey, I'm new to python so don't judge.

2017-01-05 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


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

2017-01-05 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: Hey, I'm new to python so don't judge.

2017-01-05 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: Hey, I'm new to python so don't judge.

2017-01-05 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: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-05 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-05 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: Clickable hyperlinks

2017-01-05 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