Re: [Tutor] Coding

2014-12-08 Thread Danny Yoo
On Mon, Dec 8, 2014 at 3:06 PM, Awais Idris <2010-3...@slougheton.com> wrote:
> The problem is when i enter my first choice it accepts it fine and well.
> When it says would you like a second item, andi say yes it listd the options
> and says have a good day and the program cuts off. In wondering if this is a
> problem with the statements?

Hi Awais,

Yes, there is a problem that we can see.  Look for Alan and Stephen's
responses in your email inbox.  They should explain what's going on,
and how to correct the bug.  Can you confirm that you're getting these
emails from them?


You can also see these responses if you look at the email archive.


Your question:

 https://mail.python.org/pipermail/tutor/2014-December/103581.html

and the responses:

https://mail.python.org/pipermail/tutor/2014-December/103584.html
https://mail.python.org/pipermail/tutor/2014-December/103586.html
https://mail.python.org/pipermail/tutor/2014-December/103588.html
https://mail.python.org/pipermail/tutor/2014-December/103590.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coding

2014-12-08 Thread Awais Idris
Ok thank you i appreciate your help

On Monday, 8 December 2014, Danny Yoo  wrote:

> On Mon, Dec 8, 2014 at 12:14 PM, Awais Idris <2010-3...@slougheton.com
> > wrote:
> > The problem is when i enter my first choice it accepts it fine and well.
> > When it says would you like a second item, andi say yes it listd the
> options
> > and says have a good day and the program cuts off. In wondering if this
> is a
> > problem with the loops?
> >
>
> Please use Reply to All on this mailing list, so that all of us here
> can help respond.  I have a day job, so sometimes I actually have to
> do something other than answer email.  :P
>
> From your description, it sounds like you should look at the
> *conditions* in your if statements, because they aren't branching in a
> way that you want.  Other replies to your thread should point out
> things you want to look at.  Read all the replies, and start asking
> questions when you hit something you don't understand.  This is a
> conversation: we'll listen to what you're saying.
>
>
> Also, be careful about what terms you are using.  You are using the
> term "loop", and have done so repeatedly, but there are no loops in
> your program, as Alan has pointed out earlier.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coding

2014-12-08 Thread Danny Yoo
On Mon, Dec 8, 2014 at 12:14 PM, Awais Idris <2010-3...@slougheton.com> wrote:
> The problem is when i enter my first choice it accepts it fine and well.
> When it says would you like a second item, andi say yes it listd the options
> and says have a good day and the program cuts off. In wondering if this is a
> problem with the loops?
>

Please use Reply to All on this mailing list, so that all of us here
can help respond.  I have a day job, so sometimes I actually have to
do something other than answer email.  :P

>From your description, it sounds like you should look at the
*conditions* in your if statements, because they aren't branching in a
way that you want.  Other replies to your thread should point out
things you want to look at.  Read all the replies, and start asking
questions when you hit something you don't understand.  This is a
conversation: we'll listen to what you're saying.


Also, be careful about what terms you are using.  You are using the
term "loop", and have done so repeatedly, but there are no loops in
your program, as Alan has pointed out earlier.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Plotting subsets of data

2014-12-08 Thread Colin Ross
Perfect, thank you Danny!

On Mon, Dec 8, 2014 at 3:49 PM, Danny Yoo  wrote:

> On Mon, Dec 8, 2014 at 7:48 AM, Colin Ross 
> wrote:
> > Good afternoon,
> >
> > I am using the following to code to plot the output from an optical
> encoder:
>
> Hi Colin,
>
> Matplotlib is a third-party library, so you may also consider asking
> the matplotlib folks.
>
> From a brief look at:
>
>
> http://matplotlib.org/1.4.2/users/pyplot_tutorial.html#working-with-multiple-figures-and-axes
>
> it appears that you can override the default axis, and specify xmin,
> ymin, xmax, and ymax values.
>
> http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.axis
>
> For your particular case, you may want to just limit your x axis, in
> which case xlim() might be appropriate.
>
> http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.xlim
>
>
> If all else fails, just filter your data before submitting it to the
> grapher.  The program loads data here, using loadtxt
> (http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html):
>
> data = np.loadtxt('2014_12_04-16_30_03.txt',skiprows = 0 ,usecols =
> (0,1))
>
> and it's just a numpy array: you can manipulate numpy arrays.   See:
>
>
> http://stackoverflow.com/questions/26154711/filter-rows-of-a-numpy-array
>
> as an example of an approach.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Plotting subsets of data

