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

2017-01-06 Thread Terry Reedy
On 1/3/2017 7:02 PM, Callum Robinson wrote:
> When i check the code it comes up with invalid syntax and my writing line
gets re directed here
>
> def is_same(target, number:
> if target == number:
> result="win"
> elif target > number:
> result="low"
> else:
> result="high"
> return result

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


--
Terry Jan Reedy

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


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

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

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

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


Re: Clickable hyperlinks

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

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

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

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

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

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

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

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


Re: How Best to Coerce Python Objects to Integers?

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

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

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

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

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

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

E.

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


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

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

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

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


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

2017-01-06 Thread Erik
Hi Callum,

On 04/01/17 00:30, Callum Robinson wrote:
> I feel like im missing something so blatantly obvious.

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

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

See the difference?

E.

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


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

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

I feel like im missing something so blatantly obvious.

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


Re: Screwing Up looping in Generator

2017-01-06 Thread Erik
Hi,

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

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

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

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

E.

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


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

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

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


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

Somewhere on the screen you see something like:


x = 23 + )
 ^
SyntaxError: invalid syntax



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





--
Steve
â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and
sure
enough, things got worse.

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


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

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

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

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

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


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

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

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

--
Issue
--

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


-
Here is the most recent code
-


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

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

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

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

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

higher_or_lower = is_same(computer_number, guess)

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

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


Re: trouble with cmd.Cmd and prompting

2017-01-06 Thread Cameron Simpson
On 03Jan2017 16:57, Peter Otten <[email protected]> wrote:
>Cameron Simpson wrote:
>> On 03Jan2017 00:14, Dennis Lee Bieber  wrote:
>>>On Tue, 3 Jan 2017 11:33:15 +1100, Cameron Simpson 
>>>declaimed the following:
I'm using cmd.Cmd to write a little FTP-like command line to interface to
a storage system of mine and encountering weird behaviour. When I enter a
command the next prompt appears _before_ the associated operation runs,
[...]
>>>Haven't used the module but there is something I find intriguing in the
>>>help system
>>>-=-=-=-=-
>>> Cmd.precmd(line)
>>>Hook method executed just before the command line is interpreted, but
>>>after the input prompt is generated and issued.
>>>-=-=-=-=-
>>>"... AFTER the input prompt is ... issued"
[...]
>I don't believe Dennis' reading of the docs is correct, and the relevant
>part of the source (Python 3.4) does not show anything to support it:
[... code that runs as I had imagined ...]
>Is there something asynchronous in your command? Perhaps you can post a
>minimal runnable example that shows the odd behaviour.

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

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

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

Cheers,
Cameron Simpson 

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


Re: How Best to Coerce Python Objects to Integers?

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

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

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


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

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

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


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


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

Indeed.


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




--
Steve
â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and
sure
enough, things got worse.

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


Re: Screwing Up looping in Generator

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

I just need it to write after each file however the

with open(#file) as csvf:

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

Sayth

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Cameron Simpson
On 03Jan2017 12:57, Steve D'Aprano  wrote:
>I dislike the Unix-style Vim/Emacs text editors, I prefer a traditional
>GUI-based editor. So my "IDE" is:
>- Firefox, for doing searches and looking up documentation;
>- an GUI programmer's editor, preferably one with a tab-based
>  interface, such as geany or kate;
>- a tab-based terminal.

"traditional GUI-based editor"

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

Just narking,
Cameron Simpson 

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


RE: Screwing Up looping in Generator

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

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

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


Re: Screwing Up looping in Generator

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

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

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

Cheers

Sayth

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


RE: Screwing Up looping in Generator

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

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

For a simple little Fibbonacci number generator:

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

and at the console:

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

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

But in 3.4.3 you get:

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

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

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


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

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

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

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


Re: How Best to Coerce Python Objects to Integers?

2017-01-06 Thread Erik
On 04/01/17 01:10, Steve D'Aprano wrote:
> On Wed, 4 Jan 2017 11:22 am, Erik wrote:
>> What he *should* have done is just validated his input strings before
>> presenting the string to int() - i.e., process the input with knowledge
>> that is specific to the problem domain before calling the
>> general-purpose function.
>
> That's the Look Before You Leap solution. But in this case, given the
> scenario described (a text file with a few typos), the best way is to ask
> for forgiveness rather than permission:

Yes, probably, in this case ;)

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

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

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

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

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

E.

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


RE: Screwing Up looping in Generator

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

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

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

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


Re: Screwing Up looping in Generator

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

Good idea or better available?

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



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

Sayth

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


RE: Screwing Up looping in Generator

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

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

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


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

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

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

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


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

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

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

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

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


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

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


But now look at how you check the result:

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


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

while higher_or_lower != "win":

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

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

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

- "to low"

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

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

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



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

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


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

2017-01-06 Thread Erik
On 04/01/17 02:24, Callum Robinson wrote:
> On Wednesday, January 4, 2017 at 3:05:48 PM UTC+13, MRAB wrote:
>> What values can 'is_same' return?
>>
>> Which of those values are you checking for in the loop?
>
> I'm sorry but i do not completely understand what you are stating

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

  higher_or_lower = is_same(computer_number, guess)

... you added:

print (higher_or_lower)

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

E.

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


Re: Clickable hyperlinks

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

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

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

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

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

Thanks.

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


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

2017-01-06 Thread Dennis Lee Bieber
On Tue, 3 Jan 2017 18:47:43 -0800 (PST), Callum Robinson
 declaimed the following:


>
>hello.
>I have thought of a number between 1 and 100.
>Can you guess it?
>5
>Low
>Sorry , you are too high. Try again.
>
>Does this mean the number i entered is to low but the code is still stating it
is to high?

Is that a cut&paste from some console window, or are you just retyping
what you think it did?

Nothing in your previous code produces the word "Low" -- it will
produce "low" (notice the case).

And where in your code do you test for that return word?


To simplify things -- don't return words from your function... change
it to return +1 for high, -1 for low, and 0 for "win".

Then figure out how to modify the main loop to use those integers...

--
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.home.netcom.com/

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


RE: Clickable hyperlinks

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

Actually it is, or at least it doesn't happen in all email readers. Mine, for 
instance, never breaks up threads.

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

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

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

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

> Thanks.

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

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


RE: Screwing Up looping in Generator

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

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

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

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


Re: Clickable hyperlinks

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

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

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

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

Sounds good.

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

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


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

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

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

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

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

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


RE: Clickable hyperlinks

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

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

I'm getting that.

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

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

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

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

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

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


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

2017-01-06 Thread Erik
On 04/01/17 03:25, Steven D'Aprano wrote:
> On Wednesday 04 January 2017 12:25, Callum Robinson wrote:
>
>> Hey man thanks, the sad thing is i have no idea why i put that in. I must be
>> having a terrible day.
>
> Don't worry about it. The difference between a beginner and an expert is
*not*
> that experts make fewer mistakes, but that experts know how to fix those
> mistakes so quickly that they don't even notice them.

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

E.

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


Re: Clickable hyperlinks

2017-01-06 Thread Dan Sommers
On Wed, 04 Jan 2017 16:40:00 +1100, Steven D'Aprano wrote:

