Comments (4)
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.
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:
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.
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.
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)
- [BUG] `return` on the 1-2 indent levels levels inside of `try`/`except` resets the closes `except` level HOT 5
- replacing a call atom with a comprehension raises ParsingError
- ComprehensionLoopNode target/iterator attributes transposed
- Misleading AST for modulo operator combined with multiplication HOT 1
- Please add a LICENSE file
- Conversion to ast ASTs
- Incorrect parsing of Unicode Literals. Got - UntreatedError: Untreated elements
- Middle-ground betwixt `ast` and `baron` for parsing source code, and emitting only what changed in FST from AST HOT 1
- bug: Comments determine indent level of function body
- GroupingError on await expression
- RedBaron confuse relative path to ellipsis in from_imports
- py.test tests failing
- bug: Unpacking operator `*` used in list gives an error HOT 2
- support for walrus operator
- support for context manager tuple
- Unsupported positional-only argument syntax
- Indent of function docstrings always four spaces HOT 2
- Sort functions by their usage?
- FromImportNode modifyed in memory but not saved to the file
- bug: remove() doesn't perform well. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redbaron.