Giter VIP home page Giter VIP logo

Comments (5)

ncw avatar ncw commented on June 12, 2024

If I save what you wrote to a file then it works fine in gpython,

Can you show us what you tried and the error it gave?

from gpython.

raff avatar raff commented on June 12, 2024

Ah!

So, the problem is that it doesn't work from REPL. REPL should probably ignore empty lines.

What I did was, I was writing a test for the print stuff, and wanted to try in the REPL first. I also wrote in in a file, but didn't named it *.py, since it was just a test, but gpython currently doesn't read files if they don't have the .py extension (while regular python does), so I just did:

 go run main.go < xxx

from gpython.

ncw avatar ncw commented on June 12, 2024

That doesn't work in the python3 REPL either. I tried pasting your example with the blank line and I get the same errors.

I think this is a known problem with the python REPL: eg https://stackoverflow.com/questions/37891771/python-interactive-interpreter-has-problems-with-blank-lines-when-i-paste-in-a-s

So I think gpython is following cpython here, unless I mis-understand what you mean.

from gpython.

raff avatar raff commented on June 12, 2024

Given a file classes.py:

class X(object):
    def __init__(self, x):
        self.x = x

    def __str__(self):
        return "my name is " + str(self.x)

x = X("hello")
print(x)

x = X(42)
print(x)

This works:

$ python3.4 < classes.py 
my name is hello
my name is 42

This doesn't:

$ go run main.go < classes.py 
Gpython 3.4.0
Compile error: 
  File "<string>", line 1, offset 4
        def __str__(self):


SyntaxError: 'invalid syntax'
Compile error: 
  File "<string>", line 1, offset 8
            return "my name is " + str(self.x)


SyntaxError: 'invalid syntax'
<X object at 0xc0000efb00>
<X object at 0xc0000efb90>

I am actually testing against python3.7, that is what got installed on my Mac, but I wouldn't think this is something that changed between 3.4 and 3.7, since it works the same in 2.7

from gpython.

ncw avatar ncw commented on June 12, 2024

Ah, I see - thanks for the explanation.

What appears to be happening is that gpython is starting the interactive interpreter when you do gpython < file.py whereas when you do python3 < file.py it doesn't start the REPL, it treats the input as a proper file.

From https://docs.python.org/3/using/cmdline.html

When called with standard input connected to a tty device, it prompts for commands and executes them until an EOF (an end-of-file character, you can produce that with Ctrl-D on UNIX or Ctrl-Z, Enter on Windows) is read.

When called with a file name argument or with a file as standard input, it reads and executes a script from that file.

Which I think agrees with the above.

from gpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.