Ask Your Question

jediknight219's profile - activity

2015-11-03 15:57:34 -0600 commented question Bug with raw literals?

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

2015-11-03 14:55:38 -0600 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 07:58:39 -0600 received badge  Self-Learner (source)
2015-11-02 13:35:04 -0600 answered a question Bug with raw literals?

Looks like it is a known IPython bug.

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

2015-11-02 12:59:31 -0600 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 12:46:58 -0600 received badge  Student (source)
2015-11-02 12:44:11 -0600 commented question Bug with raw literals?

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

r"""
\
"""
2015-11-02 12:20:49 -0600 received badge  Scholar (source)
2015-11-02 12:19:39 -0600 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 14:42:07 -0600 received badge  Self-Learner (source)
2015-10-28 14:42:07 -0600 received badge  Teacher (source)
2015-10-28 13:36:12 -0600 answered a question Custom Input Transformation

Figured it out. Replaced logical_line_transforms with physical_line_transforms.

2015-10-28 13:23:44 -0600 received badge  Editor (source)
2015-10-28 12:58:34 -0600 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.