> On Wednesday 04 January 2017 15:46, Deborah Swanson wrote:
>
>> Steven D'Aprano wrote, on January 03, 2017 8:04 PM
> [...]
>>> Of course you have to put quotes around them to enter them in
>>> your source code.
>>> We don't expect this to work:
>>>
>>> print(Hello World!)
>>>
>>> you have to use a string literal with quotes:
>>>
>>> print('Hello World!')
>>>
>>> Same for all of the above.
>
>> I didn't try printing them before, but I just did. Got:
>>
> print([Example](http://www.example.com)
>>
>> SyntaxError: invalid syntax  (arrow pointing at the colon)
>
> You missed the part where I said you have to put them in quotes.

ObPython:  "When I've got these antlers on I am dictating and when I take them 
off I am not dictating."  :-)

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


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

2017-01-06 Thread Erik
On 04/01/17 02:47, Callum Robinson wrote:
> On Wednesday, January 4, 2017 at 3:35:53 PM UTC+13, Erik wrote:
> I did it and this is what it states when i run it
>
> hello.
> I have thought of a number between 1 and 100.
> Can you guess it?
> 5
> Low
> Sorry , you are too high. Try again.
>
> Does this mean the number i entered is to low but the code is still stating
it is to high?

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

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

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

E.

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do

2017-01-06 Thread Paul Rudin
Tim Johnson  writes:

> * Antonio Caminero Garcia  [170102 20:56]:
>> Guys really thank you for your answers. Basically now I am more
>> emphasizing in learning in depth a tool and get stick to it so I
>> can get a fast workflow. Eventually I will learn Vim and its
>> python developing setup, I know people who have been programming
>> using Vim for almost 20 years and they did not need to change
>> editor (that is really awesome).
>
>  Bye the way, one thing I like about the GUI based vim is that it
>  supports tabs, where emacs does not.

M-x package-install tabbar

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


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

2017-01-06 Thread Dennis Lee Bieber
On Tue, 3 Jan 2017 16:27:33 -0800 (PST), Callum Robinson
 declaimed the following:

>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

And that statement tells us you are trying to run from within some
IDE/editor which is trapping Python exceptions and producing a dialog box
for them.

Instead, save your script (if you haven't yet) as a file (whatever.py).

Open a command line interpreter/shell.

Navigate (cd ...) to where you saved the file

Type "python whatever.py"

Copy and paste the results of the CLI/Shell window.
--
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.home.netcom.com/

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


RE: Clickable hyperlinks

2017-01-06 Thread Steven D'Aprano
On Wednesday 04 January 2017 15:46, Deborah Swanson wrote:

> Steven D'Aprano wrote, on January 03, 2017 8:04 PM
[...]
>> Of course you have to put quotes around them to enter them in
>> your source code.
>> We don't expect this to work:
>>
>> print(Hello World!)
>>
>>
>> you have to use a string literal with quotes:
>>
>> print('Hello World!')
>>
>>
>> Same for all of the above.

> I didn't try printing them before, but I just did. Got:
>
 print([Example](http://www.example.com)
>
> SyntaxError: invalid syntax  (arrow pointing at the colon)

You missed the part where I said you have to put them in quotes.

Like any other string in Python, you have to use quotation marks around it for 
Python to understand it as a string. None of these things will work:

print( Hello World! )

print( What do you want to do today? )

print( 3 2 1 blast off )

print( http://www.example.com )


This isn't specific to print. This won't work either:

message = Hello World!

In *all* of these cases, you have to tell Python you're dealing with a string, 
and you do that with quotation marks:

message = "Hello World!"
print( 'What do you want to do today?' ) count_down = '3 2 1 blast off'
url = 'http://www.example.com'




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

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


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

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

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

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

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

comptuer_number = number.radnint(1, 100)

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

comptuer_number = random.radnint(1, 100)


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

comptuer_number = random.randint(1, 100)


and then a third time:

computer_number = random.randint(1, 100)


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




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

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do

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

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


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

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

http://leoeditor.com/

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



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

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Rustom Mody
On Wednesday, January 4, 2017 at 5:42:34 AM UTC+5:30, Dietmar Schwertberger 
wrote:
> 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

Im surprised no one's talked of idle (or Ive missed it?)

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


Re: Clickable hyperlinks

2017-01-06 Thread boB Stepp
On Tue, Jan 3, 2017 at 10:46 PM, Deborah Swanson
 wrote:
>

>
> I didn't try printing them before, but I just did. Got:
>
> >>> print([Example](http://www.example.com)
>
> SyntaxError: invalid syntax  (arrow pointing at the colon)

As Steve had said, you need to put everything inside quotes.  Also, you are 
missing a matching paren.  Thus:

py3: print("[Example](http://www.example.com)") 
[Example](http://www.example.com)

As to whether anything will be "clickable" or not, what has already been said 
about different types of terminals applies.

--
boB

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


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

2017-01-06 Thread Larry Hudson via Python-list
On 01/03/2017 04:27 PM, Callum Robinson wrote:
> 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
>

Exactly HOW are you running this?

If you are getting a popup, I suspect you are using an on-line version in a 
browser.  To get the
proper Python error messages (called Tracebacks) you MUST run the program in a 
terminal on your
own computer.  These tracebacks are VERY informative (once you get used to 
them).   :-)
And these tracebacks are what WE need to see to help you.

You DO have Python installed, don't you?

--
  -=- Larry -=-

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


Re: Clickable hyperlinks

2017-01-06 Thread Dennis Lee Bieber
On Tue, 3 Jan 2017 20:46:31 -0800, "Deborah Swanson"
 declaimed the following:

>
>I didn't try printing them before, but I just did. Got:
>
 print([Example](http://www.example.com)
>
>SyntaxError: invalid syntax  (arrow pointing at the colon)
>

As I mentioned to someone else earlier...

Count your parentheses... You need a ) for each (

AND you need " (or ') around the strings.

As you entered it, you have invoked a print operation, passing it:

A list containing a reference to a (undefined) variable "Example", and then you 
attempt call that list as a function passing it some unrecognized keyword 
"http" with a colon that Python normally uses indicate the start of a code 
block; said block being "//www.example.com".

Try

print("[Example](http://www.example.com)")

--
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.home.netcom.com/

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Michael Torrie wrote, on January 03, 2017 8:05 PM
>
> On 01/03/2017 08:46 PM, Deborah Swanson wrote:
> > Actually it is, or at least it doesn't happen in all email readers.
> > Mine, for instance, never breaks up threads.
>
> Mine doesn't either, which illustrates the issue. This
> message, for example appears under a long thread that started
> out life as "mentor training python Romania with
> certification" and then changed to "Cleaning up conditionals"
> and then changed to "Clickable hyperlinks." All in one
> thread. My client doesn't break them up because they all tie
> together via the message-id header.
>
> And most of us would not like our client to break a thread
> just because the subject changes. Often in long conversations
> there are twists and turns in the discussion and sometimes
> side-paths are explored, and the subject often is changed to
> reflect this.  With a truly threaded email reader (one that
> shows a tree of messages, not just chronological order), this
> works out very well.  So if a discussion has a natural
> evolution into various other topics, it is often considered
> okay to just change the subject but continue the thread.
> Other times, it's better to start a new thread.  Where that
> line is is hard to say!
>
> > I did say in the message you're replying to that I will try to
> > remember to start new threads with brand new messages.
> (Even though I
> > think pipermail's behavior is a bug, that's what many
> people read the
> > list
> > from.)
>
> Sounds good.
>
> I don't know of anyone that reads on the pipermail archive,
> except in response to web searches.  Most people use clients
> of some kind, NNTP or email.  And those that group messages
> according to message-id (most clients except for ones that
> try to be smart like Gmail web or Outlook) will show all the
> topics I mentioned before as one giant thread, which is by
> design (that's what message-id headers are for).

I suppose. Times change of course, which always suits some and not others. 
Personally, I think putting messages that have different titles all in one 
thread is a bad design, but as I've said a couple of times now I intend to 
comply with the new rules. But compliance doesn't imply agreement. I prefer the 
old system, which ordered threads by titles, but there's obviously no pleasing 
everyone on this issue.

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


Re: Clickable hyperlinks

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

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

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

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

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

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

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


Re: Clickable hyperlinks

2017-01-06 Thread Paul Rudin
"Deborah Swanson"  writes:

>
> I didn't try printing them before, but I just did. Got:
>
 print([Example](http://www.example.com)
>
> SyntaxError: invalid syntax  (arrow pointing at the colon)
>

With respect, if you typed that at python then it's probably a good idea to 
take a step back and work through the excellent tutorial.

https://docs.python.org/3/tutorial/

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


RE: Clickable hyperlinks

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

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

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

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

The above are just text, no different from:

Hello World!


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

print(Hello World!)


you have to use a string literal with quotes:

print('Hello World!')


Same for all of the above.

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


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

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


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




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

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Antonio Caminero Garcia
On Tuesday, January 3, 2017 at 4:12:34 PM UTC-8, Dietmar Schwertberger wrote:
> On 02.01.2017 12:38, Antonio Caminero Garcia wrote:
> 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.

That sounds interesting. By the look of it I think I am going to give it a try.

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

If it happens to be Arduino I normally use a sublime plugin called Stino 
https://github.com/Robot-Will/Stino
(1337 people starred that cool number :D)

>  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 want editor with those IDE capabilities and git integration, with optionally 
cool stuff as for example remote debugging.

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

Unfortunately most of the time I am still using print and input functions. I 
know that sucks, I did not use the pdb module, I guess that IDE debuggers 
leverage such module.

> Regards,
>
> Dietmar

Thank you so much for your answer.

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


Re: Mutable global state and threads

2017-01-06 Thread Chris Angelico
On Wed, Jan 4, 2017 at 5:41 PM, Kev Dwyer  wrote:
> Hello List,
>
> I came across some threading code in Some Other place recently and wanted to
> sanity-check my assumptions.
>
> The code (below) creates a number of threads; each thread takes the last
> (index -1) value from a global list of integers, increments it by one and
> appends the new value to the list.
>
> The originator of the code expected that when all the threads completed, the
> list would be an ascending sequence of integers, for example if the original
> list was [0] and two threads mutated it twice each, the final state would be
> [0, 1, 2, 3, 4].
>
> Here is a version of the code (slightly simplified and modified to allow
> changing the number of threads and mutations).
>
>
> import sys
> import threading
>
>
> class myThread(threading.Thread):
>
> def __init__(self, nmutations):
> threading.Thread.__init__(self)
> self.nmutations = nmutations
>
> def run(self):
> mutate(self.nmutations)
> # print (L)
> return
>
> def mutate(nmutations):
> n = nmutations
> while n:
> L.append(L[-1 ]+ 1)
> n -= 1
> return
>
>
> def main(nthreads=2, nmutations=2):
> global L
> L = [0]
> threads = [myThread(nmutations) for i in range(nthreads)]

You can drop the myThread class and instead instantiate threading.Thread 
directly:

threads = [threading.Thread(target=mutate, args=(nmutations,))
for i in range(nthreads)]
> Firstly, is it true that the statement
>
> L.append(L[-1 ]+ 1)
>
> is not atomic, that is the thread might evaluate L[-1] and then yield,
> allowing another thread to mutate L, before incrementing and appending?

That is indeed true. If the code were all run sequentially (setting nthreads to 
1), the last element in the final list would be equal to nthreads*nmutations, 
and you can mess around with the numbers to find out exactly how far short it 
is.

Python guarantees that certain primitive operations (such as the list append 
itself) won't be broken, but anything that involves application code can be 
split up. So you can be confident that you'll end up with a list of integers 
and not a segfault, but they might not even be consecutive.

> Secondly, the original code printed the list at the end of a thread's run
> method to examine the state of the list.  I don't think this would work
> quite as expected, because the thread might yield after mutating the list
> but before printing, so the list could have been mutated before the print
> was executed.  Is there a way to display the state of the list before any
> further mutations take place?

At the end of one thread's run, there are other threads still running. So 
you're correct again; another thread could change the list. What you could 
possibly do mess with locking, but before I advise that, I'd have to see what 
you're trying to accomplish - toy examples are hard to mess with. Bear in mind 
that simple code like this can't actually benefit from threads, as Python (or 
at least, CPython) won't run two of them at once.

> (Disclaimer: I understand that sanity, mutable global state and threads are
> unlikely bedfellows and so promise never to try anything like this in
> production code).

Well, I lost my sanity shortly after becoming a programmer, so I've happily 
used mutable globals in threaded programs. :) You can use them quite happily as 
long as you know what you're doing. But if you find yourself tossing in heaps 
of locks to try to reclaim your sanity, you may want to consider asyncio 
instead. Instead of locking and unlocking to say "don't yield here", you 
explicitly say "yield here". The downside is that you have to have *everything* 
cope with that - and not everything can. (For a long time, it was easy to 
establish a socket connection asynchronously, but hard to look up 
"www.python.org" without potentially stalling.) They're two models that can 
both be used to solve a lot of the same problems.

By and large, your analysis is correct. Have fun threading! :)

ChrisA

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Steve D'Aprano wrote, on January 04, 2017 2:09 AM
>
> On Wed, 4 Jan 2017 08:00 pm, Deborah Swanson wrote:
>
> [speaking of threading emails]
>
> > I suppose. Times change of course, which always suits some and not
> > others. Personally, I think putting messages that have different
> > titles all in one thread is a bad design, but as I've said
> a couple of
> > times now I intend to comply with the new rules. But compliance
> > doesn't imply agreement. I prefer the old system, which ordered
> > threads by titles, but there's obviously no pleasing
> everyone on this
> > issue.
>
> Indeed :-)
>
> However, as far as I am aware, the use of threading by
> following the In-Reply-To and References header lines goes
> back to at least 1982, which makes them pretty old, and
> certainly pre-dates Gmail and Outlook by many years. They're
> also official standards which ALL email programs are supposed
> to follow, so if Gmail and Outlook fail to follow the
> standard, well, I wouldn't be surprised. I don't absolutely
> know for a fact that threading in this way is older than
> threading by subject line, but I'm fairly confident that what
> you are calling the "new rules" are actually the much older rules.
>
> Are there any old-timers here who were using email prior to
> 1982 that would care to comment?
>
>
> Here's a discussion by Jamie Zawinski, who wrote Netscape
> Navigator, before it became Mozila and Firefox, so he knows
> what he's talking about:
>
https://www.jwz.org/doc/threading.html


The concept here is not so much that people start a new topic and change the 
subject, but that sometimes the topic just naturally evolves to the point that 
a change in subject is sensible. Take this thread for example: the topic has 
drifted from "Clickable hyperlinks" to talking about email threading. I should 
be able to change the subject without breaking the
thread:

Clickable hyperlinks
+- RE: Clickable hyperlinks
ü  +- Re: RE: Clickable hyperlinks
ü  L- RE: Clickable hyperlinks
ü L- Threading [was Re: Clickable hyperlinks]
üL- Re: Threading
+- RE: Clickable hyperlinks
L- Re: Clickable hyperlinks


Adding a "Re:" or "RE" to the subject doesn't change the thread, and neither 
does changing the subject line in a more substantial way.

Of course, I can always *choose* to sort by subject line, or date. Personally I 
hardly ever sort by thread, so it is no skin off my nose what you do. But when 
you hit "Reply" to a message, you inherit the "Reference" and "In-Reply-To" 
headers from the previous message, so at least some people will see it threaded 
in an existing thread rather than starting a brand new one.




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

Interesting history lesson. I actually wouldn't know which came first, since 
I've only been online since 1992 (offline computing since 1972). I do know that 
I've been on a lot of mailing lists like this one since 1992 (remember 
Fidonet?), some with actively posting members in the thousands. And I have 
never heard anyone whine and complain about threading issues that had anything 
to do with the message title until yesterday.

So it goes. I'll repeat again that I'll comply with the rules of this group 
that are brand spanking new to me, and I've been around a corner or two.

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


Re: Simulating int arithmetic with wrap-around

2017-01-06 Thread Gregory Ewing
Paul Rubin wrote:
> 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 possibly numpy.

--
Greg

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


Introducing my Python/PyQt5 powered Bing wallpaper open source project

2017-01-06 Thread iMath
Hello everyone ,
I'd like to introduce my Python/PyQt5 powered Bing wallpaper open source 
project.
â ï

BingNiceWallpapers
https://github.com/redstoneleo/BingNiceWallpapers

BingNiceWallpapers can get background images from 
http://www.bing.com/?mkt=zh-CN and set them as your desktop wallpaper by just a 
single click on system tray icon.

For Windows binary installer and more information, please refer to 
http://mathjoy.lofter.com/post/42208d_7cabcf7 (written in simplified Chinese)

Features

Changing wallpaper in a single click on system tray icon or after a specified 
time interval
Windows and Linux Gnome desktop support Delete or save the current wallpaper


Welcome to help with the project !

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


Re: Clickable hyperlinks

2017-01-06 Thread Rodrigo Bistolfi
2017-01-04 7:39 GMT-03:00 Steve D'Aprano :

> On Wed, 4 Jan 2017 08:32 pm, Deborah Swanson wrote:
>
> Aside: you've actually raised a fascinating question. I wonder whether
> there
> are any programming languages that understand URLs as native data types, so
> that *source code* starting with http:// etc is understood in the same way
> that source code starting with [ is seen as a list or { as a dict?
> ...
>

Some Smalltalk implementations have something that comes close:

st> 'https://python.org' asUrl retrieveContents

`asUrl` would be a string method returning a URL instance, which also has a 
convenient method `retrieveContents` wrapping an http client. Not hard to do 
with Python, I think this could be an interesting exercise for a learner.

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Steven D'Aprano wrote, on January 03, 2017 8:04 PM
>
> On Wednesday 04 January 2017 14:04, Deborah Swanson wrote:
>
> > Steve D'Aprano wrote, on January 03, 2017 4:56 PM
> [...]
> >> Python can't force the console to treat something as a clickable
> >> link, if the console has no capacity for clickable links. Nor can
> >> Python predict what format the console uses to recognise a link.
> >>
> >> The best you can do is to experiment with a couple of
> simple formats
> >> and see which, if any, your console understands:
> >>
> >> # HTML
> >> http://www.example.com";>Example.
> >>
> >> # URL in angle brackets
> >> Example 
> >>
> >> # URL alone
> >> http://www.example.com
> >>
> >> # I can't remember what these are called
> >> http://www.example.com>
> >>
> >> # Markup
> >> [Example](http://www.example.com)
> >>
> >> # Rest
> >> `Example `_
> [...]
>
> > I tried all of your examples in IDLE, and they all get
> syntax errors.
> > I'd expect the same from PyCharm, though I didn't try it.
>
> Syntax errors? How can you get syntax errors from *output* text?
>
> The above are just text, no different from:
>
> Hello World!

I closed the IDLE window these were on, but the error arrow was pointing to 
punctuation in each case, a colon in one case, angle bracket in another. Sorta 
seems like IDLE is trying to do something with them and not taking them as 
simple plain text. But it's not making hyperlinks, so I'm not sure how much I 
care exactly what it's doing.

> Of course you have to put quotes around them to enter them in
> your source code.
> We don't expect this to work:
>
> print(Hello World!)
>
>
> you have to use a string literal with quotes:
>
> print('Hello World!')
>
>
> Same for all of the above.

I didn't try printing them before, but I just did. Got:

>>> print([Example](http://www.example.com)

SyntaxError: invalid syntax  (arrow pointing at the colon)

> py> print('http://www.example.com";>Example.')
> http://www.example.com";>Example.
>
>
> That's the Python interactive interpreter (with a custom
> prompt, I prefer "py>"
> rather than the default ">>>"). Or I can do this from the
> operating system's
> shell prompt:
>
> steve@runes:~$ python -c "print 'http://www.example.com'"
http://www.example.com


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




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

I need to get a new power supply in my Linux-capable machine, but for now I'm 
stuck with Winblows on a very old PC.

As I've mentioned in other posts on this thread, I'm now thinking that I need 
to write a class to do this, and find out how Firefox and url aware terminals 
in Linux do it. There must be a way.

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


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
On 2017-01-04 08:44 AM, Rodrigo Bistolfi wrote:
> 2017-01-04 7:39 GMT-03:00 Steve D'Aprano :
>> Aside: you've actually raised a fascinating question. I wonder whether
>> there
>> are any programming languages that understand URLs as native data types, so
>> that *source code* starting with http:// etc is understood in the same way
>> that source code starting with [ is seen as a list or { as a dict?
>
> Some Smalltalk implementations have something that comes close:
>
> st> 'https://python.org' asUrl retrieveContents

But notice that even here the URL has to be defined as a string.  To be a first 
class object you would need to do something like this:

   url = https://python.org/

The only time you would see that is in config files and languages like shell 
where everything is a string so no quotes necessary.  They are implied.

> `asUrl` would be a string method returning a URL instance, which also has a
> convenient method `retrieveContents` wrapping an http client. Not hard to
> do with Python, I think this could be an interesting exercise for a learner.

Sure but the issue is, what to do with it.  In any case, it's still just a 
wrapper around various string methods.  You still need to give the class a 
string to create the object.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:[email protected] VoIP: sip:[email protected]

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


Mutable global state and threads

2017-01-06 Thread Kev Dwyer
Hello List,

I came across some threading code in Some Other place recently and wanted to 
sanity-check my assumptions.

The code (below) creates a number of threads; each thread takes the last (index 
-1) value from a global list of integers, increments it by one and appends the 
new value to the list.

The originator of the code expected that when all the threads completed, the 
list would be an ascending sequence of integers, for example if the original 
list was [0] and two threads mutated it twice each, the final state would be 
[0, 1, 2, 3, 4].

Here is a version of the code (slightly simplified and modified to allow 
changing the number of threads and mutations).


import sys
import threading


class myThread(threading.Thread):

def __init__(self, nmutations):
threading.Thread.__init__(self)
self.nmutations = nmutations

def run(self):
mutate(self.nmutations)
# print (L)
return


def mutate(nmutations):
n = nmutations
while n:
L.append(L[-1 ]+ 1)
n -= 1
return


def main(nthreads=2, nmutations=2):
global L
L = [0]
threads = [myThread(nmutations) for i in range(nthreads)]
for t in threads:
t.start()
for t in threads:
t.join()
print(L)
assert L == list(range((nthreads * nmutations) + 1))

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

Firstly, is it true that the statement

L.append(L[-1 ]+ 1)

is not atomic, that is the thread might evaluate L[-1] and then yield, allowing 
another thread to mutate L, before incrementing and appending?

Secondly, the original code printed the list at the end of a thread's run 
method to examine the state of the list.  I don't think this would work quite 
as expected, because the thread might yield after mutating the list but before 
printing, so the list could have been mutated before the print was executed.  
Is there a way to display the state of the list before any further mutations 
take place?

(Disclaimer: I understand that sanity, mutable global state and threads are 
unlikely bedfellows and so promise never to try anything like this in 
production code).

Cheers,

Kev

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Steven D'Aprano wrote, on January 03, 2017 9:40 PM
>
> On Wednesday 04 January 2017 15:46, Deborah Swanson wrote:
>
> > Steven D'Aprano wrote, on January 03, 2017 8:04 PM
> [...]
> >> Of course you have to put quotes around them to enter them in your
> >> source code. We don't expect this to work:
> >>
> >> print(Hello World!)
> >>
> >>
> >> you have to use a string literal with quotes:
> >>
> >> print('Hello World!')
> >>
> >>
> >> Same for all of the above.
>
> > I didn't try printing them before, but I just did. Got:
> >
>  print([Example](http://www.example.com)
> >
> > SyntaxError: invalid syntax  (arrow pointing at the colon)
>
> You missed the part where I said you have to put them in quotes.
>
> Like any other string in Python, you have to use quotation
> marks around it for
> Python to understand it as a string. None of these things will work:
>
> print( Hello World! )
>
> print( What do you want to do today? )
>
> print( 3 2 1 blast off )
>
> print( http://www.example.com )
>
>
> This isn't specific to print. This won't work either:
>
> message = Hello World!
>
> In *all* of these cases, you have to tell Python you're
> dealing with a string,
> and you do that with quotation marks:
>
> message = "Hello World!"
> print( 'What do you want to do today?' )
> count_down = '3 2 1 blast off'
> url = 'http://www.example.com'
>
>
>
>
> --
> Steven

Thanks, Steven. Yes, of course if you want to print strings you must enclose 
them in quotes. I think you learn that in Week 1 of any introductory course on 
Python.

But we aren't trying to print strings here, the point is to produce clickable 
links. I didn't enclose them with quotes because I didn't see any point in 
printing plain text when I wanted clickable links. I actually didn't understand 
why you thought I should print them, but it never would have occurred to me 
that you wanted me to print out a bunch of silly plain text strings, apparently 
just for the heck of it.

At this point, if I pursue this any farther, it will be to look into how 
Firefox takes webpage titles and urls out of its sqlite database and makes 
objects you can click on to open the webpages. That's the basic technology I'd 
need to find a way to talk (write) python into doing.

If it's even worth it. On a practical level it's not worth it, way too much 
work for the teensy advantage of having it to use. It might be some giggles to 
figure out how to do it and maybe I will sometime just for funsies.

My original question was whether python had anything to provide this 
functionality, and the answer appears to be a resounding NO!!!

Answer received, and thanks to all who contributed.

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


Re: Screwing Up looping in Generator

2017-01-06 Thread Rhodri James
On 04/01/17 02:10, Deborah Swanson wrote:
> Sayth Renshaw wrote, on January 03, 2017 5:36 PM
>>
>> So can I call the generator twice and receive the same file
>> twice in 2 for loops?
>>
>> Once to get the files name and the second to process?
>>
>>  for file in rootobs:
>> base = os.path.basename(file.name)
>> write_to = os.path.join("output",
>> os.path.splitext(base)[0] + ".csv")
>> with open(write_to, 'w', newline='') as csvf:
>> for file in rootobs:
>>   # create and write csv
>>
>> Cheers
>>
>> Sayth
>
> I don't see why not, if you let the first one run to completion and then
> do it again a second time. Assuming your generator doesn't somehow
> delete or modify the file specifications as it yields them. It would be
> helpful to see the code for rootobs, if you have it.

Ahem.  If Sayth is using the correct terminology and rootobs actually is a 
generator (not, say, a list or tuple), then no it won't work.  Once a generator 
is exhausted, it's exhausted.  Besides, the nested for-loops over the same 
iterable is a dead giveaway that something is wrong.


--
Rhodri James *-* Kynesim Ltd

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


Re: Simulating int arithmetic with wrap-around

2017-01-06 Thread Random832
On Fri, Dec 30, 2016, at 09:47, Steve D'Aprano wrote:
> 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?

I'd do something like:

bit_mask = (1 << bits) - 1 # 0x sign_bit = 1 << (bits - 1) # 0x8000 
sign_ext = ~bit_mask # ...F

def signed(value):
if value & sign_bit:
return value | sign_ext
else:
return value & bit_mask

def unsigned(value):
return value & bit_mask

And also avoid doing it on intermediate steps where it can be shown to not 
affect the result or allow the value to grow too large.

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


Re: Screwing Up looping in Generator

2017-01-06 Thread Steve D'Aprano
On Wed, 4 Jan 2017 01:09 pm, Sayth Renshaw wrote:

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

It "may" work. Or it "may not" work. It is hard to tell because we don't have 
enough context to understand your code.

Let me see if I can guess what you are doing:

> Good idea or better available?
>
> def get_list_of_names(generator_arg):
> name_set = set()
> for name in generator_arg:
> base = os.path.basename(name.name)
> filename = os.path.splitext(base)[0]
> name_set.add(filename)
> return name_set

What does "generator_arg" do? Since you iterate over it, it could be a list, a 
tuple, any other sequence, or an iterator. Why does it have to be a generator?

What is "name.name"?

I *think* that your intention is to take a list of objects that hold filenames:


["C://My Documents/data.txt", "C://My Documents/folder/image.jpg",
 "C://file.txt", "D://installer.exe", "E://folder/image.gif"]

strip off the path, strip off the file extensions, remove any duplicates, 
giving:

set(["data", "image", "file", "installer"])

(Notice that image.jpg and image.gif count as duplicates.)


If that is what you want, then I think get_list_of_names will work, except:

- the name is WRONG: it returns a set, not a list;

- the name does not describe what the function does;

- there's no documentation

- the name of the argument is misleading, it doesn't have to be a generator.


Other than that, I think the code does what I think you want.


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


Your indentation is wrong.

What's "rootobs"?

The code you show here does not have enough detail for me to even try to guess 
what it does.





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

2017-01-06 Thread William Ray Wing

> On Jan 4, 2017, at 1:54 AM, Antonio Caminero Garcia 
wrote:
>
> On Tuesday, January 3, 2017 at 4:12:34 PM UTC-8, Dietmar Schwertberger wrote:
>> On 02.01.2017 12:38, Antonio Caminero Garcia wrote:
>> 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.
>
> That sounds interesting. By the look of it I think I am going to give it a
try.
>
>

[byte]


> I want editor with those IDE capabilities and git integration, with
optionally  cool stuff as for example remote debugging.

I use Wing, and I think you will like it.  It *is* pythonic, and for what it is 
worth, offers remote debugging as one of its more recently added features.

-Bill

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


RE: Clickable hyperlinks

2017-01-06 Thread Steve D'Aprano
On Wed, 4 Jan 2017 08:32 pm, Deborah Swanson wrote:

> Thanks, Steven. Yes, of course if you want to print strings you must
> enclose them in quotes. I think you learn that in Week 1 of any
> introductory course on Python.
>
> But we aren't trying to print strings here, the point is to produce
> clickable links. I didn't enclose them with quotes because I didn't see
> any point in printing plain text when I wanted clickable links. I
> actually didn't understand why you thought I should print them, but it
> never would have occurred to me that you wanted me to print out a bunch
> of silly plain text strings, apparently just for the heck of it.

What we have here is a failure to communicate :-)

I apologise for ruffling your feathers, but its difficult to judge another 
person's level of knowledge. In someways you're obviously quite knowledgeable 
about Python, but in other ways you're still learning (as we all are!) and I'm 
afraid I may have misjudged exactly what your level of knowledge was. Sorry 
about that.

I'm not suggesting that you print "silly plain text strings" just for the heck 
of it. You've asked how to get a clickable link using Python. There is only one 
way I know of to get a clickable link using Python:

Write out a link as plain text to another application which then interprets the 
plain text as a clickable link.

You *might* be able to get clickable links in Python by writing an entire GUI 
application, using (say) the tkinter library, or one of the third-party
GUI libraries like wxPython, kivy, pyqt, or others, but I haven't a clue
how. But even there, your links will start off as text, which means you will 
still need to surround them with quotes to make them strings.


Aside: you've actually raised a fascinating question. I wonder whether there 
are any programming languages that understand URLs as native data types, so 
that *source code* starting with http:// etc is understood in the same way that 
source code starting with [ is seen as a list or { as a dict?


But back to your problem: short of writing you own GUI application, in which 
case you can do *anything you like*, you can:

- write out a HTML file containing the URLs you want, in 
tags, then open the HTML file in a web browser and let the web browser 
interpret the HTML tags as clickable links;


- write out an Excel spreadsheet, using whatever format Excel expects, open
the spreadsheet in Excel, and let Excel interpret the mystery format as a 
clickable link;

- print the URL to the console, and see if the console is smart enough to
interpret it as a clickable link.


I'm sorry that I can't give you a one-sentence answer "just use such-and-such a 
function, that does exactly what you want in a platform-independent manner" :-(




--
Steve
â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and
sure
enough, things got worse.

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


RE: Clickable hyperlinks

2017-01-06 Thread Steve D'Aprano
On Wed, 4 Jan 2017 08:00 pm, Deborah Swanson wrote:

[speaking of threading emails]

> I suppose. Times change of course, which always suits some and not
> others. Personally, I think putting messages that have different titles
> all in one thread is a bad design, but as I've said a couple of times
> now I intend to comply with the new rules. But compliance doesn't imply
> agreement. I prefer the old system, which ordered threads by titles, but
> there's obviously no pleasing everyone on this issue.

Indeed :-)

However, as far as I am aware, the use of threading by following the 
In-Reply-To and References header lines goes back to at least 1982, which makes 
them pretty old, and certainly pre-dates Gmail and Outlook by many years. 
They're also official standards which ALL email programs are supposed to 
follow, so if Gmail and Outlook fail to follow the standard, well, I wouldn't 
be surprised. I don't absolutely know for a fact that threading in this way is 
older than threading by subject line, but I'm fairly confident that what you 
are calling the "new rules" are actually the much older rules.

Are there any old-timers here who were using email prior to 1982 that would 
care to comment?


Here's a discussion by Jamie Zawinski, who wrote Netscape Navigator, before it 
became Mozila and Firefox, so he knows what he's talking about:

https://www.jwz.org/doc/threading.html


The concept here is not so much that people start a new topic and change the 
subject, but that sometimes the topic just naturally evolves to the point that 
a change in subject is sensible. Take this thread for example: the topic has 
drifted from "Clickable hyperlinks" to talking about email threading. I should 
be able to change the subject without breaking the thread:

Clickable hyperlinks
âö£âö  RE: Clickable hyperlinks
âöé  âö£âö  Re: RE: Clickable hyperlinks
âöé  âööâö  RE: Clickable hyperlinks
âöé âööâö  Threading [was Re: Clickable hyperlinks]
âöéâööâö  Re: Threading
âö£âö  RE: Clickable hyperlinks
âööâö  Re: Clickable hyperlinks


Adding a "Re:" or "RE" to the subject doesn't change the thread, and neither 
does changing the subject line in a more substantial way.

Of course, I can always *choose* to sort by subject line, or date. Personally I 
hardly ever sort by thread, so it is no skin off my nose what you do. But when 
you hit "Reply" to a message, you inherit the "Reference" and "In-Reply-To" 
headers from the previous message, so at least some people will see it threaded 
in an existing thread rather than starting a brand new one.




--
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-06 Thread Tim Johnson
* Paul Rudin  [170103 23:17]:
> Tim Johnson  writes:
>
> > * Antonio Caminero Garcia  [170102 20:56]:
> >> Guys really thank you for your answers. Basically now I am more
> >> emphasizing in learning in depth a tool and get stick to it so I
> >> can get a fast workflow. Eventually I will learn Vim and its
> >> python developing setup, I know people who have been programming
> >> using Vim for almost 20 years and they did not need to change
> >> editor (that is really awesome).
> >
> >  Bye the way, one thing I like about the GUI based vim is that it
> >  supports tabs, where emacs does not.
>
> M-x package-install tabbar
  :) Thank you. list-packages is my friend ...
--
Tim
http://www.akwebsoft.com, http://www.tj49.com

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


RE: Clickable hyperlinks

2017-01-06 Thread Steve D'Aprano
On Wed, 4 Jan 2017 03:46 pm, Deborah Swanson wrote:

> As I've mentioned in other posts on this thread, I'm now thinking that I
> need to write a class to do this, and find out how Firefox and url aware
> terminals in Linux do it. There must be a way.


A GUI application can interpret text any way it chooses. Firefox takes a HTML 
file and renders it, using whatever GUI library it chooses. That GUI
library understands that text like:

Hello World!

should be shown in bold face, and text like:

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

should be shown as the word "Example" underlined and in some colour, and when 
you click on it the browser will navigate to the URL given. Firefox can do this 
because it controls the environment it runs in.

Same for Excel, which also controls the environment it runs in.

That's *not* the case for Python, which is at the mercy of whatever console or 
terminal application it is running in.

However, you can use Python to write GUI applications. Then it becomes
*your* responsibility to create the window, populate it with any buttons or
text or scroll bars you want, and you can choose to interpret text any way you 
like -- including as clickable Hyperlinks.

The bottom line is, there is no "a way" to do this. There are a thousand, ten 
thousand, ways to do it. Every web browser, every terminal, every URL-aware 
application, can choose its own way to do it. There's no one
single way that works everywhere, but if you are working in a console or 
terminal, just printing the URL is likely to be interpreted by the console as a 
clickable link:

print("http://www.example.com";)




--
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: Simulating int arithmetic with wrap-around

2017-01-06 Thread Rob Gaddi
On 01/03/2017 10:00 PM, Gregory Ewing wrote:
> Paul Rubin wrote:
>> 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 possibly numpy.
>

Agreed.  If you had to do a lot of calculations on arbitrary sized 
signed/unsigned ints, figuring how to parallelize them into numpy arrays would 
save you a ton of time.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address 
domain is currently out of order.  See above to fix.

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


Re: Clickable hyperlinks

2017-01-06 Thread Gilmeh Serda
On Tue, 03 Jan 2017 11:46:16 -0800, Deborah Swanson wrote:

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

Write it as HTML code save to temp file and call the browser which loads the 
file.

--
Gilmeh

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Steve D'Aprano wrote, on January 04, 2017 2:20 AM
>
> On Wed, 4 Jan 2017 03:46 pm, Deborah Swanson wrote:
>
> > As I've mentioned in other posts on this thread, I'm now
> thinking that
> > I need to write a class to do this, and find out how
> Firefox and url
> > aware terminals in Linux do it. There must be a way.
>
>
> A GUI application can interpret text any way it chooses.
> Firefox takes a HTML file and renders it, using whatever GUI
> library it chooses. That GUI library understands that text like:
>
> Hello World!
>
> should be shown in bold face, and text like:
>
> http://www.example.com";>Example
>
> should be shown as the word "Example" underlined and in some
> colour, and when you click on it the browser will navigate to
> the URL given. Firefox can do this because it controls the
> environment it runs in.
>
> Same for Excel, which also controls the environment it runs in.
>
> That's *not* the case for Python, which is at the mercy of
> whatever console or terminal application it is running in.
>
> However, you can use Python to write GUI applications. Then it becomes
> *your* responsibility to create the window, populate it with
> any buttons or text or scroll bars you want, and you can
> choose to interpret text any way you like -- including as
> clickable Hyperlinks.
>
> The bottom line is, there is no "a way" to do this. There are
> a thousand, ten thousand, ways to do it. Every web browser,
> every terminal, every URL-aware application, can choose its
> own way to do it. There's no one single way that works
> everywhere, but if you are working in a console or terminal,
> just printing the URL is likely to be interpreted by the
> console as a clickable link:
>
> print("http://www.example.com";)
>
>
>
>
> --
> Steve
> "Cheer up," they said, "things could be worse." So I cheered
> up, and sure enough, things got worse.

I can appreciate all that and pretty much knew most of it already. At this 
point I'm not so much concerned with how to put characters on a white space 
that are clickable, we've pretty much established at least a couple dozen 
messages ago that there's nothing for python to get hold of there because of 
the vast number of places people might want to put clickable links. (I actually 
read every message on a thread that interests me enough to participate.)

I think the entry point to this problem is to find out how to connect to the 
internet when you click that link. Then I think the nuts and bolts of what 
symbols to put where for a particular target would fall into place.

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


Re: Screwing Up looping in Generator

2017-01-06 Thread Sayth Renshaw
For completeness I was close this is the working code.

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


def data_attr(roots):
"""Get the root object and iter items."""
for name in names:
directory = "output"
write_name = name + ".csv"
with open(os.path.join(directory, write_name), 'w', newline='') as
csvf:
race_writer = csv.writer(csvf, delimiter=','
)


thanks for your time and assistance. It's much appreciated

Sayth

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Steve D'Aprano wrote, on January 04, 2017 2:39 AM
>
> On Wed, 4 Jan 2017 08:32 pm, Deborah Swanson wrote:
>
> > Thanks, Steven. Yes, of course if you want to print strings
> you must
> > enclose them in quotes. I think you learn that in Week 1 of any
> > introductory course on Python.
> >
> > But we aren't trying to print strings here, the point is to produce
> > clickable links. I didn't enclose them with quotes because I didn't
> > see any point in printing plain text when I wanted
> clickable links. I
> > actually didn't understand why you thought I should print
> them, but it
> > never would have occurred to me that you wanted me to print out a
> > bunch of silly plain text strings, apparently just for the
> heck of it.
>
> What we have here is a failure to communicate :-)
>
> I apologise for ruffling your feathers, but its difficult to
> judge another person's level of knowledge. In someways you're
> obviously quite knowledgeable about Python, but in other ways
> you're still learning (as we all are!) and I'm afraid I may
> have misjudged exactly what your level of knowledge was.
> Sorry about that.
>
> I'm not suggesting that you print "silly plain text strings"
> just for the heck of it. You've asked how to get a clickable
> link using Python. There is only one way I know of to get a
> clickable link using Python:
>
> Write out a link as plain text to another application which
> then interprets the plain text as a clickable link.
>
> You *might* be able to get clickable links in Python by
> writing an entire GUI application, using (say) the tkinter
> library, or one of the third-party GUI libraries like
> wxPython, kivy, pyqt, or others, but I haven't a clue how.
> But even there, your links will start off as text, which
> means you will still need to surround them with quotes to
> make them strings.
>
>
> Aside: you've actually raised a fascinating question. I
> wonder whether there are any programming languages that
> understand URLs as native data types, so that *source code*
> starting with http:// etc is understood in the same way that
> source code starting with [ is seen as a list or { as a dict?
>
>
> But back to your problem: short of writing you own GUI
> application, in which case you can do *anything you like*, you can:
>
> - write out a HTML file containing the URLs you want, in  href= ...  tags, then open the HTML file in a web browser
> and let the web browser interpret the HTML tags as clickable links;
>
>
> - write out an Excel spreadsheet, using whatever format Excel
> expects, open the spreadsheet in Excel, and let Excel
> interpret the mystery format as a clickable link;
>
> - print the URL to the console, and see if the console is
> smart enough to interpret it as a clickable link.
>
>
> I'm sorry that I can't give you a one-sentence answer "just
> use such-and-such a function, that does exactly what you want
> in a platform-independent manner" :-(
>
>
>
>
> --
> Steve
> "Cheer up," they said, "things could be worse." So I cheered
> up, and sure enough, things got worse.

Well, well. People mix and people misunderstand and misjudge each other. It's 
the way of things with people. I just needed to tell you how it all looked from 
my side.  So are we done with that?  I certainly hope so.

I'm quite well aware by now that there is no one-sentence answer to my original 
question, if there's any coherent answer at all. Them's the breaks. Live with 
it or live without it, it doesn't care.

I do appreciate the education I've gotten on this thread about the issues 
involved. But I rather imagine that near term anyway, I'll only be pondering it 
now and then, and maybe poking around a bit. Who knows, maybe I'll eventually 
invent the solution and make my first million dollars from it.  haha, yeah 
right.

So it goes.


Deborah

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
D'Arcy Cain wrote, on Wednesday, January 04, 2017 5:03 AM
>
> Deborah - please trim your quoted text.

Yes, I will. Some lists want to have it all to review in one message, some want 
it trimmed to just the lines you are responding to. I was just waiting to see 
what this list wants.

> On 2017-01-04 04:32 AM, Deborah Swanson wrote:


> > But we aren't trying to print strings here, the point is to produce
> > clickable links. I didn't enclose them with quotes because I didn't
> > see any point in printing plain text when I wanted
> clickable links. I
>
> I'm not sure what your links are composed of but mine all look like
> sequences of characters or "strings."  It sounds like you are
> trying to
> make URL a first class type like strings. integers, floats, etc.  I
> can't think of any language that treats URLs as first class objects.
> Even HTML needs quotes:
>
>http://...";>Go here

It seemed reasonable that you might be able to print urls, which is why I tried 
the experiment with all of Steven's suggested formats. But I was highly 
skeptical that any would work without some kind of modifiers to a bare print 
statement.

> > actually didn't understand why you thought I should print
> them, but it
>
> You want to output them to something.  That often involves
> printing them
> to a particular handler.

Yes, that's one of the things I would expect if we could print them.

> > never would have occurred to me that you wanted me to print out a
> > bunch of silly plain text strings, apparently just for the
> heck of it.
>
> Is that really what you got from his message?

Please forgive me, and I hope Steven forgives me too, but I was sick to death 
of all the beating on a dead horse (using Python to make clickable links in a 
console, any console). I'd taken heart when he first suggested his print 
experiment, because it was a plausible approach. But I lost my temper when he 
upbraided me in this message for failing to enclose my strings in quotes, in a 
most patronizing kind of way, when printing out plain text was absolutely 
nowhere on the progress toward a solution scale. I've been quite impressed with 
Steven's knowledge and talent, and after fending off the throng of unseeing 
naysayers all afternoon, it was just a little too much. I really should have 
closed my email reader hours before I read and replied to this message. 
Shoulda, coulda, woulda.



> I can assure you that FF prints the string at some point.  It
> may wrap
> it in HTML tags first but printing is what it does.  Also,
> the URLs are
> stored as strings.  SQLite has no URL type.  If it did then it would
> still store it as a string somewhere.  PostGreSQL would let
> you create a
> URL type if you wanted but you would still need to wrap it in quotes
> (single in this case) when you created the entry.

I have no doubt that some variant of printing is involved. Transporting urls to 
the internet is an output process. FF's sqlite implementation does store urls 
as a text field in at least 2 tables. I would be interested in how FF takes 
those text urls and opens web pages with them, although I've learned and 
figured out just today some ways that Python can also do it. Turns out 
clickable links were a red herring.

If Steven's original suggestion included anything but a bare print statement, 
like the use of a special specifier or linking the print statement to some 
module, the use of quoted strings would have at least been worthy of 
consideration. But we all know what print("http://www.wherever.com";) would 
print, and it would be utterly worthless for the purpose at hand. Trying the 
print statement without the quotes was a least a possibility, if there was any 
awareness in the print code of urls and what to do with them. That was the 
whole point of this fishing expedition, as I saw it. To see if there was any 
undocumented or narrowly known-of features in the print code.


> In all the messages in this thread I still don't understand what this
> "teensy advantage" is supposed to be.  Do you want to be able
> to do this:
>
>make_web_link(http://...)
>
> instead of:
>
>make_web_link("http://...";)
>
> --
> D'Arcy J.M. Cain
> System Administrator, Vex.Net
> http://www.Vex.Net/ IM:[email protected]
> VoIP: sip:[email protected]

You probably didn't see my oneliner on the "why do it" part in the swarm of 
messages on this thread yesterday. In it I mentioned that the use would be to 
open urls in the data I'm working with while I'm debugging the code that uses 
them. I want to see what pages they open, without having to leave my IDE. 
(Obviously I'd have to open another .py file, but that would be easier and 
quicker than the alternatives.) I never intended my original question to be any 
more than a frivolous toss out into the sea, to see if anyone knew an answer. I 
was flat out astonished when it blew up into the mini-monster that it did.

Is make_web_link("http://...";) valid python code? That's exactly the kind of 
answer I was loo

Re: Clickable hyperlinks

2017-01-06 Thread Chris Angelico
On Wed, Jan 4, 2017 at 10:43 PM, Deborah Swanson
 wrote:
> I'm quite well aware by now that there is no one-sentence answer to my
> original question, if there's any coherent answer at all. Them's the
> breaks. Live with it or live without it, it doesn't care.

Yeah, there's no simple answer; however, you'll find that Python on many 
platforms is entirely capable of popping a URL up in the user's default 
browser. Check this out:

>>> import antigravity

This uses the 'webbrowser' module, which knows about a number of different ways 
to open a browser, and will attempt them all. So if you can figure out the UI 
part of things, actually making the link pop up in a browser isn't too hard; 
for instance, if you're doing OAuth at the command line and need the user to go 
and authenticate, you can simply webbrowser.open("http://.../";) and it'll 
DTRT.

ChrisA

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


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

2017-01-06 Thread Terry Reedy
On 1/3/2017 10:15 PM, Dennis Lee Bieber wrote:

> And that statement tells us you are trying to run from within some
> IDE/editor which is trapping Python exceptions and producing a dialog
> box for them.

IDLE does this when one runs code from the editor, because it
cannot/should not inject error messages into the editor buffer... AND it 
replaces the ^ with red highlighting of the code pointed to.  No
information is lost.  Apparently, some beginners do not see the connection 
between the SyntaxError box and the red highlighting.  I think I should add 
something to the box.  Maybe 'The error was detected at the point of the red 
highlighting.'

> Instead, save your script (if you haven't yet) as a file
> (whatever.py).
>
> Open a command line interpreter/shell.
>
> Navigate (cd ...) to where you saved the file
>
> Type "python whatever.py"

What a nuisance.

> Copy and paste the results of the CLI/Shell window.

Or one can hit F5 to run the code or Alt-X to just check the syntax. A beginner 
should do this every few lines, and it should be as easy as possible to check.  
If one needs to ask about a syntax error, one can copy the code up and 
including the highlighted part. Example:

"When I run this code in IDLE

def is_same(target, number:
 if

I get a SyntaxError at 'if'."

If the OP had known to do this, the error might have been seen without posting.

--
Terry Jan Reedy

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


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
Deborah - please trim your quoted text.

On 2017-01-04 04:32 AM, Deborah Swanson wrote:
> Thanks, Steven. Yes, of course if you want to print strings you must
> enclose them in quotes. I think you learn that in Week 1 of any
> introductory course on Python.

Closer to minute one.  When I investigated Python years ago the first thing I 
learned was;

  print "Hello, world"

> But we aren't trying to print strings here, the point is to produce
> clickable links. I didn't enclose them with quotes because I didn't see
> any point in printing plain text when I wanted clickable links. I

I'm not sure what your links are composed of but mine all look like sequences 
of characters or "strings."  It sounds like you are trying to make URL a first 
class type like strings. integers, floats, etc.  I can't think of any language 
that treats URLs as first class objects. Even HTML needs quotes:

   http://...";>Go here

> actually didn't understand why you thought I should print them, but it

You want to output them to something.  That often involves printing them to a 
particular handler.

> never would have occurred to me that you wanted me to print out a bunch
> of silly plain text strings, apparently just for the heck of it.

Is that really what you got from his message?

> At this point, if I pursue this any farther, it will be to look into how
> Firefox takes webpage titles and urls out of its sqlite database and
> makes objects you can click on to open the webpages. That's the basic
> technology I'd need to find a way to talk (write) python into doing.

I can assure you that FF prints the string at some point.  It may wrap it in 
HTML tags first but printing is what it does.  Also, the URLs are stored as 
strings.  SQLite has no URL type.  If it did then it would still store it as a 
string somewhere.  PostGreSQL would let you create a URL type if you wanted but 
you would still need to wrap it in quotes
(single in this case) when you created the entry.

> If it's even worth it. On a practical level it's not worth it, way too
> much work for the teensy advantage of having it to use. It might be some
> giggles to figure out how to do it and maybe I will sometime just for
> funsies.

In all the messages in this thread I still don't understand what this "teensy 
advantage" is supposed to be.  Do you want to be able to do this:

   make_web_link(http://...)

instead of:

   make_web_link("http://...";)

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:[email protected] VoIP: sip:[email protected]

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Chris Angelico wrote, on January 04, 2017 4:16 AM
>
> On Wed, Jan 4, 2017 at 10:43 PM, Deborah Swanson
>  wrote:
> > I'm quite well aware by now that there is no one-sentence
> answer to my
> > original question, if there's any coherent answer at all.
> Them's the
> > breaks. Live with it or live without it, it doesn't care.
>
> Yeah, there's no simple answer; however, you'll find that
> Python on many platforms is entirely capable of popping a URL
> up in the user's default browser. Check this out:
>
> >>> import antigravity
>
> This uses the 'webbrowser' module, which knows about a number
> of different ways to open a browser, and will attempt them
> all. So if you can figure out the UI part of things, actually
> making the link pop up in a browser isn't too hard; for
> instance, if you're doing OAuth at the command line and need
> the user to go and authenticate, you can simply
> webbrowser.open("http://.../";) and it'll DTRT.
>

Thank you, thank you! Finally, at least one person on this list knows about 
something (anything) in the python world that is internet aware. It's also 
occurred to me that Beautifulsoup downloads data from a url, so that code must 
have access to some kind of an internet engine too.

I googled antigravity and found a number of interesting links.

The History of Python: import antigravity 
http://python-history.blogspot.com/2010/06/import-antigravity.html

Among other things, it was added to Python 3 in 2010, so it's been around a 
little while. And a comment mentions that "The antigravity module is also 
included in Python 2.7."

And a reddit poster tells us that "if you type 'import antigravity' into a 
Python command line your default browser opens the XKCD comic 'Python' in a 
tab."
https://www.reddit.com/r/ProgrammerHumor/comments/1hvb5n/til_if_you_type
_import_antigravity_into_a_python/

An "import antigravity" video at
https://www.youtube.com/watch?v=_V0V6Rk6Fp4

And its page in the Package Index:
https://pypi.python.org/pypi/antigravity/0.1, with a Page Not Found Error for 
the Home Page. So it doesn't look like there's any alternative but to download 
it and look at the code.

Yes, I'd gotten as far as figuring out that you don't need a clickable link. 
Code that opens a url in a browse would do the job just fine. Or the 
webbrowser.open("http://.../";) in a Linux terminal you suggest. (I just 
have to get my Linux machine up and running again to try it.)

All in all, given that clickable urls in a console is a non-starter, this hits 
the nail on the head. Many thanks again!

Deborah

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


Re: Clickable hyperlinks

2017-01-06 Thread Grant Edwards
On 2017-01-03, Deborah Swanson  wrote:
> 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"?

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

Thanks, that's a bit clearer.  For those of us from the Unix world "console" 
means something else.

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

There is no definition for what a "clickable link" is unless you're sending 
HTML to a web browser.  That means there's no way to create funcationality to 
make one.

--
Grant Edwards   grant.b.edwardsYow! I'm not an Iranian!!
  at   I voted for Dianne
  gmail.comFeinstein!!

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


Re: Clickable hyperlinks

2017-01-06 Thread Grant Edwards
On 2017-01-04, Michael Torrie  wrote:

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

What I have done is defined a window manager root menu entry that opens a web 
browser on the current text selection.  That lets me "click" on a link in any 
application that suport the standard X11 text-selection mechanism (which is 
almost all of them).

>> I was hoping there was some functionality in python to make clickable
>> links. Could be a package, if the core language doesn't have it.
>
> No, there is not.  If you made a full GUI app using a toolkit like
> GTK or Qt, you can indeed place hyperlinks on your forms and the
> operating system will automatically connect them to the web browser.
> But not in text-mode terminal apps.

For me it's double-click to select the url in the terminal window or PDF viewer 
or whaterver, then right-click on the root window and pick
the menu entry that says 'Firefox [sel]' or 'Chrome [sel]'.  It's a few extra 
steps, but it works for almostly any application that displays text.

--
Grant Edwards   grant.b.edwardsYow! Where do your SOCKS
  at   go when you lose them in
  gmail.comth' WASHER?

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


Re: Clickable hyperlinks

2017-01-06 Thread Terry Reedy
On 1/4/2017 4:32 AM, Deborah Swanson wrote:

> My original question was whether python had anything to provide this
> functionality, and the answer appears to be a resounding NO!!!

I would say 'Yes, but with user effort'.

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.

* If the software directly recognizes a bare url such as
'http://www.example.com' as a link, without further indication, then it
should have a way to disable conversion to a clickable link.

--
Terry Jan Reedy

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


Re: Clickable hyperlinks

2017-01-06 Thread Chris Angelico
On Thu, Jan 5, 2017 at 9:58 AM, Deborah Swanson
 wrote:
> Chris Angelico wrote, on January 04, 2017 4:16 AM
>> This uses the 'webbrowser' module, which knows about a number
>> of different ways to open a browser, and will attempt them
>> all. So if you can figure out the UI part of things, actually
>> making the link pop up in a browser isn't too hard; for
>> instance, if you're doing OAuth at the command line and need
>> the user to go and authenticate, you can simply
>> webbrowser.open("http://.../";) and it'll DTRT.
>>
>
> Thank you, thank you! Finally, at least one person on this list knows
> about something (anything) in the python world that is internet aware.
> It's also occurred to me that Beautifulsoup downloads data from a url,
> so that code must have access to some kind of an internet engine too.

We've been all talking at cross purposes a bit in this thread. Most of us 
thought you were talking about the *user interface* of a clickable link, but if 
you're talking about the *mechanics* of HTTP downloads, Python has excellent 
facilities. I'd recommend checking out the third-party 'requests' module on 
PyPI.

> I googled antigravity and found a number of interesting links.
>
> The History of Python: import antigravity
> http://python-history.blogspot.com/2010/06/import-antigravity.html
>
> Among other things, it was added to Python 3 in 2010, so it's been
> around a little while. And a comment mentions that "The antigravity
> module is also included in Python 2.7."
>
> And a reddit poster tells us that "if you type 'import antigravity' into
> a Python command line your default browser opens the XKCD comic 'Python'
> in a tab."
> https://www.reddit.com/r/ProgrammerHumor/comments/1hvb5n/til_if_you_type
> _import_antigravity_into_a_python/
>
> An "import antigravity" video at
> https://www.youtube.com/watch?v=_V0V6Rk6Fp4

Hehe, yeah. It's a big joke that started because XKCD mentioned the language. 
But actually, the source code for antigravity.py itself isn't significant; all 
it does is call on the webbrowser module:

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

> Yes, I'd gotten as far as figuring out that you don't need a clickable
> link. Code that opens a url in a browse would do the job just fine. Or
> the webbrowser.open("http://.../";) in a Linux terminal you suggest.
> (I just have to get my Linux machine up and running again to try it.)
>
> All in all, given that clickable urls in a console is a non-starter,
> this hits the nail on the head. Many thanks again!

Cool! Glad I could help out a bit. There are a few different things you can 
consider:

1) Open up a browser tab and let the user see the result 2) Make the request 
programmatically and access the text of the page for further processing
3) Invoke a hidden web browser, browse to a URL, submit form data, etc, as a 
means of testing a web server.

All three are possible. Take your pick!

ChrisA

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


Work between multiple processes

2017-01-06 Thread zxpatric
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.

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Hans-Peter Jansen
On Montag, 2. Januar 2017 03:38:53 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.

Well, since nobody mentioned it, yet: eric is doing quite nice here. With on 
the fly error checking, jedi and qscintilla calltips and autocompletion, git 
integration (using a plugin), graphical debugger, it's grown to a capable IDE 
over the years.

Given, it's a fully open source, PyQt based project, it also shows the powers 
of Python3 and PyQt.

Pete

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Dietmar Schwertberger
On 04.01.2017 15:41, William Ray Wing wrote:
> I use Wing, and I think you will like it.  It *is* pythonic, and for what it
is worth, offers remote debugging as one of its more recently added features. 
Obviously, you had no other choice than using Wing ;-)

The remote debugging has been around for some years. I have been using it quite 
often to debug on my Raspberry Pi, Nokia N900 and Jolla Phone, all running some 
Linux system. It works well. It is or was a bit complicated to set up. I think 
this has been improved with Wing 6, but I did not need it in the last weeks, so 
I don't know.

Regards,

Dietmar

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


Re: Clickable hyperlinks

2017-01-06 Thread Rustom Mody
This thread does lead to the question: Is the Url type in python less 
first-class than it could be?

In scheme I could point to something like this 
https://docs.racket-lang.org/net/url.html

Is there something equivalent in python?

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do

2017-01-06 Thread William Ray Wing

> On Jan 4, 2017, at 3:44 PM, Dietmar Schwertberger 
wrote:
>
> On 04.01.2017 15:41, William Ray Wing wrote:
>> I use Wing, and I think you will like it.  It *is* pythonic, and for what it
is worth, offers remote debugging as one of its more recently added features.
> Obviously, you had no other choice than using Wing ;-)

I should have said something.  First, and to the best of my knowledge, I have 
no relationship with the Wing developers other than being a satisfied customer. 
Second, seven years ago, when I was reading IDE reviews and testing the more 
highly rated products, Wing just bubbled up to the top of the sieve I was using 
(features, ease of use, and the way it fit my idea of â £naturalâ Ø, pretty 
much everyone's standard list).

>
> The remote debugging has been around for some years. I have been using it
quite often to debug on my Raspberry Pi, Nokia N900 and Jolla Phone, all 
running some Linux system. It works well. It is or was a bit complicated to set 
up. I think this has been improved with Wing 6, but I did not need it in the 
last weeks, so I don't know.

They claim it has been, but like you, I havenâ Öt had need to test it on the 
new release.

Thanks,
Bill

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

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Dietmar Schwertberger
On 04.01.2017 07:54, Antonio Caminero Garcia wrote:
> Unfortunately most of the time I am still using print and input functions. I
know that sucks, I did not use the pdb module, I guess that IDE debuggers 
leverage such module.
pdb is actually quite useful. On my Windows PCs I can invoke python on any .py 
file with the -i command line switch by right clicking in the Explorer and 
selecting "Debug". Now when the script crashes, I can inspect variables without 
launching a full-scale IDE or starting the script from the command line. For 
such quick fixes I have also a context menu entry "Edit" for editing with 
Pythonwin, which is still quite OK as editor and has no licensing restrictions 
or installation requirements. This is a nice option when you deploy your 
installation to many PCs over the network.

For the print functions vs. debugger: The most useful application for a 
debugger like Wing is not for bug-fixing, but to set a break point and then 
interactively develop on the debugger console and with the IDE editor's 
autocompletion using introspection on the live objects. This is very helpful 
for hardware interfacing, network protocols or GUI programs. It really boosted 
my productivity in a way I could not believe before. This is something most 
people forget when they evaluate programming languages. It's not the language 
or syntax that counts, but the overall environment. Probably the only other 
really interactive language and environment is Forth.

> If it happens to be Arduino I normally use a sublime plugin called Stino
> https://github.com/Robot-Will/Stino
> (1337 people starred that cool number :D)
Well, it is CodeWarrior which was quite famous at the time of the 68k Macs. The 
company was bought by Motorola and the IDE is still around for 
Freescale/NXP/Qualcomm microcontrollers like the HCS08 8 bit series. Around ten 
years ago the original CodeWarrior IDE was migrated to something Eclipse based.
When I last evaluated HCS08 vs. Arduino, the HCS08 won due to the better debug 
interface and native USB support. HCS08 is still quite cool, but when it comes 
to documentation, learning curve, tools etc. the Arduinos win


Regards,

Dietmar

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


RE: Clickable hyperlinks

2017-01-06 Thread Deborah Swanson
Chris Angelico wrote, on January 04, 2017 4:16 AM
>
> Yeah, there's no simple answer; however, you'll find that
> Python on many platforms is entirely capable of popping a URL
> up in the user's default browser. Check this out:
>
> >>> import antigravity

I downloaded the code from the Package Index, but there really wasn't much in 
it. This is the entire .py file:

STRIP_URL = "http://xkcd.com/353/";

def start():
return STRIP_URL

And setup.py is equally disappointing: from distutils.core import setup

setup(
name='antigravity',
version='0.1',
description='A really simple module that allow everyone to do
"import antigravity"',
author='Fabien Schwob',
author_email='[email protected]',
url='http://fabien.schwob.org/antigravity/',
packages=['antigravity'],
)

> This uses the 'webbrowser' module, which knows about a number
> of different ways to open a browser, and will attempt them
> all. So if you can figure out the UI part of things, actually
> making the link pop up in a browser isn't too hard; for
> instance, if you're doing OAuth at the command line and need
> the user to go and authenticate, you can simply
> webbrowser.open("http://.../";) and it'll DTRT.
>
> ChrisA

All the action of antigravity must be done by the import statement. When import 
opens a module that immediately returns a url, it must have a mechanism to open 
it in a browser.

It would be very easy to do the same thing with my own .py and import it into 
another .py.

Or, take a look at import's code and figure out how it opens a url in a 
browser. I imagine it's the 'webbrowser' module you mention. If it tries 
several methods, just pick one that will work for you.

Or, take a look at this Index of Packages Matching 'webbrowser' (~50 packages)
https://pypi.python.org/pypi?%3Aaction=search&term=webbrowser&submit=sea
rch

D'Arcy was right, there's lots in python that's internet aware, though that 
wasn't the question I knew to ask.

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


Re: Clickable hyperlinks

2017-01-06 Thread Michael Torrie
On 01/04/2017 03:58 PM, Deborah Swanson wrote:
> Thank you, thank you! Finally, at least one person on this list knows
> about something (anything) in the python world that is internet aware.
> It's also occurred to me that Beautifulsoup downloads data from a url,
> so that code must have access to some kind of an internet engine too.

Except that you never mentioned anything about this in your posts before. It 
seemed to me you were asking about printing out clickable hyperlinks with 
python.  Calling the OS to launch a browser to view a url is a different beast 
which is why no one mentioned it before.

If you don't tell us what you're actually trying to do (your end goal), things 
are more frustrating for everyone.  If you had said early on you just want to 
be able to send the user to a particular url in a web browser, what Chris 
suggested would have been said a long time ago, rather than focusing on console 
output which is what you were asking about and focusing attention on.

Just so you know, BeautifulSoup does not do any internet access itself; it's 
only an HTML parser. You have to fetch web pages using something like python's 
urllib and then feed the data to BeautifulSoup.  urllib is not a web browser 
though.  It can pretend to be a browser as far as the server is concerned but 
it knows nothing about javascript or rendering. It just retrieves bytes which 
you can then feed to BeautifulSoup or some other parser.

> Yes, I'd gotten as far as figuring out that you don't need a clickable
> link. Code that opens a url in a browse would do the job just fine.

Good! I just wish you would have mentioned this much earlier as your end goal.

> Or the webbrowser.open("http://.../";) in a Linux terminal you suggest.
> (I just have to get my Linux machine up and running again to try it.)

The webbrowser module does not require console or terminal output. It will work 
on Windows or Linux if I'm not mistaken.  It asks the OS to launch the default 
browser and load the indicated url.

> All in all, given that clickable urls in a console is a non-starter,
> this hits the nail on the head. Many thanks again!

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


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

2017-01-06 Thread Steven D'Aprano
On Thursday 05 January 2017 10:21, Terry Reedy wrote:

> On 1/3/2017 10:15 PM, Dennis Lee Bieber wrote:
>
>> And that statement tells us you are trying to run from within some
>> IDE/editor which is trapping Python exceptions and producing a dialog
>> box for them.
>
> IDLE does this when one runs code from the editor, because it
> cannot/should not inject error messages into the editor buffer...
> AND it replaces the ^ with red highlighting of the code pointed to.  No
> information is lost.  Apparently, some beginners do not see the
> connection between the SyntaxError box and the red highlighting.

Some people may not even be able to distinguish red from other colours. Those 
with red-green colourblindness will probably see the red as a sort of muddy 
brown that hardly stands out as different from usual black text.

http://wearecolorblind.com/

One should never use colour alone as the only indicator of status.

http://stackoverflow.com/questions/1498669/gui-design-for-color-blindness

http://davemeeker.com/color-blind-considerations-for-ui-design/


> I
> think I should add something to the box.  Maybe 'The error was detected
> at the point of the red highlighting.'


I just tested the REPL in idle for 2.7.4, and I get this:

>>> print Hello World
SyntaxError: invalid syntax


where "print" is green text on a white background, and "World" is black text on 
a red background. That may be unfriendly to the colourblind, and makes coping 
and pasting the error less helpful. I suggest:

- check the colours in a colourblindness simulator, and pay attention to the
contrast; is the text still clear?

- include the ^ caret as the primary status indicator, delegating colour to
secondary; this makes errors in IDLE a little more like the same experience in 
the standard REPL.


If I open a Python file containing:

print Hello World

and choose "Check Module", IDLE highlights the word "World" in red and displays 
a dialog showing:

There's an error in your program:
invalid syntax

Suggestion:

Change the dialog box to display a read-only text field showing the traceback:

  File "idletest.py", line 1
print Hello World
^
SyntaxError: invalid syntax


and add a button "Copy traceback" to allow the user to copy the text of the 
traceback and paste it into an email.

(Strictly speaking, the Copy button is redundant if the user can select the 
text in the field, but beginners may not realise the text can be selected.)



>> Instead, save your script (if you haven't yet) as a file
>> (whatever.py).
>>
>> Open a command line interpreter/shell.
>>
>> Navigate (cd ...) to where you saved the file
>>
>> Type "python whatever.py"
>
> What a nuisance.

*shrug* If you're a Linux user, chances are you already have a shell open and
ready to go. And with tab completion, you don't have to type as much as you 
might think. It just becomes second nature after a while.

I type something like "pypathwhat" and the shell will 
autocomplete directory and filenames.

Anyway, this isn't an argument over which is better, IDLE or the system 
terminal. They both have their advantages and disadvantages, and in practice 
the real answer to "which is better?" is always "whichever one you are used 
to".



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

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


Re: Python for WEB-page !?

2017-01-06 Thread Ionut Predoiu
Good morning,

Thanks to all for feedback and advice.
Because I am a beginner I will read more about versions of Python recommended 
by you.

On the other side I am interested to know if exist some sites which have 
develop platform where can be use for free Python from browsers, without have 
it installed on PC/laptop. As beginner I want to practice from everywhere.

I waiting with higher interest your feedback. 

Thanks to all members of community for support and advice. 
Keep in touch. 
Kind regards. 



On Thursday, January 5, 2017 at 2:57:23 PM UTC+2, 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.
> 
> 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


MySQL schema sync or diff

2017-01-06 Thread Charles Heizer
Hello,
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?

Thanks!

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


Re: Clickable hyperlinks

2017-01-06 Thread Dennis Lee Bieber
On Wed, 4 Jan 2017 14:58:42 -0800, "Deborah Swanson"
 declaimed the following:

>Thank you, thank you! Finally, at least one person on this list knows
>about something (anything) in the python world that is internet aware.
>It's also occurred to me that Beautifulsoup downloads data from a url,
>so that code must have access to some kind of an internet engine too.
>

Uhm... There is a big difference between "clickable links" and
"internet aware".

Look at the Library reference manual. There is a section on "Internet
Data Handling", and another on "Internet Protocols and Support". For just 
retrieving things identified by a URL, there are both urllib and urllib2; and 
for more specific there is httplib, ftplib, poplib, etc.


Clickable links is a user interface matter -- and as mentioned numerous
times, depends upon the features of the interface, not of Python (unless you 
are writing a full-fledged GUI application in which case you have to tag 
entities as clickable and handle the user clicking on that entity, followed by 
actually using one of the above library routines to fetch the contents at the 
clickable's target)

--
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.home.netcom.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-06 Thread Antonio Caminero Garcia
On Thursday, January 5, 2017 at 12:32:19 PM UTC-8, fpp wrote:
> > 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

Interesting thanks for the link. There are a huge diversity when it comes to 
IDEs/editors. Now I have more than enough options. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
On 2017-01-04 05:58 PM, Deborah Swanson wrote:
>> the user to go and authenticate, you can simply
>> webbrowser.open("http://.../";) and it'll DTRT.
>
> Thank you, thank you! Finally, at least one person on this list knows
> about something (anything) in the python world that is internet aware.

Lots of things in Python are Internet aware.  That's not the question you asked 
though.

> It's also occurred to me that Beautifulsoup downloads data from a url,
> so that code must have access to some kind of an internet engine too.

Nope.  You have to feed it HTML.  You either need to generate that or capture 
it from somewhere.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:[email protected] VoIP: sip:[email protected]

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


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

2017-01-06 Thread H Krishnan
Hello Mr.Eryk,

Thanks for the detailed explanation. After I added attribute support to my
extension class for stdio, the problem was resolved.

Regards,
Krishnan


On Fri, Jan 6, 2017 at 9:24 AM, eryk sun  wrote:

> 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
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
On 2017-01-04 07:07 PM, Deborah Swanson wrote:
> D'Arcy Cain wrote, on Wednesday, January 04, 2017 5:03 AM
>> In all the messages in this thread I still don't understand what this
>> "teensy advantage" is supposed to be.  Do you want to be able
>> to do this:
>>
>>make_web_link(http://...)
>>
>> instead of:
>>
>>make_web_link("http://...";)

[...]

> Is make_web_link("http://...";) valid python code? That's exactly the

It's just a made up name.  My point was that the first was syntactically 
incorrect and the second, while not a real method, was at least parseable.

I think I saw someone else mention this but it bears repeating.  When you ask a 
question make sure you are presenting the problem and not your solution to a 
secret problem.  Always tell us the actual problem you are trying to solve.  
You will get much better answers.

Think of it this way.  You drop a ring down a drain.  You can ask two 
questions, "How do I remove a drain trap?" or "How do I recover a ring that I 
dropped down the drain?"  If you ask the first question you will get lots of 
advice on tools and buckets, etc.  People will assume that the drain is 
blocked.  Ask the second question and someone might mention a magnet and a 
piece of string.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:[email protected] VoIP: sip:[email protected]

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


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

2017-01-06 Thread Sayth Renshaw
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?

Cheers

Sayth

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


Receiving a lot of double messages.

2017-01-06 Thread Antoon Pardon
Is there something going on with the mailinglist? Because I have receive
a lot of double messages. One copy is fairly normal and is part of the
discussion thread, the other is completely seperated. -- Antoon Pardon.

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


Re: Clickable hyperlinks

2017-01-06 Thread Chris Angelico
On Thu, Jan 5, 2017 at 2:24 PM, D'Arcy Cain  wrote:
> Think of it this way.  You drop a ring down a drain.  You can ask two
> questions, "How do I remove a drain trap?" or "How do I recover a ring that
> I dropped down the drain?"  If you ask the first question you will get lots
> of advice on tools and buckets, etc.  People will assume that the drain is
> blocked.  Ask the second question and someone might mention a magnet and a
> piece of string.

... and then you follow up with "it's a gold ring, magnet won't touch it", and 
we'll go off on a tangent about whether the ring is sufficiently plain that it 
might be the One Ring, and shouldn't you destroy it instead of retrieving 
it because that's what we do here
:D

ChrisA

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


  1   2   >