Giter Club home page Giter Club logo

Comments (4)

Psycojoker avatar Psycojoker commented on September 28, 2024 1

Hello,

The support regarding formatting modification isn't very well integrated into RedBaron yet but it's accessible. The way to go to find this kind of information is to use .help(). But, formatting informations aren't displayed by default in .help(), for that, you'll need to use this paramter: http://redbaron.readthedocs.org/en/latest/basics.html#with-formatting

Which gives this in your case:

In [2]: RedBaron("a = 1").help(with_formatting=True)
0 -----------------------------------------------------
AssignmentNode()
  # identifiers: assign, assignment, assignment_, assignmentnode
  operator=''
  target ->
    NameNode()
      # identifiers: name, name_, namenode
      value='a'
  value ->
    IntNode()
      # identifiers: int, int_, intnode
      value='1'
  first_formatting ->
    * SpaceNode()
        # identifiers: space, space_, spacenode
        value=' '
  second_formatting ->
    * SpaceNode()
        # identifiers: space, space_, spacenode
        value=' '

Therefor:

In [7]: RedBaron("a =\\\n    2")[0].second_formatting
Out[7]: 0   '\\\n    '

Hope that helps,

from redbaron.

b5y avatar b5y commented on September 28, 2024

Hello,

Sorry for late answer. Your example can't be used in my project. I will explain why. When I compare '\n ' with body_line.second_formatting[0].value, it always gives False result. Even if I copy value from debugging console and past it to Watches window in PyCharm (print screen is attached).

Here is input test.

And my code:

from redbaron import RedBaron


def main():
    input = open('input_test.py', 'rb')
    red = RedBaron(input.read())
    assignments = red.find_all('AssignmentNode')
    for ind, body_line in enumerate(assignments.data):
        print body_line.second_formatting[0].value

if __name__ == '__main__':
    main()

Print screen of debugging process:
screenshot from 2016-04-04 15 28 31

I found another solution for my problem - getting position by absolute_bounding_box and comparing lines, but I want to know how to get comparison by returns. It still doesn't work like standard strings in Python.

from redbaron.

Psycojoker avatar Psycojoker commented on September 28, 2024

If you only want to see if a "\n" is present in the string you can do it this way:

In [6]: "\n" in RedBaron("a =\\\n    2")[0].second_formatting.dumps()
Out[6]: True

And this other way works too but is less general:

In [7]: "\n" in RedBaron("a =\\\n    2")[0].second_formatting[0].value
Out[7]: True

from redbaron.

b5y avatar b5y commented on September 28, 2024

Yes, it is what I want, but it doesn't work in this test case:

f = q\
     &t

Sorry for tediousness - I am implementing Python analyzer and need to check all test cases. absolute_bounding_box is still the only solution.
Anyway, thank you very much!

from redbaron.

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.