Re: [Tutor] Interactive editing of variables.

2019-06-04 Thread Steven D'Aprano
Hi Sean,

On Sat, Jun 01, 2019 at 12:53:00PM +1000, mhysnm1...@gmail.com wrote:
> I have had a look and cannot find an example where I can interactively edit
> a content of a variable at the command line. I do not want to use GUI at
> all. As this is a simple program only requiring CLI. I have no problems
> showing the prompt, but cannot insert text into the edit (input) area. Any
> ideas?

Let me see if I understand what you are asking for.

The built-in function "input()" takes one argument, the prompt, and lets 
the user type a response. So if I run the function:

input("What is your name?")

the terminal will display the prompt, and put the text cursor next to 
it. That is how things work now.

I think what you are asking for is the ability to pass a second argument 
to the function, like this:

input("What is your name?", "George")

and the terminal will display the prompt, then place the word "George" 
next to the prompt in the edit-zone. The user (you) can then backspace 
over the word and type something new, or otherwise edit it.

Is that what you want?

If so, then on Linux or Unix systems, you can do this:


import readline

def myinput(prompt='', initial=''):
readline.set_startup_hook(lambda: readline.insert_text(initial))
try:
response = input(prompt)
finally:
readline.set_startup_hook(None)
return response


The bad news is that this only works on Linux and other Unix systems 
with readline installed (which nearly all of them do). It won't work 
under Windows.

But if you install the third-party library pyreadline, you *may* be able 
to use that instead:

import pyreadline as readline

and the rest might work. (I don't have Windows and can't try it.)


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interactive editing of variables.

2019-06-04 Thread Mats Wichmann
On 6/4/19 2:49 AM, Steven D'Aprano wrote:

> The bad news is that this only works on Linux and other Unix systems 
> with readline installed (which nearly all of them do). It won't work 
> under Windows.
> 
> But if you install the third-party library pyreadline, you *may* be able 
> to use that instead:
> 
> import pyreadline as readline
> 
> and the rest might work. (I don't have Windows and can't try it.)

you don't need to change code, the installation of pyreadline also adds
a stub so that "import readline" works.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fw: Download issues for Python

2019-06-04 Thread tom milikic


Hi my name is Tom and I come from Brisbane in Australia.  I cannot seem to 
download Python on my computer as I really need it to help with my Quantitative 
Finance studies.  It seems to say that some program is missing from my 
computer?  What do I do? I am running Windows and a Toshiba computer. I have 
looked in the help section and I still cant seem to fix or find the issue with 
why it is not downloading onto my computer?

It states that this is missing from my computer -:

api-ms-win-crt-runtime-l1-1-0.dl

Also Python 3.7.2 and Python 3.7.3 appear in my download folders but when I 
click them nothing happens?

If you can help would be much appreciated

Thanks
Tom


[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
  Virus-free. 
www.avast.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fw: Download issues for Python

2019-06-04 Thread Grant Edwards
On 2019-06-04, tom milikic  wrote:

> [...]
>
> It states that this is missing from my computer -:
>
> api-ms-win-crt-runtime-l1-1-0.dl

[You left off the second 'l'.  Precision is very important when dealing with 
software problems.]

You can often the answer just by Googling the error message:

  
https://www.google.com/search?q=python+install+missing+api-ms-win-crt-runtime-l1-1-0.dll&oq=python+install+missing+api-ms-win-crt-runtime-l1-1-0.dll

-- 
Grant Edwards   grant.b.edwardsYow! I'm thinking about
  at   DIGITAL READ-OUT systems
  gmail.comand computer-generated
   IMAGE FORMATIONS ...

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] would someone please explain this concept to me

2019-06-04 Thread nathan tech
Hi there,

So I have just fixed a huge bug in my program, but don't understand 
exactly... How it bugged.

Confused?

I sure was.

Here's some code:

globals.py:

feeds={}

blank_feed={}

blank_feed["checked"]=1

blank_feed["feed"]=0


main file:

import globals as g

# some code that loads a feed into the variable knm

g.feeds[link]=g.blank_feed;

g.feeds[link]["feed"]=knm

#in the below code, the variable link has a different value:

# load a feed into the variable r

g.feeds[link]=g.blank_feed

g.feeds[link]["feed"]=r


Now at this point, python would set the first loaded feed to the same 
thing as the second loaded feed. It also set g.blank_feed to the second 
feed, as well.

I replaced the last three lines with this:

# load a feed into the variable r

g.feeds[link]=g.blank_feed;

g.feeds[link]["feed"]=r

And it works.

but why does it work?

Why does that semi unlink all the variables?

Thanks

Nathan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] would someone please explain this concept to me

2019-06-04 Thread Alan Gauld via Tutor
On 05/06/2019 00:37, nathan tech wrote:
> Hi there,
> 
> So I have just fixed a huge bug in my program, but don't understand 
> exactly... How it bugged.

Neither do I, your explanation raises more questions than answers.

> globals.py:
> feeds={}
> blank_feed={}
> blank_feed["checked"]=1
> blank_feed["feed"]=0
> 
> 
> main file:
> 
> import globals as g
> # some code that loads a feed into the variable knm

Your terminology is odd here.
You are not loading anything into knm, rather you are assigning
the value of knm to the "feed" dictionary entry.