2014-12-08 Thread Danny Yoo
On Mon, Dec 8, 2014 at 7:48 AM, Colin Ross  wrote:
> Good afternoon,
>
> I am using the following to code to plot the output from an optical encoder:

Hi Colin,

Matplotlib is a third-party library, so you may also consider asking
the matplotlib folks.

>From a brief look at:


http://matplotlib.org/1.4.2/users/pyplot_tutorial.html#working-with-multiple-figures-and-axes

it appears that you can override the default axis, and specify xmin,
ymin, xmax, and ymax values.

http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.axis

For your particular case, you may want to just limit your x axis, in
which case xlim() might be appropriate.

http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.xlim


If all else fails, just filter your data before submitting it to the
grapher.  The program loads data here, using loadtxt
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html):

data = np.loadtxt('2014_12_04-16_30_03.txt',skiprows = 0 ,usecols = (0,1))

and it's just a numpy array: you can manipulate numpy arrays.   See:

http://stackoverflow.com/questions/26154711/filter-rows-of-a-numpy-array

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


[Tutor] Plotting subsets of data

2014-12-08 Thread Colin Ross
Good afternoon,

I am using the following to code to plot the output from an optical encoder:

import numpy as np
from numpy import ma, logical_or
import pylab
from pylab import *
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator
import sys

# Defining x and y minorlocator

xminorLocator=AutoMinorLocator()
yminorLocator=AutoMinorLocator()

# Load data from .txt file

data = np.loadtxt('2014_12_04-16_30_03.txt',skiprows = 0 ,usecols = (0,1))

print "\n Chopper Test for X-SPEC Prototype"
print "\n  Time (sec) Pos (deg)"
print data

# Place column data in array to be plotted

time = np.array(data[:,0])
print "Time (sec):"
#print time

pos = np.array(data[:,1])
print "Position (deg):"
print pos

# Setting minor ticks

ax = plt.subplot(111)
ax.xaxis.set_minor_locator(xminorLocator)
ax.yaxis.set_minor_locator(yminorLocator)

#Plotting commands.

subplot(2,1,1)
plot(time, pos, 'ro')
title('Encoder Output')
ylabel('Pos (deg)')

subplot(2,1,2)
plot(t_small, pos, 'ro')
xlabel('Time (sec)')
ylabel('Pos (deg)')

show()

The desired result is a square wave, but this is not readily available from
the plot (see attached). For the subplot(2,1,2) I would like to plot the
output over a 5 second interval so that the behaviour becomes more evident.
Can someone please advise me as to the easiest way isolate the first 5
seconds of data?

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


Re: [Tutor] getting input for stdin

2014-12-08 Thread Alan Gauld



On 08/12/14 03:50, diliup gabadamudalige wrote:

I managed to get the output file and input file working.
The output works fine but the input does not. It simply exits the
program. No crash. Exits.It DOES NOT WAIT FOR ME TO TYPE IN THE
inputfile.txt


Can you show us what your input file looks like?


if __name__ == '__main__':
## menna me kaalla to change the output path
p = os.getcwd()
outfile = "\output_file.txt"
infile = "\input_file.txt"


One point, you probably should make these raw strings otherwise the 
first character may get interpreted as a specioal one due to the back slash:


   infile = r"\input_file.txt"

I assume you are running on Windows?
And you use the \ as a path specifier?


outfilepath = p + outfile
infilepath = p + infile


You should use os.path.join to do this safely and portably.


sys.stdout = open(outfilepath, "w+")
sys.stdin = open(infilepath, "w+")


You probably should make the input have read mode.
Using 'w+' for an input is not usually what you want.


os.startfile(outfilepath)
os.startfile(infilepath)


What do you think this does? I suspect it starts a
copy of Notepad running? Is that right? Any changes in the files
will not be reflected in Notepad, and any changes in Notepad
will not be reflected in the files until the user saves the file.

However you may also have problems opening the files since the
OS should have put a lock on them when Python opened them in
write mode.


run = True
while run:
scaletemplate = ["C", "D", "E", "F", "G", "A", "B"]
getscale = sys.stdin.readline()
raw_input("Which scale do you require?:")


I suspect the prompt will get printed on the console (using stderr)
but you are not assigning the return value (from infile.txt) to anything 
so it will get lost.


I suspect you want to reverse those lines and use a print:

  print "Which scale do you require?:"
  getscale = sys.stdin.readline()


if len(getscale) > 1:
getscale = getscale[0].upper() + getscale[1:]


Don't you only want the first character? Otherwise it might mess up the 
'in' test below. If not, you could use string.capitalize() to do it in a 
single operation.



else:
getscale = getscale.upper()



if getscale in data.scalenames:
scale = main(getscale)


Where did main() come from? It's not defined in your code?


print scale

elif getscale == "Q" or getscale == "X" or getscale == "":
run = False
print"exiting..."


--
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] getting input for stdin

2014-12-08 Thread Alan Gauld

On 08/12/14 08:14, Alan Gauld wrote:


1.What I want to do is to redirect the output of the program to a text
file instead of the standard Python output. That is why I opened the
text file. That part of the program works fine.


Thats OK, although its still usual to keep a reference to the real 
stdout in case you want to print to it.



2. data is a py file named data.py which holds all the text
...into a separate file which is loaded as a
module at the begining of the program. hence data.info


Your code doesn't show that?


 which is a list of strings which are printed to the
scree. Hence in my program I open a text file and send the print out
put to that which is then printed to the text file. This works too.


I don't understand how the  thing can work. Its not a 
string and not a valid variable name and a for loop won't work on a 
construct like that. OK, I just went back to your original message.
I see that the url is being generated by my mail reader from what is 
presumably an HTML post. You actually just had data.info in your code.
Apologies, but it shows the dangers of posting to a text based list 
using HTML... :-(



3. When I ask for input in python the prompt which is usually in the
Python output console waits for the user input and returns that as a
string.
4.Insted of 3 above I would like the user to be able to type into a
text file which may be opened by the program to collect input.


OK, Just to clarify. You expect the file to already exist before the 
program runs? How does Python learn the name of this file?
Normally you would pass it into the program as a parameter or use 
redirection.


In fact it sounds like redirection would solve most of your problems here.

You can write the program to output to normal stdout and read from 
normal stdin.


When you start the program you can redirect those at the command
line like:

$ python myscript >myoutfile.txt < myinfile.txt.

Would that do what you want?


instance i open a text file named give_me_your_input.txt and then the
user types his requirement in that text file which is taken as a
string by the program which in turn either returns the appropriate
answer.


This is the bit I don;t understand. It still sounds like you want the 
user to open the file and type in it while your python code is running?
Can you elaborate on how that works? How exactly would your user 
interact with the computer in this scenario?



I know how to do everything else above except how to get the input
from the text file in real time.


raw_input can read from a file that already exists. It just reads one 
line at a time. You just need to modify sys,stdin in the same way you 
modified sys.stdout. Is that all you want? Or do you want raw_input to 
read changes in a file as its being edited by a user? That's much

harder - maybe impossible.


--
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] getting input for stdin

2014-12-08 Thread Alan Gauld

Forwarding tom list
Please always use Reply All (or Reply List) to include the list.

On 08/12/14 03:19, diliup gabadamudalige wrote:
I do not need to save any info in the text files opened for stdout and 
stdin.

The text files are empty files used only for Python output or Input.
I only need to use them as standard output and input.
I do not need to both above in the same file.
They may be in two different files.
after the user gets his answers from the program, on exit the files 
may be closed without saving.


Sorry for not adding the above in the previous email.
Thank you again.

On Mon, Dec 8, 2014 at 8:41 AM, diliup gabadamudalige 
mailto:dili...@gmail.com>> wrote:


Dear Allen,

:)

Thank you very much for the responses but some things have been
totally misunderstood here. :)

1.What I want to do is to redirect the output of the program to a
text file instead of the standard Python output. That is why I
opened the text file. That part of the program works fine.

2. data is a py file named data.py which holds all the text I need
to be printed to the console. As it is an explanation of music
theory and will be large i have put it into a separate file which
is loaded as a module at the begining of the program. hence
data.info  which is a list of strings which are
printed to the scree. Hence in my program I open a text file and
send the print out put to that which is then printed to the text
file. This works too.

3. When I ask for input in python the prompt which is usually in
the Python output console waits for the user input and returns
that as a string.
4.Insted of 3 above I would like the user to be able to type into
a text file which may be opened by the program to collect input.
For instance i open a text file named give_me_your_input.txt and
then the user types his requirement in that text file which is
taken as a string by the program which in turn either returns the
appropriate answer.

I know how to do everything else above except how to get the input
from the text file in real time.

My program works without any flaws without any of the stdin or
stdout in the normal console.

I hope this is clear enough to supply me with an answer.

I thank you once again for your time and hope you can spare a
little more to help me on the way.


On Mon, Dec 8, 2014 at 7:33 AM, Alan Gauld
mailto:alan.ga...@btinternet.com>> wrote:

On 07/12/14 17:38, diliup gabadamudalige wrote:

if __name__ == '__main__':


You don't really need that unless your code can be treated
as a module, which yours can't.

 p = os.getcwd()
 filename = "\get scale of choice.txt"
 filepath = p + filename
 sys.stdout = open(filepath, "w")


Why are you overwriting stdout with a file?
Why not just write to the file directly?
Usually if you do overwrite stdout you make a reference
to the old stdout first so you can restore it later.

 os.startfile(filepath)


This tries to execute filepath, but you just opened it
in write mode which creates an empty file. So you are
trying to execute an empty file?

 for i in data.info  :


What is data?
and what is the url like thing supposed to be?

Have you done a tutorial on Python?
Do you understand how the for loop works?
It needs an iterator/collection to operate on.

# print all the scale info

to window
 print i


This will print to stdout, which you have assigned
to a file above. So it won't print in any window.

 run = True
 while run:
 scaletemplate = ["C", "D", "E", "F", "G", "A", "B"]
 getscale = sys.stdin.raw_input(filepath)


Not sure what this is doing but raw_input reads from
stdin - it is not a method of stdin. And the argument to stdin
is supposed to be a prompt to the user, you have passed a
filename?

 #getscale = raw_input("Which scale do you require?:")

 if len(getscale) > 1:
 getscale = getscale[0].upper() + getscale[1:]


getscale is commented out so this will raise an error.

 else:
 getscale = getscale.upper()


 if getscale in data.scalenames:
 scale = main(getscale)
 print scale


Again, what is data?

 elif getscale == "Q" or getscale == "X" or
getscale == "":
 run = False
 print"exiting..."
 else:

Re: [Tutor] getting input for stdin

2014-12-08 Thread Alan Gauld

Forwarding tom list
Please always use Reply All (or Reply List) to include the list.

On 08/12/14 03:50, diliup gabadamudalige wrote:

I managed to get the output file and input file working.
The output works fine but the input does not. It simply exits the 
program. No crash. Exits.It DOES NOT WAIT FOR ME TO TYPE IN THE 
inputfile.txt


