Python Forum
How to correct, save, run with ptpython
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to correct, save, run with ptpython
#1
Hi all. I am Administrator. With Notepad: I go to correct the error, then I click on "save" icon, then I go to Command Prompt and run with "python Filename".

But with ptpython , where to correct, where to save, where to run.
Beside that , At the bottom, right corner I have "Meta+Enter Execute". What is it ?
Also at the bottom I have "History". I should like to use that, but I don't know how.
Error:
C:\Users\Sylvain λ ptpython >>> class Selfless: ... def __init__(Self, data): ... self.data=data ... def selfless(arg1,arg2): ... return arg1+arg2 ... def normal(self,arg1,arg2): ... return self.data+arg1+arg2 >>> X=Selfless(2) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in __init__ NameError: name 'self' is not defined name 'self' is not defined >>>
Reply
#2
self is always lowercase.
class Selfless:
    def __init__(self, data):
        self.data = data

    def selfless(self, arg1, arg2):
        return arg1 + arg2

    def normal(self, arg1, arg2):
        return self.data + arg1 + arg2
So now copy into ptpython,just Enter after copy in will execute class Selfless:
C:\Users\Tom
λ ptpython
>>> class Selfless:
...     def __init__(self, data):
...         self.data = data
...
...     def selfless(self, arg1, arg2):
...         return arg1 + arg2
...
...     def normal(self, arg1, arg2):
...         return self.data + arg1 + arg2

>>> # use Class
>>> obj = Selfless(2)
>>> obj.selfless(5, 8)
13
>>> obj.normal(5, 8)
15
>>>
Not using self in selfless,use @staticmethod.
Then just a function placed in class Selfless
@staticmethod
def selfless(arg1, arg2):
    return arg1 + arg2
Reply
#3
@snippsat
Thanks. But i should appreciate explanations about "History", and "Meta+Enter -Execute" Is somewhere a User Help ?
Reply
#4
Press F3 to start history.
[Image: S8uo3p.jpg]
ptpython review
Reply
#5
I cannot copy correctly a console program. First I tried "double click", on forum's page, 2. I I swept all lines, one after the other; Always same bad copy. Here is the copy:
Error:
C:\Users\Sylvain λ class Selfless: def __init__(self, data): self.data = data def selfless(self, arg1, arg2) : return arg1 + arg2 def normal(self, arg1, arg2): return self.data + arg1 + arg2 'class' is not recognized as an internal or external command, operable program or batch file.
Reply
#6
You have not started ptpython.
Now you have just coped into command line.
There is always >>> when you start.
E:\1py_div\a
λ ptpython
>>>  
Now first can you copy in code or push F3 for historie as my laste post was about.
Reply
#7
Before pasting i got: Warning! Pasting long text (208 chars) may make the console non-responsive until the paste finishes ! Continue ?

Of course I continued , and here is always the same bad copy:

Error:
C:\Users\Sylvain λ ptpython >>> class Selfless: def __init__(self, data): self.data = data def selfless(self, arg1, ar ... g2): return arg1 + arg2 def normal(self, arg1, arg2): return self.data + arg1 + ar ... g2
Reply
#8
Copy code from my post and it should work.
This can happens when you copy for some other editors,
just try again with different approach.
Reply
#9
Strange enough! I went to your post. I tried to copy(1 double clic, then 2 line after line) always the same bad copy. Is it possible nobody until now tried to copy a console program ??
Reply
#10
(May-29-2018, 04:43 PM)snippsat Wrote: self is always lowercase.

Formally, you can write it the way you want - or replace with any other name, since self is just a convention. Of course, that would be a very bad idea Naughty , and it will piss off any Pythonista reading that blasphemy Evil - but it will work
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 560 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  How to handle "History" in ptpython sylas 4 4,005 Oct-07-2018, 11:09 PM
Last Post: Larz60+
  Cannot use functions at the bottom of ptpython sylas 1 2,213 Aug-29-2018, 12:02 PM
Last Post: sylas
  Error in a file and problem with ptpython sylas 7 4,226 Aug-25-2018, 10:17 AM
Last Post: sylas
  ptpython docstring metulburr 4 4,491 Nov-17-2017, 01:36 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020