> g.feeds[link]=g.blank_feed;
> g.feeds[link]["feed"]=knm
> 
> #in the below code, the variable link has a different value:
> 
> # load a feed into the variable r

Similarly this assigns the value of r to the "feed" entry - the
same "feed" entry as for knm so you have now overwritten the
knm value in the dictionary..

> g.feeds[link]=g.blank_feed
> g.feeds[link]["feed"]=r

> Now at this point, python would set the first loaded feed to the same 
> thing as the second loaded feed. It also set g.blank_feed to the second 
> feed, as well.

Sorry, I have no idea what you mean by that.
Which is the "first loaded feed"? knm?, r or the feeds dictionary?
And what is the "second loaded feed"?
What do you mean by a "feed" in this context?

You are setting g.feeds[link] to g.blank_feed in both cases.
Your line

g.feeds[link]["feed"]=r

is exactly the same as if you typed

g.blank_feed["feed"]=r

If you set the knm and r variables to fixed integer values
(say 42 and 666) that would allow you to tell us what
variable has what value. And what you expected them to store.
(The fact that knm and r may normally contain some other
kind of object is not relevant to this question.)

> I replaced the last three lines with this:
> 
> # load a feed into the variable r
> g.feeds[link]=g.blank_feed;
> g.feeds[link]["feed"]=r
> 
> And it works.

What works? What is different?
I still don't know what you think should be happening,
what is happening first time round, and what is now happening.

> but why does it work?
> 
> Why does that semi unlink all the variables?

The semicolon should not "unlink all variables", whatever
that means. But I have no idea what you are seeing so
cannot comment any further. You need to give us more specifics.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] would someone please explain this concept to me

2019-06-04 Thread Steven D'Aprano
On Tue, Jun 04, 2019 at 11:37:23PM +, nathan tech wrote:

> globals.py:
> 
> feeds={}
> blank_feed={}
> blank_feed["checked"]=1
> blank_feed["feed"]=0

That is more easily, and better, written as:

feeds = {}
blank_feed = {"checked": 1, "feed": 0}


> main file:
> 
> import globals as g
> # some code that loads a feed into the variable knm

Do you mean something like this? If so, you should say so.

knm = "some feed"


> g.feeds[link]=g.blank_feed;

What's "link" here? And there is no need for the semi-colon.

> g.feeds[link]["feed"]=knm

Right... what the above line does is *precisely* the same as 

g.blank_feed["feed"] = knm

Follow the program logic. I'm inserting 1970s BASIC style line numbers 
to make it easier to discuss the code, remember that you can't actually 
do that in Python.

10: g.feeds[link] = g.blank_feed
20: g.feeds[link]["feed"] = knm

Line 10 sets g.feeds[link] to the dict "blank_feed". *Not* a copy: you 
now have two ways of referring to the same dict:

"g.blank_feed" and "g.feeds[link]"

both refer to the one dict, just as "Nathan" and "Mr Tech" are two ways 
of referring to the same person (you).

So line 20 does this:

- look for the name "g", which gives the "globals.py" module;

- inside that module, look for the name "feeds", which gives
  the "feeds" dict;

- look inside that dict for the key "link" (whatever value
  that currently holds), which by line 10 has been set to
  the same dict "blank_feed".

- inside the blank_feed dict, set key "feed" to "knm".



> #in the below code, the variable link has a different value:
> # load a feed into the variable r

Something like this?

r = "a different feed"

> g.feeds[link]=g.blank_feed

Now you have *three* ways of naming the same dict:

"g.blank_feed", "g.feeds[link]", "g.feeds[different_link]"

but they all point to the same dict.

> g.feeds[link]["feed"]=r
> 
> 
> Now at this point, python would set the first loaded feed to the same 
> thing as the second loaded feed. It also set g.blank_feed to the second 
> feed, as well.

No, there is only one feed in total. You just keep updating the same 
feed under different names.


> I replaced the last three lines with this:
> 
> # load a feed into the variable r
> g.feeds[link]=g.blank_feed;
> g.feeds[link]["feed"]=r
> 
> And it works.

I don't see any difference between the replacement code and the original 
code. The code you show does exactly the same thing.


> but why does it work?
> 
> Why does that semi unlink all the variables?

Semi-colon?

It doesn't. You must have made other changes as well, semi-colons don't 
have any runtime effect. They are *purely* syntax to tell the parser to 
seperate multiple statements on one line.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] would someone please explain this concept to me

2019-06-04 Thread Steven D'Aprano
In case you are still confused, we can simplify the whole process by 
eliminating the unnecessary use of an external module.

blank = {}
feeds = {}

feeds['a'] = blank
feeds['a'][1] = "Hello"

print(blank)
# will print {1: 'Hello'}

We can see that the dict named "blank" and the dict named "feeds['a']" 
are actually the same dict:

print(feeds['a'] is blank)  # Not the same as == (equals).

In case you still need more evidence:

feeds['b'] = blank
feeds['b'][1] = "Goodbye"
print(blank)
print(feeds)

will print:

{1: 'Goodbye'}
{'a': {1: 'Goodbye'}, 'b': {1: 'Goodbye'}}


(possibly the a and the b will be swapped around).



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor