Re: [Tutor] Python Shell

2016-10-09 Thread Alan Gauld via Tutor
On 08/10/16 20:43, Alan Clarke wrote:

> I created a program called HW.py  that runs under a command prompt, 
> but Python Shell gives the following error:

How are you running it in the Python shell?

> Traceback (most recent call last):
>   File "", line 1, in 
> HW.py
> NameError: name 'HW' is not defined
> 
> Can someone please tell me what I'm doing wrong?

Since you don't tell us what you are doing, we
cant tell you what about it is wrong.

If you are are trying to execute HW.py from
the >>> prompt by just typing its name
then that's wrong. You need to import it as HW

import HW   # note not HW.py, just HW

And if it has a sentinel section that runs
a main() function then you need to replicate
that code manually.

But it's not normal to run programs from the
Python shell like that. Most IDEs such as
IDLE have a menu option to run the program
and the output then appears in the shell
window. But, even then, it should just be for
testing, the best way to run the program
is, as you apparently did, using the
python interpreter directly from the OS.

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


[Tutor] Python Shell

2016-10-08 Thread Alan Clarke
Hi.

I have just installed Python 2.7.12 ( i have windows xp).

I created a program called HW.py  that runs under a command prompt, but Python 
Shell gives the following error:

Traceback (most recent call last):
  File "", line 1, in 
HW.py
NameError: name 'HW' is not defined

Can someone please tell me what I'm doing wrong?

I have added the Python directory to the Path.



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


[Tutor] Python shell wont open IDLE or an exisiting .py files

2014-01-30 Thread shangonichols
I am on Windows 8, Python 3.3.4 and 3.3.3 and all previous versions exhibit the 
same problem on my Windows 8 PC. This problem occurred out of nowhere 
overnight. It was working fine for months until today.

>  I tried to open a file and nothing happened. If I tried to open a .py file
> (any .py file) from an existing instance of IDLE, it briefly flashed up a
> new window and then closed both the new window and the existing window
> (normally it opens the requested in a new window leaving the existing window
> untouched).
>
> If I launch the Python GUI it opens a Python Shell fine. But as soon as I
> try to open a file (including a "new" file), it closes the Shell.
>
> I rebooted the machine. Same problem.
>
> I repaired the Python installation and rebooted. Same problem.
>
> I uninstalled Python. Rebooted. Deleted the Python33 directory entirely.
> Rebooted. Installed Python. Rebooted. Same problem.
>
> Everything else on the system appears to be working just fine.
>
> Any ideas what the problem might be or how else I might go about fixing
> things?








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


Re: [Tutor] Python shell wont open IDLE or an exisiting .py files

2014-01-29 Thread eryksun
On Wed, Jan 29, 2014 at 11:16 PM, Ben Finney  wrote:
> Terry Reedy  writes:
>
>> This I do not. What is 'Python GUI'? What is 'Python Shell'?
>
> Those are (part of) the names of menu entries created by the Python
> installer for MS Windows. I am not sure exactly what programs they
> invoke.

The above reply was cross-posted from the following thread on python-list:

https://mail.python.org/pipermail/python-list/2014-January/thread.html#665549

The Windows start menu has a shortcut for "IDLE (Python GUI)" that
runs the idle.pyw script. The file extension .pyw is associated with
either pythonw.exe or the launcher pyw.exe, which are both linked as
GUI programs. That means the process is created without an attached
console (one can be allocated or attached later using Windows API
calls).

idle.pyw imports idlelib.PyShell and calls its `main`. The shell
itself is implemented by the PyShell class, for which the window title
is

"Python " + platform.python_version() + " Shell"

http://hg.python.org/cpython/file/c3896275c0f6/Lib/idlelib/PyShell.py#l829

Also, the editor window's run menu has a "Python Shell" item:

('run', [('Python Shell', '<>')])

http://hg.python.org/cpython/file/c3896275c0f6/Lib/idlelib/Bindings.py#l59
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python shell wont open IDLE or an exisiting .py files

2014-01-29 Thread Ben Finney
Terry Reedy  writes:

> On 1/29/2014 6:26 PM, shangonich...@sbcglobal.net wrote:
> >  > If I launch the Python GUI it opens a Python Shell fine. But as
> >  > soon as I try to open a file (including a "new" file), it closes
> >  > the Shell.
>
> This I do not. What is 'Python GUI'? What is 'Python Shell'?

Those are (part of) the names of menu entries created by the Python
installer for MS Windows. I am not sure exactly what programs they
invoke.