here is the program in all.

I have attached the whole program if you think that will help.
if __name__ == '__main__':
## menna me kaalla to change the output path
p = os.getcwd()
outfile = "\output_file.txt"
infile = "\input_file.txt"

outfilepath = p + outfile
infilepath = p + infile

sys.stdout = open(outfilepath, "w+")
sys.stdin = open(infilepath, "w+")

os.startfile(outfilepath)
os.startfile(infilepath)
##

for i in data.info :  # print all the scale info 
to window


print i

run = True

while run:
scaletemplate = ["C", "D", "E", "F", "G", "A", "B"]
## menna input ganna thana
getscale = sys.stdin.readline()
raw_input("Which scale do you require?:")
##---
print getscale



if len(getscale) > 1:
getscale = getscale[0].upper() + getscale[1:]
else:
getscale = getscale.upper()



if getscale in data.scalenames:

scale = main(getscale)

print scale

elif getscale == "Q" or getscale == "X" or getscale == "":
run = False
print"exiting..."

else:
print "No such scale"

On Mon, Dec 8, 2014 at 8:49 AM, diliup gabadamudalige 
mailto:dili...@gmail.com>> wrote:


I do not need to save any info in the text files opened for stdout
and stdin.
The text files are empty files used only for Python output or Input.
I only need to use them as standard output and input.
I do not need to both above in the same file.
They may be in two different files.
after the user gets his answers from the program, on exit the
files may be closed without saving.

Sorry for not adding the above in the previous email.
Thank you again.

On Mon, Dec 8, 2014 at 8:41 AM, diliup gabadamudalige
mailto:dili...@gmail.com>> wrote:

Dear Allen,

:)

Thank you very much for the responses but some things have
been totally misunderstood here. :)

1.What I want to do is to redirect the output of the program
to a text file instead of the standard Python output. That is
why I opened the text file. That part of the program works fine.

2. data is a py file named data.py which holds all the text I
need to be printed to the console. As it is an explanation of
music theory and will be large i have put it into a separate
file which is loaded as a module at the begining of the
program. hence data.info  which is a list of
strings which are printed to the scree. Hence in my program I
open a text file and send the print out put to that which is
then printed to the text file. This works too.

3. When I ask for input in python the prompt which is usually
in the Python output console waits for the user input and
returns that as a string.
4.Insted of 3 above I would like the user to be able to type
into a text file which may be opened by the program to collect
input. For instance i open a text file named
give_me_your_input.txt and then the user types his requirement
in that text file which is taken as a string by the program
which in turn either returns the appropriate answer.

I know how to do everything else above except how to get the
input from the text file in real time.

My program works without any flaws without any of the stdin or
stdout in the normal console.

I hope this is clear enough to supply me with an answer.

I thank you once again for your time and hope you can spare a
little more to help me on the way.


On Mon, Dec 8, 2014 at 7:33 AM, Alan Gauld
mailto:alan.ga...@btinternet.com>>
wrote:

On 07/12/14 17:38, diliup gabadamudalige wrote:

if __name__ == '__main__':


You don't really need that unless your code can be treated
as a module, which yours can't.

 p = os.getcwd()
 filename = "\get scale of choice.txt"
 filepath = p + filename
 sys.stdout = open(filepath, "w")


Why are you overwriting stdout with a file?
Why not just write to the file directly?
Usually if you do overwrite stdout you make a reference
to the old stdout first so you can restore it later.


Re: [Tutor] Coding

2014-12-08 Thread Alan Gauld

On 08/12/14 02:24, Steven D'Aprano wrote:


Python sees it like:

if FirstChoice == ('Coke' or 'Pepsi' or 'Water'):

So evaluates the bit in parens first which results in a boolean value of
True.



Actually it sees it as:

if ((FirstChoice == 'Coke') or 'Pepsi' or 'Water'):

which will always evaluate as True.


Oops, you're right.
Always test...


