mathialo / bython Goto Github PK
View Code? Open in Web Editor NEWPython with braces. Because python is awesome, but whitespace is awful.
License: MIT License
Python with braces. Because python is awesome, but whitespace is awful.
License: MIT License
I will be working with others on projects and will be maintaining some of their code.
For this it would be nice if I could simply change their code and mix indented code with braced code.
Make it easier for those who've written code in other languages by converting &&
to and
and ||
to or
Consider converting !x
to not x
but that may be less trivial
Compiling more than one file at a time is not yet supported. This means that you cannot import from bython-files yet.
Hi! I'm not a pro at using Python but there seems to be a parsing error for arguments with Bython
I'm trying to pass JSON string as an argument, which works if you use python but breaks when using Bython, the whitespaces and/or the double-quotes in the argument breaks.
sample JSON argument that breaks:
'{"1": [1,2]}'
when the output is printed from sys.argv, it becomes {1:[1,2]} thereby breaks the load function of the JSON
EDIT:
The argument above should have backslashes before the double quotes for it to work properly :)
Thanks!
This fails in Bython
a = { 'a', 'b' }
print("Works in Python")
With:
$ bython test2.py
File "python_test2.py.py", line 1
a =:'a', 'b'
^
SyntaxError: invalid syntax
It appears some glitches in bython occur because it's reading the source code as text. It might be more useful to python -m tokenize input.py
first and then change the tokenized version
cp ex.by ex2"$(yes ls | head -n 16)"
bython ex2*
Fails after running ls
15 times.
py2by fails on a lot of valid python indentation cases, including, but not limited to:
No way to express mixed indentation levels, which are valid in python. E.g.:
if (1==1):
if(2==2):
print("Oops!")
Indentation that does not impact nesting level. E.g.:
print("Sometimes strings that are too long,",
"are broken up on different lines.")
I'm considering rewriting py2by utilizing the python tokenizer to detect INDENT and DEDENT tokens. Should be more portable too, should the indentation rules for python ever change
Hi! I'm new to this project but i'm not sure if bython already supports transpiling to python, instead of just interpreting bython code. This isn't explicitly stated in the readme (to my understanding), so can bython transpile .by to .py?
As the title suggests, when doing something like this:
def test()
{
return "test"
}
It gets turned into this, which doesn't work:
def test()
:
return "test"
I think there was an effort to make this work in line 161 of parser.py:
line = re.sub(r"\n:", ":", line)
However this is applied to lines, it should be applied to infile_str_intdented, like this:
infile_str_indented = re.sub(r"\n:", ":", infile_str_indented)
Which will fix it
Since dictionaries uses curly braces they will cause a lot of errors when translating from bython to python. Dictionaries in python-files you import works.
Lines with "}" can't have stuff behind them. The following code doesn't run:
if condition {
pass
} else {
pass
}
but must instead be written as
if condition {
pass
}
else {
pass
}
You have the same goal as PyBrace. Reach out and collaborate.
There is py2by
, but no by2py
.
I think it would be better bython -c
is aliased to by2py
by default. :)
I was trying to use bython for newliners. I found that in addition to #33, there's another problem. Consider the following program:
m=0; for line in __import__("sys").stdin { m = m if m > int(line.strip()) else int(line.strip())} ; print(m)
This only works if m=0 has its own line. Could this limitation be lifted?
Is it possible to hack the Python import system to import Bython code, just like how we could do register hooks on Node? I don't want to transpile it all the time beforehand you know...
There's a proposal of adding a new import hook in Python, but it has been staggered for like 16 years. I don't know it that's relevant. Maybe we should exploit ImportError
and then get the transpiled code injected there...
But I don't know Python at all, anyway.
I want this to work:
#!/usr/bin/env bython
def a():
print("a")
def b() {
if 4<5:
print("b")
}
a()
b()
The situation here is: I get a Python script that I edit. Most of it is white-space indented correctly. But parts of it use braces.
In particular I need braces to paste-in a section. In the above I got the if
and print
statements from another source with different indention. So I simply wrapped it with {} and this should then be understood correctly.
So I am asking for a mixed mode, where indention matters if there are no braces overriding it.
im getting this in terminal when i try to install following instructions in the readme:
Makefile:5: recipe for target 'install' failed
make: *** [install] Error 1
is this a problem on my end or something with the makefile?
I would like to enable auto-format-on-save for my IDE but can't find a way to format bython.
I thought by2py example.by && py2by example.py && rm example.py
would achieve what I'm looking for, but it generates some additional newlines etc.
py2by
also doesn't overwrite the existing example.by
so it would have to be done with rm example.by
between by2py
& py2by
. Deleting the file would probably mess up the IDE, 'in place' replacement would be preferable.
Input:
def print_message(num_of_times) {
for i in range(num_of_times) {
print("Bython is awesome!");
}
}
if __name__ == "__main__" {
print_message(10);
}
After by2py:
def print_message(num_of_times):
for i in range(num_of_times):
print("Bython is awesome!")
if __name__ == "__main__":
print_message(10)
After py2by:
def print_message(num_of_times){
for i in range(num_of_times){
print("Bython is awesome!")
}
}
if __name__ == "__main__"{
print_message(10)
}
Bython should be able to parse itself, and not rely on filthy regular python in doing so!
There are many options in the source which is not covered by README. It would be good to put those in a man page.
I'm trying to install Bython on windows with Python 3.7.1, by using pip install bython
in the Windows admin command prompt. Pip reports it as installed, but the command prompt won't recognize the bython
command. Am I doing something wrong?
import os
def main(){
c= {1,3}
print('hello')
print({'A':1,
'b':2}
)
}
main()
Fails with
File "python_main.py", line 4
c=:1,3
^
IndentationError: expected an indented block
The compiler seems to have issues working with Python dictionaries. It converts the left curly brace to a colon.
Last commit is from 2018, it would be nice to have the improvements implemented
Hi there!
One of my main gripes about Python is not being able to write multiline lambdas. I had an idea to create a Python preprocessor that allows braces (and found this before making it myself) to allow multiline lambdas, but also to generally improve readability.
I'm just wondering if Bython supports multiline lambdas, or plans to in the future.
Thanks so much!
When working with files written by others it would be nice if you could convert their code to braced code.
By being able to convert both ways you open up for making an emacs-filter that inserts braces when opening a file and removes them when saving the file. Give that emacs can run .gz-files through a filter it ought to be easy to do that for .py-files, too.
PS: And thank you. I have been holding off using Python for anything serious because of the missing braces. Now that hurdle is gone.
def test(x): #prints x
print(x)
is converted to
def test(x) #prints x
{
print(x);
}
which when run is converted to
def text(x) #prints x:
print(x)
which causes a syntax error because the : is commented out.
Is it even possible to use this on Windows? If so, how?
Thanks for bython, I like it! Could you add -r that reads the code from argv as opposed to the filename, so that I could use it in one-liners?
Is there any tmLanguage grammar available for the bython language? If there is one let me know
Bython v0.8 exhibits a problem in which it modifies braces within single and double quotation strings.
Code to reproduce:
test.by:
print('Hello, world! I have braces {} here.');
print("Hello, world! I have braces {} here, too.");
The output produced is:
Hello, world! I have braces:here.
Hello, world! I have braces:here, too.
The expected output is, of course:
Hello, world! I have braces {} here.
Hello, world! I have braces {} here, too.
Thanks!
You, my good sir, are a magnificent bastard for doing this!
Though I am unfit to touch the hem of your garment, as your disciple I will go forth and hail this good news unto the multitudes.
Would havign Bython on VSCode and PyCharm make programming easier?
Hi! I've made a rudementary syntax highlighting module for vim, and am requesting for help with writing the indenting code. I know I can use a variant of vim's native cindent
feature, but other than that, I'm stumped as how to made semicolons optional.
JS can do it. I think if bython cannot support JSON syntax, this will be a major weakness down the road.
🅱ython.
Enough said
Here's a python snippet:
print("Hello World: !")
Running py2by on this snippet results in:
print("Hello World !")
The documentation explains that py2by is experimental- but I'd like to report this bug. Maybe there's an easy fix?
I discovered this bug when py2by-ing a souce file with type annotations (they break).
Just came here to tell you this. This project is just awesome! Create some VSCODE syntax highlighter and the project will have a tailwind.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.