Ask Your Question

jediknight219's profile - activity

2022-09-30 17:49:09 +0200 received badge  Popular Question (source)
2015-11-03 22:57:34 +0200 commented question Bug with raw literals?

On cloud.sagemath it works in a sage worksheet, but not a Jupyter notebook.

2015-11-03 21:55:38 +0200 answered a question Save boolean polynomial ring to file and read it again

Try this:

variables=[]
for i in range(1,257):
    variables.append('x'+str(i))
R = BooleanPolynomialRing(names=variables)
R.inject_variables()
fw = open('/home/pro/Desktop/polynomials.txt', 'w')
polynomial = R.random_element(degree=2,terms=+infinity)
fw.write(repr(polynomial) + "\n")                      # replaced str with repr
fr = open('/home/pro/Desktop/polynomials.txt', 'r')
polynomial = eval(fr.readline())                       # added eval
2015-11-03 14:58:39 +0200 received badge  Self-Learner (source)
2015-11-02 20:35:04 +0200 answered a question Bug with raw literals?

Looks like it is a known IPython bug.

https://github.com/ipython/ipython/is...

2015-11-02 19:59:31 +0200 commented question Bug with raw literals?

I'm on cloud.sagemath.com, running a Jupyter notebook, running the Python 2 kernel. I tried changing to Python 3, but to no avail.

2015-11-02 19:46:58 +0200 received badge  Student (source)
2015-11-02 19:44:11 +0200 commented question Bug with raw literals?

Apparently it only happens on the first line. The following works fine.

r"""
\
"""
2015-11-02 19:20:49 +0200 received badge  Scholar (source)
2015-11-02 19:19:39 +0200 asked a question Bug with raw literals?

On cloud.sagemath, the following is interpreted as an empty string

r"""\
"""

According to the python docs, Section 2.4.1 of the language specification:: "Note also that a single backslash followed by a newline is interpreted as those two characters as part of the literal, not as a line continuation."

Is this a bug? Or am I missing something?

2015-10-28 20:42:07 +0200 received badge  Self-Learner (source)
2015-10-28 20:42:07 +0200 received badge  Teacher (source)
2015-10-28 19:36:12 +0200 answered a question Custom Input Transformation

Figured it out. Replaced logical_line_transforms with physical_line_transforms.

2015-10-28 19:23:44 +0200 received badge  Editor (source)
2015-10-28 18:58:34 +0200 asked a question Custom Input Transformation

Greetings. I am trying to emulate the << >> functionality of OCaml in python on cloud.sagemath.com. For instance, if I type:

<<stuff>>

I want it to call default_parser("stuff"). I have it working if << and >> are on the same line, but I want it to be able to span multiple lines. Here's my code:

from IPython.core.inputtransformer import (StatelessInputTransformer)

@StatelessInputTransformer.wrap
def quotations(line):
    if line is not None:
        line = line.replace("<<", 'default_parser("""')
        line = line.replace(">>", '""")')
    return line

ip = get_ipython()
ip.input_splitter.logical_line_transforms.append(quotations())
ip.input_transformer_manager.logical_line_transforms.append(quotations())

It can't handle this:

<<
stuff
>>

It replaces the << in the first line just fine, but apparently once it goes into triple quote mode, it stops calling my transformation function.