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
#11
@snippsat
I think nobody till now tried to copy an interactive prompt. I think this ptpython, or even python, writes somewhere all the commands you entered, since you refind them after a turn-off of the computer.
About the use of History, I tried what you discovered. It works well. But what for the piece of history you selected, and which is now at the right side ?
Reply
#12
Success at last. Before i paste, I had the following message: Pasting multi-line text involves sending <Enter> keypresses to console ! Continue ?
I did so and here is the result:
...                                             
>>>  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)                      
Reply
#13
You need to copy the code plain code without >>> and ...,
as i posted first.
class Selfless:
    def __init__(self, data):
        self.data = data

    @staticmethod
    def selfless(arg1, arg2):
        return arg1 + arg2

    def normal(self, arg1, arg2):
        return self.data + arg1 + arg2
Then it look like this with code over.
You press ok 2 times about warning,then Enter 2 times.
[Image: mFNjs6.jpg]
(May-30-2018, 08:40 PM)volcano63 Wrote: Formally, you can write it the way you want - or replace with any other name, since self is just a convention.
I know this,all follow the convention,so this can be info for @sylas.
Reply
#14
Thanks, however, after I have copied, beside the >>> followed by the cursor(on the console) I must make a right click, which makes appear the little window, telling.......... Pasting multi-line text involves sending <Enter> keypresses to console ! Continue ?
Reply
#15
(May-31-2018, 12:57 PM)sylas Wrote: I must make a right click, which makes appear the little window, telling.......... Pasting multi-line text involves sending <Enter> keypresses to
Yes as i mention you push Ok or Enter then code will be pasted in,
then Enter and >>> show up and you can test class as show i picture.
Reply
#16
Since it is not obvious I think I have to speak of error handling. So I put an error in a file which ran well. Instead of print I wrote pxint.
After file was ran, interpreter noticed the error and the line.
Next I went to History (with F3). I saw the file. I went to the error line with the cursor, and then with "space" repeated many times, I had at the right pane all the lines following the error line. (error line included). Then with an ENTER the 2 Panes disappear.
Now with the cursor I go to the first line(error line) and correct the error.
Now, for running I have to go down to last line and last letter of this last line.
I run there, with just hitting ENTER.
Reply
#17
The error will not be in History.
>>> a = 'hello'
>>> print(a)
hello

>>> prinx(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'prinx' is not defined
name 'prinx' is not defined
Now F3 choose lines and Enter.
Back in normal windows Ctrl+Enter to execute.
>>> a = 'hello'
... print(a)
hello 
Choose(space) just line with error from history(Enter).
Ctrl+Enter to execute or just go to end on line and Enter.
The error will be regenerated bye python.
>>> prinx(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'prinx' is not defined
name 'prinx' is not defined
Reply
#18
Once the correction made, no need to go to the bottom of the file, just a ctrl+enter, makes run the piece of file.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 542 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  How to handle "History" in ptpython sylas 4 3,992 Oct-07-2018, 11:09 PM
Last Post: Larz60+
  Cannot use functions at the bottom of ptpython sylas 1 2,205 Aug-29-2018, 12:02 PM
Last Post: sylas
  Error in a file and problem with ptpython sylas 7 4,193 Aug-25-2018, 10:17 AM
Last Post: sylas
  ptpython docstring metulburr 4 4,469 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