# The short way
if FirstChoice in ('Coke', 'Pepsi', 'Water'):


Which is what I was suggesting so we get to the same end game :-)


--
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] getting input for stdin

2014-12-08 Thread Alan Gauld

Forwarding tom list
Please always use Reply All (or Reply List) to include the list.


On 08/12/14 03:11, diliup gabadamudalige wrote:

Dear Allen,

:)

Thank you very much for the responses but some things have been 
totally misunderstood here. :)


1.What I want to do is to redirect the output of the program to a text 
file instead of the standard Python output. That is why I opened the 
text file. That part of the program works fine.


2. data is a py file named data.py which holds all the text I need to 
be printed to the console. As it is an explanation of music theory and 
will be large i have put it into a separate file which is loaded as a 
module at the begining of the program. hence data.info 
 which is a list of strings which are printed to the 
scree. Hence in my program I open a text file and send the print out 
put to that which is then printed to the text file. This works too.


3. When I ask for input in python the prompt which is usually in the 
Python output console waits for the user input and returns that as a 
string.
4.Insted of 3 above I would like the user to be able to type into a 
text file which may be opened by the program to collect input. For 
instance i open a text file named give_me_your_input.txt and then the 
user types his requirement in that text file which is taken as a 
string by the program which in turn either returns the appropriate answer.


I know how to do everything else above except how to get the input 
from the text file in real time.


My program works without any flaws without any of the stdin or stdout 
in the normal console.


I hope this is clear enough to supply me with an answer.

I thank you once again for your time and hope you can spare a little 
more to help me on the way.



On Mon, Dec 8, 2014 at 7:33 AM, Alan Gauld > wrote:


On 07/12/14 17:38, diliup gabadamudalige wrote:

if __name__ == '__main__':


You don't really need that unless your code can be treated
as a module, which yours can't.

 p = os.getcwd()
 filename = "\get scale of choice.txt"
 filepath = p + filename
 sys.stdout = open(filepath, "w")


Why are you overwriting stdout with a file?
Why not just write to the file directly?
Usually if you do overwrite stdout you make a reference
to the old stdout first so you can restore it later.

 os.startfile(filepath)


This tries to execute filepath, but you just opened it
in write mode which creates an empty file. So you are
trying to execute an empty file?

 for i in data.info  :


What is data?
and what is the url like thing supposed to be?

Have you done a tutorial on Python?
Do you understand how the for loop works?
It needs an iterator/collection to operate on.

# print all the scale info

to window
 print i


This will print to stdout, which you have assigned
to a file above. So it won't print in any window.

 run = True
 while run:
 scaletemplate = ["C", "D", "E", "F", "G", "A", "B"]
 getscale = sys.stdin.raw_input(filepath)


Not sure what this is doing but raw_input reads from
stdin - it is not a method of stdin. And the argument to stdin is
supposed to be a prompt to the user, you have passed a filename?

 #getscale = raw_input("Which scale do you require?:")

 if len(getscale) > 1:
 getscale = getscale[0].upper() + getscale[1:]


getscale is commented out so this will raise an error.

 else:
 getscale = getscale.upper()


 if getscale in data.scalenames:
 scale = main(getscale)
 print scale


Again, what is data?

 elif getscale == "Q" or getscale == "X" or getscale
== "":
 run = False
 print"exiting..."
 else:
 print "No such scale"


Again, these prints will go to your file since it is stdout.

I need to get the stdin input from the text I type into the
same text
file that I have stdout at.


How would that work exactly?
You want to open the file in a text editor or somesuch? Then as
you type into it you want Python to read the values you type?
Before you save it? Or after? And you also want the output from
Python to go into the file that you are editing? While you are
editing it?

Can you explain exactly how the user is expected to use this
combination of things?

It is not clear, very unlike any normal computing task and
probably impossible. I suspect you have a concept in your mind but
it's not
what you are describing here.

How do I do that. None of the answers at