-- 
 \   “… whoever claims any right that he is unwilling to accord to |
  `\ his fellow-men is dishonest and infamous.” —Robert G. |
_o__)   Ingersoll, _The Liberty of Man, Woman and Child_, 1877 |
Ben Finney

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


Re: [Tutor] python shell not working like it used to

2007-02-26 Thread Jeff Peery
well the __init__() funciton is not my code, it is in:
 
 C:\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\py\shell.py
 
as I mentioned I upgraded wxpython... maybe I should email there... anyhow I 
just want to use my dictionary in the shell, but I'm not sure what the 
attribute 'this' is... it seems to be something different from my previous 
version of wxpython.

thanks. 
J

Alan Gauld <[EMAIL PROTECTED]> wrote: "Jeff Peery"  wrote 

>  def __init__(self, other):
>d['this'] = other.this
>   
>  "other" here is the dictionary I pass in (I think), 
> so it's for some reason looking for some attribute in 
> my dictionary called 'this'. 

other is whatever you pass in.
The code expects it to be dictionary like and to 
have a this attribute

> of course my dictionary doesn't have this attribute. 

So why is your code trying to access one if you know 
it doesn't exist? And why are you surprised at the 
error message? (Or is the init() not your code?)

> I have no idea what this is. any ideas? 

Youu seem to have answered your own question.
You are passing a dictionary into init() that does not 
have a this attribute but the code inside the init() is 
trying to access a this attribute. It can't find one so 
it raises an error.

Either remove the this access in init or add a thus 
attribute to your dictionary argument. Or pass an 
argument that does have a this attribute.

I'm slightly confused about what you are asking us to tell you?

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



-
Everyone is raving about the all-new Yahoo! Mail beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python shell not working like it used to

2007-02-26 Thread Alan Gauld
"Jeff Peery" <[EMAIL PROTECTED]> wrote 

>  def __init__(self, other):
>d['this'] = other.this
>   
>  "other" here is the dictionary I pass in (I think), 
> so it's for some reason looking for some attribute in 
> my dictionary called 'this'. 

other is whatever you pass in.
The code expects it to be dictionary like and to 
have a this attribute

> of course my dictionary doesn't have this attribute. 

So why is your code trying to access one if you know 
it doesn't exist? And why are you surprised at the 
error message? (Or is the init() not your code?)

> I have no idea what this is. any ideas? 

Youu seem to have answered your own question.
You are passing a dictionary into init() that does not 
have a this attribute but the code inside the init() is 
trying to access a this attribute. It can't find one so 
it raises an error.

Either remove the this access in init or add a thus 
attribute to your dictionary argument. Or pass an 
argument that does have a this attribute.

I'm slightly confused about what you are asking us to tell you?

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python shell not working like it used to

2007-02-25 Thread Jeff Peery
hello, I just upgraded to python 2.5 and wxpython 2.6. I'm not sure the correct 
list for this but I'm trying to shove some variables into a py shell using the 
below code. this worked pretty well before, but now it gives me an error on the 
last line of my brief example. The error is:
   
  'dict' object has no attribute 'this' 
   
  it occurs on line 171 in shell.py. so I looked in shell.py and it looks like 
this:
   
  def __init__(self, other):
"""Create a ShellFacade instance."""
d = self.__dict__
d['other'] = other
d['helpText'] = HELP_TEXT
d['this'] = other.this
   
  "other" here is the dictionary I pass in (I think), so it's for some reason 
looking for some attribute in my dictionary called 'this'. of course my 
dictionary doesn't have this attribute. I have no idea what this is. any ideas? 
my few lines of code are below.
   
   
  import py
  import wx.py as py
   
  partList = {'this is some dictionary':1}
  pyWindow2  = py.editor.EditWindow(py.editor.Editor, splitterWindow1, 
-1)
pyWindow1  = py.shell.Shell(splitterWindow1, -1, introText = None)
pyWindow1.interp.locals['partList'] = py.shell.ShellFacade(partList)

 
-
Never Miss an Email
Stay connected with Yahoo! Mail on your mobile. Get started!___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Shell Not Saved Problem

2005-10-06 Thread Kent Johnson
Steve Haley wrote:
> A 
> couple of folks also mentioned a book, Beginning Python: From Novice to 
> Professional.  I think I might try that.

There are many good beginner's resources, both on-line and print. Here are a 
couple of good lists:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers?highlight=%28BeginnersGuide%2F%29
http://wiki.python.org/moin/IntroductoryBooks

> Again, thanks everyone for all the help.  I was very impressed with the 
> response to my cry for help.

You're welcome. The Python community is a pretty friendly bunch and the tutor 
list is for newbie questions so come back next time you are stumped.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Shell Not Saved Problem

2005-10-05 Thread Alan Gauld
> Also, someone advised that the Shell window not be used that way anyway. 
> I
> think I agree and will operate from Pythonwin from now on.

The same applies in Pythonwin. You cannot run the interactive shell buffer
because Python will try to execute all the output from the commands - they
get executed as soon as you type them. You run programs from the text 
buffers
and the output appears in the shell window.

The typical way of working is:
- start the IDE(IDLE or Pythonwin)
- from the Shell buffer default window use File->Open(or New) to
  open a new code editor window
- from the new window use Run to execute the code in the current edit pane.
- look at the output in the shell window/pane

You don't need to close the window between runs just save the code and
rerun it.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Shell Not Saved Problem

2005-10-05 Thread Steve Haley








Dear folks,

 

Just wanted to thank everyone for the help.  I think I
know what was going on with that “The buffer for Python Shell is not
saved” message I was getting when I tried to run a script. 
Apparently you need to open the module before you run the script and also to
re-open it each time you want to run the script.  That seems a little
strange to me but it appears to work that way.  By the way, a couple of
folks said their screen didn’t look like what I described and wondered
what version I was using.  It is version 2.1 which I have because it that
version is bundled with ESRI ArcGIS 9 which I have.  I have been wondering
if I can update that version but am afraid that it might be customized to
ArcGIS somehow and I might mess that up if I upgrade just the Python portion.

 

Also, someone advised that the Shell
window not be used that way anyway.  I think I agree and will operate from
Pythonwin from now on.  A couple of folks also mentioned a book, Beginning
Python: From Novice to Professional.  I think I might try
that.

 

Again, thanks everyone for all the help.  I was very
impressed with the response to my cry for help.

 

- Steve






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor